DXGL r120 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r119‎ | r120 | r121 >
Date:18:39, 11 March 2012
Author:admin
Status:new
Tags:
Comment:
Add EnumTextureFormats and GetTextureStageState
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glRenderer.cpp (modified) (history)
  • /ddraw/shadergen.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -120,6 +120,53 @@
121121 FALSE, //clipplaneenable
122122 };
123123
 124+const TEXTURESTAGE texstagedefault0 =
 125+{
 126+ D3DTOP_MODULATE,
 127+ D3DTA_TEXTURE,
 128+ D3DTA_CURRENT,
 129+ D3DTOP_SELECTARG1,
 130+ D3DTA_TEXTURE,
 131+ D3DTA_CURRENT,
 132+ 0,0,0,0,
 133+ 0,
 134+ D3DTADDRESS_WRAP,
 135+ D3DTADDRESS_WRAP,
 136+ 0,
 137+ D3DTFG_POINT,
 138+ D3DTFN_POINT,
 139+ D3DTFP_NONE,
 140+ 0,
 141+ 0,
 142+ 1,
 143+ 0,
 144+ 0,
 145+ D3DTTFF_DISABLE
 146+};
 147+const TEXTURESTAGE texstagedefault1 =
 148+{
 149+ D3DTOP_DISABLE,
 150+ D3DTA_TEXTURE,
 151+ D3DTA_CURRENT,
 152+ D3DTOP_DISABLE,
 153+ D3DTA_TEXTURE,
 154+ D3DTA_CURRENT,
 155+ 0,0,0,0,
 156+ 0,
 157+ D3DTADDRESS_WRAP,
 158+ D3DTADDRESS_WRAP,
 159+ 0,
 160+ D3DTFG_POINT,
 161+ D3DTFN_POINT,
 162+ D3DTFP_NONE,
 163+ 0,
 164+ 0,
 165+ 1,
 166+ 0,
 167+ 0,
 168+ D3DTTFF_DISABLE
 169+};
 170+
124171 int setdrawmode(D3DPRIMITIVETYPE d3dptPrimitiveType)
125172 {
126173 switch(d3dptPrimitiveType)
@@ -153,6 +200,9 @@
154201 __gluMakeIdentityf(matView);
155202 __gluMakeIdentityf(matProjection);
156203 __gluMakeIdentityf(matNormal);
 204+ texstages[0] = texstagedefault0;
 205+ texstages[1] = texstages[2] = texstages[3] = texstages[4] =
 206+ texstages[5] = texstages[6] = texstages[7] = texstagedefault1;
157207 refcount = 1;
158208 inscene = false;
159209 normal_dirty = false;
@@ -468,11 +518,31 @@
469519 FIXME("glDirect3DDevice7::EndStateBlock: stub");
470520 ERR(DDERR_GENERIC);
471521 }
 522+
 523+// Use EXACTLY one line per entry. Don't change layout of the list.
 524+const int TEXFMT_START = __LINE__;
 525+const DDPIXELFORMAT texformats[] =
 526+{
 527+ {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0xF00,0xF0,0xF,0xF000},
 528+ {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,16,0x7C00,0x3E0,0x1F,0x8000},
 529+ {sizeof(DDPIXELFORMAT),DDPF_RGB,0,16,0xF800,0x7E0,0x1F,0},
 530+ {sizeof(DDPIXELFORMAT),DDPF_RGB|DDPF_ALPHAPIXELS,0,32,0xFF0000,0xFF00,0xFF,0xFF000000}
 531+};
 532+const int TEXFMT_END = __LINE__ - 4;
 533+const int numtexfmt = TEXFMT_END-TEXFMT_START;
 534+
472535 HRESULT WINAPI glDirect3DDevice7::EnumTextureFormats(LPD3DENUMPIXELFORMATSCALLBACK lpd3dEnumPixelProc, LPVOID lpArg)
473536 {
474537 if(!this) return DDERR_INVALIDPARAMS;
475 - FIXME("glDirect3DDevice7::EnumTextureFormats: stub");
476 - ERR(DDERR_GENERIC);
 538+ HRESULT result;
 539+ DDPIXELFORMAT fmt;
 540+ for(int i = 0; i < numtexfmt; i++)
 541+ {
 542+ memcpy(&fmt,&texformats[i],sizeof(DDPIXELFORMAT));
 543+ result = lpd3dEnumPixelProc(&fmt,lpArg);
 544+ if(result != D3DENUMRET_OK) return D3D_OK;
 545+ }
 546+ return D3D_OK;
477547 }
478548 HRESULT WINAPI glDirect3DDevice7::GetCaps(LPD3DDEVICEDESC7 lpD3DDevDesc)
479549 {
@@ -557,8 +627,84 @@
558628 }
559629 HRESULT WINAPI glDirect3DDevice7::GetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, LPDWORD lpdwValue)
560630 {
 631+ if(dwStage > 7) return DDERR_INVALIDPARAMS;
 632+ if(!lpdwValue) return DDERR_INVALIDPARAMS;
561633 if(!this) return DDERR_INVALIDPARAMS;
562 - FIXME("glDirect3DDevice7::GetTextureStageState: stub");
 634+ switch(dwState)
 635+ {
 636+ case D3DTSS_COLOROP:
 637+ *lpdwValue = texstages[dwStage].colorop;
 638+ return D3D_OK;
 639+ case D3DTSS_COLORARG1:
 640+ *lpdwValue = texstages[dwStage].colorarg1;
 641+ return D3D_OK;
 642+ case D3DTSS_COLORARG2:
 643+ *lpdwValue = texstages[dwStage].colorarg2;
 644+ return D3D_OK;
 645+ case D3DTSS_ALPHAOP:
 646+ *lpdwValue = texstages[dwStage].alphaop;
 647+ return D3D_OK;
 648+ case D3DTSS_ALPHAARG1:
 649+ *lpdwValue = texstages[dwStage].alphaarg1;
 650+ return D3D_OK;
 651+ case D3DTSS_ALPHAARG2:
 652+ *lpdwValue = texstages[dwStage].alphaarg2;
 653+ return D3D_OK;
 654+ case D3DTSS_BUMPENVMAT00:
 655+ memcpy(lpdwValue,&texstages[dwStage].bumpenv00,sizeof(D3DVALUE));
 656+ return D3D_OK;
 657+ case D3DTSS_BUMPENVMAT01:
 658+ memcpy(lpdwValue,&texstages[dwStage].bumpenv01,sizeof(D3DVALUE));
 659+ return D3D_OK;
 660+ case D3DTSS_BUMPENVMAT10:
 661+ memcpy(lpdwValue,&texstages[dwStage].bumpenv10,sizeof(D3DVALUE));
 662+ return D3D_OK;
 663+ case D3DTSS_BUMPENVMAT11:
 664+ memcpy(lpdwValue,&texstages[dwStage].bumpenv11,sizeof(D3DVALUE));
 665+ return D3D_OK;
 666+ case D3DTSS_TEXCOORDINDEX:
 667+ *lpdwValue = texstages[dwStage].texcoordindex;
 668+ return D3D_OK;
 669+ case D3DTSS_ADDRESS:
 670+ case D3DTSS_ADDRESSU:
 671+ *lpdwValue = texstages[dwStage].addressu;
 672+ return D3D_OK;
 673+ case D3DTSS_ADDRESSV:
 674+ *lpdwValue = texstages[dwStage].addressv;
 675+ return D3D_OK;
 676+ case D3DTSS_BORDERCOLOR:
 677+ *lpdwValue = texstages[dwStage].bordercolor;
 678+ return D3D_OK;
 679+ case D3DTSS_MAGFILTER:
 680+ *lpdwValue = texstages[dwStage].magfilter;
 681+ return D3D_OK;
 682+ case D3DTSS_MINFILTER:
 683+ *lpdwValue = texstages[dwStage].minfilter;
 684+ return D3D_OK;
 685+ case D3DTSS_MIPFILTER:
 686+ *lpdwValue = texstages[dwStage].mipfilter;
 687+ return D3D_OK;
 688+ case D3DTSS_MIPMAPLODBIAS:
 689+ memcpy(lpdwValue,&texstages[dwStage].lodbias,sizeof(D3DVALUE));
 690+ return D3D_OK;
 691+ case D3DTSS_MAXMIPLEVEL:
 692+ *lpdwValue = texstages[dwStage].miplevel;
 693+ return D3D_OK;
 694+ case D3DTSS_MAXANISOTROPY:
 695+ *lpdwValue = texstages[dwStage].anisotropy;
 696+ return D3D_OK;
 697+ case D3DTSS_BUMPENVLSCALE:
 698+ memcpy(lpdwValue,&texstages[dwStage].bumpenvlscale,sizeof(D3DVALUE));
 699+ return D3D_OK;
 700+ case D3DTSS_BUMPENVLOFFSET:
 701+ memcpy(lpdwValue,&texstages[dwStage].bumpenvloffset,sizeof(D3DVALUE));
 702+ return D3D_OK;
 703+ case D3DTSS_TEXTURETRANSFORMFLAGS:
 704+ *lpdwValue = texstages[dwStage].textransform;
 705+ return D3D_OK;
 706+ default:
 707+ return DDERR_INVALIDPARAMS;
 708+ }
563709 ERR(DDERR_GENERIC);
564710 }
565711 HRESULT WINAPI glDirect3DDevice7::GetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
Index: ddraw/glDirect3DDevice.h
@@ -19,6 +19,33 @@
2020 #ifndef __GLDIRECT3DDEVICE_H
2121 #define __GLDIRECT3DDEVICE_H
2222
 23+struct TEXTURESTAGE
 24+{
 25+ D3DTEXTUREOP colorop;
 26+ DWORD colorarg1;
 27+ DWORD colorarg2;
 28+ D3DTEXTUREOP alphaop;
 29+ DWORD alphaarg1;
 30+ DWORD alphaarg2;
 31+ D3DVALUE bumpenv00;
 32+ D3DVALUE bumpenv01;
 33+ D3DVALUE bumpenv10;
 34+ D3DVALUE bumpenv11;
 35+ DWORD texcoordindex;
 36+ D3DTEXTUREADDRESS addressu;
 37+ D3DTEXTUREADDRESS addressv;
 38+ DWORD bordercolor;
 39+ D3DTEXTUREMAGFILTER magfilter;
 40+ D3DTEXTUREMINFILTER minfilter;
 41+ D3DTEXTUREMIPFILTER mipfilter;
 42+ D3DVALUE lodbias;
 43+ DWORD miplevel;
 44+ DWORD anisotropy;
 45+ D3DVALUE bumpenvlscale;
 46+ D3DVALUE bumpenvloffset;
 47+ D3DTEXTURETRANSFORMFLAGS textransform;
 48+};
 49+
2350 class glDirect3DLight;
2451 class glDirectDrawSurface7;
2552 class glDirect3DDevice7 : public IDirect3DDevice7
@@ -99,6 +126,7 @@
100127 int gllights[8];
101128 glDirectDrawSurface7 *glDDS7;
102129 DWORD renderstate[153];
 130+ TEXTURESTAGE texstages[8];
103131
104132 private:
105133 HRESULT fvftoglvertex(DWORD dwVertexTypeDesc,LPDWORD vertptr);
Index: ddraw/glRenderer.cpp
@@ -1068,6 +1068,16 @@
10691069 glVertexAttribPointer(colorloc,4,GL_UNSIGNED_BYTE,true,vertices[i+8].stride,vertices[i+8].data);
10701070 }
10711071 }
 1072+ for(i = 0; i < 8; i++)
 1073+ {
 1074+ {
 1075+ switch(texformats[i])
 1076+ {
 1077+
 1078+ }
 1079+
 1080+ }
 1081+ }
10721082 if(device->normal_dirty) device->UpdateNormalMatrix();
10731083 GLint loc = glGetUniformLocation(prog,"world");
10741084 viewLHtoRH(tmpmat,device->matWorld);
Index: ddraw/shadergen.cpp
@@ -91,7 +91,7 @@
9292 Bit 47: Enable texture coordinate transform
9393 Bits 48-49: Number of texcoord dimensions
9494 Bit 50: Projected texcoord
95 -Bits 51-52: Texutre coordinate format:
 95+Bits 51-52: Texture coordinate format:
9696 00=2dim 01=3dim 10=4dim 11=1dim
9797 */
9898 void ZeroShaderArray()