Merge branch 'lp-offset-twoside'
[mesa.git] / src / mesa / state_tracker / st_cb_eglimage.c
index 935b29a32427f728e4824e86468371bb945fba8a..c4b84de790c3867a9b8f8f84e9223ce027b83b4e 100644 (file)
  * The above copyright notice and this permission notice shall be included
  * in all copies or substantial portions of the Software.
  *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  *
  * Authors:
  *    Chia-I Wu <olv@lunarg.com>
@@ -32,6 +33,7 @@
 #include "util/u_format.h"
 #include "st_cb_eglimage.h"
 #include "st_cb_fbo.h"
+#include "st_context.h"
 #include "st_texture.h"
 #include "st_format.h"
 #include "st_manager.h"
@@ -69,16 +71,16 @@ st_pipe_format_to_base_format(enum pipe_format format)
 }
 
 static void
-st_egl_image_target_renderbuffer_storage(GLcontext *ctx,
+st_egl_image_target_renderbuffer_storage(struct gl_context *ctx,
                                         struct gl_renderbuffer *rb,
                                         GLeglImageOES image_handle)
 {
-   struct st_context *st = ctx->st;
+   struct st_context *st = st_context(ctx);
    struct st_renderbuffer *strb = st_renderbuffer(rb);
    struct pipe_surface *ps;
    unsigned usage;
 
-   usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+   usage = PIPE_BIND_RENDER_TARGET;
    ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage);
    if (ps) {
       strb->Base.Width = ps->width;
@@ -89,14 +91,14 @@ st_egl_image_target_renderbuffer_storage(GLcontext *ctx,
       strb->Base.InternalFormat = strb->Base._BaseFormat;
 
       pipe_surface_reference(&strb->surface, ps);
-      pipe_texture_reference(&strb->texture, ps->texture);
+      pipe_resource_reference(&strb->texture, ps->texture);
 
       pipe_surface_reference(&ps, NULL);
    }
 }
 
 static void
-st_bind_surface(GLcontext *ctx, GLenum target,
+st_bind_surface(struct gl_context *ctx, GLenum target,
                 struct gl_texture_object *texObj,
                 struct gl_texture_image *texImage,
                 struct pipe_surface *ps)
@@ -104,6 +106,7 @@ st_bind_surface(GLcontext *ctx, GLenum target,
    struct st_texture_object *stObj;
    struct st_texture_image *stImage;
    GLenum internalFormat;
+   gl_format texFormat;
 
    /* map pipe format to base format */
    if (util_format_get_component_bits(ps->format, UTIL_FORMAT_COLORSPACE_RGB, 3) > 0)
@@ -120,29 +123,35 @@ st_bind_surface(GLcontext *ctx, GLenum target,
       stObj->surface_based = GL_TRUE;
    }
 
+   texFormat = st_pipe_format_to_mesa_format(ps->format);
+
    _mesa_init_teximage_fields(ctx, target, texImage,
-                              ps->width, ps->height, 1, 0, internalFormat);
-   texImage->TexFormat = st_pipe_format_to_mesa_format(ps->format);
-   _mesa_set_fetch_functions(texImage, 2);
+                              ps->width, ps->height, 1, 0, internalFormat,
+                              texFormat);
 
-   stObj->pipe = ctx->st->pipe;
    /* FIXME create a non-default sampler view from the pipe_surface? */
-   pipe_texture_reference(&stImage->pt, ps->texture);
+   pipe_resource_reference(&stObj->pt, ps->texture);
+   pipe_sampler_view_reference(&stObj->sampler_view, NULL);
+   pipe_resource_reference(&stImage->pt, stObj->pt);
+
+   stObj->width0 = ps->width;
+   stObj->height0 = ps->height;
+   stObj->depth0 = 1;
 
    _mesa_dirty_texobj(ctx, texObj, GL_TRUE);
 }
 
 static void
-st_egl_image_target_texture_2d(GLcontext *ctx, GLenum target,
+st_egl_image_target_texture_2d(struct gl_context *ctx, GLenum target,
                               struct gl_texture_object *texObj,
                               struct gl_texture_image *texImage,
                               GLeglImageOES image_handle)
 {
-   struct st_context *st = ctx->st;
+   struct st_context *st = st_context(ctx);
    struct pipe_surface *ps;
    unsigned usage;
 
-   usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+   usage = PIPE_BIND_SAMPLER_VIEW;
    ps = st_manager_get_egl_image_surface(st, (void *) image_handle, usage);
    if (ps) {
       st_bind_surface(ctx, target, texObj, texImage, ps);