/** * Create a framebuffer from a manager interface. */ static struct st_framebuffer * st_framebuffer_create(struct st_framebuffer_iface *stfbi) { struct st_framebuffer *stfb; struct gl_config mode; gl_buffer_index idx; if (!stfbi) return NULL; stfb = CALLOC_STRUCT(st_framebuffer); if (!stfb) return NULL; st_visual_to_context_mode(stfbi->visual, &mode); _mesa_initialize_window_framebuffer(&stfb->Base, &mode); stfb->iface = stfbi; stfb->iface_stamp = p_atomic_read(&stfbi->stamp) - 1; /* add the color buffer */ idx = stfb->Base._ColorDrawBufferIndexes[0]; if (!st_framebuffer_add_renderbuffer(stfb, idx)) { free(stfb); return NULL; } st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH); st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM); stfb->stamp = 0; st_framebuffer_update_attachments(stfb); return stfb; }
/** * Create a framebuffer from a manager interface. */ static struct st_framebuffer * st_framebuffer_create(struct st_framebuffer_iface *stfbi) { struct st_framebuffer *stfb; struct gl_config mode; gl_buffer_index idx; if (!stfbi) return NULL; stfb = CALLOC_STRUCT(st_framebuffer); if (!stfb) return NULL; st_visual_to_context_mode(stfbi->visual, &mode); _mesa_initialize_window_framebuffer(&stfb->Base, &mode); /* modify the draw/read buffers of the fb */ st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorDrawBuffer[0], &stfb->Base._ColorDrawBufferIndexes[0]); st_visual_to_default_buffer(stfbi->visual, &stfb->Base.ColorReadBuffer, &stfb->Base._ColorReadBufferIndex); stfb->iface = stfbi; /* add the color buffer */ idx = stfb->Base._ColorDrawBufferIndexes[0]; if (!st_framebuffer_add_renderbuffer(stfb, idx)) { FREE(stfb); return NULL; } st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH); st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM); st_framebuffer_update_attachments(stfb); stfb->Base.Initialized = GL_TRUE; return stfb; }
static struct st_context_iface * st_api_create_context(struct st_api *stapi, struct st_manager *smapi, const struct st_context_attribs *attribs, enum st_context_error *error, struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; struct gl_config mode; gl_api api; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; switch (attribs->profile) { case ST_PROFILE_DEFAULT: api = API_OPENGL; break; case ST_PROFILE_OPENGL_ES1: api = API_OPENGLES; break; case ST_PROFILE_OPENGL_ES2: api = API_OPENGLES2; break; case ST_PROFILE_OPENGL_CORE: default: *error = ST_CONTEXT_ERROR_BAD_API; return NULL; break; } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) { *error = ST_CONTEXT_ERROR_NO_MEMORY; return NULL; } st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx); if (!st) { *error = ST_CONTEXT_ERROR_NO_MEMORY; pipe->destroy(pipe); return NULL; } /* need to perform version check */ if (attribs->major > 1 || attribs->minor > 0) { _mesa_compute_version(st->ctx); /* Is the actual version less than the requested version? Mesa can't * yet enforce the added restrictions of a forward-looking context, so * fail that too. */ if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor < attribs->major * 10 + attribs->minor || (attribs->flags & ~ST_CONTEXT_FLAG_DEBUG) != 0) { *error = ST_CONTEXT_ERROR_BAD_VERSION; st_destroy_context(st); return NULL; } } st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); st->iface.destroy = st_context_destroy; st->iface.flush = st_context_flush; st->iface.teximage = st_context_teximage; st->iface.copy = st_context_copy; st->iface.share = st_context_share; st->iface.st_context_private = (void *) smapi; *error = ST_CONTEXT_SUCCESS; return &st->iface; }
static struct st_context_iface * st_api_create_context(struct st_api *stapi, struct st_manager *smapi, const struct st_context_attribs *attribs, enum st_context_error *error, struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; struct gl_config mode; gl_api api; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; switch (attribs->profile) { case ST_PROFILE_DEFAULT: api = API_OPENGL_COMPAT; break; case ST_PROFILE_OPENGL_ES1: api = API_OPENGLES; break; case ST_PROFILE_OPENGL_ES2: api = API_OPENGLES2; break; case ST_PROFILE_OPENGL_CORE: api = API_OPENGL_CORE; break; default: *error = ST_CONTEXT_ERROR_BAD_API; return NULL; break; } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) { *error = ST_CONTEXT_ERROR_NO_MEMORY; return NULL; } st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx, &attribs->options); if (!st) { *error = ST_CONTEXT_ERROR_NO_MEMORY; pipe->destroy(pipe); return NULL; } st->ctx->Debug.DebugOutput = GL_FALSE; if (attribs->flags & ST_CONTEXT_FLAG_DEBUG){ st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT; st->ctx->Debug.DebugOutput = GL_TRUE; } if (attribs->flags & ST_CONTEXT_FLAG_FORWARD_COMPATIBLE) st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT; /* need to perform version check */ if (attribs->major > 1 || attribs->minor > 0) { /* Is the actual version less than the requested version? */ if (st->ctx->Version < attribs->major * 10 + attribs->minor) { *error = ST_CONTEXT_ERROR_BAD_VERSION; st_destroy_context(st); return NULL; } } st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); st->iface.destroy = st_context_destroy; st->iface.flush = st_context_flush; st->iface.teximage = st_context_teximage; st->iface.copy = st_context_copy; st->iface.share = st_context_share; st->iface.st_context_private = (void *) smapi; st->iface.cso_context = st->cso_context; st->iface.pipe = st->pipe; *error = ST_CONTEXT_SUCCESS; return &st->iface; }
/** * Create a framebuffer from a manager interface. */ static struct st_framebuffer * st_framebuffer_create(struct st_context *st, struct st_framebuffer_iface *stfbi) { struct st_framebuffer *stfb; struct gl_config mode; gl_buffer_index idx; if (!stfbi) return NULL; stfb = CALLOC_STRUCT(st_framebuffer); if (!stfb) return NULL; st_visual_to_context_mode(stfbi->visual, &mode); /* * For desktop GL, sRGB framebuffer write is controlled by both the * capability of the framebuffer and GL_FRAMEBUFFER_SRGB. We should * advertise the capability when the pipe driver (and core Mesa) supports * it so that applications can enable sRGB write when they want to. * * This is not to be confused with GLX_FRAMEBUFFER_SRGB_CAPABLE_ARB. When * the attribute is GLX_TRUE, it tells the st manager to pick a color * format such that util_format_srgb(visual->color_format) can be supported * by the pipe driver. We still need to advertise the capability here. * * For GLES, however, sRGB framebuffer write is controlled only by the * capability of the framebuffer. There is GL_EXT_sRGB_write_control to * give applications the control back, but sRGB write is still enabled by * default. To avoid unexpected results, we should not advertise the * capability. This could change when we add support for * EGL_KHR_gl_colorspace. */ if (_mesa_is_desktop_gl(st->ctx)) { struct pipe_screen *screen = st->pipe->screen; const enum pipe_format srgb_format = util_format_srgb(stfbi->visual->color_format); if (srgb_format != PIPE_FORMAT_NONE && st_pipe_format_to_mesa_format(srgb_format) != MESA_FORMAT_NONE && screen->is_format_supported(screen, srgb_format, PIPE_TEXTURE_2D, stfbi->visual->samples, PIPE_BIND_RENDER_TARGET)) mode.sRGBCapable = GL_TRUE; } _mesa_initialize_window_framebuffer(&stfb->Base, &mode); stfb->iface = stfbi; stfb->iface_stamp = p_atomic_read(&stfbi->stamp) - 1; /* add the color buffer */ idx = stfb->Base._ColorDrawBufferIndexes[0]; if (!st_framebuffer_add_renderbuffer(stfb, idx)) { free(stfb); return NULL; } st_framebuffer_add_renderbuffer(stfb, BUFFER_DEPTH); st_framebuffer_add_renderbuffer(stfb, BUFFER_ACCUM); stfb->stamp = 0; st_framebuffer_update_attachments(stfb); return stfb; }
static struct st_context_iface * st_api_create_context(struct st_api *stapi, struct st_manager *smapi, const struct st_context_attribs *attribs, struct st_context_iface *shared_stctxi) { struct st_context *shared_ctx = (struct st_context *) shared_stctxi; struct st_context *st; struct pipe_context *pipe; struct gl_config mode; gl_api api; if (!(stapi->profile_mask & (1 << attribs->profile))) return NULL; switch (attribs->profile) { case ST_PROFILE_DEFAULT: api = API_OPENGL; break; case ST_PROFILE_OPENGL_ES1: api = API_OPENGLES; break; case ST_PROFILE_OPENGL_ES2: api = API_OPENGLES2; break; case ST_PROFILE_OPENGL_CORE: default: return NULL; break; } pipe = smapi->screen->context_create(smapi->screen, NULL); if (!pipe) return NULL; st_visual_to_context_mode(&attribs->visual, &mode); st = st_create_context(api, pipe, &mode, shared_ctx); if (!st) { pipe->destroy(pipe); return NULL; } /* need to perform version check */ if (attribs->major > 1 || attribs->minor > 0) { _mesa_compute_version(st->ctx); /* is the actual version less than the requested version? */ if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor < attribs->major * 10 + attribs->minor) { st_destroy_context(st); return NULL; } } st->invalidate_on_gl_viewport = smapi->get_param(smapi, ST_MANAGER_BROKEN_INVALIDATE); st->iface.destroy = st_context_destroy; st->iface.notify_invalid_framebuffer = st_context_notify_invalid_framebuffer; st->iface.flush = st_context_flush; st->iface.teximage = st_context_teximage; st->iface.copy = st_context_copy; st->iface.share = st_context_share; st->iface.st_context_private = (void *) smapi; return &st->iface; }