Moved fields containing information about currently used color, shader and transformation for vertices from VBO_ITEM to VBO_CONTAINER (OPENGL_GAL).
This commit is contained in:
parent
4de43d7c5f
commit
83f5bd60c1
|
@ -1543,7 +1543,7 @@ void OPENGL_GAL::Save()
|
|||
if( isGrouping )
|
||||
{
|
||||
transformStack.push( transform );
|
||||
curVboItem->SetTransformMatrix( &transform );
|
||||
vboContainer->SetTransformMatrix( &transform );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1562,7 +1562,7 @@ void OPENGL_GAL::Restore()
|
|||
if( transformStack.empty() )
|
||||
{
|
||||
// Disable transforming, as the selected matrix is identity
|
||||
curVboItem->SetTransformMatrix( NULL );
|
||||
vboContainer->SetTransformMatrix( NULL );
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
*/
|
||||
|
||||
#include <gal/opengl/vbo_container.h>
|
||||
#include <gal/opengl/vbo_item.h>
|
||||
#include <cstring>
|
||||
#include <wx/log.h>
|
||||
#ifdef __WXDEBUG__
|
||||
|
@ -40,8 +39,11 @@
|
|||
using namespace KiGfx;
|
||||
|
||||
VBO_CONTAINER::VBO_CONTAINER( int aSize ) :
|
||||
m_freeSpace( aSize ), m_currentSize( aSize ), itemStarted( false )
|
||||
m_freeSpace( aSize ), m_currentSize( aSize ), itemStarted( false ), m_transform( NULL )
|
||||
{
|
||||
// By default no shader is used
|
||||
m_shader[0] = 0;
|
||||
|
||||
m_vertices = new VBO_VERTEX[aSize];
|
||||
|
||||
// In the beginning there is only free space
|
||||
|
@ -88,6 +90,7 @@ void VBO_CONTAINER::EndItem()
|
|||
void VBO_CONTAINER::Add( VBO_ITEM* aVboItem, const VBO_VERTEX* aVertex, unsigned int aSize )
|
||||
{
|
||||
unsigned int offset;
|
||||
VBO_VERTEX* vertexPtr;
|
||||
|
||||
if( itemStarted ) // There is an item being created with an unknown size..
|
||||
{
|
||||
|
@ -146,7 +149,44 @@ void VBO_CONTAINER::Add( VBO_ITEM* aVboItem, const VBO_VERTEX* aVertex, unsigned
|
|||
offset = getChunkOffset( *it ) + itemSize;
|
||||
}
|
||||
|
||||
memcpy( &m_vertices[offset], aVertex, aSize * VBO_ITEM::VertByteSize );
|
||||
for( unsigned int i = 0; i < aSize; ++i )
|
||||
{
|
||||
// Pointer to the vertex that we are currently adding
|
||||
vertexPtr = &m_vertices[offset + i];
|
||||
|
||||
// Modify the vertex according to the currently used transformations
|
||||
if( m_transform != NULL )
|
||||
{
|
||||
// Apply transformations
|
||||
glm::vec4 vertex( aVertex[i].x, aVertex[i].y, aVertex[i].z, 1.0f );
|
||||
vertex = *m_transform * vertex;
|
||||
|
||||
// Replace only coordinates, leave color as it is
|
||||
vertexPtr->x = vertex.x;
|
||||
vertexPtr->y = vertex.y;
|
||||
vertexPtr->z = vertex.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Simply copy coordinates
|
||||
vertexPtr->x = aVertex[i].x;
|
||||
vertexPtr->y = aVertex[i].y;
|
||||
vertexPtr->z = aVertex[i].z;
|
||||
}
|
||||
|
||||
// Apply currently used color
|
||||
vertexPtr->r = m_color[0];
|
||||
vertexPtr->g = m_color[1];
|
||||
vertexPtr->b = m_color[2];
|
||||
vertexPtr->a = m_color[3];
|
||||
|
||||
// Apply currently used shader
|
||||
for( unsigned int i = 0; i < VBO_ITEM::ShaderStride; ++i )
|
||||
{
|
||||
vertexPtr->shader[i] = m_shader[i];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,12 +37,8 @@ VBO_ITEM::VBO_ITEM( VBO_CONTAINER* aContainer ) :
|
|||
m_offset( 0 ),
|
||||
m_size( 0 ),
|
||||
m_container( aContainer ),
|
||||
m_isDirty( true ),
|
||||
m_transform( NULL )
|
||||
m_isDirty( true )
|
||||
{
|
||||
// By default no shader is used
|
||||
m_shader[0] = 0;
|
||||
|
||||
// The item's size is not known yet, so we just start an item in the container
|
||||
aContainer->StartItem( this );
|
||||
}
|
||||
|
@ -54,32 +50,8 @@ VBO_ITEM::~VBO_ITEM()
|
|||
}
|
||||
|
||||
|
||||
void VBO_ITEM::PushVertex( VBO_VERTEX* aVertex )
|
||||
void VBO_ITEM::PushVertex( const VBO_VERTEX* aVertex )
|
||||
{
|
||||
if( m_transform != NULL )
|
||||
{
|
||||
// Apply transformations
|
||||
glm::vec4 vertex( aVertex->x, aVertex->y, aVertex->z, 1.0f );
|
||||
vertex = *m_transform * vertex;
|
||||
|
||||
// Replace only coordinates, leave color as it is
|
||||
aVertex->x = vertex.x;
|
||||
aVertex->y = vertex.y;
|
||||
aVertex->z = vertex.z;
|
||||
}
|
||||
|
||||
// Apply currently used color
|
||||
aVertex->r = m_color[0];
|
||||
aVertex->g = m_color[1];
|
||||
aVertex->b = m_color[2];
|
||||
aVertex->a = m_color[3];
|
||||
|
||||
// Apply currently used shader
|
||||
for( int i = 0; i < ShaderStride; ++i )
|
||||
{
|
||||
aVertex->shader[i] = m_shader[i];
|
||||
}
|
||||
|
||||
m_container->Add( this, aVertex );
|
||||
|
||||
m_size++;
|
||||
|
@ -87,7 +59,7 @@ void VBO_ITEM::PushVertex( VBO_VERTEX* aVertex )
|
|||
}
|
||||
|
||||
|
||||
void VBO_ITEM::PushVertices( VBO_VERTEX* aVertices, GLuint aSize )
|
||||
void VBO_ITEM::PushVertices( const VBO_VERTEX* aVertices, GLuint aSize )
|
||||
{
|
||||
for( unsigned int i = 0; i < aSize; ++i )
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#define GLM_FORCE_RADIANS
|
||||
#include <gal/opengl/glm/gtc/matrix_transform.hpp>
|
||||
|
||||
#include <gal/opengl/vbo_item.h>
|
||||
#include <gal/opengl/vbo_container.h>
|
||||
#include <gal/opengl/shader.h>
|
||||
|
||||
// wxWidgets imports
|
||||
|
@ -58,7 +58,6 @@
|
|||
namespace KiGfx
|
||||
{
|
||||
class SHADER;
|
||||
class VBO_CONTAINER;
|
||||
|
||||
/**
|
||||
* @brief Class OpenGL_GAL is the OpenGL implementation of the Graphics Abstraction Layer.
|
||||
|
@ -601,7 +600,7 @@ private:
|
|||
{
|
||||
if( isGrouping )
|
||||
{
|
||||
curVboItem->UseColor( COLOR4D( aRed, aGreen, aBlue, aAlpha ) );
|
||||
vboContainer->UseColor( aRed, aGreen, aBlue, aAlpha );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -620,7 +619,7 @@ private:
|
|||
{
|
||||
if( isGrouping )
|
||||
{
|
||||
curVboItem->UseColor( aColor );
|
||||
vboContainer->UseColor( aColor );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -642,7 +641,7 @@ private:
|
|||
{
|
||||
const GLfloat shader[] = { aShader, aParam1, aParam2, aParam3 };
|
||||
|
||||
curVboItem->UseShader( shader );
|
||||
vboContainer->UseShader( shader );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
#define VBO_CONTAINER_H_
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <gal/opengl/glm/glm.hpp>
|
||||
#include <gal/opengl/vbo_item.h>
|
||||
#include <gal/color4d.h>
|
||||
#include <map>
|
||||
#include <wx/log.h>
|
||||
|
||||
|
@ -118,6 +121,73 @@ public:
|
|||
return m_currentSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetTransformMatrix()
|
||||
* Sets transformation matrix for vertices that are added to VBO_ITEM. If you do not want to
|
||||
* transform vertices at all, pass NULL as the argument.
|
||||
* @param aMatrix is the new transform matrix or NULL if you do not want to use transformation
|
||||
* matrix.
|
||||
*/
|
||||
inline void SetTransformMatrix( const glm::mat4* aMatrix )
|
||||
{
|
||||
m_transform = aMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function UseColor()
|
||||
* Sets color used for all added vertices.
|
||||
* @param aColor is the color used for added vertices.
|
||||
*/
|
||||
inline void UseColor( const COLOR4D& aColor )
|
||||
{
|
||||
m_color[0] = aColor.r;
|
||||
m_color[1] = aColor.g;
|
||||
m_color[2] = aColor.b;
|
||||
m_color[3] = aColor.a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function UseColor()
|
||||
* Sets color used for all added vertices.
|
||||
* @param aColor is the color used for added vertices.
|
||||
*/
|
||||
inline void UseColor( const GLfloat aColor[VBO_ITEM::ColorStride] )
|
||||
{
|
||||
for( unsigned int i = 0; i < VBO_ITEM::ColorStride; ++i )
|
||||
{
|
||||
m_color[i] = aColor[i];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function UseColor()
|
||||
* Sets color used for all added vertices.
|
||||
* @param aR is the red component of the color.
|
||||
* @param aG is the green component of the color.
|
||||
* @param aB is the blue component of the color.
|
||||
* @param aA is the alpha component of the color.
|
||||
*/
|
||||
inline void UseColor( GLfloat aR, GLfloat aG, GLfloat aB, GLfloat aA )
|
||||
{
|
||||
m_color[0] = aR;
|
||||
m_color[1] = aG;
|
||||
m_color[2] = aB;
|
||||
m_color[3] = aA;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function UseShader()
|
||||
* Sets shader and its parameters used for all added vertices.
|
||||
* @param aShader is the array that contains shader number followed by its parameters.
|
||||
*/
|
||||
inline void UseShader( const GLfloat aShader[VBO_ITEM::ShaderStride] )
|
||||
{
|
||||
for( unsigned int i = 0; i < VBO_ITEM::ShaderStride; ++i )
|
||||
{
|
||||
m_shader[i] = aShader[i];
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
///< Stores size & offset of free chunks.
|
||||
FreeChunkMap m_freeChunks;
|
||||
|
@ -221,27 +291,37 @@ private:
|
|||
void free( const ReservedChunkMap::iterator& aChunk );
|
||||
|
||||
///< How many vertices we can store in the container
|
||||
unsigned int m_freeSpace;
|
||||
unsigned int m_freeSpace;
|
||||
|
||||
///< How big is the current container, expressed in vertices
|
||||
unsigned int m_currentSize;
|
||||
unsigned int m_currentSize;
|
||||
|
||||
///< Actual storage memory
|
||||
VBO_VERTEX* m_vertices;
|
||||
VBO_VERTEX* m_vertices;
|
||||
|
||||
///< A flag saying if there is the item with an unknown size being added
|
||||
bool itemStarted;
|
||||
bool itemStarted;
|
||||
|
||||
///< Variables holding the state of the item currently being added
|
||||
unsigned int itemSize, itemChunkSize;
|
||||
VBO_ITEM* item;
|
||||
unsigned int itemSize;
|
||||
unsigned int itemChunkSize;
|
||||
VBO_ITEM* item;
|
||||
|
||||
///< Color used for new vertices pushed.
|
||||
GLfloat m_color[VBO_ITEM::ColorStride];
|
||||
|
||||
///< Shader and its parameters used for new vertices pushed
|
||||
GLfloat m_shader[VBO_ITEM::ShaderStride];
|
||||
|
||||
///< Current transform matrix applied for every new vertex pushed.
|
||||
const glm::mat4* m_transform;
|
||||
|
||||
/**
|
||||
* Function getPowerOf2()
|
||||
* Returns the nearest power of 2, bigger than aNumber.
|
||||
* @param aNumber is the number for which we look for a bigger power of 2.
|
||||
*/
|
||||
unsigned int getPowerOf2( unsigned int aNumber )
|
||||
unsigned int getPowerOf2( unsigned int aNumber ) const
|
||||
{
|
||||
unsigned int power = 1;
|
||||
|
||||
|
|
|
@ -31,9 +31,7 @@
|
|||
#define VBO_ITEM_H_
|
||||
|
||||
#include <GL/gl.h>
|
||||
#include <gal/opengl/glm/glm.hpp>
|
||||
#include <gal/color4d.h>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace KiGfx
|
||||
|
@ -61,7 +59,7 @@ public:
|
|||
* @param aVertex is a vertex to be added.
|
||||
* @param aShader is an attribute for shader.
|
||||
*/
|
||||
void PushVertex( VBO_VERTEX* aVertex );
|
||||
void PushVertex( const VBO_VERTEX* aVertex );
|
||||
|
||||
/**
|
||||
* Function PushVertices()
|
||||
|
@ -72,7 +70,7 @@ public:
|
|||
* @param aSize is an amount of vertices to be added.
|
||||
* @param aShader is an attribute for shader.
|
||||
*/
|
||||
void PushVertices( VBO_VERTEX* aVertices, GLuint aSize );
|
||||
void PushVertices( const VBO_VERTEX* aVertices, GLuint aSize );
|
||||
|
||||
/**
|
||||
* Function GetVertices()
|
||||
|
@ -97,7 +95,7 @@ public:
|
|||
* Sets data offset in the VBO.
|
||||
* @param aOffset is the offset expressed as a number of vertices.
|
||||
*/
|
||||
void SetOffset( unsigned int aOffset )
|
||||
inline void SetOffset( unsigned int aOffset )
|
||||
{
|
||||
m_offset = aOffset;
|
||||
}
|
||||
|
@ -112,18 +110,6 @@ public:
|
|||
return m_offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function SetTransformMatrix()
|
||||
* Sets transformation matrix for vertices that are added to VBO_ITEM. If you do not want to
|
||||
* transform vertices at all, pass NULL as the argument.
|
||||
* @param aMatrix is the new transform matrix or NULL if you do not want to use transformation
|
||||
* matrix.
|
||||
*/
|
||||
void SetTransformMatrix( const glm::mat4* aMatrix )
|
||||
{
|
||||
m_transform = aMatrix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function ChangeColor()
|
||||
* Colors all vertices to the specified color.
|
||||
|
@ -131,77 +117,42 @@ public:
|
|||
*/
|
||||
void ChangeColor( const COLOR4D& aColor );
|
||||
|
||||
/**
|
||||
* Function UseColor()
|
||||
* Sets color used for all added vertices.
|
||||
* @param aColor is the color used for added vertices.
|
||||
*/
|
||||
void UseColor( const COLOR4D& aColor )
|
||||
{
|
||||
m_color[0] = aColor.r;
|
||||
m_color[1] = aColor.g;
|
||||
m_color[2] = aColor.b;
|
||||
m_color[3] = aColor.a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function UseShader()
|
||||
* Sets shader and its parameters used for all added vertices.
|
||||
* @param aShader is the array that contains shader number followed by its parameters.
|
||||
*/
|
||||
inline void UseShader( const GLfloat* aShader )
|
||||
{
|
||||
for( int i = 0; i < ShaderStride; ++i )
|
||||
{
|
||||
m_shader[i] = aShader[i];
|
||||
}
|
||||
}
|
||||
|
||||
///< Informs the container that there will be no more vertices for the current VBO_ITEM
|
||||
void Finish();
|
||||
|
||||
///< Data organization information for vertices {X,Y,Z,R,G,B,A} (@see VBO_VERTEX).
|
||||
static const int VertByteSize = sizeof(VBO_VERTEX);
|
||||
static const int VertStride = VertByteSize / sizeof(GLfloat);
|
||||
static const unsigned int VertByteSize = sizeof(VBO_VERTEX);
|
||||
static const unsigned int VertStride = VertByteSize / sizeof(GLfloat);
|
||||
|
||||
static const int CoordByteSize = sizeof(VBO_VERTEX().x) + sizeof(VBO_VERTEX().y) +
|
||||
sizeof(VBO_VERTEX().z);
|
||||
static const int CoordStride = CoordByteSize / sizeof(GLfloat);
|
||||
static const unsigned int CoordByteSize = sizeof(VBO_VERTEX().x) + sizeof(VBO_VERTEX().y) +
|
||||
sizeof(VBO_VERTEX().z);
|
||||
static const unsigned int CoordStride = CoordByteSize / sizeof(GLfloat);
|
||||
|
||||
// Offset of color data from the beginning of each vertex data
|
||||
static const int ColorByteOffset = offsetof(VBO_VERTEX, r);
|
||||
static const int ColorOffset = ColorByteOffset / sizeof(GLfloat);
|
||||
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);
|
||||
static const unsigned int ColorByteOffset = offsetof(VBO_VERTEX, r);
|
||||
static const unsigned int ColorOffset = ColorByteOffset / sizeof(GLfloat);
|
||||
static const unsigned int ColorByteSize = sizeof(VBO_VERTEX().r) + sizeof(VBO_VERTEX().g) +
|
||||
sizeof(VBO_VERTEX().b) + sizeof(VBO_VERTEX().a);
|
||||
static const unsigned int ColorStride = ColorByteSize / sizeof(GLfloat);
|
||||
|
||||
// Shader attributes
|
||||
static const int ShaderByteOffset = offsetof(VBO_VERTEX, shader);
|
||||
static const int ShaderOffset = ShaderByteOffset / sizeof(GLfloat);
|
||||
static const int ShaderByteSize = sizeof(VBO_VERTEX().shader);
|
||||
static const int ShaderStride = ShaderByteSize / sizeof(GLfloat);
|
||||
static const unsigned int ShaderByteOffset = offsetof(VBO_VERTEX, shader);
|
||||
static const unsigned int ShaderOffset = ShaderByteOffset / sizeof(GLfloat);
|
||||
static const unsigned int ShaderByteSize = sizeof(VBO_VERTEX().shader);
|
||||
static const unsigned int ShaderStride = ShaderByteSize / sizeof(GLfloat);
|
||||
|
||||
static const int IndByteSize = sizeof(GLuint);
|
||||
static const unsigned int IndByteSize = sizeof(GLuint);
|
||||
|
||||
private:
|
||||
///< Offset and size of data stored in the VBO_CONTAINER.
|
||||
unsigned int m_offset;
|
||||
unsigned int m_size;
|
||||
unsigned int m_offset;
|
||||
unsigned int m_size;
|
||||
|
||||
///< Storage for vertices.
|
||||
VBO_CONTAINER* m_container;
|
||||
|
||||
///< Color used for new vertices pushed.
|
||||
GLfloat m_color[ColorStride];
|
||||
|
||||
///< Shader and its parameters used for new vertices pushed
|
||||
GLfloat m_shader[ShaderStride];
|
||||
VBO_CONTAINER* m_container;
|
||||
|
||||
///< Flag telling if the item should be recached in VBO or not.
|
||||
bool m_isDirty;
|
||||
|
||||
///< Current transform matrix applied for every new vertex pushed.
|
||||
const glm::mat4* m_transform;
|
||||
bool m_isDirty;
|
||||
};
|
||||
} // namespace KiGfx
|
||||
|
||||
|
|
Loading…
Reference in New Issue