Index: ddraw/ShaderGen2D.h |
— | — | @@ -19,8 +19,12 @@ |
20 | 20 | #ifndef _SHADERGEN2D_H
|
21 | 21 | #define _SHADERGEN2D_H
|
22 | 22 |
|
23 | | -class ShaderManager;
|
| 23 | +#ifdef __cplusplus
|
| 24 | +extern "C" {
|
| 25 | +#endif
|
24 | 26 |
|
| 27 | +struct ShaderManager;
|
| 28 | +
|
25 | 29 | typedef struct
|
26 | 30 | {
|
27 | 31 | GLint vs;
|
— | — | @@ -59,4 +63,8 @@ |
60 | 64 | void ShaderGen2D_Delete(ShaderGen2D *gen);
|
61 | 65 | void ShaderGen2D_CreateShader2D(ShaderGen2D *gen, int index, DWORD id);
|
62 | 66 |
|
| 67 | +#ifdef __cplusplus
|
| 68 | +}
|
| 69 | +#endif
|
| 70 | +
|
63 | 71 | #endif //_SHADERGEN2D_H |
\ No newline at end of file |
Index: ddraw/ShaderManager.cpp |
— | — | @@ -21,13 +21,13 @@ |
22 | 22 | #include "timer.h"
|
23 | 23 | #include "glRenderer.h"
|
24 | 24 | #include "glDirect3DDevice.h"
|
25 | | -#include <string>
|
26 | | -using namespace std;
|
27 | 25 | #include "string.h"
|
28 | 26 | #include "ShaderManager.h"
|
29 | 27 | #include "ShaderGen3D.h"
|
30 | 28 | #include "ShaderGen2D.h"
|
31 | 29 |
|
| 30 | +extern "C" {
|
| 31 | +
|
32 | 32 | const char frag_Texture[] = "\
|
33 | 33 | #version 110\n\
|
34 | 34 | uniform sampler2D tex0;\n\
|
— | — | @@ -132,77 +132,80 @@ |
133 | 133 | const int SHADER_END = __LINE__ - 4;
|
134 | 134 | const int NumberOfShaders = SHADER_END - SHADER_START;
|
135 | 135 |
|
136 | | -ShaderManager::ShaderManager(glExtensions *glext)
|
| 136 | +
|
| 137 | +void ShaderManager_Init(glExtensions *glext, ShaderManager *shaderman)
|
137 | 138 | {
|
138 | | - ext = glext;
|
139 | | - shaders = (SHADER*)malloc(sizeof(SHADER)*NumberOfShaders);
|
140 | | - memcpy(shaders, shader_template, sizeof(SHADER)*NumberOfShaders);
|
| 139 | + shaderman->ext = glext;
|
| 140 | + shaderman->shaders = (SHADER*)malloc(sizeof(SHADER)*NumberOfShaders);
|
| 141 | + memcpy(shaderman->shaders, shader_template, sizeof(SHADER)*NumberOfShaders);
|
141 | 142 | const GLchar *src;
|
142 | 143 | GLint srclen;
|
143 | 144 | for(int i = 0; i < NumberOfShaders; i++)
|
144 | 145 | {
|
145 | | - shaders[i].prog = ext->glCreateProgram();
|
146 | | - if(shaders[i].vsrc)
|
| 146 | + shaderman->shaders[i].prog = shaderman->ext->glCreateProgram();
|
| 147 | + if(shaderman->shaders[i].vsrc)
|
147 | 148 | {
|
148 | | - shaders[i].vs = ext->glCreateShader(GL_VERTEX_SHADER);
|
149 | | - src = shaders[i].vsrc;
|
150 | | - srclen = strlen(shaders[i].vsrc);
|
151 | | - ext->glShaderSource(shaders[i].vs,1,&src,&srclen);
|
152 | | - ext->glCompileShader(shaders[i].vs);
|
153 | | - ext->glAttachShader(shaders[i].prog,shaders[i].vs);
|
| 149 | + shaderman->shaders[i].vs = shaderman->ext->glCreateShader(GL_VERTEX_SHADER);
|
| 150 | + src = shaderman->shaders[i].vsrc;
|
| 151 | + srclen = strlen(shaderman->shaders[i].vsrc);
|
| 152 | + shaderman->ext->glShaderSource(shaderman->shaders[i].vs,1,&src,&srclen);
|
| 153 | + shaderman->ext->glCompileShader(shaderman->shaders[i].vs);
|
| 154 | + shaderman->ext->glAttachShader(shaderman->shaders[i].prog,shaderman->shaders[i].vs);
|
154 | 155 | }
|
155 | | - if(shaders[i].fsrc)
|
| 156 | + if(shaderman->shaders[i].fsrc)
|
156 | 157 | {
|
157 | | - shaders[i].fs = ext->glCreateShader(GL_FRAGMENT_SHADER);
|
158 | | - src = shaders[i].fsrc;
|
159 | | - srclen = strlen(shaders[i].fsrc);
|
160 | | - ext->glShaderSource(shaders[i].fs,1,&src,&srclen);
|
161 | | - ext->glCompileShader(shaders[i].fs);
|
162 | | - ext->glAttachShader(shaders[i].prog,shaders[i].fs);
|
| 158 | + shaderman->shaders[i].fs = shaderman->ext->glCreateShader(GL_FRAGMENT_SHADER);
|
| 159 | + src = shaderman->shaders[i].fsrc;
|
| 160 | + srclen = strlen(shaderman->shaders[i].fsrc);
|
| 161 | + shaderman->ext->glShaderSource(shaderman->shaders[i].fs,1,&src,&srclen);
|
| 162 | + shaderman->ext->glCompileShader(shaderman->shaders[i].fs);
|
| 163 | + shaderman->ext->glAttachShader(shaderman->shaders[i].prog,shaderman->shaders[i].fs);
|
163 | 164 | }
|
164 | | - ext->glLinkProgram(shaders[i].prog);
|
165 | | - shaders[i].pos = ext->glGetAttribLocation(shaders[i].prog,"xy");
|
166 | | - shaders[i].texcoord = ext->glGetAttribLocation(shaders[i].prog,"st");
|
167 | | - shaders[i].tex0 = ext->glGetUniformLocation(shaders[i].prog,"tex0");
|
168 | | - shaders[i].tex1 = ext->glGetUniformLocation(shaders[i].prog,"tex1");
|
169 | | - shaders[i].ckey = ext->glGetUniformLocation(shaders[i].prog,"ckey");
|
170 | | - shaders[i].pal = ext->glGetUniformLocation(shaders[i].prog,"pal");
|
171 | | - shaders[i].view = ext->glGetUniformLocation(shaders[i].prog,"view");
|
| 165 | + shaderman->ext->glLinkProgram(shaderman->shaders[i].prog);
|
| 166 | + shaderman->shaders[i].pos = shaderman->ext->glGetAttribLocation(shaderman->shaders[i].prog,"xy");
|
| 167 | + shaderman->shaders[i].texcoord = shaderman->ext->glGetAttribLocation(shaderman->shaders[i].prog,"st");
|
| 168 | + shaderman->shaders[i].tex0 = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"tex0");
|
| 169 | + shaderman->shaders[i].tex1 = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"tex1");
|
| 170 | + shaderman->shaders[i].ckey = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"ckey");
|
| 171 | + shaderman->shaders[i].pal = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"pal");
|
| 172 | + shaderman->shaders[i].view = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"view");
|
172 | 173 | }
|
173 | | - gen3d = new ShaderGen3D(ext, this);
|
174 | | - gen2d = (ShaderGen2D*)malloc(sizeof(ShaderGen2D));
|
175 | | - ZeroMemory(gen2d, sizeof(ShaderGen2D));
|
176 | | - ShaderGen2D_Init(gen2d, ext, this);
|
| 174 | + shaderman->gen3d = new ShaderGen3D(shaderman->ext, shaderman);
|
| 175 | + shaderman->gen2d = (ShaderGen2D*)malloc(sizeof(ShaderGen2D));
|
| 176 | + ZeroMemory(shaderman->gen2d, sizeof(ShaderGen2D));
|
| 177 | + ShaderGen2D_Init(shaderman->gen2d, shaderman->ext, shaderman);
|
177 | 178 | }
|
178 | 179 |
|
179 | | -ShaderManager::~ShaderManager()
|
| 180 | +void ShaderManager_Delete(ShaderManager *This)
|
180 | 181 | {
|
181 | | - ext->glUseProgram(0);
|
| 182 | + This->ext->glUseProgram(0);
|
182 | 183 | for(int i = 0; i < NumberOfShaders; i++)
|
183 | 184 | {
|
184 | | - if(shaders[i].prog)
|
| 185 | + if(This->shaders[i].prog)
|
185 | 186 | {
|
186 | | - ext->glDeleteProgram(shaders[i].prog);
|
187 | | - shaders[i].prog = 0;
|
| 187 | + This->ext->glDeleteProgram(This->shaders[i].prog);
|
| 188 | + This->shaders[i].prog = 0;
|
188 | 189 | }
|
189 | | - if(shaders[i].vs)
|
| 190 | + if(This->shaders[i].vs)
|
190 | 191 | {
|
191 | | - ext->glDeleteShader(shaders[i].vs);
|
192 | | - shaders[i].vs = 0;
|
| 192 | + This->ext->glDeleteShader(This->shaders[i].vs);
|
| 193 | + This->shaders[i].vs = 0;
|
193 | 194 | }
|
194 | | - if(shaders[i].fs)
|
| 195 | + if(This->shaders[i].fs)
|
195 | 196 | {
|
196 | | - ext->glDeleteShader(shaders[i].fs);
|
197 | | - shaders[i].fs = 0;
|
| 197 | + This->ext->glDeleteShader(This->shaders[i].fs);
|
| 198 | + This->shaders[i].fs = 0;
|
198 | 199 | }
|
199 | 200 | }
|
200 | | - free(shaders);
|
201 | | - ShaderGen2D_Delete(gen2d);
|
202 | | - free(gen2d);
|
203 | | - delete gen3d;
|
| 201 | + free(This->shaders);
|
| 202 | + ShaderGen2D_Delete(This->gen2d);
|
| 203 | + free(This->gen2d);
|
| 204 | + delete This->gen3d;
|
204 | 205 | }
|
205 | 206 |
|
206 | | -void ShaderManager::SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type)
|
| 207 | +void ShaderManager_SetShader(ShaderManager *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type)
|
207 | 208 | {
|
208 | | - gen3d->SetShader(id, texstate, texcoords, type, gen2d);
|
| 209 | + This->gen3d->SetShader(id, texstate, texcoords, type, This->gen2d);
|
| 210 | +}
|
| 211 | +
|
209 | 212 | } |
\ No newline at end of file |
Index: ddraw/ShaderManager.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011-2012 William Feely
|
| 3 | +// Copyright (C) 2011-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
— | — | @@ -19,6 +19,10 @@ |
20 | 20 | #ifndef __SHADERS_H
|
21 | 21 | #define __SHADERS_H
|
22 | 22 |
|
| 23 | +#ifdef __cplusplus
|
| 24 | +extern "C" {
|
| 25 | +#endif
|
| 26 | +
|
23 | 27 | typedef struct
|
24 | 28 | {
|
25 | 29 | GLint vs;
|
— | — | @@ -47,17 +51,20 @@ |
48 | 52 | struct TEXTURESTAGE;
|
49 | 53 | class ShaderGen3D;
|
50 | 54 |
|
51 | | -class ShaderManager
|
| 55 | +typedef struct ShaderManager
|
52 | 56 | {
|
53 | | -public:
|
54 | | - ShaderManager(glExtensions *glext);
|
55 | | - ~ShaderManager();
|
56 | | - void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type);
|
57 | 57 | SHADER *shaders;
|
58 | 58 | ShaderGen3D *gen3d;
|
59 | 59 | ShaderGen2D *gen2d;
|
60 | | -private:
|
61 | 60 | glExtensions *ext;
|
62 | | -};
|
| 61 | +} ShaderManager;
|
63 | 62 |
|
| 63 | +void ShaderManager_Init(glExtensions *glext, ShaderManager *shaderman);
|
| 64 | +void ShaderManager_Delete(ShaderManager *This);
|
| 65 | +void ShaderManager_SetShader(ShaderManager *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type);
|
| 66 | +
|
| 67 | +#ifdef __cplusplus
|
| 68 | +}
|
| 69 | +#endif
|
| 70 | +
|
64 | 71 | #endif //__SHADERS_H |
\ No newline at end of file |
Index: ddraw/glRenderer.cpp |
— | — | @@ -732,7 +732,8 @@ |
733 | 733 | This->backx = 0;
|
734 | 734 | This->backy = 0;
|
735 | 735 | }
|
736 | | - delete This->shaders;
|
| 736 | + ShaderManager_Delete(This->shaders);
|
| 737 | + free(This->shaders);
|
737 | 738 | free(This->texman);
|
738 | 739 | free(This->ext);
|
739 | 740 | delete This->util;
|
— | — | @@ -909,7 +910,8 @@ |
910 | 911 | }
|
911 | 912 | else This->gl_caps.ShaderVer = 0;
|
912 | 913 | glGetIntegerv(GL_MAX_TEXTURE_SIZE,&This->gl_caps.TextureMax);
|
913 | | - This->shaders = new ShaderManager(This->ext);
|
| 914 | + This->shaders = (ShaderManager*)malloc(sizeof(ShaderManager));
|
| 915 | + ShaderManager_Init(This->ext, This->shaders);
|
914 | 916 | This->fbo.fbo = 0;
|
915 | 917 | This->util->InitFBO(&This->fbo);
|
916 | 918 | This->util->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
— | — | @@ -1185,7 +1187,7 @@ |
1186 | 1188 | if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
|
1187 | 1189 | if (usedest)
|
1188 | 1190 | {
|
1189 | | - This->shaders->SetShader(PROG_TEXTURE, NULL, NULL, 0);
|
| 1191 | + ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, NULL, 0);
|
1190 | 1192 | glRenderer__DrawBackbufferRect(This, dest->texture, destrect, PROG_TEXTURE);
|
1191 | 1193 | This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
|
1192 | 1194 | This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
|
— | — | @@ -1192,7 +1194,7 @@ |
1193 | 1195 | This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
|
1194 | 1196 | This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
|
1195 | 1197 | }
|
1196 | | - This->shaders->SetShader(shaderid, NULL, NULL, 1);
|
| 1198 | + ShaderManager_SetShader(This->shaders, shaderid, NULL, NULL, 1);
|
1197 | 1199 | GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
|
1198 | 1200 | This->util->BlendEnable(false);
|
1199 | 1201 | do
|
— | — | @@ -1501,7 +1503,7 @@ |
1502 | 1504 | glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
1503 | 1505 | if(This->ddInterface->GetBPP() == 8)
|
1504 | 1506 | {
|
1505 | | - This->shaders->SetShader(PROG_PAL256,NULL,NULL,0);
|
| 1507 | + ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,NULL,0);
|
1506 | 1508 | progtype = PROG_PAL256;
|
1507 | 1509 | TextureManager__UploadTexture(This->texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1,FALSE);
|
1508 | 1510 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
— | — | @@ -1511,7 +1513,7 @@ |
1512 | 1514 | if(dxglcfg.scalingfilter)
|
1513 | 1515 | {
|
1514 | 1516 | glRenderer__DrawBackbuffer(This,&texture,dest->fakex,dest->fakey,progtype);
|
1515 | | - This->shaders->SetShader(PROG_TEXTURE,NULL,NULL,0);
|
| 1517 | + ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,NULL,0);
|
1516 | 1518 | progtype = PROG_TEXTURE;
|
1517 | 1519 | TextureManager_SetTexture(This->texman,0,texture);
|
1518 | 1520 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
— | — | @@ -1524,7 +1526,7 @@ |
1525 | 1527 | }
|
1526 | 1528 | else
|
1527 | 1529 | {
|
1528 | | - This->shaders->SetShader(PROG_TEXTURE,NULL,NULL,0);
|
| 1530 | + ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,NULL,0);
|
1529 | 1531 | progtype = PROG_TEXTURE;
|
1530 | 1532 | TextureManager_SetTexture(This->texman,0,texture);
|
1531 | 1533 | This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
|
— | — | @@ -1828,7 +1830,7 @@ |
1829 | 1831 | return;
|
1830 | 1832 | }
|
1831 | 1833 | __int64 shader = device->SelectShader(vertices);
|
1832 | | - This->shaders->SetShader(shader,device->texstages,texformats,2);
|
| 1834 | + ShaderManager_SetShader(This->shaders,shader,device->texstages,texformats,2);
|
1833 | 1835 | device->SetDepthComp(This->util);
|
1834 | 1836 | if(device->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
|
1835 | 1837 | else This->util->DepthTest(false);
|
— | — | @@ -2065,7 +2067,7 @@ |
2066 | 2068 | view[3] = (GLfloat)surface->ddsd.dwHeight;
|
2067 | 2069 | This->util->SetViewport(0,0,surface->ddsd.dwWidth,surface->ddsd.dwHeight);
|
2068 | 2070 | glClear(GL_COLOR_BUFFER_BIT);
|
2069 | | - This->shaders->SetShader(PROG_CLIPSTENCIL,NULL,NULL,0);
|
| 2071 | + ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,NULL,0);
|
2070 | 2072 | This->ext->glUniform4f(This->shaders->shaders[PROG_CLIPSTENCIL].view,view[0],view[1],view[2],view[3]);
|
2071 | 2073 | This->util->EnableArray(This->shaders->shaders[PROG_CLIPSTENCIL].pos,true);
|
2072 | 2074 | This->ext->glVertexAttribPointer(This->shaders->shaders[PROG_CLIPSTENCIL].pos,
|
Index: ddraw/matrix.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2012 William Feely
|
| 3 | +// Copyright (C) 2012-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/scalers.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/scalers.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2011 William Feely
|
| 3 | +// Copyright (C) 2011-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/timer.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
| 3 | +// Copyright (C) 2013-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/timer.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
| 3 | +// Copyright (C) 2013-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/trace.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
| 3 | +// Copyright (C) 2013-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/trace.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
| 3 | +// Copyright (C) 2013-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/util.c |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
| 3 | +// Copyright (C) 2013-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|
Index: ddraw/util.h |
— | — | @@ -1,5 +1,5 @@ |
2 | 2 | // DXGL
|
3 | | -// Copyright (C) 2013 William Feely
|
| 3 | +// Copyright (C) 2013-2014 William Feely
|
4 | 4 |
|
5 | 5 | // This library is free software; you can redistribute it and/or
|
6 | 6 | // modify it under the terms of the GNU Lesser General Public
|