From b6fd66beac63a778b1fa357033edd036ee8ee1c4 Mon Sep 17 00:00:00 2001 From: spartanj Date: Sun, 22 Aug 2010 04:02:51 -0300 Subject: [PATCH] Added support for OpenGL ES rendering ( not implemented really, just modified some renderings to render for OpenGL ES compilant code ). --- src/base.hpp | 4 ++ src/gaming/cisomap.cpp | 4 ++ src/graphics/cbatchrenderer.cpp | 120 ++++++++++++++++++++++++++++++++ src/graphics/cfont.cpp | 28 ++++++-- 4 files changed, 152 insertions(+), 4 deletions(-) diff --git a/src/base.hpp b/src/base.hpp index 21b410d7c..015df9b51 100644 --- a/src/base.hpp +++ b/src/base.hpp @@ -103,6 +103,10 @@ namespace EE { const eeFloat PId180 = PI / 180.f; const eeFloat d180PI = 180.f / PI; + #ifdef EE_GLES + const GLubyte EE_GLES_INDICES [] = {0, 3, 1, 2}; + #endif + using namespace std; } diff --git a/src/gaming/cisomap.cpp b/src/gaming/cisomap.cpp index 424d69abc..8520c0351 100755 --- a/src/gaming/cisomap.cpp +++ b/src/gaming/cisomap.cpp @@ -155,7 +155,11 @@ void cIsoMap::Draw() { glVertexPointer( 2, GL_FLOAT, 0, reinterpret_cast( T ) + sizeof(eeColor) * 4 ); glTexCoordPointer( 2, GL_FLOAT, 0, reinterpret_cast( &TexCoords[0] ) ); + #ifndef EE_GLES glDrawArrays( GL_QUADS, 0, 4 ); + #else + glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, EE_GLES_INDICES ); + #endif if ( TileAABB.Contains( MouseMapPos ) ) { if ( IntersectQuad2( T->Q, eeQuad2f( MouseMapPos, MouseMapPos, MouseMapPos, MouseMapPos ) ) ) { diff --git a/src/graphics/cbatchrenderer.cpp b/src/graphics/cbatchrenderer.cpp index f49231c61..a7e1b5160 100755 --- a/src/graphics/cbatchrenderer.cpp +++ b/src/graphics/cbatchrenderer.cpp @@ -141,6 +141,7 @@ void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloa center.y = y + height * 0.5f; } +#ifndef EE_GLES SetBlendMode( EE_GL_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; @@ -170,6 +171,37 @@ void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloa mTVertex->tex = mTexCoord[3]; mTVertex->color = mVerColor[3]; Rotate(center, &mTVertex->pos, angle); +#else + SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + + mTVertex = &mVertex[ mNumVertex ]; + mTVertex->pos.x = x; + mTVertex->pos.y = y; + mTVertex->tex = mTexCoord[0]; + mTVertex->color = mVerColor[0]; + Rotate(center, &mTVertex->pos, angle); + + mTVertex = &mVertex[ mNumVertex + 1 ]; + mTVertex->pos.x = x + width; + mTVertex->pos.y = y; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + Rotate(center, &mTVertex->pos, angle); + + mTVertex = &mVertex[ mNumVertex + 2 ]; + mTVertex->pos.x = x; + mTVertex->pos.y = y + height; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + Rotate(center, &mTVertex->pos, angle); + + mTVertex = &mVertex[ mNumVertex + 3 ]; + mTVertex->pos.x = x + width; + mTVertex->pos.y = y + height; + mTVertex->tex = mTexCoord[2]; + mTVertex->color = mVerColor[2]; + Rotate(center, &mTVertex->pos, angle); +#endif AddVertexs(4); } @@ -199,6 +231,7 @@ void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFl center.x += x; center.y += y; +#ifndef EE_GLES SetBlendMode( EE_GL_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; @@ -228,6 +261,37 @@ void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFl mTVertex->tex = mTexCoord[3]; mTVertex->color = mVerColor[3]; Rotate(center, &mTVertex->pos, angle); +#else + SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + + mTVertex = &mVertex[ mNumVertex ]; + mTVertex->pos.x = mx; + mTVertex->pos.y = my; + mTVertex->tex = mTexCoord[0]; + mTVertex->color = mVerColor[0]; + Rotate(center, &mTVertex->pos, angle); + + mTVertex = &mVertex[ mNumVertex + 1 ]; + mTVertex->pos.x = mx + mwidth; + mTVertex->pos.y = my; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + Rotate(center, &mTVertex->pos, angle); + + mTVertex = &mVertex[ mNumVertex + 2 ]; + mTVertex->pos.x = mx; + mTVertex->pos.y = my + mheight; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + Rotate(center, &mTVertex->pos, angle); + + mTVertex = &mVertex[ mNumVertex + 3 ]; + mTVertex->pos.x = mx + mwidth; + mTVertex->pos.y = my + mheight; + mTVertex->tex = mTexCoord[2]; + mTVertex->color = mVerColor[2]; + Rotate(center, &mTVertex->pos, angle); +#endif AddVertexs(4); } @@ -236,6 +300,7 @@ void cBatchRenderer::BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const if ( mNumVertex + 3 >= mVertex.size() ) return; +#ifndef EE_GLES SetBlendMode( EE_GL_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; @@ -261,6 +326,33 @@ void cBatchRenderer::BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const mTVertex->pos.y = y3; mTVertex->tex = mTexCoord[3]; mTVertex->color = mVerColor[3]; +#else + SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + + mTVertex = &mVertex[ mNumVertex ]; + mTVertex->pos.x = x0; + mTVertex->pos.y = y0; + mTVertex->tex = mTexCoord[0]; + mTVertex->color = mVerColor[0]; + + mTVertex = &mVertex[ mNumVertex + 1 ]; + mTVertex->pos.x = x3; + mTVertex->pos.y = y3; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + + mTVertex = &mVertex[ mNumVertex + 2 ]; + mTVertex->pos.x = x1; + mTVertex->pos.y = y1; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + + mTVertex = &mVertex[ mNumVertex + 3 ]; + mTVertex->pos.x = x2; + mTVertex->pos.y = y2; + mTVertex->tex = mTexCoord[2]; + mTVertex->color = mVerColor[2]; +#endif AddVertexs(4); } @@ -304,6 +396,7 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons if ( Angle != 0 ) mQ = RotateQuadCentered( mQ, Angle, QCenter ); +#ifndef EE_GLES SetBlendMode( EE_GL_QUADS, mForceBlendMode ); mTVertex = &mVertex[ mNumVertex ]; @@ -329,6 +422,33 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons mTVertex->pos.y = mQ[3].y; mTVertex->tex = mTexCoord[3]; mTVertex->color = mVerColor[3]; +#else + SetBlendMode( EE_GL_TRIANGLE_STRIP, mForceBlendMode ); + + mTVertex = &mVertex[ mNumVertex ]; + mTVertex->pos.x = mQ[0].x; + mTVertex->pos.y = mQ[0].y; + mTVertex->tex = mTexCoord[0]; + mTVertex->color = mVerColor[0]; + + mTVertex = &mVertex[ mNumVertex + 1 ]; + mTVertex->pos.x = mQ[3].x; + mTVertex->pos.y = mQ[3].y; + mTVertex->tex = mTexCoord[3]; + mTVertex->color = mVerColor[3]; + + mTVertex = &mVertex[ mNumVertex + 2 ]; + mTVertex->pos.x = mQ[1].x; + mTVertex->pos.y = mQ[1].y; + mTVertex->tex = mTexCoord[1]; + mTVertex->color = mVerColor[1]; + + mTVertex = &mVertex[ mNumVertex + 3 ]; + mTVertex->pos.x = mQ[2].x; + mTVertex->pos.y = mQ[2].y; + mTVertex->tex = mTexCoord[2]; + mTVertex->color = mVerColor[2]; +#endif AddVertexs(4); } diff --git a/src/graphics/cfont.cpp b/src/graphics/cfont.cpp index e63054452..77fe68f29 100644 --- a/src/graphics/cfont.cpp +++ b/src/graphics/cfont.cpp @@ -225,6 +225,14 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con numvert++; } + #ifdef EE_GLES + glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast( &Colors[0] ) ); + glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[ numvert - 4 ] ) ); + glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[ numvert - 4 ] ) + sizeof(eeFloat) * 2 ); + + glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, EE_GLES_INDICES ); + #endif + if (mVerticalDraw) nY += GetFontHeight(); else @@ -232,11 +240,13 @@ void cFont::Draw( cTextCache& TextCache, const eeFloat& X, const eeFloat& Y, con } } + #ifndef EE_GLES glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast( &Colors[0] ) ); glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[0] ) ); glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &RenderCoords[0] ) + sizeof(eeFloat) * 2 ); glDrawArrays( GL_QUADS, 0, numvert ); + #endif if ( Angle != 0.0f || Scale != 1.0f ) glPopMatrix(); @@ -336,13 +346,21 @@ void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& break; default: for ( Uint8 z = 0; z < 8; z+=2 ) { - mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[z]; - mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ z + 1 ]; - mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[z] + nX; - mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ z + 1 ] + nY; + mRenderCoords[ numvert ].TexCoords[0] = C->TexCoords[z]; + mRenderCoords[ numvert ].TexCoords[1] = C->TexCoords[ z + 1 ]; + mRenderCoords[ numvert ].Vertex[0] = cX + C->Vertex[z] + nX; + mRenderCoords[ numvert ].Vertex[1] = cY + C->Vertex[ z + 1 ] + nY; numvert++; } + #ifdef EE_GLES + glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast( &mColors[0] ) ); + glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &mRenderCoords[ numvert - 4 ] ) ); + glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &mRenderCoords[ numvert - 4 ] ) + sizeof(eeFloat) * 2 ); + + glDrawElements( GL_TRIANGLE_STRIP, 4, GL_UNSIGNED_BYTE, EE_GLES_INDICES ); + #endif + if (mVerticalDraw) nY += GetFontHeight(); else @@ -350,11 +368,13 @@ void cFont::SubDraw( const std::wstring& Text, const eeFloat& X, const eeFloat& } } + #ifndef EE_GLES glColorPointer( 4, GL_UNSIGNED_BYTE, 0, reinterpret_cast( &mColors[0] ) ); glTexCoordPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &mRenderCoords[0] ) ); glVertexPointer( 2, GL_FLOAT, sizeof(eeVertexCoords), reinterpret_cast( &mRenderCoords[0] ) + sizeof(eeFloat) * 2 ); glDrawArrays( GL_QUADS, 0, numvert ); + #endif if ( Angle != 0.0f || Scale != 1.0f ) glPopMatrix();