/** * 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; }
/** * Initialize an EGL context for the current display. */ EGLContext fghCreateNewContextEGL( SFG_Window* window ) { EGLContext context; EGLDisplay eglDisplay = fgDisplay.pDisplay.egl.Display; EGLConfig eglConfig = window->Window.pContext.egl.Config; /* Ensure OpenGLES 2.0 context */ static const EGLint ctx_attribs[] = { #ifdef GL_ES_VERSION_2_0 EGL_CONTEXT_CLIENT_VERSION, 2, #elif GL_VERSION_ES_CM_1_0 || GL_VERSION_ES_CL_1_0 || GL_VERSION_ES_CM_1_1 || GL_VERSION_ES_CL_1_1 EGL_CONTEXT_CLIENT_VERSION, 1, #endif EGL_NONE }; context = eglCreateContext(eglDisplay, eglConfig, EGL_NO_CONTEXT, ctx_attribs); if (context == EGL_NO_CONTEXT) { fgWarning("Cannot initialize EGL context, err=%x\n", eglGetError()); fghContextCreationError(); } EGLint ver = -1; eglQueryContext(fgDisplay.pDisplay.egl.Display, context, EGL_CONTEXT_CLIENT_VERSION, &ver); #ifdef GL_ES_VERSION_2_0 if (ver != 2) #else if (ver != 1) #endif fgError("Wrong GLES major version: %d\n", ver); return context; }
void fgNewWGLCreateContext( SFG_Window* window ) { HGLRC context; int attributes[9]; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB; /* If nothing fancy has been required, leave the context as it is */ if ( fghIsLegacyContextRequested() ) { return; } wglMakeCurrent( window->Window.pContext.Device, window->Window.Context ); if ( !fghIsExtensionSupported( window->Window.pContext.Device, "WGL_ARB_create_context" ) ) { /* wglCreateContextAttribsARB not found, yet the user has requested the new context creation */ fgWarning( "OpenGL >2.1 context requested but wglCreateContextAttribsARB is not available! Falling back to legacy context creation" ); /* Legacy context already created at this point in WM_CREATE path of fgPlatformWindowProc, just return */ return; } /* new context creation */ fghFillContextAttributes( attributes ); wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" ); if ( wglCreateContextAttribsARB == NULL ) { /* wglCreateContextAttribsARB not found, yet the user has requested the new context creation */ fgWarning( "OpenGL >2.1 context requested but wglCreateContextAttribsARB is not available! Falling back to legacy context creation" ); /* Legacy context already created at this point in WM_CREATE path of fgPlatformWindowProc, just return */ return; } context = wglCreateContextAttribsARB( window->Window.pContext.Device, 0, attributes ); if ( context == NULL ) { fghContextCreationError(); } wglMakeCurrent( NULL, NULL ); wglDeleteContext( window->Window.Context ); window->Window.Context = context; }
void fgNewWGLCreateContext( SFG_Window* window ) { HGLRC context; int attributes[9]; PFNWGLCREATECONTEXTATTRIBSARBPROC wglCreateContextAttribsARB; /* If nothing fancy has been required, leave the context as it is */ if ( fghIsLegacyContextRequested() ) { return; } wglMakeCurrent( window->Window.pContext.Device, window->Window.Context ); if ( !fghIsExtensionSupported( window->Window.pContext.Device, "WGL_ARB_create_context" ) ) { return; } /* new context creation */ fghFillContextAttributes( attributes ); wglCreateContextAttribsARB = (PFNWGLCREATECONTEXTATTRIBSARBPROC) wglGetProcAddress( "wglCreateContextAttribsARB" ); if ( wglCreateContextAttribsARB == NULL ) { fgError( "wglCreateContextAttribsARB not found" ); } context = wglCreateContextAttribsARB( window->Window.pContext.Device, 0, attributes ); if ( context == NULL ) { fghContextCreationError(); } wglMakeCurrent( NULL, NULL ); wglDeleteContext( window->Window.Context ); window->Window.Context = context; }