diff --git a/include/ACGL/OpenGL/Controller/FrameBufferControl.hh b/include/ACGL/OpenGL/Controller/FrameBufferControl.hh index e7285e5b27a6b9c812ed2c1ff8c98e91874ed263..9459b0c28a4443abb048d910a8be867478a2d19a 100644 --- a/include/ACGL/OpenGL/Controller/FrameBufferControl.hh +++ b/include/ACGL/OpenGL/Controller/FrameBufferControl.hh @@ -44,15 +44,15 @@ public: inline FrameBufferControl& depthTexture (const SharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; } inline FrameBufferControl& depthRenderBuffer (const SharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; return *this; } - inline FrameBufferControl& colorTexture(const SharedTexture& _texture) + inline FrameBufferControl& colorTexture(const std::string& name, const SharedTexture& _texture) { - FrameBuffer::Attachment attachment = {"", _texture, SharedRenderBuffer()}; + FrameBuffer::Attachment attachment = {name, _texture, SharedRenderBuffer()}; mColorAttachments.push_back(attachment); return *this; } - inline FrameBufferControl& colorRenderBuffer(const SharedRenderBuffer& _renderBuffer) + inline FrameBufferControl& colorRenderBuffer(const std::string& name, const SharedRenderBuffer& _renderBuffer) { - FrameBuffer::Attachment attachment = {"", SharedTexture(), _renderBuffer}; + FrameBuffer::Attachment attachment = {name, SharedTexture(), _renderBuffer}; mColorAttachments.push_back(attachment); return *this; } diff --git a/include/ACGL/OpenGL/Objects/Shader.hh b/include/ACGL/OpenGL/Objects/Shader.hh index 0fb4644d41353e3808b1f2ef49f36d7c744810a8..a81f82c52f1bcb2629594973190eb30c4442258f 100644 --- a/include/ACGL/OpenGL/Objects/Shader.hh +++ b/include/ACGL/OpenGL/Objects/Shader.hh @@ -27,6 +27,7 @@ class Shader // ===================================================================================================== \/ public: typedef std::vector<std::string> AttributeVec; + typedef std::vector<std::string> FragmentDataVec; // ========================================================================================================= \/ // ============================================================================================ CONSTRUCTORS \/ @@ -53,7 +54,7 @@ public: inline GLenum getType (void) const { return mType; } inline const std::vector<std::string>& getAttributes() const { return mAttributes; } - + inline const std::vector<std::string>& getFragmentData() const { return mFragmentData; } // ==================================================================================================== \/ // ============================================================================================ METHODS \/ // ==================================================================================================== \/ @@ -71,6 +72,7 @@ protected: GLuint mContext; GLenum mType; AttributeVec mAttributes; + FragmentDataVec mFragmentData; }; ACGL_SHARED_TYPEDEF(Shader) diff --git a/include/ACGL/OpenGL/Objects/ShaderProgram.hh b/include/ACGL/OpenGL/Objects/ShaderProgram.hh index f11ef049ea55d22e7fcbd79773b7ffdf8c89c57a..8673605dabd89f25fe89a2df0c90f70fdf893b7c 100644 --- a/include/ACGL/OpenGL/Objects/ShaderProgram.hh +++ b/include/ACGL/OpenGL/Objects/ShaderProgram.hh @@ -111,6 +111,7 @@ public: // =================================================================================================== \/ protected: void bindAttributeLocations() const; + void bindFragmentDataLocations() const; GLuint mContext; ConstSharedShaderVec mShaders; diff --git a/src/ACGL/OpenGL/Controller/FrameBufferControl.cc b/src/ACGL/OpenGL/Controller/FrameBufferControl.cc index 75988156e9dc3201874b3456ca7b813bf4336f5b..11f754b1a807f5ba083bb91aacbba1d385954d9b 100644 --- a/src/ACGL/OpenGL/Controller/FrameBufferControl.cc +++ b/src/ACGL/OpenGL/Controller/FrameBufferControl.cc @@ -19,9 +19,11 @@ SharedFrameBuffer FrameBufferControl::create(void) else if(mColorAttachments[i].renderBuffer) frameBuffer->attachColorRenderBuffer(mColorAttachments[i].renderBuffer); } + if(mDepthAttachment.texture) frameBuffer->setDepthTexture(mDepthAttachment.texture); else if(mDepthAttachment.renderBuffer) frameBuffer->setDepthRenderBuffer(mDepthAttachment.renderBuffer); + return frameBuffer; } diff --git a/src/ACGL/OpenGL/Controller/VertexBufferControlFileOBJ.cc b/src/ACGL/OpenGL/Controller/VertexBufferControlFileOBJ.cc index 28283042b70dcf81ebfc7fc3462edd05c1e0b7a2..6ddd0f5d1eced5710fbf95e3f25693f85767d15b 100644 --- a/src/ACGL/OpenGL/Controller/VertexBufferControlFileOBJ.cc +++ b/src/ACGL/OpenGL/Controller/VertexBufferControlFileOBJ.cc @@ -294,17 +294,17 @@ bool VertexBufferControlFileOBJ::loadOBJ(SharedVertexBuffer& _vertexBuffer) arrayBuffer->removeAttributes(); _vertexBuffer->removeAttributes(); - arrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE); - _vertexBuffer->attachAttribute("aPosition", 0, "aPosition"); + arrayBuffer->attachAttribute("iPosition", GL_FLOAT, 4, GL_FALSE); + _vertexBuffer->attachAttribute("iPosition", 0, "iPosition"); if(hasNormals) { - arrayBuffer->attachAttribute("aNormal", GL_FLOAT, 3, GL_FALSE); - _vertexBuffer->attachAttribute("aNormal", 0, "aNormal"); + arrayBuffer->attachAttribute("iNormal", GL_FLOAT, 3, GL_FALSE); + _vertexBuffer->attachAttribute("iNormal", 0, "iNormal"); } if(texCoordDimension > 0) { - arrayBuffer->attachAttribute("aTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE); - _vertexBuffer->attachAttribute("aTexCoord", 0, "aTexCoord"); + arrayBuffer->attachAttribute("iTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE); + _vertexBuffer->attachAttribute("iTexCoord", 0, "iTexCoord"); } elementArrayBuffer->setType(indexType); diff --git a/src/ACGL/OpenGL/Objects/Shader.cc b/src/ACGL/OpenGL/Objects/Shader.cc index 0e545fa579dd66a9c10b69b1e31d8af7a6918bb7..546ab79b80672fbcb33ddef5067be6dc1f62c9a5 100644 --- a/src/ACGL/OpenGL/Objects/Shader.cc +++ b/src/ACGL/OpenGL/Objects/Shader.cc @@ -10,6 +10,8 @@ #include <iostream> #include <fstream> +#include <tr1/regex> + using namespace ACGL::Base; using namespace ACGL::Utils; using namespace ACGL::OpenGL; @@ -48,16 +50,35 @@ bool Shader::setSource(const std::string& _source) while (stream.good()) { - std::getline(stream,line); - if(StringOperations::startsWith(line, "attribute")) + std::getline(stream, line, ' '); + + if(this->mType == GL_VERTEX_SHADER) + { + if(StringOperations::startsWith(line, "in")) + { + std::vector<std::string> tokens = StringOperations::split(line, ' '); + if(tokens.size() > 2) + { + std::vector<std::string> tokensOfToken = StringOperations::split(tokens[2], ';'); + if(tokensOfToken.size() > 0) + { + mAttributes.push_back(tokensOfToken[0]); + } + } + } + } + else if(this->mType == GL_FRAGMENT_SHADER) { - std::vector<std::string> tokens = StringOperations::split(line, ' '); - if(tokens.size() > 2) + if(StringOperations::startsWith(line, "out")) { - std::vector<std::string> tokensOfToken = StringOperations::split(tokens[2], ';'); - if(tokensOfToken.size() > 0) + std::vector<std::string> tokens = StringOperations::split(line, ' '); + if(tokens.size() > 2) { - mAttributes.push_back(tokensOfToken[0]); + std::vector<std::string> tokensOfToken = StringOperations::split(tokens[2], ';'); + if(tokensOfToken.size() > 0) + { + mFragmentData.push_back(tokensOfToken[0]); + } } } } diff --git a/src/ACGL/OpenGL/Objects/ShaderProgram.cc b/src/ACGL/OpenGL/Objects/ShaderProgram.cc index 5c5668ba29e074ff1ecec6f88cfa6e6c564ea182..6775b5b12e96fdc2ea03c6176a4745d67703aedd 100644 --- a/src/ACGL/OpenGL/Objects/ShaderProgram.cc +++ b/src/ACGL/OpenGL/Objects/ShaderProgram.cc @@ -22,9 +22,22 @@ void ShaderProgram::bindAttributeLocations() const } } +void ShaderProgram::bindFragmentDataLocations() const +{ + for (ConstSharedShaderVec::size_type i = 0; i < mShaders.size(); ++i) + { + const Shader::FragmentDataVec& fragData = mShaders[i]->getFragmentData(); + for (Shader::FragmentDataVec::size_type k = 0; k < fragData.size(); ++k) + { + glBindFragDataLocation(mContext, k, fragData[k].c_str()); + } + } +} + bool ShaderProgram::link(void) const { bindAttributeLocations(); + bindFragmentDataLocations(); glLinkProgram(mContext);