diff --git a/CMakeLists.txt b/CMakeLists.txt index 690923f1c..e6374c252 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,9 +53,6 @@ endfunction() include(CMakeDependentOption) option(PROJECT_FOLDERS "Put source files into subfolders in project file" ON) option(USE_CONSOLE "Build dedicated server" OFF) -CMAKE_DEPENDENT_OPTION(USE_GL "Enable OpenGL support" ON "NOT USE_CONSOLE" OFF) -# DirectX is disabled because it misses essential features -CMAKE_DEPENDENT_OPTION(USE_DIRECTX "Enable DirectX support" OFF "WIN32 AND NOT USE_CONSOLE" OFF) CMAKE_DEPENDENT_OPTION(USE_SDL_MAINLOOP "Use SDL to create windows etc." OFF "NOT USE_CONSOLE" OFF) CMAKE_DEPENDENT_OPTION(USE_X11 "Use X11 to create windows etc." ON "UNIX AND NOT APPLE AND NOT USE_SDL_MAINLOOP AND NOT USE_CONSOLE" OFF) @@ -220,10 +217,6 @@ set(OC_CLONK_SOURCES src/graphics/Bitmap256.cpp src/graphics/Bitmap256.h src/graphics/C4Draw.cpp - src/graphics/C4DrawD3D.cpp - src/graphics/C4DrawD3D.h - src/graphics/C4DrawD3DShader.cpp - src/graphics/C4DrawD3DShader.h src/graphics/C4DrawGL.cpp src/graphics/C4DrawGLCtx.cpp src/graphics/C4DrawGL.h @@ -1310,7 +1303,7 @@ if(WIN32) set(HAVE_DBGHELP ${DBGHELP_FOUND}) endif() -if(USE_GL) +if(NOT USE_CONSOLE) include(FindOpenGL) FINDLIB(GLEW_LIBRARIES NAMES GLEW glew32 glew32s) FIND_PATH(GLEW_INCLUDE_DIR NAMES GL/glew.h) @@ -1320,28 +1313,6 @@ if(USE_GL) ) include_directories(${GLEW_INCLUDE_DIR}) endif() -if(USE_DIRECTX) - if(EXISTS $ENV{DXSDK_DIR}) - list(APPEND CMAKE_INCLUDE_PATH $ENV{DXSDK_DIR}/Include) - if(CMAKE_CL_64) - list(APPEND CMAKE_LIBRARY_PATH $ENV{DXSDK_DIR}/Lib/x64) - else() - list(APPEND CMAKE_LIBRARY_PATH $ENV{DXSDK_DIR}/Lib/x86) - endif() - endif() - FINDLIB(DIRECT3D_LIBRARIES d3d9) - FINDLIB(DIRECT3DX_LIBRARIES d3dx9) - FIND_PATH(DIRECT3D_INCLUDE_DIR NAMES d3d9.h) - FIND_PATH(DIRECT3DX_INCLUDE_DIR NAMES d3dx9.h) - target_link_libraries(openclonk - ${DIRECT3D_LIBRARIES} - ${DIRECT3DX_LIBRARIES} - ) - include_directories( - ${DIRECT3D_INCLUDE_DIR} - ${DIRECT3DX_INCLUDE_DIR} - ) -endif() if(USE_GTK) SET(WITH_DEVELOPER_MODE ${GTK_FOUND}) SET(WITH_GLIB ${GTK_FOUND}) diff --git a/config.h.cmake b/config.h.cmake index c38a58653..c8e1ed003 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -157,12 +157,6 @@ /* dedicated server mode */ #cmakedefine USE_CONSOLE 1 -/* DirectX graphics */ -#cmakedefine USE_DIRECTX 1 - -/* OpenGL graphics */ -#cmakedefine USE_GL 1 - /* MP3 music */ #cmakedefine USE_MP3 1 diff --git a/src/config/C4Config.cpp b/src/config/C4Config.cpp index 55e788014..2124bc215 100644 --- a/src/config/C4Config.cpp +++ b/src/config/C4Config.cpp @@ -111,7 +111,6 @@ void C4ConfigGraphics::CompileFunc(StdCompiler *pComp) pComp->Value(mkNamingAdapt(BitDepth, "BitDepth", 32 ,false, true)); pComp->Value(mkNamingAdapt(Windowed, "Windowed", 0 ,false, true)); pComp->Value(mkNamingAdapt(PXSGfx, "PXSGfx" , 1 )); - pComp->Value(mkNamingAdapt(Engine, "Engine" , 1 ,false, true)); pComp->Value(mkNamingAdapt(Gamma1, "Gamma1" , 0 )); pComp->Value(mkNamingAdapt(Gamma2, "Gamma2" , 0x808080 )); pComp->Value(mkNamingAdapt(Gamma3, "Gamma3" , 0xffffff )); @@ -357,10 +356,6 @@ bool C4Config::Load(const char *szConfigFile) if (fWinSock) WSACleanup(); #endif General.DefaultLanguage(); -#if defined USE_GL && !defined USE_DIRECTX - if (Graphics.Engine == GFXENGN_DIRECTX || Graphics.Engine == GFXENGN_DIRECTXS) - Graphics.Engine = GFXENGN_OPENGL; -#endif // bit depth sanity check (might be corrupted by resolution check bug in old version) if (Graphics.BitDepth < 16) { diff --git a/src/config/C4Config.h b/src/config/C4Config.h index d460a580e..1bab4a2d1 100644 --- a/src/config/C4Config.h +++ b/src/config/C4Config.h @@ -112,7 +112,6 @@ public: int32_t ShowCrewCNames; // show clonk names above clonks? int32_t BitDepth; // used bit depth for newgfx int32_t PXSGfx; // show PXS-graphics (instead of sole pixels) - int32_t Engine; // 0: D3D; 1: OpenGL; int32_t Gamma1, Gamma2, Gamma3; // gamma ramps int32_t Currency; // default wealth symbolseb int32_t RenderInactiveEM; // draw vieports even if inactive in CPEM diff --git a/src/editor/C4ConsoleWin32.cpp b/src/editor/C4ConsoleWin32.cpp index 774445c4b..7afec7fe2 100644 --- a/src/editor/C4ConsoleWin32.cpp +++ b/src/editor/C4ConsoleWin32.cpp @@ -26,7 +26,6 @@ #include #include "C4ConsoleGUI.h" #include -#include #include #include #include @@ -309,9 +308,7 @@ class C4ToolsDlg::State: public C4ConsoleGUI::InternalState { public: HWND hDialog; -#ifdef USE_GL CStdGLCtx* pGLCtx; -#endif friend INT_PTR CALLBACK ToolsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam); HBITMAP hbmBrush,hbmBrush2; HBITMAP hbmLine,hbmLine2; @@ -372,13 +369,11 @@ public: if (hbmFill) DeleteObject(hbmFill); if (hbmIFT) DeleteObject(hbmIFT); if (hbmNoIFT) DeleteObject(hbmNoIFT); -#ifdef USE_GL if (pGLCtx) { delete pGLCtx; pGLCtx = NULL; } -#endif if (hDialog) DestroyWindow(hDialog); hDialog=NULL; } @@ -954,10 +949,8 @@ bool C4ConsoleGUI::ToolsDlgOpen(C4ToolsDlg *dlg) // Load bitmaps if necessary dlg->state->LoadBitmaps(Application.GetInstance()); // create target ctx for OpenGL rendering -#ifdef USE_GL if (pDraw && !dlg->state->pGLCtx) dlg->state->pGLCtx = pDraw->CreateContext(GetDlgItem(dlg->state->hDialog,IDC_PREVIEW), &Application); -#endif // Show window RestoreWindowPosition(dlg->state->hDialog, "Property", Config.GetSubkeyPath("Console")); SetWindowPos(dlg->state->hDialog,Console.hWindow,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE); @@ -1083,14 +1076,6 @@ void C4ToolsDlg::NeedPreviewUpdate() //Application.DDraw->AttachPrimaryPalette(sfcPreview); -#ifdef USE_DIRECTX - if (pD3D) - pD3D->BlitSurface2Window( sfcPreview, - 0,0,iPrvWdt,iPrvHgt, - GetDlgItem(state->hDialog,IDC_PREVIEW), - rect.left,rect.top,rect.right,rect.bottom); -#endif -#ifdef USE_GL // FIXME: This activates the wrong GL context. To avoid breaking the main window display, // FIXME: it has been disabled for the moment //if (pGLCtx->Select()) @@ -1098,7 +1083,6 @@ void C4ToolsDlg::NeedPreviewUpdate() // pGL->Blit(sfcPreview, 0,0,(float)iPrvWdt,(float)iPrvHgt, Application.pWindow->pSurface, rect.left,rect.top, iPrvWdt,iPrvHgt); // Application.pWindow->pSurface->PageFlip(); //} -#endif delete sfcPreview; } diff --git a/src/editor/C4ToolsDlg.cpp b/src/editor/C4ToolsDlg.cpp index 75c74498f..f7d95a11a 100644 --- a/src/editor/C4ToolsDlg.cpp +++ b/src/editor/C4ToolsDlg.cpp @@ -33,8 +33,7 @@ #include #include #include -#include -#ifdef USE_GL +#ifndef USE_CONSOLE #include #endif diff --git a/src/game/C4Application.cpp b/src/game/C4Application.cpp index 8a8b7cde9..2ad8cbfa0 100644 --- a/src/game/C4Application.cpp +++ b/src/game/C4Application.cpp @@ -172,8 +172,8 @@ bool C4Application::DoInit(int argc, char * argv[]) Log(C4ENGINEINFOLONG); LogF("Version: %s %s (%s)", C4VERSION, C4_OS, Revision.getData()); - // Initialize D3D/OpenGL - bool success = DDrawInit(this, !!isEditor, false, GetConfigWidth(), GetConfigHeight(), Config.Graphics.BitDepth, Config.Graphics.Engine, Config.Graphics.Monitor); + // Initialize OpenGL + bool success = DDrawInit(this, !!isEditor, false, GetConfigWidth(), GetConfigHeight(), Config.Graphics.BitDepth, Config.Graphics.Monitor); if (!success) { LogFatal(LoadResStr("IDS_ERR_DDRAW")); Clear(); ShowGfxErrorDialog(); return false; } if (!isEditor) diff --git a/src/graphics/C4Draw.cpp b/src/graphics/C4Draw.cpp index 4849c9aa0..1f540d969 100644 --- a/src/graphics/C4Draw.cpp +++ b/src/graphics/C4Draw.cpp @@ -28,7 +28,6 @@ #include "C4App.h" #include #include -#include #include #include #include @@ -1189,21 +1188,14 @@ void C4Draw::RemoveZoom(float & X, float & Y) Y = (Y - ZoomY) / Zoom + ZoomY; } -bool DDrawInit(C4AbstractApp * pApp, bool Editor, bool fUsePageLock, unsigned int iXRes, unsigned int iYRes, int iBitDepth, int Engine, unsigned int iMonitor) +bool DDrawInit(C4AbstractApp * pApp, bool Editor, bool fUsePageLock, unsigned int iXRes, unsigned int iYRes, int iBitDepth, unsigned int iMonitor) { // create engine - switch (Engine) - { - default: // Use the first engine possible if none selected -#ifdef USE_DIRECTX - case GFXENGN_DIRECTX: pDraw = new CStdD3D(false); break; - case GFXENGN_DIRECTXS: pDraw = new CStdD3D(true); break; -#endif -#ifdef USE_GL - case GFXENGN_OPENGL: pDraw = new CStdGL(); break; -#endif - case GFXENGN_NOGFX: pDraw = new CStdNoGfx(); break; - } + #ifndef USE_CONSOLE + pDraw = new CStdGL(); + #else + pDraw = new CStdNoGfx(); + #endif if (!pDraw) return false; // init it if (!pDraw->Init(pApp, Editor, fUsePageLock, iXRes, iYRes, iBitDepth, iMonitor)) diff --git a/src/graphics/C4Draw.h b/src/graphics/C4Draw.h index c931b9edf..64b03eec6 100644 --- a/src/graphics/C4Draw.h +++ b/src/graphics/C4Draw.h @@ -30,12 +30,6 @@ #include #endif -// engines -#define GFXENGN_DIRECTX 0 -#define GFXENGN_OPENGL 1 -#define GFXENGN_DIRECTXS 2 -#define GFXENGN_NOGFX 3 - // Global Draw access pointer extern C4Draw *pDraw; @@ -130,14 +124,12 @@ struct C4BltData // This structure is used by StdGL, too -#ifndef USE_DIRECTX -typedef struct _D3DGAMMARAMP +typedef struct _GAMMARAMP { WORD red [256]; WORD green[256]; WORD blue [256]; -} D3DGAMMARAMP; -#endif +} GAMMARAMP; // gamma ramp control class C4GammaControl @@ -146,7 +138,7 @@ private: void SetClrChannel(WORD *pBuf, BYTE c1, BYTE c2, int c3); // set color channel ramp protected: - D3DGAMMARAMP ramp; + GAMMARAMP ramp; public: C4GammaControl() { Default(); } // ctor @@ -212,7 +204,6 @@ public: #ifdef _WIN32 virtual CStdGLCtx *CreateContext(HWND, C4AbstractApp *) { return NULL; } #endif - virtual int GetEngine() = 0; // get indexed engine virtual bool OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) = 0; // reinit clipper for new resolution virtual bool IsOpenGL() { return false; } virtual bool IsShaderific() { return false; } @@ -325,7 +316,6 @@ protected: friend class C4Surface; friend class C4TexRef; friend class C4Pattern; - friend class CStdD3DShader; }; struct ZoomDataStackItem: public ZoomData @@ -340,5 +330,5 @@ bool UnLockSurfaceGlobal(C4Surface * sfcTarget); bool DLineSPix(int32_t x, int32_t y, int32_t col); bool DLineSPixDw(int32_t x, int32_t y, int32_t dwClr); -bool DDrawInit(C4AbstractApp * pApp, bool Editor, bool fUsePageLock, unsigned int iXRes, unsigned int iYRes, int iBitDepth, int Engine, unsigned int iMonitor); +bool DDrawInit(C4AbstractApp * pApp, bool Editor, bool fUsePageLock, unsigned int iXRes, unsigned int iYRes, int iBitDepth, unsigned int iMonitor); #endif // INC_STDDDRAW2 diff --git a/src/graphics/C4DrawD3D.cpp b/src/graphics/C4DrawD3D.cpp deleted file mode 100644 index 420665de3..000000000 --- a/src/graphics/C4DrawD3D.cpp +++ /dev/null @@ -1,1165 +0,0 @@ -/* - * OpenClonk, http://www.openclonk.org - * - * Copyright (c) 2002, 2004-2007 Sven Eberhardt - * Copyright (c) 2004-2011 Günther Brammer - * Copyright (c) 2007 Peter Wortmann - * Copyright (c) 2008 Matthes Bender - * Copyright (c) 2009 Nicolas Hake - * Copyright (c) 2010 Armin Burgmeier - * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de - * - * Portions might be copyrighted by other authors who have contributed - * to OpenClonk. - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * See isc_license.txt for full license and disclaimer. - * - * "Clonk" is a registered trademark of Matthes Bender. - * See clonk_trademark_license.txt for full license. - */ - -/* Direct3D implementation of NewGfx */ - -#include "C4Include.h" -#include - -#include - -#include -#include -#include -#include - -#ifdef USE_DIRECTX - -#include -#include -#include -#include - -CStdD3D::CStdD3D(bool fSoftware) -{ - this->fSoftware = fSoftware; - Default(); - // global ptr - pD3D = this; -} - -CStdD3D::~CStdD3D() -{ - Clear(); - pD3D=NULL; -} - -void CStdD3D::Default() -{ - C4Draw::Default(); - SceneOpen=false; - lpD3D=NULL; - lpDevice=NULL; - pVB=pVBClr=pVBClrTex=NULL; - ZeroMemory(&sfcBmpInfo, sizeof(sfcBmpInfo)); - bltState[0] = bltState[1] = bltState[2] = 0; - bltBaseState[0] = bltBaseState[1] = bltBaseState[2] = bltBaseState[3] = 0; - drawSolidState[0] = drawSolidState[1] = 0; - pSavedState = 0; - for (int i=0; iIntUnlock(); // cannot do this here or we can't preserve textures across GL reinitialization as required when changing multisampling - if (lpDevice) - { - EndScene(); - DeleteDeviceObjects(); - } - if (lpD3D) - { - if (lpDevice) { lpDevice->Release(); lpDevice=NULL; } - lpD3D->Release(); lpD3D=NULL; - } - SceneOpen=false; - C4Draw::Clear(); -} - - -/* Direct3D initialization */ - -bool CStdD3D::PageFlip(C4Rect *pSrcRt, C4Rect *pDstRt, C4Window * pWindow) -{ - RECT SrcRt, DstRt; - if (pSrcRt) - { - SrcRt.left = pSrcRt->x; - SrcRt.top = pSrcRt->y; - SrcRt.right = pSrcRt->x + pSrcRt->Wdt; - SrcRt.bottom = pSrcRt->y + pSrcRt->Hgt; - } - if (pDstRt) - { - DstRt.left = pDstRt->x; - DstRt.top = pDstRt->y; - DstRt.right = pDstRt->x + pDstRt->Wdt; - DstRt.bottom = pDstRt->y + pDstRt->Hgt; - } - // call from gfx thread only! - if (!pApp || !pApp->AssertMainThread()) return false; - // safety - if (!lpDevice) return false; - // end the scene and present it - EndScene(); - if (lpDevice->Present(pSrcRt ? &SrcRt : 0, pDstRt ? &DstRt : 0, pWindow ? pWindow->hWindow : 0, NULL) == D3DERR_DEVICELOST) - { - if (lpDevice->TestCooperativeLevel() == D3DERR_DEVICELOST) return false; - if (!RestoreDeviceObjects()) return false; - lpDevice->Present(NULL, NULL, NULL, NULL); - } - return true; -} - - -bool CStdD3D::BeginScene() -{ - // already open? - if (SceneOpen) return true; - // not active? - if (!Active) - if (!RestoreDeviceObjects()) - return false; - // do open - SceneOpen=(lpDevice->BeginScene() == D3D_OK); - if (!SceneOpen) return false; - // clear scene - //lpDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(rand()%256,rand()%256,rand()%256), 1.0f, 0L ); - // set some def values - // success - return true; -} - -void CStdD3D::FillBG(DWORD dwClr) -{ - if (lpDevice) lpDevice->Clear( 0, NULL, D3DCLEAR_TARGET, dwClr, 1.0f, 0L ); -} - -void CStdD3D::EndScene() -{ - // end scene, if open - if (!SceneOpen) return; - lpDevice->EndScene(); - SceneOpen=false; -} - -bool CStdD3D::UpdateClipper() -{ - // no render target? do nothing - if (!RenderTarget || !Active) return true; - // negative/zero? - int iWdt=Min(iClipX2, RenderTarget->Wdt-1)-iClipX1+1; - int iHgt=Min(iClipY2, RenderTarget->Hgt-1)-iClipY1+1; - int iX=iClipX1; if (iX<0) { iWdt+=iX; iX=0; } - int iY=iClipY1; if (iY<0) { iHgt+=iY; iY=0; } - if (iWdt<=0 || iHgt<=0) - { - ClipAll=true; - return true; - } - ClipAll=false; - // bound clipper to surface size - D3DVIEWPORT9 Clipper; - Clipper.X=iX; Clipper.Y=iY; Clipper.Width=iWdt; Clipper.Height=iHgt; - Clipper.MinZ=0.0f; Clipper.MaxZ=1.0f; - // set it - lpDevice->SetViewport(&Clipper); - return true; -} - - -bool CStdD3D::PrepareMaterial(StdMeshMaterial &mat) -{ - // TODO - return false; -} - -bool CStdD3D::PrepareRendering(C4Surface * sfcToSurface) -{ - // call from gfx thread only! - if (!pApp || !pApp->AssertMainThread()) return false; - // do not render to inactive fullscreen - if (!Active && !Editor) return false; - // device? - if (!lpDevice) return false; - // target? - if (!sfcToSurface) return false; - // target locked? - if (sfcToSurface->Locked) return false; - // target is already set as render target? - if (sfcToSurface != RenderTarget) - { - // target is a render-target? - if (!sfcToSurface->IsRenderTarget()) return false; - IDirect3DSurface9 *pDest=sfcToSurface->GetSurface(); - if (!pDest) return false; - // set target - EndScene(); - if (lpDevice->SetRenderTarget(0, pDest) != D3D_OK) - { - pDest->Release(); - return false; - } - RenderTarget=sfcToSurface; - pDest->Release(); - // new target might need new clipping - UpdateClipper(); - } - // start scene, if not already done - BeginScene(); - // done - return true; -} - -void CStdD3D::PerformBlt(C4BltData &rBltData, C4TexRef *pTex, DWORD dwModClr, bool fMod2, bool fExact) -{ - if (!lpDevice || !pVB) return; - - // globally modulated blit - int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE; - - assert(rBltData.byNumVertices < sizeof(bltClrVertices)/sizeof(*bltClrVertices)); - // write to vertex buffer - for (int i = 0; i < rBltData.byNumVertices; ++i) - { - bltClrVertices[i].x = rBltData.vtVtx[i].ftx; - bltClrVertices[i].y = rBltData.vtVtx[i].fty; - if (rBltData.pTransform) - rBltData.pTransform->TransformPoint(bltClrVertices[i].x, bltClrVertices[i].y); - // Compensate for D3D's half-a-pixel offset - // FIXME: Put this into a global transformation matrix or something - bltClrVertices[i].x -= 0.5; - bltClrVertices[i].y -= 0.5; - bltClrVertices[i].tu = rBltData.vtVtx[i].tx; - bltClrVertices[i].tv = rBltData.vtVtx[i].ty; - bltClrVertices[i].color = dwModClr; - } - - bltBaseState[iAdditive + (fMod2 ? C4GFXBLIT_MOD2 : 0)]->Apply(); - lpDevice->SetFVF(D3DFVF_C4CTVERTEX); - - // color mod map by pixel shader? - CStdD3DShader *pShader = NULL; - if (fUseClrModMap && HasShaders()) - { - bool fColoredFoW = pClrModMap->IsColored(); - pShader = pShaders[fMod2 * SHIDX_Mod2 + fColoredFoW * SHIDX_ColoredFoW]; - lpDevice->SetPixelShader(pShader->GetInterface()); - lpDevice->SetTexture(pShader->iInTexIndex, pTex->pTex); - C4Surface * pModSurface = pClrModMap->GetSurface(); - if (pModSurface->ppTex) lpDevice->SetTexture(pShader->iFoWTexIndex, (*(pModSurface->ppTex))->pTex); - const float mod_proj[4] = { 1.0f/(pClrModMap->GetResolutionX()* (*(pModSurface->ppTex))->iSizeX), - 1.0f/(pClrModMap->GetResolutionY()* (*(pModSurface->ppTex))->iSizeY), - float(pClrModMap->OffX), float(pClrModMap->OffY) - }; - lpDevice->SetPixelShaderConstantF(pShader->iFoWTransformIndex, mod_proj, 1); - lpDevice->SetSamplerState( pShader->iFoWTexIndex, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); - } - else - { - // set texture - lpDevice->SetTexture(0, pTex->pTex); - } - // override linear filter mode for exact blits - if (fExact) - { - lpDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_POINT); - lpDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_POINT); - } - // draw! - lpDevice->DrawPrimitiveUP( D3DPT_TRIANGLEFAN, rBltData.byNumVertices-2, bltClrVertices, sizeof(bltClrVertices[0]) ); - // done, cleanup - if (pShader) - { - lpDevice->SetPixelShader(NULL); - lpDevice->SetTexture(pShader->iInTexIndex, NULL); - lpDevice->SetTexture(pShader->iFoWTexIndex, NULL); - } -} - -void CStdD3D::PerformMesh(StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform *pTransform) -{ - // TODO: Implement this - for (int x = 0; x < twdt; x += 10) - for (int y = 0; y < thgt; y += 10) - this->DrawBoxDw(0, tx+x, ty+y, tx+Min(twdt, x+10.0f), ty+Min(thgt, y+10.0f), - (((x+y)/10)&1)?0xff00ff:0x00ff00); -} - -// get bit depth from surface format -unsigned int Format2BitDepth(D3DFORMAT format) -{ - switch (format) - { - case D3DFMT_X1R5G5B5: - case D3DFMT_R5G6B5: - return 16; - - case D3DFMT_X8R8G8B8: - case D3DFMT_A8R8G8B8: - return 32; - - default: - // unknown - return 0; - } -} - -bool CStdD3D::BlitTex2Window(C4TexRef *pTexRef, HDC hdcTarget, RECT &rtFrom, RECT &rtTo) -{ - // lock - if (!pTexRef->Lock()) return false; - // get bits - BYTE *pBits = (BYTE *) pTexRef->texLock.pBits; - if (!pBits) return false; - // get size - int fWdt = rtFrom.right-rtFrom.left; - int fHgt = rtFrom.bottom-rtFrom.top; - int tWdt = rtTo.right-rtTo.left; - int tHgt = rtTo.bottom-rtTo.top; - // adjust bitmap info - sfcBmpInfo.bmiHeader.biHeight = pTexRef->iSizeY; sfcBmpInfo.bmiHeader.biWidth = pTexRef->iSizeX; - // Same size - if ((fWdt==tWdt) && (fHgt==tHgt)) - return SetDIBitsToDevice(hdcTarget, rtTo.left, rtTo.top, fWdt, fHgt, rtFrom.left, rtFrom.top, 0, fWdt, pBits, &sfcBmpInfo, DIB_RGB_COLORS) > 0; - // Stretch - SetMapMode(hdcTarget,MM_TEXT); - int i = StretchDIBits(hdcTarget, rtTo.left, rtTo.top, tWdt, tHgt, rtFrom.left, rtFrom.top, fWdt, fHgt, pBits, &sfcBmpInfo, DIB_RGB_COLORS, SRCCOPY); - if (i == GDI_ERROR) return false; - return true; -} - -bool CStdD3D::BlitSurface2Window(C4Surface * sfcSource, - int fX, int fY, int fWdt, int fHgt, - HWND hWnd, - int tX, int tY, int tWdt, int tHgt) -{ - bool fOkay = false; - if (!sfcSource->Lock()) return false; - HDC hdcTarget=GetDC(hWnd); - if (hdcTarget) - { - // blit textures - // blit with basesfc? - bool fBaseSfc=false; - if (sfcSource->pMainSfc) if (sfcSource->pMainSfc->ppTex) fBaseSfc=true; - // calc stretch - float scaleX=(float) tWdt/fWdt; - float scaleY=(float) tHgt/fHgt; - // get involved texture offsets - int iTexSizeX=sfcSource->iTexSize; - int iTexSizeY=sfcSource->iTexSize; - int iTexX=fX/iTexSizeX; - int iTexY=fY/iTexSizeY; - int iTexX2=Min((fX+fWdt-1)/iTexSizeX +1, sfcSource->iTexX); - int iTexY2=Min((fY+fHgt-1)/iTexSizeY +1, sfcSource->iTexY); - C4TexRef **ppTex=sfcSource->ppTex+iTexY*sfcSource->iTexX+iTexX; - // blit from all these textures - C4TexRef **ppTexRow, *pBaseTex=NULL; - for (int iY=iTexY; iYiTexSize*iX; - int iBlitY=sfcSource->iTexSize*iY; - // get new texture source bounds - RECT fTexBlt; - fTexBlt.left = Max(fX-iBlitX, 0); - fTexBlt.top = Max(fY-iBlitY, 0); - fTexBlt.right = Min(fX+fWdt-iBlitX, iTexSizeX); - fTexBlt.bottom= Min(fY+fHgt-iBlitY, iTexSizeY); - // get new dest bounds - RECT tTexBlt; - tTexBlt.left = (long) ((fTexBlt.left +iBlitX-fX)*scaleX+tX); - tTexBlt.top = (long) ((fTexBlt.top +iBlitY-fY)*scaleY+tY); - tTexBlt.right = (long) ((fTexBlt.right +iBlitX-fX)*scaleX+tX); - tTexBlt.bottom= (long) ((fTexBlt.bottom+iBlitY-fY)*scaleY+tY); - // is there a base-surface to be blitted first? - if (fBaseSfc) - { - // then get this surface as same offset as from other surface - // assuming this is only valid as long as there's no texture management, - // organizing partially used textures together! - pBaseTex=*(sfcSource->pMainSfc->ppTex+(ppTex-sfcSource->ppTex)); - BlitTex2Window(pBaseTex, hdcTarget, fTexBlt, tTexBlt); - } - // blit this texture - BlitTex2Window(*ppTex, hdcTarget, fTexBlt, tTexBlt); - // next col - ++ppTex; - } - // next row - ppTex=ppTexRow+sfcSource->iTexX; - } - // done, release DC - ReleaseDC(hWnd,hdcTarget); - } - sfcSource->Unlock(); - return fOkay; -} - -bool CStdD3D::FindDisplayMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iMonitor) -{ - if (iColorDepth == 32) - return FindDisplayMode(iXRes, iYRes, D3DFMT_A8R8G8B8, iMonitor) || - FindDisplayMode(iXRes, iYRes, D3DFMT_X8R8G8B8, iMonitor); - else if (iColorDepth == 16) - return FindDisplayMode(iXRes, iYRes, D3DFMT_R5G6B5, iMonitor) || - FindDisplayMode(iXRes, iYRes, D3DFMT_A1R5G5B5, iMonitor); - else - return false; -} - -bool CStdD3D::FindDisplayMode(unsigned int iXRes, unsigned int iYRes, D3DFORMAT format, unsigned int iMonitor) -{ - bool fFound=false; - D3DDISPLAYMODE dmode; - // enumerate modes - int iNumModes=lpD3D->GetAdapterModeCount(iMonitor, format); - for (int i=0; iEnumAdapterModes(iMonitor, format, i, &dmode) == D3D_OK) - { - // size is OK? - if (dmode.Width==iXRes && dmode.Height==iYRes) - { - // compare with found one - if (fFound) - // try getting a mode that is close to 85Hz, rather than taking the one with highest refresh rate - // (which may set absurd modes on some devices) - if (Abs(85-dmode.RefreshRate)>Abs(85-dspMode.RefreshRate)) - // the previous one was better - continue; - // choose this one - fFound=true; - dspMode=dmode; - } - } - return fFound; -} - -bool CStdD3D::SetOutputAdapter(unsigned int iMonitor) -{ - // get associated monitor rect - HMONITOR hMon = lpD3D->GetAdapterMonitor(iMonitor); - if (!hMon) return Error("GetAdapterMonitor error"); - MONITORINFO nfo; ZeroMemory(&nfo, sizeof(nfo)); - nfo.cbSize = sizeof(MONITORINFO); - if (!GetMonitorInfo(hMon, &nfo)) return Error("GetMonitorInfo error"); - return true; -} - -bool CStdD3D::CreatePrimarySurfaces(bool Editor, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor) -{ - // FIXME: this needs to work with iXRes==iYRes==-1, which means "use the desktop resolution" - DebugLog("Init DX"); - DebugLog(" Create Direct3D9..."); - if ((lpD3D=Direct3DCreate9(D3D_SDK_VERSION))==NULL) return Error(" Direct3DCreate9 failure."); - // set monitor info (Monitor-var and target rect) - DebugLog(" SetOutput adapter..."); - // FIXME: Do not do resolution changes here, SetVideoMode will take care of that - if (!SetOutputAdapter(iMonitor)) - return Error(" Output adapter failure."); - - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - // set needed surface type - switch (iColorDepth) - { - case 16: dwSurfaceType=D3DFMT_A4R4G4B4; break; - case 32: dwSurfaceType=D3DFMT_A8R8G8B8; break; - } - - HRESULT hr; - HWND hWindow = pApp->pWindow->hWindow; - DebugLog(" Create Device..."); - if (!Editor) - { - // fullscreen mode - // pick a display mode - if (0) - { - // "Windowed fullscreen" - if (lpD3D->GetAdapterDisplayMode(iMonitor, &dspMode) != D3D_OK) - if (lpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dspMode) != D3D_OK) - return Error("Could not get current display mode"); - SetWindowPos(hWindow, HWND_TOP, 0, 0, iXRes,iYRes, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOMOVE); - d3dpp.Windowed = true; - } - else - { - // true fullscreen - if (!FindDisplayMode(iXRes, iYRes, iColorDepth, iMonitor)) - return Error("Display mode not supported"); - } - // fill present structure - d3dpp.BackBufferWidth = iXRes; - d3dpp.BackBufferHeight= iYRes; - d3dpp.BackBufferFormat= dspMode.Format; - d3dpp.BackBufferCount = 0; - d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; - d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; - hr = lpD3D->CreateDevice(iMonitor, fSoftware ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL, hWindow, - D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, - &d3dpp, &lpDevice); - } - else - { - // windowed mode - // get current display mode - if (lpD3D->GetAdapterDisplayMode(iMonitor, &dspMode) != D3D_OK) - if (lpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dspMode) != D3D_OK) - return Error("Could not get current display mode"); - d3dpp.Windowed = true; - d3dpp.BackBufferCount = 1; - d3dpp.SwapEffect = D3DSWAPEFFECT_COPY; - d3dpp.BackBufferWidth = dspMode.Width; - d3dpp.BackBufferHeight= dspMode.Height; - d3dpp.BackBufferFormat = dspMode.Format; - d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; - // create primary surface - hr = lpD3D->CreateDevice(iMonitor, fSoftware ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL, hWindow, - D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, - &d3dpp, &lpDevice); - // windowed mode: Try dfault adapter as well - if (hr != D3D_OK && iMonitor != D3DADAPTER_DEFAULT) - hr = lpD3D->CreateDevice(D3DADAPTER_DEFAULT, fSoftware ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL, hWindow, - D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, - &d3dpp, &lpDevice); - } - switch (hr) - { - case D3DERR_INVALIDCALL: return Error("CreateDevice: D3DERR_INVALIDCALL"); - case D3DERR_NOTAVAILABLE: return Error("CreateDevice: D3DERR_NOTAVAILABLE"); - case D3DERR_OUTOFVIDEOMEMORY: return Error("CreateDevice: D3DERR_OUTOFVIDEOMEMORY"); - case D3DERR_DRIVERINTERNALERROR: return Error("CreateDevice: D3DERR_DRIVERINTERNALERROR"); - case D3D_OK: break; - default: return Error("CreateDevice: unknown error"); - } - - // device successfully created? - if (!lpDevice) return Error("CreateDevice: unreported error"); - // store color depth - byByteCnt=iColorDepth/8; - PrimarySrfcFormat=d3dpp.BackBufferFormat; - // create bmi-header - ZeroMemory(&sfcBmpInfo, sizeof(sfcBmpInfo)); - sfcBmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - sfcBmpInfo.bmiHeader.biWidth = iXRes; - sfcBmpInfo.bmiHeader.biHeight = -int(iYRes); - sfcBmpInfo.bmiHeader.biPlanes = 1; - sfcBmpInfo.bmiHeader.biBitCount = Format2BitDepth(dspMode.Format); - sfcBmpInfo.bmiHeader.biCompression = BI_RGB; - // initialize device-dependent objects - if (!InitDeviceObjects()) - { - // cleanup - DeleteDeviceObjects(); - // failure - return false; - } - // update monitor rect by new screen size - if (!SetOutputAdapter(iMonitor)) return false; - // success! - return true; -} - -bool CStdD3D::OnResolutionChanged(unsigned int iXRes, unsigned int iYRes) -{ - assert(lpDevice); - // NOTE: This should be replaced by using a desktop-size video buffer and - // just clipping to the current resolution to improve performance - d3dpp.BackBufferWidth = iXRes; - d3dpp.BackBufferHeight = iYRes; - DeleteDeviceObjects(); - HRESULT hr = lpDevice->Reset(&d3dpp); - InitDeviceObjects(); - RestoreDeviceObjects(); - return hr == D3D_OK; -} - -bool CStdD3D::SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepthFIXME, unsigned int iMonitor, bool fFullScreen) -{ - // note that this should happen in fullscreen mode only! - // do not mess with real presetn parameters until resolution change worked - D3DPRESENT_PARAMETERS d3dpp; - // reinit window for new resolution - int iColorDepth = byByteCnt*8; - ZeroMemory( &d3dpp, sizeof(d3dpp) ); - HRESULT hr; - HWND hWindow = pApp->pWindow->hWindow; - // pick a display mode - if (!fFullScreen) - { - // "Windowed fullscreen" - if (lpD3D->GetAdapterDisplayMode(iMonitor, &dspMode) != D3D_OK) - if (lpD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dspMode) != D3D_OK) - return Error("Could not get current display mode"); - SetWindowPos(hWindow, HWND_TOP, 0, 0, iXRes, iYRes, SWP_NOOWNERZORDER | SWP_SHOWWINDOW | SWP_NOMOVE); - d3dpp.Windowed = true; - } - else - { - // true fullscreen - if (!FindDisplayMode(iXRes, iYRes, iColorDepth, iMonitor)) - return Error("Display mode not supported"); - } - // fill present structure - d3dpp.BackBufferWidth = iXRes; - d3dpp.BackBufferHeight= iYRes; - d3dpp.BackBufferFormat= dspMode.Format; - d3dpp.BackBufferCount = 0; - d3dpp.SwapEffect = D3DSWAPEFFECT_FLIP; - d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; - // reset device to these parameters - DeleteDeviceObjects(); - hr = lpDevice->Reset(&d3dpp); - if (hr != D3D_OK) - { - // reset failed - if (InitDeviceObjects()) - RestoreDeviceObjects(); // try restore at old resolution - switch (hr) - { - case D3DERR_INVALIDCALL: return Error(" CreateDevice: D3DERR_INVALIDCALL"); - case D3DERR_NOTAVAILABLE: return Error(" CreateDevice: D3DERR_NOTAVAILABLE"); - case D3DERR_OUTOFVIDEOMEMORY: return Error(" CreateDevice: D3DERR_OUTOFVIDEOMEMORY"); - case D3DERR_DRIVERINTERNALERROR: return Error(" CreateDevice: D3DERR_DRIVERINTERNALERROR"); - default: return Error(" CreateDevice: unknown error"); - } - } - // device successfully reset! Reflect changes - this->d3dpp = d3dpp; - // store color depth - byByteCnt=iColorDepth/8; - PrimarySrfcFormat=d3dpp.BackBufferFormat; - // update bmi-header - sfcBmpInfo.bmiHeader.biWidth = iXRes; - sfcBmpInfo.bmiHeader.biHeight = -int(iYRes); - sfcBmpInfo.bmiHeader.biBitCount = Format2BitDepth(dspMode.Format); - // reinit device-dependant objects - InitDeviceObjects(); - RestoreDeviceObjects(); - // update monitor rect by new screen size - if (!SetOutputAdapter(iMonitor)) return false; - // success! - return true; -} - -void CStdD3D::PerformPix(C4Surface * sfcDest, float tx, float ty, DWORD dwClr) -{ - // is render target? - if (!sfcDest->IsRenderTarget()) - // on non-rendertargets, just set using locks - { - sfcDest->SetPixDw((int)tx, (int)ty, dwClr); - return; - } - else if (sfcDest->IsLocked()) - { - DrawPixPrimary(sfcDest, int(tx), int(ty), dwClr); - return; - } - // on a render target, blit as a box (ugh!) - // set vertex buffer data - // vertex order: - // 0=upper left dwClr1 - // 1=lower left dwClr3 - // 2=lower right dwClr4 - // 3=upper right dwClr2 - float vtx[8]; - vtx[0] = tx ; vtx[1] = ty; - vtx[2] = tx ; vtx[3] = ty+1.0f; - vtx[4] = tx+1.0f; vtx[5] = ty+1.0f; - vtx[6] = tx+1.0f; vtx[7] = ty; - DrawQuadDw(sfcDest, vtx, dwClr, dwClr, dwClr, dwClr); -} - -void CStdD3D::DrawPixPrimary(C4Surface * sfcDest, int iX, int iY, DWORD dwClr) -{ - // Must be render target and locked - if (!sfcDest->IsRenderTarget() || !sfcDest->IsLocked()) return; - // set according to pixel format - BYTE *pBits = sfcDest->PrimarySurfaceLockBits; - int iPitch = sfcDest->PrimarySurfaceLockPitch; - DWORD *pPix32; WORD *pPix16; - switch (sfcDest->dwClrFormat) - { - case D3DFMT_X1R5G5B5: - // 16 bit 5-5-5 - pPix16=(WORD *) (pBits+iY*iPitch+iX*2); - *pPix16=WORD((dwClr & 0x000000f8) >> 3) - | WORD((dwClr & 0x0000f800) >> 6) - | WORD((dwClr & 0x00f80000) >> 9); - break; - - case D3DFMT_R5G6B5: - // 16 bit 5-6-5 - pPix16=(WORD *) (pBits+iY*iPitch+iX*2); - *pPix16=WORD((dwClr & 0x000000f8) >> 3) - | WORD((dwClr & 0x0000fc00) >> 5) - | WORD((dwClr & 0x00f80000) >> 8); - break; - - case D3DFMT_X8R8G8B8: - // 32 bit - pPix32=(DWORD *) (pBits+iY*iPitch+iX*4); - BltAlpha(*pPix32, dwClr); - break; - default: assert(false); break; // should not happen - } -} - -void CStdD3D::DrawQuadDw(C4Surface * sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4) -{ - // prepare rendering to target - if (!PrepareRendering(sfcTarget)) return; - // set blitting state - int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE; - drawSolidState[iAdditive]->Apply(); - lpDevice->SetRenderState( D3DRS_DESTBLEND, iAdditive ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA ); - lpDevice->SetStreamSource(0, pVBClr, 0, sizeof(C4CLRVERTEX)); - lpDevice->SetFVF(D3DFVF_C4CLRVERTEX); - // 2do: manual clipping? - // set vertex buffer data - float fX1 = (float) ipVtx[0] - 0.5f; - float fY1 = (float) ipVtx[1] - 0.5f; - float fX2 = (float) ipVtx[2] - 0.5f; - float fY2 = (float) ipVtx[3] - 0.5f; - float fX3 = (float) ipVtx[4] - 0.5f; - float fY3 = (float) ipVtx[5] - 0.5f; - float fX4 = (float) ipVtx[6] - 0.5f; - float fY4 = (float) ipVtx[7] - 0.5f; - // apply color modulation - if (BlitModulated) - { - ModulateClr(dwClr1, BlitModulateClr); - ModulateClr(dwClr2, BlitModulateClr); - ModulateClr(dwClr3, BlitModulateClr); - ModulateClr(dwClr4, BlitModulateClr); - } - // set vertices - clrVertices[0].x = fX1; clrVertices[0].y = fY1; clrVertices[0].color=dwClr1; - clrVertices[1].x = fX2; clrVertices[1].y = fY2; clrVertices[1].color=dwClr2; - clrVertices[2].x = fX3; clrVertices[2].y = fY3; clrVertices[2].color=dwClr3; - clrVertices[3].x = fX3; clrVertices[3].y = fY3; clrVertices[3].color=dwClr3; - clrVertices[4].x = fX4; clrVertices[4].y = fY4; clrVertices[4].color=dwClr4; - clrVertices[5].x = fX1; clrVertices[5].y = fY1; clrVertices[5].color=dwClr1; - if (fUseClrModMap) - for (int i = 0; i < 6; ++i) ModulateClr(clrVertices[i].color, pClrModMap->GetModAt((int)clrVertices[i].x, (int)clrVertices[i].y)); - // copy into vertex buffer - VOID* pVertices; - if ( pVBClr->Lock(0, sizeof(clrVertices), &pVertices, 0) != D3D_OK ) return; - memcpy(pVertices, clrVertices, sizeof(clrVertices)); - pVBClr->Unlock(); - // draw - lpDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 2 ); -} - -void CStdD3D::PerformLine(C4Surface * sfcTarget, float x1, float y1, float x2, float y2, DWORD dwClr, float width) -{ - // FIXME: zoom width - //dwClr |= 0xf0000000; - // render target? - if (sfcTarget->IsRenderTarget()) - if (!sfcTarget->IsLocked()) - { - // draw as primitive - if (!PrepareRendering(sfcTarget)) return; - // set blitting state - use src alpha channel als opacity because some systems cannot antialias otherwise - int iAdditive = dwBlitMode & C4GFXBLIT_ADDITIVE; - drawSolidState[iAdditive]->Apply(); - lpDevice->SetRenderState( D3DRS_DESTBLEND, iAdditive ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA ); - lpDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA); - lpDevice->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, true ); - lpDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true ); - lpDevice->SetStreamSource(0, pVBClr, 0, sizeof(C4CLRVERTEX)); - lpDevice->SetFVF(D3DFVF_C4CLRVERTEX); - // set vertex buffer data - float fX1 = (float) x1;// - 0.5f; - float fY1 = (float) y1;// - 0.5f; - float fX2 = (float) x2;// + 0.5f; - float fY2 = (float) y2;// + 0.5f; - clrVertices[0].x = fX1; clrVertices[0].y = fY1; clrVertices[0].color=dwClr; - clrVertices[1].x = fX2; clrVertices[1].y = fY2; clrVertices[1].color=dwClr; - clrVertices[2].x = fX2; clrVertices[2].y = fY2; clrVertices[2].color=dwClr; - clrVertices[3].x = fX1; clrVertices[3].y = fY1; clrVertices[3].color=dwClr; - if (fUseClrModMap) - for (int i = 0; i < 4; ++i) ModulateClr(clrVertices[i].color, pClrModMap->GetModAt((int)clrVertices[i].x, (int)clrVertices[i].y)); - // copy into vertex buffer - VOID* pVertices; - if ( pVBClr->Lock(0, sizeof(clrVertices[0])*4, &pVertices, 0) != D3D_OK ) return; - memcpy(pVertices, clrVertices, sizeof(clrVertices[0])*4); - pVBClr->Unlock(); - // draw - actually two lines, to ensure that the last pixels are drawn, too... - lpDevice->DrawPrimitive(D3DPT_LINELIST, 0, 2 ); - } - else - { - if (fUseClrModMap) - ModulateClr(dwClr, pClrModMap->GetModAt((int)((x1+x2)/2), (int)((y1+y2)/2))); - if (Abs(x1 - x2) > Abs(y1 - y2)) - { - // flip line direction - if (x2 < x1) - { - float tmp = x2; x2 = x1; x1 = tmp; - tmp = y2; y2 = y1; y1 = tmp; - } - // round coordinates - int32_t iX1 = BoundBy(int32_t(x1+.5f),0,sfcTarget->Wdt-1), - iX2 = BoundBy(int32_t(x2+.5f),0,sfcTarget->Wdt-1), - iY1 = BoundBy(int32_t(y1+.5f),0,sfcTarget->Hgt-1), - iY2 = BoundBy(int32_t(y2+.5f),0,sfcTarget->Hgt-1), - iDX = iX2 - iX1; - // single pixel case? - if (!iDX) { DrawPixPrimary(sfcTarget, iX1, iY1, dwClr); return; } - // calculate gradient - uint32_t g = ((uint32_t(Abs(iY2 - iY1)) << 16) / uint32_t(iX2 - iX1)) << 16; - // alpha divisor - uint32_t alpha = dwClr >> 24; - if (alpha == 0) return; // invisible line - uint32_t div = (uint32_t(1 << 24) / alpha) << 8; - DWORD dwClrBase = dwClr & 0x00FFFFFF; - // current position - uint32_t sp = 0; - if (y2 > y1) - for (int32_t iX = 0, iY = 0; ; iX++) - { - // draw pixels - DWORD dwClr1 = dwClrBase + ((alpha + sp / div) << 24), - dwClr2 = dwClrBase + ((255 - sp / div) << 24); - DrawPixPrimary(sfcTarget, iX1+iX, iY1+iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX1+iX, iY1+iY+1, dwClr2); - if (iX * 2 >= iDX) break; - DrawPixPrimary(sfcTarget, iX2-iX, iY2-iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX2-iX, iY2-iY-1, dwClr2); - if (iX * 2 + 1 >= iDX) break; - // next pixel - sp += g; if (sp < g) iY++; - } - else - for (int32_t iX = 0, iY = 0; ; iX++) - { - // draw pixels - DWORD dwClr1 = dwClrBase + ((alpha + sp / div) << 24), - dwClr2 = dwClrBase + ((255 - sp / div) << 24); - DrawPixPrimary(sfcTarget, iX1+iX, iY1+iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX1+iX, iY1+iY-1, dwClr2); - if (iX * 2 >= iDX) break; - DrawPixPrimary(sfcTarget, iX2-iX, iY2-iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX2-iX, iY2-iY+1, dwClr2); - if (iX * 2 + 1 >= iDX) break; - // next pixel - sp += g; if (sp < g) iY--; - } - } - else - { - // flip line direction - if (y2 < y1) - { - float tmp = y2; y2 = y1; y1 = tmp; - tmp = x2; x2 = x1; x1 = tmp; - } - // calculate gradient - uint32_t g = uint32_t( Abs(x2 - x1) / (y2 - y1) * 4294967296.0f ); - // round coordinates - int32_t iX1 = BoundBy(int32_t(x1+.5f),0,sfcTarget->Wdt-1), - iX2 = BoundBy(int32_t(x2+.5f),0,sfcTarget->Wdt-1), - iY1 = BoundBy(int32_t(y1+.5f),0,sfcTarget->Hgt-1), - iY2 = BoundBy(int32_t(y2+.5f),0,sfcTarget->Hgt-1), - iDY = iY2 - iY1; - // single pixel case? - if (!iDY) { DrawPixPrimary(sfcTarget, iX1, iY1, dwClr); return; } - // alpha divisor - uint32_t alpha = dwClr >> 24; - if (alpha == 0) return; // invisible line - uint32_t div = (uint32_t(1 << 24) / alpha) << 8; - DWORD dwClrBase = dwClr & 0x00FFFFFF; - // current position - uint32_t sp = 0; - if (x2 > x1) - for (int32_t iY = 0, iX = 0; ; iY++) - { - // draw pixels - DWORD dwClr1 = dwClrBase + ((alpha + sp / div) << 24), - dwClr2 = dwClrBase + ((255 - sp / div) << 24); - DrawPixPrimary(sfcTarget, iX1+iX, iY1+iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX1+iX+1, iY1+iY, dwClr2); - if (iY * 2 >= iDY) break; - DrawPixPrimary(sfcTarget, iX2-iX, iY2-iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX2-iX-1, iY2-iY, dwClr2); - if (iY * 2 + 1 >= iDY) break; - // next pixel - sp += g; if (sp < g) iX++; - } - else - for (int32_t iY = 0, iX = 0; ; iY++) - { - // draw pixels - DWORD dwClr1 = dwClrBase + ((alpha + sp / div) << 24), - dwClr2 = dwClrBase + ((255 - sp / div) << 24); - DrawPixPrimary(sfcTarget, iX1+iX, iY1+iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX1+iX-1, iY1+iY, dwClr2); - if (iY * 2 >= iDY) break; - DrawPixPrimary(sfcTarget, iX2-iX, iY2-iY, dwClr1); - if (sp) DrawPixPrimary(sfcTarget, iX2-iX+1, iY2-iY, dwClr2); - if (iY * 2 + 1 >= iDY) break; - // next pixel - sp += g; if (sp < g) iX--; - } - } - } - else /* if(!sfcTarget->IsRenderTarget()) */ - { - if (!LockSurfaceGlobal(sfcTarget)) return; - ForLine((int)x1,(int)y1,(int)x2,(int)y2,&DLineSPixDw,dwClr); - UnLockSurfaceGlobal(sfcTarget); - } -} - -bool CStdD3D::InitDeviceObjects() -{ - D3DCAPS9 d3dCaps; - pD3D->lpDevice->GetDeviceCaps(&d3dCaps); - MaxTexSize = d3dCaps.MaxTextureWidth; - bool fSuccess=true; - // Create shaders - for (int i=0; iInit(lpDevice, !!(i&SHIDX_Mod2), !!(i&SHIDX_ColoredFoW))) { fOK = false; break; } - } - if (!fOK) for (int i=0; iTestCooperativeLevel() == D3DERR_DEVICENOTRESET) lpDevice->Reset(&d3dpp); - // couldn't reset? - if (lpDevice->TestCooperativeLevel() != D3D_OK) return false; - bool fSuccess=true; - // restore primary/back - /* IDirect3DSurface9 *pPrimarySfc; - if (lpDevice->GetRenderTarget(0, &pPrimarySfc) != D3D_OK) - { Error("Could not get primary surface"); fSuccess=false; } - RenderTarget=lpPrimary; - lpPrimary->AttachSfc(pPrimarySfc,0,0); - lpPrimary->dwClrFormat=PrimarySrfcFormat; - lpPrimary->byBytesPP=Format2BitDepth(PrimarySrfcFormat)/8;*/ - // create vertex buffer - if ( lpDevice->CreateVertexBuffer(sizeof(bltVertices), 0, D3DFVF_C4VERTEX, D3DPOOL_DEFAULT, &pVB, NULL) != D3D_OK ) return false; - // fill initial data for vertex buffer - int i; - for (i=0; i<6; ++i) - { - bltVertices[i].z=0.9f; - bltVertices[i].rhw=1.0f; - } - // create solid color vertex buffer - if ( lpDevice->CreateVertexBuffer(sizeof(clrVertices), 0, D3DFVF_C4CLRVERTEX, D3DPOOL_DEFAULT, &pVBClr, NULL) != D3D_OK ) return false; - // fill initial data for vertex buffer - for (i=0; i<6; ++i) - { - clrVertices[i].z=0.9f; - clrVertices[i].rhw=1.0f; - } - // create color-texblit vertices - if ( lpDevice->CreateVertexBuffer(sizeof(bltClrVertices), 0, D3DFVF_C4CTVERTEX, D3DPOOL_DEFAULT, &pVBClrTex, NULL) != D3D_OK ) return false; - // fill initial data for vertex buffer - for (i=0; i<6; ++i) - { - bltClrVertices[i].z=0.9f; - bltClrVertices[i].rhw=1.0f; - } - // create state blocks - CreateStateBlock(&bltState[0], false, false, false, false, false); - CreateStateBlock(&bltState[1], true, false, false, false, false); - CreateStateBlock(&bltState[2], true, false, false, true, false); - CreateStateBlock(&drawSolidState[0], false, false, false, false, false); - CreateStateBlock(&drawSolidState[1], false, false, false, true, false); - CreateStateBlock(&bltBaseState[0], true, false, true, false, false); - CreateStateBlock(&bltBaseState[1], true, false, true, true, false); - CreateStateBlock(&bltBaseState[2], true, false, true, false, true); - CreateStateBlock(&bltBaseState[3], true, false, true, true, true); - // activate if successful - Active=fSuccess; - // restore gamma if active - if (Active) EnableGamma(); - // reset blit states - dwBlitMode = 0; - // done - return Active; -} - -template static inline void SafeRelease(IF *&pInterface) -{ - if (pInterface) - pInterface->Release(); - pInterface = 0; -} - -bool CStdD3D::InvalidateDeviceObjects() -{ - bool fSuccess=true; - // clear gamma - DisableGamma(); - // deactivate - Active=false; - // release state blocks - SafeRelease(bltState[0]); - SafeRelease(bltState[1]); - SafeRelease(bltState[2]); - SafeRelease(drawSolidState[0]); - SafeRelease(bltBaseState[0]); - SafeRelease(bltBaseState[1]); - SafeRelease(drawSolidState[1]); - SafeRelease(bltBaseState[2]); - SafeRelease(bltBaseState[3]); - SafeRelease(pSavedState); - // release vertex buffer - SafeRelease(pVBClr); - SafeRelease(pVB); - SafeRelease(pVBClrTex); - return fSuccess; -} - -bool CStdD3D::DeleteDeviceObjects() -{ - InvalidateDeviceObjects(); - bool fSuccess=true; - NoPrimaryClipper(); - // del main surfaces - RenderTarget=NULL; - for (int i=0; iBeginStateBlock(); - // set states - lpDevice->SetRenderState( D3DRS_LIGHTING, false ); - lpDevice->SetRenderState( D3DRS_MULTISAMPLEANTIALIAS, false ); // no antialiasing - lpDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true ); - lpDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA ); - lpDevice->SetRenderState( D3DRS_DESTBLEND, fAdditive ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA ); - /* // This isn't necessary, as a>=0 is equal to no alpha testing anyway - lpDevice->SetRenderState( D3DRS_ALPHATESTENABLE, true ); - lpDevice->SetRenderState( D3DRS_ALPHAREF, 0x00 ); - lpDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL ); - */ - lpDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID ); - lpDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); - lpDevice->SetRenderState( D3DRS_ZENABLE, false ); - lpDevice->SetRenderState( D3DRS_STENCILENABLE, false ); - lpDevice->SetRenderState( D3DRS_CLIPPING, true ); - lpDevice->SetRenderState( D3DRS_ANTIALIASEDLINEENABLE, false ); - lpDevice->SetRenderState( D3DRS_CLIPPLANEENABLE, false ); - lpDevice->SetRenderState( D3DRS_VERTEXBLEND, false ); - lpDevice->SetRenderState( D3DRS_INDEXEDVERTEXBLENDENABLE, false ); - lpDevice->SetRenderState( D3DRS_FOGENABLE, false ); - if (!fBaseTex) - { - lpDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); - lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); - lpDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, fSolid ? D3DTA_DIFFUSE : D3DTA_TEXTURE ); - lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, fSolid ? D3DTA_DIFFUSE : D3DTA_TEXTURE ); - } - else - { - lpDevice->SetTextureStageState( 0, D3DTSS_COLOROP, fMod2 ? D3DTOP_ADDSIGNED2X : D3DTOP_MODULATE ); - lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - lpDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); - lpDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); - lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); - lpDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); - } - lpDevice->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); - lpDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); - lpDevice->SetSamplerState( 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR ); - lpDevice->SetSamplerState( 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR ); - lpDevice->SetSamplerState( 0, D3DSAMP_MIPFILTER, D3DTEXF_NONE ); - lpDevice->SetTextureStageState( 0, D3DTSS_TEXCOORDINDEX, 0 ); - lpDevice->SetTextureStageState( 0, D3DTSS_TEXTURETRANSFORMFLAGS, D3DTTFF_DISABLE ); - lpDevice->SetSamplerState( 0, D3DSAMP_ADDRESSU , D3DTADDRESS_CLAMP ); - lpDevice->SetSamplerState( 0, D3DSAMP_ADDRESSV , D3DTADDRESS_CLAMP ); - // capture - return lpDevice->EndStateBlock(pBlock) == D3D_OK; -} - -void CStdD3D::SetTexture() -{ -} - -void CStdD3D::ResetTexture() -{ - if (Active) lpDevice->SetTexture(0, NULL); -} - -bool CStdD3D::ApplyGammaRamp(D3DGAMMARAMP &ramp, bool fForce) -{ - if (!lpDevice || (!Active && !fForce)) return false; - lpDevice->SetGammaRamp(0, D3DSGR_CALIBRATE, &ramp); - return true; -} - -bool CStdD3D::SaveDefaultGammaRamp(D3DGAMMARAMP &ramp) -{ - if (!lpDevice) return false; - lpDevice->GetGammaRamp(0, &ramp); - return true; -} - -void CStdD3D::TaskOut() -{ - InvalidateDeviceObjects(); -} - -void CStdD3D::TaskIn() -{ - RestoreDeviceObjects(); -} - -CStdD3D *pD3D=NULL; - -#endif // USE_DIRECTX - diff --git a/src/graphics/C4DrawD3D.h b/src/graphics/C4DrawD3D.h deleted file mode 100644 index be213035e..000000000 --- a/src/graphics/C4DrawD3D.h +++ /dev/null @@ -1,176 +0,0 @@ -/* - * OpenClonk, http://www.openclonk.org - * - * Copyright (c) 2002, 2005 Sven Eberhardt - * Copyright (c) 2005, 2009, 2011 Günther Brammer - * Copyright (c) 2009 Nicolas Hake - * Copyright (c) 2001-2009, RedWolf Design GmbH, http://www.clonk.de - * - * Portions might be copyrighted by other authors who have contributed - * to OpenClonk. - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * See isc_license.txt for full license and disclaimer. - * - * "Clonk" is a registered trademark of Matthes Bender. - * See clonk_trademark_license.txt for full license. - */ - -/* Direct3D implementation of NewGfx */ - -#if defined(USE_DIRECTX) && !defined(INC_STDD3D) -#define INC_STDD3D - -// debug memmgmt off -#ifdef _DEBUG -#ifdef _MSC_VER -#undef new -#endif // _MSC_VER -#endif // _DEBUG - -#include -#include -#include -#undef DrawText -#include - -// debug memmgmt on -#ifdef _DEBUG -#ifdef _MSC_VER -#define new new(_NORMAL_BLOCK, __FILE__, __LINE__) -#endif // _MSC_VER -#endif // _DEBUG - -// check version -#if (DIRECT3D_VERSION > 0x0900) -#error "Using DirectX > 9.0 headers! Program won't run on computers using DX 9.0!" -#endif - -// default Clonk vertex format -struct C4VERTEX -{ - FLOAT x, y, z, rhw; // transformed vertex pos - FLOAT tu, tv; // texture offsets -}; - -// vertex format for solid blits -struct C4CLRVERTEX -{ - FLOAT x, y, z, rhw; // transformed vertex pos - DWORD color; // blit color -}; - -// vertex format for ColorByOwner-blits -struct C4CTVERTEX -{ - FLOAT x, y, z, rhw; // transformed vertex pos - DWORD color; // overlay color - FLOAT tu, tv; // texture offsets -}; - -#define D3DFVF_C4VERTEX (D3DFVF_XYZRHW|D3DFVF_TEX1) -#define D3DFVF_C4CLRVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE) -#define D3DFVF_C4CTVERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1) - -typedef C4VERTEX C4VERTEXQUAD[4]; -typedef C4CLRVERTEX C4CLRVERTEXQUAD[4]; -typedef C4CTVERTEX C4CTVERTEXQUAD[4]; - -class CStdD3DShader; - -// direct draw encapsulation -class CStdD3D : public C4Draw -{ -public: - CStdD3D(bool fSoftware); - ~CStdD3D(); -protected: - IDirect3D9 *lpD3D; - IDirect3DDevice9 *lpDevice; - IDirect3DVertexBuffer9 *pVB; // prepared vertex buffer for blitting - IDirect3DVertexBuffer9 *pVBClr; // prepared vertex buffer for drawing in solid color - IDirect3DVertexBuffer9 *pVBClrTex;// prepared vertex buffer for blitting iwth color/tex-modulation - C4VERTEX bltVertices[8]; // prepared vertex data; need to insert x/y and u/v - C4CLRVERTEX clrVertices[8]; // prepared vertex data; need to insert x/y and color - C4CTVERTEX bltClrVertices[8]; // prepared vertex data; need to insert x/y, color and u/v - IDirect3DStateBlock9 *bltState[3]; // saved state block for blitting (0: copy; 1: blit; 2: blit additive) - IDirect3DStateBlock9 *bltBaseState[4]; // saved state block for blitting with a base face (0: normal; 1: additive; 2: mod2; 3: mod2+additive) - IDirect3DStateBlock9 *drawSolidState[2]; // saved state block for drawing in solid color (0: normal; 1: additive) - IDirect3DStateBlock9 *pSavedState; // state block to backup current state - D3DVIEWPORT9 WindowClipper; - D3DDISPLAYMODE dspMode; - D3DPRESENT_PARAMETERS d3dpp; // device present parameters - D3DFORMAT dwSurfaceType;// surface format for new textures - D3DFORMAT PrimarySrfcFormat;// surace format of primary surface - bool fSoftware; // software rendering - enum ShaderIndex - { - SHIDX_Mod2 = 1, - SHIDX_ColoredFoW = 2, - SHIDX_Size = 4, - }; - CStdD3DShader *pShaders[SHIDX_Size]; - BITMAPINFO sfcBmpInfo; // surface bits as bitmap bits info - bool SceneOpen; // set if a scene has begun -public: - // General - void Clear(); - void Default(); - bool PageFlip(C4Rect *pSrcRt=NULL, C4Rect *pDstRt=NULL, C4Window * pWindow = NULL); - bool BeginScene(); // prepare device for drawing - void EndScene(); // prepare device for surface locking, flipping etc. - virtual int GetEngine() { return fSoftware ? 2 : 0; } // get indexed engine - void TaskOut(); // user taskswitched the app away - void TaskIn(); // user tasked back - bool SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iMonitor, bool fFullScreen); - virtual bool OnResolutionChanged(unsigned int iXRes, unsigned int iYRes); // reinit clipper for new resolution - // Clipper - bool UpdateClipper(); // set current clipper to render target - virtual bool PrepareMaterial(StdMeshMaterial &mat); - // Surface - bool PrepareRendering(C4Surface * sfcToSurface); // check if/make rendering possible to given surface - // Blit - virtual void PerformMesh(StdMeshInstance &instance, float tx, float ty, float twdt, float thgt, DWORD dwPlayerColor, C4BltTransform* pTransform); - void PerformBlt(C4BltData &rBltData, C4TexRef *pTex, DWORD dwModClr, bool fMod2, bool fExact); - bool BlitTex2Window(C4TexRef *pTexRef, HDC hdcTarget, RECT &rtFrom, RECT &rtTo); - bool BlitSurface2Window(C4Surface * sfcSource, int fX, int fY, int fWdt, int fHgt, HWND hWnd, int tX, int tY, int tWdt, int tHgt); - void FillBG(DWORD dwClr=0); - // Drawing - void DrawQuadDw(C4Surface * sfcTarget, float *ipVtx, DWORD dwClr1, DWORD dwClr2, DWORD dwClr3, DWORD dwClr4); - void PerformLine(C4Surface * sfcTarget, float x1, float y1, float x2, float y2, DWORD dwClr, float width); - void PerformPix(C4Surface * sfcDest, float tx, float ty, DWORD dwCol); - void DrawPixPrimary(C4Surface * sfcDest, int tx, int ty, DWORD dwCol); - // Gamma - bool ApplyGammaRamp(D3DGAMMARAMP &ramp, bool fForce); - bool SaveDefaultGammaRamp(D3DGAMMARAMP &ramp); - // device objects - bool InitDeviceObjects(); // init device dependent objects - bool InitShaders(); // parse and set shaders - bool RestoreDeviceObjects(); // restore device dependent objects - bool InvalidateDeviceObjects(); // free device dependent objects - bool DeleteDeviceObjects(); // free device dependent objects - void SetTexture(); - void ResetTexture(); - bool DeviceReady() { return !!lpDevice; } - - bool CreateStateBlock(IDirect3DStateBlock9 **pBlock, bool fTransparent, bool fSolid, bool fBaseTex, bool fAdditive, bool fMod2); // capture state blocks for blitting - -protected: - bool FindDisplayMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iMonitor); - bool FindDisplayMode(unsigned int iXRes, unsigned int iYRes, D3DFORMAT format, unsigned int iMonitor); - virtual bool CreatePrimarySurfaces(bool Editor, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor); - bool SetOutputAdapter(unsigned int iMonitor); - inline bool HasShaders() const { return !!pShaders[0]; } - - - friend class C4Surface; - friend class C4TexRef; - friend class C4Pattern; -}; - -// Global D3D access pointer -extern CStdD3D *pD3D; - -#endif // defined(USE_DIRECTX) && !defined(INC_STDD3D) diff --git a/src/graphics/C4DrawD3DShader.cpp b/src/graphics/C4DrawD3DShader.cpp deleted file mode 100644 index 30293fb68..000000000 --- a/src/graphics/C4DrawD3DShader.cpp +++ /dev/null @@ -1,192 +0,0 @@ -/* - * OpenClonk, http://www.openclonk.org - * - * Copyright (c) 2009 Sven Eberhardt - * Copyright (c) 2009, RedWolf Design GmbH, http://www.clonk.de - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * "Clonk" is a registered trademark of Matthes Bender. */ - -/* Direct3D shader used for FoW-modulated blitting */ - -#include "C4Include.h" - -#ifdef USE_DIRECTX -#include - -static const char *szShaderCode = - "sampler in_tex; /* Blitted input texture */" - "\n" "sampler fow_tex; /* FogOfWar modulation texture */" - "\n" "" - "\n" "float4 fow_proj; /* Projection of FogOfWar-texture into screen space: xy=scale, zw=offset */" - "\n" "" - "\n" "struct PS_INPUT" - "\n" "{" - "\n" " float4 Color : COLOR0; /* Per-vertex modulation color */" - "\n" " float2 TexPos : TEXCOORD0; /* Texture position */" - "\n" " float2 ScreenPos : VPOS; /* Output screen position */" - "\n" "};" - "\n" "" - "\n" "struct PS_OUTPUT" - "\n" "{" - "\n" " float4 Color : COLOR; /* Calculated output color */" - "\n" "};" - "\n" "" - "\n" "/* Main shader function */" - "\n" "PS_OUTPUT MainExec(PS_INPUT In)" - "\n" "{" - "\n" " PS_OUTPUT Out;" - "\n" " /* Sample source texture */" - "\n" " float4 in_tex_color = tex2D(in_tex,In.TexPos);" - "\n" " /* Sample FoW texture */" - "\n" " float4 fow_tex_color = tex2D(fow_tex,(In.ScreenPos-fow_proj.zw)*fow_proj.xy);" - "\n" "#ifdef MOD2" - "\n" " /* Apply Mod2-modulation (x2 scale input color and signed add modulation color) */" - "\n" " Out.Color.rgb = saturate(in_tex_color.rgb*2 + In.Color.rgb - 0.5);" - "\n" "#else" - "\n" " /* Apply regular modulation */" - "\n" " Out.Color.rgb = In.Color.rgb * in_tex_color.rgb;" - "\n" "#endif" - "\n" " /* Apply FoW */" - "\n" "#ifdef COLORED_FOW" - "\n" " /* Colored FoW: Mix source color and FoW color */" - "\n" " Out.Color.rgb = Out.Color.rgb * fow_tex_color.a + fow_tex_color.rgb * (1.0 - fow_tex_color.a);" - "\n" "#else" - "\n" " /* Black FoW: Just darken */" - "\n" " Out.Color.rgb *= fow_tex_color.a;" - "\n" "#endif" - "\n" " /* Alpha values modulated */" - "\n" " Out.Color.a = In.Color.a * in_tex_color.a;" - "\n" " return Out;" - "\n" "}"; - - -CStdD3DShader::CStdD3DShader() : pDevice(NULL), pInterface(NULL), pConstTable(NULL), pCodeBuffer(NULL) -{ -} - -CStdD3DShader::~CStdD3DShader() -{ - Discard(); -} - -void CStdD3DShader::Release() -{ - // properly release interface - ReleaseCode(); - if (pInterface) { pInterface->Release(); pInterface = NULL; } - pDevice = NULL; -} - -void CStdD3DShader::ReleaseCode() -{ - // release init-time temp values - if (pConstTable) { pConstTable->Release(); pConstTable = NULL; } - if (pCodeBuffer) { pCodeBuffer->Release(); pCodeBuffer = NULL; } -} - -void CStdD3DShader::Discard() -{ - // discard interface without deleting - pCodeBuffer = NULL; - pConstTable = NULL; - pInterface = NULL; - pDevice = NULL; -} - -bool CStdD3DShader::Error(const char *szMsg) -{ - return pDraw->Error(FormatString("Direct3D Shader error: %s", szMsg).getData()); -} - -bool CStdD3DShader::Compile(bool fMod2, bool fColoredFoW) -{ - ID3DXBuffer *pErrMsg=NULL; - // load and compile shader - D3DXMACRO defines[3]; int i=0; - if (fMod2) - { - defines[i].Name = "MOD2"; - defines[i].Definition = "1"; - i++; - } - if (fColoredFoW) - { - defines[i].Name = "COLORED_FOW"; - defines[i].Definition = "1"; - i++; - } - defines[i].Name = 0; - defines[i].Definition = 0; - HRESULT hr = D3DXCompileShader(szShaderCode, strlen(szShaderCode), i?defines:NULL, NULL, "MainExec", D3DXGetPixelShaderProfile(pDevice), 0, &pCodeBuffer, &pErrMsg, &pConstTable); - if (hr != D3D_OK) - { - StdStrBuf errmsg; - errmsg.Format("D3DXCompileShaderFromFile error %x", static_cast(hr)); - if (pErrMsg) - { - errmsg.AppendFormat(": %*s", static_cast(pErrMsg->GetBufferSize()), static_cast(pErrMsg->GetBufferPointer())); - pErrMsg->Release(); - } - return Error(errmsg.getData()); - } - return true; -} - -int CStdD3DShader::GetConstRegister(const char *szName, D3DXREGISTER_SET eRegType) -{ - // get named register index for shader input - // errors are not fatal; shader will probably just not need this input - if (!pConstTable) return 0; - D3DXHANDLE hConstant = pConstTable->GetConstantByName(NULL, szName); - if (!hConstant) return 0; - D3DXCONSTANT_DESC constDesc; - UINT c=1; - HRESULT hr = pConstTable->GetConstantDesc(hConstant, &constDesc, &c); - if (hr != D3D_OK) return 0; - if (constDesc.RegisterSet != eRegType) return 0; - return constDesc.RegisterIndex; -} - -bool CStdD3DShader::CreateShader() -{ - // creating actual DX shader! - HRESULT hr = pDevice->CreatePixelShader((const DWORD *)pCodeBuffer->GetBufferPointer(), &pInterface); - if (hr != D3D_OK) return Error(FormatString("CreatePixelShader error %x", static_cast(hr)).getData()); - return true; -} - -bool CStdD3DShader::Init(IDirect3DDevice9 *pDevice, bool fMod2, bool fColoredFoW) -{ - // re-init? - if (pInterface) Release(); - // store device for easy acccess - this->pDevice = pDevice; - // compile code - if (!Compile(fMod2, fColoredFoW)) { Release(); return false; } - // get const registers - iInTexIndex = GetConstRegister("in_tex", D3DXRS_SAMPLER); - iFoWTexIndex = GetConstRegister("fow_tex", D3DXRS_SAMPLER); - iFoWTransformIndex = GetConstRegister("fow_proj", D3DXRS_FLOAT4); - // create actual shader on device - if (!CreateShader()) { Release(); return false; } - // del temp objects - ReleaseCode(); - // done, success! - return true; -} - - - -#endif diff --git a/src/graphics/C4DrawD3DShader.h b/src/graphics/C4DrawD3DShader.h deleted file mode 100644 index 3ddb980f5..000000000 --- a/src/graphics/C4DrawD3DShader.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * OpenClonk, http://www.openclonk.org - * - * Copyright (c) 2009 Sven Eberhardt - * Copyright (c) 2009, RedWolf Design GmbH, http://www.clonk.de - * - * Permission to use, copy, modify, and/or distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * "Clonk" is a registered trademark of Matthes Bender. */ - -/* Direct3D shader used for FoW-modulated blitting */ - -#if defined(USE_DIRECTX) && !defined(INC_STDD3DSHADER) -#define INC_STDD3DSHADER - -#include - -class CStdD3DShader -{ -private: - IDirect3DDevice9 *pDevice; // DX device parenting shader - IDirect3DPixelShader9 *pInterface; // DX interface - ID3DXConstantTable *pConstTable; // offsets of shader inputs - ID3DXBuffer *pCodeBuffer; // buffer containing shader bytecode - - void ReleaseCode(); // release init-time members only - - bool Compile(bool fMod22, bool fColoredFoW); // create shader byte code - int GetConstRegister(const char *szName, D3DXREGISTER_SET eRegType); // get named register index for shader input - bool CreateShader(); // create actual DX pixel shader object - - bool Error(const char *szMsg); // error to ddraw; always return false - -public: - // todo: Make those constants in the shader - int iInTexIndex, iFoWTexIndex, iFoWTransformIndex; // constant indices used to pass data to the shader - - CStdD3DShader(); - ~CStdD3DShader(); - - void Release(); // properly release interfaces - void Discard(); // zero members (e.g. after device has been destroyed) - - bool Init(IDirect3DDevice9 *pDevice, bool fMod2, bool fColoredFoW); - - IDirect3DPixelShader9 *GetInterface() const { return pInterface; } -}; - -#endif // defined(USE_DIRECTX) && !defined(INC_STDD3DSHADER) diff --git a/src/graphics/C4DrawGL.cpp b/src/graphics/C4DrawGL.cpp index ca8ae0f05..08e743f2a 100644 --- a/src/graphics/C4DrawGL.cpp +++ b/src/graphics/C4DrawGL.cpp @@ -36,7 +36,7 @@ #include "C4Config.h" #include "C4Application.h" -#ifdef USE_GL +#ifndef USE_CONSOLE // MSVC doesn't define M_PI in math.h unless requested #ifdef _MSC_VER @@ -995,4 +995,4 @@ void CStdGL::Default() iClrDpt=0; } -#endif // USE_GL +#endif // USE_CONSOLE diff --git a/src/graphics/C4DrawGL.h b/src/graphics/C4DrawGL.h index 14943f071..5f1638926 100644 --- a/src/graphics/C4DrawGL.h +++ b/src/graphics/C4DrawGL.h @@ -21,7 +21,8 @@ /* OpenGL implementation of NewGfx */ -#if !defined(INC_StdGL) && defined(USE_GL) + +#if !defined(INC_StdGL) && !defined(USE_CONSOLE) #define INC_StdGL #ifdef _WIN32 @@ -106,7 +107,6 @@ public: // General void Clear(); void Default(); - virtual int GetEngine() { return 1; } // get indexed engine virtual bool IsOpenGL() { return true; } virtual bool IsShaderific() { return shaders[0] != 0; } virtual bool OnResolutionChanged(unsigned int iXRes, unsigned int iYRes); // reinit clipper for new resolution diff --git a/src/graphics/C4DrawGLCtx.cpp b/src/graphics/C4DrawGLCtx.cpp index fa76ae462..7ea739d99 100644 --- a/src/graphics/C4DrawGLCtx.cpp +++ b/src/graphics/C4DrawGLCtx.cpp @@ -30,7 +30,7 @@ #include #include -#ifdef USE_GL +#ifndef USE_CONSOLE void CStdGLCtx::SelectCommon() { @@ -565,4 +565,4 @@ bool CStdGLCtx::PageFlip() #endif //USE_X11/USE_SDL_MAINLOOP -#endif // USE_GL +#endif // USE_CONSOLE diff --git a/src/graphics/C4DrawMeshGL.cpp b/src/graphics/C4DrawMeshGL.cpp index b4fce8858..5036dc353 100644 --- a/src/graphics/C4DrawMeshGL.cpp +++ b/src/graphics/C4DrawMeshGL.cpp @@ -23,7 +23,7 @@ #include "StdMesh.h" -#ifdef USE_GL +#ifndef USE_CONSOLE namespace { @@ -1038,4 +1038,4 @@ void CStdGL::PerformMesh(StdMeshInstance &instance, float tx, float ty, float tw glClear(GL_DEPTH_BUFFER_BIT); } -#endif // USE_GL +#endif // USE_CONSOLE diff --git a/src/graphics/C4DrawT.cpp b/src/graphics/C4DrawT.cpp index 588753fac..c90628325 100644 --- a/src/graphics/C4DrawT.cpp +++ b/src/graphics/C4DrawT.cpp @@ -21,16 +21,6 @@ #include #include -CStdNoGfx::CStdNoGfx() -{ - Default(); -} - -CStdNoGfx::~CStdNoGfx() -{ - Clear(); -} - bool CStdNoGfx::CreatePrimarySurfaces(bool Fullscreen, unsigned int iXRes, unsigned int iYRes, int iColorDepth, unsigned int iMonitor) { Log("Graphics disabled."); diff --git a/src/graphics/C4DrawT.h b/src/graphics/C4DrawT.h index 6e8eba7d9..4c70e106a 100644 --- a/src/graphics/C4DrawT.h +++ b/src/graphics/C4DrawT.h @@ -25,13 +25,9 @@ class CStdNoGfx : public C4Draw { -public: - CStdNoGfx(); - virtual ~CStdNoGfx(); public: virtual bool BeginScene() { return true; } virtual void EndScene() { } - virtual int GetEngine() { return GFXENGN_NOGFX; } virtual void TaskOut() { } virtual void TaskIn() { } virtual bool UpdateClipper() { return true; } diff --git a/src/graphics/C4Facet.cpp b/src/graphics/C4Facet.cpp index d21b03689..a3548247c 100644 --- a/src/graphics/C4Facet.cpp +++ b/src/graphics/C4Facet.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #ifdef WITH_GLIB diff --git a/src/graphics/C4Surface.cpp b/src/graphics/C4Surface.cpp index 19055fa46..f23e8ed69 100644 --- a/src/graphics/C4Surface.cpp +++ b/src/graphics/C4Surface.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -68,9 +67,8 @@ C4Surface::C4Surface(C4AbstractApp * pApp, C4Window * pWindow): fPrimary=true; this->pWindow=pWindow; // create rendering context -#ifdef USE_GL - if (pGL) - pCtx = pGL->CreateContext(pWindow, pApp); +#ifndef USE_CONSOLE + pCtx = pGL->CreateContext(pWindow, pApp); #endif // reset clipping NoClip(); @@ -93,12 +91,9 @@ void C4Surface::Default() Locked=0; Attached=false; fPrimary=false; -#ifdef USE_DIRECTX - pSfc=NULL; -#endif ppTex=NULL; pMainSfc=NULL; -#ifdef USE_GL +#ifndef USE_CONSOLE pCtx=NULL; #endif pWindow=NULL; @@ -136,11 +131,7 @@ void C4Surface::MoveFrom(C4Surface *psfcFrom) iTexSize=psfcFrom->iTexSize; iTexX=psfcFrom->iTexX; iTexY=psfcFrom->iTexY; byBytesPP=psfcFrom->byBytesPP; -#ifdef USE_DIRECTX - dwClrFormat=psfcFrom->dwClrFormat; - pSfc=psfcFrom->pSfc; -#endif -#ifdef USE_GL +#ifndef USE_CONSOLE Format=psfcFrom->Format; #endif fIsBackground = psfcFrom->fIsBackground; @@ -153,14 +144,7 @@ void C4Surface::Clear() // Undo all locks while (Locked) Unlock(); // release surface -#ifdef USE_DIRECTX - if (pD3D) - { - if (pSfc) pSfc->Release(); - } - pSfc=NULL; -#endif -#ifdef USE_GL +#ifndef USE_CONSOLE if (pCtx) { delete pCtx; @@ -178,14 +162,7 @@ void C4Surface::Clear() bool C4Surface::IsRenderTarget() { // primary is always OK... - return fPrimary - // other surfaces may be used as render targets, if offscreen rendertargets are not disabled by config, - // or the surface is split (large sfcs) or locked (landscape) - // (only D3D for now) -#ifdef USE_DIRECTX - || (!Locked && !Config.Graphics.NoOffscreenBlits && pD3D && fIsRenderTarget) -#endif - ; + return fPrimary; } void C4Surface::NoClip() @@ -210,17 +187,9 @@ bool C4Surface::Create(int iWdt, int iHgt, bool, bool fIsRenderTarget, int MaxTe if (!pDraw->DeviceReady()) return false; // store color format that will be used -#ifdef USE_DIRECTX - if (pD3D) - dwClrFormat=pD3D->dwSurfaceType; - else +#ifndef USE_CONSOLE + Format=pGL->sfcFmt; #endif -#ifdef USE_GL - if (pGL) - Format=pGL->sfcFmt; - else -#endif - {/* nothing to do */} byBytesPP=pDraw->byByteCnt; this->fIsRenderTarget = fIsRenderTarget; // create textures @@ -252,7 +221,7 @@ namespace { int iNeedSize = Size; - #ifdef USE_GL + #ifndef USE_CONSOLE if (!pGL || !GLEW_ARB_texture_non_power_of_two) #endif { @@ -295,14 +264,6 @@ bool C4Surface::CreateTextures(int MaxTextureSize) if (fIsBackground && ppCTex) (*ppCTex)->FillBlack(); -#ifdef USE_DIRECTX - if (!(*ppCTex)->pTex && pD3D) - { - // error creating texture - return false; - } -#endif - ++ppCTex; } } @@ -316,7 +277,7 @@ bool C4Surface::CreateTextures(int MaxTextureSize) { // last texture might be smaller iNeedSize=Max(Wdt%iTexSize, Hgt%iTexSize); -#ifdef USE_GL +#ifndef USE_CONSOLE if (!pGL || !GLEW_ARB_texture_non_power_of_two) #endif { @@ -327,13 +288,6 @@ bool C4Surface::CreateTextures(int MaxTextureSize) *ppCTex = new C4TexRef(iNeedSize, fIsRenderTarget); } if (fIsBackground && ppCTex) (*ppCTex)->FillBlack(); -#ifdef USE_DIRECTX - if (!(*ppCTex)->pTex && pD3D) - { - // error creating texture - return false; - } -#endif } #endif @@ -480,32 +434,6 @@ bool C4Surface::SetAsClrByOwnerOf(C4Surface *pOfSurface) return true; } -#ifdef USE_GL -/*bool C4Surface::CreatePrimaryGLTextures() - { - if (!pGL) return false; - // primary OpenGL-surface: ensure context is selected - if (!pGL->pCurrCtx) if (!pGL->MainCtx.Select()) return false; - // create texture array - CreateTextures(); - // get from framebuffer - C4TexRef **ppTexRef = ppTex; - for (int iY=0; iYtexName); - glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, iX, iY, txWdt, txHgt, 0); - // next texture reference - ++ppTexRef; - } - // done, success - return true; - }*/ -#endif - bool C4Surface::UpdateSize(int wdt, int hgt) { assert(fPrimary); @@ -522,39 +450,12 @@ bool C4Surface::PageFlip(C4Rect *pSrcRt, C4Rect *pDstRt) return false; // call from gfx thread only! if (!pDraw->pApp || !pDraw->pApp->AssertMainThread()) return false; -#ifdef USE_GL - if (pGL) - return pCtx->PageFlip(); -#endif -#ifdef USE_DIRECTX - if (pD3D) - return pD3D->PageFlip(pSrcRt, pDstRt); +#ifndef USE_CONSOLE + return pCtx->PageFlip(); #endif return true; } -#ifdef USE_DIRECTX -IDirect3DSurface9 *C4Surface::GetSurface() -{ - // direct surface? - if (pSfc) - { - pSfc->AddRef(); - return pSfc; - } - // surface by texture? - if (fIsRenderTarget && ppTex) - { - IDirect3DTexture9 *pTex = (*ppTex)->pTex; - IDirect3DSurface9 *pSfcResult=NULL; - if (pTex) pTex->GetSurfaceLevel(0, &pSfcResult); - return pSfcResult; - } - // split surfaces: Won't work; we're no render target anyway - return NULL; -} -#endif //USE_DIRECTX - bool C4Surface::ReadBMP(CStdStream &hGroup) { int lcnt; @@ -693,8 +594,8 @@ bool C4Surface::SavePNG(const char *szFilename, bool fSaveAlpha, bool fApplyGamm C4Surface *pMainSfcBackup = NULL; if (fSaveOverlayOnly) { pMainSfcBackup=pMainSfc; pMainSfc=NULL; } -#ifdef USE_GL - if (fPrimary && pGL) +#ifndef USE_CONSOLE + if (fPrimary) { // Take shortcut. FIXME: Check Endian for (int y = 0; y < Hgt; ++y) @@ -750,37 +651,9 @@ bool C4Surface::Lock() { // lock main sfc if (pMainSfc) if (!pMainSfc->Lock()) return false; - // not yet locked? - if (!Locked) - { - if (fPrimary) - { -#ifdef USE_DIRECTX - if (pD3D) - { - D3DLOCKED_RECT lock; - // locking primary - if (!pSfc) return false; - // lock it - if (pSfc->LockRect(&lock, NULL, 0) != D3D_OK) - return false; - pDraw->LockingPrimary(); - // store pitch and pointer - PrimarySurfaceLockPitch=lock.Pitch; - PrimarySurfaceLockBits=(BYTE*) lock.pBits; - } -#endif //USE_DIRECTX - - // OpenGL: - // cannot really lock primary surface, but Get/SetPix will emulate it - } - else - { - if (!ppTex) return false; - // lock texture - // textures will be locked when needed - } - } + // lock texture + if (!Locked && !fPrimary && !ppTex) + return false; // count lock Locked++; return true; } @@ -791,32 +664,18 @@ bool C4Surface::Unlock() if (pMainSfc) pMainSfc->Unlock(); // locked? if (!Locked) return false; - // decrease lock counter; check if zeroed + // decrease lock counter; check if zeroed and unlock then Locked--; if (!Locked) { - // zeroed: unlock if (fPrimary) { -#ifdef USE_DIRECTX - if (pD3D) - { - if (!pSfc) return false; - // unlocking primary? - if (pSfc->UnlockRect() != D3D_OK) - return false; - pDraw->PrimaryUnlocked(); - } - else -#endif - { - // if tex refs exist, free them - /*FreeTextures();*/ - // otherwise, emulated primary locks in OpenGL - delete[] PrimarySurfaceLockBits; - PrimarySurfaceLockBits = 0; - return true; - } + // if tex refs exist, free them + /*FreeTextures();*/ + // otherwise, emulated primary locks in OpenGL + delete[] PrimarySurfaceLockBits; + PrimarySurfaceLockBits = 0; + return true; } else { @@ -875,17 +734,14 @@ DWORD C4Surface::GetPixDw(int iX, int iY, bool fApplyModulation) // primary? if (fPrimary) { -#ifdef USE_GL - // OpenGL? - if (pGL) +#ifndef USE_CONSOLE + if (!PrimarySurfaceLockBits) { - if (!PrimarySurfaceLockBits) - { - PrimarySurfaceLockBits = new unsigned char[Wdt*Hgt*3 + 1]; - glReadPixels( 0, 0, Wdt, Hgt, GL_BGR, GL_UNSIGNED_BYTE, PrimarySurfaceLockBits); - PrimarySurfaceLockPitch = Wdt*3; - } - return * (DWORD *) (PrimarySurfaceLockBits+(Hgt-iY-1)*PrimarySurfaceLockPitch+iX*3); + PrimarySurfaceLockBits = new unsigned char[Wdt*Hgt*3 + 1]; + glReadPixels( 0, 0, Wdt, Hgt, GL_BGR, GL_UNSIGNED_BYTE, PrimarySurfaceLockBits); + PrimarySurfaceLockPitch = Wdt*3; + } + return * (DWORD *) (PrimarySurfaceLockBits+(Hgt-iY-1)*PrimarySurfaceLockPitch+iX*3); // copy content into textures /*if (!ppTex) if (!CreatePrimaryGLTextures()) return 0; @@ -897,42 +753,6 @@ DWORD C4Surface::GetPixDw(int iX, int iY, bool fApplyModulation) iPitch=pTexRef->texLock.Pitch; // get pixel return *(DWORD *)(pBuf+iY*iPitch+iX*4);*/ - } -#endif -#ifdef USE_DIRECTX - if (!PrimarySurfaceLockBits) - { - return 0; - } - else - { - // clip - if (iX<0 || iY<0 || iX>=Wdt || iY>=Hgt) return 0; - // get pixel from primary surface - WORD pix16; - switch (dwClrFormat) - { - case D3DFMT_X1R5G5B5: - // 16 bit 5-5-5 - pix16= * (WORD *) (((BYTE *) PrimarySurfaceLockBits)+iY*PrimarySurfaceLockPitch+iX*2); - return ((pix16 & 0x001f) << 3) - | ((pix16 & 0x03e0) << 6) - | ((pix16 & 0x7c00) << 9); - - case D3DFMT_R5G6B5: - // 16 bit 5-6-5 - pix16= * (WORD *) (((BYTE *) PrimarySurfaceLockBits)+iY*PrimarySurfaceLockPitch+iX*2); - return ((pix16 & 0x001f) << 3) - | ((pix16 & 0x07e0) << 5) - | ((pix16 & 0xf800) << 8); - break; - - case D3DFMT_X8R8G8B8: - // 32 bit - return * (DWORD *) (((BYTE *) PrimarySurfaceLockBits)+iY*PrimarySurfaceLockPitch+iX*4); - default: assert(false); return 0; // should not happen - } - } #endif } else @@ -1018,46 +838,11 @@ bool C4Surface::IsPixTransparent(int iX, int iY) if ((iXClipX2) || (iYClipY2)) return true; // primary? if (fPrimary) - { -#ifdef USE_GL - // OpenGL: Use OpenGL API - if (pGL) - { +#ifndef USE_CONSOLE pGL->DrawPixInt(this, iX, iY, dwClr); - } else #endif { -#ifdef USE_DIRECTX - // must be locked! - if (!Bits) return false; - // set according to pixel format - DWORD *pPix32; WORD *pPix16; - switch (dwClrFormat) - { - case D3DFMT_X1R5G5B5: - // 16 bit 5-5-5 - pPix16=(WORD *) (((BYTE *) Bits)+iY*Pitch+iX*2); - *pPix16=WORD((dwClr & 0x000000f8) >> 3) - | WORD((dwClr & 0x0000f800) >> 6) - | WORD((dwClr & 0x00f80000) >> 9); - break; - - case D3DFMT_R5G6B5: - // 16 bit 5-6-5 - pPix16=(WORD *) (((BYTE *) Bits)+iY*Pitch+iX*2); - *pPix16=WORD((dwClr & 0x000000f8) >> 3) - | WORD((dwClr & 0x0000fc00) >> 5) - | WORD((dwClr & 0x00f80000) >> 8); - break; - - case D3DFMT_X8R8G8B8: - // 32 bit - pPix32=(DWORD *) (((BYTE *) Bits)+iY*Pitch+iX*4); - *pPix32=dwClr; - break; - } -#endif } return true; } @@ -1077,11 +862,11 @@ bool C4Surface::SetPixDw(int iX, int iY, DWORD dwClr) // if color is fully transparent, ensure it's black if (dwClr>>24 == 0x00) dwClr=0x00000000; C4TexRef *pTexRef; -#ifdef USE_GL +#ifndef USE_CONSOLE // openGL: use glTexSubImage2D // This optimization was moved to LockForUpdate, as it only slows down mass updates here // Keep this code in case there is a need for fast single pixel updates again - if (0 && pGL && pGL->pCurrCtx) + if (0 && pGL->pCurrCtx) { if (!GetTexAt(&pTexRef, iX, iY)) return false; @@ -1284,10 +1069,7 @@ bool C4Surface::CopyBytes(BYTE *pImageData) C4TexRef::C4TexRef(int iSizeX, int iSizeY, bool fSingle) { // zero fields -#ifdef USE_DIRECTX - pTex=NULL; -#endif -#ifdef USE_GL +#ifndef USE_CONSOLE texName=0; #endif texLock.pBits=NULL; fIntLock=false; @@ -1301,63 +1083,32 @@ C4TexRef::C4TexRef(int iSizeX, int iSizeY, bool fSingle) if (!pDraw) return; if (!pDraw->DeviceReady()) return; // create it! -#ifdef USE_DIRECTX - if (pD3D) +#ifndef USE_CONSOLE + // OpenGL + // create mem array for texture creation + texLock.pBits = new unsigned char[iSizeX*iSizeY*pGL->byByteCnt]; + texLock.Pitch = iSizeX*pGL->byByteCnt; + memset(texLock.pBits, 0x00, texLock.Pitch*iSizeY); + // turn mem array into texture + Unlock(); +#endif + if (pDraw) { - // Direct3D - bool fRenderTarget = fSingle && !Config.Graphics.NoOffscreenBlits; - if (pD3D->lpDevice->CreateTexture(iSizeX, iSizeY, 1, fRenderTarget ? D3DUSAGE_RENDERTARGET : 0, pD3D->dwSurfaceType, fRenderTarget ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED, &pTex, NULL) != D3D_OK) - { - pDraw->Error("Error creating surface"); - return; - } - // empty texture - if (!Lock()) return; - FillMemory(texLock.pBits, texLock.Pitch*iSizeY, 0x00); - Unlock(); + texLock.pBits = new unsigned char[iSizeX*iSizeY*pDraw->byByteCnt]; + texLock.Pitch = iSizeX*pDraw->byByteCnt; + memset(texLock.pBits, 0x00, texLock.Pitch*iSizeY); + // Always locked + LockSize.x = LockSize.y = 0; + LockSize.Wdt = iSizeX; LockSize.Hgt = iSizeY; } - else -#endif -#ifdef USE_GL - if (pGL) - { - // OpenGL - // create mem array for texture creation - texLock.pBits = new unsigned char[iSizeX*iSizeY*pGL->byByteCnt]; - texLock.Pitch = iSizeX*pGL->byByteCnt; - memset(texLock.pBits, 0x00, texLock.Pitch*iSizeY); - // turn mem array into texture - Unlock(); - } - else -#endif - if (pDraw) - { - texLock.pBits = new unsigned char[iSizeX*iSizeY*pDraw->byByteCnt]; - texLock.Pitch = iSizeX*pDraw->byByteCnt; - memset(texLock.pBits, 0x00, texLock.Pitch*iSizeY); - // Always locked - LockSize.x = LockSize.y = 0; - LockSize.Wdt = iSizeX; LockSize.Hgt = iSizeY; - } } C4TexRef::~C4TexRef() { fIntLock=false; // free texture -#ifdef USE_DIRECTX - if (pD3D) - { - if (texLock.pBits) Unlock(); - if (pTex) pTex->Release(); - } -#endif -#ifdef USE_GL - if (pGL) - { - if (texName && pGL->pCurrCtx) glDeleteTextures(1, &texName); - } +#ifndef USE_CONSOLE + if (texName && pGL && pGL->pCurrCtx) glDeleteTextures(1, &texName); #endif if (pDraw) delete [] static_cast(texLock.pBits); texLock.pBits = 0; // remove from texture manager @@ -1381,36 +1132,15 @@ bool C4TexRef::LockForUpdate(C4Rect & rtUpdate) } } // lock -#ifdef USE_DIRECTX - if (pD3D) - { - RECT r; - r.left = rtUpdate.x; - r.top = rtUpdate.y; - r.right = rtUpdate.x + rtUpdate.Wdt; - r.bottom = rtUpdate.y + rtUpdate.Hgt; - if (pTex) - if (pTex->LockRect(0, &texLock, &r, D3DLOCK_DISCARD) == D3D_OK) - { - LockSize = rtUpdate; - return true; - } - } - else -#endif -#ifdef USE_GL - if (pGL) +#ifndef USE_CONSOLE + if (texName) { - if (texName) - { - // prepare texture data - texLock.pBits = new unsigned char[rtUpdate.Wdt * rtUpdate.Hgt * pGL->byByteCnt]; - texLock.Pitch = rtUpdate.Wdt * pGL->byByteCnt; - LockSize = rtUpdate; - return true; - } + // prepare texture data + texLock.pBits = new unsigned char[rtUpdate.Wdt * rtUpdate.Hgt * pGL->byByteCnt]; + texLock.Pitch = rtUpdate.Wdt * pGL->byByteCnt; + LockSize = rtUpdate; + return true; } - else #endif { // nothing to do @@ -1426,17 +1156,7 @@ bool C4TexRef::Lock() LockSize.Wdt = iSizeX; LockSize.Hgt = iSizeY; LockSize.x = LockSize.y = 0; // lock -#ifdef USE_DIRECTX - if (pD3D) - { - if (pTex) - if (pTex->LockRect(0, &texLock, NULL, 0) == D3D_OK) return true; - } - else -#endif -#ifdef USE_GL - if (pGL) - { +#ifndef USE_CONSOLE if (texName) { if (!pGL->pCurrCtx) return false; @@ -1447,8 +1167,6 @@ bool C4TexRef::Lock() glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, pDraw->byByteCnt == 2 ? GL_UNSIGNED_SHORT_4_4_4_4_REV : GL_UNSIGNED_INT_8_8_8_8_REV, texLock.pBits); return true; } - } - else #endif { // nothing to do @@ -1461,18 +1179,7 @@ void C4TexRef::Unlock() { // locked? if (!texLock.pBits || fIntLock) return; -#ifdef USE_DIRECTX - if (pD3D) - { - // unlock - if (pTex) pTex->UnlockRect(0); - texLock.pBits=NULL; - } - else -#endif -#ifdef USE_GL - if (pGL) - { +#ifndef USE_CONSOLE if (!pGL->pCurrCtx) { // BREAKPOINT_HERE; @@ -1502,12 +1209,7 @@ void C4TexRef::Unlock() } delete[] static_cast(texLock.pBits); texLock.pBits=NULL; // switch back to original context - } - else #endif - { - // nothing to do - } } bool C4TexRef::ClearRect(C4Rect &rtClear) @@ -1602,7 +1304,7 @@ void C4TexMgr::IntLock() if (pRef->Lock() && pRef->texLock.pBits) { pRef->fIntLock = true; -#ifdef USE_GL +#ifndef USE_CONSOLE // Release the underlying texture with GL and recreate // it on unlock, so that the texture survives // context recreation. diff --git a/src/graphics/C4Surface.h b/src/graphics/C4Surface.h index f378b3624..507f29862 100644 --- a/src/graphics/C4Surface.h +++ b/src/graphics/C4Surface.h @@ -29,14 +29,9 @@ #ifdef _WIN32 #include #endif -#ifdef USE_DIRECTX -#include -#undef DrawText -#else typedef void* IDirect3DSurface9; -#endif -#ifdef USE_GL +#ifndef USE_CONSOLE #include #endif @@ -61,12 +56,7 @@ typedef void* IDirect3DSurface9; const int ALeft=0,ACenter=1,ARight=2; -#ifdef USE_DIRECTX -class CStdD3D; -extern CStdD3D *pD3D; -#endif - -#ifdef USE_GL +#ifndef USE_CONSOLE class CStdGL; class CStdGLCtx; extern CStdGL *pGL; @@ -95,29 +85,9 @@ public: #ifdef _DEBUG int *dbg_idx; #endif -#if defined(USE_DIRECTX) && defined(USE_GL) - union - { - struct // D3D values - { -#endif -#ifdef USE_DIRECTX - IDirect3DSurface9 *pSfc; // surface (primary sfc) - D3DFORMAT dwClrFormat; // used color format in textures -#endif -#if defined(USE_DIRECTX) && defined(USE_GL) - - }; - struct // OpenGL values - { -#endif -#ifdef USE_GL +#ifndef USE_CONSOLE GLenum Format; // used color format in textures CStdGLCtx * pCtx; -#endif -#if defined(USE_DIRECTX) && defined(USE_GL) - }; - }; #endif C4TexRef **ppTex; // textures BYTE byBytesPP; // bytes per pixel (2 or 4) @@ -152,7 +122,7 @@ public: bool Copy(C4Surface &fromSfc); bool CreateColorByOwner(C4Surface *pBySurface); // create ColorByOwner-surface bool SetAsClrByOwnerOf(C4Surface *pOfSurface); // assume that ColorByOwner-surface has been created, and just assign it; fails if the size doesn't match -#ifdef USE_GL +#ifndef USE_CONSOLE bool CreatePrimaryGLTextures(); // create primary textures from back buffer #endif // Only for surfaces which map to a window @@ -177,9 +147,6 @@ public: bool ReadBMP(CStdStream &hGroup); bool AttachPalette(); -#ifdef USE_DIRECTX - IDirect3DSurface9 *GetSurface(); // get internal surface -#endif bool GetSurfaceSize(int &irX, int &irY); // get surface size void SetClr(DWORD toClr) { ClrByOwnerClr=toClr; } DWORD GetClr() { return ClrByOwnerClr; } @@ -197,39 +164,19 @@ protected: friend class CStdGL; }; -#ifndef USE_DIRECTX typedef struct _D3DLOCKED_RECT { int Pitch; unsigned char * pBits; } D3DLOCKED_RECT; -#endif // one texture encapsulation class C4TexRef { public: D3DLOCKED_RECT texLock; // current lock-data -#if defined(USE_DIRECTX) && defined(USE_GL) - union - { - struct // D3D - { -#endif -#ifdef USE_DIRECTX - IDirect3DTexture9 *pTex; // texture -#endif -#if defined(USE_DIRECTX) && defined(USE_GL) - }; - struct // OpenGL - { -#endif -#ifdef USE_GL - GLuint texName; -#endif -#if defined(USE_DIRECTX) && defined(USE_GL) - }; - }; +#ifndef USE_CONSOLE + GLuint texName; #endif int iSizeX; int iSizeY; diff --git a/src/gui/C4GuiDialogs.cpp b/src/gui/C4GuiDialogs.cpp index e80450173..8e2bfd28d 100644 --- a/src/gui/C4GuiDialogs.cpp +++ b/src/gui/C4GuiDialogs.cpp @@ -225,7 +225,7 @@ namespace C4GUI { pSurface->Wdt = r.Wdt; pSurface->Hgt = r.Hgt; -#ifdef USE_GL +#ifndef USE_CONSOLE pGL->PrepareRendering(pSurface); glClear(GL_COLOR_BUFFER_BIT); #endif diff --git a/src/gui/C4StartupOptionsDlg.cpp b/src/gui/C4StartupOptionsDlg.cpp index a9286edd6..d32376ab4 100644 --- a/src/gui/C4StartupOptionsDlg.cpp +++ b/src/gui/C4StartupOptionsDlg.cpp @@ -792,32 +792,6 @@ C4StartupOptionsDlg::C4StartupOptionsDlg() : C4StartupDlg(LoadResStrNoAmp("IDS_D // --- page graphics C4GUI::ComponentAligner caSheetGraphics(pSheetGraphics->GetClientRect(), iIndentX1, iIndentY1, true); - // --subgroup engine - C4GUI::GroupBox *pGroupEngine = new C4GUI::GroupBox(caSheetGraphics.GetGridCell(0,2,0,3)); - pGroupEngine->SetTitle(LoadResStrNoAmp("IDS_CTL_GFXENGINE")); - pGroupEngine->SetFont(pUseFont); - pGroupEngine->SetColors(C4StartupEditBorderColor, C4StartupFontClr); - pGroupEngine->SetToolTip(LoadResStr("IDS_MSG_GFXENGINE_DESC")); - pSheetGraphics->AddElement(pGroupEngine); - C4GUI::ComponentAligner caGroupEngine(pGroupEngine->GetClientRect(), iIndentX1, iIndentY2, true); - const char *szGfxEngineNames[3] = { "DirectX", "OpenGL", "DirectX Software" }; - C4GUI::BaseCallbackHandler *pGfxEngineCheckCB = new C4GUI::CallbackHandler(this, &C4StartupOptionsDlg::OnGfxEngineCheck); - for (int32_t iGfxEngine = 0; iGfxEngine<3; ++iGfxEngine) - { - pCheckGfxEngines[iGfxEngine] = new C4GUI::CheckBox(caGroupEngine.GetGridCell(0,1,iGfxEngine,3,-1,iCheckHgt,true), szGfxEngineNames[iGfxEngine], (Config.Graphics.Engine == iGfxEngine)); - pCheckGfxEngines[iGfxEngine]->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled); - pCheckGfxEngines[iGfxEngine]->SetOnChecked(pGfxEngineCheckCB); - pGroupEngine->AddElement(pCheckGfxEngines[iGfxEngine]); - } -#ifndef USE_DIRECTX - pCheckGfxEngines[GFXENGN_DIRECTX]->SetEnabled(false); - pCheckGfxEngines[GFXENGN_DIRECTXS]->SetEnabled(false); -#endif -#ifndef USE_GL - pCheckGfxEngines[GFXENGN_OPENGL]->SetEnabled(false); -#endif - pCheckGfxEngines[GFXENGN_DIRECTX]->SetEnabled(false); // as long as DX doesnt work, its disabled - pCheckGfxEngines[GFXENGN_DIRECTXS]->SetEnabled(false); // better not using this // --subgroup resolution C4GUI::GroupBox *pGroupResolution = new C4GUI::GroupBox(caSheetGraphics.GetGridCell(1,2,0,3)); pGroupResolution->SetTitle(LoadResStrNoAmp("IDS_CTL_RESOLUTION")); @@ -848,8 +822,8 @@ C4StartupOptionsDlg::C4StartupOptionsDlg() : C4StartupDlg(LoadResStrNoAmp("IDS_D C4GUI::BaseCallbackHandler *pGfxClrDepthCheckCB = new C4GUI::CallbackHandler(this, &C4StartupOptionsDlg::OnGfxClrDepthCheck); for (int32_t iBitDepthIdx = 0; iBitDepthIdx<2; ++iBitDepthIdx) { - int iBitDepth = (iBitDepthIdx+1) * 16; - pCheckGfxClrDepth[iBitDepthIdx] = new C4GUI::CheckBox(caGroupEngine.GetGridCell(iBitDepthIdx,2,2,4,-1,iCheckHgt,true), FormatString("%d Bit", (int)iBitDepth).getData(), (Config.Graphics.BitDepth == iBitDepth)); + int iBitDepth = (iBitDepthIdx+1) * 16; //WORKAROUND + pCheckGfxClrDepth[iBitDepthIdx] = new C4GUI::CheckBox(caGroupResolution.GetGridCell(iBitDepthIdx,2,2,4,-1,iCheckHgt,true), FormatString("%d Bit", (int)iBitDepth).getData(), (Config.Graphics.BitDepth == iBitDepth)); pCheckGfxClrDepth[iBitDepthIdx]->SetFont(pUseFont, C4StartupFontClr, C4StartupFontClrDisabled); pCheckGfxClrDepth[iBitDepthIdx]->SetOnChecked(pGfxClrDepthCheckCB); pCheckGfxClrDepth[iBitDepthIdx]->SetToolTip(LoadResStr("IDS_CTL_BITDEPTH")); @@ -1093,28 +1067,6 @@ void C4StartupOptionsDlg::OnResetConfigBtn(C4GUI::Control *btn) Application.Quit(); } -void C4StartupOptionsDlg::OnGfxEngineCheck(C4GUI::Element *pCheckBox) -{ - C4GUI::CheckBox *pCheck = static_cast(pCheckBox); - // radiogroup: do not allow unchecking! - if (!pCheck->GetChecked()) - { - pCheck->SetChecked(true); - return; - } - // get new engine - int i; - for (i=0; i<3; ++i) if (pCheck == pCheckGfxEngines[i]) break; - if (i==3 || i == Config.Graphics.Engine) return; - // okay, engine change - pCheckGfxEngines[Config.Graphics.Engine]->SetChecked(false); - StdStrBuf sTitle; sTitle.Copy(LoadResStrNoAmp("IDS_CTL_GFXENGINE")); - GetScreen()->ShowMessage(LoadResStr("IDS_MSG_RESTARTCHANGECFG"), sTitle.getData(), C4GUI::Ico_Notify, &Config.Startup.HideMsgGfxEngineChange); - SaveGfxTroubleshoot(); - Config.Graphics.Engine = i; - LoadGfxTroubleshoot(); -} - void C4StartupOptionsDlg::OnGfxMSComboFill(C4GUI::ComboBox_FillCB *pFiller) { // clear all old entries first to allow a clean refill @@ -1137,38 +1089,22 @@ void C4StartupOptionsDlg::OnGfxMSComboFill(C4GUI::ComboBox_FillCB *pFiller) bool C4StartupOptionsDlg::OnGfxMSComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection) { if(pTexMgr) pTexMgr->IntLock(); -#ifdef USE_GL +#ifndef USE_CONSOLE pDraw->InvalidateDeviceObjects(); // Note: This assumes there is only one GL context (the main context). This // is true in fullscreen mode, and since the startup dlg is only shown in // fullscreen mode we are safe this way. if(pGL) pGL->pMainCtx->Clear(); #endif -#ifdef USE_DIRECTX - // It should also be possible to clear+reinit DDraw also for GL, however, - // if ReInit() does _not_ create a new window on X11 then all rendering - // stops until the Window is being moved again (or tasked-out and back in - // in fullscreen mode). This does not happen when only reinitializing the - // GL context instead of whole DDraw so that's why we do this currently. - if(pD3D) pDraw->Clear(); -#endif - int32_t PrevMultiSampling = Config.Graphics.MultiSampling; Config.Graphics.MultiSampling = idNewSelection; bool success = Application.pWindow->ReInit(&Application); -#ifdef USE_GL +#ifndef USE_CONSOLE if(pGL) pGL->pMainCtx->Init(Application.pWindow, &Application); pDraw->RestoreDeviceObjects(); #endif -#ifdef USE_DIRECTX - // Note: Editor is hardcoded to false at this point... I guess that's OK - // because C4StartupOptionsDlg is never shown in editor mode anyway. - if(pD3D) pDraw->Init(&Application, false, false, Config.Graphics.ResX, Config.Graphics.ResY, Config.Graphics.BitDepth, Config.Graphics.Monitor); -#endif - if(pTexMgr) pTexMgr->IntUnlock(); - if(!success) Config.Graphics.MultiSampling = PrevMultiSampling; return !success; } @@ -1527,10 +1463,8 @@ void C4StartupOptionsDlg::SaveGfxTroubleshoot() { // get it from controls Config.Graphics.EnableShaders=pShaders->GetChecked(); - // get config set to be used - bool fUseGL = (Config.Graphics.Engine == GFXENGN_OPENGL); - // and apply them directly, if the engine is current - if (fUseGL == pDraw->IsOpenGL()) + + if (pDraw->IsOpenGL()) { pDraw->RestoreDeviceObjects(); } diff --git a/src/gui/C4StartupOptionsDlg.h b/src/gui/C4StartupOptionsDlg.h index c798e986e..e6309d285 100644 --- a/src/gui/C4StartupOptionsDlg.h +++ b/src/gui/C4StartupOptionsDlg.h @@ -129,7 +129,6 @@ private: void OnWindowedModeComboFill(C4GUI::ComboBox_FillCB *pFiller); bool OnWindowedModeComboSelChange(C4GUI::ComboBox *pForCombo, int32_t idNewSelection); void OnGfxAllResolutionsChange(C4GUI::Element *pCheckBox); - void OnGfxEngineCheck(C4GUI::Element *pCheckBox); void OnGfxTroubleCheck(C4GUI::Element *pCheckBox) { SaveGfxTroubleshoot(); } // immediate save and test void OnGfxResComboFill(C4GUI::ComboBox_FillCB *pFiller); @@ -142,7 +141,7 @@ private: const char * GetWindowedName(int32_t mode = -1); void OnEffectsSliderChange(int32_t iNewVal); - C4GUI::CheckBox *pCheckGfxEngines[3], *pCheckGfxClrDepth[2]; + C4GUI::CheckBox *pCheckGfxClrDepth[2]; C4GUI::GroupBox *pGroupTrouble; C4GUI::CheckBox *pShaders; int32_t iGfxTexIndent; diff --git a/src/landscape/C4Landscape.cpp b/src/landscape/C4Landscape.cpp index 7b15f6d5f..06edb888a 100644 --- a/src/landscape/C4Landscape.cpp +++ b/src/landscape/C4Landscape.cpp @@ -1325,7 +1325,7 @@ bool C4Landscape::Init(C4Group &hGroup, bool fOverloadCurrent, bool fLoadSky, bo } // Create renderer -#ifdef USE_GL +#ifndef USE_CONSOLE if (!pLandscapeRender && ::Config.Graphics.HighResLandscape) pLandscapeRender = new C4LandscapeRenderGL(); #endif diff --git a/src/landscape/C4LandscapeRender.cpp b/src/landscape/C4LandscapeRender.cpp index e82c620a4..9d96fab9d 100644 --- a/src/landscape/C4LandscapeRender.cpp +++ b/src/landscape/C4LandscapeRender.cpp @@ -11,7 +11,7 @@ #include "C4DrawGL.h" #include "StdColors.h" -#ifdef USE_GL +#ifndef USE_CONSOLE // Automatically reload shaders when changed at runtime? #define AUTO_RELOAD_SHADERS diff --git a/src/landscape/C4LandscapeRender.h b/src/landscape/C4LandscapeRender.h index 829bcefd0..cdd463205 100644 --- a/src/landscape/C4LandscapeRender.h +++ b/src/landscape/C4LandscapeRender.h @@ -72,7 +72,7 @@ public: virtual void Draw(const C4TargetFacet &cgo) = 0; }; -#ifdef USE_GL +#ifndef USE_CONSOLE class C4LandscapeRenderGL : public C4LandscapeRender { public: diff --git a/src/landscape/C4PXS.cpp b/src/landscape/C4PXS.cpp index 747b984fd..98f527988 100644 --- a/src/landscape/C4PXS.cpp +++ b/src/landscape/C4PXS.cpp @@ -252,12 +252,6 @@ void C4PXSSystem::Draw(C4TargetFacet &cgo) C4Rect VisibleRect(cgo.TargetX, cgo.TargetY, cgo.Wdt, cgo.Hgt); VisibleRect.Enlarge(20); - // Lock primary surface -#ifdef USE_DIRECTX - if (pD3D) - cgo.Surface->Lock(); -#endif - // First pass: draw simple PXS (lines/pixels) float cgox = cgo.X - cgo.TargetX, cgoy = cgo.Y - cgo.TargetY; unsigned int cnt; @@ -289,12 +283,6 @@ void C4PXSSystem::Draw(C4TargetFacet &cgo) } } - // Unlock primary surface -#ifdef USE_DIRECTX - if (pD3D) - cgo.Surface->Unlock(); -#endif - // PXS graphics disabled? if (!Config.Graphics.PXSGfx) return; diff --git a/src/network/C4Network2.cpp b/src/network/C4Network2.cpp index 68617282e..5a70d5e24 100644 --- a/src/network/C4Network2.cpp +++ b/src/network/C4Network2.cpp @@ -368,9 +368,7 @@ bool C4Network2::DoLobby() ChangeGameStatus(GS_Lobby, 0); // determine lobby type - bool fFullscreenLobby = !Console.Active && (pDraw->GetEngine() != GFXENGN_NOGFX); - - if (!fFullscreenLobby) + if (Console.Active) { // console lobby - update console if (Console.Active) Console.UpdateMenus(); diff --git a/src/platform/C4App.h b/src/platform/C4App.h index da9224ee9..5727fdbc9 100644 --- a/src/platform/C4App.h +++ b/src/platform/C4App.h @@ -97,8 +97,8 @@ public: bool SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen); void RestoreVideoMode(); // Gamma - virtual bool ApplyGammaRamp(struct _D3DGAMMARAMP &ramp, bool fForce); - virtual bool SaveDefaultGammaRamp(struct _D3DGAMMARAMP &ramp); + virtual bool ApplyGammaRamp(struct _GAMMARAMP &ramp, bool fForce); + virtual bool SaveDefaultGammaRamp(struct _GAMMARAMP &ramp); bool ScheduleProcs(int iTimeout = -1); bool FlushMessages(); C4Window * pWindow; diff --git a/src/platform/C4AppT.cpp b/src/platform/C4AppT.cpp index d406191c9..0731c7ef1 100644 --- a/src/platform/C4AppT.cpp +++ b/src/platform/C4AppT.cpp @@ -93,8 +93,8 @@ bool C4AbstractApp::IsClipboardFull(bool fClipboard) return false; } -bool C4AbstractApp::ApplyGammaRamp(_D3DGAMMARAMP&, bool) { return true; } -bool C4AbstractApp::SaveDefaultGammaRamp(_D3DGAMMARAMP&) { return true; } +bool C4AbstractApp::ApplyGammaRamp(_GAMMARAMP&, bool) { return true; } +bool C4AbstractApp::SaveDefaultGammaRamp(_GAMMARAMP&) { return true; } void C4AbstractApp::MessageDialog(const char * message) {} bool C4AbstractApp::FlushMessages() diff --git a/src/platform/C4WindowWin32.cpp b/src/platform/C4WindowWin32.cpp index 51211313d..e77a0d241 100644 --- a/src/platform/C4WindowWin32.cpp +++ b/src/platform/C4WindowWin32.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include @@ -114,7 +113,7 @@ LRESULT APIENTRY FullScreenWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l // fall through to next case case WM_ACTIVATEAPP: Application.Active = wParam != 0; -#ifdef USE_GL +#ifndef USE_CONSOLE if (pGL) { if (Application.Active) @@ -139,12 +138,6 @@ LRESULT APIENTRY FullScreenWinProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l } } } -#endif -#ifdef USE_DIRECTX - if (pD3D && Application.Active) - pD3D->TaskIn(); - if (pD3D && !Application.Active) - pD3D->TaskOut(); #endif // redraw background ::GraphicsSystem.InvalidateBg(); @@ -753,14 +746,10 @@ void C4Window::FlashWindow() void C4Window::EnumerateMultiSamples(std::vector& samples) const { -#ifdef USE_GL +#ifndef USE_CONSOLE if(pGL && pGL->pMainCtx) samples = pGL->pMainCtx->EnumerateMultiSamples(); #endif - -#ifdef USE_DIRECTX - // TODO: Enumerate multi samples -#endif } /* CStdMessageProc */ @@ -884,16 +873,7 @@ void C4AbstractApp::RestoreVideoMode() bool C4AbstractApp::SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigned int iColorDepth, unsigned int iRefreshRate, unsigned int iMonitor, bool fFullScreen) { -#ifdef USE_DIRECTX - if (pD3D) - { - if (!pD3D->SetVideoMode(iXRes, iYRes, iColorDepth, iMonitor, fFullScreen)) - return false; - OnResolutionChanged(iXRes, iYRes); - return true; - } -#endif -#ifdef USE_GL +#ifndef USE_CONSOLE SetWindowLong(pWindow->hWindow, GWL_EXSTYLE, GetWindowLong(pWindow->hWindow, GWL_EXSTYLE) | WS_EX_APPWINDOW); // change mode @@ -995,14 +975,8 @@ bool C4AbstractApp::SetVideoMode(unsigned int iXRes, unsigned int iYRes, unsigne #endif } -bool C4AbstractApp::SaveDefaultGammaRamp(_D3DGAMMARAMP &ramp) +bool C4AbstractApp::SaveDefaultGammaRamp(_GAMMARAMP &ramp) { -#ifdef USE_DIRECTX - if (pD3D) - { - return pD3D->SaveDefaultGammaRamp(ramp); - } -#endif HDC hDC = GetDC(pWindow->hWindow); if (hDC) { @@ -1017,14 +991,8 @@ bool C4AbstractApp::SaveDefaultGammaRamp(_D3DGAMMARAMP &ramp) return false; } -bool C4AbstractApp::ApplyGammaRamp(_D3DGAMMARAMP &ramp, bool fForce) +bool C4AbstractApp::ApplyGammaRamp(_GAMMARAMP &ramp, bool fForce) { -#ifdef USE_DIRECTX - if (pD3D) - { - return pD3D->ApplyGammaRamp(ramp, fForce); - } -#endif if (!Active && !fForce) return false; HDC hDC = GetDC(pWindow->hWindow); if (hDC)