DXGL r106 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r105‎ | r106 | r107 >
Date:01:04, 23 February 2012
Author:admin
Status:new
Tags:
Comment:
Almost have DrawIndexedPrimitive working.
Fix for ATI fix (eliminate errors on NVIDIA GPUs)
Modified paths:
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /dxgltest/Tests3D.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.h
@@ -97,10 +97,10 @@
9898 D3DVIEWPORT7 viewport;
9999 glDirect3DLight **lights;
100100 int gllights[8];
 101+ glDirectDrawSurface7 *glDDS7;
101102
102103 private:
103104 glDirect3D7 *glD3D7;
104 - glDirectDrawSurface7 *glDDS7;
105105 ULONG refcount;
106106 DWORD renderstate[153];
107107 GLuint gltextures[8];
Index: ddraw/glDirectDrawSurface.h
@@ -128,6 +128,7 @@
129129 DDSURFACEDESC2 ddsd;
130130 glDirectDrawPalette *palette;
131131 HGLRC hRC;
 132+ glDirectDrawSurface7 *zbuffer;
132133 private:
133134 ULONG refcount;
134135 int locked;
@@ -137,7 +138,6 @@
138139 glDirectDraw7 *ddInterface;
139140 int surfacetype; // 0-generic memory, 1-GDI surface, 2-OpenGL Texture
140141 glDirectDrawSurface7 *backbuffer;
141 - glDirectDrawSurface7 *zbuffer;
142142 glDirectDrawClipper *clipper;
143143 int pagelocked;
144144 GLint filter;
Index: ddraw/glRenderer.cpp
@@ -735,8 +735,11 @@
736736 glEnableVertexAttribArray(xyloc);
737737 glVertexAttribPointer(xyloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].x);
738738 GLint rgbloc = glGetAttribLocation(prog,"rgb");
739 - glEnableVertexAttribArray(rgbloc);
740 - glVertexAttribPointer(rgbloc,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
 739+ if(rgbloc != -1)
 740+ {
 741+ glEnableVertexAttribArray(rgbloc);
 742+ glVertexAttribPointer(rgbloc,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
 743+ }
741744 if(!(dwFlags & DDBLT_COLORFILL))
742745 {
743746 GLint stloc = glGetAttribLocation(prog,"st");
@@ -928,8 +931,11 @@
929932 glEnableVertexAttribArray(stloc);
930933 glVertexAttribPointer(stloc,2,GL_FLOAT,false,sizeof(BltVertex),&bltvertices[0].s);
931934 GLint rgbloc = glGetAttribLocation(prog,"rgb");
932 - glEnableVertexAttribArray(rgbloc);
933 - glVertexAttribPointer(rgbloc,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
 935+ if(rgbloc != -1)
 936+ {
 937+ glEnableVertexAttribArray(rgbloc);
 938+ glVertexAttribPointer(rgbloc,3,GL_UNSIGNED_BYTE,true,sizeof(BltVertex),&bltvertices[0].r);
 939+ }
934940 glDrawRangeElements(GL_TRIANGLE_STRIP,0,3,4,GL_UNSIGNED_SHORT,bltindices);
935941 glDisable(GL_TEXTURE_2D);
936942 glFlush();
@@ -1092,8 +1098,31 @@
10931099 colorptr[1] = ptr;
10941100 ptr++;
10951101 }
 1102+ int numtex = (dwVertexTypeDesc&D3DFVF_TEXCOUNT_MASK)>>D3DFVF_TEXCOUNT_SHIFT;
 1103+ for(i = 0; i < numtex; i++)
 1104+ {
 1105+ texptr[0] = ptr;
 1106+ switch(dwVertexTypeDesc>>(16+(2*i))&3)
 1107+ {
 1108+ case 0: // st
 1109+ ptr += 2;
 1110+ break;
 1111+ case 1: // str
 1112+ ptr += 3;
 1113+ break;
 1114+ case 2: // strq
 1115+ ptr += 4;
 1116+ break;
 1117+ case 3: // s
 1118+ ptr++;
 1119+ break;
 1120+ }
 1121+ }
10961122 int stride = NextMultipleOf8(ptr*4);
1097 - SetShader(device->SelectShader(dwVertexTypeDesc),NULL,0);
 1123+ TexState texstage;
 1124+ ZeroMemory(&texstage,sizeof(TexState));
 1125+ __int64 shader = device->SelectShader(dwVertexTypeDesc);
 1126+ SetShader(shader,&texstage,0);
10981127 GLuint prog = GetProgram();
10991128 if(transformed)
11001129 {
@@ -1139,19 +1168,19 @@
11401169 loc = glGetUniformLocation(prog,"view");
11411170 glUniformMatrix4fv(loc,1,false,device->matView);
11421171 loc = glGetUniformLocation(prog,"projection");
1143 - glUniformMatrix4fv(loc,1,false,device->matProjection);
 1172+ glUniformMatrix4fv(loc,1,true,device->matProjection);
11441173 loc = glGetUniformLocation(prog,"normalmat");
11451174 glUniformMatrix4fv(loc,1,true,device->matNormal);
11461175 loc = glGetUniformLocation(prog,"material.diffuse");
1147 - glUniform4fv(prog,4,(GLfloat*)&device->material.diffuse);
 1176+ glUniform4fv(loc,1,(GLfloat*)&device->material.diffuse);
11481177 loc = glGetUniformLocation(prog,"material.ambient");
1149 - glUniform4fv(prog,4,(GLfloat*)&device->material.ambient);
 1178+ glUniform4fv(loc,1,(GLfloat*)&device->material.ambient);
11501179 loc = glGetUniformLocation(prog,"material.specular");
1151 - glUniform4fv(prog,4,(GLfloat*)&device->material.specular);
 1180+ glUniform4fv(loc,1,(GLfloat*)&device->material.specular);
11521181 loc = glGetUniformLocation(prog,"material.emissive");
1153 - glUniform4fv(prog,4,(GLfloat*)&device->material.emissive);
 1182+ glUniform4fv(loc,1,(GLfloat*)&device->material.emissive);
11541183 loc = glGetUniformLocation(prog,"material.power");
1155 - glUniform1f(prog,device->material.power);
 1184+ glUniform1f(loc,device->material.power);
11561185 int lightindex = 0;
11571186 char lightname[] = "lightX.xxxxxxxxxxxxxxxx";
11581187 for(i = 0; i < 8; i++)
@@ -1159,21 +1188,52 @@
11601189 if(device->gllights[i] != -1)
11611190 {
11621191 lightname[5] = lightindex+'0';
1163 - memcpy((void*)(lightindex+7),"diffuse",8);
 1192+ memcpy((void*)(lightname+7),"diffuse",8);
11641193 loc = glGetUniformLocation(prog,lightname);
1165 - glUniform4fv(prog,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvDiffuse);
1166 - memcpy((void*)(lightindex+7),"specular",9);
 1194+ glUniform4fv(loc,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvDiffuse);
 1195+ memcpy((void*)(lightname+7),"specular",9);
11671196 loc = glGetUniformLocation(prog,lightname);
1168 - glUniform4fv(prog,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvSpecular);
1169 - memcpy((void*)(lightindex+7),"ambient",8);
 1197+ glUniform4fv(loc,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvSpecular);
 1198+ memcpy((void*)(lightname+7),"ambient",8);
11701199 loc = glGetUniformLocation(prog,lightname);
1171 - glUniform4fv(prog,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvAmbient);
 1200+ glUniform4fv(loc,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dcvAmbient);
 1201+ memcpy((void*)(lightname+7),"direction",10);
 1202+ loc = glGetUniformLocation(prog,lightname);
 1203+ glUniform3fv(loc,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dvDirection);
 1204+ if(device->lights[device->gllights[i]]->light.dltType != D3DLIGHT_DIRECTIONAL)
 1205+ {
 1206+ memcpy((void*)(lightname+7),"position",9);
 1207+ loc = glGetUniformLocation(prog,lightname);
 1208+ glUniform3fv(loc,1,(GLfloat*)&device->lights[device->gllights[i]]->light.dvPosition);
 1209+ memcpy((void*)(lightname+7),"range",6);
 1210+ loc = glGetUniformLocation(prog,lightname);
 1211+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvRange);
 1212+ memcpy((void*)(lightname+7),"falloff",8);
 1213+ loc = glGetUniformLocation(prog,lightname);
 1214+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvFalloff);
 1215+ memcpy((void*)(lightname+7),"constant",9);
 1216+ loc = glGetUniformLocation(prog,lightname);
 1217+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvAttenuation0);
 1218+ memcpy((void*)(lightname+7),"linear",7);
 1219+ loc = glGetUniformLocation(prog,lightname);
 1220+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvAttenuation1);
 1221+ memcpy((void*)(lightname+7),"quad",5);
 1222+ loc = glGetUniformLocation(prog,lightname);
 1223+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvAttenuation2);
 1224+ memcpy((void*)(lightname+7),"theta",6);
 1225+ loc = glGetUniformLocation(prog,lightname);
 1226+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvTheta);
 1227+ memcpy((void*)(lightname+7),"Phi",4);
 1228+ loc = glGetUniformLocation(prog,lightname);
 1229+ glUniform1f(loc,device->lights[device->gllights[i]]->light.dvPhi);
 1230+ }
11721231 }
11731232 }
1174 - // Uniforms
1175 - // struct Light vec3 position,direction float range,falloff,constant,linear,quad,theta,pi uniform lightX
1176 - FIXME("glDirect3DDevice::DrawIndexedPrimitive: stub");
1177 - outputs[0] = (void*)DDERR_GENERIC;
 1233+ SetFBO(device->glDDS7->texture,device->glDDS7->zbuffer->texture,device->glDDS7->zbuffer->hasstencil);
 1234+ glViewport(device->viewport.dwX,device->viewport.dwY,device->viewport.dwWidth,device->viewport.dwHeight);
 1235+ glDrawRangeElements(drawmode,0,dwIndexCount,dwVertexCount,GL_UNSIGNED_SHORT,lpwIndices);
 1236+ if(dwFlags & D3DDP_WAIT) glFlush();
 1237+ outputs[0] = (void*)D3D_OK;
11781238 wndbusy = false;
11791239 return;
11801240 }
Index: dxgltest/Tests3D.cpp
@@ -443,6 +443,7 @@
444444
445445 void RunTestTimed3D(int test)
446446 {
 447+ if(!d3d7dev) return;
447448 POINT p;
448449 RECT srcrect,destrect;
449450 HRESULT error;