DXGL r333 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r332‎ | r333 | r334 >
Date:03:20, 24 February 2013
Author:admin
Status:new
Tags:
Comment:
Fix D3DTLVERTEX x/y position calculation.
Handle case where D3D1 viewport minZ and maxZ are both zero.
Modified paths:
  • /ddraw/glDirect3DViewport.cpp (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DViewport.cpp
@@ -293,6 +293,7 @@
294294 vp.dvClipWidth = viewport.dvClipWidth;
295295 vp.dvClipX = viewport.dvClipX;
296296 vp.dvClipY = viewport.dvClipY;
 297+ if((vp.dvMinZ == 0) && (vp.dvMaxZ == 0)) vp.dvMaxZ = 1.0f;
297298 viewport = vp;
298299 maxX = lpData->dvMaxX;
299300 maxY = lpData->dvMaxY;
Index: ddraw/glRenderer.cpp
@@ -1553,18 +1553,20 @@
15541554 }
15551555 else SetTexture(i,0);
15561556 glUniform1i(prog.uniforms[128+i],i);
1557 - if(device->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && device->texstages[i].texture && (prog.uniforms[140+i] != -1))
 1557+ if(device->renderstate[D3DRENDERSTATE_COLORKEYENABLE] && device->texstages[i].texture && (prog.uniforms[142+i] != -1))
15581558 {
15591559 if(device->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
15601560 {
15611561 dwordto4int(device->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,keycolor);
1562 - glUniform4iv(prog.uniforms[140+i],1,keycolor);
 1562+ glUniform4iv(prog.uniforms[142+i],1,keycolor);
15631563 }
15641564 }
15651565 }
1566 - if(prog.uniforms[137]!= -1) glUniform1f(prog.uniforms[137],device->glDDS7->fakex);
1567 - if(prog.uniforms[138]!= -1) glUniform1f(prog.uniforms[138],device->glDDS7->fakey);
1568 - if(prog.uniforms[139]!= -1) glUniform1i(prog.uniforms[139],device->renderstate[D3DRENDERSTATE_ALPHAREF]);
 1566+ if(prog.uniforms[137]!= -1) glUniform1f(prog.uniforms[137],device->viewport.dwWidth);
 1567+ if(prog.uniforms[138]!= -1) glUniform1f(prog.uniforms[138],device->viewport.dwHeight);
 1568+ if(prog.uniforms[139]!= -1) glUniform1f(prog.uniforms[139],device->viewport.dwX);
 1569+ if(prog.uniforms[140]!= -1) glUniform1f(prog.uniforms[140],device->viewport.dwY);
 1570+ if(prog.uniforms[141]!= -1) glUniform1i(prog.uniforms[141],device->renderstate[D3DRENDERSTATE_ALPHAREF]);
15691571 if(device->glDDS7->zbuffer) SetFBO(device->glDDS7->texture,device->glDDS7->zbuffer->texture,device->glDDS7->zbuffer->hasstencil);
15701572 else SetFBO(device->glDDS7->texture,0,false);
15711573 SetViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
Index: ddraw/shadergen.cpp
@@ -260,8 +260,10 @@
261261 static const char unif_light[] = "uniform Light lightX;\n";
262262 static const char unif_ambient[] = "uniform vec4 ambientcolor;\n";
263263 static const char unif_tex[] = "uniform sampler2D texX;\n";
264 -static const char unif_size[] = "uniform float width;\n\
265 -uniform float height;\n";
 264+static const char unif_viewport[] = "uniform float width;\n\
 265+uniform float height;\n\
 266+uniform float xoffset;\n\
 267+uniform float yoffset;\n";
266268 static const char unif_alpharef[] = "uniform int alpharef;\n";
267269 static const char unif_key[] = "uniform ivec4 keyX;\n";
268270 static const char unif_world[] = "uniform mat4 matWorld;\n";
@@ -280,7 +282,7 @@
281283 gl_Position = vec4(pos.x,-pos.y,pos.z,pos.w);\n";
282284 static const char op_normalize[] = "N = normalize(gl_NormalMatrix*nxyz);\n";
283285 static const char op_normalpassthru[] = "N = gl_NormalMatrix*nxyz;\n";
284 -static const char op_passthru[] = "gl_Position = vec4(((xyz.x+.5)/(width/2.0))-1.0,((xyz.y+.5)/(height/2.0))-1.0,(xyz.z),1.0);\n";
 286+static const char op_tlvertex[] = "gl_Position = vec4((((xyz.x-xoffset)+.5)/(width/2.0))-1.0,(((xyz.y-yoffset)+.5)/(height/2.0))-1.0,(xyz.z),1.0);\n";
285287 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
286288 ambient = ambientcolor / 255.0;\n";
287289 static const char op_dirlight[] = "DirLight(lightX);\n";
@@ -473,7 +475,7 @@
474476
475477 // Uniforms
476478 vsrc->append(unif_ambient);
477 - if((id>>50)&1) vsrc->append(unif_size);
 479+ if((id>>50)&1) vsrc->append(unif_viewport);
478480 if((id>>59)&1) numlights = (id>>18)&7;
479481 else numlights = 0;
480482 if((id>>50)&1) numlights = 0;
@@ -513,7 +515,7 @@
514516 if(hasdir) vsrc->append(func_dirlight);
515517 //Main
516518 vsrc->append(mainstart);
517 - if((id>>50)&1) vsrc->append(op_passthru);
 519+ if((id>>50)&1) vsrc->append(op_tlvertex);
518520 else vsrc->append(op_transform);
519521 if((id>>49)&1) vsrc->append(op_normalize);
520522 else vsrc->append(op_normalpassthru);
@@ -1138,11 +1140,13 @@
11391141 genshaders[index].shader.uniforms[136] = glGetUniformLocation(genshaders[index].shader.prog,"ambientcolor");
11401142 genshaders[index].shader.uniforms[137] = glGetUniformLocation(genshaders[index].shader.prog,"width");
11411143 genshaders[index].shader.uniforms[138] = glGetUniformLocation(genshaders[index].shader.prog,"height");
1142 - genshaders[index].shader.uniforms[139] = glGetUniformLocation(genshaders[index].shader.prog,"alpharef");
 1144+ genshaders[index].shader.uniforms[139] = glGetUniformLocation(genshaders[index].shader.prog,"xoffset");
 1145+ genshaders[index].shader.uniforms[140] = glGetUniformLocation(genshaders[index].shader.prog,"yoffset");
 1146+ genshaders[index].shader.uniforms[141] = glGetUniformLocation(genshaders[index].shader.prog,"alpharef");
11431147 char unifkey[] = "keyX";
11441148 for(int i = 0; i < 8; i++)
11451149 {
11461150 unifkey[3] = i + '0';
1147 - genshaders[index].shader.uniforms[140+i] = glGetUniformLocation(genshaders[index].shader.prog,unifkey);
 1151+ genshaders[index].shader.uniforms[142+i] = glGetUniformLocation(genshaders[index].shader.prog,unifkey);
11481152 }
11491153 }