DXGL r510 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r509‎ | r510 | r511 >
Date:17:52, 1 September 2014
Author:admin
Status:new
Tags:
Comment:
Convert ShaderGen3D to structure and C linkage, and remove C++ string usage.
Modified paths:
  • /ddraw/ShaderGen3D.cpp (modified) (history)
  • /ddraw/ShaderGen3D.h (modified) (history)
  • /ddraw/ShaderManager.cpp (modified) (history)
  • /ddraw/ShaderManager.h (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen3D.cpp
@@ -21,8 +21,6 @@
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 "ShaderGen3D.h"
2927 #include "ShaderGen2D.h"
@@ -29,24 +27,26 @@
3028 #include "ShaderManager.h"
3129 #include "../common/version.h"
3230
33 -ShaderGen3D::ShaderGen3D(glExtensions *glext, ShaderManager *shaderman)
 31+extern "C" {
 32+
 33+void ShaderGen3D_Init(glExtensions *glext, ShaderManager *shaderman, ShaderGen3D *gen)
3434 {
35 - ext = glext;
36 - shaders = shaderman;
37 - ZeroMemory(current_texid,8*sizeof(__int64));
38 - shadercount = 0;
39 - genindex = 0;
40 - maxshaders = 256;
41 - genshaders = (GenShader*)malloc(256 * sizeof(GenShader));
42 - ZeroMemory(genshaders, 256 * sizeof(GenShader));
43 - current_shader = 0;
44 - current_shadertype = 0;
 35+ gen->ext = glext;
 36+ gen->shaders = shaderman;
 37+ ZeroMemory(gen->current_texid,8*sizeof(__int64));
 38+ gen->shadercount = 0;
 39+ gen->genindex = 0;
 40+ gen->maxshaders = 256;
 41+ gen->genshaders = (GenShader*)malloc(256 * sizeof(GenShader));
 42+ ZeroMemory(gen->genshaders, 256 * sizeof(GenShader));
 43+ gen->current_shader = 0;
 44+ gen->current_shadertype = 0;
4545 }
4646
47 -ShaderGen3D::~ShaderGen3D()
 47+void ShaderGen3D_Delete(ShaderGen3D *This)
4848 {
49 - ClearShaders();
50 - free(genshaders);
 49+ ShaderGen3D_ClearShaders(This);
 50+ free(This->genshaders);
5151 }
5252 /* Bits in Shader ID:
5353 Bits 0-1 - Shading mode: 00=flat 01=gouraud 11=phong 10=flat per-pixel GL/VS/FS
@@ -114,29 +114,33 @@
115115
116116 /**
117117 * Deletes all shader programs in the array.
 118+ * @param This
 119+ * Pointer to ShaderGen3D structure
118120 */
119 -void ShaderGen3D::ClearShaders()
 121+void ShaderGen3D_ClearShaders(ShaderGen3D *This)
120122 {
121 - if(!genshaders) return;
122 - for(int i = 0; i < shadercount; i++)
 123+ if(!This->genshaders) return;
 124+ for(int i = 0; i < This->shadercount; i++)
123125 {
124 - genshaders[i].id = 0;
125 - ZeroMemory(genshaders[i].texids,8*sizeof(__int64));
126 - if(genshaders[i].shader.prog) ext->glDeleteProgram(genshaders[i].shader.prog);
127 - if(genshaders[i].shader.fs) ext->glDeleteShader(genshaders[i].shader.fs);
128 - if(genshaders[i].shader.vs) ext->glDeleteShader(genshaders[i].shader.vs);
129 - if(genshaders[i].shader.fsrc.ptr) String_Free(&genshaders[i].shader.fsrc);
130 - if(genshaders[i].shader.vsrc.ptr) String_Free(&genshaders[i].shader.vsrc);
 126+ This->genshaders[i].id = 0;
 127+ ZeroMemory(This->genshaders[i].texids,8*sizeof(__int64));
 128+ if(This->genshaders[i].shader.prog) This->ext->glDeleteProgram(This->genshaders[i].shader.prog);
 129+ if(This->genshaders[i].shader.fs) This->ext->glDeleteShader(This->genshaders[i].shader.fs);
 130+ if(This->genshaders[i].shader.vs) This->ext->glDeleteShader(This->genshaders[i].shader.vs);
 131+ if(This->genshaders[i].shader.fsrc.ptr) String_Free(&This->genshaders[i].shader.fsrc);
 132+ if(This->genshaders[i].shader.vsrc.ptr) String_Free(&This->genshaders[i].shader.vsrc);
131133 }
132 - if(genshaders) free(genshaders);
133 - genshaders = NULL;
134 - current_genshader = -1;
135 - shadercount = 0;
136 - genindex = 0;
 134+ if(This->genshaders) free(This->genshaders);
 135+ This->genshaders = NULL;
 136+ This->current_genshader = -1;
 137+ This->shadercount = 0;
 138+ This->genindex = 0;
137139 }
138140
139141 /**
140142 * Sets a shader by render state. If the shader does not exist, generates it.
 143+ * @param This
 144+ * Pointer to ShaderGen3D structure
141145 * @param id
142146 * 64-bit value containing current render states
143147 * @param texstate
@@ -149,25 +153,25 @@
150154 * 1 for generated 2D
151155 * 2 for generated 3D
152156 */
153 -void ShaderGen3D::SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type, ShaderGen2D *gen2d)
 157+void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type, ShaderGen2D *gen2d)
154158 {
155159 int shaderindex = -1;
156160 switch(type)
157161 {
158162 case 0: // Static built-in shader
159 - if((current_shadertype == 0) && (shaders->shaders[id].prog == current_shader)) return;
160 - ext->glUseProgram(shaders->shaders[id].prog);
161 - current_shader = shaders->shaders[id].prog;
162 - current_shadertype = 0;
163 - current_genshader = -1;
 163+ if((This->current_shadertype == 0) && (This->shaders->shaders[id].prog == This->current_shader)) return;
 164+ This->ext->glUseProgram(This->shaders->shaders[id].prog);
 165+ This->current_shader = This->shaders->shaders[id].prog;
 166+ This->current_shadertype = 0;
 167+ This->current_genshader = -1;
164168 break;
165169 case 1: // 2D generated shader
166 - if ((current_shadertype == 1) && (id == current_shader)) return;
167 - current_shader = id;
168 - current_shadertype = 1;
 170+ if ((This->current_shadertype == 1) && (id == This->current_shader)) return;
 171+ This->current_shader = id;
 172+ This->current_shadertype = 1;
169173 for (int i = 0; i < gen2d->shadercount; i++)
170174 {
171 - if (shaders->gen2d->genshaders2D[i].id == id)
 175+ if (This->shaders->gen2d->genshaders2D[i].id == id)
172176 {
173177 shaderindex = i;
174178 break;
@@ -179,10 +183,10 @@
180184 if (gen2d->shadercount > 256) gen2d->shadercount = 256;
181185 if (gen2d->genshaders2D[gen2d->genindex].shader.prog)
182186 {
183 - ext->glUseProgram(0);
184 - ext->glDeleteProgram(gen2d->genshaders2D[gen2d->genindex].shader.prog);
185 - ext->glDeleteShader(gen2d->genshaders2D[gen2d->genindex].shader.vs);
186 - ext->glDeleteShader(gen2d->genshaders2D[gen2d->genindex].shader.fs);
 187+ This->ext->glUseProgram(0);
 188+ This->ext->glDeleteProgram(gen2d->genshaders2D[gen2d->genindex].shader.prog);
 189+ This->ext->glDeleteShader(gen2d->genshaders2D[gen2d->genindex].shader.vs);
 190+ This->ext->glDeleteShader(gen2d->genshaders2D[gen2d->genindex].shader.fs);
187191 String_Free(&gen2d->genshaders2D[gen2d->genindex].shader.vsrc);
188192 String_Free(&gen2d->genshaders2D[gen2d->genindex].shader.fsrc);
189193 ZeroMemory(&gen2d->genshaders2D[gen2d->genindex], sizeof(GenShader2D));
@@ -193,27 +197,27 @@
194198 if (gen2d->genindex >= 256) gen2d->genindex = 0;
195199 }
196200 gen2d->genshaders2D[shaderindex].id = id;
197 - ext->glUseProgram(gen2d->genshaders2D[shaderindex].shader.prog);
198 - current_prog = gen2d->genshaders2D[shaderindex].shader.prog;
199 - current_genshader = shaderindex;
 201+ This->ext->glUseProgram(gen2d->genshaders2D[shaderindex].shader.prog);
 202+ This->current_prog = gen2d->genshaders2D[shaderindex].shader.prog;
 203+ This->current_genshader = shaderindex;
200204 break;
201205 case 2: // 3D generated shader
202 - if((current_shadertype == 2) && (id == current_shader))
 206+ if((This->current_shadertype == 2) && (id == This->current_shader))
203207 {
204 - if(!memcmp(current_texid,texstate,8*sizeof(__int64))) return;
 208+ if(!memcmp(This->current_texid,texstate,8*sizeof(__int64))) return;
205209 }
206 - current_shader = id;
207 - current_shadertype = 2;
208 - for(int i = 0; i < shadercount; i++)
 210+ This->current_shader = id;
 211+ This->current_shadertype = 2;
 212+ for(int i = 0; i < This->shadercount; i++)
209213 {
210 - if(genshaders[i].id == id)
 214+ if(This->genshaders[i].id == id)
211215 {
212216 bool texidmatch = true;
213217 for(int j = 0; j < 8; j++)
214 - if(genshaders[i].texids[j] != texstate[j].shaderid) texidmatch = false;
 218+ if(This->genshaders[i].texids[j] != texstate[j].shaderid) texidmatch = false;
215219 if(texidmatch)
216220 {
217 - if(!memcmp(genshaders[i].texcoords,texcoords,8*sizeof(int)))
 221+ if(!memcmp(This->genshaders[i].texcoords,texcoords,8*sizeof(int)))
218222 {
219223 shaderindex = i;
220224 break;
@@ -223,43 +227,45 @@
224228 }
225229 if(shaderindex == -1)
226230 {
227 - shadercount++;
228 - if(shadercount > 256) shadercount = 256;
229 - if(genshaders[genindex].shader.prog)
 231+ This->shadercount++;
 232+ if(This->shadercount > 256) This->shadercount = 256;
 233+ if(This->genshaders[This->genindex].shader.prog)
230234 {
231 - ext->glUseProgram(0);
232 - ext->glDeleteProgram(genshaders[genindex].shader.prog);
233 - ext->glDeleteShader(genshaders[genindex].shader.vs);
234 - ext->glDeleteShader(genshaders[genindex].shader.fs);
235 - String_Free(&genshaders[genindex].shader.vsrc);
236 - String_Free(&genshaders[genindex].shader.fsrc);
237 - ZeroMemory(&genshaders[genindex],sizeof(GenShader));
 235+ This->ext->glUseProgram(0);
 236+ This->ext->glDeleteProgram(This->genshaders[This->genindex].shader.prog);
 237+ This->ext->glDeleteShader(This->genshaders[This->genindex].shader.vs);
 238+ This->ext->glDeleteShader(This->genshaders[This->genindex].shader.fs);
 239+ String_Free(&This->genshaders[This->genindex].shader.vsrc);
 240+ String_Free(&This->genshaders[This->genindex].shader.fsrc);
 241+ ZeroMemory(&This->genshaders[This->genindex],sizeof(GenShader));
238242 }
239 - CreateShader(genindex,id,texstate,texcoords);
240 - shaderindex = genindex;
241 - genindex++;
242 - if(genindex >= 256) genindex = 0;
 243+ ShaderGen3D_CreateShader(This, This->genindex,id,texstate,texcoords);
 244+ shaderindex = This->genindex;
 245+ This->genindex++;
 246+ if(This->genindex >= 256) This->genindex = 0;
243247 }
244 - genshaders[shaderindex].id = id;
 248+ This->genshaders[shaderindex].id = id;
245249 for(int i = 0; i < 8; i++)
246 - genshaders[shaderindex].texids[i] = texstate[i].shaderid;
247 - memcpy(genshaders[shaderindex].texcoords,texcoords,8*sizeof(int));
248 - ext->glUseProgram(genshaders[shaderindex].shader.prog);
249 - current_prog = genshaders[shaderindex].shader.prog;
250 - current_genshader = shaderindex;
 250+ This->genshaders[shaderindex].texids[i] = texstate[i].shaderid;
 251+ memcpy(This->genshaders[shaderindex].texcoords,texcoords,8*sizeof(int));
 252+ This->ext->glUseProgram(This->genshaders[shaderindex].shader.prog);
 253+ This->current_prog = This->genshaders[shaderindex].shader.prog;
 254+ This->current_genshader = shaderindex;
251255 }
252256 }
253257
254258 /**
255259 * Retrieves the GLSL program currently in use
 260+ * @param This
 261+ * Pointer to ShaderGen3D structure
256262 * @return
257263 * Number of the current GLSL program, or if using built-in shaders, the ID of
258264 * the shader
259265 */
260 -GLuint ShaderGen3D::GetProgram()
 266+GLuint ShaderGen3D_GetProgram(ShaderGen3D *This)
261267 {
262 - if (current_shadertype == 0) return current_shader & 0xFFFFFFFF;
263 - else return current_prog;
 268+ if (This->current_shadertype == 0) return This->current_shader & 0xFFFFFFFF;
 269+ else return This->current_prog;
264270 }
265271
266272
@@ -429,6 +435,8 @@
430436
431437 /**
432438 * Creates an OpenGL shader program
 439+ * @param This
 440+ * Pointer to ShaderGen3D structure
433441 * @param index
434442 * Index of the shader in the array to generate
435443 * @param id
@@ -438,9 +446,10 @@
439447 * @param texcoords
440448 * Pointer to number of texture coordinates in each texture stage
441449 */
442 -void ShaderGen3D::CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords)
 450+void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords)
443451 {
444 - string tmp;
 452+ STRING tmp;
 453+ ZeroMemory(&tmp, sizeof(STRING));
445454 int i;
446455 bool hasdir = false;
447456 bool haspoint = false;
@@ -457,11 +466,11 @@
458467 char idstring[22];
459468 _snprintf(idstring,21,"%0.16I64X\n",id);
460469 idstring[21] = 0;
461 - genshaders[index].shader.vsrc.ptr = NULL;
462 - genshaders[index].shader.fsrc.ptr = NULL;
 470+ This->genshaders[index].shader.vsrc.ptr = NULL;
 471+ This->genshaders[index].shader.fsrc.ptr = NULL;
463472 // Create vertex shader
464473 //Header
465 - STRING *vsrc = &genshaders[index].shader.vsrc;
 474+ STRING *vsrc = &This->genshaders[index].shader.vsrc;
466475 String_Append(vsrc, header);
467476 String_Append(vsrc, vertexshader);
468477 String_Append(vsrc, idheader);
@@ -469,16 +478,16 @@
470479 // Attributes
471480 String_Append(vsrc, attr_xyz);
472481 if((id>>50)&1) String_Append(vsrc, attr_rhw);
473 - tmp = attr_rgba;
 482+ String_Assign(&tmp, attr_rgba);
474483 if((id>>35)&1)
475484 {
476 - tmp.replace(19,1,"0");
477 - String_Append(vsrc, tmp.c_str());
 485+ tmp.ptr[19] = '0';
 486+ String_Append(vsrc, tmp.ptr);
478487 }
479488 if((id>>36)&1)
480489 {
481 - tmp.replace(19,1,"1");
482 - String_Append(vsrc, tmp.c_str());
 490+ tmp.ptr[19] = '1';
 491+ String_Append(vsrc, tmp.ptr);
483492 }
484493 if((id>>37)&1) String_Append(vsrc, attr_nxyz);
485494 else String_Append(vsrc, const_nxyz);
@@ -485,11 +494,11 @@
486495 count = (id>>46)&7;
487496 if(count)
488497 {
489 - tmp = attr_blend;
 498+ String_Assign(&tmp,attr_blend);
490499 for(i = 0; i < count; i++)
491500 {
492 - tmp.replace(21,1,_itoa(i,idstring,10));
493 - String_Append(vsrc, tmp.c_str());
 501+ tmp.ptr[21] = *(_itoa(i,idstring,10));
 502+ String_Append(vsrc, tmp.ptr);
494503 }
495504 }
496505 for(i = 0; i < 8; i++)
@@ -499,23 +508,23 @@
500509 case -1:
501510 continue;
502511 case 3:
503 - tmp = attr_s;
504 - tmp.replace(16,1,_itoa(i,idstring,10));
 512+ String_Assign(&tmp,attr_s);
 513+ tmp.ptr[16] = *(_itoa(i,idstring,10));
505514 break;
506515 case 0:
507 - tmp = attr_st;
508 - tmp.replace(17,1,_itoa(i,idstring,10));
 516+ String_Assign(&tmp, attr_st);
 517+ tmp.ptr[17] = *(_itoa(i,idstring,10));
509518 break;
510519 case 1:
511 - tmp = attr_str;
512 - tmp.replace(18,1,_itoa(i,idstring,10));
 520+ String_Assign(&tmp, attr_str);
 521+ tmp.ptr[18] = *(_itoa(i,idstring,10));
513522 break;
514523 case 2:
515 - tmp = attr_strq;
516 - tmp.replace(19,1,_itoa(i,idstring,10));
 524+ String_Assign(&tmp, attr_strq);
 525+ tmp.ptr[19] = *(_itoa(i,idstring,10));
517526 break;
518527 }
519 - String_Append(vsrc, tmp.c_str());
 528+ String_Append(vsrc, tmp.ptr);
520529 }
521530
522531 // Uniforms
@@ -528,11 +537,11 @@
529538 {
530539 String_Append(vsrc, lightstruct);
531540 String_Append(vsrc, unif_world);
532 - tmp = unif_light;
 541+ String_Assign(&tmp, unif_light);
533542 for(i = 0; i < numlights; i++)
534543 {
535 - tmp.replace(19,1,_itoa(i,idstring,10));
536 - String_Append(vsrc, tmp.c_str());
 544+ tmp.ptr[19] = *(_itoa(i,idstring,10));
 545+ String_Append(vsrc, tmp.ptr);
537546 }
538547 }
539548
@@ -564,7 +573,7 @@
565574 else String_Append(vsrc, op_transform);
566575 if((id>>49)&1) String_Append(vsrc, op_normalize);
567576 else String_Append(vsrc, op_normalpassthru);
568 - const string colorargs[] = {"gl_FrontMaterial.diffuse","gl_FrontMaterial.ambient","gl_FrontMaterial.specular",
 577+ const char *colorargs[] = {"gl_FrontMaterial.diffuse","gl_FrontMaterial.ambient","gl_FrontMaterial.specular",
569578 "gl_FrontMaterial.emission","rgba0.bgra","rgba1.bgra"};
570579 if(numlights)
571580 {
@@ -575,22 +584,22 @@
576585 {
577586 if(id>>(51+i)&1)
578587 {
579 - tmp = op_spotlight;
580 - tmp.replace(15,1,_itoa(i,idstring,10));
581 - String_Append(vsrc, tmp.c_str());
 588+ String_Assign(&tmp, op_spotlight);
 589+ tmp.ptr[15] = *(_itoa(i,idstring,10));
 590+ String_Append(vsrc, tmp.ptr);
582591 }
583592 else
584593 {
585 - tmp = op_pointlight;
586 - tmp.replace(16,1,_itoa(i,idstring,10));
587 - String_Append(vsrc, tmp.c_str());
 594+ String_Assign(&tmp, op_pointlight);
 595+ tmp.ptr[16] = *(_itoa(i,idstring,10));
 596+ String_Append(vsrc, tmp.ptr);
588597 }
589598 }
590599 else
591600 {
592 - tmp = op_dirlight;
593 - tmp.replace(14,1,_itoa(i,idstring,10));
594 - String_Append(vsrc, tmp.c_str());
 601+ String_Assign(&tmp, op_dirlight);
 602+ tmp.ptr[14] = *(_itoa(i,idstring,10));
 603+ String_Append(vsrc, tmp.ptr);
595604 }
596605 }
597606 if((id>>60)&1)
@@ -602,24 +611,24 @@
603612 int matcolor;
604613 String_Append(vsrc, "gl_FrontColor = (");
605614 matcolor = ((id>>23)&3);
606 - if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
607 - else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
608 - else String_Append(vsrc, colorargs[0].c_str());
 615+ if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4]);
 616+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5]);
 617+ else String_Append(vsrc, colorargs[0]);
609618 String_Append(vsrc, " * diffuse) + (");
610619 matcolor = ((id>>27)&3);
611 - if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
612 - else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
613 - else String_Append(vsrc, colorargs[1].c_str());
 620+ if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4]);
 621+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5]);
 622+ else String_Append(vsrc, colorargs[1]);
614623 String_Append(vsrc, " * ambient)\n+ (");
615624 matcolor = ((id>>25)&3);
616 - if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
617 - else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
618 - else String_Append(vsrc, colorargs[2].c_str());
 625+ if((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4]);
 626+ else if((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5]);
 627+ else String_Append(vsrc, colorargs[2]);
619628 String_Append(vsrc, " * specular) + ");
620629 matcolor = ((id>>29)&3);
621 - if ((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4].c_str());
622 - else if ((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5].c_str());
623 - else String_Append(vsrc, colorargs[3].c_str());
 630+ if ((matcolor == D3DMCS_COLOR1) && hascolor1) String_Append(vsrc, colorargs[4]);
 631+ else if ((matcolor == D3DMCS_COLOR2) && hascolor2) String_Append(vsrc, colorargs[5]);
 632+ else String_Append(vsrc, colorargs[3]);
624633 String_Append(vsrc, ";\n");
625634 }
626635 else String_Append(vsrc, op_colorout);
@@ -639,9 +648,9 @@
640649 }
641650 else
642651 {
643 - tmp = op_texpassthru1;
644 - tmp.replace(12,1,_itoa(i,idstring,10));
645 - String_Append(vsrc, tmp.c_str());
 652+ String_Assign(&tmp,op_texpassthru1);
 653+ tmp.ptr[12] = *(_itoa(i,idstring,10));
 654+ String_Append(vsrc, tmp.ptr);
646655 texindex = (texstate[i].shaderid>>54)&3;
647656 switch(texcoords[texindex])
648657 {
@@ -649,25 +658,25 @@
650659 String_Append(vsrc, op_texpassthru2null);
651660 break;
652661 case 0: // st
653 - tmp = op_texpassthru2st;
654 - tmp.replace(7,1,_itoa(texindex,idstring,10));
655 - String_Append(vsrc, tmp.c_str());
 662+ String_Assign(&tmp, op_texpassthru2st);
 663+ tmp.ptr[7] = *(_itoa(texindex,idstring,10));
 664+ String_Append(vsrc, tmp.ptr);
656665 default:
657666 break;
658667 case 1: // str
659 - tmp = op_texpassthru2str;
660 - tmp.replace(8,1,_itoa(texindex,idstring,10));
661 - String_Append(vsrc, tmp.c_str());
 668+ String_Assign(&tmp, op_texpassthru2str);
 669+ tmp.ptr[8] = *(_itoa(texindex,idstring,10));
 670+ String_Append(vsrc, tmp.ptr);
662671 break;
663672 case 2: // strq
664 - tmp = op_texpassthru2strq;
665 - tmp.replace(4,1,_itoa(texindex,idstring,10));
666 - String_Append(vsrc, tmp.c_str());
 673+ String_Assign(&tmp, op_texpassthru2strq);
 674+ tmp.ptr[4] = *(_itoa(texindex,idstring,10));
 675+ String_Append(vsrc, tmp.ptr);
667676 break;
668677 case 3: // s
669 - tmp = op_texpassthru2s;
670 - tmp.replace(6,1,_itoa(texindex,idstring,10));
671 - String_Append(vsrc, tmp.c_str());
 678+ String_Assign(&tmp, op_texpassthru2s);
 679+ tmp.ptr[6] = *(_itoa(texindex,idstring,10));
 680+ String_Append(vsrc, tmp.ptr);
672681 break;
673682 }
674683 }
@@ -699,21 +708,21 @@
700709 TRACE_STRING(vsrc->ptr);
701710 TRACE_STRING("\nCompiling vertex shader:\n");
702711 #endif
703 - genshaders[index].shader.vs = ext->glCreateShader(GL_VERTEX_SHADER);
 712+ This->genshaders[index].shader.vs = This->ext->glCreateShader(GL_VERTEX_SHADER);
704713 const char *src = vsrc->ptr;
705714 GLint srclen = strlen(src);
706 - ext->glShaderSource(genshaders[index].shader.vs,1,&src,&srclen);
707 - ext->glCompileShader(genshaders[index].shader.vs);
 715+ This->ext->glShaderSource(This->genshaders[index].shader.vs,1,&src,&srclen);
 716+ This->ext->glCompileShader(This->genshaders[index].shader.vs);
708717 GLint result;
709718 char *infolog = NULL;
710 - ext->glGetShaderiv(genshaders[index].shader.vs,GL_COMPILE_STATUS,&result);
 719+ This->ext->glGetShaderiv(This->genshaders[index].shader.vs,GL_COMPILE_STATUS,&result);
711720 #ifdef _DEBUG
712721 GLint loglen;
713722 if(!result)
714723 {
715 - ext->glGetShaderiv(genshaders[index].shader.vs,GL_INFO_LOG_LENGTH,&loglen);
 724+ This->ext->glGetShaderiv(This->genshaders[index].shader.vs,GL_INFO_LOG_LENGTH,&loglen);
716725 infolog = (char*)malloc(loglen);
717 - ext->glGetShaderInfoLog(genshaders[index].shader.vs,loglen,&result,infolog);
 726+ This->ext->glGetShaderInfoLog(This->genshaders[index].shader.vs,loglen,&result,infolog);
718727 OutputDebugStringA("Compilation failed. Error messages:\n");
719728 OutputDebugStringA(infolog);
720729 TRACE_STRING("Compilation failed. Error messages:\n");
@@ -722,7 +731,7 @@
723732 }
724733 #endif
725734 // Create fragment shader
726 - STRING *fsrc = &genshaders[index].shader.fsrc;
 735+ STRING *fsrc = &This->genshaders[index].shader.fsrc;
727736 String_Append(fsrc, header);
728737 String_Append(fsrc, fragshader);
729738 _snprintf(idstring,21,"%0.16I64X\n",id);
@@ -733,9 +742,9 @@
734743 for(i = 0; i < 8; i++)
735744 {
736745 if((texstate[i].shaderid & 31) == D3DTOP_DISABLE)break;
737 - tmp = unif_tex;
738 - tmp.replace(21,1,_itoa(i,idstring,10));
739 - String_Append(fsrc, tmp.c_str());
 746+ String_Assign(&tmp, unif_tex);
 747+ tmp.ptr[21] = *(_itoa(i,idstring,10));
 748+ String_Append(fsrc, tmp.ptr);
740749 }
741750 if((id>>13)&1)
742751 {
@@ -743,9 +752,9 @@
744753 {
745754 if((texstate[i].shaderid>>60)&1)
746755 {
747 - tmp = unif_key;
748 - tmp.replace(17,1,_itoa(i,idstring,10));
749 - String_Append(fsrc, tmp.c_str());
 756+ String_Assign(&tmp, unif_key);
 757+ tmp.ptr[17] = *(_itoa(i,idstring,10));
 758+ String_Append(fsrc, tmp.ptr);
750759 }
751760 }
752761 }
@@ -758,12 +767,15 @@
759768 // Main
760769 String_Append(fsrc, mainstart);
761770 String_Append(fsrc, op_colorfragin);
762 - string arg1,arg2;
763 - string texarg;
 771+ STRING arg1,arg2;
 772+ STRING texarg;
 773+ ZeroMemory(&arg1, sizeof(STRING));
 774+ ZeroMemory(&arg2, sizeof(STRING));
 775+ ZeroMemory(&texarg, sizeof(STRING));
764776 int args[4];
765777 bool texfail;
766778 bool alphadisabled = false;
767 - const string blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y])",
 779+ const char *blendargs[] = {"color","gl_Color","texture2DProj(texX,gl_TexCoord[Y])",
768780 "","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a",".aaa"};
769781 bool usecolorkey = false;
770782 if((id>>13)&1) usecolorkey = true;
@@ -779,11 +791,11 @@
780792 {
781793 if((texstate[i].shaderid>>60)&1)
782794 {
783 - arg1.assign(op_colorkey);
784 - arg1.replace(26,1,_itoa(i,idstring,10));
785 - arg1.replace(40,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
786 - arg1.replace(57,1,_itoa(i,idstring,10));
787 - String_Append(fsrc, arg1.c_str());
 795+ String_Assign(&arg1, op_colorkey);
 796+ arg1.ptr[26] = *(_itoa(i,idstring,10));
 797+ arg1.ptr[40] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 798+ arg1.ptr[57] = *(_itoa(i,idstring,10));
 799+ String_Append(fsrc, arg1.ptr);
788800 }
789801 }
790802 // Color stage
@@ -792,60 +804,74 @@
793805 {
794806 case D3DTA_CURRENT:
795807 default:
796 - arg1 = blendargs[0];
 808+ String_Assign(&arg1, blendargs[0]);
797809 break;
798810 case D3DTA_DIFFUSE:
799 - arg1 = blendargs[1];
 811+ String_Assign(&arg1, blendargs[1]);
800812 break;
801813 case D3DTA_TEXTURE:
802814 if((texstate[i].shaderid >> 59)&1)
803815 {
804 - arg1 = blendargs[2];
805 - arg1.replace(17,1,_itoa(i,idstring,10));
806 - arg1.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 816+ String_Assign(&arg1, blendargs[2]);
 817+ arg1.ptr[17] = *(_itoa(i,idstring,10));
 818+ arg1.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
807819 }
808820 else texfail = true;
809821 break;
810822 case D3DTA_TFACTOR:
811823 FIXME("Support texture factor value");
812 - arg1 = blendargs[4];
 824+ String_Append(&arg1, blendargs[4]);
813825 break;
814826 case D3DTA_SPECULAR:
815 - arg1 = blendargs[5];
 827+ String_Append(&arg1, blendargs[5]);
816828 break;
817829 }
818 - if(args[0] & D3DTA_COMPLEMENT) arg1 = "(1.0 - " + arg1 + ")";
819 - if(args[0] & D3DTA_ALPHAREPLICATE) arg1.append(blendargs[10]);
820 - else arg1.append(blendargs[8]);
 830+ if (args[0] & D3DTA_COMPLEMENT)
 831+ {
 832+ String_Assign(&tmp, arg1.ptr);
 833+ String_Append(&tmp, "(1.0 - ");
 834+ String_Append(&tmp, arg1.ptr);
 835+ String_Append(&tmp, ")");
 836+ String_Assign(&arg1, tmp.ptr);
 837+ }
 838+ if (args[0] & D3DTA_ALPHAREPLICATE) String_Append(&arg1, blendargs[10]);
 839+ else String_Append(&arg1, blendargs[8]);
821840 switch(args[1]&7) //arg2
822841 {
823842 case D3DTA_CURRENT:
824843 default:
825 - arg2 = blendargs[0];
 844+ String_Assign(&arg2, blendargs[0]);
826845 break;
827846 case D3DTA_DIFFUSE:
828 - arg2 = blendargs[1];
 847+ String_Assign(&arg2, blendargs[1]);
829848 break;
830849 case D3DTA_TEXTURE:
831850 if((texstate[i].shaderid >> 59)&1)
832851 {
833 - arg2 = blendargs[2];
834 - arg2.replace(17,1,_itoa(i,idstring,10));
835 - arg2.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 852+ String_Assign(&arg2, blendargs[2]);
 853+ arg2.ptr[17] = *(_itoa(i,idstring,10));
 854+ arg2.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
836855 }
837856 else texfail = true;
838857 break;
839858 case D3DTA_TFACTOR:
840859 FIXME("Support texture factor value");
841 - arg2 = blendargs[4];
 860+ String_Assign(&arg2, blendargs[4]);
842861 break;
843862 case D3DTA_SPECULAR:
844 - arg2 = blendargs[5];
 863+ String_Assign(&arg2, blendargs[5]);
845864 break;
846865 }
847 - if(args[1] & D3DTA_COMPLEMENT) arg2 = "(1.0 - " + arg2 + ")";
848 - if(args[1] & D3DTA_ALPHAREPLICATE) arg2.append(blendargs[10]);
849 - else arg2.append(blendargs[8]);
 866+ if(args[1] & D3DTA_COMPLEMENT)
 867+ {
 868+ String_Assign(&tmp, arg2.ptr);
 869+ String_Append(&tmp, "(1.0 - ");
 870+ String_Append(&tmp, arg2.ptr);
 871+ String_Append(&tmp, ")");
 872+ String_Assign(&arg2, tmp.ptr);
 873+ }
 874+ if (args[1] & D3DTA_ALPHAREPLICATE) String_Append(&arg2, blendargs[10]);
 875+ else String_Append(&arg2, blendargs[8]);
850876 if(!texfail) switch(texstate[i].shaderid & 31)
851877 {
852878 case D3DTOP_DISABLE:
@@ -853,119 +879,119 @@
854880 break;
855881 case D3DTOP_SELECTARG1:
856882 String_Append(fsrc, "color.rgb = ");
857 - String_Append(fsrc, arg1.c_str());
 883+ String_Append(fsrc, arg1.ptr);
858884 String_Append(fsrc, ";\n");
859885 break;
860886 case D3DTOP_SELECTARG2:
861887 String_Append(fsrc, "color.rgb = ");
862 - String_Append(fsrc, arg2.c_str());
 888+ String_Append(fsrc, arg2.ptr);
863889 String_Append(fsrc, ";\n");
864890 break;
865891 case D3DTOP_MODULATE:
866892 String_Append(fsrc, "color.rgb = ");
867 - String_Append(fsrc, arg1.c_str());
 893+ String_Append(fsrc, arg1.ptr);
868894 String_Append(fsrc, " * ");
869 - String_Append(fsrc, arg2.c_str());
 895+ String_Append(fsrc, arg2.ptr);
870896 String_Append(fsrc, ";\n");
871897 break;
872898 case D3DTOP_MODULATE2X:
873899 String_Append(fsrc, "color.rgb = (");
874 - String_Append(fsrc, arg1.c_str());
 900+ String_Append(fsrc, arg1.ptr);
875901 String_Append(fsrc, " * ");
876 - String_Append(fsrc, arg2.c_str());
 902+ String_Append(fsrc, arg2.ptr);
877903 String_Append(fsrc, ") * 2.0;\n");
878904 break;
879905 case D3DTOP_MODULATE4X:
880906 String_Append(fsrc, "color.rgb = (");
881 - String_Append(fsrc, arg1.c_str());
 907+ String_Append(fsrc, arg1.ptr);
882908 String_Append(fsrc, " * ");
883 - String_Append(fsrc, arg2.c_str());
 909+ String_Append(fsrc, arg2.ptr);
884910 String_Append(fsrc, ") * 4.0;\n");
885911 break;
886912 case D3DTOP_ADD:
887913 String_Append(fsrc, "color.rgb = ");
888 - String_Append(fsrc, arg1.c_str());
 914+ String_Append(fsrc, arg1.ptr);
889915 String_Append(fsrc, " + ");
890 - String_Append(fsrc, arg2.c_str());
 916+ String_Append(fsrc, arg2.ptr);
891917 String_Append(fsrc, ";\n");
892918 break;
893919 case D3DTOP_ADDSIGNED:
894920 String_Append(fsrc, "color.rgb = ");
895 - String_Append(fsrc, arg1.c_str());
 921+ String_Append(fsrc, arg1.ptr);
896922 String_Append(fsrc, " + ");
897 - String_Append(fsrc, arg2.c_str());
 923+ String_Append(fsrc, arg2.ptr);
898924 String_Append(fsrc, " - .5;\n");
899925 break;
900926 case D3DTOP_ADDSIGNED2X:
901927 String_Append(fsrc, "color.rgb = (");
902 - String_Append(fsrc, arg1.c_str());
 928+ String_Append(fsrc, arg1.ptr);
903929 String_Append(fsrc, " + ");
904 - String_Append(fsrc, arg2.c_str());
 930+ String_Append(fsrc, arg2.ptr);
905931 String_Append(fsrc, " - .5) * 2.0;\n");
906932 break;
907933 case D3DTOP_SUBTRACT:
908934 String_Append(fsrc, "color.rgb = ");
909 - String_Append(fsrc, arg1.c_str());
 935+ String_Append(fsrc, arg1.ptr);
910936 String_Append(fsrc, " - ");
911 - String_Append(fsrc, arg2.c_str());
 937+ String_Append(fsrc, arg2.ptr);
912938 String_Append(fsrc, ";\n");
913939 break;
914940 case D3DTOP_ADDSMOOTH:
915941 String_Append(fsrc, "color.rgb = ");
916 - String_Append(fsrc, arg1.c_str());
 942+ String_Append(fsrc, arg1.ptr);
917943 String_Append(fsrc, " + ");
918 - String_Append(fsrc, arg2.c_str());
 944+ String_Append(fsrc, arg2.ptr);
919945 String_Append(fsrc, " - ");
920 - String_Append(fsrc, arg1.c_str());
 946+ String_Append(fsrc, arg1.ptr);
921947 String_Append(fsrc, " * ");
922 - String_Append(fsrc, arg2.c_str());
 948+ String_Append(fsrc, arg2.ptr);
923949 String_Append(fsrc, ";\n");
924950 break;
925951 case D3DTOP_BLENDDIFFUSEALPHA:
926952 String_Append(fsrc, "color.rgb = ");
927 - String_Append(fsrc, arg1.c_str());
 953+ String_Append(fsrc, arg1.ptr);
928954 String_Append(fsrc, " * gl_Color.a + ");
929 - String_Append(fsrc, arg2.c_str());
 955+ String_Append(fsrc, arg2.ptr);
930956 String_Append(fsrc, " * (1.0-gl_Color.a);\n");
931957 break;
932958 case D3DTOP_BLENDTEXTUREALPHA:
933 - texarg = blendargs[2];
934 - texarg.replace(17,1,_itoa(i,idstring,10));
935 - texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 959+ String_Assign(&texarg, blendargs[2]);
 960+ texarg.ptr[17] = *(_itoa(i,idstring,10));
 961+ texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
936962 String_Append(fsrc, "color.rgb = ");
937 - String_Append(fsrc, arg1.c_str());
 963+ String_Append(fsrc, arg1.ptr);
938964 String_Append(fsrc, " * ");
939 - String_Append(fsrc, texarg.c_str());
 965+ String_Append(fsrc, texarg.ptr);
940966 String_Append(fsrc, ".a + ");
941 - String_Append(fsrc, arg2.c_str());
 967+ String_Append(fsrc, arg2.ptr);
942968 String_Append(fsrc, " * (1.0-");
943 - String_Append(fsrc, texarg.c_str());
 969+ String_Append(fsrc, texarg.ptr);
944970 String_Append(fsrc, ".a);\n");
945971 break;
946972 case D3DTOP_BLENDFACTORALPHA:
947973 String_Append(fsrc, "color.rgb = ");
948 - String_Append(fsrc, arg1.c_str());
 974+ String_Append(fsrc, arg1.ptr);
949975 String_Append(fsrc, " * texfactor.a + ");
950 - String_Append(fsrc, arg2.c_str());
 976+ String_Append(fsrc, arg2.ptr);
951977 String_Append(fsrc, " * (1.0-texfactor.a);\n");
952978 break;
953979 case D3DTOP_BLENDTEXTUREALPHAPM:
954 - texarg = blendargs[2];
955 - texarg.replace(17,1,_itoa(i,idstring,10));
956 - texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 980+ String_Assign(&texarg, blendargs[2]);
 981+ texarg.ptr[17] = *(_itoa(i,idstring,10));
 982+ texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
957983 String_Append(fsrc, "color.rgb = ");
958 - String_Append(fsrc, arg1.c_str());
 984+ String_Append(fsrc, arg1.ptr);
959985 String_Append(fsrc, " + ");
960 - String_Append(fsrc, arg2.c_str());
 986+ String_Append(fsrc, arg2.ptr);
961987 String_Append(fsrc, " * (1.0-");
962 - String_Append(fsrc, texarg.c_str());
 988+ String_Append(fsrc, texarg.ptr);
963989 String_Append(fsrc, ".a);\n");
964990 break;
965991 case D3DTOP_BLENDCURRENTALPHA:
966992 String_Append(fsrc, "color.rgb = ");
967 - String_Append(fsrc, arg1.c_str());
 993+ String_Append(fsrc, arg1.ptr);
968994 String_Append(fsrc, " * color.a + ");
969 - String_Append(fsrc, arg2.c_str());
 995+ String_Append(fsrc, arg2.ptr);
970996 String_Append(fsrc, " * (1.0-color.a);\n");
971997 break;
972998 }
@@ -977,178 +1003,200 @@
9781004 {
9791005 case D3DTA_CURRENT:
9801006 default:
981 - arg1 = blendargs[0]+blendargs[9];
 1007+ String_Assign(&arg1, blendargs[0]);
 1008+ String_Append(&arg1, blendargs[9]);
9821009 break;
9831010 case D3DTA_DIFFUSE:
984 - arg1 = blendargs[1]+blendargs[9];
 1011+ String_Assign(&arg1, blendargs[1]);
 1012+ String_Append(&arg1, blendargs[9]);
9851013 break;
9861014 case D3DTA_TEXTURE:
9871015 if((texstate[i].shaderid >> 59)&1)
9881016 {
989 - arg1 = blendargs[2]+blendargs[9];
990 - arg1.replace(17,1,_itoa(i,idstring,10));
991 - arg1.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1017+ String_Assign(&arg1, blendargs[2]);
 1018+ String_Append(&arg1, blendargs[9]);
 1019+ arg1.ptr[17] = *(_itoa(i,idstring,10));
 1020+ arg1.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
9921021 }
9931022 else texfail = true;
9941023 break;
9951024 case D3DTA_TFACTOR:
9961025 FIXME("Support texture factor value");
997 - arg1 = blendargs[4]+blendargs[9];
 1026+ String_Assign(&arg1, blendargs[4]);
 1027+ String_Append(&arg1, blendargs[9]);
9981028 break;
9991029 case D3DTA_SPECULAR:
1000 - arg1 = blendargs[5]+blendargs[9];
 1030+ String_Assign(&arg1, blendargs[5]);
 1031+ String_Append(&arg1, blendargs[9]);
10011032 break;
10021033 }
10031034 if(args[2] & D3DTA_COMPLEMENT)
1004 - arg1 = "(1.0 - " + arg1 + ")";
1005 - switch(args[3]&7) //arg2
10061035 {
 1036+ String_Assign(&tmp, arg1.ptr);
 1037+ String_Append(&tmp, "(1.0 - ");
 1038+ String_Append(&tmp, arg1.ptr);
 1039+ String_Append(&tmp, ")");
 1040+ String_Assign(&arg1, tmp.ptr);
 1041+ }
 1042+ switch (args[3] & 7) //arg2
 1043+ {
10071044 case D3DTA_CURRENT:
10081045 default:
1009 - arg2 = blendargs[1]+blendargs[9];
 1046+ String_Assign(&arg2, blendargs[0]);
 1047+ String_Append(&arg2, blendargs[9]);
10101048 break;
10111049 case D3DTA_DIFFUSE:
1012 - arg2 = blendargs[1]+blendargs[9];
 1050+ String_Assign(&arg2, blendargs[1]);
 1051+ String_Append(&arg2, blendargs[9]);
10131052 break;
10141053 case D3DTA_TEXTURE:
10151054 if((texstate[i].shaderid >> 59)&1)
10161055 {
1017 - arg2 = blendargs[2]+blendargs[9];
1018 - arg2.replace(17,1,_itoa(i,idstring,10));
1019 - arg2.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1056+ String_Assign(&arg2, blendargs[2]);
 1057+ String_Append(&arg2, blendargs[9]);
 1058+ arg2.ptr[17] = *(_itoa(i,idstring,10));
 1059+ arg2.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
10201060 }
10211061 else texfail = true;
10221062 break;
10231063 case D3DTA_TFACTOR:
10241064 FIXME("Support texture factor value");
1025 - arg2 = blendargs[4]+blendargs[9];
 1065+ String_Assign(&arg2, blendargs[4]);
 1066+ String_Append(&arg2, blendargs[9]);
10261067 break;
10271068 case D3DTA_SPECULAR:
1028 - arg2 = blendargs[5]+blendargs[9];
 1069+ String_Assign(&arg2, blendargs[5]);
 1070+ String_Append(&arg2, blendargs[9]);
10291071 break;
10301072 }
10311073 if(args[3] & D3DTA_COMPLEMENT)
1032 - arg2 = "(1.0 - " + arg2 + ")";
1033 - if(!texfail) switch((texstate[i].shaderid>>17) & 31)
10341074 {
 1075+ String_Assign(&tmp, arg2.ptr);
 1076+ String_Append(&tmp, "(1.0 - ");
 1077+ String_Append(&tmp, arg2.ptr);
 1078+ String_Append(&tmp, ")");
 1079+ String_Assign(&arg2, tmp.ptr);
 1080+ }
 1081+ if (!texfail) switch ((texstate[i].shaderid >> 17) & 31)
 1082+ {
10351083 case D3DTOP_DISABLE:
10361084 default:
10371085 break;
10381086 case D3DTOP_SELECTARG1:
10391087 String_Append(fsrc, "color.a = ");
1040 - String_Append(fsrc, arg1.c_str());
 1088+ String_Append(fsrc, arg1.ptr);
10411089 String_Append(fsrc, ";\n");
10421090 break;
10431091 case D3DTOP_SELECTARG2:
10441092 String_Append(fsrc, "color.a = ");
1045 - String_Append(fsrc, arg2.c_str());
 1093+ String_Append(fsrc, arg2.ptr);
10461094 String_Append(fsrc, ";\n");
10471095 break;
10481096 case D3DTOP_MODULATE:
10491097 String_Append(fsrc, "color.a = ");
1050 - String_Append(fsrc, arg1.c_str());
 1098+ String_Append(fsrc, arg1.ptr);
10511099 String_Append(fsrc, " * ");
1052 - String_Append(fsrc, arg2.c_str());
 1100+ String_Append(fsrc, arg2.ptr);
10531101 String_Append(fsrc, ";\n");
10541102 break;
10551103 case D3DTOP_MODULATE2X:
10561104 String_Append(fsrc, "color.a = (");
1057 - String_Append(fsrc, arg1.c_str());
 1105+ String_Append(fsrc, arg1.ptr);
10581106 String_Append(fsrc, " * ");
1059 - String_Append(fsrc, arg2.c_str());
 1107+ String_Append(fsrc, arg2.ptr);
10601108 String_Append(fsrc, ") * 2.0;\n");
10611109 break;
10621110 case D3DTOP_MODULATE4X:
10631111 String_Append(fsrc, "color.a = (");
1064 - String_Append(fsrc, arg1.c_str());
 1112+ String_Append(fsrc, arg1.ptr);
10651113 String_Append(fsrc, " * ");
1066 - String_Append(fsrc, arg2.c_str());
 1114+ String_Append(fsrc, arg2.ptr);
10671115 String_Append(fsrc, ") * 4.0;\n");
10681116 break;
10691117 case D3DTOP_ADD:
10701118 String_Append(fsrc, "color.a = ");
1071 - String_Append(fsrc, arg1.c_str());
 1119+ String_Append(fsrc, arg1.ptr);
10721120 String_Append(fsrc, " + ");
1073 - String_Append(fsrc, arg2.c_str());
 1121+ String_Append(fsrc, arg2.ptr);
10741122 String_Append(fsrc, ";\n");
10751123 break;
10761124 case D3DTOP_ADDSIGNED:
10771125 String_Append(fsrc, "color.a = ");
1078 - String_Append(fsrc, arg1.c_str());
 1126+ String_Append(fsrc, arg1.ptr);
10791127 String_Append(fsrc, " + ");
1080 - String_Append(fsrc, arg2.c_str());
 1128+ String_Append(fsrc, arg2.ptr);
10811129 String_Append(fsrc, " - .5;\n");
10821130 break;
10831131 case D3DTOP_ADDSIGNED2X:
10841132 String_Append(fsrc, "color.a = (");
1085 - String_Append(fsrc, arg1.c_str());
 1133+ String_Append(fsrc, arg1.ptr);
10861134 String_Append(fsrc, " + ");
1087 - String_Append(fsrc, arg2.c_str());
 1135+ String_Append(fsrc, arg2.ptr);
10881136 String_Append(fsrc, " - .5) * 2.0;\n");
10891137 break;
10901138 case D3DTOP_SUBTRACT:
10911139 String_Append(fsrc, "color.a = ");
1092 - String_Append(fsrc, arg1.c_str());
 1140+ String_Append(fsrc, arg1.ptr);
10931141 String_Append(fsrc, " - ");
1094 - String_Append(fsrc, arg2.c_str());
 1142+ String_Append(fsrc, arg2.ptr);
10951143 String_Append(fsrc, ";\n");
10961144 break;
10971145 case D3DTOP_ADDSMOOTH:
10981146 String_Append(fsrc, "color.a = ");
1099 - String_Append(fsrc, arg1.c_str());
 1147+ String_Append(fsrc, arg1.ptr);
11001148 String_Append(fsrc, " + ");
1101 - String_Append(fsrc, arg2.c_str());
 1149+ String_Append(fsrc, arg2.ptr);
11021150 String_Append(fsrc, " - ");
1103 - String_Append(fsrc, arg1.c_str());
 1151+ String_Append(fsrc, arg1.ptr);
11041152 String_Append(fsrc, " * ");
1105 - String_Append(fsrc, arg2.c_str());
 1153+ String_Append(fsrc, arg2.ptr);
11061154 String_Append(fsrc, ";\n");
11071155 break;
11081156 case D3DTOP_BLENDDIFFUSEALPHA:
11091157 String_Append(fsrc, "color.a = ");
1110 - String_Append(fsrc, arg1.c_str());
 1158+ String_Append(fsrc, arg1.ptr);
11111159 String_Append(fsrc, " * gl_Color.a + ");
1112 - String_Append(fsrc, arg2.c_str());
 1160+ String_Append(fsrc, arg2.ptr);
11131161 String_Append(fsrc, " * (1.0-gl_Color.a);\n");
11141162 break;
11151163 case D3DTOP_BLENDTEXTUREALPHA:
1116 - texarg = blendargs[2];
1117 - texarg.replace(17,1,_itoa(i,idstring,10));
1118 - texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1164+ String_Assign(&texarg, blendargs[2]);
 1165+ texarg.ptr[17] = *(_itoa(i,idstring,10));
 1166+ texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
11191167 String_Append(fsrc, "color.a = ");
1120 - String_Append(fsrc, arg1.c_str());
 1168+ String_Append(fsrc, arg1.ptr);
11211169 String_Append(fsrc, " * ");
1122 - String_Append(fsrc, texarg.c_str());
 1170+ String_Append(fsrc, texarg.ptr);
11231171 String_Append(fsrc, ".a + ");
1124 - String_Append(fsrc, arg2.c_str());
 1172+ String_Append(fsrc, arg2.ptr);
11251173 String_Append(fsrc, " * (1.0-");
1126 - String_Append(fsrc, texarg.c_str());
 1174+ String_Append(fsrc, texarg.ptr);
11271175 String_Append(fsrc, ".a);\n");
11281176 break;
11291177 case D3DTOP_BLENDFACTORALPHA:
11301178 String_Append(fsrc, "color.a = ");
1131 - String_Append(fsrc, arg1.c_str());
 1179+ String_Append(fsrc, arg1.ptr);
11321180 String_Append(fsrc, " * texfactor.a + ");
1133 - String_Append(fsrc, arg2.c_str());
 1181+ String_Append(fsrc, arg2.ptr);
11341182 String_Append(fsrc, " * (1.0-texfactor.a);\n");
11351183 break;
11361184 case D3DTOP_BLENDTEXTUREALPHAPM:
1137 - texarg = blendargs[2];
1138 - texarg.replace(17,1,_itoa(i,idstring,10));
1139 - texarg.replace(31,1,_itoa((texstate[i].shaderid>>54)&7,idstring,10));
 1185+ String_Assign(&texarg, blendargs[2]);
 1186+ texarg.ptr[17] = *(_itoa(i,idstring,10));
 1187+ texarg.ptr[31] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
11401188 String_Append(fsrc, "color.a = ");
1141 - String_Append(fsrc, arg1.c_str());
 1189+ String_Append(fsrc, arg1.ptr);
11421190 String_Append(fsrc, " + ");
1143 - String_Append(fsrc, arg2.c_str());
 1191+ String_Append(fsrc, arg2.ptr);
11441192 String_Append(fsrc, " * (1.0-");
1145 - String_Append(fsrc, texarg.c_str());
 1193+ String_Append(fsrc, texarg.ptr);
11461194 String_Append(fsrc, ".a);\n");
11471195 break;
11481196 case D3DTOP_BLENDCURRENTALPHA:
11491197 String_Append(fsrc, "color.a = ");
1150 - String_Append(fsrc, arg1.c_str());
 1198+ String_Append(fsrc, arg1.ptr);
11511199 String_Append(fsrc, " * color.a + ");
1152 - String_Append(fsrc, arg2.c_str());
 1200+ String_Append(fsrc, arg2.ptr);
11531201 String_Append(fsrc, " * (1.0-color.a);\n");
11541202 break;
11551203 }
@@ -1205,6 +1253,10 @@
12061254 if(((id>>61)&1) && !vertexfog && !pixelfog) String_Append(fsrc, op_fogassign);
12071255 String_Append(fsrc, op_colorfragout);
12081256 String_Append(fsrc, mainend);
 1257+ String_Free(&tmp);
 1258+ String_Free(&arg1);
 1259+ String_Free(&arg2);
 1260+ String_Free(&texarg);
12091261 #ifdef _DEBUG
12101262 OutputDebugStringA("Fragment shader:\n");
12111263 OutputDebugStringA(fsrc->ptr);
@@ -1213,18 +1265,18 @@
12141266 TRACE_STRING(fsrc->ptr);
12151267 TRACE_STRING("\nCompiling fragment shader:\n");
12161268 #endif
1217 - genshaders[index].shader.fs = ext->glCreateShader(GL_FRAGMENT_SHADER);
 1269+ This->genshaders[index].shader.fs = This->ext->glCreateShader(GL_FRAGMENT_SHADER);
12181270 src = fsrc->ptr;
12191271 srclen = strlen(src);
1220 - ext->glShaderSource(genshaders[index].shader.fs,1,&src,&srclen);
1221 - ext->glCompileShader(genshaders[index].shader.fs);
1222 - ext->glGetShaderiv(genshaders[index].shader.fs,GL_COMPILE_STATUS,&result);
 1272+ This->ext->glShaderSource(This->genshaders[index].shader.fs,1,&src,&srclen);
 1273+ This->ext->glCompileShader(This->genshaders[index].shader.fs);
 1274+ This->ext->glGetShaderiv(This->genshaders[index].shader.fs,GL_COMPILE_STATUS,&result);
12231275 #ifdef _DEBUG
12241276 if(!result)
12251277 {
1226 - ext->glGetShaderiv(genshaders[index].shader.fs,GL_INFO_LOG_LENGTH,&loglen);
 1278+ This->ext->glGetShaderiv(This->genshaders[index].shader.fs,GL_INFO_LOG_LENGTH,&loglen);
12271279 infolog = (char*)malloc(loglen);
1228 - ext->glGetShaderInfoLog(genshaders[index].shader.fs,loglen,&result,infolog);
 1280+ This->ext->glGetShaderInfoLog(This->genshaders[index].shader.fs,loglen,&result,infolog);
12291281 OutputDebugStringA("Compilation failed. Error messages:\n");
12301282 OutputDebugStringA(infolog);
12311283 TRACE_STRING("Compilation failed. Error messages:\n");
@@ -1233,17 +1285,17 @@
12341286 }
12351287 OutputDebugStringA("\nLinking program:\n");
12361288 #endif
1237 - genshaders[index].shader.prog = ext->glCreateProgram();
1238 - ext->glAttachShader(genshaders[index].shader.prog,genshaders[index].shader.vs);
1239 - ext->glAttachShader(genshaders[index].shader.prog,genshaders[index].shader.fs);
1240 - ext->glLinkProgram(genshaders[index].shader.prog);
1241 - ext->glGetProgramiv(genshaders[index].shader.prog,GL_LINK_STATUS,&result);
 1289+ This->genshaders[index].shader.prog = This->ext->glCreateProgram();
 1290+ This->ext->glAttachShader(This->genshaders[index].shader.prog,This->genshaders[index].shader.vs);
 1291+ This->ext->glAttachShader(This->genshaders[index].shader.prog,This->genshaders[index].shader.fs);
 1292+ This->ext->glLinkProgram(This->genshaders[index].shader.prog);
 1293+ This->ext->glGetProgramiv(This->genshaders[index].shader.prog,GL_LINK_STATUS,&result);
12421294 #ifdef _DEBUG
12431295 if(!result)
12441296 {
1245 - ext->glGetProgramiv(genshaders[index].shader.prog,GL_INFO_LOG_LENGTH,&loglen);
 1297+ This->ext->glGetProgramiv(This->genshaders[index].shader.prog,GL_INFO_LOG_LENGTH,&loglen);
12461298 infolog = (char*)malloc(loglen);
1247 - ext->glGetProgramInfoLog(genshaders[index].shader.prog,loglen,&result,infolog);
 1299+ This->ext->glGetProgramInfoLog(This->genshaders[index].shader.prog,loglen,&result,infolog);
12481300 OutputDebugStringA("Program link failed. Error messages:\n");
12491301 OutputDebugStringA(infolog);
12501302 TRACE_STRING("Program link failed. Error messages:\n");
@@ -1252,41 +1304,41 @@
12531305 }
12541306 #endif
12551307 // Attributes
1256 - genshaders[index].shader.attribs[0] = ext->glGetAttribLocation(genshaders[index].shader.prog,"xyz");
1257 - genshaders[index].shader.attribs[1] = ext->glGetAttribLocation(genshaders[index].shader.prog,"rhw");
1258 - genshaders[index].shader.attribs[2] = ext->glGetAttribLocation(genshaders[index].shader.prog,"blend0");
1259 - genshaders[index].shader.attribs[3] = ext->glGetAttribLocation(genshaders[index].shader.prog,"blend1");
1260 - genshaders[index].shader.attribs[4] = ext->glGetAttribLocation(genshaders[index].shader.prog,"blend2");
1261 - genshaders[index].shader.attribs[5] = ext->glGetAttribLocation(genshaders[index].shader.prog,"blend3");
1262 - genshaders[index].shader.attribs[6] = ext->glGetAttribLocation(genshaders[index].shader.prog,"blend4");
1263 - genshaders[index].shader.attribs[7] = ext->glGetAttribLocation(genshaders[index].shader.prog,"nxyz");
1264 - genshaders[index].shader.attribs[8] = ext->glGetAttribLocation(genshaders[index].shader.prog,"rgba0");
1265 - genshaders[index].shader.attribs[9] = ext->glGetAttribLocation(genshaders[index].shader.prog,"rgba1");
 1308+ This->genshaders[index].shader.attribs[0] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"xyz");
 1309+ This->genshaders[index].shader.attribs[1] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"rhw");
 1310+ This->genshaders[index].shader.attribs[2] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"blend0");
 1311+ This->genshaders[index].shader.attribs[3] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"blend1");
 1312+ This->genshaders[index].shader.attribs[4] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"blend2");
 1313+ This->genshaders[index].shader.attribs[5] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"blend3");
 1314+ This->genshaders[index].shader.attribs[6] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"blend4");
 1315+ This->genshaders[index].shader.attribs[7] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"nxyz");
 1316+ This->genshaders[index].shader.attribs[8] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"rgba0");
 1317+ This->genshaders[index].shader.attribs[9] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog,"rgba1");
12661318 char attrS[] = "sX";
12671319 for(int i = 0; i < 8; i++)
12681320 {
12691321 attrS[1] = i + '0';
1270 - genshaders[index].shader.attribs[i+10] = ext->glGetAttribLocation(genshaders[index].shader.prog,attrS);
 1322+ This->genshaders[index].shader.attribs[i + 10] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog, attrS);
12711323 }
12721324 char attrST[] = "stX";
12731325 for(int i = 0; i < 8; i++)
12741326 {
12751327 attrST[2] = i + '0';
1276 - genshaders[index].shader.attribs[i+18] = ext->glGetAttribLocation(genshaders[index].shader.prog,attrST);
 1328+ This->genshaders[index].shader.attribs[i + 18] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog, attrST);
12771329 }
12781330 char attrSTR[] = "strX";
12791331 for(int i = 0; i < 8; i++)
12801332 {
12811333 attrSTR[3] = i + '0';
1282 - genshaders[index].shader.attribs[i+26] = ext->glGetAttribLocation(genshaders[index].shader.prog,attrSTR);
 1334+ This->genshaders[index].shader.attribs[i + 26] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog, attrSTR);
12831335 }
12841336 char attrSTRQ[] = "strqX";
12851337 for(int i = 0; i < 8; i++)
12861338 {
12871339 attrSTRQ[4] = i + '0';
1288 - genshaders[index].shader.attribs[i+34] = ext->glGetAttribLocation(genshaders[index].shader.prog,attrSTRQ);
 1340+ This->genshaders[index].shader.attribs[i + 34] = This->ext->glGetAttribLocation(This->genshaders[index].shader.prog, attrSTRQ);
12891341 }
1290 - genshaders[index].shader.uniforms[0] = ext->glGetUniformLocation(genshaders[index].shader.prog,"matWorld");
 1342+ This->genshaders[index].shader.uniforms[0] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, "matWorld");
12911343 // Uniforms
12921344 // TODO: 4-14 world1-3 and texture0-7
12931345 char uniflight[] = "lightX. ";
@@ -1294,46 +1346,48 @@
12951347 {
12961348 uniflight[5] = i + '0';
12971349 strcpy(uniflight+7,"diffuse");
1298 - genshaders[index].shader.uniforms[20+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1350+ This->genshaders[index].shader.uniforms[20 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
12991351 strcpy(uniflight+7,"specular");
1300 - genshaders[index].shader.uniforms[21+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1352+ This->genshaders[index].shader.uniforms[21 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13011353 strcpy(uniflight+7,"ambient");
1302 - genshaders[index].shader.uniforms[22+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1354+ This->genshaders[index].shader.uniforms[22 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13031355 strcpy(uniflight+7,"position");
1304 - genshaders[index].shader.uniforms[23+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1356+ This->genshaders[index].shader.uniforms[23 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13051357 strcpy(uniflight+7,"direction");
1306 - genshaders[index].shader.uniforms[24+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1358+ This->genshaders[index].shader.uniforms[24 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13071359 strcpy(uniflight+7,"range");
1308 - genshaders[index].shader.uniforms[25+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1360+ This->genshaders[index].shader.uniforms[25 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13091361 strcpy(uniflight+7,"falloff");
1310 - genshaders[index].shader.uniforms[26+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1362+ This->genshaders[index].shader.uniforms[26 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13111363 strcpy(uniflight+7,"constant");
1312 - genshaders[index].shader.uniforms[27+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1364+ This->genshaders[index].shader.uniforms[27 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13131365 strcpy(uniflight+7,"linear");
1314 - genshaders[index].shader.uniforms[28+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1366+ This->genshaders[index].shader.uniforms[28 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13151367 strcpy(uniflight+7,"quad");
1316 - genshaders[index].shader.uniforms[29+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1368+ This->genshaders[index].shader.uniforms[29 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13171369 strcpy(uniflight+7,"theta");
1318 - genshaders[index].shader.uniforms[30+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1370+ This->genshaders[index].shader.uniforms[30 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13191371 strcpy(uniflight+7,"phi");
1320 - genshaders[index].shader.uniforms[31+(i*12)] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniflight);
 1372+ This->genshaders[index].shader.uniforms[31 + (i * 12)] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniflight);
13211373 }
13221374 char uniftex[] = "texX";
13231375 for(int i = 0; i < 8; i++)
13241376 {
13251377 uniftex[3] = i + '0';
1326 - genshaders[index].shader.uniforms[128+i] = ext->glGetUniformLocation(genshaders[index].shader.prog,uniftex);
 1378+ This->genshaders[index].shader.uniforms[128 + i] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, uniftex);
13271379 }
1328 - genshaders[index].shader.uniforms[136] = ext->glGetUniformLocation(genshaders[index].shader.prog,"ambientcolor");
1329 - genshaders[index].shader.uniforms[137] = ext->glGetUniformLocation(genshaders[index].shader.prog,"width");
1330 - genshaders[index].shader.uniforms[138] = ext->glGetUniformLocation(genshaders[index].shader.prog,"height");
1331 - genshaders[index].shader.uniforms[139] = ext->glGetUniformLocation(genshaders[index].shader.prog,"xoffset");
1332 - genshaders[index].shader.uniforms[140] = ext->glGetUniformLocation(genshaders[index].shader.prog,"yoffset");
1333 - genshaders[index].shader.uniforms[141] = ext->glGetUniformLocation(genshaders[index].shader.prog,"alpharef");
 1380+ This->genshaders[index].shader.uniforms[136] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"ambientcolor");
 1381+ This->genshaders[index].shader.uniforms[137] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"width");
 1382+ This->genshaders[index].shader.uniforms[138] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"height");
 1383+ This->genshaders[index].shader.uniforms[139] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"xoffset");
 1384+ This->genshaders[index].shader.uniforms[140] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"yoffset");
 1385+ This->genshaders[index].shader.uniforms[141] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog,"alpharef");
13341386 char unifkey[] = "keyX";
13351387 for(int i = 0; i < 8; i++)
13361388 {
13371389 unifkey[3] = i + '0';
1338 - genshaders[index].shader.uniforms[142+i] = ext->glGetUniformLocation(genshaders[index].shader.prog,unifkey);
 1390+ This->genshaders[index].shader.uniforms[142 + i] = This->ext->glGetUniformLocation(This->genshaders[index].shader.prog, unifkey);
13391391 }
13401392 }
 1393+
 1394+}
\ No newline at end of file
Index: ddraw/ShaderGen3D.h
@@ -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
@@ -18,6 +18,10 @@
1919 #ifndef _SHADERGEN_H
2020 #define _SHADERGEN_H
2121
 22+#ifdef __cplusplus
 23+extern "C" {
 24+#endif
 25+
2226 typedef struct
2327 {
2428 GLint vs;
@@ -42,19 +46,10 @@
4347
4448 struct ShaderGen2D;
4549
46 -class ShaderGen3D
 50+typedef struct ShaderGen3D
4751 {
48 -public:
49 - ShaderGen3D(glExtensions *glext, ShaderManager *shaderman);
50 - ~ShaderGen3D();
51 - void ClearShaders();
52 - void SetShader(__int64 id, TEXTURESTAGE *texstate, int *texcoords, int type, ShaderGen2D *gen2d);
53 - GLuint GetProgram();
54 - void ZeroShaderArray();
55 - void CreateShader(int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords);
5652 GenShader *genshaders;
5753 int current_genshader;
58 -private:
5954 __int64 current_shader;
6055 __int64 current_texid[8];
6156 int current_shadertype;
@@ -64,6 +59,18 @@
6560 GLuint current_prog;
6661 glExtensions *ext;
6762 ShaderManager *shaders;
68 -};
 63+} ShaderGen3D;
6964
 65+void ShaderGen3D_Init(glExtensions *glext, ShaderManager *shaderman, ShaderGen3D *gen);
 66+void ShaderGen3D_Delete(ShaderGen3D *This);
 67+void ShaderGen3D_ClearShaders(ShaderGen3D *This);
 68+void ShaderGen3D_SetShader(ShaderGen3D *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type, ShaderGen2D *gen2d);
 69+GLuint ShaderGen3D_GetProgram(ShaderGen3D *This);
 70+void ShaderGen3D_ZeroShaderArray(ShaderGen3D *This);
 71+void ShaderGen3D_CreateShader(ShaderGen3D *This, int index, __int64 id, TEXTURESTAGE *texstate, int *texcoords);
 72+
 73+#ifdef __cplusplus
 74+}
 75+#endif
 76+
7077 #endif
\ No newline at end of file
Index: ddraw/ShaderManager.cpp
@@ -17,10 +17,9 @@
1818
1919 #include "common.h"
2020 #include "TextureManager.h"
 21+#include "timer.h"
2122 #include "glUtil.h"
22 -#include "timer.h"
2323 #include "glRenderer.h"
24 -#include "glDirect3DDevice.h"
2524 #include "string.h"
2625 #include "ShaderManager.h"
2726 #include "ShaderGen3D.h"
@@ -170,7 +169,8 @@
171170 shaderman->shaders[i].pal = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"pal");
172171 shaderman->shaders[i].view = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"view");
173172 }
174 - shaderman->gen3d = new ShaderGen3D(shaderman->ext, shaderman);
 173+ shaderman->gen3d = (ShaderGen3D*)malloc(sizeof(ShaderGen3D));
 174+ ShaderGen3D_Init(shaderman->ext, shaderman, shaderman->gen3d);
175175 shaderman->gen2d = (ShaderGen2D*)malloc(sizeof(ShaderGen2D));
176176 ZeroMemory(shaderman->gen2d, sizeof(ShaderGen2D));
177177 ShaderGen2D_Init(shaderman->gen2d, shaderman->ext, shaderman);
@@ -200,12 +200,13 @@
201201 free(This->shaders);
202202 ShaderGen2D_Delete(This->gen2d);
203203 free(This->gen2d);
204 - delete This->gen3d;
 204+ ShaderGen3D_Delete(This->gen3d);
 205+ free(This->gen3d);
205206 }
206207
207208 void ShaderManager_SetShader(ShaderManager *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type)
208209 {
209 - This->gen3d->SetShader(id, texstate, texcoords, type, This->gen2d);
 210+ ShaderGen3D_SetShader(This->gen3d, id, texstate, texcoords, type, This->gen2d);
210211 }
211212
212213 }
\ No newline at end of file
Index: ddraw/ShaderManager.h
@@ -49,7 +49,7 @@
5050 #define PROG_CLIPSTENCIL 5
5151
5252 struct TEXTURESTAGE;
53 -class ShaderGen3D;
 53+struct ShaderGen3D;
5454
5555 typedef struct ShaderManager
5656 {