X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=platform%2Fwin32%2FGenaDrive%2FDirect.cpp;h=da86b16f77a06c9c9adccf1e50e24b6a87000da4;hb=efcba75f8a730340df6c1b679a207723f98d1ee6;hp=07e874764cf228bfe0e41746b4f93c1d1e4bd4c4;hpb=03a265e5ebabff7adbb4f97387f81e9b0428dbee;p=picodrive.git diff --git a/platform/win32/GenaDrive/Direct.cpp b/platform/win32/GenaDrive/Direct.cpp index 07e8747..da86b16 100644 --- a/platform/win32/GenaDrive/Direct.cpp +++ b/platform/win32/GenaDrive/Direct.cpp @@ -1,5 +1,6 @@ #include "app.h" +#ifdef USE_D3D // d3d static IDirect3D8 *Direct3D=NULL; IDirect3DDevice8 *Device=NULL; @@ -16,6 +17,7 @@ struct CustomVertex #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1) static CustomVertex VertexList[4]; +#endif // ddraw #include @@ -56,7 +58,7 @@ static int DirectDrawInit() // Create the backbuffer surface ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_3DDEVICE; + ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | DDSCAPS_SYSTEMMEMORY; ddsd.dwWidth = EmuWidth; ddsd.dwHeight = EmuHeight; @@ -93,7 +95,7 @@ static int DirectScreenDDraw() ret = m_pddsBackBuffer->Lock(NULL, &sd, DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT|DDLOCK_WRITEONLY, NULL); if (ret) { LOGFAIL(); return 1; } - //dprintf2("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount); + //lprintf("w: %i h: %i pi: %i pf: %i\n", sd.dwWidth, sd.dwHeight, sd.lPitch, sd.ddpfPixelFormat.dwRGBBitCount); if (sd.ddpfPixelFormat.dwRGBBitCount == 32) { @@ -108,6 +110,20 @@ static int DirectScreenDDraw() dst = (int *)((char *)dst + sd.lPitch); } } + else if (sd.ddpfPixelFormat.dwRGBBitCount == 24) /* wine uses this for me */ + { + void *dst = sd.lpSurface; + for (y = 0; y < EmuHeight; y++) + { + unsigned char *dst1 = (unsigned char *) dst; + for (x = 0; x < EmuWidth; x++, dst1 += 3) + { + int s = *ps++; + dst1[2] = (s&0xf800)>>8; dst1[1] = (s&0x07e0)>>3; dst1[0] = s<<3; // BGR + } + dst = (void *)((char *)dst + sd.lPitch); + } + } else if (sd.ddpfPixelFormat.dwRGBBitCount == 16) { unsigned short *dst = (unsigned short *)sd.lpSurface; @@ -144,7 +160,9 @@ static int DirectClearDDraw(unsigned int colour) static int DirectPresentDDraw() { - int ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, NULL, DDBLT_WAIT, NULL); + int ret = 0; + if (FrameRectMy.right - FrameRectMy.left > 0 && FrameRectMy.bottom - FrameRectMy.top > 0) + ret = m_pddsFrontBuffer->Blt(&FrameRectMy, m_pddsBackBuffer, &EmuScreenRect, DDBLT_WAIT, NULL); if (ret) { LOGFAIL(); return 1; } return 0; } @@ -154,6 +172,7 @@ static int DirectPresentDDraw() int DirectInit() { +#if USE_D3D D3DPRESENT_PARAMETERS d3dpp; D3DDISPLAYMODE mode; int i,u,ret=0; @@ -242,14 +261,14 @@ fail0: RELEASE(Direct3D) // error("Failed to use Direct3D, trying DirectDraw.."); - +#endif // try DirectDraw return DirectDrawInit(); } void DirectExit() { - //FontExit(); +#ifdef USE_D3D TexScreenExit(); // d3d @@ -257,10 +276,36 @@ void DirectExit() RELEASE(DirectBack) RELEASE(Device) RELEASE(Direct3D) - +#endif DirectExitDDraw(); } +int DirectClear(unsigned int colour) +{ +#ifdef USE_D3D + if (Device != NULL) { + Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0); + return 0; + } +#endif + + return DirectClearDDraw(colour); +} + +int DirectPresent() +{ +#ifdef USE_D3D + if (Device != NULL) { + Device->Present(NULL,NULL,NULL,NULL); + return 0; + } +#endif + + return DirectPresentDDraw(); +} + +#ifdef USE_D3D +#define PI 3.14159265f static int MakeVertexList() { @@ -303,24 +348,6 @@ static int MakeVertexList() return 0; } -int DirectClear(unsigned int colour) -{ - if (Device == NULL) - return DirectClearDDraw(colour); - - Device->Clear(0,NULL,D3DCLEAR_TARGET,colour,1.0f,0); - return 0; -} - -int DirectPresent() -{ - if (Device == NULL) - return DirectPresentDDraw(); - - Device->Present(NULL,NULL,NULL,NULL); - return 0; -} - static int SetupMatrices() { D3DXVECTOR3 eye ( 0.0f, 0.0f, 0.0f ); @@ -365,7 +392,7 @@ int DirectScreen() TexScreenSwizzle(); #else ret=TexScreenLinear(); - if (ret) dprintf2("TexScreenLinear failed\n"); + if (ret) lprintf("TexScreenLinear failed\n"); #endif SetupMatrices(); @@ -374,7 +401,7 @@ int DirectScreen() // Copy vertices in: VertexBuffer->Lock(0,sizeof(VertexList),&lock,0); - if (lock==NULL) { dprintf2("VertexBuffer->Lock failed\n"); return 1; } + if (lock==NULL) { lprintf("VertexBuffer->Lock failed\n"); return 1; } memcpy(lock,VertexList,sizeof(VertexList)); VertexBuffer->Unlock(); @@ -387,3 +414,10 @@ int DirectScreen() return 0; } +#else +int DirectScreen() +{ + return DirectScreenDDraw(); +} +#endif +