Code formatting
Renamed VERTEX related constants to follow UPPER_CASE naming.
This commit is contained in:
parent
19ad350c1c
commit
342bb2bf78
|
@ -257,7 +257,7 @@ bool CACHED_CONTAINER::reallocate( unsigned int aSize )
|
||||||
(int) m_item, oldChunkOffset, newChunkOffset );
|
(int) m_item, oldChunkOffset, newChunkOffset );
|
||||||
#endif
|
#endif
|
||||||
// The item was reallocated, so we have to copy all the old data to the new place
|
// The item was reallocated, so we have to copy all the old data to the new place
|
||||||
memcpy( &m_vertices[newChunkOffset], &m_vertices[m_chunkOffset], itemSize * VertexSize );
|
memcpy( &m_vertices[newChunkOffset], &m_vertices[m_chunkOffset], itemSize * VERTEX_SIZE );
|
||||||
|
|
||||||
// Free the space used by the previous chunk
|
// Free the space used by the previous chunk
|
||||||
addFreeChunk( m_chunkOffset, m_chunkSize );
|
addFreeChunk( m_chunkOffset, m_chunkSize );
|
||||||
|
@ -288,7 +288,7 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget )
|
||||||
int itemSize = item->GetSize();
|
int itemSize = item->GetSize();
|
||||||
|
|
||||||
// Move an item to the new container
|
// Move an item to the new container
|
||||||
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VertexSize );
|
memcpy( &aTarget[newOffset], &m_vertices[itemOffset], itemSize * VERTEX_SIZE );
|
||||||
|
|
||||||
// Update new offset
|
// Update new offset
|
||||||
item->setOffset( newOffset );
|
item->setOffset( newOffset );
|
||||||
|
@ -301,7 +301,7 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget )
|
||||||
if( m_item->GetSize() > 0 )
|
if( m_item->GetSize() > 0 )
|
||||||
{
|
{
|
||||||
memcpy( &aTarget[newOffset], &m_vertices[m_item->GetOffset()],
|
memcpy( &aTarget[newOffset], &m_vertices[m_item->GetOffset()],
|
||||||
m_item->GetSize() * VertexSize );
|
m_item->GetSize() * VERTEX_SIZE );
|
||||||
m_item->setOffset( newOffset );
|
m_item->setOffset( newOffset );
|
||||||
m_chunkOffset = newOffset;
|
m_chunkOffset = newOffset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) :
|
||||||
|
|
||||||
glGenBuffers( 1, &m_glBufferHandle );
|
glGenBuffers( 1, &m_glBufferHandle );
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
glBindBuffer( GL_ARRAY_BUFFER, m_glBufferHandle );
|
||||||
glBufferData( GL_ARRAY_BUFFER, m_currentSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
glBufferData( GL_ARRAY_BUFFER, m_currentSize * VERTEX_SIZE, NULL, GL_DYNAMIC_DRAW );
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
||||||
checkGlError( "allocating video memory for cached container" );
|
checkGlError( "allocating video memory for cached container" );
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize )
|
||||||
assert( eaBuffer == 0 );
|
assert( eaBuffer == 0 );
|
||||||
#endif /* __WXDEBUG__ */
|
#endif /* __WXDEBUG__ */
|
||||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer );
|
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer );
|
||||||
glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VERTEX_SIZE, NULL, GL_DYNAMIC_DRAW );
|
||||||
checkGlError( "creating buffer during defragmentation" );
|
checkGlError( "creating buffer during defragmentation" );
|
||||||
|
|
||||||
ITEMS::iterator it, it_end;
|
ITEMS::iterator it, it_end;
|
||||||
|
@ -135,7 +135,7 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize )
|
||||||
|
|
||||||
// Move an item to the new container
|
// Move an item to the new container
|
||||||
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
||||||
itemOffset * VertexSize, newOffset * VertexSize, itemSize * VertexSize );
|
itemOffset * VERTEX_SIZE, newOffset * VERTEX_SIZE, itemSize * VERTEX_SIZE );
|
||||||
|
|
||||||
// Update new offset
|
// Update new offset
|
||||||
item->setOffset( newOffset );
|
item->setOffset( newOffset );
|
||||||
|
@ -148,8 +148,8 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize )
|
||||||
if( m_item->GetSize() > 0 )
|
if( m_item->GetSize() > 0 )
|
||||||
{
|
{
|
||||||
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER,
|
||||||
m_item->GetOffset() * VertexSize, newOffset * VertexSize,
|
m_item->GetOffset() * VERTEX_SIZE, newOffset * VERTEX_SIZE,
|
||||||
m_item->GetSize() * VertexSize );
|
m_item->GetSize() * VERTEX_SIZE );
|
||||||
|
|
||||||
m_item->setOffset( newOffset );
|
m_item->setOffset( newOffset );
|
||||||
m_chunkOffset = newOffset;
|
m_chunkOffset = newOffset;
|
||||||
|
@ -217,7 +217,7 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize )
|
||||||
assert( eaBuffer == 0 );
|
assert( eaBuffer == 0 );
|
||||||
#endif /* __WXDEBUG__ */
|
#endif /* __WXDEBUG__ */
|
||||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer );
|
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, newBuffer );
|
||||||
glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VertexSize, NULL, GL_DYNAMIC_DRAW );
|
glBufferData( GL_ELEMENT_ARRAY_BUFFER, aNewSize * VERTEX_SIZE, NULL, GL_DYNAMIC_DRAW );
|
||||||
newBufferMem = static_cast<VERTEX*>( glMapBuffer( GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY ) );
|
newBufferMem = static_cast<VERTEX*>( glMapBuffer( GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY ) );
|
||||||
checkGlError( "creating buffer during defragmentation" );
|
checkGlError( "creating buffer during defragmentation" );
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM( unsigned int aSize ) :
|
||||||
glGenBuffers( 1, &m_verticesBuffer );
|
glGenBuffers( 1, &m_verticesBuffer );
|
||||||
checkGlError( "generating vertices buffer" );
|
checkGlError( "generating vertices buffer" );
|
||||||
|
|
||||||
m_vertices = static_cast<VERTEX*>( malloc( aSize * VertexSize ) );
|
m_vertices = static_cast<VERTEX*>( malloc( aSize * VERTEX_SIZE ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ void CACHED_CONTAINER_RAM::Unmap()
|
||||||
// Upload vertices coordinates and shader types to GPU memory
|
// Upload vertices coordinates and shader types to GPU memory
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, m_verticesBuffer );
|
glBindBuffer( GL_ARRAY_BUFFER, m_verticesBuffer );
|
||||||
checkGlError( "binding vertices buffer" );
|
checkGlError( "binding vertices buffer" );
|
||||||
glBufferData( GL_ARRAY_BUFFER, usedSpace() * VertexSize, m_vertices, GL_STREAM_DRAW );
|
glBufferData( GL_ARRAY_BUFFER, usedSpace() * VERTEX_SIZE, m_vertices, GL_STREAM_DRAW );
|
||||||
checkGlError( "transferring vertices" );
|
checkGlError( "transferring vertices" );
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
glBindBuffer( GL_ARRAY_BUFFER, 0 );
|
||||||
checkGlError( "unbinding vertices buffer" );
|
checkGlError( "unbinding vertices buffer" );
|
||||||
|
@ -85,7 +85,7 @@ bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize )
|
||||||
PROF_COUNTER totalTime;
|
PROF_COUNTER totalTime;
|
||||||
#endif /* __WXDEBUG__ */
|
#endif /* __WXDEBUG__ */
|
||||||
|
|
||||||
VERTEX* newBufferMem = static_cast<VERTEX*>( malloc( aNewSize * VertexSize ) );
|
VERTEX* newBufferMem = static_cast<VERTEX*>( malloc( aNewSize * VERTEX_SIZE ) );
|
||||||
|
|
||||||
if( !newBufferMem )
|
if( !newBufferMem )
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -160,15 +160,15 @@ void GPU_CACHED_MANAGER::EndDrawing()
|
||||||
|
|
||||||
// Bind vertices data buffers
|
// Bind vertices data buffers
|
||||||
glBindBuffer( GL_ARRAY_BUFFER, cached->GetBufferHandle() );
|
glBindBuffer( GL_ARRAY_BUFFER, cached->GetBufferHandle() );
|
||||||
glVertexPointer( CoordStride, GL_FLOAT, VertexSize, 0 );
|
glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, (GLvoid*) COORD_OFFSET );
|
||||||
glColorPointer( ColorStride, GL_UNSIGNED_BYTE, VertexSize, (GLvoid*) ColorOffset );
|
glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, (GLvoid*) COLOR_OFFSET );
|
||||||
|
|
||||||
if( m_shader != NULL ) // Use shader if applicable
|
if( m_shader != NULL ) // Use shader if applicable
|
||||||
{
|
{
|
||||||
m_shader->Use();
|
m_shader->Use();
|
||||||
glEnableVertexAttribArray( m_shaderAttrib );
|
glEnableVertexAttribArray( m_shaderAttrib );
|
||||||
glVertexAttribPointer( m_shaderAttrib, ShaderStride, GL_FLOAT, GL_FALSE,
|
glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE,
|
||||||
VertexSize, (GLvoid*) ShaderOffset );
|
VERTEX_SIZE, (GLvoid*) SHADER_OFFSET );
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indicesBuffer );
|
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indicesBuffer );
|
||||||
|
@ -252,23 +252,23 @@ void GPU_NONCACHED_MANAGER::EndDrawing()
|
||||||
|
|
||||||
VERTEX* vertices = m_container->GetAllVertices();
|
VERTEX* vertices = m_container->GetAllVertices();
|
||||||
GLfloat* coordinates = (GLfloat*) ( vertices );
|
GLfloat* coordinates = (GLfloat*) ( vertices );
|
||||||
GLubyte* colors = (GLubyte*) ( vertices ) + ColorOffset;
|
GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET;
|
||||||
|
|
||||||
// Prepare buffers
|
// Prepare buffers
|
||||||
glEnableClientState( GL_VERTEX_ARRAY );
|
glEnableClientState( GL_VERTEX_ARRAY );
|
||||||
glEnableClientState( GL_COLOR_ARRAY );
|
glEnableClientState( GL_COLOR_ARRAY );
|
||||||
|
|
||||||
glVertexPointer( CoordStride, GL_FLOAT, VertexSize, coordinates );
|
glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates );
|
||||||
glColorPointer( ColorStride, GL_UNSIGNED_BYTE, VertexSize, colors );
|
glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors );
|
||||||
|
|
||||||
if( m_shader != NULL ) // Use shader if applicable
|
if( m_shader != NULL ) // Use shader if applicable
|
||||||
{
|
{
|
||||||
GLfloat* shaders = (GLfloat*) ( vertices ) + ShaderOffset / sizeof(GLfloat);
|
GLfloat* shaders = (GLfloat*) ( vertices ) + SHADER_OFFSET / sizeof(GLfloat);
|
||||||
|
|
||||||
m_shader->Use();
|
m_shader->Use();
|
||||||
glEnableVertexAttribArray( m_shaderAttrib );
|
glEnableVertexAttribArray( m_shaderAttrib );
|
||||||
glVertexAttribPointer( m_shaderAttrib, ShaderStride, GL_FLOAT, GL_FALSE,
|
glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE,
|
||||||
VertexSize, shaders );
|
VERTEX_SIZE, shaders );
|
||||||
}
|
}
|
||||||
|
|
||||||
glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
|
glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() );
|
||||||
|
|
|
@ -44,7 +44,7 @@ VERTEX_MANAGER::VERTEX_MANAGER( bool aCached ) :
|
||||||
m_gpu.reset( GPU_MANAGER::MakeManager( m_container.get() ) );
|
m_gpu.reset( GPU_MANAGER::MakeManager( m_container.get() ) );
|
||||||
|
|
||||||
// There is no shader used by default
|
// There is no shader used by default
|
||||||
for( unsigned int i = 0; i < ShaderStride; ++i )
|
for( unsigned int i = 0; i < SHADER_STRIDE; ++i )
|
||||||
m_shader[i] = 0.0f;
|
m_shader[i] = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -279,7 +279,7 @@ void VERTEX_MANAGER::putVertex( VERTEX& aTarget, GLfloat aX, GLfloat aY, GLfloat
|
||||||
aTarget.a = m_color[3];
|
aTarget.a = m_color[3];
|
||||||
|
|
||||||
// Apply currently used shader
|
// Apply currently used shader
|
||||||
for( unsigned int j = 0; j < ShaderStride; ++j )
|
for( unsigned int j = 0; j < SHADER_STRIDE; ++j )
|
||||||
{
|
{
|
||||||
aTarget.shader[j] = m_shader[j];
|
aTarget.shader[j] = m_shader[j];
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
namespace KIGFX
|
namespace KIGFX
|
||||||
{
|
{
|
||||||
// Possible types of shaders
|
///> Possible types of shaders
|
||||||
enum SHADER_MODE
|
enum SHADER_MODE
|
||||||
{
|
{
|
||||||
SHADER_NONE = 0,
|
SHADER_NONE = 0,
|
||||||
|
@ -46,32 +46,32 @@ enum SHADER_MODE
|
||||||
SHADER_FONT
|
SHADER_FONT
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
///> Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m}
|
||||||
|
struct VERTEX
|
||||||
{
|
{
|
||||||
GLfloat x, y, z; // Coordinates
|
GLfloat x, y, z; // Coordinates
|
||||||
GLubyte r, g, b, a; // Color
|
GLubyte r, g, b, a; // Color
|
||||||
GLfloat shader[4]; // Shader type & params
|
GLfloat shader[4]; // Shader type & params
|
||||||
} VERTEX;
|
};
|
||||||
|
|
||||||
///< Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m} (@see VERTEX).
|
static constexpr size_t VERTEX_SIZE = sizeof(VERTEX);
|
||||||
const size_t VertexSize = sizeof(VERTEX);
|
static constexpr size_t VERTEX_STRIDE = VERTEX_SIZE / sizeof(GLfloat);
|
||||||
const size_t VertexStride = VertexSize / sizeof(GLfloat);
|
|
||||||
|
|
||||||
const size_t CoordSize = sizeof(VERTEX().x) + sizeof(VERTEX().y) + sizeof(VERTEX().z);
|
static constexpr size_t COORD_OFFSET = offsetof(VERTEX, x);
|
||||||
const size_t CoordStride = CoordSize / sizeof(GLfloat);
|
static constexpr size_t COORD_SIZE = sizeof(VERTEX::x) + sizeof(VERTEX::y) + sizeof(VERTEX::z);
|
||||||
|
static constexpr size_t COORD_STRIDE = COORD_SIZE / sizeof(GLfloat);
|
||||||
|
|
||||||
// Offset of color data from the beginning of each vertex data
|
static constexpr size_t COLOR_OFFSET = offsetof(VERTEX, r);
|
||||||
const size_t ColorOffset = offsetof(VERTEX, r);
|
static constexpr size_t COLOR_SIZE = sizeof(VERTEX::r) + sizeof(VERTEX::g) + sizeof(VERTEX::b) + sizeof(VERTEX::a);
|
||||||
const size_t ColorSize = sizeof(VERTEX().r) + sizeof(VERTEX().g) +
|
static constexpr size_t COLOR_STRIDE = COLOR_SIZE / sizeof(GLubyte);
|
||||||
sizeof(VERTEX().b) + sizeof(VERTEX().a);
|
|
||||||
const size_t ColorStride = ColorSize / sizeof(GLubyte);
|
|
||||||
|
|
||||||
// Shader attributes
|
// Shader attributes
|
||||||
const size_t ShaderOffset = offsetof(VERTEX, shader);
|
static constexpr size_t SHADER_OFFSET = offsetof(VERTEX, shader);
|
||||||
const size_t ShaderSize = sizeof(VERTEX().shader);
|
static constexpr size_t SHADER_SIZE = sizeof(VERTEX::shader);
|
||||||
const size_t ShaderStride = ShaderSize / sizeof(GLfloat);
|
static constexpr size_t SHADER_STRIDE = SHADER_SIZE / sizeof(GLfloat);
|
||||||
|
|
||||||
|
static constexpr size_t INDEX_SIZE = sizeof(GLuint);
|
||||||
|
|
||||||
const size_t IndexSize = sizeof(GLuint);
|
|
||||||
} // namespace KIGFX
|
} // namespace KIGFX
|
||||||
|
|
||||||
#endif /* VERTEX_COMMON_H_ */
|
#endif /* VERTEX_COMMON_H_ */
|
||||||
|
|
|
@ -361,9 +361,9 @@ protected:
|
||||||
/// Stack of transformation matrices, used for Push/PopMatrix
|
/// Stack of transformation matrices, used for Push/PopMatrix
|
||||||
std::stack<glm::mat4> m_transformStack;
|
std::stack<glm::mat4> m_transformStack;
|
||||||
/// Currently used color
|
/// Currently used color
|
||||||
GLubyte m_color[ColorStride];
|
GLubyte m_color[COLOR_STRIDE];
|
||||||
/// Currently used shader and its parameters
|
/// Currently used shader and its parameters
|
||||||
GLfloat m_shader[ShaderStride];
|
GLfloat m_shader[SHADER_STRIDE];
|
||||||
|
|
||||||
/// Currently reserved chunk to store vertices
|
/// Currently reserved chunk to store vertices
|
||||||
VERTEX* m_reserved;
|
VERTEX* m_reserved;
|
||||||
|
|
Loading…
Reference in New Issue