Re: Question about support for OpenGL 3.2 Core context
Brian Paul <[email protected]>
| Newsgroups | gmane.comp.video.mesa3d.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Ken, I'm attaching two patches, one against mesa which implements the new OSMesaCreateContextAttribs() function, and a second patch against mesa-demos which tests it with the osdemo.c program. If you can apply/test, or at least look things over, that'd be great. The code isn't final, but should be testable. -Brian On 12/11/2015 06:22 PM, Ken Martin wrote: > Definitely, we can change our call. We just might have to add an #ifdef > to handle cases where people are building against an older version of > mesa so that we can handle both. > > Thanks > Ken > > On Fri, Dec 11, 2015 at 7:45 PM, Brian Paul <[email protected] > <mailto:[email protected]>> wrote: > > On 12/11/2015 02:22 PM, Ken Martin wrote: > > OK so the specific failure point appears to be OSMesa with > llvmpipe. For > some reason we are getting a 3.0 context instead of 3.2. I am > not sure > how to request a 3.2 context from OS mesa. We are just doing a > OSMesaCreateContext(GL_RGBA,0) Is there an argument or build > option to > get 3.2? > > > Hmm, I think we'll have to add a new version of OSMesaCreateContext > to be able to specify a core profile so that GL 3.3 can be used. If > I do that, can you adapt your code to use the new entrypoint? > > Otherwise, I'd have to hack something. Maybe an env var. > > -Brian > > > > > -- > Ken Martin PhD > Chairman & CFO > Kitware Inc. > 28 Corporate Drive > Clifton Park NY 12065 > 518 371 3971 > > This communication, including all attachments, contains confidential and > legally privileged information, and it is intended only for the use of > the addressee. Access to this email by anyone else is unauthorized. If > you are not the intended recipient, any disclosure, copying, > distribution or any action taken in reliance on it is prohibited and may > be unlawful. If you received this communication in error please notify > us immediately and destroy the original message. Thank you. _______________________________________________ mesa-users mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/mesa-users
mesa.patch
(text/x-patch, 10.5 KB)
diff --git a/include/GL/osmesa.h b/include/GL/osmesa.h
index ca0d167..c60db0a 100644
--- a/include/GL/osmesa.h
+++ b/include/GL/osmesa.h
@@ -58,8 +58,8 @@ extern "C" {
#include <GL/gl.h>
-#define OSMESA_MAJOR_VERSION 10
-#define OSMESA_MINOR_VERSION 0
+#define OSMESA_MAJOR_VERSION 11
+#define OSMESA_MINOR_VERSION 2
#define OSMESA_PATCH_VERSION 0
@@ -95,6 +95,18 @@ extern "C" {
#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */
#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */
+/*
+ * Accepted in OSMesaCreateContextAttrib's attribute list.
+ */
+#define OSMESA_DEPTH_BITS 0x30
+#define OSMESA_STENCIL_BITS 0x31
+#define OSMESA_ACCUM_BITS 0x32
+#define OSMESA_PROFILE 0x33
+#define OSMESA_CORE_PROFILE 0x34
+#define OSMESA_COMPAT_PROFILE 0x35
+#define OSMESA_CONTEXT_MAJOR_VERSION 0x36
+#define OSMESA_CONTEXT_MINOR_VERSION 0x37
+
typedef struct osmesa_context *OSMesaContext;
@@ -128,6 +140,35 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
/*
+ * Create an Off-Screen Mesa rendering context with attribute list.
+ * The list is composed of (attribute, value) pairs and terminated with
+ * attribute==0. Supported Attributes:
+ *
+ * Attributes Values
+ * --------------------------------------------------------------------------
+ * OSMESA_FORMAT OSMESA_RGBA*, OSMESA_BGRA, OSMESA_ARGB, etc.
+ * OSMESA_DEPTH_BITS 0*, 16, 24, 32
+ * OSMESA_STENCIL_BITS 0*, 8
+ * OSMESA_ACCUM_BITS 0*, 16
+ * OSMESA_PROFILE OSMESA_COMPAT_PROFILE*, OSMESA_CORE_PROFILE
+ * OSMESA_CONTEXT_MAJOR_VERSION 1*, 2, 3
+ * OSMESA_CONTEXT_MINOR_VERSION 0+
+ *
+ * Note: * = default value
+ *
+ * We return a context version at least what's specified by
+ * OSMESA_CONTEXT_MAJOR/MINOR_VERSION for the given profile. For example, if
+ * you request a GL 1.4 compat profile, you might get a GL 3.0 compat profile.
+ * Otherwise, null is returned if the version/profile is not supported.
+ *
+ * New in Mesa 11.2
+ */
+GLAPI OSMesaContext GLAPIENTRY
+OSMesaCreateContextAttribs( const int *attribList, OSMesaContext sharelist );
+
+
+
+/*
* Destroy an Off-Screen Mesa rendering context.
*
* Input: ctx - the context to destroy
diff --git a/src/gallium/state_trackers/osmesa/osmesa.c b/src/gallium/state_trackers/osmesa/osmesa.c
index 0f27ba8..06884f8 100644
--- a/src/gallium/state_trackers/osmesa/osmesa.c
+++ b/src/gallium/state_trackers/osmesa/osmesa.c
@@ -544,11 +544,39 @@ GLAPI OSMesaContext GLAPIENTRY
OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits,
GLint accumBits, OSMesaContext sharelist)
{
+ int attribs[100], n = 0;
+
+ attribs[n++] = OSMESA_FORMAT;
+ attribs[n++] = format;
+ attribs[n++] = OSMESA_DEPTH_BITS;
+ attribs[n++] = depthBits;
+ attribs[n++] = OSMESA_STENCIL_BITS;
+ attribs[n++] = stencilBits;
+ attribs[n++] = OSMESA_ACCUM_BITS;
+ attribs[n++] = accumBits;
+ attribs[n++] = 0;
+
+ return OSMesaCreateContextAttribs(attribs, sharelist);
+}
+
+
+/**
+ * New in Mesa 11.2
+ *
+ * Create context with attribute list.
+ */
+GLAPI OSMesaContext GLAPIENTRY
+OSMesaCreateContextAttribs(const int *attribList, OSMesaContext sharelist)
+{
OSMesaContext osmesa;
struct st_context_iface *st_shared;
enum st_context_error st_error = 0;
struct st_context_attribs attribs;
struct st_api *stapi = get_st_api();
+ GLenum format = GL_RGBA;
+ int depthBits = 0, stencilBits = 0, accumBits = 0;
+ int profile = OSMESA_COMPAT_PROFILE, version_major = 1, version_minor = 0;
+ int i;
if (sharelist) {
st_shared = sharelist->stctx;
@@ -561,6 +589,42 @@ OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits,
if (!osmesa)
return NULL;
+ for (i = 0; attribList[i]; i += 2) {
+ switch (attribList[i]) {
+ case OSMESA_FORMAT:
+ format = attribList[i+1];
+ assert(format >= 0);
+ break;
+ case OSMESA_DEPTH_BITS:
+ depthBits = attribList[i+1];
+ assert(depthBits >= 0);
+ break;
+ case OSMESA_STENCIL_BITS:
+ stencilBits = attribList[i+1];
+ assert(stencilBits >= 0);
+ break;
+ case OSMESA_ACCUM_BITS:
+ accumBits = attribList[i+1];
+ assert(accumBits >= 0);
+ break;
+ case OSMESA_PROFILE:
+ profile = attribList[i+1];
+ assert(profile == OSMESA_CORE_PROFILE ||
+ profile == OSMESA_COMPAT_PROFILE);
+ break;
+ case OSMESA_CONTEXT_MAJOR_VERSION:
+ version_major = attribList[i+1];
+ assert(version_major >= 1);
+ break;
+ case OSMESA_CONTEXT_MINOR_VERSION:
+ version_minor = attribList[i+1];
+ assert(version_minor >= 0);
+ break;
+ default:
+ break;
+ }
+ }
+
/* Choose depth/stencil/accum buffer formats */
if (accumBits > 0) {
osmesa->accum_format = PIPE_FORMAT_R16G16B16A16_SNORM;
@@ -581,9 +645,11 @@ OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits,
/*
* Create the rendering context
*/
- attribs.profile = ST_PROFILE_DEFAULT;
- attribs.major = 2;
- attribs.minor = 1;
+ memset(&attribs, 0, sizeof(attribs));
+ attribs.profile = (profile == OSMESA_CORE_PROFILE)
+ ? ST_PROFILE_OPENGL_CORE : ST_PROFILE_DEFAULT;
+ attribs.major = version_major;
+ attribs.minor = version_minor;
attribs.flags = 0; /* ST_CONTEXT_FLAG_x */
attribs.options.force_glsl_extensions_warn = FALSE;
attribs.options.disable_blend_func_extended = FALSE;
@@ -614,6 +680,7 @@ OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits,
}
+
/**
* Destroy an Off-Screen Mesa rendering context.
*
@@ -883,6 +950,7 @@ struct name_function
static struct name_function functions[] = {
{ "OSMesaCreateContext", (OSMESAproc) OSMesaCreateContext },
{ "OSMesaCreateContextExt", (OSMESAproc) OSMesaCreateContextExt },
+ { "OSMesaCreateContextAttribs", (OSMESAproc) OSMesaCreateContextAttribs },
{ "OSMesaDestroyContext", (OSMESAproc) OSMesaDestroyContext },
{ "OSMesaMakeCurrent", (OSMESAproc) OSMesaMakeCurrent },
{ "OSMesaGetCurrentContext", (OSMESAproc) OSMesaGetCurrentContext },
diff --git a/src/mesa/drivers/osmesa/osmesa.c b/src/mesa/drivers/osmesa/osmesa.c
index 5c7dcac..dcf8e5e 100644
--- a/src/mesa/drivers/osmesa/osmesa.c
+++ b/src/mesa/drivers/osmesa/osmesa.c
@@ -645,10 +645,85 @@ GLAPI OSMesaContext GLAPIENTRY
OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
GLint accumBits, OSMesaContext sharelist )
{
+ int attribs[100], n = 0;
+
+ attribs[n++] = OSMESA_FORMAT;
+ attribs[n++] = format;
+ attribs[n++] = OSMESA_DEPTH_BITS;
+ attribs[n++] = depthBits;
+ attribs[n++] = OSMESA_STENCIL_BITS;
+ attribs[n++] = stencilBits;
+ attribs[n++] = OSMESA_ACCUM_BITS;
+ attribs[n++] = accumBits;
+ attribs[n++] = 0;
+
+ return OSMesaCreateContextAttribs(attribs, sharelist);
+}
+
+
+/**
+ * New in Mesa 11.2
+ *
+ * Create context with attribute list.
+ */
+GLAPI OSMesaContext GLAPIENTRY
+OSMesaCreateContextAttribs(const int *attribList, OSMesaContext sharelist)
+{
OSMesaContext osmesa;
struct dd_function_table functions;
GLint rind, gind, bind, aind;
GLint redBits = 0, greenBits = 0, blueBits = 0, alphaBits =0;
+ GLenum format = OSMESA_RGBA;
+ GLint depthBits = 0, stencilBits = 0, accumBits = 0;
+ int profile = OSMESA_COMPAT_PROFILE, version_major = 1, version_minor = 0;
+ gl_api api_profile;
+ int i;
+
+ osmesa = (OSMesaContext) CALLOC_STRUCT(osmesa_context);
+ if (!osmesa)
+ return NULL;
+
+ for (i = 0; attribList[i]; i += 2) {
+ switch (attribList[i]) {
+ case OSMESA_FORMAT:
+ format = attribList[i+1];
+ assert(format >= 0);
+ break;
+ case OSMESA_DEPTH_BITS:
+ depthBits = attribList[i+1];
+ assert(depthBits >= 0);
+ break;
+ case OSMESA_STENCIL_BITS:
+ stencilBits = attribList[i+1];
+ assert(stencilBits >= 0);
+ break;
+ case OSMESA_ACCUM_BITS:
+ accumBits = attribList[i+1];
+ assert(accumBits >= 0);
+ break;
+ case OSMESA_PROFILE:
+ profile = attribList[i+1];
+ assert(profile == OSMESA_CORE_PROFILE ||
+ profile == OSMESA_COMPAT_PROFILE);
+ if (profile == OSMESA_COMPAT_PROFILE)
+ api_profile = API_OPENGL_COMPAT;
+ else if (profile == OSMESA_CORE_PROFILE)
+ api_profile = API_OPENGL_CORE;
+ else
+ return NULL;
+ break;
+ case OSMESA_CONTEXT_MAJOR_VERSION:
+ version_major = attribList[i+1];
+ assert(version_major >= 1);
+ break;
+ case OSMESA_CONTEXT_MINOR_VERSION:
+ version_minor = attribList[i+1];
+ assert(version_minor >= 0);
+ break;
+ default:
+ break;
+ }
+ }
rind = gind = bind = aind = 0;
if (format==OSMESA_RGBA) {
@@ -742,7 +817,7 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
functions.UpdateState = osmesa_update_state;
if (!_mesa_initialize_context(&osmesa->mesa,
- API_OPENGL_COMPAT,
+ api_profile,
osmesa->gl_visual,
sharelist ? &sharelist->mesa
: (struct gl_context *) NULL,
@@ -819,6 +894,13 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
_mesa_compute_version(ctx);
+ if (ctx->Version < version_major * 10 + version_minor) {
+ _mesa_destroy_visual(osmesa->gl_visual);
+ _mesa_free_context_data(ctx);
+ free(osmesa);
+ return NULL;
+ }
+
/* Exec table initialization requires the version to be computed */
_mesa_initialize_dispatch_tables(ctx);
_mesa_initialize_vbo_vtxfmt(ctx);
@@ -1121,6 +1203,7 @@ struct name_function
static struct name_function functions[] = {
{ "OSMesaCreateContext", (OSMESAproc) OSMesaCreateContext },
{ "OSMesaCreateContextExt", (OSMESAproc) OSMesaCreateContextExt },
+ { "OSMesaCreateContextAttribs", (OSMESAproc) OSMesaCreateContextAttribs },
{ "OSMesaDestroyContext", (OSMESAproc) OSMesaDestroyContext },
{ "OSMesaMakeCurrent", (OSMESAproc) OSMesaMakeCurrent },
{ "OSMesaGetCurrentContext", (OSMESAproc) OSMesaGetCurrentContext },
demos.patch
(text/x-patch, 1.5 KB)
diff --git a/src/osdemos/osdemo.c b/src/osdemos/osdemo.c
index cd98ce4..be4da8d 100644
--- a/src/osdemos/osdemo.c
+++ b/src/osdemos/osdemo.c
@@ -17,6 +17,7 @@
*/
+#include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
@@ -244,6 +245,8 @@ write_ppm(const char *filename, const GLubyte *buffer, int width, int height)
#endif
+typedef OSMesaContext GLAPIENTRY (*OSMesaCreateContextAttribs_func)( const int *attribList, OSMesaContext sharelist );
+
int
main(int argc, char *argv[])
@@ -265,7 +268,26 @@ main(int argc, char *argv[])
}
/* Create an RGBA-mode context */
-#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
+#if OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 1102
+ {
+ static const int attribs[] = {
+ OSMESA_FORMAT, OSMESA_RGBA,
+ OSMESA_DEPTH_BITS, 16,
+ OSMESA_STENCIL_BITS, 0,
+ OSMESA_ACCUM_BITS, 0,
+ OSMESA_PROFILE, OSMESA_COMPAT_PROFILE,
+ OSMESA_CONTEXT_MAJOR_VERSION, 1,
+ OSMESA_CONTEXT_MINOR_VERSION, 5,
+ 0 };
+
+ OSMesaCreateContextAttribs_func OSMesaCreateContextAttribs =
+ (OSMesaCreateContextAttribs_func)
+ OSMesaGetProcAddress("OSMesaCreateContextAttribs");
+ assert(OSMesaCreateContextAttribs);
+
+ ctx = OSMesaCreateContextAttribs(attribs, NULL);
+ }
+#elif OSMESA_MAJOR_VERSION * 100 + OSMESA_MINOR_VERSION >= 305
/* specify Z, stencil, accum sizes */
ctx = OSMesaCreateContextExt( OSMESA_RGBA, 16, 0, 0, NULL );
#else