Index: ddraw/TextureManager.c |
— | — | @@ -108,37 +108,6 @@ |
109 | 109 | TextureManager_DownloadTextureClassic(This, texture, level, data);
|
110 | 110 | }
|
111 | 111 |
|
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 | | -
|
143 | 112 | void TextureManager_CreateTextureClassic(TextureManager *This, TEXTURE *texture, int width, int height)
|
144 | 113 | {
|
145 | 114 | int texformat = -1;
|
Index: ddraw/TextureManager.h |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 |
|
29 | 29 | typedef struct TEXTURE
|
30 | 30 | {
|
| 31 | + UINT refcount;
|
31 | 32 | GLuint id;
|
32 | 33 | GLsizei width;
|
33 | 34 | GLsizei height;
|
— | — | @@ -57,21 +58,11 @@ |
58 | 59 | // 6 - Alpha
|
59 | 60 | // 7 - Luminance Alpha
|
60 | 61 |
|
61 | | -typedef struct
|
62 | | -{
|
63 | | - GLuint id;
|
64 | | - GLint wraps;
|
65 | | - GLint wrapt;
|
66 | | - GLint minfilter;
|
67 | | - GLint magfilter;
|
68 | | -} SAMPLER;
|
69 | | -
|
70 | 62 | extern const DDPIXELFORMAT texformats[];
|
71 | 63 | extern int numtexformats;
|
72 | 64 |
|
73 | 65 | typedef struct TextureManager
|
74 | 66 | {
|
75 | | - SAMPLER samplers[8];
|
76 | 67 | glExtensions *ext;
|
77 | 68 | GLint texlevel;
|
78 | 69 | GLuint textures[16];
|
— | — | @@ -80,8 +71,6 @@ |
81 | 72 | DWORD CalculateMipLevels(DWORD width, DWORD height);
|
82 | 73 |
|
83 | 74 | TextureManager *TextureManager_Create(glExtensions *glext);
|
84 | | -void TextureManager_InitSamplers(TextureManager *This);
|
85 | | -void TextureManager_DeleteSamplers(TextureManager *This);
|
86 | 75 | void TextureManager_SetActiveTexture(TextureManager *This, int level);
|
87 | 76 | void TextureManager_SetTexture(TextureManager *This, unsigned int level, TEXTURE *texture);
|
88 | 77 | void TextureManager__CreateTexture(TextureManager *This, TEXTURE *texture, int width, int height);
|
Index: ddraw/glDirectDrawSurface.cpp |
— | — | @@ -1702,7 +1702,7 @@ |
1703 | 1703 | if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
|
1704 | 1704 | TRACE_RET(HRESULT,23,Unlock((LPRECT)lpSurfaceData));
|
1705 | 1705 | }
|
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)
|
1707 | 1707 | {
|
1708 | 1708 | TRACE_ENTER(4,14,this,11,level,11,mag,11,min);
|
1709 | 1709 | switch(dxglcfg.texfilter)
|
— | — | @@ -1734,8 +1734,8 @@ |
1735 | 1735 | }
|
1736 | 1736 | if(ext->GLEXT_ARB_sampler_objects)
|
1737 | 1737 | {
|
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);
|
1740 | 1740 | }
|
1741 | 1741 | else
|
1742 | 1742 | {
|
Index: ddraw/glDirectDrawSurface.h |
— | — | @@ -110,7 +110,7 @@ |
111 | 111 | ULONG WINAPI ReleaseGamma();
|
112 | 112 | ULONG WINAPI AddRefColor();
|
113 | 113 | 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);
|
115 | 115 | TEXTURE *GetTexture(){
|
116 | 116 | return texture;
|
117 | 117 | }
|
Index: ddraw/glRenderer.cpp |
— | — | @@ -888,7 +888,6 @@ |
889 | 889 | if(This->dib.hdc) DeleteDC(This->dib.hdc);
|
890 | 890 | ZeroMemory(&This->dib,sizeof(DIB));
|
891 | 891 | }
|
892 | | - TextureManager_DeleteSamplers(This->texman);
|
893 | 892 | glUtil_DeleteFBO(This->util, &This->fbo);
|
894 | 893 | if(This->pbo)
|
895 | 894 | {
|
— | — | @@ -1151,7 +1150,6 @@ |
1152 | 1151 | }
|
1153 | 1152 | BufferObject_Create(&This->pbo, This->ext, This->util);
|
1154 | 1153 | BufferObject_SetData(This->pbo, GL_PIXEL_PACK_BUFFER, width*height * 4, NULL, GL_STREAM_READ);
|
1155 | | - TextureManager_InitSamplers(This->texman);
|
1156 | 1154 | TRACE_SYSINFO();
|
1157 | 1155 | return TRUE;
|
1158 | 1156 | }
|
— | — | @@ -1486,8 +1484,8 @@ |
1487 | 1485 | if(This->ext->GLEXT_ARB_sampler_objects)
|
1488 | 1486 | {
|
1489 | 1487 | 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);
|
1492 | 1490 | }
|
1493 | 1491 | }
|
1494 | 1492 | else TextureManager_SetTexture(This->texman,0,NULL);
|
— | — | @@ -1560,7 +1558,7 @@ |
1561 | 1559 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
1562 | 1560 | TextureManager_SetTexture(This->texman,0,*texture);
|
1563 | 1561 | *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);
|
1565 | 1563 | This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
|
1566 | 1564 | This->bltvertices[0].s = This->bltvertices[0].t = This->bltvertices[1].t = This->bltvertices[2].s = 1.;
|
1567 | 1565 | This->bltvertices[1].s = This->bltvertices[2].t = This->bltvertices[3].s = This->bltvertices[3].t = 0.;
|
— | — | @@ -1714,8 +1712,8 @@ |
1715 | 1713 | }
|
1716 | 1714 | if(This->ext->GLEXT_ARB_sampler_objects)
|
1717 | 1715 | {
|
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);
|
1720 | 1718 | }
|
1721 | 1719 | }
|
1722 | 1720 | else
|
— | — | @@ -1726,9 +1724,9 @@ |
1727 | 1725 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
1728 | 1726 | }
|
1729 | 1727 | 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);
|
1731 | 1729 | 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);
|
1733 | 1731 | glUtil_SetViewport(This->util,viewport[0],viewport[1],viewport[2],viewport[3]);
|
1734 | 1732 | This->ext->glUniform4f(This->shaders->shaders[progtype].view,view[0],view[1],view[2],view[3]);
|
1735 | 1733 | if(This->ddInterface->GetFullscreen())
|
— | — | @@ -2305,7 +2303,7 @@ |
2306 | 2304 | This->texstages[i].texture->dirty &= ~1;
|
2307 | 2305 | }
|
2308 | 2306 | 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);
|
2310 | 2308 | TextureManager_SetTexture(This->texman,i,This->texstages[i].texture->texture);
|
2311 | 2309 | glUtil_SetWrap(This->util, i, 0, This->texstages[i].addressu, This->texman);
|
2312 | 2310 | glUtil_SetWrap(This->util, i, 1, This->texstages[i].addressv, This->texman);
|
Index: ddraw/glUtil.cpp |
— | — | @@ -71,6 +71,21 @@ |
72 | 72 | util->vboElementArrayBinding = util->uboUniformBufferBinding = util->LastBoundBuffer = NULL;
|
73 | 73 | util->refcount = 1;
|
74 | 74 | *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 | +
|
75 | 90 | }
|
76 | 91 |
|
77 | 92 | void glUtil_AddRef(glUtil *This)
|
— | — | @@ -81,7 +96,20 @@ |
82 | 97 | void glUtil_Release(glUtil *This)
|
83 | 98 | {
|
84 | 99 | 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 | + }
|
86 | 114 | }
|
87 | 115 |
|
88 | 116 | void glUtil_InitFBO(glUtil *This, FBO *fbo)
|
— | — | @@ -263,18 +291,18 @@ |
264 | 292 | {
|
265 | 293 | if(coord)
|
266 | 294 | {
|
267 | | - if(texman->samplers[level].wrapt != wrapmode)
|
| 295 | + if(This->samplers[level].wrapt != wrapmode)
|
268 | 296 | {
|
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;
|
271 | 299 | }
|
272 | 300 | }
|
273 | 301 | else
|
274 | 302 | {
|
275 | | - if(texman->samplers[level].wraps != wrapmode)
|
| 303 | + if(This->samplers[level].wraps != wrapmode)
|
276 | 304 | {
|
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;
|
279 | 307 | }
|
280 | 308 | }
|
281 | 309 | }
|
Index: ddraw/glUtil.h |
— | — | @@ -30,8 +30,17 @@ |
31 | 31 | struct BufferObject;
|
32 | 32 | struct TextureManager;
|
33 | 33 |
|
34 | | -typedef struct
|
| 34 | +typedef struct SAMPLER
|
35 | 35 | {
|
| 36 | + GLuint id;
|
| 37 | + GLint wraps;
|
| 38 | + GLint wrapt;
|
| 39 | + GLint minfilter;
|
| 40 | + GLint magfilter;
|
| 41 | +} SAMPLER;
|
| 42 | +
|
| 43 | +typedef struct FBO
|
| 44 | +{
|
36 | 45 | GLuint fbo;
|
37 | 46 | TEXTURE *fbcolor;
|
38 | 47 | TEXTURE *fbz;
|
— | — | @@ -94,6 +103,7 @@ |
95 | 104 | D3DFILLMODE polymode;
|
96 | 105 | D3DSHADEMODE shademode;
|
97 | 106 | BufferObject *LastBoundBuffer;
|
| 107 | + SAMPLER samplers[8];
|
98 | 108 | } glUtil;
|
99 | 109 |
|
100 | 110 | void glUtil_Create(glExtensions *glext, glUtil **out);
|