Commit d9ad3dcc authored by Lars Krecklau's avatar Lars Krecklau

-Created the RenderObject from the State. The RenderObject now only composes...

-Created the RenderObject from the State. The RenderObject now only composes VBOs, SPOs and FBOs and automatically creates the right mappings between them.
-Removed the pre processor from the shader class, since we now only work with the gl getters to retrieve any locations (uniform, attribute, fragdata).
-The ShaderProgram controllers have the possibility to define the order of the attributes manually (so the programmer can work with conventions).
parent d5f6362f
......@@ -22,10 +22,10 @@
#include <ACGL/OpenGL/Controller/ElementArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/FrameBufferObjectControl.hh>
#include <ACGL/OpenGL/Controller/RenderBufferControl.hh>
#include <ACGL/OpenGL/Controller/RenderObjectControl.hh>
#include <ACGL/OpenGL/Controller/ShaderControlFile.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramControlAutoFiles.hh>
#include <ACGL/OpenGL/Controller/ShaderProgramObjectControl.hh>
#include <ACGL/OpenGL/Controller/StateControl.hh>
#include <ACGL/OpenGL/Controller/TextureControl.hh>
#include <ACGL/OpenGL/Controller/TextureControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/UniformControl.hh>
......
......@@ -29,8 +29,8 @@ public:
mDepthAttachment()
{
mDepthAttachment.name = "";
mDepthAttachment.texture = SharedTexture();
mDepthAttachment.renderBuffer = SharedRenderBuffer();
mDepthAttachment.texture = ConstSharedTexture();
mDepthAttachment.renderBuffer = ConstSharedRenderBuffer();
}
virtual ~FrameBufferObjectControl() {}
......@@ -38,16 +38,16 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline FrameBufferObjectControl& depthTexture (const SharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; }
inline FrameBufferObjectControl& depthRenderBuffer (const SharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; return *this; }
inline FrameBufferObjectControl& depthTexture (const ConstSharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; }
inline FrameBufferObjectControl& depthRenderBuffer (const ConstSharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; return *this; }
inline FrameBufferObjectControl& colorTexture(const std::string& _name, const SharedTexture& _texture)
inline FrameBufferObjectControl& colorTexture(const std::string& _name, const ConstSharedTexture& _texture)
{
FrameBufferObject::Attachment attachment = {_name, _texture, SharedRenderBuffer()};
mColorAttachments.push_back(attachment);
return *this;
}
inline FrameBufferObjectControl& colorRenderBuffer(const std::string& _name, const SharedRenderBuffer& _renderBuffer)
inline FrameBufferObjectControl& colorRenderBuffer(const std::string& _name, const ConstSharedRenderBuffer& _renderBuffer)
{
FrameBufferObject::Attachment attachment = {_name, SharedTexture(), _renderBuffer};
mColorAttachments.push_back(attachment);
......
......@@ -3,64 +3,58 @@
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_STATECONTROL_HH
#define ACGL_OPENGL_CONTROLLER_STATECONTROL_HH
#ifndef ACGL_OPENGL_CONTROLLER_RENDEROBJECTCONTROL_HH
#define ACGL_OPENGL_CONTROLLER_RENDEROBJECTCONTROL_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/State.hh>
#include <ACGL/OpenGL/Objects/RenderObject.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class StateControl : public Resource::BasicCreateController<State>
class RenderObjectControl : public Resource::BasicCreateController<RenderObject>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
StateControl(
const ConstSharedShaderProgramObject& _shaderProgramObject,
RenderObjectControl(
const ConstSharedVertexBufferObject& _vertexBufferObject,
const ConstSharedViewport& _viewport)
const ConstSharedShaderProgramObject& _shaderProgramObject)
: mpVertexBufferObject(_vertexBufferObject),
mpShaderProgramObject(_shaderProgramObject),
mpFrameBufferObject(),
mpViewport(_viewport)
mpFrameBufferObject()
{}
StateControl(
RenderObjectControl(
const ConstSharedVertexBufferObject& _vertexBufferObject,
const ConstSharedShaderProgramObject& _shaderProgramObject,
const ConstSharedFrameBufferObject& _frameBufferObject,
const ConstSharedViewport& _viewport)
const ConstSharedFrameBufferObject& _frameBufferObject)
: mpVertexBufferObject(_vertexBufferObject),
mpShaderProgramObject(_shaderProgramObject),
mpFrameBufferObject(_frameBufferObject),
mpViewport(_viewport)
mpFrameBufferObject(_frameBufferObject)
{}
virtual ~StateControl(void) {}
virtual ~RenderObjectControl(void) {}
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline StateControl& vertexBufferObject (const ConstSharedVertexBufferObject& _vertexBufferObject) { mpVertexBufferObject = _vertexBufferObject; return *this; }
inline StateControl& shaderProgramObject (const ConstSharedShaderProgramObject& _shaderProgramObject) { mpShaderProgramObject = _shaderProgramObject; return *this; }
inline StateControl& frameBufferObject (const ConstSharedFrameBufferObject& _frameBufferObject) { mpFrameBufferObject = _frameBufferObject; return *this; }
inline StateControl& viewport (const ConstSharedViewport& _viewport) { mpViewport = _viewport; return *this; }
inline RenderObjectControl& vertexBufferObject (const ConstSharedVertexBufferObject& _vertexBufferObject) { mpVertexBufferObject = _vertexBufferObject; return *this; }
inline RenderObjectControl& shaderProgramObject (const ConstSharedShaderProgramObject& _shaderProgramObject) { mpShaderProgramObject = _shaderProgramObject; return *this; }
inline RenderObjectControl& frameBufferObject (const ConstSharedFrameBufferObject& _frameBufferObject) { mpFrameBufferObject = _frameBufferObject; return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedState create(void)
virtual SharedRenderObject create(void)
{
SharedState state(new State(mpVertexBufferObject, mpShaderProgramObject, mpFrameBufferObject, mpViewport));
return state;
SharedRenderObject renderObject(new RenderObject(mpVertexBufferObject, mpShaderProgramObject, mpFrameBufferObject));
return renderObject;
}
// =================================================================================================== \/
......@@ -70,7 +64,6 @@ protected:
ConstSharedVertexBufferObject mpVertexBufferObject;
ConstSharedShaderProgramObject mpShaderProgramObject;
ConstSharedFrameBufferObject mpFrameBufferObject;
ConstSharedViewport mpViewport;
};
} // OpenGL
......
......@@ -24,16 +24,32 @@ class ShaderProgramControlAutoFiles : public Resource::FileController<ShaderProg
// ========================================================================================================= \/
public:
ShaderProgramControlAutoFiles(const std::string& _filename)
: Resource::FileController<ShaderProgram>(_filename)
: Resource::FileController<ShaderProgram>(_filename),
mAttributeLocations(),
mFragmentDataLocations()
{}
virtual ~ShaderProgramControlAutoFiles(void) {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline ShaderProgramControlAutoFiles& attributeLocation (const std::string& _attributeName) { mAttributeLocations.push_back(_attributeName); return *this; }
inline ShaderProgramControlAutoFiles& fragmentDataLocation (const std::string& _fragmentDataName) { mAttributeLocations.push_back(_fragmentDataName); return *this; }
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedShaderProgram create(void);
virtual bool update(SharedShaderProgram& shaderProgram);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
std::vector<std::string> mAttributeLocations;
std::vector<std::string> mFragmentDataLocations;
};
} // OpenGL
......
......@@ -22,6 +22,9 @@ class UniformControl : public Resource::BasicCreateController<UNIFORM>
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
UniformControl(void)
: mValue()
{}
UniformControl(const typename UNIFORM::DATA_TYPE& _value)
: mValue(_value)
{}
......
......@@ -9,7 +9,6 @@
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/State.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
......@@ -54,7 +53,6 @@ public:
virtual SharedViewport create(void)
{
SharedViewport viewport(new Viewport(mOffsetX, mOffsetY, mWidth, mHeight));
return viewport;
}
......
......@@ -29,6 +29,8 @@ typedef Resource::NameManager<FrameBufferObject> FrameBufferObjectNameManager;
typedef Resource::NameManager<RenderBuffer> RenderBufferNameManager;
typedef Resource::NameManager<RenderObject> RenderObjectNameManager;
typedef Resource::NameManager<Shader> ShaderNameManager;
typedef Resource::FileManager<Shader> ShaderFileManager;
......@@ -37,8 +39,6 @@ typedef Resource::FileManager<ShaderProgram> ShaderProgramFileManager;
typedef Resource::NameManager<ShaderProgramObject> ShaderProgramObjectNameManager;
typedef Resource::NameManager<State> StateNameManager;
typedef Resource::NameManager<Texture> TextureNameManager;
typedef Resource::FileManager<Texture> TextureFileManager;
......
......@@ -16,10 +16,10 @@
#include <ACGL/OpenGL/Objects/ElementArrayBuffer.hh>
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include <ACGL/OpenGL/Objects/RenderBuffer.hh>
#include <ACGL/OpenGL/Objects/RenderObject.hh>
#include <ACGL/OpenGL/Objects/Shader.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/Objects/ShaderProgramObject.hh>
#include <ACGL/OpenGL/Objects/State.hh>
#include <ACGL/OpenGL/Objects/Texture.hh>
#include <ACGL/OpenGL/Objects/Uniform.hh>
#include <ACGL/OpenGL/Objects/VertexBufferObject.hh>
......
......@@ -55,8 +55,8 @@ public:
struct Attachment
{
std::string name;
SharedTexture texture;
SharedRenderBuffer renderBuffer;
ConstSharedTexture texture;
ConstSharedRenderBuffer renderBuffer;
};
// ===================================================================================================== \/
......@@ -81,8 +81,8 @@ public:
return;
}
mDepthAttachment.name = "";
mDepthAttachment.texture = SharedTexture();
mDepthAttachment.renderBuffer = SharedRenderBuffer();
mDepthAttachment.texture = ConstSharedTexture();
mDepthAttachment.renderBuffer = ConstSharedRenderBuffer();
}
virtual ~FrameBufferObject(void)
......@@ -141,7 +141,7 @@ public:
return true;
}
inline bool attachColorRenderBuffer(const std::string _name, const SharedRenderBuffer& _renderBuffer)
inline bool attachColorRenderBuffer(const std::string _name, const ConstSharedRenderBuffer& _renderBuffer)
{
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + mDrawBuffers, GL_RENDERBUFFER, _renderBuffer->getContext());
if (openGLCommonErrorOccured()) {
......@@ -154,7 +154,7 @@ public:
return true;
}
inline bool attachColorTexture(const std::string _name, const SharedTexture& _texture)
inline bool attachColorTexture(const std::string _name, const ConstSharedTexture& _texture)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + mDrawBuffers, _texture->getTarget(), _texture->getContext(), 0);
if (openGLCommonErrorOccured()) {
......@@ -167,7 +167,7 @@ public:
return true;
}
inline bool setDepthRenderBuffer(const SharedRenderBuffer& _renderBuffer)
inline bool setDepthRenderBuffer(const ConstSharedRenderBuffer& _renderBuffer)
{
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _renderBuffer->getContext());
#ifdef OPENGL_ES
......@@ -183,7 +183,7 @@ public:
return true;
}
inline bool setDepthTexture(const SharedTexture& _texture)
inline bool setDepthTexture(const ConstSharedTexture& _texture)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, _texture->getTarget(), _texture->getContext(), 0);
#ifdef OPENGL_ES
......
......@@ -3,8 +3,8 @@
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_OBJECTS_STATE_HH
#define ACGL_OPENGL_OBJECTS_STATE_HH
#ifndef ACGL_OPENGL_OBJECTS_RENDEROBJECT_HH
#define ACGL_OPENGL_OBJECTS_RENDEROBJECT_HH
#include <vector>
#include <string>
......@@ -24,69 +24,58 @@
namespace ACGL{
namespace OpenGL{
class State
class RenderObject
{
ACGL_NOT_COPYABLE(State)
ACGL_NOT_COPYABLE(RenderObject)
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
private:
struct AttributeMapping
{
int_t arrayBufferID;
int_t vertexBufferObjectAttribute;
int_t shaderProgramAttributeLocation;
//! The attributeID stores the attribute index within the vbo.
int_t attributeID;
//! The attributeLocation comes from the shader
int_t attributeLocation;
};
struct FragmentDataMapping
{
int_t frameBufferObjectColorAttachment;
int_t shaderProgramFragmentDataLocation;
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
private:
typedef std::vector< AttributeMapping > AttributeMappingVec;
typedef std::vector< FragmentDataMapping > FragmentDataMappingVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
State(ConstSharedVertexBufferObject _vertexBufferObject,
RenderObject(ConstSharedVertexBufferObject _vertexBufferObject,
ConstSharedShaderProgramObject _shaderProgram,
ConstSharedFrameBufferObject _frameBufferObject,
ConstSharedViewport _viewport)
ConstSharedFrameBufferObject _frameBufferObject)
: mpVertexBufferObject(_vertexBufferObject),
mpShaderProgramObject(_shaderProgram),
mpFrameBufferObject(_frameBufferObject),
mpViewport(_viewport),
mAttributeMappings(),
mFragmentDataMappings(),
mpBuffers(NULL)
mpDrawBuffers(NULL)
{
updateMappings();
}
State(ConstSharedVertexBufferObject _vertexBufferObject,
ConstSharedShaderProgramObject _shaderProgram,
ConstSharedViewport _viewport)
RenderObject(ConstSharedVertexBufferObject _vertexBufferObject,
ConstSharedShaderProgramObject _shaderProgram)
: mpVertexBufferObject(_vertexBufferObject),
mpShaderProgramObject(_shaderProgram),
mpFrameBufferObject(),
mpViewport(_viewport),
mAttributeMappings(),
mFragmentDataMappings(),
mpBuffers(NULL)
mpDrawBuffers(NULL)
{
updateMappings();
}
virtual ~State(void)
virtual ~RenderObject(void)
{
if(mpBuffers != NULL)
delete[](mpBuffers);
if(mpDrawBuffers != NULL)
delete[](mpDrawBuffers);
}
// ==================================================================================================== \/
......@@ -96,7 +85,6 @@ public:
inline ConstSharedVertexBufferObject getVertexBufferObject (void) const { return mpVertexBufferObject; }
inline ConstSharedFrameBufferObject getFrameBufferObject (void) const { return mpFrameBufferObject; }
inline ConstSharedShaderProgramObject getShaderProgramObject (void) const { return mpShaderProgramObject; }
inline ConstSharedViewport getViewport (void) const { return mpViewport; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
......@@ -104,16 +92,21 @@ public:
public:
void updateMappings (void);
void useViewport (void) const;
void useShaderProgramObject (void) const;
void bindFrameBufferObject (void) const;
void useShaderProgramObject (void) const;
void enableVertexBufferObject (void) const;
void disableVertexBufferObject (void) const;
inline void validate (void) const
inline void enable(void) const
{
mpFrameBufferObject->validate();
mpVertexBufferObject->validate();
bindFrameBufferObject();
useShaderProgramObject();
enableVertexBufferObject();
}
inline void disable(void) const
{
disableVertexBufferObject();
}
inline void draw(void) const
......@@ -123,12 +116,15 @@ public:
inline void render(void) const
{
useViewport();
useShaderProgramObject();
bindFrameBufferObject();
enableVertexBufferObject();
enable();
draw();
disableVertexBufferObject();
disable();
}
inline void validate (void) const
{
mpFrameBufferObject->validate();
mpVertexBufferObject->validate();
}
// =================================================================================================== \/
......@@ -138,17 +134,14 @@ protected:
ConstSharedVertexBufferObject mpVertexBufferObject;
ConstSharedShaderProgramObject mpShaderProgramObject;
ConstSharedFrameBufferObject mpFrameBufferObject;
ConstSharedViewport mpViewport;
AttributeMappingVec mAttributeMappings;
FragmentDataMappingVec mFragmentDataMappings;
GLuint* mpBuffers;
GLuint* mpDrawBuffers;
};
ACGL_SHARED_TYPEDEF(State)
ACGL_SHARED_TYPEDEF(RenderObject)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_OBJECTS_STATE_HH
#endif // ACGL_OPENGL_OBJECTS_RENDEROBJECT_HH
......@@ -22,13 +22,6 @@ class Shader
{
ACGL_NOT_COPYABLE(Shader)
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector<std::string> AttributeNameVec;
typedef std::vector<std::string> FragmentDataNameVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
......@@ -53,9 +46,6 @@ public:
inline GLuint getContext (void) const { return mContext; }
inline GLenum getType (void) const { return mType; }
inline const std::vector<std::string>& getAttributeNames (void) const { return mAttributeNames; }
inline const std::vector<std::string>& getFragmentDataNames (void) const { return mFragmentDataNames; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
......@@ -72,8 +62,6 @@ protected:
protected:
GLuint mContext;
GLenum mType;
AttributeNameVec mAttributeNames;
FragmentDataNameVec mFragmentDataNames;
};
ACGL_SHARED_TYPEDEF(Shader)
......
......@@ -62,6 +62,9 @@ public:
inline GLint getAttributeLocation (const std::string& _nameInShader) const { return glGetAttribLocation (mContext, _nameInShader.c_str()); }
inline GLint getFragmentDataLocation (const std::string& _nameInShader) const { return glGetFragDataLocation(mContext, _nameInShader.c_str()); }
inline void bindAttributeLocation (const std::string& _nameInShader, GLuint _location) const { glBindAttribLocation (mContext, _location, _nameInShader.c_str()); }
inline void bindFragmentDataLocation (const std::string& _nameInShader, GLuint _location) const { glBindFragDataLocation (mContext, _location, _nameInShader.c_str()); }
inline void use(void) const { glUseProgram(mContext); }
inline void attachShader(const ConstSharedShader& _shader)
......@@ -106,9 +109,6 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
void bindAttributeLocations() const;
void bindFragmentDataLocations() const;
GLuint mContext;
ConstSharedShaderVec mShaders;
};
......
......@@ -70,6 +70,7 @@ public:
// ===================================================================================================== \/
public:
void use (void) const;
void updateUniforms (void) const;
inline void attachUniform(
const std::string& _name,
......
......@@ -67,11 +67,6 @@ public:
public:
int_t getAttributeIndexByName(const std::string& _name) const;
inline int_t getArrayBufferIDByAttributeIndex(AttributeVec::size_type _indexInArray) const
{
return mAttributes[_indexInArray].bufferID;
}
inline void setAttributePointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
{
mArrayBuffers[mAttributes[_indexInArray].bufferID]->setAttributePointer(
......
......@@ -20,6 +20,12 @@ SharedShaderProgram ShaderProgramControlAutoFiles::create(void)
shaderProgram->attachShader(shader);
if(ConstSharedShader shader = ShaderFileManager::the()->get(ShaderControlFile(mFilename + ".fsh").type(GL_FRAGMENT_SHADER)))
shaderProgram->attachShader(shader);
for (std::vector<std::string>::size_type i = 0; i < mAttributeLocations.size(); ++i)
shaderProgram->bindAttributeLocation(mAttributeLocations[i], i);
for (std::vector<std::string>::size_type i = 0; i < mFragmentDataLocations.size(); ++i)
shaderProgram->bindFragmentDataLocation(mFragmentDataLocations[i], i);
if(shaderProgram->link())
return shaderProgram;
return SharedShaderProgram();
......
......@@ -294,17 +294,17 @@ bool VertexBufferObjectControlFileOBJ::loadOBJ(SharedVertexBufferObject& _vertex
arrayBuffer->removeAttributes();
_vertexBuffer->removeAttributes();
arrayBuffer->attachAttribute("iPosition", GL_FLOAT, 4, GL_FALSE);
_vertexBuffer->attachAttribute("iPosition", 0, "iPosition");
arrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE);
_vertexBuffer->attachAttribute("aPosition", 0, "aPosition");
if(hasNormals)
{
arrayBuffer->attachAttribute("iNormal", GL_FLOAT, 3, GL_FALSE);
_vertexBuffer->attachAttribute("iNormal", 0, "iNormal");
arrayBuffer->attachAttribute("aNormal", GL_FLOAT, 3, GL_FALSE);
_vertexBuffer->attachAttribute("aNormal", 0, "aNormal");
}
if(texCoordDimension > 0)
{
arrayBuffer->attachAttribute("iTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE);
_vertexBuffer->attachAttribute("iTexCoord", 0, "iTexCoord");
arrayBuffer->attachAttribute("aTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE);
_vertexBuffer->attachAttribute("aTexCoord", 0, "aTexCoord");
}
elementArrayBuffer->setType(indexType);
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Objects/RenderObject.hh>
#include <ACGL/OpenGL/Tools.hh>
#include <ACGL/Base/StringOperations.hh>
#include <iostream>
#include <fstream>
using namespace ACGL::Base;
using namespace ACGL::Utils;
using namespace ACGL::OpenGL;
void RenderObject::updateMappings (void)
{
for(VertexBufferObject::AttributeVec::size_type i = 0; i < mpVertexBufferObject->getAttributes().size(); ++i)
{
AttributeMapping mapping = {i, mpShaderProgramObject->getShaderProgram()->getAttributeLocation(mpVertexBufferObject->getAttributes()[i].name)};
bool inserted = false;
for (AttributeMappingVec::iterator it = mAttributeMappings.begin(); it < mAttributeMappings.end() && !inserted; it++)
{
if(mpVertexBufferObject->getAttributes()[(*it).attributeID].bufferID > mpVertexBufferObject->getAttributes()[mapping.attributeID].bufferID)
{
mAttributeMappings.insert(it, mapping);
inserted = true;
}
}
if(!inserted)
mAttributeMappings.push_back(mapping);
}
if(mpFrameBufferObject)
{
mpDrawBuffers = new GLuint[mpFrameBufferObject->getColorAttachments().size()];
for(FrameBufferObject::AttachmentVec::size_type i = 0; i < mpFrameBufferObject->getColorAttachments().size(); ++i)
mpDrawBuffers[i] = GL_COLOR_ATTACHMENT0 + mpShaderProgramObject->getShaderProgram()->getFragmentDataLocation(mpFrameBufferObject->getColorAttachments()[i].name);
}
}
void RenderObject::bindFrameBufferObject (void) const
{
if(mpFrameBufferObject)
{
mpFrameBufferObject->bind();
glDrawBuffers(mpFrameBufferObject->getColorAttachments().size(), mpDrawBuffers);
}
else
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}