From 05ad8604b58f355890f0e3804906c7e8d598edfa Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Tue, 3 Aug 2004 17:50:18 +0000 Subject: Bug fix from user GKW on the JOGL forums for problems reported by users in JOGL 1.1 betas where the code path for wglChoosePixelFormatARB (supporting full-scene antialiasing) was failing on older cards. The old drivers expect an OpenGL context to be current while the wglChoosePixelFormatARB and associated calls are being made, even though the documentation explicitly states that this is not necessary. GKW's fix creates a native window synchronously (independent of the AWT) and associates an OpenGL context with it which is used to choose pixel formats for other windows on the same GraphicsDevice. Upon VM shutdown, a native message pump is started which causes proper disposal of the native window and its OpenGL contexts. There is currently no bug ID associated with this fix, although it may be a component of completely addressing several open bugs. Also includes a bug fix from GKW and kbr for: Issue 98: Just 1st frame rendering on ATI Radeon This was a race condition between JOGL's automatic discovery that the ATI_WORKAROUND was needed and the creation of the first GLCanvas and associated Animator. The need for disabling the setRenderingThread optimization was computed too late, incorrectly locking out other threads (in particular, the AWT event queue thread) from performing rendering of the component. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/trunk@144 232f8b59-042b-4e1e-8c03-345bb8c30851 --- make/build.xml | 4 +- make/stub_includes/win32/wingdi.h | 40 ++++++++++++++++ make/wgl-CustomCCode.c | 99 +++++++++++++++++++++++++++++++++++++++ make/wingdi-win32.cfg | 2 + 4 files changed, 143 insertions(+), 2 deletions(-) create mode 100755 make/wgl-CustomCCode.c (limited to 'make') diff --git a/make/build.xml b/make/build.xml index 41536e8b4..80adba7f0 100644 --- a/make/build.xml +++ b/make/build.xml @@ -265,7 +265,7 @@ - + @@ -315,7 +315,7 @@ - + diff --git a/make/stub_includes/win32/wingdi.h b/make/stub_includes/win32/wingdi.h index 3cb6f8568..2141135e7 100644 --- a/make/stub_includes/win32/wingdi.h +++ b/make/stub_includes/win32/wingdi.h @@ -83,6 +83,37 @@ typedef struct tagPIXELFORMATDESCRIPTOR #define PFD_MAIN_PLANE 0 #define PFD_OVERLAY_PLANE 1 #define PFD_UNDERLAY_PLANE (-1) +#define WGL_SWAP_MAIN_PLANE 1 +#define WGL_SWAP_OVERLAY1 2 +#define WGL_SWAP_OVERLAY2 4 +#define WGL_SWAP_OVERLAY3 8 +#define WGL_SWAP_OVERLAY4 16 +#define WGL_SWAP_OVERLAY5 32 +#define WGL_SWAP_OVERLAY6 64 +#define WGL_SWAP_OVERLAY7 128 +#define WGL_SWAP_OVERLAY8 256 +#define WGL_SWAP_OVERLAY9 512 +#define WGL_SWAP_OVERLAY10 1024 +#define WGL_SWAP_OVERLAY11 2048 +#define WGL_SWAP_OVERLAY12 4096 +#define WGL_SWAP_OVERLAY13 8192 +#define WGL_SWAP_OVERLAY14 16384 +#define WGL_SWAP_OVERLAY15 32768 +#define WGL_SWAP_UNDERLAY1 65536 +#define WGL_SWAP_UNDERLAY2 0x20000 +#define WGL_SWAP_UNDERLAY3 0x40000 +#define WGL_SWAP_UNDERLAY4 0x80000 +#define WGL_SWAP_UNDERLAY5 0x100000 +#define WGL_SWAP_UNDERLAY6 0x200000 +#define WGL_SWAP_UNDERLAY7 0x400000 +#define WGL_SWAP_UNDERLAY8 0x800000 +#define WGL_SWAP_UNDERLAY9 0x1000000 +#define WGL_SWAP_UNDERLAY10 0x2000000 +#define WGL_SWAP_UNDERLAY11 0x4000000 +#define WGL_SWAP_UNDERLAY12 0x8000000 +#define WGL_SWAP_UNDERLAY13 0x10000000 +#define WGL_SWAP_UNDERLAY14 0x20000000 +#define WGL_SWAP_UNDERLAY15 0x40000000 /* PIXELFORMATDESCRIPTOR flags */ #define PFD_DOUBLEBUFFER 0x00000001 @@ -132,6 +163,7 @@ WINGDIAPI BOOL WINAPI wglMakeCurrent(HDC, HGLRC); WINGDIAPI BOOL WINAPI wglShareLists(HGLRC, HGLRC); WINGDIAPI BOOL WINAPI SwapBuffers(HDC); WINGDIAPI PROC WINAPI wglGetProcAddress(LPCSTR); +WINGDIAPI BOOL WINAPI wglSwapLayerBuffers(HDC,UINT); /* --- FIXME: need to handle these entry points! WINGDIAPI HGLRC WINAPI wglCreateLayerContext(HDC, int); @@ -150,3 +182,11 @@ WINGDIAPI HBITMAP WINAPI CreateDIBSection(HDC, CONST BITMAPINFO *, UINT, VOID ** WINGDIAPI BOOL WINAPI DeleteDC(HDC); WINGDIAPI BOOL WINAPI DeleteObject(HGDIOBJ); WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC, HGDIOBJ); + +// Routines for creation of a dummy device context and OpenGL context +// for the purposes of getting wglChoosePixelFormatARB and associated +// routines +WINGDIAPI HDC WINAPI GetDC(HDC); +WINGDIAPI HDC WINAPI CreateDummyWindow(int,int,int,int); +WINGDIAPI VOID WINAPI DestroyDummyWindow(HWND,HDC); +WINGDIAPI VOID WINAPI NativeEventLoop(); diff --git a/make/wgl-CustomCCode.c b/make/wgl-CustomCCode.c new file mode 100755 index 000000000..be233fd9a --- /dev/null +++ b/make/wgl-CustomCCode.c @@ -0,0 +1,99 @@ +#include + +LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); +ATOM oglClass = 0; + +HWND CreateDummyWindow( int x, int y, int width, int height ) { + RECT rect; + HINSTANCE hInstance; + DWORD dwExStyle; + DWORD dwStyle; + HWND hWnd; + ZeroMemory( &rect, sizeof( rect ) ); + // I don't know if we need this but it can't hurt + if( width < 0 ) { + rect.left = x + width; + rect.right = x; + } else { + rect.left = x; + rect.right = x + width; + } + if( height < 0 ) { + rect.top = y + height; + rect.bottom = y; + } else { + rect.top = y; + rect.bottom = y + height; + } + hInstance = GetModuleHandle(NULL); + + if( !oglClass ) { + WNDCLASS wc; + ZeroMemory( &wc, sizeof( wc ) ); + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = (WNDPROC) WndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = "OpenGL"; + if( !(oglClass = RegisterClass( &wc )) ) { + printf( "RegisterClass Failed: %d\n", GetLastError() ); + return( 0 ); + } + } + + dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + dwStyle = WS_OVERLAPPEDWINDOW; + if( !(hWnd=CreateWindowEx( dwExStyle, "OpenGL", "OpenGL", + dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, + rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + NULL, NULL, hInstance, NULL ) ) ) { + return( 0 ); + } + return( hWnd ); +} + +void NativeEventLoop() { + MSG msg; + BOOL ret; + // Grab windows system messages from queue + while( ( ret = GetMessage( &msg, NULL, 0, 0 ) ) != 0 ) { + if( ret == -1 ) { + printf( "Error GetMessage: %d", GetLastError() ); + } else { + DispatchMessage( &msg ); + } + } +} + +void DestroyDummyWindow(HWND handle, HDC hdc) { + // Post a close window message from shutdown hook thread to + // window message pump thread + if( !PostMessage( handle, WM_CLOSE, 0, (LPARAM) hdc ) ) { + printf( "PostMessage Failed: %d\n", GetLastError() ); + } +} + +LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { + switch( uMsg ) { + case WM_CLOSE: + // Destroy HDC + if( ReleaseDC( hWnd, (HDC) lParam ) != 1 ) { + printf( "Error Releasing DC: %d\n", GetLastError() ); + } + // Destroy HWND + if( DestroyWindow( hWnd ) == 0 ) { + printf( "Error Destroying Window: %d\n", GetLastError() ); + } + break; + case WM_DESTROY: + // Terminate Dummy Window + PostQuitMessage(0); + return(0); + } + return DefWindowProc(hWnd,uMsg,wParam,lParam); +} diff --git a/make/wingdi-win32.cfg b/make/wingdi-win32.cfg index 622cef25d..a3c5a5ebb 100644 --- a/make/wingdi-win32.cfg +++ b/make/wingdi-win32.cfg @@ -24,3 +24,5 @@ CustomCCode /* This typedef is only needed for VC6 */ CustomCCode #if _MSC_VER <= 1200 CustomCCode typedef int intptr_t; CustomCCode #endif + +IncludeAs CustomCCode wgl-CustomCCode.c -- cgit v1.2.3