2 * Mesa 3-D graphics library
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Meta operations. Some GL operations can be expressed in terms of
27 * other GL operations. For example, glBlitFramebuffer() can be done
28 * with texture mapping and glClear() can be done with polygon rendering.
34 #include "main/glheader.h"
35 #include "main/mtypes.h"
36 #include "main/imports.h"
37 #include "main/arrayobj.h"
38 #include "main/blend.h"
39 #include "main/bufferobj.h"
40 #include "main/buffers.h"
41 #include "main/colortab.h"
42 #include "main/convolve.h"
43 #include "main/depth.h"
44 #include "main/enable.h"
45 #include "main/fbobject.h"
46 #include "main/formats.h"
47 #include "main/image.h"
48 #include "main/macros.h"
49 #include "main/matrix.h"
50 #include "main/mipmap.h"
51 #include "main/polygon.h"
52 #include "main/readpix.h"
53 #include "main/scissor.h"
54 #include "main/shaders.h"
55 #include "main/state.h"
56 #include "main/stencil.h"
57 #include "main/texobj.h"
58 #include "main/texenv.h"
59 #include "main/teximage.h"
60 #include "main/texparam.h"
61 #include "main/texstate.h"
62 #include "main/varray.h"
63 #include "main/viewport.h"
64 #include "shader/program.h"
65 #include "shader/arbprogram.h"
66 #include "swrast/swrast.h"
67 #include "drivers/common/meta.h"
70 /** Return offset in bytes of the field within a vertex struct */
71 #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
75 * Flags passed to _mesa_meta_begin().
79 #define META_ALPHA_TEST 0x1
80 #define META_BLEND 0x2 /**< includes logicop */
81 #define META_COLOR_MASK 0x4
82 #define META_DEPTH_TEST 0x8
84 #define META_PIXEL_STORE 0x20
85 #define META_PIXEL_TRANSFER 0x40
86 #define META_RASTERIZATION 0x80
87 #define META_SCISSOR 0x100
88 #define META_SHADER 0x200
89 #define META_STENCIL_TEST 0x400
90 #define META_TRANSFORM 0x800 /**< modelview, projection, clip planes */
91 #define META_TEXTURE 0x1000
92 #define META_VERTEX 0x2000
93 #define META_VIEWPORT 0x4000
98 * State which we may save/restore across meta ops.
99 * XXX this may be incomplete...
103 GLbitfield SavedState
; /**< bitmask of META_* flags */
105 /** META_ALPHA_TEST */
106 GLboolean AlphaEnabled
;
109 GLboolean BlendEnabled
;
110 GLboolean ColorLogicOpEnabled
;
112 /** META_COLOR_MASK */
113 GLubyte ColorMask
[4];
115 /** META_DEPTH_TEST */
116 struct gl_depthbuffer_attrib Depth
;
121 /** META_PIXEL_STORE */
122 struct gl_pixelstore_attrib Pack
, Unpack
;
124 /** META_PIXEL_TRANSFER */
125 GLfloat RedBias
, RedScale
;
126 GLfloat GreenBias
, GreenScale
;
127 GLfloat BlueBias
, BlueScale
;
128 GLfloat AlphaBias
, AlphaScale
;
129 GLfloat DepthBias
, DepthScale
;
130 GLboolean MapColorFlag
;
131 GLboolean Convolution1DEnabled
;
132 GLboolean Convolution2DEnabled
;
133 GLboolean Separable2DEnabled
;
135 /** META_RASTERIZATION */
136 GLenum FrontPolygonMode
, BackPolygonMode
;
137 GLboolean PolygonOffset
;
138 GLboolean PolygonSmooth
;
139 GLboolean PolygonStipple
;
140 GLboolean PolygonCull
;
143 struct gl_scissor_attrib Scissor
;
146 GLboolean VertexProgramEnabled
;
147 struct gl_vertex_program
*VertexProgram
;
148 GLboolean FragmentProgramEnabled
;
149 struct gl_fragment_program
*FragmentProgram
;
152 /** META_STENCIL_TEST */
153 struct gl_stencil_attrib Stencil
;
155 /** META_TRANSFORM */
157 GLfloat ModelviewMatrix
[16];
158 GLfloat ProjectionMatrix
[16];
159 GLfloat TextureMatrix
[16];
160 GLbitfield ClipPlanesEnabled
;
164 GLuint ClientActiveUnit
;
165 /** for unit[0] only */
166 struct gl_texture_object
*CurrentTexture
[NUM_TEXTURE_TARGETS
];
167 /** mask of TEXTURE_2D_BIT, etc */
168 GLbitfield TexEnabled
[MAX_TEXTURE_UNITS
];
169 GLbitfield TexGenEnabled
[MAX_TEXTURE_UNITS
];
170 GLuint EnvMode
; /* unit[0] only */
173 struct gl_array_object
*ArrayObj
;
174 struct gl_buffer_object
*ArrayBufferObj
;
177 GLint ViewportX
, ViewportY
, ViewportW
, ViewportH
;
178 GLclampd DepthNear
, DepthFar
;
180 /** Miscellaneous (always disabled) */
186 * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
187 * This is currently shared by all the meta ops. But we could create a
188 * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
193 GLenum Target
; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
194 GLsizei MinSize
; /**< Min texture size to allocate */
195 GLsizei MaxSize
; /**< Max possible texture size */
196 GLboolean NPOT
; /**< Non-power of two size OK? */
197 GLsizei Width
, Height
; /**< Current texture size */
199 GLfloat Sright
, Ttop
; /**< right, top texcoords */
204 * State for glBlitFramebufer()
215 * State for glClear()
225 * State for glCopyPixels()
235 * State for glDrawPixels()
241 GLuint StencilFP
; /**< Fragment program for drawing stencil images */
242 GLuint DepthFP
; /**< Fragment program for drawing depth images */
247 * State for glBitmap()
253 struct temp_texture Tex
; /**< separate texture from other meta ops */
258 * State for _mesa_meta_generate_mipmap()
260 struct gen_mipmap_state
269 * All per-context meta state.
273 struct save_state Save
; /**< state saved during meta-ops */
275 struct temp_texture TempTex
;
277 struct blit_state Blit
; /**< For _mesa_meta_BlitFramebuffer() */
278 struct clear_state Clear
; /**< For _mesa_meta_Clear() */
279 struct copypix_state CopyPix
; /**< For _mesa_meta_CopyPixels() */
280 struct drawpix_state DrawPix
; /**< For _mesa_meta_DrawPixels() */
281 struct bitmap_state Bitmap
; /**< For _mesa_meta_Bitmap() */
282 struct gen_mipmap_state Mipmap
; /**< For _mesa_meta_GenerateMipmap() */
287 * Initialize meta-ops for a context.
288 * To be called once during context creation.
291 _mesa_meta_init(GLcontext
*ctx
)
295 ctx
->Meta
= CALLOC_STRUCT(gl_meta_state
);
300 * Free context meta-op state.
301 * To be called once during context destruction.
304 _mesa_meta_free(GLcontext
*ctx
)
306 struct gl_meta_state
*meta
= ctx
->Meta
;
308 if (_mesa_get_current_context()) {
309 /* if there's no current context, these textures, buffers, etc should
310 * still get freed by _mesa_free_context_data().
313 /* the temporary texture */
314 _mesa_DeleteTextures(1, &meta
->TempTex
.TexObj
);
316 /* glBlitFramebuffer */
317 _mesa_DeleteBuffersARB(1, & meta
->Blit
.VBO
);
318 _mesa_DeleteVertexArraysAPPLE(1, &meta
->Blit
.ArrayObj
);
319 _mesa_DeletePrograms(1, &meta
->Blit
.DepthFP
);
322 _mesa_DeleteBuffersARB(1, & meta
->Clear
.VBO
);
323 _mesa_DeleteVertexArraysAPPLE(1, &meta
->Clear
.ArrayObj
);
326 _mesa_DeleteBuffersARB(1, & meta
->CopyPix
.VBO
);
327 _mesa_DeleteVertexArraysAPPLE(1, &meta
->CopyPix
.ArrayObj
);
330 _mesa_DeleteVertexArraysAPPLE(1, &meta
->DrawPix
.ArrayObj
);
331 _mesa_DeletePrograms(1, &meta
->DrawPix
.DepthFP
);
332 _mesa_DeletePrograms(1, &meta
->DrawPix
.StencilFP
);
335 _mesa_DeleteBuffersARB(1, & meta
->Bitmap
.VBO
);
336 _mesa_DeleteVertexArraysAPPLE(1, &meta
->Bitmap
.ArrayObj
);
337 _mesa_DeleteTextures(1, &meta
->Bitmap
.Tex
.TexObj
);
340 _mesa_free(ctx
->Meta
);
346 * Enter meta state. This is like a light-weight version of glPushAttrib
347 * but it also resets most GL state back to default values.
349 * \param state bitmask of META_* flags indicating which attribute groups
350 * to save and reset to their defaults
353 _mesa_meta_begin(GLcontext
*ctx
, GLbitfield state
)
355 struct save_state
*save
= &ctx
->Meta
->Save
;
357 save
->SavedState
= state
;
359 if (state
& META_ALPHA_TEST
) {
360 save
->AlphaEnabled
= ctx
->Color
.AlphaEnabled
;
361 if (ctx
->Color
.AlphaEnabled
)
362 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_FALSE
);
365 if (state
& META_BLEND
) {
366 save
->BlendEnabled
= ctx
->Color
.BlendEnabled
;
367 if (ctx
->Color
.BlendEnabled
)
368 _mesa_set_enable(ctx
, GL_BLEND
, GL_FALSE
);
369 save
->ColorLogicOpEnabled
= ctx
->Color
.ColorLogicOpEnabled
;
370 if (ctx
->Color
.ColorLogicOpEnabled
)
371 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, GL_FALSE
);
374 if (state
& META_COLOR_MASK
) {
375 COPY_4V(save
->ColorMask
, ctx
->Color
.ColorMask
);
376 if (!ctx
->Color
.ColorMask
[0] ||
377 !ctx
->Color
.ColorMask
[1] ||
378 !ctx
->Color
.ColorMask
[2] ||
379 !ctx
->Color
.ColorMask
[3])
380 _mesa_ColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
383 if (state
& META_DEPTH_TEST
) {
384 save
->Depth
= ctx
->Depth
; /* struct copy */
386 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_FALSE
);
389 if (state
& META_FOG
) {
390 save
->Fog
= ctx
->Fog
.Enabled
;
391 if (ctx
->Fog
.Enabled
)
392 _mesa_set_enable(ctx
, GL_FOG
, GL_FALSE
);
395 if (state
& META_PIXEL_STORE
) {
396 save
->Pack
= ctx
->Pack
;
397 save
->Unpack
= ctx
->Unpack
;
398 ctx
->Pack
= ctx
->DefaultPacking
;
399 ctx
->Unpack
= ctx
->DefaultPacking
;
402 if (state
& META_PIXEL_TRANSFER
) {
403 save
->RedScale
= ctx
->Pixel
.RedScale
;
404 save
->RedBias
= ctx
->Pixel
.RedBias
;
405 save
->GreenScale
= ctx
->Pixel
.GreenScale
;
406 save
->GreenBias
= ctx
->Pixel
.GreenBias
;
407 save
->BlueScale
= ctx
->Pixel
.BlueScale
;
408 save
->BlueBias
= ctx
->Pixel
.BlueBias
;
409 save
->AlphaScale
= ctx
->Pixel
.AlphaScale
;
410 save
->AlphaBias
= ctx
->Pixel
.AlphaBias
;
411 save
->MapColorFlag
= ctx
->Pixel
.MapColorFlag
;
412 save
->Convolution1DEnabled
= ctx
->Pixel
.Convolution1DEnabled
;
413 save
->Convolution2DEnabled
= ctx
->Pixel
.Convolution2DEnabled
;
414 save
->Separable2DEnabled
= ctx
->Pixel
.Separable2DEnabled
;
415 ctx
->Pixel
.RedScale
= 1.0F
;
416 ctx
->Pixel
.RedBias
= 0.0F
;
417 ctx
->Pixel
.GreenScale
= 1.0F
;
418 ctx
->Pixel
.GreenBias
= 0.0F
;
419 ctx
->Pixel
.BlueScale
= 1.0F
;
420 ctx
->Pixel
.BlueBias
= 0.0F
;
421 ctx
->Pixel
.AlphaScale
= 1.0F
;
422 ctx
->Pixel
.AlphaBias
= 0.0F
;
423 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
424 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
425 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
426 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
428 ctx
->NewState
|=_NEW_PIXEL
;
431 if (state
& META_RASTERIZATION
) {
432 save
->FrontPolygonMode
= ctx
->Polygon
.FrontMode
;
433 save
->BackPolygonMode
= ctx
->Polygon
.BackMode
;
434 save
->PolygonOffset
= ctx
->Polygon
.OffsetFill
;
435 save
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
436 save
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
437 save
->PolygonCull
= ctx
->Polygon
.CullFlag
;
438 _mesa_PolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
439 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, GL_FALSE
);
440 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, GL_FALSE
);
441 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, GL_FALSE
);
442 _mesa_set_enable(ctx
, GL_CULL_FACE
, GL_FALSE
);
445 if (state
& META_SCISSOR
) {
446 save
->Scissor
= ctx
->Scissor
; /* struct copy */
449 if (state
& META_SHADER
) {
450 if (ctx
->Extensions
.ARB_vertex_program
) {
451 save
->VertexProgramEnabled
= ctx
->VertexProgram
.Enabled
;
452 save
->VertexProgram
= ctx
->VertexProgram
.Current
;
453 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
, GL_FALSE
);
456 if (ctx
->Extensions
.ARB_fragment_program
) {
457 save
->FragmentProgramEnabled
= ctx
->FragmentProgram
.Enabled
;
458 save
->FragmentProgram
= ctx
->FragmentProgram
.Current
;
459 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_FALSE
);
462 if (ctx
->Extensions
.ARB_shader_objects
) {
463 save
->Shader
= ctx
->Shader
.CurrentProgram
?
464 ctx
->Shader
.CurrentProgram
->Name
: 0;
465 _mesa_UseProgramObjectARB(0);
469 if (state
& META_STENCIL_TEST
) {
470 save
->Stencil
= ctx
->Stencil
; /* struct copy */
471 if (ctx
->Stencil
.Enabled
)
472 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_FALSE
);
473 /* NOTE: other stencil state not reset */
476 if (state
& META_TEXTURE
) {
479 save
->ActiveUnit
= ctx
->Texture
.CurrentUnit
;
480 save
->ClientActiveUnit
= ctx
->Array
.ActiveTexture
;
481 save
->EnvMode
= ctx
->Texture
.Unit
[0].EnvMode
;
483 /* Disable all texture units */
484 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
485 save
->TexEnabled
[u
] = ctx
->Texture
.Unit
[u
].Enabled
;
486 save
->TexGenEnabled
[u
] = ctx
->Texture
.Unit
[u
].TexGenEnabled
;
487 if (ctx
->Texture
.Unit
[u
].Enabled
||
488 ctx
->Texture
.Unit
[u
].TexGenEnabled
) {
489 _mesa_ActiveTextureARB(GL_TEXTURE0
+ u
);
490 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
491 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
492 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
493 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
494 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE
, GL_FALSE
);
495 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
496 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
497 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
498 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
502 /* save current texture objects for unit[0] only */
503 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
504 _mesa_reference_texobj(&save
->CurrentTexture
[tgt
],
505 ctx
->Texture
.Unit
[0].CurrentTex
[tgt
]);
508 /* set defaults for unit[0] */
509 _mesa_ActiveTextureARB(GL_TEXTURE0
);
510 _mesa_ClientActiveTextureARB(GL_TEXTURE0
);
511 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
514 if (state
& META_TRANSFORM
) {
515 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
516 _mesa_memcpy(save
->ModelviewMatrix
, ctx
->ModelviewMatrixStack
.Top
->m
,
517 16 * sizeof(GLfloat
));
518 _mesa_memcpy(save
->ProjectionMatrix
, ctx
->ProjectionMatrixStack
.Top
->m
,
519 16 * sizeof(GLfloat
));
520 _mesa_memcpy(save
->TextureMatrix
, ctx
->TextureMatrixStack
[0].Top
->m
,
521 16 * sizeof(GLfloat
));
522 save
->MatrixMode
= ctx
->Transform
.MatrixMode
;
523 /* set 1:1 vertex:pixel coordinate transform */
524 _mesa_ActiveTextureARB(GL_TEXTURE0
);
525 _mesa_MatrixMode(GL_TEXTURE
);
526 _mesa_LoadIdentity();
527 _mesa_ActiveTextureARB(GL_TEXTURE0
+ activeTexture
);
528 _mesa_MatrixMode(GL_MODELVIEW
);
529 _mesa_LoadIdentity();
530 _mesa_MatrixMode(GL_PROJECTION
);
531 _mesa_LoadIdentity();
532 _mesa_Ortho(0.0F
, ctx
->DrawBuffer
->Width
,
533 0.0F
, ctx
->DrawBuffer
->Height
,
535 save
->ClipPlanesEnabled
= ctx
->Transform
.ClipPlanesEnabled
;
536 if (ctx
->Transform
.ClipPlanesEnabled
) {
538 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
539 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
544 if (state
& META_VERTEX
) {
545 /* save vertex array object state */
546 _mesa_reference_array_object(ctx
, &save
->ArrayObj
,
547 ctx
->Array
.ArrayObj
);
548 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
,
549 ctx
->Array
.ArrayBufferObj
);
550 /* set some default state? */
553 if (state
& META_VIEWPORT
) {
554 /* save viewport state */
555 save
->ViewportX
= ctx
->Viewport
.X
;
556 save
->ViewportY
= ctx
->Viewport
.Y
;
557 save
->ViewportW
= ctx
->Viewport
.Width
;
558 save
->ViewportH
= ctx
->Viewport
.Height
;
559 /* set viewport to match window size */
560 if (ctx
->Viewport
.X
!= 0 ||
561 ctx
->Viewport
.Y
!= 0 ||
562 ctx
->Viewport
.Width
!= ctx
->DrawBuffer
->Width
||
563 ctx
->Viewport
.Height
!= ctx
->DrawBuffer
->Height
) {
564 _mesa_set_viewport(ctx
, 0, 0,
565 ctx
->DrawBuffer
->Width
, ctx
->DrawBuffer
->Height
);
567 /* save depth range state */
568 save
->DepthNear
= ctx
->Viewport
.Near
;
569 save
->DepthFar
= ctx
->Viewport
.Far
;
570 /* set depth range to default */
571 _mesa_DepthRange(0.0, 1.0);
576 save
->Lighting
= ctx
->Light
.Enabled
;
577 if (ctx
->Light
.Enabled
)
578 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_FALSE
);
584 * Leave meta state. This is like a light-weight version of glPopAttrib().
587 _mesa_meta_end(GLcontext
*ctx
)
589 struct save_state
*save
= &ctx
->Meta
->Save
;
590 const GLbitfield state
= save
->SavedState
;
592 if (state
& META_ALPHA_TEST
) {
593 if (ctx
->Color
.AlphaEnabled
!= save
->AlphaEnabled
)
594 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, save
->AlphaEnabled
);
597 if (state
& META_BLEND
) {
598 if (ctx
->Color
.BlendEnabled
!= save
->BlendEnabled
)
599 _mesa_set_enable(ctx
, GL_BLEND
, save
->BlendEnabled
);
600 if (ctx
->Color
.ColorLogicOpEnabled
!= save
->ColorLogicOpEnabled
)
601 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, save
->ColorLogicOpEnabled
);
604 if (state
& META_COLOR_MASK
) {
605 if (!TEST_EQ_4V(ctx
->Color
.ColorMask
, save
->ColorMask
))
606 _mesa_ColorMask(save
->ColorMask
[0], save
->ColorMask
[1],
607 save
->ColorMask
[2], save
->ColorMask
[3]);
610 if (state
& META_DEPTH_TEST
) {
611 if (ctx
->Depth
.Test
!= save
->Depth
.Test
)
612 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, save
->Depth
.Test
);
613 _mesa_DepthFunc(save
->Depth
.Func
);
614 _mesa_DepthMask(save
->Depth
.Mask
);
617 if (state
& META_FOG
) {
618 _mesa_set_enable(ctx
, GL_FOG
, save
->Fog
);
621 if (state
& META_PIXEL_STORE
) {
622 ctx
->Pack
= save
->Pack
;
623 ctx
->Unpack
= save
->Unpack
;
626 if (state
& META_PIXEL_TRANSFER
) {
627 ctx
->Pixel
.RedScale
= save
->RedScale
;
628 ctx
->Pixel
.RedBias
= save
->RedBias
;
629 ctx
->Pixel
.GreenScale
= save
->GreenScale
;
630 ctx
->Pixel
.GreenBias
= save
->GreenBias
;
631 ctx
->Pixel
.BlueScale
= save
->BlueScale
;
632 ctx
->Pixel
.BlueBias
= save
->BlueBias
;
633 ctx
->Pixel
.AlphaScale
= save
->AlphaScale
;
634 ctx
->Pixel
.AlphaBias
= save
->AlphaBias
;
635 ctx
->Pixel
.MapColorFlag
= save
->MapColorFlag
;
636 ctx
->Pixel
.Convolution1DEnabled
= save
->Convolution1DEnabled
;
637 ctx
->Pixel
.Convolution2DEnabled
= save
->Convolution2DEnabled
;
638 ctx
->Pixel
.Separable2DEnabled
= save
->Separable2DEnabled
;
640 ctx
->NewState
|=_NEW_PIXEL
;
643 if (state
& META_RASTERIZATION
) {
644 _mesa_PolygonMode(GL_FRONT
, save
->FrontPolygonMode
);
645 _mesa_PolygonMode(GL_BACK
, save
->BackPolygonMode
);
646 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, save
->PolygonStipple
);
647 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, save
->PolygonOffset
);
648 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, save
->PolygonSmooth
);
649 _mesa_set_enable(ctx
, GL_CULL_FACE
, save
->PolygonCull
);
652 if (state
& META_SCISSOR
) {
653 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, save
->Scissor
.Enabled
);
654 _mesa_Scissor(save
->Scissor
.X
, save
->Scissor
.Y
,
655 save
->Scissor
.Width
, save
->Scissor
.Height
);
658 if (state
& META_SHADER
) {
659 if (ctx
->Extensions
.ARB_vertex_program
) {
660 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
,
661 save
->VertexProgramEnabled
);
662 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
663 save
->VertexProgram
);
666 if (ctx
->Extensions
.ARB_fragment_program
) {
667 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
668 save
->FragmentProgramEnabled
);
669 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
670 save
->FragmentProgram
);
673 if (ctx
->Extensions
.ARB_shader_objects
) {
674 _mesa_UseProgramObjectARB(save
->Shader
);
678 if (state
& META_STENCIL_TEST
) {
679 const struct gl_stencil_attrib
*stencil
= &save
->Stencil
;
681 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
682 _mesa_ClearStencil(stencil
->Clear
);
683 if (ctx
->Extensions
.EXT_stencil_two_side
) {
684 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
685 stencil
->TestTwoSide
);
686 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
687 ? GL_BACK
: GL_FRONT
);
690 _mesa_StencilFuncSeparate(GL_FRONT
,
691 stencil
->Function
[0],
693 stencil
->ValueMask
[0]);
694 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
695 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
696 stencil
->ZFailFunc
[0],
697 stencil
->ZPassFunc
[0]);
699 _mesa_StencilFuncSeparate(GL_BACK
,
700 stencil
->Function
[1],
702 stencil
->ValueMask
[1]);
703 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
704 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
705 stencil
->ZFailFunc
[1],
706 stencil
->ZPassFunc
[1]);
709 if (state
& META_TEXTURE
) {
712 ASSERT(ctx
->Texture
.CurrentUnit
== 0);
714 /* restore texenv for unit[0] */
715 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, save
->EnvMode
);
717 /* restore texture objects for unit[0] only */
718 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
719 _mesa_reference_texobj(&ctx
->Texture
.Unit
[0].CurrentTex
[tgt
],
720 save
->CurrentTexture
[tgt
]);
723 /* Re-enable textures, texgen */
724 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
725 if (save
->TexEnabled
[u
]) {
726 _mesa_ActiveTextureARB(GL_TEXTURE0
+ u
);
728 if (save
->TexEnabled
[u
] & TEXTURE_1D_BIT
)
729 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, GL_TRUE
);
730 if (save
->TexEnabled
[u
] & TEXTURE_2D_BIT
)
731 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, GL_TRUE
);
732 if (save
->TexEnabled
[u
] & TEXTURE_3D_BIT
)
733 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, GL_TRUE
);
734 if (save
->TexEnabled
[u
] & TEXTURE_CUBE_BIT
)
735 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_TRUE
);
736 if (save
->TexEnabled
[u
] & TEXTURE_RECT_BIT
)
737 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE
, GL_TRUE
);
740 if (save
->TexGenEnabled
[u
]) {
741 _mesa_ActiveTextureARB(GL_TEXTURE0
+ u
);
743 if (save
->TexGenEnabled
[u
] & S_BIT
)
744 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
745 if (save
->TexGenEnabled
[u
] & T_BIT
)
746 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
747 if (save
->TexGenEnabled
[u
] & R_BIT
)
748 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
749 if (save
->TexGenEnabled
[u
] & Q_BIT
)
750 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
754 /* restore current unit state */
755 _mesa_ActiveTextureARB(GL_TEXTURE0
+ save
->ActiveUnit
);
756 _mesa_ClientActiveTextureARB(GL_TEXTURE0
+ save
->ClientActiveUnit
);
759 if (state
& META_TRANSFORM
) {
760 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
761 _mesa_ActiveTextureARB(GL_TEXTURE0
);
762 _mesa_MatrixMode(GL_TEXTURE
);
763 _mesa_LoadMatrixf(save
->TextureMatrix
);
764 _mesa_ActiveTextureARB(GL_TEXTURE0
+ activeTexture
);
766 _mesa_MatrixMode(GL_MODELVIEW
);
767 _mesa_LoadMatrixf(save
->ModelviewMatrix
);
769 _mesa_MatrixMode(GL_PROJECTION
);
770 _mesa_LoadMatrixf(save
->ProjectionMatrix
);
772 _mesa_MatrixMode(save
->MatrixMode
);
774 if (save
->ClipPlanesEnabled
) {
776 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
777 if (save
->ClipPlanesEnabled
& (1 << i
)) {
778 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
784 if (state
& META_VERTEX
) {
785 /* restore vertex buffer object */
786 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, save
->ArrayBufferObj
->Name
);
787 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
, NULL
);
789 /* restore vertex array object */
790 _mesa_BindVertexArray(save
->ArrayObj
->Name
);
791 _mesa_reference_array_object(ctx
, &save
->ArrayObj
, NULL
);
794 if (state
& META_VIEWPORT
) {
795 if (save
->ViewportX
!= ctx
->Viewport
.X
||
796 save
->ViewportY
!= ctx
->Viewport
.Y
||
797 save
->ViewportW
!= ctx
->Viewport
.Width
||
798 save
->ViewportH
!= ctx
->Viewport
.Height
) {
799 _mesa_set_viewport(ctx
, save
->ViewportX
, save
->ViewportY
,
800 save
->ViewportW
, save
->ViewportH
);
802 _mesa_DepthRange(save
->DepthNear
, save
->DepthFar
);
806 if (save
->Lighting
) {
807 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_TRUE
);
813 * One-time init for a temp_texture object.
814 * Choose tex target, compute max tex size, etc.
817 init_temp_texture(GLcontext
*ctx
, struct temp_texture
*tex
)
819 /* prefer texture rectangle */
820 if (ctx
->Extensions
.NV_texture_rectangle
) {
821 tex
->Target
= GL_TEXTURE_RECTANGLE
;
822 tex
->MaxSize
= ctx
->Const
.MaxTextureRectSize
;
826 /* use 2D texture, NPOT if possible */
827 tex
->Target
= GL_TEXTURE_2D
;
828 tex
->MaxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
829 tex
->NPOT
= ctx
->Extensions
.ARB_texture_non_power_of_two
;
831 tex
->MinSize
= 16; /* 16 x 16 at least */
832 assert(tex
->MaxSize
> 0);
834 _mesa_GenTextures(1, &tex
->TexObj
);
835 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
840 * Return pointer to temp_texture info for non-bitmap ops.
841 * This does some one-time init if needed.
843 static struct temp_texture
*
844 get_temp_texture(GLcontext
*ctx
)
846 struct temp_texture
*tex
= &ctx
->Meta
->TempTex
;
849 init_temp_texture(ctx
, tex
);
857 * Return pointer to temp_texture info for _mesa_meta_bitmap().
858 * We use a separate texture for bitmaps to reduce texture
859 * allocation/deallocation.
861 static struct temp_texture
*
862 get_bitmap_temp_texture(GLcontext
*ctx
)
864 struct temp_texture
*tex
= &ctx
->Meta
->Bitmap
.Tex
;
867 init_temp_texture(ctx
, tex
);
875 * Compute the width/height of texture needed to draw an image of the
876 * given size. Return a flag indicating whether the current texture
877 * can be re-used (glTexSubImage2D) or if a new texture needs to be
878 * allocated (glTexImage2D).
879 * Also, compute s/t texcoords for drawing.
881 * \return GL_TRUE if new texture is needed, GL_FALSE otherwise
884 alloc_texture(struct temp_texture
*tex
,
885 GLsizei width
, GLsizei height
, GLenum intFormat
)
887 GLboolean newTex
= GL_FALSE
;
889 ASSERT(width
<= tex
->MaxSize
);
890 ASSERT(height
<= tex
->MaxSize
);
892 if (width
> tex
->Width
||
893 height
> tex
->Height
||
894 intFormat
!= tex
->IntFormat
) {
895 /* alloc new texture (larger or different format) */
898 /* use non-power of two size */
899 tex
->Width
= MAX2(tex
->MinSize
, width
);
900 tex
->Height
= MAX2(tex
->MinSize
, height
);
903 /* find power of two size */
905 w
= h
= tex
->MinSize
;
914 tex
->IntFormat
= intFormat
;
919 /* compute texcoords */
920 if (tex
->Target
== GL_TEXTURE_RECTANGLE
) {
921 tex
->Sright
= (GLfloat
) width
;
922 tex
->Ttop
= (GLfloat
) height
;
925 tex
->Sright
= (GLfloat
) width
/ tex
->Width
;
926 tex
->Ttop
= (GLfloat
) height
/ tex
->Height
;
934 * Setup/load texture for glCopyPixels or glBlitFramebuffer.
937 setup_copypix_texture(struct temp_texture
*tex
,
939 GLint srcX
, GLint srcY
,
940 GLsizei width
, GLsizei height
, GLenum intFormat
,
943 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
944 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, filter
);
945 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, filter
);
946 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
948 /* copy framebuffer image to texture */
950 /* create new tex image */
951 if (tex
->Width
== width
&& tex
->Height
== height
) {
952 /* create new tex with framebuffer data */
953 _mesa_CopyTexImage2D(tex
->Target
, 0, tex
->IntFormat
,
954 srcX
, srcY
, width
, height
, 0);
957 /* create empty texture */
958 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
959 tex
->Width
, tex
->Height
, 0,
960 intFormat
, GL_UNSIGNED_BYTE
, NULL
);
962 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
963 0, 0, srcX
, srcY
, width
, height
);
967 /* replace existing tex image */
968 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
969 0, 0, srcX
, srcY
, width
, height
);
975 * Setup/load texture for glDrawPixels.
978 setup_drawpix_texture(struct temp_texture
*tex
,
981 GLsizei width
, GLsizei height
,
982 GLenum format
, GLenum type
,
983 const GLvoid
*pixels
)
985 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
986 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
987 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
988 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
990 /* copy pixel data to texture */
992 /* create new tex image */
993 if (tex
->Width
== width
&& tex
->Height
== height
) {
994 /* create new tex and load image data */
995 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
996 tex
->Width
, tex
->Height
, 0, format
, type
, pixels
);
999 /* create empty texture */
1000 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1001 tex
->Width
, tex
->Height
, 0, format
, type
, NULL
);
1003 _mesa_TexSubImage2D(tex
->Target
, 0,
1004 0, 0, width
, height
, format
, type
, pixels
);
1008 /* replace existing tex image */
1009 _mesa_TexSubImage2D(tex
->Target
, 0,
1010 0, 0, width
, height
, format
, type
, pixels
);
1017 * One-time init for drawing depth pixels.
1020 init_blit_depth_pixels(GLcontext
*ctx
)
1022 static const char *program
=
1024 "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
1027 struct blit_state
*blit
= &ctx
->Meta
->Blit
;
1028 struct temp_texture
*tex
= get_temp_texture(ctx
);
1029 const char *texTarget
;
1031 assert(blit
->DepthFP
== 0);
1033 /* replace %s with "RECT" or "2D" */
1034 assert(strlen(program
) + 4 < sizeof(program2
));
1035 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1039 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1041 _mesa_GenPrograms(1, &blit
->DepthFP
);
1042 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, blit
->DepthFP
);
1043 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1044 strlen(program2
), (const GLubyte
*) program2
);
1049 * Meta implementation of ctx->Driver.BlitFramebuffer() in terms
1050 * of texture mapping and polygon rendering.
1053 _mesa_meta_BlitFramebuffer(GLcontext
*ctx
,
1054 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1055 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1056 GLbitfield mask
, GLenum filter
)
1058 struct blit_state
*blit
= &ctx
->Meta
->Blit
;
1059 struct temp_texture
*tex
= get_temp_texture(ctx
);
1060 const GLsizei maxTexSize
= tex
->MaxSize
;
1061 const GLint srcX
= MIN2(srcX0
, srcX1
);
1062 const GLint srcY
= MIN2(srcY0
, srcY1
);
1063 const GLint srcW
= abs(srcX1
- srcX0
);
1064 const GLint srcH
= abs(srcY1
- srcY0
);
1065 const GLboolean srcFlipX
= srcX1
< srcX0
;
1066 const GLboolean srcFlipY
= srcY1
< srcY0
;
1070 struct vertex verts
[4];
1073 if (srcW
> maxTexSize
|| srcH
> maxTexSize
) {
1074 /* XXX avoid this fallback */
1075 _swrast_BlitFramebuffer(ctx
, srcX0
, srcY0
, srcX1
, srcY1
,
1076 dstX0
, dstY0
, dstX1
, dstY1
, mask
, filter
);
1092 /* only scissor effects blit so save/clear all other relevant state */
1093 _mesa_meta_begin(ctx
, ~META_SCISSOR
);
1095 if (blit
->ArrayObj
== 0) {
1096 /* one-time setup */
1098 /* create vertex array object */
1099 _mesa_GenVertexArrays(1, &blit
->ArrayObj
);
1100 _mesa_BindVertexArray(blit
->ArrayObj
);
1102 /* create vertex array buffer */
1103 _mesa_GenBuffersARB(1, &blit
->VBO
);
1104 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, blit
->VBO
);
1105 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1106 NULL
, GL_DYNAMIC_DRAW_ARB
);
1108 /* setup vertex arrays */
1109 _mesa_VertexPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1110 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1111 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1112 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1115 _mesa_BindVertexArray(blit
->ArrayObj
);
1116 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, blit
->VBO
);
1119 newTex
= alloc_texture(tex
, srcW
, srcH
, GL_RGBA
);
1121 /* vertex positions/texcoords (after texture allocation!) */
1123 verts
[0].x
= (GLfloat
) dstX0
;
1124 verts
[0].y
= (GLfloat
) dstY0
;
1125 verts
[1].x
= (GLfloat
) dstX1
;
1126 verts
[1].y
= (GLfloat
) dstY0
;
1127 verts
[2].x
= (GLfloat
) dstX1
;
1128 verts
[2].y
= (GLfloat
) dstY1
;
1129 verts
[3].x
= (GLfloat
) dstX0
;
1130 verts
[3].y
= (GLfloat
) dstY1
;
1134 verts
[1].s
= tex
->Sright
;
1136 verts
[2].s
= tex
->Sright
;
1137 verts
[2].t
= tex
->Ttop
;
1139 verts
[3].t
= tex
->Ttop
;
1141 /* upload new vertex data */
1142 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1145 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1147 if (mask
& GL_COLOR_BUFFER_BIT
) {
1148 setup_copypix_texture(tex
, newTex
, srcX
, srcY
, srcW
, srcH
,
1150 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1151 mask
&= ~GL_COLOR_BUFFER_BIT
;
1154 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1155 GLuint
*tmp
= (GLuint
*) _mesa_malloc(srcW
* srcH
* sizeof(GLuint
));
1158 init_blit_depth_pixels(ctx
);
1160 /* maybe change tex format here */
1161 newTex
= alloc_texture(tex
, srcW
, srcH
, GL_DEPTH_COMPONENT
);
1163 _mesa_ReadPixels(srcX
, srcY
, srcW
, srcH
,
1164 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, tmp
);
1166 setup_drawpix_texture(tex
, newTex
, GL_DEPTH_COMPONENT
, srcW
, srcH
,
1167 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, tmp
);
1169 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, blit
->DepthFP
);
1170 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
1171 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1172 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1173 _mesa_DepthFunc(GL_ALWAYS
);
1174 _mesa_DepthMask(GL_TRUE
);
1176 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1177 mask
&= ~GL_DEPTH_BUFFER_BIT
;
1183 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1184 /* XXX can't easily do stencil */
1187 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1189 _mesa_meta_end(ctx
);
1192 _swrast_BlitFramebuffer(ctx
, srcX0
, srcY0
, srcX1
, srcY1
,
1193 dstX0
, dstY0
, dstX1
, dstY1
, mask
, filter
);
1199 * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
1202 _mesa_meta_Clear(GLcontext
*ctx
, GLbitfield buffers
)
1204 struct clear_state
*clear
= &ctx
->Meta
->Clear
;
1206 GLfloat x
, y
, z
, r
, g
, b
, a
;
1208 struct vertex verts
[4];
1209 /* save all state but scissor, pixel pack/unpack */
1210 GLbitfield metaSave
= META_ALL
- META_SCISSOR
- META_PIXEL_STORE
;
1212 if (buffers
& BUFFER_BITS_COLOR
) {
1213 /* if clearing color buffers, don't save/restore colormask */
1214 metaSave
-= META_COLOR_MASK
;
1217 _mesa_meta_begin(ctx
, metaSave
);
1219 if (clear
->ArrayObj
== 0) {
1220 /* one-time setup */
1222 /* create vertex array object */
1223 _mesa_GenVertexArrays(1, &clear
->ArrayObj
);
1224 _mesa_BindVertexArray(clear
->ArrayObj
);
1226 /* create vertex array buffer */
1227 _mesa_GenBuffersARB(1, &clear
->VBO
);
1228 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, clear
->VBO
);
1229 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1230 NULL
, GL_DYNAMIC_DRAW_ARB
);
1232 /* setup vertex arrays */
1233 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1234 _mesa_ColorPointer(4, GL_FLOAT
, sizeof(struct vertex
), OFFSET(r
));
1235 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1236 _mesa_EnableClientState(GL_COLOR_ARRAY
);
1239 _mesa_BindVertexArray(clear
->ArrayObj
);
1240 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, clear
->VBO
);
1243 /* GL_COLOR_BUFFER_BIT */
1244 if (buffers
& BUFFER_BITS_COLOR
) {
1245 /* leave colormask, glDrawBuffer state as-is */
1248 ASSERT(metaSave
& META_COLOR_MASK
);
1249 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1252 /* GL_DEPTH_BUFFER_BIT */
1253 if (buffers
& BUFFER_BIT_DEPTH
) {
1254 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1255 _mesa_DepthFunc(GL_ALWAYS
);
1256 _mesa_DepthMask(GL_TRUE
);
1259 assert(!ctx
->Depth
.Test
);
1262 /* GL_STENCIL_BUFFER_BIT */
1263 if (buffers
& BUFFER_BIT_STENCIL
) {
1264 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1265 _mesa_StencilOpSeparate(GL_FRONT_AND_BACK
,
1266 GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1267 _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK
, GL_ALWAYS
,
1268 ctx
->Stencil
.Clear
& 0x7fffffff,
1269 ctx
->Stencil
.WriteMask
[0]);
1272 assert(!ctx
->Stencil
.Enabled
);
1275 /* vertex positions/colors */
1277 const GLfloat x0
= (GLfloat
) ctx
->DrawBuffer
->_Xmin
;
1278 const GLfloat y0
= (GLfloat
) ctx
->DrawBuffer
->_Ymin
;
1279 const GLfloat x1
= (GLfloat
) ctx
->DrawBuffer
->_Xmax
;
1280 const GLfloat y1
= (GLfloat
) ctx
->DrawBuffer
->_Ymax
;
1281 const GLfloat z
= 1.0 - 2.0 * ctx
->Depth
.Clear
;
1298 for (i
= 0; i
< 4; i
++) {
1299 verts
[i
].r
= ctx
->Color
.ClearColor
[0];
1300 verts
[i
].g
= ctx
->Color
.ClearColor
[1];
1301 verts
[i
].b
= ctx
->Color
.ClearColor
[2];
1302 verts
[i
].a
= ctx
->Color
.ClearColor
[3];
1305 /* upload new vertex data */
1306 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1310 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1312 _mesa_meta_end(ctx
);
1317 * Meta implementation of ctx->Driver.CopyPixels() in terms
1318 * of texture mapping and polygon rendering.
1321 _mesa_meta_CopyPixels(GLcontext
*ctx
, GLint srcX
, GLint srcY
,
1322 GLsizei width
, GLsizei height
,
1323 GLint dstX
, GLint dstY
, GLenum type
)
1325 struct copypix_state
*copypix
= &ctx
->Meta
->CopyPix
;
1326 struct temp_texture
*tex
= get_temp_texture(ctx
);
1328 GLfloat x
, y
, z
, s
, t
;
1330 struct vertex verts
[4];
1332 GLenum intFormat
= GL_RGBA
;
1334 if (type
!= GL_COLOR
||
1335 ctx
->_ImageTransferState
||
1337 width
> tex
->MaxSize
||
1338 height
> tex
->MaxSize
) {
1339 /* XXX avoid this fallback */
1340 _swrast_CopyPixels(ctx
, srcX
, srcY
, width
, height
, dstX
, dstY
, type
);
1344 /* Most GL state applies to glCopyPixels, but a there's a few things
1345 * we need to override:
1347 _mesa_meta_begin(ctx
, (META_RASTERIZATION
|
1354 if (copypix
->ArrayObj
== 0) {
1355 /* one-time setup */
1357 /* create vertex array object */
1358 _mesa_GenVertexArrays(1, ©pix
->ArrayObj
);
1359 _mesa_BindVertexArray(copypix
->ArrayObj
);
1361 /* create vertex array buffer */
1362 _mesa_GenBuffersARB(1, ©pix
->VBO
);
1363 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, copypix
->VBO
);
1364 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1365 NULL
, GL_DYNAMIC_DRAW_ARB
);
1367 /* setup vertex arrays */
1368 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1369 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1370 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1371 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1374 _mesa_BindVertexArray(copypix
->ArrayObj
);
1375 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, copypix
->VBO
);
1378 newTex
= alloc_texture(tex
, width
, height
, intFormat
);
1380 /* vertex positions, texcoords (after texture allocation!) */
1382 const GLfloat dstX0
= (GLfloat
) dstX
;
1383 const GLfloat dstY0
= (GLfloat
) dstY
;
1384 const GLfloat dstX1
= dstX
+ width
* ctx
->Pixel
.ZoomX
;
1385 const GLfloat dstY1
= dstY
+ height
* ctx
->Pixel
.ZoomY
;
1386 const GLfloat z
= ctx
->Current
.RasterPos
[2];
1396 verts
[1].s
= tex
->Sright
;
1401 verts
[2].s
= tex
->Sright
;
1402 verts
[2].t
= tex
->Ttop
;
1407 verts
[3].t
= tex
->Ttop
;
1409 /* upload new vertex data */
1410 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1413 /* Alloc/setup texture */
1414 setup_copypix_texture(tex
, newTex
, srcX
, srcY
, width
, height
,
1415 GL_RGBA
, GL_NEAREST
);
1417 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1419 /* draw textured quad */
1420 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1422 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1424 _mesa_meta_end(ctx
);
1430 * When the glDrawPixels() image size is greater than the max rectangle
1431 * texture size we use this function to break the glDrawPixels() image
1432 * into tiles which fit into the max texture size.
1435 tiled_draw_pixels(GLcontext
*ctx
,
1437 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1438 GLenum format
, GLenum type
,
1439 const struct gl_pixelstore_attrib
*unpack
,
1440 const GLvoid
*pixels
)
1442 struct gl_pixelstore_attrib tileUnpack
= *unpack
;
1445 if (tileUnpack
.RowLength
== 0)
1446 tileUnpack
.RowLength
= width
;
1448 for (i
= 0; i
< width
; i
+= tileSize
) {
1449 const GLint tileWidth
= MIN2(tileSize
, width
- i
);
1450 const GLint tileX
= (GLint
) (x
+ i
* ctx
->Pixel
.ZoomX
);
1452 tileUnpack
.SkipPixels
= unpack
->SkipPixels
+ i
;
1454 for (j
= 0; j
< height
; j
+= tileSize
) {
1455 const GLint tileHeight
= MIN2(tileSize
, height
- j
);
1456 const GLint tileY
= (GLint
) (y
+ j
* ctx
->Pixel
.ZoomY
);
1458 tileUnpack
.SkipRows
= unpack
->SkipRows
+ j
;
1460 _mesa_meta_DrawPixels(ctx
, tileX
, tileY
, tileWidth
, tileHeight
,
1461 format
, type
, &tileUnpack
, pixels
);
1468 * One-time init for drawing stencil pixels.
1471 init_draw_stencil_pixels(GLcontext
*ctx
)
1473 /* This program is run eight times, once for each stencil bit.
1474 * The stencil values to draw are found in an 8-bit alpha texture.
1475 * We read the texture/stencil value and test if bit 'b' is set.
1476 * If the bit is not set, use KIL to kill the fragment.
1477 * Finally, we use the stencil test to update the stencil buffer.
1479 * The basic algorithm for checking if a bit is set is:
1480 * if (is_odd(value / (1 << bit)))
1481 * result is one (or non-zero).
1484 * The program parameter contains three values:
1485 * parm.x = 255 / (1 << bit)
1489 static const char *program
=
1491 "PARAM parm = program.local[0]; \n"
1493 "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */
1494 "# t = t * 255 / bit \n"
1495 "MUL t.x, t.a, parm.x; \n"
1498 "SUB t.x, t.x, t.y; \n"
1500 "MUL t.x, t.x, parm.y; \n"
1501 "# t = fract(t.x) \n"
1502 "FRC t.x, t.x; # if t.x != 0, then the bit is set \n"
1503 "# t.x = (t.x == 0 ? 1 : 0) \n"
1504 "SGE t.x, -t.x, parm.z; \n"
1506 "# for debug only \n"
1507 "#MOV result.color, t.x; \n"
1509 char program2
[1000];
1510 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1511 struct temp_texture
*tex
= get_temp_texture(ctx
);
1512 const char *texTarget
;
1514 assert(drawpix
->StencilFP
== 0);
1516 /* replace %s with "RECT" or "2D" */
1517 assert(strlen(program
) + 4 < sizeof(program2
));
1518 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1522 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1524 _mesa_GenPrograms(1, &drawpix
->StencilFP
);
1525 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
1526 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1527 strlen(program2
), (const GLubyte
*) program2
);
1532 * One-time init for drawing depth pixels.
1535 init_draw_depth_pixels(GLcontext
*ctx
)
1537 static const char *program
=
1539 "PARAM color = program.local[0]; \n"
1540 "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
1541 "MOV result.color, color; \n"
1544 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1545 struct temp_texture
*tex
= get_temp_texture(ctx
);
1546 const char *texTarget
;
1548 assert(drawpix
->DepthFP
== 0);
1550 /* replace %s with "RECT" or "2D" */
1551 assert(strlen(program
) + 4 < sizeof(program2
));
1552 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1556 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1558 _mesa_GenPrograms(1, &drawpix
->DepthFP
);
1559 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
1560 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1561 strlen(program2
), (const GLubyte
*) program2
);
1566 * Meta implementation of ctx->Driver.DrawPixels() in terms
1567 * of texture mapping and polygon rendering.
1570 _mesa_meta_DrawPixels(GLcontext
*ctx
,
1571 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1572 GLenum format
, GLenum type
,
1573 const struct gl_pixelstore_attrib
*unpack
,
1574 const GLvoid
*pixels
)
1576 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1577 struct temp_texture
*tex
= get_temp_texture(ctx
);
1578 const struct gl_pixelstore_attrib unpackSave
= ctx
->Unpack
;
1579 const GLuint origStencilMask
= ctx
->Stencil
.WriteMask
[0];
1581 GLfloat x
, y
, z
, s
, t
;
1583 struct vertex verts
[4];
1584 GLenum texIntFormat
;
1585 GLboolean fallback
, newTex
;
1586 GLbitfield metaExtraSave
= 0x0;
1590 * Determine if we can do the glDrawPixels with texture mapping.
1592 fallback
= GL_FALSE
;
1593 if (ctx
->_ImageTransferState
||
1598 if (_mesa_is_color_format(format
)) {
1599 /* use more compact format when possible */
1600 /* XXX disable special case for GL_LUMINANCE for now to work around
1601 * apparent i965 driver bug (see bug #23670).
1603 if (/*format == GL_LUMINANCE ||*/ format
== GL_LUMINANCE_ALPHA
)
1604 texIntFormat
= format
;
1606 texIntFormat
= GL_RGBA
;
1608 else if (_mesa_is_stencil_format(format
)) {
1609 if (ctx
->Extensions
.ARB_fragment_program
&&
1610 ctx
->Pixel
.IndexShift
== 0 &&
1611 ctx
->Pixel
.IndexOffset
== 0 &&
1612 type
== GL_UNSIGNED_BYTE
) {
1613 /* We'll store stencil as alpha. This only works for GLubyte
1614 * image data because of how incoming values are mapped to alpha
1617 texIntFormat
= GL_ALPHA
;
1618 metaExtraSave
= (META_COLOR_MASK
|
1627 else if (_mesa_is_depth_format(format
)) {
1628 if (ctx
->Extensions
.ARB_depth_texture
&&
1629 ctx
->Extensions
.ARB_fragment_program
) {
1630 texIntFormat
= GL_DEPTH_COMPONENT
;
1631 metaExtraSave
= (META_SHADER
);
1642 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
1643 format
, type
, unpack
, pixels
);
1648 * Check image size against max texture size, draw as tiles if needed.
1650 if (width
> tex
->MaxSize
|| height
> tex
->MaxSize
) {
1651 tiled_draw_pixels(ctx
, tex
->MaxSize
, x
, y
, width
, height
,
1652 format
, type
, unpack
, pixels
);
1656 /* Most GL state applies to glDrawPixels (like blending, stencil, etc),
1657 * but a there's a few things we need to override:
1659 _mesa_meta_begin(ctx
, (META_RASTERIZATION
|
1667 newTex
= alloc_texture(tex
, width
, height
, texIntFormat
);
1669 /* vertex positions, texcoords (after texture allocation!) */
1671 const GLfloat x0
= (GLfloat
) x
;
1672 const GLfloat y0
= (GLfloat
) y
;
1673 const GLfloat x1
= x
+ width
* ctx
->Pixel
.ZoomX
;
1674 const GLfloat y1
= y
+ height
* ctx
->Pixel
.ZoomY
;
1675 const GLfloat z
= ctx
->Current
.RasterPos
[2];
1685 verts
[1].s
= tex
->Sright
;
1690 verts
[2].s
= tex
->Sright
;
1691 verts
[2].t
= tex
->Ttop
;
1696 verts
[3].t
= tex
->Ttop
;
1699 if (drawpix
->ArrayObj
== 0) {
1700 /* one-time setup: create vertex array object */
1701 _mesa_GenVertexArrays(1, &drawpix
->ArrayObj
);
1703 _mesa_BindVertexArray(drawpix
->ArrayObj
);
1705 /* create vertex array buffer */
1706 _mesa_GenBuffersARB(1, &vbo
);
1707 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, vbo
);
1708 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1709 verts
, GL_DYNAMIC_DRAW_ARB
);
1711 /* setup vertex arrays */
1712 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1713 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1714 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1715 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1717 /* set given unpack params */
1718 ctx
->Unpack
= *unpack
;
1720 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1722 if (_mesa_is_stencil_format(format
)) {
1723 /* Drawing stencil */
1726 if (!drawpix
->StencilFP
)
1727 init_draw_stencil_pixels(ctx
);
1729 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1730 GL_ALPHA
, type
, pixels
);
1732 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1734 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1736 /* set all stencil bits to 0 */
1737 _mesa_StencilOp(GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1738 _mesa_StencilFunc(GL_ALWAYS
, 0, 255);
1739 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1741 /* set stencil bits to 1 where needed */
1742 _mesa_StencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
1744 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
1745 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
1747 for (bit
= 0; bit
< ctx
->Visual
.stencilBits
; bit
++) {
1748 const GLuint mask
= 1 << bit
;
1749 if (mask
& origStencilMask
) {
1750 _mesa_StencilFunc(GL_ALWAYS
, mask
, mask
);
1751 _mesa_StencilMask(mask
);
1753 _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
1754 255.0 / mask
, 0.5, 0.0, 0.0);
1756 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1760 else if (_mesa_is_depth_format(format
)) {
1762 if (!drawpix
->DepthFP
)
1763 init_draw_depth_pixels(ctx
);
1765 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
1766 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
1768 /* polygon color = current raster color */
1769 _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
1770 ctx
->Current
.RasterColor
);
1772 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1773 format
, type
, pixels
);
1775 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1779 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1780 format
, type
, pixels
);
1781 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1784 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1786 _mesa_DeleteBuffersARB(1, &vbo
);
1788 /* restore unpack params */
1789 ctx
->Unpack
= unpackSave
;
1791 _mesa_meta_end(ctx
);
1796 * Do glBitmap with a alpha texture quad. Use the alpha test to
1797 * cull the 'off' bits. If alpha test is already enabled, fall back
1798 * to swrast (should be a rare case).
1799 * A bitmap cache as in the gallium/mesa state tracker would
1800 * improve performance a lot.
1803 _mesa_meta_Bitmap(GLcontext
*ctx
,
1804 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1805 const struct gl_pixelstore_attrib
*unpack
,
1806 const GLubyte
*bitmap1
)
1808 struct bitmap_state
*bitmap
= &ctx
->Meta
->Bitmap
;
1809 struct temp_texture
*tex
= get_bitmap_temp_texture(ctx
);
1810 const GLenum texIntFormat
= GL_ALPHA
;
1811 const struct gl_pixelstore_attrib unpackSave
= *unpack
;
1813 GLfloat x
, y
, z
, s
, t
, r
, g
, b
, a
;
1815 struct vertex verts
[4];
1820 * Check if swrast fallback is needed.
1822 if (ctx
->_ImageTransferState
||
1823 ctx
->Color
.AlphaEnabled
||
1825 ctx
->Texture
._EnabledUnits
||
1826 width
> tex
->MaxSize
||
1827 height
> tex
->MaxSize
) {
1828 _swrast_Bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap1
);
1832 /* Most GL state applies to glBitmap (like blending, stencil, etc),
1833 * but a there's a few things we need to override:
1835 _mesa_meta_begin(ctx
, (META_ALPHA_TEST
|
1837 META_RASTERIZATION
|
1844 if (bitmap
->ArrayObj
== 0) {
1845 /* one-time setup */
1847 /* create vertex array object */
1848 _mesa_GenVertexArraysAPPLE(1, &bitmap
->ArrayObj
);
1849 _mesa_BindVertexArrayAPPLE(bitmap
->ArrayObj
);
1851 /* create vertex array buffer */
1852 _mesa_GenBuffersARB(1, &bitmap
->VBO
);
1853 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, bitmap
->VBO
);
1854 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1855 NULL
, GL_DYNAMIC_DRAW_ARB
);
1857 /* setup vertex arrays */
1858 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1859 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1860 _mesa_ColorPointer(4, GL_FLOAT
, sizeof(struct vertex
), OFFSET(r
));
1861 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1862 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1863 _mesa_EnableClientState(GL_COLOR_ARRAY
);
1866 _mesa_BindVertexArray(bitmap
->ArrayObj
);
1867 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, bitmap
->VBO
);
1870 newTex
= alloc_texture(tex
, width
, height
, texIntFormat
);
1872 /* vertex positions, texcoords, colors (after texture allocation!) */
1874 const GLfloat x0
= (GLfloat
) x
;
1875 const GLfloat y0
= (GLfloat
) y
;
1876 const GLfloat x1
= (GLfloat
) (x
+ width
);
1877 const GLfloat y1
= (GLfloat
) (y
+ height
);
1878 const GLfloat z
= ctx
->Current
.RasterPos
[2];
1889 verts
[1].s
= tex
->Sright
;
1894 verts
[2].s
= tex
->Sright
;
1895 verts
[2].t
= tex
->Ttop
;
1900 verts
[3].t
= tex
->Ttop
;
1902 for (i
= 0; i
< 4; i
++) {
1903 verts
[i
].r
= ctx
->Current
.RasterColor
[0];
1904 verts
[i
].g
= ctx
->Current
.RasterColor
[1];
1905 verts
[i
].b
= ctx
->Current
.RasterColor
[2];
1906 verts
[i
].a
= ctx
->Current
.RasterColor
[3];
1909 /* upload new vertex data */
1910 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1913 bitmap1
= _mesa_map_pbo_source(ctx
, &unpackSave
, bitmap1
);
1917 bitmap8
= (GLubyte
*) _mesa_calloc(width
* height
);
1919 _mesa_expand_bitmap(width
, height
, &unpackSave
, bitmap1
,
1920 bitmap8
, width
, 0xff);
1922 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1924 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_TRUE
);
1925 _mesa_AlphaFunc(GL_GREATER
, 0.0);
1927 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1928 GL_ALPHA
, GL_UNSIGNED_BYTE
, bitmap8
);
1930 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1932 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1934 _mesa_free(bitmap8
);
1937 _mesa_unmap_pbo_source(ctx
, &unpackSave
);
1939 _mesa_meta_end(ctx
);
1944 * Called via ctx->Driver.GenerateMipmap()
1945 * Note: texture borders and 3D texture support not yet complete.
1948 _mesa_meta_GenerateMipmap(GLcontext
*ctx
, GLenum target
,
1949 struct gl_texture_object
*texObj
)
1951 struct gen_mipmap_state
*mipmap
= &ctx
->Meta
->Mipmap
;
1953 GLfloat x
, y
, s
, t
, r
;
1955 struct vertex verts
[4];
1956 const GLuint baseLevel
= texObj
->BaseLevel
;
1957 const GLuint maxLevel
= texObj
->MaxLevel
;
1958 const GLenum minFilterSave
= texObj
->MinFilter
;
1959 const GLenum magFilterSave
= texObj
->MagFilter
;
1960 const GLint baseLevelSave
= texObj
->BaseLevel
;
1961 const GLint maxLevelSave
= texObj
->MaxLevel
;
1962 const GLboolean genMipmapSave
= texObj
->GenerateMipmap
;
1963 const GLenum wrapSSave
= texObj
->WrapS
;
1964 const GLenum wrapTSave
= texObj
->WrapT
;
1965 const GLenum wrapRSave
= texObj
->WrapR
;
1966 const GLuint fboSave
= ctx
->DrawBuffer
->Name
;
1971 /* check for fallbacks */
1972 if (!ctx
->Extensions
.EXT_framebuffer_object
||
1973 target
== GL_TEXTURE_3D
) {
1974 _mesa_generate_mipmap(ctx
, target
, texObj
);
1978 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1979 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
) {
1980 faceTarget
= target
;
1981 target
= GL_TEXTURE_CUBE_MAP
;
1984 faceTarget
= target
;
1987 _mesa_meta_begin(ctx
, META_ALL
);
1989 if (mipmap
->ArrayObj
== 0) {
1990 /* one-time setup */
1992 /* create vertex array object */
1993 _mesa_GenVertexArraysAPPLE(1, &mipmap
->ArrayObj
);
1994 _mesa_BindVertexArrayAPPLE(mipmap
->ArrayObj
);
1996 /* create vertex array buffer */
1997 _mesa_GenBuffersARB(1, &mipmap
->VBO
);
1998 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, mipmap
->VBO
);
1999 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
2000 NULL
, GL_DYNAMIC_DRAW_ARB
);
2002 /* setup vertex arrays */
2003 _mesa_VertexPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
2004 _mesa_TexCoordPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
2005 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
2006 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
2009 _mesa_BindVertexArray(mipmap
->ArrayObj
);
2010 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, mipmap
->VBO
);
2014 /* Bind the new renderbuffer to the color attachment point. */
2015 _mesa_GenFramebuffersEXT(1, &mipmap
->FBO
);
2018 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, mipmap
->FBO
);
2020 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2021 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2022 _mesa_TexParameteri(target
, GL_GENERATE_MIPMAP
, GL_FALSE
);
2023 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2024 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2025 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2027 _mesa_set_enable(ctx
, target
, GL_TRUE
);
2029 /* setup texcoords once (XXX what about border?) */
2030 switch (faceTarget
) {
2052 static const GLfloat st
[4][2] = {
2053 {0.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 1.0f
}
2057 /* loop over quad verts */
2058 for (i
= 0; i
< 4; i
++) {
2059 /* Compute sc = +/-scale and tc = +/-scale.
2060 * Not +/-1 to avoid cube face selection ambiguity near the edges,
2061 * though that can still sometimes happen with this scale factor...
2063 const GLfloat scale
= 0.9999f
;
2064 const GLfloat sc
= (2.0f
* st
[i
][0] - 1.0f
) * scale
;
2065 const GLfloat tc
= (2.0f
* st
[i
][1] - 1.0f
) * scale
;
2067 switch (faceTarget
) {
2068 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2073 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2078 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2083 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2088 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2093 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2105 _mesa_set_enable(ctx
, target
, GL_TRUE
);
2107 /* texture is already locked, unlock now */
2108 _mesa_unlock_texture(ctx
, texObj
);
2110 for (dstLevel
= baseLevel
+ 1; dstLevel
<= maxLevel
; dstLevel
++) {
2111 const struct gl_texture_image
*srcImage
;
2112 const GLuint srcLevel
= dstLevel
- 1;
2113 GLsizei srcWidth
, srcHeight
, srcDepth
;
2114 GLsizei dstWidth
, dstHeight
, dstDepth
;
2117 srcImage
= _mesa_select_tex_image(ctx
, texObj
, faceTarget
, srcLevel
);
2118 assert(srcImage
->Border
== 0); /* XXX we can fix this */
2120 /* src size w/out border */
2121 srcWidth
= srcImage
->Width
- 2 * border
;
2122 srcHeight
= srcImage
->Height
- 2 * border
;
2123 srcDepth
= srcImage
->Depth
- 2 * border
;
2125 /* new dst size w/ border */
2126 dstWidth
= MAX2(1, srcWidth
/ 2) + 2 * border
;
2127 dstHeight
= MAX2(1, srcHeight
/ 2) + 2 * border
;
2128 dstDepth
= MAX2(1, srcDepth
/ 2) + 2 * border
;
2130 if (dstWidth
== srcImage
->Width
&&
2131 dstHeight
== srcImage
->Height
&&
2132 dstDepth
== srcImage
->Depth
) {
2137 /* Create empty dest image */
2138 if (target
== GL_TEXTURE_1D
) {
2139 _mesa_TexImage1D(target
, dstLevel
, srcImage
->InternalFormat
,
2141 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2143 else if (target
== GL_TEXTURE_3D
) {
2144 _mesa_TexImage3D(target
, dstLevel
, srcImage
->InternalFormat
,
2145 dstWidth
, dstHeight
, dstDepth
, border
,
2146 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2150 _mesa_TexImage2D(faceTarget
, dstLevel
, srcImage
->InternalFormat
,
2151 dstWidth
, dstHeight
, border
,
2152 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2154 if (target
== GL_TEXTURE_CUBE_MAP
) {
2155 /* If texturing from a cube, we need to make sure all src faces
2156 * have been defined (even if we're not sampling from them.)
2157 * Otherwise the texture object will be 'incomplete' and
2158 * texturing from it will not be allowed.
2161 for (face
= 0; face
< 6; face
++) {
2162 if (!texObj
->Image
[face
][srcLevel
] ||
2163 texObj
->Image
[face
][srcLevel
]->Width
!= srcWidth
) {
2164 _mesa_TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
,
2165 srcLevel
, srcImage
->InternalFormat
,
2166 srcWidth
, srcHeight
, border
,
2167 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2173 /* setup vertex positions */
2177 verts
[1].x
= (GLfloat
) dstWidth
;
2179 verts
[2].x
= (GLfloat
) dstWidth
;
2180 verts
[2].y
= (GLfloat
) dstHeight
;
2182 verts
[3].y
= (GLfloat
) dstHeight
;
2184 /* upload new vertex data */
2185 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
2188 /* limit sampling to src level */
2189 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, srcLevel
);
2190 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, srcLevel
);
2192 /* Set to draw into the current dstLevel */
2193 if (target
== GL_TEXTURE_1D
) {
2194 _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT
,
2195 GL_COLOR_ATTACHMENT0_EXT
,
2200 else if (target
== GL_TEXTURE_3D
) {
2201 GLint zoffset
= 0; /* XXX unfinished */
2202 _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT
,
2203 GL_COLOR_ATTACHMENT0_EXT
,
2210 _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
2211 GL_COLOR_ATTACHMENT0_EXT
,
2217 _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0_EXT
);
2220 status
= _mesa_CheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
2221 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2226 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2229 _mesa_lock_texture(ctx
, texObj
); /* relock */
2231 _mesa_meta_end(ctx
);
2233 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, minFilterSave
);
2234 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, magFilterSave
);
2235 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, baseLevelSave
);
2236 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, maxLevelSave
);
2237 _mesa_TexParameteri(target
, GL_GENERATE_MIPMAP
, genMipmapSave
);
2238 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, wrapSSave
);
2239 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, wrapTSave
);
2240 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, wrapRSave
);
2242 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fboSave
);
2247 * Determine the GL data type to use for the temporary image read with
2248 * ReadPixels() and passed to Tex[Sub]Image().
2251 get_temp_image_type(GLcontext
*ctx
, GLenum baseFormat
)
2253 switch (baseFormat
) {
2258 case GL_LUMINANCE_ALPHA
:
2260 if (ctx
->DrawBuffer
->Visual
.redBits
<= 8)
2261 return GL_UNSIGNED_BYTE
;
2262 else if (ctx
->DrawBuffer
->Visual
.redBits
<= 8)
2263 return GL_UNSIGNED_SHORT
;
2266 case GL_DEPTH_COMPONENT
:
2267 return GL_UNSIGNED_INT
;
2268 case GL_DEPTH_STENCIL
:
2269 return GL_UNSIGNED_INT_24_8
;
2271 _mesa_problem(ctx
, "Unexpected format in get_temp_image_type()");
2278 * Helper for _mesa_meta_CopyTexImage1/2D() functions.
2279 * Have to be careful with locking and meta state for pixel transfer.
2282 copy_tex_image(GLcontext
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2283 GLenum internalFormat
, GLint x
, GLint y
,
2284 GLsizei width
, GLsizei height
, GLint border
)
2286 struct gl_texture_unit
*texUnit
;
2287 struct gl_texture_object
*texObj
;
2288 struct gl_texture_image
*texImage
;
2289 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2290 GLenum format
, type
;
2294 texUnit
= _mesa_get_current_tex_unit(ctx
);
2295 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2296 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2298 format
= _mesa_base_tex_format(ctx
, internalFormat
);
2299 type
= get_temp_image_type(ctx
, format
);
2300 bpp
= _mesa_bytes_per_pixel(format
, type
);
2302 _mesa_problem(ctx
, "Bad bpp in meta copy_tex_image()");
2307 * Alloc image buffer (XXX could use a PBO)
2309 buf
= _mesa_malloc(width
* height
* bpp
);
2311 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2315 _mesa_unlock_texture(ctx
, texObj
); /* need to unlock first */
2318 * Read image from framebuffer (disable pixel transfer ops)
2320 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2321 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2322 format
, type
, &ctx
->Pack
, buf
);
2323 _mesa_meta_end(ctx
);
2326 * Prepare for new texture image size/data
2328 #if FEATURE_convolve
2329 if (_mesa_is_color_format(internalFormat
)) {
2330 _mesa_adjust_image_for_convolution(ctx
, 2,
2331 &postConvWidth
, &postConvHeight
);
2335 if (texImage
->Data
) {
2336 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
2339 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2340 postConvWidth
, postConvHeight
, 1,
2341 border
, internalFormat
);
2344 * Store texture data (with pixel transfer ops)
2346 _mesa_meta_begin(ctx
, META_PIXEL_STORE
);
2348 _mesa_update_state(ctx
); /* to update pixel transfer state */
2350 if (target
== GL_TEXTURE_1D
) {
2351 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2352 width
, border
, format
, type
,
2353 buf
, &ctx
->Unpack
, texObj
, texImage
);
2356 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2357 width
, height
, border
, format
, type
,
2358 buf
, &ctx
->Unpack
, texObj
, texImage
);
2360 _mesa_meta_end(ctx
);
2362 _mesa_lock_texture(ctx
, texObj
); /* re-lock */
2369 _mesa_meta_CopyTexImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
2370 GLenum internalFormat
, GLint x
, GLint y
,
2371 GLsizei width
, GLint border
)
2373 copy_tex_image(ctx
, 1, target
, level
, internalFormat
, x
, y
,
2379 _mesa_meta_CopyTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
2380 GLenum internalFormat
, GLint x
, GLint y
,
2381 GLsizei width
, GLsizei height
, GLint border
)
2383 copy_tex_image(ctx
, 2, target
, level
, internalFormat
, x
, y
,
2384 width
, height
, border
);
2390 * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
2391 * Have to be careful with locking and meta state for pixel transfer.
2394 copy_tex_sub_image(GLcontext
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2395 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2397 GLsizei width
, GLsizei height
)
2399 struct gl_texture_unit
*texUnit
;
2400 struct gl_texture_object
*texObj
;
2401 struct gl_texture_image
*texImage
;
2402 GLenum format
, type
;
2406 texUnit
= _mesa_get_current_tex_unit(ctx
);
2407 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2408 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2410 format
= _mesa_get_format_base_format(texImage
->TexFormat
);
2411 type
= get_temp_image_type(ctx
, format
);
2412 bpp
= _mesa_bytes_per_pixel(format
, type
);
2414 _mesa_problem(ctx
, "Bad bpp in meta copy_tex_sub_image()");
2419 * Alloc image buffer (XXX could use a PBO)
2421 buf
= _mesa_malloc(width
* height
* bpp
);
2423 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%uD", dims
);
2427 _mesa_unlock_texture(ctx
, texObj
); /* need to unlock first */
2430 * Read image from framebuffer (disable pixel transfer ops)
2432 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2433 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2434 format
, type
, &ctx
->Pack
, buf
);
2435 _mesa_meta_end(ctx
);
2437 _mesa_update_state(ctx
); /* to update pixel transfer state */
2440 * Store texture data (with pixel transfer ops)
2442 _mesa_meta_begin(ctx
, META_PIXEL_STORE
);
2443 if (target
== GL_TEXTURE_1D
) {
2444 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
,
2445 width
, format
, type
, buf
,
2446 &ctx
->Unpack
, texObj
, texImage
);
2448 else if (target
== GL_TEXTURE_3D
) {
2449 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
, xoffset
, yoffset
, zoffset
,
2450 width
, height
, 1, format
, type
, buf
,
2451 &ctx
->Unpack
, texObj
, texImage
);
2454 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2455 width
, height
, format
, type
, buf
,
2456 &ctx
->Unpack
, texObj
, texImage
);
2458 _mesa_meta_end(ctx
);
2460 _mesa_lock_texture(ctx
, texObj
); /* re-lock */
2467 _mesa_meta_CopyTexSubImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
2469 GLint x
, GLint y
, GLsizei width
)
2471 copy_tex_sub_image(ctx
, 1, target
, level
, xoffset
, 0, 0,
2477 _mesa_meta_CopyTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
2478 GLint xoffset
, GLint yoffset
,
2480 GLsizei width
, GLsizei height
)
2482 copy_tex_sub_image(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2483 x
, y
, width
, height
);
2488 _mesa_meta_CopyTexSubImage3D(GLcontext
*ctx
, GLenum target
, GLint level
,
2489 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2491 GLsizei width
, GLsizei height
)
2493 copy_tex_sub_image(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2494 x
, y
, width
, height
);
2499 _mesa_meta_CopyColorTable(GLcontext
*ctx
,
2500 GLenum target
, GLenum internalformat
,
2501 GLint x
, GLint y
, GLsizei width
)
2505 buf
= (GLfloat
*) _mesa_malloc(width
* 4 * sizeof(GLfloat
));
2507 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyColorTable");
2512 * Read image from framebuffer (disable pixel transfer ops)
2514 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2515 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, 1,
2516 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2518 _mesa_ColorTable(target
, internalformat
, width
, GL_RGBA
, GL_FLOAT
, buf
);
2520 _mesa_meta_end(ctx
);
2527 _mesa_meta_CopyColorSubTable(GLcontext
*ctx
,GLenum target
, GLsizei start
,
2528 GLint x
, GLint y
, GLsizei width
)
2532 buf
= (GLfloat
*) _mesa_malloc(width
* 4 * sizeof(GLfloat
));
2534 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyColorSubTable");
2539 * Read image from framebuffer (disable pixel transfer ops)
2541 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2542 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, 1,
2543 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2545 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, GL_FLOAT
, buf
);
2547 _mesa_meta_end(ctx
);
2554 _mesa_meta_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
2555 GLenum internalFormat
,
2556 GLint x
, GLint y
, GLsizei width
)
2560 buf
= (GLfloat
*) _mesa_malloc(width
* 4 * sizeof(GLfloat
));
2562 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyConvolutionFilter2D");
2567 * Read image from framebuffer (disable pixel transfer ops)
2569 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2570 _mesa_update_state(ctx
);
2571 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, 1,
2572 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2574 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
2575 GL_RGBA
, GL_FLOAT
, buf
);
2577 _mesa_meta_end(ctx
);
2584 _mesa_meta_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
2585 GLenum internalFormat
, GLint x
, GLint y
,
2586 GLsizei width
, GLsizei height
)
2590 buf
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
2592 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyConvolutionFilter2D");
2597 * Read image from framebuffer (disable pixel transfer ops)
2599 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2600 _mesa_update_state(ctx
);
2602 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2603 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2605 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
2606 GL_RGBA
, GL_FLOAT
, buf
);
2608 _mesa_meta_end(ctx
);