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:
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;
}
......
......@@ -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)
......
......@@ -111,6 +111,7 @@ public:
// =================================================================================================== \/
protected:
void bindAttributeLocations() const;
void bindFragmentDataLocations() const;
GLuint mContext;
ConstSharedShaderVec mShaders;
......
......@@ -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;
}
......@@ -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);
......
......@@ -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]);
}
}
}
}
......
......@@ -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);
......
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