Commit e07f05dd authored by Robert Menzel's avatar Robert Menzel
parents 0f1ceeed 9f9aaee6
cmake @ f93d27f5
Subproject commit 15115c56e314569265d0ca4bba3fad1993c2777f
Subproject commit f93d27f5a7420ec6b3c1974eeb6e30bc9b97801d
......@@ -90,6 +90,21 @@ public:
}
};
class Sin : public EaseFunction
{
public:
Sin(float _frequency = 1.0f) :
mFrequency(_frequency) { }
virtual ~Sin(){}
virtual float value(const float _progress)
{
return sin(0.5f*M_PI*mFrequency*_progress);
}
float mFrequency;
};
class BlendLinear : public EaseFunction
{
public:
......
......@@ -78,7 +78,7 @@ public:
inline const T interpolate(const float _progress)
{
return mStartValue + _progress*mDiffValue;
return mStartValue + mDiffValue*_progress;
}
inline const T& finish()
......
......@@ -19,6 +19,7 @@
#include <ACGL/Resource/FileManager.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControlFileATB.hh>
#include <ACGL/OpenGL/Controller/ElementArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/FrameBufferObjectControl.hh>
#include <ACGL/OpenGL/Controller/RenderBufferControl.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROLFILEATB_HH
#define ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROLFILEATB_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class ArrayBufferControlFileATB : public Resource::FileController<ArrayBuffer>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ArrayBufferControlFileATB(const std::string& _filename)
: Resource::FileController<ArrayBuffer>(_filename, Base::Settings::the()->getFullGeometryPath()),
mpShaderProgram()
{}
virtual ~ArrayBufferControlFileATB() {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline ArrayBufferControlFileATB& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
private:
bool loadATB(SharedArrayBuffer& _arrayBuffer);
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedArrayBuffer create(void);
virtual bool update(SharedArrayBuffer& _arrayBuffer);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedShaderProgram mpShaderProgram;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_ARRAYBUFFERCONTROLFILEATB_HH
......@@ -52,10 +52,9 @@ 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& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline VertexBufferObjectControl& index (const ConstSharedElementArrayBuffer& _elementArrayBuffer) { mpElementArrayBuffer = _elementArrayBuffer; return *this; }
inline VertexBufferObjectControl& data (const ConstSharedArrayBuffer& _arrayBuffer) { mArrayBuffers.push_back(_arrayBuffer); return *this; }
inline VertexBufferObjectControl& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
inline VertexBufferObjectControl& attribute (const std::string& _name, const std::string& _nameInArray)
{
......@@ -81,10 +80,10 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
SharedElementArrayBuffer mpElementArrayBuffer;
VertexBufferObject::ArrayBufferVec mArrayBuffers;
AttributeDefineVec mAttributeDefines;
ConstSharedShaderProgram mpShaderProgram;
ConstSharedElementArrayBuffer mpElementArrayBuffer;
VertexBufferObject::ConstArrayBufferVec mArrayBuffers;
AttributeDefineVec mAttributeDefines;
ConstSharedShaderProgram mpShaderProgram;
};
} // OpenGL
......
......@@ -25,7 +25,9 @@ class VertexBufferObjectControlFileOBJ : public Resource::FileController<VertexB
public:
VertexBufferObjectControlFileOBJ(const std::string& _filename)
: Resource::FileController<VertexBufferObject>(_filename, Base::Settings::the()->getFullGeometryPath()),
mpShaderProgram()
mpShaderProgram(),
mElementArrayBuffer(),
mArrayBuffer()
{}
virtual ~VertexBufferObjectControlFileOBJ() {}
......@@ -36,20 +38,22 @@ public:
inline VertexBufferObjectControlFileOBJ& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
private:
bool loadOBJ(SharedVertexBufferObject& vertexBuffer);
bool loadOBJ(SharedVertexBufferObject& _vertexBuffer);
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedVertexBufferObject create(void);
virtual bool update(SharedVertexBufferObject& vertexBuffer);
virtual bool update(SharedVertexBufferObject& _vertexBuffer);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedShaderProgram mpShaderProgram;
SharedElementArrayBuffer mElementArrayBuffer;
SharedArrayBuffer mArrayBuffer;
};
} // OpenGL
......
......@@ -22,6 +22,7 @@ namespace ACGL{
namespace OpenGL{
typedef Resource::NameManager<ArrayBuffer> ArrayBufferNameManager;
typedef Resource::FileManager<ArrayBuffer> ArrayBufferFileManager;
typedef Resource::NameManager<ElementArrayBuffer> ElementArrayBufferNameManager;
......
......@@ -47,7 +47,7 @@ public:
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector< SharedArrayBuffer > ArrayBufferVec;
typedef std::vector< ConstSharedArrayBuffer > ConstArrayBufferVec;
typedef std::vector< Attribute > AttributeVec;
// ========================================================================================================= \/
......@@ -66,9 +66,9 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline const SharedElementArrayBuffer& getElementArrayBuffer (void) const { return mpElementArrayBuffer; }
inline const ArrayBufferVec& getArrayBuffers (void) const { return mArrayBuffers; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; }
inline const ConstSharedElementArrayBuffer& getElementArrayBuffer (void) const { return mpElementArrayBuffer; }
inline const ConstArrayBufferVec& getArrayBuffers (void) const { return mArrayBuffers; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
......@@ -85,12 +85,12 @@ public:
void validate (void) const;
inline void setElementArrayBuffer(const SharedElementArrayBuffer& _elementArrayBuffer)
inline void setElementArrayBuffer(const ConstSharedElementArrayBuffer& _elementArrayBuffer)
{
mpElementArrayBuffer = _elementArrayBuffer;
}
inline void attachArrayBuffer(const SharedArrayBuffer& _arrayBuffer)
inline void attachArrayBuffer(const ConstSharedArrayBuffer& _arrayBuffer)
{
mArrayBuffers.push_back(_arrayBuffer);
}
......@@ -159,9 +159,9 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
SharedElementArrayBuffer mpElementArrayBuffer;
ArrayBufferVec mArrayBuffers;
AttributeVec mAttributes;
ConstSharedElementArrayBuffer mpElementArrayBuffer;
ConstArrayBufferVec mArrayBuffers;
AttributeVec mAttributes;
};
ACGL_SHARED_TYPEDEF(VertexBufferObject)
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/ArrayBufferControlFileATB.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/ElementArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControl.hh>
#include <ACGL/Base/StringOperations.hh>
#include <vector>
#include <iostream>
#include <fstream>
using namespace ACGL;
using namespace ACGL::Base;
using namespace ACGL::Utils;
using namespace ACGL::OpenGL;
SharedArrayBuffer ArrayBufferControlFileATB::create(void)
{
updateFileModificationTime();
SharedArrayBuffer arrayBuffer = ArrayBufferControl().
mode(GL_TRIANGLES).
usage(GL_STATIC_DRAW).
create();
if(loadATB(arrayBuffer))
return arrayBuffer;
return SharedArrayBuffer();
}
bool ArrayBufferControlFileATB::update(SharedArrayBuffer& _arrayBuffer)
{
if(fileIsUpToDate())
return false;
if(!loadATB(_arrayBuffer))
return false;
updateFileModificationTime();
return true;
}
bool ArrayBufferControlFileATB::loadATB(SharedArrayBuffer& _arrayBuffer)
{
std::string full = getFullFilePath();
std::string line = "";
std::ifstream fileStream(full.c_str(), std::ifstream::in);
std::vector<GLfloat> sharedAttributeVector;
uint_t attributeElements = 0;
uint_t attributeDimension = 0;
bool elementOK = true;
bool lineOK = true;
uint_t lineNumber = 0;
if(fileStream.is_open())
{
//Read the first line
if(fileStream.good())
std::getline(fileStream, line);
while(fileStream.good())
{
if(StringOperations::startsWith(line, "a"))
{
std::vector<std::string> elements = StringOperations::split(line, ' ');
//The first occurence of vt gives us the number of texture coordinates per vertex.
if(attributeElements == 0)
{
attributeElements = elements.size();
attributeDimension = attributeElements - 1;
sharedAttributeVector.resize(attributeDimension);
}
if((uint_t)elements.size() == attributeElements)
{
for(uint_t i = 1; i < attributeElements; ++i)
sharedAttributeVector.push_back(StringOperations::to<GLfloat>(elements[i], &elementOK));
}
else
{
//If a later texture coordinate is defined wrong, we enter zeros, because
//otherwise the indices would be intermixed.
for(uint_t i = 1; i < attributeElements; ++i)
sharedAttributeVector.push_back(0.0f);
lineOK = false;
}
}
else if(StringOperations::startsWith(line, "f"))
{
//As soon as the first f occurs, we assume that all vertex
//positions, normals and tex coords have been defined!
break;
}
if(!lineOK)
{
warning() << "Format of line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
lineOK = true;
}
if(!elementOK)
{
warning() << "Element in line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
elementOK = true;
}
++lineNumber;
getline(fileStream, line);
}
std::vector<GLfloat> dataVector;
uint_t index = 0;
while(fileStream.good())
{
if(StringOperations::startsWith(line, "f"))
{
std::vector<std::string> elements = StringOperations::split(line, ' ');
uint_t uiPolygonSize = elements.size() - 1;
if(uiPolygonSize > 2)
{
for(size_t i = 1; i < elements.size(); ++i)
{
index++;
uint_t sharedIndex = StringOperations::to<uint_t>(elements[i], &elementOK);
for(uint_t i = 0; i < attributeDimension; ++i)
dataVector.push_back(sharedAttributeVector[attributeDimension * sharedIndex + i]);
}
}
else
{
lineOK = false;
}
}
if(!lineOK)
{
warning() << "Format of line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
lineOK = true;
}
if(!elementOK)
{
warning() << "Element in line " << lineNumber << " is wrong!" << std::endl;
debug() << line << std::endl;
elementOK = true;
}
++lineNumber;
getline(fileStream, line);
}
fileStream.close();
_arrayBuffer->removeAttributes();
_arrayBuffer->attachAttribute("aAttribute", GL_FLOAT, attributeDimension, GL_FALSE);
_arrayBuffer->bind();
_arrayBuffer->setData(&dataVector[0], index);
return true;
}
error() << "Failed to open file: " << getFullFilePath() << std::endl;
return false;
}
......@@ -28,7 +28,7 @@ SharedVertexBufferObject VertexBufferObjectControl::create(void)
vertexBuffer->setElementArrayBuffer(mpElementArrayBuffer);
for(VertexBufferObject::ArrayBufferVec::size_type i = 0; i < mArrayBuffers.size(); i++)
for(VertexBufferObject::ConstArrayBufferVec::size_type i = 0; i < mArrayBuffers.size(); i++)
{
vertexBuffer->attachArrayBuffer(mArrayBuffers[i]);
}
......
......@@ -22,15 +22,17 @@ SharedVertexBufferObject VertexBufferObjectControlFileOBJ::create(void)
{
updateFileModificationTime();
mElementArrayBuffer = ElementArrayBufferControl().
mode(GL_TRIANGLES).
usage(GL_STATIC_DRAW).
create();
mArrayBuffer = ArrayBufferControl().
mode(GL_TRIANGLES).
usage(GL_STATIC_DRAW).
create();
SharedVertexBufferObject vertexBuffer = VertexBufferObjectControl().
index(ElementArrayBufferControl().
mode(GL_TRIANGLES).
usage(GL_STATIC_DRAW).
create()).
data(ArrayBufferControl().
mode(GL_TRIANGLES).
usage(GL_STATIC_DRAW).
create()).
index(mElementArrayBuffer).
data(mArrayBuffer).
create();
if(loadOBJ(vertexBuffer))
......@@ -39,12 +41,12 @@ SharedVertexBufferObject VertexBufferObjectControlFileOBJ::create(void)
return SharedVertexBufferObject();
}
bool VertexBufferObjectControlFileOBJ::update(SharedVertexBufferObject& vertexBuffer)
bool VertexBufferObjectControlFileOBJ::update(SharedVertexBufferObject& _vertexBuffer)
{
if(fileIsUpToDate())
return false;
if(!loadOBJ(vertexBuffer))
if(!loadOBJ(_vertexBuffer))
return false;
updateFileModificationTime();
......@@ -288,10 +290,7 @@ bool VertexBufferObjectControlFileOBJ::loadOBJ(SharedVertexBufferObject& _vertex
fileStream.close();
SharedElementArrayBuffer elementArrayBuffer = _vertexBuffer->getElementArrayBuffer();
SharedArrayBuffer arrayBuffer = _vertexBuffer->getArrayBuffers()[0];
arrayBuffer->removeAttributes();
mArrayBuffer->removeAttributes();
_vertexBuffer->removeAttributes();
#if (ACGL_OPENGL_VERSION >= 30)
......@@ -303,25 +302,25 @@ bool VertexBufferObjectControlFileOBJ::loadOBJ(SharedVertexBufferObject& _vertex
GLint shaderIndexNormal = 1;
GLint shaderIndexTexCoord = ((hasNormals) ? 2 : 1);
#endif
arrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE);
mArrayBuffer->attachAttribute("aPosition", GL_FLOAT, 4, GL_FALSE);
_vertexBuffer->attachAttribute("aPosition", 0, "aPosition", shaderIndexPosition);
if(hasNormals)
{
arrayBuffer->attachAttribute("aNormal", GL_FLOAT, 3, GL_FALSE);
mArrayBuffer->attachAttribute("aNormal", GL_FLOAT, 3, GL_FALSE);
_vertexBuffer->attachAttribute("aNormal", 0, "aNormal", shaderIndexNormal);
}
if(texCoordDimension > 0)
{
arrayBuffer->attachAttribute("aTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE);
mArrayBuffer->attachAttribute("aTexCoord", GL_FLOAT, texCoordDimension, GL_FALSE);
_vertexBuffer->attachAttribute("aTexCoord", 0, "aTexCoord", shaderIndexTexCoord);
}
elementArrayBuffer->setType(indexType);
elementArrayBuffer->bind();
elementArrayBuffer->setData(&indexVector[0], indexVector.size());
mElementArrayBuffer->setType(indexType);
mElementArrayBuffer->bind();
mElementArrayBuffer->setData(&indexVector[0], indexVector.size());
arrayBuffer->bind();
arrayBuffer->setData(&interleavedDataVector[0], index);
mArrayBuffer->bind();
mArrayBuffer->setData(&interleavedDataVector[0], index);
return true;
}
......
......@@ -80,7 +80,7 @@ void RenderObject::enableVertexBufferObject (void) const
mpVertexBufferObject->getArrayBuffers()[mpVertexBufferObject->getAttributes()[mAttributeMappings[i].attributeID].bufferID]->bind();
currentArrayBufferID = mpVertexBufferObject->getAttributes()[mAttributeMappings[i].attributeID].bufferID;
}
mpVertexBufferObject->setAttributePointer(mpVertexBufferObject->getAttributes()[mAttributeMappings[i].attributeID].attributeID, mAttributeMappings[i].attributeLocation);
mpVertexBufferObject->setAttributePointer(mAttributeMappings[i].attributeID, mAttributeMappings[i].attributeLocation);
glEnableVertexAttribArray(mAttributeMappings[i].attributeLocation);
openGLRareError();
}
......
......@@ -37,7 +37,7 @@ void VertexBufferObject::validate(void) const
return;
}
for(ArrayBufferVec::size_type k = 0; k < mArrayBuffers.size(); k++)
for(ConstArrayBufferVec::size_type k = 0; k < mArrayBuffers.size(); k++)
{
if(mArrayBuffers[k]->getMode() != mode)
Utils::error() << "VertexBufferObject validation failed: ArrayBuffer "<< k << " has different mode."<< std::endl;
......
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