Index: ddraw/ShaderGen3D.cpp |
— | — | @@ -21,8 +21,6 @@ |
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 "ShaderGen3D.h"
|
29 | 27 | #include "ShaderGen2D.h"
|
— | — | @@ -29,24 +27,26 @@ |
30 | 28 | #include "ShaderManager.h"
|
31 | 29 | #include "../common/version.h"
|
32 | 30 |
|
33 | | -ShaderGen3D::ShaderGen3D(glExtensions *glext, ShaderManager *shaderman)
|
| 31 | +extern "C" {
|
| 32 | +
|
| 33 | +void ShaderGen3D_Init(glExtensions *glext, ShaderManager *shaderman, ShaderGen3D *gen)
|
34 | 34 | {
|
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;
|
45 | 45 | }
|
46 | 46 |
|
47 | | -ShaderGen3D::~ShaderGen3D()
|
| 47 | +void ShaderGen3D_Delete(ShaderGen3D *This)
|
48 | 48 | {
|
49 | | - ClearShaders();
|
50 | | - free(genshaders);
|
| 49 | + ShaderGen3D_ClearShaders(This);
|
| 50 | + free(This->genshaders);
|
51 | 51 | }
|
52 | 52 | /* Bits in Shader ID:
|
53 | 53 | Bits 0-1 - Shading mode: 00=flat 01=gouraud 11=phong 10=flat per-pixel GL/VS/FS
|
— | — | @@ -114,29 +114,33 @@ |
115 | 115 |
|
116 | 116 | /**
|
117 | 117 | * Deletes all shader programs in the array.
|
| 118 | + * @param This
|
| 119 | + * Pointer to ShaderGen3D structure
|
118 | 120 | */
|
119 | | -void ShaderGen3D::ClearShaders()
|
| 121 | +void ShaderGen3D_ClearShaders(ShaderGen3D *This)
|
120 | 122 | {
|
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++)
|
123 | 125 | {
|
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);
|
131 | 133 | }
|
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;
|
137 | 139 | }
|
138 | 140 |
|
139 | 141 | /**
|
140 | 142 | * Sets a shader by render state. If the shader does not exist, generates it.
|
| 143 | + * @param This
|
| 144 | + * Pointer to ShaderGen3D structure
|
141 | 145 | * @param id
|
142 | 146 | * 64-bit value containing current render states
|
143 | 147 | * @param texstate
|
— | — | @@ -149,25 +153,25 @@ |
150 | 154 | * 1 for generated 2D
|
151 | 155 | * 2 for generated 3D
|
152 | 156 | */
|
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)
|
154 | 158 | {
|
155 | 159 | int shaderindex = -1;
|
156 | 160 | switch(type)
|
157 | 161 | {
|
158 | 162 | 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;
|
164 | 168 | break;
|
165 | 169 | 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;
|
169 | 173 | for (int i = 0; i < gen2d->shadercount; i++)
|
170 | 174 | {
|
171 | | - if (shaders->gen2d->genshaders2D[i].id == id)
|
| 175 | + if (This->shaders->gen2d->genshaders2D[i].id == id)
|
172 | 176 | {
|
173 | 177 | shaderindex = i;
|
174 | 178 | break;
|
— | — | @@ -179,10 +183,10 @@ |
180 | 184 | if (gen2d->shadercount > 256) gen2d->shadercount = 256;
|
181 | 185 | if (gen2d->genshaders2D[gen2d->genindex].shader.prog)
|
182 | 186 | {
|
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);
|
187 | 191 | String_Free(&gen2d->genshaders2D[gen2d->genindex].shader.vsrc);
|
188 | 192 | String_Free(&gen2d->genshaders2D[gen2d->genindex].shader.fsrc);
|
189 | 193 | ZeroMemory(&gen2d->genshaders2D[gen2d->genindex], sizeof(GenShader2D));
|
— | — | @@ -193,27 +197,27 @@ |
194 | 198 | if (gen2d->genindex >= 256) gen2d->genindex = 0;
|
195 | 199 | }
|
196 | 200 | 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;
|
200 | 204 | break;
|
201 | 205 | case 2: // 3D generated shader
|
202 | | - if((current_shadertype == 2) && (id == current_shader))
|
| 206 | + if((This->current_shadertype == 2) && (id == This->current_shader))
|
203 | 207 | {
|
204 | | - if(!memcmp(current_texid,texstate,8*sizeof(__int64))) return;
|
| 208 | + if(!memcmp(This->current_texid,texstate,8*sizeof(__int64))) return;
|
205 | 209 | }
|
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++)
|
209 | 213 | {
|
210 | | - if(genshaders[i].id == id)
|
| 214 | + if(This->genshaders[i].id == id)
|
211 | 215 | {
|
212 | 216 | bool texidmatch = true;
|
213 | 217 | 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;
|
215 | 219 | if(texidmatch)
|
216 | 220 | {
|
217 | | - if(!memcmp(genshaders[i].texcoords,texcoords,8*sizeof(int)))
|
| 221 | + if(!memcmp(This->genshaders[i].texcoords,texcoords,8*sizeof(int)))
|
218 | 222 | {
|
219 | 223 | shaderindex = i;
|
220 | 224 | break;
|
— | — | @@ -223,43 +227,45 @@ |
224 | 228 | }
|
225 | 229 | if(shaderindex == -1)
|
226 | 230 | {
|
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)
|
230 | 234 | {
|
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));
|
238 | 242 | }
|
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;
|
243 | 247 | }
|
244 | | - genshaders[shaderindex].id = id;
|
| 248 | + This->genshaders[shaderindex].id = id;
|
245 | 249 | 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;
|
251 | 255 | }
|
252 | 256 | }
|
253 | 257 |
|
254 | 258 | /**
|
255 | 259 | * Retrieves the GLSL program currently in use
|
| 260 | + * @param This
|
| 261 | + * Pointer to ShaderGen3D structure
|
256 | 262 | * @return
|
257 | 263 | * Number of the current GLSL program, or if using built-in shaders, the ID of
|
258 | 264 | * the shader
|
259 | 265 | */
|
260 | | -GLuint ShaderGen3D::GetProgram()
|
| 266 | +GLuint ShaderGen3D_GetProgram(ShaderGen3D *This)
|
261 | 267 | {
|
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;
|
264 | 270 | }
|
265 | 271 |
|
266 | 272 |
|
— | — | @@ -429,6 +435,8 @@ |
430 | 436 |
|
431 | 437 | /**
|
432 | 438 | * Creates an OpenGL shader program
|
| 439 | + * @param This
|
| 440 | + * Pointer to ShaderGen3D structure
|
433 | 441 | * @param index
|
434 | 442 | * Index of the shader in the array to generate
|
435 | 443 | * @param id
|
— | — | @@ -438,9 +446,10 @@ |
439 | 447 | * @param texcoords
|
440 | 448 | * Pointer to number of texture coordinates in each texture stage
|
441 | 449 | */
|
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)
|
443 | 451 | {
|
444 | | - string tmp;
|
| 452 | + STRING tmp;
|
| 453 | + ZeroMemory(&tmp, sizeof(STRING));
|
445 | 454 | int i;
|
446 | 455 | bool hasdir = false;
|
447 | 456 | bool haspoint = false;
|
— | — | @@ -457,11 +466,11 @@ |
458 | 467 | char idstring[22];
|
459 | 468 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
460 | 469 | 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;
|
463 | 472 | // Create vertex shader
|
464 | 473 | //Header
|
465 | | - STRING *vsrc = &genshaders[index].shader.vsrc;
|
| 474 | + STRING *vsrc = &This->genshaders[index].shader.vsrc;
|
466 | 475 | String_Append(vsrc, header);
|
467 | 476 | String_Append(vsrc, vertexshader);
|
468 | 477 | String_Append(vsrc, idheader);
|
— | — | @@ -469,16 +478,16 @@ |
470 | 479 | // Attributes
|
471 | 480 | String_Append(vsrc, attr_xyz);
|
472 | 481 | if((id>>50)&1) String_Append(vsrc, attr_rhw);
|
473 | | - tmp = attr_rgba;
|
| 482 | + String_Assign(&tmp, attr_rgba);
|
474 | 483 | if((id>>35)&1)
|
475 | 484 | {
|
476 | | - tmp.replace(19,1,"0");
|
477 | | - String_Append(vsrc, tmp.c_str());
|
| 485 | + tmp.ptr[19] = '0';
|
| 486 | + String_Append(vsrc, tmp.ptr);
|
478 | 487 | }
|
479 | 488 | if((id>>36)&1)
|
480 | 489 | {
|
481 | | - tmp.replace(19,1,"1");
|
482 | | - String_Append(vsrc, tmp.c_str());
|
| 490 | + tmp.ptr[19] = '1';
|
| 491 | + String_Append(vsrc, tmp.ptr);
|
483 | 492 | }
|
484 | 493 | if((id>>37)&1) String_Append(vsrc, attr_nxyz);
|
485 | 494 | else String_Append(vsrc, const_nxyz);
|
— | — | @@ -485,11 +494,11 @@ |
486 | 495 | count = (id>>46)&7;
|
487 | 496 | if(count)
|
488 | 497 | {
|
489 | | - tmp = attr_blend;
|
| 498 | + String_Assign(&tmp,attr_blend);
|
490 | 499 | for(i = 0; i < count; i++)
|
491 | 500 | {
|
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);
|
494 | 503 | }
|
495 | 504 | }
|
496 | 505 | for(i = 0; i < 8; i++)
|
— | — | @@ -499,23 +508,23 @@ |
500 | 509 | case -1:
|
501 | 510 | continue;
|
502 | 511 | 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));
|
505 | 514 | break;
|
506 | 515 | 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));
|
509 | 518 | break;
|
510 | 519 | 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));
|
513 | 522 | break;
|
514 | 523 | 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));
|
517 | 526 | break;
|
518 | 527 | }
|
519 | | - String_Append(vsrc, tmp.c_str());
|
| 528 | + String_Append(vsrc, tmp.ptr);
|
520 | 529 | }
|
521 | 530 |
|
522 | 531 | // Uniforms
|
— | — | @@ -528,11 +537,11 @@ |
529 | 538 | {
|
530 | 539 | String_Append(vsrc, lightstruct);
|
531 | 540 | String_Append(vsrc, unif_world);
|
532 | | - tmp = unif_light;
|
| 541 | + String_Assign(&tmp, unif_light);
|
533 | 542 | for(i = 0; i < numlights; i++)
|
534 | 543 | {
|
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);
|
537 | 546 | }
|
538 | 547 | }
|
539 | 548 |
|
— | — | @@ -564,7 +573,7 @@ |
565 | 574 | else String_Append(vsrc, op_transform);
|
566 | 575 | if((id>>49)&1) String_Append(vsrc, op_normalize);
|
567 | 576 | 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",
|
569 | 578 | "gl_FrontMaterial.emission","rgba0.bgra","rgba1.bgra"};
|
570 | 579 | if(numlights)
|
571 | 580 | {
|
— | — | @@ -575,22 +584,22 @@ |
576 | 585 | {
|
577 | 586 | if(id>>(51+i)&1)
|
578 | 587 | {
|
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);
|
582 | 591 | }
|
583 | 592 | else
|
584 | 593 | {
|
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);
|
588 | 597 | }
|
589 | 598 | }
|
590 | 599 | else
|
591 | 600 | {
|
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);
|
595 | 604 | }
|
596 | 605 | }
|
597 | 606 | if((id>>60)&1)
|
— | — | @@ -602,24 +611,24 @@ |
603 | 612 | int matcolor;
|
604 | 613 | String_Append(vsrc, "gl_FrontColor = (");
|
605 | 614 | 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]);
|
609 | 618 | String_Append(vsrc, " * diffuse) + (");
|
610 | 619 | 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]);
|
614 | 623 | String_Append(vsrc, " * ambient)\n+ (");
|
615 | 624 | 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]);
|
619 | 628 | String_Append(vsrc, " * specular) + ");
|
620 | 629 | 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]);
|
624 | 633 | String_Append(vsrc, ";\n");
|
625 | 634 | }
|
626 | 635 | else String_Append(vsrc, op_colorout);
|
— | — | @@ -639,9 +648,9 @@ |
640 | 649 | }
|
641 | 650 | else
|
642 | 651 | {
|
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);
|
646 | 655 | texindex = (texstate[i].shaderid>>54)&3;
|
647 | 656 | switch(texcoords[texindex])
|
648 | 657 | {
|
— | — | @@ -649,25 +658,25 @@ |
650 | 659 | String_Append(vsrc, op_texpassthru2null);
|
651 | 660 | break;
|
652 | 661 | 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);
|
656 | 665 | default:
|
657 | 666 | break;
|
658 | 667 | 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);
|
662 | 671 | break;
|
663 | 672 | 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);
|
667 | 676 | break;
|
668 | 677 | 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);
|
672 | 681 | break;
|
673 | 682 | }
|
674 | 683 | }
|
— | — | @@ -699,21 +708,21 @@ |
700 | 709 | TRACE_STRING(vsrc->ptr);
|
701 | 710 | TRACE_STRING("\nCompiling vertex shader:\n");
|
702 | 711 | #endif
|
703 | | - genshaders[index].shader.vs = ext->glCreateShader(GL_VERTEX_SHADER);
|
| 712 | + This->genshaders[index].shader.vs = This->ext->glCreateShader(GL_VERTEX_SHADER);
|
704 | 713 | const char *src = vsrc->ptr;
|
705 | 714 | 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);
|
708 | 717 | GLint result;
|
709 | 718 | 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);
|
711 | 720 | #ifdef _DEBUG
|
712 | 721 | GLint loglen;
|
713 | 722 | if(!result)
|
714 | 723 | {
|
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);
|
716 | 725 | 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);
|
718 | 727 | OutputDebugStringA("Compilation failed. Error messages:\n");
|
719 | 728 | OutputDebugStringA(infolog);
|
720 | 729 | TRACE_STRING("Compilation failed. Error messages:\n");
|
— | — | @@ -722,7 +731,7 @@ |
723 | 732 | }
|
724 | 733 | #endif
|
725 | 734 | // Create fragment shader
|
726 | | - STRING *fsrc = &genshaders[index].shader.fsrc;
|
| 735 | + STRING *fsrc = &This->genshaders[index].shader.fsrc;
|
727 | 736 | String_Append(fsrc, header);
|
728 | 737 | String_Append(fsrc, fragshader);
|
729 | 738 | _snprintf(idstring,21,"%0.16I64X\n",id);
|
— | — | @@ -733,9 +742,9 @@ |
734 | 743 | for(i = 0; i < 8; i++)
|
735 | 744 | {
|
736 | 745 | 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);
|
740 | 749 | }
|
741 | 750 | if((id>>13)&1)
|
742 | 751 | {
|
— | — | @@ -743,9 +752,9 @@ |
744 | 753 | {
|
745 | 754 | if((texstate[i].shaderid>>60)&1)
|
746 | 755 | {
|
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);
|
750 | 759 | }
|
751 | 760 | }
|
752 | 761 | }
|
— | — | @@ -758,12 +767,15 @@ |
759 | 768 | // Main
|
760 | 769 | String_Append(fsrc, mainstart);
|
761 | 770 | 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));
|
764 | 776 | int args[4];
|
765 | 777 | bool texfail;
|
766 | 778 | 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])",
|
768 | 780 | "","texfactor","gl_SecondaryColor","vec3(1,1,1)","1",".rgb",".a",".aaa"};
|
769 | 781 | bool usecolorkey = false;
|
770 | 782 | if((id>>13)&1) usecolorkey = true;
|
— | — | @@ -779,11 +791,11 @@ |
780 | 792 | {
|
781 | 793 | if((texstate[i].shaderid>>60)&1)
|
782 | 794 | {
|
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);
|
788 | 800 | }
|
789 | 801 | }
|
790 | 802 | // Color stage
|
— | — | @@ -792,60 +804,74 @@ |
793 | 805 | {
|
794 | 806 | case D3DTA_CURRENT:
|
795 | 807 | default:
|
796 | | - arg1 = blendargs[0];
|
| 808 | + String_Assign(&arg1, blendargs[0]);
|
797 | 809 | break;
|
798 | 810 | case D3DTA_DIFFUSE:
|
799 | | - arg1 = blendargs[1];
|
| 811 | + String_Assign(&arg1, blendargs[1]);
|
800 | 812 | break;
|
801 | 813 | case D3DTA_TEXTURE:
|
802 | 814 | if((texstate[i].shaderid >> 59)&1)
|
803 | 815 | {
|
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));
|
807 | 819 | }
|
808 | 820 | else texfail = true;
|
809 | 821 | break;
|
810 | 822 | case D3DTA_TFACTOR:
|
811 | 823 | FIXME("Support texture factor value");
|
812 | | - arg1 = blendargs[4];
|
| 824 | + String_Append(&arg1, blendargs[4]);
|
813 | 825 | break;
|
814 | 826 | case D3DTA_SPECULAR:
|
815 | | - arg1 = blendargs[5];
|
| 827 | + String_Append(&arg1, blendargs[5]);
|
816 | 828 | break;
|
817 | 829 | }
|
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]);
|
821 | 840 | switch(args[1]&7) //arg2
|
822 | 841 | {
|
823 | 842 | case D3DTA_CURRENT:
|
824 | 843 | default:
|
825 | | - arg2 = blendargs[0];
|
| 844 | + String_Assign(&arg2, blendargs[0]);
|
826 | 845 | break;
|
827 | 846 | case D3DTA_DIFFUSE:
|
828 | | - arg2 = blendargs[1];
|
| 847 | + String_Assign(&arg2, blendargs[1]);
|
829 | 848 | break;
|
830 | 849 | case D3DTA_TEXTURE:
|
831 | 850 | if((texstate[i].shaderid >> 59)&1)
|
832 | 851 | {
|
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));
|
836 | 855 | }
|
837 | 856 | else texfail = true;
|
838 | 857 | break;
|
839 | 858 | case D3DTA_TFACTOR:
|
840 | 859 | FIXME("Support texture factor value");
|
841 | | - arg2 = blendargs[4];
|
| 860 | + String_Assign(&arg2, blendargs[4]);
|
842 | 861 | break;
|
843 | 862 | case D3DTA_SPECULAR:
|
844 | | - arg2 = blendargs[5];
|
| 863 | + String_Assign(&arg2, blendargs[5]);
|
845 | 864 | break;
|
846 | 865 | }
|
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]);
|
850 | 876 | if(!texfail) switch(texstate[i].shaderid & 31)
|
851 | 877 | {
|
852 | 878 | case D3DTOP_DISABLE:
|
— | — | @@ -853,119 +879,119 @@ |
854 | 880 | break;
|
855 | 881 | case D3DTOP_SELECTARG1:
|
856 | 882 | String_Append(fsrc, "color.rgb = ");
|
857 | | - String_Append(fsrc, arg1.c_str());
|
| 883 | + String_Append(fsrc, arg1.ptr);
|
858 | 884 | String_Append(fsrc, ";\n");
|
859 | 885 | break;
|
860 | 886 | case D3DTOP_SELECTARG2:
|
861 | 887 | String_Append(fsrc, "color.rgb = ");
|
862 | | - String_Append(fsrc, arg2.c_str());
|
| 888 | + String_Append(fsrc, arg2.ptr);
|
863 | 889 | String_Append(fsrc, ";\n");
|
864 | 890 | break;
|
865 | 891 | case D3DTOP_MODULATE:
|
866 | 892 | String_Append(fsrc, "color.rgb = ");
|
867 | | - String_Append(fsrc, arg1.c_str());
|
| 893 | + String_Append(fsrc, arg1.ptr);
|
868 | 894 | String_Append(fsrc, " * ");
|
869 | | - String_Append(fsrc, arg2.c_str());
|
| 895 | + String_Append(fsrc, arg2.ptr);
|
870 | 896 | String_Append(fsrc, ";\n");
|
871 | 897 | break;
|
872 | 898 | case D3DTOP_MODULATE2X:
|
873 | 899 | String_Append(fsrc, "color.rgb = (");
|
874 | | - String_Append(fsrc, arg1.c_str());
|
| 900 | + String_Append(fsrc, arg1.ptr);
|
875 | 901 | String_Append(fsrc, " * ");
|
876 | | - String_Append(fsrc, arg2.c_str());
|
| 902 | + String_Append(fsrc, arg2.ptr);
|
877 | 903 | String_Append(fsrc, ") * 2.0;\n");
|
878 | 904 | break;
|
879 | 905 | case D3DTOP_MODULATE4X:
|
880 | 906 | String_Append(fsrc, "color.rgb = (");
|
881 | | - String_Append(fsrc, arg1.c_str());
|
| 907 | + String_Append(fsrc, arg1.ptr);
|
882 | 908 | String_Append(fsrc, " * ");
|
883 | | - String_Append(fsrc, arg2.c_str());
|
| 909 | + String_Append(fsrc, arg2.ptr);
|
884 | 910 | String_Append(fsrc, ") * 4.0;\n");
|
885 | 911 | break;
|
886 | 912 | case D3DTOP_ADD:
|
887 | 913 | String_Append(fsrc, "color.rgb = ");
|
888 | | - String_Append(fsrc, arg1.c_str());
|
| 914 | + String_Append(fsrc, arg1.ptr);
|
889 | 915 | String_Append(fsrc, " + ");
|
890 | | - String_Append(fsrc, arg2.c_str());
|
| 916 | + String_Append(fsrc, arg2.ptr);
|
891 | 917 | String_Append(fsrc, ";\n");
|
892 | 918 | break;
|
893 | 919 | case D3DTOP_ADDSIGNED:
|
894 | 920 | String_Append(fsrc, "color.rgb = ");
|
895 | | - String_Append(fsrc, arg1.c_str());
|
| 921 | + String_Append(fsrc, arg1.ptr);
|
896 | 922 | String_Append(fsrc, " + ");
|
897 | | - String_Append(fsrc, arg2.c_str());
|
| 923 | + String_Append(fsrc, arg2.ptr);
|
898 | 924 | String_Append(fsrc, " - .5;\n");
|
899 | 925 | break;
|
900 | 926 | case D3DTOP_ADDSIGNED2X:
|
901 | 927 | String_Append(fsrc, "color.rgb = (");
|
902 | | - String_Append(fsrc, arg1.c_str());
|
| 928 | + String_Append(fsrc, arg1.ptr);
|
903 | 929 | String_Append(fsrc, " + ");
|
904 | | - String_Append(fsrc, arg2.c_str());
|
| 930 | + String_Append(fsrc, arg2.ptr);
|
905 | 931 | String_Append(fsrc, " - .5) * 2.0;\n");
|
906 | 932 | break;
|
907 | 933 | case D3DTOP_SUBTRACT:
|
908 | 934 | String_Append(fsrc, "color.rgb = ");
|
909 | | - String_Append(fsrc, arg1.c_str());
|
| 935 | + String_Append(fsrc, arg1.ptr);
|
910 | 936 | String_Append(fsrc, " - ");
|
911 | | - String_Append(fsrc, arg2.c_str());
|
| 937 | + String_Append(fsrc, arg2.ptr);
|
912 | 938 | String_Append(fsrc, ";\n");
|
913 | 939 | break;
|
914 | 940 | case D3DTOP_ADDSMOOTH:
|
915 | 941 | String_Append(fsrc, "color.rgb = ");
|
916 | | - String_Append(fsrc, arg1.c_str());
|
| 942 | + String_Append(fsrc, arg1.ptr);
|
917 | 943 | String_Append(fsrc, " + ");
|
918 | | - String_Append(fsrc, arg2.c_str());
|
| 944 | + String_Append(fsrc, arg2.ptr);
|
919 | 945 | String_Append(fsrc, " - ");
|
920 | | - String_Append(fsrc, arg1.c_str());
|
| 946 | + String_Append(fsrc, arg1.ptr);
|
921 | 947 | String_Append(fsrc, " * ");
|
922 | | - String_Append(fsrc, arg2.c_str());
|
| 948 | + String_Append(fsrc, arg2.ptr);
|
923 | 949 | String_Append(fsrc, ";\n");
|
924 | 950 | break;
|
925 | 951 | case D3DTOP_BLENDDIFFUSEALPHA:
|
926 | 952 | String_Append(fsrc, "color.rgb = ");
|
927 | | - String_Append(fsrc, arg1.c_str());
|
| 953 | + String_Append(fsrc, arg1.ptr);
|
928 | 954 | String_Append(fsrc, " * gl_Color.a + ");
|
929 | | - String_Append(fsrc, arg2.c_str());
|
| 955 | + String_Append(fsrc, arg2.ptr);
|
930 | 956 | String_Append(fsrc, " * (1.0-gl_Color.a);\n");
|
931 | 957 | break;
|
932 | 958 | 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));
|
936 | 962 | String_Append(fsrc, "color.rgb = ");
|
937 | | - String_Append(fsrc, arg1.c_str());
|
| 963 | + String_Append(fsrc, arg1.ptr);
|
938 | 964 | String_Append(fsrc, " * ");
|
939 | | - String_Append(fsrc, texarg.c_str());
|
| 965 | + String_Append(fsrc, texarg.ptr);
|
940 | 966 | String_Append(fsrc, ".a + ");
|
941 | | - String_Append(fsrc, arg2.c_str());
|
| 967 | + String_Append(fsrc, arg2.ptr);
|
942 | 968 | String_Append(fsrc, " * (1.0-");
|
943 | | - String_Append(fsrc, texarg.c_str());
|
| 969 | + String_Append(fsrc, texarg.ptr);
|
944 | 970 | String_Append(fsrc, ".a);\n");
|
945 | 971 | break;
|
946 | 972 | case D3DTOP_BLENDFACTORALPHA:
|
947 | 973 | String_Append(fsrc, "color.rgb = ");
|
948 | | - String_Append(fsrc, arg1.c_str());
|
| 974 | + String_Append(fsrc, arg1.ptr);
|
949 | 975 | String_Append(fsrc, " * texfactor.a + ");
|
950 | | - String_Append(fsrc, arg2.c_str());
|
| 976 | + String_Append(fsrc, arg2.ptr);
|
951 | 977 | String_Append(fsrc, " * (1.0-texfactor.a);\n");
|
952 | 978 | break;
|
953 | 979 | 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));
|
957 | 983 | String_Append(fsrc, "color.rgb = ");
|
958 | | - String_Append(fsrc, arg1.c_str());
|
| 984 | + String_Append(fsrc, arg1.ptr);
|
959 | 985 | String_Append(fsrc, " + ");
|
960 | | - String_Append(fsrc, arg2.c_str());
|
| 986 | + String_Append(fsrc, arg2.ptr);
|
961 | 987 | String_Append(fsrc, " * (1.0-");
|
962 | | - String_Append(fsrc, texarg.c_str());
|
| 988 | + String_Append(fsrc, texarg.ptr);
|
963 | 989 | String_Append(fsrc, ".a);\n");
|
964 | 990 | break;
|
965 | 991 | case D3DTOP_BLENDCURRENTALPHA:
|
966 | 992 | String_Append(fsrc, "color.rgb = ");
|
967 | | - String_Append(fsrc, arg1.c_str());
|
| 993 | + String_Append(fsrc, arg1.ptr);
|
968 | 994 | String_Append(fsrc, " * color.a + ");
|
969 | | - String_Append(fsrc, arg2.c_str());
|
| 995 | + String_Append(fsrc, arg2.ptr);
|
970 | 996 | String_Append(fsrc, " * (1.0-color.a);\n");
|
971 | 997 | break;
|
972 | 998 | }
|
— | — | @@ -977,178 +1003,200 @@ |
978 | 1004 | {
|
979 | 1005 | case D3DTA_CURRENT:
|
980 | 1006 | default:
|
981 | | - arg1 = blendargs[0]+blendargs[9];
|
| 1007 | + String_Assign(&arg1, blendargs[0]);
|
| 1008 | + String_Append(&arg1, blendargs[9]);
|
982 | 1009 | break;
|
983 | 1010 | case D3DTA_DIFFUSE:
|
984 | | - arg1 = blendargs[1]+blendargs[9];
|
| 1011 | + String_Assign(&arg1, blendargs[1]);
|
| 1012 | + String_Append(&arg1, blendargs[9]);
|
985 | 1013 | break;
|
986 | 1014 | case D3DTA_TEXTURE:
|
987 | 1015 | if((texstate[i].shaderid >> 59)&1)
|
988 | 1016 | {
|
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));
|
992 | 1021 | }
|
993 | 1022 | else texfail = true;
|
994 | 1023 | break;
|
995 | 1024 | case D3DTA_TFACTOR:
|
996 | 1025 | FIXME("Support texture factor value");
|
997 | | - arg1 = blendargs[4]+blendargs[9];
|
| 1026 | + String_Assign(&arg1, blendargs[4]);
|
| 1027 | + String_Append(&arg1, blendargs[9]);
|
998 | 1028 | break;
|
999 | 1029 | case D3DTA_SPECULAR:
|
1000 | | - arg1 = blendargs[5]+blendargs[9];
|
| 1030 | + String_Assign(&arg1, blendargs[5]);
|
| 1031 | + String_Append(&arg1, blendargs[9]);
|
1001 | 1032 | break;
|
1002 | 1033 | }
|
1003 | 1034 | if(args[2] & D3DTA_COMPLEMENT)
|
1004 | | - arg1 = "(1.0 - " + arg1 + ")";
|
1005 | | - switch(args[3]&7) //arg2
|
1006 | 1035 | {
|
| 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 | + {
|
1007 | 1044 | case D3DTA_CURRENT:
|
1008 | 1045 | default:
|
1009 | | - arg2 = blendargs[1]+blendargs[9];
|
| 1046 | + String_Assign(&arg2, blendargs[0]);
|
| 1047 | + String_Append(&arg2, blendargs[9]);
|
1010 | 1048 | break;
|
1011 | 1049 | case D3DTA_DIFFUSE:
|
1012 | | - arg2 = blendargs[1]+blendargs[9];
|
| 1050 | + String_Assign(&arg2, blendargs[1]);
|
| 1051 | + String_Append(&arg2, blendargs[9]);
|
1013 | 1052 | break;
|
1014 | 1053 | case D3DTA_TEXTURE:
|
1015 | 1054 | if((texstate[i].shaderid >> 59)&1)
|
1016 | 1055 | {
|
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));
|
1020 | 1060 | }
|
1021 | 1061 | else texfail = true;
|
1022 | 1062 | break;
|
1023 | 1063 | case D3DTA_TFACTOR:
|
1024 | 1064 | FIXME("Support texture factor value");
|
1025 | | - arg2 = blendargs[4]+blendargs[9];
|
| 1065 | + String_Assign(&arg2, blendargs[4]);
|
| 1066 | + String_Append(&arg2, blendargs[9]);
|
1026 | 1067 | break;
|
1027 | 1068 | case D3DTA_SPECULAR:
|
1028 | | - arg2 = blendargs[5]+blendargs[9];
|
| 1069 | + String_Assign(&arg2, blendargs[5]);
|
| 1070 | + String_Append(&arg2, blendargs[9]);
|
1029 | 1071 | break;
|
1030 | 1072 | }
|
1031 | 1073 | if(args[3] & D3DTA_COMPLEMENT)
|
1032 | | - arg2 = "(1.0 - " + arg2 + ")";
|
1033 | | - if(!texfail) switch((texstate[i].shaderid>>17) & 31)
|
1034 | 1074 | {
|
| 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 | + {
|
1035 | 1083 | case D3DTOP_DISABLE:
|
1036 | 1084 | default:
|
1037 | 1085 | break;
|
1038 | 1086 | case D3DTOP_SELECTARG1:
|
1039 | 1087 | String_Append(fsrc, "color.a = ");
|
1040 | | - String_Append(fsrc, arg1.c_str());
|
| 1088 | + String_Append(fsrc, arg1.ptr);
|
1041 | 1089 | String_Append(fsrc, ";\n");
|
1042 | 1090 | break;
|
1043 | 1091 | case D3DTOP_SELECTARG2:
|
1044 | 1092 | String_Append(fsrc, "color.a = ");
|
1045 | | - String_Append(fsrc, arg2.c_str());
|
| 1093 | + String_Append(fsrc, arg2.ptr);
|
1046 | 1094 | String_Append(fsrc, ";\n");
|
1047 | 1095 | break;
|
1048 | 1096 | case D3DTOP_MODULATE:
|
1049 | 1097 | String_Append(fsrc, "color.a = ");
|
1050 | | - String_Append(fsrc, arg1.c_str());
|
| 1098 | + String_Append(fsrc, arg1.ptr);
|
1051 | 1099 | String_Append(fsrc, " * ");
|
1052 | | - String_Append(fsrc, arg2.c_str());
|
| 1100 | + String_Append(fsrc, arg2.ptr);
|
1053 | 1101 | String_Append(fsrc, ";\n");
|
1054 | 1102 | break;
|
1055 | 1103 | case D3DTOP_MODULATE2X:
|
1056 | 1104 | String_Append(fsrc, "color.a = (");
|
1057 | | - String_Append(fsrc, arg1.c_str());
|
| 1105 | + String_Append(fsrc, arg1.ptr);
|
1058 | 1106 | String_Append(fsrc, " * ");
|
1059 | | - String_Append(fsrc, arg2.c_str());
|
| 1107 | + String_Append(fsrc, arg2.ptr);
|
1060 | 1108 | String_Append(fsrc, ") * 2.0;\n");
|
1061 | 1109 | break;
|
1062 | 1110 | case D3DTOP_MODULATE4X:
|
1063 | 1111 | String_Append(fsrc, "color.a = (");
|
1064 | | - String_Append(fsrc, arg1.c_str());
|
| 1112 | + String_Append(fsrc, arg1.ptr);
|
1065 | 1113 | String_Append(fsrc, " * ");
|
1066 | | - String_Append(fsrc, arg2.c_str());
|
| 1114 | + String_Append(fsrc, arg2.ptr);
|
1067 | 1115 | String_Append(fsrc, ") * 4.0;\n");
|
1068 | 1116 | break;
|
1069 | 1117 | case D3DTOP_ADD:
|
1070 | 1118 | String_Append(fsrc, "color.a = ");
|
1071 | | - String_Append(fsrc, arg1.c_str());
|
| 1119 | + String_Append(fsrc, arg1.ptr);
|
1072 | 1120 | String_Append(fsrc, " + ");
|
1073 | | - String_Append(fsrc, arg2.c_str());
|
| 1121 | + String_Append(fsrc, arg2.ptr);
|
1074 | 1122 | String_Append(fsrc, ";\n");
|
1075 | 1123 | break;
|
1076 | 1124 | case D3DTOP_ADDSIGNED:
|
1077 | 1125 | String_Append(fsrc, "color.a = ");
|
1078 | | - String_Append(fsrc, arg1.c_str());
|
| 1126 | + String_Append(fsrc, arg1.ptr);
|
1079 | 1127 | String_Append(fsrc, " + ");
|
1080 | | - String_Append(fsrc, arg2.c_str());
|
| 1128 | + String_Append(fsrc, arg2.ptr);
|
1081 | 1129 | String_Append(fsrc, " - .5;\n");
|
1082 | 1130 | break;
|
1083 | 1131 | case D3DTOP_ADDSIGNED2X:
|
1084 | 1132 | String_Append(fsrc, "color.a = (");
|
1085 | | - String_Append(fsrc, arg1.c_str());
|
| 1133 | + String_Append(fsrc, arg1.ptr);
|
1086 | 1134 | String_Append(fsrc, " + ");
|
1087 | | - String_Append(fsrc, arg2.c_str());
|
| 1135 | + String_Append(fsrc, arg2.ptr);
|
1088 | 1136 | String_Append(fsrc, " - .5) * 2.0;\n");
|
1089 | 1137 | break;
|
1090 | 1138 | case D3DTOP_SUBTRACT:
|
1091 | 1139 | String_Append(fsrc, "color.a = ");
|
1092 | | - String_Append(fsrc, arg1.c_str());
|
| 1140 | + String_Append(fsrc, arg1.ptr);
|
1093 | 1141 | String_Append(fsrc, " - ");
|
1094 | | - String_Append(fsrc, arg2.c_str());
|
| 1142 | + String_Append(fsrc, arg2.ptr);
|
1095 | 1143 | String_Append(fsrc, ";\n");
|
1096 | 1144 | break;
|
1097 | 1145 | case D3DTOP_ADDSMOOTH:
|
1098 | 1146 | String_Append(fsrc, "color.a = ");
|
1099 | | - String_Append(fsrc, arg1.c_str());
|
| 1147 | + String_Append(fsrc, arg1.ptr);
|
1100 | 1148 | String_Append(fsrc, " + ");
|
1101 | | - String_Append(fsrc, arg2.c_str());
|
| 1149 | + String_Append(fsrc, arg2.ptr);
|
1102 | 1150 | String_Append(fsrc, " - ");
|
1103 | | - String_Append(fsrc, arg1.c_str());
|
| 1151 | + String_Append(fsrc, arg1.ptr);
|
1104 | 1152 | String_Append(fsrc, " * ");
|
1105 | | - String_Append(fsrc, arg2.c_str());
|
| 1153 | + String_Append(fsrc, arg2.ptr);
|
1106 | 1154 | String_Append(fsrc, ";\n");
|
1107 | 1155 | break;
|
1108 | 1156 | case D3DTOP_BLENDDIFFUSEALPHA:
|
1109 | 1157 | String_Append(fsrc, "color.a = ");
|
1110 | | - String_Append(fsrc, arg1.c_str());
|
| 1158 | + String_Append(fsrc, arg1.ptr);
|
1111 | 1159 | String_Append(fsrc, " * gl_Color.a + ");
|
1112 | | - String_Append(fsrc, arg2.c_str());
|
| 1160 | + String_Append(fsrc, arg2.ptr);
|
1113 | 1161 | String_Append(fsrc, " * (1.0-gl_Color.a);\n");
|
1114 | 1162 | break;
|
1115 | 1163 | 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));
|
1119 | 1167 | String_Append(fsrc, "color.a = ");
|
1120 | | - String_Append(fsrc, arg1.c_str());
|
| 1168 | + String_Append(fsrc, arg1.ptr);
|
1121 | 1169 | String_Append(fsrc, " * ");
|
1122 | | - String_Append(fsrc, texarg.c_str());
|
| 1170 | + String_Append(fsrc, texarg.ptr);
|
1123 | 1171 | String_Append(fsrc, ".a + ");
|
1124 | | - String_Append(fsrc, arg2.c_str());
|
| 1172 | + String_Append(fsrc, arg2.ptr);
|
1125 | 1173 | String_Append(fsrc, " * (1.0-");
|
1126 | | - String_Append(fsrc, texarg.c_str());
|
| 1174 | + String_Append(fsrc, texarg.ptr);
|
1127 | 1175 | String_Append(fsrc, ".a);\n");
|
1128 | 1176 | break;
|
1129 | 1177 | case D3DTOP_BLENDFACTORALPHA:
|
1130 | 1178 | String_Append(fsrc, "color.a = ");
|
1131 | | - String_Append(fsrc, arg1.c_str());
|
| 1179 | + String_Append(fsrc, arg1.ptr);
|
1132 | 1180 | String_Append(fsrc, " * texfactor.a + ");
|
1133 | | - String_Append(fsrc, arg2.c_str());
|
| 1181 | + String_Append(fsrc, arg2.ptr);
|
1134 | 1182 | String_Append(fsrc, " * (1.0-texfactor.a);\n");
|
1135 | 1183 | break;
|
1136 | 1184 | 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));
|
1140 | 1188 | String_Append(fsrc, "color.a = ");
|
1141 | | - String_Append(fsrc, arg1.c_str());
|
| 1189 | + String_Append(fsrc, arg1.ptr);
|
1142 | 1190 | String_Append(fsrc, " + ");
|
1143 | | - String_Append(fsrc, arg2.c_str());
|
| 1191 | + String_Append(fsrc, arg2.ptr);
|
1144 | 1192 | String_Append(fsrc, " * (1.0-");
|
1145 | | - String_Append(fsrc, texarg.c_str());
|
| 1193 | + String_Append(fsrc, texarg.ptr);
|
1146 | 1194 | String_Append(fsrc, ".a);\n");
|
1147 | 1195 | break;
|
1148 | 1196 | case D3DTOP_BLENDCURRENTALPHA:
|
1149 | 1197 | String_Append(fsrc, "color.a = ");
|
1150 | | - String_Append(fsrc, arg1.c_str());
|
| 1198 | + String_Append(fsrc, arg1.ptr);
|
1151 | 1199 | String_Append(fsrc, " * color.a + ");
|
1152 | | - String_Append(fsrc, arg2.c_str());
|
| 1200 | + String_Append(fsrc, arg2.ptr);
|
1153 | 1201 | String_Append(fsrc, " * (1.0-color.a);\n");
|
1154 | 1202 | break;
|
1155 | 1203 | }
|
— | — | @@ -1205,6 +1253,10 @@ |
1206 | 1254 | if(((id>>61)&1) && !vertexfog && !pixelfog) String_Append(fsrc, op_fogassign);
|
1207 | 1255 | String_Append(fsrc, op_colorfragout);
|
1208 | 1256 | String_Append(fsrc, mainend);
|
| 1257 | + String_Free(&tmp);
|
| 1258 | + String_Free(&arg1);
|
| 1259 | + String_Free(&arg2);
|
| 1260 | + String_Free(&texarg);
|
1209 | 1261 | #ifdef _DEBUG
|
1210 | 1262 | OutputDebugStringA("Fragment shader:\n");
|
1211 | 1263 | OutputDebugStringA(fsrc->ptr);
|
— | — | @@ -1213,18 +1265,18 @@ |
1214 | 1266 | TRACE_STRING(fsrc->ptr);
|
1215 | 1267 | TRACE_STRING("\nCompiling fragment shader:\n");
|
1216 | 1268 | #endif
|
1217 | | - genshaders[index].shader.fs = ext->glCreateShader(GL_FRAGMENT_SHADER);
|
| 1269 | + This->genshaders[index].shader.fs = This->ext->glCreateShader(GL_FRAGMENT_SHADER);
|
1218 | 1270 | src = fsrc->ptr;
|
1219 | 1271 | 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);
|
1223 | 1275 | #ifdef _DEBUG
|
1224 | 1276 | if(!result)
|
1225 | 1277 | {
|
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);
|
1227 | 1279 | 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);
|
1229 | 1281 | OutputDebugStringA("Compilation failed. Error messages:\n");
|
1230 | 1282 | OutputDebugStringA(infolog);
|
1231 | 1283 | TRACE_STRING("Compilation failed. Error messages:\n");
|
— | — | @@ -1233,17 +1285,17 @@ |
1234 | 1286 | }
|
1235 | 1287 | OutputDebugStringA("\nLinking program:\n");
|
1236 | 1288 | #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);
|
1242 | 1294 | #ifdef _DEBUG
|
1243 | 1295 | if(!result)
|
1244 | 1296 | {
|
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);
|
1246 | 1298 | 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);
|
1248 | 1300 | OutputDebugStringA("Program link failed. Error messages:\n");
|
1249 | 1301 | OutputDebugStringA(infolog);
|
1250 | 1302 | TRACE_STRING("Program link failed. Error messages:\n");
|
— | — | @@ -1252,41 +1304,41 @@ |
1253 | 1305 | }
|
1254 | 1306 | #endif
|
1255 | 1307 | // 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");
|
1266 | 1318 | char attrS[] = "sX";
|
1267 | 1319 | for(int i = 0; i < 8; i++)
|
1268 | 1320 | {
|
1269 | 1321 | 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);
|
1271 | 1323 | }
|
1272 | 1324 | char attrST[] = "stX";
|
1273 | 1325 | for(int i = 0; i < 8; i++)
|
1274 | 1326 | {
|
1275 | 1327 | 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);
|
1277 | 1329 | }
|
1278 | 1330 | char attrSTR[] = "strX";
|
1279 | 1331 | for(int i = 0; i < 8; i++)
|
1280 | 1332 | {
|
1281 | 1333 | 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);
|
1283 | 1335 | }
|
1284 | 1336 | char attrSTRQ[] = "strqX";
|
1285 | 1337 | for(int i = 0; i < 8; i++)
|
1286 | 1338 | {
|
1287 | 1339 | 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);
|
1289 | 1341 | }
|
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");
|
1291 | 1343 | // Uniforms
|
1292 | 1344 | // TODO: 4-14 world1-3 and texture0-7
|
1293 | 1345 | char uniflight[] = "lightX. ";
|
— | — | @@ -1294,46 +1346,48 @@ |
1295 | 1347 | {
|
1296 | 1348 | uniflight[5] = i + '0';
|
1297 | 1349 | 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);
|
1299 | 1351 | 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);
|
1301 | 1353 | 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);
|
1303 | 1355 | 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);
|
1305 | 1357 | 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);
|
1307 | 1359 | 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);
|
1309 | 1361 | 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);
|
1311 | 1363 | 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);
|
1313 | 1365 | 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);
|
1315 | 1367 | 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);
|
1317 | 1369 | 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);
|
1319 | 1371 | 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);
|
1321 | 1373 | }
|
1322 | 1374 | char uniftex[] = "texX";
|
1323 | 1375 | for(int i = 0; i < 8; i++)
|
1324 | 1376 | {
|
1325 | 1377 | 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);
|
1327 | 1379 | }
|
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");
|
1334 | 1386 | char unifkey[] = "keyX";
|
1335 | 1387 | for(int i = 0; i < 8; i++)
|
1336 | 1388 | {
|
1337 | 1389 | 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);
|
1339 | 1391 | }
|
1340 | 1392 | }
|
| 1393 | +
|
| 1394 | +} |
\ No newline at end of file |
Index: ddraw/ShaderGen3D.h |
— | — | @@ -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
|
— | — | @@ -18,6 +18,10 @@ |
19 | 19 | #ifndef _SHADERGEN_H
|
20 | 20 | #define _SHADERGEN_H
|
21 | 21 |
|
| 22 | +#ifdef __cplusplus
|
| 23 | +extern "C" {
|
| 24 | +#endif
|
| 25 | +
|
22 | 26 | typedef struct
|
23 | 27 | {
|
24 | 28 | GLint vs;
|
— | — | @@ -42,19 +46,10 @@ |
43 | 47 |
|
44 | 48 | struct ShaderGen2D;
|
45 | 49 |
|
46 | | -class ShaderGen3D
|
| 50 | +typedef struct ShaderGen3D
|
47 | 51 | {
|
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);
|
56 | 52 | GenShader *genshaders;
|
57 | 53 | int current_genshader;
|
58 | | -private:
|
59 | 54 | __int64 current_shader;
|
60 | 55 | __int64 current_texid[8];
|
61 | 56 | int current_shadertype;
|
— | — | @@ -64,6 +59,18 @@ |
65 | 60 | GLuint current_prog;
|
66 | 61 | glExtensions *ext;
|
67 | 62 | ShaderManager *shaders;
|
68 | | -};
|
| 63 | +} ShaderGen3D;
|
69 | 64 |
|
| 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 | +
|
70 | 77 | #endif |
\ No newline at end of file |
Index: ddraw/ShaderManager.cpp |
— | — | @@ -17,10 +17,9 @@ |
18 | 18 |
|
19 | 19 | #include "common.h"
|
20 | 20 | #include "TextureManager.h"
|
| 21 | +#include "timer.h"
|
21 | 22 | #include "glUtil.h"
|
22 | | -#include "timer.h"
|
23 | 23 | #include "glRenderer.h"
|
24 | | -#include "glDirect3DDevice.h"
|
25 | 24 | #include "string.h"
|
26 | 25 | #include "ShaderManager.h"
|
27 | 26 | #include "ShaderGen3D.h"
|
— | — | @@ -170,7 +169,8 @@ |
171 | 170 | shaderman->shaders[i].pal = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"pal");
|
172 | 171 | shaderman->shaders[i].view = shaderman->ext->glGetUniformLocation(shaderman->shaders[i].prog,"view");
|
173 | 172 | }
|
174 | | - shaderman->gen3d = new ShaderGen3D(shaderman->ext, shaderman);
|
| 173 | + shaderman->gen3d = (ShaderGen3D*)malloc(sizeof(ShaderGen3D));
|
| 174 | + ShaderGen3D_Init(shaderman->ext, shaderman, shaderman->gen3d);
|
175 | 175 | shaderman->gen2d = (ShaderGen2D*)malloc(sizeof(ShaderGen2D));
|
176 | 176 | ZeroMemory(shaderman->gen2d, sizeof(ShaderGen2D));
|
177 | 177 | ShaderGen2D_Init(shaderman->gen2d, shaderman->ext, shaderman);
|
— | — | @@ -200,12 +200,13 @@ |
201 | 201 | free(This->shaders);
|
202 | 202 | ShaderGen2D_Delete(This->gen2d);
|
203 | 203 | free(This->gen2d);
|
204 | | - delete This->gen3d;
|
| 204 | + ShaderGen3D_Delete(This->gen3d);
|
| 205 | + free(This->gen3d);
|
205 | 206 | }
|
206 | 207 |
|
207 | 208 | void ShaderManager_SetShader(ShaderManager *This, __int64 id, TEXTURESTAGE *texstate, int *texcoords, int type)
|
208 | 209 | {
|
209 | | - This->gen3d->SetShader(id, texstate, texcoords, type, This->gen2d);
|
| 210 | + ShaderGen3D_SetShader(This->gen3d, id, texstate, texcoords, type, This->gen2d);
|
210 | 211 | }
|
211 | 212 |
|
212 | 213 | } |
\ No newline at end of file |
Index: ddraw/ShaderManager.h |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | #define PROG_CLIPSTENCIL 5
|
51 | 51 |
|
52 | 52 | struct TEXTURESTAGE;
|
53 | | -class ShaderGen3D;
|
| 53 | +struct ShaderGen3D;
|
54 | 54 |
|
55 | 55 | typedef struct ShaderManager
|
56 | 56 | {
|