DXGL r608 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r607‎ | r608 | r609 >
Date:14:13, 2 May 2015
Author:admin
Status:new
Tags:
Comment:
Move Sampler Objects to glUtil object.
Modified paths:
  • /ddraw/TextureManager.c (modified) (history)
  • /ddraw/TextureManager.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/glUtil.cpp (modified) (history)
  • /ddraw/glUtil.h (modified) (history)

Diff [purge]

Index: ddraw/TextureManager.c
@@ -108,37 +108,6 @@
109109 TextureManager_DownloadTextureClassic(This, texture, level, data);
110110 }
111111
112 -void TextureManager_InitSamplers(TextureManager *This)
113 -{
114 - int i;
115 - if(This->ext->GLEXT_ARB_sampler_objects)
116 - {
117 - memset(This->samplers,0,8*sizeof(SAMPLER));
118 - for(i = 0; i < 8; i++)
119 - {
120 - This->ext->glGenSamplers(1,&This->samplers[i].id);
121 - This->ext->glBindSampler(i,This->samplers[i].id);
122 - This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
123 - This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
124 - This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
125 - This->ext->glSamplerParameteri(This->samplers[i].id,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
126 - }
127 - }
128 -}
129 -void TextureManager_DeleteSamplers(TextureManager *This)
130 -{
131 - int i;
132 - if(This->ext->GLEXT_ARB_sampler_objects)
133 - {
134 - for(i = 0; i < 8; i++)
135 - {
136 - This->ext->glBindSampler(i,0);
137 - This->ext->glDeleteSamplers(1,&This->samplers[i].id);
138 - This->samplers[i].id = 0;
139 - }
140 - }
141 -}
142 -
143112 void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height)
144113 {
145114 int texformat = -1;
Index: ddraw/TextureManager.h
@@ -27,6 +27,7 @@
2828
2929 typedef struct TEXTURE
3030 {
 31+ UINT refcount;
3132 GLuint id;
3233 GLsizei width;
3334 GLsizei height;
@@ -57,21 +58,11 @@
5859 // 6 - Alpha
5960 // 7 - Luminance Alpha
6061
61 -typedef struct
62 -{
63 - GLuint id;
64 - GLint wraps;
65 - GLint wrapt;
66 - GLint minfilter;
67 - GLint magfilter;
68 -} SAMPLER;
69 -
7062 extern const DDPIXELFORMAT texformats[];
7163 extern int numtexformats;
7264
7365 typedef struct TextureManager
7466 {
75 - SAMPLER samplers[8];
7667 glExtensions *ext;
7768 GLint texlevel;
7869 GLuint textures[16];
@@ -80,8 +71,6 @@
8172 DWORD CalculateMipLevels(DWORD width, DWORD height);
8273
8374 TextureManager *TextureManager_Create(glExtensions *glext);
84 -void TextureManager_InitSamplers(TextureManager *This);
85 -void TextureManager_DeleteSamplers(TextureManager *This);
8675 void TextureManager_SetActiveTexture(TextureManager *This, int level);
8776 void TextureManager_SetTexture(TextureManager *This, unsigned int level, TEXTURE *texture);
8877 void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height);
Index: ddraw/glDirectDrawSurface.cpp
@@ -1702,7 +1702,7 @@
17031703 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
17041704 TRACE_RET(HRESULT,23,Unlock((LPRECT)lpSurfaceData));
17051705 }
1706 -void glDirectDrawSurface7::SetFilter(int level, GLint mag, GLint min, glExtensions *ext, TextureManager *texman)
 1706+void glDirectDrawSurface7::SetFilter(int level, GLint mag, GLint min, glExtensions *ext, glUtil *util, TextureManager *texman)
17071707 {
17081708 TRACE_ENTER(4,14,this,11,level,11,mag,11,min);
17091709 switch(dxglcfg.texfilter)
@@ -1734,8 +1734,8 @@
17351735 }
17361736 if(ext->GLEXT_ARB_sampler_objects)
17371737 {
1738 - ext->glSamplerParameteri(texman->samplers[level].id,GL_TEXTURE_MAG_FILTER,mag);
1739 - ext->glSamplerParameteri(texman->samplers[level].id,GL_TEXTURE_MIN_FILTER,min);
 1738+ ext->glSamplerParameteri(util->samplers[level].id,GL_TEXTURE_MAG_FILTER,mag);
 1739+ ext->glSamplerParameteri(util->samplers[level].id,GL_TEXTURE_MIN_FILTER,min);
17401740 }
17411741 else
17421742 {
Index: ddraw/glDirectDrawSurface.h
@@ -110,7 +110,7 @@
111111 ULONG WINAPI ReleaseGamma();
112112 ULONG WINAPI AddRefColor();
113113 ULONG WINAPI ReleaseColor();
114 - void SetFilter(int level, GLint mag, GLint min, glExtensions *ext, TextureManager *texman);
 114+ void SetFilter(int level, GLint mag, GLint min, glExtensions *ext, glUtil *util, TextureManager *texman);
115115 TEXTURE *GetTexture(){
116116 return texture;
117117 }
Index: ddraw/glRenderer.cpp
@@ -888,7 +888,6 @@
889889 if(This->dib.hdc) DeleteDC(This->dib.hdc);
890890 ZeroMemory(&This->dib,sizeof(DIB));
891891 }
892 - TextureManager_DeleteSamplers(This->texman);
893892 glUtil_DeleteFBO(This->util, &This->fbo);
894893 if(This->pbo)
895894 {
@@ -1151,7 +1150,6 @@
11521151 }
11531152 BufferObject_Create(&This->pbo, This->ext, This->util);
11541153 BufferObject_SetData(This->pbo, GL_PIXEL_PACK_BUFFER, width*height * 4, NULL, GL_STREAM_READ);
1155 - TextureManager_InitSamplers(This->texman);
11561154 TRACE_SYSINFO();
11571155 return TRUE;
11581156 }
@@ -1486,8 +1484,8 @@
14871485 if(This->ext->GLEXT_ARB_sampler_objects)
14881486 {
14891487 if((dxglcfg.scalingfilter == 0) || (This->ddInterface->GetBPP() == 8))
1490 - src->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->texman);
1491 - else src->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->texman);
 1488+ src->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
 1489+ else src->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util,This->texman);
14921490 }
14931491 }
14941492 else TextureManager_SetTexture(This->texman,0,NULL);
@@ -1560,7 +1558,7 @@
15611559 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
15621560 TextureManager_SetTexture(This->texman,0,*texture);
15631561 *texture = This->backbuffer;
1564 - if(This->ext->GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->texman);
 1562+ if(This->ext->GLEXT_ARB_sampler_objects) ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util,This->texman);
15651563 This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
15661564 This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
15671565 This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
@@ -1714,8 +1712,8 @@
17151713 }
17161714 if(This->ext->GLEXT_ARB_sampler_objects)
17171715 {
1718 - ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->texman);
1719 - ((glDirectDrawSurface7*)NULL)->SetFilter(1,GL_NEAREST,GL_NEAREST,This->ext,This->texman);
 1716+ ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
 1717+ ((glDirectDrawSurface7*)NULL)->SetFilter(1,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
17201718 }
17211719 }
17221720 else
@@ -1726,9 +1724,9 @@
17271725 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
17281726 }
17291727 if(dxglcfg.scalingfilter && This->ext->GLEXT_ARB_sampler_objects)
1730 - ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->texman);
 1728+ ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_LINEAR,GL_LINEAR,This->ext,This->util,This->texman);
17311729 else if(This->ext->GLEXT_ARB_sampler_objects)
1732 - ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->texman);
 1730+ ((glDirectDrawSurface7*)NULL)->SetFilter(0,GL_NEAREST,GL_NEAREST,This->ext,This->util,This->texman);
17331731 glUtil_SetViewport(This->util,viewport[0],viewport[1],viewport[2],viewport[3]);
17341732 This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
17351733 if(This->ddInterface->GetFullscreen())
@@ -2305,7 +2303,7 @@
23062304 This->texstages[i].texture->dirty &= ~1;
23072305 }
23082306 if(This->texstages[i].texture)
2309 - This->texstages[i].texture->SetFilter(i,This->texstages[i].glmagfilter,This->texstages[i].glminfilter,This->ext,This->texman);
 2307+ This->texstages[i].texture->SetFilter(i,This->texstages[i].glmagfilter,This->texstages[i].glminfilter,This->ext,This->util,This->texman);
23102308 TextureManager_SetTexture(This->texman,i,This->texstages[i].texture->texture);
23112309 glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu, This->texman);
23122310 glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv, This->texman);
Index: ddraw/glUtil.cpp
@@ -71,6 +71,21 @@
7272 util->vboElementArrayBinding = util->uboUniformBufferBinding = util->LastBoundBuffer = NULL;
7373 util->refcount = 1;
7474 *out = util;
 75+ int i;
 76+ if (glext->GLEXT_ARB_sampler_objects)
 77+ {
 78+ memset(util->samplers, 0, 8 * sizeof(SAMPLER));
 79+ for (i = 0; i < 8; i++)
 80+ {
 81+ glext->glGenSamplers(1, &util->samplers[i].id);
 82+ glext->glBindSampler(i, util->samplers[i].id);
 83+ glext->glSamplerParameteri(util->samplers[i].id, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
 84+ glext->glSamplerParameteri(util->samplers[i].id, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
 85+ glext->glSamplerParameteri(util->samplers[i].id, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
 86+ glext->glSamplerParameteri(util->samplers[i].id, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 87+ }
 88+ }
 89+
7590 }
7691
7792 void glUtil_AddRef(glUtil *This)
@@ -81,7 +96,20 @@
8297 void glUtil_Release(glUtil *This)
8398 {
8499 InterlockedDecrement(&This->refcount);
85 - if (!This->refcount) free(This);
 100+ if (!This->refcount)
 101+ {
 102+ int i;
 103+ if (This->ext->GLEXT_ARB_sampler_objects)
 104+ {
 105+ for (i = 0; i < 8; i++)
 106+ {
 107+ This->ext->glBindSampler(i, 0);
 108+ This->ext->glDeleteSamplers(1, &This->samplers[i].id);
 109+ This->samplers[i].id = 0;
 110+ }
 111+ }
 112+ free(This);
 113+ }
86114 }
87115
88116 void glUtil_InitFBO(glUtil *This, FBO *fbo)
@@ -263,18 +291,18 @@
264292 {
265293 if(coord)
266294 {
267 - if(texman->samplers[level].wrapt != wrapmode)
 295+ if(This->samplers[level].wrapt != wrapmode)
268296 {
269 - This->ext->glSamplerParameteri(texman->samplers[level].id, GL_TEXTURE_WRAP_T, wrapmode);
270 - texman->samplers[level].wrapt = wrapmode;
 297+ This->ext->glSamplerParameteri(This->samplers[level].id, GL_TEXTURE_WRAP_T, wrapmode);
 298+ This->samplers[level].wrapt = wrapmode;
271299 }
272300 }
273301 else
274302 {
275 - if(texman->samplers[level].wraps != wrapmode)
 303+ if(This->samplers[level].wraps != wrapmode)
276304 {
277 - This->ext->glSamplerParameteri(texman->samplers[level].id, GL_TEXTURE_WRAP_S, wrapmode);
278 - texman->samplers[level].wraps = wrapmode;
 305+ This->ext->glSamplerParameteri(This->samplers[level].id, GL_TEXTURE_WRAP_S, wrapmode);
 306+ This->samplers[level].wraps = wrapmode;
279307 }
280308 }
281309 }
Index: ddraw/glUtil.h
@@ -30,8 +30,17 @@
3131 struct BufferObject;
3232 struct TextureManager;
3333
34 -typedef struct
 34+typedef struct SAMPLER
3535 {
 36+ GLuint id;
 37+ GLint wraps;
 38+ GLint wrapt;
 39+ GLint minfilter;
 40+ GLint magfilter;
 41+} SAMPLER;
 42+
 43+typedef struct FBO
 44+{
3645 GLuint fbo;
3746 TEXTURE *fbcolor;
3847 TEXTURE *fbz;
@@ -94,6 +103,7 @@
95104 D3DFILLMODE polymode;
96105 D3DSHADEMODE shademode;
97106 BufferObject *LastBoundBuffer;
 107+ SAMPLER samplers[8];
98108 } glUtil;
99109
100110 void glUtil_Create(glExtensions *glext, glUtil **out);