mesa: allocate gl_debug_state on demand
[mesa.git] / src / mesa / state_tracker / st_manager.c
index ec876087c95c2a6bbdfb34cb3be79ba2ef04af8c..6a776a8a236a5883069694345565510613347fee 100644 (file)
@@ -30,6 +30,7 @@
 #include "main/texobj.h"
 #include "main/teximage.h"
 #include "main/texstate.h"
+#include "main/errors.h"
 #include "main/framebuffer.h"
 #include "main/fbobject.h"
 #include "main/renderbuffer.h"
@@ -189,7 +190,7 @@ st_framebuffer_validate(struct st_framebuffer *stfb,
 
    /* validate the fb */
    do {
-      if (!stfb->iface->validate(stfb->iface, stfb->statts,
+      if (!stfb->iface->validate(&st->iface, stfb->iface, stfb->statts,
                                 stfb->num_statts, textures))
         return;
 
@@ -431,8 +432,6 @@ st_framebuffer_create(struct st_framebuffer_iface *stfbi)
    stfb->stamp = 0;
    st_framebuffer_update_attachments(stfb);
 
-   stfb->Base.Initialized = GL_TRUE;
-
    return stfb;
 }
 
@@ -471,7 +470,6 @@ st_context_teximage(struct st_context_iface *stctxi,
 {
    struct st_context *st = (struct st_context *) stctxi;
    struct gl_context *ctx = st->ctx;
-   struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
    struct gl_texture_object *texObj;
    struct gl_texture_image *texImage;
    struct st_texture_object *stObj;
@@ -497,7 +495,8 @@ st_context_teximage(struct st_context_iface *stctxi,
       return FALSE;
    }
 
-   texObj = _mesa_select_tex_object(ctx, texUnit, target);
+   texObj = _mesa_get_current_tex_object(ctx, target);
+
    _mesa_lock_texture(ctx, texObj);
 
    stObj = st_texture_object(texObj);
@@ -510,7 +509,7 @@ st_context_teximage(struct st_context_iface *stctxi,
    texImage = _mesa_get_tex_image(ctx, texObj, target, level);
    stImage = st_texture_image(texImage);
    if (tex) {
-      gl_format texFormat = st_pipe_format_to_mesa_format(pipe_format);
+      mesa_format texFormat = st_pipe_format_to_mesa_format(pipe_format);
 
       if (util_format_has_alpha(tex->format))
          internalFormat = GL_RGBA;
@@ -547,7 +546,7 @@ st_context_teximage(struct st_context_iface *stctxi,
    stObj->depth0 = depth;
    stObj->surface_format = pipe_format;
 
-   _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
+   _mesa_dirty_texobj(ctx, texObj);
    _mesa_unlock_texture(ctx, texObj);
    
    return TRUE;
@@ -628,8 +627,16 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       return NULL;
    }
 
-   if (attribs->flags & ST_CONTEXT_FLAG_DEBUG)
+   if (attribs->flags & ST_CONTEXT_FLAG_DEBUG){
+      struct gl_debug_state *debug = _mesa_get_debug_state(st->ctx);
+      if (!debug) {
+         *error = ST_CONTEXT_ERROR_NO_MEMORY;
+         return NULL;
+      }
       st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_DEBUG_BIT;
+      debug->DebugOutput = GL_TRUE;
+   }
+
    if (attribs->flags & ST_CONTEXT_FLAG_FORWARD_COMPATIBLE)
       st->ctx->Const.ContextFlags |= GL_CONTEXT_FLAG_FORWARD_COMPATIBLE_BIT;