2007-08-02 13:59:31 +01:00
|
|
|
/**************************************************************************
|
|
|
|
*
|
2007-08-02 10:29:42 -06:00
|
|
|
* Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
|
2007-08-02 13:59:31 +01:00
|
|
|
* All Rights Reserved.
|
2009-04-04 19:01:51 +02:00
|
|
|
* Copyright 2009 VMware, Inc. All Rights Reserved.
|
2007-08-02 13:59:31 +01:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sub license, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the
|
|
|
|
* next paragraph) 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, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS 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:
|
|
|
|
* Keith Whitwell <keith@tungstengraphics.com>
|
|
|
|
* Brian Paul
|
2009-04-04 19:01:51 +02:00
|
|
|
* Michel Dänzer
|
2007-08-02 13:59:31 +01:00
|
|
|
*/
|
|
|
|
|
2007-08-08 16:08:45 -06:00
|
|
|
#include "main/glheader.h"
|
2011-12-03 10:04:18 -07:00
|
|
|
#include "main/accum.h"
|
2009-10-08 20:27:27 -06:00
|
|
|
#include "main/formats.h"
|
2007-08-08 16:08:45 -06:00
|
|
|
#include "main/macros.h"
|
2012-10-15 03:55:23 +02:00
|
|
|
#include "main/glformats.h"
|
2010-06-10 23:02:41 -06:00
|
|
|
#include "program/prog_instruction.h"
|
2007-08-02 10:29:42 -06:00
|
|
|
#include "st_context.h"
|
2008-05-02 10:08:03 +00:00
|
|
|
#include "st_atom.h"
|
2007-08-02 10:29:42 -06:00
|
|
|
#include "st_cb_clear.h"
|
2007-08-09 12:59:11 -06:00
|
|
|
#include "st_cb_fbo.h"
|
2011-02-21 16:54:23 -07:00
|
|
|
#include "st_format.h"
|
2007-08-08 16:08:45 -06:00
|
|
|
#include "st_program.h"
|
2007-08-20 16:21:08 -06:00
|
|
|
|
2007-08-02 13:59:31 +01:00
|
|
|
#include "pipe/p_context.h"
|
2010-08-05 18:21:09 -07:00
|
|
|
#include "pipe/p_shader_tokens.h"
|
2007-08-20 16:21:08 -06:00
|
|
|
#include "pipe/p_state.h"
|
2007-08-02 10:29:42 -06:00
|
|
|
#include "pipe/p_defines.h"
|
2009-12-03 10:20:49 +01:00
|
|
|
#include "util/u_format.h"
|
2010-03-24 08:25:24 -06:00
|
|
|
#include "util/u_inlines.h"
|
2008-03-20 09:13:51 -06:00
|
|
|
#include "util/u_simple_shaders.h"
|
2008-03-20 10:46:44 -06:00
|
|
|
#include "util/u_draw_quad.h"
|
2012-04-13 19:27:45 +02:00
|
|
|
#include "util/u_upload_mgr.h"
|
2007-08-20 16:21:08 -06:00
|
|
|
|
2008-03-11 18:54:31 -06:00
|
|
|
#include "cso_cache/cso_context.h"
|
|
|
|
|
2007-08-20 16:21:08 -06:00
|
|
|
|
2010-03-24 08:25:24 -06:00
|
|
|
/**
|
|
|
|
* Do per-context initialization for glClear.
|
|
|
|
*/
|
2008-04-03 12:54:32 -06:00
|
|
|
void
|
|
|
|
st_init_clear(struct st_context *st)
|
|
|
|
{
|
2010-02-24 16:41:18 +01:00
|
|
|
memset(&st->clear, 0, sizeof(st->clear));
|
|
|
|
|
2008-04-03 13:16:37 -06:00
|
|
|
st->clear.raster.gl_rasterization_rules = 1;
|
2012-01-10 00:19:00 +01:00
|
|
|
st->clear.raster.depth_clip = 1;
|
2008-04-03 12:54:32 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 08:25:24 -06:00
|
|
|
/**
|
|
|
|
* Free per-context state for glClear.
|
|
|
|
*/
|
2008-03-20 09:13:51 -06:00
|
|
|
void
|
|
|
|
st_destroy_clear(struct st_context *st)
|
|
|
|
{
|
|
|
|
if (st->clear.fs) {
|
2008-04-24 12:11:24 -06:00
|
|
|
cso_delete_fragment_shader(st->cso_context, st->clear.fs);
|
2008-03-20 09:13:51 -06:00
|
|
|
st->clear.fs = NULL;
|
|
|
|
}
|
|
|
|
if (st->clear.vs) {
|
2008-04-24 12:11:24 -06:00
|
|
|
cso_delete_vertex_shader(st->cso_context, st->clear.vs);
|
2008-03-20 09:13:51 -06:00
|
|
|
st->clear.vs = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-05 13:27:00 +01:00
|
|
|
/**
|
|
|
|
* Helper function to set the fragment shaders.
|
|
|
|
*/
|
|
|
|
static INLINE void
|
|
|
|
set_fragment_shader(struct st_context *st)
|
|
|
|
{
|
|
|
|
if (!st->clear.fs)
|
|
|
|
st->clear.fs = util_make_fragment_passthrough_shader(st->pipe);
|
|
|
|
|
|
|
|
cso_set_fragment_shader_handle(st->cso_context, st->clear.fs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to set the vertex shader.
|
|
|
|
*/
|
|
|
|
static INLINE void
|
|
|
|
set_vertex_shader(struct st_context *st)
|
|
|
|
{
|
|
|
|
/* vertex shader - still required to provide the linkage between
|
|
|
|
* fragment shader input semantics and vertex_element/buffers.
|
|
|
|
*/
|
|
|
|
if (!st->clear.vs)
|
|
|
|
{
|
|
|
|
const uint semantic_names[] = { TGSI_SEMANTIC_POSITION,
|
|
|
|
TGSI_SEMANTIC_COLOR };
|
|
|
|
const uint semantic_indexes[] = { 0, 0 };
|
|
|
|
st->clear.vs = util_make_vertex_passthrough_shader(st->pipe, 2,
|
|
|
|
semantic_names,
|
|
|
|
semantic_indexes);
|
|
|
|
}
|
|
|
|
|
|
|
|
cso_set_vertex_shader_handle(st->cso_context, st->clear.vs);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 12:12:48 -06:00
|
|
|
/**
|
|
|
|
* Draw a screen-aligned quadrilateral.
|
2010-02-22 21:36:22 +01:00
|
|
|
* Coords are clip coords with y=0=bottom.
|
2007-08-02 12:12:48 -06:00
|
|
|
*/
|
|
|
|
static void
|
2010-04-23 14:00:50 -06:00
|
|
|
draw_quad(struct st_context *st,
|
2007-08-02 12:12:48 -06:00
|
|
|
float x0, float y0, float x1, float y1, GLfloat z,
|
2011-09-16 09:39:34 +01:00
|
|
|
const union pipe_color_union *color)
|
2007-08-02 12:12:48 -06:00
|
|
|
{
|
2008-03-20 10:46:44 -06:00
|
|
|
struct pipe_context *pipe = st->pipe;
|
2012-04-13 19:27:45 +02:00
|
|
|
struct pipe_resource *vbuf = NULL;
|
|
|
|
GLuint i, offset;
|
2012-04-13 20:37:41 +02:00
|
|
|
float (*vertices)[2][4]; /**< vertex pos + color */
|
|
|
|
|
|
|
|
u_upload_alloc(st->uploader, 0, 4 * sizeof(vertices[0]), &offset, &vbuf,
|
|
|
|
(void**)&vertices);
|
|
|
|
if (!vbuf) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-07 12:28:26 -07:00
|
|
|
|
2007-08-02 12:12:48 -06:00
|
|
|
/* positions */
|
2012-04-13 20:37:41 +02:00
|
|
|
vertices[0][0][0] = x0;
|
|
|
|
vertices[0][0][1] = y0;
|
2007-08-02 12:12:48 -06:00
|
|
|
|
2012-04-13 20:37:41 +02:00
|
|
|
vertices[1][0][0] = x1;
|
|
|
|
vertices[1][0][1] = y0;
|
2007-08-02 12:12:48 -06:00
|
|
|
|
2012-04-13 20:37:41 +02:00
|
|
|
vertices[2][0][0] = x1;
|
|
|
|
vertices[2][0][1] = y1;
|
2007-08-02 12:12:48 -06:00
|
|
|
|
2012-04-13 20:37:41 +02:00
|
|
|
vertices[3][0][0] = x0;
|
|
|
|
vertices[3][0][1] = y1;
|
2007-08-02 12:12:48 -06:00
|
|
|
|
|
|
|
/* same for all verts: */
|
|
|
|
for (i = 0; i < 4; i++) {
|
2012-04-13 20:37:41 +02:00
|
|
|
vertices[i][0][2] = z;
|
|
|
|
vertices[i][0][3] = 1.0;
|
|
|
|
vertices[i][1][0] = color->f[0];
|
|
|
|
vertices[i][1][1] = color->f[1];
|
|
|
|
vertices[i][1][2] = color->f[2];
|
|
|
|
vertices[i][1][3] = color->f[3];
|
2007-08-02 12:12:48 -06:00
|
|
|
}
|
|
|
|
|
2012-04-13 19:27:45 +02:00
|
|
|
u_upload_unmap(st->uploader);
|
2008-03-20 10:46:44 -06:00
|
|
|
|
|
|
|
/* draw */
|
2011-01-09 09:25:56 +01:00
|
|
|
util_draw_vertex_buffer(pipe,
|
|
|
|
st->cso_context,
|
2012-03-29 17:51:50 +02:00
|
|
|
vbuf,
|
|
|
|
cso_get_aux_vertex_buffer_slot(st->cso_context),
|
|
|
|
offset,
|
2008-03-20 10:46:44 -06:00
|
|
|
PIPE_PRIM_TRIANGLE_FAN,
|
|
|
|
4, /* verts */
|
|
|
|
2); /* attribs/vert */
|
2008-12-12 16:46:34 +00:00
|
|
|
|
2012-04-13 19:27:45 +02:00
|
|
|
pipe_resource_reference(&vbuf, NULL);
|
2007-08-02 12:12:48 -06:00
|
|
|
}
|
2007-08-02 10:29:42 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Do glClear by drawing a quadrilateral.
|
2007-08-10 16:25:21 -06:00
|
|
|
* The vertices of the quad will be computed from the
|
|
|
|
* ctx->DrawBuffer->_X/Ymin/max fields.
|
2007-08-02 10:29:42 -06:00
|
|
|
*/
|
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
clear_with_quad(struct gl_context *ctx,
|
2007-08-02 12:12:48 -06:00
|
|
|
GLboolean color, GLboolean depth, GLboolean stencil)
|
2007-08-02 10:29:42 -06:00
|
|
|
{
|
2010-04-23 14:00:50 -06:00
|
|
|
struct st_context *st = st_context(ctx);
|
2010-02-22 21:36:22 +01:00
|
|
|
const struct gl_framebuffer *fb = ctx->DrawBuffer;
|
|
|
|
const GLfloat fb_width = (GLfloat) fb->Width;
|
|
|
|
const GLfloat fb_height = (GLfloat) fb->Height;
|
|
|
|
const GLfloat x0 = (GLfloat) ctx->DrawBuffer->_Xmin / fb_width * 2.0f - 1.0f;
|
|
|
|
const GLfloat x1 = (GLfloat) ctx->DrawBuffer->_Xmax / fb_width * 2.0f - 1.0f;
|
|
|
|
const GLfloat y0 = (GLfloat) ctx->DrawBuffer->_Ymin / fb_height * 2.0f - 1.0f;
|
|
|
|
const GLfloat y1 = (GLfloat) ctx->DrawBuffer->_Ymax / fb_height * 2.0f - 1.0f;
|
2011-09-16 09:39:34 +01:00
|
|
|
union pipe_color_union clearColor;
|
2007-08-02 13:48:02 -06:00
|
|
|
|
2008-02-14 16:53:51 +00:00
|
|
|
/*
|
|
|
|
printf("%s %s%s%s %f,%f %f,%f\n", __FUNCTION__,
|
|
|
|
color ? "color, " : "",
|
|
|
|
depth ? "depth, " : "",
|
|
|
|
stencil ? "stencil" : "",
|
|
|
|
x0, y0,
|
|
|
|
x1, y1);
|
|
|
|
*/
|
2007-08-02 13:48:02 -06:00
|
|
|
|
2008-03-19 11:12:48 -06:00
|
|
|
cso_save_blend(st->cso_context);
|
2010-02-11 18:15:10 +01:00
|
|
|
cso_save_stencil_ref(st->cso_context);
|
2008-03-19 11:12:48 -06:00
|
|
|
cso_save_depth_stencil_alpha(st->cso_context);
|
|
|
|
cso_save_rasterizer(st->cso_context);
|
2012-07-24 11:17:29 +02:00
|
|
|
cso_save_sample_mask(st->cso_context);
|
2010-02-22 21:36:22 +01:00
|
|
|
cso_save_viewport(st->cso_context);
|
2008-04-21 17:51:39 +01:00
|
|
|
cso_save_fragment_shader(st->cso_context);
|
2011-12-09 18:33:58 +01:00
|
|
|
cso_save_stream_outputs(st->cso_context);
|
2008-04-21 17:51:39 +01:00
|
|
|
cso_save_vertex_shader(st->cso_context);
|
2011-11-04 18:10:16 +01:00
|
|
|
cso_save_geometry_shader(st->cso_context);
|
2010-03-09 15:09:01 +01:00
|
|
|
cso_save_vertex_elements(st->cso_context);
|
2012-03-29 17:51:50 +02:00
|
|
|
cso_save_aux_vertex_buffer_slot(st->cso_context);
|
2008-03-19 11:12:48 -06:00
|
|
|
|
2007-08-02 13:48:02 -06:00
|
|
|
/* blend state: RGBA masking */
|
2007-08-10 16:25:21 -06:00
|
|
|
{
|
|
|
|
struct pipe_blend_state blend;
|
|
|
|
memset(&blend, 0, sizeof(blend));
|
2010-01-20 18:26:49 +01:00
|
|
|
blend.rt[0].rgb_src_factor = PIPE_BLENDFACTOR_ONE;
|
|
|
|
blend.rt[0].alpha_src_factor = PIPE_BLENDFACTOR_ONE;
|
|
|
|
blend.rt[0].rgb_dst_factor = PIPE_BLENDFACTOR_ZERO;
|
|
|
|
blend.rt[0].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
|
2007-08-10 16:25:21 -06:00
|
|
|
if (color) {
|
2009-12-29 16:17:14 -07:00
|
|
|
if (ctx->Color.ColorMask[0][0])
|
2010-01-20 18:26:49 +01:00
|
|
|
blend.rt[0].colormask |= PIPE_MASK_R;
|
2009-12-29 16:17:14 -07:00
|
|
|
if (ctx->Color.ColorMask[0][1])
|
2010-01-20 18:26:49 +01:00
|
|
|
blend.rt[0].colormask |= PIPE_MASK_G;
|
2009-12-29 16:17:14 -07:00
|
|
|
if (ctx->Color.ColorMask[0][2])
|
2010-01-20 18:26:49 +01:00
|
|
|
blend.rt[0].colormask |= PIPE_MASK_B;
|
2009-12-29 16:17:14 -07:00
|
|
|
if (ctx->Color.ColorMask[0][3])
|
2010-01-20 18:26:49 +01:00
|
|
|
blend.rt[0].colormask |= PIPE_MASK_A;
|
2007-08-10 16:25:21 -06:00
|
|
|
if (st->ctx->Color.DitherFlag)
|
|
|
|
blend.dither = 1;
|
|
|
|
}
|
2008-03-11 18:54:31 -06:00
|
|
|
cso_set_blend(st->cso_context, &blend);
|
2007-08-02 13:48:02 -06:00
|
|
|
}
|
2007-08-02 10:29:42 -06:00
|
|
|
|
2007-09-17 11:55:18 -04:00
|
|
|
/* depth_stencil state: always pass/set to ref value */
|
2007-08-10 16:25:21 -06:00
|
|
|
{
|
2007-12-17 16:14:29 +00:00
|
|
|
struct pipe_depth_stencil_alpha_state depth_stencil;
|
2007-09-17 11:55:18 -04:00
|
|
|
memset(&depth_stencil, 0, sizeof(depth_stencil));
|
2007-08-10 16:25:21 -06:00
|
|
|
if (depth) {
|
2007-09-17 11:55:18 -04:00
|
|
|
depth_stencil.depth.enabled = 1;
|
|
|
|
depth_stencil.depth.writemask = 1;
|
|
|
|
depth_stencil.depth.func = PIPE_FUNC_ALWAYS;
|
2007-08-10 16:25:21 -06:00
|
|
|
}
|
2007-09-17 11:55:18 -04:00
|
|
|
|
|
|
|
if (stencil) {
|
2010-02-11 04:06:01 +01:00
|
|
|
struct pipe_stencil_ref stencil_ref;
|
|
|
|
memset(&stencil_ref, 0, sizeof(stencil_ref));
|
2007-12-17 16:14:29 +00:00
|
|
|
depth_stencil.stencil[0].enabled = 1;
|
|
|
|
depth_stencil.stencil[0].func = PIPE_FUNC_ALWAYS;
|
|
|
|
depth_stencil.stencil[0].fail_op = PIPE_STENCIL_OP_REPLACE;
|
|
|
|
depth_stencil.stencil[0].zpass_op = PIPE_STENCIL_OP_REPLACE;
|
|
|
|
depth_stencil.stencil[0].zfail_op = PIPE_STENCIL_OP_REPLACE;
|
2009-01-26 14:37:21 -05:00
|
|
|
depth_stencil.stencil[0].valuemask = 0xff;
|
|
|
|
depth_stencil.stencil[0].writemask = ctx->Stencil.WriteMask[0] & 0xff;
|
2010-02-10 21:14:18 +01:00
|
|
|
stencil_ref.ref_value[0] = ctx->Stencil.Clear;
|
|
|
|
cso_set_stencil_ref(st->cso_context, &stencil_ref);
|
2007-09-17 11:55:18 -04:00
|
|
|
}
|
2008-03-11 18:54:31 -06:00
|
|
|
|
|
|
|
cso_set_depth_stencil_alpha(st->cso_context, &depth_stencil);
|
2007-08-02 10:29:42 -06:00
|
|
|
}
|
|
|
|
|
2010-03-09 15:09:01 +01:00
|
|
|
cso_set_vertex_elements(st->cso_context, 2, st->velems_util_draw);
|
2011-12-09 18:33:58 +01:00
|
|
|
cso_set_stream_outputs(st->cso_context, 0, NULL, 0);
|
2012-07-24 11:17:29 +02:00
|
|
|
cso_set_sample_mask(st->cso_context, ~0);
|
2008-04-03 12:54:32 -06:00
|
|
|
cso_set_rasterizer(st->cso_context, &st->clear.raster);
|
2007-08-02 13:48:02 -06:00
|
|
|
|
2010-02-22 21:36:22 +01:00
|
|
|
/* viewport state: viewport matching window dims */
|
|
|
|
{
|
|
|
|
const GLboolean invert = (st_fb_orientation(fb) == Y_0_TOP);
|
|
|
|
struct pipe_viewport_state vp;
|
|
|
|
vp.scale[0] = 0.5f * fb_width;
|
|
|
|
vp.scale[1] = fb_height * (invert ? -0.5f : 0.5f);
|
|
|
|
vp.scale[2] = 1.0f;
|
|
|
|
vp.scale[3] = 1.0f;
|
|
|
|
vp.translate[0] = 0.5f * fb_width;
|
|
|
|
vp.translate[1] = 0.5f * fb_height;
|
|
|
|
vp.translate[2] = 0.0f;
|
|
|
|
vp.translate[3] = 0.0f;
|
|
|
|
cso_set_viewport(st->cso_context, &vp);
|
|
|
|
}
|
|
|
|
|
2011-03-05 13:27:00 +01:00
|
|
|
set_fragment_shader(st);
|
|
|
|
set_vertex_shader(st);
|
2011-11-04 18:10:16 +01:00
|
|
|
cso_set_geometry_shader_handle(st->cso_context, NULL);
|
2007-08-20 21:45:14 +01:00
|
|
|
|
2011-02-20 16:50:48 +01:00
|
|
|
if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
|
2012-10-15 03:55:23 +02:00
|
|
|
struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
|
|
|
|
GLboolean is_integer = _mesa_is_enum_format_integer(rb->InternalFormat);
|
|
|
|
|
|
|
|
st_translate_color(&ctx->Color.ClearColor,
|
|
|
|
&clearColor,
|
|
|
|
ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
|
|
|
|
is_integer);
|
2011-02-20 16:50:48 +01:00
|
|
|
}
|
2011-02-21 16:54:23 -07:00
|
|
|
|
|
|
|
/* draw quad matching scissor rect */
|
2011-09-16 09:39:34 +01:00
|
|
|
draw_quad(st, x0, y0, x1, y1, (GLfloat) ctx->Depth.Clear, &clearColor);
|
2007-08-02 13:59:31 +01:00
|
|
|
|
2007-08-02 16:08:18 -06:00
|
|
|
/* Restore pipe state */
|
2008-03-19 11:12:48 -06:00
|
|
|
cso_restore_blend(st->cso_context);
|
2010-02-11 18:15:10 +01:00
|
|
|
cso_restore_stencil_ref(st->cso_context);
|
2008-03-19 11:12:48 -06:00
|
|
|
cso_restore_depth_stencil_alpha(st->cso_context);
|
|
|
|
cso_restore_rasterizer(st->cso_context);
|
2012-07-24 11:17:29 +02:00
|
|
|
cso_restore_sample_mask(st->cso_context);
|
2010-02-22 21:36:22 +01:00
|
|
|
cso_restore_viewport(st->cso_context);
|
2008-04-21 17:51:39 +01:00
|
|
|
cso_restore_fragment_shader(st->cso_context);
|
|
|
|
cso_restore_vertex_shader(st->cso_context);
|
2011-11-04 18:10:16 +01:00
|
|
|
cso_restore_geometry_shader(st->cso_context);
|
2010-03-09 15:09:01 +01:00
|
|
|
cso_restore_vertex_elements(st->cso_context);
|
2012-03-29 17:51:50 +02:00
|
|
|
cso_restore_aux_vertex_buffer_slot(st->cso_context);
|
2011-12-09 18:33:58 +01:00
|
|
|
cso_restore_stream_outputs(st->cso_context);
|
2007-08-02 10:29:42 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-24 19:36:23 -06:00
|
|
|
/**
|
2013-01-14 06:57:28 +01:00
|
|
|
* Return if the scissor must be enabled during the clear.
|
2007-08-24 19:36:23 -06:00
|
|
|
*/
|
|
|
|
static INLINE GLboolean
|
2013-01-14 06:57:28 +01:00
|
|
|
is_scissor_enabled(struct gl_context *ctx, struct gl_renderbuffer *rb)
|
2008-02-14 16:53:51 +00:00
|
|
|
{
|
2013-01-14 06:57:28 +01:00
|
|
|
return ctx->Scissor.Enabled &&
|
|
|
|
(ctx->Scissor.X > 0 ||
|
|
|
|
ctx->Scissor.Y > 0 ||
|
|
|
|
ctx->Scissor.Width < rb->Width ||
|
|
|
|
ctx->Scissor.Height < rb->Height);
|
2007-08-24 19:36:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-14 06:57:28 +01:00
|
|
|
* Return if any of the color channels are masked.
|
2007-08-24 19:36:23 -06:00
|
|
|
*/
|
|
|
|
static INLINE GLboolean
|
2013-01-14 06:57:28 +01:00
|
|
|
is_color_masked(struct gl_context *ctx)
|
2007-08-24 19:36:23 -06:00
|
|
|
{
|
2013-01-14 06:57:28 +01:00
|
|
|
return !ctx->Color.ColorMask[0][0] ||
|
|
|
|
!ctx->Color.ColorMask[0][1] ||
|
|
|
|
!ctx->Color.ColorMask[0][2] ||
|
|
|
|
!ctx->Color.ColorMask[0][3];
|
2007-08-24 19:36:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2013-01-14 06:57:28 +01:00
|
|
|
* Return if any of the stencil bits are masked.
|
2007-08-24 19:36:23 -06:00
|
|
|
*/
|
|
|
|
static INLINE GLboolean
|
2013-01-14 06:57:28 +01:00
|
|
|
is_stencil_masked(struct gl_context *ctx, struct gl_renderbuffer *rb)
|
2007-08-24 19:36:23 -06:00
|
|
|
{
|
2009-10-08 20:27:27 -06:00
|
|
|
const GLuint stencilMax = 0xff;
|
2008-02-14 16:53:51 +00:00
|
|
|
|
2012-02-12 16:17:53 -07:00
|
|
|
assert(_mesa_get_format_bits(rb->Format, GL_STENCIL_BITS) > 0);
|
2013-01-14 06:57:28 +01:00
|
|
|
return (ctx->Stencil.WriteMask[0] & stencilMax) != stencilMax;
|
2007-08-24 19:36:23 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-08-02 10:29:42 -06:00
|
|
|
/**
|
|
|
|
* Called via ctx->Driver.Clear()
|
2007-08-02 13:59:31 +01:00
|
|
|
*/
|
2010-03-24 08:25:24 -06:00
|
|
|
static void
|
2010-10-12 12:26:10 -04:00
|
|
|
st_Clear(struct gl_context *ctx, GLbitfield mask)
|
2007-08-02 13:59:31 +01:00
|
|
|
{
|
2007-08-02 16:08:18 -06:00
|
|
|
static const GLbitfield BUFFER_BITS_DS
|
|
|
|
= (BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL);
|
2010-04-23 14:00:50 -06:00
|
|
|
struct st_context *st = st_context(ctx);
|
2007-08-02 16:08:18 -06:00
|
|
|
struct gl_renderbuffer *depthRb
|
|
|
|
= ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer;
|
|
|
|
struct gl_renderbuffer *stencilRb
|
|
|
|
= ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer;
|
2010-03-24 08:25:24 -06:00
|
|
|
GLbitfield quad_buffers = 0x0;
|
|
|
|
GLbitfield clear_buffers = 0x0;
|
2009-04-04 19:01:51 +02:00
|
|
|
GLuint i;
|
2007-08-02 13:59:31 +01:00
|
|
|
|
2009-04-04 19:01:51 +02:00
|
|
|
/* This makes sure the pipe has the latest scissor, etc values */
|
2007-08-02 13:59:31 +01:00
|
|
|
st_validate_state( st );
|
|
|
|
|
2009-04-04 19:01:51 +02:00
|
|
|
if (mask & BUFFER_BITS_COLOR) {
|
|
|
|
for (i = 0; i < ctx->DrawBuffer->_NumColorDrawBuffers; i++) {
|
|
|
|
GLuint b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
|
2007-08-02 16:08:18 -06:00
|
|
|
|
2009-04-04 19:01:51 +02:00
|
|
|
if (mask & (1 << b)) {
|
2007-08-13 16:16:42 -06:00
|
|
|
struct gl_renderbuffer *rb
|
|
|
|
= ctx->DrawBuffer->Attachment[b].Renderbuffer;
|
2011-01-03 13:57:13 -07:00
|
|
|
struct st_renderbuffer *strb = st_renderbuffer(rb);
|
2009-04-04 19:01:51 +02:00
|
|
|
|
2011-01-03 13:57:13 -07:00
|
|
|
if (!strb || !strb->surface)
|
2009-04-04 19:01:51 +02:00
|
|
|
continue;
|
|
|
|
|
2013-01-14 06:57:28 +01:00
|
|
|
if (is_scissor_enabled(ctx, rb) || is_color_masked(ctx))
|
2009-04-04 19:01:51 +02:00
|
|
|
quad_buffers |= PIPE_CLEAR_COLOR;
|
|
|
|
else
|
|
|
|
clear_buffers |= PIPE_CLEAR_COLOR;
|
2007-08-02 16:08:18 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-08-02 18:25:10 +01:00
|
|
|
|
2007-08-02 16:08:18 -06:00
|
|
|
if ((mask & BUFFER_BITS_DS) == BUFFER_BITS_DS && depthRb == stencilRb) {
|
|
|
|
/* clearing combined depth + stencil */
|
2009-04-04 19:01:51 +02:00
|
|
|
struct st_renderbuffer *strb = st_renderbuffer(depthRb);
|
|
|
|
|
|
|
|
if (strb->surface) {
|
2013-01-14 06:57:28 +01:00
|
|
|
if (is_scissor_enabled(ctx, depthRb) ||
|
|
|
|
is_stencil_masked(ctx, depthRb))
|
2009-04-04 19:01:51 +02:00
|
|
|
quad_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
|
|
|
|
else
|
|
|
|
clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
|
|
|
|
}
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|
|
|
|
else {
|
2007-08-02 16:08:18 -06:00
|
|
|
/* separate depth/stencil clears */
|
2010-05-29 00:04:14 +02:00
|
|
|
/* I don't think truly separate buffers are actually possible in gallium or hw? */
|
2007-08-02 16:08:18 -06:00
|
|
|
if (mask & BUFFER_BIT_DEPTH) {
|
2009-04-04 19:01:51 +02:00
|
|
|
struct st_renderbuffer *strb = st_renderbuffer(depthRb);
|
|
|
|
|
|
|
|
if (strb->surface) {
|
2013-01-14 06:57:28 +01:00
|
|
|
if (is_scissor_enabled(ctx, depthRb))
|
2010-05-29 00:04:14 +02:00
|
|
|
quad_buffers |= PIPE_CLEAR_DEPTH;
|
2009-04-04 19:01:51 +02:00
|
|
|
else
|
2010-05-29 00:04:14 +02:00
|
|
|
clear_buffers |= PIPE_CLEAR_DEPTH;
|
2009-04-04 19:01:51 +02:00
|
|
|
}
|
2007-08-02 16:08:18 -06:00
|
|
|
}
|
|
|
|
if (mask & BUFFER_BIT_STENCIL) {
|
2009-04-04 19:01:51 +02:00
|
|
|
struct st_renderbuffer *strb = st_renderbuffer(stencilRb);
|
|
|
|
|
|
|
|
if (strb->surface) {
|
2013-01-14 06:57:28 +01:00
|
|
|
if (is_scissor_enabled(ctx, stencilRb) ||
|
|
|
|
is_stencil_masked(ctx, stencilRb))
|
2010-05-29 00:04:14 +02:00
|
|
|
quad_buffers |= PIPE_CLEAR_STENCIL;
|
2009-04-04 19:01:51 +02:00
|
|
|
else
|
2010-05-29 00:04:14 +02:00
|
|
|
clear_buffers |= PIPE_CLEAR_STENCIL;
|
2009-04-04 19:01:51 +02:00
|
|
|
}
|
2007-08-02 16:08:18 -06:00
|
|
|
}
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|
2009-04-04 19:01:51 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If we're going to use clear_with_quad() for any reason, use it for
|
|
|
|
* everything possible.
|
|
|
|
*/
|
|
|
|
if (quad_buffers) {
|
|
|
|
quad_buffers |= clear_buffers;
|
|
|
|
clear_with_quad(ctx,
|
|
|
|
quad_buffers & PIPE_CLEAR_COLOR,
|
2010-05-29 00:04:14 +02:00
|
|
|
quad_buffers & PIPE_CLEAR_DEPTH,
|
|
|
|
quad_buffers & PIPE_CLEAR_STENCIL);
|
|
|
|
} else if (clear_buffers) {
|
|
|
|
/* driver cannot know it can clear everything if the buffer
|
|
|
|
* is a combined depth/stencil buffer but this wasn't actually
|
|
|
|
* required from the visual. Hence fix this up to avoid potential
|
|
|
|
* read-modify-write in the driver.
|
|
|
|
*/
|
2011-09-16 09:39:34 +01:00
|
|
|
union pipe_color_union clearColor;
|
2011-02-21 16:54:23 -07:00
|
|
|
|
2010-06-05 16:44:31 +02:00
|
|
|
if ((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) &&
|
|
|
|
((clear_buffers & PIPE_CLEAR_DEPTHSTENCIL) != PIPE_CLEAR_DEPTHSTENCIL) &&
|
2010-05-29 00:04:14 +02:00
|
|
|
(depthRb == stencilRb) &&
|
|
|
|
(ctx->DrawBuffer->Visual.depthBits == 0 ||
|
|
|
|
ctx->DrawBuffer->Visual.stencilBits == 0))
|
|
|
|
clear_buffers |= PIPE_CLEAR_DEPTHSTENCIL;
|
2011-02-21 16:54:23 -07:00
|
|
|
|
2011-02-20 16:50:48 +01:00
|
|
|
if (ctx->DrawBuffer->_ColorDrawBuffers[0]) {
|
2012-10-15 03:55:23 +02:00
|
|
|
struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0];
|
|
|
|
GLboolean is_integer = _mesa_is_enum_format_integer(rb->InternalFormat);
|
|
|
|
|
|
|
|
st_translate_color(&ctx->Color.ClearColor,
|
|
|
|
&clearColor,
|
2011-09-12 10:57:40 +01:00
|
|
|
ctx->DrawBuffer->_ColorDrawBuffers[0]->_BaseFormat,
|
2012-10-15 03:55:23 +02:00
|
|
|
is_integer);
|
2011-02-20 16:50:48 +01:00
|
|
|
}
|
2011-02-21 16:54:23 -07:00
|
|
|
|
2011-09-16 09:39:34 +01:00
|
|
|
st->pipe->clear(st->pipe, clear_buffers, &clearColor,
|
2010-04-23 14:00:50 -06:00
|
|
|
ctx->Depth.Clear, ctx->Stencil.Clear);
|
2010-05-29 00:04:14 +02:00
|
|
|
}
|
2009-04-04 19:01:51 +02:00
|
|
|
if (mask & BUFFER_BIT_ACCUM)
|
2011-12-03 10:04:18 -07:00
|
|
|
_mesa_clear_accum_buffer(ctx);
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-24 08:25:24 -06:00
|
|
|
void
|
|
|
|
st_init_clear_functions(struct dd_function_table *functions)
|
2007-08-02 13:59:31 +01:00
|
|
|
{
|
2010-03-24 08:18:13 -06:00
|
|
|
functions->Clear = st_Clear;
|
2007-08-02 13:59:31 +01:00
|
|
|
}
|