Skip to content
This repository
Open
wants to merge 9 commits into from

2 participants

kphillisjr Oliver McFadden
kphillisjr

Implemented OpenGL over EGL api. The changes are minor and shows how clean the switch from OpenGL ES to OpenGL can be.

kphillisjr

This Change is because of errors when compiling with gcc 4.6.3. There is probably other changes but this at least fixes compilation problems on Ubuntu 12.04 and linux mint 13.

added some commits August 18, 2012
kphillisjr Added more Debug information about EGL Contexts. 50dad0d
kphillisjr Changed the location of the EGL Debug information query. ac0e599
kphillisjr Fixed compile on systems involving XF86 video mode extension. ( propr…
…ietary driver )

Added extra debugging information pertaining to GLX extensions.
Added more documentation to OpenGL ES.
Fixed EGL initialization. Now the rendering api will properly initialize to OpenGL using EGL context.
d57f942
kphillisjr Added Small change to help verify Context information. This is to fin…
…d out if the OpenGL ( or OpenGL ES ) Context that was supposed to be created actually is.
2fc65f2
kphillisjr

Found a bug in mesa... It appears Mesa will try to make an OpenGL ES context no matter what. Even though All the proper information suggests that I am wanting an OpenGL Context. This is why commit #2fc65f2 exists.

kphillisjr

This variable is still used in Windows/Mac OSX. This should help fix the problems with compiling on these platforms.

Oliver McFadden
Owner

I wouldn't bother too much with Windows and OSX support. It's likely to go away as soon as I have time to make the big git rm -rf ... and unifdef the code.

I'll review the code later this week (probably, assuming Real Life(TM) doesn't have other plans...)

Oliver McFadden
Owner

Uhh, so Real Life made other plans after all... I'll try to get to review it this weekend. Hasn't been forgotten, I've just been extremely busy lately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
16  neo/SConstruct
@@ -15,7 +15,7 @@ conf_filename='site.conf'
15 15
 serialized=['CC', 'CXX', 'JOBS', 'BUILD', 'IDNET_HOST', 'DEDICATED',
16 16
 	'DEBUG_MEMORY', 'LIBC_MALLOC', 'ID_NOLANADDRESS', 'ID_MCHECK', 'ALSA',
17 17
 	'TARGET_CORE', 'TARGET_GAME', 'TARGET_D3XP', 'TARGET_MONO', 'TARGET_DEMO', 'NOCURL',
18  
-	'BUILD_ROOT', 'BUILD_GAMEPAK', 'BASEFLAGS', 'SILENT', 'TARGET_OPENGL',
  18
+	'BUILD_ROOT', 'BUILD_GAMEPAK', 'BASEFLAGS', 'SILENT', 'TARGET_OPENGL', 'TARGET_OPENGL_EGL',
19 19
 	'TARGET_ANDROID', 'NDK' ]
20 20
 
21 21
 # global build mode ------------------------------
@@ -95,7 +95,13 @@ TARGET_DEMO (default 0)
95 95
 TARGET_OPENGL (default 0)
96 96
 	Build an OpenGL renderer instead of OpenGL ES2.0.
97 97
 	GLSL shaders are compatible.
  98
+	NOTE: This default Contexts to Enable OpenGL. For Linux, This is GLX.
98 99
 
  100
+TARGET_OPENGL_EGL (default 0)
  101
+	Build an OpenGL renderer instead of OpenGL ES2.0.
  102
+	GLSL shaders are compatible.
  103
+	NOTE: This use EGL contexts to activate OpenGL.
  104
+	
99 105
 TARGET_ANDROID (default 0)
100 106
 	Build the Android version.
101 107
 
@@ -176,6 +182,7 @@ TARGET_D3XP = '1'
176 182
 TARGET_MONO = '0'
177 183
 TARGET_DEMO = '0'
178 184
 TARGET_OPENGL = '0'
  185
+TARGET_OPENGL_EGL = '0'
179 186
 TARGET_ANDROID = '0'
180 187
 NDK = ''
181 188
 IDNET_HOST = ''
@@ -395,8 +402,9 @@ local_idlibpic = 0
395 402
 local_d3xp = 0
396 403
 # OpenGL
397 404
 local_opengl = 0
  405
+local_opengl_egl = 0
398 406
 
399  
-GLOBALS = 'g_env g_env_noopt g_game_env g_os ID_MCHECK ALSA idlib_objects game_objects local_dedicated local_gamedll local_demo local_idlibpic local_curl local_d3xp local_opengl OPTCPPFLAGS NDK'
  407
+GLOBALS = 'g_env g_env_noopt g_game_env g_os ID_MCHECK ALSA idlib_objects game_objects local_dedicated local_gamedll local_demo local_idlibpic local_curl local_d3xp local_opengl local_opengl_egl OPTCPPFLAGS NDK'
400 408
 
401 409
 # end general configuration ----------------------
402 410
 
@@ -415,6 +423,10 @@ if ( TARGET_OPENGL != '0' ):
415 423
 	local_opengl = 1
416 424
 	Export( 'GLOBALS ' + GLOBALS )
417 425
 
  426
+if ( TARGET_OPENGL_EGL != '0' ):
  427
+	local_opengl_egl = local_opengl = 1
  428
+	Export( 'GLOBALS ' + GLOBALS )
  429
+	
418 430
 if ( TARGET_ANDROID != '0' ):
419 431
 	Export( 'GLOBALS ' + GLOBALS )
420 432
 
1  neo/renderer/RenderSystem_init.cpp
@@ -67,6 +67,7 @@ idCVar r_znear("r_znear", "3", CVAR_RENDERER | CVAR_FLOAT, "near Z clip plane di
67 67
 
68 68
 idCVar r_ignoreGLErrors("r_ignoreGLErrors", "1", CVAR_RENDERER | CVAR_BOOL, "ignore GL errors");
69 69
 idCVar r_finish("r_finish", "0", CVAR_RENDERER | CVAR_BOOL, "force a call to glFinish() every frame");
  70
+idCVar r_swapInterval( "r_swapInterval", "0", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_INTEGER, "changes Vertical Sync Setting" );
70 71
 
71 72
 idCVar r_gamma("r_gamma", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_FLOAT, "changes gamma tables", 0.5f, 3.0f);
72 73
 idCVar r_brightness("r_brightness", "1", CVAR_RENDERER | CVAR_ARCHIVE | CVAR_FLOAT, "changes gamma tables", 0.5f, 2.0f);
5  neo/renderer/qgl.h
@@ -38,7 +38,12 @@ If you have questions concerning this license or the applicable additional terms
38 38
 #ifdef ID_TARGET_OPENGL
39 39
 #include <GL/gl.h>
40 40
 #include <GL/glext.h>
  41
+#ifdef ID_TARGET_OPENGL_GLX
41 42
 #include <GL/glx.h>
  43
+#else
  44
+#include <EGL/egl.h>
  45
+#include <EGL/eglext.h>
  46
+#endif
42 47
 #define GL_APIENTRY	GLAPIENTRY
43 48
 #else
44 49
 #include <EGL/egl.h>
1  neo/renderer/tr_local.h
@@ -832,6 +832,7 @@ extern idCVar r_znear;					// near Z clip plane
832 832
 
833 833
 extern idCVar r_finish;					// force a call to glFinish() every frame
834 834
 extern idCVar r_frontBuffer;			// draw to front buffer for debugging
  835
+extern idCVar r_swapInterval;                  // changes Vertical Sync Swap Interval.
835 836
 extern idCVar r_offsetFactor;			// polygon offset parameter
836 837
 extern idCVar r_offsetUnits;			// polygon offset parameter
837 838
 extern idCVar r_singleTriangle;			// only draw a single triangle per primitive
2  neo/sys/linux/gl_extensions.cpp
@@ -66,7 +66,7 @@ GLExtension_t GLimp_ExtensionPointer(const char *name)
66 66
 #endif
67 67
 	GLExtension_t ret;
68 68
 
69  
-#ifdef ID_TARGET_OPENGL
  69
+#ifdef ID_TARGET_OPENGL_GLX
70 70
 	ret = glXGetProcAddressARB(name);
71 71
 #else
72 72
 	ret = eglGetProcAddress(name);
92  neo/sys/linux/gles2.cpp
@@ -91,6 +91,12 @@ bool GLimp_SpawnRenderThread(void (*a)())
91 91
 
92 92
 void GLimp_ActivateContext()
93 93
 {
  94
+#if ID_TARGET_OPENGL
  95
+	assert(eglDisplay);
  96
+	assert(eglSurface);
  97
+	assert(eglContext);
  98
+	eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
  99
+#endif
94 100
 #if 0
95 101
 	assert(dpy);
96 102
 	assert(ctx);
@@ -100,6 +106,10 @@ void GLimp_ActivateContext()
100 106
 
101 107
 void GLimp_DeactivateContext()
102 108
 {
  109
+#if ID_TARGET_OPENGL
  110
+	assert(eglDisplay);
  111
+	eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
  112
+#endif
103 113
 #if 0
104 114
 	assert(dpy);
105 115
 	glXMakeCurrent(dpy, None, NULL);
@@ -242,6 +252,15 @@ void GLimp_Shutdown()
242 252
 void GLimp_SwapBuffers()
243 253
 {
244 254
 	assert(eglDisplay && eglSurface);
  255
+
  256
+#ifdef ID_TARGET_OPENGL
  257
+	if (r_swapInterval.IsModified()) {
  258
+		// Allow disabling of Vertical Sync.
  259
+		r_swapInterval.ClearModified();
  260
+		eglSwapInterval(eglDisplay, r_swapInterval.GetInteger());
  261
+	}
  262
+#endif
  263
+
245 264
 	eglSwapBuffers(eglDisplay, eglSurface);
246 265
 }
247 266
 
@@ -336,13 +355,13 @@ bool GLimp_OpenDisplay(void)
336 355
 
337 356
 /*
338 357
 ===============
339  
-GLX_Init
  358
+EGL_Init
340 359
 ===============
341 360
 */
342 361
 	EGLConfig eglConfig;
343 362
 	EGLint eglNumConfig;
344 363
 
345  
-int GLX_Init(glimpParms_t a)
  364
+int EGL_Init(glimpParms_t a)
346 365
 {
347 366
 	EGLint attrib[] = {
348 367
 		EGL_RED_SIZE, 8,	//  1,  2
@@ -352,7 +371,11 @@ int GLX_Init(glimpParms_t a)
352 371
 		EGL_DEPTH_SIZE, 24,	//  9, 10
353 372
 		EGL_STENCIL_SIZE, 8,	// 11, 12
354 373
 		EGL_BUFFER_SIZE, 24,	// 13, 14
  374
+#ifdef ID_TARGET_OPENGL
  375
+		EGL_RENDERABLE_TYPE, EGL_OPENGL_BIT,	// 15, 16
  376
+#else		
355 377
 		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,	// 15, 16
  378
+#endif
356 379
 		EGL_NONE,	// 17
357 380
 	};
358 381
 	// these match in the array
@@ -363,6 +386,7 @@ int GLX_Init(glimpParms_t a)
363 386
 #define ATTR_DEPTH_IDX	9
364 387
 #define ATTR_STENCIL_IDX	11
365 388
 #define ATTR_BUFFER_SIZE_IDX	13
  389
+#define ATTR_RENDERABLE_TYPE	15
366 390
 	Window root;
367 391
 	XVisualInfo *visinfo;
368 392
 	XSetWindowAttributes attr;
@@ -374,11 +398,25 @@ int GLX_Init(glimpParms_t a)
374 398
 	int i;
375 399
 	const char *glstring;
376 400
 
  401
+	common->Printf("Initializing EGL\n");
377 402
 	if (!GLimp_OpenDisplay()) {
378 403
 		return false;
379 404
 	}
380 405
 
381  
-	common->Printf("Initializing OpenGL display\n");
  406
+	glstring = (const char *) eglQueryString(eglDisplay,EGL_VENDOR);
  407
+	common->Printf("EGL_VENDOR: %s\n", (glstring)?glstring:"NULL");
  408
+
  409
+	glstring = (const char *) eglQueryString(eglDisplay,EGL_VERSION);
  410
+	common->Printf("EGL_VERSION: %s\n", (glstring)?glstring:"NULL");
  411
+
  412
+	glstring = (const char *) eglQueryString(eglDisplay,EGL_CLIENT_APIS);
  413
+	common->Printf("EGL_CLIENT_APIS: %s\n", (glstring)?glstring:"NULL");
  414
+	
  415
+	glstring = (const char *) eglQueryString(eglDisplay,EGL_EXTENSIONS);
  416
+	common->Printf("EGL_EXTENSIONS: %s\n", (glstring)?glstring:"NULL");
  417
+
  418
+	glstring = (attrib[ATTR_RENDERABLE_TYPE]==EGL_OPENGL_ES2_BIT)?"OpenGL ES": "OpenGL";
  419
+	common->Printf("Initializing %s display\n",glstring);
382 420
 
383 421
 	root = RootWindow(dpy, scrnum);
384 422
 
@@ -448,10 +486,15 @@ int GLX_Init(glimpParms_t a)
448 486
 #endif
449 487
 
450 488
 	// color, depth and stencil
  489
+
451 490
 	colorbits = 24;
452 491
 	depthbits = 24;
453 492
 	stencilbits = 8;
454 493
 
  494
+#ifdef ID_TARGET_OPENGL
  495
+	colorbits = 32;
  496
+#endif
  497
+
455 498
 	for (i = 0; i < 16; i++) {
456 499
 		// 0 - default
457 500
 		// 1 - minus colorbits
@@ -546,7 +589,7 @@ int GLX_Init(glimpParms_t a)
546 589
 	}
547 590
 
548 591
 	visinfo = malloc(sizeof(XVisualInfo));
549  
-	if (!(XMatchVisualInfo(dpy, scrnum, glConfig.depthBits, TrueColor, visinfo))) {
  592
+	if (!(XMatchVisualInfo(dpy, scrnum, glConfig.depthBits, TrueColor, (XVisualInfo*)visinfo))) {
550 593
 		common->Printf("Couldn't get a visual\n");
551 594
 		return false;
552 595
 	}
@@ -618,10 +661,23 @@ int GLX_Init(glimpParms_t a)
618 661
 	}
619 662
 
620 663
 	EGLint ctxattrib[] = {
  664
+#ifndef ID_TARGET_OPENGL
621 665
 		EGL_CONTEXT_CLIENT_VERSION, 2,
  666
+#endif
622 667
 		EGL_NONE
623 668
 	};
624 669
 
  670
+
  671
+#ifdef ID_TARGET_OPENGL
  672
+	// Not all EGL Implementations will bind the current API to OpenGL
  673
+	// automatically. Simply calling eglChooseConfig with EGL_RENDERABLE_TYPE
  674
+	// set to EGL_OPENGL_BIT.
  675
+	if(!eglBindAPI(EGL_OPENGL_API))
  676
+	{
  677
+		common->Printf("Couldn't Bind OpenGL API\n");
  678
+		return false;		
  679
+	}
  680
+#endif
625 681
 	eglContext = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, ctxattrib);
626 682
 	if (eglContext == EGL_NO_CONTEXT) {
627 683
 		common->Printf("Couldn't get a EGL context\n");
@@ -630,12 +686,38 @@ int GLX_Init(glimpParms_t a)
630 686
 
631 687
 	eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
632 688
 
  689
+	EGLint Context_RendererType;
  690
+	     
  691
+	eglQueryContext(eglDisplay, eglContext,EGL_CONTEXT_CLIENT_TYPE,&Context_RendererType);
  692
+
  693
+	switch (Context_RendererType)
  694
+	{
  695
+		case EGL_OPENGL_API:
  696
+			glstring = "OpenGL";
  697
+			break;
  698
+		case EGL_OPENGL_ES_API:
  699
+			glstring = "OpenGL ES";
  700
+			break;
  701
+		case EGL_OPENVG_API:
  702
+			common->Printf("Context Query Returned OpenVG. This is Unsupported\n");
  703
+			return false;
  704
+		default:
  705
+			common->Printf("Unknown Context Type. %04X\n",Context_RendererType);
  706
+			return false;
  707
+	}
  708
+	common->Printf("EGL_CONTEXT_CLIENT_TYPE: %s\n", glstring);
633 709
 	glstring = (const char *) glGetString(GL_RENDERER);
634 710
 	common->Printf("GL_RENDERER: %s\n", glstring);
635 711
 
636 712
 	glstring = (const char *) glGetString(GL_EXTENSIONS);
637 713
 	common->Printf("GL_EXTENSIONS: %s\n", glstring);
638 714
 
  715
+
  716
+#ifdef ID_TARGET_OPENGL
  717
+	// force Update of Vertical Sync setting on next frame
  718
+	r_swapInterval.SetModified();
  719
+#endif
  720
+
639 721
 	// FIXME: here, software GL test
640 722
 
641 723
 	glConfig.isFullscreen = a.fullScreen;
@@ -669,7 +751,7 @@ bool GLimp_Init(glimpParms_t a)
669 751
 		return false;
670 752
 	}
671 753
 
672  
-	if (!GLX_Init(a)) {
  754
+	if (!EGL_Init(a)) {
673 755
 		return false;
674 756
 	}
675 757
 
11  neo/sys/linux/glimp.cpp
@@ -335,10 +335,21 @@ int GLX_Init(glimpParms_t a)
335 335
 	int i;
336 336
 	const char *glstring;
337 337
 
  338
+	common->Printf("Initializing GLX\n");
  339
+
338 340
 	if (!GLimp_OpenDisplay()) {
339 341
 		return false;
340 342
 	}
341 343
 
  344
+	glstring = glXQueryExtensionsString( dpy, GLX_VENDOR);
  345
+	common->Printf("GLX_VENDOR: %s\n", (glstring)?glstring:"NULL");
  346
+
  347
+	glstring = glXQueryExtensionsString( dpy, GLX_VERSION);
  348
+	common->Printf("GLX_VERSION: %s\n", (glstring)?glstring:"NULL");
  349
+
  350
+	glstring = glXQueryExtensionsString( dpy, GLX_EXTENSIONS);
  351
+	common->Printf("GLX_EXTENSIONS: %s\n", (glstring)?glstring:"NULL");
  352
+	
342 353
 	common->Printf("Initializing OpenGL display\n");
343 354
 
344 355
 	root = RootWindow(dpy, scrnum);
9  neo/sys/scons/SConscript.core
@@ -264,7 +264,7 @@ if ( local_dedicated == 0 ):
264 264
 		sys_string += ' android/input.cpp'
265 265
 	else:
266 266
 		sys_string += ' linux/input.cpp'
267  
-	if ( local_opengl == 0 ):
  267
+	if ( local_opengl == 0 or local_opengl_egl == 1):
268 268
 		if g_os == 'Android':
269 269
 			sys_string += ' android/gles2.cpp'
270 270
 		else:
@@ -311,7 +311,8 @@ else:
311 311
 
312 312
 if ( local_opengl == 1 ):
313 313
 	local_env.Append( CPPDEFINES = [ 'ID_TARGET_OPENGL' ] )
314  
-
  314
+	if ( local_opengl_egl == 0 ):
  315
+		local_env.Append( CPPDEFINES = [ 'ID_TARGET_OPENGL_GLX' ] )
315 316
 sound_env = local_env.Clone()
316 317
 if g_os == 'Android':
317 318
 	sound_list = [ '../android/sound.cpp' ]
@@ -358,6 +359,10 @@ if ( local_dedicated == 0 ):
358 359
 		local_env.Append( LIBS = [ 'GLESv2', 'EGL' ] )
359 360
 	else:
360 361
 		local_env.Append( LIBS = [ 'GL' ] )
  362
+		if ( local_opengl_egl == 1 ):
  363
+			local_env.Append( LIBS = [ 'EGL' ] )
  364
+		else:
  365
+			local_env.Append( LIBS = [ 'Xxf86vm' ] )
361 366
 
362 367
 source_list = core_list
363 368
 source_list += idlib_objects
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.