Commit 69098a81 authored by Robert Menzel's avatar Robert Menzel

some cleanups

parent 7d19183e
......@@ -38,200 +38,6 @@
namespace ACGL{
namespace OpenGL{
/*
class ArrayBuffer
{
ACGL_NOT_COPYABLE(ArrayBuffer)
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
public:
//! Each attribute has a dimension (#components, e.g. normal with x/y/z => 3) and an offset in the stride (in bytes)
struct Attribute
{
std::string name;
GLenum type;
GLint dimension;
GLint offset;
GLboolean normalized;
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
public:
typedef std::vector< Attribute > AttributeVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ArrayBuffer(
GLenum _usage = GL_STATIC_DRAW,
GLenum _mode = GL_TRIANGLES)
: mObjectName(0),
mUsage(_usage),
mMode(_mode),
mElements(0),
mStride(0),
mAttributes()
{
glGenBuffers(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate array buffer!" << std::endl;
}
}
virtual ~ArrayBuffer(void)
{
// buffer 0 will get ignored by OpenGL
glDeleteBuffers(1, &mObjectName);
}
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline GLuint operator() (void) const { return mObjectName; }
inline GLuint getObjectName (void) const { return mObjectName; }
inline GLenum getUsage (void) const { return mUsage; }
inline GLenum getMode (void) const { return mMode; }
inline GLsizei getElements (void) const { return mElements; }
inline GLsizei getStride (void) const { return mStride; }
inline const AttributeVec& getAttributes (void) const { return mAttributes; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
int_t getAttributeIndexByName(const std::string& _nameInArray) const;
inline void attachAttribute(
const std::string& _name,
GLenum _type,
GLint _dimension,
GLboolean _normalized = GL_FALSE)
{
Attribute attribute = {
_name,
_type,
_dimension,
mStride,
_normalized};
mStride += getGLTypeSize(_type) * _dimension;
mAttributes.push_back(attribute);
}
inline void removeAttributes(void)
{
mStride = 0;
mAttributes.clear();
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
public:
void render(void) const;
void draw(void) const
{
glDrawArrays(mMode, 0, mElements);
openGLRareError();
}
void draw(GLint _first, GLsizei _count) const
{
glDrawArrays(mMode, _first, _count);
openGLRareError();
}
//! Bind this buffer
inline void bind(void) const
{
glBindBuffer(GL_ARRAY_BUFFER, mObjectName);
openGLRareError();
}
inline void setAttributePointer(AttributeVec::size_type _indexInArray, GLuint _indexInShader) const
{
glVertexAttribPointer(
_indexInShader,
mAttributes[_indexInArray].dimension,
mAttributes[_indexInArray].type,
mAttributes[_indexInArray].normalized,
mStride,
reinterpret_cast<GLvoid*>(mAttributes[_indexInArray].offset));
openGLRareError();
}
inline bool setAttributePointer(const std::string& _nameInArray, GLuint _indexInShader) const
{
int_t index = getAttributeIndexByName(_nameInArray);
if(index == -1)
return false;
setAttributePointer(index, _indexInShader);
return true;
}
//! Set data for this buffer and change its size, usage and mode
inline void setData(
const GLvoid* _pData,
GLsizei _elements,
GLenum _usage,
GLenum _mode)
{
mUsage = _usage;
mMode = _mode;
setData( _pData, _elements );
}
//! Set data for this buffer and change its size
inline void setData(
const GLvoid* _pData,
GLsizei _elements)
{
mElements = _elements;
setData( _pData );
}
//! Set data for this buffer
//! Note: The function is not const, because it changes the corresponding GPU data
inline void setData(const GLvoid* _pData)
{
glBindBuffer(GL_ARRAY_BUFFER, mObjectName);
glBufferData(
GL_ARRAY_BUFFER,
mStride * mElements,
_pData,
mUsage);
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
GLuint mObjectName;
GLenum mUsage;
GLenum mMode;
GLsizei mElements;
GLsizei mStride;
AttributeVec mAttributes;
};
ACGL_SHARED_TYPEDEF(ArrayBuffer)
*/
class ArrayBuffer : public Buffer
{
// ==================================================================================================== \/
......@@ -388,7 +194,6 @@ public:
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
//GLsizei mElements;
GLsizei mStride;
AttributeVec mAttributes;
};
......@@ -396,8 +201,6 @@ protected:
ACGL_SHARED_TYPEDEF(ArrayBuffer)
} // OpenGL
} // ACGL
......
......@@ -31,143 +31,6 @@
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include <ACGL/OpenGL/Objects/Viewport.hh>
/*
#include <vector>
#include <string>
#include <iostream>
#include <ACGL/Base/Macros.hh>
#include <ACGL/OpenGL/Objects/VertexBufferObject.hh>
#include <ACGL/OpenGL/Objects/FrameBufferObject.hh>
#include <ACGL/OpenGL/Objects/ShaderProgramObject.hh>
#include <ACGL/OpenGL/Objects/Viewport.hh>
namespace ACGL{
namespace OpenGL{
class RenderObject
{
ACGL_NOT_COPYABLE(RenderObject)
// ==================================================================================================== \/
// ============================================================================================ STRUCTS \/
// ==================================================================================================== \/
private:
struct AttributeMapping
{
//! The attributeID stores the attribute index within the vbo.
int_t attributeID;
//! The attributeLocation comes from the shader
int_t attributeLocation;
};
// ===================================================================================================== \/
// ============================================================================================ TYPEDEFS \/
// ===================================================================================================== \/
private:
typedef std::vector< AttributeMapping > AttributeMappingVec;
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
RenderObject(ConstSharedVertexBufferObject _vertexBufferObject,
ConstSharedShaderProgramObject _shaderProgram,
ConstSharedFrameBufferObject _frameBufferObject)
: mpVertexBufferObject(_vertexBufferObject),
mpShaderProgramObject(_shaderProgram),
mpFrameBufferObject(_frameBufferObject),
mAttributeMappings(),
mpDrawBuffers(NULL)
{
updateMappings();
}
RenderObject(ConstSharedVertexBufferObject _vertexBufferObject,
ConstSharedShaderProgramObject _shaderProgram)
: mpVertexBufferObject(_vertexBufferObject),
mpShaderProgramObject(_shaderProgram),
mpFrameBufferObject(),
mAttributeMappings(),
mpDrawBuffers(NULL)
{
updateMappings();
}
virtual ~RenderObject(void)
{
delete[](mpDrawBuffers);
}
// ==================================================================================================== \/
// ============================================================================================ GETTERS \/
// ==================================================================================================== \/
public:
inline ConstSharedVertexBufferObject getVertexBufferObject (void) const { return mpVertexBufferObject; }
inline ConstSharedFrameBufferObject getFrameBufferObject (void) const { return mpFrameBufferObject; }
inline ConstSharedShaderProgramObject getShaderProgramObject (void) const { return mpShaderProgramObject; }
// ==================================================================================================== \/
// ============================================================================================ METHODS \/
// ==================================================================================================== \/
public:
void updateMappings (void);
void bindFrameBufferObject (void) const;
void useShaderProgramObject (void) const;
void enableVertexBufferObject (void) const;
void disableVertexBufferObject (void) const;
inline void enable(void) const
{
bindFrameBufferObject();
useShaderProgramObject();
enableVertexBufferObject();
}
inline void disable(void) const
{
disableVertexBufferObject();
}
inline void draw(void) const
{
mpVertexBufferObject->draw();
}
inline void render(void) const
{
enable();
draw();
disable();
}
inline void validate (void) const
{
mpFrameBufferObject->validate();
mpVertexBufferObject->validate();
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
ConstSharedVertexBufferObject mpVertexBufferObject;
ConstSharedShaderProgramObject mpShaderProgramObject;
ConstSharedFrameBufferObject mpFrameBufferObject;
AttributeMappingVec mAttributeMappings;
GLuint* mpDrawBuffers;
};
ACGL_SHARED_TYPEDEF(RenderObject)
} // OpenGL
} // ACGL
*/
namespace ACGL {
namespace OpenGL {
......
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