From f2c45e3f39d21e89fca9660c2fe4c98656cf15ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 29 Dec 2018 14:09:42 -0300 Subject: [PATCH] Replaced eeTexCoord to Vector2f in BatchRenderer class. Added BatchRenderer::batchPointList. --HG-- branch : dev --- include/eepp/graphics/batchrenderer.hpp | 14 ++++----- src/eepp/graphics/batchrenderer.cpp | 42 +++++++++++++++---------- 2 files changed, 32 insertions(+), 24 deletions(-) diff --git a/include/eepp/graphics/batchrenderer.hpp b/include/eepp/graphics/batchrenderer.hpp index 976cc1d57..e87bf699c 100755 --- a/include/eepp/graphics/batchrenderer.hpp +++ b/include/eepp/graphics/batchrenderer.hpp @@ -14,14 +14,9 @@ using namespace EE::System; namespace EE { namespace Graphics { -struct eeTexCoord { - Float u; - Float v; -}; - struct eeVertex { Vector2f pos; - eeTexCoord tex; + Vector2f tex; Color color; }; @@ -123,9 +118,12 @@ class EE_API BatchRenderer { /** Set the texture sector to be rendered */ void pointSetTexCoord(const Float & x, const Float & y); - /** Add to the batch a point ( this will change your batch rendering method to PRIMITIVE_POINTS, so if you were using another one will Draw all the batched vertexs first ) */ + /** Adds to the batch a point */ void batchPoint( const Float& x, const Float& y, const PrimitiveType& primitiveType = PRIMITIVE_POINTS ); + /** Adds to the batch a point list */ + void batchPointList( const std::vector& points, const PrimitiveType& primitiveType = PRIMITIVE_POINTS ); + /** This will set as the default batch rendering to PRIMITIVE_LINES. And will reset the line color to ColorA(255,255,255,255). */ void linesBegin(); @@ -251,7 +249,7 @@ class EE_API BatchRenderer { const Texture * mTexture; BlendMode mBlend; - eeTexCoord mTexCoord[4]; + Vector2f mTexCoord[4]; Color mVerColor[4]; PrimitiveType mCurrentMode; diff --git a/src/eepp/graphics/batchrenderer.cpp b/src/eepp/graphics/batchrenderer.cpp index b63c85422..6059cfd2f 100755 --- a/src/eepp/graphics/batchrenderer.cpp +++ b/src/eepp/graphics/batchrenderer.cpp @@ -155,7 +155,7 @@ void BatchRenderer::flush() { } GLi->vertexPointer ( 2, GL_FP , sizeof(eeVertex), reinterpret_cast ( &mVertex[0] ) , alloc ); - GLi->colorPointer ( 4, GL_UNSIGNED_BYTE , sizeof(eeVertex), reinterpret_cast ( &mVertex[0] ) + sizeof(Vector2f) + sizeof(eeTexCoord) , alloc ); + GLi->colorPointer ( 4, GL_UNSIGNED_BYTE , sizeof(eeVertex), reinterpret_cast ( &mVertex[0] ) + sizeof(Vector2f) + sizeof(Vector2f) , alloc ); if ( !GLi->quadsSupported() ) { if ( PRIMITIVE_QUADS == mCurrentMode ) { @@ -457,18 +457,18 @@ void BatchRenderer::quadsSetColorFree( const Color& Color0, const Color& Color1, } void BatchRenderer::quadsSetTexCoord( const Float& tl_u, const Float& tl_v, const Float& br_u, const Float& br_v ) { - mTexCoord[0].u = tl_u; mTexCoord[1].u = tl_u; - mTexCoord[0].v = tl_v; mTexCoord[1].v = br_v; + mTexCoord[0].x = tl_u; mTexCoord[1].x = tl_u; + mTexCoord[0].y = tl_v; mTexCoord[1].y = br_v; - mTexCoord[2].u = br_u; mTexCoord[3].u = br_u; - mTexCoord[2].v = br_v; mTexCoord[3].v = tl_v; + mTexCoord[2].x = br_u; mTexCoord[3].x = br_u; + mTexCoord[2].y = br_v; mTexCoord[3].y = tl_v; } void BatchRenderer::quadsSetTexCoordFree( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2, const Float& x3, const Float& y3 ) { - mTexCoord[0].u = x0; mTexCoord[0].v = y0; - mTexCoord[1].u = x1; mTexCoord[1].v = y1; - mTexCoord[2].u = x2; mTexCoord[2].v = y2; - mTexCoord[3].u = x3; mTexCoord[3].v = y3; + mTexCoord[0].x = x0; mTexCoord[0].y = y0; + mTexCoord[1].x = x1; mTexCoord[1].y = y1; + mTexCoord[2].x = x2; mTexCoord[2].y = y2; + mTexCoord[3].x = x3; mTexCoord[3].y = y3; } void BatchRenderer::rotate( const Vector2f& center, Vector2f* point, const Float& angle ) { @@ -491,7 +491,7 @@ void BatchRenderer::pointSetColor( const Color& color ) { } void BatchRenderer::pointSetTexCoord( const Float& x, const Float& y ) { - mTexCoord[0].u = x; mTexCoord[0].v = y; + mTexCoord[0].x = x; mTexCoord[0].y = y; } void BatchRenderer::batchPoint( const Float& x, const Float& y , const PrimitiveType & primitiveType ) { @@ -509,6 +509,16 @@ void BatchRenderer::batchPoint( const Float& x, const Float& y , const Primitive addVertexs(1); } +void BatchRenderer::batchPointList( const std::vector & points, const PrimitiveType & primitiveType ) { + setDrawMode( primitiveType, mForceBlendMode ); + + unsigned int curNumVertex = mNumVertex; + + addVertexs(points.size()); + + memcpy( (void*)&mVertex[ curNumVertex ], (void*)&points[0], sizeof(eeVertex) * points.size() ); +} + void BatchRenderer::linesBegin() { setDrawMode( PRIMITIVE_LINES, true ); quadsSetTexCoord( 0, 0, 1, 1 ); @@ -675,9 +685,9 @@ void BatchRenderer::triangleFanSetColorFree( const Color& Color0, const Color& C } void BatchRenderer::triangleFanSetTexCoord( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2 ) { - mTexCoord[0].u = x0; mTexCoord[0].v = y0; - mTexCoord[1].u = x1; mTexCoord[1].v = y1; - mTexCoord[2].u = x2; mTexCoord[2].v = y2; + mTexCoord[0].x = x0; mTexCoord[0].y = y0; + mTexCoord[1].x = x1; mTexCoord[1].y = y1; + mTexCoord[2].x = x2; mTexCoord[2].y = y2; } void BatchRenderer::batchTriangleFan( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2 ) { @@ -738,9 +748,9 @@ void BatchRenderer::trianglesSetColorFree( const Color& Color0, const Color& Col } void BatchRenderer::trianglesSetTexCoord( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2 ) { - mTexCoord[0].u = x0; mTexCoord[0].v = y0; - mTexCoord[1].u = x1; mTexCoord[1].v = y1; - mTexCoord[2].u = x2; mTexCoord[2].v = y2; + mTexCoord[0].x = x0; mTexCoord[0].y = y0; + mTexCoord[1].x = x1; mTexCoord[1].y = y1; + mTexCoord[2].x = x2; mTexCoord[2].y = y2; } void BatchRenderer::batchTriangle( const Float& x0, const Float& y0, const Float& x1, const Float& y1, const Float& x2, const Float& y2 ) {