2 * Mesa 3-D graphics library
4 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * 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/arbprogram.h"
38 #include "main/arrayobj.h"
39 #include "main/blend.h"
40 #include "main/bufferobj.h"
41 #include "main/buffers.h"
42 #include "main/colortab.h"
43 #include "main/condrender.h"
44 #include "main/depth.h"
45 #include "main/enable.h"
46 #include "main/fbobject.h"
47 #include "main/feedback.h"
48 #include "main/formats.h"
49 #include "main/glformats.h"
50 #include "main/image.h"
51 #include "main/macros.h"
52 #include "main/matrix.h"
53 #include "main/mipmap.h"
54 #include "main/multisample.h"
55 #include "main/objectlabel.h"
56 #include "main/pixel.h"
58 #include "main/polygon.h"
59 #include "main/queryobj.h"
60 #include "main/readpix.h"
61 #include "main/scissor.h"
62 #include "main/shaderapi.h"
63 #include "main/shaderobj.h"
64 #include "main/state.h"
65 #include "main/stencil.h"
66 #include "main/texobj.h"
67 #include "main/texenv.h"
68 #include "main/texgetimage.h"
69 #include "main/teximage.h"
70 #include "main/texparam.h"
71 #include "main/texstate.h"
72 #include "main/transformfeedback.h"
73 #include "main/uniforms.h"
74 #include "main/varray.h"
75 #include "main/viewport.h"
76 #include "main/samplerobj.h"
77 #include "program/program.h"
78 #include "swrast/swrast.h"
79 #include "drivers/common/meta.h"
80 #include "main/enums.h"
81 #include "main/glformats.h"
82 #include "../glsl/ralloc.h"
84 /** Return offset in bytes of the field within a vertex struct */
85 #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
87 static struct blit_shader
*
88 choose_blit_shader(GLenum target
, struct blit_shader_table
*table
);
90 static void cleanup_temp_texture(struct temp_texture
*tex
);
91 static void meta_glsl_clear_cleanup(struct clear_state
*clear
);
92 static void meta_decompress_cleanup(struct decompress_state
*decompress
);
93 static void meta_drawpix_cleanup(struct drawpix_state
*drawpix
);
96 _mesa_meta_compile_shader_with_debug(struct gl_context
*ctx
, GLenum target
,
97 const GLcharARB
*source
)
103 shader
= _mesa_CreateShader(target
);
104 _mesa_ShaderSource(shader
, 1, &source
, NULL
);
105 _mesa_CompileShader(shader
);
107 _mesa_GetShaderiv(shader
, GL_COMPILE_STATUS
, &ok
);
111 _mesa_GetShaderiv(shader
, GL_INFO_LOG_LENGTH
, &size
);
113 _mesa_DeleteShader(shader
);
119 _mesa_DeleteShader(shader
);
123 _mesa_GetShaderInfoLog(shader
, size
, NULL
, info
);
125 "meta program compile failed:\n%s\n"
130 _mesa_DeleteShader(shader
);
136 _mesa_meta_link_program_with_debug(struct gl_context
*ctx
, GLuint program
)
141 _mesa_LinkProgram(program
);
143 _mesa_GetProgramiv(program
, GL_LINK_STATUS
, &ok
);
147 _mesa_GetProgramiv(program
, GL_INFO_LOG_LENGTH
, &size
);
155 _mesa_GetProgramInfoLog(program
, size
, NULL
, info
);
156 _mesa_problem(ctx
, "meta program link failed:\n%s", info
);
164 * Generate a generic shader to blit from a texture to a framebuffer
166 * \param ctx Current GL context
167 * \param texTarget Texture target that will be the source of the blit
169 * \returns a handle to a shader program on success or zero on failure.
172 _mesa_meta_setup_blit_shader(struct gl_context
*ctx
,
174 struct blit_shader_table
*table
)
176 const char *vs_source
;
179 void *const mem_ctx
= ralloc_context(NULL
);
180 struct blit_shader
*shader
= choose_blit_shader(target
, table
);
183 assert(shader
!= NULL
);
185 if (shader
->shader_prog
!= 0) {
186 _mesa_UseProgram(shader
->shader_prog
);
190 if (ctx
->Const
.GLSLVersion
< 130) {
192 "attribute vec2 position;\n"
193 "attribute vec4 textureCoords;\n"
194 "varying vec4 texCoords;\n"
197 " texCoords = textureCoords;\n"
198 " gl_Position = vec4(position, 0.0, 1.0);\n"
201 fs_source
= ralloc_asprintf(mem_ctx
,
202 "#extension GL_EXT_texture_array : enable\n"
203 "#extension GL_ARB_texture_cube_map_array: enable\n"
204 "uniform %s texSampler;\n"
205 "varying vec4 texCoords;\n"
208 " gl_FragColor = %s(texSampler, %s);\n"
209 " gl_FragDepth = gl_FragColor.x;\n"
212 shader
->func
, shader
->texcoords
);
215 vs_source
= ralloc_asprintf(mem_ctx
,
217 "in vec2 position;\n"
218 "in vec4 textureCoords;\n"
219 "out vec4 texCoords;\n"
222 " texCoords = textureCoords;\n"
223 " gl_Position = vec4(position, 0.0, 1.0);\n"
225 fs_source
= ralloc_asprintf(mem_ctx
,
227 "#extension GL_ARB_texture_cube_map_array: enable\n"
228 "uniform %s texSampler;\n"
229 "in vec4 texCoords;\n"
230 "out vec4 out_color;\n"
234 " out_color = texture(texSampler, %s);\n"
235 " gl_FragDepth = out_color.x;\n"
241 vs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_VERTEX_SHADER
, vs_source
);
242 fs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_FRAGMENT_SHADER
, fs_source
);
244 shader
->shader_prog
= _mesa_CreateProgram();
245 _mesa_AttachShader(shader
->shader_prog
, fs
);
246 _mesa_DeleteShader(fs
);
247 _mesa_AttachShader(shader
->shader_prog
, vs
);
248 _mesa_DeleteShader(vs
);
249 _mesa_BindAttribLocation(shader
->shader_prog
, 0, "position");
250 _mesa_BindAttribLocation(shader
->shader_prog
, 1, "texcoords");
251 _mesa_meta_link_program_with_debug(ctx
, shader
->shader_prog
);
252 name
= ralloc_asprintf(mem_ctx
, "%s blit", shader
->type
);
253 _mesa_ObjectLabel(GL_PROGRAM
, shader
->shader_prog
, -1, name
);
254 ralloc_free(mem_ctx
);
256 _mesa_UseProgram(shader
->shader_prog
);
260 * Configure vertex buffer and vertex array objects for tests
262 * Regardless of whether a new VAO and new VBO are created, the objects
263 * referenced by \c VAO and \c VBO will be bound into the GL state vector
264 * when this function terminates.
266 * \param VAO Storage for vertex array object handle. If 0, a new VAO
268 * \param VBO Storage for vertex buffer object handle. If 0, a new VBO
269 * will be created. The new VBO will have storage for 4
270 * \c vertex structures.
271 * \param use_generic_attributes Should generic attributes 0 and 1 be used,
272 * or should traditional, fixed-function color and texture
273 * coordinate be used?
274 * \param vertex_size Number of components for attribute 0 / vertex.
275 * \param texcoord_size Number of components for attribute 1 / texture
276 * coordinate. If this is 0, attribute 1 will not be set or
278 * \param color_size Number of components for attribute 1 / primary color.
279 * If this is 0, attribute 1 will not be set or enabled.
281 * \note If \c use_generic_attributes is \c true, \c color_size must be zero.
282 * Use \c texcoord_size instead.
285 _mesa_meta_setup_vertex_objects(GLuint
*VAO
, GLuint
*VBO
,
286 bool use_generic_attributes
,
287 unsigned vertex_size
, unsigned texcoord_size
,
293 /* create vertex array object */
294 _mesa_GenVertexArrays(1, VAO
);
295 _mesa_BindVertexArray(*VAO
);
297 /* create vertex array buffer */
298 _mesa_GenBuffers(1, VBO
);
299 _mesa_BindBuffer(GL_ARRAY_BUFFER
, *VBO
);
300 _mesa_BufferData(GL_ARRAY_BUFFER
, 4 * sizeof(struct vertex
), NULL
,
303 /* setup vertex arrays */
304 if (use_generic_attributes
) {
305 assert(color_size
== 0);
307 _mesa_VertexAttribPointer(0, vertex_size
, GL_FLOAT
, GL_FALSE
,
308 sizeof(struct vertex
), OFFSET(x
));
309 _mesa_EnableVertexAttribArray(0);
311 if (texcoord_size
> 0) {
312 _mesa_VertexAttribPointer(1, texcoord_size
, GL_FLOAT
, GL_FALSE
,
313 sizeof(struct vertex
), OFFSET(tex
));
314 _mesa_EnableVertexAttribArray(1);
317 _mesa_VertexPointer(vertex_size
, GL_FLOAT
, sizeof(struct vertex
),
319 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
321 if (texcoord_size
> 0) {
322 _mesa_TexCoordPointer(texcoord_size
, GL_FLOAT
,
323 sizeof(struct vertex
), OFFSET(tex
));
324 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
327 if (color_size
> 0) {
328 _mesa_ColorPointer(color_size
, GL_FLOAT
,
329 sizeof(struct vertex
), OFFSET(r
));
330 _mesa_EnableClientState(GL_COLOR_ARRAY
);
334 _mesa_BindVertexArray(*VAO
);
335 _mesa_BindBuffer(GL_ARRAY_BUFFER
, *VBO
);
340 * Initialize meta-ops for a context.
341 * To be called once during context creation.
344 _mesa_meta_init(struct gl_context
*ctx
)
348 ctx
->Meta
= CALLOC_STRUCT(gl_meta_state
);
353 * Free context meta-op state.
354 * To be called once during context destruction.
357 _mesa_meta_free(struct gl_context
*ctx
)
359 GET_CURRENT_CONTEXT(old_context
);
360 _mesa_make_current(ctx
, NULL
, NULL
);
361 _mesa_meta_glsl_blit_cleanup(&ctx
->Meta
->Blit
);
362 meta_glsl_clear_cleanup(&ctx
->Meta
->Clear
);
363 _mesa_meta_glsl_generate_mipmap_cleanup(&ctx
->Meta
->Mipmap
);
364 cleanup_temp_texture(&ctx
->Meta
->TempTex
);
365 meta_decompress_cleanup(&ctx
->Meta
->Decompress
);
366 meta_drawpix_cleanup(&ctx
->Meta
->DrawPix
);
368 _mesa_make_current(old_context
, old_context
->WinSysDrawBuffer
, old_context
->WinSysReadBuffer
);
370 _mesa_make_current(NULL
, NULL
, NULL
);
377 * Enter meta state. This is like a light-weight version of glPushAttrib
378 * but it also resets most GL state back to default values.
380 * \param state bitmask of MESA_META_* flags indicating which attribute groups
381 * to save and reset to their defaults
384 _mesa_meta_begin(struct gl_context
*ctx
, GLbitfield state
)
386 struct save_state
*save
;
388 /* hope MAX_META_OPS_DEPTH is large enough */
389 assert(ctx
->Meta
->SaveStackDepth
< MAX_META_OPS_DEPTH
);
391 save
= &ctx
->Meta
->Save
[ctx
->Meta
->SaveStackDepth
++];
392 memset(save
, 0, sizeof(*save
));
393 save
->SavedState
= state
;
395 /* We always push into desktop GL mode and pop out at the end. No sense in
396 * writing our shaders varying based on the user's context choice, when
397 * Mesa can handle either.
399 save
->API
= ctx
->API
;
400 ctx
->API
= API_OPENGL_COMPAT
;
402 /* Pausing transform feedback needs to be done early, or else we won't be
403 * able to change other state.
405 save
->TransformFeedbackNeedsResume
=
406 _mesa_is_xfb_active_and_unpaused(ctx
);
407 if (save
->TransformFeedbackNeedsResume
)
408 _mesa_PauseTransformFeedback();
410 /* After saving the current occlusion object, call EndQuery so that no
411 * occlusion querying will be active during the meta-operation.
413 if (state
& MESA_META_OCCLUSION_QUERY
) {
414 save
->CurrentOcclusionObject
= ctx
->Query
.CurrentOcclusionObject
;
415 if (save
->CurrentOcclusionObject
)
416 _mesa_EndQuery(save
->CurrentOcclusionObject
->Target
);
419 if (state
& MESA_META_ALPHA_TEST
) {
420 save
->AlphaEnabled
= ctx
->Color
.AlphaEnabled
;
421 save
->AlphaFunc
= ctx
->Color
.AlphaFunc
;
422 save
->AlphaRef
= ctx
->Color
.AlphaRef
;
423 if (ctx
->Color
.AlphaEnabled
)
424 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_FALSE
);
427 if (state
& MESA_META_BLEND
) {
428 save
->BlendEnabled
= ctx
->Color
.BlendEnabled
;
429 if (ctx
->Color
.BlendEnabled
) {
430 if (ctx
->Extensions
.EXT_draw_buffers2
) {
432 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
433 _mesa_set_enablei(ctx
, GL_BLEND
, i
, GL_FALSE
);
437 _mesa_set_enable(ctx
, GL_BLEND
, GL_FALSE
);
440 save
->ColorLogicOpEnabled
= ctx
->Color
.ColorLogicOpEnabled
;
441 if (ctx
->Color
.ColorLogicOpEnabled
)
442 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, GL_FALSE
);
445 if (state
& MESA_META_COLOR_MASK
) {
446 memcpy(save
->ColorMask
, ctx
->Color
.ColorMask
,
447 sizeof(ctx
->Color
.ColorMask
));
448 if (!ctx
->Color
.ColorMask
[0][0] ||
449 !ctx
->Color
.ColorMask
[0][1] ||
450 !ctx
->Color
.ColorMask
[0][2] ||
451 !ctx
->Color
.ColorMask
[0][3])
452 _mesa_ColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
455 if (state
& MESA_META_DEPTH_TEST
) {
456 save
->Depth
= ctx
->Depth
; /* struct copy */
458 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_FALSE
);
461 if (state
& MESA_META_FOG
) {
462 save
->Fog
= ctx
->Fog
.Enabled
;
463 if (ctx
->Fog
.Enabled
)
464 _mesa_set_enable(ctx
, GL_FOG
, GL_FALSE
);
467 if (state
& MESA_META_PIXEL_STORE
) {
468 save
->Pack
= ctx
->Pack
;
469 save
->Unpack
= ctx
->Unpack
;
470 ctx
->Pack
= ctx
->DefaultPacking
;
471 ctx
->Unpack
= ctx
->DefaultPacking
;
474 if (state
& MESA_META_PIXEL_TRANSFER
) {
475 save
->RedScale
= ctx
->Pixel
.RedScale
;
476 save
->RedBias
= ctx
->Pixel
.RedBias
;
477 save
->GreenScale
= ctx
->Pixel
.GreenScale
;
478 save
->GreenBias
= ctx
->Pixel
.GreenBias
;
479 save
->BlueScale
= ctx
->Pixel
.BlueScale
;
480 save
->BlueBias
= ctx
->Pixel
.BlueBias
;
481 save
->AlphaScale
= ctx
->Pixel
.AlphaScale
;
482 save
->AlphaBias
= ctx
->Pixel
.AlphaBias
;
483 save
->MapColorFlag
= ctx
->Pixel
.MapColorFlag
;
484 ctx
->Pixel
.RedScale
= 1.0F
;
485 ctx
->Pixel
.RedBias
= 0.0F
;
486 ctx
->Pixel
.GreenScale
= 1.0F
;
487 ctx
->Pixel
.GreenBias
= 0.0F
;
488 ctx
->Pixel
.BlueScale
= 1.0F
;
489 ctx
->Pixel
.BlueBias
= 0.0F
;
490 ctx
->Pixel
.AlphaScale
= 1.0F
;
491 ctx
->Pixel
.AlphaBias
= 0.0F
;
492 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
494 ctx
->NewState
|=_NEW_PIXEL
;
497 if (state
& MESA_META_RASTERIZATION
) {
498 save
->FrontPolygonMode
= ctx
->Polygon
.FrontMode
;
499 save
->BackPolygonMode
= ctx
->Polygon
.BackMode
;
500 save
->PolygonOffset
= ctx
->Polygon
.OffsetFill
;
501 save
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
502 save
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
503 save
->PolygonCull
= ctx
->Polygon
.CullFlag
;
504 _mesa_PolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
505 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, GL_FALSE
);
506 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, GL_FALSE
);
507 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, GL_FALSE
);
508 _mesa_set_enable(ctx
, GL_CULL_FACE
, GL_FALSE
);
511 if (state
& MESA_META_SCISSOR
) {
512 save
->Scissor
= ctx
->Scissor
; /* struct copy */
513 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, GL_FALSE
);
516 if (state
& MESA_META_SHADER
) {
519 if (ctx
->Extensions
.ARB_vertex_program
) {
520 save
->VertexProgramEnabled
= ctx
->VertexProgram
.Enabled
;
521 _mesa_reference_vertprog(ctx
, &save
->VertexProgram
,
522 ctx
->VertexProgram
.Current
);
523 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
, GL_FALSE
);
526 if (ctx
->Extensions
.ARB_fragment_program
) {
527 save
->FragmentProgramEnabled
= ctx
->FragmentProgram
.Enabled
;
528 _mesa_reference_fragprog(ctx
, &save
->FragmentProgram
,
529 ctx
->FragmentProgram
.Current
);
530 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_FALSE
);
533 if (ctx
->Extensions
.ATI_fragment_shader
) {
534 save
->ATIFragmentShaderEnabled
= ctx
->ATIFragmentShader
.Enabled
;
535 _mesa_set_enable(ctx
, GL_FRAGMENT_SHADER_ATI
, GL_FALSE
);
538 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
539 _mesa_reference_shader_program(ctx
, &save
->Shader
[i
],
540 ctx
->_Shader
->CurrentProgram
[i
]);
542 _mesa_reference_shader_program(ctx
, &save
->ActiveShader
,
543 ctx
->_Shader
->ActiveProgram
);
548 if (state
& MESA_META_STENCIL_TEST
) {
549 save
->Stencil
= ctx
->Stencil
; /* struct copy */
550 if (ctx
->Stencil
.Enabled
)
551 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_FALSE
);
552 /* NOTE: other stencil state not reset */
555 if (state
& MESA_META_TEXTURE
) {
558 save
->ActiveUnit
= ctx
->Texture
.CurrentUnit
;
559 save
->ClientActiveUnit
= ctx
->Array
.ActiveTexture
;
560 save
->EnvMode
= ctx
->Texture
.Unit
[0].EnvMode
;
562 /* Disable all texture units */
563 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
564 save
->TexEnabled
[u
] = ctx
->Texture
.Unit
[u
].Enabled
;
565 save
->TexGenEnabled
[u
] = ctx
->Texture
.Unit
[u
].TexGenEnabled
;
566 if (ctx
->Texture
.Unit
[u
].Enabled
||
567 ctx
->Texture
.Unit
[u
].TexGenEnabled
) {
568 _mesa_ActiveTexture(GL_TEXTURE0
+ u
);
569 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
570 if (ctx
->Extensions
.ARB_texture_cube_map
)
571 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
573 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
574 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
575 if (ctx
->Extensions
.NV_texture_rectangle
)
576 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE
, GL_FALSE
);
577 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
578 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
579 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
580 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
584 /* save current texture objects for unit[0] only */
585 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
586 _mesa_reference_texobj(&save
->CurrentTexture
[tgt
],
587 ctx
->Texture
.Unit
[0].CurrentTex
[tgt
]);
590 /* set defaults for unit[0] */
591 _mesa_ActiveTexture(GL_TEXTURE0
);
592 _mesa_ClientActiveTexture(GL_TEXTURE0
);
593 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
596 if (state
& MESA_META_TRANSFORM
) {
597 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
598 memcpy(save
->ModelviewMatrix
, ctx
->ModelviewMatrixStack
.Top
->m
,
599 16 * sizeof(GLfloat
));
600 memcpy(save
->ProjectionMatrix
, ctx
->ProjectionMatrixStack
.Top
->m
,
601 16 * sizeof(GLfloat
));
602 memcpy(save
->TextureMatrix
, ctx
->TextureMatrixStack
[0].Top
->m
,
603 16 * sizeof(GLfloat
));
604 save
->MatrixMode
= ctx
->Transform
.MatrixMode
;
605 /* set 1:1 vertex:pixel coordinate transform */
606 _mesa_ActiveTexture(GL_TEXTURE0
);
607 _mesa_MatrixMode(GL_TEXTURE
);
608 _mesa_LoadIdentity();
609 _mesa_ActiveTexture(GL_TEXTURE0
+ activeTexture
);
610 _mesa_MatrixMode(GL_MODELVIEW
);
611 _mesa_LoadIdentity();
612 _mesa_MatrixMode(GL_PROJECTION
);
613 _mesa_LoadIdentity();
615 /* glOrtho with width = 0 or height = 0 generates GL_INVALID_VALUE.
616 * This can occur when there is no draw buffer.
618 if (ctx
->DrawBuffer
->Width
!= 0 && ctx
->DrawBuffer
->Height
!= 0)
619 _mesa_Ortho(0.0, ctx
->DrawBuffer
->Width
,
620 0.0, ctx
->DrawBuffer
->Height
,
624 if (state
& MESA_META_CLIP
) {
625 save
->ClipPlanesEnabled
= ctx
->Transform
.ClipPlanesEnabled
;
626 if (ctx
->Transform
.ClipPlanesEnabled
) {
628 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
629 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
634 if (state
& MESA_META_VERTEX
) {
635 /* save vertex array object state */
636 _mesa_reference_vao(ctx
, &save
->VAO
,
638 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
,
639 ctx
->Array
.ArrayBufferObj
);
640 /* set some default state? */
643 if (state
& MESA_META_VIEWPORT
) {
644 /* save viewport state */
645 save
->ViewportX
= ctx
->ViewportArray
[0].X
;
646 save
->ViewportY
= ctx
->ViewportArray
[0].Y
;
647 save
->ViewportW
= ctx
->ViewportArray
[0].Width
;
648 save
->ViewportH
= ctx
->ViewportArray
[0].Height
;
649 /* set viewport to match window size */
650 if (ctx
->ViewportArray
[0].X
!= 0 ||
651 ctx
->ViewportArray
[0].Y
!= 0 ||
652 ctx
->ViewportArray
[0].Width
!= (float) ctx
->DrawBuffer
->Width
||
653 ctx
->ViewportArray
[0].Height
!= (float) ctx
->DrawBuffer
->Height
) {
654 _mesa_set_viewport(ctx
, 0, 0, 0,
655 ctx
->DrawBuffer
->Width
, ctx
->DrawBuffer
->Height
);
657 /* save depth range state */
658 save
->DepthNear
= ctx
->ViewportArray
[0].Near
;
659 save
->DepthFar
= ctx
->ViewportArray
[0].Far
;
660 /* set depth range to default */
661 _mesa_DepthRange(0.0, 1.0);
664 if (state
& MESA_META_CLAMP_FRAGMENT_COLOR
) {
665 save
->ClampFragmentColor
= ctx
->Color
.ClampFragmentColor
;
667 /* Generally in here we want to do clamping according to whether
668 * it's for the pixel path (ClampFragmentColor is GL_TRUE),
669 * regardless of the internal implementation of the metaops.
671 if (ctx
->Color
.ClampFragmentColor
!= GL_TRUE
&&
672 ctx
->Extensions
.ARB_color_buffer_float
)
673 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, GL_FALSE
);
676 if (state
& MESA_META_CLAMP_VERTEX_COLOR
) {
677 save
->ClampVertexColor
= ctx
->Light
.ClampVertexColor
;
679 /* Generally in here we never want vertex color clamping --
680 * result clamping is only dependent on fragment clamping.
682 if (ctx
->Extensions
.ARB_color_buffer_float
)
683 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR
, GL_FALSE
);
686 if (state
& MESA_META_CONDITIONAL_RENDER
) {
687 save
->CondRenderQuery
= ctx
->Query
.CondRenderQuery
;
688 save
->CondRenderMode
= ctx
->Query
.CondRenderMode
;
690 if (ctx
->Query
.CondRenderQuery
)
691 _mesa_EndConditionalRender();
694 if (state
& MESA_META_SELECT_FEEDBACK
) {
695 save
->RenderMode
= ctx
->RenderMode
;
696 if (ctx
->RenderMode
== GL_SELECT
) {
697 save
->Select
= ctx
->Select
; /* struct copy */
698 _mesa_RenderMode(GL_RENDER
);
699 } else if (ctx
->RenderMode
== GL_FEEDBACK
) {
700 save
->Feedback
= ctx
->Feedback
; /* struct copy */
701 _mesa_RenderMode(GL_RENDER
);
705 if (state
& MESA_META_MULTISAMPLE
) {
706 save
->Multisample
= ctx
->Multisample
; /* struct copy */
708 if (ctx
->Multisample
.Enabled
)
709 _mesa_set_multisample(ctx
, GL_FALSE
);
710 if (ctx
->Multisample
.SampleCoverage
)
711 _mesa_set_enable(ctx
, GL_SAMPLE_COVERAGE
, GL_FALSE
);
712 if (ctx
->Multisample
.SampleAlphaToCoverage
)
713 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_COVERAGE
, GL_FALSE
);
714 if (ctx
->Multisample
.SampleAlphaToOne
)
715 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_ONE
, GL_FALSE
);
716 if (ctx
->Multisample
.SampleShading
)
717 _mesa_set_enable(ctx
, GL_SAMPLE_SHADING
, GL_FALSE
);
718 if (ctx
->Multisample
.SampleMask
)
719 _mesa_set_enable(ctx
, GL_SAMPLE_MASK
, GL_FALSE
);
722 if (state
& MESA_META_FRAMEBUFFER_SRGB
) {
723 save
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
724 if (ctx
->Color
.sRGBEnabled
)
725 _mesa_set_framebuffer_srgb(ctx
, GL_FALSE
);
730 save
->Lighting
= ctx
->Light
.Enabled
;
731 if (ctx
->Light
.Enabled
)
732 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_FALSE
);
733 save
->RasterDiscard
= ctx
->RasterDiscard
;
734 if (ctx
->RasterDiscard
)
735 _mesa_set_enable(ctx
, GL_RASTERIZER_DISCARD
, GL_FALSE
);
737 save
->DrawBufferName
= ctx
->DrawBuffer
->Name
;
738 save
->ReadBufferName
= ctx
->ReadBuffer
->Name
;
739 save
->RenderbufferName
= (ctx
->CurrentRenderbuffer
?
740 ctx
->CurrentRenderbuffer
->Name
: 0);
746 * Leave meta state. This is like a light-weight version of glPopAttrib().
749 _mesa_meta_end(struct gl_context
*ctx
)
751 struct save_state
*save
= &ctx
->Meta
->Save
[ctx
->Meta
->SaveStackDepth
- 1];
752 const GLbitfield state
= save
->SavedState
;
755 /* After starting a new occlusion query, initialize the results to the
756 * values saved previously. The driver will then continue to increment
759 if (state
& MESA_META_OCCLUSION_QUERY
) {
760 if (save
->CurrentOcclusionObject
) {
761 _mesa_BeginQuery(save
->CurrentOcclusionObject
->Target
,
762 save
->CurrentOcclusionObject
->Id
);
763 ctx
->Query
.CurrentOcclusionObject
->Result
= save
->CurrentOcclusionObject
->Result
;
767 if (state
& MESA_META_ALPHA_TEST
) {
768 if (ctx
->Color
.AlphaEnabled
!= save
->AlphaEnabled
)
769 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, save
->AlphaEnabled
);
770 _mesa_AlphaFunc(save
->AlphaFunc
, save
->AlphaRef
);
773 if (state
& MESA_META_BLEND
) {
774 if (ctx
->Color
.BlendEnabled
!= save
->BlendEnabled
) {
775 if (ctx
->Extensions
.EXT_draw_buffers2
) {
777 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
778 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (save
->BlendEnabled
>> i
) & 1);
782 _mesa_set_enable(ctx
, GL_BLEND
, (save
->BlendEnabled
& 1));
785 if (ctx
->Color
.ColorLogicOpEnabled
!= save
->ColorLogicOpEnabled
)
786 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, save
->ColorLogicOpEnabled
);
789 if (state
& MESA_META_COLOR_MASK
) {
791 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
792 if (!TEST_EQ_4V(ctx
->Color
.ColorMask
[i
], save
->ColorMask
[i
])) {
794 _mesa_ColorMask(save
->ColorMask
[i
][0], save
->ColorMask
[i
][1],
795 save
->ColorMask
[i
][2], save
->ColorMask
[i
][3]);
799 save
->ColorMask
[i
][0],
800 save
->ColorMask
[i
][1],
801 save
->ColorMask
[i
][2],
802 save
->ColorMask
[i
][3]);
808 if (state
& MESA_META_DEPTH_TEST
) {
809 if (ctx
->Depth
.Test
!= save
->Depth
.Test
)
810 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, save
->Depth
.Test
);
811 _mesa_DepthFunc(save
->Depth
.Func
);
812 _mesa_DepthMask(save
->Depth
.Mask
);
815 if (state
& MESA_META_FOG
) {
816 _mesa_set_enable(ctx
, GL_FOG
, save
->Fog
);
819 if (state
& MESA_META_PIXEL_STORE
) {
820 ctx
->Pack
= save
->Pack
;
821 ctx
->Unpack
= save
->Unpack
;
824 if (state
& MESA_META_PIXEL_TRANSFER
) {
825 ctx
->Pixel
.RedScale
= save
->RedScale
;
826 ctx
->Pixel
.RedBias
= save
->RedBias
;
827 ctx
->Pixel
.GreenScale
= save
->GreenScale
;
828 ctx
->Pixel
.GreenBias
= save
->GreenBias
;
829 ctx
->Pixel
.BlueScale
= save
->BlueScale
;
830 ctx
->Pixel
.BlueBias
= save
->BlueBias
;
831 ctx
->Pixel
.AlphaScale
= save
->AlphaScale
;
832 ctx
->Pixel
.AlphaBias
= save
->AlphaBias
;
833 ctx
->Pixel
.MapColorFlag
= save
->MapColorFlag
;
835 ctx
->NewState
|=_NEW_PIXEL
;
838 if (state
& MESA_META_RASTERIZATION
) {
839 _mesa_PolygonMode(GL_FRONT
, save
->FrontPolygonMode
);
840 _mesa_PolygonMode(GL_BACK
, save
->BackPolygonMode
);
841 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, save
->PolygonStipple
);
842 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, save
->PolygonSmooth
);
843 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, save
->PolygonOffset
);
844 _mesa_set_enable(ctx
, GL_CULL_FACE
, save
->PolygonCull
);
847 if (state
& MESA_META_SCISSOR
) {
850 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
851 _mesa_set_scissor(ctx
, i
,
852 save
->Scissor
.ScissorArray
[i
].X
,
853 save
->Scissor
.ScissorArray
[i
].Y
,
854 save
->Scissor
.ScissorArray
[i
].Width
,
855 save
->Scissor
.ScissorArray
[i
].Height
);
856 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
857 (save
->Scissor
.EnableFlags
>> i
) & 1);
861 if (state
& MESA_META_SHADER
) {
862 if (ctx
->Extensions
.ARB_vertex_program
) {
863 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
,
864 save
->VertexProgramEnabled
);
865 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
866 save
->VertexProgram
);
867 _mesa_reference_vertprog(ctx
, &save
->VertexProgram
, NULL
);
870 if (ctx
->Extensions
.ARB_fragment_program
) {
871 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
872 save
->FragmentProgramEnabled
);
873 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
874 save
->FragmentProgram
);
875 _mesa_reference_fragprog(ctx
, &save
->FragmentProgram
, NULL
);
878 if (ctx
->Extensions
.ATI_fragment_shader
) {
879 _mesa_set_enable(ctx
, GL_FRAGMENT_SHADER_ATI
,
880 save
->ATIFragmentShaderEnabled
);
883 if (ctx
->Extensions
.ARB_vertex_shader
) {
884 _mesa_use_shader_program(ctx
, GL_VERTEX_SHADER
,
885 save
->Shader
[MESA_SHADER_VERTEX
]);
888 if (_mesa_has_geometry_shaders(ctx
))
889 _mesa_use_shader_program(ctx
, GL_GEOMETRY_SHADER_ARB
,
890 save
->Shader
[MESA_SHADER_GEOMETRY
]);
892 if (ctx
->Extensions
.ARB_fragment_shader
)
893 _mesa_use_shader_program(ctx
, GL_FRAGMENT_SHADER
,
894 save
->Shader
[MESA_SHADER_FRAGMENT
]);
896 _mesa_reference_shader_program(ctx
, &ctx
->_Shader
->ActiveProgram
,
899 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++)
900 _mesa_reference_shader_program(ctx
, &save
->Shader
[i
], NULL
);
901 _mesa_reference_shader_program(ctx
, &save
->ActiveShader
, NULL
);
904 if (state
& MESA_META_STENCIL_TEST
) {
905 const struct gl_stencil_attrib
*stencil
= &save
->Stencil
;
907 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
908 _mesa_ClearStencil(stencil
->Clear
);
909 if (ctx
->Extensions
.EXT_stencil_two_side
) {
910 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
911 stencil
->TestTwoSide
);
912 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
913 ? GL_BACK
: GL_FRONT
);
916 _mesa_StencilFuncSeparate(GL_FRONT
,
917 stencil
->Function
[0],
919 stencil
->ValueMask
[0]);
920 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
921 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
922 stencil
->ZFailFunc
[0],
923 stencil
->ZPassFunc
[0]);
925 _mesa_StencilFuncSeparate(GL_BACK
,
926 stencil
->Function
[1],
928 stencil
->ValueMask
[1]);
929 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
930 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
931 stencil
->ZFailFunc
[1],
932 stencil
->ZPassFunc
[1]);
935 if (state
& MESA_META_TEXTURE
) {
938 ASSERT(ctx
->Texture
.CurrentUnit
== 0);
940 /* restore texenv for unit[0] */
941 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, save
->EnvMode
);
943 /* restore texture objects for unit[0] only */
944 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
945 if (ctx
->Texture
.Unit
[0].CurrentTex
[tgt
] != save
->CurrentTexture
[tgt
]) {
946 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
947 _mesa_reference_texobj(&ctx
->Texture
.Unit
[0].CurrentTex
[tgt
],
948 save
->CurrentTexture
[tgt
]);
950 _mesa_reference_texobj(&save
->CurrentTexture
[tgt
], NULL
);
953 /* Restore fixed function texture enables, texgen */
954 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
955 if (ctx
->Texture
.Unit
[u
].Enabled
!= save
->TexEnabled
[u
]) {
956 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
957 ctx
->Texture
.Unit
[u
].Enabled
= save
->TexEnabled
[u
];
960 if (ctx
->Texture
.Unit
[u
].TexGenEnabled
!= save
->TexGenEnabled
[u
]) {
961 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
962 ctx
->Texture
.Unit
[u
].TexGenEnabled
= save
->TexGenEnabled
[u
];
966 /* restore current unit state */
967 _mesa_ActiveTexture(GL_TEXTURE0
+ save
->ActiveUnit
);
968 _mesa_ClientActiveTexture(GL_TEXTURE0
+ save
->ClientActiveUnit
);
971 if (state
& MESA_META_TRANSFORM
) {
972 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
973 _mesa_ActiveTexture(GL_TEXTURE0
);
974 _mesa_MatrixMode(GL_TEXTURE
);
975 _mesa_LoadMatrixf(save
->TextureMatrix
);
976 _mesa_ActiveTexture(GL_TEXTURE0
+ activeTexture
);
978 _mesa_MatrixMode(GL_MODELVIEW
);
979 _mesa_LoadMatrixf(save
->ModelviewMatrix
);
981 _mesa_MatrixMode(GL_PROJECTION
);
982 _mesa_LoadMatrixf(save
->ProjectionMatrix
);
984 _mesa_MatrixMode(save
->MatrixMode
);
987 if (state
& MESA_META_CLIP
) {
988 if (save
->ClipPlanesEnabled
) {
990 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
991 if (save
->ClipPlanesEnabled
& (1 << i
)) {
992 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
998 if (state
& MESA_META_VERTEX
) {
999 /* restore vertex buffer object */
1000 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
, save
->ArrayBufferObj
->Name
);
1001 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
, NULL
);
1003 /* restore vertex array object */
1004 _mesa_BindVertexArray(save
->VAO
->Name
);
1005 _mesa_reference_vao(ctx
, &save
->VAO
, NULL
);
1008 if (state
& MESA_META_VIEWPORT
) {
1009 if (save
->ViewportX
!= ctx
->ViewportArray
[0].X
||
1010 save
->ViewportY
!= ctx
->ViewportArray
[0].Y
||
1011 save
->ViewportW
!= ctx
->ViewportArray
[0].Width
||
1012 save
->ViewportH
!= ctx
->ViewportArray
[0].Height
) {
1013 _mesa_set_viewport(ctx
, 0, save
->ViewportX
, save
->ViewportY
,
1014 save
->ViewportW
, save
->ViewportH
);
1016 _mesa_DepthRange(save
->DepthNear
, save
->DepthFar
);
1019 if (state
& MESA_META_CLAMP_FRAGMENT_COLOR
&&
1020 ctx
->Extensions
.ARB_color_buffer_float
) {
1021 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, save
->ClampFragmentColor
);
1024 if (state
& MESA_META_CLAMP_VERTEX_COLOR
&&
1025 ctx
->Extensions
.ARB_color_buffer_float
) {
1026 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR
, save
->ClampVertexColor
);
1029 if (state
& MESA_META_CONDITIONAL_RENDER
) {
1030 if (save
->CondRenderQuery
)
1031 _mesa_BeginConditionalRender(save
->CondRenderQuery
->Id
,
1032 save
->CondRenderMode
);
1035 if (state
& MESA_META_SELECT_FEEDBACK
) {
1036 if (save
->RenderMode
== GL_SELECT
) {
1037 _mesa_RenderMode(GL_SELECT
);
1038 ctx
->Select
= save
->Select
;
1039 } else if (save
->RenderMode
== GL_FEEDBACK
) {
1040 _mesa_RenderMode(GL_FEEDBACK
);
1041 ctx
->Feedback
= save
->Feedback
;
1045 if (state
& MESA_META_MULTISAMPLE
) {
1046 struct gl_multisample_attrib
*ctx_ms
= &ctx
->Multisample
;
1047 struct gl_multisample_attrib
*save_ms
= &save
->Multisample
;
1049 if (ctx_ms
->Enabled
!= save_ms
->Enabled
)
1050 _mesa_set_multisample(ctx
, save_ms
->Enabled
);
1051 if (ctx_ms
->SampleCoverage
!= save_ms
->SampleCoverage
)
1052 _mesa_set_enable(ctx
, GL_SAMPLE_COVERAGE
, save_ms
->SampleCoverage
);
1053 if (ctx_ms
->SampleAlphaToCoverage
!= save_ms
->SampleAlphaToCoverage
)
1054 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_COVERAGE
, save_ms
->SampleAlphaToCoverage
);
1055 if (ctx_ms
->SampleAlphaToOne
!= save_ms
->SampleAlphaToOne
)
1056 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_ONE
, save_ms
->SampleAlphaToOne
);
1057 if (ctx_ms
->SampleCoverageValue
!= save_ms
->SampleCoverageValue
||
1058 ctx_ms
->SampleCoverageInvert
!= save_ms
->SampleCoverageInvert
) {
1059 _mesa_SampleCoverage(save_ms
->SampleCoverageValue
,
1060 save_ms
->SampleCoverageInvert
);
1062 if (ctx_ms
->SampleShading
!= save_ms
->SampleShading
)
1063 _mesa_set_enable(ctx
, GL_SAMPLE_SHADING
, save_ms
->SampleShading
);
1064 if (ctx_ms
->SampleMask
!= save_ms
->SampleMask
)
1065 _mesa_set_enable(ctx
, GL_SAMPLE_MASK
, save_ms
->SampleMask
);
1066 if (ctx_ms
->SampleMaskValue
!= save_ms
->SampleMaskValue
)
1067 _mesa_SampleMaski(0, save_ms
->SampleMaskValue
);
1068 if (ctx_ms
->MinSampleShadingValue
!= save_ms
->MinSampleShadingValue
)
1069 _mesa_MinSampleShading(save_ms
->MinSampleShadingValue
);
1072 if (state
& MESA_META_FRAMEBUFFER_SRGB
) {
1073 if (ctx
->Color
.sRGBEnabled
!= save
->sRGBEnabled
)
1074 _mesa_set_framebuffer_srgb(ctx
, save
->sRGBEnabled
);
1078 if (save
->Lighting
) {
1079 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_TRUE
);
1081 if (save
->RasterDiscard
) {
1082 _mesa_set_enable(ctx
, GL_RASTERIZER_DISCARD
, GL_TRUE
);
1084 if (save
->TransformFeedbackNeedsResume
)
1085 _mesa_ResumeTransformFeedback();
1087 if (ctx
->DrawBuffer
->Name
!= save
->DrawBufferName
)
1088 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, save
->DrawBufferName
);
1090 if (ctx
->ReadBuffer
->Name
!= save
->ReadBufferName
)
1091 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, save
->ReadBufferName
);
1093 if (!ctx
->CurrentRenderbuffer
||
1094 ctx
->CurrentRenderbuffer
->Name
!= save
->RenderbufferName
)
1095 _mesa_BindRenderbuffer(GL_RENDERBUFFER
, save
->RenderbufferName
);
1097 ctx
->Meta
->SaveStackDepth
--;
1099 ctx
->API
= save
->API
;
1104 * Determine whether Mesa is currently in a meta state.
1107 _mesa_meta_in_progress(struct gl_context
*ctx
)
1109 return ctx
->Meta
->SaveStackDepth
!= 0;
1114 * Convert Z from a normalized value in the range [0, 1] to an object-space
1115 * Z coordinate in [-1, +1] so that drawing at the new Z position with the
1116 * default/identity ortho projection results in the original Z value.
1117 * Used by the meta-Clear, Draw/CopyPixels and Bitmap functions where the Z
1118 * value comes from the clear value or raster position.
1120 static INLINE GLfloat
1121 invert_z(GLfloat normZ
)
1123 GLfloat objZ
= 1.0f
- 2.0f
* normZ
;
1129 * One-time init for a temp_texture object.
1130 * Choose tex target, compute max tex size, etc.
1133 init_temp_texture(struct gl_context
*ctx
, struct temp_texture
*tex
)
1135 /* prefer texture rectangle */
1136 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
) {
1137 tex
->Target
= GL_TEXTURE_RECTANGLE
;
1138 tex
->MaxSize
= ctx
->Const
.MaxTextureRectSize
;
1139 tex
->NPOT
= GL_TRUE
;
1142 /* use 2D texture, NPOT if possible */
1143 tex
->Target
= GL_TEXTURE_2D
;
1144 tex
->MaxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1145 tex
->NPOT
= ctx
->Extensions
.ARB_texture_non_power_of_two
;
1147 tex
->MinSize
= 16; /* 16 x 16 at least */
1148 assert(tex
->MaxSize
> 0);
1150 _mesa_GenTextures(1, &tex
->TexObj
);
1154 cleanup_temp_texture(struct temp_texture
*tex
)
1158 _mesa_DeleteTextures(1, &tex
->TexObj
);
1164 * Return pointer to temp_texture info for non-bitmap ops.
1165 * This does some one-time init if needed.
1167 struct temp_texture
*
1168 _mesa_meta_get_temp_texture(struct gl_context
*ctx
)
1170 struct temp_texture
*tex
= &ctx
->Meta
->TempTex
;
1173 init_temp_texture(ctx
, tex
);
1181 * Return pointer to temp_texture info for _mesa_meta_bitmap().
1182 * We use a separate texture for bitmaps to reduce texture
1183 * allocation/deallocation.
1185 static struct temp_texture
*
1186 get_bitmap_temp_texture(struct gl_context
*ctx
)
1188 struct temp_texture
*tex
= &ctx
->Meta
->Bitmap
.Tex
;
1191 init_temp_texture(ctx
, tex
);
1198 * Return pointer to depth temp_texture.
1199 * This does some one-time init if needed.
1201 struct temp_texture
*
1202 _mesa_meta_get_temp_depth_texture(struct gl_context
*ctx
)
1204 struct temp_texture
*tex
= &ctx
->Meta
->Blit
.depthTex
;
1207 init_temp_texture(ctx
, tex
);
1214 * Compute the width/height of texture needed to draw an image of the
1215 * given size. Return a flag indicating whether the current texture
1216 * can be re-used (glTexSubImage2D) or if a new texture needs to be
1217 * allocated (glTexImage2D).
1218 * Also, compute s/t texcoords for drawing.
1220 * \return GL_TRUE if new texture is needed, GL_FALSE otherwise
1223 _mesa_meta_alloc_texture(struct temp_texture
*tex
,
1224 GLsizei width
, GLsizei height
, GLenum intFormat
)
1226 GLboolean newTex
= GL_FALSE
;
1228 ASSERT(width
<= tex
->MaxSize
);
1229 ASSERT(height
<= tex
->MaxSize
);
1231 if (width
> tex
->Width
||
1232 height
> tex
->Height
||
1233 intFormat
!= tex
->IntFormat
) {
1234 /* alloc new texture (larger or different format) */
1237 /* use non-power of two size */
1238 tex
->Width
= MAX2(tex
->MinSize
, width
);
1239 tex
->Height
= MAX2(tex
->MinSize
, height
);
1242 /* find power of two size */
1244 w
= h
= tex
->MinSize
;
1253 tex
->IntFormat
= intFormat
;
1258 /* compute texcoords */
1259 if (tex
->Target
== GL_TEXTURE_RECTANGLE
) {
1260 tex
->Sright
= (GLfloat
) width
;
1261 tex
->Ttop
= (GLfloat
) height
;
1264 tex
->Sright
= (GLfloat
) width
/ tex
->Width
;
1265 tex
->Ttop
= (GLfloat
) height
/ tex
->Height
;
1273 * Setup/load texture for glCopyPixels or glBlitFramebuffer.
1276 _mesa_meta_setup_copypix_texture(struct gl_context
*ctx
,
1277 struct temp_texture
*tex
,
1278 GLint srcX
, GLint srcY
,
1279 GLsizei width
, GLsizei height
,
1285 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
1286 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, filter
);
1287 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, filter
);
1288 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
1290 newTex
= _mesa_meta_alloc_texture(tex
, width
, height
, intFormat
);
1292 /* copy framebuffer image to texture */
1294 /* create new tex image */
1295 if (tex
->Width
== width
&& tex
->Height
== height
) {
1296 /* create new tex with framebuffer data */
1297 _mesa_CopyTexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1298 srcX
, srcY
, width
, height
, 0);
1301 /* create empty texture */
1302 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1303 tex
->Width
, tex
->Height
, 0,
1304 intFormat
, GL_UNSIGNED_BYTE
, NULL
);
1306 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
1307 0, 0, srcX
, srcY
, width
, height
);
1311 /* replace existing tex image */
1312 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
1313 0, 0, srcX
, srcY
, width
, height
);
1319 * Setup/load texture for glDrawPixels.
1322 _mesa_meta_setup_drawpix_texture(struct gl_context
*ctx
,
1323 struct temp_texture
*tex
,
1325 GLsizei width
, GLsizei height
,
1326 GLenum format
, GLenum type
,
1327 const GLvoid
*pixels
)
1329 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
1330 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1331 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1332 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
1334 /* copy pixel data to texture */
1336 /* create new tex image */
1337 if (tex
->Width
== width
&& tex
->Height
== height
) {
1338 /* create new tex and load image data */
1339 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1340 tex
->Width
, tex
->Height
, 0, format
, type
, pixels
);
1343 struct gl_buffer_object
*save_unpack_obj
= NULL
;
1345 _mesa_reference_buffer_object(ctx
, &save_unpack_obj
,
1346 ctx
->Unpack
.BufferObj
);
1347 _mesa_BindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
1348 /* create empty texture */
1349 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1350 tex
->Width
, tex
->Height
, 0, format
, type
, NULL
);
1351 if (save_unpack_obj
!= NULL
)
1352 _mesa_BindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB
,
1353 save_unpack_obj
->Name
);
1355 _mesa_TexSubImage2D(tex
->Target
, 0,
1356 0, 0, width
, height
, format
, type
, pixels
);
1360 /* replace existing tex image */
1361 _mesa_TexSubImage2D(tex
->Target
, 0,
1362 0, 0, width
, height
, format
, type
, pixels
);
1367 _mesa_meta_setup_ff_tnl_for_blit(GLuint
*VAO
, GLuint
*VBO
,
1368 unsigned texcoord_size
)
1370 _mesa_meta_setup_vertex_objects(VAO
, VBO
, false, 2, texcoord_size
, 0);
1372 /* setup projection matrix */
1373 _mesa_MatrixMode(GL_PROJECTION
);
1374 _mesa_LoadIdentity();
1378 * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
1381 _mesa_meta_Clear(struct gl_context
*ctx
, GLbitfield buffers
)
1383 struct clear_state
*clear
= &ctx
->Meta
->Clear
;
1384 struct vertex verts
[4];
1385 /* save all state but scissor, pixel pack/unpack */
1386 GLbitfield metaSave
= (MESA_META_ALL
-
1388 MESA_META_PIXEL_STORE
-
1389 MESA_META_CONDITIONAL_RENDER
-
1390 MESA_META_FRAMEBUFFER_SRGB
);
1391 const GLuint stencilMax
= (1 << ctx
->DrawBuffer
->Visual
.stencilBits
) - 1;
1393 if (buffers
& BUFFER_BITS_COLOR
) {
1394 /* if clearing color buffers, don't save/restore colormask */
1395 metaSave
-= MESA_META_COLOR_MASK
;
1398 _mesa_meta_begin(ctx
, metaSave
);
1400 _mesa_meta_setup_vertex_objects(&clear
->VAO
, &clear
->VBO
, false, 3, 0, 4);
1402 /* GL_COLOR_BUFFER_BIT */
1403 if (buffers
& BUFFER_BITS_COLOR
) {
1404 /* leave colormask, glDrawBuffer state as-is */
1406 /* Clears never have the color clamped. */
1407 if (ctx
->Extensions
.ARB_color_buffer_float
)
1408 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, GL_FALSE
);
1411 ASSERT(metaSave
& MESA_META_COLOR_MASK
);
1412 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1415 /* GL_DEPTH_BUFFER_BIT */
1416 if (buffers
& BUFFER_BIT_DEPTH
) {
1417 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1418 _mesa_DepthFunc(GL_ALWAYS
);
1419 _mesa_DepthMask(GL_TRUE
);
1422 assert(!ctx
->Depth
.Test
);
1425 /* GL_STENCIL_BUFFER_BIT */
1426 if (buffers
& BUFFER_BIT_STENCIL
) {
1427 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1428 _mesa_StencilOpSeparate(GL_FRONT_AND_BACK
,
1429 GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1430 _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK
, GL_ALWAYS
,
1431 ctx
->Stencil
.Clear
& stencilMax
,
1432 ctx
->Stencil
.WriteMask
[0]);
1435 assert(!ctx
->Stencil
.Enabled
);
1438 /* vertex positions/colors */
1440 const GLfloat x0
= (GLfloat
) ctx
->DrawBuffer
->_Xmin
;
1441 const GLfloat y0
= (GLfloat
) ctx
->DrawBuffer
->_Ymin
;
1442 const GLfloat x1
= (GLfloat
) ctx
->DrawBuffer
->_Xmax
;
1443 const GLfloat y1
= (GLfloat
) ctx
->DrawBuffer
->_Ymax
;
1444 const GLfloat z
= invert_z(ctx
->Depth
.Clear
);
1461 for (i
= 0; i
< 4; i
++) {
1462 verts
[i
].r
= ctx
->Color
.ClearColor
.f
[0];
1463 verts
[i
].g
= ctx
->Color
.ClearColor
.f
[1];
1464 verts
[i
].b
= ctx
->Color
.ClearColor
.f
[2];
1465 verts
[i
].a
= ctx
->Color
.ClearColor
.f
[3];
1468 /* upload new vertex data */
1469 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), verts
,
1470 GL_DYNAMIC_DRAW_ARB
);
1474 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1476 _mesa_meta_end(ctx
);
1480 meta_glsl_clear_init(struct gl_context
*ctx
, struct clear_state
*clear
)
1482 const char *vs_source
=
1483 "attribute vec4 position;\n"
1486 " gl_Position = position;\n"
1488 const char *gs_source
=
1490 "layout(triangles) in;\n"
1491 "layout(triangle_strip, max_vertices = 4) out;\n"
1492 "uniform int layer;\n"
1495 " for (int i = 0; i < 3; i++) {\n"
1496 " gl_Layer = layer;\n"
1497 " gl_Position = gl_in[i].gl_Position;\n"
1501 const char *fs_source
=
1502 "uniform vec4 color;\n"
1505 " gl_FragColor = color;\n"
1507 GLuint vs
, gs
= 0, fs
;
1508 bool has_integer_textures
;
1510 _mesa_meta_setup_vertex_objects(&clear
->VAO
, &clear
->VBO
, true, 3, 0, 0);
1512 if (clear
->ShaderProg
!= 0)
1515 vs
= _mesa_CreateShader(GL_VERTEX_SHADER
);
1516 _mesa_ShaderSource(vs
, 1, &vs_source
, NULL
);
1517 _mesa_CompileShader(vs
);
1519 if (_mesa_has_geometry_shaders(ctx
)) {
1520 gs
= _mesa_CreateShader(GL_GEOMETRY_SHADER
);
1521 _mesa_ShaderSource(gs
, 1, &gs_source
, NULL
);
1522 _mesa_CompileShader(gs
);
1525 fs
= _mesa_CreateShader(GL_FRAGMENT_SHADER
);
1526 _mesa_ShaderSource(fs
, 1, &fs_source
, NULL
);
1527 _mesa_CompileShader(fs
);
1529 clear
->ShaderProg
= _mesa_CreateProgram();
1530 _mesa_AttachShader(clear
->ShaderProg
, fs
);
1531 _mesa_DeleteShader(fs
);
1533 _mesa_AttachShader(clear
->ShaderProg
, gs
);
1534 _mesa_AttachShader(clear
->ShaderProg
, vs
);
1535 _mesa_DeleteShader(vs
);
1536 _mesa_BindAttribLocation(clear
->ShaderProg
, 0, "position");
1537 _mesa_LinkProgram(clear
->ShaderProg
);
1539 clear
->ColorLocation
= _mesa_GetUniformLocation(clear
->ShaderProg
,
1542 clear
->LayerLocation
= _mesa_GetUniformLocation(clear
->ShaderProg
,
1546 has_integer_textures
= _mesa_is_gles3(ctx
) ||
1547 (_mesa_is_desktop_gl(ctx
) && ctx
->Const
.GLSLVersion
>= 130);
1549 if (has_integer_textures
) {
1550 void *shader_source_mem_ctx
= ralloc_context(NULL
);
1551 const char *vs_int_source
=
1552 ralloc_asprintf(shader_source_mem_ctx
,
1554 "in vec4 position;\n"
1557 " gl_Position = position;\n"
1559 const char *fs_int_source
=
1560 ralloc_asprintf(shader_source_mem_ctx
,
1562 "uniform ivec4 color;\n"
1563 "out ivec4 out_color;\n"
1567 " out_color = color;\n"
1570 vs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_VERTEX_SHADER
,
1572 fs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_FRAGMENT_SHADER
,
1574 ralloc_free(shader_source_mem_ctx
);
1576 clear
->IntegerShaderProg
= _mesa_CreateProgram();
1577 _mesa_AttachShader(clear
->IntegerShaderProg
, fs
);
1578 _mesa_DeleteShader(fs
);
1580 _mesa_AttachShader(clear
->IntegerShaderProg
, gs
);
1581 _mesa_AttachShader(clear
->IntegerShaderProg
, vs
);
1582 _mesa_DeleteShader(vs
);
1583 _mesa_BindAttribLocation(clear
->IntegerShaderProg
, 0, "position");
1585 /* Note that user-defined out attributes get automatically assigned
1586 * locations starting from 0, so we don't need to explicitly
1587 * BindFragDataLocation to 0.
1590 _mesa_ObjectLabel(GL_PROGRAM
, clear
->IntegerShaderProg
, -1,
1592 _mesa_meta_link_program_with_debug(ctx
, clear
->IntegerShaderProg
);
1594 clear
->IntegerColorLocation
=
1595 _mesa_GetUniformLocation(clear
->IntegerShaderProg
, "color");
1597 clear
->IntegerLayerLocation
=
1598 _mesa_GetUniformLocation(clear
->IntegerShaderProg
, "layer");
1602 _mesa_DeleteShader(gs
);
1606 meta_glsl_clear_cleanup(struct clear_state
*clear
)
1608 if (clear
->VAO
== 0)
1610 _mesa_DeleteVertexArrays(1, &clear
->VAO
);
1612 _mesa_DeleteBuffers(1, &clear
->VBO
);
1614 _mesa_DeleteProgram(clear
->ShaderProg
);
1615 clear
->ShaderProg
= 0;
1617 if (clear
->IntegerShaderProg
) {
1618 _mesa_DeleteProgram(clear
->IntegerShaderProg
);
1619 clear
->IntegerShaderProg
= 0;
1624 * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
1627 _mesa_meta_glsl_Clear(struct gl_context
*ctx
, GLbitfield buffers
)
1629 struct clear_state
*clear
= &ctx
->Meta
->Clear
;
1630 GLbitfield metaSave
;
1631 const GLuint stencilMax
= (1 << ctx
->DrawBuffer
->Visual
.stencilBits
) - 1;
1632 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1633 const float x0
= ((float)fb
->_Xmin
/ fb
->Width
) * 2.0f
- 1.0f
;
1634 const float y0
= ((float)fb
->_Ymin
/ fb
->Height
) * 2.0f
- 1.0f
;
1635 const float x1
= ((float)fb
->_Xmax
/ fb
->Width
) * 2.0f
- 1.0f
;
1636 const float y1
= ((float)fb
->_Ymax
/ fb
->Height
) * 2.0f
- 1.0f
;
1637 const float z
= -invert_z(ctx
->Depth
.Clear
);
1638 struct vertex verts
[4];
1640 metaSave
= (MESA_META_ALPHA_TEST
|
1642 MESA_META_DEPTH_TEST
|
1643 MESA_META_RASTERIZATION
|
1645 MESA_META_STENCIL_TEST
|
1647 MESA_META_VIEWPORT
|
1649 MESA_META_CLAMP_FRAGMENT_COLOR
|
1650 MESA_META_MULTISAMPLE
|
1651 MESA_META_OCCLUSION_QUERY
);
1653 if (!(buffers
& BUFFER_BITS_COLOR
)) {
1654 /* We'll use colormask to disable color writes. Otherwise,
1655 * respect color mask
1657 metaSave
|= MESA_META_COLOR_MASK
;
1660 _mesa_meta_begin(ctx
, metaSave
);
1662 meta_glsl_clear_init(ctx
, clear
);
1664 if (fb
->_IntegerColor
) {
1665 _mesa_UseProgram(clear
->IntegerShaderProg
);
1666 _mesa_Uniform4iv(clear
->IntegerColorLocation
, 1,
1667 ctx
->Color
.ClearColor
.i
);
1669 _mesa_UseProgram(clear
->ShaderProg
);
1670 _mesa_Uniform4fv(clear
->ColorLocation
, 1,
1671 ctx
->Color
.ClearColor
.f
);
1674 /* GL_COLOR_BUFFER_BIT */
1675 if (buffers
& BUFFER_BITS_COLOR
) {
1676 /* leave colormask, glDrawBuffer state as-is */
1678 /* Clears never have the color clamped. */
1679 if (ctx
->Extensions
.ARB_color_buffer_float
)
1680 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, GL_FALSE
);
1683 ASSERT(metaSave
& MESA_META_COLOR_MASK
);
1684 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1687 /* GL_DEPTH_BUFFER_BIT */
1688 if (buffers
& BUFFER_BIT_DEPTH
) {
1689 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1690 _mesa_DepthFunc(GL_ALWAYS
);
1691 _mesa_DepthMask(GL_TRUE
);
1694 assert(!ctx
->Depth
.Test
);
1697 /* GL_STENCIL_BUFFER_BIT */
1698 if (buffers
& BUFFER_BIT_STENCIL
) {
1699 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1700 _mesa_StencilOpSeparate(GL_FRONT_AND_BACK
,
1701 GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1702 _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK
, GL_ALWAYS
,
1703 ctx
->Stencil
.Clear
& stencilMax
,
1704 ctx
->Stencil
.WriteMask
[0]);
1707 assert(!ctx
->Stencil
.Enabled
);
1710 /* vertex positions */
1724 /* upload new vertex data */
1725 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), verts
,
1726 GL_DYNAMIC_DRAW_ARB
);
1729 if (fb
->MaxNumLayers
> 0) {
1731 for (layer
= 0; layer
< fb
->MaxNumLayers
; layer
++) {
1732 if (fb
->_IntegerColor
)
1733 _mesa_Uniform1i(clear
->IntegerLayerLocation
, layer
);
1735 _mesa_Uniform1i(clear
->LayerLocation
, layer
);
1736 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1739 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1742 _mesa_meta_end(ctx
);
1746 * Meta implementation of ctx->Driver.CopyPixels() in terms
1747 * of texture mapping and polygon rendering and GLSL shaders.
1750 _mesa_meta_CopyPixels(struct gl_context
*ctx
, GLint srcX
, GLint srcY
,
1751 GLsizei width
, GLsizei height
,
1752 GLint dstX
, GLint dstY
, GLenum type
)
1754 struct copypix_state
*copypix
= &ctx
->Meta
->CopyPix
;
1755 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
1756 struct vertex verts
[4];
1758 if (type
!= GL_COLOR
||
1759 ctx
->_ImageTransferState
||
1761 width
> tex
->MaxSize
||
1762 height
> tex
->MaxSize
) {
1763 /* XXX avoid this fallback */
1764 _swrast_CopyPixels(ctx
, srcX
, srcY
, width
, height
, dstX
, dstY
, type
);
1768 /* Most GL state applies to glCopyPixels, but a there's a few things
1769 * we need to override:
1771 _mesa_meta_begin(ctx
, (MESA_META_RASTERIZATION
|
1774 MESA_META_TRANSFORM
|
1777 MESA_META_VIEWPORT
));
1779 _mesa_meta_setup_vertex_objects(©pix
->VAO
, ©pix
->VBO
, false,
1782 /* Silence valgrind warnings about reading uninitialized stack. */
1783 memset(verts
, 0, sizeof(verts
));
1785 /* Alloc/setup texture */
1786 _mesa_meta_setup_copypix_texture(ctx
, tex
, srcX
, srcY
, width
, height
,
1787 GL_RGBA
, GL_NEAREST
);
1789 /* vertex positions, texcoords (after texture allocation!) */
1791 const GLfloat dstX0
= (GLfloat
) dstX
;
1792 const GLfloat dstY0
= (GLfloat
) dstY
;
1793 const GLfloat dstX1
= dstX
+ width
* ctx
->Pixel
.ZoomX
;
1794 const GLfloat dstY1
= dstY
+ height
* ctx
->Pixel
.ZoomY
;
1795 const GLfloat z
= invert_z(ctx
->Current
.RasterPos
[2]);
1800 verts
[0].tex
[0] = 0.0F
;
1801 verts
[0].tex
[1] = 0.0F
;
1805 verts
[1].tex
[0] = tex
->Sright
;
1806 verts
[1].tex
[1] = 0.0F
;
1810 verts
[2].tex
[0] = tex
->Sright
;
1811 verts
[2].tex
[1] = tex
->Ttop
;
1815 verts
[3].tex
[0] = 0.0F
;
1816 verts
[3].tex
[1] = tex
->Ttop
;
1818 /* upload new vertex data */
1819 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1822 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1824 /* draw textured quad */
1825 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1827 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1829 _mesa_meta_end(ctx
);
1833 meta_drawpix_cleanup(struct drawpix_state
*drawpix
)
1835 if (drawpix
->VAO
!= 0) {
1836 _mesa_DeleteVertexArrays(1, &drawpix
->VAO
);
1839 _mesa_DeleteBuffers(1, &drawpix
->VBO
);
1843 if (drawpix
->StencilFP
!= 0) {
1844 _mesa_DeleteProgramsARB(1, &drawpix
->StencilFP
);
1845 drawpix
->StencilFP
= 0;
1848 if (drawpix
->DepthFP
!= 0) {
1849 _mesa_DeleteProgramsARB(1, &drawpix
->DepthFP
);
1850 drawpix
->DepthFP
= 0;
1855 * When the glDrawPixels() image size is greater than the max rectangle
1856 * texture size we use this function to break the glDrawPixels() image
1857 * into tiles which fit into the max texture size.
1860 tiled_draw_pixels(struct gl_context
*ctx
,
1862 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1863 GLenum format
, GLenum type
,
1864 const struct gl_pixelstore_attrib
*unpack
,
1865 const GLvoid
*pixels
)
1867 struct gl_pixelstore_attrib tileUnpack
= *unpack
;
1870 if (tileUnpack
.RowLength
== 0)
1871 tileUnpack
.RowLength
= width
;
1873 for (i
= 0; i
< width
; i
+= tileSize
) {
1874 const GLint tileWidth
= MIN2(tileSize
, width
- i
);
1875 const GLint tileX
= (GLint
) (x
+ i
* ctx
->Pixel
.ZoomX
);
1877 tileUnpack
.SkipPixels
= unpack
->SkipPixels
+ i
;
1879 for (j
= 0; j
< height
; j
+= tileSize
) {
1880 const GLint tileHeight
= MIN2(tileSize
, height
- j
);
1881 const GLint tileY
= (GLint
) (y
+ j
* ctx
->Pixel
.ZoomY
);
1883 tileUnpack
.SkipRows
= unpack
->SkipRows
+ j
;
1885 _mesa_meta_DrawPixels(ctx
, tileX
, tileY
, tileWidth
, tileHeight
,
1886 format
, type
, &tileUnpack
, pixels
);
1893 * One-time init for drawing stencil pixels.
1896 init_draw_stencil_pixels(struct gl_context
*ctx
)
1898 /* This program is run eight times, once for each stencil bit.
1899 * The stencil values to draw are found in an 8-bit alpha texture.
1900 * We read the texture/stencil value and test if bit 'b' is set.
1901 * If the bit is not set, use KIL to kill the fragment.
1902 * Finally, we use the stencil test to update the stencil buffer.
1904 * The basic algorithm for checking if a bit is set is:
1905 * if (is_odd(value / (1 << bit)))
1906 * result is one (or non-zero).
1909 * The program parameter contains three values:
1910 * parm.x = 255 / (1 << bit)
1914 static const char *program
=
1916 "PARAM parm = program.local[0]; \n"
1918 "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */
1919 "# t = t * 255 / bit \n"
1920 "MUL t.x, t.a, parm.x; \n"
1923 "SUB t.x, t.x, t.y; \n"
1925 "MUL t.x, t.x, parm.y; \n"
1926 "# t = fract(t.x) \n"
1927 "FRC t.x, t.x; # if t.x != 0, then the bit is set \n"
1928 "# t.x = (t.x == 0 ? 1 : 0) \n"
1929 "SGE t.x, -t.x, parm.z; \n"
1931 "# for debug only \n"
1932 "#MOV result.color, t.x; \n"
1934 char program2
[1000];
1935 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1936 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
1937 const char *texTarget
;
1939 assert(drawpix
->StencilFP
== 0);
1941 /* replace %s with "RECT" or "2D" */
1942 assert(strlen(program
) + 4 < sizeof(program2
));
1943 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1947 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1949 _mesa_GenProgramsARB(1, &drawpix
->StencilFP
);
1950 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
1951 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1952 strlen(program2
), (const GLubyte
*) program2
);
1957 * One-time init for drawing depth pixels.
1960 init_draw_depth_pixels(struct gl_context
*ctx
)
1962 static const char *program
=
1964 "PARAM color = program.local[0]; \n"
1965 "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
1966 "MOV result.color, color; \n"
1969 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1970 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
1971 const char *texTarget
;
1973 assert(drawpix
->DepthFP
== 0);
1975 /* replace %s with "RECT" or "2D" */
1976 assert(strlen(program
) + 4 < sizeof(program2
));
1977 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1981 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1983 _mesa_GenProgramsARB(1, &drawpix
->DepthFP
);
1984 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
1985 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1986 strlen(program2
), (const GLubyte
*) program2
);
1991 * Meta implementation of ctx->Driver.DrawPixels() in terms
1992 * of texture mapping and polygon rendering.
1995 _mesa_meta_DrawPixels(struct gl_context
*ctx
,
1996 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1997 GLenum format
, GLenum type
,
1998 const struct gl_pixelstore_attrib
*unpack
,
1999 const GLvoid
*pixels
)
2001 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
2002 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
2003 const struct gl_pixelstore_attrib unpackSave
= ctx
->Unpack
;
2004 const GLuint origStencilMask
= ctx
->Stencil
.WriteMask
[0];
2005 struct vertex verts
[4];
2006 GLenum texIntFormat
;
2007 GLboolean fallback
, newTex
;
2008 GLbitfield metaExtraSave
= 0x0;
2011 * Determine if we can do the glDrawPixels with texture mapping.
2013 fallback
= GL_FALSE
;
2014 if (ctx
->Fog
.Enabled
) {
2018 if (_mesa_is_color_format(format
)) {
2019 /* use more compact format when possible */
2020 /* XXX disable special case for GL_LUMINANCE for now to work around
2021 * apparent i965 driver bug (see bug #23670).
2023 if (/*format == GL_LUMINANCE ||*/ format
== GL_LUMINANCE_ALPHA
)
2024 texIntFormat
= format
;
2026 texIntFormat
= GL_RGBA
;
2028 /* If we're not supposed to clamp the resulting color, then just
2029 * promote our texture to fully float. We could do better by
2030 * just going for the matching set of channels, in floating
2033 if (ctx
->Color
.ClampFragmentColor
!= GL_TRUE
&&
2034 ctx
->Extensions
.ARB_texture_float
)
2035 texIntFormat
= GL_RGBA32F
;
2037 else if (_mesa_is_stencil_format(format
)) {
2038 if (ctx
->Extensions
.ARB_fragment_program
&&
2039 ctx
->Pixel
.IndexShift
== 0 &&
2040 ctx
->Pixel
.IndexOffset
== 0 &&
2041 type
== GL_UNSIGNED_BYTE
) {
2042 /* We'll store stencil as alpha. This only works for GLubyte
2043 * image data because of how incoming values are mapped to alpha
2046 texIntFormat
= GL_ALPHA
;
2047 metaExtraSave
= (MESA_META_COLOR_MASK
|
2048 MESA_META_DEPTH_TEST
|
2049 MESA_META_PIXEL_TRANSFER
|
2051 MESA_META_STENCIL_TEST
);
2057 else if (_mesa_is_depth_format(format
)) {
2058 if (ctx
->Extensions
.ARB_depth_texture
&&
2059 ctx
->Extensions
.ARB_fragment_program
) {
2060 texIntFormat
= GL_DEPTH_COMPONENT
;
2061 metaExtraSave
= (MESA_META_SHADER
);
2072 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
2073 format
, type
, unpack
, pixels
);
2078 * Check image size against max texture size, draw as tiles if needed.
2080 if (width
> tex
->MaxSize
|| height
> tex
->MaxSize
) {
2081 tiled_draw_pixels(ctx
, tex
->MaxSize
, x
, y
, width
, height
,
2082 format
, type
, unpack
, pixels
);
2086 /* Most GL state applies to glDrawPixels (like blending, stencil, etc),
2087 * but a there's a few things we need to override:
2089 _mesa_meta_begin(ctx
, (MESA_META_RASTERIZATION
|
2092 MESA_META_TRANSFORM
|
2095 MESA_META_VIEWPORT
|
2098 newTex
= _mesa_meta_alloc_texture(tex
, width
, height
, texIntFormat
);
2100 _mesa_meta_setup_vertex_objects(&drawpix
->VAO
, &drawpix
->VBO
, false,
2103 /* Silence valgrind warnings about reading uninitialized stack. */
2104 memset(verts
, 0, sizeof(verts
));
2106 /* vertex positions, texcoords (after texture allocation!) */
2108 const GLfloat x0
= (GLfloat
) x
;
2109 const GLfloat y0
= (GLfloat
) y
;
2110 const GLfloat x1
= x
+ width
* ctx
->Pixel
.ZoomX
;
2111 const GLfloat y1
= y
+ height
* ctx
->Pixel
.ZoomY
;
2112 const GLfloat z
= invert_z(ctx
->Current
.RasterPos
[2]);
2117 verts
[0].tex
[0] = 0.0F
;
2118 verts
[0].tex
[1] = 0.0F
;
2122 verts
[1].tex
[0] = tex
->Sright
;
2123 verts
[1].tex
[1] = 0.0F
;
2127 verts
[2].tex
[0] = tex
->Sright
;
2128 verts
[2].tex
[1] = tex
->Ttop
;
2132 verts
[3].tex
[0] = 0.0F
;
2133 verts
[3].tex
[1] = tex
->Ttop
;
2136 /* upload new vertex data */
2137 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
2138 verts
, GL_DYNAMIC_DRAW_ARB
);
2140 /* set given unpack params */
2141 ctx
->Unpack
= *unpack
;
2143 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
2145 if (_mesa_is_stencil_format(format
)) {
2146 /* Drawing stencil */
2149 if (!drawpix
->StencilFP
)
2150 init_draw_stencil_pixels(ctx
);
2152 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2153 GL_ALPHA
, type
, pixels
);
2155 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
2157 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
2159 /* set all stencil bits to 0 */
2160 _mesa_StencilOp(GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
2161 _mesa_StencilFunc(GL_ALWAYS
, 0, 255);
2162 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2164 /* set stencil bits to 1 where needed */
2165 _mesa_StencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
2167 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
2168 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
2170 for (bit
= 0; bit
< ctx
->DrawBuffer
->Visual
.stencilBits
; bit
++) {
2171 const GLuint mask
= 1 << bit
;
2172 if (mask
& origStencilMask
) {
2173 _mesa_StencilFunc(GL_ALWAYS
, mask
, mask
);
2174 _mesa_StencilMask(mask
);
2176 _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
2177 255.0f
/ mask
, 0.5f
, 0.0f
, 0.0f
);
2179 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2183 else if (_mesa_is_depth_format(format
)) {
2185 if (!drawpix
->DepthFP
)
2186 init_draw_depth_pixels(ctx
);
2188 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
2189 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
2191 /* polygon color = current raster color */
2192 _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
2193 ctx
->Current
.RasterColor
);
2195 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2196 format
, type
, pixels
);
2198 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2202 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2203 format
, type
, pixels
);
2204 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2207 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
2209 /* restore unpack params */
2210 ctx
->Unpack
= unpackSave
;
2212 _mesa_meta_end(ctx
);
2216 alpha_test_raster_color(struct gl_context
*ctx
)
2218 GLfloat alpha
= ctx
->Current
.RasterColor
[ACOMP
];
2219 GLfloat ref
= ctx
->Color
.AlphaRef
;
2221 switch (ctx
->Color
.AlphaFunc
) {
2227 return alpha
== ref
;
2229 return alpha
<= ref
;
2233 return alpha
!= ref
;
2235 return alpha
>= ref
;
2245 * Do glBitmap with a alpha texture quad. Use the alpha test to cull
2246 * the 'off' bits. A bitmap cache as in the gallium/mesa state
2247 * tracker would improve performance a lot.
2250 _mesa_meta_Bitmap(struct gl_context
*ctx
,
2251 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2252 const struct gl_pixelstore_attrib
*unpack
,
2253 const GLubyte
*bitmap1
)
2255 struct bitmap_state
*bitmap
= &ctx
->Meta
->Bitmap
;
2256 struct temp_texture
*tex
= get_bitmap_temp_texture(ctx
);
2257 const GLenum texIntFormat
= GL_ALPHA
;
2258 const struct gl_pixelstore_attrib unpackSave
= *unpack
;
2260 struct vertex verts
[4];
2265 * Check if swrast fallback is needed.
2267 if (ctx
->_ImageTransferState
||
2268 ctx
->FragmentProgram
._Enabled
||
2270 ctx
->Texture
._EnabledUnits
||
2271 width
> tex
->MaxSize
||
2272 height
> tex
->MaxSize
) {
2273 _swrast_Bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap1
);
2277 if (ctx
->Color
.AlphaEnabled
&& !alpha_test_raster_color(ctx
))
2280 /* Most GL state applies to glBitmap (like blending, stencil, etc),
2281 * but a there's a few things we need to override:
2283 _mesa_meta_begin(ctx
, (MESA_META_ALPHA_TEST
|
2284 MESA_META_PIXEL_STORE
|
2285 MESA_META_RASTERIZATION
|
2288 MESA_META_TRANSFORM
|
2291 MESA_META_VIEWPORT
));
2293 _mesa_meta_setup_vertex_objects(&bitmap
->VAO
, &bitmap
->VBO
, false, 3, 2, 4);
2295 newTex
= _mesa_meta_alloc_texture(tex
, width
, height
, texIntFormat
);
2297 /* Silence valgrind warnings about reading uninitialized stack. */
2298 memset(verts
, 0, sizeof(verts
));
2300 /* vertex positions, texcoords, colors (after texture allocation!) */
2302 const GLfloat x0
= (GLfloat
) x
;
2303 const GLfloat y0
= (GLfloat
) y
;
2304 const GLfloat x1
= (GLfloat
) (x
+ width
);
2305 const GLfloat y1
= (GLfloat
) (y
+ height
);
2306 const GLfloat z
= invert_z(ctx
->Current
.RasterPos
[2]);
2312 verts
[0].tex
[0] = 0.0F
;
2313 verts
[0].tex
[1] = 0.0F
;
2317 verts
[1].tex
[0] = tex
->Sright
;
2318 verts
[1].tex
[1] = 0.0F
;
2322 verts
[2].tex
[0] = tex
->Sright
;
2323 verts
[2].tex
[1] = tex
->Ttop
;
2327 verts
[3].tex
[0] = 0.0F
;
2328 verts
[3].tex
[1] = tex
->Ttop
;
2330 for (i
= 0; i
< 4; i
++) {
2331 verts
[i
].r
= ctx
->Current
.RasterColor
[0];
2332 verts
[i
].g
= ctx
->Current
.RasterColor
[1];
2333 verts
[i
].b
= ctx
->Current
.RasterColor
[2];
2334 verts
[i
].a
= ctx
->Current
.RasterColor
[3];
2337 /* upload new vertex data */
2338 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
2341 /* choose different foreground/background alpha values */
2342 CLAMPED_FLOAT_TO_UBYTE(fg
, ctx
->Current
.RasterColor
[ACOMP
]);
2343 bg
= (fg
> 127 ? 0 : 255);
2345 bitmap1
= _mesa_map_pbo_source(ctx
, &unpackSave
, bitmap1
);
2347 _mesa_meta_end(ctx
);
2351 bitmap8
= malloc(width
* height
);
2353 memset(bitmap8
, bg
, width
* height
);
2354 _mesa_expand_bitmap(width
, height
, &unpackSave
, bitmap1
,
2355 bitmap8
, width
, fg
);
2357 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
2359 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_TRUE
);
2360 _mesa_AlphaFunc(GL_NOTEQUAL
, UBYTE_TO_FLOAT(bg
));
2362 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2363 GL_ALPHA
, GL_UNSIGNED_BYTE
, bitmap8
);
2365 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2367 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
2372 _mesa_unmap_pbo_source(ctx
, &unpackSave
);
2374 _mesa_meta_end(ctx
);
2378 * Compute the texture coordinates for the four vertices of a quad for
2379 * drawing a 2D texture image or slice of a cube/3D texture.
2380 * \param faceTarget GL_TEXTURE_1D/2D/3D or cube face name
2381 * \param slice slice of a 1D/2D array texture or 3D texture
2382 * \param width width of the texture image
2383 * \param height height of the texture image
2384 * \param coords0/1/2/3 returns the computed texcoords
2387 _mesa_meta_setup_texture_coords(GLenum faceTarget
,
2397 static const GLfloat st
[4][2] = {
2398 {0.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 1.0f
}
2403 /* Currently all texture targets want the W component to be 1.0.
2410 switch (faceTarget
) {
2414 case GL_TEXTURE_2D_ARRAY
:
2415 if (faceTarget
== GL_TEXTURE_3D
) {
2416 assert(slice
< depth
);
2418 r
= (slice
+ 0.5f
) / depth
;
2420 else if (faceTarget
== GL_TEXTURE_2D_ARRAY
)
2424 coords0
[0] = 0.0F
; /* s */
2425 coords0
[1] = 0.0F
; /* t */
2426 coords0
[2] = r
; /* r */
2437 case GL_TEXTURE_RECTANGLE_ARB
:
2438 coords0
[0] = 0.0F
; /* s */
2439 coords0
[1] = 0.0F
; /* t */
2440 coords0
[2] = 0.0F
; /* r */
2441 coords1
[0] = (float) width
;
2444 coords2
[0] = (float) width
;
2445 coords2
[1] = (float) height
;
2448 coords3
[1] = (float) height
;
2451 case GL_TEXTURE_1D_ARRAY
:
2452 coords0
[0] = 0.0F
; /* s */
2453 coords0
[1] = (float) slice
; /* t */
2454 coords0
[2] = 0.0F
; /* r */
2456 coords1
[1] = (float) slice
;
2459 coords2
[1] = (float) slice
;
2462 coords3
[1] = (float) slice
;
2466 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2467 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2468 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2469 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2470 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2471 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2472 /* loop over quad verts */
2473 for (i
= 0; i
< 4; i
++) {
2474 /* Compute sc = +/-scale and tc = +/-scale.
2475 * Not +/-1 to avoid cube face selection ambiguity near the edges,
2476 * though that can still sometimes happen with this scale factor...
2478 const GLfloat scale
= 0.9999f
;
2479 const GLfloat sc
= (2.0f
* st
[i
][0] - 1.0f
) * scale
;
2480 const GLfloat tc
= (2.0f
* st
[i
][1] - 1.0f
) * scale
;
2500 coord
[3] = (float) (slice
/ 6);
2502 switch (faceTarget
) {
2503 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2508 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2513 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2518 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2523 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2539 assert(!"unexpected target in _mesa_meta_setup_texture_coords()");
2543 static struct blit_shader
*
2544 choose_blit_shader(GLenum target
, struct blit_shader_table
*table
)
2548 table
->sampler_1d
.type
= "sampler1D";
2549 table
->sampler_1d
.func
= "texture1D";
2550 table
->sampler_1d
.texcoords
= "texCoords.x";
2551 return &table
->sampler_1d
;
2553 table
->sampler_2d
.type
= "sampler2D";
2554 table
->sampler_2d
.func
= "texture2D";
2555 table
->sampler_2d
.texcoords
= "texCoords.xy";
2556 return &table
->sampler_2d
;
2557 case GL_TEXTURE_RECTANGLE
:
2558 table
->sampler_rect
.type
= "sampler2DRect";
2559 table
->sampler_rect
.func
= "texture2DRect";
2560 table
->sampler_rect
.texcoords
= "texCoords.xy";
2561 return &table
->sampler_rect
;
2563 /* Code for mipmap generation with 3D textures is not used yet.
2564 * It's a sw fallback.
2566 table
->sampler_3d
.type
= "sampler3D";
2567 table
->sampler_3d
.func
= "texture3D";
2568 table
->sampler_3d
.texcoords
= "texCoords.xyz";
2569 return &table
->sampler_3d
;
2570 case GL_TEXTURE_CUBE_MAP
:
2571 table
->sampler_cubemap
.type
= "samplerCube";
2572 table
->sampler_cubemap
.func
= "textureCube";
2573 table
->sampler_cubemap
.texcoords
= "texCoords.xyz";
2574 return &table
->sampler_cubemap
;
2575 case GL_TEXTURE_1D_ARRAY
:
2576 table
->sampler_1d_array
.type
= "sampler1DArray";
2577 table
->sampler_1d_array
.func
= "texture1DArray";
2578 table
->sampler_1d_array
.texcoords
= "texCoords.xy";
2579 return &table
->sampler_1d_array
;
2580 case GL_TEXTURE_2D_ARRAY
:
2581 table
->sampler_2d_array
.type
= "sampler2DArray";
2582 table
->sampler_2d_array
.func
= "texture2DArray";
2583 table
->sampler_2d_array
.texcoords
= "texCoords.xyz";
2584 return &table
->sampler_2d_array
;
2585 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2586 table
->sampler_cubemap_array
.type
= "samplerCubeArray";
2587 table
->sampler_cubemap_array
.func
= "textureCubeArray";
2588 table
->sampler_cubemap_array
.texcoords
= "texCoords.xyzw";
2589 return &table
->sampler_cubemap_array
;
2591 _mesa_problem(NULL
, "Unexpected texture target 0x%x in"
2592 " setup_texture_sampler()\n", target
);
2598 _mesa_meta_blit_shader_table_cleanup(struct blit_shader_table
*table
)
2600 _mesa_DeleteProgram(table
->sampler_1d
.shader_prog
);
2601 _mesa_DeleteProgram(table
->sampler_2d
.shader_prog
);
2602 _mesa_DeleteProgram(table
->sampler_3d
.shader_prog
);
2603 _mesa_DeleteProgram(table
->sampler_rect
.shader_prog
);
2604 _mesa_DeleteProgram(table
->sampler_cubemap
.shader_prog
);
2605 _mesa_DeleteProgram(table
->sampler_1d_array
.shader_prog
);
2606 _mesa_DeleteProgram(table
->sampler_2d_array
.shader_prog
);
2607 _mesa_DeleteProgram(table
->sampler_cubemap_array
.shader_prog
);
2609 table
->sampler_1d
.shader_prog
= 0;
2610 table
->sampler_2d
.shader_prog
= 0;
2611 table
->sampler_3d
.shader_prog
= 0;
2612 table
->sampler_rect
.shader_prog
= 0;
2613 table
->sampler_cubemap
.shader_prog
= 0;
2614 table
->sampler_1d_array
.shader_prog
= 0;
2615 table
->sampler_2d_array
.shader_prog
= 0;
2616 table
->sampler_cubemap_array
.shader_prog
= 0;
2620 * Determine the GL data type to use for the temporary image read with
2621 * ReadPixels() and passed to Tex[Sub]Image().
2624 get_temp_image_type(struct gl_context
*ctx
, mesa_format format
)
2628 baseFormat
= _mesa_get_format_base_format(format
);
2630 switch (baseFormat
) {
2637 case GL_LUMINANCE_ALPHA
:
2639 if (ctx
->DrawBuffer
->Visual
.redBits
<= 8) {
2640 return GL_UNSIGNED_BYTE
;
2641 } else if (ctx
->DrawBuffer
->Visual
.redBits
<= 16) {
2642 return GL_UNSIGNED_SHORT
;
2644 GLenum datatype
= _mesa_get_format_datatype(format
);
2645 if (datatype
== GL_INT
|| datatype
== GL_UNSIGNED_INT
)
2649 case GL_DEPTH_COMPONENT
: {
2650 GLenum datatype
= _mesa_get_format_datatype(format
);
2651 if (datatype
== GL_FLOAT
)
2654 return GL_UNSIGNED_INT
;
2656 case GL_DEPTH_STENCIL
: {
2657 GLenum datatype
= _mesa_get_format_datatype(format
);
2658 if (datatype
== GL_FLOAT
)
2659 return GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
2661 return GL_UNSIGNED_INT_24_8
;
2664 _mesa_problem(ctx
, "Unexpected format %d in get_temp_image_type()",
2671 * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
2672 * Have to be careful with locking and meta state for pixel transfer.
2675 _mesa_meta_CopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
2676 struct gl_texture_image
*texImage
,
2677 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2678 struct gl_renderbuffer
*rb
,
2680 GLsizei width
, GLsizei height
)
2682 struct gl_texture_object
*texObj
= texImage
->TexObject
;
2683 GLenum format
, type
;
2687 /* The gl_renderbuffer is part of the interface for
2688 * dd_function_table::CopyTexSubImage, but this implementation does not use
2693 /* Choose format/type for temporary image buffer */
2694 format
= _mesa_get_format_base_format(texImage
->TexFormat
);
2695 if (format
== GL_LUMINANCE
||
2696 format
== GL_LUMINANCE_ALPHA
||
2697 format
== GL_INTENSITY
) {
2698 /* We don't want to use GL_LUMINANCE, GL_INTENSITY, etc. for the
2699 * temp image buffer because glReadPixels will do L=R+G+B which is
2700 * not what we want (should be L=R).
2705 type
= get_temp_image_type(ctx
, texImage
->TexFormat
);
2706 if (_mesa_is_format_integer_color(texImage
->TexFormat
)) {
2707 format
= _mesa_base_format_to_integer_format(format
);
2709 bpp
= _mesa_bytes_per_pixel(format
, type
);
2711 _mesa_problem(ctx
, "Bad bpp in _mesa_meta_CopyTexSubImage()");
2716 * Alloc image buffer (XXX could use a PBO)
2718 buf
= malloc(width
* height
* bpp
);
2720 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%uD", dims
);
2724 _mesa_unlock_texture(ctx
, texObj
); /* need to unlock first */
2727 * Read image from framebuffer (disable pixel transfer ops)
2729 _mesa_meta_begin(ctx
, MESA_META_PIXEL_STORE
| MESA_META_PIXEL_TRANSFER
);
2730 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2731 format
, type
, &ctx
->Pack
, buf
);
2732 _mesa_meta_end(ctx
);
2734 _mesa_update_state(ctx
); /* to update pixel transfer state */
2737 * Store texture data (with pixel transfer ops)
2739 _mesa_meta_begin(ctx
, MESA_META_PIXEL_STORE
);
2741 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
2742 assert(yoffset
== 0);
2743 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2744 xoffset
, zoffset
, 0, width
, 1, 1,
2745 format
, type
, buf
, &ctx
->Unpack
);
2747 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2748 xoffset
, yoffset
, zoffset
, width
, height
, 1,
2749 format
, type
, buf
, &ctx
->Unpack
);
2752 _mesa_meta_end(ctx
);
2754 _mesa_lock_texture(ctx
, texObj
); /* re-lock */
2761 meta_decompress_cleanup(struct decompress_state
*decompress
)
2763 if (decompress
->FBO
!= 0) {
2764 _mesa_DeleteFramebuffers(1, &decompress
->FBO
);
2765 _mesa_DeleteRenderbuffers(1, &decompress
->RBO
);
2768 if (decompress
->VAO
!= 0) {
2769 _mesa_DeleteVertexArrays(1, &decompress
->VAO
);
2770 _mesa_DeleteBuffers(1, &decompress
->VBO
);
2773 if (decompress
->Sampler
!= 0)
2774 _mesa_DeleteSamplers(1, &decompress
->Sampler
);
2776 memset(decompress
, 0, sizeof(*decompress
));
2780 * Decompress a texture image by drawing a quad with the compressed
2781 * texture and reading the pixels out of the color buffer.
2782 * \param slice which slice of a 3D texture or layer of a 1D/2D texture
2783 * \param destFormat format, ala glReadPixels
2784 * \param destType type, ala glReadPixels
2785 * \param dest destination buffer
2786 * \param destRowLength dest image rowLength (ala GL_PACK_ROW_LENGTH)
2789 decompress_texture_image(struct gl_context
*ctx
,
2790 struct gl_texture_image
*texImage
,
2792 GLenum destFormat
, GLenum destType
,
2795 struct decompress_state
*decompress
= &ctx
->Meta
->Decompress
;
2796 struct gl_texture_object
*texObj
= texImage
->TexObject
;
2797 const GLint width
= texImage
->Width
;
2798 const GLint height
= texImage
->Height
;
2799 const GLint depth
= texImage
->Height
;
2800 const GLenum target
= texObj
->Target
;
2802 struct vertex verts
[4];
2804 const bool use_glsl_version
= ctx
->Extensions
.ARB_vertex_shader
&&
2805 ctx
->Extensions
.ARB_fragment_shader
;
2808 assert(target
== GL_TEXTURE_3D
||
2809 target
== GL_TEXTURE_2D_ARRAY
||
2810 target
== GL_TEXTURE_CUBE_MAP_ARRAY
);
2815 case GL_TEXTURE_1D_ARRAY
:
2816 assert(!"No compressed 1D textures.");
2820 assert(!"No compressed 3D textures.");
2823 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2824 faceTarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ (slice
% 6);
2827 case GL_TEXTURE_CUBE_MAP
:
2828 faceTarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ texImage
->Face
;
2832 faceTarget
= target
;
2836 _mesa_meta_begin(ctx
, MESA_META_ALL
& ~MESA_META_PIXEL_STORE
);
2838 samplerSave
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
?
2839 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
->Name
: 0;
2841 /* Create/bind FBO/renderbuffer */
2842 if (decompress
->FBO
== 0) {
2843 _mesa_GenFramebuffers(1, &decompress
->FBO
);
2844 _mesa_GenRenderbuffers(1, &decompress
->RBO
);
2845 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, decompress
->FBO
);
2846 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, decompress
->RBO
);
2847 _mesa_FramebufferRenderbuffer(GL_FRAMEBUFFER_EXT
,
2848 GL_COLOR_ATTACHMENT0_EXT
,
2849 GL_RENDERBUFFER_EXT
,
2853 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, decompress
->FBO
);
2856 /* alloc dest surface */
2857 if (width
> decompress
->Width
|| height
> decompress
->Height
) {
2858 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, decompress
->RBO
);
2859 _mesa_RenderbufferStorage(GL_RENDERBUFFER_EXT
, GL_RGBA
,
2861 decompress
->Width
= width
;
2862 decompress
->Height
= height
;
2865 if (use_glsl_version
) {
2866 _mesa_meta_setup_vertex_objects(&decompress
->VAO
, &decompress
->VBO
, true,
2869 _mesa_meta_setup_blit_shader(ctx
, target
, &decompress
->shaders
);
2871 _mesa_meta_setup_ff_tnl_for_blit(&decompress
->VAO
, &decompress
->VBO
, 3);
2874 if (!decompress
->Sampler
) {
2875 _mesa_GenSamplers(1, &decompress
->Sampler
);
2876 _mesa_BindSampler(ctx
->Texture
.CurrentUnit
, decompress
->Sampler
);
2877 /* nearest filtering */
2878 _mesa_SamplerParameteri(decompress
->Sampler
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2879 _mesa_SamplerParameteri(decompress
->Sampler
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2880 /* No sRGB decode or encode.*/
2881 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
2882 _mesa_SamplerParameteri(decompress
->Sampler
, GL_TEXTURE_SRGB_DECODE_EXT
,
2883 GL_SKIP_DECODE_EXT
);
2887 _mesa_BindSampler(ctx
->Texture
.CurrentUnit
, decompress
->Sampler
);
2890 /* Silence valgrind warnings about reading uninitialized stack. */
2891 memset(verts
, 0, sizeof(verts
));
2893 _mesa_meta_setup_texture_coords(faceTarget
, slice
, width
, height
, depth
,
2899 /* setup vertex positions */
2909 _mesa_set_viewport(ctx
, 0, 0, 0, width
, height
);
2911 /* upload new vertex data */
2912 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
2914 /* setup texture state */
2915 _mesa_BindTexture(target
, texObj
->Name
);
2917 if (!use_glsl_version
)
2918 _mesa_set_enable(ctx
, target
, GL_TRUE
);
2921 /* save texture object state */
2922 const GLint baseLevelSave
= texObj
->BaseLevel
;
2923 const GLint maxLevelSave
= texObj
->MaxLevel
;
2925 /* restrict sampling to the texture level of interest */
2926 if (target
!= GL_TEXTURE_RECTANGLE_ARB
) {
2927 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, texImage
->Level
);
2928 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, texImage
->Level
);
2931 /* render quad w/ texture into renderbuffer */
2932 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2934 /* Restore texture object state, the texture binding will
2935 * be restored by _mesa_meta_end().
2937 if (target
!= GL_TEXTURE_RECTANGLE_ARB
) {
2938 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, baseLevelSave
);
2939 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, maxLevelSave
);
2944 /* read pixels from renderbuffer */
2946 GLenum baseTexFormat
= texImage
->_BaseFormat
;
2947 GLenum destBaseFormat
= _mesa_base_tex_format(ctx
, destFormat
);
2949 /* The pixel transfer state will be set to default values at this point
2950 * (see MESA_META_PIXEL_TRANSFER) so pixel transfer ops are effectively
2951 * turned off (as required by glGetTexImage) but we need to handle some
2952 * special cases. In particular, single-channel texture values are
2953 * returned as red and two-channel texture values are returned as
2956 if ((baseTexFormat
== GL_LUMINANCE
||
2957 baseTexFormat
== GL_LUMINANCE_ALPHA
||
2958 baseTexFormat
== GL_INTENSITY
) ||
2959 /* If we're reading back an RGB(A) texture (using glGetTexImage) as
2960 * luminance then we need to return L=tex(R).
2962 ((baseTexFormat
== GL_RGBA
||
2963 baseTexFormat
== GL_RGB
||
2964 baseTexFormat
== GL_RG
) &&
2965 (destBaseFormat
== GL_LUMINANCE
||
2966 destBaseFormat
== GL_LUMINANCE_ALPHA
||
2967 destBaseFormat
== GL_LUMINANCE_INTEGER_EXT
||
2968 destBaseFormat
== GL_LUMINANCE_ALPHA_INTEGER_EXT
))) {
2969 /* Green and blue must be zero */
2970 _mesa_PixelTransferf(GL_GREEN_SCALE
, 0.0f
);
2971 _mesa_PixelTransferf(GL_BLUE_SCALE
, 0.0f
);
2974 _mesa_ReadPixels(0, 0, width
, height
, destFormat
, destType
, dest
);
2977 /* disable texture unit */
2978 if (!use_glsl_version
)
2979 _mesa_set_enable(ctx
, target
, GL_FALSE
);
2981 _mesa_BindSampler(ctx
->Texture
.CurrentUnit
, samplerSave
);
2983 _mesa_meta_end(ctx
);
2988 * This is just a wrapper around _mesa_get_tex_image() and
2989 * decompress_texture_image(). Meta functions should not be directly called
2993 _mesa_meta_GetTexImage(struct gl_context
*ctx
,
2994 GLenum format
, GLenum type
, GLvoid
*pixels
,
2995 struct gl_texture_image
*texImage
)
2997 /* We can only use the decompress-with-blit method here if the texels are
2998 * unsigned, normalized values. We could handle signed and unnormalized
2999 * with floating point renderbuffers...
3001 if (_mesa_is_format_compressed(texImage
->TexFormat
) &&
3002 _mesa_get_format_datatype(texImage
->TexFormat
)
3003 == GL_UNSIGNED_NORMALIZED
) {
3004 struct gl_texture_object
*texObj
= texImage
->TexObject
;
3006 /* Need to unlock the texture here to prevent deadlock... */
3007 _mesa_unlock_texture(ctx
, texObj
);
3008 for (slice
= 0; slice
< texImage
->Depth
; slice
++) {
3010 if (texImage
->TexObject
->Target
== GL_TEXTURE_2D_ARRAY
3011 || texImage
->TexObject
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) {
3012 /* Setup pixel packing. SkipPixels and SkipRows will be applied
3013 * in the decompress_texture_image() function's call to
3014 * glReadPixels but we need to compute the dest slice's address
3015 * here (according to SkipImages and ImageHeight).
3017 struct gl_pixelstore_attrib packing
= ctx
->Pack
;
3018 packing
.SkipPixels
= 0;
3019 packing
.SkipRows
= 0;
3020 dst
= _mesa_image_address3d(&packing
, pixels
, texImage
->Width
,
3021 texImage
->Height
, format
, type
,
3027 decompress_texture_image(ctx
, texImage
, slice
, format
, type
, dst
);
3029 /* ... and relock it */
3030 _mesa_lock_texture(ctx
, texObj
);
3033 _mesa_get_teximage(ctx
, format
, type
, pixels
, texImage
);
3039 * Meta implementation of ctx->Driver.DrawTex() in terms
3040 * of polygon rendering.
3043 _mesa_meta_DrawTex(struct gl_context
*ctx
, GLfloat x
, GLfloat y
, GLfloat z
,
3044 GLfloat width
, GLfloat height
)
3046 struct drawtex_state
*drawtex
= &ctx
->Meta
->DrawTex
;
3048 GLfloat x
, y
, z
, st
[MAX_TEXTURE_UNITS
][2];
3050 struct vertex verts
[4];
3053 _mesa_meta_begin(ctx
, (MESA_META_RASTERIZATION
|
3055 MESA_META_TRANSFORM
|
3057 MESA_META_VIEWPORT
));
3059 if (drawtex
->VAO
== 0) {
3060 /* one-time setup */
3061 GLint active_texture
;
3063 /* create vertex array object */
3064 _mesa_GenVertexArrays(1, &drawtex
->VAO
);
3065 _mesa_BindVertexArray(drawtex
->VAO
);
3067 /* create vertex array buffer */
3068 _mesa_GenBuffers(1, &drawtex
->VBO
);
3069 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
, drawtex
->VBO
);
3070 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
3071 NULL
, GL_DYNAMIC_DRAW_ARB
);
3073 /* client active texture is not part of the array object */
3074 active_texture
= ctx
->Array
.ActiveTexture
;
3076 /* setup vertex arrays */
3077 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
3078 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
3079 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
3080 _mesa_ClientActiveTexture(GL_TEXTURE0
+ i
);
3081 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(st
[i
]));
3082 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
3085 /* restore client active texture */
3086 _mesa_ClientActiveTexture(GL_TEXTURE0
+ active_texture
);
3089 _mesa_BindVertexArray(drawtex
->VAO
);
3090 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
, drawtex
->VBO
);
3093 /* vertex positions, texcoords */
3095 const GLfloat x1
= x
+ width
;
3096 const GLfloat y1
= y
+ height
;
3098 z
= CLAMP(z
, 0.0f
, 1.0f
);
3117 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
3118 const struct gl_texture_object
*texObj
;
3119 const struct gl_texture_image
*texImage
;
3120 GLfloat s
, t
, s1
, t1
;
3123 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
3125 for (j
= 0; j
< 4; j
++) {
3126 verts
[j
].st
[i
][0] = 0.0f
;
3127 verts
[j
].st
[i
][1] = 0.0f
;
3132 texObj
= ctx
->Texture
.Unit
[i
]._Current
;
3133 texImage
= texObj
->Image
[0][texObj
->BaseLevel
];
3134 tw
= texImage
->Width2
;
3135 th
= texImage
->Height2
;
3137 s
= (GLfloat
) texObj
->CropRect
[0] / tw
;
3138 t
= (GLfloat
) texObj
->CropRect
[1] / th
;
3139 s1
= (GLfloat
) (texObj
->CropRect
[0] + texObj
->CropRect
[2]) / tw
;
3140 t1
= (GLfloat
) (texObj
->CropRect
[1] + texObj
->CropRect
[3]) / th
;
3142 verts
[0].st
[i
][0] = s
;
3143 verts
[0].st
[i
][1] = t
;
3145 verts
[1].st
[i
][0] = s1
;
3146 verts
[1].st
[i
][1] = t
;
3148 verts
[2].st
[i
][0] = s1
;
3149 verts
[2].st
[i
][1] = t1
;
3151 verts
[3].st
[i
][0] = s
;
3152 verts
[3].st
[i
][1] = t1
;
3155 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
3158 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
3160 _mesa_meta_end(ctx
);