Commit 8e1fe5d7 authored by Maciej Suminski's avatar Maciej Suminski

Changed data structure in VBO_ITEM.

parent e9ebdf25
...@@ -83,19 +83,19 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex ) ...@@ -83,19 +83,19 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex )
vertex = *m_transform * vertex; vertex = *m_transform * vertex;
// Replace only coordinates, leave color as it is // Replace only coordinates, leave color as it is
memcpy( &m_vertPtr->struc.coord, &vertex[0], CoordByteSize ); memcpy( &m_vertPtr->x, &vertex[0], CoordByteSize );
} }
else else
{ {
// Add the new vertex // Add the new vertex
memcpy( &m_vertPtr->struc.coord, aVertex, CoordByteSize ); memcpy( &m_vertPtr->x, aVertex, CoordByteSize );
} }
// Apply currently used color // Apply currently used color
memcpy( &m_vertPtr->struc.color, m_color, ColorByteSize ); memcpy( &m_vertPtr->r, m_color, ColorByteSize );
// Apply currently used shader // Apply currently used shader
memcpy( &m_vertPtr->struc.shader, m_shader, ShaderByteSize ); memcpy( &m_vertPtr->shader, m_shader, ShaderByteSize );
// Move to the next free space // Move to the next free space
m_vertPtr++; m_vertPtr++;
...@@ -206,19 +206,6 @@ void VBO_ITEM::UseShader( const GLfloat* aShader ) ...@@ -206,19 +206,6 @@ void VBO_ITEM::UseShader( const GLfloat* aShader )
} }
/*
// TODO
void SetVbo( int aVboId )
{
}
int GetVbo() const
{
}
*/
void VBO_ITEM::useNewBlock() void VBO_ITEM::useNewBlock()
{ {
VBO_VERTEX* newVertBlock = new VBO_VERTEX[BLOCK_SIZE]; VBO_VERTEX* newVertBlock = new VBO_VERTEX[BLOCK_SIZE];
......
...@@ -40,25 +40,13 @@ ...@@ -40,25 +40,13 @@
namespace KiGfx namespace KiGfx
{ {
typedef struct VBO_VERTEX_DATA typedef struct VBO_VERTEX
{ {
GLfloat x, y, z; // Coordinates GLfloat x, y, z; // Coordinates
GLfloat r, g, b, a; // Color GLfloat r, g, b, a; // Color
GLfloat shader[4]; // Shader type & params GLfloat shader[4]; // Shader type & params
} VBO_VERTEX_DATA; } VBO_VERTEX_DATA;
typedef struct VBO_VERTEX_STRUCT
{
GLfloat coord[3]; // Coordinates
GLfloat color[4]; // Color
GLfloat shader[4]; // Shader type & params
} VBO_VERTEX_STRUCT;
typedef union VBO_VERTEX
{
VBO_VERTEX_DATA data;
VBO_VERTEX_STRUCT struc;
} VBO_VERTEX;
class VBO_ITEM class VBO_ITEM
{ {
...@@ -159,34 +147,33 @@ public: ...@@ -159,34 +147,33 @@ public:
static const int VertByteSize = sizeof(VBO_VERTEX); static const int VertByteSize = sizeof(VBO_VERTEX);
static const int VertStride = VertByteSize / sizeof(GLfloat); static const int VertStride = VertByteSize / sizeof(GLfloat);
static const int CoordStride = sizeof(VBO_VERTEX_STRUCT().coord) / sizeof(GLfloat); static const int CoordByteSize = sizeof(VBO_VERTEX().x) + sizeof(VBO_VERTEX().y) +
static const int CoordByteSize = sizeof(VBO_VERTEX_STRUCT().coord); sizeof(VBO_VERTEX().z);
static const int CoordStride = CoordByteSize / sizeof(GLfloat);
// Offset of color data from the beginning of each vertex data // Offset of color data from the beginning of each vertex data
static const int ColorByteOffset = offsetof( VBO_VERTEX_STRUCT, color ); static const int ColorByteOffset = offsetof(VBO_VERTEX, r);
static const int ColorOffset = ColorByteOffset / sizeof(GLfloat); static const int ColorOffset = ColorByteOffset / sizeof(GLfloat);
static const int ColorStride = sizeof(VBO_VERTEX_STRUCT().color) / sizeof(GLfloat); static const int ColorByteSize = sizeof(VBO_VERTEX().r) + sizeof(VBO_VERTEX().g) +
static const int ColorByteSize = sizeof(VBO_VERTEX_STRUCT().color); sizeof(VBO_VERTEX().b) + sizeof(VBO_VERTEX().a);
static const int ColorStride = ColorByteSize / sizeof(GLfloat);
// Shader attributes // Shader attributes
static const int ShaderByteOffset = offsetof( VBO_VERTEX_STRUCT, shader ); static const int ShaderByteOffset = offsetof(VBO_VERTEX, shader);
static const int ShaderOffset = ShaderByteOffset / sizeof(GLfloat); static const int ShaderOffset = ShaderByteOffset / sizeof(GLfloat);
static const int ShaderStride = sizeof(VBO_VERTEX_STRUCT().shader) / sizeof(GLfloat); static const int ShaderByteSize = sizeof(VBO_VERTEX().shader);
static const int ShaderByteSize = sizeof(VBO_VERTEX_STRUCT().shader); static const int ShaderStride = ShaderByteSize / sizeof(GLfloat);
static const int IndStride = 1; static const int IndStride = 1;
static const int IndByteSize = IndStride * sizeof(GLuint); static const int IndByteSize = IndStride * sizeof(GLuint);
private: private:
///< VBO ids in which the item is stored.
//int m_vboId; // not used yet
///< Contains vertices coordinates and colors. ///< Contains vertices coordinates and colors.
///< Packed by 7 floats for each vertex: {X, Y, Z, R, G, B, A} ///< Packed by 7 floats for each vertex: {X, Y, Z, R, G, B, A}
GLfloat* m_vertices; GLfloat* m_vertices;
///< Indices of vertices ///< Indices of vertices
GLuint* m_indices; GLuint* m_indices;
///< Lists of data blocks storing vertices ///< Lists of data blocks storing vertices
std::list<VBO_VERTEX*> m_vertBlocks; std::list<VBO_VERTEX*> m_vertBlocks;
...@@ -204,20 +191,20 @@ private: ...@@ -204,20 +191,20 @@ private:
void prepareFinal(); void prepareFinal();
///< Offset and size of data in VBO. ///< Offset and size of data in VBO.
int m_offset; int m_offset;
int m_size; int m_size;
///< Color used for new vertices pushed. ///< Color used for new vertices pushed.
GLfloat m_color[ColorStride]; GLfloat m_color[ColorStride];
///< Shader and its parameters used for new vertices pushed ///< Shader and its parameters used for new vertices pushed
GLfloat m_shader[ShaderStride]; GLfloat m_shader[ShaderStride];
///< Flag telling if the item should be recached in VBO or not. ///< Flag telling if the item should be recached in VBO or not.
bool m_isDirty; bool m_isDirty;
///< Current transform matrix for every new vertex pushed. ///< Current transform matrix applied for every new vertex pushed.
const glm::mat4* m_transform; const glm::mat4* m_transform;
}; };
} // namespace KiGfx } // namespace KiGfx
......
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