summaryrefslogtreecommitdiff
path: root/cogl/winsys/cogl-winsys-glx.c
diff options
context:
space:
mode:
authorNeil Roberts <neil@linux.intel.com>2012-09-26 20:32:36 +0100
committerRobert Bragg <robert@linux.intel.com>2013-01-22 17:48:01 +0000
commit2616ae0fa9e0e3a0ab43698cb8434facaabad254 (patch)
tree093fcea31fff5449e98c94394dda7d01e7330ee8 /cogl/winsys/cogl-winsys-glx.c
parent1abf0ed55ee42b8bbbc2ba0976dbc95b2e94e7e1 (diff)
downloadcogl-2616ae0fa9e0e3a0ab43698cb8434facaabad254.tar.gz
Add a GL 3 driver
This adds a new CoglDriver for GL 3 called COGL_DRIVER_GL3. When requested, the GLX, EGL and SDL2 winsyss will set the necessary attributes to request a forward-compatible core profile 3.1 context. That means it will have no deprecated features. To simplify the explosion of checks for specific combinations of context->driver, many of these conditionals have now been replaced with private feature flags that are checked instead. The GL and GLES drivers now initialise these private feature flags depending on which driver is used. The fixed function backends now explicitly check whether the fixed function private feature is available which means the GL3 driver will fall back to always using the GLSL progend. Since Rob's latest patches the GLSL progend no longer uses any fixed function API anyway so it should just work. The driver is currently lower priority than COGL_DRIVER_GL so it will not be used unless it is specificly requested. We may want to change this priority at some point because apparently Mesa can make some memory savings if a core profile context is used. In GL 3, getting the combined extensions string with glGetString is deprecated so this patch changes it to use glGetStringi to build up an array of extensions instead. _cogl_context_get_gl_extensions now returns this array instead of trying to return a const string. The caller is expected to free the array. Some issues with this patch: • GL 3 does not support GL_ALPHA format textures. We should probably make this a feature flag or something. Cogl uses this to render text which currently just throws a GL error and breaks so it's pretty important to do something about this before considering the GL3 driver to be stable. • GL 3 doesn't support client side vertex buffers. This probably doesn't matter because CoglBuffer won't normally use malloc'd buffers if VBOs are available, but it might but worth making malloc'd buffers a private feature and forcing it not to use them. • GL 3 doesn't support the default vertex array object. This patch just makes it create and bind a single non-default vertex array object which gets used just like the normal default object. Ideally it would be good to use vertex array objects properly and attach them to a CoglPrimitive to cache the state. Reviewed-by: Robert Bragg <robert@linux.intel.com> (cherry picked from commit 66c9db993595b3a22e63f4c201ea468bc9b88cb6)
Diffstat (limited to 'cogl/winsys/cogl-winsys-glx.c')
-rw-r--r--cogl/winsys/cogl-winsys-glx.c56
1 files changed, 48 insertions, 8 deletions
diff --git a/cogl/winsys/cogl-winsys-glx.c b/cogl/winsys/cogl-winsys-glx.c
index 6716c7c6..c9449ccf 100644
--- a/cogl/winsys/cogl-winsys-glx.c
+++ b/cogl/winsys/cogl-winsys-glx.c
@@ -331,7 +331,8 @@ _cogl_winsys_renderer_connect (CoglRenderer *renderer,
if (!_cogl_xlib_renderer_connect (renderer, error))
goto error;
- if (renderer->driver != COGL_DRIVER_GL)
+ if (renderer->driver != COGL_DRIVER_GL &&
+ renderer->driver != COGL_DRIVER_GL3)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,
COGL_WINSYS_ERROR_INIT,
@@ -394,6 +395,7 @@ update_winsys_features (CoglContext *context, CoglError **error)
_cogl_xlib_renderer_get_data (context->display->renderer);
CoglGLXRenderer *glx_renderer = context->display->renderer->winsys;
const char *glx_extensions;
+ char **split_extensions;
int default_screen;
int i;
@@ -418,11 +420,13 @@ update_winsys_features (CoglContext *context, CoglError **error)
COGL_WINSYS_FEATURE_MULTIPLE_ONSCREEN,
TRUE);
+ split_extensions = g_strsplit (glx_extensions, " ", 0 /* max_tokens */);
+
for (i = 0; i < G_N_ELEMENTS (winsys_feature_data); i++)
if (_cogl_feature_check (context->display->renderer,
"GLX", winsys_feature_data + i, 0, 0,
COGL_DRIVER_GL, /* the driver isn't used */
- glx_extensions,
+ split_extensions,
glx_renderer))
{
context->feature_flags |= winsys_feature_data[i].feature_flags;
@@ -432,6 +436,8 @@ update_winsys_features (CoglContext *context, CoglError **error)
TRUE);
}
+ g_strfreev (split_extensions);
+
/* Note: the GLX_SGI_video_sync spec explicitly states this extension
* only works for direct contexts. */
if (!glx_renderer->is_direct)
@@ -607,6 +613,36 @@ done:
return ret;
}
+static GLXContext
+create_gl3_context (CoglDisplay *display,
+ GLXFBConfig fb_config)
+{
+ CoglXlibRenderer *xlib_renderer =
+ _cogl_xlib_renderer_get_data (display->renderer);
+ CoglGLXRenderer *glx_renderer = display->renderer->winsys;
+
+ /* We want a core profile 3.1 context with no deprecated features */
+ static const int attrib_list[] =
+ {
+ GLX_CONTEXT_MAJOR_VERSION_ARB, 3,
+ GLX_CONTEXT_MINOR_VERSION_ARB, 1,
+ GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
+ GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB,
+ None
+ };
+
+ /* Make sure that the display supports the GLX_ARB_create_context
+ extension */
+ if (glx_renderer->pf_glXCreateContextAttribs == NULL)
+ return NULL;
+
+ return glx_renderer->pf_glXCreateContextAttribs (xlib_renderer->xdpy,
+ fb_config,
+ NULL /* share_context */,
+ True, /* direct */
+ attrib_list);
+}
+
static CoglBool
create_context (CoglDisplay *display, CoglError **error)
{
@@ -644,12 +680,16 @@ create_context (CoglDisplay *display, CoglError **error)
COGL_NOTE (WINSYS, "Creating GLX Context (display: %p)",
xlib_renderer->xdpy);
- glx_display->glx_context =
- glx_renderer->glXCreateNewContext (xlib_renderer->xdpy,
- config,
- GLX_RGBA_TYPE,
- NULL,
- True);
+ if (display->renderer->driver == COGL_DRIVER_GL3)
+ glx_display->glx_context = create_gl3_context (display, config);
+ else
+ glx_display->glx_context =
+ glx_renderer->glXCreateNewContext (xlib_renderer->xdpy,
+ config,
+ GLX_RGBA_TYPE,
+ NULL,
+ True);
+
if (glx_display->glx_context == NULL)
{
_cogl_set_error (error, COGL_WINSYS_ERROR,