summaryrefslogtreecommitdiffstats
path: root/src/mesa/drivers/dri/i965/brw_metaops.c
blob: 005489689f1b6fd8b0f4ef14763ad12cc03babd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/*
 Copyright (C) Intel Corp.  2006.  All Rights Reserved.
 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
 develop this 3D driver.
 
 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, sublicense, 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 NONINFRINGEMENT.
 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) 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>
  *   frame buffer texture by Gary Wong <gtw@gnu.org>
  */
 


#include "glheader.h"
#include "context.h"
#include "macros.h"

#include "shader/arbprogparse.h"

#include "intel_screen.h"
#include "intel_batchbuffer.h"
#include "intel_regions.h"

#include "brw_context.h"
#include "brw_defines.h"
#include "brw_draw.h"
#include "brw_fallback.h"

#define INIT(brw, STRUCT, ATTRIB) 		\
do {						\
   brw->attribs.ATTRIB = &ctx->ATTRIB;		\
} while (0)

#define DUP(brw, STRUCT, ATTRIB) 		\
do {						\
   brw->metaops.attribs.ATTRIB = MALLOC_STRUCT(STRUCT);	\
   memcpy(brw->metaops.attribs.ATTRIB, 			\
	  brw->attribs.ATTRIB,			\
	  sizeof(struct STRUCT));		\
} while (0)


#define INSTALL(brw, ATTRIB, STATE)		\
do {						\
   brw->attribs.ATTRIB = brw->metaops.attribs.ATTRIB;	\
   brw->state.dirty.mesa |= STATE;		\
} while (0)

#define RESTORE(brw, ATTRIB, STATE)			\
do {							\
   brw->attribs.ATTRIB = &brw->intel.ctx.ATTRIB;	\
   brw->state.dirty.mesa |= STATE;			\
} while (0)

static void init_attribs( struct brw_context *brw )
{
   DUP(brw, gl_colorbuffer_attrib, Color);
   DUP(brw, gl_depthbuffer_attrib, Depth);
   DUP(brw, gl_fog_attrib, Fog);
   DUP(brw, gl_hint_attrib, Hint);
   DUP(brw, gl_light_attrib, Light);
   DUP(brw, gl_line_attrib, Line);
   DUP(brw, gl_point_attrib, Point);
   DUP(brw, gl_polygon_attrib, Polygon);
   DUP(brw, gl_scissor_attrib, Scissor);
   DUP(brw, gl_stencil_attrib, Stencil);
   DUP(brw, gl_texture_attrib, Texture);
   DUP(brw, gl_transform_attrib, Transform);
   DUP(brw, gl_viewport_attrib, Viewport);
   DUP(brw, gl_vertex_program_state, VertexProgram);
   DUP(brw, gl_fragment_program_state, FragmentProgram);
}

static void install_attribs( struct brw_context *brw )
{
   INSTALL(brw, Color, _NEW_COLOR);
   INSTALL(brw, Depth, _NEW_DEPTH);
   INSTALL(brw, Fog, _NEW_FOG);
   INSTALL(brw, Hint, _NEW_HINT);
   INSTALL(brw, Light, _NEW_LIGHT);
   INSTALL(brw, Line, _NEW_LINE);
   INSTALL(brw, Point, _NEW_POINT);
   INSTALL(brw, Polygon, _NEW_POLYGON);
   INSTALL(brw, Scissor, _NEW_SCISSOR);
   INSTALL(brw, Stencil, _NEW_STENCIL);
   INSTALL(brw, Texture, _NEW_TEXTURE);
   INSTALL(brw, Transform, _NEW_TRANSFORM);
   INSTALL(brw, Viewport, _NEW_VIEWPORT);
   INSTALL(brw, VertexProgram, _NEW_PROGRAM);
   INSTALL(brw, FragmentProgram, _NEW_PROGRAM);
}

static void restore_attribs( struct brw_context *brw )
{
   RESTORE(brw, Color, _NEW_COLOR);
   RESTORE(brw, Depth, _NEW_DEPTH);
   RESTORE(brw, Fog, _NEW_FOG);
   RESTORE(brw, Hint, _NEW_HINT);
   RESTORE(brw, Light, _NEW_LIGHT);
   RESTORE(brw, Line, _NEW_LINE);
   RESTORE(brw, Point, _NEW_POINT);
   RESTORE(brw, Polygon, _NEW_POLYGON);
   RESTORE(brw, Scissor, _NEW_SCISSOR);
   RESTORE(brw, Stencil, _NEW_STENCIL);
   RESTORE(brw, Texture, _NEW_TEXTURE);
   RESTORE(brw, Transform, _NEW_TRANSFORM);
   RESTORE(brw, Viewport, _NEW_VIEWPORT);
   RESTORE(brw, VertexProgram, _NEW_PROGRAM);
   RESTORE(brw, FragmentProgram, _NEW_PROGRAM);
}


static const char *vp_prog =
      "!!ARBvp1.0\n"
      "MOV  result.color, vertex.color;\n"
      "MOV  result.position, vertex.position;\n"
      "END\n";

static const char *fp_prog =
      "!!ARBfp1.0\n"
      "MOV result.color, fragment.color;\n"
      "END\n";

static const char *fp_tex_prog =
      "!!ARBfp1.0\n"
      "TEMP a;\n"
      "ADD a, fragment.position, program.local[0];\n"
      "MUL a, a, program.local[1];\n"
      "TEX result.color, a, texture[0], 2D;\n"
      "MOV result.depth.z, fragment.position;\n"
      "END\n";

/* Derived values of importance:
 *
 *   FragmentProgram->_Current
 *   VertexProgram->_Enabled
 *   brw->vertex_program
 *   DrawBuffer->_ColorDrawBufferIndexes[0]
 * 
 *
 * More if drawpixels-through-texture is added.  
 */
static void init_metaops_state( struct brw_context *brw )
{
   GLcontext *ctx = &brw->intel.ctx;

   brw->metaops.vbo = ctx->Driver.NewBufferObject(ctx, 1, GL_ARRAY_BUFFER_ARB);

   ctx->Driver.BufferData(ctx,
			  GL_ARRAY_BUFFER_ARB,
			  4096,
			  NULL,
			  GL_DYNAMIC_DRAW_ARB,
			  brw->metaops.vbo);

   brw->metaops.fp = (struct gl_fragment_program *)
      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 1 );

   brw->metaops.fp_tex = (struct gl_fragment_program *)
      ctx->Driver.NewProgram(ctx, GL_FRAGMENT_PROGRAM_ARB, 1 );

   brw->metaops.vp = (struct gl_vertex_program *)
      ctx->Driver.NewProgram(ctx, GL_VERTEX_PROGRAM_ARB, 1 );

   _mesa_parse_arb_fragment_program(ctx, GL_FRAGMENT_PROGRAM_ARB, 
				    fp_prog, strlen(fp_prog),
				    brw->metaops.fp);

   _mesa_parse_arb_fragment_program(ctx, GL_FRAGMENT_PROGRAM_ARB, 
				    fp_tex_prog, strlen(fp_tex_prog),
				    brw->metaops.fp_tex);

   _mesa_parse_arb_vertex_program(ctx, GL_VERTEX_PROGRAM_ARB, 
				  vp_prog, strlen(vp_prog),
				  brw->metaops.vp);

   brw->metaops.attribs.VertexProgram->Current = brw->metaops.vp;
   brw->metaops.attribs.VertexProgram->_Enabled = GL_TRUE;

   brw->metaops.attribs.FragmentProgram->_Current = brw->metaops.fp;
}

static void meta_flat_shade( struct intel_context *intel )
{
   struct brw_context *brw = brw_context(&intel->ctx);

   brw->metaops.attribs.Light->ShadeModel = GL_FLAT;
   brw->state.dirty.mesa |= _NEW_LIGHT;
}


static void meta_no_stencil_write( struct intel_context *intel )
{
   struct brw_context *brw = brw_context(&intel->ctx);

   brw->metaops.attribs.Stencil->Enabled = GL_FALSE;
   brw->metaops.attribs.Stencil->WriteMask[0] = GL_FALSE; 
   brw->state.dirty.mesa |= _NEW_STENCIL;
}

static void meta_no_depth_write( struct intel_context *intel )
{
   struct brw_context *brw = brw_context(&intel->ctx);

   brw->metaops.attribs.Depth->Test = GL_FALSE;
   brw->metaops.attribs.Depth->Mask = GL_FALSE;
   brw->state.dirty.mesa |= _NEW_DEPTH;
}


static void meta_depth_replace( struct intel_context *intel )
{
   struct brw_context *brw = brw_context(&intel->ctx);

   /* ctx->Driver.Enable( ctx, GL_DEPTH_TEST, GL_TRUE )
    * ctx->Driver.DepthMask( ctx, GL_TRUE )
    */
   brw->metaops.attribs.Depth->Test = GL_TRUE;
   brw->metaops.attribs.Depth->Mask = GL_TRUE;
   brw->state.dirty.mesa |= _NEW_DEPTH;

   /* ctx->Driver.DepthFunc( ctx, GL_ALWAYS )
    */
   brw->metaops.attribs.Depth->Func = GL_ALWAYS;

   brw->state.dirty.mesa |= _NEW_DEPTH;
}


static void meta_stencil_replace( struct intel_context *intel,
				 GLuint s_mask,
				 GLuint s_clear)
{
   struct brw_context *brw = brw_context(&intel->ctx);

   brw->metaops.attribs.Stencil->Enabled = GL_TRUE;
   brw->metaops.attribs.Stencil->WriteMask[0] = s_mask;
   brw->metaops.attribs.Stencil->ValueMask[0] = 0xff;
   brw->metaops.attribs.Stencil->Ref[0] = s_clear;
   brw->metaops.attribs.Stencil->Function[0] = GL_ALWAYS;
   brw->metaops.attribs.Stencil->FailFunc[0] = GL_REPLACE;
   brw->metaops.attribs.Stencil->ZPassFunc[0] = GL_REPLACE;
   brw->metaops.attribs.Stencil->ZFailFunc[0] = GL_REPLACE;
   brw->state.dirty.mesa |= _NEW_STENCIL;
}


static void meta_color_mask( struct intel_context *intel, GLboolean state )
{
   struct brw_context *brw = brw_context(&intel->ctx);

   if (state)
      COPY_4V(brw->metaops.attribs.Color->ColorMask, 
	      brw->intel.ctx.Color.ColorMask); 
   else
      ASSIGN_4V(brw->metaops.attribs.Color->ColorMask, 0, 0, 0, 0);

   brw->state.dirty.mesa |= _NEW_COLOR;
}

static void meta_no_texture( struct intel_context *intel )
{
   struct brw_context *brw = brw_context(&intel->ctx);
   
   brw->metaops.attribs.FragmentProgram->_Current = brw->metaops.fp;
   
   brw->metaops.attribs.Texture->CurrentUnit = 0;
   brw->metaops.attribs.Texture->_EnabledUnits = 0;
   brw->metaops.attribs.Texture->_EnabledCoordUnits = 0;
   brw->metaops.attribs.Texture->Unit[ 0 ].Enabled = 0;
   brw->metaops.attribs.Texture->Unit[ 0 ]._ReallyEnabled = 0;

   brw->state.dirty.mesa |= _NEW_TEXTURE | _NEW_PROGRAM;
}

static void meta_texture_blend_replace(struct intel_context *intel)
{
   struct brw_context *brw = brw_context(&intel->ctx);

   brw->metaops.attribs.Texture->CurrentUnit = 0;
   brw->metaops.attribs.Texture->_EnabledUnits = 1;
   brw->metaops.attribs.Texture->_EnabledCoordUnits = 1;
   brw->metaops.attribs.Texture->Unit[ 0 ].Enabled = TEXTURE_2D_BIT;
   brw->metaops.attribs.Texture->Unit[ 0 ]._ReallyEnabled = TEXTURE_2D_BIT;
   brw->metaops.attribs.Texture->Unit[ 0 ].Current2D =
      intel->frame_buffer_texobj;
   brw->metaops.attribs.Texture->Unit[ 0 ]._Current =
      intel->frame_buffer_texobj;

   brw->state.dirty.mesa |= _NEW_TEXTURE | _NEW_PROGRAM;
}

static void meta_import_pixel_state(struct intel_context *intel)
{
   struct brw_context *brw = brw_context(&intel->ctx);
   
   RESTORE(brw, Color, _NEW_COLOR);
   RESTORE(brw, Depth, _NEW_DEPTH);
   RESTORE(brw, Fog, _NEW_FOG);
   RESTORE(brw, Scissor, _NEW_SCISSOR);
   RESTORE(brw, Stencil, _NEW_STENCIL);
   RESTORE(brw, Texture, _NEW_TEXTURE);
   RESTORE(brw, FragmentProgram, _NEW_PROGRAM);
}

static void meta_frame_buffer_texture( struct intel_context *intel,
				       GLint xoff, GLint yoff )
{
   struct brw_context *brw = brw_context(&intel->ctx);
   struct intel_region *region = intel_drawbuf_region( intel );
   
   INSTALL(brw, FragmentProgram, _NEW_PROGRAM);

   brw->metaops.attribs.FragmentProgram->_Current = brw->metaops.fp_tex;
   /* This is unfortunate, but seems to be necessary, since later on we
      will end up calling _mesa_load_state_parameters to lookup the
      local params (below), and that will want to look in ctx.FragmentProgram
      instead of brw->attribs.FragmentProgram. */
   intel->ctx.FragmentProgram.Current = brw->metaops.fp_tex;

   brw->metaops.fp_tex->Base.LocalParams[ 0 ][ 0 ] = xoff;
   brw->metaops.fp_tex->Base.LocalParams[ 0 ][ 1 ] = yoff;
   brw->metaops.fp_tex->Base.LocalParams[ 0 ][ 2 ] = 0.0;
   brw->metaops.fp_tex->Base.LocalParams[ 0 ][ 3 ] = 0.0;
   brw->metaops.fp_tex->Base.LocalParams[ 1 ][ 0 ] =
      1.0 / region->pitch;
   brw->metaops.fp_tex->Base.LocalParams[ 1 ][ 1 ] =
      -1.0 / region->height;
   brw->metaops.fp_tex->Base.LocalParams[ 1 ][ 2 ] = 0.0;
   brw->metaops.fp_tex->Base.LocalParams[ 1 ][ 3 ] = 1.0;
   
   brw->state.dirty.mesa |= _NEW_PROGRAM;
}


static void meta_draw_region( struct intel_context *intel,
			     struct intel_region *draw_region,
			     struct intel_region *depth_region )
{
   struct brw_context *brw = brw_context(&intel->ctx);

   if (!brw->metaops.saved_draw_region) {
      brw->metaops.saved_draw_region = brw->state.draw_region;
      brw->metaops.saved_depth_region = brw->state.depth_region;
   }

   brw->state.draw_region = draw_region;
   brw->state.depth_region = depth_region;

   brw->state.dirty.mesa |= _NEW_BUFFERS;
}


static void meta_draw_quad(struct intel_context *intel, 
			   GLfloat x0, GLfloat x1,
			   GLfloat y0, GLfloat y1, 
			   GLfloat z,
			   GLuint color,
			   GLfloat s0, GLfloat s1,
			   GLfloat t0, GLfloat t1)
{
   GLcontext *ctx = &intel->ctx;
   struct brw_context *brw = brw_context(&intel->ctx);
   struct gl_client_array pos_array;
   struct gl_client_array color_array;
   struct gl_client_array *attribs[VERT_ATTRIB_MAX];
   struct _mesa_prim prim[1];
   GLfloat pos[4][3];

   ctx->Driver.BufferData(ctx,
			  GL_ARRAY_BUFFER_ARB,
			  sizeof(pos) + sizeof(color),
			  NULL,
			  GL_DYNAMIC_DRAW_ARB,
			  brw->metaops.vbo);

   pos[0][0] = x0;
   pos[0][1] = y0;
   pos[0][2] = z;

   pos[1][0] = x1;
   pos[1][1] = y0;
   pos[1][2] = z;

   pos[2][0] = x1;
   pos[2][1] = y1;
   pos[2][2] = z;

   pos[3][0] = x0;
   pos[3][1] = y1;
   pos[3][2] = z;

   ctx->Driver.BufferSubData(ctx,
			     GL_ARRAY_BUFFER_ARB,
			     0,
			     sizeof(pos),
			     pos,
			     brw->metaops.vbo);

   /* Convert incoming ARGB to required RGBA */
   color = (color >> 24) | (color << 8);

   ctx->Driver.BufferSubData(ctx,
			     GL_ARRAY_BUFFER_ARB,
			     sizeof(pos),
			     sizeof(color),
			     &color,
			     brw->metaops.vbo);

   /* Ignoring texture coords. 
    */

   memset(attribs, 0, VERT_ATTRIB_MAX * sizeof(*attribs));

   attribs[VERT_ATTRIB_POS] = &pos_array;
   attribs[VERT_ATTRIB_POS]->Ptr = 0;
   attribs[VERT_ATTRIB_POS]->Type = GL_FLOAT;
   attribs[VERT_ATTRIB_POS]->Enabled = 1;
   attribs[VERT_ATTRIB_POS]->Size = 3;
   attribs[VERT_ATTRIB_POS]->StrideB = 3 * sizeof(GLfloat);
   attribs[VERT_ATTRIB_POS]->Stride = 3 * sizeof(GLfloat);
   attribs[VERT_ATTRIB_POS]->_MaxElement = 4;
   attribs[VERT_ATTRIB_POS]->Normalized = 0;
   attribs[VERT_ATTRIB_POS]->BufferObj = brw->metaops.vbo;

   attribs[VERT_ATTRIB_COLOR0] = &color_array;
   attribs[VERT_ATTRIB_COLOR0]->Ptr = (const GLubyte *)sizeof(pos);
   attribs[VERT_ATTRIB_COLOR0]->Type = GL_UNSIGNED_BYTE;
   attribs[VERT_ATTRIB_COLOR0]->Enabled = 1;
   attribs[VERT_ATTRIB_COLOR0]->Size = 4;
   attribs[VERT_ATTRIB_COLOR0]->StrideB = 0;
   attribs[VERT_ATTRIB_COLOR0]->Stride = 0;
   attribs[VERT_ATTRIB_COLOR0]->_MaxElement = 1;
   attribs[VERT_ATTRIB_COLOR0]->Normalized = 1;
   attribs[VERT_ATTRIB_COLOR0]->BufferObj = brw->metaops.vbo;
   
   /* Just ignoring texture coordinates for now. 
    */

   memset(prim, 0, sizeof(*prim));

   prim[0].mode = GL_TRIANGLE_FAN;
   prim[0].begin = 1;
   prim[0].end = 1;
   prim[0].weak = 0;
   prim[0].pad = 0;
   prim[0].start = 0;
   prim[0].count = 4;

   brw_draw_prims(&brw->intel.ctx, 
		  (const struct gl_client_array **)attribs,
		  prim, 1,
		  NULL,
		  0,
		  3 );
}


static void install_meta_state( struct intel_context *intel )
{
   GLcontext *ctx = &intel->ctx;
   struct brw_context *brw = brw_context(ctx);
   GLuint i;

   if (!brw->metaops.vbo) {
      init_metaops_state(brw);
   }

   install_attribs(brw);
   
   meta_no_texture(&brw->intel);
   meta_flat_shade(&brw->intel);
   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
      brw->metaops.restore_draw_buffers[i]
         = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
   }
   brw->metaops.restore_num_draw_buffers = ctx->DrawBuffer->_NumColorDrawBuffers;

   brw->metaops.restore_fp = ctx->FragmentProgram.Current;

   /* This works without adjusting refcounts.  Fix later? 
    */
   brw->metaops.saved_draw_region = brw->state.draw_region;
   brw->metaops.saved_depth_region = brw->state.depth_region;
   brw->metaops.active = 1;
   
   brw->state.dirty.brw |= BRW_NEW_METAOPS;
}

static void leave_meta_state( struct intel_context *intel )
{
   GLcontext *ctx = &intel->ctx;
   struct brw_context *brw = brw_context(ctx);
   GLuint i;

   restore_attribs(brw);

   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
      ctx->DrawBuffer->_ColorDrawBufferIndexes[i]
         = brw->metaops.restore_draw_buffers[i];
   }
   ctx->DrawBuffer->_NumColorDrawBuffers = brw->metaops.restore_num_draw_buffers;

   ctx->FragmentProgram.Current = brw->metaops.restore_fp;

   brw->state.draw_region = brw->metaops.saved_draw_region;
   brw->state.depth_region = brw->metaops.saved_depth_region;
   brw->metaops.saved_draw_region = NULL;
   brw->metaops.saved_depth_region = NULL;
   brw->metaops.active = 0;

   brw->state.dirty.mesa |= _NEW_BUFFERS;
   brw->state.dirty.brw |= BRW_NEW_METAOPS;
}



void brw_init_metaops( struct brw_context *brw )
{
   init_attribs(brw);


   brw->intel.vtbl.install_meta_state = install_meta_state;
   brw->intel.vtbl.leave_meta_state = leave_meta_state;
   brw->intel.vtbl.meta_no_depth_write = meta_no_depth_write;
   brw->intel.vtbl.meta_no_stencil_write = meta_no_stencil_write;
   brw->intel.vtbl.meta_stencil_replace = meta_stencil_replace;
   brw->intel.vtbl.meta_depth_replace = meta_depth_replace;
   brw->intel.vtbl.meta_color_mask = meta_color_mask;
   brw->intel.vtbl.meta_no_texture = meta_no_texture;
   brw->intel.vtbl.meta_import_pixel_state = meta_import_pixel_state;
   brw->intel.vtbl.meta_frame_buffer_texture = meta_frame_buffer_texture;
   brw->intel.vtbl.meta_draw_region = meta_draw_region;
   brw->intel.vtbl.meta_draw_quad = meta_draw_quad;
   brw->intel.vtbl.meta_texture_blend_replace = meta_texture_blend_replace;
/*    brw->intel.vtbl.meta_tex_rect_source = meta_tex_rect_source; */
/*    brw->intel.vtbl.meta_draw_format = set_draw_format; */
}

void brw_destroy_metaops( struct brw_context *brw )
{
   GLcontext *ctx = &brw->intel.ctx;

   if (brw->metaops.vbo)
      ctx->Driver.DeleteBuffer( ctx, brw->metaops.vbo );

/*    ctx->Driver.DeleteProgram( ctx, brw->metaops.fp ); */
/*    ctx->Driver.DeleteProgram( ctx, brw->metaops.fp_tex ); */
/*    ctx->Driver.DeleteProgram( ctx, brw->metaops.vp ); */
}