DXGL r130 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r129‎ | r130 | r131 >
Date:20:28, 17 March 2012
Author:admin
Status:new
Tags:
Comment:
Fix render buffer DDraw interaction
Fix upside down rendering. Breaks lighting.
Modified paths:
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/matrix.cpp (modified) (history)
  • /ddraw/matrix.h (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glRenderer.cpp
@@ -1001,6 +1001,8 @@
10021002 glClearStencil(dwStencil);
10031003 }
10041004 glClear(clearbits);
 1005+ if(target->zbuffer) target->zbuffer->dirty |= 2;
 1006+ target->dirty |= 2;
10051007 }
10061008
10071009 void glRenderer::_Flush()
@@ -1012,7 +1014,6 @@
10131015 void glRenderer::_DrawPrimitives(glDirect3DDevice7 *device, GLenum mode, GLVERTEX *vertices, int *texformats, DWORD count, LPWORD indices,
10141016 DWORD indexcount, DWORD flags)
10151017 {
1016 - GLfloat tmpmat[16];
10171018 bool transformed;
10181019 char blendvar[] = "blendX";
10191020 char rgbavar[] = "rgbaX";
@@ -1021,8 +1022,8 @@
10221023 char strvar[] = "strX";
10231024 char strqvar[] = "strqX";
10241025 int i;
1025 - if(vertices[1].data) transformed = false;
1026 - else transformed = true;
 1026+ if(vertices[1].data) transformed = true;
 1027+ else transformed = false;
10271028 if(!vertices[0].data)
10281029 {
10291030 outputs[0] = (void*)DDERR_INVALIDPARAMS;
@@ -1082,14 +1083,11 @@
10831084 }
10841085 if(device->normal_dirty) device->UpdateNormalMatrix();
10851086 GLint loc = glGetUniformLocation(prog,"world");
1086 - viewLHtoRH(tmpmat,device->matWorld);
1087 - glUniformMatrix4fv(loc,1,false,tmpmat);
 1087+ glUniformMatrix4fv(loc,1,false,device->matWorld);
10881088 loc = glGetUniformLocation(prog,"view");
1089 - viewLHtoRH(tmpmat,device->matView);
1090 - glUniformMatrix4fv(loc,1,false,tmpmat);
 1089+ glUniformMatrix4fv(loc,1,false,device->matView);
10911090 loc = glGetUniformLocation(prog,"projection");
1092 - prjLHtoRH(tmpmat,device->matProjection);
1093 - glUniformMatrix4fv(loc,1,false,tmpmat);
 1091+ glUniformMatrix4fv(loc,1,false,device->matProjection);
10941092 loc = glGetUniformLocation(prog,"normalmat");
10951093 glUniformMatrix4fv(loc,1,true,device->matNormal);
10961094 loc = glGetUniformLocation(prog,"material.diffuse");
@@ -1159,6 +1157,8 @@
11601158 glViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
11611159 if(indices) glDrawRangeElements(mode,0,indexcount,count,GL_UNSIGNED_SHORT,indices);
11621160 else glDrawArrays(mode,0,count);
 1161+ if(device->glDDS7->zbuffer) device->glDDS7->zbuffer->dirty |= 2;
 1162+ device->glDDS7->dirty |= 2;
11631163 if(flags & D3DDP_WAIT) glFlush();
11641164 outputs[0] = (void*)D3D_OK;
11651165 wndbusy = false;
Index: ddraw/matrix.cpp
@@ -46,30 +46,6 @@
4747 * other dealings in this Software without prior written authorization from
4848 * Silicon Graphics, Inc.
4949 */
50 -// Portions of this file are from the dxglwrap project, and are licensed under
51 -// the following terms:
52 -/*
53 - *
54 - * dxglwrapper 0.08 - Sept. 12, 2002
55 - * For conditions of distribution and use, see copyright notice in d3dprj.h
56 - * Copyright (c) 1991-2002 realtech VR
57 - *
58 - * Copyright (c) 2002 realtech VR
59 - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
60 - * and associated documentation files (the "Software"), to deal in the Software without
61 - * restriction, including without limitation the rights to use, copy, modify, merge, publish,
62 - * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
63 - * Software is furnished to do so, subject to the following conditions:
64 - * The above copyright notice and this permission notice shall be included in all copies or
65 - * substantial portions of the Software.
66 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
67 - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
68 - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
69 - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
70 - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
71 - * DEALINGS IN THE SOFTWARE.
72 - *
73 - */
7450 #include "common.h"
7551 #include "matrix.h"
7652
@@ -151,40 +127,4 @@
152128 m[1+4*0] = 0; m[1+4*1] = 1; m[1+4*2] = 0; m[1+4*3] = 0;
153129 m[2+4*0] = 0; m[2+4*1] = 0; m[2+4*2] = 1; m[2+4*3] = 0;
154130 m[3+4*0] = 0; m[3+4*1] = 0; m[3+4*2] = 0; m[3+4*3] = 1;
155 -}
156 -
157 -
158 -// from dxglwrap:
159 -/*
160 -
161 - This is one basic difference between OpenGL and Direct3D.
162 - In both coordinate systems, the X and Y axis are as normal.
163 - The Y positive axis going upwards and the X positive axis going to the right.
164 -
165 - However, the two systems differ in their Z-axis implementation.
166 - A Left-Handed System, which Direct3D uses, is one where the Z-axis is positive INTO the screen.
167 - Take your Left Hand, face the palm upwards with your fingers pointing in the direction of the positive x-axis (to the right), and curl your fingers in the direction of the Y-positive axis (up). Now if you stick your thumb STRAIGHT (like you were giving a sideways "thumbs-up" sign), your thumb is now pointing in the direction of the positive Z-axis.
168 -
169 - OpenGL, on the other hand, uses a Right-Handed system, where the positive Z-axis is coming OUT of the screen.
170 - Again, to remember this, take your right hand, point your palm upwards and your fingers pointing in the direction of the positive x-axis
171 - (to the right). Now curl your fingers up to the direction of the positive y-axis (up), and point your thumb out. It is now pointing in the direction of the positive Z-axis (out)..
172 -
173 - Note: no doc exists how to do the conversion
174 -*/
175 -
176 -
177 -void prjLHtoRH(float *d, const float *s) // Exclusive function
178 -{
179 - d[0] = -s[0]; d[1] = -s[1]; d[2] = -s[2]; d[3] = -s[3];
180 - d[4] = s[4]; d[5] = s[5]; d[6] = s[6]; d[7] = s[7];
181 - d[8] = -s[8]; d[9] = -s[9]; d[10] = -s[10]; d[11] = -s[11];
182 - d[12] = s[12]; d[13] = s[13]; d[14] = s[14]; d[15] = s[15];
183 -}
184 -
185 -void viewLHtoRH(float *d, const float *s)
186 -{
187 - d[0] = -s[0]; d[1] = s[1]; d[2] = -s[2]; d[3] = s[3];
188 - d[4] = -s[4]; d[5] = s[5]; d[6] = -s[6]; d[7] = s[7];
189 - d[8] = -s[8]; d[9] = s[9]; d[10] = -s[10]; d[11] = s[11];
190 - d[12] = -s[12]; d[13] = s[13]; d[14] = -s[14]; d[15] = s[15];
191 -}
 131+}
\ No newline at end of file
Index: ddraw/matrix.h
@@ -46,30 +46,6 @@
4747 * other dealings in this Software without prior written authorization from
4848 * Silicon Graphics, Inc.
4949 */
50 -// Portions of this file are from the dxglwrap project, and are licensed under
51 -// the following terms:
52 -/*
53 - *
54 - * dxglwrapper 0.08 - Sept. 12, 2002
55 - * For conditions of distribution and use, see copyright notice in d3dprj.h
56 - * Copyright (c) 1991-2002 realtech VR
57 - *
58 - * Copyright (c) 2002 realtech VR
59 - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
60 - * and associated documentation files (the "Software"), to deal in the Software without
61 - * restriction, including without limitation the rights to use, copy, modify, merge, publish,
62 - * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
63 - * Software is furnished to do so, subject to the following conditions:
64 - * The above copyright notice and this permission notice shall be included in all copies or
65 - * substantial portions of the Software.
66 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
67 - * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
68 - * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
69 - * FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
70 - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
71 - * DEALINGS IN THE SOFTWARE.
72 - *
73 - */
7450 #pragma once
7551 #ifndef _MATRIX_H
7652 #define _MATRIX_H
@@ -79,7 +55,4 @@
8056 GLfloat r[16]);
8157 void __gluMakeIdentityf(GLfloat m[16]);
8258
83 -void prjLHtoRH(float *d, const float *s);
84 -void viewLHtoRH(float *d, const float *s);
85 -
8659 #endif //_MATRIX_H
\ No newline at end of file
Index: ddraw/shadergen.cpp
@@ -251,7 +251,8 @@
252252 static const char var_xyzw[] = "vec4 xyzw;\n";
253253 // Operations
254254 static const char op_transform[] = "xyzw = vec4(xyz,1);\n\
255 -gl_Position = (projection*(view*world))*xyzw;\n";
 255+vec4 pos = (projection*(view*world))*xyzw;\n\
 256+gl_Position = vec4(pos.x,-pos.y,pos.z,pos.w);\n";
256257 static const char op_passthru[] = "gl_Position = xyzw;\n";
257258 static const char op_resetcolor[] = "diffuse = specular = vec4(0.0);\n\
258259 ambient = ambientcolor / 255.0;\n";