st/mesa: Make st_cb_drawtex.h FEATURE_OES_draw_texture aware.
[mesa.git] / src / mesa / state_tracker / st_cb_texture.c
index 5021dcbcb602a67db3c995a0b15479cf216e3da9..e34fd09dcb753f468310695d74e11f2668d30e6d 100644 (file)
 #include "state_tracker/st_debug.h"
 #include "state_tracker/st_context.h"
 #include "state_tracker/st_cb_fbo.h"
+#include "state_tracker/st_cb_flush.h"
 #include "state_tracker/st_cb_texture.h"
 #include "state_tracker/st_format.h"
 #include "state_tracker/st_texture.h"
 #include "state_tracker/st_gen_mipmap.h"
-#include "state_tracker/st_inlines.h"
 #include "state_tracker/st_atom.h"
 
 #include "pipe/p_context.h"
@@ -255,8 +255,10 @@ get_texture_dims(GLenum target)
  *
  * We use the given st_texture_image as a clue to determine the size of the
  * mipmap image at level=0.
+ *
+ * \return GL_TRUE for success, GL_FALSE if out of memory.
  */
-static void
+static GLboolean
 guess_and_alloc_texture(struct st_context *st,
                        struct st_texture_object *stObj,
                        const struct st_texture_image *stImage)
@@ -287,7 +289,8 @@ guess_and_alloc_texture(struct st_context *st,
            (dims >= 3 && depth == 1) ) {
          /* we can't determine the image size at level=0 */
          stObj->width0 = stObj->height0 = stObj->depth0 = 0;
-         return;
+         /* this is not an out of memory error */
+         return GL_TRUE;
       }
    }
 
@@ -349,7 +352,9 @@ guess_and_alloc_texture(struct st_context *st,
                                  depth,
                                  bindings);
 
-   DBG("%s - success\n", __FUNCTION__);
+   DBG("%s returning %d\n", __FUNCTION__, (stObj->pt != NULL));
+
+   return stObj->pt != NULL;
 }
 
 
@@ -459,7 +464,7 @@ compress_with_blit(GLcontext * ctx,
 
    /* Put user's tex data into the temporary texture
     */
-   tex_xfer = st_cond_flush_get_tex_transfer(st_context(ctx), src_tex,
+   tex_xfer = pipe_get_transfer(st_context(ctx)->pipe, src_tex,
                                             0, 0, 0, /* face, level are zero */
                                             PIPE_TRANSFER_WRITE,
                                             0, 0, width, height); /* x, y, w, h */
@@ -597,14 +602,12 @@ st_TexImage(GLcontext * ctx,
    }
 
    if (!stObj->pt) {
-      guess_and_alloc_texture(st, stObj, stImage);
-      if (!stObj->pt) {
+      if (!guess_and_alloc_texture(st, stObj, stImage)) {
          /* Probably out of memory.
           * Try flushing any pending rendering, then retry.
           */
          st_finish(st);
-         guess_and_alloc_texture(st, stObj, stImage);
-         if (!stObj->pt) {
+         if (!guess_and_alloc_texture(st, stObj, stImage)) {
             _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage");
             return;
          }
@@ -872,7 +875,7 @@ decompress_with_blit(GLcontext * ctx, GLenum target, GLint level,
                         PIPE_TEX_MIPFILTER_NEAREST);
 
    /* map the dst_surface so we can read from it */
-   tex_xfer = st_cond_flush_get_tex_transfer(st_context(ctx),
+   tex_xfer = pipe_get_transfer(st_context(ctx)->pipe,
                                             dst_texture, 0, 0, 0,
                                             PIPE_TRANSFER_READ,
                                             0, 0, width, height);
@@ -958,11 +961,6 @@ st_get_tex_image(GLcontext * ctx, GLenum target, GLint level,
       /* Image is stored in hardware format in a buffer managed by the
        * kernel.  Need to explicitly map and unmap it.
        */
-      unsigned face = _mesa_tex_target_to_face(target);
-
-      st_teximage_flush_before_map(st, stImage->pt, face, level,
-                                  PIPE_TRANSFER_READ);
-
       texImage->Data = st_texture_image_map(st, stImage, 0,
                                             PIPE_TRANSFER_READ, 0, 0,
                                             stImage->base.Width,
@@ -1094,16 +1092,12 @@ st_TexSubimage(GLcontext *ctx, GLint dims, GLenum target, GLint level,
     * from uploading the buffer under us.
     */
    if (stImage->pt) {
-      unsigned face = _mesa_tex_target_to_face(target);
-
       if (format == GL_DEPTH_COMPONENT &&
           util_format_is_depth_and_stencil(stImage->pt->format))
          transfer_usage = PIPE_TRANSFER_READ_WRITE;
       else
          transfer_usage = PIPE_TRANSFER_WRITE;
 
-      st_teximage_flush_before_map(st, stImage->pt, face, level,
-                                  transfer_usage);
       texImage->Data = st_texture_image_map(st, stImage, zoffset, 
                                             transfer_usage,
                                             xoffset, yoffset,
@@ -1226,11 +1220,8 @@ st_CompressedTexSubImage2D(GLcontext *ctx, GLenum target, GLint level,
    enum pipe_format pformat;
 
    if (stImage->pt) {
-      unsigned face = _mesa_tex_target_to_face(target);
       pformat = stImage->pt->format;
 
-      st_teximage_flush_before_map(st, stImage->pt, face, level,
-                                  PIPE_TRANSFER_WRITE);
       texImage->Data = st_texture_image_map(st, stImage, 0, 
                                             PIPE_TRANSFER_WRITE,
                                             xoffset, yoffset,
@@ -1314,7 +1305,7 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
       srcY = strb->Base.Height - srcY - height;
    }
 
-   src_trans = st_cond_flush_get_tex_transfer( st_context(ctx),
+   src_trans = pipe_get_transfer(st_context(ctx)->pipe,
                                               strb->texture,
                                               0, 0, 0,
                                               PIPE_TRANSFER_READ,
@@ -1328,9 +1319,6 @@ fallback_copy_texsubimage(GLcontext *ctx, GLenum target, GLint level,
    else
       transfer_usage = PIPE_TRANSFER_WRITE;
 
-   st_teximage_flush_before_map(st, stImage->pt, 0, 0,
-                               transfer_usage);
-
    texDest = st_texture_image_map(st, stImage, 0, transfer_usage,
                                   destX, destY, width, height);
 
@@ -1512,9 +1500,6 @@ st_copy_texsubimage(GLcontext *ctx,
    struct pipe_surface *dest_surface = NULL;
    GLboolean do_flip = (st_fb_orientation(ctx->ReadBuffer) == Y_0_TOP);
 
-   /* any rendering in progress must flushed before we grab the fb image */
-   st_flush(st, PIPE_FLUSH_RENDER_CACHE, NULL);
-
    /* make sure finalize_textures has been called? 
     */
    if (0) st_validate_state(st);
@@ -1775,17 +1760,12 @@ copy_image_data_to_texture(struct st_context *st,
        */
       st_texture_image_copy(st->pipe,
                             stObj->pt, dstLevel,  /* dest texture, level */
-                            stImage->pt, /* src texture */
+                            stImage->pt, stImage->level, /* src texture, level */
                             stImage->face);
 
       pipe_resource_reference(&stImage->pt, NULL);
    }
    else if (stImage->base.Data) {
-      /* More straightforward upload.  
-       */
-      st_teximage_flush_before_map(st, stObj->pt, stImage->face, dstLevel,
-                                  PIPE_TRANSFER_WRITE);
-
       st_texture_image_data(st,
                             stObj->pt,
                             stImage->face,
@@ -1812,8 +1792,7 @@ copy_image_data_to_texture(struct st_context *st,
 GLboolean
 st_finalize_texture(GLcontext *ctx,
                    struct pipe_context *pipe,
-                   struct gl_texture_object *tObj,
-                   GLboolean *needFlush)
+                   struct gl_texture_object *tObj)
 {
    struct st_context *st = st_context(ctx);
    struct st_texture_object *stObj = st_texture_object(tObj);
@@ -1822,8 +1801,6 @@ st_finalize_texture(GLcontext *ctx,
    struct st_texture_image *firstImage;
    enum pipe_format firstImageFormat;
 
-   *needFlush = GL_FALSE;
-
    if (stObj->base._Complete) {
       /* The texture is complete and we know exactly how many mipmap levels
        * are present/needed.  This is conditional because we may be called
@@ -1900,7 +1877,7 @@ st_finalize_texture(GLcontext *ctx,
     */
    for (face = 0; face < nr_faces; face++) {
       GLuint level;
-      for (level = 0; level <= stObj->lastLevel; level++) {
+      for (level = stObj->base.BaseLevel; level <= stObj->lastLevel; level++) {
          struct st_texture_image *stImage =
             st_texture_image(stObj->base.Image[face][level]);
 
@@ -1908,7 +1885,6 @@ st_finalize_texture(GLcontext *ctx,
           */
          if (stImage && stObj->pt != stImage->pt) {
             copy_image_data_to_texture(st, stObj, level, stImage);
-           *needFlush = GL_TRUE;
          }
       }
    }