Fixed some bugs, added rounder rectangles.

This commit is contained in:
spartanj
2010-06-30 23:35:28 -03:00
parent c00a979022
commit 0048fa6dfb
22 changed files with 798 additions and 436 deletions

View File

@@ -37,7 +37,7 @@ void cBatchRenderer::Draw() {
void cBatchRenderer::SetTexture( const Uint32& TexId ) {
if ( mTexture != TexId )
Flush();
mTexture = TexId;
}
@@ -61,112 +61,112 @@ void cBatchRenderer::SetBlendMode( EE_BATCH_RENDER_METHOD Mode ) {
void cBatchRenderer::Flush() {
if ( mNumVertex == 0 )
return;
bool CreateMatrix = ( mRotation || mScale != 1.0f || mPosition.x || mPosition.y );
if ( mTexture > 0 )
cTextureFactory::instance()->Bind( mTexture );
else
glDisable( GL_TEXTURE_2D );
cTextureFactory::instance()->SetBlendFunc( mBlend );
if ( mCurrentMode == EE_GL_POINTS && mTexture > 0 ) {
glEnable( GL_POINT_SPRITE_ARB );
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
glPointSize( cTextureFactory::instance()->GetTextureWidth( mTexture ) );
}
if ( CreateMatrix ) {
glLoadIdentity();
glPushMatrix();
glTranslatef( mPosition.x, mPosition.y, 0.0f);
glTranslatef( mCenter.x, mCenter.y, 0.0f);
glRotatef( mRotation, 0.0f, 0.0f, 1.0f );
glScalef( mScale, mScale, 1.0f );
glTranslatef( -mCenter.x, -mCenter.y, 0.0f);
}
glVertexPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) );
glTexCoordPointer(2, GL_FLOAT, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) );
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(eeVertex), reinterpret_cast<char*> ( &mVertex[0] ) + sizeof(eeVector2f) + sizeof(eeTexCoord) );
glDrawArrays( mCurrentMode, 0, mNumVertex );
if ( CreateMatrix )
glPopMatrix();
if ( mCurrentMode == EE_GL_POINTS && mTexture > 0 ) {
glDisable( GL_POINT_SPRITE_ARB );
}
if ( mTexture == 0 )
glEnable( GL_TEXTURE_2D );
mNumVertex = 0;
}
void cBatchRenderer::BatchQuad( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle ) {
eeVector2f center;
if ( mNumVertex + 3 >= mVertex.size() )
return;
SetBlendMode( EE_GL_QUADS );
if ( angle ) {
center.x = x + width * 0.5f;
center.y = y + height * 0.5f;
}
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;
mTVertex->pos.y = y + height;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 2];
mTVertex->pos.x = x + width;
mTVertex->pos.y = y + height;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 3];
mTVertex->pos.x = x + width;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
Rotate(center, &mTVertex->pos, angle);
AddVertexs(4);
}
void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFloat& width, const eeFloat& height, const eeFloat& angle, const eeFloat& scale, const bool& scalefromcenter ) {
eeVector2f center;
eeFloat mx = x;
eeFloat my = y;
eeFloat mwidth = width;
eeFloat mheight = height;
if ( mNumVertex + 3 >= mVertex.size() )
return;
SetBlendMode( EE_GL_QUADS );
center.x = width * 0.5f;
center.y = height * 0.5f;
if ( scale != 1.0f ) {
if ( scalefromcenter ) {
mx = mx + center.x - center.x * scale;
@@ -175,38 +175,38 @@ void cBatchRenderer::BatchQuadEx( const eeFloat& x, const eeFloat& y, const eeFl
mwidth *= scale;
mheight *= scale;
}
center.x += x;
center.y += y;
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;
mTVertex->pos.y = my + mheight;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = mx + mwidth;
mTVertex->pos.y = my + mheight;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
Rotate(center, &mTVertex->pos, angle);
mTVertex = &mVertex[ mNumVertex + 3 ];
mTVertex->pos.x = mx + mwidth;
mTVertex->pos.y = my;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
Rotate(center, &mTVertex->pos, angle);
AddVertexs(4);
}
@@ -214,33 +214,33 @@ void cBatchRenderer::BatchQuadFree( const eeFloat& x0, const eeFloat& y0, const
if ( mNumVertex + 3 >= mVertex.size() )
return;
SetBlendMode( EE_GL_QUADS );
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 = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = x2;
mTVertex->pos.y = y2;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
mTVertex = &mVertex[ mNumVertex + 3 ];
mTVertex->pos.x = x3;
mTVertex->pos.y = y3;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
AddVertexs(4);
}
@@ -250,10 +250,10 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons
mQ.V[0].y = y0; mQ.V[1].y = y1; mQ.V[2].y = y2; mQ.V[3].y = y3;
eeFloat MinX = mQ.V[0].x, MaxX = mQ.V[0].x, MinY = mQ.V[0].y, MaxY = mQ.V[0].y;
eeVector2f QCenter;
if ( mNumVertex + 3 >= mVertex.size() )
return;
if ( Angle != 0 || Scale != 1.0f ) {
for (Uint8 i = 1; i < 4; i++ ) {
if ( MinX > mQ.V[i].x ) MinX = mQ.V[i].x;
@@ -261,54 +261,54 @@ void cBatchRenderer::BatchQuadFreeEx( const eeFloat& x0, const eeFloat& y0, cons
if ( MinY > mQ.V[i].y ) MinY = mQ.V[i].y;
if ( MaxY < mQ.V[i].y ) MaxY = mQ.V[i].y;
}
QCenter.x = MinX + ( MaxX - MinX ) * 0.5f;
QCenter.y = MinY + ( MaxY - MinY ) * 0.5f;
}
if ( Scale != 1.0f ) {
for (Uint8 i = 0; i < 4; i++ ) {
if ( mQ.V[i].x < QCenter.x )
mQ.V[i].x = QCenter.x - fabs(QCenter.x - mQ.V[i].x) * Scale;
else
mQ.V[i].x = QCenter.x + fabs(QCenter.x - mQ.V[i].x) * Scale;
if ( mQ.V[i].y < QCenter.y )
mQ.V[i].y = QCenter.y - fabs(QCenter.y - mQ.V[i].y) * Scale;
else
mQ.V[i].y = QCenter.y + fabs(QCenter.y - mQ.V[i].y) * Scale;
}
}
if ( Angle != 0 )
mQ = RotateQuadCentered( mQ, Angle, QCenter );
SetBlendMode( EE_GL_QUADS );
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[1].x;
mTVertex->pos.y = mQ[1].y;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = mQ[2].x;
mTVertex->pos.y = mQ[2].y;
mTVertex->tex = mTexCoord[2];
mTVertex->color = mVerColor[2];
mTVertex = &mVertex[ mNumVertex + 3 ];
mTVertex->pos.x = mQ[3].x;
mTVertex->pos.y = mQ[3].y;
mTVertex->tex = mTexCoord[3];
mTVertex->color = mVerColor[3];
AddVertexs(4);
}
@@ -366,15 +366,15 @@ void cBatchRenderer::PointSetColor( const eeColorA Color ) {
void cBatchRenderer::BatchPoint( const eeFloat& x, const eeFloat& y ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_POINTS );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
@@ -395,21 +395,21 @@ void cBatchRenderer::LinesSetColorFree( const eeColorA Color0, const eeColorA Co
void cBatchRenderer::BatchLine( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_LINES );
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 = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
AddVertexs(2);
}
@@ -430,24 +430,47 @@ void cBatchRenderer::LineLoopSetColorFree( const eeColorA Color0, const eeColorA
void cBatchRenderer::BatchLineLoop( const eeFloat& x0, const eeFloat& y0, const eeFloat& x1, const eeFloat& y1 ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_LINE_LOOP );
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 = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
AddVertexs(2);
}
void cBatchRenderer::BatchLineLoop( const eeVector2f& vector1, const eeVector2f& vector2 ) {
BatchLineLoop( vector1.x, vector1.y, vector2.x, vector2.y );
}
void cBatchRenderer::BatchLineLoop( const eeFloat& x0, const eeFloat& y0 ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_LINE_LOOP );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x0;
mTVertex->pos.y = y0;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
void cBatchRenderer::BatchLineLoop( const eeVector2f& vector1 ) {
BatchLineLoop( vector1.x, vector1.y );
}
void cBatchRenderer::TriangleFanBegin() {
SetBlendMode( EE_GL_TRIANGLE_FAN );
TriangleFanSetSubset( 0, 0, 0, 1, 1, 1 );
@@ -472,21 +495,21 @@ void cBatchRenderer::BatchTriangleFan( const eeFloat& x0, const eeFloat& y0, con
if ( mNumVertex + 2 >= mVertex.size() )
return;
SetBlendMode( EE_GL_TRIANGLE_FAN );
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 = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = x2;
mTVertex->pos.y = y2;
@@ -520,21 +543,21 @@ void cBatchRenderer::BatchTriangle( const eeFloat& x0, const eeFloat& y0, const
if ( mNumVertex + 2 >= mVertex.size() )
return;
SetBlendMode( EE_GL_TRIANGLES );
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 = x1;
mTVertex->pos.y = y1;
mTVertex->tex = mTexCoord[1];
mTVertex->color = mVerColor[1];
mTVertex = &mVertex[ mNumVertex + 2 ];
mTVertex->pos.x = x2;
mTVertex->pos.y = y2;
@@ -551,21 +574,40 @@ void cBatchRenderer::PolygonSetColor( const eeColorA& Color ) {
void cBatchRenderer::BatchPolygon( const eePolygon2f& Polygon ) {
if ( Polygon.Size() > mVertex.size() )
return;
SetBlendMode( EE_GL_POLYGON );
for ( Uint32 i = 0; i < Polygon.Size(); i++ ) {
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = Polygon.X() + Polygon[i].x;
mTVertex->pos.y = Polygon.Y() + Polygon[i].y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
}
void cBatchRenderer::BatchPolygonByPoint( const eeFloat& x, const eeFloat& y ) {
if ( mNumVertex + 1 >= mVertex.size() )
return;
SetBlendMode( EE_GL_POLYGON );
mTVertex = &mVertex[ mNumVertex ];
mTVertex->pos.x = x;
mTVertex->pos.y = y;
mTVertex->tex = mTexCoord[0];
mTVertex->color = mVerColor[0];
AddVertexs(1);
}
void cBatchRenderer::BatchPolygonByPoint( const eeVector2f& Vector ) {
BatchPolygonByPoint( Vector.x, Vector.y );
}
void cBatchRenderer::SetLineWidth( const eeFloat& lineWidth ) {
glLineWidth( lineWidth );
}