DXGL r509 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r508‎ | r509 | r510 >
Date:00:11, 1 September 2014
Author:admin
Status:new
Tags:
Comment:
Give ShaderGen2D C linkage.
Convert ShaderManager to struct and C linkage.
Update several copyright dates.
Modified paths:
  • /ddraw/ShaderGen2D.h (modified) (history)
  • /ddraw/ShaderManager.cpp (modified) (history)
  • /ddraw/ShaderManager.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/matrix.c (modified) (history)
  • /ddraw/scalers.c (modified) (history)
  • /ddraw/scalers.h (modified) (history)
  • /ddraw/timer.c (modified) (history)
  • /ddraw/timer.h (modified) (history)
  • /ddraw/trace.c (modified) (history)
  • /ddraw/trace.h (modified) (history)
  • /ddraw/util.c (modified) (history)
  • /ddraw/util.h (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen2D.h
@@ -19,8 +19,12 @@
2020 #ifndef _SHADERGEN2D_H
2121 #define _SHADERGEN2D_H
2222
23 -class ShaderManager;
 23+#ifdef __cplusplus
 24+extern "C" {
 25+#endif
2426
 27+struct ShaderManager;
 28+
2529 typedef struct
2630 {
2731 GLint vs;
@@ -59,4 +63,8 @@
6064 void ShaderGen2D_Delete(ShaderGen2D *gen);
6165 void ShaderGen2D_CreateShader2D(ShaderGen2D *gen, int index, DWORD id);
6266
 67+#ifdef __cplusplus
 68+}
 69+#endif
 70+
6371 #endif //_SHADERGEN2D_H
\ No newline at end of file
Index: ddraw/ShaderManager.cpp
@@ -21,13 +21,13 @@
2222 #include "timer.h"
2323 #include "glRenderer.h"
2424 #include "glDirect3DDevice.h"
25 -#include <string>
26 -using namespace std;
2725 #include "string.h"
2826 #include "ShaderManager.h"
2927 #include "ShaderGen3D.h"
3028 #include "ShaderGen2D.h"
3129
 30+extern "C" {
 31+
3232 const char frag_Texture[] = "\
3333 #version 110\n\
3434 uniform sampler2D tex0;\n\
@@ -132,77 +132,80 @@
133133 const int SHADER_END = __LINE__ - 4;
134134 const int NumberOfShaders = SHADER_END - SHADER_START;
135135
136 -ShaderManager::ShaderManager(glExtensions *glext)
 136+
 137+void ShaderManager_Init(glExtensions *glext, ShaderManager *shaderman)
137138 {
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);
141142 const GLchar *src;
142143 GLint srclen;
143144 for(int i = 0; i < NumberOfShaders; i++)
144145 {
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)
147148 {
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);
154155 }
155 - if(shaders[i].fsrc)
 156+ if(shaderman->shaders[i].fsrc)
156157 {
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);
163164 }
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");
172173 }
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);
177178 }
178179
179 -ShaderManager::~ShaderManager()
 180+void ShaderManager_Delete(ShaderManager *This)
180181 {
181 - ext->glUseProgram(0);
 182+ This->ext->glUseProgram(0);
182183 for(int i = 0; i < NumberOfShaders; i++)
183184 {
184 - if(shaders[i].prog)
 185+ if(This->shaders[i].prog)
185186 {
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;
188189 }
189 - if(shaders[i].vs)
 190+ if(This->shaders[i].vs)
190191 {
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;
193194 }
194 - if(shaders[i].fs)
 195+ if(This->shaders[i].fs)
195196 {
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;
198199 }
199200 }
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;
204205 }
205206
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)
207208 {
208 - gen3d->SetShader(id, texstate, texcoords, type, gen2d);
 209+ This->gen3d->SetShader(id, texstate, texcoords, type, This->gen2d);
 210+}
 211+
209212 }
\ No newline at end of file
Index: ddraw/ShaderManager.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011-2012 William Feely
 3+// Copyright (C) 2011-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,10 @@
2020 #ifndef __SHADERS_H
2121 #define __SHADERS_H
2222
 23+#ifdef __cplusplus
 24+extern "C" {
 25+#endif
 26+
2327 typedef struct
2428 {
2529 GLint vs;
@@ -47,17 +51,20 @@
4852 struct TEXTURESTAGE;
4953 class ShaderGen3D;
5054
51 -class ShaderManager
 55+typedef struct ShaderManager
5256 {
53 -public:
54 - ShaderManager(glExtensions *glext);
55 - ~ShaderManager();
56 - void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type);
5757 SHADER *shaders;
5858 ShaderGen3D *gen3d;
5959 ShaderGen2D *gen2d;
60 -private:
6160 glExtensions *ext;
62 -};
 61+} ShaderManager;
6362
 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+
6471 #endif //__SHADERS_H
\ No newline at end of file
Index: ddraw/glRenderer.cpp
@@ -732,7 +732,8 @@
733733 This->backx = 0;
734734 This->backy = 0;
735735 }
736 - delete This->shaders;
 736+ ShaderManager_Delete(This->shaders);
 737+ free(This->shaders);
737738 free(This->texman);
738739 free(This->ext);
739740 delete This->util;
@@ -909,7 +910,8 @@
910911 }
911912 else This->gl_caps.ShaderVer = 0;
912913 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);
914916 This->fbo.fbo = 0;
915917 This->util->InitFBO(&This->fbo);
916918 This->util->ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
@@ -1185,7 +1187,7 @@
11861188 if (dwFlags & DDBLT_KEYDEST) usedest = TRUE;
11871189 if (usedest)
11881190 {
1189 - This->shaders->SetShader(PROG_TEXTURE, NULL, NULL, 0);
 1191+ ShaderManager_SetShader(This->shaders, PROG_TEXTURE, NULL, NULL, 0);
11901192 glRenderer__DrawBackbufferRect(This, dest->texture, destrect, PROG_TEXTURE);
11911193 This->bltvertices[1].dests = This->bltvertices[3].dests = 0.;
11921194 This->bltvertices[0].dests = This->bltvertices[2].dests = (GLfloat)(destrect.right - destrect.left) / (GLfloat)This->backx;
@@ -1192,7 +1194,7 @@
11931195 This->bltvertices[0].destt = This->bltvertices[1].destt = 1.;
11941196 This->bltvertices[2].destt = This->bltvertices[3].destt = 1.0-((GLfloat)(destrect.bottom - destrect.top) / (GLfloat)This->backy);
11951197 }
1196 - This->shaders->SetShader(shaderid, NULL, NULL, 1);
 1198+ ShaderManager_SetShader(This->shaders, shaderid, NULL, NULL, 1);
11971199 GenShader2D *shader = &This->shaders->gen2d->genshaders2D[This->shaders->gen3d->current_genshader];
11981200 This->util->BlendEnable(false);
11991201 do
@@ -1501,7 +1503,7 @@
15021504 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
15031505 if(This->ddInterface->GetBPP() == 8)
15041506 {
1505 - This->shaders->SetShader(PROG_PAL256,NULL,NULL,0);
 1507+ ShaderManager_SetShader(This->shaders,PROG_PAL256,NULL,NULL,0);
15061508 progtype = PROG_PAL256;
15071509 TextureManager__UploadTexture(This->texman,paltex,0,glDirectDrawPalette_GetPalette(dest->palette,NULL),256,1,FALSE);
15081510 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
@@ -1511,7 +1513,7 @@
15121514 if(dxglcfg.scalingfilter)
15131515 {
15141516 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);
15161518 progtype = PROG_TEXTURE;
15171519 TextureManager_SetTexture(This->texman,0,texture);
15181520 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
@@ -1524,7 +1526,7 @@
15251527 }
15261528 else
15271529 {
1528 - This->shaders->SetShader(PROG_TEXTURE,NULL,NULL,0);
 1530+ ShaderManager_SetShader(This->shaders,PROG_TEXTURE,NULL,NULL,0);
15291531 progtype = PROG_TEXTURE;
15301532 TextureManager_SetTexture(This->texman,0,texture);
15311533 This->ext->glUniform1i(This->shaders->shaders[progtype].tex0,0);
@@ -1828,7 +1830,7 @@
18291831 return;
18301832 }
18311833 __int64 shader = device->SelectShader(vertices);
1832 - This->shaders->SetShader(shader,device->texstages,texformats,2);
 1834+ ShaderManager_SetShader(This->shaders,shader,device->texstages,texformats,2);
18331835 device->SetDepthComp(This->util);
18341836 if(device->renderstate[D3DRENDERSTATE_ZENABLE]) This->util->DepthTest(true);
18351837 else This->util->DepthTest(false);
@@ -2065,7 +2067,7 @@
20662068 view[3] = (GLfloat)surface->ddsd.dwHeight;
20672069 This->util->SetViewport(0,0,surface->ddsd.dwWidth,surface->ddsd.dwHeight);
20682070 glClear(GL_COLOR_BUFFER_BIT);
2069 - This->shaders->SetShader(PROG_CLIPSTENCIL,NULL,NULL,0);
 2071+ ShaderManager_SetShader(This->shaders,PROG_CLIPSTENCIL,NULL,NULL,0);
20702072 This->ext->glUniform4f(This->shaders->shaders[PROG_CLIPSTENCIL].view,view[0],view[1],view[2],view[3]);
20712073 This->util->EnableArray(This->shaders->shaders[PROG_CLIPSTENCIL].pos,true);
20722074 This->ext->glVertexAttribPointer(This->shaders->shaders[PROG_CLIPSTENCIL].pos,
Index: ddraw/matrix.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2012 William Feely
 3+// Copyright (C) 2012-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/scalers.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/scalers.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2011 William Feely
 3+// Copyright (C) 2011-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/timer.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013 William Feely
 3+// Copyright (C) 2013-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/timer.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013 William Feely
 3+// Copyright (C) 2013-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/trace.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013 William Feely
 3+// Copyright (C) 2013-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/trace.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013 William Feely
 3+// Copyright (C) 2013-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/util.c
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013 William Feely
 3+// Copyright (C) 2013-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public
Index: ddraw/util.h
@@ -1,5 +1,5 @@
22 // DXGL
3 -// Copyright (C) 2013 William Feely
 3+// Copyright (C) 2013-2014 William Feely
44
55 // This library is free software; you can redistribute it and/or
66 // modify it under the terms of the GNU Lesser General Public