DXGL r193 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r192‎ | r193 | r194 >
Date:14:03, 4 July 2012
Author:admin
Status:new
Tags:
Comment:
Add rest of IDirectDraw3 functions.
Implement viewport objects.
Implement material objects.
Modified paths:
  • /ddraw/glDirect3DDevice.cpp (modified) (history)
  • /ddraw/glDirect3DDevice.h (modified) (history)
  • /ddraw/glDirect3DMaterial.cpp (modified) (history)
  • /ddraw/glDirect3DMaterial.h (modified) (history)
  • /ddraw/glDirect3DTexture.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.cpp (modified) (history)
  • /ddraw/glDirect3DViewport.h (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)

Diff [purge]

Index: ddraw/glDirect3DDevice.cpp
@@ -215,7 +215,9 @@
216216 materials = (glDirect3DMaterial3**)malloc(32*sizeof(glDirect3DMaterial3*));
217217 materialcount = 1;
218218 materials[0] = NULL;
 219+ currentmaterial = NULL;
219220 maxviewports = 32;
 221+ currentviewport = NULL;
220222 viewportcount = 0;
221223 viewports = (glDirect3DViewport3**)malloc(32*sizeof(glDirect3DViewport3*));
222224 ZeroMemory(viewports,32*sizeof(glDirect3DViewport3*));
@@ -283,7 +285,7 @@
284286
285287 HRESULT WINAPI glDirect3DDevice7::QueryInterface(REFIID riid, void** ppvObj)
286288 {
287 - if(!this) return DDERR_INVALIDPARAMS;
 289+ if(!this) return DDERR_INVALIDOBJECT;
288290 if(!ppvObj) return DDERR_INVALIDPARAMS;
289291 if(riid == IID_IUnknown)
290292 {
@@ -324,13 +326,13 @@
325327
326328 HRESULT WINAPI glDirect3DDevice7::ApplyStateBlock(DWORD dwBlockHandle)
327329 {
328 - if(!this) return DDERR_INVALIDPARAMS;
 330+ if(!this) return DDERR_INVALIDOBJECT;
329331 FIXME("glDirect3DDevice7::ApplyStateBlock: stub");
330332 ERR(DDERR_GENERIC);
331333 }
332334 HRESULT WINAPI glDirect3DDevice7::BeginScene()
333335 {
334 - if(!this) return DDERR_INVALIDPARAMS;
 336+ if(!this) return DDERR_INVALIDOBJECT;
335337 if(inscene) return D3DERR_SCENE_IN_SCENE;
336338 inscene = true;
337339 return D3D_OK;
@@ -337,25 +339,25 @@
338340 }
339341 HRESULT WINAPI glDirect3DDevice7::BeginStateBlock()
340342 {
341 - if(!this) return DDERR_INVALIDPARAMS;
 343+ if(!this) return DDERR_INVALIDOBJECT;
342344 FIXME("glDirect3DDevice7::BeginStateBlock: stub");
343345 ERR(DDERR_GENERIC);
344346 }
345347 HRESULT WINAPI glDirect3DDevice7::CaptureStateBlock(DWORD dwBlockHandle)
346348 {
347 - if(!this) return DDERR_INVALIDPARAMS;
 349+ if(!this) return DDERR_INVALIDOBJECT;
348350 FIXME("glDirect3DDevice7::CaptureStateBlock: stub");
349351 ERR(DDERR_GENERIC);
350352 }
351353 HRESULT WINAPI glDirect3DDevice7::CreateStateBlock(D3DSTATEBLOCKTYPE d3dsbtype, LPDWORD lpdwBlockHandle)
352354 {
353 - if(!this) return DDERR_INVALIDPARAMS;
 355+ if(!this) return DDERR_INVALIDOBJECT;
354356 FIXME("glDirect3DDevice7::CreateStateBlock: stub");
355357 ERR(DDERR_GENERIC);
356358 }
357359 HRESULT WINAPI glDirect3DDevice7::Clear(DWORD dwCount, LPD3DRECT lpRects, DWORD dwFlags, DWORD dwColor, D3DVALUE dvZ, DWORD dwStencil)
358360 {
359 - if(!this) return DDERR_INVALIDPARAMS;
 361+ if(!this) return DDERR_INVALIDOBJECT;
360362 if(dwCount && !lpRects) return DDERR_INVALIDPARAMS;
361363 return renderer->Clear(glDDS7,dwCount,lpRects,dwFlags,dwColor,dvZ,dwStencil);
362364 }
@@ -362,13 +364,13 @@
363365 HRESULT WINAPI glDirect3DDevice7::ComputeSphereVisibility(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres,
364366 DWORD dwFlags, LPDWORD lpdwReturnValues)
365367 {
366 - if(!this) return DDERR_INVALIDPARAMS;
 368+ if(!this) return DDERR_INVALIDOBJECT;
367369 FIXME("glDirect3DDevice7::ComputeSphereVisibility: stub");
368370 ERR(DDERR_GENERIC);
369371 }
370372 HRESULT WINAPI glDirect3DDevice7::DeleteStateBlock(DWORD dwBlockHandle)
371373 {
372 - if(!this) return DDERR_INVALIDPARAMS;
 374+ if(!this) return DDERR_INVALIDOBJECT;
373375 FIXME("glDirect3DDevice7::DeleteStateBlock: stub");
374376 ERR(DDERR_GENERIC);
375377 }
@@ -551,7 +553,7 @@
552554 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitive(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
553555 LPVOID lpvVertices, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
554556 {
555 - if(!this) return DDERR_INVALIDPARAMS;
 557+ if(!this) return DDERR_INVALIDOBJECT;
556558 if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
557559 HRESULT err = fvftoglvertex(dwVertexTypeDesc,(LPDWORD)lpvVertices);
558560 if(err != D3D_OK) return err;
@@ -561,7 +563,7 @@
562564 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveStrided(D3DPRIMITIVETYPE d3dptPrimitiveType, DWORD dwVertexTypeDesc,
563565 LPD3DDRAWPRIMITIVESTRIDEDDATA lpvVerticexArray, DWORD dwVertexCount, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
564566 {
565 - if(!this) return DDERR_INVALIDPARAMS;
 567+ if(!this) return DDERR_INVALIDOBJECT;
566568 FIXME("glDirect3DDevice7::DrawIndexedPrimitiveStrided: stub");
567569 ERR(DDERR_GENERIC);
568570 }
@@ -568,7 +570,7 @@
569571 HRESULT WINAPI glDirect3DDevice7::DrawIndexedPrimitiveVB(D3DPRIMITIVETYPE d3dptPrimitiveType, LPDIRECT3DVERTEXBUFFER7 lpd3dVertexBuffer,
570572 DWORD dwStartVertex, DWORD dwNumVertices, LPWORD lpwIndices, DWORD dwIndexCount, DWORD dwFlags)
571573 {
572 - if(!this) return DDERR_INVALIDPARAMS;
 574+ if(!this) return DDERR_INVALIDOBJECT;
573575 FIXME("glDirect3DDevice7::DrawIndexedPrimitiveVB: stub");
574576 ERR(DDERR_GENERIC);
575577 }
@@ -575,13 +577,13 @@
576578 HRESULT WINAPI glDirect3DDevice7::DrawPrimitive(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc, LPVOID lpVertices,
577579 DWORD dwVertexCount, DWORD dwFlags)
578580 {
579 - if(!this) return DDERR_INVALIDPARAMS;
 581+ if(!this) return DDERR_INVALIDOBJECT;
580582 return DrawIndexedPrimitive(dptPrimitiveType,dwVertexTypeDesc,lpVertices,dwVertexCount,NULL,0,dwFlags);
581583 }
582584 HRESULT WINAPI glDirect3DDevice7::DrawPrimitiveStrided(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc,
583585 LPD3DDRAWPRIMITIVESTRIDEDDATA lpVertexArray, DWORD dwVertexCount, DWORD dwFlags)
584586 {
585 - if(!this) return DDERR_INVALIDPARAMS;
 587+ if(!this) return DDERR_INVALIDOBJECT;
586588 FIXME("glDirect3DDevice7::DrawPrimitiveStrided: stub");
587589 ERR(DDERR_GENERIC);
588590 }
@@ -588,13 +590,13 @@
589591 HRESULT WINAPI glDirect3DDevice7::DrawPrimitiveVB(D3DPRIMITIVETYPE d3dptPrimitiveType, LPDIRECT3DVERTEXBUFFER7 lpd3dVertexBuffer,
590592 DWORD dwStartVertex, DWORD dwNumVertices, DWORD dwFlags)
591593 {
592 - if(!this) return DDERR_INVALIDPARAMS;
 594+ if(!this) return DDERR_INVALIDOBJECT;
593595 FIXME("glDirect3DDevice7::DrawPrimitiveVB: stub");
594596 ERR(DDERR_GENERIC);
595597 }
596598 HRESULT WINAPI glDirect3DDevice7::EndScene()
597599 {
598 - if(!this) return DDERR_INVALIDPARAMS;
 600+ if(!this) return DDERR_INVALIDOBJECT;
599601 if(!inscene) return D3DERR_SCENE_NOT_IN_SCENE;
600602 inscene = false;
601603 renderer->Flush();
@@ -602,7 +604,7 @@
603605 }
604606 HRESULT WINAPI glDirect3DDevice7::EndStateBlock(LPDWORD lpdwBlockHandle)
605607 {
606 - if(!this) return DDERR_INVALIDPARAMS;
 608+ if(!this) return DDERR_INVALIDOBJECT;
607609 FIXME("glDirect3DDevice7::EndStateBlock: stub");
608610 ERR(DDERR_GENERIC);
609611 }
@@ -624,7 +626,7 @@
625627
626628 HRESULT WINAPI glDirect3DDevice7::EnumTextureFormats(LPD3DENUMPIXELFORMATSCALLBACK lpd3dEnumPixelProc, LPVOID lpArg)
627629 {
628 - if(!this) return DDERR_INVALIDPARAMS;
 630+ if(!this) return DDERR_INVALIDOBJECT;
629631 HRESULT result;
630632 DDPIXELFORMAT fmt;
631633 for(int i = 0; i < numtexfmt; i++)
@@ -637,7 +639,7 @@
638640 }
639641 HRESULT WINAPI glDirect3DDevice7::GetCaps(LPD3DDEVICEDESC7 lpD3DDevDesc)
640642 {
641 - if(!this) return DDERR_INVALIDPARAMS;
 643+ if(!this) return DDERR_INVALIDOBJECT;
642644 D3DDEVICEDESC7 desc = d3ddesc;
643645 desc.dwDevCaps |= D3DDEVCAPS_HWRASTERIZATION | D3DDEVCAPS_HWTRANSFORMANDLIGHT;
644646 desc.deviceGUID = IID_IDirect3DTnLHalDevice;
@@ -646,31 +648,31 @@
647649 }
648650 HRESULT WINAPI glDirect3DDevice7::GetClipPlane(DWORD dwIndex, D3DVALUE *pPlaneEquation)
649651 {
650 - if(!this) return DDERR_INVALIDPARAMS;
 652+ if(!this) return DDERR_INVALIDOBJECT;
651653 FIXME("glDirect3DDevice7::GetClipPlane: stub");
652654 ERR(DDERR_GENERIC);
653655 }
654656 HRESULT WINAPI glDirect3DDevice7::GetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus)
655657 {
656 - if(!this) return DDERR_INVALIDPARAMS;
 658+ if(!this) return DDERR_INVALIDOBJECT;
657659 FIXME("glDirect3DDevice7::GetClipStatus: stub");
658660 ERR(DDERR_GENERIC);
659661 }
660662 HRESULT WINAPI glDirect3DDevice7::GetDirect3D(LPDIRECT3D7 *lplpD3D)
661663 {
662 - if(!this) return DDERR_INVALIDPARAMS;
 664+ if(!this) return DDERR_INVALIDOBJECT;
663665 *lplpD3D = glD3D7;
664666 return D3D_OK;
665667 }
666668 HRESULT WINAPI glDirect3DDevice7::GetInfo(DWORD dwDevInfoID, LPVOID pDevInfoStruct, DWORD dwSize)
667669 {
668 - if(!this) return DDERR_INVALIDPARAMS;
 670+ if(!this) return DDERR_INVALIDOBJECT;
669671 FIXME("glDirect3DDevice7::GetInfo: stub");
670672 ERR(DDERR_GENERIC);
671673 }
672674 HRESULT WINAPI glDirect3DDevice7::GetLight(DWORD dwLightIndex, LPD3DLIGHT7 lpLight)
673675 {
674 - if(!this) return DDERR_INVALIDPARAMS;
 676+ if(!this) return DDERR_INVALIDOBJECT;
675677 if(!lpLight) return DDERR_INVALIDPARAMS;
676678 if(dwLightIndex >= lightsmax) ERR(DDERR_INVALIDOBJECT);
677679 if(!lights[dwLightIndex]) ERR(DDERR_INVALIDOBJECT);
@@ -679,7 +681,7 @@
680682 }
681683 HRESULT WINAPI glDirect3DDevice7::GetLightEnable(DWORD dwLightIndex, BOOL* pbEnable)
682684 {
683 - if(!this) return DDERR_INVALIDPARAMS;
 685+ if(!this) return DDERR_INVALIDOBJECT;
684686 if(dwLightIndex >= lightsmax) ERR(DDERR_INVALIDOBJECT);
685687 if(!lights[dwLightIndex]) ERR(DDERR_INVALIDOBJECT);
686688 if(!pbEnable) return DDERR_INVALIDPARAMS;
@@ -690,7 +692,7 @@
691693 }
692694 HRESULT WINAPI glDirect3DDevice7::GetMaterial(LPD3DMATERIAL7 lpMaterial)
693695 {
694 - if(!this) return DDERR_INVALIDPARAMS;
 696+ if(!this) return DDERR_INVALIDOBJECT;
695697 if(!lpMaterial) return DDERR_INVALIDPARAMS;
696698 memcpy(lpMaterial,&material,sizeof(D3DMATERIAL7));
697699 return D3D_OK;
@@ -697,7 +699,7 @@
698700 }
699701 HRESULT WINAPI glDirect3DDevice7::GetRenderState(D3DRENDERSTATETYPE dwRenderStateType, LPDWORD lpdwRenderState)
700702 {
701 - if(!this) return DDERR_INVALIDPARAMS;
 703+ if(!this) return DDERR_INVALIDOBJECT;
702704 if(dwRenderStateType <= 152)
703705 {
704706 *lpdwRenderState = renderstate[dwRenderStateType];
@@ -707,7 +709,7 @@
708710 }
709711 HRESULT WINAPI glDirect3DDevice7::GetRenderTarget(LPDIRECTDRAWSURFACE7 *lplpRenderTarget)
710712 {
711 - if(!this) return DDERR_INVALIDPARAMS;
 713+ if(!this) return DDERR_INVALIDOBJECT;
712714 if(!lplpRenderTarget) return DDERR_INVALIDPARAMS;
713715 glDDS7->AddRef();
714716 *lplpRenderTarget = glDDS7;
@@ -715,7 +717,7 @@
716718 }
717719 HRESULT WINAPI glDirect3DDevice7::GetStateData(DWORD dwState, LPVOID* lplpStateData)
718720 {
719 - if(!this) return DDERR_INVALIDPARAMS;
 721+ if(!this) return DDERR_INVALIDOBJECT;
720722 FIXME("glDirect3DDevice7::GetStateData: stub");
721723 ERR(DDERR_GENERIC);
722724 }
@@ -722,7 +724,7 @@
723725 HRESULT WINAPI glDirect3DDevice7::GetTexture(DWORD dwStage, LPDIRECTDRAWSURFACE7 *lplpTexture)
724726 {
725727 if(!lplpTexture) return DDERR_INVALIDPARAMS;
726 - if(!this) return DDERR_INVALIDPARAMS;
 728+ if(!this) return DDERR_INVALIDOBJECT;
727729 if(dwStage > 7) return DDERR_INVALIDPARAMS;
728730 if(!texstages[dwStage].texture) return DDERR_INVALIDOBJECT;
729731 *lplpTexture = texstages[dwStage].texture;
@@ -733,7 +735,7 @@
734736 {
735737 if(dwStage > 7) return DDERR_INVALIDPARAMS;
736738 if(!lpdwValue) return DDERR_INVALIDPARAMS;
737 - if(!this) return DDERR_INVALIDPARAMS;
 739+ if(!this) return DDERR_INVALIDOBJECT;
738740 switch(dwState)
739741 {
740742 case D3DTSS_COLOROP:
@@ -813,7 +815,7 @@
814816 }
815817 HRESULT WINAPI glDirect3DDevice7::GetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
816818 {
817 - if(!this) return DDERR_INVALIDPARAMS;
 819+ if(!this) return DDERR_INVALIDOBJECT;
818820 switch(dtstTransformStateType)
819821 {
820822 case D3DTRANSFORMSTATE_WORLD:
@@ -831,13 +833,13 @@
832834 }
833835 HRESULT WINAPI glDirect3DDevice7::GetViewport(LPD3DVIEWPORT7 lpViewport)
834836 {
835 - if(!this) return DDERR_INVALIDPARAMS;
 837+ if(!this) return DDERR_INVALIDOBJECT;
836838 memcpy(lpViewport,&viewport,sizeof(D3DVIEWPORT7));
837839 return D3D_OK;
838840 }
839841 HRESULT WINAPI glDirect3DDevice7::LightEnable(DWORD dwLightIndex, BOOL bEnable)
840842 {
841 - if(!this) return DDERR_INVALIDPARAMS;
 843+ if(!this) return DDERR_INVALIDOBJECT;
842844 int i;
843845 D3DLIGHT7 light;
844846 bool foundlight = false;
@@ -877,37 +879,37 @@
878880 HRESULT WINAPI glDirect3DDevice7::Load(LPDIRECTDRAWSURFACE7 lpDestTex, LPPOINT lpDestPoint, LPDIRECTDRAWSURFACE7 lpSrcTex,
879881 LPRECT lprcSrcRect, DWORD dwFlags)
880882 {
881 - if(!this) return DDERR_INVALIDPARAMS;
 883+ if(!this) return DDERR_INVALIDOBJECT;
882884 FIXME("glDirect3DDevice7::Load: stub");
883885 ERR(DDERR_GENERIC);
884886 }
885887 HRESULT WINAPI glDirect3DDevice7::MultiplyTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
886888 {
887 - if(!this) return DDERR_INVALIDPARAMS;
 889+ if(!this) return DDERR_INVALIDOBJECT;
888890 FIXME("glDirect3DDevice7::MultiplyTransform: stub");
889891 ERR(DDERR_GENERIC);
890892 }
891893 HRESULT WINAPI glDirect3DDevice7::PreLoad(LPDIRECTDRAWSURFACE7 lpddsTexture)
892894 {
893 - if(!this) return DDERR_INVALIDPARAMS;
 895+ if(!this) return DDERR_INVALIDOBJECT;
894896 FIXME("glDirect3DDevice7::PreLoad: stub");
895897 ERR(DDERR_GENERIC);
896898 }
897899 HRESULT WINAPI glDirect3DDevice7::SetClipPlane(DWORD dwIndex, D3DVALUE* pPlaneEquation)
898900 {
899 - if(!this) return DDERR_INVALIDPARAMS;
 901+ if(!this) return DDERR_INVALIDOBJECT;
900902 FIXME("glDirect3DDevice7::SetClipPland: stub");
901903 ERR(DDERR_GENERIC);
902904 }
903905 HRESULT WINAPI glDirect3DDevice7::SetClipStatus(LPD3DCLIPSTATUS lpD3DClipStatus)
904906 {
905 - if(!this) return DDERR_INVALIDPARAMS;
 907+ if(!this) return DDERR_INVALIDOBJECT;
906908 FIXME("glDirect3DDevice7::SetClipStatus: stub");
907909 ERR(DDERR_GENERIC);
908910 }
909911 HRESULT WINAPI glDirect3DDevice7::SetLight(DWORD dwLightIndex, LPD3DLIGHT7 lpLight)
910912 {
911 - if(!this) return DDERR_INVALIDPARAMS;
 913+ if(!this) return DDERR_INVALIDOBJECT;
912914 bool foundlight = false;
913915 if(dwLightIndex >= lightsmax)
914916 {
@@ -919,7 +921,7 @@
920922 }
921923 HRESULT WINAPI glDirect3DDevice7::SetMaterial(LPD3DMATERIAL7 lpMaterial)
922924 {
923 - if(!this) return DDERR_INVALIDPARAMS;
 925+ if(!this) return DDERR_INVALIDOBJECT;
924926 if(!lpMaterial) return DDERR_INVALIDPARAMS;
925927 memcpy(&material,lpMaterial,sizeof(D3DMATERIAL7));
926928 return D3D_OK;
@@ -927,7 +929,7 @@
928930
929931 HRESULT WINAPI glDirect3DDevice7::SetRenderState(D3DRENDERSTATETYPE dwRendStateType, DWORD dwRenderState)
930932 {
931 - if(!this) return DDERR_INVALIDPARAMS;
 933+ if(!this) return DDERR_INVALIDOBJECT;
932934 if(dwRendStateType > 152) return DDERR_INVALIDPARAMS;
933935 if(dwRendStateType < 0) return DDERR_INVALIDPARAMS;
934936 renderstate[dwRendStateType] = dwRenderState;
@@ -935,7 +937,7 @@
936938 }
937939 HRESULT WINAPI glDirect3DDevice7::SetRenderTarget(LPDIRECTDRAWSURFACE7 lpNewRenderTarget, DWORD dwFlags)
938940 {
939 - if(!this) return DDERR_INVALIDPARAMS;
 941+ if(!this) return DDERR_INVALIDOBJECT;
940942 if(!lpNewRenderTarget) return DDERR_INVALIDPARAMS;
941943 if(dwFlags) return DDERR_INVALIDPARAMS;
942944 DDSURFACEDESC2 ddsd;
@@ -949,13 +951,13 @@
950952 }
951953 HRESULT WINAPI glDirect3DDevice7::SetStateData(DWORD dwState, LPVOID lpStateData)
952954 {
953 - if(!this) return DDERR_INVALIDPARAMS;
 955+ if(!this) return DDERR_INVALIDOBJECT;
954956 FIXME("glDirect3DDevice7::SetStateData: stub");
955957 ERR(DDERR_GENERIC);
956958 }
957959 HRESULT WINAPI glDirect3DDevice7::SetTexture(DWORD dwStage, LPDIRECTDRAWSURFACE7 lpTexture)
958960 {
959 - if(!this) return DDERR_INVALIDPARAMS;
 961+ if(!this) return DDERR_INVALIDOBJECT;
960962 if(dwStage > 7) return DDERR_INVALIDPARAMS;
961963 if(texstages[dwStage].texture) texstages[dwStage].texture->Release();
962964 texstages[dwStage].texture = (glDirectDrawSurface7*)lpTexture;
@@ -965,7 +967,7 @@
966968 }
967969 HRESULT WINAPI glDirect3DDevice7::SetTextureStageState(DWORD dwStage, D3DTEXTURESTAGESTATETYPE dwState, DWORD dwValue)
968970 {
969 - if(!this) return DDERR_INVALIDPARAMS;
 971+ if(!this) return DDERR_INVALIDOBJECT;
970972 if(dwStage > 7) return DDERR_INVALIDPARAMS;
971973 switch(dwState)
972974 {
@@ -1179,7 +1181,7 @@
11801182 }
11811183 HRESULT WINAPI glDirect3DDevice7::SetTransform(D3DTRANSFORMSTATETYPE dtstTransformStateType, LPD3DMATRIX lpD3DMatrix)
11821184 {
1183 - if(!this) return DDERR_INVALIDPARAMS;
 1185+ if(!this) return DDERR_INVALIDOBJECT;
11841186 switch(dtstTransformStateType)
11851187 {
11861188 case D3DTRANSFORMSTATE_WORLD:
@@ -1199,13 +1201,13 @@
12001202 }
12011203 HRESULT WINAPI glDirect3DDevice7::SetViewport(LPD3DVIEWPORT7 lpViewport)
12021204 {
1203 - if(!this) return DDERR_INVALIDPARAMS;
 1205+ if(!this) return DDERR_INVALIDOBJECT;
12041206 memcpy(&viewport,lpViewport,sizeof(D3DVIEWPORT7));
12051207 return D3D_OK;
12061208 }
12071209 HRESULT WINAPI glDirect3DDevice7::ValidateDevice(LPDWORD lpdwPasses)
12081210 {
1209 - if(!this) return DDERR_INVALIDPARAMS;
 1211+ if(!this) return DDERR_INVALIDOBJECT;
12101212 for(int i = 0; i < 8; i++)
12111213 {
12121214 switch(texstages[i].colorop)
@@ -1338,6 +1340,184 @@
13391341 return D3D_OK;
13401342 }
13411343
 1344+HRESULT glDirect3DDevice7::DeleteViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport)
 1345+{
 1346+ if(!this) return DDERR_INVALIDOBJECT;
 1347+ if(!lpDirect3DViewport) return DDERR_INVALIDPARAMS;
 1348+ for(int i = 0; i < maxviewports; i++)
 1349+ {
 1350+ if(viewports[i] == lpDirect3DViewport)
 1351+ {
 1352+ viewports[i]->SetCurrent(false);
 1353+ viewports[i]->Release();
 1354+ if(currentviewport == viewports[i]) currentviewport = NULL;
 1355+ viewports[i] = NULL;
 1356+ return D3D_OK;
 1357+ }
 1358+ }
 1359+ return DDERR_INVALIDPARAMS;
 1360+}
 1361+
 1362+HRESULT glDirect3DDevice7::NextViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport, LPDIRECT3DVIEWPORT3 *lplpAnotherViewport, DWORD dwFlags)
 1363+{
 1364+ if(!this) return DDERR_INVALIDOBJECT;
 1365+ if(!lpDirect3DViewport) return DDERR_INVALIDPARAMS;
 1366+ if(!lplpAnotherViewport) return DDERR_INVALIDPARAMS;
 1367+ FIXME("glDirect3DDevice7::NextViewport: stub");
 1368+ return DDERR_GENERIC;
 1369+}
 1370+
 1371+HRESULT glDirect3DDevice7::GetCurrentViewport(LPDIRECT3DVIEWPORT3 *lplpd3dViewport)
 1372+{
 1373+ if(!this) return DDERR_INVALIDOBJECT;
 1374+ if(!lplpd3dViewport) return DDERR_INVALIDPARAMS;
 1375+ if(!currentviewport) return D3DERR_NOCURRENTVIEWPORT;
 1376+ *lplpd3dViewport = currentviewport;
 1377+ currentviewport->AddRef();
 1378+ return D3D_OK;
 1379+}
 1380+
 1381+HRESULT glDirect3DDevice7::SetCurrentViewport(LPDIRECT3DVIEWPORT3 lpd3dViewport)
 1382+{
 1383+ if(!this) return DDERR_INVALIDOBJECT;
 1384+ if(!lpd3dViewport) return DDERR_INVALIDPARAMS;
 1385+ if(currentviewport == lpd3dViewport) return D3D_OK;
 1386+ for(int i = 0; i < maxviewports; i++)
 1387+ {
 1388+ if(lpd3dViewport == viewports[i])
 1389+ {
 1390+ viewports[i]->SetCurrent(true);
 1391+ currentviewport = (glDirect3DViewport3*)lpd3dViewport;
 1392+ return D3D_OK;
 1393+ }
 1394+ }
 1395+ return DDERR_INVALIDPARAMS;
 1396+}
 1397+
 1398+HRESULT glDirect3DDevice7::Begin(D3DPRIMITIVETYPE d3dpt, DWORD dwVertexTypeDesc, DWORD dwFlags)
 1399+{
 1400+ if(!this) return DDERR_INVALIDOBJECT;
 1401+ FIXME("glDirect3DDevice7::Begin: stub");
 1402+ return DDERR_GENERIC;
 1403+}
 1404+HRESULT glDirect3DDevice7::BeginIndexed(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwNumVertices, DWORD dwFlags)
 1405+{
 1406+ if(!this) return DDERR_INVALIDOBJECT;
 1407+ if(!lpvVertices) return DDERR_INVALIDPARAMS;
 1408+ FIXME("glDirect3DDevice7::BeginIndexed: stub");
 1409+ return DDERR_GENERIC;
 1410+}
 1411+HRESULT glDirect3DDevice7::Index(WORD wVertexIndex)
 1412+{
 1413+ if(!this) return DDERR_INVALIDOBJECT;
 1414+ FIXME("glDirect3DDevice7::Index: stub");
 1415+ return DDERR_GENERIC;
 1416+}
 1417+HRESULT glDirect3DDevice7::Vertex(LPVOID lpVertex)
 1418+{
 1419+ if(!this) return DDERR_INVALIDOBJECT;
 1420+ if(!lpVertex) return DDERR_INVALIDPARAMS;
 1421+ FIXME("glDirect3DDevice7::Vertex: stub");
 1422+ return DDERR_GENERIC;
 1423+}
 1424+HRESULT glDirect3DDevice7::End(DWORD dwFlags)
 1425+{
 1426+ if(!this) return DDERR_INVALIDOBJECT;
 1427+ FIXME("glDirect3DDevice7::End: stub");
 1428+ return DDERR_GENERIC;
 1429+}
 1430+
 1431+HRESULT glDirect3DDevice7::ComputeSphereVisibility3(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres, DWORD dwFlags, LPDWORD lpdwReturnValues)
 1432+{
 1433+ if(!this) return DDERR_INVALIDOBJECT;
 1434+ FIXME("glDirect3DDevice3::ComputeSphereVisibility: stub");
 1435+ return DDERR_GENERIC;
 1436+}
 1437+
 1438+HRESULT glDirect3DDevice7::GetCaps3(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc)
 1439+{
 1440+ if(!this) return DDERR_INVALIDOBJECT;
 1441+ if(!lpD3DHWDevDesc && !lpD3DHELDevDesc) return DDERR_INVALIDPARAMS;
 1442+ D3DDEVICEDESC desc = d3ddesc3;
 1443+ if(lpD3DHELDevDesc) *lpD3DHELDevDesc = desc;
 1444+ desc.dwDevCaps |= D3DDEVCAPS_HWRASTERIZATION;
 1445+ if(lpD3DHWDevDesc) *lpD3DHWDevDesc = desc;
 1446+ return D3D_OK;
 1447+}
 1448+
 1449+HRESULT glDirect3DDevice7::GetLightState(D3DLIGHTSTATETYPE dwLightStateType, LPDWORD lpdwLightState)
 1450+{
 1451+ if(!this) return DDERR_INVALIDOBJECT;
 1452+ if(!lpdwLightState)return DDERR_INVALIDPARAMS;
 1453+ switch(dwLightStateType)
 1454+ {
 1455+ default:
 1456+ return DDERR_INVALIDPARAMS;
 1457+ case D3DLIGHTSTATE_MATERIAL:
 1458+ *lpdwLightState = (DWORD)currentmaterial;
 1459+ return D3D_OK;
 1460+ case D3DLIGHTSTATE_AMBIENT:
 1461+ return GetRenderState(D3DRENDERSTATE_AMBIENT,lpdwLightState);
 1462+ case D3DLIGHTSTATE_COLORMODEL:
 1463+ *lpdwLightState = D3DCOLOR_RGB;
 1464+ return D3D_OK;
 1465+ case D3DLIGHTSTATE_FOGMODE:
 1466+ return GetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,lpdwLightState);
 1467+ case D3DLIGHTSTATE_FOGSTART:
 1468+ return GetRenderState(D3DRENDERSTATE_FOGSTART,lpdwLightState);
 1469+ case D3DLIGHTSTATE_FOGEND:
 1470+ return GetRenderState(D3DRENDERSTATE_FOGEND,lpdwLightState);
 1471+ case D3DLIGHTSTATE_FOGDENSITY:
 1472+ return GetRenderState(D3DRENDERSTATE_FOGDENSITY,lpdwLightState);
 1473+ case D3DLIGHTSTATE_COLORVERTEX:
 1474+ return GetRenderState(D3DRENDERSTATE_COLORVERTEX,lpdwLightState);
 1475+ }
 1476+}
 1477+HRESULT glDirect3DDevice7::SetLightState(D3DLIGHTSTATETYPE dwLightStateType, DWORD dwLightState)
 1478+{
 1479+ if(!this) return DDERR_INVALIDOBJECT;
 1480+ switch(dwLightStateType)
 1481+ {
 1482+ default:
 1483+ return DDERR_INVALIDPARAMS;
 1484+ case D3DLIGHTSTATE_MATERIAL:
 1485+ if(dwLightState == (DWORD)currentmaterial) return D3D_OK;
 1486+ if(!dwLightState) return DDERR_INVALIDPARAMS;
 1487+ for(int i = 0; i < materialcount; i++)
 1488+ {
 1489+ if((DWORD)materials[i] == dwLightState)
 1490+ {
 1491+ if(currentmaterial) currentmaterial->SetCurrent(false);
 1492+ materials[i]->SetCurrent(true);
 1493+ currentmaterial = materials[i];
 1494+ }
 1495+ }
 1496+ return D3D_OK;
 1497+ case D3DLIGHTSTATE_AMBIENT:
 1498+ return SetRenderState(D3DRENDERSTATE_AMBIENT,dwLightState);
 1499+ case D3DLIGHTSTATE_COLORMODEL:
 1500+ return D3D_OK;
 1501+ case D3DLIGHTSTATE_FOGMODE:
 1502+ return SetRenderState(D3DRENDERSTATE_FOGVERTEXMODE,dwLightState);
 1503+ case D3DLIGHTSTATE_FOGSTART:
 1504+ return SetRenderState(D3DRENDERSTATE_FOGSTART,dwLightState);
 1505+ case D3DLIGHTSTATE_FOGEND:
 1506+ return SetRenderState(D3DRENDERSTATE_FOGEND,dwLightState);
 1507+ case D3DLIGHTSTATE_FOGDENSITY:
 1508+ return SetRenderState(D3DRENDERSTATE_FOGDENSITY,dwLightState);
 1509+ case D3DLIGHTSTATE_COLORVERTEX:
 1510+ return SetRenderState(D3DRENDERSTATE_COLORVERTEX,dwLightState);
 1511+ }
 1512+}
 1513+
 1514+HRESULT glDirect3DDevice7::GetStats(LPD3DSTATS lpD3DStats)
 1515+{
 1516+ if(!this) return DDERR_INVALIDOBJECT;
 1517+ if(!lpD3DStats) return DDERR_INVALIDPARAMS;
 1518+ FIXME("glDirect3DDevice7::GetStats: stub");
 1519+ return DDERR_GENERIC;
 1520+}
 1521+
13421522 // IDirect3DDevice3 wrapper
13431523 glDirect3DDevice3::glDirect3DDevice3(glDirect3DDevice7 *glD3DDev7)
13441524 {
@@ -1352,7 +1532,7 @@
13531533
13541534 HRESULT WINAPI glDirect3DDevice3::QueryInterface(REFIID riid, void** ppvObj)
13551535 {
1356 - if(!this) return DDERR_INVALIDPARAMS;
 1536+ if(!this) return DDERR_INVALIDOBJECT;
13571537 if(riid == IID_IUnknown)
13581538 {
13591539 this->AddRef();
Index: ddraw/glDirect3DDevice.h
@@ -128,6 +128,7 @@
129129 HRESULT AddViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport);
130130 HRESULT DeleteViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport);
131131 HRESULT NextViewport(LPDIRECT3DVIEWPORT3 lpDirect3DViewport, LPDIRECT3DVIEWPORT3 *lplpAnotherViewport, DWORD dwFlags);
 132+ HRESULT GetCurrentViewport(LPDIRECT3DVIEWPORT3 *lplpd3dViewport);
132133 HRESULT SetCurrentViewport(LPDIRECT3DVIEWPORT3 lpd3dViewport);
133134 HRESULT Begin(D3DPRIMITIVETYPE d3dpt, DWORD dwVertexTypeDesc, DWORD dwFlags);
134135 HRESULT BeginIndexed(D3DPRIMITIVETYPE dptPrimitiveType, DWORD dwVertexTypeDesc, LPVOID lpvVertices, DWORD dwNumVertices, DWORD dwFlags);
@@ -136,7 +137,6 @@
137138 HRESULT End(DWORD dwFlags);
138139 HRESULT ComputeSphereVisibility3(LPD3DVECTOR lpCenters, LPD3DVALUE lpRadii, DWORD dwNumSpheres, DWORD dwFlags, LPDWORD lpdwReturnValues);
139140 HRESULT GetCaps3(LPD3DDEVICEDESC lpD3DHWDevDesc, LPD3DDEVICEDESC lpD3DHELDevDesc);
140 - HRESULT GetCurrentViewport(LPDIRECT3DVIEWPORT3 *lplpd3dViewport);
141141 HRESULT GetLightState(D3DLIGHTSTATETYPE dwLightStateType, LPDWORD lpdwLightState);
142142 HRESULT SetLightState(D3DLIGHTSTATETYPE dwLightStateType, DWORD dwLightState);
143143 HRESULT GetStats(LPD3DSTATS lpD3DStats);
@@ -156,6 +156,7 @@
157157 TEXTURESTAGE texstages[8];
158158 glDirect3D7 *glD3D7;
159159 glDirect3DMaterial3 **materials;
 160+ glDirect3DMaterial3 *currentmaterial;
160161 int materialcount;
161162
162163 private:
@@ -177,6 +178,7 @@
178179 int texformats[8];
179180 int maxmaterials;
180181 glDirect3DViewport3 **viewports;
 182+ glDirect3DViewport3 *currentviewport;
181183 int viewportcount;
182184 int maxviewports;
183185 };
Index: ddraw/glDirect3DMaterial.cpp
@@ -98,6 +98,7 @@
9999 if(!this) return DDERR_INVALIDOBJECT;
100100 if(lpMat->dwSize != sizeof(D3DMATERIAL)) return DDERR_INVALIDPARAMS;
101101 memcpy(&material,lpMat,sizeof(D3DMATERIAL));
 102+ if(device && current) Sync();
102103 return D3D_OK;
103104 }
104105
@@ -104,5 +105,24 @@
105106 void glDirect3DMaterial3::unbind()
106107 {
107108 device = NULL;
 109+ current = false;
108110 handle = 0;
 111+}
 112+
 113+void glDirect3DMaterial3::SetCurrent(bool current)
 114+{
 115+ if(this->current == current) return;
 116+ this->current = current;
 117+ if(current) Sync();
 118+}
 119+
 120+void glDirect3DMaterial3::Sync()
 121+{
 122+ D3DMATERIAL7 mat7;
 123+ mat7.diffuse = material.diffuse;
 124+ mat7.ambient = material.ambient;
 125+ mat7.specular = material.specular;
 126+ mat7.emissive = material.emissive;
 127+ mat7.power = material.power;
 128+ device->SetMaterial(&mat7);
109129 }
\ No newline at end of file
Index: ddraw/glDirect3DMaterial.h
@@ -30,10 +30,13 @@
3131 HRESULT WINAPI GetHandle(LPDIRECT3DDEVICE3 lpDirect3DDevice, LPD3DMATERIALHANDLE lpHandle);
3232 HRESULT WINAPI GetMaterial(LPD3DMATERIAL lpMat);
3333 HRESULT WINAPI SetMaterial(LPD3DMATERIAL lpMat);
 34+ void Sync();
 35+ void SetCurrent(bool current);
3436 void unbind();
3537 D3DMATERIAL material;
3638 private:
3739 ULONG refcount;
 40+ bool current;
3841 glDirect3DDevice7 *device;
3942 D3DMATERIALHANDLE handle;
4043 };
Index: ddraw/glDirect3DTexture.cpp
@@ -65,14 +65,17 @@
6666 {
6767 if(!this) return DDERR_INVALIDOBJECT;
6868 FIXME("glDirect3DTexture2::GetHandle: stub");
 69+ return DDERR_GENERIC;
6970 }
7071 HRESULT WINAPI glDirect3DTexture2::Load(LPDIRECT3DTEXTURE2 lpD3DTexture2)
7172 {
7273 if(!this) return DDERR_INVALIDOBJECT;
7374 FIXME("glDirect3DTexture2::Load: stub");
 75+ return DDERR_GENERIC;
7476 }
7577 HRESULT WINAPI glDirect3DTexture2::PaletteChanged(DWORD dwStart, DWORD dwCount)
7678 {
7779 if(!this) return DDERR_INVALIDOBJECT;
7880 FIXME("glDirect3DTexture2::PaletteChanged: stub");
 81+ return DDERR_GENERIC;
7982 }
Index: ddraw/glDirect3DViewport.cpp
@@ -44,6 +44,7 @@
4545 for(int i = 0; i < 8; i++)
4646 lights[i] = NULL;
4747 refcount = 1;
 48+ current = false;
4849 }
4950
5051 glDirect3DViewport3::~glDirect3DViewport3()
@@ -242,6 +243,7 @@
243244 vp.dvClipX = viewport.dvClipX;
244245 vp.dvClipY = viewport.dvClipY;
245246 viewport = vp;
 247+ if(current && device) Sync();
246248 return D3D_OK;
247249 }
248250 HRESULT WINAPI glDirect3DViewport3::SetViewport2(LPD3DVIEWPORT2 lpData)
@@ -250,6 +252,7 @@
251253 if(!device) return D3DERR_VIEWPORTHASNODEVICE;
252254 if(!lpData) return DDERR_INVALIDPARAMS;
253255 viewport = *lpData;
 256+ if(current && device) Sync();
254257 return D3D_OK;
255258 }
256259 HRESULT WINAPI glDirect3DViewport3::TransformVertices(DWORD dwVertexCount, LPD3DTRANSFORMDATA lpData, DWORD dwFlags, LPDWORD lpOffscreen)
@@ -257,4 +260,23 @@
258261 if(!this) return DDERR_INVALIDOBJECT;
259262 FIXME("glDirect3DViewport3::TransformVertices: stub");
260263 return DDERR_GENERIC;
 264+}
 265+
 266+void glDirect3DViewport3::SetCurrent(bool current)
 267+{
 268+ if(this->current && current) return;
 269+ this->current = current;
 270+ if(current && device) Sync();
 271+}
 272+
 273+void glDirect3DViewport3::Sync()
 274+{
 275+ D3DVIEWPORT7 vp7;
 276+ vp7.dwX = viewport.dwX;
 277+ vp7.dwY = viewport.dwY;
 278+ vp7.dwHeight = viewport.dwHeight;
 279+ vp7.dwWidth = viewport.dwWidth;
 280+ vp7.dvMinZ = viewport.dvMinZ;
 281+ vp7.dvMaxZ = viewport.dvMaxZ;
 282+ device->SetViewport(&vp7);
261283 }
\ No newline at end of file
Index: ddraw/glDirect3DViewport.h
@@ -48,6 +48,8 @@
4949 HRESULT WINAPI SetViewport(LPD3DVIEWPORT lpData);
5050 HRESULT WINAPI SetViewport2(LPD3DVIEWPORT2 lpData);
5151 HRESULT WINAPI TransformVertices(DWORD dwVertexCount, LPD3DTRANSFORMDATA lpData, DWORD dwFlags, LPDWORD lpOffscreen);
 52+ void SetCurrent(bool current);
 53+ void Sync();
5254 private:
5355 ULONG refcount;
5456 glDirect3DLight *lights[8];
@@ -59,6 +61,7 @@
6062 D3DVALUE maxY;
6163 D3DVALUE scaleX;
6264 D3DVALUE scaleY;
 65+ bool current;
6366 };
6467
6568 #endif //__GLDIRECT3DVIEWPORT_H
\ No newline at end of file
Index: ddraw/glDirectDrawSurface.cpp
@@ -22,6 +22,7 @@
2323 #include "glDirect3DDevice.h"
2424 #include "glDirectDraw.h"
2525 #include "glDirectDrawSurface.h"
 26+#include "glDirect3DTexture.h"
2627 #include "glDirectDrawPalette.h"
2728 #include "glDirectDrawClipper.h"
2829 #include "glRenderer.h"
@@ -519,6 +520,12 @@
520521 return DD_OK;
521522 }
522523 }
 524+ if(riid == IID_IDirect3DTexture2)
 525+ {
 526+ this->AddRef();
 527+ *ppvObj = new glDirect3DTexture2(this);
 528+ return DD_OK;
 529+ }
523530 ERR(E_NOINTERFACE);
524531 }
525532 ULONG WINAPI glDirectDrawSurface7::AddRef()