DXGL r522 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r521‎ | r522 | r523 >
Date:14:12, 7 September 2014
Author:admin
Status:new
Tags:
Comment:
Add colorkey to D3D2 texture load.
Ignore alpha channel in D3D colorkey.
Partially fix rendering T&L vertices.
Modified paths:
  • /ddraw/ShaderGen3D.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glExtensions.c (modified) (history)
  • /ddraw/glExtensions.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)

Diff [purge]

Index: ddraw/ShaderGen3D.cpp
@@ -316,7 +316,7 @@
317317 uniform float xoffset;\n\
318318 uniform float yoffset;\n";
319319 static const char unif_alpharef[] = "uniform int alpharef;\n";
320 -static const char unif_key[] = "uniform ivec4 keyX;\n";
 320+static const char unif_key[] = "uniform ivec3 keyX;\n";
321321 static const char unif_world[] = "uniform mat4 matWorld;\n";
322322 // Variables
323323 static const char var_common[] = "vec4 diffuse;\n\
@@ -333,7 +333,9 @@
334334 gl_Position = vec4(pos.x,-pos.y,pos.z,pos.w);\n";
335335 static const char op_normalize[] = "N = normalize(gl_NormalMatrix*nxyz);\n";
336336 static const char op_normalpassthru[] = "N = gl_NormalMatrix*nxyz;\n";
337 -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";
 337+static const char op_tlvertex[] = "xyzw = vec4(xyz.x/rhw,xyz.y/rhw,xyz.z/rhw,1.0/rhw);\n\
 338+vec4 pos = gl_ModelViewProjectionMatrix*xyzw;\n\
 339+gl_Position = vec4(pos.x,-pos.y,pos.z,pos.w);\n";
338340 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
339341 ambient = ambientcolor / 255.0;\n";
340342 static const char op_dirlight[] = "DirLight(lightX);\n";
@@ -347,7 +349,7 @@
348350 static const char op_colorwhite[] = "gl_FrontColor = vec4(1.0,1.0,1.0,1.0);\n";
349351 static const char op_colorfragout[] = "gl_FragColor = color;\n";
350352 static const char op_colorfragin[] = "color = gl_Color;\n";
351 -static const char op_colorkey[] = "if(ivec4(texture2DProj(texX,gl_TexCoord[Y])*255.5) == keyZ) discard;\n";
 353+static const char op_colorkey[] = "if(ivec3(texture2DProj(texX,gl_TexCoord[Y])*255.5).rgb == keyZ) discard;\n";
352354 static const char op_texpassthru1[] = "gl_TexCoord[x] = ";
353355 static const char op_texpassthru2s[] = "vec4(sX,0,0,1);\n";
354356 static const char op_texpassthru2st[] = "vec4(stX,0,1);\n";
@@ -547,7 +549,7 @@
548550
549551 // Variables
550552 String_Append(vsrc, var_common);
551 - if(!((id>>50)&1)) String_Append(vsrc, var_xyzw);
 553+ String_Append(vsrc, var_xyzw);
552554 if(vertexfog && !pixelfog) String_Append(vsrc, var_fogfactorvertex);
553555
554556 // Functions
@@ -794,7 +796,7 @@
795797 String_Assign(&arg1, op_colorkey);
796798 arg1.ptr[26] = *(_itoa(i,idstring,10));
797799 arg1.ptr[40] = *(_itoa((texstate[i].shaderid>>54)&7,idstring,10));
798 - arg1.ptr[57] = *(_itoa(i,idstring,10));
 800+ arg1.ptr[61] = *(_itoa(i,idstring,10));
799801 String_Append(fsrc, arg1.ptr);
800802 }
801803 }
Index: ddraw/glDirectDrawSurface.cpp
@@ -1715,7 +1715,10 @@
17161716 TRACE_ENTER(2,14,this,14,src);
17171717 if(!this) TRACE_RET(HRESULT,23,DDERR_INVALIDOBJECT);
17181718 if(!src) TRACE_RET(HRESULT,23,DDERR_INVALIDPARAMS);
 1719+ if (src == this) TRACE_RET(HRESULT, 23, DD_OK);
17191720 this->Blt(NULL,src,NULL,DDBLT_WAIT,NULL);
 1721+ if (src->ddsd.dwFlags & DDSD_CKSRCBLT)
 1722+ this->SetColorKey(DDCKEY_SRCBLT, &src->colorkey[0].key);
17201723 ddsd.ddsCaps.dwCaps &= ~DDSCAPS_ALLOCONLOAD;
17211724 TRACE_EXIT(23,D3D_OK);
17221725 return D3D_OK;
Index: ddraw/glExtensions.c
@@ -66,6 +66,7 @@
6767 ext->glUniform2i = (PFNGLUNIFORM2IPROC)wglGetProcAddress("glUniform2i");
6868 ext->glUniform3i = (PFNGLUNIFORM3IPROC)wglGetProcAddress("glUniform3i");
6969 ext->glUniform4i = (PFNGLUNIFORM4IPROC)wglGetProcAddress("glUniform4i");
 70+ ext->glUniform3iv = (PFNGLUNIFORM3IVPROC)wglGetProcAddress("glUniform3iv");
7071 ext->glUniform4iv = (PFNGLUNIFORM4IVPROC)wglGetProcAddress("glUniform4iv");
7172 ext->glUniform1f = (PFNGLUNIFORM1FPROC)wglGetProcAddress("glUniform1f");
7273 ext->glUniform2f = (PFNGLUNIFORM2FPROC)wglGetProcAddress("glUniform2f");
Index: ddraw/glExtensions.h
@@ -77,6 +77,7 @@
7878 void (APIENTRY *glUniform2i) (GLint location, GLint v0, GLint v1);
7979 void (APIENTRY *glUniform3i) (GLint location, GLint v0, GLint v1, GLint v2);
8080 void (APIENTRY *glUniform4i) (GLint location, GLint v0, GLint v1, GLint v2, GLint v3);
 81+ void (APIENTRY *glUniform3iv) (GLint location, GLsizei count, const GLint* value);
8182 void (APIENTRY *glUniform4iv) (GLint location, GLsizei count, const GLint* value);
8283 void (APIENTRY *glUniform1f) (GLint location, GLfloat v0);
8384 void (APIENTRY *glUniform2f) (GLint location, GLfloat v0, GLfloat v1);
Index: ddraw/glRenderer.cpp
@@ -1846,6 +1846,14 @@
18471847 This->util->EnableArray(prog.attribs[1],true);
18481848 This->ext->glVertexAttribPointer(prog.attribs[1],4,GL_FLOAT,false,vertices[1].stride,vertices[1].data);
18491849 }
 1850+ device->modelview_dirty = true;
 1851+ device->projection_dirty = true;
 1852+ glMatrixMode(GL_MODELVIEW);
 1853+ glLoadIdentity();
 1854+ glMatrixMode(GL_PROJECTION);
 1855+ glLoadIdentity();
 1856+ glOrtho(0.0, device->viewport.dwWidth, device->viewport.dwHeight, 0.0,
 1857+ -device->viewport.dvMinZ, device->viewport.dvMaxZ);
18501858 }
18511859 for(i = 0; i < 5; i++)
18521860 {
@@ -1916,8 +1924,11 @@
19171925
19181926 }
19191927 }
1920 - if(device->modelview_dirty) This->util->SetMatrix(GL_MODELVIEW,device->matView,device->matWorld,&device->modelview_dirty);
1921 - if(device->projection_dirty) This->util->SetMatrix(GL_PROJECTION,device->matProjection,NULL,&device->projection_dirty);
 1928+ if (!transformed)
 1929+ {
 1930+ if (device->modelview_dirty) This->util->SetMatrix(GL_MODELVIEW, device->matView, device->matWorld, &device->modelview_dirty);
 1931+ if (device->projection_dirty) This->util->SetMatrix(GL_PROJECTION, device->matProjection, NULL, &device->projection_dirty);
 1932+ }
19221933
19231934 This->util->SetMaterial((GLfloat*)&device->material.ambient,(GLfloat*)&device->material.diffuse,(GLfloat*)&device->material.specular,
19241935 (GLfloat*)&device->material.emissive,device->material.power);
@@ -1993,7 +2004,7 @@
19942005 if(device->texstages[i].texture->ddsd.dwFlags & DDSD_CKSRCBLT)
19952006 {
19962007 dwordto4int(device->texstages[i].texture->colorkey[0].key.dwColorSpaceLowValue,keycolor);
1997 - This->ext->glUniform4iv(prog.uniforms[142+i],1,keycolor);
 2008+ This->ext->glUniform3iv(prog.uniforms[142+i],1,keycolor);
19982009 }
19992010 }
20002011 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r582Revert D3DTLVERTEX processing from r522....admin02:10, 8 January 2015