DXGL r220 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r219‎ | r220 | r221 >
Date:20:02, 29 July 2012
Author:admin
Status:new
Tags:
Comment:
Fix buildtool for directories with spaces.
Make buildtool work on "no DXGL" builds.
Add initialization for texture shader demo.
Modified paths:
  • /buildtool/buildtool.vcxproj (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /dxgl.sln (modified) (history)
  • /dxgltest/Tests3D.cpp (modified) (history)

Diff [purge]

Index: buildtool/buildtool.vcxproj
@@ -1,10 +1,18 @@
22 <?xml version="1.0" encoding="utf-8"?>
33 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
44 <ItemGroup Label="ProjectConfigurations">
 5+ <ProjectConfiguration Include="Debug no DXGL|Win32">
 6+ <Configuration>Debug no DXGL</Configuration>
 7+ <Platform>Win32</Platform>
 8+ </ProjectConfiguration>
59 <ProjectConfiguration Include="Debug|Win32">
610 <Configuration>Debug</Configuration>
711 <Platform>Win32</Platform>
812 </ProjectConfiguration>
 13+ <ProjectConfiguration Include="Release no DXGL|Win32">
 14+ <Configuration>Release no DXGL</Configuration>
 15+ <Platform>Win32</Platform>
 16+ </ProjectConfiguration>
917 <ProjectConfiguration Include="Release|Win32">
1018 <Configuration>Release</Configuration>
1119 <Platform>Win32</Platform>
@@ -22,11 +30,21 @@
2331 <UseDebugLibraries>true</UseDebugLibraries>
2432 <CharacterSet>Unicode</CharacterSet>
2533 </PropertyGroup>
 34+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'" Label="Configuration">
 35+ <ConfigurationType>Application</ConfigurationType>
 36+ <UseDebugLibraries>true</UseDebugLibraries>
 37+ <CharacterSet>Unicode</CharacterSet>
 38+ </PropertyGroup>
2639 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
2740 <ConfigurationType>Application</ConfigurationType>
2841 <UseDebugLibraries>false</UseDebugLibraries>
2942 <CharacterSet>Unicode</CharacterSet>
3043 </PropertyGroup>
 44+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'" Label="Configuration">
 45+ <ConfigurationType>Application</ConfigurationType>
 46+ <UseDebugLibraries>false</UseDebugLibraries>
 47+ <CharacterSet>Unicode</CharacterSet>
 48+ </PropertyGroup>
3149 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
3250 <ImportGroup Label="ExtensionSettings">
3351 </ImportGroup>
@@ -33,16 +51,28 @@
3452 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
3553 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
3654 </ImportGroup>
 55+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'" Label="PropertySheets">
 56+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
 57+ </ImportGroup>
3758 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
3859 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
3960 </ImportGroup>
 61+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'" Label="PropertySheets">
 62+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
 63+ </ImportGroup>
4064 <PropertyGroup Label="UserMacros" />
4165 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4266 <LinkIncremental>true</LinkIncremental>
4367 </PropertyGroup>
 68+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">
 69+ <LinkIncremental>true</LinkIncremental>
 70+ </PropertyGroup>
4471 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
4572 <LinkIncremental>false</LinkIncremental>
4673 </PropertyGroup>
 74+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">
 75+ <LinkIncremental>false</LinkIncremental>
 76+ </PropertyGroup>
4777 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
4878 <ClCompile>
4979 <WarningLevel>Level3</WarningLevel>
@@ -57,6 +87,20 @@
5888 <PostBuildEvent />
5989 <PostBuildEvent />
6090 </ItemDefinitionGroup>
 91+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">
 92+ <ClCompile>
 93+ <WarningLevel>Level3</WarningLevel>
 94+ <Optimization>Disabled</Optimization>
 95+ <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 96+ <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
 97+ </ClCompile>
 98+ <Link>
 99+ <GenerateDebugInformation>true</GenerateDebugInformation>
 100+ <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
 101+ </Link>
 102+ <PostBuildEvent />
 103+ <PostBuildEvent />
 104+ </ItemDefinitionGroup>
61105 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62106 <ClCompile>
63107 <WarningLevel>Level3</WarningLevel>
@@ -70,6 +114,19 @@
71115 <PostBuildEvent />
72116 <PostBuildEvent />
73117 </ItemDefinitionGroup>
 118+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release no DXGL|Win32'">
 119+ <ClCompile>
 120+ <WarningLevel>Level3</WarningLevel>
 121+ <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
 122+ <PrecompiledHeaderFile>common.h</PrecompiledHeaderFile>
 123+ </ClCompile>
 124+ <Link>
 125+ <GenerateDebugInformation>true</GenerateDebugInformation>
 126+ <AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
 127+ </Link>
 128+ <PostBuildEvent />
 129+ <PostBuildEvent />
 130+ </ItemDefinitionGroup>
74131 <ItemGroup>
75132 <ClInclude Include="resource.h" />
76133 </ItemGroup>
Index: ddraw/ddraw.vcxproj
@@ -93,7 +93,7 @@
9494 <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
9595 </Link>
9696 <PreBuildEvent>
97 - <Command>$(OutDir)buildtool.exe makeheader $(SolutionDir)common</Command>
 97+ <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
9898 </PreBuildEvent>
9999 <PreBuildEvent>
100100 <Message>Create version headers</Message>
@@ -119,7 +119,7 @@
120120 <PostBuildEvent />
121121 <PostBuildEvent />
122122 <PreBuildEvent>
123 - <Command>$(OutDir)buildtool.exe makeheader $(SolutionDir)common</Command>
 123+ <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
124124 </PreBuildEvent>
125125 <PreBuildEvent>
126126 <Message>Create version headers</Message>
@@ -147,7 +147,7 @@
148148 <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
149149 </Link>
150150 <PreBuildEvent>
151 - <Command>$(OutDir)buildtool.exe makeheader $(SolutionDir)common</Command>
 151+ <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
152152 </PreBuildEvent>
153153 <PreBuildEvent>
154154 <Message>Create version headers</Message>
@@ -177,7 +177,7 @@
178178 </Link>
179179 <PostBuildEvent />
180180 <PreBuildEvent>
181 - <Command>$(OutDir)buildtool.exe makeheader $(SolutionDir)common</Command>
 181+ <Command>"$(OutDir)buildtool.exe" makeheader $(SolutionDir)common</Command>
182182 </PreBuildEvent>
183183 <PreBuildEvent>
184184 <Message>Create version headers</Message>
Index: dxgl.sln
@@ -97,12 +97,12 @@
9898 {8041FD11-3A2E-4EE9-A3FF-A9755803B7FB}.Release no DXGL|Win32.Build.0 = Release|Win32
9999 {8041FD11-3A2E-4EE9-A3FF-A9755803B7FB}.Release|Win32.ActiveCfg = Release|Win32
100100 {8041FD11-3A2E-4EE9-A3FF-A9755803B7FB}.Release|Win32.Build.0 = Release|Win32
101 - {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Debug no DXGL|Win32.ActiveCfg = Debug|Win32
102 - {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Debug no DXGL|Win32.Build.0 = Debug|Win32
 101+ {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Debug no DXGL|Win32.ActiveCfg = Debug no DXGL|Win32
 102+ {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Debug no DXGL|Win32.Build.0 = Debug no DXGL|Win32
103103 {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Debug|Win32.ActiveCfg = Debug|Win32
104104 {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Debug|Win32.Build.0 = Debug|Win32
105 - {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Release no DXGL|Win32.ActiveCfg = Release|Win32
106 - {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Release no DXGL|Win32.Build.0 = Release|Win32
 105+ {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Release no DXGL|Win32.ActiveCfg = Release no DXGL|Win32
 106+ {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Release no DXGL|Win32.Build.0 = Release no DXGL|Win32
107107 {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Release|Win32.ActiveCfg = Release|Win32
108108 {34883A93-DFE4-42EF-9DAE-BEE4D3FC87D0}.Release|Win32.Build.0 = Release|Win32
109109 {4DC98095-5F42-4A44-962C-346ABEE2C9B6}.Debug no DXGL|Win32.ActiveCfg = Debug|Win32
Index: dxgltest/Tests3D.cpp
@@ -466,11 +466,11 @@
467467 D3DMATRIX matView;
468468 D3DMATRIX matProj;
469469 D3DMATRIX mat;
 470+ D3DMATERIAL7 material;
470471 switch(test)
471472 {
472473 case 0:
473474 MakeCube3D(points,normals,vertices);
474 - D3DMATERIAL7 material;
475475 ZeroMemory(&material,sizeof(D3DMATERIAL7));
476476 material.ambient.r = 0.5f;
477477 material.ambient.g = 0.5f;
@@ -553,6 +553,35 @@
554554 lights[0].dvAttenuation1 = 0.4f;
555555 error = d3d7dev->SetLight(0,&lights[0]);
556556 break;
 557+ case 2:
 558+ MakeCube3D(points,normals,vertices);
 559+ ZeroMemory(&material,sizeof(D3DMATERIAL7));
 560+ material.ambient.r = 1.0f;
 561+ material.ambient.g = 1.0f;
 562+ material.ambient.b = 1.0f;
 563+ material.diffuse.r = 1.0f;
 564+ material.diffuse.g = 1.0f;
 565+ material.diffuse.b = 1.0f;
 566+ error = d3d7dev->SetMaterial(&material);
 567+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_LIGHTING, FALSE);
 568+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_AMBIENT, 0xffffffff);
 569+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 570+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 571+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 572+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 573+ matWorld = mat;
 574+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD,&matWorld);
 575+ matView = mat;
 576+ matView._43 = 10.0f;
 577+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_VIEW,&matView);
 578+ matProj = mat;
 579+ matProj._11 = 2.0f;
 580+ matProj._22 = 2.0f;
 581+ matProj._34 = 1.0f;
 582+ matProj._43 = -1.0f;
 583+ matProj._44 = 0.0f;
 584+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION,&matProj);
 585+ break;
557586 default:
558587 break;
559588 }
@@ -569,7 +598,7 @@
570599 ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
571600 if(d3dver >= 3) ddsd.dwSize = sizeof(DDSURFACEDESC2);
572601 else ddsd.dwSize = sizeof(DDSURFACEDESC);
573 - d3d7dev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0,1.0,0);
 602+ error = d3d7dev->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,0,1.0,0);
574603 float time = (float)clock() / (float)CLOCKS_PER_SEC;
575604 switch(test)
576605 {
@@ -598,16 +627,30 @@
599628 mat._31 = (FLOAT)sin( (float)time );
600629 error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
601630 error = d3d7dev->BeginScene();
602 - d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[0]->GetSurface());
 631+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[0]->GetSurface());
603632 error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices,4,0);
604 - d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[1]->GetSurface());
 633+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[1]->GetSurface());
605634 error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+4,4,0);
606 - d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[2]->GetSurface());
 635+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[2]->GetSurface());
607636 error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+8,4,0);
608 - d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[3]->GetSurface());
 637+ error = d3d7dev->SetTexture(0,(LPDIRECTDRAWSURFACE7)textures[3]->GetSurface());
609638 error = d3d7dev->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_VERTEX,vertices+12,4,0);
610639 error = d3d7dev->EndScene();
611640 break;
 641+ case 2:
 642+ mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
 643+ mat._12 = mat._13 = mat._14 = mat._41 = 0.0f;
 644+ mat._21 = mat._23 = mat._24 = mat._42 = 0.0f;
 645+ mat._31 = mat._32 = mat._34 = mat._43 = 0.0f;
 646+ mat._11 = (FLOAT)cos( (float)time );
 647+ mat._33 = (FLOAT)cos( (float)time );
 648+ mat._13 = -(FLOAT)sin( (float)time );
 649+ mat._31 = (FLOAT)sin( (float)time );
 650+ error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_WORLD, &mat);
 651+ error = d3d7dev->BeginScene();
 652+ error = d3d7dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,D3DFVF_VERTEX,vertices,24,cube_mesh,36,0);
 653+ error = d3d7dev->EndScene();
 654+ break;
612655 default:
613656 break;
614657 }
@@ -623,6 +666,7 @@
624667 GetClientRect(hWnd,&destrect);
625668 OffsetRect(&destrect,p.x,p.y);
626669 SetRect(&srcrect,0,0,width,height);
 670+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
627671 if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
628672 }
629673 }
@@ -634,14 +678,67 @@
635679
636680 INT_PTR CALLBACK TexShader7Proc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
637681 {
 682+ HRESULT error;
 683+ D3DVIEWPORT7 vp;
 684+ HWND hDisplay;
638685 switch(Msg)
639686 {
640687 case WM_INITDIALOG:
641 -
 688+ RECT r;
 689+ DDSCAPS2 caps;
 690+ DDSURFACEDESC2 ddsd;
 691+ DDPIXELFORMAT ddpfz;
 692+ testnum = 2;
 693+ ddinterface = new MultiDirectDraw(7,&error,NULL);
 694+ hDisplay = GetDlgItem(hWnd,IDC_DISPLAY);
 695+ ::hWnd = hDisplay;
 696+ error = ddinterface->SetCooperativeLevel(hDisplay,DDSCL_NORMAL);
 697+ ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
 698+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 699+ ddsd.dwFlags = DDSD_CAPS;
 700+ ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
 701+ error = ddinterface->CreateSurface(&ddsd,&ddsurface,NULL);
 702+ error = ddinterface->CreateClipper(0,&ddclipper,NULL);
 703+ error = ddclipper->SetHWnd(0,hDisplay);
 704+ ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2));
 705+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 706+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 707+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_3DDEVICE;
 708+ GetClientRect(hDisplay,&r);
 709+ ddsd.dwWidth = r.right;
 710+ ddsd.dwHeight = r.bottom;
 711+ error = ddinterface->CreateSurface(&ddsd,&ddsrender,NULL);
 712+ error = ddinterface->QueryInterface(IID_IDirect3D7,(VOID**)&d3d7);
 713+ error = d3d7->EnumZBufferFormats(IID_IDirect3DRGBDevice,zcallback,&ddpfz);
 714+ error = ddsrender->GetSurfaceDesc(&ddsd);
 715+ ddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT;
 716+ ddsd.ddsCaps.dwCaps = DDSCAPS_ZBUFFER|DDSCAPS_VIDEOMEMORY;
 717+ memcpy(&ddsd.ddpfPixelFormat,&ddpfz,sizeof(DDPIXELFORMAT));
 718+ error = ddinterface->CreateSurface(&ddsd,&zbuffer,NULL);
 719+ error = ddsrender->AddAttachedSurface(zbuffer);
 720+ error = d3d7->CreateDevice(IID_IDirect3DHALDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
 721+ if(error != D3D_OK)
 722+ error = d3d7->CreateDevice(IID_IDirect3DRGBDevice,(LPDIRECTDRAWSURFACE7)ddsrender->GetSurface(),&d3d7dev);
 723+ ddsrender->GetSurfaceDesc(&ddsd);
 724+ vp.dvMaxZ = 1.0f;
 725+ vp.dvMinZ = 0.0f;
 726+ vp.dwX = vp.dwY = 0;
 727+ vp.dwWidth = ddsd.dwWidth;
 728+ vp.dwHeight = ddsd.dwHeight;
 729+ error = d3d7dev->SetViewport(&vp);
 730+ error = d3d7dev->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE);
 731+ InitTest3D(2);
 732+ ::width = ddsd.dwWidth;
 733+ ::height = ddsd.dwHeight;
 734+ StartTimer(hWnd,WM_APP,60);
642735 break;
643736 case WM_CLOSE:
 737+ ddinterface->Release();
644738 EndDialog(hWnd,IDCANCEL);
645739 break;
 740+ case WM_APP:
 741+ RunTestTimed3D(testnum);
 742+ break;
646743 default:
647744 return FALSE;
648745 }