Commit a0671aea authored by Robert Menzel's avatar Robert Menzel
Browse files

REMOVED VBO - obj loading has to be reintegrated

parent bf15b688
......@@ -34,8 +34,6 @@
#include <ACGL/OpenGL/Controller/TextureControlFile.hh>
#include <ACGL/OpenGL/Controller/TextureControlFileJPG.hh>
#include <ACGL/OpenGL/Controller/UniformControl.hh>
#include <ACGL/OpenGL/Controller/VertexBufferObjectControl.hh>
#include <ACGL/OpenGL/Controller/VertexBufferObjectControlFileOBJ.hh>
#include <ACGL/OpenGL/Controller/ViewportControl.hh>
#endif // ACGL_OPENGL_CONTROLLER_HH
......@@ -23,18 +23,16 @@ class RenderObjectControl : public Resource::BasicCreateController<RenderObject>
// ========================================================================================================= \/
public:
RenderObjectControl(
const ConstSharedVertexBufferObject& _vertexBufferObject,
const ConstSharedShaderProgramObject& _shaderProgramObject)
: mpVertexBufferObject(_vertexBufferObject),
:
mpShaderProgramObject(_shaderProgramObject),
mpFrameBufferObject()
{}
RenderObjectControl(
const ConstSharedVertexBufferObject& _vertexBufferObject,
const ConstSharedShaderProgramObject& _shaderProgramObject,
const ConstSharedFrameBufferObject& _frameBufferObject)
: mpVertexBufferObject(_vertexBufferObject),
:
mpShaderProgramObject(_shaderProgramObject),
mpFrameBufferObject(_frameBufferObject)
{}
......@@ -44,7 +42,6 @@ public:
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline RenderObjectControl& vertexBufferObject (const ConstSharedVertexBufferObject& _vertexBufferObject) { mpVertexBufferObject = _vertexBufferObject; return *this; }
inline RenderObjectControl& shaderProgramObject (const ConstSharedShaderProgramObject& _shaderProgramObject) { mpShaderProgramObject = _shaderProgramObject; return *this; }
inline RenderObjectControl& frameBufferObject (const ConstSharedFrameBufferObject& _frameBufferObject) { mpFrameBufferObject = _frameBufferObject; return *this; }
......@@ -56,8 +53,6 @@ public:
{
// TODO: reimplement
//SharedRenderObject renderObject(new RenderObject(mpVertexBufferObject, mpShaderProgramObject, mpFrameBufferObject));
//return renderObject;
return SharedRenderObject();
}
......@@ -65,7 +60,6 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedVertexBufferObject mpVertexBufferObject;
ConstSharedShaderProgramObject mpShaderProgramObject;
ConstSharedFrameBufferObject mpFrameBufferObject;
};
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_VERTEXBUFFEROBJECTCONTROL_HH
#define ACGL_OPENGL_CONTROLLER_VERTEXBUFFEROBJECTCONTROL_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/BasicCreateController.hh>
#include <ACGL/OpenGL/HiLevelObjects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class VertexBufferObjectControl : public Resource::BasicCreateController<VertexBufferObject>
{
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
public:
struct AttributeDefine
{
std::string name;
int_t bufferID;
std::string attributeName;
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector< AttributeDefine > AttributeDefineVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
VertexBufferObjectControl(void)
: Resource::BasicCreateController<VertexBufferObject>(),
mpElementArrayBuffer(),
mArrayBuffers(),
mAttributeDefines(),
mpShaderProgram()
{}
virtual ~VertexBufferObjectControl() {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
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)
{
AttributeDefine a = {_name, (int_t)mArrayBuffers.size()-1, _nameInArray};
mAttributeDefines.push_back(a);
return *this;
}
inline VertexBufferObjectControl& attribute (const std::string& _name, int_t _bufferID, const std::string& _nameInArray)
{
AttributeDefine a = {_name, _bufferID, _nameInArray};
mAttributeDefines.push_back(a);
return *this;
}
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedVertexBufferObject create(void);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedElementArrayBuffer mpElementArrayBuffer;
VertexBufferObject::ConstArrayBufferVec mArrayBuffers;
AttributeDefineVec mAttributeDefines;
ConstSharedShaderProgram mpShaderProgram;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_VERTEXBUFFEROBJECTCONTROL_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_CONTROLLER_VERTEXBUFFEROBJECTCONTROLFILEOBJ_HH
#define ACGL_OPENGL_CONTROLLER_VERTEXBUFFEROBJECTCONTROLFILEOBJ_HH
#include <ACGL/ACGL.hh>
#include <ACGL/Resource/FileController.hh>
#include <ACGL/Base/Settings.hh>
#include <ACGL/OpenGL/HiLevelObjects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/ShaderProgram.hh>
#include <ACGL/OpenGL/GL.hh>
namespace ACGL{
namespace OpenGL{
class VertexBufferObjectControlFileOBJ : public Resource::FileController<VertexBufferObject>
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
VertexBufferObjectControlFileOBJ(const std::string& _filename)
: Resource::FileController<VertexBufferObject>(_filename, Base::Settings::the()->getFullGeometryPath()),
mpShaderProgram(),
mElementArrayBuffer(),
mArrayBuffer()
{}
virtual ~VertexBufferObjectControlFileOBJ() {}
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
inline VertexBufferObjectControlFileOBJ& shaderProgram (const ConstSharedShaderProgram& _shaderProgram) { mpShaderProgram = _shaderProgram; return *this; }
private:
bool loadOBJ(SharedVertexBufferObject& _vertexBuffer);
// ===================================================================================================== \/
// ============================================================================================ OVERRIDE \/
// ===================================================================================================== \/
public:
virtual SharedVertexBufferObject create(void);
virtual bool update(SharedVertexBufferObject& _vertexBuffer);
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedShaderProgram mpShaderProgram;
SharedElementArrayBuffer mElementArrayBuffer;
SharedArrayBuffer mArrayBuffer;
};
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_CONTROLLER_VERTEXBUFFEROBJECTCONTROLFILEOBJ_HH
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
#define ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
////////////////////////////////////////////////////////////////////////////////
// WARNING: broken due to refactoring of low-level objects, might get removed //
// alternative: maybe VertexBufferObjects //
////////////////////////////////////////////////////////////////////////////////
/*
* A VertexBufferObject combines the two tightly related buffers from the
* ARB_vertex_buffer_object extension.
*
* M Attributes from N ArrayBuffer and one (optional) ElementArrayBuffer form
* one VertexBufferObject.
*/
#include <ACGL/ACGL.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/GL.hh>
#include <ACGL/OpenGL/Objects/ArrayBuffer.hh>
#include <ACGL/OpenGL/Objects/ElementArrayBuffer.hh>
#include <vector>
namespace ACGL{
namespace OpenGL{
class VertexBufferObject
{
ACGL_NOT_COPYABLE(VertexBufferObject)
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
public:
struct Attribute
{
std::string name;
int_t bufferID;
int_t attributeID;
GLint indexInShader;
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector< ConstSharedArrayBuffer > ConstArrayBufferVec;
typedef std::vector< Attribute > AttributeVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
VertexBufferObject(void)
: mpElementArrayBuffer(),
mArrayBuffers(),
mAttributes()
{}
virtual ~VertexBufferObject(void) {};
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
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 \/
// ==================================================================================================== \/
public:
int_t getAttributeIndexByName(const std::string& _name) const;
inline void setAttributePointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
{
// mArrayBuffers[mAttributes[_indexInArray].bufferID]->setAttributePointer(
// mAttributes[_indexInArray].attributeID,
// _indexInShader);
}
void validate (void) const;
inline void setElementArrayBuffer(const ConstSharedElementArrayBuffer& _elementArrayBuffer)
{
mpElementArrayBuffer = _elementArrayBuffer;
}
inline void attachArrayBuffer(const ConstSharedArrayBuffer& _arrayBuffer)
{
mArrayBuffers.push_back(_arrayBuffer);
}
inline void removeArrayBuffers(void)
{
mArrayBuffers.clear();
}
inline void attachAttribute(
const std::string& _name,
int_t _bufferID,
const std::string& _attributeName,
GLint _indexInShader)
{
// Attribute attribute = {
// _name,
// _bufferID,
// mArrayBuffers[_bufferID]->getAttributeIndexByName(_attributeName),
// _indexInShader};
// mAttributes.push_back(attribute);
}
inline void removeAttributes(void)
{
mAttributes.clear();
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
public:
void enable (void) const;
void disable (void) const;
inline void render (void) const
{
enable();
draw();
disable();
}
void drawElements(void) const
{
//mpElementArrayBuffer->draw();
}
void drawArrays(void) const
{
//If no ElementArrayBuffer is specified we use the convention that
//the first ArrayBuffers determines the mode and the number of elements.
// mArrayBuffers[0]->draw();
}
void draw(void) const
{
if(mpElementArrayBuffer)
drawElements();
else
drawArrays();
openGLRareError();
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedElementArrayBuffer mpElementArrayBuffer;
ConstArrayBufferVec mArrayBuffers;
AttributeVec mAttributes;
};
ACGL_SMARTPOINTER_TYPEDEFS(VertexBufferObject)
} // OpenGL
} // ACGL
#endif // ACGL_OPENGL_OBJECTS_VERTEXBUFFEROBJECT_HH
......@@ -53,9 +53,6 @@ typedef Resource::NameManager<UniformMatrix3f> UniformMatrix3fNameManager;
typedef Resource::NameManager<UniformMatrix4f> UniformMatrix4fNameManager;
typedef Resource::NameManager<UniformTexture> UniformTextureNameManager;
typedef Resource::NameManager<VertexBufferObject> VertexBufferObjectNameManager;
typedef Resource::FileManager<VertexBufferObject> VertexBufferObjectFileManager;
typedef Resource::NameManager<Viewport> ViewportNameManager;
#if (ACGL_OPENGL_VERSION >= 30)
......
......@@ -28,7 +28,6 @@
// high-level objects (combineing multiple OpenGL objects, wrapping non-object related OpenGL funtions etc):
#include <ACGL/OpenGL/HiLevelObjects/Uniform.hh>
#include <ACGL/OpenGL/HiLevelObjects/VertexBufferObject.hh>
#include <ACGL/OpenGL/HiLevelObjects/Viewport.hh>
#include <ACGL/OpenGL/HiLevelObjects/ShaderProgramObject.hh>
#include <ACGL/OpenGL/HiLevelObjects/RenderObject.hh>
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#include <ACGL/OpenGL/Controller/VertexBufferObjectControl.hh>
using namespace ACGL::OpenGL;
SharedVertexBufferObject VertexBufferObjectControl::create(void)
{
/*
GLenum mode = GL_TRIANGLES;
GLsizei elements = 0;
if(mpElementArrayBuffer)
{
mode = mpElementArrayBuffer->getMode();
elements = mpElementArrayBuffer->getElements();
}
else if(mArrayBuffers.size() > 0 && mArrayBuffers[0])
{
mode = mArrayBuffers[0]->getMode();
elements = mArrayBuffers[0]->getElements();
}
*/
SharedVertexBufferObject vertexBuffer(new VertexBufferObject());
vertexBuffer->setElementArrayBuffer(mpElementArrayBuffer);
for(VertexBufferObject::ConstArrayBufferVec::size_type i = 0; i < mArrayBuffers.size(); i++)
{
vertexBuffer->attachArrayBuffer(mArrayBuffers[i]);
}
for(AttributeDefineVec::size_type i = 0; i < mAttributeDefines.size(); i++)
{
#if (ACGL_OPENGL_VERSION >= 30)
if(mpShaderProgram)
{
vertexBuffer->attachAttribute(
mAttributeDefines[i].name,
mAttributeDefines[i].bufferID,
mAttributeDefines[i].attributeName,
mpShaderProgram->getAttributeLocation(mAttributeDefines[i].attributeName));
}
else
#endif
{
vertexBuffer->attachAttribute(
mAttributeDefines[i].name,
mAttributeDefines[i].bufferID,
mAttributeDefines[i].attributeName,
i);
}
}
return vertexBuffer;
}
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// TODO: lots of stuff commented out here
// this code is deprecated and will shortly be removed completely
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <ACGL/OpenGL/Controller/VertexBufferObjectControlFileOBJ.hh>
#include <ACGL/OpenGL/Controller/ArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/ElementArrayBufferControl.hh>
#include <ACGL/OpenGL/Controller/VertexBufferObjectControl.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;
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(mElementArrayBuffer).
// data(mArrayBuffer).
// create();
// if(loadOBJ(vertexBuffer))
// return vertexBuffer;
return SharedVertexBufferObject();
}
bool VertexBufferObjectControlFileOBJ::update(SharedVertexBufferObject& _vertexBuffer)
{
if(fileIsUpToDate())
return false;
if(!loadOBJ(_vertexBuffer))
return false;
updateFileModificationTime();
return true;
}
bool VertexBufferObjectControlFileOBJ::loadOBJ(SharedVertexBufferObject& _vertexBuffer)
{
// std::string full = getFullFilePath();
// std::string line = "";
// std::ifstream fileStream(full.c_str(), std::ifstream::in);
// std::vector<GLfloat> sharedVertexVector;
// std::vector<GLfloat> sharedTexCoordVector;
// std::vector<GLfloat> sharedNormalVector;
// uint_t texCoordElements = 0;
// uint_t texCoordDimension = 0;
// sharedVertexVector.resize(4);
// sharedNormalVector.resize(3);
// 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, "vt"))
// {
// std::vector<std::string> elements = StringOperations::split(line, ' ');
// //The first occurence of vt gives us the number of texture coordinates per vertex.
// if(texCoordElements == 0)
// {
// texCoordElements = elements.size();
// texCoordDimension = texCoordElements - 1;
// sharedTexCoordVector.resize(texCoordDimension);
// }
// if((uint_t)elements.size() == texCoordElements)
// {
// for(uint_t i = 1; i < texCoordElements; ++i)
// sharedTexCoordVector.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 < texCoordElements; ++i)
// sharedTexCoordVector.push_back(0.0f);
// lineOK = false;
// }
// }
// else if(StringOperations::startsWith(line, "vn"))
// {
// std::vector<std::string> elements = StringOperations::split(line, ' ');
// if(elements.size() == 4)
// {
// sharedNormalVector.push_back(StringOperations::to<GLfloat>(elements[1], &elementOK));
// sharedNormalVector.push_back(StringOperations::to<GLfloat>(elements[2], &elementOK));
// sharedNormalVector.push_back(StringOperations::to<GLfloat>(elements[3], &elementOK));
// }
// else
// {
// //If a later texture coordinate is defined wrong, we enter zeros, because
// //otherwise the indices would be intermixed.
// sharedNormalVector.push_back(0.0f);
// sharedNormalVector.push_back(0.0f);
// sharedNormalVector.push_back(0.0f);
// lineOK = false;
// }
// }
// else if(StringOperations::startsWith(line, "v"))
// {