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/image.h"
47 #include "main/macros.h"
48 #include "main/matrix.h"
49 #include "main/mipmap.h"
50 #include "main/polygon.h"
51 #include "main/readpix.h"
52 #include "main/scissor.h"
53 #include "main/shaders.h"
54 #include "main/state.h"
55 #include "main/stencil.h"
56 #include "main/texobj.h"
57 #include "main/texenv.h"
58 #include "main/teximage.h"
59 #include "main/texparam.h"
60 #include "main/texstate.h"
61 #include "main/varray.h"
62 #include "main/viewport.h"
63 #include "shader/program.h"
64 #include "shader/arbprogram.h"
65 #include "swrast/swrast.h"
66 #include "drivers/common/meta.h"
69 /** Return offset in bytes of the field within a vertex struct */
70 #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
74 * Flags passed to _mesa_meta_begin().
78 #define META_ALPHA_TEST 0x1
79 #define META_BLEND 0x2 /**< includes logicop */
80 #define META_COLOR_MASK 0x4
81 #define META_DEPTH_TEST 0x8
83 #define META_PIXEL_STORE 0x20
84 #define META_PIXEL_TRANSFER 0x40
85 #define META_RASTERIZATION 0x80
86 #define META_SCISSOR 0x100
87 #define META_SHADER 0x200
88 #define META_STENCIL_TEST 0x400
89 #define META_TRANSFORM 0x800 /**< modelview, projection, clip planes */
90 #define META_TEXTURE 0x1000
91 #define META_VERTEX 0x2000
92 #define META_VIEWPORT 0x4000
97 * State which we may save/restore across meta ops.
98 * XXX this may be incomplete...
102 GLbitfield SavedState
; /**< bitmask of META_* flags */
104 /** META_ALPHA_TEST */
105 GLboolean AlphaEnabled
;
108 GLboolean BlendEnabled
;
109 GLboolean ColorLogicOpEnabled
;
111 /** META_COLOR_MASK */
112 GLubyte ColorMask
[4];
114 /** META_DEPTH_TEST */
115 struct gl_depthbuffer_attrib Depth
;
120 /** META_PIXEL_STORE */
121 struct gl_pixelstore_attrib Pack
, Unpack
;
123 /** META_PIXEL_TRANSFER */
124 GLfloat RedBias
, RedScale
;
125 GLfloat GreenBias
, GreenScale
;
126 GLfloat BlueBias
, BlueScale
;
127 GLfloat AlphaBias
, AlphaScale
;
128 GLfloat DepthBias
, DepthScale
;
129 GLboolean MapColorFlag
;
130 GLboolean Convolution1DEnabled
;
131 GLboolean Convolution2DEnabled
;
132 GLboolean Separable2DEnabled
;
134 /** META_RASTERIZATION */
135 GLenum FrontPolygonMode
, BackPolygonMode
;
136 GLboolean PolygonOffset
;
137 GLboolean PolygonSmooth
;
138 GLboolean PolygonStipple
;
139 GLboolean PolygonCull
;
142 struct gl_scissor_attrib Scissor
;
145 GLboolean VertexProgramEnabled
;
146 struct gl_vertex_program
*VertexProgram
;
147 GLboolean FragmentProgramEnabled
;
148 struct gl_fragment_program
*FragmentProgram
;
151 /** META_STENCIL_TEST */
152 struct gl_stencil_attrib Stencil
;
154 /** META_TRANSFORM */
156 GLfloat ModelviewMatrix
[16];
157 GLfloat ProjectionMatrix
[16];
158 GLfloat TextureMatrix
[16];
159 GLbitfield ClipPlanesEnabled
;
163 GLuint ClientActiveUnit
;
164 /** for unit[0] only */
165 struct gl_texture_object
*CurrentTexture
[NUM_TEXTURE_TARGETS
];
166 /** mask of TEXTURE_2D_BIT, etc */
167 GLbitfield TexEnabled
[MAX_TEXTURE_UNITS
];
168 GLbitfield TexGenEnabled
[MAX_TEXTURE_UNITS
];
169 GLuint EnvMode
; /* unit[0] only */
172 struct gl_array_object
*ArrayObj
;
173 struct gl_buffer_object
*ArrayBufferObj
;
176 GLint ViewportX
, ViewportY
, ViewportW
, ViewportH
;
177 GLclampd DepthNear
, DepthFar
;
179 /** Miscellaneous (always disabled) */
185 * Temporary texture used for glBlitFramebuffer, glDrawPixels, etc.
186 * This is currently shared by all the meta ops. But we could create a
187 * separate one for each of glDrawPixel, glBlitFramebuffer, glCopyPixels, etc.
192 GLenum Target
; /**< GL_TEXTURE_2D or GL_TEXTURE_RECTANGLE */
193 GLsizei MinSize
; /**< Min texture size to allocate */
194 GLsizei MaxSize
; /**< Max possible texture size */
195 GLboolean NPOT
; /**< Non-power of two size OK? */
196 GLsizei Width
, Height
; /**< Current texture size */
198 GLfloat Sright
, Ttop
; /**< right, top texcoords */
203 * State for glBlitFramebufer()
214 * State for glClear()
224 * State for glCopyPixels()
234 * State for glDrawPixels()
240 GLuint StencilFP
; /**< Fragment program for drawing stencil images */
241 GLuint DepthFP
; /**< Fragment program for drawing depth images */
246 * State for glBitmap()
252 struct temp_texture Tex
; /**< separate texture from other meta ops */
257 * State for _mesa_meta_generate_mipmap()
259 struct gen_mipmap_state
268 * All per-context meta state.
272 struct save_state Save
; /**< state saved during meta-ops */
274 struct temp_texture TempTex
;
276 struct blit_state Blit
; /**< For _mesa_meta_BlitFramebuffer() */
277 struct clear_state Clear
; /**< For _mesa_meta_Clear() */
278 struct copypix_state CopyPix
; /**< For _mesa_meta_CopyPixels() */
279 struct drawpix_state DrawPix
; /**< For _mesa_meta_DrawPixels() */
280 struct bitmap_state Bitmap
; /**< For _mesa_meta_Bitmap() */
281 struct gen_mipmap_state Mipmap
; /**< For _mesa_meta_GenerateMipmap() */
286 * Initialize meta-ops for a context.
287 * To be called once during context creation.
290 _mesa_meta_init(GLcontext
*ctx
)
294 ctx
->Meta
= CALLOC_STRUCT(gl_meta_state
);
299 * Free context meta-op state.
300 * To be called once during context destruction.
303 _mesa_meta_free(GLcontext
*ctx
)
305 struct gl_meta_state
*meta
= ctx
->Meta
;
307 if (_mesa_get_current_context()) {
308 /* if there's no current context, these textures, buffers, etc should
309 * still get freed by _mesa_free_context_data().
312 /* the temporary texture */
313 _mesa_DeleteTextures(1, &meta
->TempTex
.TexObj
);
315 /* glBlitFramebuffer */
316 _mesa_DeleteBuffersARB(1, & meta
->Blit
.VBO
);
317 _mesa_DeleteVertexArraysAPPLE(1, &meta
->Blit
.ArrayObj
);
318 _mesa_DeletePrograms(1, &meta
->Blit
.DepthFP
);
321 _mesa_DeleteBuffersARB(1, & meta
->Clear
.VBO
);
322 _mesa_DeleteVertexArraysAPPLE(1, &meta
->Clear
.ArrayObj
);
325 _mesa_DeleteBuffersARB(1, & meta
->CopyPix
.VBO
);
326 _mesa_DeleteVertexArraysAPPLE(1, &meta
->CopyPix
.ArrayObj
);
329 _mesa_DeleteVertexArraysAPPLE(1, &meta
->DrawPix
.ArrayObj
);
330 _mesa_DeletePrograms(1, &meta
->DrawPix
.DepthFP
);
331 _mesa_DeletePrograms(1, &meta
->DrawPix
.StencilFP
);
334 _mesa_DeleteBuffersARB(1, & meta
->Bitmap
.VBO
);
335 _mesa_DeleteVertexArraysAPPLE(1, &meta
->Bitmap
.ArrayObj
);
336 _mesa_DeleteTextures(1, &meta
->Bitmap
.Tex
.TexObj
);
339 _mesa_free(ctx
->Meta
);
345 * Enter meta state. This is like a light-weight version of glPushAttrib
346 * but it also resets most GL state back to default values.
348 * \param state bitmask of META_* flags indicating which attribute groups
349 * to save and reset to their defaults
352 _mesa_meta_begin(GLcontext
*ctx
, GLbitfield state
)
354 struct save_state
*save
= &ctx
->Meta
->Save
;
356 save
->SavedState
= state
;
358 if (state
& META_ALPHA_TEST
) {
359 save
->AlphaEnabled
= ctx
->Color
.AlphaEnabled
;
360 if (ctx
->Color
.AlphaEnabled
)
361 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_FALSE
);
364 if (state
& META_BLEND
) {
365 save
->BlendEnabled
= ctx
->Color
.BlendEnabled
;
366 if (ctx
->Color
.BlendEnabled
)
367 _mesa_set_enable(ctx
, GL_BLEND
, GL_FALSE
);
368 save
->ColorLogicOpEnabled
= ctx
->Color
.ColorLogicOpEnabled
;
369 if (ctx
->Color
.ColorLogicOpEnabled
)
370 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, GL_FALSE
);
373 if (state
& META_COLOR_MASK
) {
374 COPY_4V(save
->ColorMask
, ctx
->Color
.ColorMask
);
375 if (!ctx
->Color
.ColorMask
[0] ||
376 !ctx
->Color
.ColorMask
[1] ||
377 !ctx
->Color
.ColorMask
[2] ||
378 !ctx
->Color
.ColorMask
[3])
379 _mesa_ColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
382 if (state
& META_DEPTH_TEST
) {
383 save
->Depth
= ctx
->Depth
; /* struct copy */
385 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_FALSE
);
388 if (state
& META_FOG
) {
389 save
->Fog
= ctx
->Fog
.Enabled
;
390 if (ctx
->Fog
.Enabled
)
391 _mesa_set_enable(ctx
, GL_FOG
, GL_FALSE
);
394 if (state
& META_PIXEL_STORE
) {
395 save
->Pack
= ctx
->Pack
;
396 save
->Unpack
= ctx
->Unpack
;
397 ctx
->Pack
= ctx
->DefaultPacking
;
398 ctx
->Unpack
= ctx
->DefaultPacking
;
401 if (state
& META_PIXEL_TRANSFER
) {
402 save
->RedScale
= ctx
->Pixel
.RedScale
;
403 save
->RedBias
= ctx
->Pixel
.RedBias
;
404 save
->GreenScale
= ctx
->Pixel
.GreenScale
;
405 save
->GreenBias
= ctx
->Pixel
.GreenBias
;
406 save
->BlueScale
= ctx
->Pixel
.BlueScale
;
407 save
->BlueBias
= ctx
->Pixel
.BlueBias
;
408 save
->AlphaScale
= ctx
->Pixel
.AlphaScale
;
409 save
->AlphaBias
= ctx
->Pixel
.AlphaBias
;
410 save
->MapColorFlag
= ctx
->Pixel
.MapColorFlag
;
411 save
->Convolution1DEnabled
= ctx
->Pixel
.Convolution1DEnabled
;
412 save
->Convolution2DEnabled
= ctx
->Pixel
.Convolution2DEnabled
;
413 save
->Separable2DEnabled
= ctx
->Pixel
.Separable2DEnabled
;
414 ctx
->Pixel
.RedScale
= 1.0F
;
415 ctx
->Pixel
.RedBias
= 0.0F
;
416 ctx
->Pixel
.GreenScale
= 1.0F
;
417 ctx
->Pixel
.GreenBias
= 0.0F
;
418 ctx
->Pixel
.BlueScale
= 1.0F
;
419 ctx
->Pixel
.BlueBias
= 0.0F
;
420 ctx
->Pixel
.AlphaScale
= 1.0F
;
421 ctx
->Pixel
.AlphaBias
= 0.0F
;
422 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
423 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
424 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
425 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
427 ctx
->NewState
|=_NEW_PIXEL
;
430 if (state
& META_RASTERIZATION
) {
431 save
->FrontPolygonMode
= ctx
->Polygon
.FrontMode
;
432 save
->BackPolygonMode
= ctx
->Polygon
.BackMode
;
433 save
->PolygonOffset
= ctx
->Polygon
.OffsetFill
;
434 save
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
435 save
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
436 save
->PolygonCull
= ctx
->Polygon
.CullFlag
;
437 _mesa_PolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
438 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, GL_FALSE
);
439 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, GL_FALSE
);
440 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, GL_FALSE
);
441 _mesa_set_enable(ctx
, GL_CULL_FACE
, GL_FALSE
);
444 if (state
& META_SCISSOR
) {
445 save
->Scissor
= ctx
->Scissor
; /* struct copy */
448 if (state
& META_SHADER
) {
449 if (ctx
->Extensions
.ARB_vertex_program
) {
450 save
->VertexProgramEnabled
= ctx
->VertexProgram
.Enabled
;
451 save
->VertexProgram
= ctx
->VertexProgram
.Current
;
452 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
, GL_FALSE
);
455 if (ctx
->Extensions
.ARB_fragment_program
) {
456 save
->FragmentProgramEnabled
= ctx
->FragmentProgram
.Enabled
;
457 save
->FragmentProgram
= ctx
->FragmentProgram
.Current
;
458 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_FALSE
);
461 if (ctx
->Extensions
.ARB_shader_objects
) {
462 save
->Shader
= ctx
->Shader
.CurrentProgram
?
463 ctx
->Shader
.CurrentProgram
->Name
: 0;
464 _mesa_UseProgramObjectARB(0);
468 if (state
& META_STENCIL_TEST
) {
469 save
->Stencil
= ctx
->Stencil
; /* struct copy */
470 if (ctx
->Stencil
.Enabled
)
471 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_FALSE
);
472 /* NOTE: other stencil state not reset */
475 if (state
& META_TEXTURE
) {
478 save
->ActiveUnit
= ctx
->Texture
.CurrentUnit
;
479 save
->ClientActiveUnit
= ctx
->Array
.ActiveTexture
;
480 save
->EnvMode
= ctx
->Texture
.Unit
[0].EnvMode
;
482 /* Disable all texture units */
483 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
484 save
->TexEnabled
[u
] = ctx
->Texture
.Unit
[u
].Enabled
;
485 save
->TexGenEnabled
[u
] = ctx
->Texture
.Unit
[u
].TexGenEnabled
;
486 if (ctx
->Texture
.Unit
[u
].Enabled
||
487 ctx
->Texture
.Unit
[u
].TexGenEnabled
) {
488 _mesa_ActiveTextureARB(GL_TEXTURE0
+ u
);
489 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
490 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
491 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
492 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
493 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE
, GL_FALSE
);
494 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
495 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
496 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
497 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
501 /* save current texture objects for unit[0] only */
502 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
503 _mesa_reference_texobj(&save
->CurrentTexture
[tgt
],
504 ctx
->Texture
.Unit
[0].CurrentTex
[tgt
]);
507 /* set defaults for unit[0] */
508 _mesa_ActiveTextureARB(GL_TEXTURE0
);
509 _mesa_ClientActiveTextureARB(GL_TEXTURE0
);
510 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
513 if (state
& META_TRANSFORM
) {
514 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
515 _mesa_memcpy(save
->ModelviewMatrix
, ctx
->ModelviewMatrixStack
.Top
->m
,
516 16 * sizeof(GLfloat
));
517 _mesa_memcpy(save
->ProjectionMatrix
, ctx
->ProjectionMatrixStack
.Top
->m
,
518 16 * sizeof(GLfloat
));
519 _mesa_memcpy(save
->TextureMatrix
, ctx
->TextureMatrixStack
[0].Top
->m
,
520 16 * sizeof(GLfloat
));
521 save
->MatrixMode
= ctx
->Transform
.MatrixMode
;
522 /* set 1:1 vertex:pixel coordinate transform */
523 _mesa_ActiveTextureARB(GL_TEXTURE0
);
524 _mesa_MatrixMode(GL_TEXTURE
);
525 _mesa_LoadIdentity();
526 _mesa_ActiveTextureARB(GL_TEXTURE0
+ activeTexture
);
527 _mesa_MatrixMode(GL_MODELVIEW
);
528 _mesa_LoadIdentity();
529 _mesa_MatrixMode(GL_PROJECTION
);
530 _mesa_LoadIdentity();
531 _mesa_Ortho(0.0F
, ctx
->DrawBuffer
->Width
,
532 0.0F
, ctx
->DrawBuffer
->Height
,
534 save
->ClipPlanesEnabled
= ctx
->Transform
.ClipPlanesEnabled
;
535 if (ctx
->Transform
.ClipPlanesEnabled
) {
537 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
538 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
543 if (state
& META_VERTEX
) {
544 /* save vertex array object state */
545 _mesa_reference_array_object(ctx
, &save
->ArrayObj
,
546 ctx
->Array
.ArrayObj
);
547 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
,
548 ctx
->Array
.ArrayBufferObj
);
549 /* set some default state? */
552 if (state
& META_VIEWPORT
) {
553 /* save viewport state */
554 save
->ViewportX
= ctx
->Viewport
.X
;
555 save
->ViewportY
= ctx
->Viewport
.Y
;
556 save
->ViewportW
= ctx
->Viewport
.Width
;
557 save
->ViewportH
= ctx
->Viewport
.Height
;
558 /* set viewport to match window size */
559 if (ctx
->Viewport
.X
!= 0 ||
560 ctx
->Viewport
.Y
!= 0 ||
561 ctx
->Viewport
.Width
!= ctx
->DrawBuffer
->Width
||
562 ctx
->Viewport
.Height
!= ctx
->DrawBuffer
->Height
) {
563 _mesa_set_viewport(ctx
, 0, 0,
564 ctx
->DrawBuffer
->Width
, ctx
->DrawBuffer
->Height
);
566 /* save depth range state */
567 save
->DepthNear
= ctx
->Viewport
.Near
;
568 save
->DepthFar
= ctx
->Viewport
.Far
;
569 /* set depth range to default */
570 _mesa_DepthRange(0.0, 1.0);
575 save
->Lighting
= ctx
->Light
.Enabled
;
576 if (ctx
->Light
.Enabled
)
577 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_FALSE
);
583 * Leave meta state. This is like a light-weight version of glPopAttrib().
586 _mesa_meta_end(GLcontext
*ctx
)
588 struct save_state
*save
= &ctx
->Meta
->Save
;
589 const GLbitfield state
= save
->SavedState
;
591 if (state
& META_ALPHA_TEST
) {
592 if (ctx
->Color
.AlphaEnabled
!= save
->AlphaEnabled
)
593 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, save
->AlphaEnabled
);
596 if (state
& META_BLEND
) {
597 if (ctx
->Color
.BlendEnabled
!= save
->BlendEnabled
)
598 _mesa_set_enable(ctx
, GL_BLEND
, save
->BlendEnabled
);
599 if (ctx
->Color
.ColorLogicOpEnabled
!= save
->ColorLogicOpEnabled
)
600 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, save
->ColorLogicOpEnabled
);
603 if (state
& META_COLOR_MASK
) {
604 if (!TEST_EQ_4V(ctx
->Color
.ColorMask
, save
->ColorMask
))
605 _mesa_ColorMask(save
->ColorMask
[0], save
->ColorMask
[1],
606 save
->ColorMask
[2], save
->ColorMask
[3]);
609 if (state
& META_DEPTH_TEST
) {
610 if (ctx
->Depth
.Test
!= save
->Depth
.Test
)
611 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, save
->Depth
.Test
);
612 _mesa_DepthFunc(save
->Depth
.Func
);
613 _mesa_DepthMask(save
->Depth
.Mask
);
616 if (state
& META_FOG
) {
617 _mesa_set_enable(ctx
, GL_FOG
, save
->Fog
);
620 if (state
& META_PIXEL_STORE
) {
621 ctx
->Pack
= save
->Pack
;
622 ctx
->Unpack
= save
->Unpack
;
625 if (state
& META_PIXEL_TRANSFER
) {
626 ctx
->Pixel
.RedScale
= save
->RedScale
;
627 ctx
->Pixel
.RedBias
= save
->RedBias
;
628 ctx
->Pixel
.GreenScale
= save
->GreenScale
;
629 ctx
->Pixel
.GreenBias
= save
->GreenBias
;
630 ctx
->Pixel
.BlueScale
= save
->BlueScale
;
631 ctx
->Pixel
.BlueBias
= save
->BlueBias
;
632 ctx
->Pixel
.AlphaScale
= save
->AlphaScale
;
633 ctx
->Pixel
.AlphaBias
= save
->AlphaBias
;
634 ctx
->Pixel
.MapColorFlag
= save
->MapColorFlag
;
635 ctx
->Pixel
.Convolution1DEnabled
= save
->Convolution1DEnabled
;
636 ctx
->Pixel
.Convolution2DEnabled
= save
->Convolution2DEnabled
;
637 ctx
->Pixel
.Separable2DEnabled
= save
->Separable2DEnabled
;
639 ctx
->NewState
|=_NEW_PIXEL
;
642 if (state
& META_RASTERIZATION
) {
643 _mesa_PolygonMode(GL_FRONT
, save
->FrontPolygonMode
);
644 _mesa_PolygonMode(GL_BACK
, save
->BackPolygonMode
);
645 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, save
->PolygonStipple
);
646 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, save
->PolygonOffset
);
647 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, save
->PolygonSmooth
);
648 _mesa_set_enable(ctx
, GL_CULL_FACE
, save
->PolygonCull
);
651 if (state
& META_SCISSOR
) {
652 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, save
->Scissor
.Enabled
);
653 _mesa_Scissor(save
->Scissor
.X
, save
->Scissor
.Y
,
654 save
->Scissor
.Width
, save
->Scissor
.Height
);
657 if (state
& META_SHADER
) {
658 if (ctx
->Extensions
.ARB_vertex_program
) {
659 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
,
660 save
->VertexProgramEnabled
);
661 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
662 save
->VertexProgram
);
665 if (ctx
->Extensions
.ARB_fragment_program
) {
666 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
667 save
->FragmentProgramEnabled
);
668 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
669 save
->FragmentProgram
);
672 if (ctx
->Extensions
.ARB_shader_objects
) {
673 _mesa_UseProgramObjectARB(save
->Shader
);
677 if (state
& META_STENCIL_TEST
) {
678 const struct gl_stencil_attrib
*stencil
= &save
->Stencil
;
680 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
681 _mesa_ClearStencil(stencil
->Clear
);
682 if (ctx
->Extensions
.EXT_stencil_two_side
) {
683 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
684 stencil
->TestTwoSide
);
685 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
686 ? GL_BACK
: GL_FRONT
);
689 _mesa_StencilFuncSeparate(GL_FRONT
,
690 stencil
->Function
[0],
692 stencil
->ValueMask
[0]);
693 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
694 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
695 stencil
->ZFailFunc
[0],
696 stencil
->ZPassFunc
[0]);
698 _mesa_StencilFuncSeparate(GL_BACK
,
699 stencil
->Function
[1],
701 stencil
->ValueMask
[1]);
702 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
703 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
704 stencil
->ZFailFunc
[1],
705 stencil
->ZPassFunc
[1]);
708 if (state
& META_TEXTURE
) {
711 ASSERT(ctx
->Texture
.CurrentUnit
== 0);
713 /* restore texenv for unit[0] */
714 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, save
->EnvMode
);
716 /* restore texture objects for unit[0] only */
717 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
718 _mesa_reference_texobj(&ctx
->Texture
.Unit
[0].CurrentTex
[tgt
],
719 save
->CurrentTexture
[tgt
]);
722 /* Re-enable textures, texgen */
723 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
724 if (save
->TexEnabled
[u
]) {
725 _mesa_ActiveTextureARB(GL_TEXTURE0
+ u
);
727 if (save
->TexEnabled
[u
] & TEXTURE_1D_BIT
)
728 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, GL_TRUE
);
729 if (save
->TexEnabled
[u
] & TEXTURE_2D_BIT
)
730 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, GL_TRUE
);
731 if (save
->TexEnabled
[u
] & TEXTURE_3D_BIT
)
732 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, GL_TRUE
);
733 if (save
->TexEnabled
[u
] & TEXTURE_CUBE_BIT
)
734 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_TRUE
);
735 if (save
->TexEnabled
[u
] & TEXTURE_RECT_BIT
)
736 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE
, GL_TRUE
);
739 if (save
->TexGenEnabled
[u
]) {
740 _mesa_ActiveTextureARB(GL_TEXTURE0
+ u
);
742 if (save
->TexGenEnabled
[u
] & S_BIT
)
743 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, GL_TRUE
);
744 if (save
->TexGenEnabled
[u
] & T_BIT
)
745 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, GL_TRUE
);
746 if (save
->TexGenEnabled
[u
] & R_BIT
)
747 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, GL_TRUE
);
748 if (save
->TexGenEnabled
[u
] & Q_BIT
)
749 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, GL_TRUE
);
753 /* restore current unit state */
754 _mesa_ActiveTextureARB(GL_TEXTURE0
+ save
->ActiveUnit
);
755 _mesa_ClientActiveTextureARB(GL_TEXTURE0
+ save
->ClientActiveUnit
);
758 if (state
& META_TRANSFORM
) {
759 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
760 _mesa_ActiveTextureARB(GL_TEXTURE0
);
761 _mesa_MatrixMode(GL_TEXTURE
);
762 _mesa_LoadMatrixf(save
->TextureMatrix
);
763 _mesa_ActiveTextureARB(GL_TEXTURE0
+ activeTexture
);
765 _mesa_MatrixMode(GL_MODELVIEW
);
766 _mesa_LoadMatrixf(save
->ModelviewMatrix
);
768 _mesa_MatrixMode(GL_PROJECTION
);
769 _mesa_LoadMatrixf(save
->ProjectionMatrix
);
771 _mesa_MatrixMode(save
->MatrixMode
);
773 if (save
->ClipPlanesEnabled
) {
775 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
776 if (save
->ClipPlanesEnabled
& (1 << i
)) {
777 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
783 if (state
& META_VERTEX
) {
784 /* restore vertex buffer object */
785 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, save
->ArrayBufferObj
->Name
);
786 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
, NULL
);
788 /* restore vertex array object */
789 _mesa_BindVertexArray(save
->ArrayObj
->Name
);
790 _mesa_reference_array_object(ctx
, &save
->ArrayObj
, NULL
);
793 if (state
& META_VIEWPORT
) {
794 if (save
->ViewportX
!= ctx
->Viewport
.X
||
795 save
->ViewportY
!= ctx
->Viewport
.Y
||
796 save
->ViewportW
!= ctx
->Viewport
.Width
||
797 save
->ViewportH
!= ctx
->Viewport
.Height
) {
798 _mesa_set_viewport(ctx
, save
->ViewportX
, save
->ViewportY
,
799 save
->ViewportW
, save
->ViewportH
);
801 _mesa_DepthRange(save
->DepthNear
, save
->DepthFar
);
805 if (save
->Lighting
) {
806 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_TRUE
);
812 * One-time init for a temp_texture object.
813 * Choose tex target, compute max tex size, etc.
816 init_temp_texture(GLcontext
*ctx
, struct temp_texture
*tex
)
818 /* prefer texture rectangle */
819 if (ctx
->Extensions
.NV_texture_rectangle
) {
820 tex
->Target
= GL_TEXTURE_RECTANGLE
;
821 tex
->MaxSize
= ctx
->Const
.MaxTextureRectSize
;
825 /* use 2D texture, NPOT if possible */
826 tex
->Target
= GL_TEXTURE_2D
;
827 tex
->MaxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
828 tex
->NPOT
= ctx
->Extensions
.ARB_texture_non_power_of_two
;
830 tex
->MinSize
= 16; /* 16 x 16 at least */
831 assert(tex
->MaxSize
> 0);
833 _mesa_GenTextures(1, &tex
->TexObj
);
834 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
839 * Return pointer to temp_texture info for non-bitmap ops.
840 * This does some one-time init if needed.
842 static struct temp_texture
*
843 get_temp_texture(GLcontext
*ctx
)
845 struct temp_texture
*tex
= &ctx
->Meta
->TempTex
;
848 init_temp_texture(ctx
, tex
);
856 * Return pointer to temp_texture info for _mesa_meta_bitmap().
857 * We use a separate texture for bitmaps to reduce texture
858 * allocation/deallocation.
860 static struct temp_texture
*
861 get_bitmap_temp_texture(GLcontext
*ctx
)
863 struct temp_texture
*tex
= &ctx
->Meta
->Bitmap
.Tex
;
866 init_temp_texture(ctx
, tex
);
874 * Compute the width/height of texture needed to draw an image of the
875 * given size. Return a flag indicating whether the current texture
876 * can be re-used (glTexSubImage2D) or if a new texture needs to be
877 * allocated (glTexImage2D).
878 * Also, compute s/t texcoords for drawing.
880 * \return GL_TRUE if new texture is needed, GL_FALSE otherwise
883 alloc_texture(struct temp_texture
*tex
,
884 GLsizei width
, GLsizei height
, GLenum intFormat
)
886 GLboolean newTex
= GL_FALSE
;
888 ASSERT(width
<= tex
->MaxSize
);
889 ASSERT(height
<= tex
->MaxSize
);
891 if (width
> tex
->Width
||
892 height
> tex
->Height
||
893 intFormat
!= tex
->IntFormat
) {
894 /* alloc new texture (larger or different format) */
897 /* use non-power of two size */
898 tex
->Width
= MAX2(tex
->MinSize
, width
);
899 tex
->Height
= MAX2(tex
->MinSize
, height
);
902 /* find power of two size */
904 w
= h
= tex
->MinSize
;
913 tex
->IntFormat
= intFormat
;
918 /* compute texcoords */
919 if (tex
->Target
== GL_TEXTURE_RECTANGLE
) {
920 tex
->Sright
= (GLfloat
) width
;
921 tex
->Ttop
= (GLfloat
) height
;
924 tex
->Sright
= (GLfloat
) width
/ tex
->Width
;
925 tex
->Ttop
= (GLfloat
) height
/ tex
->Height
;
933 * Setup/load texture for glCopyPixels or glBlitFramebuffer.
936 setup_copypix_texture(struct temp_texture
*tex
,
938 GLint srcX
, GLint srcY
,
939 GLsizei width
, GLsizei height
, GLenum intFormat
,
942 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
943 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, filter
);
944 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, filter
);
945 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
947 /* copy framebuffer image to texture */
949 /* create new tex image */
950 if (tex
->Width
== width
&& tex
->Height
== height
) {
951 /* create new tex with framebuffer data */
952 _mesa_CopyTexImage2D(tex
->Target
, 0, tex
->IntFormat
,
953 srcX
, srcY
, width
, height
, 0);
956 /* create empty texture */
957 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
958 tex
->Width
, tex
->Height
, 0,
959 intFormat
, GL_UNSIGNED_BYTE
, NULL
);
961 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
962 0, 0, srcX
, srcY
, width
, height
);
966 /* replace existing tex image */
967 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
968 0, 0, srcX
, srcY
, width
, height
);
974 * Setup/load texture for glDrawPixels.
977 setup_drawpix_texture(struct temp_texture
*tex
,
980 GLsizei width
, GLsizei height
,
981 GLenum format
, GLenum type
,
982 const GLvoid
*pixels
)
984 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
985 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
986 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
987 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
989 /* copy pixel data to texture */
991 /* create new tex image */
992 if (tex
->Width
== width
&& tex
->Height
== height
) {
993 /* create new tex and load image data */
994 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
995 tex
->Width
, tex
->Height
, 0, format
, type
, pixels
);
998 /* create empty texture */
999 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1000 tex
->Width
, tex
->Height
, 0, format
, type
, NULL
);
1002 _mesa_TexSubImage2D(tex
->Target
, 0,
1003 0, 0, width
, height
, format
, type
, pixels
);
1007 /* replace existing tex image */
1008 _mesa_TexSubImage2D(tex
->Target
, 0,
1009 0, 0, width
, height
, format
, type
, pixels
);
1016 * One-time init for drawing depth pixels.
1019 init_blit_depth_pixels(GLcontext
*ctx
)
1021 static const char *program
=
1023 "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
1026 struct blit_state
*blit
= &ctx
->Meta
->Blit
;
1027 struct temp_texture
*tex
= get_temp_texture(ctx
);
1028 const char *texTarget
;
1030 assert(blit
->DepthFP
== 0);
1032 /* replace %s with "RECT" or "2D" */
1033 assert(strlen(program
) + 4 < sizeof(program2
));
1034 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1038 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1040 _mesa_GenPrograms(1, &blit
->DepthFP
);
1041 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, blit
->DepthFP
);
1042 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1043 strlen(program2
), (const GLubyte
*) program2
);
1048 * Meta implementation of ctx->Driver.BlitFramebuffer() in terms
1049 * of texture mapping and polygon rendering.
1052 _mesa_meta_BlitFramebuffer(GLcontext
*ctx
,
1053 GLint srcX0
, GLint srcY0
, GLint srcX1
, GLint srcY1
,
1054 GLint dstX0
, GLint dstY0
, GLint dstX1
, GLint dstY1
,
1055 GLbitfield mask
, GLenum filter
)
1057 struct blit_state
*blit
= &ctx
->Meta
->Blit
;
1058 struct temp_texture
*tex
= get_temp_texture(ctx
);
1059 const GLsizei maxTexSize
= tex
->MaxSize
;
1060 const GLint srcX
= MIN2(srcX0
, srcX1
);
1061 const GLint srcY
= MIN2(srcY0
, srcY1
);
1062 const GLint srcW
= abs(srcX1
- srcX0
);
1063 const GLint srcH
= abs(srcY1
- srcY0
);
1064 const GLboolean srcFlipX
= srcX1
< srcX0
;
1065 const GLboolean srcFlipY
= srcY1
< srcY0
;
1069 struct vertex verts
[4];
1072 if (srcW
> maxTexSize
|| srcH
> maxTexSize
) {
1073 /* XXX avoid this fallback */
1074 _swrast_BlitFramebuffer(ctx
, srcX0
, srcY0
, srcX1
, srcY1
,
1075 dstX0
, dstY0
, dstX1
, dstY1
, mask
, filter
);
1091 /* only scissor effects blit so save/clear all other relevant state */
1092 _mesa_meta_begin(ctx
, ~META_SCISSOR
);
1094 if (blit
->ArrayObj
== 0) {
1095 /* one-time setup */
1097 /* create vertex array object */
1098 _mesa_GenVertexArrays(1, &blit
->ArrayObj
);
1099 _mesa_BindVertexArray(blit
->ArrayObj
);
1101 /* create vertex array buffer */
1102 _mesa_GenBuffersARB(1, &blit
->VBO
);
1103 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, blit
->VBO
);
1104 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1105 NULL
, GL_DYNAMIC_DRAW_ARB
);
1107 /* setup vertex arrays */
1108 _mesa_VertexPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1109 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1110 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1111 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1114 _mesa_BindVertexArray(blit
->ArrayObj
);
1115 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, blit
->VBO
);
1118 newTex
= alloc_texture(tex
, srcW
, srcH
, GL_RGBA
);
1120 /* vertex positions/texcoords (after texture allocation!) */
1122 verts
[0].x
= (GLfloat
) dstX0
;
1123 verts
[0].y
= (GLfloat
) dstY0
;
1124 verts
[1].x
= (GLfloat
) dstX1
;
1125 verts
[1].y
= (GLfloat
) dstY0
;
1126 verts
[2].x
= (GLfloat
) dstX1
;
1127 verts
[2].y
= (GLfloat
) dstY1
;
1128 verts
[3].x
= (GLfloat
) dstX0
;
1129 verts
[3].y
= (GLfloat
) dstY1
;
1133 verts
[1].s
= tex
->Sright
;
1135 verts
[2].s
= tex
->Sright
;
1136 verts
[2].t
= tex
->Ttop
;
1138 verts
[3].t
= tex
->Ttop
;
1140 /* upload new vertex data */
1141 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1144 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1146 if (mask
& GL_COLOR_BUFFER_BIT
) {
1147 setup_copypix_texture(tex
, newTex
, srcX
, srcY
, srcW
, srcH
,
1149 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1150 mask
&= ~GL_COLOR_BUFFER_BIT
;
1153 if (mask
& GL_DEPTH_BUFFER_BIT
) {
1154 GLuint
*tmp
= (GLuint
*) _mesa_malloc(srcW
* srcH
* sizeof(GLuint
));
1157 init_blit_depth_pixels(ctx
);
1159 /* maybe change tex format here */
1160 newTex
= alloc_texture(tex
, srcW
, srcH
, GL_DEPTH_COMPONENT
);
1162 _mesa_ReadPixels(srcX
, srcY
, srcW
, srcH
,
1163 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, tmp
);
1165 setup_drawpix_texture(tex
, newTex
, GL_DEPTH_COMPONENT
, srcW
, srcH
,
1166 GL_DEPTH_COMPONENT
, GL_UNSIGNED_INT
, tmp
);
1168 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, blit
->DepthFP
);
1169 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
1170 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1171 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1172 _mesa_DepthFunc(GL_ALWAYS
);
1173 _mesa_DepthMask(GL_TRUE
);
1175 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1176 mask
&= ~GL_DEPTH_BUFFER_BIT
;
1182 if (mask
& GL_STENCIL_BUFFER_BIT
) {
1183 /* XXX can't easily do stencil */
1186 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1188 _mesa_meta_end(ctx
);
1191 _swrast_BlitFramebuffer(ctx
, srcX0
, srcY0
, srcX1
, srcY1
,
1192 dstX0
, dstY0
, dstX1
, dstY1
, mask
, filter
);
1198 * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
1201 _mesa_meta_Clear(GLcontext
*ctx
, GLbitfield buffers
)
1203 struct clear_state
*clear
= &ctx
->Meta
->Clear
;
1205 GLfloat x
, y
, z
, r
, g
, b
, a
;
1207 struct vertex verts
[4];
1208 /* save all state but scissor, pixel pack/unpack */
1209 GLbitfield metaSave
= META_ALL
- META_SCISSOR
- META_PIXEL_STORE
;
1211 if (buffers
& BUFFER_BITS_COLOR
) {
1212 /* if clearing color buffers, don't save/restore colormask */
1213 metaSave
-= META_COLOR_MASK
;
1216 _mesa_meta_begin(ctx
, metaSave
);
1218 if (clear
->ArrayObj
== 0) {
1219 /* one-time setup */
1221 /* create vertex array object */
1222 _mesa_GenVertexArrays(1, &clear
->ArrayObj
);
1223 _mesa_BindVertexArray(clear
->ArrayObj
);
1225 /* create vertex array buffer */
1226 _mesa_GenBuffersARB(1, &clear
->VBO
);
1227 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, clear
->VBO
);
1228 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1229 NULL
, GL_DYNAMIC_DRAW_ARB
);
1231 /* setup vertex arrays */
1232 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1233 _mesa_ColorPointer(4, GL_FLOAT
, sizeof(struct vertex
), OFFSET(r
));
1234 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1235 _mesa_EnableClientState(GL_COLOR_ARRAY
);
1238 _mesa_BindVertexArray(clear
->ArrayObj
);
1239 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, clear
->VBO
);
1242 /* GL_COLOR_BUFFER_BIT */
1243 if (buffers
& BUFFER_BITS_COLOR
) {
1244 /* leave colormask, glDrawBuffer state as-is */
1247 ASSERT(metaSave
& META_COLOR_MASK
);
1248 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1251 /* GL_DEPTH_BUFFER_BIT */
1252 if (buffers
& BUFFER_BIT_DEPTH
) {
1253 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1254 _mesa_DepthFunc(GL_ALWAYS
);
1255 _mesa_DepthMask(GL_TRUE
);
1258 assert(!ctx
->Depth
.Test
);
1261 /* GL_STENCIL_BUFFER_BIT */
1262 if (buffers
& BUFFER_BIT_STENCIL
) {
1263 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1264 _mesa_StencilOpSeparate(GL_FRONT_AND_BACK
,
1265 GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1266 _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK
, GL_ALWAYS
,
1267 ctx
->Stencil
.Clear
& 0x7fffffff,
1268 ctx
->Stencil
.WriteMask
[0]);
1271 assert(!ctx
->Stencil
.Enabled
);
1274 /* vertex positions/colors */
1276 const GLfloat x0
= (GLfloat
) ctx
->DrawBuffer
->_Xmin
;
1277 const GLfloat y0
= (GLfloat
) ctx
->DrawBuffer
->_Ymin
;
1278 const GLfloat x1
= (GLfloat
) ctx
->DrawBuffer
->_Xmax
;
1279 const GLfloat y1
= (GLfloat
) ctx
->DrawBuffer
->_Ymax
;
1280 const GLfloat z
= 1.0 - 2.0 * ctx
->Depth
.Clear
;
1297 for (i
= 0; i
< 4; i
++) {
1298 verts
[i
].r
= ctx
->Color
.ClearColor
[0];
1299 verts
[i
].g
= ctx
->Color
.ClearColor
[1];
1300 verts
[i
].b
= ctx
->Color
.ClearColor
[2];
1301 verts
[i
].a
= ctx
->Color
.ClearColor
[3];
1304 /* upload new vertex data */
1305 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1309 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1311 _mesa_meta_end(ctx
);
1316 * Meta implementation of ctx->Driver.CopyPixels() in terms
1317 * of texture mapping and polygon rendering.
1320 _mesa_meta_CopyPixels(GLcontext
*ctx
, GLint srcX
, GLint srcY
,
1321 GLsizei width
, GLsizei height
,
1322 GLint dstX
, GLint dstY
, GLenum type
)
1324 struct copypix_state
*copypix
= &ctx
->Meta
->CopyPix
;
1325 struct temp_texture
*tex
= get_temp_texture(ctx
);
1327 GLfloat x
, y
, z
, s
, t
;
1329 struct vertex verts
[4];
1331 GLenum intFormat
= GL_RGBA
;
1333 if (type
!= GL_COLOR
||
1334 ctx
->_ImageTransferState
||
1336 width
> tex
->MaxSize
||
1337 height
> tex
->MaxSize
) {
1338 /* XXX avoid this fallback */
1339 _swrast_CopyPixels(ctx
, srcX
, srcY
, width
, height
, dstX
, dstY
, type
);
1343 /* Most GL state applies to glCopyPixels, but a there's a few things
1344 * we need to override:
1346 _mesa_meta_begin(ctx
, (META_RASTERIZATION
|
1353 if (copypix
->ArrayObj
== 0) {
1354 /* one-time setup */
1356 /* create vertex array object */
1357 _mesa_GenVertexArrays(1, ©pix
->ArrayObj
);
1358 _mesa_BindVertexArray(copypix
->ArrayObj
);
1360 /* create vertex array buffer */
1361 _mesa_GenBuffersARB(1, ©pix
->VBO
);
1362 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, copypix
->VBO
);
1363 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1364 NULL
, GL_DYNAMIC_DRAW_ARB
);
1366 /* setup vertex arrays */
1367 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1368 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1369 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1370 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1373 _mesa_BindVertexArray(copypix
->ArrayObj
);
1374 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, copypix
->VBO
);
1377 newTex
= alloc_texture(tex
, width
, height
, intFormat
);
1379 /* vertex positions, texcoords (after texture allocation!) */
1381 const GLfloat dstX0
= (GLfloat
) dstX
;
1382 const GLfloat dstY0
= (GLfloat
) dstY
;
1383 const GLfloat dstX1
= dstX
+ width
* ctx
->Pixel
.ZoomX
;
1384 const GLfloat dstY1
= dstY
+ height
* ctx
->Pixel
.ZoomY
;
1385 const GLfloat z
= ctx
->Current
.RasterPos
[2];
1395 verts
[1].s
= tex
->Sright
;
1400 verts
[2].s
= tex
->Sright
;
1401 verts
[2].t
= tex
->Ttop
;
1406 verts
[3].t
= tex
->Ttop
;
1408 /* upload new vertex data */
1409 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1412 /* Alloc/setup texture */
1413 setup_copypix_texture(tex
, newTex
, srcX
, srcY
, width
, height
,
1414 GL_RGBA
, GL_NEAREST
);
1416 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1418 /* draw textured quad */
1419 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1421 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1423 _mesa_meta_end(ctx
);
1429 * When the glDrawPixels() image size is greater than the max rectangle
1430 * texture size we use this function to break the glDrawPixels() image
1431 * into tiles which fit into the max texture size.
1434 tiled_draw_pixels(GLcontext
*ctx
,
1436 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1437 GLenum format
, GLenum type
,
1438 const struct gl_pixelstore_attrib
*unpack
,
1439 const GLvoid
*pixels
)
1441 struct gl_pixelstore_attrib tileUnpack
= *unpack
;
1444 if (tileUnpack
.RowLength
== 0)
1445 tileUnpack
.RowLength
= width
;
1447 for (i
= 0; i
< width
; i
+= tileSize
) {
1448 const GLint tileWidth
= MIN2(tileSize
, width
- i
);
1449 const GLint tileX
= (GLint
) (x
+ i
* ctx
->Pixel
.ZoomX
);
1451 tileUnpack
.SkipPixels
= unpack
->SkipPixels
+ i
;
1453 for (j
= 0; j
< height
; j
+= tileSize
) {
1454 const GLint tileHeight
= MIN2(tileSize
, height
- j
);
1455 const GLint tileY
= (GLint
) (y
+ j
* ctx
->Pixel
.ZoomY
);
1457 tileUnpack
.SkipRows
= unpack
->SkipRows
+ j
;
1459 _mesa_meta_DrawPixels(ctx
, tileX
, tileY
, tileWidth
, tileHeight
,
1460 format
, type
, &tileUnpack
, pixels
);
1467 * One-time init for drawing stencil pixels.
1470 init_draw_stencil_pixels(GLcontext
*ctx
)
1472 /* This program is run eight times, once for each stencil bit.
1473 * The stencil values to draw are found in an 8-bit alpha texture.
1474 * We read the texture/stencil value and test if bit 'b' is set.
1475 * If the bit is not set, use KIL to kill the fragment.
1476 * Finally, we use the stencil test to update the stencil buffer.
1478 * The basic algorithm for checking if a bit is set is:
1479 * if (is_odd(value / (1 << bit)))
1480 * result is one (or non-zero).
1483 * The program parameter contains three values:
1484 * parm.x = 255 / (1 << bit)
1488 static const char *program
=
1490 "PARAM parm = program.local[0]; \n"
1492 "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */
1493 "# t = t * 255 / bit \n"
1494 "MUL t.x, t.a, parm.x; \n"
1497 "SUB t.x, t.x, t.y; \n"
1499 "MUL t.x, t.x, parm.y; \n"
1500 "# t = fract(t.x) \n"
1501 "FRC t.x, t.x; # if t.x != 0, then the bit is set \n"
1502 "# t.x = (t.x == 0 ? 1 : 0) \n"
1503 "SGE t.x, -t.x, parm.z; \n"
1505 "# for debug only \n"
1506 "#MOV result.color, t.x; \n"
1508 char program2
[1000];
1509 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1510 struct temp_texture
*tex
= get_temp_texture(ctx
);
1511 const char *texTarget
;
1513 assert(drawpix
->StencilFP
== 0);
1515 /* replace %s with "RECT" or "2D" */
1516 assert(strlen(program
) + 4 < sizeof(program2
));
1517 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1521 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1523 _mesa_GenPrograms(1, &drawpix
->StencilFP
);
1524 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
1525 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1526 strlen(program2
), (const GLubyte
*) program2
);
1531 * One-time init for drawing depth pixels.
1534 init_draw_depth_pixels(GLcontext
*ctx
)
1536 static const char *program
=
1538 "PARAM color = program.local[0]; \n"
1539 "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
1540 "MOV result.color, color; \n"
1543 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1544 struct temp_texture
*tex
= get_temp_texture(ctx
);
1545 const char *texTarget
;
1547 assert(drawpix
->DepthFP
== 0);
1549 /* replace %s with "RECT" or "2D" */
1550 assert(strlen(program
) + 4 < sizeof(program2
));
1551 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1555 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1557 _mesa_GenPrograms(1, &drawpix
->DepthFP
);
1558 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
1559 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1560 strlen(program2
), (const GLubyte
*) program2
);
1565 * Meta implementation of ctx->Driver.DrawPixels() in terms
1566 * of texture mapping and polygon rendering.
1569 _mesa_meta_DrawPixels(GLcontext
*ctx
,
1570 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1571 GLenum format
, GLenum type
,
1572 const struct gl_pixelstore_attrib
*unpack
,
1573 const GLvoid
*pixels
)
1575 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1576 struct temp_texture
*tex
= get_temp_texture(ctx
);
1577 const struct gl_pixelstore_attrib unpackSave
= ctx
->Unpack
;
1578 const GLuint origStencilMask
= ctx
->Stencil
.WriteMask
[0];
1580 GLfloat x
, y
, z
, s
, t
;
1582 struct vertex verts
[4];
1583 GLenum texIntFormat
;
1584 GLboolean fallback
, newTex
;
1585 GLbitfield metaExtraSave
= 0x0;
1589 * Determine if we can do the glDrawPixels with texture mapping.
1591 fallback
= GL_FALSE
;
1592 if (ctx
->_ImageTransferState
||
1597 if (_mesa_is_color_format(format
)) {
1598 /* use more compact format when possible */
1599 /* XXX disable special case for GL_LUMINANCE for now to work around
1600 * apparent i965 driver bug (see bug #23670).
1602 if (/*format == GL_LUMINANCE ||*/ format
== GL_LUMINANCE_ALPHA
)
1603 texIntFormat
= format
;
1605 texIntFormat
= GL_RGBA
;
1607 else if (_mesa_is_stencil_format(format
)) {
1608 if (ctx
->Extensions
.ARB_fragment_program
&&
1609 ctx
->Pixel
.IndexShift
== 0 &&
1610 ctx
->Pixel
.IndexOffset
== 0 &&
1611 type
== GL_UNSIGNED_BYTE
) {
1612 /* We'll store stencil as alpha. This only works for GLubyte
1613 * image data because of how incoming values are mapped to alpha
1616 texIntFormat
= GL_ALPHA
;
1617 metaExtraSave
= (META_COLOR_MASK
|
1626 else if (_mesa_is_depth_format(format
)) {
1627 if (ctx
->Extensions
.ARB_depth_texture
&&
1628 ctx
->Extensions
.ARB_fragment_program
) {
1629 texIntFormat
= GL_DEPTH_COMPONENT
;
1630 metaExtraSave
= (META_SHADER
);
1641 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
1642 format
, type
, unpack
, pixels
);
1647 * Check image size against max texture size, draw as tiles if needed.
1649 if (width
> tex
->MaxSize
|| height
> tex
->MaxSize
) {
1650 tiled_draw_pixels(ctx
, tex
->MaxSize
, x
, y
, width
, height
,
1651 format
, type
, unpack
, pixels
);
1655 /* Most GL state applies to glDrawPixels (like blending, stencil, etc),
1656 * but a there's a few things we need to override:
1658 _mesa_meta_begin(ctx
, (META_RASTERIZATION
|
1666 newTex
= alloc_texture(tex
, width
, height
, texIntFormat
);
1668 /* vertex positions, texcoords (after texture allocation!) */
1670 const GLfloat x0
= (GLfloat
) x
;
1671 const GLfloat y0
= (GLfloat
) y
;
1672 const GLfloat x1
= x
+ width
* ctx
->Pixel
.ZoomX
;
1673 const GLfloat y1
= y
+ height
* ctx
->Pixel
.ZoomY
;
1674 const GLfloat z
= ctx
->Current
.RasterPos
[2];
1684 verts
[1].s
= tex
->Sright
;
1689 verts
[2].s
= tex
->Sright
;
1690 verts
[2].t
= tex
->Ttop
;
1695 verts
[3].t
= tex
->Ttop
;
1698 if (drawpix
->ArrayObj
== 0) {
1699 /* one-time setup: create vertex array object */
1700 _mesa_GenVertexArrays(1, &drawpix
->ArrayObj
);
1702 _mesa_BindVertexArray(drawpix
->ArrayObj
);
1704 /* create vertex array buffer */
1705 _mesa_GenBuffersARB(1, &vbo
);
1706 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, vbo
);
1707 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1708 verts
, GL_DYNAMIC_DRAW_ARB
);
1710 /* setup vertex arrays */
1711 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1712 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1713 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1714 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1716 /* set given unpack params */
1717 ctx
->Unpack
= *unpack
;
1719 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1721 if (_mesa_is_stencil_format(format
)) {
1722 /* Drawing stencil */
1725 if (!drawpix
->StencilFP
)
1726 init_draw_stencil_pixels(ctx
);
1728 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1729 GL_ALPHA
, type
, pixels
);
1731 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1733 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1735 /* set all stencil bits to 0 */
1736 _mesa_StencilOp(GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1737 _mesa_StencilFunc(GL_ALWAYS
, 0, 255);
1738 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1740 /* set stencil bits to 1 where needed */
1741 _mesa_StencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
1743 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
1744 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
1746 for (bit
= 0; bit
< ctx
->Visual
.stencilBits
; bit
++) {
1747 const GLuint mask
= 1 << bit
;
1748 if (mask
& origStencilMask
) {
1749 _mesa_StencilFunc(GL_ALWAYS
, mask
, mask
);
1750 _mesa_StencilMask(mask
);
1752 _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
1753 255.0 / mask
, 0.5, 0.0, 0.0);
1755 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1759 else if (_mesa_is_depth_format(format
)) {
1761 if (!drawpix
->DepthFP
)
1762 init_draw_depth_pixels(ctx
);
1764 _mesa_BindProgram(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
1765 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
1767 /* polygon color = current raster color */
1768 _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
1769 ctx
->Current
.RasterColor
);
1771 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1772 format
, type
, pixels
);
1774 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1778 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1779 format
, type
, pixels
);
1780 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1783 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1785 _mesa_DeleteBuffersARB(1, &vbo
);
1787 /* restore unpack params */
1788 ctx
->Unpack
= unpackSave
;
1790 _mesa_meta_end(ctx
);
1795 * Do glBitmap with a alpha texture quad. Use the alpha test to
1796 * cull the 'off' bits. If alpha test is already enabled, fall back
1797 * to swrast (should be a rare case).
1798 * A bitmap cache as in the gallium/mesa state tracker would
1799 * improve performance a lot.
1802 _mesa_meta_Bitmap(GLcontext
*ctx
,
1803 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1804 const struct gl_pixelstore_attrib
*unpack
,
1805 const GLubyte
*bitmap1
)
1807 struct bitmap_state
*bitmap
= &ctx
->Meta
->Bitmap
;
1808 struct temp_texture
*tex
= get_bitmap_temp_texture(ctx
);
1809 const GLenum texIntFormat
= GL_ALPHA
;
1810 const struct gl_pixelstore_attrib unpackSave
= *unpack
;
1812 GLfloat x
, y
, z
, s
, t
, r
, g
, b
, a
;
1814 struct vertex verts
[4];
1819 * Check if swrast fallback is needed.
1821 if (ctx
->_ImageTransferState
||
1822 ctx
->Color
.AlphaEnabled
||
1824 ctx
->Texture
._EnabledUnits
||
1825 width
> tex
->MaxSize
||
1826 height
> tex
->MaxSize
) {
1827 _swrast_Bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap1
);
1831 /* Most GL state applies to glBitmap (like blending, stencil, etc),
1832 * but a there's a few things we need to override:
1834 _mesa_meta_begin(ctx
, (META_ALPHA_TEST
|
1836 META_RASTERIZATION
|
1843 if (bitmap
->ArrayObj
== 0) {
1844 /* one-time setup */
1846 /* create vertex array object */
1847 _mesa_GenVertexArraysAPPLE(1, &bitmap
->ArrayObj
);
1848 _mesa_BindVertexArrayAPPLE(bitmap
->ArrayObj
);
1850 /* create vertex array buffer */
1851 _mesa_GenBuffersARB(1, &bitmap
->VBO
);
1852 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, bitmap
->VBO
);
1853 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1854 NULL
, GL_DYNAMIC_DRAW_ARB
);
1856 /* setup vertex arrays */
1857 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
1858 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
1859 _mesa_ColorPointer(4, GL_FLOAT
, sizeof(struct vertex
), OFFSET(r
));
1860 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
1861 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
1862 _mesa_EnableClientState(GL_COLOR_ARRAY
);
1865 _mesa_BindVertexArray(bitmap
->ArrayObj
);
1866 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, bitmap
->VBO
);
1869 newTex
= alloc_texture(tex
, width
, height
, texIntFormat
);
1871 /* vertex positions, texcoords, colors (after texture allocation!) */
1873 const GLfloat x0
= (GLfloat
) x
;
1874 const GLfloat y0
= (GLfloat
) y
;
1875 const GLfloat x1
= (GLfloat
) (x
+ width
);
1876 const GLfloat y1
= (GLfloat
) (y
+ height
);
1877 const GLfloat z
= ctx
->Current
.RasterPos
[2];
1888 verts
[1].s
= tex
->Sright
;
1893 verts
[2].s
= tex
->Sright
;
1894 verts
[2].t
= tex
->Ttop
;
1899 verts
[3].t
= tex
->Ttop
;
1901 for (i
= 0; i
< 4; i
++) {
1902 verts
[i
].r
= ctx
->Current
.RasterColor
[0];
1903 verts
[i
].g
= ctx
->Current
.RasterColor
[1];
1904 verts
[i
].b
= ctx
->Current
.RasterColor
[2];
1905 verts
[i
].a
= ctx
->Current
.RasterColor
[3];
1908 /* upload new vertex data */
1909 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1912 bitmap1
= _mesa_map_pbo_source(ctx
, &unpackSave
, bitmap1
);
1916 bitmap8
= (GLubyte
*) _mesa_calloc(width
* height
);
1918 _mesa_expand_bitmap(width
, height
, &unpackSave
, bitmap1
,
1919 bitmap8
, width
, 0xff);
1921 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1923 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_TRUE
);
1924 _mesa_AlphaFunc(GL_GREATER
, 0.0);
1926 setup_drawpix_texture(tex
, newTex
, texIntFormat
, width
, height
,
1927 GL_ALPHA
, GL_UNSIGNED_BYTE
, bitmap8
);
1929 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1931 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1933 _mesa_free(bitmap8
);
1936 _mesa_unmap_pbo_source(ctx
, &unpackSave
);
1938 _mesa_meta_end(ctx
);
1943 * Called via ctx->Driver.GenerateMipmap()
1944 * Note: texture borders and 3D texture support not yet complete.
1947 _mesa_meta_GenerateMipmap(GLcontext
*ctx
, GLenum target
,
1948 struct gl_texture_object
*texObj
)
1950 struct gen_mipmap_state
*mipmap
= &ctx
->Meta
->Mipmap
;
1952 GLfloat x
, y
, s
, t
, r
;
1954 struct vertex verts
[4];
1955 const GLuint baseLevel
= texObj
->BaseLevel
;
1956 const GLuint maxLevel
= texObj
->MaxLevel
;
1957 const GLenum minFilterSave
= texObj
->MinFilter
;
1958 const GLenum magFilterSave
= texObj
->MagFilter
;
1959 const GLint baseLevelSave
= texObj
->BaseLevel
;
1960 const GLint maxLevelSave
= texObj
->MaxLevel
;
1961 const GLboolean genMipmapSave
= texObj
->GenerateMipmap
;
1962 const GLenum wrapSSave
= texObj
->WrapS
;
1963 const GLenum wrapTSave
= texObj
->WrapT
;
1964 const GLenum wrapRSave
= texObj
->WrapR
;
1965 const GLuint fboSave
= ctx
->DrawBuffer
->Name
;
1970 /* check for fallbacks */
1971 if (!ctx
->Extensions
.EXT_framebuffer_object
||
1972 target
== GL_TEXTURE_3D
) {
1973 _mesa_generate_mipmap(ctx
, target
, texObj
);
1977 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1978 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
) {
1979 faceTarget
= target
;
1980 target
= GL_TEXTURE_CUBE_MAP
;
1983 faceTarget
= target
;
1986 _mesa_meta_begin(ctx
, META_ALL
);
1988 if (mipmap
->ArrayObj
== 0) {
1989 /* one-time setup */
1991 /* create vertex array object */
1992 _mesa_GenVertexArraysAPPLE(1, &mipmap
->ArrayObj
);
1993 _mesa_BindVertexArrayAPPLE(mipmap
->ArrayObj
);
1995 /* create vertex array buffer */
1996 _mesa_GenBuffersARB(1, &mipmap
->VBO
);
1997 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, mipmap
->VBO
);
1998 _mesa_BufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
1999 NULL
, GL_DYNAMIC_DRAW_ARB
);
2001 /* setup vertex arrays */
2002 _mesa_VertexPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
2003 _mesa_TexCoordPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(s
));
2004 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
2005 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
2008 _mesa_BindVertexArray(mipmap
->ArrayObj
);
2009 _mesa_BindBufferARB(GL_ARRAY_BUFFER_ARB
, mipmap
->VBO
);
2013 /* Bind the new renderbuffer to the color attachment point. */
2014 _mesa_GenFramebuffersEXT(1, &mipmap
->FBO
);
2017 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, mipmap
->FBO
);
2019 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
2020 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
2021 _mesa_TexParameteri(target
, GL_GENERATE_MIPMAP
, GL_FALSE
);
2022 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
2023 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
2024 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, GL_CLAMP_TO_EDGE
);
2026 _mesa_set_enable(ctx
, target
, GL_TRUE
);
2028 /* setup texcoords once (XXX what about border?) */
2029 switch (faceTarget
) {
2051 static const GLfloat st
[4][2] = {
2052 {0.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 1.0f
}
2056 /* loop over quad verts */
2057 for (i
= 0; i
< 4; i
++) {
2058 /* Compute sc = +/-scale and tc = +/-scale.
2059 * Not +/-1 to avoid cube face selection ambiguity near the edges,
2060 * though that can still sometimes happen with this scale factor...
2062 const GLfloat scale
= 0.9999f
;
2063 const GLfloat sc
= (2.0f
* st
[i
][0] - 1.0f
) * scale
;
2064 const GLfloat tc
= (2.0f
* st
[i
][1] - 1.0f
) * scale
;
2066 switch (faceTarget
) {
2067 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2077 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2082 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2087 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2092 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2104 _mesa_set_enable(ctx
, target
, GL_TRUE
);
2106 /* texture is already locked, unlock now */
2107 _mesa_unlock_texture(ctx
, texObj
);
2109 for (dstLevel
= baseLevel
+ 1; dstLevel
<= maxLevel
; dstLevel
++) {
2110 const struct gl_texture_image
*srcImage
;
2111 const GLuint srcLevel
= dstLevel
- 1;
2112 GLsizei srcWidth
, srcHeight
, srcDepth
;
2113 GLsizei dstWidth
, dstHeight
, dstDepth
;
2116 srcImage
= _mesa_select_tex_image(ctx
, texObj
, faceTarget
, srcLevel
);
2117 assert(srcImage
->Border
== 0); /* XXX we can fix this */
2119 /* src size w/out border */
2120 srcWidth
= srcImage
->Width
- 2 * border
;
2121 srcHeight
= srcImage
->Height
- 2 * border
;
2122 srcDepth
= srcImage
->Depth
- 2 * border
;
2124 /* new dst size w/ border */
2125 dstWidth
= MAX2(1, srcWidth
/ 2) + 2 * border
;
2126 dstHeight
= MAX2(1, srcHeight
/ 2) + 2 * border
;
2127 dstDepth
= MAX2(1, srcDepth
/ 2) + 2 * border
;
2129 if (dstWidth
== srcImage
->Width
&&
2130 dstHeight
== srcImage
->Height
&&
2131 dstDepth
== srcImage
->Depth
) {
2136 /* Create empty dest image */
2137 if (target
== GL_TEXTURE_1D
) {
2138 _mesa_TexImage1D(target
, dstLevel
, srcImage
->InternalFormat
,
2140 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2142 else if (target
== GL_TEXTURE_3D
) {
2143 _mesa_TexImage3D(target
, dstLevel
, srcImage
->InternalFormat
,
2144 dstWidth
, dstHeight
, dstDepth
, border
,
2145 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2149 _mesa_TexImage2D(faceTarget
, dstLevel
, srcImage
->InternalFormat
,
2150 dstWidth
, dstHeight
, border
,
2151 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2153 if (target
== GL_TEXTURE_CUBE_MAP
) {
2154 /* If texturing from a cube, we need to make sure all src faces
2155 * have been defined (even if we're not sampling from them.)
2156 * Otherwise the texture object will be 'incomplete' and
2157 * texturing from it will not be allowed.
2160 for (face
= 0; face
< 6; face
++) {
2161 if (!texObj
->Image
[face
][srcLevel
] ||
2162 texObj
->Image
[face
][srcLevel
]->Width
!= srcWidth
) {
2163 _mesa_TexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
,
2164 srcLevel
, srcImage
->InternalFormat
,
2165 srcWidth
, srcHeight
, border
,
2166 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
);
2172 /* setup vertex positions */
2176 verts
[1].x
= (GLfloat
) dstWidth
;
2178 verts
[2].x
= (GLfloat
) dstWidth
;
2179 verts
[2].y
= (GLfloat
) dstHeight
;
2181 verts
[3].y
= (GLfloat
) dstHeight
;
2183 /* upload new vertex data */
2184 _mesa_BufferSubDataARB(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
2187 /* limit sampling to src level */
2188 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, srcLevel
);
2189 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, srcLevel
);
2191 /* Set to draw into the current dstLevel */
2192 if (target
== GL_TEXTURE_1D
) {
2193 _mesa_FramebufferTexture1DEXT(GL_FRAMEBUFFER_EXT
,
2194 GL_COLOR_ATTACHMENT0_EXT
,
2199 else if (target
== GL_TEXTURE_3D
) {
2200 GLint zoffset
= 0; /* XXX unfinished */
2201 _mesa_FramebufferTexture3DEXT(GL_FRAMEBUFFER_EXT
,
2202 GL_COLOR_ATTACHMENT0_EXT
,
2209 _mesa_FramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT
,
2210 GL_COLOR_ATTACHMENT0_EXT
,
2216 _mesa_DrawBuffer(GL_COLOR_ATTACHMENT0_EXT
);
2219 status
= _mesa_CheckFramebufferStatusEXT (GL_FRAMEBUFFER_EXT
);
2220 if (status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2225 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2228 _mesa_lock_texture(ctx
, texObj
); /* relock */
2230 _mesa_meta_end(ctx
);
2232 _mesa_TexParameteri(target
, GL_TEXTURE_MIN_FILTER
, minFilterSave
);
2233 _mesa_TexParameteri(target
, GL_TEXTURE_MAG_FILTER
, magFilterSave
);
2234 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, baseLevelSave
);
2235 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, maxLevelSave
);
2236 _mesa_TexParameteri(target
, GL_GENERATE_MIPMAP
, genMipmapSave
);
2237 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_S
, wrapSSave
);
2238 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_T
, wrapTSave
);
2239 _mesa_TexParameteri(target
, GL_TEXTURE_WRAP_R
, wrapRSave
);
2241 _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, fboSave
);
2246 * Determine the GL data type to use for the temporary image read with
2247 * ReadPixels() and passed to Tex[Sub]Image().
2250 get_temp_image_type(GLcontext
*ctx
, GLenum baseFormat
)
2252 switch (baseFormat
) {
2257 case GL_LUMINANCE_ALPHA
:
2259 if (ctx
->DrawBuffer
->Visual
.redBits
<= 8)
2260 return GL_UNSIGNED_BYTE
;
2261 else if (ctx
->DrawBuffer
->Visual
.redBits
<= 8)
2262 return GL_UNSIGNED_SHORT
;
2265 case GL_DEPTH_COMPONENT
:
2266 return GL_UNSIGNED_INT
;
2267 case GL_DEPTH_STENCIL
:
2268 return GL_UNSIGNED_INT_24_8
;
2270 _mesa_problem(ctx
, "Unexpected format in get_temp_image_type()");
2277 * Helper for _mesa_meta_CopyTexImage1/2D() functions.
2278 * Have to be careful with locking and meta state for pixel transfer.
2281 copy_tex_image(GLcontext
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2282 GLenum internalFormat
, GLint x
, GLint y
,
2283 GLsizei width
, GLsizei height
, GLint border
)
2285 struct gl_texture_unit
*texUnit
;
2286 struct gl_texture_object
*texObj
;
2287 struct gl_texture_image
*texImage
;
2288 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2289 GLenum format
, type
;
2293 texUnit
= _mesa_get_current_tex_unit(ctx
);
2294 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2295 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2297 format
= _mesa_base_tex_format(ctx
, internalFormat
);
2298 type
= get_temp_image_type(ctx
, format
);
2299 bpp
= _mesa_bytes_per_pixel(format
, type
);
2301 _mesa_problem(ctx
, "Bad bpp in meta copy_tex_image()");
2306 * Alloc image buffer (XXX could use a PBO)
2308 buf
= _mesa_malloc(width
* height
* bpp
);
2310 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2314 _mesa_unlock_texture(ctx
, texObj
); /* need to unlock first */
2317 * Read image from framebuffer (disable pixel transfer ops)
2319 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2320 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2321 format
, type
, &ctx
->Pack
, buf
);
2322 _mesa_meta_end(ctx
);
2325 * Prepare for new texture image size/data
2327 #if FEATURE_convolve
2328 if (_mesa_is_color_format(internalFormat
)) {
2329 _mesa_adjust_image_for_convolution(ctx
, 2,
2330 &postConvWidth
, &postConvHeight
);
2334 if (texImage
->Data
) {
2335 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
2338 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2339 postConvWidth
, postConvHeight
, 1,
2340 border
, internalFormat
);
2343 * Store texture data (with pixel transfer ops)
2345 _mesa_meta_begin(ctx
, META_PIXEL_STORE
);
2347 _mesa_update_state(ctx
); /* to update pixel transfer state */
2349 if (target
== GL_TEXTURE_1D
) {
2350 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2351 width
, border
, format
, type
,
2352 buf
, &ctx
->Unpack
, texObj
, texImage
);
2355 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2356 width
, height
, border
, format
, type
,
2357 buf
, &ctx
->Unpack
, texObj
, texImage
);
2359 _mesa_meta_end(ctx
);
2361 _mesa_lock_texture(ctx
, texObj
); /* re-lock */
2368 _mesa_meta_CopyTexImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
2369 GLenum internalFormat
, GLint x
, GLint y
,
2370 GLsizei width
, GLint border
)
2372 copy_tex_image(ctx
, 1, target
, level
, internalFormat
, x
, y
,
2378 _mesa_meta_CopyTexImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
2379 GLenum internalFormat
, GLint x
, GLint y
,
2380 GLsizei width
, GLsizei height
, GLint border
)
2382 copy_tex_image(ctx
, 2, target
, level
, internalFormat
, x
, y
,
2383 width
, height
, border
);
2389 * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
2390 * Have to be careful with locking and meta state for pixel transfer.
2393 copy_tex_sub_image(GLcontext
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2394 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2396 GLsizei width
, GLsizei height
)
2398 struct gl_texture_unit
*texUnit
;
2399 struct gl_texture_object
*texObj
;
2400 struct gl_texture_image
*texImage
;
2401 GLenum format
, type
;
2405 texUnit
= _mesa_get_current_tex_unit(ctx
);
2406 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2407 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2409 format
= texImage
->TexFormat
->BaseFormat
;
2410 type
= get_temp_image_type(ctx
, format
);
2411 bpp
= _mesa_bytes_per_pixel(format
, type
);
2413 _mesa_problem(ctx
, "Bad bpp in meta copy_tex_sub_image()");
2418 * Alloc image buffer (XXX could use a PBO)
2420 buf
= _mesa_malloc(width
* height
* bpp
);
2422 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%uD", dims
);
2426 _mesa_unlock_texture(ctx
, texObj
); /* need to unlock first */
2429 * Read image from framebuffer (disable pixel transfer ops)
2431 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2432 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2433 format
, type
, &ctx
->Pack
, buf
);
2434 _mesa_meta_end(ctx
);
2436 _mesa_update_state(ctx
); /* to update pixel transfer state */
2439 * Store texture data (with pixel transfer ops)
2441 _mesa_meta_begin(ctx
, META_PIXEL_STORE
);
2442 if (target
== GL_TEXTURE_1D
) {
2443 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
,
2444 width
, format
, type
, buf
,
2445 &ctx
->Unpack
, texObj
, texImage
);
2447 else if (target
== GL_TEXTURE_3D
) {
2448 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
, xoffset
, yoffset
, zoffset
,
2449 width
, height
, 1, format
, type
, buf
,
2450 &ctx
->Unpack
, texObj
, texImage
);
2453 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2454 width
, height
, format
, type
, buf
,
2455 &ctx
->Unpack
, texObj
, texImage
);
2457 _mesa_meta_end(ctx
);
2459 _mesa_lock_texture(ctx
, texObj
); /* re-lock */
2466 _mesa_meta_CopyTexSubImage1D(GLcontext
*ctx
, GLenum target
, GLint level
,
2468 GLint x
, GLint y
, GLsizei width
)
2470 copy_tex_sub_image(ctx
, 1, target
, level
, xoffset
, 0, 0,
2476 _mesa_meta_CopyTexSubImage2D(GLcontext
*ctx
, GLenum target
, GLint level
,
2477 GLint xoffset
, GLint yoffset
,
2479 GLsizei width
, GLsizei height
)
2481 copy_tex_sub_image(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2482 x
, y
, width
, height
);
2487 _mesa_meta_CopyTexSubImage3D(GLcontext
*ctx
, GLenum target
, GLint level
,
2488 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2490 GLsizei width
, GLsizei height
)
2492 copy_tex_sub_image(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2493 x
, y
, width
, height
);
2498 _mesa_meta_CopyColorTable(GLcontext
*ctx
,
2499 GLenum target
, GLenum internalformat
,
2500 GLint x
, GLint y
, GLsizei width
)
2504 buf
= (GLfloat
*) _mesa_malloc(width
* 4 * sizeof(GLfloat
));
2506 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyColorTable");
2511 * Read image from framebuffer (disable pixel transfer ops)
2513 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2514 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, 1,
2515 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2517 _mesa_ColorTable(target
, internalformat
, width
, GL_RGBA
, GL_FLOAT
, buf
);
2519 _mesa_meta_end(ctx
);
2526 _mesa_meta_CopyColorSubTable(GLcontext
*ctx
,GLenum target
, GLsizei start
,
2527 GLint x
, GLint y
, GLsizei width
)
2531 buf
= (GLfloat
*) _mesa_malloc(width
* 4 * sizeof(GLfloat
));
2533 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyColorSubTable");
2538 * Read image from framebuffer (disable pixel transfer ops)
2540 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2541 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, 1,
2542 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2544 _mesa_ColorSubTable(target
, start
, width
, GL_RGBA
, GL_FLOAT
, buf
);
2546 _mesa_meta_end(ctx
);
2553 _mesa_meta_CopyConvolutionFilter1D(GLcontext
*ctx
, GLenum target
,
2554 GLenum internalFormat
,
2555 GLint x
, GLint y
, GLsizei width
)
2559 buf
= (GLfloat
*) _mesa_malloc(width
* 4 * sizeof(GLfloat
));
2561 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyConvolutionFilter2D");
2566 * Read image from framebuffer (disable pixel transfer ops)
2568 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2569 _mesa_update_state(ctx
);
2570 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, 1,
2571 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2573 _mesa_ConvolutionFilter1D(target
, internalFormat
, width
,
2574 GL_RGBA
, GL_FLOAT
, buf
);
2576 _mesa_meta_end(ctx
);
2583 _mesa_meta_CopyConvolutionFilter2D(GLcontext
*ctx
, GLenum target
,
2584 GLenum internalFormat
, GLint x
, GLint y
,
2585 GLsizei width
, GLsizei height
)
2589 buf
= (GLfloat
*) _mesa_malloc(width
* height
* 4 * sizeof(GLfloat
));
2591 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyConvolutionFilter2D");
2596 * Read image from framebuffer (disable pixel transfer ops)
2598 _mesa_meta_begin(ctx
, META_PIXEL_STORE
| META_PIXEL_TRANSFER
);
2599 _mesa_update_state(ctx
);
2601 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2602 GL_RGBA
, GL_FLOAT
, &ctx
->Pack
, buf
);
2604 _mesa_ConvolutionFilter2D(target
, internalFormat
, width
, height
,
2605 GL_RGBA
, GL_FLOAT
, buf
);
2607 _mesa_meta_end(ctx
);