From 342bb2bf78f8ac48363888192c34c44f8fa397dd Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Sat, 9 Sep 2017 20:40:00 +0200 Subject: [PATCH] Code formatting Renamed VERTEX related constants to follow UPPER_CASE naming. --- common/gal/opengl/cached_container.cpp | 6 ++-- common/gal/opengl/cached_container_gpu.cpp | 12 ++++---- common/gal/opengl/cached_container_ram.cpp | 6 ++-- common/gal/opengl/gpu_manager.cpp | 20 ++++++------- common/gal/opengl/vertex_manager.cpp | 4 +-- include/gal/opengl/cached_container.h | 10 +++---- include/gal/opengl/vertex_common.h | 34 +++++++++++----------- include/gal/opengl/vertex_manager.h | 4 +-- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/common/gal/opengl/cached_container.cpp b/common/gal/opengl/cached_container.cpp index fd9a689965..cadeed9f91 100644 --- a/common/gal/opengl/cached_container.cpp +++ b/common/gal/opengl/cached_container.cpp @@ -257,7 +257,7 @@ bool CACHED_CONTAINER::reallocate( unsigned int aSize ) (int) m_item, oldChunkOffset, newChunkOffset ); #endif // 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 addFreeChunk( m_chunkOffset, m_chunkSize ); @@ -288,7 +288,7 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget ) int itemSize = item->GetSize(); // 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 item->setOffset( newOffset ); @@ -301,7 +301,7 @@ void CACHED_CONTAINER::defragment( VERTEX* aTarget ) if( m_item->GetSize() > 0 ) { memcpy( &aTarget[newOffset], &m_vertices[m_item->GetOffset()], - m_item->GetSize() * VertexSize ); + m_item->GetSize() * VERTEX_SIZE ); m_item->setOffset( newOffset ); m_chunkOffset = newOffset; } diff --git a/common/gal/opengl/cached_container_gpu.cpp b/common/gal/opengl/cached_container_gpu.cpp index 9ccf972b64..f3f5498011 100644 --- a/common/gal/opengl/cached_container_gpu.cpp +++ b/common/gal/opengl/cached_container_gpu.cpp @@ -45,7 +45,7 @@ CACHED_CONTAINER_GPU::CACHED_CONTAINER_GPU( unsigned int aSize ) : glGenBuffers( 1, &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 ); checkGlError( "allocating video memory for cached container" ); } @@ -120,7 +120,7 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) assert( eaBuffer == 0 ); #endif /* __WXDEBUG__ */ 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" ); ITEMS::iterator it, it_end; @@ -135,7 +135,7 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) // Move an item to the new container 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 item->setOffset( newOffset ); @@ -148,8 +148,8 @@ bool CACHED_CONTAINER_GPU::defragmentResize( unsigned int aNewSize ) if( m_item->GetSize() > 0 ) { glCopyBufferSubData( GL_ARRAY_BUFFER, GL_ELEMENT_ARRAY_BUFFER, - m_item->GetOffset() * VertexSize, newOffset * VertexSize, - m_item->GetSize() * VertexSize ); + m_item->GetOffset() * VERTEX_SIZE, newOffset * VERTEX_SIZE, + m_item->GetSize() * VERTEX_SIZE ); m_item->setOffset( newOffset ); m_chunkOffset = newOffset; @@ -217,7 +217,7 @@ bool CACHED_CONTAINER_GPU::defragmentResizeMemcpy( unsigned int aNewSize ) assert( eaBuffer == 0 ); #endif /* __WXDEBUG__ */ 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( glMapBuffer( GL_ELEMENT_ARRAY_BUFFER, GL_WRITE_ONLY ) ); checkGlError( "creating buffer during defragmentation" ); diff --git a/common/gal/opengl/cached_container_ram.cpp b/common/gal/opengl/cached_container_ram.cpp index a7109545cb..b6eff40b2a 100644 --- a/common/gal/opengl/cached_container_ram.cpp +++ b/common/gal/opengl/cached_container_ram.cpp @@ -45,7 +45,7 @@ CACHED_CONTAINER_RAM::CACHED_CONTAINER_RAM( unsigned int aSize ) : glGenBuffers( 1, &m_verticesBuffer ); checkGlError( "generating vertices buffer" ); - m_vertices = static_cast( malloc( aSize * VertexSize ) ); + m_vertices = static_cast( malloc( aSize * VERTEX_SIZE ) ); } @@ -64,7 +64,7 @@ void CACHED_CONTAINER_RAM::Unmap() // Upload vertices coordinates and shader types to GPU memory glBindBuffer( GL_ARRAY_BUFFER, m_verticesBuffer ); 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" ); glBindBuffer( GL_ARRAY_BUFFER, 0 ); checkGlError( "unbinding vertices buffer" ); @@ -85,7 +85,7 @@ bool CACHED_CONTAINER_RAM::defragmentResize( unsigned int aNewSize ) PROF_COUNTER totalTime; #endif /* __WXDEBUG__ */ - VERTEX* newBufferMem = static_cast( malloc( aNewSize * VertexSize ) ); + VERTEX* newBufferMem = static_cast( malloc( aNewSize * VERTEX_SIZE ) ); if( !newBufferMem ) return false; diff --git a/common/gal/opengl/gpu_manager.cpp b/common/gal/opengl/gpu_manager.cpp index 1f26e74c30..374e31c074 100644 --- a/common/gal/opengl/gpu_manager.cpp +++ b/common/gal/opengl/gpu_manager.cpp @@ -160,15 +160,15 @@ void GPU_CACHED_MANAGER::EndDrawing() // Bind vertices data buffers glBindBuffer( GL_ARRAY_BUFFER, cached->GetBufferHandle() ); - glVertexPointer( CoordStride, GL_FLOAT, VertexSize, 0 ); - glColorPointer( ColorStride, GL_UNSIGNED_BYTE, VertexSize, (GLvoid*) ColorOffset ); + glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, (GLvoid*) COORD_OFFSET ); + glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, (GLvoid*) COLOR_OFFSET ); if( m_shader != NULL ) // Use shader if applicable { m_shader->Use(); glEnableVertexAttribArray( m_shaderAttrib ); - glVertexAttribPointer( m_shaderAttrib, ShaderStride, GL_FLOAT, GL_FALSE, - VertexSize, (GLvoid*) ShaderOffset ); + glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, + VERTEX_SIZE, (GLvoid*) SHADER_OFFSET ); } glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, m_indicesBuffer ); @@ -252,23 +252,23 @@ void GPU_NONCACHED_MANAGER::EndDrawing() VERTEX* vertices = m_container->GetAllVertices(); GLfloat* coordinates = (GLfloat*) ( vertices ); - GLubyte* colors = (GLubyte*) ( vertices ) + ColorOffset; + GLubyte* colors = (GLubyte*) ( vertices ) + COLOR_OFFSET; // Prepare buffers glEnableClientState( GL_VERTEX_ARRAY ); glEnableClientState( GL_COLOR_ARRAY ); - glVertexPointer( CoordStride, GL_FLOAT, VertexSize, coordinates ); - glColorPointer( ColorStride, GL_UNSIGNED_BYTE, VertexSize, colors ); + glVertexPointer( COORD_STRIDE, GL_FLOAT, VERTEX_SIZE, coordinates ); + glColorPointer( COLOR_STRIDE, GL_UNSIGNED_BYTE, VERTEX_SIZE, colors ); 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(); glEnableVertexAttribArray( m_shaderAttrib ); - glVertexAttribPointer( m_shaderAttrib, ShaderStride, GL_FLOAT, GL_FALSE, - VertexSize, shaders ); + glVertexAttribPointer( m_shaderAttrib, SHADER_STRIDE, GL_FLOAT, GL_FALSE, + VERTEX_SIZE, shaders ); } glDrawArrays( GL_TRIANGLES, 0, m_container->GetSize() ); diff --git a/common/gal/opengl/vertex_manager.cpp b/common/gal/opengl/vertex_manager.cpp index 5e9b393b0a..76d433b9f7 100644 --- a/common/gal/opengl/vertex_manager.cpp +++ b/common/gal/opengl/vertex_manager.cpp @@ -44,7 +44,7 @@ VERTEX_MANAGER::VERTEX_MANAGER( bool aCached ) : m_gpu.reset( GPU_MANAGER::MakeManager( m_container.get() ) ); // 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; } @@ -279,7 +279,7 @@ void VERTEX_MANAGER::putVertex( VERTEX& aTarget, GLfloat aX, GLfloat aY, GLfloat aTarget.a = m_color[3]; // 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]; } diff --git a/include/gal/opengl/cached_container.h b/include/gal/opengl/cached_container.h index 3b32612943..299c997262 100644 --- a/include/gal/opengl/cached_container.h +++ b/include/gal/opengl/cached_container.h @@ -91,17 +91,17 @@ protected: typedef std::set ITEMS; ///> Stores size & offset of free chunks. - FREE_CHUNK_MAP m_freeChunks; + FREE_CHUNK_MAP m_freeChunks; ///> Stored VERTEX_ITEMs - ITEMS m_items; + ITEMS m_items; ///> Currently modified item - VERTEX_ITEM* m_item; + VERTEX_ITEM* m_item; ///> Properties of currently modified chunk & item - unsigned int m_chunkSize; - unsigned int m_chunkOffset; + unsigned int m_chunkSize; + unsigned int m_chunkOffset; /** * Resizes the chunk that stores the current item to the given size. The current item has diff --git a/include/gal/opengl/vertex_common.h b/include/gal/opengl/vertex_common.h index 38700bab15..f255633c4b 100644 --- a/include/gal/opengl/vertex_common.h +++ b/include/gal/opengl/vertex_common.h @@ -36,7 +36,7 @@ namespace KIGFX { -// Possible types of shaders +///> Possible types of shaders enum SHADER_MODE { SHADER_NONE = 0, @@ -46,32 +46,32 @@ enum SHADER_MODE SHADER_FONT }; -typedef struct +///> Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m} +struct VERTEX { GLfloat x, y, z; // Coordinates GLubyte r, g, b, a; // Color GLfloat shader[4]; // Shader type & params -} VERTEX; +}; -///< Data structure for vertices {X,Y,Z,R,G,B,A,shader¶m} (@see VERTEX). -const size_t VertexSize = sizeof(VERTEX); -const size_t VertexStride = VertexSize / sizeof(GLfloat); +static constexpr size_t VERTEX_SIZE = sizeof(VERTEX); +static constexpr size_t VERTEX_STRIDE = VERTEX_SIZE / sizeof(GLfloat); -const size_t CoordSize = sizeof(VERTEX().x) + sizeof(VERTEX().y) + sizeof(VERTEX().z); -const size_t CoordStride = CoordSize / sizeof(GLfloat); +static constexpr size_t COORD_OFFSET = offsetof(VERTEX, x); +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 -const size_t ColorOffset = offsetof(VERTEX, r); -const size_t ColorSize = sizeof(VERTEX().r) + sizeof(VERTEX().g) + - sizeof(VERTEX().b) + sizeof(VERTEX().a); -const size_t ColorStride = ColorSize / sizeof(GLubyte); +static constexpr size_t COLOR_OFFSET = offsetof(VERTEX, r); +static constexpr size_t COLOR_SIZE = sizeof(VERTEX::r) + sizeof(VERTEX::g) + sizeof(VERTEX::b) + sizeof(VERTEX::a); +static constexpr size_t COLOR_STRIDE = COLOR_SIZE / sizeof(GLubyte); // Shader attributes -const size_t ShaderOffset = offsetof(VERTEX, shader); -const size_t ShaderSize = sizeof(VERTEX().shader); -const size_t ShaderStride = ShaderSize / sizeof(GLfloat); +static constexpr size_t SHADER_OFFSET = offsetof(VERTEX, shader); +static constexpr size_t SHADER_SIZE = sizeof(VERTEX::shader); +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 #endif /* VERTEX_COMMON_H_ */ diff --git a/include/gal/opengl/vertex_manager.h b/include/gal/opengl/vertex_manager.h index 09c089b883..12bbaaea50 100644 --- a/include/gal/opengl/vertex_manager.h +++ b/include/gal/opengl/vertex_manager.h @@ -361,9 +361,9 @@ protected: /// Stack of transformation matrices, used for Push/PopMatrix std::stack m_transformStack; /// Currently used color - GLubyte m_color[ColorStride]; + GLubyte m_color[COLOR_STRIDE]; /// Currently used shader and its parameters - GLfloat m_shader[ShaderStride]; + GLfloat m_shader[SHADER_STRIDE]; /// Currently reserved chunk to store vertices VERTEX* m_reserved;