DXGL r326 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r325‎ | r326 | r327 >
Date:01:25, 17 February 2013
Author:admin
Status:new
Tags:
Comment:
Add IDirect3DDevice::GetStats
Add D3DOP_SETSTATS
Fix rendering transformed and lit vertices when lighting is enabled.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -246,6 +246,30 @@
247247 }
248248 }
249249
 250+void AddStats(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwCount, D3DSTATS *stats)
 251+{
 252+ switch(d3dptPrimitiveType)
 253+ {
 254+ case D3DPT_POINTLIST:
 255+ stats->dwPointsDrawn += dwCount;
 256+ break;
 257+ case D3DPT_LINELIST:
 258+ stats->dwLinesDrawn += dwCount / 2;
 259+ break;
 260+ case D3DPT_LINESTRIP:
 261+ if(dwCount > 1) stats->dwLinesDrawn += dwCount - 1;
 262+ break;
 263+ case D3DPT_TRIANGLELIST:
 264+ stats->dwTrianglesDrawn += dwCount / 3;
 265+ break;
 266+ case D3DPT_TRIANGLESTRIP:
 267+ case D3DPT_TRIANGLEFAN:
 268+ if(dwCount > 2) stats->dwTrianglesDrawn += dwCount - 2;
 269+ break;
 270+ default:
 271+ break;
 272+ }
 273+}
250274
251275 glDirect3DDevice7::glDirect3DDevice7(REFCLSID rclsid, glDirect3D7 *glD3D7, glDirectDrawSurface7 *glDDS7)
252276 {
@@ -326,6 +350,8 @@
327351 ZeroMemory(lights,16*sizeof(glDirect3DLight*));
328352 memset(gllights,0xff,8*sizeof(int));
329353 memset(gltextures,0,8*sizeof(GLuint));
 354+ ZeroMemory(&stats,sizeof(D3DSTATS));
 355+ stats.dwSize = sizeof(D3DSTATS);
330356 d3ddesc.dwMaxTextureWidth = d3ddesc.dwMaxTextureHeight =
331357 d3ddesc.dwMaxTextureRepeat = d3ddesc.dwMaxTextureAspectRatio = renderer->gl_caps.TextureMax;
332358 d3ddesc3.dwMaxTextureWidth = d3ddesc3.dwMaxTextureHeight =
@@ -708,6 +734,8 @@
709735 if(!this) return DDERR_INVALIDOBJECT;
710736 if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
711737 HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
 738+ if(lpwIndices) AddStats(d3dptPrimitiveType,dwIndexCount,&stats);
 739+ else AddStats(d3dptPrimitiveType,dwVertexCount,&stats);
712740 if(err != D3D_OK) return err;
713741 return renderer->DrawPrimitives(this,setdrawmode(d3dptPrimitiveType),vertdata,texformats,
714742 dwVertexCount,lpwIndices,dwIndexCount,dwFlags);
@@ -1814,8 +1842,9 @@
18151843 {
18161844 if(!this) return DDERR_INVALIDOBJECT;
18171845 if(!lpD3DStats) return DDERR_INVALIDPARAMS;
1818 - FIXME("glDirect3DDevice7::GetStats: stub");
1819 - return DDERR_GENERIC;
 1846+ if(lpD3DStats->dwSize < sizeof(D3DSTATS)) return DDERR_INVALIDPARAMS;
 1847+ memcpy(lpD3DStats,&stats,sizeof(D3DSTATS));
 1848+ return D3D_OK;
18201849 }
18211850
18221851 HRESULT glDirect3DDevice7::SwapTextureHandles(LPDIRECT3DTEXTURE2 lpD3DTex1, LPDIRECT3DTEXTURE2 lpD3DTex2)
@@ -2282,6 +2311,7 @@
22832312 default:
22842313 break;
22852314 }
 2315+ stats.dwVerticesProcessed += ((D3DPROCESSVERTICES*)opptr)->dwCount;
22862316 opptr += instruction->bSize;
22872317 }
22882318 break;
@@ -2301,8 +2331,20 @@
23022332 FIXME("D3DOP_SPAN: stub");
23032333 break;
23042334 case D3DOP_SETSTATUS:
2305 - opptr += sizeof(D3DINSTRUCTION)+(instruction->bSize*instruction->wCount);
2306 - FIXME("D3DOP_SETSTATUS: stub");
 2335+ opptr += sizeof(D3DINSTRUCTION);
 2336+ if(instruction->bSize < sizeof(D3DSTATUS))
 2337+ {
 2338+ opptr += (instruction->bSize*instruction->wCount);
 2339+ break;
 2340+ }
 2341+ for(i = 0; i < instruction->wCount; i++)
 2342+ {
 2343+ if(((D3DSTATUS*)opptr)->dwFlags & D3DSETSTATUS_STATUS)
 2344+ data.dsStatus.dwStatus = ((D3DSTATUS*)opptr)->dwStatus;
 2345+ if(((D3DSTATUS*)opptr)->dwFlags & D3DSETSTATUS_EXTENTS)
 2346+ data.dsStatus.drExtent = ((D3DSTATUS*)opptr)->drExtent;
 2347+ opptr += instruction->bSize;
 2348+ }
23072349 break;
23082350 default:
23092351 opptr += sizeof(D3DINSTRUCTION)+(instruction->bSize*instruction->wCount);
Index: ddraw/glDirect3DDevice.h
@@ -191,6 +191,7 @@
192192 int texturecount;
193193 bool modelview_dirty;
194194 bool projection_dirty;
 195+ D3DSTATS stats;
195196 glDirect3DDevice3 *glD3DDev3;
196197 glDirect3DDevice2 *glD3DDev2;
197198 glDirect3DDevice1 *glD3DDev1;
Index: ddraw/shadergen.cpp
@@ -476,6 +476,7 @@
477477 if((id>>50)&1) vsrc->append(unif_size);
478478 if((id>>59)&1) numlights = (id>>18)&7;
479479 else numlights = 0;
 480+ if((id>>50)&1) numlights = 0;
480481 if(numlights) // Lighting
481482 {
482483 vsrc->append(lightstruct);