DXGL r37 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r36‎ | r37 | r38 >
Date:19:42, 24 December 2011
Author:admin
Status:new
Tags:
Comment:
Add vsync for Flip()
Fix PIXELFORMATDESCRIPTOR initialization to support vsync
Delete Code::Blocks layout files
Modified paths:
  • /cfgmgr (modified) (history)
  • /cfgmgr/cfgmgr.layout (deleted) (history)
  • /common/common.layout (deleted) (history)
  • /ddraw/ddraw.cpp (modified) (history)
  • /ddraw/ddraw.h (modified) (history)
  • /ddraw/ddraw.vcxproj (modified) (history)
  • /ddraw/glDirectDraw.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.cpp (modified) (history)
  • /ddraw/glDirectDrawSurface.h (modified) (history)
  • /dxglcfg/dxglcfg.layout (deleted) (history)

Diff [purge]

Index: cfgmgr/cfgmgr.layout
@@ -1,10 +0,0 @@
2 -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
3 -<CodeBlocks_layout_file>
4 - <ActiveTarget name="Unicode Debug" />
5 - <File name="cfgmgr.cpp" open="0" top="0" tabpos="0">
6 - <Cursor position="10558" topLine="305" />
7 - </File>
8 - <File name="stdafx.h" open="0" top="0" tabpos="0">
9 - <Cursor position="972" topLine="0" />
10 - </File>
11 -</CodeBlocks_layout_file>
Index: cfgmgr
Property changes on: cfgmgr
___________________________________________________________________
Modified: svn:ignore
## -4,3 +4,4 ##
121 Release
132 Release no DXGL
143 bin
 4+*.cbTemp
Index: common/common.layout
@@ -1,4 +0,0 @@
2 -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
3 -<CodeBlocks_layout_file>
4 - <ActiveTarget name="Debug" />
5 -</CodeBlocks_layout_file>
Index: dxglcfg/dxglcfg.layout
@@ -1,7 +0,0 @@
2 -<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
3 -<CodeBlocks_layout_file>
4 - <ActiveTarget name="Debug" />
5 - <File name="dxglcfg.cpp" open="1" top="0" tabpos="1">
6 - <Cursor position="37000" topLine="0" />
7 - </File>
8 -</CodeBlocks_layout_file>
Index: ddraw/ddraw.cpp
@@ -30,8 +30,9 @@
3131 const GUID device_template =
3232 { 0x9ff8900, 0x8c4a, 0x4ba4, { 0xbf, 0x29, 0x56, 0x50, 0x4a, 0xf, 0x3b, 0xb3 } };
3333
 34+DWORD timer;
 35+int vsyncstatus;
3436
35 -
3637 DDRAW_API void WINAPI AcquireDDThreadLock()
3738 {
3839 // FIXME: Add thread lock
Index: ddraw/ddraw.h
@@ -58,5 +58,8 @@
5959
6060 extern DXGLCFG dxglcfg;
6161 extern bool gllock;
 62+extern DWORD timer;
 63+extern int vsyncstatus;
6264
 65+
6366 #endif //_DDRAW_H
\ No newline at end of file
Index: ddraw/ddraw.vcxproj
@@ -89,7 +89,7 @@
9090 <SubSystem>Windows</SubSystem>
9191 <GenerateDebugInformation>true</GenerateDebugInformation>
9292 <ModuleDefinitionFile>ddraw.def</ModuleDefinitionFile>
93 - <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
 93+ <AdditionalDependencies>$(OutDir)cfgmgr.lib;glu32.lib;opengl32.lib;winmm.lib;%(AdditionalDependencies)</AdditionalDependencies>
9494 </Link>
9595 </ItemDefinitionGroup>
9696 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug no DXGL|Win32'">
Index: ddraw/glDirectDraw.cpp
@@ -553,6 +553,7 @@
554554 fpusetup = false;
555555 threadsafe = false;
556556 nowindowchanges = false;
 557+ timer = timeGetTime();
557558 ZeroMemory(&oldmode,sizeof(DEVMODE));
558559 surfaces = (glDirectDrawSurface7 **)malloc(1024*sizeof(glDirectDrawSurface7 *));
559560 if(!surfaces)
@@ -776,7 +777,8 @@
777778 else ERR(DDERR_INVALIDPARAMS);
778779 ddCaps.dwCaps = DDCAPS_BLT | DDCAPS_BLTCOLORFILL | DDCAPS_BLTSTRETCH |
779780 DDCAPS_GDI | DDCAPS_PALETTE | DDCAPS_CANBLTSYSMEM;
780 - ddCaps.dwCaps2 = DDCAPS2_CANRENDERWINDOWED | DDCAPS2_WIDESURFACES | DDCAPS2_NOPAGELOCKREQUIRED;
 781+ ddCaps.dwCaps2 = DDCAPS2_CANRENDERWINDOWED | DDCAPS2_WIDESURFACES | DDCAPS2_NOPAGELOCKREQUIRED |
 782+ DDCAPS2_FLIPINTERVAL | DDCAPS2_FLIPNOVSYNC;
781783 ddCaps.dwFXCaps = DDFXCAPS_BLTSHRINKX | DDFXCAPS_BLTSHRINKY |
782784 DDFXCAPS_BLTSTRETCHX | DDFXCAPS_BLTSTRETCHY;
783785 ddCaps.dwPalCaps = DDPCAPS_8BIT | DDPCAPS_PRIMARYSURFACE;
@@ -1198,9 +1200,9 @@
11991201 HRESULT WINAPI glDirectDraw7::WaitForVerticalBlank(DWORD dwFlags, HANDLE hEvent)
12001202 {
12011203 if(dwFlags & DDWAITVB_BLOCKBEGINEVENT) return DDERR_UNSUPPORTED;
1202 - if(wglSwapIntervalEXT) wglSwapIntervalEXT(1);
 1204+ SetSwap(1);
12031205 primary->RenderScreen(primary->texture,primary);
1204 - if(wglSwapIntervalEXT) wglSwapIntervalEXT(0);
 1206+ SetSwap(0);
12051207 return DD_OK;
12061208 }
12071209 HRESULT WINAPI glDirectDraw7::GetAvailableVidMem(LPDDSCAPS2 lpDDSCaps2, LPDWORD lpdwTotal, LPDWORD lpdwFree)
@@ -1303,9 +1305,14 @@
13041306 hRenderWnd = CreateWindowA("DXGLRenderWindow","Renderer",WS_CHILD|WS_VISIBLE,0,0,rectRender.right - rectRender.left,
13051307 rectRender.bottom - rectRender.top,hWnd,NULL,NULL,this);
13061308 SetWindowPos(hRenderWnd,HWND_TOP,0,0,rectRender.right,rectRender.bottom,SWP_SHOWWINDOW);
1307 - PIXELFORMATDESCRIPTOR pfd =
1308 - {sizeof(PIXELFORMATDESCRIPTOR),1,PFD_SUPPORT_OPENGL,bpp,
1309 - 0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,PFD_MAIN_PLANE,0,0,0,0};
 1309+ PIXELFORMATDESCRIPTOR pfd;
 1310+ ZeroMemory(&pfd,sizeof(PIXELFORMATDESCRIPTOR));
 1311+ pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
 1312+ pfd.nVersion = 1;
 1313+ pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
 1314+ pfd.iPixelType = PFD_TYPE_RGBA;
 1315+ pfd.cColorBits = bpp;
 1316+ pfd.iLayerType = PFD_MAIN_PLANE;
13101317 hDC = GetDC(hRenderWnd);
13111318 if(!hDC)
13121319 {
Index: ddraw/glDirectDrawSurface.cpp
@@ -24,6 +24,16 @@
2525 #include "glDirectDrawPalette.h"
2626 #include "glDirectDrawClipper.h"
2727
 28+int swapinterval;
 29+inline void SetSwap(int swap)
 30+{
 31+ if(swap != swapinterval)
 32+ {
 33+ wglSwapIntervalEXT(swap);
 34+ swapinterval = swap;
 35+ }
 36+}
 37+
2838 inline int NextMultipleOf8(int number){return ((number+7) & (~7));}
2939 inline int NextMultipleOf4(int number){return ((number+3) & (~3));}
3040 inline int NextMultipleOf2(int number){return ((number+1) & (~1));}
@@ -715,6 +725,16 @@
716726 }
717727 HRESULT WINAPI glDirectDrawSurface7::Flip(LPDIRECTDRAWSURFACE7 lpDDSurfaceTargetOverride, DWORD dwFlags)
718728 {
 729+ int test;
 730+ if(dwFlags & DDFLIP_NOVSYNC) SetSwap(0);
 731+ else
 732+ {
 733+ if(dwFlags & DDFLIP_INTERVAL3) SetSwap(3);
 734+ else if(dwFlags & DDFLIP_INTERVAL2) SetSwap(2);
 735+ else if(dwFlags & DDFLIP_INTERVAL4) SetSwap(4);
 736+ else SetSwap(1);
 737+ }
 738+
719739 int flips = 1;
720740 if(lpDDSurfaceTargetOverride) ERR(DDERR_GENERIC);
721741 if(ddsd.ddsCaps.dwCaps & DDSCAPS_FLIP)
Index: ddraw/glDirectDrawSurface.h
@@ -19,6 +19,8 @@
2020 #ifndef _GLDIRECTDRAWSURFACE_H
2121 #define _GLDIRECTDRAWSURFACE_H
2222
 23+extern inline void SetSwap(int swap);
 24+
2325 typedef struct
2426 {
2527 bool enabled;