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 dimenions per image for the given texture target.
894 get_texture_dimensions(GLenum target
)
898 case GL_TEXTURE_1D_ARRAY
:
899 case GL_PROXY_TEXTURE_1D
:
900 case GL_PROXY_TEXTURE_1D_ARRAY
:
903 case GL_TEXTURE_2D_ARRAY
:
904 case GL_TEXTURE_RECTANGLE
:
905 case GL_TEXTURE_CUBE_MAP
:
906 case GL_PROXY_TEXTURE_2D
:
907 case GL_PROXY_TEXTURE_2D_ARRAY
:
908 case GL_PROXY_TEXTURE_RECTANGLE
:
909 case GL_PROXY_TEXTURE_CUBE_MAP
:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
912 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
913 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
914 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
915 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
918 case GL_PROXY_TEXTURE_3D
:
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 * Helper function to determine whether a target supports compressed textures
1280 target_can_be_compressed(struct gl_context
*ctx
, GLenum target
)
1284 case GL_PROXY_TEXTURE_2D
:
1286 case GL_PROXY_TEXTURE_CUBE_MAP
:
1287 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1288 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1289 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1290 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1291 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1293 return ctx
->Extensions
.ARB_texture_cube_map
;
1294 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1295 case GL_TEXTURE_2D_ARRAY_EXT
:
1296 return ctx
->Extensions
.MESA_texture_array
;
1304 * Test the glTexImage[123]D() parameters for errors.
1306 * \param ctx GL context.
1307 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1308 * \param target texture target given by the user.
1309 * \param level image level given by the user.
1310 * \param internalFormat internal format given by the user.
1311 * \param format pixel data format given by the user.
1312 * \param type pixel data type given by the user.
1313 * \param width image width given by the user.
1314 * \param height image height given by the user.
1315 * \param depth image depth given by the user.
1316 * \param border image border given by the user.
1318 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1320 * Verifies each of the parameters against the constants specified in
1321 * __struct gl_contextRec::Const and the supported extensions, and according
1322 * to the OpenGL specification.
1325 texture_error_check( struct gl_context
*ctx
,
1326 GLuint dimensions
, GLenum target
,
1327 GLint level
, GLint internalFormat
,
1328 GLenum format
, GLenum type
,
1329 GLint width
, GLint height
,
1330 GLint depth
, GLint border
)
1332 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1333 GLboolean sizeOK
= GL_TRUE
;
1334 GLboolean colorFormat
, indexFormat
;
1335 GLenum proxy_target
;
1337 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1338 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1340 _mesa_error(ctx
, GL_INVALID_VALUE
,
1341 "glTexImage%dD(level=%d)", dimensions
, level
);
1347 if (border
< 0 || border
> 1 ||
1348 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1349 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1351 _mesa_error(ctx
, GL_INVALID_VALUE
,
1352 "glTexImage%dD(border=%d)", dimensions
, border
);
1357 if (width
< 0 || height
< 0 || depth
< 0) {
1359 _mesa_error(ctx
, GL_INVALID_VALUE
,
1360 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1365 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1366 * level, width, height and depth.
1368 if (dimensions
== 1) {
1369 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1370 proxy_target
= GL_PROXY_TEXTURE_1D
;
1375 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1379 else if (dimensions
== 2) {
1381 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1382 proxy_target
= GL_PROXY_TEXTURE_2D
;
1384 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1385 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1386 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1387 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1388 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1391 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1392 sizeOK
= (width
== height
);
1394 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1395 target
== GL_TEXTURE_RECTANGLE_NV
) {
1396 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1397 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1400 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1402 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1403 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1404 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1407 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1411 else if (dimensions
== 3) {
1412 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1413 proxy_target
= GL_PROXY_TEXTURE_3D
;
1415 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1416 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1417 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1420 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1425 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1429 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1430 internalFormat
, format
,
1431 type
, width
, height
,
1435 _mesa_error(ctx
, GL_INVALID_VALUE
,
1436 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1437 dimensions
, level
, width
, height
, depth
);
1442 /* Check internalFormat */
1443 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1445 _mesa_error(ctx
, GL_INVALID_VALUE
,
1446 "glTexImage%dD(internalFormat=%s)",
1447 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1452 /* Check incoming image format and type */
1453 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1454 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1455 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1456 * GL_EXT_texture_integer extension, some combinations should generate
1457 * GL_INVALID_ENUM instead (grr!).
1460 GLenum error
= _mesa_is_integer_format(format
)
1461 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1462 _mesa_error(ctx
, error
,
1463 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1464 dimensions
, format
, type
);
1469 /* make sure internal format and format basically agree */
1470 colorFormat
= _mesa_is_color_format(format
);
1471 indexFormat
= _mesa_is_index_format(format
);
1472 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1473 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1474 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1475 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1476 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1477 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1479 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1480 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1481 dimensions
, internalFormat
, format
);
1485 /* additional checks for ycbcr textures */
1486 if (internalFormat
== GL_YCBCR_MESA
) {
1487 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1488 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1489 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1491 _mesa_snprintf(message
, sizeof(message
),
1492 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1493 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1494 return GL_TRUE
; /* error */
1496 if (target
!= GL_TEXTURE_2D
&&
1497 target
!= GL_PROXY_TEXTURE_2D
&&
1498 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1499 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1501 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1507 _mesa_snprintf(message
, sizeof(message
),
1508 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1509 dimensions
, border
);
1510 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1516 /* additional checks for depth textures */
1517 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1518 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1519 if (target
!= GL_TEXTURE_1D
&&
1520 target
!= GL_PROXY_TEXTURE_1D
&&
1521 target
!= GL_TEXTURE_2D
&&
1522 target
!= GL_PROXY_TEXTURE_2D
&&
1523 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1524 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1526 _mesa_error(ctx
, GL_INVALID_ENUM
,
1527 "glTexImage(target/internalFormat)");
1532 /* additional checks for compressed textures */
1533 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1534 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1535 _mesa_error(ctx
, GL_INVALID_ENUM
,
1536 "glTexImage%dD(target)", dimensions
);
1541 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1542 "glTexImage%dD(border!=0)", dimensions
);
1548 /* additional checks for integer textures */
1549 if (ctx
->Extensions
.EXT_texture_integer
&&
1550 (_mesa_is_integer_format(format
) !=
1551 _mesa_is_integer_format(internalFormat
))) {
1553 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1554 "glTexImage%dD(integer/non-integer format mismatch)",
1560 /* if we get here, the parameters are OK */
1566 * Test glTexSubImage[123]D() parameters for errors.
1568 * \param ctx GL context.
1569 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1570 * \param target texture target given by the user.
1571 * \param level image level given by the user.
1572 * \param xoffset sub-image x offset given by the user.
1573 * \param yoffset sub-image y offset given by the user.
1574 * \param zoffset sub-image z offset given by the user.
1575 * \param format pixel data format given by the user.
1576 * \param type pixel data type given by the user.
1577 * \param width image width given by the user.
1578 * \param height image height given by the user.
1579 * \param depth image depth given by the user.
1581 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1583 * Verifies each of the parameters against the constants specified in
1584 * __struct gl_contextRec::Const and the supported extensions, and according
1585 * to the OpenGL specification.
1588 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1589 GLenum target
, GLint level
,
1590 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1591 GLint width
, GLint height
, GLint depth
,
1592 GLenum format
, GLenum type
)
1595 if (dimensions
== 1) {
1596 if (target
!= GL_TEXTURE_1D
) {
1597 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1601 else if (dimensions
== 2) {
1602 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1603 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1604 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1605 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1609 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1610 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1611 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1615 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1616 if (!ctx
->Extensions
.MESA_texture_array
) {
1617 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1621 else if (target
!= GL_TEXTURE_2D
) {
1622 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1626 else if (dimensions
== 3) {
1627 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1628 if (!ctx
->Extensions
.MESA_texture_array
) {
1629 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1633 else if (target
!= GL_TEXTURE_3D
) {
1634 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1639 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1643 /* Basic level check */
1644 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1645 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1650 _mesa_error(ctx
, GL_INVALID_VALUE
,
1651 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1654 if (height
< 0 && dimensions
> 1) {
1655 _mesa_error(ctx
, GL_INVALID_VALUE
,
1656 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1659 if (depth
< 0 && dimensions
> 2) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
,
1661 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1665 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1666 /* As with the glTexImage2D check above, the error code here
1667 * depends on texture integer.
1669 GLenum error
= _mesa_is_integer_format(format
)
1670 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1671 _mesa_error(ctx
, error
,
1672 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1673 dimensions
, format
, type
);
1682 * Do second part of glTexSubImage which depends on the destination texture.
1683 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1686 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1687 GLenum target
, GLint level
,
1688 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1689 GLint width
, GLint height
, GLint depth
,
1690 GLenum format
, GLenum type
,
1691 const struct gl_texture_image
*destTex
)
1694 /* undefined image level */
1695 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1699 if (xoffset
< -((GLint
)destTex
->Border
)) {
1700 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1704 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1705 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1709 if (dimensions
> 1) {
1710 if (yoffset
< -((GLint
)destTex
->Border
)) {
1711 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1715 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1716 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1721 if (dimensions
> 2) {
1722 if (zoffset
< -((GLint
)destTex
->Border
)) {
1723 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1726 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1727 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1732 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1735 if (!target_can_be_compressed(ctx
, target
)) {
1736 _mesa_error(ctx
, GL_INVALID_ENUM
,
1737 "glTexSubImage%dD(target=%s)", dimensions
,
1738 _mesa_lookup_enum_by_nr(target
));
1742 /* do tests which depend on compression block size */
1743 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1745 /* offset must be multiple of block size */
1746 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1747 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1748 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1749 dimensions
, xoffset
, yoffset
);
1752 /* size must be multiple of bw by bh or equal to whole texture size */
1753 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1755 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1758 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1759 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1760 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1770 * Test glCopyTexImage[12]D() parameters for errors.
1772 * \param ctx GL context.
1773 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1774 * \param target texture target given by the user.
1775 * \param level image level given by the user.
1776 * \param internalFormat internal format given by the user.
1777 * \param width image width given by the user.
1778 * \param height image height given by the user.
1779 * \param border texture border.
1781 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1783 * Verifies each of the parameters against the constants specified in
1784 * __struct gl_contextRec::Const and the supported extensions, and according
1785 * to the OpenGL specification.
1788 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1789 GLenum target
, GLint level
, GLint internalFormat
,
1790 GLint width
, GLint height
, GLint border
)
1796 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1797 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1798 _mesa_error(ctx
, GL_INVALID_VALUE
,
1799 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1803 /* Check that the source buffer is complete */
1804 if (ctx
->ReadBuffer
->Name
) {
1805 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1806 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1807 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1808 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1814 if (border
< 0 || border
> 1 ||
1815 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1816 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1820 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1822 _mesa_error(ctx
, GL_INVALID_VALUE
,
1823 "glCopyTexImage%dD(internalFormat)", dimensions
);
1827 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1828 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1829 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1833 /* NOTE: the format and type aren't really significant for
1834 * TestProxyTexImage(). Only the internalformat really matters.
1838 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1839 * level, width, height and depth.
1841 if (dimensions
== 1) {
1842 if (target
== GL_TEXTURE_1D
) {
1843 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1844 level
, internalFormat
,
1846 width
, 1, 1, border
);
1849 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1853 else if (dimensions
== 2) {
1854 if (target
== GL_TEXTURE_2D
) {
1855 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1856 level
, internalFormat
,
1858 width
, height
, 1, border
);
1860 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1861 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1862 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1863 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1866 sizeOK
= (width
== height
) &&
1867 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1868 level
, internalFormat
, format
, type
,
1869 width
, height
, 1, border
);
1871 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1872 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1873 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1876 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1877 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1878 level
, internalFormat
,
1880 width
, height
, 1, border
);
1882 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1883 if (!ctx
->Extensions
.MESA_texture_array
) {
1884 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1887 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1888 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1889 level
, internalFormat
,
1891 width
, height
, 1, border
);
1894 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1899 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1904 if (dimensions
== 1) {
1905 _mesa_error(ctx
, GL_INVALID_VALUE
,
1906 "glCopyTexImage1D(width=%d)", width
);
1909 ASSERT(dimensions
== 2);
1910 _mesa_error(ctx
, GL_INVALID_VALUE
,
1911 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1916 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1917 if (!target_can_be_compressed(ctx
, target
)) {
1918 _mesa_error(ctx
, GL_INVALID_ENUM
,
1919 "glCopyTexImage%dD(target)", dimensions
);
1923 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1924 "glCopyTexImage%dD(border!=0)", dimensions
);
1928 else if (_mesa_is_depth_format(internalFormat
)) {
1929 /* make sure we have depth/stencil buffers */
1930 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1931 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1932 "glCopyTexImage%dD(no depth)", dimensions
);
1936 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1937 /* make sure we have depth/stencil buffers */
1938 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1940 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1945 /* if we get here, the parameters are OK */
1951 * Test glCopyTexSubImage[12]D() parameters for errors.
1952 * Note that this is the first part of error checking.
1953 * See also copytexsubimage_error_check2() below for the second part.
1955 * \param ctx GL context.
1956 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1957 * \param target texture target given by the user.
1958 * \param level image level given by the user.
1960 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1963 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
1964 GLenum target
, GLint level
)
1966 /* Check that the source buffer is complete */
1967 if (ctx
->ReadBuffer
->Name
) {
1968 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1969 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1970 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1971 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1977 if (dimensions
== 1) {
1978 if (target
!= GL_TEXTURE_1D
) {
1979 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1983 else if (dimensions
== 2) {
1984 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1985 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1986 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1987 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1991 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1992 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1993 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1997 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1998 if (!ctx
->Extensions
.MESA_texture_array
) {
1999 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2003 else if (target
!= GL_TEXTURE_2D
) {
2004 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2008 else if (dimensions
== 3) {
2009 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2010 (!ctx
->Extensions
.MESA_texture_array
))
2011 && (target
!= GL_TEXTURE_3D
)) {
2012 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2018 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2019 _mesa_error(ctx
, GL_INVALID_VALUE
,
2020 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2029 * Second part of error checking for glCopyTexSubImage[12]D().
2030 * \param xoffset sub-image x offset given by the user.
2031 * \param yoffset sub-image y offset given by the user.
2032 * \param zoffset sub-image z offset given by the user.
2033 * \param width image width given by the user.
2034 * \param height image height given by the user.
2037 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2038 GLenum target
, GLint level
,
2039 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2040 GLsizei width
, GLsizei height
,
2041 const struct gl_texture_image
*teximage
)
2043 /* check that dest tex image exists */
2045 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2046 "glCopyTexSubImage%dD(undefined texture level: %d)",
2053 _mesa_error(ctx
, GL_INVALID_VALUE
,
2054 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2057 if (dimensions
> 1 && height
< 0) {
2058 _mesa_error(ctx
, GL_INVALID_VALUE
,
2059 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2063 /* check x/y offsets */
2064 if (xoffset
< -((GLint
)teximage
->Border
)) {
2065 _mesa_error(ctx
, GL_INVALID_VALUE
,
2066 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2069 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2070 _mesa_error(ctx
, GL_INVALID_VALUE
,
2071 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2074 if (dimensions
> 1) {
2075 if (yoffset
< -((GLint
)teximage
->Border
)) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
,
2077 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2080 /* NOTE: we're adding the border here, not subtracting! */
2081 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2082 _mesa_error(ctx
, GL_INVALID_VALUE
,
2083 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2088 /* check z offset */
2089 if (dimensions
> 2) {
2090 if (zoffset
< -((GLint
)teximage
->Border
)) {
2091 _mesa_error(ctx
, GL_INVALID_VALUE
,
2092 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2095 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2096 _mesa_error(ctx
, GL_INVALID_VALUE
,
2097 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2102 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2103 if (!target_can_be_compressed(ctx
, target
)) {
2104 _mesa_error(ctx
, GL_INVALID_ENUM
,
2105 "glCopyTexSubImage%dD(target)", dimensions
);
2108 /* offset must be multiple of 4 */
2109 if ((xoffset
& 3) || (yoffset
& 3)) {
2110 _mesa_error(ctx
, GL_INVALID_VALUE
,
2111 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2114 /* size must be multiple of 4 */
2115 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2116 _mesa_error(ctx
, GL_INVALID_VALUE
,
2117 "glCopyTexSubImage%dD(width)", dimensions
);
2120 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "glCopyTexSubImage%dD(height)", dimensions
);
2127 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2128 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2132 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2133 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2134 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2135 dimensions
, teximage
->_BaseFormat
);
2139 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2140 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2141 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2142 "glCopyTexSubImage%dD(no depth buffer)",
2147 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2148 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2149 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2150 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2156 /* If copying into an integer texture, the source buffer must also be
2159 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2160 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2161 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glCopyTexSubImage%dD(source buffer is not integer format)",
2169 /* if we get here, the parameters are OK */
2174 /** Callback info for walking over FBO hash table */
2177 struct gl_context
*ctx
;
2178 struct gl_texture_object
*texObj
;
2184 * Check render to texture callback. Called from _mesa_HashWalk().
2187 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2189 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2190 const struct cb_info
*info
= (struct cb_info
*) userData
;
2191 struct gl_context
*ctx
= info
->ctx
;
2192 const struct gl_texture_object
*texObj
= info
->texObj
;
2193 const GLuint level
= info
->level
, face
= info
->face
;
2195 /* If this is a user-created FBO */
2198 /* check if any of the FBO's attachments point to 'texObj' */
2199 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2200 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2201 if (att
->Type
== GL_TEXTURE
&&
2202 att
->Texture
== texObj
&&
2203 att
->TextureLevel
== level
&&
2204 att
->CubeMapFace
== face
) {
2205 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2206 /* Tell driver about the new renderbuffer texture */
2207 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2208 /* Mark fb status as indeterminate to force re-validation */
2217 * When a texture image is specified we have to check if it's bound to
2218 * any framebuffer objects (render to texture) in order to detect changes
2219 * in size or format since that effects FBO completeness.
2220 * Any FBOs rendering into the texture must be re-validated.
2223 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2224 GLuint face
, GLuint level
)
2226 /* Only check this texture if it's been marked as RenderToTexture */
2227 if (texObj
->_RenderToTexture
) {
2228 struct cb_info info
;
2230 info
.texObj
= texObj
;
2233 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2239 * If the texture object's GenerateMipmap flag is set and we've
2240 * changed the texture base level image, regenerate the rest of the
2241 * mipmap levels now.
2244 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2245 struct gl_texture_object
*texObj
, GLint level
)
2247 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2248 if (texObj
->GenerateMipmap
&&
2249 level
== texObj
->BaseLevel
&&
2250 level
< texObj
->MaxLevel
) {
2251 ASSERT(ctx
->Driver
.GenerateMipmap
);
2252 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2257 /** Debug helper: override the user-requested internal format */
2259 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2262 if (internalFormat
== GL_RGBA16F_ARB
||
2263 internalFormat
== GL_RGBA32F_ARB
) {
2264 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2267 else if (internalFormat
== GL_RGB16F_ARB
||
2268 internalFormat
== GL_RGB32F_ARB
) {
2269 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2272 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2273 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2274 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2275 return GL_LUMINANCE_ALPHA
;
2277 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2278 internalFormat
== GL_LUMINANCE32F_ARB
) {
2279 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2280 return GL_LUMINANCE
;
2282 else if (internalFormat
== GL_ALPHA16F_ARB
||
2283 internalFormat
== GL_ALPHA32F_ARB
) {
2284 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2288 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2289 internalFormat = GL_RGBA;
2293 return internalFormat
;
2296 return internalFormat
;
2302 * Choose the actual hardware format for a texture image.
2303 * Try to use the same format as the previous image level when possible.
2304 * Otherwise, ask the driver for the best format.
2305 * It's important to try to choose a consistant format for all levels
2306 * for efficient texture memory layout/allocation. In particular, this
2307 * comes up during automatic mipmap generation.
2310 _mesa_choose_texture_format(struct gl_context
*ctx
,
2311 struct gl_texture_object
*texObj
,
2312 GLenum target
, GLint level
,
2313 GLenum internalFormat
, GLenum format
, GLenum type
)
2317 /* see if we've already chosen a format for the previous level */
2319 struct gl_texture_image
*prevImage
=
2320 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2321 /* See if the prev level is defined and has an internal format which
2322 * matches the new internal format.
2325 prevImage
->Width
> 0 &&
2326 prevImage
->InternalFormat
== internalFormat
) {
2327 /* use the same format */
2328 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2329 return prevImage
->TexFormat
;
2333 /* choose format from scratch */
2334 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2335 ASSERT(f
!= MESA_FORMAT_NONE
);
2342 * Called from the API. Note that width includes the border.
2345 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2346 GLsizei width
, GLint border
, GLenum format
,
2347 GLenum type
, const GLvoid
*pixels
)
2349 GET_CURRENT_CONTEXT(ctx
);
2350 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2352 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2353 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2354 _mesa_lookup_enum_by_nr(target
), level
,
2355 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2356 _mesa_lookup_enum_by_nr(format
),
2357 _mesa_lookup_enum_by_nr(type
), pixels
);
2359 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2361 if (target
== GL_TEXTURE_1D
) {
2362 /* non-proxy target */
2363 struct gl_texture_object
*texObj
;
2364 struct gl_texture_image
*texImage
;
2365 const GLuint face
= _mesa_tex_target_to_face(target
);
2367 if (texture_error_check(ctx
, 1, target
, level
, internalFormat
,
2368 format
, type
, width
, 1, 1, border
)) {
2369 return; /* error was recorded */
2372 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2373 _mesa_update_state(ctx
);
2375 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2376 _mesa_lock_texture(ctx
, texObj
);
2378 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2380 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2383 gl_format texFormat
;
2385 if (texImage
->Data
) {
2386 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2389 ASSERT(texImage
->Data
== NULL
);
2391 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2392 internalFormat
, format
,
2395 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2397 border
, internalFormat
,
2400 /* Give the texture to the driver. <pixels> may be null. */
2401 ASSERT(ctx
->Driver
.TexImage1D
);
2402 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2403 width
, border
, format
, type
, pixels
,
2404 &ctx
->Unpack
, texObj
, texImage
);
2406 check_gen_mipmap(ctx
, target
, texObj
, level
);
2408 update_fbo_texture(ctx
, texObj
, face
, level
);
2411 texObj
->_Complete
= GL_FALSE
;
2412 ctx
->NewState
|= _NEW_TEXTURE
;
2415 _mesa_unlock_texture(ctx
, texObj
);
2417 else if (target
== GL_PROXY_TEXTURE_1D
) {
2418 /* Proxy texture: check for errors and update proxy state */
2419 struct gl_texture_image
*texImage
;
2420 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2421 if (texture_error_check(ctx
, 1, target
, level
, internalFormat
,
2422 format
, type
, width
, 1, 1, border
)) {
2423 /* when error, clear all proxy texture image parameters */
2425 clear_teximage_fields(texImage
);
2428 /* no error, set the tex image parameters */
2429 struct gl_texture_object
*texObj
=
2430 _mesa_get_current_tex_object(ctx
, target
);
2431 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
,
2435 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2436 border
, internalFormat
, texFormat
);
2440 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2447 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2448 GLsizei width
, GLsizei height
, GLint border
,
2449 GLenum format
, GLenum type
,
2450 const GLvoid
*pixels
)
2452 GET_CURRENT_CONTEXT(ctx
);
2453 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2455 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2456 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2457 _mesa_lookup_enum_by_nr(target
), level
,
2458 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2459 border
, _mesa_lookup_enum_by_nr(format
),
2460 _mesa_lookup_enum_by_nr(type
), pixels
);
2462 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2464 if (target
== GL_TEXTURE_2D
||
2465 (ctx
->Extensions
.ARB_texture_cube_map
&&
2466 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2467 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2468 (ctx
->Extensions
.NV_texture_rectangle
&&
2469 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2470 (ctx
->Extensions
.MESA_texture_array
&&
2471 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2472 /* non-proxy target */
2473 struct gl_texture_object
*texObj
;
2474 struct gl_texture_image
*texImage
;
2475 const GLuint face
= _mesa_tex_target_to_face(target
);
2477 if (texture_error_check(ctx
, 2, target
, level
, internalFormat
,
2478 format
, type
, width
, height
, 1, border
)) {
2479 return; /* error was recorded */
2482 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2483 _mesa_update_state(ctx
);
2485 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2486 _mesa_lock_texture(ctx
, texObj
);
2488 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2490 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2493 gl_format texFormat
;
2495 if (texImage
->Data
) {
2496 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2499 ASSERT(texImage
->Data
== NULL
);
2501 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2502 internalFormat
, format
,
2505 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2506 border
, internalFormat
, texFormat
);
2508 /* Give the texture to the driver. <pixels> may be null. */
2509 ASSERT(ctx
->Driver
.TexImage2D
);
2510 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2511 width
, height
, border
, format
, type
,
2512 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2514 check_gen_mipmap(ctx
, target
, texObj
, level
);
2516 update_fbo_texture(ctx
, texObj
, face
, level
);
2519 texObj
->_Complete
= GL_FALSE
;
2520 ctx
->NewState
|= _NEW_TEXTURE
;
2523 _mesa_unlock_texture(ctx
, texObj
);
2525 else if (target
== GL_PROXY_TEXTURE_2D
||
2526 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2527 ctx
->Extensions
.ARB_texture_cube_map
) ||
2528 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2529 ctx
->Extensions
.NV_texture_rectangle
) ||
2530 (ctx
->Extensions
.MESA_texture_array
&&
2531 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2532 /* Proxy texture: check for errors and update proxy state */
2533 struct gl_texture_image
*texImage
;
2534 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2535 if (texture_error_check(ctx
, 2, target
, level
, internalFormat
,
2536 format
, type
, width
, height
, 1, border
)) {
2537 /* when error, clear all proxy texture image parameters */
2539 clear_teximage_fields(texImage
);
2542 /* no error, set the tex image parameters */
2543 struct gl_texture_object
*texObj
=
2544 _mesa_get_current_tex_object(ctx
, target
);
2545 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2549 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2550 border
, internalFormat
, texFormat
);
2554 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2561 * Called by the API or display list executor.
2562 * Note that width and height include the border.
2565 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2566 GLsizei width
, GLsizei height
, GLsizei depth
,
2567 GLint border
, GLenum format
, GLenum type
,
2568 const GLvoid
*pixels
)
2570 GET_CURRENT_CONTEXT(ctx
);
2571 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2573 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2574 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2575 _mesa_lookup_enum_by_nr(target
), level
,
2576 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2577 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2578 _mesa_lookup_enum_by_nr(type
), pixels
);
2580 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2582 if (target
== GL_TEXTURE_3D
||
2583 (ctx
->Extensions
.MESA_texture_array
&&
2584 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2585 /* non-proxy target */
2586 struct gl_texture_object
*texObj
;
2587 struct gl_texture_image
*texImage
;
2588 const GLuint face
= _mesa_tex_target_to_face(target
);
2590 if (texture_error_check(ctx
, 3, target
, level
, (GLint
) internalFormat
,
2591 format
, type
, width
, height
, depth
, border
)) {
2592 return; /* error was recorded */
2595 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2596 _mesa_update_state(ctx
);
2598 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2599 _mesa_lock_texture(ctx
, texObj
);
2601 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2603 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2606 gl_format texFormat
;
2608 if (texImage
->Data
) {
2609 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2612 ASSERT(texImage
->Data
== NULL
);
2613 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2614 internalFormat
, format
,
2616 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2617 width
, height
, depth
,
2618 border
, internalFormat
, texFormat
);
2620 /* Give the texture to the driver. <pixels> may be null. */
2621 ASSERT(ctx
->Driver
.TexImage3D
);
2622 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2623 width
, height
, depth
, border
, format
, type
,
2624 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2626 check_gen_mipmap(ctx
, target
, texObj
, level
);
2628 update_fbo_texture(ctx
, texObj
, face
, level
);
2631 texObj
->_Complete
= GL_FALSE
;
2632 ctx
->NewState
|= _NEW_TEXTURE
;
2635 _mesa_unlock_texture(ctx
, texObj
);
2637 else if (target
== GL_PROXY_TEXTURE_3D
||
2638 (ctx
->Extensions
.MESA_texture_array
&&
2639 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2640 /* Proxy texture: check for errors and update proxy state */
2641 struct gl_texture_image
*texImage
;
2642 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2643 if (texture_error_check(ctx
, 3, target
, level
, internalFormat
,
2644 format
, type
, width
, height
, depth
, border
)) {
2645 /* when error, clear all proxy texture image parameters */
2647 clear_teximage_fields(texImage
);
2650 /* no error, set the tex image parameters */
2651 struct gl_texture_object
*texObj
=
2652 _mesa_get_current_tex_object(ctx
, target
);
2653 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2657 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2658 depth
, border
, internalFormat
, texFormat
);
2662 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2669 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2670 GLsizei width
, GLsizei height
, GLsizei depth
,
2671 GLint border
, GLenum format
, GLenum type
,
2672 const GLvoid
*pixels
)
2674 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2675 depth
, border
, format
, type
, pixels
);
2679 #if FEATURE_OES_EGL_image
2681 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2683 struct gl_texture_object
*texObj
;
2684 struct gl_texture_image
*texImage
;
2685 GET_CURRENT_CONTEXT(ctx
);
2686 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2688 if (!ctx
->Extensions
.OES_EGL_image
) {
2689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2690 "glEGLImageTargetTexture2DOES(unsupported)");
2694 if (target
!= GL_TEXTURE_2D
) {
2695 _mesa_error(ctx
, GL_INVALID_ENUM
,
2696 "glEGLImageTargetTexture2D(target=%d)", target
);
2700 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2701 _mesa_update_state(ctx
);
2703 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2704 _mesa_lock_texture(ctx
, texObj
);
2706 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2708 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2711 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2713 ASSERT(texImage
->Data
== NULL
);
2714 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2715 texObj
, texImage
, image
);
2718 texObj
->_Complete
= GL_FALSE
;
2719 ctx
->NewState
|= _NEW_TEXTURE
;
2721 _mesa_unlock_texture(ctx
, texObj
);
2728 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2729 GLint xoffset
, GLsizei width
,
2730 GLenum format
, GLenum type
,
2731 const GLvoid
*pixels
)
2733 struct gl_texture_object
*texObj
;
2734 struct gl_texture_image
*texImage
;
2735 GET_CURRENT_CONTEXT(ctx
);
2736 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2738 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2739 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2740 _mesa_lookup_enum_by_nr(target
), level
,
2741 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2742 _mesa_lookup_enum_by_nr(type
), pixels
);
2744 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2745 _mesa_update_state(ctx
);
2747 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2748 width
, 1, 1, format
, type
)) {
2749 return; /* error was detected */
2753 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2756 _mesa_lock_texture(ctx
, texObj
);
2758 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2760 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2761 width
, 1, 1, format
, type
, texImage
)) {
2762 /* error was recorded */
2764 else if (width
> 0) {
2765 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2766 xoffset
+= texImage
->Border
;
2768 ASSERT(ctx
->Driver
.TexSubImage1D
);
2769 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2770 format
, type
, pixels
, &ctx
->Unpack
,
2773 check_gen_mipmap(ctx
, target
, texObj
, level
);
2775 ctx
->NewState
|= _NEW_TEXTURE
;
2778 _mesa_unlock_texture(ctx
, texObj
);
2783 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2784 GLint xoffset
, GLint yoffset
,
2785 GLsizei width
, GLsizei height
,
2786 GLenum format
, GLenum type
,
2787 const GLvoid
*pixels
)
2789 struct gl_texture_object
*texObj
;
2790 struct gl_texture_image
*texImage
;
2791 GET_CURRENT_CONTEXT(ctx
);
2792 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2794 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2795 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2796 _mesa_lookup_enum_by_nr(target
), level
,
2797 xoffset
, yoffset
, width
, height
,
2798 _mesa_lookup_enum_by_nr(format
),
2799 _mesa_lookup_enum_by_nr(type
), pixels
);
2801 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2802 _mesa_update_state(ctx
);
2804 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2805 width
, height
, 1, format
, type
)) {
2806 return; /* error was detected */
2809 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2811 _mesa_lock_texture(ctx
, texObj
);
2813 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2815 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2816 width
, height
, 1, format
, type
, texImage
)) {
2817 /* error was recorded */
2819 else if (width
> 0 && height
>= 0) {
2820 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2821 xoffset
+= texImage
->Border
;
2822 yoffset
+= texImage
->Border
;
2824 ASSERT(ctx
->Driver
.TexSubImage2D
);
2825 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2826 width
, height
, format
, type
, pixels
,
2827 &ctx
->Unpack
, texObj
, texImage
);
2829 check_gen_mipmap(ctx
, target
, texObj
, level
);
2831 ctx
->NewState
|= _NEW_TEXTURE
;
2834 _mesa_unlock_texture(ctx
, texObj
);
2840 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2841 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2842 GLsizei width
, GLsizei height
, GLsizei depth
,
2843 GLenum format
, GLenum type
,
2844 const GLvoid
*pixels
)
2846 struct gl_texture_object
*texObj
;
2847 struct gl_texture_image
*texImage
;
2848 GET_CURRENT_CONTEXT(ctx
);
2849 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2851 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2852 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2853 _mesa_lookup_enum_by_nr(target
), level
,
2854 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2855 _mesa_lookup_enum_by_nr(format
),
2856 _mesa_lookup_enum_by_nr(type
), pixels
);
2858 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2859 _mesa_update_state(ctx
);
2861 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2862 width
, height
, depth
, format
, type
)) {
2863 return; /* error was detected */
2866 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2868 _mesa_lock_texture(ctx
, texObj
);
2870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2872 if (subtexture_error_check2(ctx
, 3, target
, level
,
2873 xoffset
, yoffset
, zoffset
,
2874 width
, height
, depth
,
2875 format
, type
, texImage
)) {
2876 /* error was recorded */
2878 else if (width
> 0 && height
> 0 && height
> 0) {
2879 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2880 xoffset
+= texImage
->Border
;
2881 yoffset
+= texImage
->Border
;
2882 zoffset
+= texImage
->Border
;
2884 ASSERT(ctx
->Driver
.TexSubImage3D
);
2885 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2886 xoffset
, yoffset
, zoffset
,
2887 width
, height
, depth
,
2888 format
, type
, pixels
,
2889 &ctx
->Unpack
, texObj
, texImage
);
2891 check_gen_mipmap(ctx
, target
, texObj
, level
);
2893 ctx
->NewState
|= _NEW_TEXTURE
;
2896 _mesa_unlock_texture(ctx
, texObj
);
2902 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2903 GLenum internalFormat
,
2905 GLsizei width
, GLint border
)
2907 struct gl_texture_object
*texObj
;
2908 struct gl_texture_image
*texImage
;
2909 const GLuint face
= _mesa_tex_target_to_face(target
);
2910 GET_CURRENT_CONTEXT(ctx
);
2911 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2913 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2914 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2915 _mesa_lookup_enum_by_nr(target
), level
,
2916 _mesa_lookup_enum_by_nr(internalFormat
),
2917 x
, y
, width
, border
);
2919 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2920 _mesa_update_state(ctx
);
2922 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2926 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2928 _mesa_lock_texture(ctx
, texObj
);
2930 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2932 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2935 gl_format texFormat
;
2937 if (texImage
->Data
) {
2938 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2941 ASSERT(texImage
->Data
== NULL
);
2943 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2944 internalFormat
, GL_NONE
,
2947 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2948 border
, internalFormat
, texFormat
);
2950 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2951 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2952 x
, y
, width
, border
);
2954 check_gen_mipmap(ctx
, target
, texObj
, level
);
2956 update_fbo_texture(ctx
, texObj
, face
, level
);
2959 texObj
->_Complete
= GL_FALSE
;
2960 ctx
->NewState
|= _NEW_TEXTURE
;
2963 _mesa_unlock_texture(ctx
, texObj
);
2969 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2970 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2973 struct gl_texture_object
*texObj
;
2974 struct gl_texture_image
*texImage
;
2975 const GLuint face
= _mesa_tex_target_to_face(target
);
2976 GET_CURRENT_CONTEXT(ctx
);
2977 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2979 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2980 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2981 _mesa_lookup_enum_by_nr(target
), level
,
2982 _mesa_lookup_enum_by_nr(internalFormat
),
2983 x
, y
, width
, height
, border
);
2985 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2986 _mesa_update_state(ctx
);
2988 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2989 width
, height
, border
))
2992 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2994 _mesa_lock_texture(ctx
, texObj
);
2996 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2999 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3002 gl_format texFormat
;
3004 if (texImage
->Data
) {
3005 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3008 ASSERT(texImage
->Data
== NULL
);
3010 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3011 internalFormat
, GL_NONE
,
3014 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3015 border
, internalFormat
, texFormat
);
3017 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3018 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
3019 x
, y
, width
, height
, border
);
3021 check_gen_mipmap(ctx
, target
, texObj
, level
);
3023 update_fbo_texture(ctx
, texObj
, face
, level
);
3026 texObj
->_Complete
= GL_FALSE
;
3027 ctx
->NewState
|= _NEW_TEXTURE
;
3030 _mesa_unlock_texture(ctx
, texObj
);
3035 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3036 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3038 struct gl_texture_object
*texObj
;
3039 struct gl_texture_image
*texImage
;
3043 GET_CURRENT_CONTEXT(ctx
);
3044 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3046 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3047 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
3048 _mesa_lookup_enum_by_nr(target
),
3049 level
, xoffset
, x
, y
, width
);
3051 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3052 _mesa_update_state(ctx
);
3054 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3057 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3059 _mesa_lock_texture(ctx
, texObj
);
3061 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3063 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3064 xoffset
, 0, 0, width
, 1, texImage
)) {
3065 /* error was recorded */
3068 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3069 xoffset
+= texImage
->Border
;
3071 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3073 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3074 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3075 xoffset
, x
, y
, width
);
3077 check_gen_mipmap(ctx
, target
, texObj
, level
);
3079 ctx
->NewState
|= _NEW_TEXTURE
;
3083 _mesa_unlock_texture(ctx
, texObj
);
3089 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3090 GLint xoffset
, GLint yoffset
,
3091 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3093 struct gl_texture_object
*texObj
;
3094 struct gl_texture_image
*texImage
;
3095 GET_CURRENT_CONTEXT(ctx
);
3096 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3098 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3099 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
3100 _mesa_lookup_enum_by_nr(target
),
3101 level
, xoffset
, yoffset
, x
, y
, width
, height
);
3103 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3104 _mesa_update_state(ctx
);
3106 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3109 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3111 _mesa_lock_texture(ctx
, texObj
);
3113 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3115 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
3116 xoffset
, yoffset
, 0,
3117 width
, height
, texImage
)) {
3118 /* error was recorded */
3121 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3122 xoffset
+= texImage
->Border
;
3123 yoffset
+= texImage
->Border
;
3125 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3127 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3128 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
3129 x
, y
, width
, height
);
3131 check_gen_mipmap(ctx
, target
, texObj
, level
);
3133 ctx
->NewState
|= _NEW_TEXTURE
;
3137 _mesa_unlock_texture(ctx
, texObj
);
3143 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3144 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3145 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3147 struct gl_texture_object
*texObj
;
3148 struct gl_texture_image
*texImage
;
3149 GET_CURRENT_CONTEXT(ctx
);
3150 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3152 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3153 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
3154 _mesa_lookup_enum_by_nr(target
),
3155 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3157 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3158 _mesa_update_state(ctx
);
3160 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3163 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3165 _mesa_lock_texture(ctx
, texObj
);
3167 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3169 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3170 zoffset
, width
, height
, texImage
)) {
3171 /* error was recored */
3174 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3175 xoffset
+= texImage
->Border
;
3176 yoffset
+= texImage
->Border
;
3177 zoffset
+= texImage
->Border
;
3179 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3181 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3182 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3183 xoffset
, yoffset
, zoffset
,
3184 x
, y
, width
, height
);
3186 check_gen_mipmap(ctx
, target
, texObj
, level
);
3188 ctx
->NewState
|= _NEW_TEXTURE
;
3192 _mesa_unlock_texture(ctx
, texObj
);
3198 /**********************************************************************/
3199 /****** Compressed Textures ******/
3200 /**********************************************************************/
3204 * Return expected size of a compressed texture.
3207 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3210 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3211 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3216 * Return compressed texture block size, in pixels.
3219 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3221 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3222 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3227 * Error checking for glCompressedTexImage[123]D().
3228 * \return error code or GL_NO_ERROR.
3231 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3232 GLenum target
, GLint level
,
3233 GLenum internalFormat
, GLsizei width
,
3234 GLsizei height
, GLsizei depth
, GLint border
,
3237 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3239 if (dimensions
== 1) {
3240 /* 1D compressed textures not allowed */
3241 return GL_INVALID_ENUM
;
3243 else if (dimensions
== 2) {
3244 if (target
== GL_PROXY_TEXTURE_2D
) {
3245 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3247 else if (target
== GL_TEXTURE_2D
) {
3248 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3250 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3251 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3252 return GL_INVALID_ENUM
; /*target*/
3253 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3255 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3256 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3257 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3258 return GL_INVALID_ENUM
; /*target*/
3259 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3262 return GL_INVALID_ENUM
; /*target*/
3265 else if (dimensions
== 3) {
3266 /* 3D compressed textures not allowed */
3267 return GL_INVALID_ENUM
;
3271 return GL_INVALID_ENUM
;
3274 maxTextureSize
= 1 << (maxLevels
- 1);
3276 /* This will detect any invalid internalFormat value */
3277 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3278 return GL_INVALID_ENUM
;
3280 /* This should really never fail */
3281 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3282 return GL_INVALID_ENUM
;
3285 return GL_INVALID_VALUE
;
3288 * XXX We should probably use the proxy texture error check function here.
3290 if (width
< 1 || width
> maxTextureSize
||
3291 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3292 return GL_INVALID_VALUE
;
3294 if ((height
< 1 || height
> maxTextureSize
||
3295 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3297 return GL_INVALID_VALUE
;
3299 if ((depth
< 1 || depth
> maxTextureSize
||
3300 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3302 return GL_INVALID_VALUE
;
3304 /* For cube map, width must equal height */
3305 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3306 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3307 return GL_INVALID_VALUE
;
3309 if (level
< 0 || level
>= maxLevels
)
3310 return GL_INVALID_VALUE
;
3312 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3313 if (expectedSize
!= imageSize
)
3314 return GL_INVALID_VALUE
;
3316 #if FEATURE_EXT_texture_sRGB
3317 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3318 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3319 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3320 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3322 return GL_INVALID_OPERATION
;
3331 * Error checking for glCompressedTexSubImage[123]D().
3332 * \warning There are some bad assumptions here about the size of compressed
3333 * texture tiles (multiple of 4) used to test the validity of the
3334 * offset and size parameters.
3335 * \return error code or GL_NO_ERROR.
3338 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3339 GLenum target
, GLint level
,
3340 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3341 GLsizei width
, GLsizei height
, GLsizei depth
,
3342 GLenum format
, GLsizei imageSize
)
3344 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3348 if (dimensions
== 1) {
3349 /* 1D compressed textures not allowed */
3350 return GL_INVALID_ENUM
;
3352 else if (dimensions
== 2) {
3353 if (target
== GL_PROXY_TEXTURE_2D
) {
3354 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3356 else if (target
== GL_TEXTURE_2D
) {
3357 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3359 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3360 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3361 return GL_INVALID_ENUM
; /*target*/
3362 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3364 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3365 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3366 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3367 return GL_INVALID_ENUM
; /*target*/
3368 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3371 return GL_INVALID_ENUM
; /*target*/
3374 else if (dimensions
== 3) {
3375 /* 3D compressed textures not allowed */
3376 return GL_INVALID_ENUM
;
3379 maxTextureSize
= 1 << (maxLevels
- 1);
3381 /* this will catch any invalid compressed format token */
3382 if (!_mesa_is_compressed_format(ctx
, format
))
3383 return GL_INVALID_ENUM
;
3385 if (width
< 1 || width
> maxTextureSize
)
3386 return GL_INVALID_VALUE
;
3388 if ((height
< 1 || height
> maxTextureSize
)
3390 return GL_INVALID_VALUE
;
3392 if (level
< 0 || level
>= maxLevels
)
3393 return GL_INVALID_VALUE
;
3396 * do checks which depend on compression block size
3398 get_compressed_block_size(format
, &bw
, &bh
);
3400 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3401 return GL_INVALID_VALUE
;
3403 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3404 return GL_INVALID_VALUE
;
3406 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3407 return GL_INVALID_VALUE
;
3409 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3410 if (expectedSize
!= imageSize
)
3411 return GL_INVALID_VALUE
;
3418 * Do second part of glCompressedTexSubImage error checking.
3419 * \return GL_TRUE if error found, GL_FALSE otherwise.
3422 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3423 GLsizei width
, GLsizei height
,
3424 GLsizei depth
, GLenum format
,
3425 struct gl_texture_image
*texImage
)
3428 if ((GLint
) format
!= texImage
->InternalFormat
) {
3429 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3430 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3434 if (((width
== 1 || width
== 2) &&
3435 width
!= (GLsizei
) texImage
->Width
) ||
3436 (width
> (GLsizei
) texImage
->Width
)) {
3437 _mesa_error(ctx
, GL_INVALID_VALUE
,
3438 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3443 if (((height
== 1 || height
== 2) &&
3444 height
!= (GLsizei
) texImage
->Height
) ||
3445 (height
> (GLsizei
) texImage
->Height
)) {
3446 _mesa_error(ctx
, GL_INVALID_VALUE
,
3447 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3453 if (((depth
== 1 || depth
== 2) &&
3454 depth
!= (GLsizei
) texImage
->Depth
) ||
3455 (depth
> (GLsizei
) texImage
->Depth
)) {
3456 _mesa_error(ctx
, GL_INVALID_VALUE
,
3457 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3468 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3469 GLenum internalFormat
, GLsizei width
,
3470 GLint border
, GLsizei imageSize
,
3473 GET_CURRENT_CONTEXT(ctx
);
3474 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3476 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3477 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3478 _mesa_lookup_enum_by_nr(target
), level
,
3479 _mesa_lookup_enum_by_nr(internalFormat
),
3480 width
, border
, imageSize
, data
);
3482 if (target
== GL_TEXTURE_1D
) {
3483 /* non-proxy target */
3484 struct gl_texture_object
*texObj
;
3485 struct gl_texture_image
*texImage
;
3486 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3487 internalFormat
, width
, 1, 1, border
, imageSize
);
3489 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3493 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3495 _mesa_lock_texture(ctx
, texObj
);
3497 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3499 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3502 gl_format texFormat
;
3504 if (texImage
->Data
) {
3505 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3507 ASSERT(texImage
->Data
== NULL
);
3509 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3510 internalFormat
, GL_NONE
,
3513 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3514 border
, internalFormat
, texFormat
);
3516 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3517 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3518 internalFormat
, width
, border
,
3522 check_gen_mipmap(ctx
, target
, texObj
, level
);
3525 texObj
->_Complete
= GL_FALSE
;
3526 ctx
->NewState
|= _NEW_TEXTURE
;
3529 _mesa_unlock_texture(ctx
, texObj
);
3531 else if (target
== GL_PROXY_TEXTURE_1D
) {
3532 /* Proxy texture: check for errors and update proxy state */
3533 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3534 internalFormat
, width
, 1, 1, border
, imageSize
);
3536 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3537 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3538 internalFormat
, GL_NONE
, GL_NONE
,
3539 width
, 1, 1, border
);
3542 /* if error, clear all proxy texture image parameters */
3543 struct gl_texture_image
*texImage
;
3544 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3546 clear_teximage_fields(texImage
);
3549 /* store the teximage parameters */
3550 struct gl_texture_object
*texObj
;
3551 struct gl_texture_image
*texImage
;
3552 gl_format texFormat
;
3554 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3556 _mesa_lock_texture(ctx
, texObj
);
3558 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3559 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3560 internalFormat
, GL_NONE
,
3562 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3563 border
, internalFormat
, texFormat
);
3565 _mesa_unlock_texture(ctx
, texObj
);
3569 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3575 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3576 GLenum internalFormat
, GLsizei width
,
3577 GLsizei height
, GLint border
, GLsizei imageSize
,
3580 GET_CURRENT_CONTEXT(ctx
);
3581 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3583 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3584 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3585 _mesa_lookup_enum_by_nr(target
), level
,
3586 _mesa_lookup_enum_by_nr(internalFormat
),
3587 width
, height
, border
, imageSize
, data
);
3590 switch (internalFormat
) {
3591 case GL_PALETTE4_RGB8_OES
:
3592 case GL_PALETTE4_RGBA8_OES
:
3593 case GL_PALETTE4_R5_G6_B5_OES
:
3594 case GL_PALETTE4_RGBA4_OES
:
3595 case GL_PALETTE4_RGB5_A1_OES
:
3596 case GL_PALETTE8_RGB8_OES
:
3597 case GL_PALETTE8_RGBA8_OES
:
3598 case GL_PALETTE8_R5_G6_B5_OES
:
3599 case GL_PALETTE8_RGBA4_OES
:
3600 case GL_PALETTE8_RGB5_A1_OES
:
3601 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3602 width
, height
, imageSize
, data
);
3607 if (target
== GL_TEXTURE_2D
||
3608 (ctx
->Extensions
.ARB_texture_cube_map
&&
3609 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3610 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3611 /* non-proxy target */
3612 struct gl_texture_object
*texObj
;
3613 struct gl_texture_image
*texImage
;
3615 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3616 internalFormat
, width
, height
, 1, border
, imageSize
);
3618 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3622 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3624 _mesa_lock_texture(ctx
, texObj
);
3626 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3628 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3631 gl_format texFormat
;
3633 if (texImage
->Data
) {
3634 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3636 ASSERT(texImage
->Data
== NULL
);
3638 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3639 internalFormat
, GL_NONE
,
3642 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3643 border
, internalFormat
, texFormat
);
3645 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3646 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3647 internalFormat
, width
, height
,
3648 border
, imageSize
, data
,
3651 check_gen_mipmap(ctx
, target
, texObj
, level
);
3654 texObj
->_Complete
= GL_FALSE
;
3655 ctx
->NewState
|= _NEW_TEXTURE
;
3658 _mesa_unlock_texture(ctx
, texObj
);
3660 else if (target
== GL_PROXY_TEXTURE_2D
||
3661 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3662 ctx
->Extensions
.ARB_texture_cube_map
)) {
3663 /* Proxy texture: check for errors and update proxy state */
3664 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3665 internalFormat
, width
, height
, 1, border
, imageSize
);
3667 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3668 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3669 internalFormat
, GL_NONE
, GL_NONE
,
3670 width
, height
, 1, border
);
3673 /* if error, clear all proxy texture image parameters */
3674 struct gl_texture_image
*texImage
;
3675 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3677 clear_teximage_fields(texImage
);
3680 /* store the teximage parameters */
3681 struct gl_texture_object
*texObj
;
3682 struct gl_texture_image
*texImage
;
3683 gl_format texFormat
;
3685 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3687 _mesa_lock_texture(ctx
, texObj
);
3689 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3690 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3691 internalFormat
, GL_NONE
,
3693 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3694 border
, internalFormat
, texFormat
);
3696 _mesa_unlock_texture(ctx
, texObj
);
3700 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3707 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3708 GLenum internalFormat
, GLsizei width
,
3709 GLsizei height
, GLsizei depth
, GLint border
,
3710 GLsizei imageSize
, const GLvoid
*data
)
3712 GET_CURRENT_CONTEXT(ctx
);
3713 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3715 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3716 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3717 _mesa_lookup_enum_by_nr(target
), level
,
3718 _mesa_lookup_enum_by_nr(internalFormat
),
3719 width
, height
, depth
, border
, imageSize
, data
);
3721 if (target
== GL_TEXTURE_3D
) {
3722 /* non-proxy target */
3723 struct gl_texture_object
*texObj
;
3724 struct gl_texture_image
*texImage
;
3725 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3726 internalFormat
, width
, height
, depth
, border
, imageSize
);
3728 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3732 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3734 _mesa_lock_texture(ctx
, texObj
);
3736 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3738 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3741 gl_format texFormat
;
3743 if (texImage
->Data
) {
3744 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3746 ASSERT(texImage
->Data
== NULL
);
3748 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3749 internalFormat
, GL_NONE
,
3752 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3753 width
, height
, depth
,
3754 border
, internalFormat
, texFormat
);
3756 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3757 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3759 width
, height
, depth
,
3760 border
, imageSize
, data
,
3763 check_gen_mipmap(ctx
, target
, texObj
, level
);
3766 texObj
->_Complete
= GL_FALSE
;
3767 ctx
->NewState
|= _NEW_TEXTURE
;
3770 _mesa_unlock_texture(ctx
, texObj
);
3772 else if (target
== GL_PROXY_TEXTURE_3D
) {
3773 /* Proxy texture: check for errors and update proxy state */
3774 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3775 internalFormat
, width
, height
, depth
, border
, imageSize
);
3777 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3778 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3779 internalFormat
, GL_NONE
, GL_NONE
,
3780 width
, height
, depth
, border
);
3783 /* if error, clear all proxy texture image parameters */
3784 struct gl_texture_image
*texImage
;
3785 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3787 clear_teximage_fields(texImage
);
3790 /* store the teximage parameters */
3791 struct gl_texture_object
*texObj
;
3792 struct gl_texture_image
*texImage
;
3793 gl_format texFormat
;
3795 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3797 _mesa_lock_texture(ctx
, texObj
);
3799 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3800 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3801 internalFormat
, GL_NONE
,
3803 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3804 depth
, border
, internalFormat
,
3807 _mesa_unlock_texture(ctx
, texObj
);
3811 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3818 * Common helper for glCompressedTexSubImage1/2/3D().
3821 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3822 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3823 GLsizei width
, GLsizei height
, GLsizei depth
,
3824 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3826 struct gl_texture_object
*texObj
;
3827 struct gl_texture_image
*texImage
;
3829 GET_CURRENT_CONTEXT(ctx
);
3830 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3832 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3833 xoffset
, 0, 0, /* pos */
3834 width
, height
, depth
, /* size */
3837 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3841 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3843 _mesa_lock_texture(ctx
, texObj
);
3845 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3848 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3849 format
, texImage
)) {
3850 /* error was recorded */
3852 else if (width
> 0 && height
> 0 && depth
> 0) {
3855 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3856 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3858 format
, imageSize
, data
,
3863 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3864 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3867 format
, imageSize
, data
,
3872 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3873 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3874 xoffset
, yoffset
, zoffset
,
3875 width
, height
, depth
,
3876 format
, imageSize
, data
,
3884 check_gen_mipmap(ctx
, target
, texObj
, level
);
3886 ctx
->NewState
|= _NEW_TEXTURE
;
3889 _mesa_unlock_texture(ctx
, texObj
);
3894 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3895 GLsizei width
, GLenum format
,
3896 GLsizei imageSize
, const GLvoid
*data
)
3898 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3899 format
, imageSize
, data
);
3904 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3905 GLint yoffset
, GLsizei width
, GLsizei height
,
3906 GLenum format
, GLsizei imageSize
,
3909 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3910 width
, height
, 1, format
, imageSize
, data
);
3915 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3916 GLint yoffset
, GLint zoffset
, GLsizei width
,
3917 GLsizei height
, GLsizei depth
, GLenum format
,
3918 GLsizei imageSize
, const GLvoid
*data
)
3920 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3921 width
, height
, depth
, format
, imageSize
, data
);