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 * Check if the given texture target value is legal for a
1323 * glTexImage1/2/3D call.
1326 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1332 case GL_PROXY_TEXTURE_1D
:
1340 case GL_PROXY_TEXTURE_2D
:
1342 case GL_PROXY_TEXTURE_CUBE_MAP
:
1343 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1344 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1345 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1346 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1347 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1348 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1349 return ctx
->Extensions
.ARB_texture_cube_map
;
1350 case GL_TEXTURE_RECTANGLE_NV
:
1351 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1352 return ctx
->Extensions
.NV_texture_rectangle
;
1353 case GL_TEXTURE_1D_ARRAY_EXT
:
1354 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1355 return ctx
->Extensions
.MESA_texture_array
;
1362 case GL_PROXY_TEXTURE_3D
:
1364 case GL_TEXTURE_2D_ARRAY_EXT
:
1365 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1366 return ctx
->Extensions
.MESA_texture_array
;
1371 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1378 * Test the glTexImage[123]D() parameters for errors.
1380 * \param ctx GL context.
1381 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1382 * \param target texture target given by the user.
1383 * \param level image level given by the user.
1384 * \param internalFormat internal format given by the user.
1385 * \param format pixel data format given by the user.
1386 * \param type pixel data type given by the user.
1387 * \param width image width given by the user.
1388 * \param height image height given by the user.
1389 * \param depth image depth given by the user.
1390 * \param border image border given by the user.
1392 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1394 * Verifies each of the parameters against the constants specified in
1395 * __struct gl_contextRec::Const and the supported extensions, and according
1396 * to the OpenGL specification.
1399 texture_error_check( struct gl_context
*ctx
,
1400 GLuint dimensions
, GLenum target
,
1401 GLint level
, GLint internalFormat
,
1402 GLenum format
, GLenum type
,
1403 GLint width
, GLint height
,
1404 GLint depth
, GLint border
)
1406 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1407 GLboolean sizeOK
= GL_TRUE
;
1408 GLboolean colorFormat
, indexFormat
;
1409 GLenum proxy_target
;
1411 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1412 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1414 _mesa_error(ctx
, GL_INVALID_VALUE
,
1415 "glTexImage%dD(level=%d)", dimensions
, level
);
1421 if (border
< 0 || border
> 1 ||
1422 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1423 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1425 _mesa_error(ctx
, GL_INVALID_VALUE
,
1426 "glTexImage%dD(border=%d)", dimensions
, border
);
1431 if (width
< 0 || height
< 0 || depth
< 0) {
1433 _mesa_error(ctx
, GL_INVALID_VALUE
,
1434 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1439 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1440 * level, width, height and depth.
1442 if (dimensions
== 1) {
1443 proxy_target
= GL_PROXY_TEXTURE_1D
;
1447 else if (dimensions
== 2) {
1449 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1450 proxy_target
= GL_PROXY_TEXTURE_2D
;
1452 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1453 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1454 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1455 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1456 sizeOK
= (width
== height
);
1458 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1459 target
== GL_TEXTURE_RECTANGLE_NV
) {
1460 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1462 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1463 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1464 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1467 _mesa_problem(ctx
, "unexpected target in texture_error_check()");
1472 assert(dimensions
== 3);
1474 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1475 proxy_target
= GL_PROXY_TEXTURE_3D
;
1477 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1478 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1479 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1482 _mesa_problem(ctx
, "unexpected target in texture_error_check()");
1487 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1488 internalFormat
, format
,
1489 type
, width
, height
,
1493 _mesa_error(ctx
, GL_INVALID_VALUE
,
1494 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1495 dimensions
, level
, width
, height
, depth
);
1500 /* Check internalFormat */
1501 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1503 _mesa_error(ctx
, GL_INVALID_VALUE
,
1504 "glTexImage%dD(internalFormat=%s)",
1505 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1510 /* Check incoming image format and type */
1511 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1512 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1513 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1514 * GL_EXT_texture_integer extension, some combinations should generate
1515 * GL_INVALID_ENUM instead (grr!).
1518 GLenum error
= _mesa_is_integer_format(format
)
1519 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1520 _mesa_error(ctx
, error
,
1521 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1522 dimensions
, format
, type
);
1527 /* make sure internal format and format basically agree */
1528 colorFormat
= _mesa_is_color_format(format
);
1529 indexFormat
= _mesa_is_index_format(format
);
1530 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1531 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1532 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1533 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1534 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1535 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1537 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1538 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1539 dimensions
, internalFormat
, format
);
1543 /* additional checks for ycbcr textures */
1544 if (internalFormat
== GL_YCBCR_MESA
) {
1545 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1546 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1547 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1549 _mesa_snprintf(message
, sizeof(message
),
1550 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1551 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1552 return GL_TRUE
; /* error */
1554 if (target
!= GL_TEXTURE_2D
&&
1555 target
!= GL_PROXY_TEXTURE_2D
&&
1556 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1557 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1559 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1565 _mesa_snprintf(message
, sizeof(message
),
1566 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1567 dimensions
, border
);
1568 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1574 /* additional checks for depth textures */
1575 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1576 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1577 if (target
!= GL_TEXTURE_1D
&&
1578 target
!= GL_PROXY_TEXTURE_1D
&&
1579 target
!= GL_TEXTURE_2D
&&
1580 target
!= GL_PROXY_TEXTURE_2D
&&
1581 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1582 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1584 _mesa_error(ctx
, GL_INVALID_ENUM
,
1585 "glTexImage(target/internalFormat)");
1590 /* additional checks for compressed textures */
1591 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1592 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1593 _mesa_error(ctx
, GL_INVALID_ENUM
,
1594 "glTexImage%dD(target)", dimensions
);
1599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1600 "glTexImage%dD(border!=0)", dimensions
);
1606 /* additional checks for integer textures */
1607 if (ctx
->Extensions
.EXT_texture_integer
&&
1608 (_mesa_is_integer_format(format
) !=
1609 _mesa_is_integer_format(internalFormat
))) {
1611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1612 "glTexImage%dD(integer/non-integer format mismatch)",
1618 /* if we get here, the parameters are OK */
1624 * Test glTexSubImage[123]D() parameters for errors.
1626 * \param ctx GL context.
1627 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1628 * \param target texture target given by the user.
1629 * \param level image level given by the user.
1630 * \param xoffset sub-image x offset given by the user.
1631 * \param yoffset sub-image y offset given by the user.
1632 * \param zoffset sub-image z offset given by the user.
1633 * \param format pixel data format given by the user.
1634 * \param type pixel data type given by the user.
1635 * \param width image width given by the user.
1636 * \param height image height given by the user.
1637 * \param depth image depth given by the user.
1639 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1641 * Verifies each of the parameters against the constants specified in
1642 * __struct gl_contextRec::Const and the supported extensions, and according
1643 * to the OpenGL specification.
1646 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1647 GLenum target
, GLint level
,
1648 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1649 GLint width
, GLint height
, GLint depth
,
1650 GLenum format
, GLenum type
)
1653 if (dimensions
== 1) {
1654 if (target
!= GL_TEXTURE_1D
) {
1655 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1659 else if (dimensions
== 2) {
1660 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1661 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1662 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1663 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1667 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1668 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1669 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1673 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1674 if (!ctx
->Extensions
.MESA_texture_array
) {
1675 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1679 else if (target
!= GL_TEXTURE_2D
) {
1680 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1684 else if (dimensions
== 3) {
1685 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1686 if (!ctx
->Extensions
.MESA_texture_array
) {
1687 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1691 else if (target
!= GL_TEXTURE_3D
) {
1692 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1697 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1701 /* Basic level check */
1702 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1703 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1708 _mesa_error(ctx
, GL_INVALID_VALUE
,
1709 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1712 if (height
< 0 && dimensions
> 1) {
1713 _mesa_error(ctx
, GL_INVALID_VALUE
,
1714 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1717 if (depth
< 0 && dimensions
> 2) {
1718 _mesa_error(ctx
, GL_INVALID_VALUE
,
1719 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1723 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1724 /* As with the glTexImage2D check above, the error code here
1725 * depends on texture integer.
1727 GLenum error
= _mesa_is_integer_format(format
)
1728 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1729 _mesa_error(ctx
, error
,
1730 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1731 dimensions
, format
, type
);
1740 * Do second part of glTexSubImage which depends on the destination texture.
1741 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1744 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1745 GLenum target
, GLint level
,
1746 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1747 GLint width
, GLint height
, GLint depth
,
1748 GLenum format
, GLenum type
,
1749 const struct gl_texture_image
*destTex
)
1752 /* undefined image level */
1753 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1757 if (xoffset
< -((GLint
)destTex
->Border
)) {
1758 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1762 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1767 if (dimensions
> 1) {
1768 if (yoffset
< -((GLint
)destTex
->Border
)) {
1769 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1773 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1774 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1779 if (dimensions
> 2) {
1780 if (zoffset
< -((GLint
)destTex
->Border
)) {
1781 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1784 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1785 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1790 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1793 if (!target_can_be_compressed(ctx
, target
)) {
1794 _mesa_error(ctx
, GL_INVALID_ENUM
,
1795 "glTexSubImage%dD(target=%s)", dimensions
,
1796 _mesa_lookup_enum_by_nr(target
));
1800 /* do tests which depend on compression block size */
1801 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1803 /* offset must be multiple of block size */
1804 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1805 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1806 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1807 dimensions
, xoffset
, yoffset
);
1810 /* size must be multiple of bw by bh or equal to whole texture size */
1811 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1812 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1813 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1816 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1817 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1818 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1828 * Test glCopyTexImage[12]D() parameters for errors.
1830 * \param ctx GL context.
1831 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1832 * \param target texture target given by the user.
1833 * \param level image level given by the user.
1834 * \param internalFormat internal format given by the user.
1835 * \param width image width given by the user.
1836 * \param height image height given by the user.
1837 * \param border texture border.
1839 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1841 * Verifies each of the parameters against the constants specified in
1842 * __struct gl_contextRec::Const and the supported extensions, and according
1843 * to the OpenGL specification.
1846 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1847 GLenum target
, GLint level
, GLint internalFormat
,
1848 GLint width
, GLint height
, GLint border
)
1854 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1855 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1856 _mesa_error(ctx
, GL_INVALID_VALUE
,
1857 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1861 /* Check that the source buffer is complete */
1862 if (ctx
->ReadBuffer
->Name
) {
1863 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1864 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1865 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1866 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1872 if (border
< 0 || border
> 1 ||
1873 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1874 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1878 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1880 _mesa_error(ctx
, GL_INVALID_VALUE
,
1881 "glCopyTexImage%dD(internalFormat)", dimensions
);
1885 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1886 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1887 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1891 /* NOTE: the format and type aren't really significant for
1892 * TestProxyTexImage(). Only the internalformat really matters.
1896 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1897 * level, width, height and depth.
1899 if (dimensions
== 1) {
1900 if (target
== GL_TEXTURE_1D
) {
1901 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1902 level
, internalFormat
,
1904 width
, 1, 1, border
);
1907 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1911 else if (dimensions
== 2) {
1912 if (target
== GL_TEXTURE_2D
) {
1913 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1914 level
, internalFormat
,
1916 width
, height
, 1, border
);
1918 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1919 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1920 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1921 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1924 sizeOK
= (width
== height
) &&
1925 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1926 level
, internalFormat
, format
, type
,
1927 width
, height
, 1, border
);
1929 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1930 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1931 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1934 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1935 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1936 level
, internalFormat
,
1938 width
, height
, 1, border
);
1940 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1941 if (!ctx
->Extensions
.MESA_texture_array
) {
1942 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1945 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1946 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1947 level
, internalFormat
,
1949 width
, height
, 1, border
);
1952 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1957 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1962 if (dimensions
== 1) {
1963 _mesa_error(ctx
, GL_INVALID_VALUE
,
1964 "glCopyTexImage1D(width=%d)", width
);
1967 ASSERT(dimensions
== 2);
1968 _mesa_error(ctx
, GL_INVALID_VALUE
,
1969 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1974 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1975 if (!target_can_be_compressed(ctx
, target
)) {
1976 _mesa_error(ctx
, GL_INVALID_ENUM
,
1977 "glCopyTexImage%dD(target)", dimensions
);
1981 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1982 "glCopyTexImage%dD(border!=0)", dimensions
);
1986 else if (_mesa_is_depth_format(internalFormat
)) {
1987 /* make sure we have depth/stencil buffers */
1988 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1989 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1990 "glCopyTexImage%dD(no depth)", dimensions
);
1994 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1995 /* make sure we have depth/stencil buffers */
1996 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1998 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
2003 /* if we get here, the parameters are OK */
2009 * Test glCopyTexSubImage[12]D() parameters for errors.
2010 * Note that this is the first part of error checking.
2011 * See also copytexsubimage_error_check2() below for the second part.
2013 * \param ctx GL context.
2014 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2015 * \param target texture target given by the user.
2016 * \param level image level given by the user.
2018 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2021 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2022 GLenum target
, GLint level
)
2024 /* Check that the source buffer is complete */
2025 if (ctx
->ReadBuffer
->Name
) {
2026 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2027 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2028 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2029 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2035 if (dimensions
== 1) {
2036 if (target
!= GL_TEXTURE_1D
) {
2037 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2041 else if (dimensions
== 2) {
2042 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2043 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2044 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2045 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2049 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2050 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2051 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2055 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2056 if (!ctx
->Extensions
.MESA_texture_array
) {
2057 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2061 else if (target
!= GL_TEXTURE_2D
) {
2062 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2066 else if (dimensions
== 3) {
2067 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2068 (!ctx
->Extensions
.MESA_texture_array
))
2069 && (target
!= GL_TEXTURE_3D
)) {
2070 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2076 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2077 _mesa_error(ctx
, GL_INVALID_VALUE
,
2078 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2087 * Second part of error checking for glCopyTexSubImage[12]D().
2088 * \param xoffset sub-image x offset given by the user.
2089 * \param yoffset sub-image y offset given by the user.
2090 * \param zoffset sub-image z offset given by the user.
2091 * \param width image width given by the user.
2092 * \param height image height given by the user.
2095 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2096 GLenum target
, GLint level
,
2097 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2098 GLsizei width
, GLsizei height
,
2099 const struct gl_texture_image
*teximage
)
2101 /* check that dest tex image exists */
2103 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2104 "glCopyTexSubImage%dD(undefined texture level: %d)",
2111 _mesa_error(ctx
, GL_INVALID_VALUE
,
2112 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2115 if (dimensions
> 1 && height
< 0) {
2116 _mesa_error(ctx
, GL_INVALID_VALUE
,
2117 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2121 /* check x/y offsets */
2122 if (xoffset
< -((GLint
)teximage
->Border
)) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2127 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2132 if (dimensions
> 1) {
2133 if (yoffset
< -((GLint
)teximage
->Border
)) {
2134 _mesa_error(ctx
, GL_INVALID_VALUE
,
2135 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2138 /* NOTE: we're adding the border here, not subtracting! */
2139 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2140 _mesa_error(ctx
, GL_INVALID_VALUE
,
2141 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2146 /* check z offset */
2147 if (dimensions
> 2) {
2148 if (zoffset
< -((GLint
)teximage
->Border
)) {
2149 _mesa_error(ctx
, GL_INVALID_VALUE
,
2150 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2153 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
,
2155 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2160 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2161 if (!target_can_be_compressed(ctx
, target
)) {
2162 _mesa_error(ctx
, GL_INVALID_ENUM
,
2163 "glCopyTexSubImage%dD(target)", dimensions
);
2166 /* offset must be multiple of 4 */
2167 if ((xoffset
& 3) || (yoffset
& 3)) {
2168 _mesa_error(ctx
, GL_INVALID_VALUE
,
2169 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2172 /* size must be multiple of 4 */
2173 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2174 _mesa_error(ctx
, GL_INVALID_VALUE
,
2175 "glCopyTexSubImage%dD(width)", dimensions
);
2178 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2179 _mesa_error(ctx
, GL_INVALID_VALUE
,
2180 "glCopyTexSubImage%dD(height)", dimensions
);
2185 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2186 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2190 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2191 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2192 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2193 dimensions
, teximage
->_BaseFormat
);
2197 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2198 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2200 "glCopyTexSubImage%dD(no depth buffer)",
2205 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2206 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2208 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2214 /* If copying into an integer texture, the source buffer must also be
2217 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2218 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2219 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2221 "glCopyTexSubImage%dD(source buffer is not integer format)",
2227 /* if we get here, the parameters are OK */
2232 /** Callback info for walking over FBO hash table */
2235 struct gl_context
*ctx
;
2236 struct gl_texture_object
*texObj
;
2242 * Check render to texture callback. Called from _mesa_HashWalk().
2245 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2247 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2248 const struct cb_info
*info
= (struct cb_info
*) userData
;
2249 struct gl_context
*ctx
= info
->ctx
;
2250 const struct gl_texture_object
*texObj
= info
->texObj
;
2251 const GLuint level
= info
->level
, face
= info
->face
;
2253 /* If this is a user-created FBO */
2256 /* check if any of the FBO's attachments point to 'texObj' */
2257 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2258 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2259 if (att
->Type
== GL_TEXTURE
&&
2260 att
->Texture
== texObj
&&
2261 att
->TextureLevel
== level
&&
2262 att
->CubeMapFace
== face
) {
2263 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2264 /* Tell driver about the new renderbuffer texture */
2265 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2266 /* Mark fb status as indeterminate to force re-validation */
2275 * When a texture image is specified we have to check if it's bound to
2276 * any framebuffer objects (render to texture) in order to detect changes
2277 * in size or format since that effects FBO completeness.
2278 * Any FBOs rendering into the texture must be re-validated.
2281 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2282 GLuint face
, GLuint level
)
2284 /* Only check this texture if it's been marked as RenderToTexture */
2285 if (texObj
->_RenderToTexture
) {
2286 struct cb_info info
;
2288 info
.texObj
= texObj
;
2291 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2297 * If the texture object's GenerateMipmap flag is set and we've
2298 * changed the texture base level image, regenerate the rest of the
2299 * mipmap levels now.
2302 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2303 struct gl_texture_object
*texObj
, GLint level
)
2305 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2306 if (texObj
->GenerateMipmap
&&
2307 level
== texObj
->BaseLevel
&&
2308 level
< texObj
->MaxLevel
) {
2309 ASSERT(ctx
->Driver
.GenerateMipmap
);
2310 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2315 /** Debug helper: override the user-requested internal format */
2317 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2320 if (internalFormat
== GL_RGBA16F_ARB
||
2321 internalFormat
== GL_RGBA32F_ARB
) {
2322 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2325 else if (internalFormat
== GL_RGB16F_ARB
||
2326 internalFormat
== GL_RGB32F_ARB
) {
2327 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2330 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2331 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2332 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2333 return GL_LUMINANCE_ALPHA
;
2335 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2336 internalFormat
== GL_LUMINANCE32F_ARB
) {
2337 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2338 return GL_LUMINANCE
;
2340 else if (internalFormat
== GL_ALPHA16F_ARB
||
2341 internalFormat
== GL_ALPHA32F_ARB
) {
2342 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2346 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2347 internalFormat = GL_RGBA;
2351 return internalFormat
;
2354 return internalFormat
;
2360 * Choose the actual hardware format for a texture image.
2361 * Try to use the same format as the previous image level when possible.
2362 * Otherwise, ask the driver for the best format.
2363 * It's important to try to choose a consistant format for all levels
2364 * for efficient texture memory layout/allocation. In particular, this
2365 * comes up during automatic mipmap generation.
2368 _mesa_choose_texture_format(struct gl_context
*ctx
,
2369 struct gl_texture_object
*texObj
,
2370 GLenum target
, GLint level
,
2371 GLenum internalFormat
, GLenum format
, GLenum type
)
2375 /* see if we've already chosen a format for the previous level */
2377 struct gl_texture_image
*prevImage
=
2378 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2379 /* See if the prev level is defined and has an internal format which
2380 * matches the new internal format.
2383 prevImage
->Width
> 0 &&
2384 prevImage
->InternalFormat
== internalFormat
) {
2385 /* use the same format */
2386 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2387 return prevImage
->TexFormat
;
2391 /* choose format from scratch */
2392 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2393 ASSERT(f
!= MESA_FORMAT_NONE
);
2399 * Common code to implement all the glTexImage1D/2D/3D functions.
2402 teximage(struct gl_context
*ctx
, GLuint dims
,
2403 GLenum target
, GLint level
, GLint internalFormat
,
2404 GLsizei width
, GLsizei height
, GLsizei depth
,
2405 GLint border
, GLenum format
, GLenum type
,
2406 const GLvoid
*pixels
)
2410 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2412 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2413 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2415 _mesa_lookup_enum_by_nr(target
), level
,
2416 _mesa_lookup_enum_by_nr(internalFormat
),
2417 width
, height
, depth
, border
,
2418 _mesa_lookup_enum_by_nr(format
),
2419 _mesa_lookup_enum_by_nr(type
), pixels
);
2421 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2423 /* target error checking */
2424 if (!legal_teximage_target(ctx
, dims
, target
)) {
2425 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2426 dims
, _mesa_lookup_enum_by_nr(target
));
2430 /* general error checking */
2431 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2432 format
, type
, width
, height
, depth
, border
);
2434 if (_mesa_is_proxy_texture(target
)) {
2435 /* Proxy texture: just clear or set state depending on error checking */
2436 struct gl_texture_image
*texImage
=
2437 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2440 /* when error, clear all proxy texture image parameters */
2442 clear_teximage_fields(texImage
);
2445 /* no error, set the tex image parameters */
2446 struct gl_texture_object
*texObj
=
2447 _mesa_get_current_tex_object(ctx
, target
);
2448 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2453 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2454 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2455 depth
, border
, internalFormat
,
2458 else if (texImage
) {
2459 clear_teximage_fields(texImage
);
2464 /* non-proxy target */
2465 const GLuint face
= _mesa_tex_target_to_face(target
);
2466 struct gl_texture_object
*texObj
;
2467 struct gl_texture_image
*texImage
;
2470 return; /* error was recorded */
2473 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2474 _mesa_update_state(ctx
);
2476 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2478 _mesa_lock_texture(ctx
, texObj
);
2480 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2483 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2486 gl_format texFormat
;
2488 if (texImage
->Data
) {
2489 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2492 ASSERT(texImage
->Data
== NULL
);
2493 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2494 internalFormat
, format
,
2497 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2498 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2499 width
, height
, depth
,
2500 border
, internalFormat
, texFormat
);
2502 /* Give the texture to the driver. <pixels> may be null. */
2503 ASSERT(ctx
->Driver
.TexImage3D
);
2506 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2507 width
, border
, format
,
2508 type
, pixels
, &ctx
->Unpack
, texObj
,
2512 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2513 width
, height
, border
, format
,
2514 type
, pixels
, &ctx
->Unpack
, texObj
,
2518 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2519 width
, height
, depth
, border
, format
,
2520 type
, pixels
, &ctx
->Unpack
, texObj
,
2524 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2527 check_gen_mipmap(ctx
, target
, texObj
, level
);
2529 update_fbo_texture(ctx
, texObj
, face
, level
);
2532 texObj
->_Complete
= GL_FALSE
;
2533 ctx
->NewState
|= _NEW_TEXTURE
;
2536 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2540 _mesa_unlock_texture(ctx
, texObj
);
2546 * Called from the API. Note that width includes the border.
2549 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2550 GLsizei width
, GLint border
, GLenum format
,
2551 GLenum type
, const GLvoid
*pixels
)
2553 GET_CURRENT_CONTEXT(ctx
);
2554 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2555 border
, format
, type
, pixels
);
2560 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2561 GLsizei width
, GLsizei height
, GLint border
,
2562 GLenum format
, GLenum type
,
2563 const GLvoid
*pixels
)
2565 GET_CURRENT_CONTEXT(ctx
);
2566 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2567 border
, format
, type
, pixels
);
2572 * Called by the API or display list executor.
2573 * Note that width and height include the border.
2576 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2577 GLsizei width
, GLsizei height
, GLsizei depth
,
2578 GLint border
, GLenum format
, GLenum type
,
2579 const GLvoid
*pixels
)
2581 GET_CURRENT_CONTEXT(ctx
);
2582 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2583 border
, format
, type
, pixels
);
2588 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2589 GLsizei width
, GLsizei height
, GLsizei depth
,
2590 GLint border
, GLenum format
, GLenum type
,
2591 const GLvoid
*pixels
)
2593 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2594 depth
, border
, format
, type
, pixels
);
2598 #if FEATURE_OES_EGL_image
2600 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2602 struct gl_texture_object
*texObj
;
2603 struct gl_texture_image
*texImage
;
2604 GET_CURRENT_CONTEXT(ctx
);
2605 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2607 if (!ctx
->Extensions
.OES_EGL_image
) {
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2609 "glEGLImageTargetTexture2DOES(unsupported)");
2613 if (target
!= GL_TEXTURE_2D
) {
2614 _mesa_error(ctx
, GL_INVALID_ENUM
,
2615 "glEGLImageTargetTexture2D(target=%d)", target
);
2619 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2620 _mesa_update_state(ctx
);
2622 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2623 _mesa_lock_texture(ctx
, texObj
);
2625 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2627 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2630 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2632 ASSERT(texImage
->Data
== NULL
);
2633 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2634 texObj
, texImage
, image
);
2637 texObj
->_Complete
= GL_FALSE
;
2638 ctx
->NewState
|= _NEW_TEXTURE
;
2640 _mesa_unlock_texture(ctx
, texObj
);
2647 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2648 GLint xoffset
, GLsizei width
,
2649 GLenum format
, GLenum type
,
2650 const GLvoid
*pixels
)
2652 struct gl_texture_object
*texObj
;
2653 struct gl_texture_image
*texImage
;
2654 GET_CURRENT_CONTEXT(ctx
);
2655 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2657 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2658 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2659 _mesa_lookup_enum_by_nr(target
), level
,
2660 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2661 _mesa_lookup_enum_by_nr(type
), pixels
);
2663 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2664 _mesa_update_state(ctx
);
2666 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2667 width
, 1, 1, format
, type
)) {
2668 return; /* error was detected */
2672 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2675 _mesa_lock_texture(ctx
, texObj
);
2677 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2679 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2680 width
, 1, 1, format
, type
, texImage
)) {
2681 /* error was recorded */
2683 else if (width
> 0) {
2684 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2685 xoffset
+= texImage
->Border
;
2687 ASSERT(ctx
->Driver
.TexSubImage1D
);
2688 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2689 format
, type
, pixels
, &ctx
->Unpack
,
2692 check_gen_mipmap(ctx
, target
, texObj
, level
);
2694 ctx
->NewState
|= _NEW_TEXTURE
;
2697 _mesa_unlock_texture(ctx
, texObj
);
2702 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2703 GLint xoffset
, GLint yoffset
,
2704 GLsizei width
, GLsizei height
,
2705 GLenum format
, GLenum type
,
2706 const GLvoid
*pixels
)
2708 struct gl_texture_object
*texObj
;
2709 struct gl_texture_image
*texImage
;
2710 GET_CURRENT_CONTEXT(ctx
);
2711 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2713 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2714 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2715 _mesa_lookup_enum_by_nr(target
), level
,
2716 xoffset
, yoffset
, width
, height
,
2717 _mesa_lookup_enum_by_nr(format
),
2718 _mesa_lookup_enum_by_nr(type
), pixels
);
2720 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2721 _mesa_update_state(ctx
);
2723 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2724 width
, height
, 1, format
, type
)) {
2725 return; /* error was detected */
2728 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2730 _mesa_lock_texture(ctx
, texObj
);
2732 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2734 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2735 width
, height
, 1, format
, type
, texImage
)) {
2736 /* error was recorded */
2738 else if (width
> 0 && height
>= 0) {
2739 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2740 xoffset
+= texImage
->Border
;
2741 yoffset
+= texImage
->Border
;
2743 ASSERT(ctx
->Driver
.TexSubImage2D
);
2744 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2745 width
, height
, format
, type
, pixels
,
2746 &ctx
->Unpack
, texObj
, texImage
);
2748 check_gen_mipmap(ctx
, target
, texObj
, level
);
2750 ctx
->NewState
|= _NEW_TEXTURE
;
2753 _mesa_unlock_texture(ctx
, texObj
);
2759 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2760 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2761 GLsizei width
, GLsizei height
, GLsizei depth
,
2762 GLenum format
, GLenum type
,
2763 const GLvoid
*pixels
)
2765 struct gl_texture_object
*texObj
;
2766 struct gl_texture_image
*texImage
;
2767 GET_CURRENT_CONTEXT(ctx
);
2768 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2770 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2771 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2772 _mesa_lookup_enum_by_nr(target
), level
,
2773 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2774 _mesa_lookup_enum_by_nr(format
),
2775 _mesa_lookup_enum_by_nr(type
), pixels
);
2777 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2778 _mesa_update_state(ctx
);
2780 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2781 width
, height
, depth
, format
, type
)) {
2782 return; /* error was detected */
2785 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2787 _mesa_lock_texture(ctx
, texObj
);
2789 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2791 if (subtexture_error_check2(ctx
, 3, target
, level
,
2792 xoffset
, yoffset
, zoffset
,
2793 width
, height
, depth
,
2794 format
, type
, texImage
)) {
2795 /* error was recorded */
2797 else if (width
> 0 && height
> 0 && height
> 0) {
2798 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2799 xoffset
+= texImage
->Border
;
2800 yoffset
+= texImage
->Border
;
2801 zoffset
+= texImage
->Border
;
2803 ASSERT(ctx
->Driver
.TexSubImage3D
);
2804 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2805 xoffset
, yoffset
, zoffset
,
2806 width
, height
, depth
,
2807 format
, type
, pixels
,
2808 &ctx
->Unpack
, texObj
, texImage
);
2810 check_gen_mipmap(ctx
, target
, texObj
, level
);
2812 ctx
->NewState
|= _NEW_TEXTURE
;
2815 _mesa_unlock_texture(ctx
, texObj
);
2821 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2822 GLenum internalFormat
,
2824 GLsizei width
, GLint border
)
2826 struct gl_texture_object
*texObj
;
2827 struct gl_texture_image
*texImage
;
2828 const GLuint face
= _mesa_tex_target_to_face(target
);
2829 GET_CURRENT_CONTEXT(ctx
);
2830 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2832 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2833 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2834 _mesa_lookup_enum_by_nr(target
), level
,
2835 _mesa_lookup_enum_by_nr(internalFormat
),
2836 x
, y
, width
, border
);
2838 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2839 _mesa_update_state(ctx
);
2841 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2845 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2847 _mesa_lock_texture(ctx
, texObj
);
2849 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2851 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2854 gl_format texFormat
;
2856 if (texImage
->Data
) {
2857 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2860 ASSERT(texImage
->Data
== NULL
);
2862 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2863 internalFormat
, GL_NONE
,
2866 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
2867 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2868 border
, internalFormat
, texFormat
);
2870 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2871 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2872 x
, y
, width
, border
);
2874 check_gen_mipmap(ctx
, target
, texObj
, level
);
2876 update_fbo_texture(ctx
, texObj
, face
, level
);
2879 texObj
->_Complete
= GL_FALSE
;
2880 ctx
->NewState
|= _NEW_TEXTURE
;
2883 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2887 _mesa_unlock_texture(ctx
, texObj
);
2893 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2894 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2897 struct gl_texture_object
*texObj
;
2898 struct gl_texture_image
*texImage
;
2899 const GLuint face
= _mesa_tex_target_to_face(target
);
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
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2905 _mesa_lookup_enum_by_nr(target
), level
,
2906 _mesa_lookup_enum_by_nr(internalFormat
),
2907 x
, y
, width
, height
, border
);
2909 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2910 _mesa_update_state(ctx
);
2912 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2913 width
, height
, border
))
2916 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2918 _mesa_lock_texture(ctx
, texObj
);
2920 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2923 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2926 gl_format texFormat
;
2928 if (texImage
->Data
) {
2929 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2932 ASSERT(texImage
->Data
== NULL
);
2934 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2935 internalFormat
, GL_NONE
,
2938 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2939 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2940 border
, internalFormat
, texFormat
);
2942 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2943 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2944 x
, y
, width
, height
, border
);
2946 check_gen_mipmap(ctx
, target
, texObj
, level
);
2948 update_fbo_texture(ctx
, texObj
, face
, level
);
2951 texObj
->_Complete
= GL_FALSE
;
2952 ctx
->NewState
|= _NEW_TEXTURE
;
2955 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2959 _mesa_unlock_texture(ctx
, texObj
);
2964 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2965 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2967 struct gl_texture_object
*texObj
;
2968 struct gl_texture_image
*texImage
;
2972 GET_CURRENT_CONTEXT(ctx
);
2973 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2975 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2976 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2977 _mesa_lookup_enum_by_nr(target
),
2978 level
, xoffset
, x
, y
, width
);
2980 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2981 _mesa_update_state(ctx
);
2983 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2986 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2988 _mesa_lock_texture(ctx
, texObj
);
2990 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2992 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2993 xoffset
, 0, 0, width
, 1, texImage
)) {
2994 /* error was recorded */
2997 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2998 xoffset
+= texImage
->Border
;
3000 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3002 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3003 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3004 xoffset
, x
, y
, width
);
3006 check_gen_mipmap(ctx
, target
, texObj
, level
);
3008 ctx
->NewState
|= _NEW_TEXTURE
;
3012 _mesa_unlock_texture(ctx
, texObj
);
3018 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3019 GLint xoffset
, GLint yoffset
,
3020 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3022 struct gl_texture_object
*texObj
;
3023 struct gl_texture_image
*texImage
;
3024 GET_CURRENT_CONTEXT(ctx
);
3025 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3027 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3028 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
3029 _mesa_lookup_enum_by_nr(target
),
3030 level
, xoffset
, yoffset
, x
, y
, width
, height
);
3032 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3033 _mesa_update_state(ctx
);
3035 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3038 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3040 _mesa_lock_texture(ctx
, texObj
);
3042 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3044 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
3045 xoffset
, yoffset
, 0,
3046 width
, height
, texImage
)) {
3047 /* error was recorded */
3050 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3051 xoffset
+= texImage
->Border
;
3052 yoffset
+= texImage
->Border
;
3054 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3056 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3057 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
3058 x
, y
, width
, height
);
3060 check_gen_mipmap(ctx
, target
, texObj
, level
);
3062 ctx
->NewState
|= _NEW_TEXTURE
;
3066 _mesa_unlock_texture(ctx
, texObj
);
3072 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3073 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3074 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3076 struct gl_texture_object
*texObj
;
3077 struct gl_texture_image
*texImage
;
3078 GET_CURRENT_CONTEXT(ctx
);
3079 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3081 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3082 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
3083 _mesa_lookup_enum_by_nr(target
),
3084 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3086 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3087 _mesa_update_state(ctx
);
3089 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3092 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3094 _mesa_lock_texture(ctx
, texObj
);
3096 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3098 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3099 zoffset
, width
, height
, texImage
)) {
3100 /* error was recored */
3103 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3104 xoffset
+= texImage
->Border
;
3105 yoffset
+= texImage
->Border
;
3106 zoffset
+= texImage
->Border
;
3108 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3110 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3111 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3112 xoffset
, yoffset
, zoffset
,
3113 x
, y
, width
, height
);
3115 check_gen_mipmap(ctx
, target
, texObj
, level
);
3117 ctx
->NewState
|= _NEW_TEXTURE
;
3121 _mesa_unlock_texture(ctx
, texObj
);
3127 /**********************************************************************/
3128 /****** Compressed Textures ******/
3129 /**********************************************************************/
3133 * Return expected size of a compressed texture.
3136 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3139 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3140 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3145 * Return compressed texture block size, in pixels.
3148 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3150 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3151 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3156 * Error checking for glCompressedTexImage[123]D().
3157 * \return error code or GL_NO_ERROR.
3160 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3161 GLenum target
, GLint level
,
3162 GLenum internalFormat
, GLsizei width
,
3163 GLsizei height
, GLsizei depth
, GLint border
,
3166 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3168 if (dimensions
== 1) {
3169 /* 1D compressed textures not allowed */
3170 return GL_INVALID_ENUM
;
3172 else if (dimensions
== 2) {
3173 if (target
== GL_PROXY_TEXTURE_2D
) {
3174 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3176 else if (target
== GL_TEXTURE_2D
) {
3177 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3179 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3180 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3181 return GL_INVALID_ENUM
; /*target*/
3182 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3184 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3185 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3186 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3187 return GL_INVALID_ENUM
; /*target*/
3188 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3191 return GL_INVALID_ENUM
; /*target*/
3194 else if (dimensions
== 3) {
3195 /* 3D compressed textures not allowed */
3196 return GL_INVALID_ENUM
;
3200 return GL_INVALID_ENUM
;
3203 maxTextureSize
= 1 << (maxLevels
- 1);
3205 /* This will detect any invalid internalFormat value */
3206 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3207 return GL_INVALID_ENUM
;
3209 /* This should really never fail */
3210 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3211 return GL_INVALID_ENUM
;
3214 return GL_INVALID_VALUE
;
3217 * XXX We should probably use the proxy texture error check function here.
3219 if (width
< 1 || width
> maxTextureSize
||
3220 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3221 return GL_INVALID_VALUE
;
3223 if ((height
< 1 || height
> maxTextureSize
||
3224 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3226 return GL_INVALID_VALUE
;
3228 if ((depth
< 1 || depth
> maxTextureSize
||
3229 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3231 return GL_INVALID_VALUE
;
3233 /* For cube map, width must equal height */
3234 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3235 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3236 return GL_INVALID_VALUE
;
3238 if (level
< 0 || level
>= maxLevels
)
3239 return GL_INVALID_VALUE
;
3241 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3242 if (expectedSize
!= imageSize
)
3243 return GL_INVALID_VALUE
;
3245 #if FEATURE_EXT_texture_sRGB
3246 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3247 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3248 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3249 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3251 return GL_INVALID_OPERATION
;
3260 * Error checking for glCompressedTexSubImage[123]D().
3261 * \warning There are some bad assumptions here about the size of compressed
3262 * texture tiles (multiple of 4) used to test the validity of the
3263 * offset and size parameters.
3264 * \return error code or GL_NO_ERROR.
3267 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3268 GLenum target
, GLint level
,
3269 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3270 GLsizei width
, GLsizei height
, GLsizei depth
,
3271 GLenum format
, GLsizei imageSize
)
3273 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3277 if (dimensions
== 1) {
3278 /* 1D compressed textures not allowed */
3279 return GL_INVALID_ENUM
;
3281 else if (dimensions
== 2) {
3282 if (target
== GL_PROXY_TEXTURE_2D
) {
3283 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3285 else if (target
== GL_TEXTURE_2D
) {
3286 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3288 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3289 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3290 return GL_INVALID_ENUM
; /*target*/
3291 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3293 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3294 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3295 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3296 return GL_INVALID_ENUM
; /*target*/
3297 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3300 return GL_INVALID_ENUM
; /*target*/
3303 else if (dimensions
== 3) {
3304 /* 3D compressed textures not allowed */
3305 return GL_INVALID_ENUM
;
3308 maxTextureSize
= 1 << (maxLevels
- 1);
3310 /* this will catch any invalid compressed format token */
3311 if (!_mesa_is_compressed_format(ctx
, format
))
3312 return GL_INVALID_ENUM
;
3314 if (width
< 1 || width
> maxTextureSize
)
3315 return GL_INVALID_VALUE
;
3317 if ((height
< 1 || height
> maxTextureSize
)
3319 return GL_INVALID_VALUE
;
3321 if (level
< 0 || level
>= maxLevels
)
3322 return GL_INVALID_VALUE
;
3325 * do checks which depend on compression block size
3327 get_compressed_block_size(format
, &bw
, &bh
);
3329 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3330 return GL_INVALID_VALUE
;
3332 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3333 return GL_INVALID_VALUE
;
3335 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3336 return GL_INVALID_VALUE
;
3338 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3339 if (expectedSize
!= imageSize
)
3340 return GL_INVALID_VALUE
;
3347 * Do second part of glCompressedTexSubImage error checking.
3348 * \return GL_TRUE if error found, GL_FALSE otherwise.
3351 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3352 GLsizei width
, GLsizei height
,
3353 GLsizei depth
, GLenum format
,
3354 struct gl_texture_image
*texImage
)
3357 if ((GLint
) format
!= texImage
->InternalFormat
) {
3358 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3359 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3363 if (((width
== 1 || width
== 2) &&
3364 width
!= (GLsizei
) texImage
->Width
) ||
3365 (width
> (GLsizei
) texImage
->Width
)) {
3366 _mesa_error(ctx
, GL_INVALID_VALUE
,
3367 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3372 if (((height
== 1 || height
== 2) &&
3373 height
!= (GLsizei
) texImage
->Height
) ||
3374 (height
> (GLsizei
) texImage
->Height
)) {
3375 _mesa_error(ctx
, GL_INVALID_VALUE
,
3376 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3382 if (((depth
== 1 || depth
== 2) &&
3383 depth
!= (GLsizei
) texImage
->Depth
) ||
3384 (depth
> (GLsizei
) texImage
->Depth
)) {
3385 _mesa_error(ctx
, GL_INVALID_VALUE
,
3386 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3397 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3398 GLenum internalFormat
, GLsizei width
,
3399 GLint border
, GLsizei imageSize
,
3402 GET_CURRENT_CONTEXT(ctx
);
3403 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3405 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3406 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3407 _mesa_lookup_enum_by_nr(target
), level
,
3408 _mesa_lookup_enum_by_nr(internalFormat
),
3409 width
, border
, imageSize
, data
);
3411 if (target
== GL_TEXTURE_1D
) {
3412 /* non-proxy target */
3413 struct gl_texture_object
*texObj
;
3414 struct gl_texture_image
*texImage
;
3415 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3416 internalFormat
, width
, 1, 1, border
, imageSize
);
3418 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3422 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3424 _mesa_lock_texture(ctx
, texObj
);
3426 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3428 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3431 gl_format texFormat
;
3433 if (texImage
->Data
) {
3434 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3436 ASSERT(texImage
->Data
== NULL
);
3438 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3439 internalFormat
, GL_NONE
,
3442 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3443 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3444 border
, internalFormat
, texFormat
);
3446 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3447 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3448 internalFormat
, width
, border
,
3452 check_gen_mipmap(ctx
, target
, texObj
, level
);
3455 texObj
->_Complete
= GL_FALSE
;
3456 ctx
->NewState
|= _NEW_TEXTURE
;
3459 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3463 _mesa_unlock_texture(ctx
, texObj
);
3465 else if (target
== GL_PROXY_TEXTURE_1D
) {
3466 /* Proxy texture: check for errors and update proxy state */
3467 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3468 internalFormat
, width
, 1, 1, border
, imageSize
);
3470 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3471 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3472 internalFormat
, GL_NONE
, GL_NONE
,
3473 width
, 1, 1, border
);
3476 /* if error, clear all proxy texture image parameters */
3477 struct gl_texture_image
*texImage
;
3478 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3480 clear_teximage_fields(texImage
);
3483 /* store the teximage parameters */
3484 struct gl_texture_object
*texObj
;
3485 struct gl_texture_image
*texImage
;
3486 gl_format texFormat
;
3488 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3490 _mesa_lock_texture(ctx
, texObj
);
3492 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3493 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3494 internalFormat
, GL_NONE
,
3496 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3497 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3498 border
, internalFormat
, texFormat
);
3500 else if (texImage
) {
3501 clear_teximage_fields(texImage
);
3504 _mesa_unlock_texture(ctx
, texObj
);
3508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3514 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3515 GLenum internalFormat
, GLsizei width
,
3516 GLsizei height
, GLint border
, GLsizei imageSize
,
3519 GET_CURRENT_CONTEXT(ctx
);
3520 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3522 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3523 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3524 _mesa_lookup_enum_by_nr(target
), level
,
3525 _mesa_lookup_enum_by_nr(internalFormat
),
3526 width
, height
, border
, imageSize
, data
);
3529 switch (internalFormat
) {
3530 case GL_PALETTE4_RGB8_OES
:
3531 case GL_PALETTE4_RGBA8_OES
:
3532 case GL_PALETTE4_R5_G6_B5_OES
:
3533 case GL_PALETTE4_RGBA4_OES
:
3534 case GL_PALETTE4_RGB5_A1_OES
:
3535 case GL_PALETTE8_RGB8_OES
:
3536 case GL_PALETTE8_RGBA8_OES
:
3537 case GL_PALETTE8_R5_G6_B5_OES
:
3538 case GL_PALETTE8_RGBA4_OES
:
3539 case GL_PALETTE8_RGB5_A1_OES
:
3540 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3541 width
, height
, imageSize
, data
);
3546 if (target
== GL_TEXTURE_2D
||
3547 (ctx
->Extensions
.ARB_texture_cube_map
&&
3548 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3549 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3550 /* non-proxy target */
3551 struct gl_texture_object
*texObj
;
3552 struct gl_texture_image
*texImage
;
3554 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3555 internalFormat
, width
, height
, 1, border
, imageSize
);
3557 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3561 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3563 _mesa_lock_texture(ctx
, texObj
);
3565 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3567 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3570 gl_format texFormat
;
3572 if (texImage
->Data
) {
3573 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3575 ASSERT(texImage
->Data
== NULL
);
3577 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3578 internalFormat
, GL_NONE
,
3581 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3582 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
3583 height
, 1, border
, internalFormat
,
3586 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3587 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3588 internalFormat
, width
, height
,
3589 border
, imageSize
, data
,
3592 check_gen_mipmap(ctx
, target
, texObj
, level
);
3595 texObj
->_Complete
= GL_FALSE
;
3596 ctx
->NewState
|= _NEW_TEXTURE
;
3599 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3603 _mesa_unlock_texture(ctx
, texObj
);
3605 else if (target
== GL_PROXY_TEXTURE_2D
||
3606 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3607 ctx
->Extensions
.ARB_texture_cube_map
)) {
3608 /* Proxy texture: check for errors and update proxy state */
3609 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3610 internalFormat
, width
, height
, 1, border
, imageSize
);
3612 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3613 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3614 internalFormat
, GL_NONE
, GL_NONE
,
3615 width
, height
, 1, border
);
3618 /* if error, clear all proxy texture image parameters */
3619 struct gl_texture_image
*texImage
;
3620 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3622 clear_teximage_fields(texImage
);
3625 /* store the teximage parameters */
3626 struct gl_texture_object
*texObj
;
3627 struct gl_texture_image
*texImage
;
3628 gl_format texFormat
;
3630 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3632 _mesa_lock_texture(ctx
, texObj
);
3634 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3635 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3636 internalFormat
, GL_NONE
,
3638 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
3639 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
3640 height
, 1, border
, internalFormat
,
3644 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3647 _mesa_unlock_texture(ctx
, texObj
);
3651 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3658 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3659 GLenum internalFormat
, GLsizei width
,
3660 GLsizei height
, GLsizei depth
, GLint border
,
3661 GLsizei imageSize
, const GLvoid
*data
)
3663 GET_CURRENT_CONTEXT(ctx
);
3664 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3666 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3667 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3668 _mesa_lookup_enum_by_nr(target
), level
,
3669 _mesa_lookup_enum_by_nr(internalFormat
),
3670 width
, height
, depth
, border
, imageSize
, data
);
3672 if (target
== GL_TEXTURE_3D
) {
3673 /* non-proxy target */
3674 struct gl_texture_object
*texObj
;
3675 struct gl_texture_image
*texImage
;
3676 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3677 internalFormat
, width
, height
, depth
, border
, imageSize
);
3679 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3683 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3685 _mesa_lock_texture(ctx
, texObj
);
3687 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3689 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3692 gl_format texFormat
;
3694 if (texImage
->Data
) {
3695 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3697 ASSERT(texImage
->Data
== NULL
);
3699 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3700 internalFormat
, GL_NONE
,
3703 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3704 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3705 width
, height
, depth
,
3706 border
, internalFormat
, texFormat
);
3708 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3709 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3711 width
, height
, depth
,
3712 border
, imageSize
, data
,
3715 check_gen_mipmap(ctx
, target
, texObj
, level
);
3718 texObj
->_Complete
= GL_FALSE
;
3719 ctx
->NewState
|= _NEW_TEXTURE
;
3722 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3726 _mesa_unlock_texture(ctx
, texObj
);
3728 else if (target
== GL_PROXY_TEXTURE_3D
) {
3729 /* Proxy texture: check for errors and update proxy state */
3730 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3731 internalFormat
, width
, height
, depth
, border
, imageSize
);
3733 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3734 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3735 internalFormat
, GL_NONE
, GL_NONE
,
3736 width
, height
, depth
, border
);
3739 /* if error, clear all proxy texture image parameters */
3740 struct gl_texture_image
*texImage
;
3741 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3743 clear_teximage_fields(texImage
);
3746 /* store the teximage parameters */
3747 struct gl_texture_object
*texObj
;
3748 struct gl_texture_image
*texImage
;
3749 gl_format texFormat
;
3751 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3753 _mesa_lock_texture(ctx
, texObj
);
3755 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3756 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3757 internalFormat
, GL_NONE
,
3759 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3760 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3761 depth
, border
, internalFormat
,
3764 else if (texImage
) {
3765 clear_teximage_fields(texImage
);
3768 _mesa_unlock_texture(ctx
, texObj
);
3772 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3779 * Common helper for glCompressedTexSubImage1/2/3D().
3782 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3783 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3784 GLsizei width
, GLsizei height
, GLsizei depth
,
3785 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3787 struct gl_texture_object
*texObj
;
3788 struct gl_texture_image
*texImage
;
3790 GET_CURRENT_CONTEXT(ctx
);
3791 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3793 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3794 xoffset
, 0, 0, /* pos */
3795 width
, height
, depth
, /* size */
3798 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3802 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3804 _mesa_lock_texture(ctx
, texObj
);
3806 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3809 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3810 format
, texImage
)) {
3811 /* error was recorded */
3813 else if (width
> 0 && height
> 0 && depth
> 0) {
3816 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3817 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3819 format
, imageSize
, data
,
3824 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3825 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3828 format
, imageSize
, data
,
3833 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3834 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3835 xoffset
, yoffset
, zoffset
,
3836 width
, height
, depth
,
3837 format
, imageSize
, data
,
3845 check_gen_mipmap(ctx
, target
, texObj
, level
);
3847 ctx
->NewState
|= _NEW_TEXTURE
;
3850 _mesa_unlock_texture(ctx
, texObj
);
3855 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3856 GLsizei width
, GLenum format
,
3857 GLsizei imageSize
, const GLvoid
*data
)
3859 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3860 format
, imageSize
, data
);
3865 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3866 GLint yoffset
, GLsizei width
, GLsizei height
,
3867 GLenum format
, GLsizei imageSize
,
3870 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3871 width
, height
, 1, format
, imageSize
, data
);
3876 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3877 GLint yoffset
, GLint zoffset
, GLsizei width
,
3878 GLsizei height
, GLsizei depth
, GLenum format
,
3879 GLsizei imageSize
, const GLvoid
*data
)
3881 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3882 width
, height
, depth
, format
, imageSize
, data
);