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/pipelineobj.h"
57 #include "main/pixel.h"
59 #include "main/polygon.h"
60 #include "main/queryobj.h"
61 #include "main/readpix.h"
62 #include "main/scissor.h"
63 #include "main/shaderapi.h"
64 #include "main/shaderobj.h"
65 #include "main/state.h"
66 #include "main/stencil.h"
67 #include "main/texobj.h"
68 #include "main/texenv.h"
69 #include "main/texgetimage.h"
70 #include "main/teximage.h"
71 #include "main/texparam.h"
72 #include "main/texstate.h"
73 #include "main/transformfeedback.h"
74 #include "main/uniforms.h"
75 #include "main/varray.h"
76 #include "main/viewport.h"
77 #include "main/samplerobj.h"
78 #include "program/program.h"
79 #include "swrast/swrast.h"
80 #include "drivers/common/meta.h"
81 #include "main/enums.h"
82 #include "main/glformats.h"
83 #include "../glsl/ralloc.h"
85 /** Return offset in bytes of the field within a vertex struct */
86 #define OFFSET(FIELD) ((void *) offsetof(struct vertex, FIELD))
88 static struct blit_shader
*
89 choose_blit_shader(GLenum target
, struct blit_shader_table
*table
);
91 static void cleanup_temp_texture(struct temp_texture
*tex
);
92 static void meta_glsl_clear_cleanup(struct clear_state
*clear
);
93 static void meta_decompress_cleanup(struct decompress_state
*decompress
);
94 static void meta_drawpix_cleanup(struct drawpix_state
*drawpix
);
97 _mesa_meta_compile_shader_with_debug(struct gl_context
*ctx
, GLenum target
,
98 const GLcharARB
*source
)
104 shader
= _mesa_CreateShader(target
);
105 _mesa_ShaderSource(shader
, 1, &source
, NULL
);
106 _mesa_CompileShader(shader
);
108 _mesa_GetShaderiv(shader
, GL_COMPILE_STATUS
, &ok
);
112 _mesa_GetShaderiv(shader
, GL_INFO_LOG_LENGTH
, &size
);
114 _mesa_DeleteShader(shader
);
120 _mesa_DeleteShader(shader
);
124 _mesa_GetShaderInfoLog(shader
, size
, NULL
, info
);
126 "meta program compile failed:\n%s\n"
131 _mesa_DeleteShader(shader
);
137 _mesa_meta_link_program_with_debug(struct gl_context
*ctx
, GLuint program
)
142 _mesa_LinkProgram(program
);
144 _mesa_GetProgramiv(program
, GL_LINK_STATUS
, &ok
);
148 _mesa_GetProgramiv(program
, GL_INFO_LOG_LENGTH
, &size
);
156 _mesa_GetProgramInfoLog(program
, size
, NULL
, info
);
157 _mesa_problem(ctx
, "meta program link failed:\n%s", info
);
165 * Generate a generic shader to blit from a texture to a framebuffer
167 * \param ctx Current GL context
168 * \param texTarget Texture target that will be the source of the blit
170 * \returns a handle to a shader program on success or zero on failure.
173 _mesa_meta_setup_blit_shader(struct gl_context
*ctx
,
175 struct blit_shader_table
*table
)
177 const char *vs_source
;
180 void *const mem_ctx
= ralloc_context(NULL
);
181 struct blit_shader
*shader
= choose_blit_shader(target
, table
);
184 assert(shader
!= NULL
);
186 if (shader
->shader_prog
!= 0) {
187 _mesa_UseProgram(shader
->shader_prog
);
191 if (ctx
->Const
.GLSLVersion
< 130) {
193 "attribute vec2 position;\n"
194 "attribute vec4 textureCoords;\n"
195 "varying vec4 texCoords;\n"
198 " texCoords = textureCoords;\n"
199 " gl_Position = vec4(position, 0.0, 1.0);\n"
202 fs_source
= ralloc_asprintf(mem_ctx
,
203 "#extension GL_EXT_texture_array : enable\n"
204 "#extension GL_ARB_texture_cube_map_array: enable\n"
205 "uniform %s texSampler;\n"
206 "varying vec4 texCoords;\n"
209 " gl_FragColor = %s(texSampler, %s);\n"
210 " gl_FragDepth = gl_FragColor.x;\n"
213 shader
->func
, shader
->texcoords
);
216 vs_source
= ralloc_asprintf(mem_ctx
,
218 "in vec2 position;\n"
219 "in vec4 textureCoords;\n"
220 "out vec4 texCoords;\n"
223 " texCoords = textureCoords;\n"
224 " gl_Position = vec4(position, 0.0, 1.0);\n"
226 fs_source
= ralloc_asprintf(mem_ctx
,
228 "#extension GL_ARB_texture_cube_map_array: enable\n"
229 "uniform %s texSampler;\n"
230 "in vec4 texCoords;\n"
231 "out vec4 out_color;\n"
235 " out_color = texture(texSampler, %s);\n"
236 " gl_FragDepth = out_color.x;\n"
242 vs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_VERTEX_SHADER
, vs_source
);
243 fs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_FRAGMENT_SHADER
, fs_source
);
245 shader
->shader_prog
= _mesa_CreateProgram();
246 _mesa_AttachShader(shader
->shader_prog
, fs
);
247 _mesa_DeleteShader(fs
);
248 _mesa_AttachShader(shader
->shader_prog
, vs
);
249 _mesa_DeleteShader(vs
);
250 _mesa_BindAttribLocation(shader
->shader_prog
, 0, "position");
251 _mesa_BindAttribLocation(shader
->shader_prog
, 1, "texcoords");
252 _mesa_meta_link_program_with_debug(ctx
, shader
->shader_prog
);
253 name
= ralloc_asprintf(mem_ctx
, "%s blit", shader
->type
);
254 _mesa_ObjectLabel(GL_PROGRAM
, shader
->shader_prog
, -1, name
);
255 ralloc_free(mem_ctx
);
257 _mesa_UseProgram(shader
->shader_prog
);
261 * Configure vertex buffer and vertex array objects for tests
263 * Regardless of whether a new VAO and new VBO are created, the objects
264 * referenced by \c VAO and \c VBO will be bound into the GL state vector
265 * when this function terminates.
267 * \param VAO Storage for vertex array object handle. If 0, a new VAO
269 * \param VBO Storage for vertex buffer object handle. If 0, a new VBO
270 * will be created. The new VBO will have storage for 4
271 * \c vertex structures.
272 * \param use_generic_attributes Should generic attributes 0 and 1 be used,
273 * or should traditional, fixed-function color and texture
274 * coordinate be used?
275 * \param vertex_size Number of components for attribute 0 / vertex.
276 * \param texcoord_size Number of components for attribute 1 / texture
277 * coordinate. If this is 0, attribute 1 will not be set or
279 * \param color_size Number of components for attribute 1 / primary color.
280 * If this is 0, attribute 1 will not be set or enabled.
282 * \note If \c use_generic_attributes is \c true, \c color_size must be zero.
283 * Use \c texcoord_size instead.
286 _mesa_meta_setup_vertex_objects(GLuint
*VAO
, GLuint
*VBO
,
287 bool use_generic_attributes
,
288 unsigned vertex_size
, unsigned texcoord_size
,
294 /* create vertex array object */
295 _mesa_GenVertexArrays(1, VAO
);
296 _mesa_BindVertexArray(*VAO
);
298 /* create vertex array buffer */
299 _mesa_GenBuffers(1, VBO
);
300 _mesa_BindBuffer(GL_ARRAY_BUFFER
, *VBO
);
301 _mesa_BufferData(GL_ARRAY_BUFFER
, 4 * sizeof(struct vertex
), NULL
,
304 /* setup vertex arrays */
305 if (use_generic_attributes
) {
306 assert(color_size
== 0);
308 _mesa_VertexAttribPointer(0, vertex_size
, GL_FLOAT
, GL_FALSE
,
309 sizeof(struct vertex
), OFFSET(x
));
310 _mesa_EnableVertexAttribArray(0);
312 if (texcoord_size
> 0) {
313 _mesa_VertexAttribPointer(1, texcoord_size
, GL_FLOAT
, GL_FALSE
,
314 sizeof(struct vertex
), OFFSET(tex
));
315 _mesa_EnableVertexAttribArray(1);
318 _mesa_VertexPointer(vertex_size
, GL_FLOAT
, sizeof(struct vertex
),
320 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
322 if (texcoord_size
> 0) {
323 _mesa_TexCoordPointer(texcoord_size
, GL_FLOAT
,
324 sizeof(struct vertex
), OFFSET(tex
));
325 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
328 if (color_size
> 0) {
329 _mesa_ColorPointer(color_size
, GL_FLOAT
,
330 sizeof(struct vertex
), OFFSET(r
));
331 _mesa_EnableClientState(GL_COLOR_ARRAY
);
335 _mesa_BindVertexArray(*VAO
);
336 _mesa_BindBuffer(GL_ARRAY_BUFFER
, *VBO
);
341 * Initialize meta-ops for a context.
342 * To be called once during context creation.
345 _mesa_meta_init(struct gl_context
*ctx
)
349 ctx
->Meta
= CALLOC_STRUCT(gl_meta_state
);
354 * Free context meta-op state.
355 * To be called once during context destruction.
358 _mesa_meta_free(struct gl_context
*ctx
)
360 GET_CURRENT_CONTEXT(old_context
);
361 _mesa_make_current(ctx
, NULL
, NULL
);
362 _mesa_meta_glsl_blit_cleanup(&ctx
->Meta
->Blit
);
363 meta_glsl_clear_cleanup(&ctx
->Meta
->Clear
);
364 _mesa_meta_glsl_generate_mipmap_cleanup(&ctx
->Meta
->Mipmap
);
365 cleanup_temp_texture(&ctx
->Meta
->TempTex
);
366 meta_decompress_cleanup(&ctx
->Meta
->Decompress
);
367 meta_drawpix_cleanup(&ctx
->Meta
->DrawPix
);
369 _mesa_make_current(old_context
, old_context
->WinSysDrawBuffer
, old_context
->WinSysReadBuffer
);
371 _mesa_make_current(NULL
, NULL
, NULL
);
378 * Enter meta state. This is like a light-weight version of glPushAttrib
379 * but it also resets most GL state back to default values.
381 * \param state bitmask of MESA_META_* flags indicating which attribute groups
382 * to save and reset to their defaults
385 _mesa_meta_begin(struct gl_context
*ctx
, GLbitfield state
)
387 struct save_state
*save
;
389 /* hope MAX_META_OPS_DEPTH is large enough */
390 assert(ctx
->Meta
->SaveStackDepth
< MAX_META_OPS_DEPTH
);
392 save
= &ctx
->Meta
->Save
[ctx
->Meta
->SaveStackDepth
++];
393 memset(save
, 0, sizeof(*save
));
394 save
->SavedState
= state
;
396 /* We always push into desktop GL mode and pop out at the end. No sense in
397 * writing our shaders varying based on the user's context choice, when
398 * Mesa can handle either.
400 save
->API
= ctx
->API
;
401 ctx
->API
= API_OPENGL_COMPAT
;
403 /* Pausing transform feedback needs to be done early, or else we won't be
404 * able to change other state.
406 save
->TransformFeedbackNeedsResume
=
407 _mesa_is_xfb_active_and_unpaused(ctx
);
408 if (save
->TransformFeedbackNeedsResume
)
409 _mesa_PauseTransformFeedback();
411 /* After saving the current occlusion object, call EndQuery so that no
412 * occlusion querying will be active during the meta-operation.
414 if (state
& MESA_META_OCCLUSION_QUERY
) {
415 save
->CurrentOcclusionObject
= ctx
->Query
.CurrentOcclusionObject
;
416 if (save
->CurrentOcclusionObject
)
417 _mesa_EndQuery(save
->CurrentOcclusionObject
->Target
);
420 if (state
& MESA_META_ALPHA_TEST
) {
421 save
->AlphaEnabled
= ctx
->Color
.AlphaEnabled
;
422 save
->AlphaFunc
= ctx
->Color
.AlphaFunc
;
423 save
->AlphaRef
= ctx
->Color
.AlphaRef
;
424 if (ctx
->Color
.AlphaEnabled
)
425 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_FALSE
);
428 if (state
& MESA_META_BLEND
) {
429 save
->BlendEnabled
= ctx
->Color
.BlendEnabled
;
430 if (ctx
->Color
.BlendEnabled
) {
431 if (ctx
->Extensions
.EXT_draw_buffers2
) {
433 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
434 _mesa_set_enablei(ctx
, GL_BLEND
, i
, GL_FALSE
);
438 _mesa_set_enable(ctx
, GL_BLEND
, GL_FALSE
);
441 save
->ColorLogicOpEnabled
= ctx
->Color
.ColorLogicOpEnabled
;
442 if (ctx
->Color
.ColorLogicOpEnabled
)
443 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, GL_FALSE
);
446 if (state
& MESA_META_COLOR_MASK
) {
447 memcpy(save
->ColorMask
, ctx
->Color
.ColorMask
,
448 sizeof(ctx
->Color
.ColorMask
));
449 if (!ctx
->Color
.ColorMask
[0][0] ||
450 !ctx
->Color
.ColorMask
[0][1] ||
451 !ctx
->Color
.ColorMask
[0][2] ||
452 !ctx
->Color
.ColorMask
[0][3])
453 _mesa_ColorMask(GL_TRUE
, GL_TRUE
, GL_TRUE
, GL_TRUE
);
456 if (state
& MESA_META_DEPTH_TEST
) {
457 save
->Depth
= ctx
->Depth
; /* struct copy */
459 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_FALSE
);
462 if (state
& MESA_META_FOG
) {
463 save
->Fog
= ctx
->Fog
.Enabled
;
464 if (ctx
->Fog
.Enabled
)
465 _mesa_set_enable(ctx
, GL_FOG
, GL_FALSE
);
468 if (state
& MESA_META_PIXEL_STORE
) {
469 save
->Pack
= ctx
->Pack
;
470 save
->Unpack
= ctx
->Unpack
;
471 ctx
->Pack
= ctx
->DefaultPacking
;
472 ctx
->Unpack
= ctx
->DefaultPacking
;
475 if (state
& MESA_META_PIXEL_TRANSFER
) {
476 save
->RedScale
= ctx
->Pixel
.RedScale
;
477 save
->RedBias
= ctx
->Pixel
.RedBias
;
478 save
->GreenScale
= ctx
->Pixel
.GreenScale
;
479 save
->GreenBias
= ctx
->Pixel
.GreenBias
;
480 save
->BlueScale
= ctx
->Pixel
.BlueScale
;
481 save
->BlueBias
= ctx
->Pixel
.BlueBias
;
482 save
->AlphaScale
= ctx
->Pixel
.AlphaScale
;
483 save
->AlphaBias
= ctx
->Pixel
.AlphaBias
;
484 save
->MapColorFlag
= ctx
->Pixel
.MapColorFlag
;
485 ctx
->Pixel
.RedScale
= 1.0F
;
486 ctx
->Pixel
.RedBias
= 0.0F
;
487 ctx
->Pixel
.GreenScale
= 1.0F
;
488 ctx
->Pixel
.GreenBias
= 0.0F
;
489 ctx
->Pixel
.BlueScale
= 1.0F
;
490 ctx
->Pixel
.BlueBias
= 0.0F
;
491 ctx
->Pixel
.AlphaScale
= 1.0F
;
492 ctx
->Pixel
.AlphaBias
= 0.0F
;
493 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
495 ctx
->NewState
|=_NEW_PIXEL
;
498 if (state
& MESA_META_RASTERIZATION
) {
499 save
->FrontPolygonMode
= ctx
->Polygon
.FrontMode
;
500 save
->BackPolygonMode
= ctx
->Polygon
.BackMode
;
501 save
->PolygonOffset
= ctx
->Polygon
.OffsetFill
;
502 save
->PolygonSmooth
= ctx
->Polygon
.SmoothFlag
;
503 save
->PolygonStipple
= ctx
->Polygon
.StippleFlag
;
504 save
->PolygonCull
= ctx
->Polygon
.CullFlag
;
505 _mesa_PolygonMode(GL_FRONT_AND_BACK
, GL_FILL
);
506 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, GL_FALSE
);
507 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, GL_FALSE
);
508 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, GL_FALSE
);
509 _mesa_set_enable(ctx
, GL_CULL_FACE
, GL_FALSE
);
512 if (state
& MESA_META_SCISSOR
) {
513 save
->Scissor
= ctx
->Scissor
; /* struct copy */
514 _mesa_set_enable(ctx
, GL_SCISSOR_TEST
, GL_FALSE
);
517 if (state
& MESA_META_SHADER
) {
520 if (ctx
->Extensions
.ARB_vertex_program
) {
521 save
->VertexProgramEnabled
= ctx
->VertexProgram
.Enabled
;
522 _mesa_reference_vertprog(ctx
, &save
->VertexProgram
,
523 ctx
->VertexProgram
.Current
);
524 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
, GL_FALSE
);
527 if (ctx
->Extensions
.ARB_fragment_program
) {
528 save
->FragmentProgramEnabled
= ctx
->FragmentProgram
.Enabled
;
529 _mesa_reference_fragprog(ctx
, &save
->FragmentProgram
,
530 ctx
->FragmentProgram
.Current
);
531 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_FALSE
);
534 if (ctx
->Extensions
.ATI_fragment_shader
) {
535 save
->ATIFragmentShaderEnabled
= ctx
->ATIFragmentShader
.Enabled
;
536 _mesa_set_enable(ctx
, GL_FRAGMENT_SHADER_ATI
, GL_FALSE
);
539 if (ctx
->Extensions
.ARB_separate_shader_objects
) {
540 /* Warning it must be done before _mesa_UseProgram call */
541 _mesa_reference_pipeline_object(ctx
, &save
->_Shader
, ctx
->_Shader
);
542 _mesa_reference_pipeline_object(ctx
, &save
->Pipeline
,
543 ctx
->Pipeline
.Current
);
544 _mesa_BindProgramPipeline(0);
547 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++) {
548 _mesa_reference_shader_program(ctx
, &save
->Shader
[i
],
549 ctx
->_Shader
->CurrentProgram
[i
]);
551 _mesa_reference_shader_program(ctx
, &save
->ActiveShader
,
552 ctx
->_Shader
->ActiveProgram
);
557 if (state
& MESA_META_STENCIL_TEST
) {
558 save
->Stencil
= ctx
->Stencil
; /* struct copy */
559 if (ctx
->Stencil
.Enabled
)
560 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_FALSE
);
561 /* NOTE: other stencil state not reset */
564 if (state
& MESA_META_TEXTURE
) {
567 save
->ActiveUnit
= ctx
->Texture
.CurrentUnit
;
568 save
->ClientActiveUnit
= ctx
->Array
.ActiveTexture
;
569 save
->EnvMode
= ctx
->Texture
.Unit
[0].EnvMode
;
571 /* Disable all texture units */
572 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
573 save
->TexEnabled
[u
] = ctx
->Texture
.Unit
[u
].Enabled
;
574 save
->TexGenEnabled
[u
] = ctx
->Texture
.Unit
[u
].TexGenEnabled
;
575 if (ctx
->Texture
.Unit
[u
].Enabled
||
576 ctx
->Texture
.Unit
[u
].TexGenEnabled
) {
577 _mesa_ActiveTexture(GL_TEXTURE0
+ u
);
578 _mesa_set_enable(ctx
, GL_TEXTURE_2D
, GL_FALSE
);
579 if (ctx
->Extensions
.ARB_texture_cube_map
)
580 _mesa_set_enable(ctx
, GL_TEXTURE_CUBE_MAP
, GL_FALSE
);
582 _mesa_set_enable(ctx
, GL_TEXTURE_1D
, GL_FALSE
);
583 _mesa_set_enable(ctx
, GL_TEXTURE_3D
, GL_FALSE
);
584 if (ctx
->Extensions
.NV_texture_rectangle
)
585 _mesa_set_enable(ctx
, GL_TEXTURE_RECTANGLE
, GL_FALSE
);
586 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_S
, GL_FALSE
);
587 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_T
, GL_FALSE
);
588 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_R
, GL_FALSE
);
589 _mesa_set_enable(ctx
, GL_TEXTURE_GEN_Q
, GL_FALSE
);
593 /* save current texture objects for unit[0] only */
594 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
595 _mesa_reference_texobj(&save
->CurrentTexture
[tgt
],
596 ctx
->Texture
.Unit
[0].CurrentTex
[tgt
]);
599 /* set defaults for unit[0] */
600 _mesa_ActiveTexture(GL_TEXTURE0
);
601 _mesa_ClientActiveTexture(GL_TEXTURE0
);
602 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
605 if (state
& MESA_META_TRANSFORM
) {
606 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
607 memcpy(save
->ModelviewMatrix
, ctx
->ModelviewMatrixStack
.Top
->m
,
608 16 * sizeof(GLfloat
));
609 memcpy(save
->ProjectionMatrix
, ctx
->ProjectionMatrixStack
.Top
->m
,
610 16 * sizeof(GLfloat
));
611 memcpy(save
->TextureMatrix
, ctx
->TextureMatrixStack
[0].Top
->m
,
612 16 * sizeof(GLfloat
));
613 save
->MatrixMode
= ctx
->Transform
.MatrixMode
;
614 /* set 1:1 vertex:pixel coordinate transform */
615 _mesa_ActiveTexture(GL_TEXTURE0
);
616 _mesa_MatrixMode(GL_TEXTURE
);
617 _mesa_LoadIdentity();
618 _mesa_ActiveTexture(GL_TEXTURE0
+ activeTexture
);
619 _mesa_MatrixMode(GL_MODELVIEW
);
620 _mesa_LoadIdentity();
621 _mesa_MatrixMode(GL_PROJECTION
);
622 _mesa_LoadIdentity();
624 /* glOrtho with width = 0 or height = 0 generates GL_INVALID_VALUE.
625 * This can occur when there is no draw buffer.
627 if (ctx
->DrawBuffer
->Width
!= 0 && ctx
->DrawBuffer
->Height
!= 0)
628 _mesa_Ortho(0.0, ctx
->DrawBuffer
->Width
,
629 0.0, ctx
->DrawBuffer
->Height
,
633 if (state
& MESA_META_CLIP
) {
634 save
->ClipPlanesEnabled
= ctx
->Transform
.ClipPlanesEnabled
;
635 if (ctx
->Transform
.ClipPlanesEnabled
) {
637 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
638 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_FALSE
);
643 if (state
& MESA_META_VERTEX
) {
644 /* save vertex array object state */
645 _mesa_reference_vao(ctx
, &save
->VAO
,
647 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
,
648 ctx
->Array
.ArrayBufferObj
);
649 /* set some default state? */
652 if (state
& MESA_META_VIEWPORT
) {
653 /* save viewport state */
654 save
->ViewportX
= ctx
->ViewportArray
[0].X
;
655 save
->ViewportY
= ctx
->ViewportArray
[0].Y
;
656 save
->ViewportW
= ctx
->ViewportArray
[0].Width
;
657 save
->ViewportH
= ctx
->ViewportArray
[0].Height
;
658 /* set viewport to match window size */
659 if (ctx
->ViewportArray
[0].X
!= 0 ||
660 ctx
->ViewportArray
[0].Y
!= 0 ||
661 ctx
->ViewportArray
[0].Width
!= (float) ctx
->DrawBuffer
->Width
||
662 ctx
->ViewportArray
[0].Height
!= (float) ctx
->DrawBuffer
->Height
) {
663 _mesa_set_viewport(ctx
, 0, 0, 0,
664 ctx
->DrawBuffer
->Width
, ctx
->DrawBuffer
->Height
);
666 /* save depth range state */
667 save
->DepthNear
= ctx
->ViewportArray
[0].Near
;
668 save
->DepthFar
= ctx
->ViewportArray
[0].Far
;
669 /* set depth range to default */
670 _mesa_DepthRange(0.0, 1.0);
673 if (state
& MESA_META_CLAMP_FRAGMENT_COLOR
) {
674 save
->ClampFragmentColor
= ctx
->Color
.ClampFragmentColor
;
676 /* Generally in here we want to do clamping according to whether
677 * it's for the pixel path (ClampFragmentColor is GL_TRUE),
678 * regardless of the internal implementation of the metaops.
680 if (ctx
->Color
.ClampFragmentColor
!= GL_TRUE
&&
681 ctx
->Extensions
.ARB_color_buffer_float
)
682 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, GL_FALSE
);
685 if (state
& MESA_META_CLAMP_VERTEX_COLOR
) {
686 save
->ClampVertexColor
= ctx
->Light
.ClampVertexColor
;
688 /* Generally in here we never want vertex color clamping --
689 * result clamping is only dependent on fragment clamping.
691 if (ctx
->Extensions
.ARB_color_buffer_float
)
692 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR
, GL_FALSE
);
695 if (state
& MESA_META_CONDITIONAL_RENDER
) {
696 save
->CondRenderQuery
= ctx
->Query
.CondRenderQuery
;
697 save
->CondRenderMode
= ctx
->Query
.CondRenderMode
;
699 if (ctx
->Query
.CondRenderQuery
)
700 _mesa_EndConditionalRender();
703 if (state
& MESA_META_SELECT_FEEDBACK
) {
704 save
->RenderMode
= ctx
->RenderMode
;
705 if (ctx
->RenderMode
== GL_SELECT
) {
706 save
->Select
= ctx
->Select
; /* struct copy */
707 _mesa_RenderMode(GL_RENDER
);
708 } else if (ctx
->RenderMode
== GL_FEEDBACK
) {
709 save
->Feedback
= ctx
->Feedback
; /* struct copy */
710 _mesa_RenderMode(GL_RENDER
);
714 if (state
& MESA_META_MULTISAMPLE
) {
715 save
->Multisample
= ctx
->Multisample
; /* struct copy */
717 if (ctx
->Multisample
.Enabled
)
718 _mesa_set_multisample(ctx
, GL_FALSE
);
719 if (ctx
->Multisample
.SampleCoverage
)
720 _mesa_set_enable(ctx
, GL_SAMPLE_COVERAGE
, GL_FALSE
);
721 if (ctx
->Multisample
.SampleAlphaToCoverage
)
722 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_COVERAGE
, GL_FALSE
);
723 if (ctx
->Multisample
.SampleAlphaToOne
)
724 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_ONE
, GL_FALSE
);
725 if (ctx
->Multisample
.SampleShading
)
726 _mesa_set_enable(ctx
, GL_SAMPLE_SHADING
, GL_FALSE
);
727 if (ctx
->Multisample
.SampleMask
)
728 _mesa_set_enable(ctx
, GL_SAMPLE_MASK
, GL_FALSE
);
731 if (state
& MESA_META_FRAMEBUFFER_SRGB
) {
732 save
->sRGBEnabled
= ctx
->Color
.sRGBEnabled
;
733 if (ctx
->Color
.sRGBEnabled
)
734 _mesa_set_framebuffer_srgb(ctx
, GL_FALSE
);
739 save
->Lighting
= ctx
->Light
.Enabled
;
740 if (ctx
->Light
.Enabled
)
741 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_FALSE
);
742 save
->RasterDiscard
= ctx
->RasterDiscard
;
743 if (ctx
->RasterDiscard
)
744 _mesa_set_enable(ctx
, GL_RASTERIZER_DISCARD
, GL_FALSE
);
746 save
->DrawBufferName
= ctx
->DrawBuffer
->Name
;
747 save
->ReadBufferName
= ctx
->ReadBuffer
->Name
;
748 save
->RenderbufferName
= (ctx
->CurrentRenderbuffer
?
749 ctx
->CurrentRenderbuffer
->Name
: 0);
755 * Leave meta state. This is like a light-weight version of glPopAttrib().
758 _mesa_meta_end(struct gl_context
*ctx
)
760 struct save_state
*save
= &ctx
->Meta
->Save
[ctx
->Meta
->SaveStackDepth
- 1];
761 const GLbitfield state
= save
->SavedState
;
764 /* After starting a new occlusion query, initialize the results to the
765 * values saved previously. The driver will then continue to increment
768 if (state
& MESA_META_OCCLUSION_QUERY
) {
769 if (save
->CurrentOcclusionObject
) {
770 _mesa_BeginQuery(save
->CurrentOcclusionObject
->Target
,
771 save
->CurrentOcclusionObject
->Id
);
772 ctx
->Query
.CurrentOcclusionObject
->Result
= save
->CurrentOcclusionObject
->Result
;
776 if (state
& MESA_META_ALPHA_TEST
) {
777 if (ctx
->Color
.AlphaEnabled
!= save
->AlphaEnabled
)
778 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, save
->AlphaEnabled
);
779 _mesa_AlphaFunc(save
->AlphaFunc
, save
->AlphaRef
);
782 if (state
& MESA_META_BLEND
) {
783 if (ctx
->Color
.BlendEnabled
!= save
->BlendEnabled
) {
784 if (ctx
->Extensions
.EXT_draw_buffers2
) {
786 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
787 _mesa_set_enablei(ctx
, GL_BLEND
, i
, (save
->BlendEnabled
>> i
) & 1);
791 _mesa_set_enable(ctx
, GL_BLEND
, (save
->BlendEnabled
& 1));
794 if (ctx
->Color
.ColorLogicOpEnabled
!= save
->ColorLogicOpEnabled
)
795 _mesa_set_enable(ctx
, GL_COLOR_LOGIC_OP
, save
->ColorLogicOpEnabled
);
798 if (state
& MESA_META_COLOR_MASK
) {
800 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
801 if (!TEST_EQ_4V(ctx
->Color
.ColorMask
[i
], save
->ColorMask
[i
])) {
803 _mesa_ColorMask(save
->ColorMask
[i
][0], save
->ColorMask
[i
][1],
804 save
->ColorMask
[i
][2], save
->ColorMask
[i
][3]);
808 save
->ColorMask
[i
][0],
809 save
->ColorMask
[i
][1],
810 save
->ColorMask
[i
][2],
811 save
->ColorMask
[i
][3]);
817 if (state
& MESA_META_DEPTH_TEST
) {
818 if (ctx
->Depth
.Test
!= save
->Depth
.Test
)
819 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, save
->Depth
.Test
);
820 _mesa_DepthFunc(save
->Depth
.Func
);
821 _mesa_DepthMask(save
->Depth
.Mask
);
824 if (state
& MESA_META_FOG
) {
825 _mesa_set_enable(ctx
, GL_FOG
, save
->Fog
);
828 if (state
& MESA_META_PIXEL_STORE
) {
829 ctx
->Pack
= save
->Pack
;
830 ctx
->Unpack
= save
->Unpack
;
833 if (state
& MESA_META_PIXEL_TRANSFER
) {
834 ctx
->Pixel
.RedScale
= save
->RedScale
;
835 ctx
->Pixel
.RedBias
= save
->RedBias
;
836 ctx
->Pixel
.GreenScale
= save
->GreenScale
;
837 ctx
->Pixel
.GreenBias
= save
->GreenBias
;
838 ctx
->Pixel
.BlueScale
= save
->BlueScale
;
839 ctx
->Pixel
.BlueBias
= save
->BlueBias
;
840 ctx
->Pixel
.AlphaScale
= save
->AlphaScale
;
841 ctx
->Pixel
.AlphaBias
= save
->AlphaBias
;
842 ctx
->Pixel
.MapColorFlag
= save
->MapColorFlag
;
844 ctx
->NewState
|=_NEW_PIXEL
;
847 if (state
& MESA_META_RASTERIZATION
) {
848 _mesa_PolygonMode(GL_FRONT
, save
->FrontPolygonMode
);
849 _mesa_PolygonMode(GL_BACK
, save
->BackPolygonMode
);
850 _mesa_set_enable(ctx
, GL_POLYGON_STIPPLE
, save
->PolygonStipple
);
851 _mesa_set_enable(ctx
, GL_POLYGON_SMOOTH
, save
->PolygonSmooth
);
852 _mesa_set_enable(ctx
, GL_POLYGON_OFFSET_FILL
, save
->PolygonOffset
);
853 _mesa_set_enable(ctx
, GL_CULL_FACE
, save
->PolygonCull
);
856 if (state
& MESA_META_SCISSOR
) {
859 for (i
= 0; i
< ctx
->Const
.MaxViewports
; i
++) {
860 _mesa_set_scissor(ctx
, i
,
861 save
->Scissor
.ScissorArray
[i
].X
,
862 save
->Scissor
.ScissorArray
[i
].Y
,
863 save
->Scissor
.ScissorArray
[i
].Width
,
864 save
->Scissor
.ScissorArray
[i
].Height
);
865 _mesa_set_enablei(ctx
, GL_SCISSOR_TEST
, i
,
866 (save
->Scissor
.EnableFlags
>> i
) & 1);
870 if (state
& MESA_META_SHADER
) {
871 if (ctx
->Extensions
.ARB_vertex_program
) {
872 _mesa_set_enable(ctx
, GL_VERTEX_PROGRAM_ARB
,
873 save
->VertexProgramEnabled
);
874 _mesa_reference_vertprog(ctx
, &ctx
->VertexProgram
.Current
,
875 save
->VertexProgram
);
876 _mesa_reference_vertprog(ctx
, &save
->VertexProgram
, NULL
);
879 if (ctx
->Extensions
.ARB_fragment_program
) {
880 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
,
881 save
->FragmentProgramEnabled
);
882 _mesa_reference_fragprog(ctx
, &ctx
->FragmentProgram
.Current
,
883 save
->FragmentProgram
);
884 _mesa_reference_fragprog(ctx
, &save
->FragmentProgram
, NULL
);
887 if (ctx
->Extensions
.ATI_fragment_shader
) {
888 _mesa_set_enable(ctx
, GL_FRAGMENT_SHADER_ATI
,
889 save
->ATIFragmentShaderEnabled
);
892 /* Warning it must be done before _mesa_use_shader_program call */
893 if (ctx
->Extensions
.ARB_separate_shader_objects
) {
894 _mesa_reference_pipeline_object(ctx
, &ctx
->_Shader
, save
->_Shader
);
895 _mesa_reference_pipeline_object(ctx
, &ctx
->Pipeline
.Current
,
897 _mesa_reference_pipeline_object(ctx
, &save
->Pipeline
, NULL
);
900 if (ctx
->Extensions
.ARB_vertex_shader
) {
901 _mesa_use_shader_program(ctx
, GL_VERTEX_SHADER
,
902 save
->Shader
[MESA_SHADER_VERTEX
],
906 if (_mesa_has_geometry_shaders(ctx
))
907 _mesa_use_shader_program(ctx
, GL_GEOMETRY_SHADER_ARB
,
908 save
->Shader
[MESA_SHADER_GEOMETRY
],
911 if (ctx
->Extensions
.ARB_fragment_shader
)
912 _mesa_use_shader_program(ctx
, GL_FRAGMENT_SHADER
,
913 save
->Shader
[MESA_SHADER_FRAGMENT
],
916 _mesa_reference_shader_program(ctx
, &ctx
->_Shader
->ActiveProgram
,
919 for (i
= 0; i
< MESA_SHADER_STAGES
; i
++)
920 _mesa_reference_shader_program(ctx
, &save
->Shader
[i
], NULL
);
921 _mesa_reference_shader_program(ctx
, &save
->ActiveShader
, NULL
);
922 _mesa_reference_pipeline_object(ctx
, &save
->_Shader
, NULL
);
925 if (state
& MESA_META_STENCIL_TEST
) {
926 const struct gl_stencil_attrib
*stencil
= &save
->Stencil
;
928 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, stencil
->Enabled
);
929 _mesa_ClearStencil(stencil
->Clear
);
930 if (ctx
->Extensions
.EXT_stencil_two_side
) {
931 _mesa_set_enable(ctx
, GL_STENCIL_TEST_TWO_SIDE_EXT
,
932 stencil
->TestTwoSide
);
933 _mesa_ActiveStencilFaceEXT(stencil
->ActiveFace
934 ? GL_BACK
: GL_FRONT
);
937 _mesa_StencilFuncSeparate(GL_FRONT
,
938 stencil
->Function
[0],
940 stencil
->ValueMask
[0]);
941 _mesa_StencilMaskSeparate(GL_FRONT
, stencil
->WriteMask
[0]);
942 _mesa_StencilOpSeparate(GL_FRONT
, stencil
->FailFunc
[0],
943 stencil
->ZFailFunc
[0],
944 stencil
->ZPassFunc
[0]);
946 _mesa_StencilFuncSeparate(GL_BACK
,
947 stencil
->Function
[1],
949 stencil
->ValueMask
[1]);
950 _mesa_StencilMaskSeparate(GL_BACK
, stencil
->WriteMask
[1]);
951 _mesa_StencilOpSeparate(GL_BACK
, stencil
->FailFunc
[1],
952 stencil
->ZFailFunc
[1],
953 stencil
->ZPassFunc
[1]);
956 if (state
& MESA_META_TEXTURE
) {
959 ASSERT(ctx
->Texture
.CurrentUnit
== 0);
961 /* restore texenv for unit[0] */
962 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, save
->EnvMode
);
964 /* restore texture objects for unit[0] only */
965 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
966 if (ctx
->Texture
.Unit
[0].CurrentTex
[tgt
] != save
->CurrentTexture
[tgt
]) {
967 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
968 _mesa_reference_texobj(&ctx
->Texture
.Unit
[0].CurrentTex
[tgt
],
969 save
->CurrentTexture
[tgt
]);
971 _mesa_reference_texobj(&save
->CurrentTexture
[tgt
], NULL
);
974 /* Restore fixed function texture enables, texgen */
975 for (u
= 0; u
< ctx
->Const
.MaxTextureUnits
; u
++) {
976 if (ctx
->Texture
.Unit
[u
].Enabled
!= save
->TexEnabled
[u
]) {
977 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
978 ctx
->Texture
.Unit
[u
].Enabled
= save
->TexEnabled
[u
];
981 if (ctx
->Texture
.Unit
[u
].TexGenEnabled
!= save
->TexGenEnabled
[u
]) {
982 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
983 ctx
->Texture
.Unit
[u
].TexGenEnabled
= save
->TexGenEnabled
[u
];
987 /* restore current unit state */
988 _mesa_ActiveTexture(GL_TEXTURE0
+ save
->ActiveUnit
);
989 _mesa_ClientActiveTexture(GL_TEXTURE0
+ save
->ClientActiveUnit
);
992 if (state
& MESA_META_TRANSFORM
) {
993 GLuint activeTexture
= ctx
->Texture
.CurrentUnit
;
994 _mesa_ActiveTexture(GL_TEXTURE0
);
995 _mesa_MatrixMode(GL_TEXTURE
);
996 _mesa_LoadMatrixf(save
->TextureMatrix
);
997 _mesa_ActiveTexture(GL_TEXTURE0
+ activeTexture
);
999 _mesa_MatrixMode(GL_MODELVIEW
);
1000 _mesa_LoadMatrixf(save
->ModelviewMatrix
);
1002 _mesa_MatrixMode(GL_PROJECTION
);
1003 _mesa_LoadMatrixf(save
->ProjectionMatrix
);
1005 _mesa_MatrixMode(save
->MatrixMode
);
1008 if (state
& MESA_META_CLIP
) {
1009 if (save
->ClipPlanesEnabled
) {
1011 for (i
= 0; i
< ctx
->Const
.MaxClipPlanes
; i
++) {
1012 if (save
->ClipPlanesEnabled
& (1 << i
)) {
1013 _mesa_set_enable(ctx
, GL_CLIP_PLANE0
+ i
, GL_TRUE
);
1019 if (state
& MESA_META_VERTEX
) {
1020 /* restore vertex buffer object */
1021 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
, save
->ArrayBufferObj
->Name
);
1022 _mesa_reference_buffer_object(ctx
, &save
->ArrayBufferObj
, NULL
);
1024 /* restore vertex array object */
1025 _mesa_BindVertexArray(save
->VAO
->Name
);
1026 _mesa_reference_vao(ctx
, &save
->VAO
, NULL
);
1029 if (state
& MESA_META_VIEWPORT
) {
1030 if (save
->ViewportX
!= ctx
->ViewportArray
[0].X
||
1031 save
->ViewportY
!= ctx
->ViewportArray
[0].Y
||
1032 save
->ViewportW
!= ctx
->ViewportArray
[0].Width
||
1033 save
->ViewportH
!= ctx
->ViewportArray
[0].Height
) {
1034 _mesa_set_viewport(ctx
, 0, save
->ViewportX
, save
->ViewportY
,
1035 save
->ViewportW
, save
->ViewportH
);
1037 _mesa_DepthRange(save
->DepthNear
, save
->DepthFar
);
1040 if (state
& MESA_META_CLAMP_FRAGMENT_COLOR
&&
1041 ctx
->Extensions
.ARB_color_buffer_float
) {
1042 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, save
->ClampFragmentColor
);
1045 if (state
& MESA_META_CLAMP_VERTEX_COLOR
&&
1046 ctx
->Extensions
.ARB_color_buffer_float
) {
1047 _mesa_ClampColor(GL_CLAMP_VERTEX_COLOR
, save
->ClampVertexColor
);
1050 if (state
& MESA_META_CONDITIONAL_RENDER
) {
1051 if (save
->CondRenderQuery
)
1052 _mesa_BeginConditionalRender(save
->CondRenderQuery
->Id
,
1053 save
->CondRenderMode
);
1056 if (state
& MESA_META_SELECT_FEEDBACK
) {
1057 if (save
->RenderMode
== GL_SELECT
) {
1058 _mesa_RenderMode(GL_SELECT
);
1059 ctx
->Select
= save
->Select
;
1060 } else if (save
->RenderMode
== GL_FEEDBACK
) {
1061 _mesa_RenderMode(GL_FEEDBACK
);
1062 ctx
->Feedback
= save
->Feedback
;
1066 if (state
& MESA_META_MULTISAMPLE
) {
1067 struct gl_multisample_attrib
*ctx_ms
= &ctx
->Multisample
;
1068 struct gl_multisample_attrib
*save_ms
= &save
->Multisample
;
1070 if (ctx_ms
->Enabled
!= save_ms
->Enabled
)
1071 _mesa_set_multisample(ctx
, save_ms
->Enabled
);
1072 if (ctx_ms
->SampleCoverage
!= save_ms
->SampleCoverage
)
1073 _mesa_set_enable(ctx
, GL_SAMPLE_COVERAGE
, save_ms
->SampleCoverage
);
1074 if (ctx_ms
->SampleAlphaToCoverage
!= save_ms
->SampleAlphaToCoverage
)
1075 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_COVERAGE
, save_ms
->SampleAlphaToCoverage
);
1076 if (ctx_ms
->SampleAlphaToOne
!= save_ms
->SampleAlphaToOne
)
1077 _mesa_set_enable(ctx
, GL_SAMPLE_ALPHA_TO_ONE
, save_ms
->SampleAlphaToOne
);
1078 if (ctx_ms
->SampleCoverageValue
!= save_ms
->SampleCoverageValue
||
1079 ctx_ms
->SampleCoverageInvert
!= save_ms
->SampleCoverageInvert
) {
1080 _mesa_SampleCoverage(save_ms
->SampleCoverageValue
,
1081 save_ms
->SampleCoverageInvert
);
1083 if (ctx_ms
->SampleShading
!= save_ms
->SampleShading
)
1084 _mesa_set_enable(ctx
, GL_SAMPLE_SHADING
, save_ms
->SampleShading
);
1085 if (ctx_ms
->SampleMask
!= save_ms
->SampleMask
)
1086 _mesa_set_enable(ctx
, GL_SAMPLE_MASK
, save_ms
->SampleMask
);
1087 if (ctx_ms
->SampleMaskValue
!= save_ms
->SampleMaskValue
)
1088 _mesa_SampleMaski(0, save_ms
->SampleMaskValue
);
1089 if (ctx_ms
->MinSampleShadingValue
!= save_ms
->MinSampleShadingValue
)
1090 _mesa_MinSampleShading(save_ms
->MinSampleShadingValue
);
1093 if (state
& MESA_META_FRAMEBUFFER_SRGB
) {
1094 if (ctx
->Color
.sRGBEnabled
!= save
->sRGBEnabled
)
1095 _mesa_set_framebuffer_srgb(ctx
, save
->sRGBEnabled
);
1099 if (save
->Lighting
) {
1100 _mesa_set_enable(ctx
, GL_LIGHTING
, GL_TRUE
);
1102 if (save
->RasterDiscard
) {
1103 _mesa_set_enable(ctx
, GL_RASTERIZER_DISCARD
, GL_TRUE
);
1105 if (save
->TransformFeedbackNeedsResume
)
1106 _mesa_ResumeTransformFeedback();
1108 if (ctx
->DrawBuffer
->Name
!= save
->DrawBufferName
)
1109 _mesa_BindFramebuffer(GL_DRAW_FRAMEBUFFER
, save
->DrawBufferName
);
1111 if (ctx
->ReadBuffer
->Name
!= save
->ReadBufferName
)
1112 _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER
, save
->ReadBufferName
);
1114 if (!ctx
->CurrentRenderbuffer
||
1115 ctx
->CurrentRenderbuffer
->Name
!= save
->RenderbufferName
)
1116 _mesa_BindRenderbuffer(GL_RENDERBUFFER
, save
->RenderbufferName
);
1118 ctx
->Meta
->SaveStackDepth
--;
1120 ctx
->API
= save
->API
;
1125 * Determine whether Mesa is currently in a meta state.
1128 _mesa_meta_in_progress(struct gl_context
*ctx
)
1130 return ctx
->Meta
->SaveStackDepth
!= 0;
1135 * Convert Z from a normalized value in the range [0, 1] to an object-space
1136 * Z coordinate in [-1, +1] so that drawing at the new Z position with the
1137 * default/identity ortho projection results in the original Z value.
1138 * Used by the meta-Clear, Draw/CopyPixels and Bitmap functions where the Z
1139 * value comes from the clear value or raster position.
1141 static INLINE GLfloat
1142 invert_z(GLfloat normZ
)
1144 GLfloat objZ
= 1.0f
- 2.0f
* normZ
;
1150 * One-time init for a temp_texture object.
1151 * Choose tex target, compute max tex size, etc.
1154 init_temp_texture(struct gl_context
*ctx
, struct temp_texture
*tex
)
1156 /* prefer texture rectangle */
1157 if (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
) {
1158 tex
->Target
= GL_TEXTURE_RECTANGLE
;
1159 tex
->MaxSize
= ctx
->Const
.MaxTextureRectSize
;
1160 tex
->NPOT
= GL_TRUE
;
1163 /* use 2D texture, NPOT if possible */
1164 tex
->Target
= GL_TEXTURE_2D
;
1165 tex
->MaxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1166 tex
->NPOT
= ctx
->Extensions
.ARB_texture_non_power_of_two
;
1168 tex
->MinSize
= 16; /* 16 x 16 at least */
1169 assert(tex
->MaxSize
> 0);
1171 _mesa_GenTextures(1, &tex
->TexObj
);
1175 cleanup_temp_texture(struct temp_texture
*tex
)
1179 _mesa_DeleteTextures(1, &tex
->TexObj
);
1185 * Return pointer to temp_texture info for non-bitmap ops.
1186 * This does some one-time init if needed.
1188 struct temp_texture
*
1189 _mesa_meta_get_temp_texture(struct gl_context
*ctx
)
1191 struct temp_texture
*tex
= &ctx
->Meta
->TempTex
;
1194 init_temp_texture(ctx
, tex
);
1202 * Return pointer to temp_texture info for _mesa_meta_bitmap().
1203 * We use a separate texture for bitmaps to reduce texture
1204 * allocation/deallocation.
1206 static struct temp_texture
*
1207 get_bitmap_temp_texture(struct gl_context
*ctx
)
1209 struct temp_texture
*tex
= &ctx
->Meta
->Bitmap
.Tex
;
1212 init_temp_texture(ctx
, tex
);
1219 * Return pointer to depth temp_texture.
1220 * This does some one-time init if needed.
1222 struct temp_texture
*
1223 _mesa_meta_get_temp_depth_texture(struct gl_context
*ctx
)
1225 struct temp_texture
*tex
= &ctx
->Meta
->Blit
.depthTex
;
1228 init_temp_texture(ctx
, tex
);
1235 * Compute the width/height of texture needed to draw an image of the
1236 * given size. Return a flag indicating whether the current texture
1237 * can be re-used (glTexSubImage2D) or if a new texture needs to be
1238 * allocated (glTexImage2D).
1239 * Also, compute s/t texcoords for drawing.
1241 * \return GL_TRUE if new texture is needed, GL_FALSE otherwise
1244 _mesa_meta_alloc_texture(struct temp_texture
*tex
,
1245 GLsizei width
, GLsizei height
, GLenum intFormat
)
1247 GLboolean newTex
= GL_FALSE
;
1249 ASSERT(width
<= tex
->MaxSize
);
1250 ASSERT(height
<= tex
->MaxSize
);
1252 if (width
> tex
->Width
||
1253 height
> tex
->Height
||
1254 intFormat
!= tex
->IntFormat
) {
1255 /* alloc new texture (larger or different format) */
1258 /* use non-power of two size */
1259 tex
->Width
= MAX2(tex
->MinSize
, width
);
1260 tex
->Height
= MAX2(tex
->MinSize
, height
);
1263 /* find power of two size */
1265 w
= h
= tex
->MinSize
;
1274 tex
->IntFormat
= intFormat
;
1279 /* compute texcoords */
1280 if (tex
->Target
== GL_TEXTURE_RECTANGLE
) {
1281 tex
->Sright
= (GLfloat
) width
;
1282 tex
->Ttop
= (GLfloat
) height
;
1285 tex
->Sright
= (GLfloat
) width
/ tex
->Width
;
1286 tex
->Ttop
= (GLfloat
) height
/ tex
->Height
;
1294 * Setup/load texture for glCopyPixels or glBlitFramebuffer.
1297 _mesa_meta_setup_copypix_texture(struct gl_context
*ctx
,
1298 struct temp_texture
*tex
,
1299 GLint srcX
, GLint srcY
,
1300 GLsizei width
, GLsizei height
,
1306 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
1307 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, filter
);
1308 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, filter
);
1309 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
1311 newTex
= _mesa_meta_alloc_texture(tex
, width
, height
, intFormat
);
1313 /* copy framebuffer image to texture */
1315 /* create new tex image */
1316 if (tex
->Width
== width
&& tex
->Height
== height
) {
1317 /* create new tex with framebuffer data */
1318 _mesa_CopyTexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1319 srcX
, srcY
, width
, height
, 0);
1322 /* create empty texture */
1323 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1324 tex
->Width
, tex
->Height
, 0,
1325 intFormat
, GL_UNSIGNED_BYTE
, NULL
);
1327 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
1328 0, 0, srcX
, srcY
, width
, height
);
1332 /* replace existing tex image */
1333 _mesa_CopyTexSubImage2D(tex
->Target
, 0,
1334 0, 0, srcX
, srcY
, width
, height
);
1340 * Setup/load texture for glDrawPixels.
1343 _mesa_meta_setup_drawpix_texture(struct gl_context
*ctx
,
1344 struct temp_texture
*tex
,
1346 GLsizei width
, GLsizei height
,
1347 GLenum format
, GLenum type
,
1348 const GLvoid
*pixels
)
1350 _mesa_BindTexture(tex
->Target
, tex
->TexObj
);
1351 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1352 _mesa_TexParameteri(tex
->Target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1353 _mesa_TexEnvi(GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_REPLACE
);
1355 /* copy pixel data to texture */
1357 /* create new tex image */
1358 if (tex
->Width
== width
&& tex
->Height
== height
) {
1359 /* create new tex and load image data */
1360 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1361 tex
->Width
, tex
->Height
, 0, format
, type
, pixels
);
1364 struct gl_buffer_object
*save_unpack_obj
= NULL
;
1366 _mesa_reference_buffer_object(ctx
, &save_unpack_obj
,
1367 ctx
->Unpack
.BufferObj
);
1368 _mesa_BindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB
, 0);
1369 /* create empty texture */
1370 _mesa_TexImage2D(tex
->Target
, 0, tex
->IntFormat
,
1371 tex
->Width
, tex
->Height
, 0, format
, type
, NULL
);
1372 if (save_unpack_obj
!= NULL
)
1373 _mesa_BindBuffer(GL_PIXEL_UNPACK_BUFFER_ARB
,
1374 save_unpack_obj
->Name
);
1376 _mesa_TexSubImage2D(tex
->Target
, 0,
1377 0, 0, width
, height
, format
, type
, pixels
);
1381 /* replace existing tex image */
1382 _mesa_TexSubImage2D(tex
->Target
, 0,
1383 0, 0, width
, height
, format
, type
, pixels
);
1388 _mesa_meta_setup_ff_tnl_for_blit(GLuint
*VAO
, GLuint
*VBO
,
1389 unsigned texcoord_size
)
1391 _mesa_meta_setup_vertex_objects(VAO
, VBO
, false, 2, texcoord_size
, 0);
1393 /* setup projection matrix */
1394 _mesa_MatrixMode(GL_PROJECTION
);
1395 _mesa_LoadIdentity();
1399 * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
1402 _mesa_meta_Clear(struct gl_context
*ctx
, GLbitfield buffers
)
1404 struct clear_state
*clear
= &ctx
->Meta
->Clear
;
1405 struct vertex verts
[4];
1406 /* save all state but scissor, pixel pack/unpack */
1407 GLbitfield metaSave
= (MESA_META_ALL
-
1409 MESA_META_PIXEL_STORE
-
1410 MESA_META_CONDITIONAL_RENDER
-
1411 MESA_META_FRAMEBUFFER_SRGB
);
1412 const GLuint stencilMax
= (1 << ctx
->DrawBuffer
->Visual
.stencilBits
) - 1;
1414 if (buffers
& BUFFER_BITS_COLOR
) {
1415 /* if clearing color buffers, don't save/restore colormask */
1416 metaSave
-= MESA_META_COLOR_MASK
;
1419 _mesa_meta_begin(ctx
, metaSave
);
1421 _mesa_meta_setup_vertex_objects(&clear
->VAO
, &clear
->VBO
, false, 3, 0, 4);
1423 /* GL_COLOR_BUFFER_BIT */
1424 if (buffers
& BUFFER_BITS_COLOR
) {
1425 /* leave colormask, glDrawBuffer state as-is */
1427 /* Clears never have the color clamped. */
1428 if (ctx
->Extensions
.ARB_color_buffer_float
)
1429 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, GL_FALSE
);
1432 ASSERT(metaSave
& MESA_META_COLOR_MASK
);
1433 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1436 /* GL_DEPTH_BUFFER_BIT */
1437 if (buffers
& BUFFER_BIT_DEPTH
) {
1438 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1439 _mesa_DepthFunc(GL_ALWAYS
);
1440 _mesa_DepthMask(GL_TRUE
);
1443 assert(!ctx
->Depth
.Test
);
1446 /* GL_STENCIL_BUFFER_BIT */
1447 if (buffers
& BUFFER_BIT_STENCIL
) {
1448 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1449 _mesa_StencilOpSeparate(GL_FRONT_AND_BACK
,
1450 GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1451 _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK
, GL_ALWAYS
,
1452 ctx
->Stencil
.Clear
& stencilMax
,
1453 ctx
->Stencil
.WriteMask
[0]);
1456 assert(!ctx
->Stencil
.Enabled
);
1459 /* vertex positions/colors */
1461 const GLfloat x0
= (GLfloat
) ctx
->DrawBuffer
->_Xmin
;
1462 const GLfloat y0
= (GLfloat
) ctx
->DrawBuffer
->_Ymin
;
1463 const GLfloat x1
= (GLfloat
) ctx
->DrawBuffer
->_Xmax
;
1464 const GLfloat y1
= (GLfloat
) ctx
->DrawBuffer
->_Ymax
;
1465 const GLfloat z
= invert_z(ctx
->Depth
.Clear
);
1482 for (i
= 0; i
< 4; i
++) {
1483 verts
[i
].r
= ctx
->Color
.ClearColor
.f
[0];
1484 verts
[i
].g
= ctx
->Color
.ClearColor
.f
[1];
1485 verts
[i
].b
= ctx
->Color
.ClearColor
.f
[2];
1486 verts
[i
].a
= ctx
->Color
.ClearColor
.f
[3];
1489 /* upload new vertex data */
1490 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), verts
,
1491 GL_DYNAMIC_DRAW_ARB
);
1495 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1497 _mesa_meta_end(ctx
);
1501 meta_glsl_clear_init(struct gl_context
*ctx
, struct clear_state
*clear
)
1503 const char *vs_source
=
1504 "attribute vec4 position;\n"
1507 " gl_Position = position;\n"
1509 const char *gs_source
=
1511 "layout(triangles) in;\n"
1512 "layout(triangle_strip, max_vertices = 4) out;\n"
1513 "uniform int layer;\n"
1516 " for (int i = 0; i < 3; i++) {\n"
1517 " gl_Layer = layer;\n"
1518 " gl_Position = gl_in[i].gl_Position;\n"
1522 const char *fs_source
=
1523 "uniform vec4 color;\n"
1526 " gl_FragColor = color;\n"
1528 GLuint vs
, gs
= 0, fs
;
1529 bool has_integer_textures
;
1531 _mesa_meta_setup_vertex_objects(&clear
->VAO
, &clear
->VBO
, true, 3, 0, 0);
1533 if (clear
->ShaderProg
!= 0)
1536 vs
= _mesa_CreateShader(GL_VERTEX_SHADER
);
1537 _mesa_ShaderSource(vs
, 1, &vs_source
, NULL
);
1538 _mesa_CompileShader(vs
);
1540 if (_mesa_has_geometry_shaders(ctx
)) {
1541 gs
= _mesa_CreateShader(GL_GEOMETRY_SHADER
);
1542 _mesa_ShaderSource(gs
, 1, &gs_source
, NULL
);
1543 _mesa_CompileShader(gs
);
1546 fs
= _mesa_CreateShader(GL_FRAGMENT_SHADER
);
1547 _mesa_ShaderSource(fs
, 1, &fs_source
, NULL
);
1548 _mesa_CompileShader(fs
);
1550 clear
->ShaderProg
= _mesa_CreateProgram();
1551 _mesa_AttachShader(clear
->ShaderProg
, fs
);
1552 _mesa_DeleteShader(fs
);
1554 _mesa_AttachShader(clear
->ShaderProg
, gs
);
1555 _mesa_AttachShader(clear
->ShaderProg
, vs
);
1556 _mesa_DeleteShader(vs
);
1557 _mesa_BindAttribLocation(clear
->ShaderProg
, 0, "position");
1558 _mesa_LinkProgram(clear
->ShaderProg
);
1560 clear
->ColorLocation
= _mesa_GetUniformLocation(clear
->ShaderProg
,
1563 clear
->LayerLocation
= _mesa_GetUniformLocation(clear
->ShaderProg
,
1567 has_integer_textures
= _mesa_is_gles3(ctx
) ||
1568 (_mesa_is_desktop_gl(ctx
) && ctx
->Const
.GLSLVersion
>= 130);
1570 if (has_integer_textures
) {
1571 void *shader_source_mem_ctx
= ralloc_context(NULL
);
1572 const char *vs_int_source
=
1573 ralloc_asprintf(shader_source_mem_ctx
,
1575 "in vec4 position;\n"
1578 " gl_Position = position;\n"
1580 const char *fs_int_source
=
1581 ralloc_asprintf(shader_source_mem_ctx
,
1583 "uniform ivec4 color;\n"
1584 "out ivec4 out_color;\n"
1588 " out_color = color;\n"
1591 vs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_VERTEX_SHADER
,
1593 fs
= _mesa_meta_compile_shader_with_debug(ctx
, GL_FRAGMENT_SHADER
,
1595 ralloc_free(shader_source_mem_ctx
);
1597 clear
->IntegerShaderProg
= _mesa_CreateProgram();
1598 _mesa_AttachShader(clear
->IntegerShaderProg
, fs
);
1599 _mesa_DeleteShader(fs
);
1601 _mesa_AttachShader(clear
->IntegerShaderProg
, gs
);
1602 _mesa_AttachShader(clear
->IntegerShaderProg
, vs
);
1603 _mesa_DeleteShader(vs
);
1604 _mesa_BindAttribLocation(clear
->IntegerShaderProg
, 0, "position");
1606 /* Note that user-defined out attributes get automatically assigned
1607 * locations starting from 0, so we don't need to explicitly
1608 * BindFragDataLocation to 0.
1611 _mesa_ObjectLabel(GL_PROGRAM
, clear
->IntegerShaderProg
, -1,
1613 _mesa_meta_link_program_with_debug(ctx
, clear
->IntegerShaderProg
);
1615 clear
->IntegerColorLocation
=
1616 _mesa_GetUniformLocation(clear
->IntegerShaderProg
, "color");
1618 clear
->IntegerLayerLocation
=
1619 _mesa_GetUniformLocation(clear
->IntegerShaderProg
, "layer");
1623 _mesa_DeleteShader(gs
);
1627 meta_glsl_clear_cleanup(struct clear_state
*clear
)
1629 if (clear
->VAO
== 0)
1631 _mesa_DeleteVertexArrays(1, &clear
->VAO
);
1633 _mesa_DeleteBuffers(1, &clear
->VBO
);
1635 _mesa_DeleteProgram(clear
->ShaderProg
);
1636 clear
->ShaderProg
= 0;
1638 if (clear
->IntegerShaderProg
) {
1639 _mesa_DeleteProgram(clear
->IntegerShaderProg
);
1640 clear
->IntegerShaderProg
= 0;
1645 * Meta implementation of ctx->Driver.Clear() in terms of polygon rendering.
1648 _mesa_meta_glsl_Clear(struct gl_context
*ctx
, GLbitfield buffers
)
1650 struct clear_state
*clear
= &ctx
->Meta
->Clear
;
1651 GLbitfield metaSave
;
1652 const GLuint stencilMax
= (1 << ctx
->DrawBuffer
->Visual
.stencilBits
) - 1;
1653 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
1654 const float x0
= ((float)fb
->_Xmin
/ fb
->Width
) * 2.0f
- 1.0f
;
1655 const float y0
= ((float)fb
->_Ymin
/ fb
->Height
) * 2.0f
- 1.0f
;
1656 const float x1
= ((float)fb
->_Xmax
/ fb
->Width
) * 2.0f
- 1.0f
;
1657 const float y1
= ((float)fb
->_Ymax
/ fb
->Height
) * 2.0f
- 1.0f
;
1658 const float z
= -invert_z(ctx
->Depth
.Clear
);
1659 struct vertex verts
[4];
1661 metaSave
= (MESA_META_ALPHA_TEST
|
1663 MESA_META_DEPTH_TEST
|
1664 MESA_META_RASTERIZATION
|
1666 MESA_META_STENCIL_TEST
|
1668 MESA_META_VIEWPORT
|
1670 MESA_META_CLAMP_FRAGMENT_COLOR
|
1671 MESA_META_MULTISAMPLE
|
1672 MESA_META_OCCLUSION_QUERY
);
1674 if (!(buffers
& BUFFER_BITS_COLOR
)) {
1675 /* We'll use colormask to disable color writes. Otherwise,
1676 * respect color mask
1678 metaSave
|= MESA_META_COLOR_MASK
;
1681 _mesa_meta_begin(ctx
, metaSave
);
1683 meta_glsl_clear_init(ctx
, clear
);
1685 if (fb
->_IntegerColor
) {
1686 _mesa_UseProgram(clear
->IntegerShaderProg
);
1687 _mesa_Uniform4iv(clear
->IntegerColorLocation
, 1,
1688 ctx
->Color
.ClearColor
.i
);
1690 _mesa_UseProgram(clear
->ShaderProg
);
1691 _mesa_Uniform4fv(clear
->ColorLocation
, 1,
1692 ctx
->Color
.ClearColor
.f
);
1695 /* GL_COLOR_BUFFER_BIT */
1696 if (buffers
& BUFFER_BITS_COLOR
) {
1697 /* leave colormask, glDrawBuffer state as-is */
1699 /* Clears never have the color clamped. */
1700 if (ctx
->Extensions
.ARB_color_buffer_float
)
1701 _mesa_ClampColor(GL_CLAMP_FRAGMENT_COLOR
, GL_FALSE
);
1704 ASSERT(metaSave
& MESA_META_COLOR_MASK
);
1705 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
1708 /* GL_DEPTH_BUFFER_BIT */
1709 if (buffers
& BUFFER_BIT_DEPTH
) {
1710 _mesa_set_enable(ctx
, GL_DEPTH_TEST
, GL_TRUE
);
1711 _mesa_DepthFunc(GL_ALWAYS
);
1712 _mesa_DepthMask(GL_TRUE
);
1715 assert(!ctx
->Depth
.Test
);
1718 /* GL_STENCIL_BUFFER_BIT */
1719 if (buffers
& BUFFER_BIT_STENCIL
) {
1720 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
1721 _mesa_StencilOpSeparate(GL_FRONT_AND_BACK
,
1722 GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
1723 _mesa_StencilFuncSeparate(GL_FRONT_AND_BACK
, GL_ALWAYS
,
1724 ctx
->Stencil
.Clear
& stencilMax
,
1725 ctx
->Stencil
.WriteMask
[0]);
1728 assert(!ctx
->Stencil
.Enabled
);
1731 /* vertex positions */
1745 /* upload new vertex data */
1746 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
), verts
,
1747 GL_DYNAMIC_DRAW_ARB
);
1750 if (fb
->MaxNumLayers
> 0) {
1752 for (layer
= 0; layer
< fb
->MaxNumLayers
; layer
++) {
1753 if (fb
->_IntegerColor
)
1754 _mesa_Uniform1i(clear
->IntegerLayerLocation
, layer
);
1756 _mesa_Uniform1i(clear
->LayerLocation
, layer
);
1757 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1760 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1763 _mesa_meta_end(ctx
);
1767 * Meta implementation of ctx->Driver.CopyPixels() in terms
1768 * of texture mapping and polygon rendering and GLSL shaders.
1771 _mesa_meta_CopyPixels(struct gl_context
*ctx
, GLint srcX
, GLint srcY
,
1772 GLsizei width
, GLsizei height
,
1773 GLint dstX
, GLint dstY
, GLenum type
)
1775 struct copypix_state
*copypix
= &ctx
->Meta
->CopyPix
;
1776 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
1777 struct vertex verts
[4];
1779 if (type
!= GL_COLOR
||
1780 ctx
->_ImageTransferState
||
1782 width
> tex
->MaxSize
||
1783 height
> tex
->MaxSize
) {
1784 /* XXX avoid this fallback */
1785 _swrast_CopyPixels(ctx
, srcX
, srcY
, width
, height
, dstX
, dstY
, type
);
1789 /* Most GL state applies to glCopyPixels, but a there's a few things
1790 * we need to override:
1792 _mesa_meta_begin(ctx
, (MESA_META_RASTERIZATION
|
1795 MESA_META_TRANSFORM
|
1798 MESA_META_VIEWPORT
));
1800 _mesa_meta_setup_vertex_objects(©pix
->VAO
, ©pix
->VBO
, false,
1803 /* Silence valgrind warnings about reading uninitialized stack. */
1804 memset(verts
, 0, sizeof(verts
));
1806 /* Alloc/setup texture */
1807 _mesa_meta_setup_copypix_texture(ctx
, tex
, srcX
, srcY
, width
, height
,
1808 GL_RGBA
, GL_NEAREST
);
1810 /* vertex positions, texcoords (after texture allocation!) */
1812 const GLfloat dstX0
= (GLfloat
) dstX
;
1813 const GLfloat dstY0
= (GLfloat
) dstY
;
1814 const GLfloat dstX1
= dstX
+ width
* ctx
->Pixel
.ZoomX
;
1815 const GLfloat dstY1
= dstY
+ height
* ctx
->Pixel
.ZoomY
;
1816 const GLfloat z
= invert_z(ctx
->Current
.RasterPos
[2]);
1821 verts
[0].tex
[0] = 0.0F
;
1822 verts
[0].tex
[1] = 0.0F
;
1826 verts
[1].tex
[0] = tex
->Sright
;
1827 verts
[1].tex
[1] = 0.0F
;
1831 verts
[2].tex
[0] = tex
->Sright
;
1832 verts
[2].tex
[1] = tex
->Ttop
;
1836 verts
[3].tex
[0] = 0.0F
;
1837 verts
[3].tex
[1] = tex
->Ttop
;
1839 /* upload new vertex data */
1840 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
1843 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
1845 /* draw textured quad */
1846 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
1848 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
1850 _mesa_meta_end(ctx
);
1854 meta_drawpix_cleanup(struct drawpix_state
*drawpix
)
1856 if (drawpix
->VAO
!= 0) {
1857 _mesa_DeleteVertexArrays(1, &drawpix
->VAO
);
1860 _mesa_DeleteBuffers(1, &drawpix
->VBO
);
1864 if (drawpix
->StencilFP
!= 0) {
1865 _mesa_DeleteProgramsARB(1, &drawpix
->StencilFP
);
1866 drawpix
->StencilFP
= 0;
1869 if (drawpix
->DepthFP
!= 0) {
1870 _mesa_DeleteProgramsARB(1, &drawpix
->DepthFP
);
1871 drawpix
->DepthFP
= 0;
1876 * When the glDrawPixels() image size is greater than the max rectangle
1877 * texture size we use this function to break the glDrawPixels() image
1878 * into tiles which fit into the max texture size.
1881 tiled_draw_pixels(struct gl_context
*ctx
,
1883 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1884 GLenum format
, GLenum type
,
1885 const struct gl_pixelstore_attrib
*unpack
,
1886 const GLvoid
*pixels
)
1888 struct gl_pixelstore_attrib tileUnpack
= *unpack
;
1891 if (tileUnpack
.RowLength
== 0)
1892 tileUnpack
.RowLength
= width
;
1894 for (i
= 0; i
< width
; i
+= tileSize
) {
1895 const GLint tileWidth
= MIN2(tileSize
, width
- i
);
1896 const GLint tileX
= (GLint
) (x
+ i
* ctx
->Pixel
.ZoomX
);
1898 tileUnpack
.SkipPixels
= unpack
->SkipPixels
+ i
;
1900 for (j
= 0; j
< height
; j
+= tileSize
) {
1901 const GLint tileHeight
= MIN2(tileSize
, height
- j
);
1902 const GLint tileY
= (GLint
) (y
+ j
* ctx
->Pixel
.ZoomY
);
1904 tileUnpack
.SkipRows
= unpack
->SkipRows
+ j
;
1906 _mesa_meta_DrawPixels(ctx
, tileX
, tileY
, tileWidth
, tileHeight
,
1907 format
, type
, &tileUnpack
, pixels
);
1914 * One-time init for drawing stencil pixels.
1917 init_draw_stencil_pixels(struct gl_context
*ctx
)
1919 /* This program is run eight times, once for each stencil bit.
1920 * The stencil values to draw are found in an 8-bit alpha texture.
1921 * We read the texture/stencil value and test if bit 'b' is set.
1922 * If the bit is not set, use KIL to kill the fragment.
1923 * Finally, we use the stencil test to update the stencil buffer.
1925 * The basic algorithm for checking if a bit is set is:
1926 * if (is_odd(value / (1 << bit)))
1927 * result is one (or non-zero).
1930 * The program parameter contains three values:
1931 * parm.x = 255 / (1 << bit)
1935 static const char *program
=
1937 "PARAM parm = program.local[0]; \n"
1939 "TEX t, fragment.texcoord[0], texture[0], %s; \n" /* NOTE %s here! */
1940 "# t = t * 255 / bit \n"
1941 "MUL t.x, t.a, parm.x; \n"
1944 "SUB t.x, t.x, t.y; \n"
1946 "MUL t.x, t.x, parm.y; \n"
1947 "# t = fract(t.x) \n"
1948 "FRC t.x, t.x; # if t.x != 0, then the bit is set \n"
1949 "# t.x = (t.x == 0 ? 1 : 0) \n"
1950 "SGE t.x, -t.x, parm.z; \n"
1952 "# for debug only \n"
1953 "#MOV result.color, t.x; \n"
1955 char program2
[1000];
1956 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1957 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
1958 const char *texTarget
;
1960 assert(drawpix
->StencilFP
== 0);
1962 /* replace %s with "RECT" or "2D" */
1963 assert(strlen(program
) + 4 < sizeof(program2
));
1964 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
1968 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
1970 _mesa_GenProgramsARB(1, &drawpix
->StencilFP
);
1971 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
1972 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
1973 strlen(program2
), (const GLubyte
*) program2
);
1978 * One-time init for drawing depth pixels.
1981 init_draw_depth_pixels(struct gl_context
*ctx
)
1983 static const char *program
=
1985 "PARAM color = program.local[0]; \n"
1986 "TEX result.depth, fragment.texcoord[0], texture[0], %s; \n"
1987 "MOV result.color, color; \n"
1990 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
1991 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
1992 const char *texTarget
;
1994 assert(drawpix
->DepthFP
== 0);
1996 /* replace %s with "RECT" or "2D" */
1997 assert(strlen(program
) + 4 < sizeof(program2
));
1998 if (tex
->Target
== GL_TEXTURE_RECTANGLE
)
2002 _mesa_snprintf(program2
, sizeof(program2
), program
, texTarget
);
2004 _mesa_GenProgramsARB(1, &drawpix
->DepthFP
);
2005 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
2006 _mesa_ProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
2007 strlen(program2
), (const GLubyte
*) program2
);
2012 * Meta implementation of ctx->Driver.DrawPixels() in terms
2013 * of texture mapping and polygon rendering.
2016 _mesa_meta_DrawPixels(struct gl_context
*ctx
,
2017 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2018 GLenum format
, GLenum type
,
2019 const struct gl_pixelstore_attrib
*unpack
,
2020 const GLvoid
*pixels
)
2022 struct drawpix_state
*drawpix
= &ctx
->Meta
->DrawPix
;
2023 struct temp_texture
*tex
= _mesa_meta_get_temp_texture(ctx
);
2024 const struct gl_pixelstore_attrib unpackSave
= ctx
->Unpack
;
2025 const GLuint origStencilMask
= ctx
->Stencil
.WriteMask
[0];
2026 struct vertex verts
[4];
2027 GLenum texIntFormat
;
2028 GLboolean fallback
, newTex
;
2029 GLbitfield metaExtraSave
= 0x0;
2032 * Determine if we can do the glDrawPixels with texture mapping.
2034 fallback
= GL_FALSE
;
2035 if (ctx
->Fog
.Enabled
) {
2039 if (_mesa_is_color_format(format
)) {
2040 /* use more compact format when possible */
2041 /* XXX disable special case for GL_LUMINANCE for now to work around
2042 * apparent i965 driver bug (see bug #23670).
2044 if (/*format == GL_LUMINANCE ||*/ format
== GL_LUMINANCE_ALPHA
)
2045 texIntFormat
= format
;
2047 texIntFormat
= GL_RGBA
;
2049 /* If we're not supposed to clamp the resulting color, then just
2050 * promote our texture to fully float. We could do better by
2051 * just going for the matching set of channels, in floating
2054 if (ctx
->Color
.ClampFragmentColor
!= GL_TRUE
&&
2055 ctx
->Extensions
.ARB_texture_float
)
2056 texIntFormat
= GL_RGBA32F
;
2058 else if (_mesa_is_stencil_format(format
)) {
2059 if (ctx
->Extensions
.ARB_fragment_program
&&
2060 ctx
->Pixel
.IndexShift
== 0 &&
2061 ctx
->Pixel
.IndexOffset
== 0 &&
2062 type
== GL_UNSIGNED_BYTE
) {
2063 /* We'll store stencil as alpha. This only works for GLubyte
2064 * image data because of how incoming values are mapped to alpha
2067 texIntFormat
= GL_ALPHA
;
2068 metaExtraSave
= (MESA_META_COLOR_MASK
|
2069 MESA_META_DEPTH_TEST
|
2070 MESA_META_PIXEL_TRANSFER
|
2072 MESA_META_STENCIL_TEST
);
2078 else if (_mesa_is_depth_format(format
)) {
2079 if (ctx
->Extensions
.ARB_depth_texture
&&
2080 ctx
->Extensions
.ARB_fragment_program
) {
2081 texIntFormat
= GL_DEPTH_COMPONENT
;
2082 metaExtraSave
= (MESA_META_SHADER
);
2093 _swrast_DrawPixels(ctx
, x
, y
, width
, height
,
2094 format
, type
, unpack
, pixels
);
2099 * Check image size against max texture size, draw as tiles if needed.
2101 if (width
> tex
->MaxSize
|| height
> tex
->MaxSize
) {
2102 tiled_draw_pixels(ctx
, tex
->MaxSize
, x
, y
, width
, height
,
2103 format
, type
, unpack
, pixels
);
2107 /* Most GL state applies to glDrawPixels (like blending, stencil, etc),
2108 * but a there's a few things we need to override:
2110 _mesa_meta_begin(ctx
, (MESA_META_RASTERIZATION
|
2113 MESA_META_TRANSFORM
|
2116 MESA_META_VIEWPORT
|
2119 newTex
= _mesa_meta_alloc_texture(tex
, width
, height
, texIntFormat
);
2121 _mesa_meta_setup_vertex_objects(&drawpix
->VAO
, &drawpix
->VBO
, false,
2124 /* Silence valgrind warnings about reading uninitialized stack. */
2125 memset(verts
, 0, sizeof(verts
));
2127 /* vertex positions, texcoords (after texture allocation!) */
2129 const GLfloat x0
= (GLfloat
) x
;
2130 const GLfloat y0
= (GLfloat
) y
;
2131 const GLfloat x1
= x
+ width
* ctx
->Pixel
.ZoomX
;
2132 const GLfloat y1
= y
+ height
* ctx
->Pixel
.ZoomY
;
2133 const GLfloat z
= invert_z(ctx
->Current
.RasterPos
[2]);
2138 verts
[0].tex
[0] = 0.0F
;
2139 verts
[0].tex
[1] = 0.0F
;
2143 verts
[1].tex
[0] = tex
->Sright
;
2144 verts
[1].tex
[1] = 0.0F
;
2148 verts
[2].tex
[0] = tex
->Sright
;
2149 verts
[2].tex
[1] = tex
->Ttop
;
2153 verts
[3].tex
[0] = 0.0F
;
2154 verts
[3].tex
[1] = tex
->Ttop
;
2157 /* upload new vertex data */
2158 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
2159 verts
, GL_DYNAMIC_DRAW_ARB
);
2161 /* set given unpack params */
2162 ctx
->Unpack
= *unpack
;
2164 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
2166 if (_mesa_is_stencil_format(format
)) {
2167 /* Drawing stencil */
2170 if (!drawpix
->StencilFP
)
2171 init_draw_stencil_pixels(ctx
);
2173 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2174 GL_ALPHA
, type
, pixels
);
2176 _mesa_ColorMask(GL_FALSE
, GL_FALSE
, GL_FALSE
, GL_FALSE
);
2178 _mesa_set_enable(ctx
, GL_STENCIL_TEST
, GL_TRUE
);
2180 /* set all stencil bits to 0 */
2181 _mesa_StencilOp(GL_REPLACE
, GL_REPLACE
, GL_REPLACE
);
2182 _mesa_StencilFunc(GL_ALWAYS
, 0, 255);
2183 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2185 /* set stencil bits to 1 where needed */
2186 _mesa_StencilOp(GL_KEEP
, GL_KEEP
, GL_REPLACE
);
2188 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->StencilFP
);
2189 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
2191 for (bit
= 0; bit
< ctx
->DrawBuffer
->Visual
.stencilBits
; bit
++) {
2192 const GLuint mask
= 1 << bit
;
2193 if (mask
& origStencilMask
) {
2194 _mesa_StencilFunc(GL_ALWAYS
, mask
, mask
);
2195 _mesa_StencilMask(mask
);
2197 _mesa_ProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
2198 255.0f
/ mask
, 0.5f
, 0.0f
, 0.0f
);
2200 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2204 else if (_mesa_is_depth_format(format
)) {
2206 if (!drawpix
->DepthFP
)
2207 init_draw_depth_pixels(ctx
);
2209 _mesa_BindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, drawpix
->DepthFP
);
2210 _mesa_set_enable(ctx
, GL_FRAGMENT_PROGRAM_ARB
, GL_TRUE
);
2212 /* polygon color = current raster color */
2213 _mesa_ProgramLocalParameter4fvARB(GL_FRAGMENT_PROGRAM_ARB
, 0,
2214 ctx
->Current
.RasterColor
);
2216 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2217 format
, type
, pixels
);
2219 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2223 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2224 format
, type
, pixels
);
2225 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2228 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
2230 /* restore unpack params */
2231 ctx
->Unpack
= unpackSave
;
2233 _mesa_meta_end(ctx
);
2237 alpha_test_raster_color(struct gl_context
*ctx
)
2239 GLfloat alpha
= ctx
->Current
.RasterColor
[ACOMP
];
2240 GLfloat ref
= ctx
->Color
.AlphaRef
;
2242 switch (ctx
->Color
.AlphaFunc
) {
2248 return alpha
== ref
;
2250 return alpha
<= ref
;
2254 return alpha
!= ref
;
2256 return alpha
>= ref
;
2266 * Do glBitmap with a alpha texture quad. Use the alpha test to cull
2267 * the 'off' bits. A bitmap cache as in the gallium/mesa state
2268 * tracker would improve performance a lot.
2271 _mesa_meta_Bitmap(struct gl_context
*ctx
,
2272 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2273 const struct gl_pixelstore_attrib
*unpack
,
2274 const GLubyte
*bitmap1
)
2276 struct bitmap_state
*bitmap
= &ctx
->Meta
->Bitmap
;
2277 struct temp_texture
*tex
= get_bitmap_temp_texture(ctx
);
2278 const GLenum texIntFormat
= GL_ALPHA
;
2279 const struct gl_pixelstore_attrib unpackSave
= *unpack
;
2281 struct vertex verts
[4];
2286 * Check if swrast fallback is needed.
2288 if (ctx
->_ImageTransferState
||
2289 ctx
->FragmentProgram
._Enabled
||
2291 ctx
->Texture
._EnabledUnits
||
2292 width
> tex
->MaxSize
||
2293 height
> tex
->MaxSize
) {
2294 _swrast_Bitmap(ctx
, x
, y
, width
, height
, unpack
, bitmap1
);
2298 if (ctx
->Color
.AlphaEnabled
&& !alpha_test_raster_color(ctx
))
2301 /* Most GL state applies to glBitmap (like blending, stencil, etc),
2302 * but a there's a few things we need to override:
2304 _mesa_meta_begin(ctx
, (MESA_META_ALPHA_TEST
|
2305 MESA_META_PIXEL_STORE
|
2306 MESA_META_RASTERIZATION
|
2309 MESA_META_TRANSFORM
|
2312 MESA_META_VIEWPORT
));
2314 _mesa_meta_setup_vertex_objects(&bitmap
->VAO
, &bitmap
->VBO
, false, 3, 2, 4);
2316 newTex
= _mesa_meta_alloc_texture(tex
, width
, height
, texIntFormat
);
2318 /* Silence valgrind warnings about reading uninitialized stack. */
2319 memset(verts
, 0, sizeof(verts
));
2321 /* vertex positions, texcoords, colors (after texture allocation!) */
2323 const GLfloat x0
= (GLfloat
) x
;
2324 const GLfloat y0
= (GLfloat
) y
;
2325 const GLfloat x1
= (GLfloat
) (x
+ width
);
2326 const GLfloat y1
= (GLfloat
) (y
+ height
);
2327 const GLfloat z
= invert_z(ctx
->Current
.RasterPos
[2]);
2333 verts
[0].tex
[0] = 0.0F
;
2334 verts
[0].tex
[1] = 0.0F
;
2338 verts
[1].tex
[0] = tex
->Sright
;
2339 verts
[1].tex
[1] = 0.0F
;
2343 verts
[2].tex
[0] = tex
->Sright
;
2344 verts
[2].tex
[1] = tex
->Ttop
;
2348 verts
[3].tex
[0] = 0.0F
;
2349 verts
[3].tex
[1] = tex
->Ttop
;
2351 for (i
= 0; i
< 4; i
++) {
2352 verts
[i
].r
= ctx
->Current
.RasterColor
[0];
2353 verts
[i
].g
= ctx
->Current
.RasterColor
[1];
2354 verts
[i
].b
= ctx
->Current
.RasterColor
[2];
2355 verts
[i
].a
= ctx
->Current
.RasterColor
[3];
2358 /* upload new vertex data */
2359 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
2362 /* choose different foreground/background alpha values */
2363 CLAMPED_FLOAT_TO_UBYTE(fg
, ctx
->Current
.RasterColor
[ACOMP
]);
2364 bg
= (fg
> 127 ? 0 : 255);
2366 bitmap1
= _mesa_map_pbo_source(ctx
, &unpackSave
, bitmap1
);
2368 _mesa_meta_end(ctx
);
2372 bitmap8
= malloc(width
* height
);
2374 memset(bitmap8
, bg
, width
* height
);
2375 _mesa_expand_bitmap(width
, height
, &unpackSave
, bitmap1
,
2376 bitmap8
, width
, fg
);
2378 _mesa_set_enable(ctx
, tex
->Target
, GL_TRUE
);
2380 _mesa_set_enable(ctx
, GL_ALPHA_TEST
, GL_TRUE
);
2381 _mesa_AlphaFunc(GL_NOTEQUAL
, UBYTE_TO_FLOAT(bg
));
2383 _mesa_meta_setup_drawpix_texture(ctx
, tex
, newTex
, width
, height
,
2384 GL_ALPHA
, GL_UNSIGNED_BYTE
, bitmap8
);
2386 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2388 _mesa_set_enable(ctx
, tex
->Target
, GL_FALSE
);
2393 _mesa_unmap_pbo_source(ctx
, &unpackSave
);
2395 _mesa_meta_end(ctx
);
2399 * Compute the texture coordinates for the four vertices of a quad for
2400 * drawing a 2D texture image or slice of a cube/3D texture.
2401 * \param faceTarget GL_TEXTURE_1D/2D/3D or cube face name
2402 * \param slice slice of a 1D/2D array texture or 3D texture
2403 * \param width width of the texture image
2404 * \param height height of the texture image
2405 * \param coords0/1/2/3 returns the computed texcoords
2408 _mesa_meta_setup_texture_coords(GLenum faceTarget
,
2418 static const GLfloat st
[4][2] = {
2419 {0.0f
, 0.0f
}, {1.0f
, 0.0f
}, {1.0f
, 1.0f
}, {0.0f
, 1.0f
}
2424 /* Currently all texture targets want the W component to be 1.0.
2431 switch (faceTarget
) {
2435 case GL_TEXTURE_2D_ARRAY
:
2436 if (faceTarget
== GL_TEXTURE_3D
) {
2437 assert(slice
< depth
);
2439 r
= (slice
+ 0.5f
) / depth
;
2441 else if (faceTarget
== GL_TEXTURE_2D_ARRAY
)
2445 coords0
[0] = 0.0F
; /* s */
2446 coords0
[1] = 0.0F
; /* t */
2447 coords0
[2] = r
; /* r */
2458 case GL_TEXTURE_RECTANGLE_ARB
:
2459 coords0
[0] = 0.0F
; /* s */
2460 coords0
[1] = 0.0F
; /* t */
2461 coords0
[2] = 0.0F
; /* r */
2462 coords1
[0] = (float) width
;
2465 coords2
[0] = (float) width
;
2466 coords2
[1] = (float) height
;
2469 coords3
[1] = (float) height
;
2472 case GL_TEXTURE_1D_ARRAY
:
2473 coords0
[0] = 0.0F
; /* s */
2474 coords0
[1] = (float) slice
; /* t */
2475 coords0
[2] = 0.0F
; /* r */
2477 coords1
[1] = (float) slice
;
2480 coords2
[1] = (float) slice
;
2483 coords3
[1] = (float) slice
;
2487 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2488 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2489 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2490 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2491 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2492 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2493 /* loop over quad verts */
2494 for (i
= 0; i
< 4; i
++) {
2495 /* Compute sc = +/-scale and tc = +/-scale.
2496 * Not +/-1 to avoid cube face selection ambiguity near the edges,
2497 * though that can still sometimes happen with this scale factor...
2499 const GLfloat scale
= 0.9999f
;
2500 const GLfloat sc
= (2.0f
* st
[i
][0] - 1.0f
) * scale
;
2501 const GLfloat tc
= (2.0f
* st
[i
][1] - 1.0f
) * scale
;
2521 coord
[3] = (float) (slice
/ 6);
2523 switch (faceTarget
) {
2524 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2534 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2539 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2544 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2549 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2560 assert(!"unexpected target in _mesa_meta_setup_texture_coords()");
2564 static struct blit_shader
*
2565 choose_blit_shader(GLenum target
, struct blit_shader_table
*table
)
2569 table
->sampler_1d
.type
= "sampler1D";
2570 table
->sampler_1d
.func
= "texture1D";
2571 table
->sampler_1d
.texcoords
= "texCoords.x";
2572 return &table
->sampler_1d
;
2574 table
->sampler_2d
.type
= "sampler2D";
2575 table
->sampler_2d
.func
= "texture2D";
2576 table
->sampler_2d
.texcoords
= "texCoords.xy";
2577 return &table
->sampler_2d
;
2578 case GL_TEXTURE_RECTANGLE
:
2579 table
->sampler_rect
.type
= "sampler2DRect";
2580 table
->sampler_rect
.func
= "texture2DRect";
2581 table
->sampler_rect
.texcoords
= "texCoords.xy";
2582 return &table
->sampler_rect
;
2584 /* Code for mipmap generation with 3D textures is not used yet.
2585 * It's a sw fallback.
2587 table
->sampler_3d
.type
= "sampler3D";
2588 table
->sampler_3d
.func
= "texture3D";
2589 table
->sampler_3d
.texcoords
= "texCoords.xyz";
2590 return &table
->sampler_3d
;
2591 case GL_TEXTURE_CUBE_MAP
:
2592 table
->sampler_cubemap
.type
= "samplerCube";
2593 table
->sampler_cubemap
.func
= "textureCube";
2594 table
->sampler_cubemap
.texcoords
= "texCoords.xyz";
2595 return &table
->sampler_cubemap
;
2596 case GL_TEXTURE_1D_ARRAY
:
2597 table
->sampler_1d_array
.type
= "sampler1DArray";
2598 table
->sampler_1d_array
.func
= "texture1DArray";
2599 table
->sampler_1d_array
.texcoords
= "texCoords.xy";
2600 return &table
->sampler_1d_array
;
2601 case GL_TEXTURE_2D_ARRAY
:
2602 table
->sampler_2d_array
.type
= "sampler2DArray";
2603 table
->sampler_2d_array
.func
= "texture2DArray";
2604 table
->sampler_2d_array
.texcoords
= "texCoords.xyz";
2605 return &table
->sampler_2d_array
;
2606 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2607 table
->sampler_cubemap_array
.type
= "samplerCubeArray";
2608 table
->sampler_cubemap_array
.func
= "textureCubeArray";
2609 table
->sampler_cubemap_array
.texcoords
= "texCoords.xyzw";
2610 return &table
->sampler_cubemap_array
;
2612 _mesa_problem(NULL
, "Unexpected texture target 0x%x in"
2613 " setup_texture_sampler()\n", target
);
2619 _mesa_meta_blit_shader_table_cleanup(struct blit_shader_table
*table
)
2621 _mesa_DeleteProgram(table
->sampler_1d
.shader_prog
);
2622 _mesa_DeleteProgram(table
->sampler_2d
.shader_prog
);
2623 _mesa_DeleteProgram(table
->sampler_3d
.shader_prog
);
2624 _mesa_DeleteProgram(table
->sampler_rect
.shader_prog
);
2625 _mesa_DeleteProgram(table
->sampler_cubemap
.shader_prog
);
2626 _mesa_DeleteProgram(table
->sampler_1d_array
.shader_prog
);
2627 _mesa_DeleteProgram(table
->sampler_2d_array
.shader_prog
);
2628 _mesa_DeleteProgram(table
->sampler_cubemap_array
.shader_prog
);
2630 table
->sampler_1d
.shader_prog
= 0;
2631 table
->sampler_2d
.shader_prog
= 0;
2632 table
->sampler_3d
.shader_prog
= 0;
2633 table
->sampler_rect
.shader_prog
= 0;
2634 table
->sampler_cubemap
.shader_prog
= 0;
2635 table
->sampler_1d_array
.shader_prog
= 0;
2636 table
->sampler_2d_array
.shader_prog
= 0;
2637 table
->sampler_cubemap_array
.shader_prog
= 0;
2641 * Determine the GL data type to use for the temporary image read with
2642 * ReadPixels() and passed to Tex[Sub]Image().
2645 get_temp_image_type(struct gl_context
*ctx
, mesa_format format
)
2649 baseFormat
= _mesa_get_format_base_format(format
);
2651 switch (baseFormat
) {
2658 case GL_LUMINANCE_ALPHA
:
2660 if (ctx
->DrawBuffer
->Visual
.redBits
<= 8) {
2661 return GL_UNSIGNED_BYTE
;
2662 } else if (ctx
->DrawBuffer
->Visual
.redBits
<= 16) {
2663 return GL_UNSIGNED_SHORT
;
2665 GLenum datatype
= _mesa_get_format_datatype(format
);
2666 if (datatype
== GL_INT
|| datatype
== GL_UNSIGNED_INT
)
2670 case GL_DEPTH_COMPONENT
: {
2671 GLenum datatype
= _mesa_get_format_datatype(format
);
2672 if (datatype
== GL_FLOAT
)
2675 return GL_UNSIGNED_INT
;
2677 case GL_DEPTH_STENCIL
: {
2678 GLenum datatype
= _mesa_get_format_datatype(format
);
2679 if (datatype
== GL_FLOAT
)
2680 return GL_FLOAT_32_UNSIGNED_INT_24_8_REV
;
2682 return GL_UNSIGNED_INT_24_8
;
2685 _mesa_problem(ctx
, "Unexpected format %d in get_temp_image_type()",
2692 * Helper for _mesa_meta_CopyTexSubImage1/2/3D() functions.
2693 * Have to be careful with locking and meta state for pixel transfer.
2696 _mesa_meta_CopyTexSubImage(struct gl_context
*ctx
, GLuint dims
,
2697 struct gl_texture_image
*texImage
,
2698 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2699 struct gl_renderbuffer
*rb
,
2701 GLsizei width
, GLsizei height
)
2703 struct gl_texture_object
*texObj
= texImage
->TexObject
;
2704 GLenum format
, type
;
2708 /* The gl_renderbuffer is part of the interface for
2709 * dd_function_table::CopyTexSubImage, but this implementation does not use
2714 /* Choose format/type for temporary image buffer */
2715 format
= _mesa_get_format_base_format(texImage
->TexFormat
);
2716 if (format
== GL_LUMINANCE
||
2717 format
== GL_LUMINANCE_ALPHA
||
2718 format
== GL_INTENSITY
) {
2719 /* We don't want to use GL_LUMINANCE, GL_INTENSITY, etc. for the
2720 * temp image buffer because glReadPixels will do L=R+G+B which is
2721 * not what we want (should be L=R).
2726 type
= get_temp_image_type(ctx
, texImage
->TexFormat
);
2727 if (_mesa_is_format_integer_color(texImage
->TexFormat
)) {
2728 format
= _mesa_base_format_to_integer_format(format
);
2730 bpp
= _mesa_bytes_per_pixel(format
, type
);
2732 _mesa_problem(ctx
, "Bad bpp in _mesa_meta_CopyTexSubImage()");
2737 * Alloc image buffer (XXX could use a PBO)
2739 buf
= malloc(width
* height
* bpp
);
2741 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%uD", dims
);
2745 _mesa_unlock_texture(ctx
, texObj
); /* need to unlock first */
2748 * Read image from framebuffer (disable pixel transfer ops)
2750 _mesa_meta_begin(ctx
, MESA_META_PIXEL_STORE
| MESA_META_PIXEL_TRANSFER
);
2751 ctx
->Driver
.ReadPixels(ctx
, x
, y
, width
, height
,
2752 format
, type
, &ctx
->Pack
, buf
);
2753 _mesa_meta_end(ctx
);
2755 _mesa_update_state(ctx
); /* to update pixel transfer state */
2758 * Store texture data (with pixel transfer ops)
2760 _mesa_meta_begin(ctx
, MESA_META_PIXEL_STORE
);
2762 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
2763 assert(yoffset
== 0);
2764 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2765 xoffset
, zoffset
, 0, width
, 1, 1,
2766 format
, type
, buf
, &ctx
->Unpack
);
2768 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2769 xoffset
, yoffset
, zoffset
, width
, height
, 1,
2770 format
, type
, buf
, &ctx
->Unpack
);
2773 _mesa_meta_end(ctx
);
2775 _mesa_lock_texture(ctx
, texObj
); /* re-lock */
2782 meta_decompress_cleanup(struct decompress_state
*decompress
)
2784 if (decompress
->FBO
!= 0) {
2785 _mesa_DeleteFramebuffers(1, &decompress
->FBO
);
2786 _mesa_DeleteRenderbuffers(1, &decompress
->RBO
);
2789 if (decompress
->VAO
!= 0) {
2790 _mesa_DeleteVertexArrays(1, &decompress
->VAO
);
2791 _mesa_DeleteBuffers(1, &decompress
->VBO
);
2794 if (decompress
->Sampler
!= 0)
2795 _mesa_DeleteSamplers(1, &decompress
->Sampler
);
2797 memset(decompress
, 0, sizeof(*decompress
));
2801 * Decompress a texture image by drawing a quad with the compressed
2802 * texture and reading the pixels out of the color buffer.
2803 * \param slice which slice of a 3D texture or layer of a 1D/2D texture
2804 * \param destFormat format, ala glReadPixels
2805 * \param destType type, ala glReadPixels
2806 * \param dest destination buffer
2807 * \param destRowLength dest image rowLength (ala GL_PACK_ROW_LENGTH)
2810 decompress_texture_image(struct gl_context
*ctx
,
2811 struct gl_texture_image
*texImage
,
2813 GLenum destFormat
, GLenum destType
,
2816 struct decompress_state
*decompress
= &ctx
->Meta
->Decompress
;
2817 struct gl_texture_object
*texObj
= texImage
->TexObject
;
2818 const GLint width
= texImage
->Width
;
2819 const GLint height
= texImage
->Height
;
2820 const GLint depth
= texImage
->Height
;
2821 const GLenum target
= texObj
->Target
;
2823 struct vertex verts
[4];
2825 const bool use_glsl_version
= ctx
->Extensions
.ARB_vertex_shader
&&
2826 ctx
->Extensions
.ARB_fragment_shader
;
2829 assert(target
== GL_TEXTURE_3D
||
2830 target
== GL_TEXTURE_2D_ARRAY
||
2831 target
== GL_TEXTURE_CUBE_MAP_ARRAY
);
2836 case GL_TEXTURE_1D_ARRAY
:
2837 assert(!"No compressed 1D textures.");
2841 assert(!"No compressed 3D textures.");
2844 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2845 faceTarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ (slice
% 6);
2848 case GL_TEXTURE_CUBE_MAP
:
2849 faceTarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ texImage
->Face
;
2853 faceTarget
= target
;
2857 _mesa_meta_begin(ctx
, MESA_META_ALL
& ~MESA_META_PIXEL_STORE
);
2859 samplerSave
= ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
?
2860 ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
].Sampler
->Name
: 0;
2862 /* Create/bind FBO/renderbuffer */
2863 if (decompress
->FBO
== 0) {
2864 _mesa_GenFramebuffers(1, &decompress
->FBO
);
2865 _mesa_GenRenderbuffers(1, &decompress
->RBO
);
2866 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, decompress
->FBO
);
2867 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, decompress
->RBO
);
2868 _mesa_FramebufferRenderbuffer(GL_FRAMEBUFFER_EXT
,
2869 GL_COLOR_ATTACHMENT0_EXT
,
2870 GL_RENDERBUFFER_EXT
,
2874 _mesa_BindFramebuffer(GL_FRAMEBUFFER_EXT
, decompress
->FBO
);
2877 /* alloc dest surface */
2878 if (width
> decompress
->Width
|| height
> decompress
->Height
) {
2879 _mesa_BindRenderbuffer(GL_RENDERBUFFER_EXT
, decompress
->RBO
);
2880 _mesa_RenderbufferStorage(GL_RENDERBUFFER_EXT
, GL_RGBA
,
2882 decompress
->Width
= width
;
2883 decompress
->Height
= height
;
2886 if (use_glsl_version
) {
2887 _mesa_meta_setup_vertex_objects(&decompress
->VAO
, &decompress
->VBO
, true,
2890 _mesa_meta_setup_blit_shader(ctx
, target
, &decompress
->shaders
);
2892 _mesa_meta_setup_ff_tnl_for_blit(&decompress
->VAO
, &decompress
->VBO
, 3);
2895 if (!decompress
->Sampler
) {
2896 _mesa_GenSamplers(1, &decompress
->Sampler
);
2897 _mesa_BindSampler(ctx
->Texture
.CurrentUnit
, decompress
->Sampler
);
2898 /* nearest filtering */
2899 _mesa_SamplerParameteri(decompress
->Sampler
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
2900 _mesa_SamplerParameteri(decompress
->Sampler
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
2901 /* No sRGB decode or encode.*/
2902 if (ctx
->Extensions
.EXT_texture_sRGB_decode
) {
2903 _mesa_SamplerParameteri(decompress
->Sampler
, GL_TEXTURE_SRGB_DECODE_EXT
,
2904 GL_SKIP_DECODE_EXT
);
2908 _mesa_BindSampler(ctx
->Texture
.CurrentUnit
, decompress
->Sampler
);
2911 /* Silence valgrind warnings about reading uninitialized stack. */
2912 memset(verts
, 0, sizeof(verts
));
2914 _mesa_meta_setup_texture_coords(faceTarget
, slice
, width
, height
, depth
,
2920 /* setup vertex positions */
2930 _mesa_set_viewport(ctx
, 0, 0, 0, width
, height
);
2932 /* upload new vertex data */
2933 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
2935 /* setup texture state */
2936 _mesa_BindTexture(target
, texObj
->Name
);
2938 if (!use_glsl_version
)
2939 _mesa_set_enable(ctx
, target
, GL_TRUE
);
2942 /* save texture object state */
2943 const GLint baseLevelSave
= texObj
->BaseLevel
;
2944 const GLint maxLevelSave
= texObj
->MaxLevel
;
2946 /* restrict sampling to the texture level of interest */
2947 if (target
!= GL_TEXTURE_RECTANGLE_ARB
) {
2948 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, texImage
->Level
);
2949 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, texImage
->Level
);
2952 /* render quad w/ texture into renderbuffer */
2953 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
2955 /* Restore texture object state, the texture binding will
2956 * be restored by _mesa_meta_end().
2958 if (target
!= GL_TEXTURE_RECTANGLE_ARB
) {
2959 _mesa_TexParameteri(target
, GL_TEXTURE_BASE_LEVEL
, baseLevelSave
);
2960 _mesa_TexParameteri(target
, GL_TEXTURE_MAX_LEVEL
, maxLevelSave
);
2965 /* read pixels from renderbuffer */
2967 GLenum baseTexFormat
= texImage
->_BaseFormat
;
2968 GLenum destBaseFormat
= _mesa_base_tex_format(ctx
, destFormat
);
2970 /* The pixel transfer state will be set to default values at this point
2971 * (see MESA_META_PIXEL_TRANSFER) so pixel transfer ops are effectively
2972 * turned off (as required by glGetTexImage) but we need to handle some
2973 * special cases. In particular, single-channel texture values are
2974 * returned as red and two-channel texture values are returned as
2977 if ((baseTexFormat
== GL_LUMINANCE
||
2978 baseTexFormat
== GL_LUMINANCE_ALPHA
||
2979 baseTexFormat
== GL_INTENSITY
) ||
2980 /* If we're reading back an RGB(A) texture (using glGetTexImage) as
2981 * luminance then we need to return L=tex(R).
2983 ((baseTexFormat
== GL_RGBA
||
2984 baseTexFormat
== GL_RGB
||
2985 baseTexFormat
== GL_RG
) &&
2986 (destBaseFormat
== GL_LUMINANCE
||
2987 destBaseFormat
== GL_LUMINANCE_ALPHA
||
2988 destBaseFormat
== GL_LUMINANCE_INTEGER_EXT
||
2989 destBaseFormat
== GL_LUMINANCE_ALPHA_INTEGER_EXT
))) {
2990 /* Green and blue must be zero */
2991 _mesa_PixelTransferf(GL_GREEN_SCALE
, 0.0f
);
2992 _mesa_PixelTransferf(GL_BLUE_SCALE
, 0.0f
);
2995 _mesa_ReadPixels(0, 0, width
, height
, destFormat
, destType
, dest
);
2998 /* disable texture unit */
2999 if (!use_glsl_version
)
3000 _mesa_set_enable(ctx
, target
, GL_FALSE
);
3002 _mesa_BindSampler(ctx
->Texture
.CurrentUnit
, samplerSave
);
3004 _mesa_meta_end(ctx
);
3009 * This is just a wrapper around _mesa_get_tex_image() and
3010 * decompress_texture_image(). Meta functions should not be directly called
3014 _mesa_meta_GetTexImage(struct gl_context
*ctx
,
3015 GLenum format
, GLenum type
, GLvoid
*pixels
,
3016 struct gl_texture_image
*texImage
)
3018 /* We can only use the decompress-with-blit method here if the texels are
3019 * unsigned, normalized values. We could handle signed and unnormalized
3020 * with floating point renderbuffers...
3022 if (_mesa_is_format_compressed(texImage
->TexFormat
) &&
3023 _mesa_get_format_datatype(texImage
->TexFormat
)
3024 == GL_UNSIGNED_NORMALIZED
) {
3025 struct gl_texture_object
*texObj
= texImage
->TexObject
;
3027 /* Need to unlock the texture here to prevent deadlock... */
3028 _mesa_unlock_texture(ctx
, texObj
);
3029 for (slice
= 0; slice
< texImage
->Depth
; slice
++) {
3031 if (texImage
->TexObject
->Target
== GL_TEXTURE_2D_ARRAY
3032 || texImage
->TexObject
->Target
== GL_TEXTURE_CUBE_MAP_ARRAY
) {
3033 /* Setup pixel packing. SkipPixels and SkipRows will be applied
3034 * in the decompress_texture_image() function's call to
3035 * glReadPixels but we need to compute the dest slice's address
3036 * here (according to SkipImages and ImageHeight).
3038 struct gl_pixelstore_attrib packing
= ctx
->Pack
;
3039 packing
.SkipPixels
= 0;
3040 packing
.SkipRows
= 0;
3041 dst
= _mesa_image_address3d(&packing
, pixels
, texImage
->Width
,
3042 texImage
->Height
, format
, type
,
3048 decompress_texture_image(ctx
, texImage
, slice
, format
, type
, dst
);
3050 /* ... and relock it */
3051 _mesa_lock_texture(ctx
, texObj
);
3054 _mesa_get_teximage(ctx
, format
, type
, pixels
, texImage
);
3060 * Meta implementation of ctx->Driver.DrawTex() in terms
3061 * of polygon rendering.
3064 _mesa_meta_DrawTex(struct gl_context
*ctx
, GLfloat x
, GLfloat y
, GLfloat z
,
3065 GLfloat width
, GLfloat height
)
3067 struct drawtex_state
*drawtex
= &ctx
->Meta
->DrawTex
;
3069 GLfloat x
, y
, z
, st
[MAX_TEXTURE_UNITS
][2];
3071 struct vertex verts
[4];
3074 _mesa_meta_begin(ctx
, (MESA_META_RASTERIZATION
|
3076 MESA_META_TRANSFORM
|
3078 MESA_META_VIEWPORT
));
3080 if (drawtex
->VAO
== 0) {
3081 /* one-time setup */
3082 GLint active_texture
;
3084 /* create vertex array object */
3085 _mesa_GenVertexArrays(1, &drawtex
->VAO
);
3086 _mesa_BindVertexArray(drawtex
->VAO
);
3088 /* create vertex array buffer */
3089 _mesa_GenBuffers(1, &drawtex
->VBO
);
3090 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
, drawtex
->VBO
);
3091 _mesa_BufferData(GL_ARRAY_BUFFER_ARB
, sizeof(verts
),
3092 NULL
, GL_DYNAMIC_DRAW_ARB
);
3094 /* client active texture is not part of the array object */
3095 active_texture
= ctx
->Array
.ActiveTexture
;
3097 /* setup vertex arrays */
3098 _mesa_VertexPointer(3, GL_FLOAT
, sizeof(struct vertex
), OFFSET(x
));
3099 _mesa_EnableClientState(GL_VERTEX_ARRAY
);
3100 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
3101 _mesa_ClientActiveTexture(GL_TEXTURE0
+ i
);
3102 _mesa_TexCoordPointer(2, GL_FLOAT
, sizeof(struct vertex
), OFFSET(st
[i
]));
3103 _mesa_EnableClientState(GL_TEXTURE_COORD_ARRAY
);
3106 /* restore client active texture */
3107 _mesa_ClientActiveTexture(GL_TEXTURE0
+ active_texture
);
3110 _mesa_BindVertexArray(drawtex
->VAO
);
3111 _mesa_BindBuffer(GL_ARRAY_BUFFER_ARB
, drawtex
->VBO
);
3114 /* vertex positions, texcoords */
3116 const GLfloat x1
= x
+ width
;
3117 const GLfloat y1
= y
+ height
;
3119 z
= CLAMP(z
, 0.0f
, 1.0f
);
3138 for (i
= 0; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
3139 const struct gl_texture_object
*texObj
;
3140 const struct gl_texture_image
*texImage
;
3141 GLfloat s
, t
, s1
, t1
;
3144 if (!ctx
->Texture
.Unit
[i
]._ReallyEnabled
) {
3146 for (j
= 0; j
< 4; j
++) {
3147 verts
[j
].st
[i
][0] = 0.0f
;
3148 verts
[j
].st
[i
][1] = 0.0f
;
3153 texObj
= ctx
->Texture
.Unit
[i
]._Current
;
3154 texImage
= texObj
->Image
[0][texObj
->BaseLevel
];
3155 tw
= texImage
->Width2
;
3156 th
= texImage
->Height2
;
3158 s
= (GLfloat
) texObj
->CropRect
[0] / tw
;
3159 t
= (GLfloat
) texObj
->CropRect
[1] / th
;
3160 s1
= (GLfloat
) (texObj
->CropRect
[0] + texObj
->CropRect
[2]) / tw
;
3161 t1
= (GLfloat
) (texObj
->CropRect
[1] + texObj
->CropRect
[3]) / th
;
3163 verts
[0].st
[i
][0] = s
;
3164 verts
[0].st
[i
][1] = t
;
3166 verts
[1].st
[i
][0] = s1
;
3167 verts
[1].st
[i
][1] = t
;
3169 verts
[2].st
[i
][0] = s1
;
3170 verts
[2].st
[i
][1] = t1
;
3172 verts
[3].st
[i
][0] = s
;
3173 verts
[3].st
[i
][1] = t1
;
3176 _mesa_BufferSubData(GL_ARRAY_BUFFER_ARB
, 0, sizeof(verts
), verts
);
3179 _mesa_DrawArrays(GL_TRIANGLE_FAN
, 0, 4);
3181 _mesa_meta_end(ctx
);