Commit d9ad3dcc authored by Lars Krecklau's avatar Lars Krecklau
Browse files

-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