DXGL r607 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r606‎ | r607 | r608 >
Date:18:29, 12 April 2015
Author:admin
Status:new
Tags:
Comment:
Convert glUtil to C struct and linkage with reference count.
Modified paths:
  • /ddraw/BufferObject.cpp (modified) (history)
  • /ddraw/BufferObject.h (modified) (history)
  • /ddraw/glExtensions.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glRenderer.h (modified) (history)
  • /ddraw/glUtil.cpp (modified) (history)
  • /ddraw/glUtil.h (modified) (history)

Diff [purge]

Index: ddraw/BufferObject.cpp
@@ -21,7 +21,7 @@
2222
2323 extern "C" {
2424
25 -void BufferObject_Create(BufferObject **out, glExtensions *ext, glUtil *util)
 25+void BufferObject_Create(BufferObject **out, glExtensions *ext, struct glUtil *util)
2626 {
2727 BufferObject *buffer = (BufferObject*)malloc(sizeof(BufferObject));
2828 if (!buffer)
@@ -30,8 +30,10 @@
3131 return;
3232 }
3333 ZeroMemory(buffer, sizeof(BufferObject));
 34+ buffer->refcount = 1;
3435 buffer->ext = ext;
3536 buffer->util = util;
 37+ glUtil_AddRef(util);
3638 ext->glGenBuffers(1, &buffer->buffer);
3739 *out = buffer;
3840 }
@@ -47,6 +49,7 @@
4850 if (!This->refcount)
4951 {
5052 This->ext->glDeleteBuffers(1, &This->buffer);
 53+ glUtil_Release(This->util);
5154 free(This);
5255 }
5356 }
@@ -63,19 +66,19 @@
6467 }
6568 else
6669 {
67 - This->util->BindBuffer(This, target);
 70+ glUtil_BindBuffer(This->util, This, target);
6871 This->ext->glBufferData(target, size, data, usage);
69 - This->util->UndoBindBuffer(target);
 72+ glUtil_UndoBindBuffer(This->util, target);
7073 }
7174 }
7275
7376 void BufferObject_Bind(BufferObject *This, GLenum target)
7477 {
75 - This->util->BindBuffer(This, target);
 78+ glUtil_BindBuffer(This->util, This, target);
7679 }
7780 void BufferObject_Unbind(BufferObject *This, GLenum target)
7881 {
79 - This->util->BindBuffer(NULL, target);
 82+ glUtil_BindBuffer(This->util, NULL, target);
8083 }
8184
8285 void *BufferObject_Map(BufferObject *This, GLenum target, GLenum access)
@@ -91,9 +94,9 @@
9295 }
9396 else
9497 {
95 - This->util->BindBuffer(This, target);
 98+ glUtil_BindBuffer(This->util, This, target);
9699 ptr = This->ext->glMapBuffer(target, access);
97 - This->util->UndoBindBuffer(target);
 100+ glUtil_UndoBindBuffer(This->util, target);
98101 }
99102 return ptr;
100103 }
@@ -110,9 +113,9 @@
111114 }
112115 else
113116 {
114 - This->util->BindBuffer(This, target);
 117+ glUtil_BindBuffer(This->util, This, target);
115118 ret = This->ext->glUnmapBuffer(target);
116 - This->util->UndoBindBuffer(target);
 119+ glUtil_UndoBindBuffer(This->util, target);
117120 }
118121 return ret;
119122 }
Index: ddraw/BufferObject.h
@@ -21,11 +21,9 @@
2222
2323 #ifdef __cplusplus
2424 extern "C" {
25 -class glUtil;
26 -#else
27 -typedef int glUtil;
2825 #endif
2926
 27+struct glUtil;
3028
3129 typedef struct BufferObject
3230 {
@@ -38,10 +36,10 @@
3937 BOOL bound;
4038 BOOL target;
4139 glExtensions *ext;
42 - glUtil *util;
 40+ struct glUtil *util;
4341 } BufferObject;
4442
45 -void BufferObject_Create(BufferObject **out, glExtensions *ext, glUtil *util);
 43+void BufferObject_Create(BufferObject **out, glExtensions *ext, struct glUtil *util);
4644 void BufferObject_AddRef(BufferObject *This);
4745 void BufferObject_Release(BufferObject *This);
4846 void BufferObject_SetData(BufferObject *This, GLenum target, GLsizeiptr size, GLvoid *data, GLenum usage);
Index: ddraw/glExtensions.h
@@ -34,7 +34,7 @@
3535 extern "C" {
3636 #endif
3737
38 -typedef struct
 38+typedef struct glExtensions
3939 {
4040 GLuint(APIENTRY *glCreateShader) (GLenum type);
4141 void (APIENTRY *glShaderSource) (GLuint shader, GLsizei count, const GLchar* const* string, const GLint* length);
Index: ddraw/glRenderer.cpp
@@ -889,7 +889,7 @@
890890 ZeroMemory(&This->dib,sizeof(DIB));
891891 }
892892 TextureManager_DeleteSamplers(This->texman);
893 - This->util->DeleteFBO(&This->fbo);
 893+ glUtil_DeleteFBO(This->util, &This->fbo);
894894 if(This->pbo)
895895 {
896896 BufferObject_Release(This->pbo);
@@ -904,10 +904,10 @@
905905 This->backy = 0;
906906 }
907907 ShaderManager_Delete(This->shaders);
 908+ glUtil_Release(This->util);
908909 free(This->shaders);
909910 free(This->texman);
910911 free(This->ext);
911 - delete This->util;
912912 This->ext = NULL;
913913 wglMakeCurrent(NULL,NULL);
914914 wglDeleteContext(This->hRC);
@@ -1082,21 +1082,21 @@
10831083 LeaveCriticalSection(&dll_cs);
10841084 This->ext = (glExtensions *)malloc(sizeof(glExtensions));
10851085 glExtensions_Init(This->ext);
1086 - This->util = new glUtil(This->ext);
 1086+ glUtil_Create(This->ext, &This->util);
10871087 glRenderer__SetSwap(This,1);
10881088 glFinish();
10891089 DXGLTimer_Init(&This->timer);
10901090 DXGLTimer_Calibrate(&This->timer, height, frequency);
10911091 glRenderer__SetSwap(This,0);
1092 - This->util->SetViewport(0,0,width,height);
 1092+ glUtil_SetViewport(This->util,0,0,width,height);
10931093 glViewport(0,0,width,height);
1094 - This->util->SetDepthRange(0.0,1.0);
1095 - This->util->DepthWrite(true);
1096 - This->util->DepthTest(false);
1097 - This->util->MatrixMode(GL_MODELVIEW);
 1094+ glUtil_SetDepthRange(This->util,0.0,1.0);
 1095+ glUtil_DepthWrite(This->util,TRUE);
 1096+ glUtil_DepthTest(This->util,FALSE);
 1097+ glUtil_MatrixMode(This->util,GL_MODELVIEW);
10981098 glDisable(GL_DEPTH_TEST);
10991099 glDisable(GL_DITHER);
1100 - This->util->SetDepthComp(GL_LESS);
 1100+ glUtil_SetDepthComp(This->util,GL_LESS);
11011101 const GLubyte *glver = glGetString(GL_VERSION);
11021102 This->gl_caps.Version = (GLfloat)atof((char*)glver);
11031103 if(This->gl_caps.Version >= 2)
@@ -1109,18 +1109,18 @@
11101110 This->shaders = (ShaderManager*)malloc(sizeof(ShaderManager));
11111111 ShaderManager_Init(This->ext, This->shaders);
11121112 This->fbo.fbo = 0;
1113 - This->util->InitFBO(&This->fbo);
1114 - This->util->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
1115 - This->util->ClearDepth(1.0);
1116 - This->util->ClearStencil(0);
1117 - This->util->EnableArray(-1,false);
1118 - This->util->BlendFunc(GL_ONE,GL_ZERO);
1119 - This->util->BlendEnable(false);
 1113+ glUtil_InitFBO(This->util,&This->fbo);
 1114+ glUtil_ClearColor(This->util, 0.0f, 0.0f, 0.0f, 0.0f);
 1115+ glUtil_ClearDepth(This->util, 1.0);
 1116+ glUtil_ClearStencil(This->util, 0);
 1117+ glUtil_EnableArray(This->util,-1,FALSE);
 1118+ glUtil_BlendFunc(This->util,GL_ONE,GL_ZERO);
 1119+ glUtil_BlendEnable(This->util,FALSE);
11201120 glClear(GL_COLOR_BUFFER_BIT);
11211121 glFlush();
1122 - This->util->SetScissor(false,0,0,0,0);
 1122+ glUtil_SetScissor(This->util,FALSE,0,0,0,0);
11231123 glDisable(GL_SCISSOR_TEST);
1124 - This->util->SetCull(D3DCULL_CCW);
 1124+ glUtil_SetCull(This->util,D3DCULL_CCW);
11251125 glEnable(GL_CULL_FACE);
11261126 SwapBuffers(This->hDC);
11271127 This->texman = TextureManager_Create(This->ext);
@@ -1129,11 +1129,11 @@
11301130 glRenderer__SetFogStart(This,0);
11311131 glRenderer__SetFogEnd(This,1);
11321132 glRenderer__SetFogDensity(This,1);
1133 - This->util->SetPolyMode(D3DFILL_SOLID);
1134 - This->util->SetShadeMode(D3DSHADE_GOURAUD);
 1133+ glUtil_SetPolyMode(This->util, D3DFILL_SOLID);
 1134+ glUtil_SetShadeMode(This->util, D3DSHADE_GOURAUD);
11351135 if(hWnd)
11361136 {
1137 - This->dib.enabled = true;
 1137+ This->dib.enabled = TRUE;
11381138 This->dib.width = width;
11391139 This->dib.height = height;
11401140 This->dib.pitch = (((width<<3)+31)&~31) >>3;
@@ -1390,18 +1390,18 @@
13911391 }
13921392 ShaderManager_SetShader(This->shaders, shaderid, NULL, 1);
13931393 GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
1394 - This->util->BlendEnable(false);
 1394+ glUtil_BlendEnable(This->util, FALSE);
13951395 do
13961396 {
1397 - if (This->util->SetFBO(dest) == GL_FRAMEBUFFER_COMPLETE) break;
 1397+ if (glUtil_SetFBOSurface(This->util, dest) == GL_FRAMEBUFFER_COMPLETE) break;
13981398 if (!dest->texture->internalformats[1]) break;
13991399 TextureManager_FixTexture(This->texman, dest->texture, (dest->bigbuffer ? dest->bigbuffer : dest->buffer), &dest->dirty, dest->miplevel);
1400 - This->util->SetFBO((FBO*)NULL);
 1400+ glUtil_SetFBO(This->util, NULL);
14011401 dest->fbo.fbcolor = NULL;
14021402 dest->fbo.fbz = NULL;
14031403 } while (1);
1404 - This->util->SetViewport(0,0,dest->fakex,dest->fakey);
1405 - This->util->DepthTest(false);
 1404+ glUtil_SetViewport(This->util,0,0,dest->fakex,dest->fakey);
 1405+ glUtil_DepthTest(This->util, FALSE);
14061406 DDSURFACEDESC2 ddsdSrc;
14071407 ddsdSrc.dwSize = sizeof(DDSURFACEDESC2);
14081408 if(src) src->GetSurfaceDesc(&ddsdSrc);
@@ -1477,8 +1477,8 @@
14781478 {
14791479 TextureManager_SetTexture(This->texman, 3, dest->stencil);
14801480 This->ext->glUniform1i(shader->shader.uniforms[4],3);
1481 - This->util->EnableArray(shader->shader.attribs[5],true);
1482 - This->ext->glVertexAttribPointer(shader->shader.attribs[5], 2, GL_FLOAT, false, sizeof(BltVertex), &This->bltvertices[0].stencils);
 1481+ glUtil_EnableArray(This->util, shader->shader.attribs[5], TRUE);
 1482+ This->ext->glVertexAttribPointer(shader->shader.attribs[5], 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &This->bltvertices[0].stencils);
14831483 }
14841484 if(src)
14851485 {
@@ -1497,22 +1497,22 @@
14981498 if(dest) This->ext->glUniform4i(shader->shader.uniforms[11], dest->texture->colorsizes[0], dest->texture->colorsizes[1],
14991499 dest->texture->colorsizes[2], dest->texture->colorsizes[3]);
15001500 dest->dirty |= 2;
1501 - This->util->EnableArray(shader->shader.attribs[0],true);
1502 - This->ext->glVertexAttribPointer(shader->shader.attribs[0],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].x);
 1501+ glUtil_EnableArray(This->util, shader->shader.attribs[0], TRUE);
 1502+ This->ext->glVertexAttribPointer(shader->shader.attribs[0],2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].x);
15031503 if(!(dwFlags & DDBLT_COLORFILL))
15041504 {
1505 - This->util->EnableArray(shader->shader.attribs[3],true);
1506 - This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
 1505+ glUtil_EnableArray(This->util, shader->shader.attribs[3], TRUE);
 1506+ This->ext->glVertexAttribPointer(shader->shader.attribs[3],2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].s);
15071507 }
15081508 if (usedest)
15091509 {
1510 - This->util->EnableArray(shader->shader.attribs[4], true);
1511 - This->ext->glVertexAttribPointer(shader->shader.attribs[4],2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].dests);
 1510+ glUtil_EnableArray(This->util, shader->shader.attribs[4], TRUE);
 1511+ This->ext->glVertexAttribPointer(shader->shader.attribs[4],2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].dests);
15121512 }
1513 - This->util->SetCull(D3DCULL_NONE);
1514 - This->util->SetPolyMode(D3DFILL_SOLID);
 1513+ glUtil_SetCull(This->util, D3DCULL_NONE);
 1514+ glUtil_SetPolyMode(This->util, D3DFILL_SOLID);
15151515 This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
1516 - This->util->SetFBO((FBO*)NULL);
 1516+ glUtil_SetFBO(This->util, NULL);
15171517 if(((ddsd.ddsCaps.dwCaps & (DDSCAPS_FRONTBUFFER)) &&
15181518 (ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE)) ||
15191519 ((ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE) &&
@@ -1552,11 +1552,11 @@
15531553 This->backx = x;
15541554 This->backy = y;
15551555 }
1556 - This->util->SetFBO(&This->fbo,This->backbuffer,0,false);
 1556+ glUtil_SetFBOTextures(This->util,&This->fbo,This->backbuffer,0,FALSE);
15571557 view[0] = view[2] = 0;
15581558 view[1] = (GLfloat)x;
15591559 view[3] = (GLfloat)y;
1560 - This->util->SetViewport(0,0,x,y);
 1560+ glUtil_SetViewport(This->util,0,0,x,y);
15611561 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
15621562 TextureManager_SetTexture(This->texman,0,*texture);
15631563 *texture = This->backbuffer;
@@ -1567,14 +1567,14 @@
15681568 This->bltvertices[0].y = This->bltvertices[1].y = This->bltvertices[1].x = This->bltvertices[3].x = 0.;
15691569 This->bltvertices[0].x = This->bltvertices[2].x = (float)x;
15701570 This->bltvertices[2].y = This->bltvertices[3].y = (float)y;
1571 - This->util->EnableArray(This->shaders->shaders[progtype].pos,true);
1572 - This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos,2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].x);
1573 - This->util->EnableArray(This->shaders->shaders[progtype].texcoord,true);
1574 - This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord,2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
1575 - This->util->SetCull(D3DCULL_NONE);
1576 - This->util->SetPolyMode(D3DFILL_SOLID);
 1571+ glUtil_EnableArray(This->util,This->shaders->shaders[progtype].pos,TRUE);
 1572+ This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos,2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].x);
 1573+ glUtil_EnableArray(This->util,This->shaders->shaders[progtype].texcoord,TRUE);
 1574+ This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord,2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].s);
 1575+ glUtil_SetCull(This->util,D3DCULL_NONE);
 1576+ glUtil_SetPolyMode(This->util,D3DFILL_SOLID);
15771577 This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
1578 - This->util->SetFBO((FBO*)NULL);
 1578+ glUtil_SetFBO(This->util, NULL);
15791579 }
15801580
15811581 void glRenderer__DrawBackbufferRect(glRenderer *This, TEXTURE *texture, RECT srcrect, int progtype)
@@ -1606,14 +1606,14 @@
16071607 This->backx = x;
16081608 This->backy = y;
16091609 }
1610 - This->util->SetFBO(&This->fbo, This->backbuffer, 0, false);
 1610+ glUtil_SetFBOTextures(This->util, &This->fbo, This->backbuffer, 0, FALSE);
16111611 view[0] = view[2] = 0;
16121612 view[1] = (GLfloat)This->backx;
16131613 view[3] = (GLfloat)This->backy;
1614 - This->util->SetViewport(0, 0, This->backx, This->backy);
1615 - This->util->SetScissor(true, 0, 0, This->backx, This->backy);
 1614+ glUtil_SetViewport(This->util, 0, 0, This->backx, This->backy);
 1615+ glUtil_SetScissor(This->util, TRUE, 0, 0, This->backx, This->backy);
16161616 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1617 - This->util->SetScissor(false, 0, 0, 0, 0);
 1617+ glUtil_SetScissor(This->util, FALSE, 0, 0, 0, 0);
16181618 TextureManager_SetTexture(This->texman, 0, texture);
16191619 This->ext->glUniform4f(This->shaders->shaders[progtype].view, view[0], view[1], view[2], view[3]);
16201620 This->bltvertices[1].s = This->bltvertices[3].s = (GLfloat)srcrect.left / (GLfloat)texture->width;
@@ -1624,14 +1624,14 @@
16251625 This->bltvertices[0].x = This->bltvertices[2].x = (float)x;
16261626 This->bltvertices[0].y = This->bltvertices[1].y = 0.;
16271627 This->bltvertices[2].y = This->bltvertices[3].y = (float)y;
1628 - This->util->EnableArray(This->shaders->shaders[progtype].pos, true);
1629 - This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos, 2, GL_FLOAT, false, sizeof(BltVertex), &This->bltvertices[0].x);
1630 - This->util->EnableArray(This->shaders->shaders[progtype].texcoord, true);
1631 - This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord, 2, GL_FLOAT, false, sizeof(BltVertex), &This->bltvertices[0].s);
1632 - This->util->SetCull(D3DCULL_NONE);
1633 - This->util->SetPolyMode(D3DFILL_SOLID);
 1628+ glUtil_EnableArray(This->util, This->shaders->shaders[progtype].pos, TRUE);
 1629+ This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos, 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &This->bltvertices[0].x);
 1630+ glUtil_EnableArray(This->util, This->shaders->shaders[progtype].texcoord, TRUE);
 1631+ This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord, 2, GL_FLOAT, GL_FALSE, sizeof(BltVertex), &This->bltvertices[0].s);
 1632+ glUtil_SetCull(This->util, D3DCULL_NONE);
 1633+ glUtil_SetPolyMode(This->util, D3DFILL_SOLID);
16341634 This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP, 0, 3, 4, GL_UNSIGNED_SHORT, bltindices);
1635 - This->util->SetFBO((FBO*)NULL);
 1635+ glUtil_SetFBO(This->util, NULL);
16361636 }
16371637
16381638 void glRenderer__DrawScreen(glRenderer *This, TEXTURE *texture, TEXTURE *paltex, glDirectDrawSurface7 *dest, glDirectDrawSurface7 *src, GLint vsync, bool setsync)
@@ -1638,7 +1638,7 @@
16391639 {
16401640 int progtype;
16411641 RECT r,r2;
1642 - This->util->BlendEnable(false);
 1642+ glUtil_BlendEnable(This->util, FALSE);
16431643 if((dest->ddsd.ddsCaps.dwCaps & DDSCAPS_PRIMARYSURFACE))
16441644 {
16451645 GetClientRect(This->hWnd,&r);
@@ -1646,7 +1646,7 @@
16471647 if(memcmp(&r2,&r,sizeof(RECT)))
16481648 SetWindowPos(This->RenderWnd->GetHWnd(),NULL,0,0,r.right,r.bottom,SWP_SHOWWINDOW);
16491649 }
1650 - This->util->DepthTest(false);
 1650+ glUtil_DepthTest(This->util, FALSE);
16511651 RECT *viewrect = &r2;
16521652 glRenderer__SetSwap(This,vsync);
16531653 LONG sizes[6];
@@ -1693,7 +1693,7 @@
16941694 view[2] = 0;
16951695 view[3] = (GLfloat)dest->fakey;
16961696 }
1697 - This->util->SetFBO((FBO*)NULL);
 1697+ glUtil_SetFBO(This->util, NULL);
16981698 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
16991699 if(This->ddInterface->GetBPP() == 8)
17001700 {
@@ -1729,7 +1729,7 @@
17301730 ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->texman);
17311731 else if(This->ext->GLEXT_ARB_sampler_objects)
17321732 ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->texman);
1733 - This->util->SetViewport(viewport[0],viewport[1],viewport[2],viewport[3]);
 1733+ glUtil_SetViewport(This->util,viewport[0],viewport[1],viewport[2],viewport[3]);
17341734 This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
17351735 if(This->ddInterface->GetFullscreen())
17361736 {
@@ -1745,12 +1745,12 @@
17461746 }
17471747 This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
17481748 This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
1749 - This->util->EnableArray(This->shaders->shaders[progtype].pos,true);
1750 - This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos,2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].x);
1751 - This->util->EnableArray(This->shaders->shaders[progtype].texcoord,true);
1752 - This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord,2,GL_FLOAT,false,sizeof(BltVertex),&This->bltvertices[0].s);
1753 - This->util->SetCull(D3DCULL_NONE);
1754 - This->util->SetPolyMode(D3DFILL_SOLID);
 1749+ glUtil_EnableArray(This->util, This->shaders->shaders[progtype].pos, TRUE);
 1750+ This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].pos,2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].x);
 1751+ glUtil_EnableArray(This->util, This->shaders->shaders[progtype].texcoord, TRUE);
 1752+ This->ext->glVertexAttribPointer(This->shaders->shaders[progtype].texcoord,2,GL_FLOAT,GL_FALSE,sizeof(BltVertex),&This->bltvertices[0].s);
 1753+ glUtil_SetCull(This->util, D3DCULL_NONE);
 1754+ glUtil_SetPolyMode(This->util, D3DFILL_SOLID);
17551755 This->ext->glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
17561756 glFlush();
17571757 if(This->hWnd) SwapBuffers(This->hDC);
@@ -1895,17 +1895,17 @@
18961896 SetEvent(This->busy);
18971897 glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
18981898 GLfloat ambient[] = {0.0,0.0,0.0,0.0};
1899 - if(zbuffer) This->util->DepthTest(true);
1900 - This->util->SetDepthComp(GL_LEQUAL);
 1899+ if (zbuffer) glUtil_DepthTest(This->util, TRUE);
 1900+ glUtil_SetDepthComp(This->util, GL_LEQUAL);
19011901 GLfloat identity[16];
19021902 __gluMakeIdentityf(identity);
1903 - This->util->SetMatrix(GL_MODELVIEW,identity,identity,NULL);
1904 - This->util->SetMatrix(GL_PROJECTION,identity,NULL,NULL);
 1903+ glUtil_SetMatrix(This->util, GL_MODELVIEW, identity, identity, NULL);
 1904+ glUtil_SetMatrix(This->util, GL_PROJECTION, identity, NULL, NULL);
19051905 for (int i = 0; i < 24; i++)
19061906 memcpy(&This->transform[i], identity, sizeof(D3DMATRIX));
19071907 GLfloat one[4] = {1,1,1,1};
19081908 GLfloat zero[4] = {0,0,0,1};
1909 - This->util->SetMaterial(one,one,zero,zero,0);
 1909+ glUtil_SetMaterial(This->util, one, one, zero, zero, 0);
19101910 ZeroMemory(&This->material, sizeof(D3DMATERIAL7));
19111911 ZeroMemory(&This->lights, 8 * sizeof(D3DLIGHT7));
19121912 memcpy(&This->renderstate, &renderstate_default, 153 * sizeof(DWORD));
@@ -1928,10 +1928,10 @@
19291929 dwordto4float(dwColor,color);
19301930 do
19311931 {
1932 - if (This->util->SetFBO(target) == GL_FRAMEBUFFER_COMPLETE) break;
 1932+ if (glUtil_SetFBOSurface(This->util, target) == GL_FRAMEBUFFER_COMPLETE) break;
19331933 if (!target->texture->internalformats[1]) break;
19341934 TextureManager_FixTexture(This->texman, target->texture, (target->bigbuffer ? target->bigbuffer : target->buffer), &target->dirty, target->miplevel);
1935 - This->util->SetFBO((FBO*)NULL);
 1935+ glUtil_SetFBO(This->util, NULL);
19361936 target->fbo.fbcolor = NULL;
19371937 target->fbo.fbz = NULL;
19381938 } while (1);
@@ -1939,27 +1939,27 @@
19401940 if(dwFlags & D3DCLEAR_TARGET)
19411941 {
19421942 clearbits |= GL_COLOR_BUFFER_BIT;
1943 - This->util->ClearColor(color[0],color[1],color[2],color[3]);
 1943+ glUtil_ClearColor(This->util, color[0], color[1], color[2], color[3]);
19441944 }
19451945 if(dwFlags & D3DCLEAR_ZBUFFER)
19461946 {
19471947 clearbits |= GL_DEPTH_BUFFER_BIT;
1948 - This->util->ClearDepth(dvZ);
1949 - This->util->DepthWrite(true);
 1948+ glUtil_ClearDepth(This->util, dvZ);
 1949+ glUtil_DepthWrite(This->util, TRUE);
19501950 }
19511951 if(dwFlags & D3DCLEAR_STENCIL)
19521952 {
19531953 clearbits |= GL_STENCIL_BUFFER_BIT;
1954 - This->util->ClearStencil(dwStencil);
 1954+ glUtil_ClearStencil(This->util, dwStencil);
19551955 }
19561956 if(dwCount)
19571957 {
19581958 for(DWORD i = 0; i < dwCount; i++)
19591959 {
1960 - This->util->SetScissor(true,lpRects[i].x1,lpRects[i].y1,lpRects[i].x2,lpRects[i].y2);
 1960+ glUtil_SetScissor(This->util, TRUE, lpRects[i].x1, lpRects[i].y1, lpRects[i].x2, lpRects[i].y2);
19611961 glClear(clearbits);
19621962 }
1963 - This->util->SetScissor(false,0,0,0,0);
 1963+ glUtil_SetScissor(This->util, false, 0, 0, 0, 0);
19641964 }
19651965 else glClear(clearbits);
19661966 if(target->zbuffer) target->zbuffer->dirty |= 2;
@@ -2009,7 +2009,7 @@
20102010 DXGLTimer_Init(&This->timer);
20112011 DXGLTimer_Calibrate(&This->timer, height, frequency);
20122012 glRenderer__SetSwap(This,0);
2013 - This->util->SetViewport(0,0,width,height);
 2013+ glUtil_SetViewport(This->util, 0, 0, width, height);
20142014 }
20152015
20162016 SetEvent(This->busy);
@@ -2114,7 +2114,7 @@
21152115 gldest = GL_SRC_ALPHA;
21162116 break;
21172117 }
2118 - This->util->BlendFunc(glsrc,gldest);
 2118+ glUtil_BlendFunc(This->util, glsrc, gldest);
21192119 }
21202120
21212121 void glRenderer__DrawPrimitives(glRenderer *This, glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
@@ -2154,19 +2154,19 @@
21552155 if (vertices[7].data) This->shaderstate3d.stateid |= (1i64 << 37);
21562156 ShaderManager_SetShader(This->shaders,This->shaderstate3d.stateid,This->shaderstate3d.texstageid,2);
21572157 glRenderer__SetDepthComp(This);
2158 - if(This->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
2159 - else This->util->DepthTest(false);
2160 - if(This->renderstate[D3DRENDERSTATE_ZWRITEENABLE]) This->util->DepthWrite(true);
2161 - else This->util->DepthWrite(false);
 2158+ if(This->renderstate[D3DRENDERSTATE_ZENABLE]) glUtil_DepthTest(This->util, TRUE);
 2159+ else glUtil_DepthTest(This->util, FALSE);
 2160+ if (This->renderstate[D3DRENDERSTATE_ZWRITEENABLE]) glUtil_DepthWrite(This->util, TRUE);
 2161+ else glUtil_DepthWrite(This->util, FALSE);
21622162 _GENSHADER *prog = &This->shaders->gen3d->genshaders[This->shaders->gen3d->current_genshader].shader;
2163 - This->util->EnableArray(prog->attribs[0],true);
2164 - This->ext->glVertexAttribPointer(prog->attribs[0],3,GL_FLOAT,false,vertices[0].stride,vertices[0].data);
 2163+ glUtil_EnableArray(This->util, prog->attribs[0], TRUE);
 2164+ This->ext->glVertexAttribPointer(prog->attribs[0],3,GL_FLOAT,GL_FALSE,vertices[0].stride,vertices[0].data);
21652165 if(transformed)
21662166 {
21672167 if(prog->attribs[1] != -1)
21682168 {
2169 - This->util->EnableArray(prog->attribs[1],true);
2170 - This->ext->glVertexAttribPointer(prog->attribs[1],4,GL_FLOAT,false,vertices[1].stride,vertices[1].data);
 2169+ glUtil_EnableArray(This->util, prog->attribs[1], TRUE);
 2170+ This->ext->glVertexAttribPointer(prog->attribs[1],4,GL_FLOAT,GL_FALSE,vertices[1].stride,vertices[1].data);
21712171 }
21722172 }
21732173 for(i = 0; i < 5; i++)
@@ -2175,8 +2175,8 @@
21762176 {
21772177 if(prog->attribs[i+2] != -1)
21782178 {
2179 - This->util->EnableArray(prog->attribs[i+2],true);
2180 - This->ext->glVertexAttribPointer(prog->attribs[i+2],1,GL_FLOAT,false,vertices[i+2].stride,vertices[i+2].data);
 2179+ glUtil_EnableArray(This->util, prog->attribs[i + 2], TRUE);
 2180+ This->ext->glVertexAttribPointer(prog->attribs[i+2],1,GL_FLOAT,GL_FALSE,vertices[i+2].stride,vertices[i+2].data);
21812181 }
21822182 }
21832183 }
@@ -2184,8 +2184,8 @@
21852185 {
21862186 if(prog->attribs[7] != -1)
21872187 {
2188 - This->util->EnableArray(prog->attribs[7],true);
2189 - This->ext->glVertexAttribPointer(prog->attribs[7],3,GL_FLOAT,false,vertices[7].stride,vertices[7].data);
 2188+ glUtil_EnableArray(This->util, prog->attribs[7], TRUE);
 2189+ This->ext->glVertexAttribPointer(prog->attribs[7],3,GL_FLOAT,GL_FALSE,vertices[7].stride,vertices[7].data);
21902190 }
21912191 }
21922192 for(i = 0; i < 2; i++)
@@ -2194,8 +2194,8 @@
21952195 {
21962196 if(prog->attribs[8+i] != -1)
21972197 {
2198 - This->util->EnableArray(prog->attribs[8+i],true);
2199 - This->ext->glVertexAttribPointer(prog->attribs[8+i],4,GL_UNSIGNED_BYTE,true,vertices[i+8].stride,vertices[i+8].data);
 2198+ glUtil_EnableArray(This->util, prog->attribs[8 + i], TRUE);
 2199+ This->ext->glVertexAttribPointer(prog->attribs[8+i],4,GL_UNSIGNED_BYTE,GL_TRUE,vertices[i+8].stride,vertices[i+8].data);
22002200 }
22012201 }
22022202 }
@@ -2209,28 +2209,28 @@
22102210 case 1: // s
22112211 if (prog->attribs[i + 10] != -1)
22122212 {
2213 - This->util->EnableArray(prog->attribs[i + 10], true);
2214 - This->ext->glVertexAttribPointer(prog->attribs[i + 10], 1, GL_FLOAT, false, vertices[i + 10].stride, vertices[i + 10].data);
 2213+ glUtil_EnableArray(This->util, prog->attribs[i + 10], TRUE);
 2214+ This->ext->glVertexAttribPointer(prog->attribs[i + 10], 1, GL_FLOAT, GL_FALSE, vertices[i + 10].stride, vertices[i + 10].data);
22152215 }
22162216 break;
22172217 case 2: // st
22182218 if(prog->attribs[i+18] != -1)
22192219 {
2220 - This->util->EnableArray(prog->attribs[i+18],true);
2221 - This->ext->glVertexAttribPointer(prog->attribs[i+18],2,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 2220+ glUtil_EnableArray(This->util, prog->attribs[i + 18], TRUE);
 2221+ This->ext->glVertexAttribPointer(prog->attribs[i+18],2,GL_FLOAT,GL_FALSE,vertices[i+10].stride,vertices[i+10].data);
22222222 }
22232223 break;
22242224 case 3: // str
22252225 if(prog->attribs[i+26] != -1)
22262226 {
2227 - This->util->EnableArray(prog->attribs[i+26],true);
2228 - This->ext->glVertexAttribPointer(prog->attribs[i+26],3,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
 2227+ glUtil_EnableArray(This->util, prog->attribs[i + 26], TRUE);
 2228+ This->ext->glVertexAttribPointer(prog->attribs[i+26],3,GL_FLOAT,GL_FALSE,vertices[i+10].stride,vertices[i+10].data);
22292229 }
22302230 break;
22312231 case 4: // strq
22322232 if(prog->attribs[i+34] != -1)
22332233 {
2234 - This->util->EnableArray(prog->attribs[i+34],true);
 2234+ glUtil_EnableArray(This->util, prog->attribs[i + 34], TRUE);
22352235 This->ext->glVertexAttribPointer(prog->attribs[i+34],4,GL_FLOAT,false,vertices[i+10].stride,vertices[i+10].data);
22362236 }
22372237 break;
@@ -2238,12 +2238,12 @@
22392239
22402240 }
22412241 }
2242 - This->util->SetMatrix(GL_MODELVIEW, (GLfloat*)&This->transform[D3DTRANSFORMSTATE_VIEW],
 2242+ glUtil_SetMatrix(This->util, GL_MODELVIEW, (GLfloat*)&This->transform[D3DTRANSFORMSTATE_VIEW],
22432243 (GLfloat*)&This->transform[D3DTRANSFORMSTATE_WORLD],NULL);
2244 - This->util->SetMatrix(GL_PROJECTION, (GLfloat*)&This->transform[D3DTRANSFORMSTATE_PROJECTION], NULL, NULL);
 2244+ glUtil_SetMatrix(This->util, GL_PROJECTION, (GLfloat*)&This->transform[D3DTRANSFORMSTATE_PROJECTION], NULL, NULL);
22452245
2246 - This->util->SetMaterial((GLfloat*)&This->material.ambient,(GLfloat*)&This->material.diffuse,(GLfloat*)&This->material.specular,
2247 - (GLfloat*)&This->material.emissive,This->material.power);
 2246+ glUtil_SetMaterial(This->util, (GLfloat*)&This->material.ambient, (GLfloat*)&This->material.diffuse, (GLfloat*)&This->material.specular,
 2247+ (GLfloat*)&This->material.emissive, This->material.power);
22482248
22492249 int lightindex = 0;
22502250 char lightname[] = "lightX.xxxxxxxxxxxxxxxx";
@@ -2307,8 +2307,8 @@
23082308 if(This->texstages[i].texture)
23092309 This->texstages[i].texture->SetFilter(i,This->texstages[i].glmagfilter,This->texstages[i].glminfilter,This->ext,This->texman);
23102310 TextureManager_SetTexture(This->texman,i,This->texstages[i].texture->texture);
2311 - This->util->SetWrap(i,0,This->texstages[i].addressu,This->texman);
2312 - This->util->SetWrap(i,1,This->texstages[i].addressv,This->texman);
 2311+ glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu, This->texman);
 2312+ glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv, This->texman);
23132313 }
23142314 TextureManager_SetTexture(This->texman,i,0);
23152315 This->ext->glUniform1i(prog->uniforms[128+i],i);
@@ -2334,29 +2334,29 @@
23352335 if(prog->uniforms[150]!= -1) This->ext->glUniform4iv(prog->uniforms[150],1,(GLint*)device->glDDS7->texture->colorbits);
23362336 do
23372337 {
2338 - if (This->util->SetFBO(device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
 2338+ if (glUtil_SetFBOSurface(This->util, device->glDDS7) == GL_FRAMEBUFFER_COMPLETE) break;
23392339 if (!device->glDDS7->texture->internalformats[1]) break;
23402340 TextureManager_FixTexture(This->texman, device->glDDS7->texture,
23412341 (device->glDDS7->bigbuffer ? device->glDDS7->bigbuffer : device->glDDS7->buffer), &device->glDDS7->dirty, device->glDDS7->miplevel);
2342 - This->util->SetFBO((FBO*)NULL);
 2342+ glUtil_SetFBO(This->util, NULL);
23432343 device->glDDS7->fbo.fbcolor = NULL;
23442344 device->glDDS7->fbo.fbz = NULL;
23452345 } while (1);
2346 - This->util->SetViewport((int)((float)This->viewport.dwX*device->glDDS7->mulx),
 2346+ glUtil_SetViewport(This->util, (int)((float)This->viewport.dwX*device->glDDS7->mulx),
23472347 (int)((float)This->viewport.dwY*device->glDDS7->muly),
23482348 (int)((float)This->viewport.dwWidth*device->glDDS7->mulx),
23492349 (int)((float)This->viewport.dwHeight*device->glDDS7->muly));
2350 - This->util->SetDepthRange(This->viewport.dvMinZ,This->viewport.dvMaxZ);
2351 - if(This->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) This->util->BlendEnable(true);
2352 - else This->util->BlendEnable(false);
 2350+ glUtil_SetDepthRange(This->util, This->viewport.dvMinZ, This->viewport.dvMaxZ);
 2351+ if (This->renderstate[D3DRENDERSTATE_ALPHABLENDENABLE]) glUtil_BlendEnable(This->util, TRUE);
 2352+ else glUtil_BlendEnable(This->util, FALSE);
23532353 glRenderer__SetBlend(This,This->renderstate[D3DRENDERSTATE_SRCBLEND],This->renderstate[D3DRENDERSTATE_DESTBLEND]);
2354 - This->util->SetCull((D3DCULL)This->renderstate[D3DRENDERSTATE_CULLMODE]);
 2354+ glUtil_SetCull(This->util, (D3DCULL)This->renderstate[D3DRENDERSTATE_CULLMODE]);
23552355 glRenderer__SetFogColor(This,This->renderstate[D3DRENDERSTATE_FOGCOLOR]);
23562356 glRenderer__SetFogStart(This,*(GLfloat*)(&This->renderstate[D3DRENDERSTATE_FOGSTART]));
23572357 glRenderer__SetFogEnd(This,*(GLfloat*)(&This->renderstate[D3DRENDERSTATE_FOGEND]));
23582358 glRenderer__SetFogDensity(This,*(GLfloat*)(&This->renderstate[D3DRENDERSTATE_FOGDENSITY]));
2359 - This->util->SetPolyMode((D3DFILLMODE)This->renderstate[D3DRENDERSTATE_FILLMODE]);
2360 - This->util->SetShadeMode((D3DSHADEMODE)This->renderstate[D3DRENDERSTATE_SHADEMODE]);
 2359+ glUtil_SetPolyMode(This->util, (D3DFILLMODE)This->renderstate[D3DRENDERSTATE_FILLMODE]);
 2360+ glUtil_SetShadeMode(This->util, (D3DSHADEMODE)This->renderstate[D3DRENDERSTATE_SHADEMODE]);
23612361 if(indices) glDrawElements(mode,indexcount,GL_UNSIGNED_SHORT,indices);
23622362 else glDrawArrays(mode,0,count);
23632363 if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
@@ -2369,7 +2369,7 @@
23702370
23712371 void glRenderer__DeleteFBO(glRenderer *This, FBO *fbo)
23722372 {
2373 - This->util->DeleteFBO(fbo);
 2373+ glUtil_DeleteFBO(This->util, fbo);
23742374 SetEvent(This->busy);
23752375 }
23762376
@@ -2394,22 +2394,22 @@
23952395 (surface->ddsd.dwHeight != surface->stencil->height))
23962396 TextureManager__UploadTexture(This->texman, surface->stencil, 0, NULL,
23972397 surface->ddsd.dwWidth, surface->ddsd.dwHeight, FALSE, TRUE);
2398 - This->util->SetFBO(&surface->stencilfbo, surface->stencil, 0, false);
 2398+ glUtil_SetFBOTextures(This->util, &surface->stencilfbo, surface->stencil, 0, FALSE);
23992399 view[0] = view[2] = 0;
24002400 view[1] = (GLfloat)surface->ddsd.dwWidth;
24012401 view[3] = (GLfloat)surface->ddsd.dwHeight;
2402 - This->util->SetViewport(0,0,surface->ddsd.dwWidth,surface->ddsd.dwHeight);
 2402+ glUtil_SetViewport(This->util, 0, 0, surface->ddsd.dwWidth, surface->ddsd.dwHeight);
24032403 glClear(GL_COLOR_BUFFER_BIT);
24042404 ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,0);
24052405 This->ext->glUniform4f(This->shaders->shaders[PROG_CLIPSTENCIL].view,view[0],view[1],view[2],view[3]);
2406 - This->util->EnableArray(This->shaders->shaders[PROG_CLIPSTENCIL].pos,true);
 2406+ glUtil_EnableArray(This->util, This->shaders->shaders[PROG_CLIPSTENCIL].pos, TRUE);
24072407 This->ext->glVertexAttribPointer(This->shaders->shaders[PROG_CLIPSTENCIL].pos,
24082408 2,GL_FLOAT,false,sizeof(BltVertex),&surface->clipper->vertices[0].x);
2409 - This->util->SetCull(D3DCULL_NONE);
2410 - This->util->SetPolyMode(D3DFILL_SOLID);
 2409+ glUtil_SetCull(This->util, D3DCULL_NONE);
 2410+ glUtil_SetPolyMode(This->util, D3DFILL_SOLID);
24112411 This->ext->glDrawRangeElements(GL_TRIANGLES, 0, (6 * surface->clipper->clipsize) - 1,
24122412 6 * surface->clipper->clipsize, GL_UNSIGNED_SHORT, surface->clipper->indices);
2413 - This->util->SetFBO((FBO*)NULL);
 2413+ glUtil_SetFBO(This->util, NULL);
24142414 SetEvent(This->busy);
24152415 }
24162416
@@ -2431,12 +2431,12 @@
24322432 {
24332433 do
24342434 {
2435 - if (This->util->SetFBO(dest->attachparent) == GL_FRAMEBUFFER_COMPLETE) break;
 2435+ if (glUtil_SetFBOSurface(This->util, dest->attachparent) == GL_FRAMEBUFFER_COMPLETE) break;
24362436 if (!dest->attachparent->texture->internalformats[1]) break;
24372437 TextureManager_FixTexture(This->texman, dest->attachparent->texture,
24382438 (dest->attachparent->bigbuffer ? dest->attachparent->bigbuffer : dest->attachparent->buffer),
24392439 &dest->attachparent->dirty, dest->attachparent->miplevel);
2440 - This->util->SetFBO((FBO*)NULL);
 2440+ glUtil_SetFBO(This->util, NULL);
24412441 dest->attachparent->fbo.fbcolor = NULL;
24422442 dest->attachparent->fbo.fbz = NULL;
24432443 } while (1);
@@ -2461,15 +2461,15 @@
24622462 (dest->ddsd.dwHeight != dest->dummycolor->height))
24632463 TextureManager__UploadTexture(This->texman, dest->dummycolor, 0, NULL,
24642464 dest->ddsd.dwWidth, dest->ddsd.dwHeight, FALSE, TRUE);
2465 - This->util->SetFBO(&dest->zfbo, dest->dummycolor, dest->texture, false);
 2465+ glUtil_SetFBOTextures(This->util, &dest->zfbo, dest->dummycolor, dest->texture, FALSE);
24662466 }
2467 - This->util->SetViewport(0, 0, dest->ddsd.dwWidth, dest->ddsd.dwHeight);
2468 - if (lpDestRect) This->util->SetScissor(true, lpDestRect->left, lpDestRect->top,
 2467+ glUtil_SetViewport(This->util, 0, 0, dest->ddsd.dwWidth, dest->ddsd.dwHeight);
 2468+ if (lpDestRect) glUtil_SetScissor(This->util, TRUE, lpDestRect->left, lpDestRect->top,
24692469 lpDestRect->right, lpDestRect->bottom);
2470 - This->util->DepthWrite(true);
2471 - This->util->ClearDepth(lpDDBltFx->dwFillDepth / (double)0xFFFF);
 2470+ glUtil_DepthWrite(This->util, TRUE);
 2471+ glUtil_ClearDepth(This->util, lpDDBltFx->dwFillDepth / (double)0xFFFF); // FIXME: SOTE depth workaround
24722472 glClear(GL_DEPTH_BUFFER_BIT);
2473 - if (lpDestRect)This->util->SetScissor(false, 0, 0, 0, 0);
 2473+ if (lpDestRect)glUtil_SetScissor(This->util, false, 0, 0, 0, 0);
24742474 This->outputs[0] = DD_OK;
24752475 SetEvent(This->busy);
24762476 }
@@ -2877,29 +2877,29 @@
28782878 switch (This->renderstate[D3DRENDERSTATE_ZFUNC])
28792879 {
28802880 case D3DCMP_NEVER:
2881 - This->util->SetDepthComp(GL_NEVER);
 2881+ glUtil_SetDepthComp(This->util, GL_NEVER);
28822882 break;
28832883 case D3DCMP_LESS:
2884 - This->util->SetDepthComp(GL_LESS);
 2884+ glUtil_SetDepthComp(This->util, GL_LESS);
28852885 break;
28862886 case D3DCMP_EQUAL:
2887 - This->util->SetDepthComp(GL_EQUAL);
 2887+ glUtil_SetDepthComp(This->util, GL_EQUAL);
28882888 break;
28892889 case D3DCMP_LESSEQUAL:
2890 - This->util->SetDepthComp(GL_LEQUAL);
 2890+ glUtil_SetDepthComp(This->util, GL_LEQUAL);
28912891 break;
28922892 case D3DCMP_GREATER:
2893 - This->util->SetDepthComp(GL_GREATER);
 2893+ glUtil_SetDepthComp(This->util, GL_GREATER);
28942894 break;
28952895 case D3DCMP_NOTEQUAL:
2896 - This->util->SetDepthComp(GL_NOTEQUAL);
 2896+ glUtil_SetDepthComp(This->util, GL_NOTEQUAL);
28972897 break;
28982898 case D3DCMP_GREATEREQUAL:
2899 - This->util->SetDepthComp(GL_GEQUAL);
 2899+ glUtil_SetDepthComp(This->util, GL_GEQUAL);
29002900 break;
29012901 case D3DCMP_ALWAYS:
29022902 default:
2903 - This->util->SetDepthComp(GL_ALWAYS);
 2903+ glUtil_SetDepthComp(This->util, GL_ALWAYS);
29042904 break;
29052905 }
29062906 }
Index: ddraw/glRenderer.h
@@ -26,7 +26,7 @@
2727 } GLCAPS;
2828 typedef struct
2929 {
30 - bool enabled;
 30+ BOOL enabled;
3131 int width;
3232 int height;
3333 int pitch;
Index: ddraw/glUtil.cpp
@@ -21,145 +21,165 @@
2222 #include "BufferObject.h"
2323 #include "glDirectDrawSurface.h"
2424
25 -glUtil::glUtil(glExtensions *glext)
 25+extern "C" {
 26+
 27+void glUtil_Create(glExtensions *glext, glUtil **out)
2628 {
27 - ext = glext;
28 - depthwrite = true;
29 - depthtest = false;
30 - depthcomp = 0;
31 - alphacomp = 0;
32 - currentfbo = NULL;
33 - scissorx = 0;
34 - scissory = 0;
35 - scissorwidth = 0;
36 - scissorheight = 0;
37 - viewportx = 0;
38 - viewporty = 0;
39 - viewportwidth = 0;
40 - viewportheight = 0;
41 - depthnear = 0.0;
42 - depthfar = 1.0;
43 - matrixmode = GL_MODELVIEW;
44 - ZeroMemory(materialambient, 4 * sizeof(GLfloat));
45 - ZeroMemory(materialdiffuse, 4 * sizeof(GLfloat));
46 - ZeroMemory(materialspecular, 4 * sizeof(GLfloat));
47 - ZeroMemory(materialemission, 4 * sizeof(GLfloat));
48 - materialshininess = 0;
49 - scissorenabled = false;
50 - texwrap[16];
51 - clearr = 0.0;
52 - clearg = 0.0;
53 - clearb = 0.0;
54 - cleara = 0.0;
55 - cleardepth = 1.0;
56 - clearstencil = 0;
57 - blendsrc = GL_ONE;
58 - blenddest = GL_ZERO;
59 - blendenabled = false;
60 - arrays[42];
61 - cullmode = D3DCULL_NONE;
62 - cullenabled = false;
63 - polymode = D3DFILL_SOLID;
64 - shademode = D3DSHADE_GOURAUD;
65 - pboPackBinding = pboUnpackBinding = vboArrayBinding =
66 - vboElementArrayBinding = uboUniformBufferBinding = LastBoundBuffer = NULL;
 29+ glUtil *util;
 30+ util = (glUtil *)malloc(sizeof(glUtil));
 31+ if (!util) return;
 32+ ZeroMemory(util, sizeof(glUtil));
 33+ util->ext = glext;
 34+ util->depthwrite = TRUE;
 35+ util->depthtest = FALSE;
 36+ util->depthcomp = 0;
 37+ util->alphacomp = 0;
 38+ util->currentfbo = NULL;
 39+ util->scissorx = 0;
 40+ util->scissory = 0;
 41+ util->scissorwidth = 0;
 42+ util->scissorheight = 0;
 43+ util->viewportx = 0;
 44+ util->viewporty = 0;
 45+ util->viewportwidth = 0;
 46+ util->viewportheight = 0;
 47+ util->depthnear = 0.0;
 48+ util->depthfar = 1.0;
 49+ util->matrixmode = GL_MODELVIEW;
 50+ ZeroMemory(util->materialambient, 4 * sizeof(GLfloat));
 51+ ZeroMemory(util->materialdiffuse, 4 * sizeof(GLfloat));
 52+ ZeroMemory(util->materialspecular, 4 * sizeof(GLfloat));
 53+ ZeroMemory(util->materialemission, 4 * sizeof(GLfloat));
 54+ util->materialshininess = 0;
 55+ util->scissorenabled = FALSE;
 56+ util->texwrap[16];
 57+ util->clearr = 0.0;
 58+ util->clearg = 0.0;
 59+ util->clearb = 0.0;
 60+ util->cleara = 0.0;
 61+ util->cleardepth = 1.0;
 62+ util->clearstencil = 0;
 63+ util->blendsrc = GL_ONE;
 64+ util->blenddest = GL_ZERO;
 65+ util->blendenabled = FALSE;
 66+ util->arrays[42];
 67+ util->cullmode = D3DCULL_NONE;
 68+ util->cullenabled = FALSE;
 69+ util->polymode = D3DFILL_SOLID;
 70+ util->shademode = D3DSHADE_GOURAUD;
 71+ util->pboPackBinding = util->pboUnpackBinding = util->vboArrayBinding =
 72+ util->vboElementArrayBinding = util->uboUniformBufferBinding = util->LastBoundBuffer = NULL;
 73+ util->refcount = 1;
 74+ *out = util;
6775 }
68 -void glUtil::InitFBO(FBO *fbo)
 76+
 77+void glUtil_AddRef(glUtil *This)
6978 {
 79+ InterlockedIncrement(&This->refcount);
 80+}
 81+
 82+void glUtil_Release(glUtil *This)
 83+{
 84+ InterlockedDecrement(&This->refcount);
 85+ if (!This->refcount) free(This);
 86+}
 87+
 88+void glUtil_InitFBO(glUtil *This, FBO *fbo)
 89+{
7090 if(!fbo->fbo)
7191 {
7292 ZeroMemory(fbo,sizeof(FBO));
73 - if(ext->GLEXT_ARB_framebuffer_object) ext->glGenFramebuffers(1,&fbo->fbo);
74 - else if(ext->GLEXT_EXT_framebuffer_object) ext->glGenFramebuffersEXT(1,&fbo->fbo);
 93+ if(This->ext->GLEXT_ARB_framebuffer_object) This->ext->glGenFramebuffers(1,&fbo->fbo);
 94+ else if(This->ext->GLEXT_EXT_framebuffer_object) This->ext->glGenFramebuffersEXT(1,&fbo->fbo);
7595 }
7696 }
7797
78 -void glUtil::DeleteFBO(FBO *fbo)
 98+void glUtil_DeleteFBO(glUtil *This, FBO *fbo)
7999 {
80100 if(fbo->fbo)
81101 {
82 - if(ext->GLEXT_ARB_framebuffer_object)
 102+ if(This->ext->GLEXT_ARB_framebuffer_object)
83103 {
84 - if(currentfbo == fbo) ext->glBindFramebuffer(GL_FRAMEBUFFER,0);
85 - ext->glDeleteFramebuffers(1,&fbo->fbo);
 104+ if(This->currentfbo == fbo) This->ext->glBindFramebuffer(GL_FRAMEBUFFER,0);
 105+ This->ext->glDeleteFramebuffers(1,&fbo->fbo);
86106 ZeroMemory(fbo,sizeof(FBO));
87107 }
88 - else if(ext->GLEXT_EXT_framebuffer_object)
 108+ else if(This->ext->GLEXT_EXT_framebuffer_object)
89109 {
90 - if(currentfbo == fbo) ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
91 - ext->glDeleteFramebuffersEXT(1,&fbo->fbo);
 110+ if(This->currentfbo == fbo) This->ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
 111+ This->ext->glDeleteFramebuffersEXT(1,&fbo->fbo);
92112 ZeroMemory(fbo,sizeof(FBO));
93113 }
94114 }
95115 }
96116
97 -void glUtil::SetFBOTexture(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil)
 117+void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, TEXTURE *color, TEXTURE *z, BOOL stencil)
98118 {
99119 if(!color) return;
100120 if(!fbo->fbo) return;
101 - if(ext->GLEXT_ARB_framebuffer_object)
 121+ if(This->ext->GLEXT_ARB_framebuffer_object)
102122 {
103 - if(currentfbo != fbo) ext->glBindFramebuffer(GL_FRAMEBUFFER,fbo->fbo);
104 - currentfbo = fbo;
105 - ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color->id,0);
 123+ if(This->currentfbo != fbo) This->ext->glBindFramebuffer(GL_FRAMEBUFFER,fbo->fbo);
 124+ This->currentfbo = fbo;
 125+ This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,color->id,0);
106126 fbo->fbcolor = color;
107127 if(stencil)
108128 {
109 - if(!fbo->stencil) ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
110 - if(z)ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,z->id,0);
111 - else ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
 129+ if(!fbo->stencil) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
 130+ if(z)This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,z->id,0);
 131+ else This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
112132 }
113133 else
114134 {
115 - if(fbo->stencil) ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
116 - if(z) ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,z->id,0);
117 - else ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
 135+ if(fbo->stencil) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_TEXTURE_2D,0,0);
 136+ if(z) This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,z->id,0);
 137+ else This->ext->glFramebufferTexture2D(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_TEXTURE_2D,0,0);
118138 }
119139 fbo->stencil = stencil;
120140 fbo->fbz = z;
121 - fbo->status = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
 141+ fbo->status = This->ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
122142 }
123 - else if(ext->GLEXT_EXT_framebuffer_object)
 143+ else if(This->ext->GLEXT_EXT_framebuffer_object)
124144 {
125 - if(currentfbo != fbo) ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fbo->fbo);
126 - currentfbo = fbo;
127 - ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,color->id,0);
 145+ if (This->currentfbo != fbo) This->ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo);
 146+ This->currentfbo = fbo;
 147+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, color->id, 0);
128148 fbo->fbcolor = color;
129149 if(stencil)
130150 {
131151 if(z)
132152 {
133 - ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,z->id,0);
134 - ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_STENCIL_ATTACHMENT_EXT,GL_TEXTURE_2D,z->id,0);
 153+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, 0);
 154+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, 0);
135155 }
136156 else
137157 {
138 - ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,0,0);
139 - ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_STENCIL_ATTACHMENT_EXT,GL_TEXTURE_2D,0,0);
 158+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
 159+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
140160 }
141161 }
142162 else
143163 {
144 - ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_STENCIL_ATTACHMENT_EXT,GL_TEXTURE_2D,0,0);
145 - if(z)ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,z->id,0);
146 - else ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_TEXTURE_2D,0,0);
 164+ This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_STENCIL_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
 165+ if (z)This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, z->id, 0);
 166+ else This->ext->glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_TEXTURE_2D, 0, 0);
147167 }
148168 fbo->stencil = stencil;
149169 fbo->fbz = z;
150 - fbo->status = ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 170+ fbo->status = This->ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
151171 }
152172 }
153173
154 -GLenum glUtil::SetFBO(glDirectDrawSurface7 *surface)
 174+GLenum glUtil_SetFBOSurface(glUtil *This, glDirectDrawSurface7 *surface)
155175 {
156 - if(!surface) return SetFBO((FBO*)NULL);
157 - if(surface->zbuffer) return SetFBO(&surface->fbo,surface->texture,surface->zbuffer->texture,surface->zbuffer->hasstencil);
158 - else return SetFBO(&surface->fbo,surface->texture,NULL,false);
 176+ if (!surface) return glUtil_SetFBO(This, (FBO*)NULL);
 177+ if (surface->zbuffer) return glUtil_SetFBOTextures(This, &surface->fbo, surface->texture, surface->zbuffer->texture, surface->zbuffer->hasstencil);
 178+ else return glUtil_SetFBOTextures(This, &surface->fbo, surface->texture, NULL, FALSE);
159179 }
160180
161 -GLenum glUtil::SetFBO(FBO *fbo)
 181+GLenum glUtil_SetFBO(glUtil *This, FBO *fbo)
162182 {
163 - if (fbo == currentfbo)
 183+ if (fbo == This->currentfbo)
164184 {
165185 if (fbo) return fbo->status;
166186 else return GL_FRAMEBUFFER_COMPLETE;
@@ -166,52 +186,52 @@
167187 }
168188 if(!fbo)
169189 {
170 - if (ext->GLEXT_ARB_framebuffer_object) ext->glBindFramebuffer(GL_FRAMEBUFFER, 0);
171 - else if(ext->GLEXT_EXT_framebuffer_object) ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
 190+ if (This->ext->GLEXT_ARB_framebuffer_object) This->ext->glBindFramebuffer(GL_FRAMEBUFFER, 0);
 191+ else if (This->ext->GLEXT_EXT_framebuffer_object) This->ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
172192 }
173193 else
174194 {
175 - if (ext->GLEXT_ARB_framebuffer_object)
 195+ if (This->ext->GLEXT_ARB_framebuffer_object)
176196 {
177 - ext->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fbo);
178 - fbo->status = ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
 197+ This->ext->glBindFramebuffer(GL_FRAMEBUFFER, fbo->fbo);
 198+ fbo->status = This->ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
179199 }
180 - else if (ext->GLEXT_EXT_framebuffer_object)
 200+ else if (This->ext->GLEXT_EXT_framebuffer_object)
181201 {
182 - ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo);
183 - fbo->status = ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 202+ This->ext->glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo->fbo);
 203+ fbo->status = This->ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
184204 }
185205 }
186 - currentfbo = fbo;
 206+ This->currentfbo = fbo;
187207 if (fbo) return fbo->status;
188208 else
189209 {
190 - if (ext->GLEXT_ARB_framebuffer_object) return ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
191 - else if (ext->GLEXT_EXT_framebuffer_object) return ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
 210+ if (This->ext->GLEXT_ARB_framebuffer_object) return This->ext->glCheckFramebufferStatus(GL_FRAMEBUFFER);
 211+ else if (This->ext->GLEXT_EXT_framebuffer_object) return This->ext->glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
192212 else return 0;
193213 }
194214 }
195215
196 -GLenum glUtil::SetFBO(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil)
 216+GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, TEXTURE *color, TEXTURE *z, BOOL stencil)
197217 {
198218 if(!fbo)
199219 {
200 - return SetFBO((FBO*)NULL);
 220+ return glUtil_SetFBO(This, (FBO*)NULL);
201221 }
202 - if(!fbo->fbo) InitFBO(fbo);
 222+ if(!fbo->fbo) glUtil_InitFBO(This, fbo);
203223 if (!color) return GL_INVALID_ENUM;
204224 if((color != fbo->fbcolor) || (z != fbo->fbz) || (stencil != fbo->stencil))
205 - SetFBOTexture(fbo,color,z,stencil);
206 - if(fbo != currentfbo) return SetFBO(fbo);
 225+ glUtil_SetFBOTexture(This, fbo,color,z,stencil);
 226+ if(fbo != This->currentfbo) return glUtil_SetFBO(This, fbo);
207227 else return fbo->status;
208228 }
209229
210 -void glUtil::SetWrap(int level, DWORD coord, DWORD address, TextureManager *texman)
 230+void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address, TextureManager *texman)
211231 {
212232 if(level == -1)
213233 {
214234 for(int i = 0; i < 16; i++)
215 - texwrap[i] = GL_REPEAT;
 235+ This->texwrap[i] = GL_REPEAT;
216236 }
217237 if(coord > 1) return;
218238 if(level > 7) return;
@@ -237,15 +257,15 @@
238258 //if(texwrap[level*2+coord] == wrapmode) return;
239259 //else
240260 {
241 - texwrap[level*2+coord] = wrapmode;
 261+ This->texwrap[level * 2 + coord] = wrapmode;
242262 //int currtexture = texlevel;
243 - if(ext->GLEXT_ARB_sampler_objects)
 263+ if (This->ext->GLEXT_ARB_sampler_objects)
244264 {
245265 if(coord)
246266 {
247267 if(texman->samplers[level].wrapt != wrapmode)
248268 {
249 - ext->glSamplerParameteri(texman->samplers[level].id,GL_TEXTURE_WRAP_T,wrapmode);
 269+ This->ext->glSamplerParameteri(texman->samplers[level].id, GL_TEXTURE_WRAP_T, wrapmode);
250270 texman->samplers[level].wrapt = wrapmode;
251271 }
252272 }
@@ -253,7 +273,7 @@
254274 {
255275 if(texman->samplers[level].wraps != wrapmode)
256276 {
257 - ext->glSamplerParameteri(texman->samplers[level].id,GL_TEXTURE_WRAP_S,wrapmode);
 277+ This->ext->glSamplerParameteri(texman->samplers[level].id, GL_TEXTURE_WRAP_S, wrapmode);
258278 texman->samplers[level].wraps = wrapmode;
259279 }
260280 }
@@ -264,233 +284,236 @@
265285 if(coord) glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,wrapmode);
266286 else glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,wrapmode);
267287 }
268 - //SetActiveTexture(currtexture);
 288+ //TextureManager_SetActiveTexture(texman,currtexture);
269289 }
270290 }
271291
272 -void glUtil::DepthWrite(bool enabled)
 292+void glUtil_DepthWrite(glUtil *This, BOOL enabled)
273293 {
274 - if(enabled != depthwrite)
 294+ if (enabled != This->depthwrite)
275295 {
276 - depthwrite = enabled;
277 - if(depthwrite) glDepthMask(GL_TRUE);
 296+ This->depthwrite = enabled;
 297+ if (This->depthwrite) glDepthMask(GL_TRUE);
278298 else glDepthMask(GL_FALSE);
279299 }
280300 }
281 -void glUtil::DepthTest(bool enabled)
 301+void glUtil_DepthTest(glUtil *This, BOOL enabled)
282302 {
283 - if(enabled != depthtest)
 303+ if (enabled != This->depthtest)
284304 {
285 - depthtest = enabled;
286 - if(depthtest) glEnable(GL_DEPTH_TEST);
 305+ This->depthtest = enabled;
 306+ if (This->depthtest) glEnable(GL_DEPTH_TEST);
287307 else glDisable(GL_DEPTH_TEST);
288308 }
289309 }
290 -void glUtil::SetDepthComp(GLenum comp)
 310+void glUtil_SetDepthComp(glUtil *This, GLenum comp)
291311 {
292 - if(comp != depthcomp)
 312+ if (comp != This->depthcomp)
293313 {
294 - depthcomp = comp;
 314+ This->depthcomp = comp;
295315 glDepthFunc(comp);
296316 }
297317 }
298318
299 -void glUtil::SetScissor(bool enabled, GLint x, GLint y, GLsizei width, GLsizei height)
 319+void glUtil_SetScissor(glUtil *This, BOOL enabled, GLint x, GLint y, GLsizei width, GLsizei height)
300320 {
301 - if(enabled != scissorenabled)
 321+ if (enabled != This->scissorenabled)
302322 {
303 - scissorenabled = enabled;
 323+ This->scissorenabled = enabled;
304324 if(enabled) glEnable(GL_SCISSOR_TEST);
305325 else glDisable(GL_SCISSOR_TEST);
306326 }
307 - if((x != scissorx) || (y != scissory) || (width != scissorwidth) || (height != scissorheight))
 327+ if ((x != This->scissorx) || (y != This->scissory) ||
 328+ (width != This->scissorwidth) || (height != This->scissorheight))
308329 {
309 - scissorx = x;
310 - scissory = y;
311 - scissorwidth = width;
312 - scissorheight = height;
 330+ This->scissorx = x;
 331+ This->scissory = y;
 332+ This->scissorwidth = width;
 333+ This->scissorheight = height;
313334 glScissor(x,y,width,height);
314335 }
315336 }
316337
317 -void glUtil::MatrixMode(GLenum mode)
 338+void glUtil_MatrixMode(glUtil *This, GLenum mode)
318339 {
319 - if(mode != matrixmode)
 340+ if (mode != This->matrixmode)
320341 {
321 - matrixmode = mode;
 342+ This->matrixmode = mode;
322343 glMatrixMode(mode);
323344 }
324345 }
325346
326 -void glUtil::SetMatrix(GLenum mode, GLfloat *mat1, GLfloat *mat2, bool *dirty)
 347+void glUtil_SetMatrix(glUtil *This, GLenum mode, GLfloat *mat1, GLfloat *mat2, BOOL *dirty)
327348 {
328 - if(ext->GLEXT_EXT_direct_state_access)
 349+ if(This->ext->GLEXT_EXT_direct_state_access)
329350 {
330 - ext->glMatrixLoadfEXT(mode,mat1);
331 - if(mode == GL_MODELVIEW) ext->glMatrixMultfEXT(mode,mat2);
 351+ This->ext->glMatrixLoadfEXT(mode, mat1);
 352+ if (mode == GL_MODELVIEW) This->ext->glMatrixMultfEXT(mode, mat2);
332353 }
333354 else
334355 {
335 - MatrixMode(mode);
 356+ glUtil_MatrixMode(This, mode);
336357 glLoadMatrixf(mat1);
337358 if(mode == GL_MODELVIEW) glMultMatrixf(mat2);
338359 }
339 - if(dirty) *dirty = false;
 360+ if(dirty) *dirty = FALSE;
340361 }
341362
342 -void glUtil::SetMaterial(GLfloat ambient[4],GLfloat diffuse[4],GLfloat specular[4],GLfloat emission[4],GLfloat shininess)
 363+void glUtil_SetMaterial(glUtil *This, GLfloat ambient[4],GLfloat diffuse[4],GLfloat specular[4],GLfloat emission[4],GLfloat shininess)
343364 {
344 - if(memcmp(ambient,materialambient,4*sizeof(GLfloat)))
 365+ if(memcmp(ambient,This->materialambient,4*sizeof(GLfloat)))
345366 {
346 - memcpy(materialambient,ambient,4*sizeof(GLfloat));
 367+ memcpy(This->materialambient, ambient, 4 * sizeof(GLfloat));
347368 glMaterialfv(GL_FRONT,GL_AMBIENT,ambient);
348369 }
349 - if(memcmp(diffuse,materialdiffuse,4*sizeof(GLfloat)))
 370+ if (memcmp(diffuse, This->materialdiffuse, 4 * sizeof(GLfloat)))
350371 {
351 - memcpy(materialdiffuse,diffuse,4*sizeof(GLfloat));
 372+ memcpy(This->materialdiffuse, diffuse, 4 * sizeof(GLfloat));
352373 glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuse);
353374 }
354 - if(memcmp(specular,materialspecular,4*sizeof(GLfloat)))
 375+ if (memcmp(specular, This->materialspecular, 4 * sizeof(GLfloat)))
355376 {
356 - memcpy(materialspecular,specular,4*sizeof(GLfloat));
 377+ memcpy(This->materialspecular, specular, 4 * sizeof(GLfloat));
357378 glMaterialfv(GL_FRONT,GL_SPECULAR,specular);
358379 }
359 - if(memcmp(emission,materialemission,4*sizeof(GLfloat)))
 380+ if (memcmp(emission, This->materialemission, 4 * sizeof(GLfloat)))
360381 {
361 - memcpy(materialemission,emission,4*sizeof(GLfloat));
 382+ memcpy(This->materialemission, emission, 4 * sizeof(GLfloat));
362383 glMaterialfv(GL_FRONT,GL_EMISSION,emission);
363384 }
364 - if(shininess != materialshininess)
 385+ if (shininess != This->materialshininess)
365386 {
366 - materialshininess = shininess;
 387+ This->materialshininess = shininess;
367388 glMaterialf(GL_FRONT,GL_SHININESS,shininess);
368389 }
369390 }
370391
371 -void glUtil::SetViewport(GLint x, GLint y, GLsizei width, GLsizei height)
 392+void glUtil_SetViewport(glUtil *This, GLint x, GLint y, GLsizei width, GLsizei height)
372393 {
373 - if((x != viewportx) || (y != viewporty) || (width != viewportwidth) || (height != viewportheight))
 394+ if ((x != This->viewportx) || (y != This->viewporty) ||
 395+ (width != This->viewportwidth) || (height != This->viewportheight))
374396 {
375 - viewportx = x;
376 - viewporty = y;
377 - viewportwidth = width;
378 - viewportheight = height;
 397+ This->viewportx = x;
 398+ This->viewporty = y;
 399+ This->viewportwidth = width;
 400+ This->viewportheight = height;
379401 glViewport(x,y,width,height);
380402 }
381403 }
382404
383 -void glUtil::SetDepthRange(GLclampd rangenear, GLclampd rangefar)
 405+void glUtil_SetDepthRange(glUtil *This, GLclampd rangenear, GLclampd rangefar)
384406 {
385 - if((rangenear != depthnear) || (rangefar != depthfar))
 407+ if ((rangenear != This->depthnear) || (rangefar != This->depthfar))
386408 {
387 - depthnear = rangenear;
388 - depthfar = rangefar;
 409+ This->depthnear = rangenear;
 410+ This->depthfar = rangefar;
389411 glDepthRange(rangenear,rangefar);
390412 }
391413 }
392414
393 -void glUtil::ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a)
 415+void glUtil_ClearColor(glUtil *This, GLclampf r, GLclampf g, GLclampf b, GLclampf a)
394416 {
395 - if((clearr != r) || (clearg != g) || (clearb != b) || (cleara != a))
 417+ if ((This->clearr != r) || (This->clearg != g) ||
 418+ (This->clearb != b) || (This->cleara != a))
396419 {
397 - clearr = r;
398 - clearg = g;
399 - clearb = b;
400 - cleara = a;
 420+ This->clearr = r;
 421+ This->clearg = g;
 422+ This->clearb = b;
 423+ This->cleara = a;
401424 glClearColor(r,g,b,a);
402425 }
403426 }
404427
405 -void glUtil::ClearDepth(GLclampd depth)
 428+void glUtil_ClearDepth(glUtil *This, GLclampd depth)
406429 {
407 - if(cleardepth != depth)
 430+ if (This->cleardepth != depth)
408431 {
409 - cleardepth = depth;
 432+ This->cleardepth = depth;
410433 glClearDepth(depth);
411434 }
412435 }
413436
414 -void glUtil::ClearStencil(GLint stencil)
 437+void glUtil_ClearStencil(glUtil *This, GLint stencil)
415438 {
416 - if(clearstencil != stencil)
 439+ if (This->clearstencil != stencil)
417440 {
418 - clearstencil = stencil;
 441+ This->clearstencil = stencil;
419442 glClearStencil(stencil);
420443 }
421444 }
422445
423 -void glUtil::EnableArray(int index, bool enabled)
 446+void glUtil_EnableArray(glUtil *This, int index, BOOL enabled)
424447 {
425448 if(index == -1)
426449 {
427450 for(int i = 0; i < 42; i++)
428 - arrays[i] = false;
 451+ This->arrays[i] = FALSE;
429452 return;
430453 }
431454 if(index >= 42) return;
432 - if(arrays[index] != enabled)
 455+ if (This->arrays[index] != enabled)
433456 {
434 - arrays[index] = enabled;
435 - if(enabled) ext->glEnableVertexAttribArray(index);
436 - else ext->glDisableVertexAttribArray(index);
 457+ This->arrays[index] = enabled;
 458+ if (enabled) This->ext->glEnableVertexAttribArray(index);
 459+ else This->ext->glDisableVertexAttribArray(index);
437460 }
438461 }
439462
440 -void glUtil::BlendFunc(GLenum src, GLenum dest)
 463+void glUtil_BlendFunc(glUtil *This, GLenum src, GLenum dest)
441464 {
442 - if((blendsrc != src) || (blenddest != dest))
 465+ if ((This->blendsrc != src) || (This->blenddest != dest))
443466 {
444 - blendsrc = src;
445 - blenddest = dest;
 467+ This->blendsrc = src;
 468+ This->blenddest = dest;
446469 glBlendFunc(src,dest);
447470 }
448471 }
449472
450 -void glUtil::BlendEnable(bool enabled)
 473+void glUtil_BlendEnable(glUtil *This, BOOL enabled)
451474 {
452 - if(enabled != blendenabled)
 475+ if(enabled != This->blendenabled)
453476 {
454 - blendenabled = enabled;
 477+ This->blendenabled = enabled;
455478 if(enabled) glEnable(GL_BLEND);
456479 else glDisable(GL_BLEND);
457480 }
458481 }
459482
460 -void glUtil::EnableCull(bool enabled)
 483+void glUtil_EnableCull(glUtil *This, BOOL enabled)
461484 {
462 - if(cullenabled != enabled)
 485+ if (This->cullenabled != enabled)
463486 {
464 - cullenabled = enabled;
 487+ This->cullenabled = enabled;
465488 if(enabled) glEnable(GL_CULL_FACE);
466489 else glDisable(GL_CULL_FACE);
467490 }
468491 }
469 -void glUtil::SetCull(D3DCULL mode)
 492+void glUtil_SetCull(glUtil *This, D3DCULL mode)
470493 {
471 - if(cullmode != mode)
 494+ if (This->cullmode != mode)
472495 {
473 - cullmode = mode;
 496+ This->cullmode = mode;
474497 switch(mode)
475498 {
476499 case D3DCULL_CCW:
477 - EnableCull(true);
 500+ glUtil_EnableCull(This, TRUE);
478501 glFrontFace(GL_CCW);
479502 break;
480503 case D3DCULL_CW:
481 - EnableCull(true);
 504+ glUtil_EnableCull(This, TRUE);
482505 glFrontFace(GL_CW);
483506 break;
484507 case D3DCULL_NONE:
485 - EnableCull(false);
 508+ glUtil_EnableCull(This, FALSE);
486509 break;
487510 }
488511 }
489512 }
490 -void glUtil::SetPolyMode(D3DFILLMODE mode)
 513+void glUtil_SetPolyMode(glUtil *This, D3DFILLMODE mode)
491514 {
492 - if(polymode != mode)
 515+ if (This->polymode != mode)
493516 {
494 - polymode = mode;
 517+ This->polymode = mode;
495518 switch(mode)
496519 {
497520 case D3DFILL_POINT:
@@ -507,11 +530,11 @@
508531 }
509532 }
510533
511 -void glUtil::SetShadeMode(D3DSHADEMODE mode)
 534+void glUtil_SetShadeMode(glUtil *This, D3DSHADEMODE mode)
512535 {
513 - if(shademode != mode)
 536+ if (This->shademode != mode)
514537 {
515 - shademode = mode;
 538+ This->shademode = mode;
516539 switch(mode)
517540 {
518541 case D3DSHADE_FLAT:
@@ -527,40 +550,42 @@
528551 }
529552 }
530553
531 -void glUtil::BindBuffer(BufferObject *buffer, GLenum target)
 554+void glUtil_BindBuffer(glUtil *This, BufferObject *buffer, GLenum target)
532555 {
533556 switch (target)
534557 {
535558 case GL_PIXEL_PACK_BUFFER:
536 - LastBoundBuffer = pboPackBinding;
537 - pboPackBinding = buffer;
 559+ This->LastBoundBuffer = This->pboPackBinding;
 560+ This->pboPackBinding = buffer;
538561 break;
539562 case GL_PIXEL_UNPACK_BUFFER:
540 - LastBoundBuffer = pboUnpackBinding;
541 - pboUnpackBinding = buffer;
 563+ This->LastBoundBuffer = This->pboUnpackBinding;
 564+ This->pboUnpackBinding = buffer;
542565 break;
543566 case GL_ARRAY_BUFFER:
544 - LastBoundBuffer = vboArrayBinding;
545 - vboArrayBinding = buffer;
 567+ This->LastBoundBuffer = This->vboArrayBinding;
 568+ This->vboArrayBinding = buffer;
546569 break;
547570 case GL_ELEMENT_ARRAY_BUFFER:
548 - LastBoundBuffer = vboElementArrayBinding;
549 - vboElementArrayBinding = buffer;
 571+ This->LastBoundBuffer = This->vboElementArrayBinding;
 572+ This->vboElementArrayBinding = buffer;
550573 break;
551574 case GL_UNIFORM_BUFFER:
552 - LastBoundBuffer = uboUniformBufferBinding;
553 - uboUniformBufferBinding = buffer;
 575+ This->LastBoundBuffer = This->uboUniformBufferBinding;
 576+ This->uboUniformBufferBinding = buffer;
554577 break;
555578 default:
556 - LastBoundBuffer = NULL;
 579+ This->LastBoundBuffer = NULL;
557580 }
558 - if(buffer) ext->glBindBuffer(target, buffer->buffer);
559 - else ext->glBindBuffer(target, 0);
 581+ if (buffer) This->ext->glBindBuffer(target, buffer->buffer);
 582+ else This->ext->glBindBuffer(target, 0);
560583 }
561584
562 -void glUtil::UndoBindBuffer(GLenum target)
 585+void glUtil_UndoBindBuffer(glUtil *This, GLenum target)
563586 {
564 - if (LastBoundBuffer) ext->glBindBuffer(target, LastBoundBuffer->buffer);
565 - else ext->glBindBuffer(target, 0);
566 - LastBoundBuffer = NULL;
567 -}
\ No newline at end of file
 587+ if (This->LastBoundBuffer) This->ext->glBindBuffer(target, This->LastBoundBuffer->buffer);
 588+ else This->ext->glBindBuffer(target, 0);
 589+ This->LastBoundBuffer = NULL;
 590+}
 591+
 592+};
\ No newline at end of file
Index: ddraw/glUtil.h
@@ -19,6 +19,13 @@
2020 #ifndef _GLUTIL_H
2121 #define _GLUTIL_H
2222
 23+#ifdef __cplusplus
 24+class glDirectDrawSurface7;
 25+extern "C" {
 26+#else
 27+typedef int glDirectDrawSurface7;
 28+#endif
 29+
2330 struct TEXTURE;
2431 struct BufferObject;
2532 struct TextureManager;
@@ -28,7 +35,7 @@
2936 GLuint fbo;
3037 TEXTURE *fbcolor;
3138 TEXTURE *fbz;
32 - bool stencil;
 39+ BOOL stencil;
3340 GLenum status;
3441 } FBO;
3542
@@ -40,40 +47,9 @@
4148 GLfloat stencils, stencilt;
4249 } BltVertex;
4350
44 -class glDirectDrawSurface7;
45 -
46 -class glUtil
 51+typedef struct glUtil
4752 {
48 -public:
49 - glUtil(glExtensions *glext);
50 - void InitFBO(FBO *fbo);
51 - void DeleteFBO(FBO *fbo);
52 - void SetFBOTexture(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil);
53 - void SetWrap(int level, DWORD coord, DWORD address, TextureManager *texman);
54 - GLenum SetFBO(glDirectDrawSurface7 *surface);
55 - GLenum SetFBO(FBO *fbo);
56 - GLenum SetFBO(FBO *fbo, TEXTURE *color, TEXTURE *z, bool stencil);
57 - void SetDepthComp(GLenum comp);
58 - void DepthWrite(bool enabled);
59 - void DepthTest(bool enabled);
60 - void SetScissor(bool enabled, GLint x, GLint y, GLsizei width, GLsizei height);
61 - void SetMatrix(GLenum mode, GLfloat *mat1, GLfloat *mat2, bool *dirty);
62 - void MatrixMode(GLenum mode);
63 - void SetMaterial(GLfloat ambient[4], GLfloat diffuse[4], GLfloat specular[4], GLfloat emission[4], GLfloat shininess);
64 - void SetViewport(GLint x, GLint y, GLsizei width, GLsizei height);
65 - void SetDepthRange(GLclampd rangenear, GLclampd rangefar);
66 - void ClearColor(GLclampf r, GLclampf g, GLclampf b, GLclampf a);
67 - void ClearDepth(GLclampd depth);
68 - void ClearStencil(GLint stencil);
69 - void EnableArray(int index, bool enabled);
70 - void BlendFunc(GLenum src, GLenum dest);
71 - void BlendEnable(bool enabled);
72 - void EnableCull(bool enabled);
73 - void SetCull(D3DCULL mode);
74 - void SetPolyMode(D3DFILLMODE mode);
75 - void SetShadeMode(D3DSHADEMODE mode);
76 - void BindBuffer(BufferObject *buffer, GLenum target);
77 - void UndoBindBuffer(GLenum target);
 53+ ULONG refcount;
7854 FBO *currentfbo;
7955 BufferObject *pboPackBinding;
8056 BufferObject *pboUnpackBinding;
@@ -80,10 +56,9 @@
8157 BufferObject *vboArrayBinding;
8258 BufferObject *vboElementArrayBinding;
8359 BufferObject *uboUniformBufferBinding;
84 -private:
8560 glExtensions *ext;
86 - bool depthwrite;
87 - bool depthtest;
 61+ BOOL depthwrite;
 62+ BOOL depthtest;
8863 GLuint depthcomp;
8964 GLuint alphacomp;
9065 GLint scissorx;
@@ -102,7 +77,7 @@
10378 GLfloat materialspecular[4];
10479 GLfloat materialemission[4];
10580 GLfloat materialshininess;
106 - bool scissorenabled;
 81+ BOOL scissorenabled;
10782 GLint texwrap[16];
10883 GLclampf clearr;
10984 GLclampf clearg;
@@ -112,13 +87,49 @@
11388 GLint clearstencil;
11489 GLenum blendsrc;
11590 GLenum blenddest;
116 - bool blendenabled;
117 - bool arrays[42];
 91+ BOOL blendenabled;
 92+ BOOL arrays[42];
11893 D3DCULL cullmode;
119 - bool cullenabled;
 94+ BOOL cullenabled;
12095 D3DFILLMODE polymode;
12196 D3DSHADEMODE shademode;
12297 BufferObject *LastBoundBuffer;
123 -};
 98+} glUtil;
12499
 100+void glUtil_Create(glExtensions *glext, glUtil **out);
 101+void glUtil_AddRef(glUtil *This);
 102+void glUtil_Release(glUtil *This);
 103+void glUtil_InitFBO(glUtil *This, FBO *fbo);
 104+void glUtil_DeleteFBO(glUtil *This, FBO *fbo);
 105+void glUtil_SetFBOTexture(glUtil *This, FBO *fbo, TEXTURE *color, TEXTURE *z, BOOL stencil);
 106+void glUtil_SetWrap(glUtil *This, int level, DWORD coord, DWORD address, TextureManager *texman);
 107+GLenum glUtil_SetFBOSurface(glUtil *This, glDirectDrawSurface7 *surface);
 108+GLenum glUtil_SetFBO(glUtil *This, FBO *fbo);
 109+GLenum glUtil_SetFBOTextures(glUtil *This, FBO *fbo, TEXTURE *color, TEXTURE *z, BOOL stencil);
 110+void glUtil_SetDepthComp(glUtil *This, GLenum comp);
 111+void glUtil_DepthWrite(glUtil *This, BOOL enabled);
 112+void glUtil_DepthTest(glUtil *This, BOOL enabled);
 113+void glUtil_SetScissor(glUtil *This, BOOL enabled, GLint x, GLint y, GLsizei width, GLsizei height);
 114+void glUtil_SetMatrix(glUtil *This, GLenum mode, GLfloat *mat1, GLfloat *mat2, BOOL *dirty);
 115+void glUtil_MatrixMode(glUtil *This, GLenum mode);
 116+void glUtil_SetMaterial(glUtil *This, GLfloat ambient[4], GLfloat diffuse[4], GLfloat specular[4], GLfloat emission[4], GLfloat shininess);
 117+void glUtil_SetViewport(glUtil *This, GLint x, GLint y, GLsizei width, GLsizei height);
 118+void glUtil_SetDepthRange(glUtil *This, GLclampd rangenear, GLclampd rangefar);
 119+void glUtil_ClearColor(glUtil *This, GLclampf r, GLclampf g, GLclampf b, GLclampf a);
 120+void glUtil_ClearDepth(glUtil *This, GLclampd depth);
 121+void glUtil_ClearStencil(glUtil *This, GLint stencil);
 122+void glUtil_EnableArray(glUtil *This, int index, BOOL enabled);
 123+void glUtil_BlendFunc(glUtil *This, GLenum src, GLenum dest);
 124+void glUtil_BlendEnable(glUtil *This, BOOL enabled);
 125+void glUtil_EnableCull(glUtil *This, BOOL enabled);
 126+void glUtil_SetCull(glUtil *This, D3DCULL mode);
 127+void glUtil_SetPolyMode(glUtil *This, D3DFILLMODE mode);
 128+void glUtil_SetShadeMode(glUtil *This, D3DSHADEMODE mode);
 129+void glUtil_BindBuffer(glUtil *This, BufferObject *buffer, GLenum target);
 130+void glUtil_UndoBindBuffer(glUtil *This, GLenum target);
 131+
 132+#ifdef __cplusplus
 133+}
 134+#endif
 135+
125136 #endif //_GLUTIL_H