GLAPI OSMesaContext GLAPIENTRY OSMesaGetCurrentContext(void) { struct st_api *stapi = get_st_api(); struct st_context_iface *st = stapi->get_current(stapi); return st ? (OSMesaContext) st->st_manager_private : NULL; }
/** * Bind an OSMesaContext to an image buffer. The image buffer is just a * block of memory which the client provides. Its size must be at least * as large as width*height*pixelSize. Its address should be a multiple * of 4 if using RGBA mode. * * By default, image data is stored in the order of glDrawPixels: row-major * order with the lower-left image pixel stored in the first array position * (ie. bottom-to-top). * * If the context's viewport hasn't been initialized yet, it will now be * initialized to (0,0,width,height). * * Input: osmesa - the rendering context * buffer - the image buffer memory * type - data type for pixel components * GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT * or GL_FLOAT. * width, height - size of image buffer in pixels, at least 1 * Return: GL_TRUE if success, GL_FALSE if error because of invalid osmesa, * invalid type, invalid size, etc. */ GLAPI GLboolean GLAPIENTRY OSMesaMakeCurrent(OSMesaContext osmesa, void *buffer, GLenum type, GLsizei width, GLsizei height) { struct st_api *stapi = get_st_api(); struct osmesa_buffer *osbuffer; enum pipe_format color_format; if (osmesa->format == OSMESA_RGB_565 && type != GL_UNSIGNED_SHORT_5_6_5) { return GL_FALSE; } if (width < 1 || height < 1) { return GL_FALSE; } color_format = osmesa_choose_format(osmesa->format, type); if (color_format == PIPE_FORMAT_NONE) { fprintf(stderr, "OSMesaMakeCurrent(unsupported format/type)\n"); return GL_FALSE; } /* See if we already have a buffer that uses these pixel formats */ osbuffer = osmesa_find_buffer(color_format, osmesa->depth_stencil_format, osmesa->accum_format); if (!osbuffer) { /* Existing buffer found, create new buffer */ osbuffer = osmesa_create_buffer(color_format, osmesa->depth_stencil_format, osmesa->accum_format); } osbuffer->width = width; osbuffer->height = height; osbuffer->map = buffer; /* XXX unused for now */ (void) osmesa_destroy_buffer; osmesa->current_buffer = osbuffer; osmesa->type = type; stapi->make_current(stapi, osmesa->stctx, osbuffer->stfb, osbuffer->stfb); return GL_TRUE; }
/** * Bind an OSMesaContext to an image buffer. The image buffer is just a * block of memory which the client provides. Its size must be at least * as large as width*height*pixelSize. Its address should be a multiple * of 4 if using RGBA mode. * * By default, image data is stored in the order of glDrawPixels: row-major * order with the lower-left image pixel stored in the first array position * (ie. bottom-to-top). * * If the context's viewport hasn't been initialized yet, it will now be * initialized to (0,0,width,height). * * Input: osmesa - the rendering context * buffer - the image buffer memory * type - data type for pixel components * GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT_5_6_5, GL_UNSIGNED_SHORT * or GL_FLOAT. * width, height - size of image buffer in pixels, at least 1 * Return: GL_TRUE if success, GL_FALSE if error because of invalid osmesa, * invalid type, invalid size, etc. */ GLAPI GLboolean GLAPIENTRY OSMesaMakeCurrent(OSMesaContext osmesa, void *buffer, GLenum type, GLsizei width, GLsizei height) { struct st_api *stapi = get_st_api(); struct osmesa_buffer *osbuffer; enum pipe_format color_format; if (!osmesa || !buffer || width < 1 || height < 1) { return GL_FALSE; } if (osmesa->format == OSMESA_RGB_565 && type != GL_UNSIGNED_SHORT_5_6_5) { return GL_FALSE; } color_format = osmesa_choose_format(osmesa->format, type); if (color_format == PIPE_FORMAT_NONE) { fprintf(stderr, "OSMesaMakeCurrent(unsupported format/type)\n"); return GL_FALSE; } /* See if we already have a buffer that uses these pixel formats */ osbuffer = osmesa_find_buffer(color_format, osmesa->depth_stencil_format, osmesa->accum_format, width, height); if (!osbuffer) { /* Existing buffer found, create new buffer */ osbuffer = osmesa_create_buffer(color_format, osmesa->depth_stencil_format, osmesa->accum_format); } osbuffer->width = width; osbuffer->height = height; osbuffer->map = buffer; /* XXX unused for now */ (void) osmesa_destroy_buffer; osmesa->current_buffer = osbuffer; osmesa->type = type; stapi->make_current(stapi, osmesa->stctx, osbuffer->stfb, osbuffer->stfb); if (!osmesa->ever_used) { /* one-time init, just postprocessing for now */ boolean any_pp_enabled = FALSE; unsigned i; for (i = 0; i < ARRAY_SIZE(osmesa->pp_enabled); i++) { if (osmesa->pp_enabled[i]) { any_pp_enabled = TRUE; break; } } if (any_pp_enabled) { osmesa->pp = pp_init(osmesa->stctx->pipe, osmesa->pp_enabled, osmesa->stctx->cso_context); pp_init_fbos(osmesa->pp, width, height); } osmesa->ever_used = TRUE; } return GL_TRUE; }
/** * 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; } else { st_shared = NULL; } for (i = 0; attribList[i]; i += 2) { switch (attribList[i]) { case OSMESA_FORMAT: format = attribList[i+1]; switch (format) { case OSMESA_COLOR_INDEX: case OSMESA_RGBA: case OSMESA_BGRA: case OSMESA_ARGB: case OSMESA_RGB: case OSMESA_BGR: case OSMESA_RGB_565: /* legal */ break; default: return NULL; } break; case OSMESA_DEPTH_BITS: depthBits = attribList[i+1]; if (depthBits < 0) return NULL; break; case OSMESA_STENCIL_BITS: stencilBits = attribList[i+1]; if (stencilBits < 0) return NULL; break; case OSMESA_ACCUM_BITS: accumBits = attribList[i+1]; if (accumBits < 0) return NULL; break; case OSMESA_PROFILE: profile = attribList[i+1]; if (profile != OSMESA_CORE_PROFILE && profile != OSMESA_COMPAT_PROFILE) return NULL; break; case OSMESA_CONTEXT_MAJOR_VERSION: version_major = attribList[i+1]; if (version_major < 1) return NULL; break; case OSMESA_CONTEXT_MINOR_VERSION: version_minor = attribList[i+1]; if (version_minor < 0) return NULL; break; case 0: /* end of list */ break; default: fprintf(stderr, "Bad attribute in OSMesaCreateContextAttribs()\n"); return NULL; } } osmesa = (OSMesaContext) CALLOC_STRUCT(osmesa_context); if (!osmesa) return NULL; /* Choose depth/stencil/accum buffer formats */ if (accumBits > 0) { osmesa->accum_format = PIPE_FORMAT_R16G16B16A16_SNORM; } if (depthBits > 0 && stencilBits > 0) { osmesa->depth_stencil_format = PIPE_FORMAT_Z24_UNORM_S8_UINT; } else if (stencilBits > 0) { osmesa->depth_stencil_format = PIPE_FORMAT_S8_UINT; } else if (depthBits >= 24) { osmesa->depth_stencil_format = PIPE_FORMAT_Z24X8_UNORM; } else if (depthBits >= 16) { osmesa->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; } /* * Create the rendering context */ 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; attribs.options.disable_glsl_line_continuations = FALSE; attribs.options.disable_shader_bit_encoding = FALSE; attribs.options.force_s3tc_enable = FALSE; attribs.options.force_glsl_version = 0; osmesa_init_st_visual(&attribs.visual, PIPE_FORMAT_R8G8B8A8_UNORM, osmesa->depth_stencil_format, osmesa->accum_format); osmesa->stctx = stapi->create_context(stapi, get_st_manager(), &attribs, &st_error, st_shared); if (!osmesa->stctx) { FREE(osmesa); return NULL; } osmesa->stctx->st_manager_private = osmesa; osmesa->format = format; osmesa->user_row_length = 0; osmesa->y_up = GL_TRUE; return osmesa; }
/** * New in Mesa 3.5 * * Create context and specify size of ancillary buffers. */ GLAPI OSMesaContext GLAPIENTRY OSMesaCreateContextExt(GLenum format, GLint depthBits, GLint stencilBits, GLint accumBits, 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(); if (sharelist) { st_shared = sharelist->stctx; } else { st_shared = NULL; } osmesa = (OSMesaContext) CALLOC_STRUCT(osmesa_context); if (!osmesa) return NULL; /* Choose depth/stencil/accum buffer formats */ if (accumBits > 0) { osmesa->accum_format = PIPE_FORMAT_R16G16B16A16_SNORM; } if (depthBits > 0 && stencilBits > 0) { osmesa->depth_stencil_format = PIPE_FORMAT_Z24_UNORM_S8_UINT; } else if (stencilBits > 0) { osmesa->depth_stencil_format = PIPE_FORMAT_S8_UINT; } else if (depthBits >= 24) { osmesa->depth_stencil_format = PIPE_FORMAT_Z24X8_UNORM; } else if (depthBits >= 16) { osmesa->depth_stencil_format = PIPE_FORMAT_Z16_UNORM; } /* * Create the rendering context */ attribs.profile = ST_PROFILE_DEFAULT; attribs.major = 2; attribs.minor = 1; attribs.flags = 0; /* ST_CONTEXT_FLAG_x */ attribs.options.force_glsl_extensions_warn = FALSE; attribs.options.disable_blend_func_extended = FALSE; attribs.options.disable_glsl_line_continuations = FALSE; attribs.options.disable_shader_bit_encoding = FALSE; attribs.options.force_s3tc_enable = FALSE; attribs.options.force_glsl_version = 0; osmesa_init_st_visual(&attribs.visual, PIPE_FORMAT_R8G8B8A8_UNORM, osmesa->depth_stencil_format, osmesa->accum_format); osmesa->stctx = stapi->create_context(stapi, get_st_manager(), &attribs, &st_error, st_shared); if (!osmesa->stctx) { FREE(osmesa); return NULL; } osmesa->stctx->st_manager_private = osmesa; osmesa->format = format; osmesa->user_row_length = 0; osmesa->y_up = GL_TRUE; return osmesa; }
static struct st_api * guess_gl_api(enum st_profile_type profile) { return get_st_api(ST_API_OPENGL); }