Changed data structure in VBO_ITEM.
This commit is contained in:
parent
e9ebdf2583
commit
8e1fe5d766
|
@ -83,19 +83,19 @@ void VBO_ITEM::PushVertex( const GLfloat* aVertex )
|
|||
vertex = *m_transform * vertex;
|
||||
|
||||
// Replace only coordinates, leave color as it is
|
||||
memcpy( &m_vertPtr->struc.coord, &vertex[0], CoordByteSize );
|
||||
memcpy( &m_vertPtr->x, &vertex[0], CoordByteSize );
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add the new vertex
|
||||
memcpy( &m_vertPtr->struc.coord, aVertex, CoordByteSize );
|
||||
memcpy( &m_vertPtr->x, aVertex, CoordByteSize );
|
||||
}
|
||||
|
||||
// Apply currently used color
|
||||
memcpy( &m_vertPtr->struc.color, m_color, ColorByteSize );
|
||||
memcpy( &m_vertPtr->r, m_color, ColorByteSize );
|
||||
|
||||
// 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
|
||||
m_vertPtr++;
|
||||
|
@ -206,19 +206,6 @@ void VBO_ITEM::UseShader( const GLfloat* aShader )
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
// TODO
|
||||
void SetVbo( int aVboId )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
int GetVbo() const
|
||||
{
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
void VBO_ITEM::useNewBlock()
|
||||
{
|
||||
VBO_VERTEX* newVertBlock = new VBO_VERTEX[BLOCK_SIZE];
|
||||
|
|
|
@ -40,25 +40,13 @@
|
|||
|
||||
namespace KiGfx
|
||||
{
|
||||
typedef struct VBO_VERTEX_DATA
|
||||
typedef struct VBO_VERTEX
|
||||
{
|
||||
GLfloat x, y, z; // Coordinates
|
||||
GLfloat r, g, b, a; // Color
|
||||
GLfloat shader[4]; // Shader type & params
|
||||
} 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
|
||||
{
|
||||
|
@ -159,34 +147,33 @@ public:
|
|||
static const int VertByteSize = sizeof(VBO_VERTEX);
|
||||
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_STRUCT().coord);
|
||||
static const int CoordByteSize = sizeof(VBO_VERTEX().x) + sizeof(VBO_VERTEX().y) +
|
||||
sizeof(VBO_VERTEX().z);
|
||||
static const int CoordStride = CoordByteSize / sizeof(GLfloat);
|
||||
|
||||
// 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 ColorStride = sizeof(VBO_VERTEX_STRUCT().color) / sizeof(GLfloat);
|
||||
static const int ColorByteSize = sizeof(VBO_VERTEX_STRUCT().color);
|
||||
static const int ColorByteSize = sizeof(VBO_VERTEX().r) + sizeof(VBO_VERTEX().g) +
|
||||
sizeof(VBO_VERTEX().b) + sizeof(VBO_VERTEX().a);
|
||||
static const int ColorStride = ColorByteSize / sizeof(GLfloat);
|
||||
|
||||
// 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 ShaderStride = sizeof(VBO_VERTEX_STRUCT().shader) / sizeof(GLfloat);
|
||||
static const int ShaderByteSize = sizeof(VBO_VERTEX_STRUCT().shader);
|
||||
static const int ShaderByteSize = sizeof(VBO_VERTEX().shader);
|
||||
static const int ShaderStride = ShaderByteSize / sizeof(GLfloat);
|
||||
|
||||
static const int IndStride = 1;
|
||||
static const int IndByteSize = IndStride * sizeof(GLuint);
|
||||
|
||||
private:
|
||||
///< VBO ids in which the item is stored.
|
||||
//int m_vboId; // not used yet
|
||||
|
||||
///< Contains vertices coordinates and colors.
|
||||
///< Packed by 7 floats for each vertex: {X, Y, Z, R, G, B, A}
|
||||
GLfloat* m_vertices;
|
||||
GLfloat* m_vertices;
|
||||
|
||||
///< Indices of vertices
|
||||
GLuint* m_indices;
|
||||
GLuint* m_indices;
|
||||
|
||||
///< Lists of data blocks storing vertices
|
||||
std::list<VBO_VERTEX*> m_vertBlocks;
|
||||
|
@ -204,20 +191,20 @@ private:
|
|||
void prepareFinal();
|
||||
|
||||
///< Offset and size of data in VBO.
|
||||
int m_offset;
|
||||
int m_size;
|
||||
int m_offset;
|
||||
int m_size;
|
||||
|
||||
///< Color used for new vertices pushed.
|
||||
GLfloat m_color[ColorStride];
|
||||
GLfloat m_color[ColorStride];
|
||||
|
||||
///< 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.
|
||||
bool m_isDirty;
|
||||
bool m_isDirty;
|
||||
|
||||
///< Current transform matrix for every new vertex pushed.
|
||||
const glm::mat4* m_transform;
|
||||
///< Current transform matrix applied for every new vertex pushed.
|
||||
const glm::mat4* m_transform;
|
||||
};
|
||||
} // namespace KiGfx
|
||||
|
||||
|
|
Loading…
Reference in New Issue