Skip to content

Commit a34e761

Browse files
committed
osmesa: add new OSMesaCreateContextAttribs function
This allows specifying a GL profile and version so one can get a core- profile context. Reviewed-by: Jose Fonseca <[email protected]>
1 parent c2c0983 commit a34e761

File tree

3 files changed

+144
-3
lines changed

3 files changed

+144
-3
lines changed

docs/relnotes/11.2.0.html

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ <h2>New features</h2>
5656
<li>GL_ARB_vertex_type_10f_11f_11f_rev on freedreno/a4xx</li>
5757
<li>GL_KHR_texture_compression_astc_ldr on freedreno/a4xx</li>
5858
<li>GL_AMD_performance_monitor on radeonsi (CIK+ only)</li>
59+
<li>New OSMesaCreateContextAttribs() function (for creating core profile
60+
contexts)</li>
5961
</ul>
6062

6163
<h2>Bug fixes</h2>

include/GL/osmesa.h

+43-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ extern "C" {
5858
#include <GL/gl.h>
5959

6060

61-
#define OSMESA_MAJOR_VERSION 10
62-
#define OSMESA_MINOR_VERSION 0
61+
#define OSMESA_MAJOR_VERSION 11
62+
#define OSMESA_MINOR_VERSION 2
6363
#define OSMESA_PATCH_VERSION 0
6464

6565

@@ -95,6 +95,18 @@ extern "C" {
9595
#define OSMESA_MAX_WIDTH 0x24 /* new in 4.0 */
9696
#define OSMESA_MAX_HEIGHT 0x25 /* new in 4.0 */
9797

98+
/*
99+
* Accepted in OSMesaCreateContextAttrib's attribute list.
100+
*/
101+
#define OSMESA_DEPTH_BITS 0x30
102+
#define OSMESA_STENCIL_BITS 0x31
103+
#define OSMESA_ACCUM_BITS 0x32
104+
#define OSMESA_PROFILE 0x33
105+
#define OSMESA_CORE_PROFILE 0x34
106+
#define OSMESA_COMPAT_PROFILE 0x35
107+
#define OSMESA_CONTEXT_MAJOR_VERSION 0x36
108+
#define OSMESA_CONTEXT_MINOR_VERSION 0x37
109+
98110

99111
typedef struct osmesa_context *OSMesaContext;
100112

@@ -127,6 +139,35 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
127139
GLint accumBits, OSMesaContext sharelist);
128140

129141

142+
/*
143+
* Create an Off-Screen Mesa rendering context with attribute list.
144+
* The list is composed of (attribute, value) pairs and terminated with
145+
* attribute==0. Supported Attributes:
146+
*
147+
* Attributes Values
148+
* --------------------------------------------------------------------------
149+
* OSMESA_FORMAT OSMESA_RGBA*, OSMESA_BGRA, OSMESA_ARGB, etc.
150+
* OSMESA_DEPTH_BITS 0*, 16, 24, 32
151+
* OSMESA_STENCIL_BITS 0*, 8
152+
* OSMESA_ACCUM_BITS 0*, 16
153+
* OSMESA_PROFILE OSMESA_COMPAT_PROFILE*, OSMESA_CORE_PROFILE
154+
* OSMESA_CONTEXT_MAJOR_VERSION 1*, 2, 3
155+
* OSMESA_CONTEXT_MINOR_VERSION 0+
156+
*
157+
* Note: * = default value
158+
*
159+
* We return a context version >= what's specified by OSMESA_CONTEXT_MAJOR/
160+
* MINOR_VERSION for the given profile. For example, if you request a GL 1.4
161+
* compat profile, you might get a GL 3.0 compat profile.
162+
* Otherwise, null is returned if the version/profile is not supported.
163+
*
164+
* New in Mesa 11.2
165+
*/
166+
GLAPI OSMesaContext GLAPIENTRY
167+
OSMesaCreateContextAttribs( const int *attribList, OSMesaContext sharelist );
168+
169+
170+
130171
/*
131172
* Destroy an Off-Screen Mesa rendering context.
132173
*

src/mesa/drivers/osmesa/osmesa.c

+99-1
Original file line numberDiff line numberDiff line change
@@ -644,11 +644,101 @@ OSMesaCreateContext( GLenum format, OSMesaContext sharelist )
644644
GLAPI OSMesaContext GLAPIENTRY
645645
OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
646646
GLint accumBits, OSMesaContext sharelist )
647+
{
648+
int attribs[100], n = 0;
649+
650+
attribs[n++] = OSMESA_FORMAT;
651+
attribs[n++] = format;
652+
attribs[n++] = OSMESA_DEPTH_BITS;
653+
attribs[n++] = depthBits;
654+
attribs[n++] = OSMESA_STENCIL_BITS;
655+
attribs[n++] = stencilBits;
656+
attribs[n++] = OSMESA_ACCUM_BITS;
657+
attribs[n++] = accumBits;
658+
attribs[n++] = 0;
659+
660+
return OSMesaCreateContextAttribs(attribs, sharelist);
661+
}
662+
663+
664+
/**
665+
* New in Mesa 11.2
666+
*
667+
* Create context with attribute list.
668+
*/
669+
GLAPI OSMesaContext GLAPIENTRY
670+
OSMesaCreateContextAttribs(const int *attribList, OSMesaContext sharelist)
647671
{
648672
OSMesaContext osmesa;
649673
struct dd_function_table functions;
650674
GLint rind, gind, bind, aind;
651675
GLint redBits = 0, greenBits = 0, blueBits = 0, alphaBits =0;
676+
GLenum format = OSMESA_RGBA;
677+
GLint depthBits = 0, stencilBits = 0, accumBits = 0;
678+
int profile = OSMESA_COMPAT_PROFILE, version_major = 1, version_minor = 0;
679+
gl_api api_profile = API_OPENGL_COMPAT;
680+
int i;
681+
682+
for (i = 0; attribList[i]; i += 2) {
683+
switch (attribList[i]) {
684+
case OSMESA_FORMAT:
685+
format = attribList[i+1];
686+
switch (format) {
687+
case OSMESA_COLOR_INDEX:
688+
case OSMESA_RGBA:
689+
case OSMESA_BGRA:
690+
case OSMESA_ARGB:
691+
case OSMESA_RGB:
692+
case OSMESA_BGR:
693+
case OSMESA_RGB_565:
694+
/* legal */
695+
break;
696+
default:
697+
return NULL;
698+
}
699+
break;
700+
case OSMESA_DEPTH_BITS:
701+
depthBits = attribList[i+1];
702+
if (depthBits < 0)
703+
return NULL;
704+
break;
705+
case OSMESA_STENCIL_BITS:
706+
stencilBits = attribList[i+1];
707+
if (stencilBits < 0)
708+
return NULL;
709+
break;
710+
case OSMESA_ACCUM_BITS:
711+
accumBits = attribList[i+1];
712+
if (accumBits < 0)
713+
return NULL;
714+
break;
715+
case OSMESA_PROFILE:
716+
profile = attribList[i+1];
717+
if (profile == OSMESA_COMPAT_PROFILE)
718+
api_profile = API_OPENGL_COMPAT;
719+
else if (profile == OSMESA_CORE_PROFILE)
720+
api_profile = API_OPENGL_CORE;
721+
else
722+
return NULL;
723+
break;
724+
case OSMESA_CONTEXT_MAJOR_VERSION:
725+
version_major = attribList[i+1];
726+
if (version_major < 1)
727+
return NULL;
728+
break;
729+
case OSMESA_CONTEXT_MINOR_VERSION:
730+
version_minor = attribList[i+1];
731+
if (version_minor < 0)
732+
return NULL;
733+
break;
734+
case 0:
735+
/* end of list */
736+
break;
737+
default:
738+
fprintf(stderr, "Bad attribute in OSMesaCreateContextAttribs()\n");
739+
return NULL;
740+
}
741+
}
652742

653743
rind = gind = bind = aind = 0;
654744
if (format==OSMESA_RGBA) {
@@ -742,7 +832,7 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
742832
functions.UpdateState = osmesa_update_state;
743833

744834
if (!_mesa_initialize_context(&osmesa->mesa,
745-
API_OPENGL_COMPAT,
835+
api_profile,
746836
osmesa->gl_visual,
747837
sharelist ? &sharelist->mesa
748838
: (struct gl_context *) NULL,
@@ -819,6 +909,13 @@ OSMesaCreateContextExt( GLenum format, GLint depthBits, GLint stencilBits,
819909

820910
_mesa_compute_version(ctx);
821911

912+
if (ctx->Version < version_major * 10 + version_minor) {
913+
_mesa_destroy_visual(osmesa->gl_visual);
914+
_mesa_free_context_data(ctx);
915+
free(osmesa);
916+
return NULL;
917+
}
918+
822919
/* Exec table initialization requires the version to be computed */
823920
_mesa_initialize_dispatch_tables(ctx);
824921
_mesa_initialize_vbo_vtxfmt(ctx);
@@ -1121,6 +1218,7 @@ struct name_function
11211218
static struct name_function functions[] = {
11221219
{ "OSMesaCreateContext", (OSMESAproc) OSMesaCreateContext },
11231220
{ "OSMesaCreateContextExt", (OSMESAproc) OSMesaCreateContextExt },
1221+
{ "OSMesaCreateContextAttribs", (OSMESAproc) OSMesaCreateContextAttribs },
11241222
{ "OSMesaDestroyContext", (OSMESAproc) OSMesaDestroyContext },
11251223
{ "OSMesaMakeCurrent", (OSMESAproc) OSMesaMakeCurrent },
11261224
{ "OSMesaGetCurrentContext", (OSMESAproc) OSMesaGetCurrentContext },

0 commit comments

Comments
 (0)