Commit 7eec3733 authored by Robert Menzel's avatar Robert Menzel

worked on element array buffer

parent 0c56afc7
......@@ -17,6 +17,12 @@
#include <cmath>
#include <limits>
#ifndef M_PI
// M_PI is not defined on e.g. VS2010 (isn't part of the standart), so in that case it gets defined here
// outside of the namespace because some code might expect it to be in math.h which is oviously not in our namespace...
#define M_PI 3.14159265358979323846
#endif
namespace ACGL{
namespace Math{
namespace Constants{
......
......@@ -51,15 +51,13 @@ public:
public:
virtual SharedElementArrayBuffer create(void)
{
SharedElementArrayBuffer elementArrayBuffer(new ElementArrayBuffer(
mUsage,
mMode,
mType));
SharedElementArrayBuffer elementArrayBuffer( new ElementArrayBuffer(mType) );
if(mpData != NULL)
{
elementArrayBuffer->bind();
elementArrayBuffer->setData(mpData, mElements);
//glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
GLsizeiptr bytesInBuffer = mElements / getGLTypeSize(mType);
elementArrayBuffer->setData( bytesInBuffer, mpData );
}
return elementArrayBuffer;
}
......
......@@ -128,8 +128,13 @@ private:
return value;
}
public:
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
//! not side effect free! will bind this buffer to it's last target!
//! caching of these values on RAM could be a good idea if needed very often!
//! caching of these values on RAM could be a good idea if needed very(!) often (as it's done with the size)!
//inline GLint64 getSize() { return getParameter64( GL_BUFFER_SIZE ); }
inline GLint64 getMapOffset() { return getParameter64( GL_BUFFER_MAP_OFFSET ); }
inline GLint64 getMapLength() { return getParameter64( GL_BUFFER_MAP_LENGTH ); }
......@@ -145,10 +150,6 @@ private:
inline GLint64 getSize() { return mSize; }
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
public:
//! Bind this buffer
inline void bind( GLenum _target )
{
......
......@@ -31,138 +31,17 @@
namespace ACGL{
namespace OpenGL{
class ElementArrayBuffer
class ElementArrayBuffer : public Buffer
{
ACGL_NOT_COPYABLE(ElementArrayBuffer)
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ElementArrayBuffer(
GLenum _usage = GL_STATIC_DRAW,
GLenum _mode = GL_TRIANGLES,
GLenum _type = GL_UNSIGNED_INT)
: mObjectName(0),
mUsage(_usage),
mMode(_mode),
mElements(0),
mType(_type),
mSizeOfType(getGLTypeSize(_type))
{
glGenBuffers(1, &mObjectName);
if (openGLCriticalErrorOccured() ) {
ACGL::Utils::error() << "could not generate element array buffer!" << std::endl;
}
}
virtual ~ElementArrayBuffer(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 GLenum getType (void) const { return mType; }
inline GLint getSizeOfType (void) const { return mSizeOfType; }
// ==================================================================================================== \/
// ============================================================================================ SETTERS \/
// ==================================================================================================== \/
public:
inline void setUsage (GLenum _usage) { mUsage = _usage; }
inline void setMode (GLenum _mode) { mMode = _mode; }
inline void setType (GLenum _type)
{
mType = _type;
mSizeOfType = getGLTypeSize(mType);
}
// ===================================================================================================== \/
// ============================================================================================ WRAPPERS \/
// ===================================================================================================== \/
public:
//! Bind this buffer
inline void bind(void) const
{
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mObjectName);
}
void draw(GLint _first, GLsizei _count) const
{
glDrawElements(mMode, _count, mType, reinterpret_cast<GLvoid*>(_first));
openGLRareError();
}
void draw(void) const
{
glDrawElements(mMode, mElements, mType, (GLvoid*)0);
openGLRareError();
}
//! Set data for this buffer
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_ELEMENT_ARRAY_BUFFER, mObjectName);
glBufferData(
GL_ELEMENT_ARRAY_BUFFER,
mElements * mSizeOfType,
_pData,
mUsage);
openGLRareError();
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
protected:
GLuint mObjectName;
GLenum mUsage;
GLenum mMode;
GLsizei mElements;
GLenum mType;
GLint mSizeOfType;
};
ACGL_SHARED_TYPEDEF(ElementArrayBuffer)
class ElementArrayBufferX : Buffer
{
// ========================================================================================================= \/
// ============================================================================================ CONSTRUCTORS \/
// ========================================================================================================= \/
public:
ElementArrayBufferX( GLenum _type = GL_UNSIGNED_INT)
ElementArrayBuffer( GLenum _type = GL_UNSIGNED_INT)
: Buffer(GL_ELEMENT_ARRAY_BUFFER), mType(_type)
{}
ElementArrayBufferX( SharedBufferObject _pBuffer, GLenum _type = GL_UNSIGNED_INT)
ElementArrayBuffer( SharedBufferObject _pBuffer, GLenum _type = GL_UNSIGNED_INT)
: Buffer(_pBuffer, GL_ELEMENT_ARRAY_BUFFER), mType(_type)
{}
......@@ -188,6 +67,10 @@ public:
ACGL::Utils::error() << "DON'T redefine the target binding point of an ElementArrayBuffer" << std::endl;
}
GLuint getElements() {
return getSize() / getGLTypeSize(mType);
}
// =================================================================================================== \/
// ============================================================================================ FIELDS \/
// =================================================================================================== \/
......@@ -196,10 +79,7 @@ protected:
GLenum mType;
};
ACGL_SHARED_TYPEDEF(ElementArrayBufferX)
ACGL_SHARED_TYPEDEF(ElementArrayBuffer)
} // OpenGL
......
......@@ -135,7 +135,7 @@ public:
void drawElements(void) const
{
mpElementArrayBuffer->draw();
//mpElementArrayBuffer->draw();
}
void drawArrays(void) const
......
......@@ -17,18 +17,24 @@
namespace ACGL{
namespace OpenGL{
//! returns the size in bytes of the common gl types named by there GLenums.
inline GLint getGLTypeSize ( GLenum _type )
{
switch(_type)
{
case GL_BYTE: return sizeof(GLubyte);
case GL_UNSIGNED_BYTE: return sizeof(GLbyte);
case GL_BYTE: return sizeof(GLbyte);
case GL_UNSIGNED_BYTE: return sizeof(GLubyte);
case GL_SHORT: return sizeof(GLshort);
case GL_UNSIGNED_SHORT: return sizeof(GLushort);
case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint);
case GL_FLOAT: return sizeof(GLfloat);
case GL_DOUBLE: return sizeof(GLdouble);
case GL_INT64_NV: return sizeof(GLint64);
case GL_UNSIGNED_INT64_NV: return sizeof(GLuint64);
case GL_HALF_FLOAT: return sizeof(GLhalf);
case GL_FIXED: return 4; // fixed are packed in a 32bit int (see 2.1.2 of the spec.)
}
return 0;
}
......
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