Commit 9074a852 authored by Andreas Neu's avatar Andreas Neu
Browse files

-Added member to the Attribute struct (VertexBufferObject) in order to save...

-Added member to the Attribute struct (VertexBufferObject) in order to save the index of the attribute within the shader
-VertexBufferObjectControl and VertexBufferObjectControlFileOBJ can now do the mapping based on a shaderProgram assigned to them
parent 8028d1f8
......@@ -44,7 +44,7 @@ public:
public:
inline FrameBufferObjectControl& depthTexture (const ConstSharedTexture& _pDepthTexture) { mDepthAttachment.texture = _pDepthTexture; return *this; }
inline FrameBufferObjectControl& depthRenderBuffer (const ConstSharedRenderBuffer& _pDepthRenderBuffer) { mDepthAttachment.renderBuffer = _pDepthRenderBuffer; return *this; }
inline FrameBufferObjectControl& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline FrameBufferObjectControl& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline FrameBufferObjectControl& colorTexture(const std::string& _name, const ConstSharedTexture& _texture)
{
......
......@@ -10,6 +10,7 @@
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/Objects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
......@@ -42,7 +43,8 @@ public:
: Resource::BasicCreateController<VertexBufferObject>(),
mpElementArrayBuffer(),
mArrayBuffers(),
mAttributeDefines()
mAttributeDefines(),
mpShaderProgram()
{}
virtual ~VertexBufferObjectControl() {}
......@@ -50,8 +52,10 @@ public:
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline VertexBufferObjectControl& index (const SharedElementArrayBuffer& _elementArrayBuffer) { mpElementArrayBuffer = _elementArrayBuffer; return *this; }
inline VertexBufferObjectControl& data (const SharedArrayBuffer& _vertexBuffer) { mArrayBuffers.push_back(_vertexBuffer); return *this; }
inline VertexBufferObjectControl& index (const SharedElementArrayBuffer& _elementArrayBuffer) { mpElementArrayBuffer = _elementArrayBuffer; return *this; }
inline VertexBufferObjectControl& data (const SharedArrayBuffer& _vertexBuffer) { mArrayBuffers.push_back(_vertexBuffer); return *this; }
inline VertexBufferObjectControl& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline VertexBufferObjectControl& attribute (const std::string& _name, const std::string& _nameInArray)
{
......@@ -80,6 +84,7 @@ protected:
SharedElementArrayBuffer mpElementArrayBuffer;
VertexBufferObject::ArrayBufferVec mArrayBuffers;
AttributeDefineVec mAttributeDefines;
ConstSharedShaderProgram mpShaderProgram;
};
} // OpenGL
......
......@@ -11,6 +11,7 @@
#include <ACGL/Resource/FileController.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Objects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
......@@ -23,10 +24,17 @@ class VertexBufferObjectControlFileOBJ : public Resource::FileController<VertexB
// ========================================================================================================= \/
public:
VertexBufferObjectControlFileOBJ(const std::string& _filename)
: Resource::FileController<VertexBufferObject>(_filename, Base::Settings::the()->getFullGeometryPath())
: Resource::FileController<VertexBufferObject>(_filename, Base::Settings::the()->getFullGeometryPath()),
mpShaderProgram()
{}
virtual ~VertexBufferObjectControlFileOBJ() {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline VertexBufferObjectControlFileOBJ& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
private:
bool loadOBJ(SharedVertexBufferObject& vertexBuffer);
......@@ -36,6 +44,12 @@ private:
public:
virtual SharedVertexBufferObject create(void);
virtual bool update(SharedVertexBufferObject& vertexBuffer);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedShaderProgram mpShaderProgram;
};
} // OpenGL
......
......@@ -32,6 +32,7 @@ public:
std::string name;
int_t bufferID;
int_t attributeID;
GLint indexInShader;
};
// ===================================================================================================== \/
......@@ -94,12 +95,14 @@ public:
inline void attachAttribute(
const std::string& _name,
int_t _bufferID,
const std::string& _attributeName)
const std::string& _attributeName,
GLint _indexInShader)
{
Attribute attribute = {
_name,
_bufferID,
mArrayBuffers[_bufferID]->getAttributeIndexByName(_attributeName)};
mArrayBuffers[_bufferID]->getAttributeIndexByName(_attributeName),
_indexInShader};
mAttributes.push_back(attribute);
}
......
......@@ -33,10 +33,22 @@ SharedVertexBufferObject VertexBufferObjectControl::create(void)
for(AttributeDefineVec::size_type i = 0; i < mAttributeDefines.size(); i++)
{
vertexBuffer->attachAttribute(
mAttributeDefines[i].name,
mAttributeDefines[i].bufferID,
mAttributeDefines[i].attributeName);
if(mpShaderProgram)
{
vertexBuffer->attachAttribute(
mAttributeDefines[i].name,
mAttributeDefines[i].bufferID,
mAttributeDefines[i].attributeName,
mpShaderProgram->getAttributeLocation(mAttributeDefines[i].attributeName));
}
else
{
vertexBuffer->attachAttribute(
mAttributeDefines[i].name,
mAttributeDefines[i].bufferID,
mAttributeDefines[i].attributeName,
i);
}
}
return vertexBuffer;
......
......@@ -294,27 +294,29 @@ bool VertexBufferObjectControlFileOBJ::loadOBJ(SharedVertexBufferObject& _vertex
arrayBuffer->removeAttributes();
_vertexBuffer->removeAttributes();
GLint shaderIndexPosition = (mpShaderProgram) ? mpShaderProgram->getAttributeLocation("aPosition") : 0;
GLint shaderIndexNormal = (mpShaderProgram) ? mpShaderProgram->getAttributeLocation("aNormal") : 1;
GLint shaderIndexTexCoord = (mpShaderProgram) ? mpShaderProgram->getAttributeLocation("aTexCoord") : ((hasNormals) ? 2 : 1);
arrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE);
_vertexBuffer->attachAttribute("aPosition", 0, "aPosition");
_vertexBuffer->attachAttribute("aPosition", 0, "aPosition", shaderIndexPosition);
if(hasNormals)
{
arrayBuffer->attachAttribute("aNormal", GL_FLOAT, 3, GL_FALSE);
_vertexBuffer->attachAttribute("aNormal", 0, "aNormal");
_vertexBuffer->attachAttribute("aNormal", 0, "aNormal", shaderIndexNormal);
}
if(texCoordDimension > 0)
{
arrayBuffer->attachAttribute("aTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE);
_vertexBuffer->attachAttribute("aTexCoord", 0, "aTexCoord");
_vertexBuffer->attachAttribute("aTexCoord", 0, "aTexCoord", shaderIndexTexCoord);
}
elementArrayBuffer->setType(indexType);
elementArrayBuffer->bind();
elementArrayBuffer->setData(&indexVector[0], indexVector.size());
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
arrayBuffer->bind();
arrayBuffer->setData(&interleavedDataVector[0], index);
//glBindBuffer(GL_ARRAY_BUFFER, 0);
//_vertexBuffer->setElements(indexVector.size());
return true;
}
......
......@@ -60,8 +60,8 @@ void VertexBufferObject::enable(void) const
currentBufferID = mAttributes[i].bufferID;
mArrayBuffers[currentBufferID]->bind();
}
mArrayBuffers[currentBufferID]->setAttributePointer(mAttributes[i].attributeID, i);
glEnableVertexAttribArray(i);
mArrayBuffers[currentBufferID]->setAttributePointer(mAttributes[i].attributeID, mAttributes[i].indexInShader);
glEnableVertexAttribArray(mAttributes[i].indexInShader);
openGLRareError();
}
}
......@@ -76,7 +76,7 @@ void VertexBufferObject::disable(void) const
currentBufferID = mAttributes[i].bufferID;
mArrayBuffers[currentBufferID]->bind();
}
glDisableVertexAttribArray(i);
glDisableVertexAttribArray(mAttributes[i].indexInShader);
openGLRareError();
}
}
Supports Markdown
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