Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tweaks: DDS to glmax2d, MSAA to glgraphics #131

Merged
merged 4 commits into from May 14, 2019

Conversation

markcwm
Copy link
Contributor

@markcwm markcwm commented May 13, 2019

Okay, just changed the 5 files this time, also forgot to edit the NG include line in glgraphics.win32.c last night so glad you didn't commit it. :)

@GWRon
Copy link
Contributor

GWRon commented May 13, 2019

As the glgraphics file is a "complete replacement" I pasted both files to Meld and created a Diff:

--- <unbenannt>
+++ <unbenannt>
@@ -11,6 +11,12 @@
 	_DEPTHBUFFER=	0x8,
 	_STENCILBUFFER=	0x10,
 	_ACCUMBUFFER=	0x20,
+
+	_MULTISAMPLE2X=	0x40,
+	_MULTISAMPLE4X=	0x80,
+	_MULTISAMPLE8X=	0x100,
+	_MULTISAMPLE16X=0x200,
+	_HIDDEN=0x400,
 };
 
 enum{
@@ -20,6 +26,113 @@
 	MODE_DISPLAY
 };
 
+//------------
+// NEW SECTION
+//------------
+
+#define WGL_NUMBER_PIXEL_FORMATS_ARB        0x2000
+#define WGL_DRAW_TO_WINDOW_ARB              0x2001
+#define WGL_DRAW_TO_BITMAP_ARB              0x2002
+#define WGL_ACCELERATION_ARB                0x2003
+#define WGL_NEED_PALETTE_ARB                0x2004
+#define WGL_NEED_SYSTEM_PALETTE_ARB         0x2005
+#define WGL_SWAP_LAYER_BUFFERS_ARB          0x2006
+#define WGL_SWAP_METHOD_ARB                 0x2007
+#define WGL_NUMBER_OVERLAYS_ARB             0x2008
+#define WGL_NUMBER_UNDERLAYS_ARB            0x2009
+#define WGL_TRANSPARENT_ARB                 0x200A
+#define WGL_TRANSPARENT_RED_VALUE_ARB       0x2037
+#define WGL_TRANSPARENT_GREEN_VALUE_ARB     0x2038
+#define WGL_TRANSPARENT_BLUE_VALUE_ARB      0x2039
+#define WGL_TRANSPARENT_ALPHA_VALUE_ARB     0x203A
+#define WGL_TRANSPARENT_INDEX_VALUE_ARB     0x203B
+#define WGL_SHARE_DEPTH_ARB                 0x200C
+#define WGL_SHARE_STENCIL_ARB               0x200D
+#define WGL_SHARE_ACCUM_ARB                 0x200E
+#define WGL_SUPPORT_GDI_ARB                 0x200F
+#define WGL_SUPPORT_OPENGL_ARB              0x2010
+#define WGL_DOUBLE_BUFFER_ARB               0x2011
+#define WGL_STEREO_ARB                      0x2012
+#define WGL_PIXEL_TYPE_ARB                  0x2013
+#define WGL_COLOR_BITS_ARB                  0x2014
+#define WGL_RED_BITS_ARB                    0x2015
+#define WGL_RED_SHIFT_ARB                   0x2016
+#define WGL_GREEN_BITS_ARB                  0x2017
+#define WGL_GREEN_SHIFT_ARB                 0x2018
+#define WGL_BLUE_BITS_ARB                   0x2019
+#define WGL_BLUE_SHIFT_ARB                  0x201A
+#define WGL_ALPHA_BITS_ARB                  0x201B
+#define WGL_ALPHA_SHIFT_ARB                 0x201C
+#define WGL_ACCUM_BITS_ARB                  0x201D
+#define WGL_ACCUM_RED_BITS_ARB              0x201E
+#define WGL_ACCUM_GREEN_BITS_ARB            0x201F
+#define WGL_ACCUM_BLUE_BITS_ARB             0x2020
+#define WGL_ACCUM_ALPHA_BITS_ARB            0x2021
+#define WGL_DEPTH_BITS_ARB                  0x2022
+#define WGL_STENCIL_BITS_ARB                0x2023
+#define WGL_AUX_BUFFERS_ARB                 0x2024
+#define WGL_NO_ACCELERATION_ARB             0x2025
+#define WGL_GENERIC_ACCELERATION_ARB        0x2026
+#define WGL_FULL_ACCELERATION_ARB           0x2027
+#define WGL_SWAP_EXCHANGE_ARB               0x2028
+#define WGL_SWAP_COPY_ARB                   0x2029
+#define WGL_SWAP_UNDEFINED_ARB              0x202A
+#define WGL_TYPE_RGBA_ARB                   0x202B
+#define WGL_TYPE_COLORINDEX_ARB             0x202C
+#define WGL_SAMPLE_BUFFERS_ARB              0x2041
+#define WGL_SAMPLES_ARB                     0x2042
+
+static BOOL _wglChoosePixelFormatARB( int hDC, const int *intAttribs, const FLOAT *floatAttribs, unsigned int maxFormats, int *lPixelFormat, unsigned int *numFormats){
+	//Define function pointer datatype
+	typedef BOOL (APIENTRY * WGLCHOOSEPIXELFORMATARB) (int hDC, const int *intAttribs, const FLOAT *floatAttribs, unsigned int maxFormats, int *lPixelFormat, unsigned int *numFormats);
+
+	//Get the "wglChoosePixelFormatARB" function
+	WGLCHOOSEPIXELFORMATARB wglChoosePixelFormatARB = (WGLCHOOSEPIXELFORMATARB)wglGetProcAddress("wglChoosePixelFormatARB");
+	if(wglChoosePixelFormatARB)
+		return wglChoosePixelFormatARB(hDC, intAttribs, floatAttribs, maxFormats, lPixelFormat, numFormats);
+	else
+		MessageBox(0,"wglChoosePixelFormatARB() function not found!","Error",0);
+	return 0;
+}
+
+static int MyChoosePixelFormat( int hDC, const int flags ){
+	//Extract multisample mode from flags 
+	int multisample = 0;
+	if (_MULTISAMPLE2X & flags) multisample = 2;
+	else if (_MULTISAMPLE4X & flags) multisample = 4;
+	else if (_MULTISAMPLE8X & flags) multisample = 8;
+	else if (_MULTISAMPLE16X & flags) multisample = 16;
+
+	//Empty float attributes array
+	float floatAttribs[] = {0.0,0.0};
+	
+	//Some variables
+	int lPixelFormat = 0;
+	int numFormats=1;
+	int result=0;
+
+	//Include the multisample in the flags
+	if (multisample > 0){
+		int intAttribs[] = {WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,WGL_SUPPORT_OPENGL_ARB,GL_TRUE,WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,WGL_COLOR_BITS_ARB,24,WGL_ALPHA_BITS_ARB,8,WGL_DEPTH_BITS_ARB,16,WGL_DOUBLE_BUFFER_ARB,GL_TRUE,WGL_SAMPLE_BUFFERS_ARB,GL_TRUE,WGL_SAMPLES_ARB,multisample,0,0};
+		result=_wglChoosePixelFormatARB(hDC, &intAttribs, &floatAttribs, 1, &lPixelFormat, &numFormats);
+	}else{
+		int intAttribs[] = {WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,WGL_SUPPORT_OPENGL_ARB,GL_TRUE,WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,WGL_COLOR_BITS_ARB,24,WGL_ALPHA_BITS_ARB,8,WGL_DEPTH_BITS_ARB,16,WGL_DOUBLE_BUFFER_ARB,GL_TRUE,WGL_SAMPLE_BUFFERS_ARB,GL_FALSE,0,0};
+		result=_wglChoosePixelFormatARB(hDC, &intAttribs, &floatAttribs, 1, &lPixelFormat, &numFormats);
+	}
+
+	//If result=True return lPixelFormat
+	if (result > 0){
+		return lPixelFormat;
+	}else{
+		MessageBox(0,"wglChoosePixelFormatARB() failed.","Error",MB_OK);
+		return 0;
+	}
+}
+
+//------------
+//
+//------------
+
 extern int _bbusew;
 
 static const char *CLASS_NAME="BlitzMax GLGraphics";
@@ -52,6 +165,10 @@
 
 static const wchar_t *appTitleW(){
 	return bbTmpWString( bbAppTitle );
+}
+
+static const char *_appTitle(){
+	return bbStringToCString( bbAppTitle );
 }
 
 static void _initPfd( PIXELFORMATDESCRIPTOR *pfd,int flags ){
@@ -142,6 +259,12 @@
 	case WM_PAINT:
 		ValidateRect( hwnd,0 );
 		return 0;
+	case WM_LBUTTONDOWN: case WM_RBUTTONDOWN: case WM_MBUTTONDOWN:
+		if( !_fullScreen ) SetCapture( hwnd );
+		return 0;
+	case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP:
+		if( !_fullScreen ) ReleaseCapture();
+		return 0;
 	}
 	return _bbusew ? DefWindowProcW( hwnd,msg,wp,lp ) : DefWindowProc( hwnd,msg,wp,lp );
 }
@@ -157,18 +280,16 @@
 		wc.hInstance=GetModuleHandle(0);
 		wc.lpszClassName=CLASS_NAMEW;
 		wc.hCursor=(HCURSOR)LoadCursor( 0,IDC_ARROW );
-		wc.hIcon = bbAppIcon(wc.hInstance);
 		wc.hbrBackground=0;
 		if( !RegisterClassExW( &wc ) ) exit( -1 );
 	}else{
-		WNDCLASSEX wc={sizeof(wc)};
+		WNDCLASSEX wc={sizeof(wc)}; //WNDCLASS wc={0};
 		wc.style=CS_HREDRAW|CS_VREDRAW|CS_OWNDC;
 		wc.lpfnWndProc=(WNDPROC)_wndProc;
 		wc.hInstance=GetModuleHandle(0);
 		wc.lpszClassName=CLASS_NAME;
 		wc.hCursor=(HCURSOR)LoadCursor( 0,IDC_ARROW );
-		wc.hIcon = bbAppIcon(wc.hInstance);
-		wc.hbrBackground=0;
+		wc.hbrBackground=0; //(HBRUSH)GetStockObject(BLACK_BRUSH);
 		if( !RegisterClassEx( &wc ) ) exit( -1 );
 	}
 
@@ -257,14 +378,23 @@
 	PIXELFORMATDESCRIPTOR pfd;
 	RECT rect;
 	
-	_initWndClass();
+	_initWndClass(); //bbGLGraphicsShareContexts();
 	
 	hdc=GetDC( hwnd );
 	if( !hdc ) return 0;
 	
 	_initPfd( &pfd,flags );
 
-	pf=ChoosePixelFormat( hdc,&pfd );
+	int multisample = 0;
+	if (_MULTISAMPLE2X & flags) multisample = 2;
+	else if (_MULTISAMPLE4X & flags) multisample = 4;
+	else if (_MULTISAMPLE8X & flags) multisample = 8;
+	else if (_MULTISAMPLE16X & flags) multisample = 16;
+	if (multisample>0){
+		pf=MyChoosePixelFormat( hdc,flags );
+	}else{
+		pf=ChoosePixelFormat( hdc,&pfd );
+	}
 	if( !pf ) return 0;
 	SetPixelFormat( hdc,pf,&pfd );
 	hglrc=wglCreateContext( hdc );
@@ -304,7 +434,7 @@
 	int hwnd_style;
 	RECT rect={0,0,width,height};
 	
-	_initWndClass();
+	_initWndClass(); //bbGLGraphicsShareContexts();
 	
 	if( depth ){
 		mode=MODE_DISPLAY;
@@ -344,7 +474,16 @@
 	_initPfd( &pfd,flags );
 
 	hdc=GetDC( hwnd );
-	pf=ChoosePixelFormat( hdc,&pfd );
+	int multisample = 0;
+	if (_MULTISAMPLE2X & flags) multisample = 2;
+	else if (_MULTISAMPLE4X & flags) multisample = 4;
+	else if (_MULTISAMPLE8X & flags) multisample = 8;
+	else if (_MULTISAMPLE16X & flags) multisample = 16;
+	if (multisample>0){
+		pf=MyChoosePixelFormat( hdc,flags );
+	}else{
+		pf=ChoosePixelFormat( hdc,&pfd );
+	}
 	if( !pf ){
 		DestroyWindow( hwnd );
 		return 0;
@@ -371,8 +510,14 @@
 	context->succ=_contexts;
 	_contexts=context;
 	
-	ShowWindow( hwnd,SW_SHOW );
-	
+	//if ((_HIDDEN & flags)==0) 
+
+	if (_HIDDEN & flags){
+		//MessageBox(0,"HIDDEN","",0);
+	}else{
+		//MessageBox(0,"SHOWN","",0);
+		ShowWindow( hwnd,SW_SHOW );
+	}
 	return context;
 }
 
@@ -404,6 +549,17 @@
 	*p=t->succ;
 }
 
+void bbGLGraphicsSwapSharedContext(){
+
+	if( wglGetCurrentContext()!=_sharedContext->hglrc ){
+		wglMakeCurrent( _sharedContext->hdc,_sharedContext->hglrc );
+	}else if( _currentContext ){
+		wglMakeCurrent( _currentContext->hdc,_currentContext->hglrc );
+	}else{
+		wglMakeCurrent( 0,0 );
+	}
+}
+
 void bbGLGraphicsSetGraphics( BBGLContext *context ){
 
 	if( context==_currentContext ) return;

@woollybah woollybah merged commit 4d8d341 into bmx-ng:master May 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants