From 8fe28f8d996d4c5ef2ff4a44dc16f2cfc4e216ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=C2=ADn=20Lucas=20Golini?= Date: Sun, 19 Mar 2017 19:18:30 -0300 Subject: [PATCH] Other minor clean up. --HG-- branch : dev --- include/eepp/graphics/fonthelper.hpp | 5 - include/eepp/graphics/text.hpp | 11 +- include/eepp/graphics/vertexbuffer.hpp | 7 +- src/eepp/graphics/text.cpp | 164 ++++++++++++------------- src/eepp/graphics/vertexbuffer.cpp | 10 +- 5 files changed, 106 insertions(+), 91 deletions(-) diff --git a/include/eepp/graphics/fonthelper.hpp b/include/eepp/graphics/fonthelper.hpp index 0e8ae79b0..22e8c4cca 100644 --- a/include/eepp/graphics/fonthelper.hpp +++ b/include/eepp/graphics/fonthelper.hpp @@ -32,11 +32,6 @@ inline Uint32 fontVAlignGet( Uint32 Flags ) { #define FONT_DRAW_ALIGN_MASK ( FONT_DRAW_VALIGN_MASK | FONT_DRAW_HALIGN_MASK ) -struct VertexCoords { - Float TexCoords[2]; - Float Vertex[2]; -}; - #define EE_TTF_FONT_MAGIC ( ( 'E' << 0 ) | ( 'E' << 8 ) | ( 'F' << 16 ) | ( 'N' << 24 ) ) }} diff --git a/include/eepp/graphics/text.hpp b/include/eepp/graphics/text.hpp index a86220435..36a27ef4e 100644 --- a/include/eepp/graphics/text.hpp +++ b/include/eepp/graphics/text.hpp @@ -101,7 +101,10 @@ class EE_API Text { void setStyleConfig( const FontStyleConfig& styleConfig ); protected: - void ensureGeometryUpdate(); + struct VertexCoords { + Vector2f texCoords; + Vector2f position; + }; String mString; ///< String to display Font * mFont; ///< FontTrueType used to display the string @@ -131,8 +134,14 @@ class EE_API Text { std::vector mOutlineColors; std::vector mLinesWidth; + void ensureGeometryUpdate(); + /** Force to cache the width of the current text */ void cacheWidth(); + + static void addLine(std::vector& vertices, std::vector& colors, Float lineLength, Float lineTop, const EE::System::ColorA& color, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX); + + static void addGlyphQuad(std::vector& vertices, std::vector& colors, Vector2f position, const EE::System::ColorA& color, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX); }; }} diff --git a/include/eepp/graphics/vertexbuffer.hpp b/include/eepp/graphics/vertexbuffer.hpp index 493943b65..c42d8a09b 100644 --- a/include/eepp/graphics/vertexbuffer.hpp +++ b/include/eepp/graphics/vertexbuffer.hpp @@ -7,7 +7,7 @@ namespace EE { namespace Graphics { /** @brief The vertex buffer class holds vertex data. The vertex position, colors, texture coordinates and indexes. -* This is useful to accelerate and encapsulate data. GPU VBOs are much faster because the data is in the GPU once is uploaded. eepp will try to use GPU VBOs if the GPU support them. +* This is useful to accelerate and encapsulate data. */ class EE_API VertexBuffer { public: @@ -20,6 +20,9 @@ class EE_API VertexBuffer { */ static VertexBuffer * New( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT, EE_DRAW_MODE DrawType = DM_QUADS, const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0, EE_VBO_USAGE_TYPE UsageType = VBO_USAGE_TYPE_STATIC ); + /** Creates the simple vertex array implementation ( without VBOs or VAO ), which it's faster for many cases. */ + static VertexBuffer * NewVertexArray( const Uint32& VertexFlags = VERTEX_FLAGS_DEFAULT, EE_DRAW_MODE DrawType = DM_QUADS, const Int32& ReserveVertexSize = 0, const Int32& ReserveIndexSize = 0, EE_VBO_USAGE_TYPE UsageType = VBO_USAGE_TYPE_STATIC ); + virtual ~VertexBuffer(); /** @brief Adds a vertex of the type indicated to the buffer @@ -35,7 +38,7 @@ class EE_API VertexBuffer { * @param VertexCoord The vertex texture coordinate. * @param TextureLevel Indicates the texture level if it's using multitextures. */ - void addVertexCoord( const Vector2f& VertexCoord, const Uint32& TextureLevel = 0 ); + void addTextureCoord( const Vector2f& VertexCoord, const Uint32& TextureLevel = 0 ); /** @brief Adds a color to the buffer. * @param Color The color value. diff --git a/src/eepp/graphics/text.cpp b/src/eepp/graphics/text.cpp index 3b87c896a..11c17a511 100644 --- a/src/eepp/graphics/text.cpp +++ b/src/eepp/graphics/text.cpp @@ -8,7 +8,7 @@ namespace EE { namespace Graphics { // Add an underline or strikethrough line to the vertex array - static void addLine(std::vector& vertices, std::vector& colors, Float lineLength, Float lineTop, const EE::System::ColorA& color, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) { + void Text::addLine(std::vector& vertices, std::vector& colors, Float lineLength, Float lineTop, const EE::System::ColorA& color, Float offset, Float thickness, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) { Float top = std::floor(lineTop + offset - (thickness / 2) + 0.5f); Float bottom = top + std::floor(thickness + 0.5f); Float u1 = 0; @@ -18,80 +18,80 @@ namespace EE { namespace Graphics { VertexCoords vc; if ( GLi->quadsSupported() ) { - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + -outlineThickness; - vc.Vertex[1] = top - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + -outlineThickness; + vc.position.y = top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + -outlineThickness; - vc.Vertex[1] = bottom + outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + -outlineThickness; + vc.position.y = bottom + outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + lineLength + outlineThickness; - vc.Vertex[1] = bottom + outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + lineLength + outlineThickness; + vc.position.y = bottom + outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + lineLength + outlineThickness; - vc.Vertex[1] = top - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + lineLength + outlineThickness; + vc.position.y = top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); } else { - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + -outlineThickness; - vc.Vertex[1] = bottom + outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + -outlineThickness; + vc.position.y = bottom + outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + -outlineThickness; - vc.Vertex[1] = top - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + -outlineThickness; + vc.position.y = top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + lineLength + outlineThickness; - vc.Vertex[1] = top - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + lineLength + outlineThickness; + vc.position.y = top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + -outlineThickness; - vc.Vertex[1] = bottom + outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + -outlineThickness; + vc.position.y = bottom + outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + lineLength + outlineThickness; - vc.Vertex[1] = bottom + outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + lineLength + outlineThickness; + vc.position.y = bottom + outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + lineLength + outlineThickness; - vc.Vertex[1] = top - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + lineLength + outlineThickness; + vc.position.y = top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); } } // Add a glyph quad to the vertex array - static void addGlyphQuad(std::vector& vertices, std::vector& colors, Vector2f position, const EE::System::ColorA& color, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) { + void Text::addGlyphQuad(std::vector& vertices, std::vector& colors, Vector2f position, const EE::System::ColorA& color, const EE::Graphics::Glyph& glyph, Float italic, Float outlineThickness, Sizei textureSize, Int32 centerDiffX) { Float left = glyph.bounds.Left; Float top = glyph.bounds.Top; Float right = glyph.bounds.Left + glyph.bounds.Right; @@ -105,73 +105,73 @@ namespace EE { namespace Graphics { if ( GLi->quadsSupported() ) { - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + position.x + left - italic * top - outlineThickness; - vc.Vertex[1] = position.y + top - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness; + vc.position.y = position.y + top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + position.x + left - italic * bottom - outlineThickness; - vc.Vertex[1] = position.y + bottom - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness; + vc.position.y = position.y + bottom - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + position.x + right - italic * bottom - outlineThickness; - vc.Vertex[1] = position.y + bottom - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + position.x + right - italic * bottom - outlineThickness; + vc.position.y = position.y + bottom - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + position.x + right - italic * top - outlineThickness; - vc.Vertex[1] = position.y + top - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness; + vc.position.y = position.y + top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); } else { - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + position.x + left - italic * bottom - outlineThickness; - vc.Vertex[1] = position.y + bottom - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness; + vc.position.y = position.y + bottom - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + position.x + left - italic * top - outlineThickness; - vc.Vertex[1] = position.y + top - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + position.x + left - italic * top - outlineThickness; + vc.position.y = position.y + top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + position.x + right - italic * top - outlineThickness; - vc.Vertex[1] = position.y + top - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness; + vc.position.y = position.y + top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u1; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + position.x + left - italic * bottom - outlineThickness; - vc.Vertex[1] = position.y + bottom - outlineThickness; + vc.texCoords.x = u1; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + position.x + left - italic * bottom - outlineThickness; + vc.position.y = position.y + bottom - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v2; - vc.Vertex[0] = centerDiffX + position.x + right - italic * bottom - outlineThickness; - vc.Vertex[1] = position.y + bottom - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v2; + vc.position.x = centerDiffX + position.x + right - italic * bottom - outlineThickness; + vc.position.y = position.y + bottom - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); - vc.TexCoords[0] = u2; - vc.TexCoords[1] = v1; - vc.Vertex[0] = centerDiffX + position.x + right - italic * top - outlineThickness; - vc.Vertex[1] = position.y + top - outlineThickness; + vc.texCoords.x = u2; + vc.texCoords.y = v1; + vc.position.x = centerDiffX + position.x + right - italic * top - outlineThickness; + vc.position.y = position.y + top - outlineThickness; colors.push_back( color ); vertices.push_back( vc ); } diff --git a/src/eepp/graphics/vertexbuffer.cpp b/src/eepp/graphics/vertexbuffer.cpp index d71967cff..703dd4d54 100644 --- a/src/eepp/graphics/vertexbuffer.cpp +++ b/src/eepp/graphics/vertexbuffer.cpp @@ -14,6 +14,10 @@ VertexBuffer * VertexBuffer::New( const Uint32& VertexFlags, EE_DRAW_MODE DrawTy return eeNew( VertexBufferOGL, ( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) ); } +VertexBuffer * VertexBuffer::NewVertexArray(const Uint32 & VertexFlags, EE_DRAW_MODE DrawType, const Int32 & ReserveVertexSize, const Int32 & ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) { + return eeNew( VertexBufferOGL, ( VertexFlags, DrawType, ReserveVertexSize, ReserveIndexSize, UsageType ) ); +} + VertexBuffer::VertexBuffer( const Uint32& VertexFlags, EE_DRAW_MODE DrawType, const Int32& ReserveVertexSize, const Int32& ReserveIndexSize, EE_VBO_USAGE_TYPE UsageType ) : mVertexFlags( VertexFlags ), mDrawType( DrawType ), @@ -31,6 +35,10 @@ VertexBuffer::VertexBuffer( const Uint32& VertexFlags, EE_DRAW_MODE DrawType, co } } + if ( ReserveIndexSize > 0 ) { + mIndexArray.reserve( ReserveIndexSize ); + } + VertexBufferManager::instance()->add( this ); } @@ -49,7 +57,7 @@ void VertexBuffer::addVertex( const Vector2f& Vertex ) { addVertex( VERTEX_FLAG_POSITION, Vertex ); } -void VertexBuffer::addVertexCoord( const Vector2f& VertexCoord, const Uint32& TextureLevel ) { +void VertexBuffer::addTextureCoord( const Vector2f& VertexCoord, const Uint32& TextureLevel ) { addVertex( VERTEX_FLAG_TEXTURE0 + TextureLevel, VertexCoord ); }