mesa: move check for no-op glAlphaFunc call earlier
[mesa.git] / src / mesa / state_tracker / st_cb_drawpixels.c
index 97f2130773dcd8df52a47c2c66cea86d3fb9306d..e736d4b50830b5418e3a0033bba0e060cbb86dde 100644 (file)
@@ -33,6 +33,7 @@
 #include "main/imports.h"
 #include "main/image.h"
 #include "main/bufferobj.h"
+#include "main/blit.h"
 #include "main/format_pack.h"
 #include "main/macros.h"
 #include "main/mtypes.h"
@@ -201,7 +202,7 @@ st_make_drawpix_z_stencil_program(struct st_context *st,
    GLuint ic = 0;
    const GLuint shaderIndex = write_depth * 2 + write_stencil;
 
-   assert(shaderIndex < Elements(st->drawpix.shaders));
+   assert(shaderIndex < ARRAY_SIZE(st->drawpix.shaders));
 
    if (st->drawpix.shaders[shaderIndex]) {
       /* already have the proper shader */
@@ -483,7 +484,7 @@ make_texture(struct st_context *st,
 {
    struct gl_context *ctx = st->ctx;
    struct pipe_context *pipe = st->pipe;
-   gl_format mformat;
+   mesa_format mformat;
    struct pipe_resource *pt;
    enum pipe_format pipeFormat;
    GLenum baseInternalFormat;
@@ -491,25 +492,22 @@ make_texture(struct st_context *st,
    /* Choose a pixel format for the temp texture which will hold the
     * image to draw.
     */
-   pipeFormat = st_choose_matching_format(pipe->screen, PIPE_BIND_SAMPLER_VIEW,
+   pipeFormat = st_choose_matching_format(st, PIPE_BIND_SAMPLER_VIEW,
                                           format, type, unpack->SwapBytes);
 
-   if (pipeFormat != PIPE_FORMAT_NONE) {
-      mformat = st_pipe_format_to_mesa_format(pipeFormat);
-      baseInternalFormat = _mesa_get_format_base_format(mformat);
-   }
-   else {
+   if (pipeFormat == PIPE_FORMAT_NONE) {
       /* Use the generic approach. */
       GLenum intFormat = internal_format(ctx, format, type);
 
-      baseInternalFormat = _mesa_base_tex_format(ctx, intFormat);
       pipeFormat = st_choose_format(st, intFormat, format, type,
                                     PIPE_TEXTURE_2D, 0, PIPE_BIND_SAMPLER_VIEW,
                                     FALSE);
       assert(pipeFormat != PIPE_FORMAT_NONE);
-      mformat = st_pipe_format_to_mesa_format(pipeFormat);
    }
 
+   mformat = st_pipe_format_to_mesa_format(pipeFormat);
+   baseInternalFormat = _mesa_get_format_base_format(mformat);
+
    pixels = _mesa_map_pbo_source(ctx, unpack, pixels);
    if (!pixels)
       return NULL;
@@ -542,7 +540,7 @@ make_texture(struct st_context *st,
        */
       success = _mesa_texstore(ctx, 2,           /* dims */
                                baseInternalFormat, /* baseInternalFormat */
-                               mformat,          /* gl_format */
+                               mformat,          /* mesa_format */
                                transfer->stride, /* dstRowStride, bytes */
                                &dest,            /* destSlices */
                                width, height, 1, /* size */
@@ -696,6 +694,8 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    cso_save_fragment_shader(cso);
    cso_save_stream_outputs(cso);
    cso_save_vertex_shader(cso);
+   cso_save_tessctrl_shader(cso);
+   cso_save_tesseval_shader(cso);
    cso_save_geometry_shader(cso);
    cso_save_vertex_elements(cso);
    cso_save_aux_vertex_buffer_slot(cso);
@@ -749,7 +749,9 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    /* vertex shader state: position + texcoord pass-through */
    cso_set_vertex_shader_handle(cso, driver_vp);
 
-   /* geometry shader state: disabled */
+   /* disable other shaders */
+   cso_set_tessctrl_shader_handle(cso, NULL);
+   cso_set_tesseval_shader_handle(cso, NULL);
    cso_set_geometry_shader_handle(cso, NULL);
 
    /* texture sampling state: */
@@ -779,16 +781,14 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
       vp.scale[0] =  0.5f * w;
       vp.scale[1] = -0.5f * h;
       vp.scale[2] = 0.5f;
-      vp.scale[3] = 1.0f;
       vp.translate[0] = 0.5f * w;
       vp.translate[1] = 0.5f * h;
       vp.translate[2] = 0.5f;
-      vp.translate[3] = 0.0f;
       cso_set_viewport(cso, &vp);
    }
 
    cso_set_vertex_elements(cso, 3, st->velems_util_draw);
-   cso_set_stream_outputs(st->cso_context, 0, NULL, 0);
+   cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
 
    /* texture state: */
    cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num_sampler_view, sv);
@@ -821,6 +821,8 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint y, GLfloat z,
    cso_restore_sampler_views(cso, PIPE_SHADER_FRAGMENT);
    cso_restore_fragment_shader(cso);
    cso_restore_vertex_shader(cso);
+   cso_restore_tessctrl_shader(cso);
+   cso_restore_tesseval_shader(cso);
    cso_restore_geometry_shader(cso);
    cso_restore_vertex_elements(cso);
    cso_restore_aux_vertex_buffer_slot(cso);
@@ -1105,7 +1107,7 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
    const GLfloat *color;
    struct pipe_context *pipe = st->pipe;
    GLboolean write_stencil = GL_FALSE, write_depth = GL_FALSE;
-   struct pipe_sampler_view *sv[2];
+   struct pipe_sampler_view *sv[2] = { NULL };
    int num_sampler_view = 1;
    struct st_fp_variant *fpv;
    struct gl_pixelstore_attrib clippedUnpack;
@@ -1159,8 +1161,9 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
 
       color = NULL;
       if (st->pixel_xfer.pixelmap_enabled) {
-         sv[1] = st->pixel_xfer.pixelmap_sampler_view;
-         num_sampler_view++;
+         pipe_sampler_view_reference(&sv[1],
+                                     st->pixel_xfer.pixelmap_sampler_view);
+         num_sampler_view++;
       }
    }
 
@@ -1181,7 +1184,8 @@ st_DrawPixels(struct gl_context *ctx, GLint x, GLint y,
             if (write_stencil) {
                enum pipe_format stencil_format =
                      util_format_stencil_only(pt->format);
-
+               /* we should not be doing pixel map/transfer (see above) */
+               assert(num_sampler_view == 1);
                sv[1] = st_create_texture_sampler_view_format(st->pipe, pt,
                                                              stencil_format);
                num_sampler_view++;
@@ -1309,31 +1313,6 @@ st_get_color_read_renderbuffer(struct gl_context *ctx)
 }
 
 
-/**
- * \return TRUE if two regions overlap, FALSE otherwise
- */
-static boolean
-regions_overlap(int srcX0, int srcY0,
-                int srcX1, int srcY1,
-                int dstX0, int dstY0,
-                int dstX1, int dstY1)
-{
-   if (MAX2(srcX0, srcX1) < MIN2(dstX0, dstX1))
-      return FALSE; /* src completely left of dst */
-
-   if (MAX2(dstX0, dstX1) < MIN2(srcX0, srcX1))
-      return FALSE; /* dst completely left of src */
-
-   if (MAX2(srcY0, srcY1) < MIN2(dstY0, dstY1))
-      return FALSE; /* src completely above dst */
-
-   if (MAX2(dstY0, dstY1) < MIN2(srcY0, srcY1))
-      return FALSE; /* dst completely above src */
-
-   return TRUE; /* some overlap */
-}
-
-
 /**
  * Try to do a glCopyPixels for simple cases with a blit by calling
  * pipe->blit().
@@ -1364,7 +1343,7 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
        !ctx->Stencil.Enabled &&
        !ctx->FragmentProgram.Enabled &&
        !ctx->VertexProgram.Enabled &&
-       !ctx->Shader.CurrentProgram[MESA_SHADER_FRAGMENT] &&
+       !ctx->_Shader->CurrentProgram[MESA_SHADER_FRAGMENT] &&
        ctx->DrawBuffer->_NumColorDrawBuffers == 1 &&
        !ctx->Query.CondRenderQuery &&
        !ctx->Query.CurrentOcclusionObject) {
@@ -1417,8 +1396,8 @@ blit_copy_pixels(struct gl_context *ctx, GLint srcx, GLint srcy,
       }
 
       if (rbRead != rbDraw ||
-          !regions_overlap(readX, readY, readX + readW, readY + readH,
-                           drawX, drawY, drawX + drawW, drawY + drawH)) {
+          !_mesa_regions_overlap(readX, readY, readX + readW, readY + readH,
+                                 drawX, drawY, drawX + drawW, drawY + drawH)) {
          struct pipe_blit_info blit;
 
          memset(&blit, 0, sizeof(blit));
@@ -1472,7 +1451,7 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
    struct st_renderbuffer *rbRead;
    void *driver_vp, *driver_fp;
    struct pipe_resource *pt;
-   struct pipe_sampler_view *sv[2];
+   struct pipe_sampler_view *sv[2] = { NULL };
    int num_sampler_view = 1;
    GLfloat *color;
    enum pipe_format srcFormat;
@@ -1521,7 +1500,8 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,
       driver_vp = make_passthrough_vertex_shader(st, GL_FALSE);
 
       if (st->pixel_xfer.pixelmap_enabled) {
-         sv[1] = st->pixel_xfer.pixelmap_sampler_view;
+         pipe_sampler_view_reference(&sv[1],
+                                     st->pixel_xfer.pixelmap_sampler_view);
          num_sampler_view++;
       }
    }
@@ -1686,7 +1666,7 @@ st_destroy_drawpix(struct st_context *st)
 {
    GLuint i;
 
-   for (i = 0; i < Elements(st->drawpix.shaders); i++) {
+   for (i = 0; i < ARRAY_SIZE(st->drawpix.shaders); i++) {
       if (st->drawpix.shaders[i])
          _mesa_reference_fragprog(st->ctx, &st->drawpix.shaders[i], NULL);
    }