Commit 01b1bda6 authored by Andreas Neu's avatar Andreas Neu
Browse files

Besides the attributes, the shader now processes the fragmentdata in order to automatically

call glBindFragData(...).
The RenderTargets of a FBO can now be named.
Furthermore every occurence of 'aPosition' has been changed to 'iPosition' etc. for aColor, aNormal..
parent 19cf2b44
...@@ -44,15 +44,15 @@ public: ...@@ -44,15 +44,15 @@ public:
inline FrameBufferControl& depthTexture (const SharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; } inline FrameBufferControl& depthTexture (const SharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; }
inline FrameBufferControl& depthRenderBuffer (const SharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; 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); mColorAttachments.push_back(attachment);
return *this; 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); mColorAttachments.push_back(attachment);
return *this; return *this;
} }
......
...@@ -27,6 +27,7 @@ class Shader ...@@ -27,6 +27,7 @@ class Shader
// ===================================================================================================== \/ // ===================================================================================================== \/
public: public:
typedef std::vector<std::string> AttributeVec; typedef std::vector<std::string> AttributeVec;
typedef std::vector<std::string> FragmentDataVec;
// ========================================================================================================= \/ // ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/ // ============================================================================================ CONSTRUCTORS \/
...@@ -53,7 +54,7 @@ public: ...@@ -53,7 +54,7 @@ public:
inline GLenum getType (void) const { return mType; } inline GLenum getType (void) const { return mType; }
inline const std::vector<std::string>& getAttributes() const { return mAttributes; } inline const std::vector<std::string>& getAttributes() const { return mAttributes; }
inline const std::vector<std::string>& getFragmentData() const { return mFragmentData; }
// ==================================================================================================== \/ // ==================================================================================================== \/
// ============================================================================================ METHODS \/ // ============================================================================================ METHODS \/
// ==================================================================================================== \/ // ==================================================================================================== \/
...@@ -71,6 +72,7 @@ protected: ...@@ -71,6 +72,7 @@ protected:
GLuint mContext; GLuint mContext;
GLenum mType; GLenum mType;
AttributeVec mAttributes; AttributeVec mAttributes;
FragmentDataVec mFragmentData;
}; };
ACGL_SHARED_TYPEDEF(Shader) ACGL_SHARED_TYPEDEF(Shader)
......
...@@ -111,6 +111,7 @@ public: ...@@ -111,6 +111,7 @@ public:
// =================================================================================================== \/ // =================================================================================================== \/
protected: protected:
void bindAttributeLocations() const; void bindAttributeLocations() const;
void bindFragmentDataLocations() const;
GLuint mContext; GLuint mContext;
ConstSharedShaderVec mShaders; ConstSharedShaderVec mShaders;
......
...@@ -19,9 +19,11 @@ SharedFrameBuffer FrameBufferControl::create(void) ...@@ -19,9 +19,11 @@ SharedFrameBuffer FrameBufferControl::create(void)
else if(mColorAttachments[i].renderBuffer) else if(mColorAttachments[i].renderBuffer)
frameBuffer->attachColorRenderBuffer(mColorAttachments[i].renderBuffer); frameBuffer->attachColorRenderBuffer(mColorAttachments[i].renderBuffer);
} }
if(mDepthAttachment.texture) if(mDepthAttachment.texture)
frameBuffer->setDepthTexture(mDepthAttachment.texture); frameBuffer->setDepthTexture(mDepthAttachment.texture);
else if(mDepthAttachment.renderBuffer) else if(mDepthAttachment.renderBuffer)
frameBuffer->setDepthRenderBuffer(mDepthAttachment.renderBuffer); frameBuffer->setDepthRenderBuffer(mDepthAttachment.renderBuffer);
return frameBuffer; return frameBuffer;
} }
...@@ -294,17 +294,17 @@ bool VertexBufferControlFileOBJ::loadOBJ(SharedVertexBuffer& _vertexBuffer) ...@@ -294,17 +294,17 @@ bool VertexBufferControlFileOBJ::loadOBJ(SharedVertexBuffer& _vertexBuffer)
arrayBuffer->removeAttributes(); arrayBuffer->removeAttributes();
_vertexBuffer->removeAttributes(); _vertexBuffer->removeAttributes();
arrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE); arrayBuffer->attachAttribute("iPosition", GL_FLOAT, 4, GL_FALSE);
_vertexBuffer->attachAttribute("aPosition", 0, "aPosition"); _vertexBuffer->attachAttribute("iPosition", 0, "iPosition");
if(hasNormals) if(hasNormals)
{ {
arrayBuffer->attachAttribute("aNormal", GL_FLOAT, 3, GL_FALSE); arrayBuffer->attachAttribute("iNormal", GL_FLOAT, 3, GL_FALSE);
_vertexBuffer->attachAttribute("aNormal", 0, "aNormal"); _vertexBuffer->attachAttribute("iNormal", 0, "iNormal");
} }
if(texCoordDimension > 0) if(texCoordDimension > 0)
{ {
arrayBuffer->attachAttribute("aTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE); arrayBuffer->attachAttribute("iTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE);
_vertexBuffer->attachAttribute("aTexCoord", 0, "aTexCoord"); _vertexBuffer->attachAttribute("iTexCoord", 0, "iTexCoord");
} }
elementArrayBuffer->setType(indexType); elementArrayBuffer->setType(indexType);
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <tr1/regex>
using namespace ACGL::Base; using namespace ACGL::Base;
using namespace ACGL::Utils; using namespace ACGL::Utils;
using namespace ACGL::OpenGL; using namespace ACGL::OpenGL;
...@@ -48,16 +50,35 @@ bool Shader::setSource(const std::string& _source) ...@@ -48,16 +50,35 @@ bool Shader::setSource(const std::string& _source)
while (stream.good()) while (stream.good())
{ {
std::getline(stream,line); std::getline(stream, line, ' ');
if(StringOperations::startsWith(line, "attribute"))
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(StringOperations::startsWith(line, "out"))
if(tokens.size() > 2)
{ {
std::vector<std::string> tokensOfToken = StringOperations::split(tokens[2], ';'); std::vector<std::string> tokens = StringOperations::split(line, ' ');
if(tokensOfToken.size() > 0) 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]);
}
} }
} }
} }
......
...@@ -22,9 +22,22 @@ void ShaderProgram::bindAttributeLocations() const ...@@ -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 bool ShaderProgram::link(void) const
{ {
bindAttributeLocations(); bindAttributeLocations();
bindFragmentDataLocations();
glLinkProgram(mContext); glLinkProgram(mContext);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment