gallium: pass the current context to the flush_front state tracker function
[mesa.git] / src / mesa / state_tracker / st_manager.c
index 875e0c44ac101f709be366828e56158790d7d062..da58186147990b937be0132d2ebe923d4a2ffc0a 100644 (file)
@@ -430,7 +430,7 @@ st_framebuffer_create(struct st_framebuffer_iface *stfbi)
    /* add the color buffer */
    idx = stfb->Base._ColorDrawBufferIndexes[0];
    if (!st_framebuffer_add_renderbuffer(stfb, idx)) {
-      FREE(stfb);
+      free(stfb);
       return NULL;
    }
 
@@ -468,7 +468,7 @@ st_context_flush(struct st_context_iface *stctxi, unsigned flags,
 
 static boolean
 st_context_teximage(struct st_context_iface *stctxi,
-                    enum st_texture_type target,
+                    enum st_texture_type tex_type,
                     int level, enum pipe_format internal_format,
                     struct pipe_resource *tex, boolean mipmap)
 {
@@ -481,8 +481,9 @@ st_context_teximage(struct st_context_iface *stctxi,
    struct st_texture_image *stImage;
    GLenum internalFormat;
    GLuint width, height, depth;
+   GLenum target;
 
-   switch (target) {
+   switch (tex_type) {
    case ST_TEXTURE_1D:
       target = GL_TEXTURE_1D;
       break;
@@ -497,7 +498,6 @@ st_context_teximage(struct st_context_iface *stctxi,
       break;
    default:
       return FALSE;
-      break;
    }
 
    texObj = _mesa_select_tex_object(ctx, texUnit, target);
@@ -533,7 +533,7 @@ st_context_teximage(struct st_context_iface *stctxi,
       else
          internalFormat = GL_RGB;
 
-      texFormat = st_ChooseTextureFormat(ctx, internalFormat,
+      texFormat = st_ChooseTextureFormat(ctx, target, internalFormat,
                                          GL_BGRA, GL_UNSIGNED_BYTE);
 
       _mesa_init_teximage_fields(ctx, texImage,
@@ -615,7 +615,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
 
    switch (attribs->profile) {
    case ST_PROFILE_DEFAULT:
-      api = API_OPENGL;
+      api = API_OPENGL_COMPAT;
       break;
    case ST_PROFILE_OPENGL_ES1:
       api = API_OPENGLES;
@@ -624,6 +624,8 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       api = API_OPENGLES2;
       break;
    case ST_PROFILE_OPENGL_CORE:
+      api = API_OPENGL_CORE;
+      break;
    default:
       *error = ST_CONTEXT_ERROR_BAD_API;
       return NULL;
@@ -637,24 +639,25 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
    }
 
    st_visual_to_context_mode(&attribs->visual, &mode);
-   st = st_create_context(api, pipe, &mode, shared_ctx);
+   st = st_create_context(api, pipe, &mode, shared_ctx, &attribs->options);
    if (!st) {
       *error = ST_CONTEXT_ERROR_NO_MEMORY;
       pipe->destroy(pipe);
       return NULL;
    }
 
+   if (attribs->flags & ST_CONTEXT_FLAG_DEBUG)
+      st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
+   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) {
       _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.
+      /* Is the actual version less than the requested version?
        */
-      if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor <
-          attribs->major * 10 + attribs->minor
-         || (attribs->flags & ~ST_CONTEXT_FLAG_DEBUG) != 0) {
+      if (st->ctx->Version < attribs->major * 10 + attribs->minor) {
         *error = ST_CONTEXT_ERROR_BAD_VERSION;
          st_destroy_context(st);
          return NULL;
@@ -670,6 +673,8 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
    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;
@@ -784,7 +789,7 @@ st_manager_flush_frontbuffer(struct st_context *st)
 
    /* never a dummy fb */
    assert(&stfb->Base != _mesa_get_incomplete_framebuffer());
-   stfb->iface->flush_front(stfb->iface, ST_ATTACHMENT_FRONT_LEFT);
+   stfb->iface->flush_front(&st->iface, stfb->iface, ST_ATTACHMENT_FRONT_LEFT);
 }
 
 /**
@@ -885,6 +890,7 @@ static const struct st_api st_gl_api = {
    ST_API_OPENGL,
 #if FEATURE_GL
    ST_PROFILE_DEFAULT_MASK |
+   ST_PROFILE_OPENGL_CORE_MASK |
 #endif
 #if FEATURE_ES1
    ST_PROFILE_OPENGL_ES1_MASK |