Add PerformMultiTris to draw many texturized triangles at once

issue1247
Armin Burgmeier 2014-10-08 13:35:55 -04:00
parent 2e03c3157b
commit b06e10e03b
4 changed files with 40 additions and 19 deletions

View File

@ -43,15 +43,6 @@ inline DWORD GetTextShadowClr(DWORD dwTxtClr)
return RGBA(((dwTxtClr >> 0) % 256) / 3, ((dwTxtClr >> 8) % 256) / 3, ((dwTxtClr >> 16) % 256) / 3, (dwTxtClr >> 24) % 256);
}
inline void DwTo4UB(DWORD dwClr, unsigned char (&r)[4])
{
//unsigned char r[4];
r[0] = GLubyte( (dwClr >> 16) & 0xff);
r[1] = GLubyte( (dwClr >> 8) & 0xff);
r[2] = GLubyte( (dwClr ) & 0xff);
r[3] = GLubyte( (dwClr >> 24) & 0xff);
}
void C4BltTransform::SetRotate(float iAngle, float fOffX, float fOffY) // set by angle and rotation offset
{
// iAngle is in degrees (cycling from 0 to 360)

View File

@ -30,6 +30,15 @@
// Global Draw access pointer
extern C4Draw *pDraw;
inline void DwTo4UB(DWORD dwClr, unsigned char (&r)[4])
{
//unsigned char r[4];
r[0] = (unsigned char)( (dwClr >> 16) & 0xff);
r[1] = (unsigned char)( (dwClr >> 8) & 0xff);
r[2] = (unsigned char)( (dwClr ) & 0xff);
r[3] = (unsigned char)( (dwClr >> 24) & 0xff);
}
// rotation info class
class C4BltTransform
{
@ -252,6 +261,7 @@ public:
// Drawing
virtual void PerformMultiPix(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices) = 0;
virtual void PerformMultiLines(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices, float width) = 0;
virtual void PerformMultiTris(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices, C4TexRef* pTex) = 0; // blit the same texture many times
void DrawBoxDw(C4Surface * sfcDest, int iX1, int iY1, int iX2, int iY2, DWORD dwClr); // calls DrawBoxFade
void DrawBoxFade(C4Surface * sfcDest, float iX, float iY, float iWdt, float iHgt, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4, int iBoxOffX, int iBoxOffY); // calls DrawQuadDw
void DrawPatternedCircle(C4Surface * sfcDest, int x, int y, int r, BYTE col, C4Pattern & Pattern, CStdPalette &rPal);

View File

@ -140,16 +140,6 @@ C4DrawGLProgram::~C4DrawGLProgram()
glDeleteObjectARB(Program);
}
// GLubyte (&r)[4] is a reference to an array of four bytes named r.
static void DwTo4UB(DWORD dwClr, GLubyte (&r)[4])
{
//unsigned char r[4];
r[0] = GLubyte(dwClr>>16);
r[1] = GLubyte(dwClr>>8);
r[2] = GLubyte(dwClr);
r[3] = GLubyte(dwClr>>24);
}
CStdGL::CStdGL():
pMainCtx(0)
{
@ -903,6 +893,35 @@ void CStdGL::PerformMultiLines(C4Surface* sfcTarget, const C4BltVertex* vertices
ResetMultiBlt(lines_tex);
}
void CStdGL::PerformMultiTris(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices, C4TexRef* pTex)
{
// Only direct rendering
assert(sfcTarget->IsRenderTarget());
if(!PrepareRendering(sfcTarget)) return;
// Feed the vertices to the GL
SetupMultiBlt(pTex ? pTex->texName : 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
if(pTex)
{
glClientActiveTexture(GL_TEXTURE0); // pTex was loaded in tex0 by SetupMultiBlt
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(2, GL_FLOAT, sizeof(C4BltVertex), &vertices[0].tx);
}
glVertexPointer(2, GL_FLOAT, sizeof(C4BltVertex), &vertices[0].ftx);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(C4BltVertex), &vertices[0].color[0]);
glDrawArrays(GL_TRIANGLES, 0, n_vertices);
if(pTex) glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
ResetMultiBlt(pTex ? pTex->texName : 0);
}
static void DefineShaderARB(const char * p, GLuint & s)
{
glBindProgramARB (GL_FRAGMENT_PROGRAM_ARB, s);

View File

@ -166,6 +166,7 @@ public:
void DrawQuadDw(C4Surface * sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4);
void PerformMultiPix(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices);
void PerformMultiLines(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices, float width);
void PerformMultiTris(C4Surface* sfcTarget, const C4BltVertex* vertices, unsigned int n_vertices, C4TexRef* pTex);
// device objects
bool RestoreDeviceObjects(); // restore device dependent objects
bool InvalidateDeviceObjects(); // free device dependent objects