/** * Initialize an EGL context for the current display. */ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { EGLContext context; EGLint ver = -1; EGLDisplay eglDisplay = fgDisplay.pDisplay.egl.Display; EGLConfig eglConfig = window->Window.pContext.egl.Config; /* On GLES, user specifies the target version with glutInitContextVersion */ EGLint attributes[32]; int where = 0; ATTRIB_VAL(EGL_CONTEXT_CLIENT_VERSION, fgState.MajorVersion); ATTRIB(EGL_NONE); context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, attributes); if (context == EGL_NO_CONTEXT) { fgWarning("Cannot initialize EGL context, err=%x\n", eglGetError()); fghContextCreationError(); } eglQueryContext(fgDisplay.pDisplay.egl.Display, context, EGL_CONTEXT_CLIENT_VERSION, &ver); if (ver != fgState.MajorVersion) fgError("Wrong GLES major version: %d\n", ver); return context; }
static void fghFillContextAttributes( int *attributes ) { int where = 0, contextFlags, contextProfile; ATTRIB_VAL( WGL_CONTEXT_MAJOR_VERSION_ARB, fgState.MajorVersion ); ATTRIB_VAL( WGL_CONTEXT_MINOR_VERSION_ARB, fgState.MinorVersion ); contextFlags = fghMapBit( fgState.ContextFlags, GLUT_DEBUG, WGL_CONTEXT_DEBUG_BIT_ARB ) | fghMapBit( fgState.ContextFlags, GLUT_FORWARD_COMPATIBLE, WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB ); if ( contextFlags != 0 ) { ATTRIB_VAL( WGL_CONTEXT_FLAGS_ARB, contextFlags ); } contextProfile = fghMapBit( fgState.ContextProfile, GLUT_CORE_PROFILE, WGL_CONTEXT_CORE_PROFILE_BIT_ARB ) | fghMapBit( fgState.ContextProfile, GLUT_COMPATIBILITY_PROFILE, WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB ); if ( contextProfile != 0 ) { ATTRIB_VAL( WGL_CONTEXT_PROFILE_MASK_ARB, contextProfile ); } ATTRIB( 0 ); }
int fghChooseConfig(EGLConfig* config) { EGLint attributes[32]; int where = 0; ATTRIB_VAL(EGL_SURFACE_TYPE, EGL_WINDOW_BIT); if (fgState.MajorVersion >= 2) { /* * Khronos does not specify a EGL_OPENGL_ES3_BIT outside of the OpenGL extension "EGL_KHR_create_context". There are numerous references on the internet that * say to use EGL_OPENGL_ES3_BIT, followed by many saying they can't find it in any headers. In fact, the offical updated specification for EGL does not have * any references to OpenGL ES 3.0. Tests have shown that EGL_OPENGL_ES2_BIT will work with ES 3.0. */ ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT); } else { ATTRIB_VAL(EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT); } /* Technically it's possible to request a standard OpenGL (non-ES) context, but currently our build system assumes EGL => GLES */ /* attribs[i++] = EGL_RENDERABLE_TYPE; */ /* attribs[i++] = EGL_OPENGL_BIT; */ #ifdef TARGET_HOST_BLACKBERRY /* Only 888 and 565 seem to work. Based on http://qt.gitorious.org/qt/qtbase/source/893deb1a93021cdfabe038cdf1869de33a60cbc9:src/plugins/platforms/qnx/qqnxglcontext.cpp and https://twitter.com/BlackBerryDev/status/380720927475912706 */ ATTRIB_VAL(EGL_BLUE_SIZE, 8); ATTRIB_VAL(EGL_GREEN_SIZE, 8); ATTRIB_VAL(EGL_RED_SIZE, 8); #else ATTRIB_VAL(EGL_BLUE_SIZE, 1); ATTRIB_VAL(EGL_GREEN_SIZE, 1); ATTRIB_VAL(EGL_RED_SIZE, 1); #endif ATTRIB_VAL(EGL_ALPHA_SIZE, (fgState.DisplayMode & GLUT_ALPHA) ? 1 : 0); ATTRIB_VAL(EGL_DEPTH_SIZE, (fgState.DisplayMode & GLUT_DEPTH) ? 1 : 0); ATTRIB_VAL(EGL_STENCIL_SIZE, (fgState.DisplayMode & GLUT_STENCIL) ? 1 : 0); ATTRIB_VAL(EGL_SAMPLE_BUFFERS, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? 1 : 0); ATTRIB_VAL(EGL_SAMPLES, (fgState.DisplayMode & GLUT_MULTISAMPLE) ? fgState.SampleNumber : 0); ATTRIB(EGL_NONE); EGLint num_config; if (!eglChooseConfig(fgDisplay.pDisplay.egl.Display, attributes, config, 1, &num_config)) { fgWarning("eglChooseConfig: error %x\n", eglGetError()); return 0; } return 1; }
XVisualInfo* fgChooseVisual( void ) { #define BUFFER_SIZES 6 int bufferSize[BUFFER_SIZES] = { 16, 12, 8, 4, 2, 1 }; GLboolean wantIndexedMode = GL_FALSE; int attributes[ 32 ]; int where = 0; /* First we have to process the display mode settings... */ /* * XXX Why is there a semi-colon in this #define? The code * XXX that uses the macro seems to always add more semicolons... */ #define ATTRIB(a) attributes[where++]=a; #define ATTRIB_VAL(a,v) {ATTRIB(a); ATTRIB(v);} if( fgState.DisplayMode & GLUT_INDEX ) { ATTRIB_VAL( GLX_BUFFER_SIZE, 8 ); wantIndexedMode = GL_TRUE; } else { ATTRIB( GLX_RGBA ); ATTRIB_VAL( GLX_RED_SIZE, 1 ); ATTRIB_VAL( GLX_GREEN_SIZE, 1 ); ATTRIB_VAL( GLX_BLUE_SIZE, 1 ); if( fgState.DisplayMode & GLUT_ALPHA ) ATTRIB_VAL( GLX_ALPHA_SIZE, 1 ); } if( fgState.DisplayMode & GLUT_DOUBLE ) ATTRIB( GLX_DOUBLEBUFFER ); if( fgState.DisplayMode & GLUT_STEREO ) ATTRIB( GLX_STEREO ); if( fgState.DisplayMode & GLUT_DEPTH ) ATTRIB_VAL( GLX_DEPTH_SIZE, 1 ); if( fgState.DisplayMode & GLUT_STENCIL ) ATTRIB_VAL( GLX_STENCIL_SIZE, 1 ); if( fgState.DisplayMode & GLUT_ACCUM ) { ATTRIB_VAL( GLX_ACCUM_RED_SIZE, 1 ); ATTRIB_VAL( GLX_ACCUM_GREEN_SIZE, 1 ); ATTRIB_VAL( GLX_ACCUM_BLUE_SIZE, 1 ); if( fgState.DisplayMode & GLUT_ALPHA ) ATTRIB_VAL( GLX_ACCUM_ALPHA_SIZE, 1 ); } if( fgState.DisplayMode & GLUT_AUX1 ) ATTRIB_VAL( GLX_AUX_BUFFERS, 1 ); if( fgState.DisplayMode & GLUT_AUX2 ) ATTRIB_VAL( GLX_AUX_BUFFERS, 2 ); if( fgState.DisplayMode & GLUT_AUX3 ) ATTRIB_VAL( GLX_AUX_BUFFERS, 3 ); if( fgState.DisplayMode & GLUT_AUX4 ) ATTRIB_VAL( GLX_AUX_BUFFERS, 4 ); /* Push a null at the end of the list */ ATTRIB( None ); if( ! wantIndexedMode ) return glXChooseVisual( fgDisplay.Display, fgDisplay.Screen, attributes ); else { XVisualInfo* visualInfo; int i; /* * In indexed mode, we need to check how many bits of depth can we * achieve. We do this by trying each possibility from the list * given in the {bufferSize} array. If we match, we return to caller. */ for( i=0; i<BUFFER_SIZES; i++ ) { attributes[ 1 ] = bufferSize[ i ]; visualInfo = glXChooseVisual( fgDisplay.Display, fgDisplay.Screen, attributes ); if( visualInfo != NULL ) return visualInfo; } return NULL; } }
static void fghFillPixelFormatAttributes( int *attributes, const PIXELFORMATDESCRIPTOR *ppfd ) { int where = 0; ATTRIB_VAL( WGL_DRAW_TO_WINDOW_ARB, GL_TRUE ); ATTRIB_VAL( WGL_SUPPORT_OPENGL_ARB, GL_TRUE ); ATTRIB_VAL( WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB ); ATTRIB_VAL( WGL_COLOR_BITS_ARB, ppfd->cColorBits ); ATTRIB_VAL( WGL_ALPHA_BITS_ARB, ppfd->cAlphaBits ); ATTRIB_VAL( WGL_DEPTH_BITS_ARB, ppfd->cDepthBits ); ATTRIB_VAL( WGL_STENCIL_BITS_ARB, ppfd->cStencilBits ); ATTRIB_VAL( WGL_DOUBLE_BUFFER_ARB, ( fgState.DisplayMode & GLUT_DOUBLE ) != 0 ); if ( fgState.DisplayMode & GLUT_SRGB ) { ATTRIB_VAL( WGL_FRAMEBUFFER_SRGB_CAPABLE_ARB, TRUE ); } ATTRIB_VAL( WGL_SAMPLE_BUFFERS_ARB, GL_TRUE ); ATTRIB_VAL( WGL_SAMPLES_ARB, fgState.SampleNumber ); ATTRIB( 0 ); }