summaryrefslogtreecommitdiff
path: root/src/mesa/drivers/dri/intel/intel_clear.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/drivers/dri/intel/intel_clear.c')
-rw-r--r--src/mesa/drivers/dri/intel/intel_clear.c108
1 files changed, 77 insertions, 31 deletions
diff --git a/src/mesa/drivers/dri/intel/intel_clear.c b/src/mesa/drivers/dri/intel/intel_clear.c
index 28281b3861..309ac1923b 100644
--- a/src/mesa/drivers/dri/intel/intel_clear.c
+++ b/src/mesa/drivers/dri/intel/intel_clear.c
@@ -30,6 +30,7 @@
#include "main/enums.h"
#include "main/image.h"
#include "main/mtypes.h"
+#include "main/arrayobj.h"
#include "main/attrib.h"
#include "main/blend.h"
#include "main/bufferobj.h"
@@ -38,6 +39,7 @@
#include "main/enable.h"
#include "main/macros.h"
#include "main/matrix.h"
+#include "main/polygon.h"
#include "main/texstate.h"
#include "main/shaders.h"
#include "main/stencil.h"
@@ -51,6 +53,7 @@
#include "intel_clear.h"
#include "intel_fbo.h"
#include "intel_pixel.h"
+#include "intel_regions.h"
#define FILE_DEBUG_FLAG DEBUG_BLIT
@@ -65,6 +68,45 @@
BUFFER_BIT_COLOR6 | \
BUFFER_BIT_COLOR7)
+
+/**
+ * Per-context one-time init of things for intl_clear_tris().
+ * Basically set up a private array object for vertex/color arrays.
+ */
+static void
+init_clear(GLcontext *ctx)
+{
+ struct intel_context *intel = intel_context(ctx);
+ struct gl_array_object *arraySave = NULL;
+ const GLuint arrayBuffer = ctx->Array.ArrayBufferObj->Name;
+ const GLuint elementBuffer = ctx->Array.ElementArrayBufferObj->Name;
+
+ /* create new array object */
+ intel->clear.arrayObj = _mesa_new_array_object(ctx, ~0);
+
+ /* save current array object, bind new one */
+ _mesa_reference_array_object(ctx, &arraySave, ctx->Array.ArrayObj);
+ _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, intel->clear.arrayObj);
+
+ /* one-time setup of vertex arrays (pos, color) */
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
+ _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
+ _mesa_ColorPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), intel->clear.color);
+ _mesa_VertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), intel->clear.vertices);
+ _mesa_Enable(GL_COLOR_ARRAY);
+ _mesa_Enable(GL_VERTEX_ARRAY);
+
+ /* restore original array object */
+ _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, arraySave);
+ _mesa_reference_array_object(ctx, &arraySave, NULL);
+
+ /* restore original buffer objects */
+ _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB, arrayBuffer);
+ _mesa_BindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, elementBuffer);
+}
+
+
+
/**
* Perform glClear where mask contains only color, depth, and/or stencil.
*
@@ -77,14 +119,16 @@ void
intel_clear_tris(GLcontext *ctx, GLbitfield mask)
{
struct intel_context *intel = intel_context(ctx);
- GLfloat vertices[4][3];
- GLfloat color[4][4];
GLfloat dst_z;
struct gl_framebuffer *fb = ctx->DrawBuffer;
int i;
GLboolean saved_fp_enable = GL_FALSE, saved_vp_enable = GL_FALSE;
GLuint saved_shader_program = 0;
unsigned int saved_active_texture;
+ struct gl_array_object *arraySave = NULL;
+
+ if (!intel->clear.arrayObj)
+ init_clear(ctx);
assert((mask & ~(TRI_CLEAR_COLOR_BITS | BUFFER_BIT_DEPTH |
BUFFER_BIT_STENCIL)) == 0);
@@ -93,10 +137,10 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
GL_CURRENT_BIT |
GL_DEPTH_BUFFER_BIT |
GL_ENABLE_BIT |
+ GL_POLYGON_BIT |
GL_STENCIL_BUFFER_BIT |
GL_TRANSFORM_BIT |
GL_CURRENT_BIT);
- _mesa_PushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
saved_active_texture = ctx->Texture.CurrentUnit;
/* Disable existing GL state we don't want to apply to a clear. */
@@ -114,6 +158,7 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
_mesa_Disable(GL_CLIP_PLANE3);
_mesa_Disable(GL_CLIP_PLANE4);
_mesa_Disable(GL_CLIP_PLANE5);
+ _mesa_PolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (ctx->Extensions.ARB_fragment_program && ctx->FragmentProgram.Enabled) {
saved_fp_enable = GL_TRUE;
_mesa_Disable(GL_FRAGMENT_PROGRAM_ARB);
@@ -146,13 +191,14 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
}
}
+ /* save current array object, bind our private one */
+ _mesa_reference_array_object(ctx, &arraySave, ctx->Array.ArrayObj);
+ _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, intel->clear.arrayObj);
+
intel_meta_set_passthrough_transform(intel);
for (i = 0; i < 4; i++) {
- color[i][0] = ctx->Color.ClearColor[0];
- color[i][1] = ctx->Color.ClearColor[1];
- color[i][2] = ctx->Color.ClearColor[2];
- color[i][3] = ctx->Color.ClearColor[3];
+ COPY_4FV(intel->clear.color[i], ctx->Color.ClearColor);
}
/* convert clear Z from [0,1] to NDC coord in [-1,1] */
@@ -161,23 +207,18 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
/* Prepare the vertices, which are the same regardless of which buffer we're
* drawing to.
*/
- vertices[0][0] = fb->_Xmin;
- vertices[0][1] = fb->_Ymin;
- vertices[0][2] = dst_z;
- vertices[1][0] = fb->_Xmax;
- vertices[1][1] = fb->_Ymin;
- vertices[1][2] = dst_z;
- vertices[2][0] = fb->_Xmax;
- vertices[2][1] = fb->_Ymax;
- vertices[2][2] = dst_z;
- vertices[3][0] = fb->_Xmin;
- vertices[3][1] = fb->_Ymax;
- vertices[3][2] = dst_z;
-
- _mesa_ColorPointer(4, GL_FLOAT, 4 * sizeof(GLfloat), &color);
- _mesa_VertexPointer(3, GL_FLOAT, 3 * sizeof(GLfloat), &vertices);
- _mesa_Enable(GL_COLOR_ARRAY);
- _mesa_Enable(GL_VERTEX_ARRAY);
+ intel->clear.vertices[0][0] = fb->_Xmin;
+ intel->clear.vertices[0][1] = fb->_Ymin;
+ intel->clear.vertices[0][2] = dst_z;
+ intel->clear.vertices[1][0] = fb->_Xmax;
+ intel->clear.vertices[1][1] = fb->_Ymin;
+ intel->clear.vertices[1][2] = dst_z;
+ intel->clear.vertices[2][0] = fb->_Xmax;
+ intel->clear.vertices[2][1] = fb->_Ymax;
+ intel->clear.vertices[2][2] = dst_z;
+ intel->clear.vertices[3][0] = fb->_Xmin;
+ intel->clear.vertices[3][1] = fb->_Ymax;
+ intel->clear.vertices[3][2] = dst_z;
while (mask != 0) {
GLuint this_mask = 0;
@@ -215,8 +256,10 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
/* Control writing of the stencil clear value to stencil. */
if (this_mask & BUFFER_BIT_STENCIL) {
_mesa_Enable(GL_STENCIL_TEST);
- _mesa_StencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
- _mesa_StencilFuncSeparate(GL_FRONT, GL_ALWAYS, ctx->Stencil.Clear,
+ _mesa_StencilOpSeparate(GL_FRONT_AND_BACK,
+ GL_REPLACE, GL_REPLACE, GL_REPLACE);
+ _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS,
+ ctx->Stencil.Clear,
ctx->Stencil.WriteMask[0]);
} else {
_mesa_Disable(GL_STENCIL_TEST);
@@ -238,8 +281,11 @@ intel_clear_tris(GLcontext *ctx, GLbitfield mask)
if (saved_shader_program)
_mesa_UseProgramObjectARB(saved_shader_program);
- _mesa_PopClientAttrib();
_mesa_PopAttrib();
+
+ /* restore current array object */
+ _mesa_reference_array_object(ctx, &ctx->Array.ArrayObj, arraySave);
+ _mesa_reference_array_object(ctx, &arraySave, NULL);
}
static const char *buffer_names[] = {
@@ -267,7 +313,6 @@ static const char *buffer_names[] = {
static void
intelClear(GLcontext *ctx, GLbitfield mask)
{
- struct intel_context *intel = intel_context(ctx);
const GLuint colorMask = *((GLuint *) & ctx->Color.ColorMask);
GLbitfield tri_mask = 0;
GLbitfield blit_mask = 0;
@@ -295,7 +340,7 @@ intelClear(GLcontext *ctx, GLbitfield mask)
= intel_get_rb_region(fb, BUFFER_STENCIL);
if (stencilRegion) {
/* have hw stencil */
- if (IS_965(intel->intelScreen->deviceID) ||
+ if (stencilRegion->tiling == I915_TILING_Y ||
(ctx->Stencil.WriteMask[0] & 0xff) != 0xff) {
/* We have to use the 3D engine if we're clearing a partial mask
* of the stencil buffer, or if we're on a 965 which has a tiled
@@ -312,9 +357,10 @@ intelClear(GLcontext *ctx, GLbitfield mask)
/* HW depth */
if (mask & BUFFER_BIT_DEPTH) {
+ const struct intel_region *irb = intel_get_rb_region(fb, BUFFER_DEPTH);
+
/* clear depth with whatever method is used for stencil (see above) */
- if (IS_965(intel->intelScreen->deviceID) ||
- tri_mask & BUFFER_BIT_STENCIL)
+ if (irb->tiling == I915_TILING_Y || tri_mask & BUFFER_BIT_STENCIL)
tri_mask |= BUFFER_BIT_DEPTH;
else
blit_mask |= BUFFER_BIT_DEPTH;