2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
44 #include "texcompress.h"
53 * State changes which we care about for glCopyTex[Sub]Image() calls.
54 * In particular, we care about pixel transfer state and buffer state
55 * (such as glReadBuffer to make sure we read from the right renderbuffer).
57 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
64 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
68 _mesa_alloc_texmemory(GLsizei bytes
)
70 return _mesa_align_malloc(bytes
, 512);
75 * Free texture memory allocated with _mesa_alloc_texmemory()
78 _mesa_free_texmemory(void *m
)
85 * Compute floor(log_base_2(n)).
115 * Return the simple base format for a given internal texture format.
116 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
118 * \param ctx GL context.
119 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
121 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
122 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
124 * This is the format which is used during texture application (i.e. the
125 * texture format and env mode determine the arithmetic used.
127 * XXX this could be static
130 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
132 switch (internalFormat
) {
147 case GL_LUMINANCE_ALPHA
:
148 case GL_LUMINANCE4_ALPHA4
:
149 case GL_LUMINANCE6_ALPHA2
:
150 case GL_LUMINANCE8_ALPHA8
:
151 case GL_LUMINANCE12_ALPHA4
:
152 case GL_LUMINANCE12_ALPHA12
:
153 case GL_LUMINANCE16_ALPHA16
:
154 return GL_LUMINANCE_ALPHA
;
185 if (ctx
->Extensions
.EXT_paletted_texture
) {
186 switch (internalFormat
) {
188 case GL_COLOR_INDEX1_EXT
:
189 case GL_COLOR_INDEX2_EXT
:
190 case GL_COLOR_INDEX4_EXT
:
191 case GL_COLOR_INDEX8_EXT
:
192 case GL_COLOR_INDEX12_EXT
:
193 case GL_COLOR_INDEX16_EXT
:
194 return GL_COLOR_INDEX
;
200 if (ctx
->Extensions
.ARB_depth_texture
) {
201 switch (internalFormat
) {
202 case GL_DEPTH_COMPONENT
:
203 case GL_DEPTH_COMPONENT16
:
204 case GL_DEPTH_COMPONENT24
:
205 case GL_DEPTH_COMPONENT32
:
206 return GL_DEPTH_COMPONENT
;
212 switch (internalFormat
) {
213 case GL_COMPRESSED_ALPHA
:
215 case GL_COMPRESSED_LUMINANCE
:
217 case GL_COMPRESSED_LUMINANCE_ALPHA
:
218 return GL_LUMINANCE_ALPHA
;
219 case GL_COMPRESSED_INTENSITY
:
221 case GL_COMPRESSED_RGB
:
223 case GL_COMPRESSED_RGBA
:
229 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
230 switch (internalFormat
) {
231 case GL_COMPRESSED_RGB_FXT1_3DFX
:
233 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
240 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
241 switch (internalFormat
) {
242 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
244 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
245 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
246 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
253 if (ctx
->Extensions
.S3_s3tc
) {
254 switch (internalFormat
) {
266 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
267 if (internalFormat
== GL_YCBCR_MESA
)
268 return GL_YCBCR_MESA
;
271 if (ctx
->Extensions
.ARB_texture_float
) {
272 switch (internalFormat
) {
273 case GL_ALPHA16F_ARB
:
274 case GL_ALPHA32F_ARB
:
282 case GL_INTENSITY16F_ARB
:
283 case GL_INTENSITY32F_ARB
:
285 case GL_LUMINANCE16F_ARB
:
286 case GL_LUMINANCE32F_ARB
:
288 case GL_LUMINANCE_ALPHA16F_ARB
:
289 case GL_LUMINANCE_ALPHA32F_ARB
:
290 return GL_LUMINANCE_ALPHA
;
296 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
297 switch (internalFormat
) {
306 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
307 switch (internalFormat
) {
316 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
317 switch (internalFormat
) {
318 case GL_DEPTH_STENCIL_EXT
:
319 case GL_DEPTH24_STENCIL8_EXT
:
320 return GL_DEPTH_STENCIL_EXT
;
326 #if FEATURE_EXT_texture_sRGB
327 if (ctx
->Extensions
.EXT_texture_sRGB
) {
328 switch (internalFormat
) {
331 case GL_COMPRESSED_SRGB_EXT
:
332 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
334 case GL_SRGB_ALPHA_EXT
:
335 case GL_SRGB8_ALPHA8_EXT
:
336 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
337 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
341 case GL_SLUMINANCE_ALPHA_EXT
:
342 case GL_SLUMINANCE8_ALPHA8_EXT
:
343 case GL_COMPRESSED_SLUMINANCE_EXT
:
344 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
345 return GL_LUMINANCE_ALPHA
;
346 case GL_SLUMINANCE_EXT
:
347 case GL_SLUMINANCE8_EXT
:
353 #endif /* FEATURE_EXT_texture_sRGB */
355 if (ctx
->Extensions
.EXT_texture_integer
) {
356 switch (internalFormat
) {
358 case GL_RGBA16UI_EXT
:
359 case GL_RGBA32UI_EXT
:
371 case GL_ALPHA8UI_EXT
:
372 case GL_ALPHA16UI_EXT
:
373 case GL_ALPHA32UI_EXT
:
375 case GL_ALPHA16I_EXT
:
376 case GL_ALPHA32I_EXT
:
378 case GL_INTENSITY8UI_EXT
:
379 case GL_INTENSITY16UI_EXT
:
380 case GL_INTENSITY32UI_EXT
:
381 case GL_INTENSITY8I_EXT
:
382 case GL_INTENSITY16I_EXT
:
383 case GL_INTENSITY32I_EXT
:
385 case GL_LUMINANCE8UI_EXT
:
386 case GL_LUMINANCE16UI_EXT
:
387 case GL_LUMINANCE32UI_EXT
:
388 case GL_LUMINANCE8I_EXT
:
389 case GL_LUMINANCE16I_EXT
:
390 case GL_LUMINANCE32I_EXT
:
392 case GL_LUMINANCE_ALPHA8UI_EXT
:
393 case GL_LUMINANCE_ALPHA16UI_EXT
:
394 case GL_LUMINANCE_ALPHA32UI_EXT
:
395 case GL_LUMINANCE_ALPHA8I_EXT
:
396 case GL_LUMINANCE_ALPHA16I_EXT
:
397 case GL_LUMINANCE_ALPHA32I_EXT
:
398 return GL_LUMINANCE_ALPHA
;
404 if (ctx
->Extensions
.ARB_texture_rg
) {
405 switch (internalFormat
) {
407 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
409 if (!ctx
->Extensions
.ARB_half_float_pixel
)
413 if (!ctx
->Extensions
.ARB_texture_float
)
422 if (!ctx
->Extensions
.EXT_texture_integer
)
428 case GL_COMPRESSED_RED
:
432 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
434 if (!ctx
->Extensions
.ARB_half_float_pixel
)
438 if (!ctx
->Extensions
.ARB_texture_float
)
447 if (!ctx
->Extensions
.EXT_texture_integer
)
453 case GL_COMPRESSED_RG
:
460 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
461 switch (internalFormat
) {
469 if (ctx
->Extensions
.EXT_packed_float
) {
470 switch (internalFormat
) {
471 case GL_R11F_G11F_B10F_EXT
:
478 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
479 switch (internalFormat
) {
480 case GL_DEPTH_COMPONENT32F
:
481 return GL_DEPTH_COMPONENT
;
482 case GL_DEPTH32F_STENCIL8
:
483 return GL_DEPTH_STENCIL
;
489 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
490 switch (internalFormat
) {
491 case GL_COMPRESSED_RED_RGTC1
:
492 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
494 case GL_COMPRESSED_RG_RGTC2
:
495 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
502 return -1; /* error */
507 * For cube map faces, return a face index in [0,5].
508 * For other targets return 0;
511 _mesa_tex_target_to_face(GLenum target
)
513 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
514 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
515 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
523 * Store a gl_texture_image pointer in a gl_texture_object structure
524 * according to the target and level parameters.
526 * \param tObj texture object.
527 * \param target texture target.
528 * \param level image level.
529 * \param texImage texture image.
531 * This was basically prompted by the introduction of cube maps.
534 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
535 GLenum target
, GLint level
,
536 struct gl_texture_image
*texImage
)
538 const GLuint face
= _mesa_tex_target_to_face(target
);
542 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
544 tObj
->Image
[face
][level
] = texImage
;
546 /* Set the 'back' pointer */
547 texImage
->TexObject
= tObj
;
552 * Allocate a texture image structure.
554 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
557 * \return a pointer to gl_texture_image struct with all fields initialized to
560 struct gl_texture_image
*
561 _mesa_new_texture_image( struct gl_context
*ctx
)
564 return CALLOC_STRUCT(gl_texture_image
);
569 * Free texture image data.
570 * This function is a fallback called via ctx->Driver.FreeTexImageData().
572 * \param texImage texture image.
574 * Free the texture image data if it's not marked as client data.
577 _mesa_free_texture_image_data(struct gl_context
*ctx
,
578 struct gl_texture_image
*texImage
)
582 if (texImage
->Data
&& !texImage
->IsClientData
) {
583 /* free the old texture data */
584 _mesa_free_texmemory(texImage
->Data
);
587 texImage
->Data
= NULL
;
592 * Free texture image.
594 * \param texImage texture image.
596 * Free the texture image structure and the associated image data.
599 _mesa_delete_texture_image(struct gl_context
*ctx
,
600 struct gl_texture_image
*texImage
)
602 /* Free texImage->Data and/or any other driver-specific texture
605 ASSERT(ctx
->Driver
.FreeTexImageData
);
606 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
608 ASSERT(texImage
->Data
== NULL
);
609 if (texImage
->ImageOffsets
)
610 free(texImage
->ImageOffsets
);
616 * Test if a target is a proxy target.
618 * \param target texture target.
620 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
623 _mesa_is_proxy_texture(GLenum target
)
625 /* NUM_TEXTURE_TARGETS should match number of terms below */
626 assert(NUM_TEXTURE_TARGETS
== 7);
628 return (target
== GL_PROXY_TEXTURE_1D
||
629 target
== GL_PROXY_TEXTURE_2D
||
630 target
== GL_PROXY_TEXTURE_3D
||
631 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
632 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
633 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
634 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
639 * Get the texture object that corresponds to the target of the given
642 * \param ctx GL context.
643 * \param texUnit texture unit.
644 * \param target texture target.
646 * \return pointer to the texture object on success, or NULL on failure.
648 * \sa gl_texture_unit.
650 struct gl_texture_object
*
651 _mesa_select_tex_object(struct gl_context
*ctx
,
652 const struct gl_texture_unit
*texUnit
,
657 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
658 case GL_PROXY_TEXTURE_1D
:
659 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
661 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
662 case GL_PROXY_TEXTURE_2D
:
663 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
665 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
666 case GL_PROXY_TEXTURE_3D
:
667 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
668 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
669 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
670 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
671 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
672 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
673 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
674 case GL_TEXTURE_CUBE_MAP_ARB
:
675 return ctx
->Extensions
.ARB_texture_cube_map
676 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
677 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
678 return ctx
->Extensions
.ARB_texture_cube_map
679 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
680 case GL_TEXTURE_RECTANGLE_NV
:
681 return ctx
->Extensions
.NV_texture_rectangle
682 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
683 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
684 return ctx
->Extensions
.NV_texture_rectangle
685 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
686 case GL_TEXTURE_1D_ARRAY_EXT
:
687 return ctx
->Extensions
.MESA_texture_array
688 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
689 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
690 return ctx
->Extensions
.MESA_texture_array
691 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
692 case GL_TEXTURE_2D_ARRAY_EXT
:
693 return ctx
->Extensions
.MESA_texture_array
694 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
695 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
696 return ctx
->Extensions
.MESA_texture_array
697 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
699 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
706 * Return pointer to texture object for given target on current texture unit.
708 struct gl_texture_object
*
709 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
711 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
712 return _mesa_select_tex_object(ctx
, texUnit
, target
);
717 * Get a texture image pointer from a texture object, given a texture
718 * target and mipmap level. The target and level parameters should
719 * have already been error-checked.
721 * \param ctx GL context.
722 * \param texObj texture unit.
723 * \param target texture target.
724 * \param level image level.
726 * \return pointer to the texture image structure, or NULL on failure.
728 struct gl_texture_image
*
729 _mesa_select_tex_image(struct gl_context
*ctx
,
730 const struct gl_texture_object
*texObj
,
731 GLenum target
, GLint level
)
733 const GLuint face
= _mesa_tex_target_to_face(target
);
737 ASSERT(level
< MAX_TEXTURE_LEVELS
);
739 return texObj
->Image
[face
][level
];
744 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
745 * it and install it. Only return NULL if passed a bad parameter or run
748 struct gl_texture_image
*
749 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
750 GLenum target
, GLint level
)
752 struct gl_texture_image
*texImage
;
757 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
759 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
761 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
765 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
773 * Return pointer to the specified proxy texture image.
774 * Note that proxy textures are per-context, not per-texture unit.
775 * \return pointer to texture image or NULL if invalid target, invalid
776 * level, or out of memory.
778 struct gl_texture_image
*
779 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
781 struct gl_texture_image
*texImage
;
788 case GL_PROXY_TEXTURE_1D
:
789 if (level
>= ctx
->Const
.MaxTextureLevels
)
791 texIndex
= TEXTURE_1D_INDEX
;
793 case GL_PROXY_TEXTURE_2D
:
794 if (level
>= ctx
->Const
.MaxTextureLevels
)
796 texIndex
= TEXTURE_2D_INDEX
;
798 case GL_PROXY_TEXTURE_3D
:
799 if (level
>= ctx
->Const
.Max3DTextureLevels
)
801 texIndex
= TEXTURE_3D_INDEX
;
803 case GL_PROXY_TEXTURE_CUBE_MAP
:
804 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
806 texIndex
= TEXTURE_CUBE_INDEX
;
808 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
811 texIndex
= TEXTURE_RECT_INDEX
;
813 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
814 if (level
>= ctx
->Const
.MaxTextureLevels
)
816 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
818 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
819 if (level
>= ctx
->Const
.MaxTextureLevels
)
821 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
827 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
829 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
831 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
834 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
835 /* Set the 'back' pointer */
836 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
843 * Get the maximum number of allowed mipmap levels.
845 * \param ctx GL context.
846 * \param target texture target.
848 * \return the maximum number of allowed mipmap levels for the given
849 * texture target, or zero if passed a bad target.
854 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
858 case GL_PROXY_TEXTURE_1D
:
860 case GL_PROXY_TEXTURE_2D
:
861 return ctx
->Const
.MaxTextureLevels
;
863 case GL_PROXY_TEXTURE_3D
:
864 return ctx
->Const
.Max3DTextureLevels
;
865 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
866 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
867 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
868 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
869 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
870 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
871 case GL_TEXTURE_CUBE_MAP_ARB
:
872 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
873 return ctx
->Extensions
.ARB_texture_cube_map
874 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
875 case GL_TEXTURE_RECTANGLE_NV
:
876 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
877 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
878 case GL_TEXTURE_1D_ARRAY_EXT
:
879 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
880 case GL_TEXTURE_2D_ARRAY_EXT
:
881 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
882 return ctx
->Extensions
.MESA_texture_array
883 ? ctx
->Const
.MaxTextureLevels
: 0;
885 return 0; /* bad target */
891 * Return number of dimensions per mipmap level for the given texture target.
894 get_texture_dimensions(GLenum target
)
898 case GL_PROXY_TEXTURE_1D
:
901 case GL_TEXTURE_RECTANGLE
:
902 case GL_TEXTURE_CUBE_MAP
:
903 case GL_PROXY_TEXTURE_2D
:
904 case GL_PROXY_TEXTURE_RECTANGLE
:
905 case GL_PROXY_TEXTURE_CUBE_MAP
:
906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
912 case GL_TEXTURE_1D_ARRAY
:
913 case GL_PROXY_TEXTURE_1D_ARRAY
:
916 case GL_PROXY_TEXTURE_3D
:
917 case GL_TEXTURE_2D_ARRAY
:
918 case GL_PROXY_TEXTURE_2D_ARRAY
:
921 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
930 #if 000 /* not used anymore */
932 * glTexImage[123]D can accept a NULL image pointer. In this case we
933 * create a texture image with unspecified image contents per the OpenGL
937 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
939 const GLint components
= _mesa_components_in_format(format
);
940 const GLint numPixels
= width
* height
* depth
;
941 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
945 * Let's see if anyone finds this. If glTexImage2D() is called with
946 * a NULL image pointer then load the texture image with something
947 * interesting instead of leaving it indeterminate.
950 static const char message
[8][32] = {
954 " X X XXXX XXX XXXXX ",
957 " X X XXXXX XXX X X ",
961 GLubyte
*imgPtr
= data
;
963 for (h
= 0; h
< depth
; h
++) {
964 for (i
= 0; i
< height
; i
++) {
965 GLint srcRow
= 7 - (i
% 8);
966 for (j
= 0; j
< width
; j
++) {
967 GLint srcCol
= j
% 32;
968 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
969 for (k
= 0; k
< components
; k
++) {
985 * Reset the fields of a gl_texture_image struct to zero.
987 * \param img texture image structure.
989 * This is called when a proxy texture test fails, we set all the
990 * image members (except DriverData) to zero.
991 * It's also used in glTexImage[123]D as a safeguard to be sure all
992 * required fields get initialized properly by the Driver.TexImage[123]D
996 clear_teximage_fields(struct gl_texture_image
*img
)
999 img
->_BaseFormat
= 0;
1000 img
->InternalFormat
= 0;
1006 if (img
->ImageOffsets
) {
1007 free(img
->ImageOffsets
);
1008 img
->ImageOffsets
= NULL
;
1014 img
->HeightLog2
= 0;
1017 img
->TexFormat
= MESA_FORMAT_NONE
;
1018 img
->FetchTexelc
= NULL
;
1019 img
->FetchTexelf
= NULL
;
1024 * Initialize basic fields of the gl_texture_image struct.
1026 * \param ctx GL context.
1027 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1028 * \param img texture image structure to be initialized.
1029 * \param width image width.
1030 * \param height image height.
1031 * \param depth image depth.
1032 * \param border image border.
1033 * \param internalFormat internal format.
1034 * \param format the actual hardware format (one of MESA_FORMAT_*)
1036 * Fills in the fields of \p img with the given information.
1037 * Note: width, height and depth include the border.
1040 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1041 struct gl_texture_image
*img
,
1042 GLsizei width
, GLsizei height
, GLsizei depth
,
1043 GLint border
, GLenum internalFormat
,
1050 ASSERT(height
>= 0);
1053 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1054 ASSERT(img
->_BaseFormat
> 0);
1055 img
->InternalFormat
= internalFormat
;
1056 img
->Border
= border
;
1058 img
->Height
= height
;
1061 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1062 img
->WidthLog2
= logbase2(img
->Width2
);
1064 if (height
== 1) { /* 1-D texture */
1066 img
->HeightLog2
= 0;
1069 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1070 img
->HeightLog2
= logbase2(img
->Height2
);
1073 if (depth
== 1) { /* 2-D texture */
1078 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1079 img
->DepthLog2
= logbase2(img
->Depth2
);
1082 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1084 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1085 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1086 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1087 img
->_IsPowerOfTwo
= GL_TRUE
;
1089 img
->_IsPowerOfTwo
= GL_FALSE
;
1091 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1092 img
->RowStride
= width
;
1093 /* Allocate the ImageOffsets array and initialize to typical values.
1094 * We allocate the array for 1D/2D textures too in order to avoid special-
1095 * case code in the texstore routines.
1097 if (img
->ImageOffsets
)
1098 free(img
->ImageOffsets
);
1099 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1100 for (i
= 0; i
< depth
; i
++) {
1101 img
->ImageOffsets
[i
] = i
* width
* height
;
1104 /* Compute Width/Height/DepthScale for mipmap lod computation */
1105 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1106 /* scale = 1.0 since texture coords directly map to texels */
1107 img
->WidthScale
= 1.0;
1108 img
->HeightScale
= 1.0;
1109 img
->DepthScale
= 1.0;
1112 img
->WidthScale
= (GLfloat
) img
->Width
;
1113 img
->HeightScale
= (GLfloat
) img
->Height
;
1114 img
->DepthScale
= (GLfloat
) img
->Depth
;
1117 img
->TexFormat
= format
;
1119 dims
= get_texture_dimensions(target
);
1121 _mesa_set_fetch_functions(img
, dims
);
1126 * Free and clear fields of the gl_texture_image struct.
1128 * \param ctx GL context.
1129 * \param texImage texture image structure to be cleared.
1131 * After the call, \p texImage will have no data associated with it. Its
1132 * fields are cleared so that its parent object will test incomplete.
1135 _mesa_clear_texture_image(struct gl_context
*ctx
,
1136 struct gl_texture_image
*texImage
)
1138 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1139 clear_teximage_fields(texImage
);
1144 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1145 * level, width, height and depth against the ctx->Const limits for textures.
1147 * A hardware driver might override this function if, for example, the
1148 * max 3D texture size is 512x512x64 (i.e. not a cube).
1150 * Note that width, height, depth == 0 is not an error. However, a
1151 * texture with zero width/height/depth will be considered "incomplete"
1152 * and texturing will effectively be disabled.
1154 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1155 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1156 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1157 * \param level as passed to glTexImage
1158 * \param internalFormat as passed to glTexImage
1159 * \param format as passed to glTexImage
1160 * \param type as passed to glTexImage
1161 * \param width as passed to glTexImage
1162 * \param height as passed to glTexImage
1163 * \param depth as passed to glTexImage
1164 * \param border as passed to glTexImage
1165 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1168 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1169 GLint internalFormat
, GLenum format
, GLenum type
,
1170 GLint width
, GLint height
, GLint depth
, GLint border
)
1174 (void) internalFormat
;
1179 case GL_PROXY_TEXTURE_1D
:
1180 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1181 if (width
< 2 * border
|| width
> 2 + maxSize
||
1182 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1183 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1184 level
>= ctx
->Const
.MaxTextureLevels
) {
1185 /* bad width or level */
1189 case GL_PROXY_TEXTURE_2D
:
1190 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1191 if (width
< 2 * border
|| width
> 2 + maxSize
||
1192 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1193 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1194 height
< 2 * border
|| height
> 2 + maxSize
||
1195 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1196 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1197 level
>= ctx
->Const
.MaxTextureLevels
) {
1198 /* bad width or height or level */
1202 case GL_PROXY_TEXTURE_3D
:
1203 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1204 if (width
< 2 * border
|| width
> 2 + maxSize
||
1205 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1206 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1207 height
< 2 * border
|| height
> 2 + maxSize
||
1208 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1209 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1210 depth
< 2 * border
|| depth
> 2 + maxSize
||
1211 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1212 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1213 level
>= ctx
->Const
.Max3DTextureLevels
) {
1214 /* bad width or height or depth or level */
1218 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1219 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1220 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1222 /* bad width or height or level */
1226 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1227 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1228 if (width
< 2 * border
|| width
> 2 + maxSize
||
1229 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1230 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1231 height
< 2 * border
|| height
> 2 + maxSize
||
1232 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1233 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1234 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1235 /* bad width or height */
1239 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1240 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1241 if (width
< 2 * border
|| width
> 2 + maxSize
||
1242 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1243 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1244 level
>= ctx
->Const
.MaxTextureLevels
) {
1245 /* bad width or level */
1249 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1253 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1254 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1255 if (width
< 2 * border
|| width
> 2 + maxSize
||
1256 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1257 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1258 height
< 2 * border
|| height
> 2 + maxSize
||
1259 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1260 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1261 level
>= ctx
->Const
.MaxTextureLevels
) {
1262 /* bad width or height or level */
1265 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1270 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1277 * Check if the memory used by the texture would exceed the driver's limit.
1278 * This lets us support a max 3D texture size of 8K (for example) but
1279 * prevents allocating a full 8K x 8K x 8K texture.
1280 * XXX this could be rolled into the proxy texture size test (above) but
1281 * we don't have the actual texture internal format at that point.
1284 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1285 GLint width
, GLint height
, GLint depth
)
1287 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1288 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1289 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1295 * Helper function to determine whether a target supports compressed textures
1298 target_can_be_compressed(struct gl_context
*ctx
, GLenum target
)
1302 case GL_PROXY_TEXTURE_2D
:
1304 case GL_PROXY_TEXTURE_CUBE_MAP
:
1305 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1306 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1307 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1308 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1309 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1310 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1311 return ctx
->Extensions
.ARB_texture_cube_map
;
1312 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1313 case GL_TEXTURE_2D_ARRAY_EXT
:
1314 return ctx
->Extensions
.MESA_texture_array
;
1322 * Test the glTexImage[123]D() parameters for errors.
1324 * \param ctx GL context.
1325 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1326 * \param target texture target given by the user.
1327 * \param level image level given by the user.
1328 * \param internalFormat internal format given by the user.
1329 * \param format pixel data format given by the user.
1330 * \param type pixel data type given by the user.
1331 * \param width image width given by the user.
1332 * \param height image height given by the user.
1333 * \param depth image depth given by the user.
1334 * \param border image border given by the user.
1336 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1338 * Verifies each of the parameters against the constants specified in
1339 * __struct gl_contextRec::Const and the supported extensions, and according
1340 * to the OpenGL specification.
1343 texture_error_check( struct gl_context
*ctx
,
1344 GLuint dimensions
, GLenum target
,
1345 GLint level
, GLint internalFormat
,
1346 GLenum format
, GLenum type
,
1347 GLint width
, GLint height
,
1348 GLint depth
, GLint border
)
1350 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1351 GLboolean sizeOK
= GL_TRUE
;
1352 GLboolean colorFormat
, indexFormat
;
1353 GLenum proxy_target
;
1355 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1356 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1358 _mesa_error(ctx
, GL_INVALID_VALUE
,
1359 "glTexImage%dD(level=%d)", dimensions
, level
);
1365 if (border
< 0 || border
> 1 ||
1366 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1367 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1369 _mesa_error(ctx
, GL_INVALID_VALUE
,
1370 "glTexImage%dD(border=%d)", dimensions
, border
);
1375 if (width
< 0 || height
< 0 || depth
< 0) {
1377 _mesa_error(ctx
, GL_INVALID_VALUE
,
1378 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1383 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1384 * level, width, height and depth.
1386 if (dimensions
== 1) {
1387 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1388 proxy_target
= GL_PROXY_TEXTURE_1D
;
1393 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1397 else if (dimensions
== 2) {
1399 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1400 proxy_target
= GL_PROXY_TEXTURE_2D
;
1402 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1403 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1404 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1405 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1406 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1409 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1410 sizeOK
= (width
== height
);
1412 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1413 target
== GL_TEXTURE_RECTANGLE_NV
) {
1414 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1418 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1420 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1421 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1422 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1425 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1429 else if (dimensions
== 3) {
1430 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1431 proxy_target
= GL_PROXY_TEXTURE_3D
;
1433 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1434 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1435 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1438 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1443 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1447 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1448 internalFormat
, format
,
1449 type
, width
, height
,
1453 _mesa_error(ctx
, GL_INVALID_VALUE
,
1454 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1455 dimensions
, level
, width
, height
, depth
);
1460 /* Check internalFormat */
1461 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1463 _mesa_error(ctx
, GL_INVALID_VALUE
,
1464 "glTexImage%dD(internalFormat=%s)",
1465 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1470 /* Check incoming image format and type */
1471 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1472 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1473 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1474 * GL_EXT_texture_integer extension, some combinations should generate
1475 * GL_INVALID_ENUM instead (grr!).
1478 GLenum error
= _mesa_is_integer_format(format
)
1479 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1480 _mesa_error(ctx
, error
,
1481 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1482 dimensions
, format
, type
);
1487 /* make sure internal format and format basically agree */
1488 colorFormat
= _mesa_is_color_format(format
);
1489 indexFormat
= _mesa_is_index_format(format
);
1490 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1491 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1492 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1493 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1494 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1495 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1497 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1498 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1499 dimensions
, internalFormat
, format
);
1503 /* additional checks for ycbcr textures */
1504 if (internalFormat
== GL_YCBCR_MESA
) {
1505 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1506 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1507 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1509 _mesa_snprintf(message
, sizeof(message
),
1510 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1511 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1512 return GL_TRUE
; /* error */
1514 if (target
!= GL_TEXTURE_2D
&&
1515 target
!= GL_PROXY_TEXTURE_2D
&&
1516 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1517 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1519 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1525 _mesa_snprintf(message
, sizeof(message
),
1526 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1527 dimensions
, border
);
1528 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1534 /* additional checks for depth textures */
1535 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1536 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1537 if (target
!= GL_TEXTURE_1D
&&
1538 target
!= GL_PROXY_TEXTURE_1D
&&
1539 target
!= GL_TEXTURE_2D
&&
1540 target
!= GL_PROXY_TEXTURE_2D
&&
1541 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1542 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1544 _mesa_error(ctx
, GL_INVALID_ENUM
,
1545 "glTexImage(target/internalFormat)");
1550 /* additional checks for compressed textures */
1551 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1552 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1553 _mesa_error(ctx
, GL_INVALID_ENUM
,
1554 "glTexImage%dD(target)", dimensions
);
1559 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1560 "glTexImage%dD(border!=0)", dimensions
);
1566 /* additional checks for integer textures */
1567 if (ctx
->Extensions
.EXT_texture_integer
&&
1568 (_mesa_is_integer_format(format
) !=
1569 _mesa_is_integer_format(internalFormat
))) {
1571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1572 "glTexImage%dD(integer/non-integer format mismatch)",
1578 /* if we get here, the parameters are OK */
1584 * Test glTexSubImage[123]D() parameters for errors.
1586 * \param ctx GL context.
1587 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1588 * \param target texture target given by the user.
1589 * \param level image level given by the user.
1590 * \param xoffset sub-image x offset given by the user.
1591 * \param yoffset sub-image y offset given by the user.
1592 * \param zoffset sub-image z offset given by the user.
1593 * \param format pixel data format given by the user.
1594 * \param type pixel data type given by the user.
1595 * \param width image width given by the user.
1596 * \param height image height given by the user.
1597 * \param depth image depth given by the user.
1599 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1601 * Verifies each of the parameters against the constants specified in
1602 * __struct gl_contextRec::Const and the supported extensions, and according
1603 * to the OpenGL specification.
1606 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1607 GLenum target
, GLint level
,
1608 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1609 GLint width
, GLint height
, GLint depth
,
1610 GLenum format
, GLenum type
)
1613 if (dimensions
== 1) {
1614 if (target
!= GL_TEXTURE_1D
) {
1615 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1619 else if (dimensions
== 2) {
1620 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1621 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1622 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1623 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1627 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1628 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1629 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1633 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1634 if (!ctx
->Extensions
.MESA_texture_array
) {
1635 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1639 else if (target
!= GL_TEXTURE_2D
) {
1640 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1644 else if (dimensions
== 3) {
1645 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1646 if (!ctx
->Extensions
.MESA_texture_array
) {
1647 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1651 else if (target
!= GL_TEXTURE_3D
) {
1652 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1657 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1661 /* Basic level check */
1662 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1663 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1668 _mesa_error(ctx
, GL_INVALID_VALUE
,
1669 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1672 if (height
< 0 && dimensions
> 1) {
1673 _mesa_error(ctx
, GL_INVALID_VALUE
,
1674 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1677 if (depth
< 0 && dimensions
> 2) {
1678 _mesa_error(ctx
, GL_INVALID_VALUE
,
1679 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1683 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1684 /* As with the glTexImage2D check above, the error code here
1685 * depends on texture integer.
1687 GLenum error
= _mesa_is_integer_format(format
)
1688 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1689 _mesa_error(ctx
, error
,
1690 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1691 dimensions
, format
, type
);
1700 * Do second part of glTexSubImage which depends on the destination texture.
1701 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1704 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1705 GLenum target
, GLint level
,
1706 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1707 GLint width
, GLint height
, GLint depth
,
1708 GLenum format
, GLenum type
,
1709 const struct gl_texture_image
*destTex
)
1712 /* undefined image level */
1713 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1717 if (xoffset
< -((GLint
)destTex
->Border
)) {
1718 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1722 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1723 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1727 if (dimensions
> 1) {
1728 if (yoffset
< -((GLint
)destTex
->Border
)) {
1729 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1733 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1734 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1739 if (dimensions
> 2) {
1740 if (zoffset
< -((GLint
)destTex
->Border
)) {
1741 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1744 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1745 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1750 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1753 if (!target_can_be_compressed(ctx
, target
)) {
1754 _mesa_error(ctx
, GL_INVALID_ENUM
,
1755 "glTexSubImage%dD(target=%s)", dimensions
,
1756 _mesa_lookup_enum_by_nr(target
));
1760 /* do tests which depend on compression block size */
1761 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1763 /* offset must be multiple of block size */
1764 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1765 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1766 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1767 dimensions
, xoffset
, yoffset
);
1770 /* size must be multiple of bw by bh or equal to whole texture size */
1771 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1773 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1776 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1778 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1788 * Test glCopyTexImage[12]D() parameters for errors.
1790 * \param ctx GL context.
1791 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1792 * \param target texture target given by the user.
1793 * \param level image level given by the user.
1794 * \param internalFormat internal format given by the user.
1795 * \param width image width given by the user.
1796 * \param height image height given by the user.
1797 * \param border texture border.
1799 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1801 * Verifies each of the parameters against the constants specified in
1802 * __struct gl_contextRec::Const and the supported extensions, and according
1803 * to the OpenGL specification.
1806 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1807 GLenum target
, GLint level
, GLint internalFormat
,
1808 GLint width
, GLint height
, GLint border
)
1814 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1815 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1816 _mesa_error(ctx
, GL_INVALID_VALUE
,
1817 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1821 /* Check that the source buffer is complete */
1822 if (ctx
->ReadBuffer
->Name
) {
1823 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1824 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1825 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1826 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1832 if (border
< 0 || border
> 1 ||
1833 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1834 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1838 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1840 _mesa_error(ctx
, GL_INVALID_VALUE
,
1841 "glCopyTexImage%dD(internalFormat)", dimensions
);
1845 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1847 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1851 /* NOTE: the format and type aren't really significant for
1852 * TestProxyTexImage(). Only the internalformat really matters.
1856 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1857 * level, width, height and depth.
1859 if (dimensions
== 1) {
1860 if (target
== GL_TEXTURE_1D
) {
1861 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1862 level
, internalFormat
,
1864 width
, 1, 1, border
);
1867 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1871 else if (dimensions
== 2) {
1872 if (target
== GL_TEXTURE_2D
) {
1873 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1874 level
, internalFormat
,
1876 width
, height
, 1, border
);
1878 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1879 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1880 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1881 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1884 sizeOK
= (width
== height
) &&
1885 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1886 level
, internalFormat
, format
, type
,
1887 width
, height
, 1, border
);
1889 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1890 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1891 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1894 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1895 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1896 level
, internalFormat
,
1898 width
, height
, 1, border
);
1900 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1901 if (!ctx
->Extensions
.MESA_texture_array
) {
1902 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1905 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1906 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1907 level
, internalFormat
,
1909 width
, height
, 1, border
);
1912 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1917 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1922 if (dimensions
== 1) {
1923 _mesa_error(ctx
, GL_INVALID_VALUE
,
1924 "glCopyTexImage1D(width=%d)", width
);
1927 ASSERT(dimensions
== 2);
1928 _mesa_error(ctx
, GL_INVALID_VALUE
,
1929 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1934 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1935 if (!target_can_be_compressed(ctx
, target
)) {
1936 _mesa_error(ctx
, GL_INVALID_ENUM
,
1937 "glCopyTexImage%dD(target)", dimensions
);
1941 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1942 "glCopyTexImage%dD(border!=0)", dimensions
);
1946 else if (_mesa_is_depth_format(internalFormat
)) {
1947 /* make sure we have depth/stencil buffers */
1948 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1949 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1950 "glCopyTexImage%dD(no depth)", dimensions
);
1954 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1955 /* make sure we have depth/stencil buffers */
1956 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1957 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1958 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1963 /* if we get here, the parameters are OK */
1969 * Test glCopyTexSubImage[12]D() parameters for errors.
1970 * Note that this is the first part of error checking.
1971 * See also copytexsubimage_error_check2() below for the second part.
1973 * \param ctx GL context.
1974 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1975 * \param target texture target given by the user.
1976 * \param level image level given by the user.
1978 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1981 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
1982 GLenum target
, GLint level
)
1984 /* Check that the source buffer is complete */
1985 if (ctx
->ReadBuffer
->Name
) {
1986 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1987 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1988 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1989 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1995 if (dimensions
== 1) {
1996 if (target
!= GL_TEXTURE_1D
) {
1997 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2001 else if (dimensions
== 2) {
2002 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2003 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2004 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2005 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2009 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2010 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2011 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2015 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2016 if (!ctx
->Extensions
.MESA_texture_array
) {
2017 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2021 else if (target
!= GL_TEXTURE_2D
) {
2022 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2026 else if (dimensions
== 3) {
2027 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2028 (!ctx
->Extensions
.MESA_texture_array
))
2029 && (target
!= GL_TEXTURE_3D
)) {
2030 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2036 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2037 _mesa_error(ctx
, GL_INVALID_VALUE
,
2038 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2047 * Second part of error checking for glCopyTexSubImage[12]D().
2048 * \param xoffset sub-image x offset given by the user.
2049 * \param yoffset sub-image y offset given by the user.
2050 * \param zoffset sub-image z offset given by the user.
2051 * \param width image width given by the user.
2052 * \param height image height given by the user.
2055 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2056 GLenum target
, GLint level
,
2057 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2058 GLsizei width
, GLsizei height
,
2059 const struct gl_texture_image
*teximage
)
2061 /* check that dest tex image exists */
2063 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2064 "glCopyTexSubImage%dD(undefined texture level: %d)",
2071 _mesa_error(ctx
, GL_INVALID_VALUE
,
2072 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2075 if (dimensions
> 1 && height
< 0) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
,
2077 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2081 /* check x/y offsets */
2082 if (xoffset
< -((GLint
)teximage
->Border
)) {
2083 _mesa_error(ctx
, GL_INVALID_VALUE
,
2084 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2087 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2088 _mesa_error(ctx
, GL_INVALID_VALUE
,
2089 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2092 if (dimensions
> 1) {
2093 if (yoffset
< -((GLint
)teximage
->Border
)) {
2094 _mesa_error(ctx
, GL_INVALID_VALUE
,
2095 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2098 /* NOTE: we're adding the border here, not subtracting! */
2099 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2100 _mesa_error(ctx
, GL_INVALID_VALUE
,
2101 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2106 /* check z offset */
2107 if (dimensions
> 2) {
2108 if (zoffset
< -((GLint
)teximage
->Border
)) {
2109 _mesa_error(ctx
, GL_INVALID_VALUE
,
2110 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2113 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2114 _mesa_error(ctx
, GL_INVALID_VALUE
,
2115 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2120 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2121 if (!target_can_be_compressed(ctx
, target
)) {
2122 _mesa_error(ctx
, GL_INVALID_ENUM
,
2123 "glCopyTexSubImage%dD(target)", dimensions
);
2126 /* offset must be multiple of 4 */
2127 if ((xoffset
& 3) || (yoffset
& 3)) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2132 /* size must be multiple of 4 */
2133 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2134 _mesa_error(ctx
, GL_INVALID_VALUE
,
2135 "glCopyTexSubImage%dD(width)", dimensions
);
2138 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2139 _mesa_error(ctx
, GL_INVALID_VALUE
,
2140 "glCopyTexSubImage%dD(height)", dimensions
);
2145 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2146 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2150 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2151 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2152 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2153 dimensions
, teximage
->_BaseFormat
);
2157 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2158 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2159 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2160 "glCopyTexSubImage%dD(no depth buffer)",
2165 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2166 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2167 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2168 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2174 /* If copying into an integer texture, the source buffer must also be
2177 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2178 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2179 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2180 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2181 "glCopyTexSubImage%dD(source buffer is not integer format)",
2187 /* if we get here, the parameters are OK */
2192 /** Callback info for walking over FBO hash table */
2195 struct gl_context
*ctx
;
2196 struct gl_texture_object
*texObj
;
2202 * Check render to texture callback. Called from _mesa_HashWalk().
2205 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2207 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2208 const struct cb_info
*info
= (struct cb_info
*) userData
;
2209 struct gl_context
*ctx
= info
->ctx
;
2210 const struct gl_texture_object
*texObj
= info
->texObj
;
2211 const GLuint level
= info
->level
, face
= info
->face
;
2213 /* If this is a user-created FBO */
2216 /* check if any of the FBO's attachments point to 'texObj' */
2217 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2218 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2219 if (att
->Type
== GL_TEXTURE
&&
2220 att
->Texture
== texObj
&&
2221 att
->TextureLevel
== level
&&
2222 att
->CubeMapFace
== face
) {
2223 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2224 /* Tell driver about the new renderbuffer texture */
2225 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2226 /* Mark fb status as indeterminate to force re-validation */
2235 * When a texture image is specified we have to check if it's bound to
2236 * any framebuffer objects (render to texture) in order to detect changes
2237 * in size or format since that effects FBO completeness.
2238 * Any FBOs rendering into the texture must be re-validated.
2241 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2242 GLuint face
, GLuint level
)
2244 /* Only check this texture if it's been marked as RenderToTexture */
2245 if (texObj
->_RenderToTexture
) {
2246 struct cb_info info
;
2248 info
.texObj
= texObj
;
2251 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2257 * If the texture object's GenerateMipmap flag is set and we've
2258 * changed the texture base level image, regenerate the rest of the
2259 * mipmap levels now.
2262 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2263 struct gl_texture_object
*texObj
, GLint level
)
2265 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2266 if (texObj
->GenerateMipmap
&&
2267 level
== texObj
->BaseLevel
&&
2268 level
< texObj
->MaxLevel
) {
2269 ASSERT(ctx
->Driver
.GenerateMipmap
);
2270 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2275 /** Debug helper: override the user-requested internal format */
2277 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2280 if (internalFormat
== GL_RGBA16F_ARB
||
2281 internalFormat
== GL_RGBA32F_ARB
) {
2282 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2285 else if (internalFormat
== GL_RGB16F_ARB
||
2286 internalFormat
== GL_RGB32F_ARB
) {
2287 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2290 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2291 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2292 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2293 return GL_LUMINANCE_ALPHA
;
2295 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2296 internalFormat
== GL_LUMINANCE32F_ARB
) {
2297 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2298 return GL_LUMINANCE
;
2300 else if (internalFormat
== GL_ALPHA16F_ARB
||
2301 internalFormat
== GL_ALPHA32F_ARB
) {
2302 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2306 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2307 internalFormat = GL_RGBA;
2311 return internalFormat
;
2314 return internalFormat
;
2320 * Choose the actual hardware format for a texture image.
2321 * Try to use the same format as the previous image level when possible.
2322 * Otherwise, ask the driver for the best format.
2323 * It's important to try to choose a consistant format for all levels
2324 * for efficient texture memory layout/allocation. In particular, this
2325 * comes up during automatic mipmap generation.
2328 _mesa_choose_texture_format(struct gl_context
*ctx
,
2329 struct gl_texture_object
*texObj
,
2330 GLenum target
, GLint level
,
2331 GLenum internalFormat
, GLenum format
, GLenum type
)
2335 /* see if we've already chosen a format for the previous level */
2337 struct gl_texture_image
*prevImage
=
2338 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2339 /* See if the prev level is defined and has an internal format which
2340 * matches the new internal format.
2343 prevImage
->Width
> 0 &&
2344 prevImage
->InternalFormat
== internalFormat
) {
2345 /* use the same format */
2346 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2347 return prevImage
->TexFormat
;
2351 /* choose format from scratch */
2352 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2353 ASSERT(f
!= MESA_FORMAT_NONE
);
2360 * Called from the API. Note that width includes the border.
2363 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2364 GLsizei width
, GLint border
, GLenum format
,
2365 GLenum type
, const GLvoid
*pixels
)
2367 GET_CURRENT_CONTEXT(ctx
);
2368 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2370 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2371 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2372 _mesa_lookup_enum_by_nr(target
), level
,
2373 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2374 _mesa_lookup_enum_by_nr(format
),
2375 _mesa_lookup_enum_by_nr(type
), pixels
);
2377 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2379 if (target
== GL_TEXTURE_1D
) {
2380 /* non-proxy target */
2381 struct gl_texture_object
*texObj
;
2382 struct gl_texture_image
*texImage
;
2383 const GLuint face
= _mesa_tex_target_to_face(target
);
2385 if (texture_error_check(ctx
, 1, target
, level
, internalFormat
,
2386 format
, type
, width
, 1, 1, border
)) {
2387 return; /* error was recorded */
2390 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2391 _mesa_update_state(ctx
);
2393 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2394 _mesa_lock_texture(ctx
, texObj
);
2396 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2398 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2401 gl_format texFormat
;
2403 if (texImage
->Data
) {
2404 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2407 ASSERT(texImage
->Data
== NULL
);
2409 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2410 internalFormat
, format
,
2413 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
2414 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2416 border
, internalFormat
,
2419 /* Give the texture to the driver. <pixels> may be null. */
2420 ASSERT(ctx
->Driver
.TexImage1D
);
2421 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2422 width
, border
, format
, type
, pixels
,
2423 &ctx
->Unpack
, texObj
, texImage
);
2425 check_gen_mipmap(ctx
, target
, texObj
, level
);
2427 update_fbo_texture(ctx
, texObj
, face
, level
);
2430 texObj
->_Complete
= GL_FALSE
;
2431 ctx
->NewState
|= _NEW_TEXTURE
;
2434 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2438 _mesa_unlock_texture(ctx
, texObj
);
2440 else if (target
== GL_PROXY_TEXTURE_1D
) {
2441 /* Proxy texture: check for errors and update proxy state */
2442 struct gl_texture_image
*texImage
;
2443 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2444 if (texture_error_check(ctx
, 1, target
, level
, internalFormat
,
2445 format
, type
, width
, 1, 1, border
)) {
2446 /* when error, clear all proxy texture image parameters */
2448 clear_teximage_fields(texImage
);
2451 /* no error, set the tex image parameters */
2452 struct gl_texture_object
*texObj
=
2453 _mesa_get_current_tex_object(ctx
, target
);
2454 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
,
2458 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
2459 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2460 border
, internalFormat
, texFormat
);
2462 else if (texImage
) {
2463 clear_teximage_fields(texImage
);
2468 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2475 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2476 GLsizei width
, GLsizei height
, GLint border
,
2477 GLenum format
, GLenum type
,
2478 const GLvoid
*pixels
)
2480 GET_CURRENT_CONTEXT(ctx
);
2481 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2483 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2484 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2485 _mesa_lookup_enum_by_nr(target
), level
,
2486 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2487 border
, _mesa_lookup_enum_by_nr(format
),
2488 _mesa_lookup_enum_by_nr(type
), pixels
);
2490 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2492 if (target
== GL_TEXTURE_2D
||
2493 (ctx
->Extensions
.ARB_texture_cube_map
&&
2494 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2495 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2496 (ctx
->Extensions
.NV_texture_rectangle
&&
2497 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2498 (ctx
->Extensions
.MESA_texture_array
&&
2499 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2500 /* non-proxy target */
2501 struct gl_texture_object
*texObj
;
2502 struct gl_texture_image
*texImage
;
2503 const GLuint face
= _mesa_tex_target_to_face(target
);
2505 if (texture_error_check(ctx
, 2, target
, level
, internalFormat
,
2506 format
, type
, width
, height
, 1, border
)) {
2507 return; /* error was recorded */
2510 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2511 _mesa_update_state(ctx
);
2513 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2514 _mesa_lock_texture(ctx
, texObj
);
2516 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2518 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2521 gl_format texFormat
;
2523 if (texImage
->Data
) {
2524 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2527 ASSERT(texImage
->Data
== NULL
);
2529 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2530 internalFormat
, format
,
2533 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2534 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
2535 height
, 1, border
, internalFormat
,
2538 /* Give the texture to the driver. <pixels> may be null. */
2539 ASSERT(ctx
->Driver
.TexImage2D
);
2540 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2541 width
, height
, border
, format
, type
,
2542 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2544 check_gen_mipmap(ctx
, target
, texObj
, level
);
2546 update_fbo_texture(ctx
, texObj
, face
, level
);
2549 texObj
->_Complete
= GL_FALSE
;
2550 ctx
->NewState
|= _NEW_TEXTURE
;
2553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2557 _mesa_unlock_texture(ctx
, texObj
);
2559 else if (target
== GL_PROXY_TEXTURE_2D
||
2560 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2561 ctx
->Extensions
.ARB_texture_cube_map
) ||
2562 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2563 ctx
->Extensions
.NV_texture_rectangle
) ||
2564 (ctx
->Extensions
.MESA_texture_array
&&
2565 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2566 /* Proxy texture: check for errors and update proxy state */
2567 struct gl_texture_image
*texImage
;
2568 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2569 if (texture_error_check(ctx
, 2, target
, level
, internalFormat
,
2570 format
, type
, width
, height
, 1, border
)) {
2571 /* when error, clear all proxy texture image parameters */
2573 clear_teximage_fields(texImage
);
2576 /* no error, set the tex image parameters */
2577 struct gl_texture_object
*texObj
=
2578 _mesa_get_current_tex_object(ctx
, target
);
2579 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2583 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
2584 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2585 border
, internalFormat
, texFormat
);
2587 else if (texImage
) {
2588 clear_teximage_fields(texImage
);
2593 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2600 * Called by the API or display list executor.
2601 * Note that width and height include the border.
2604 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2605 GLsizei width
, GLsizei height
, GLsizei depth
,
2606 GLint border
, GLenum format
, GLenum type
,
2607 const GLvoid
*pixels
)
2609 GET_CURRENT_CONTEXT(ctx
);
2610 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2612 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2613 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2614 _mesa_lookup_enum_by_nr(target
), level
,
2615 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2616 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2617 _mesa_lookup_enum_by_nr(type
), pixels
);
2619 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2621 if (target
== GL_TEXTURE_3D
||
2622 (ctx
->Extensions
.MESA_texture_array
&&
2623 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2624 /* non-proxy target */
2625 struct gl_texture_object
*texObj
;
2626 struct gl_texture_image
*texImage
;
2627 const GLuint face
= _mesa_tex_target_to_face(target
);
2629 if (texture_error_check(ctx
, 3, target
, level
, (GLint
) internalFormat
,
2630 format
, type
, width
, height
, depth
, border
)) {
2631 return; /* error was recorded */
2634 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2635 _mesa_update_state(ctx
);
2637 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2638 _mesa_lock_texture(ctx
, texObj
);
2640 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2642 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2645 gl_format texFormat
;
2647 if (texImage
->Data
) {
2648 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2651 ASSERT(texImage
->Data
== NULL
);
2652 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2653 internalFormat
, format
,
2656 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2657 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2658 width
, height
, depth
,
2659 border
, internalFormat
, texFormat
);
2661 /* Give the texture to the driver. <pixels> may be null. */
2662 ASSERT(ctx
->Driver
.TexImage3D
);
2663 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2664 width
, height
, depth
, border
, format
,
2665 type
, pixels
, &ctx
->Unpack
, texObj
,
2668 check_gen_mipmap(ctx
, target
, texObj
, level
);
2670 update_fbo_texture(ctx
, texObj
, face
, level
);
2673 texObj
->_Complete
= GL_FALSE
;
2674 ctx
->NewState
|= _NEW_TEXTURE
;
2677 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2681 _mesa_unlock_texture(ctx
, texObj
);
2683 else if (target
== GL_PROXY_TEXTURE_3D
||
2684 (ctx
->Extensions
.MESA_texture_array
&&
2685 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2686 /* Proxy texture: check for errors and update proxy state */
2687 struct gl_texture_image
*texImage
;
2688 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2689 if (texture_error_check(ctx
, 3, target
, level
, internalFormat
,
2690 format
, type
, width
, height
, depth
, border
)) {
2691 /* when error, clear all proxy texture image parameters */
2693 clear_teximage_fields(texImage
);
2696 /* no error, set the tex image parameters */
2697 struct gl_texture_object
*texObj
=
2698 _mesa_get_current_tex_object(ctx
, target
);
2699 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2703 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2704 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2705 depth
, border
, internalFormat
,
2708 else if (texImage
) {
2709 clear_teximage_fields(texImage
);
2714 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2721 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2722 GLsizei width
, GLsizei height
, GLsizei depth
,
2723 GLint border
, GLenum format
, GLenum type
,
2724 const GLvoid
*pixels
)
2726 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2727 depth
, border
, format
, type
, pixels
);
2731 #if FEATURE_OES_EGL_image
2733 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2735 struct gl_texture_object
*texObj
;
2736 struct gl_texture_image
*texImage
;
2737 GET_CURRENT_CONTEXT(ctx
);
2738 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2740 if (!ctx
->Extensions
.OES_EGL_image
) {
2741 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2742 "glEGLImageTargetTexture2DOES(unsupported)");
2746 if (target
!= GL_TEXTURE_2D
) {
2747 _mesa_error(ctx
, GL_INVALID_ENUM
,
2748 "glEGLImageTargetTexture2D(target=%d)", target
);
2752 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2753 _mesa_update_state(ctx
);
2755 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2756 _mesa_lock_texture(ctx
, texObj
);
2758 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2760 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2763 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2765 ASSERT(texImage
->Data
== NULL
);
2766 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2767 texObj
, texImage
, image
);
2770 texObj
->_Complete
= GL_FALSE
;
2771 ctx
->NewState
|= _NEW_TEXTURE
;
2773 _mesa_unlock_texture(ctx
, texObj
);
2780 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2781 GLint xoffset
, GLsizei width
,
2782 GLenum format
, GLenum type
,
2783 const GLvoid
*pixels
)
2785 struct gl_texture_object
*texObj
;
2786 struct gl_texture_image
*texImage
;
2787 GET_CURRENT_CONTEXT(ctx
);
2788 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2790 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2791 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2792 _mesa_lookup_enum_by_nr(target
), level
,
2793 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2794 _mesa_lookup_enum_by_nr(type
), pixels
);
2796 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2797 _mesa_update_state(ctx
);
2799 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2800 width
, 1, 1, format
, type
)) {
2801 return; /* error was detected */
2805 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2808 _mesa_lock_texture(ctx
, texObj
);
2810 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2812 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2813 width
, 1, 1, format
, type
, texImage
)) {
2814 /* error was recorded */
2816 else if (width
> 0) {
2817 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2818 xoffset
+= texImage
->Border
;
2820 ASSERT(ctx
->Driver
.TexSubImage1D
);
2821 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2822 format
, type
, pixels
, &ctx
->Unpack
,
2825 check_gen_mipmap(ctx
, target
, texObj
, level
);
2827 ctx
->NewState
|= _NEW_TEXTURE
;
2830 _mesa_unlock_texture(ctx
, texObj
);
2835 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2836 GLint xoffset
, GLint yoffset
,
2837 GLsizei width
, GLsizei height
,
2838 GLenum format
, GLenum type
,
2839 const GLvoid
*pixels
)
2841 struct gl_texture_object
*texObj
;
2842 struct gl_texture_image
*texImage
;
2843 GET_CURRENT_CONTEXT(ctx
);
2844 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2846 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2847 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2848 _mesa_lookup_enum_by_nr(target
), level
,
2849 xoffset
, yoffset
, width
, height
,
2850 _mesa_lookup_enum_by_nr(format
),
2851 _mesa_lookup_enum_by_nr(type
), pixels
);
2853 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2854 _mesa_update_state(ctx
);
2856 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2857 width
, height
, 1, format
, type
)) {
2858 return; /* error was detected */
2861 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2863 _mesa_lock_texture(ctx
, texObj
);
2865 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2867 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2868 width
, height
, 1, format
, type
, texImage
)) {
2869 /* error was recorded */
2871 else if (width
> 0 && height
>= 0) {
2872 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2873 xoffset
+= texImage
->Border
;
2874 yoffset
+= texImage
->Border
;
2876 ASSERT(ctx
->Driver
.TexSubImage2D
);
2877 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2878 width
, height
, format
, type
, pixels
,
2879 &ctx
->Unpack
, texObj
, texImage
);
2881 check_gen_mipmap(ctx
, target
, texObj
, level
);
2883 ctx
->NewState
|= _NEW_TEXTURE
;
2886 _mesa_unlock_texture(ctx
, texObj
);
2892 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2893 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2894 GLsizei width
, GLsizei height
, GLsizei depth
,
2895 GLenum format
, GLenum type
,
2896 const GLvoid
*pixels
)
2898 struct gl_texture_object
*texObj
;
2899 struct gl_texture_image
*texImage
;
2900 GET_CURRENT_CONTEXT(ctx
);
2901 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2903 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2904 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2905 _mesa_lookup_enum_by_nr(target
), level
,
2906 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2907 _mesa_lookup_enum_by_nr(format
),
2908 _mesa_lookup_enum_by_nr(type
), pixels
);
2910 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2911 _mesa_update_state(ctx
);
2913 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2914 width
, height
, depth
, format
, type
)) {
2915 return; /* error was detected */
2918 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2920 _mesa_lock_texture(ctx
, texObj
);
2922 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2924 if (subtexture_error_check2(ctx
, 3, target
, level
,
2925 xoffset
, yoffset
, zoffset
,
2926 width
, height
, depth
,
2927 format
, type
, texImage
)) {
2928 /* error was recorded */
2930 else if (width
> 0 && height
> 0 && height
> 0) {
2931 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2932 xoffset
+= texImage
->Border
;
2933 yoffset
+= texImage
->Border
;
2934 zoffset
+= texImage
->Border
;
2936 ASSERT(ctx
->Driver
.TexSubImage3D
);
2937 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2938 xoffset
, yoffset
, zoffset
,
2939 width
, height
, depth
,
2940 format
, type
, pixels
,
2941 &ctx
->Unpack
, texObj
, texImage
);
2943 check_gen_mipmap(ctx
, target
, texObj
, level
);
2945 ctx
->NewState
|= _NEW_TEXTURE
;
2948 _mesa_unlock_texture(ctx
, texObj
);
2954 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2955 GLenum internalFormat
,
2957 GLsizei width
, GLint border
)
2959 struct gl_texture_object
*texObj
;
2960 struct gl_texture_image
*texImage
;
2961 const GLuint face
= _mesa_tex_target_to_face(target
);
2962 GET_CURRENT_CONTEXT(ctx
);
2963 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2965 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2966 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2967 _mesa_lookup_enum_by_nr(target
), level
,
2968 _mesa_lookup_enum_by_nr(internalFormat
),
2969 x
, y
, width
, border
);
2971 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2972 _mesa_update_state(ctx
);
2974 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2978 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2980 _mesa_lock_texture(ctx
, texObj
);
2982 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2984 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2987 gl_format texFormat
;
2989 if (texImage
->Data
) {
2990 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2993 ASSERT(texImage
->Data
== NULL
);
2995 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2996 internalFormat
, GL_NONE
,
2999 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3000 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3001 border
, internalFormat
, texFormat
);
3003 ASSERT(ctx
->Driver
.CopyTexImage1D
);
3004 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
3005 x
, y
, width
, border
);
3007 check_gen_mipmap(ctx
, target
, texObj
, level
);
3009 update_fbo_texture(ctx
, texObj
, face
, level
);
3012 texObj
->_Complete
= GL_FALSE
;
3013 ctx
->NewState
|= _NEW_TEXTURE
;
3016 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
3020 _mesa_unlock_texture(ctx
, texObj
);
3026 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3027 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3030 struct gl_texture_object
*texObj
;
3031 struct gl_texture_image
*texImage
;
3032 const GLuint face
= _mesa_tex_target_to_face(target
);
3033 GET_CURRENT_CONTEXT(ctx
);
3034 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3036 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3037 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
3038 _mesa_lookup_enum_by_nr(target
), level
,
3039 _mesa_lookup_enum_by_nr(internalFormat
),
3040 x
, y
, width
, height
, border
);
3042 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3043 _mesa_update_state(ctx
);
3045 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3046 width
, height
, border
))
3049 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3051 _mesa_lock_texture(ctx
, texObj
);
3053 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3056 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3059 gl_format texFormat
;
3061 if (texImage
->Data
) {
3062 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3065 ASSERT(texImage
->Data
== NULL
);
3067 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3068 internalFormat
, GL_NONE
,
3071 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
3072 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3073 border
, internalFormat
, texFormat
);
3075 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3076 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
3077 x
, y
, width
, height
, border
);
3079 check_gen_mipmap(ctx
, target
, texObj
, level
);
3081 update_fbo_texture(ctx
, texObj
, face
, level
);
3084 texObj
->_Complete
= GL_FALSE
;
3085 ctx
->NewState
|= _NEW_TEXTURE
;
3088 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3092 _mesa_unlock_texture(ctx
, texObj
);
3097 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3098 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3100 struct gl_texture_object
*texObj
;
3101 struct gl_texture_image
*texImage
;
3105 GET_CURRENT_CONTEXT(ctx
);
3106 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3108 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3109 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
3110 _mesa_lookup_enum_by_nr(target
),
3111 level
, xoffset
, x
, y
, width
);
3113 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3114 _mesa_update_state(ctx
);
3116 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3119 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3121 _mesa_lock_texture(ctx
, texObj
);
3123 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3125 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3126 xoffset
, 0, 0, width
, 1, texImage
)) {
3127 /* error was recorded */
3130 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3131 xoffset
+= texImage
->Border
;
3133 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3135 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3136 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3137 xoffset
, x
, y
, width
);
3139 check_gen_mipmap(ctx
, target
, texObj
, level
);
3141 ctx
->NewState
|= _NEW_TEXTURE
;
3145 _mesa_unlock_texture(ctx
, texObj
);
3151 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3152 GLint xoffset
, GLint yoffset
,
3153 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3155 struct gl_texture_object
*texObj
;
3156 struct gl_texture_image
*texImage
;
3157 GET_CURRENT_CONTEXT(ctx
);
3158 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3160 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3161 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
3162 _mesa_lookup_enum_by_nr(target
),
3163 level
, xoffset
, yoffset
, x
, y
, width
, height
);
3165 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3166 _mesa_update_state(ctx
);
3168 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3171 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3173 _mesa_lock_texture(ctx
, texObj
);
3175 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3177 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
3178 xoffset
, yoffset
, 0,
3179 width
, height
, texImage
)) {
3180 /* error was recorded */
3183 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3184 xoffset
+= texImage
->Border
;
3185 yoffset
+= texImage
->Border
;
3187 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3189 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3190 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
3191 x
, y
, width
, height
);
3193 check_gen_mipmap(ctx
, target
, texObj
, level
);
3195 ctx
->NewState
|= _NEW_TEXTURE
;
3199 _mesa_unlock_texture(ctx
, texObj
);
3205 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3206 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3207 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3209 struct gl_texture_object
*texObj
;
3210 struct gl_texture_image
*texImage
;
3211 GET_CURRENT_CONTEXT(ctx
);
3212 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3214 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3215 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
3216 _mesa_lookup_enum_by_nr(target
),
3217 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3219 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3220 _mesa_update_state(ctx
);
3222 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3225 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3227 _mesa_lock_texture(ctx
, texObj
);
3229 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3231 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3232 zoffset
, width
, height
, texImage
)) {
3233 /* error was recored */
3236 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3237 xoffset
+= texImage
->Border
;
3238 yoffset
+= texImage
->Border
;
3239 zoffset
+= texImage
->Border
;
3241 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3243 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3244 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3245 xoffset
, yoffset
, zoffset
,
3246 x
, y
, width
, height
);
3248 check_gen_mipmap(ctx
, target
, texObj
, level
);
3250 ctx
->NewState
|= _NEW_TEXTURE
;
3254 _mesa_unlock_texture(ctx
, texObj
);
3260 /**********************************************************************/
3261 /****** Compressed Textures ******/
3262 /**********************************************************************/
3266 * Return expected size of a compressed texture.
3269 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3272 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3273 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3278 * Return compressed texture block size, in pixels.
3281 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3283 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3284 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3289 * Error checking for glCompressedTexImage[123]D().
3290 * \return error code or GL_NO_ERROR.
3293 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3294 GLenum target
, GLint level
,
3295 GLenum internalFormat
, GLsizei width
,
3296 GLsizei height
, GLsizei depth
, GLint border
,
3299 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3301 if (dimensions
== 1) {
3302 /* 1D compressed textures not allowed */
3303 return GL_INVALID_ENUM
;
3305 else if (dimensions
== 2) {
3306 if (target
== GL_PROXY_TEXTURE_2D
) {
3307 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3309 else if (target
== GL_TEXTURE_2D
) {
3310 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3312 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3313 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3314 return GL_INVALID_ENUM
; /*target*/
3315 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3317 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3318 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3319 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3320 return GL_INVALID_ENUM
; /*target*/
3321 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3324 return GL_INVALID_ENUM
; /*target*/
3327 else if (dimensions
== 3) {
3328 /* 3D compressed textures not allowed */
3329 return GL_INVALID_ENUM
;
3333 return GL_INVALID_ENUM
;
3336 maxTextureSize
= 1 << (maxLevels
- 1);
3338 /* This will detect any invalid internalFormat value */
3339 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3340 return GL_INVALID_ENUM
;
3342 /* This should really never fail */
3343 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3344 return GL_INVALID_ENUM
;
3347 return GL_INVALID_VALUE
;
3350 * XXX We should probably use the proxy texture error check function here.
3352 if (width
< 1 || width
> maxTextureSize
||
3353 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3354 return GL_INVALID_VALUE
;
3356 if ((height
< 1 || height
> maxTextureSize
||
3357 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3359 return GL_INVALID_VALUE
;
3361 if ((depth
< 1 || depth
> maxTextureSize
||
3362 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3364 return GL_INVALID_VALUE
;
3366 /* For cube map, width must equal height */
3367 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3368 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3369 return GL_INVALID_VALUE
;
3371 if (level
< 0 || level
>= maxLevels
)
3372 return GL_INVALID_VALUE
;
3374 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3375 if (expectedSize
!= imageSize
)
3376 return GL_INVALID_VALUE
;
3378 #if FEATURE_EXT_texture_sRGB
3379 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3380 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3381 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3382 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3384 return GL_INVALID_OPERATION
;
3393 * Error checking for glCompressedTexSubImage[123]D().
3394 * \warning There are some bad assumptions here about the size of compressed
3395 * texture tiles (multiple of 4) used to test the validity of the
3396 * offset and size parameters.
3397 * \return error code or GL_NO_ERROR.
3400 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3401 GLenum target
, GLint level
,
3402 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3403 GLsizei width
, GLsizei height
, GLsizei depth
,
3404 GLenum format
, GLsizei imageSize
)
3406 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3410 if (dimensions
== 1) {
3411 /* 1D compressed textures not allowed */
3412 return GL_INVALID_ENUM
;
3414 else if (dimensions
== 2) {
3415 if (target
== GL_PROXY_TEXTURE_2D
) {
3416 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3418 else if (target
== GL_TEXTURE_2D
) {
3419 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3421 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3422 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3423 return GL_INVALID_ENUM
; /*target*/
3424 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3426 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3427 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3428 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3429 return GL_INVALID_ENUM
; /*target*/
3430 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3433 return GL_INVALID_ENUM
; /*target*/
3436 else if (dimensions
== 3) {
3437 /* 3D compressed textures not allowed */
3438 return GL_INVALID_ENUM
;
3441 maxTextureSize
= 1 << (maxLevels
- 1);
3443 /* this will catch any invalid compressed format token */
3444 if (!_mesa_is_compressed_format(ctx
, format
))
3445 return GL_INVALID_ENUM
;
3447 if (width
< 1 || width
> maxTextureSize
)
3448 return GL_INVALID_VALUE
;
3450 if ((height
< 1 || height
> maxTextureSize
)
3452 return GL_INVALID_VALUE
;
3454 if (level
< 0 || level
>= maxLevels
)
3455 return GL_INVALID_VALUE
;
3458 * do checks which depend on compression block size
3460 get_compressed_block_size(format
, &bw
, &bh
);
3462 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3463 return GL_INVALID_VALUE
;
3465 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3466 return GL_INVALID_VALUE
;
3468 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3469 return GL_INVALID_VALUE
;
3471 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3472 if (expectedSize
!= imageSize
)
3473 return GL_INVALID_VALUE
;
3480 * Do second part of glCompressedTexSubImage error checking.
3481 * \return GL_TRUE if error found, GL_FALSE otherwise.
3484 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3485 GLsizei width
, GLsizei height
,
3486 GLsizei depth
, GLenum format
,
3487 struct gl_texture_image
*texImage
)
3490 if ((GLint
) format
!= texImage
->InternalFormat
) {
3491 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3492 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3496 if (((width
== 1 || width
== 2) &&
3497 width
!= (GLsizei
) texImage
->Width
) ||
3498 (width
> (GLsizei
) texImage
->Width
)) {
3499 _mesa_error(ctx
, GL_INVALID_VALUE
,
3500 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3505 if (((height
== 1 || height
== 2) &&
3506 height
!= (GLsizei
) texImage
->Height
) ||
3507 (height
> (GLsizei
) texImage
->Height
)) {
3508 _mesa_error(ctx
, GL_INVALID_VALUE
,
3509 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3515 if (((depth
== 1 || depth
== 2) &&
3516 depth
!= (GLsizei
) texImage
->Depth
) ||
3517 (depth
> (GLsizei
) texImage
->Depth
)) {
3518 _mesa_error(ctx
, GL_INVALID_VALUE
,
3519 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3530 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3531 GLenum internalFormat
, GLsizei width
,
3532 GLint border
, GLsizei imageSize
,
3535 GET_CURRENT_CONTEXT(ctx
);
3536 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3538 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3539 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3540 _mesa_lookup_enum_by_nr(target
), level
,
3541 _mesa_lookup_enum_by_nr(internalFormat
),
3542 width
, border
, imageSize
, data
);
3544 if (target
== GL_TEXTURE_1D
) {
3545 /* non-proxy target */
3546 struct gl_texture_object
*texObj
;
3547 struct gl_texture_image
*texImage
;
3548 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3549 internalFormat
, width
, 1, 1, border
, imageSize
);
3551 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3555 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3557 _mesa_lock_texture(ctx
, texObj
);
3559 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3561 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3564 gl_format texFormat
;
3566 if (texImage
->Data
) {
3567 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3569 ASSERT(texImage
->Data
== NULL
);
3571 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3572 internalFormat
, GL_NONE
,
3575 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3576 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3577 border
, internalFormat
, texFormat
);
3579 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3580 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3581 internalFormat
, width
, border
,
3585 check_gen_mipmap(ctx
, target
, texObj
, level
);
3588 texObj
->_Complete
= GL_FALSE
;
3589 ctx
->NewState
|= _NEW_TEXTURE
;
3592 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3596 _mesa_unlock_texture(ctx
, texObj
);
3598 else if (target
== GL_PROXY_TEXTURE_1D
) {
3599 /* Proxy texture: check for errors and update proxy state */
3600 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3601 internalFormat
, width
, 1, 1, border
, imageSize
);
3603 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3604 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3605 internalFormat
, GL_NONE
, GL_NONE
,
3606 width
, 1, 1, border
);
3609 /* if error, clear all proxy texture image parameters */
3610 struct gl_texture_image
*texImage
;
3611 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3613 clear_teximage_fields(texImage
);
3616 /* store the teximage parameters */
3617 struct gl_texture_object
*texObj
;
3618 struct gl_texture_image
*texImage
;
3619 gl_format texFormat
;
3621 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3623 _mesa_lock_texture(ctx
, texObj
);
3625 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3626 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3627 internalFormat
, GL_NONE
,
3629 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3630 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3631 border
, internalFormat
, texFormat
);
3633 else if (texImage
) {
3634 clear_teximage_fields(texImage
);
3637 _mesa_unlock_texture(ctx
, texObj
);
3641 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3647 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3648 GLenum internalFormat
, GLsizei width
,
3649 GLsizei height
, GLint border
, GLsizei imageSize
,
3652 GET_CURRENT_CONTEXT(ctx
);
3653 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3655 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3656 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3657 _mesa_lookup_enum_by_nr(target
), level
,
3658 _mesa_lookup_enum_by_nr(internalFormat
),
3659 width
, height
, border
, imageSize
, data
);
3662 switch (internalFormat
) {
3663 case GL_PALETTE4_RGB8_OES
:
3664 case GL_PALETTE4_RGBA8_OES
:
3665 case GL_PALETTE4_R5_G6_B5_OES
:
3666 case GL_PALETTE4_RGBA4_OES
:
3667 case GL_PALETTE4_RGB5_A1_OES
:
3668 case GL_PALETTE8_RGB8_OES
:
3669 case GL_PALETTE8_RGBA8_OES
:
3670 case GL_PALETTE8_R5_G6_B5_OES
:
3671 case GL_PALETTE8_RGBA4_OES
:
3672 case GL_PALETTE8_RGB5_A1_OES
:
3673 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3674 width
, height
, imageSize
, data
);
3679 if (target
== GL_TEXTURE_2D
||
3680 (ctx
->Extensions
.ARB_texture_cube_map
&&
3681 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3682 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3683 /* non-proxy target */
3684 struct gl_texture_object
*texObj
;
3685 struct gl_texture_image
*texImage
;
3687 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3688 internalFormat
, width
, height
, 1, border
, imageSize
);
3690 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3694 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3696 _mesa_lock_texture(ctx
, texObj
);
3698 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3700 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3703 gl_format texFormat
;
3705 if (texImage
->Data
) {
3706 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3708 ASSERT(texImage
->Data
== NULL
);
3710 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3711 internalFormat
, GL_NONE
,
3714 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3715 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
3716 height
, 1, border
, internalFormat
,
3719 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3720 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3721 internalFormat
, width
, height
,
3722 border
, imageSize
, data
,
3725 check_gen_mipmap(ctx
, target
, texObj
, level
);
3728 texObj
->_Complete
= GL_FALSE
;
3729 ctx
->NewState
|= _NEW_TEXTURE
;
3732 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3736 _mesa_unlock_texture(ctx
, texObj
);
3738 else if (target
== GL_PROXY_TEXTURE_2D
||
3739 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3740 ctx
->Extensions
.ARB_texture_cube_map
)) {
3741 /* Proxy texture: check for errors and update proxy state */
3742 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3743 internalFormat
, width
, height
, 1, border
, imageSize
);
3745 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3746 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3747 internalFormat
, GL_NONE
, GL_NONE
,
3748 width
, height
, 1, border
);
3751 /* if error, clear all proxy texture image parameters */
3752 struct gl_texture_image
*texImage
;
3753 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3755 clear_teximage_fields(texImage
);
3758 /* store the teximage parameters */
3759 struct gl_texture_object
*texObj
;
3760 struct gl_texture_image
*texImage
;
3761 gl_format texFormat
;
3763 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3765 _mesa_lock_texture(ctx
, texObj
);
3767 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3768 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3769 internalFormat
, GL_NONE
,
3771 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
3772 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
3773 height
, 1, border
, internalFormat
,
3777 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3780 _mesa_unlock_texture(ctx
, texObj
);
3784 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3791 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3792 GLenum internalFormat
, GLsizei width
,
3793 GLsizei height
, GLsizei depth
, GLint border
,
3794 GLsizei imageSize
, const GLvoid
*data
)
3796 GET_CURRENT_CONTEXT(ctx
);
3797 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3799 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3800 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3801 _mesa_lookup_enum_by_nr(target
), level
,
3802 _mesa_lookup_enum_by_nr(internalFormat
),
3803 width
, height
, depth
, border
, imageSize
, data
);
3805 if (target
== GL_TEXTURE_3D
) {
3806 /* non-proxy target */
3807 struct gl_texture_object
*texObj
;
3808 struct gl_texture_image
*texImage
;
3809 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3810 internalFormat
, width
, height
, depth
, border
, imageSize
);
3812 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3816 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3818 _mesa_lock_texture(ctx
, texObj
);
3820 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3822 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3825 gl_format texFormat
;
3827 if (texImage
->Data
) {
3828 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3830 ASSERT(texImage
->Data
== NULL
);
3832 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3833 internalFormat
, GL_NONE
,
3836 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3837 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3838 width
, height
, depth
,
3839 border
, internalFormat
, texFormat
);
3841 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3842 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3844 width
, height
, depth
,
3845 border
, imageSize
, data
,
3848 check_gen_mipmap(ctx
, target
, texObj
, level
);
3851 texObj
->_Complete
= GL_FALSE
;
3852 ctx
->NewState
|= _NEW_TEXTURE
;
3855 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3859 _mesa_unlock_texture(ctx
, texObj
);
3861 else if (target
== GL_PROXY_TEXTURE_3D
) {
3862 /* Proxy texture: check for errors and update proxy state */
3863 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3864 internalFormat
, width
, height
, depth
, border
, imageSize
);
3866 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3867 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3868 internalFormat
, GL_NONE
, GL_NONE
,
3869 width
, height
, depth
, border
);
3872 /* if error, clear all proxy texture image parameters */
3873 struct gl_texture_image
*texImage
;
3874 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3876 clear_teximage_fields(texImage
);
3879 /* store the teximage parameters */
3880 struct gl_texture_object
*texObj
;
3881 struct gl_texture_image
*texImage
;
3882 gl_format texFormat
;
3884 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3886 _mesa_lock_texture(ctx
, texObj
);
3888 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3889 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3890 internalFormat
, GL_NONE
,
3892 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3893 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3894 depth
, border
, internalFormat
,
3897 else if (texImage
) {
3898 clear_teximage_fields(texImage
);
3901 _mesa_unlock_texture(ctx
, texObj
);
3905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3912 * Common helper for glCompressedTexSubImage1/2/3D().
3915 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3916 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3917 GLsizei width
, GLsizei height
, GLsizei depth
,
3918 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3920 struct gl_texture_object
*texObj
;
3921 struct gl_texture_image
*texImage
;
3923 GET_CURRENT_CONTEXT(ctx
);
3924 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3926 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3927 xoffset
, 0, 0, /* pos */
3928 width
, height
, depth
, /* size */
3931 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3935 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3937 _mesa_lock_texture(ctx
, texObj
);
3939 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3942 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3943 format
, texImage
)) {
3944 /* error was recorded */
3946 else if (width
> 0 && height
> 0 && depth
> 0) {
3949 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3950 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3952 format
, imageSize
, data
,
3957 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3958 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3961 format
, imageSize
, data
,
3966 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3967 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3968 xoffset
, yoffset
, zoffset
,
3969 width
, height
, depth
,
3970 format
, imageSize
, data
,
3978 check_gen_mipmap(ctx
, target
, texObj
, level
);
3980 ctx
->NewState
|= _NEW_TEXTURE
;
3983 _mesa_unlock_texture(ctx
, texObj
);
3988 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3989 GLsizei width
, GLenum format
,
3990 GLsizei imageSize
, const GLvoid
*data
)
3992 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3993 format
, imageSize
, data
);
3998 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3999 GLint yoffset
, GLsizei width
, GLsizei height
,
4000 GLenum format
, GLsizei imageSize
,
4003 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
4004 width
, height
, 1, format
, imageSize
, data
);
4009 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
4010 GLint yoffset
, GLint zoffset
, GLsizei width
,
4011 GLsizei height
, GLsizei depth
, GLenum format
,
4012 GLsizei imageSize
, const GLvoid
*data
)
4014 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4015 width
, height
, depth
, format
, imageSize
, data
);