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"
39 #include "framebuffer.h"
45 #include "texcompress.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
65 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
69 _mesa_alloc_texmemory(GLsizei bytes
)
71 return _mesa_align_malloc(bytes
, 512);
76 * Free texture memory allocated with _mesa_alloc_texmemory()
79 _mesa_free_texmemory(void *m
)
86 * Compute floor(log_base_2(n)).
116 * Return the simple base format for a given internal texture format.
117 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
119 * \param ctx GL context.
120 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
122 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
123 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
125 * This is the format which is used during texture application (i.e. the
126 * texture format and env mode determine the arithmetic used.
128 * XXX this could be static
131 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
133 switch (internalFormat
) {
148 case GL_LUMINANCE_ALPHA
:
149 case GL_LUMINANCE4_ALPHA4
:
150 case GL_LUMINANCE6_ALPHA2
:
151 case GL_LUMINANCE8_ALPHA8
:
152 case GL_LUMINANCE12_ALPHA4
:
153 case GL_LUMINANCE12_ALPHA12
:
154 case GL_LUMINANCE16_ALPHA16
:
155 return GL_LUMINANCE_ALPHA
;
186 if (ctx
->Extensions
.EXT_paletted_texture
) {
187 switch (internalFormat
) {
189 case GL_COLOR_INDEX1_EXT
:
190 case GL_COLOR_INDEX2_EXT
:
191 case GL_COLOR_INDEX4_EXT
:
192 case GL_COLOR_INDEX8_EXT
:
193 case GL_COLOR_INDEX12_EXT
:
194 case GL_COLOR_INDEX16_EXT
:
195 return GL_COLOR_INDEX
;
201 if (ctx
->Extensions
.ARB_depth_texture
) {
202 switch (internalFormat
) {
203 case GL_DEPTH_COMPONENT
:
204 case GL_DEPTH_COMPONENT16
:
205 case GL_DEPTH_COMPONENT24
:
206 case GL_DEPTH_COMPONENT32
:
207 return GL_DEPTH_COMPONENT
;
213 switch (internalFormat
) {
214 case GL_COMPRESSED_ALPHA
:
216 case GL_COMPRESSED_LUMINANCE
:
218 case GL_COMPRESSED_LUMINANCE_ALPHA
:
219 return GL_LUMINANCE_ALPHA
;
220 case GL_COMPRESSED_INTENSITY
:
222 case GL_COMPRESSED_RGB
:
224 case GL_COMPRESSED_RGBA
:
230 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
231 switch (internalFormat
) {
232 case GL_COMPRESSED_RGB_FXT1_3DFX
:
234 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
241 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
242 switch (internalFormat
) {
243 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
245 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
246 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
247 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
254 if (ctx
->Extensions
.S3_s3tc
) {
255 switch (internalFormat
) {
267 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
268 if (internalFormat
== GL_YCBCR_MESA
)
269 return GL_YCBCR_MESA
;
272 if (ctx
->Extensions
.ARB_texture_float
) {
273 switch (internalFormat
) {
274 case GL_ALPHA16F_ARB
:
275 case GL_ALPHA32F_ARB
:
283 case GL_INTENSITY16F_ARB
:
284 case GL_INTENSITY32F_ARB
:
286 case GL_LUMINANCE16F_ARB
:
287 case GL_LUMINANCE32F_ARB
:
289 case GL_LUMINANCE_ALPHA16F_ARB
:
290 case GL_LUMINANCE_ALPHA32F_ARB
:
291 return GL_LUMINANCE_ALPHA
;
297 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
298 switch (internalFormat
) {
307 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
308 switch (internalFormat
) {
317 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
318 switch (internalFormat
) {
319 case GL_DEPTH_STENCIL_EXT
:
320 case GL_DEPTH24_STENCIL8_EXT
:
321 return GL_DEPTH_STENCIL_EXT
;
327 #if FEATURE_EXT_texture_sRGB
328 if (ctx
->Extensions
.EXT_texture_sRGB
) {
329 switch (internalFormat
) {
332 case GL_COMPRESSED_SRGB_EXT
:
333 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
335 case GL_SRGB_ALPHA_EXT
:
336 case GL_SRGB8_ALPHA8_EXT
:
337 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
340 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
342 case GL_SLUMINANCE_ALPHA_EXT
:
343 case GL_SLUMINANCE8_ALPHA8_EXT
:
344 case GL_COMPRESSED_SLUMINANCE_EXT
:
345 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
346 return GL_LUMINANCE_ALPHA
;
347 case GL_SLUMINANCE_EXT
:
348 case GL_SLUMINANCE8_EXT
:
354 #endif /* FEATURE_EXT_texture_sRGB */
356 if (ctx
->Extensions
.EXT_texture_integer
) {
357 switch (internalFormat
) {
359 case GL_RGBA16UI_EXT
:
360 case GL_RGBA32UI_EXT
:
372 case GL_ALPHA8UI_EXT
:
373 case GL_ALPHA16UI_EXT
:
374 case GL_ALPHA32UI_EXT
:
376 case GL_ALPHA16I_EXT
:
377 case GL_ALPHA32I_EXT
:
379 case GL_INTENSITY8UI_EXT
:
380 case GL_INTENSITY16UI_EXT
:
381 case GL_INTENSITY32UI_EXT
:
382 case GL_INTENSITY8I_EXT
:
383 case GL_INTENSITY16I_EXT
:
384 case GL_INTENSITY32I_EXT
:
386 case GL_LUMINANCE8UI_EXT
:
387 case GL_LUMINANCE16UI_EXT
:
388 case GL_LUMINANCE32UI_EXT
:
389 case GL_LUMINANCE8I_EXT
:
390 case GL_LUMINANCE16I_EXT
:
391 case GL_LUMINANCE32I_EXT
:
393 case GL_LUMINANCE_ALPHA8UI_EXT
:
394 case GL_LUMINANCE_ALPHA16UI_EXT
:
395 case GL_LUMINANCE_ALPHA32UI_EXT
:
396 case GL_LUMINANCE_ALPHA8I_EXT
:
397 case GL_LUMINANCE_ALPHA16I_EXT
:
398 case GL_LUMINANCE_ALPHA32I_EXT
:
399 return GL_LUMINANCE_ALPHA
;
405 if (ctx
->Extensions
.ARB_texture_rg
) {
406 switch (internalFormat
) {
436 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
437 switch (internalFormat
) {
445 if (ctx
->Extensions
.EXT_packed_float
) {
446 switch (internalFormat
) {
447 case GL_R11F_G11F_B10F_EXT
:
454 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
455 switch (internalFormat
) {
456 case GL_DEPTH_COMPONENT32F
:
457 return GL_DEPTH_COMPONENT
;
458 case GL_DEPTH32F_STENCIL8
:
459 return GL_DEPTH_STENCIL
;
465 if (ctx
->Extensions
.EXT_texture_compression_rgtc
) {
466 switch (internalFormat
) {
467 case GL_COMPRESSED_RED
:
468 case GL_COMPRESSED_RED_RGTC1_EXT
:
469 case GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
:
471 case GL_COMPRESSED_RG
:
472 case GL_COMPRESSED_RED_GREEN_RGTC2_EXT
:
473 case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
:
480 return -1; /* error */
485 * For cube map faces, return a face index in [0,5].
486 * For other targets return 0;
489 _mesa_tex_target_to_face(GLenum target
)
491 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
492 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
493 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
501 * Store a gl_texture_image pointer in a gl_texture_object structure
502 * according to the target and level parameters.
504 * \param tObj texture object.
505 * \param target texture target.
506 * \param level image level.
507 * \param texImage texture image.
509 * This was basically prompted by the introduction of cube maps.
512 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
513 GLenum target
, GLint level
,
514 struct gl_texture_image
*texImage
)
516 const GLuint face
= _mesa_tex_target_to_face(target
);
520 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
522 tObj
->Image
[face
][level
] = texImage
;
524 /* Set the 'back' pointer */
525 texImage
->TexObject
= tObj
;
530 * Allocate a texture image structure.
532 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
535 * \return a pointer to gl_texture_image struct with all fields initialized to
538 struct gl_texture_image
*
539 _mesa_new_texture_image( GLcontext
*ctx
)
542 return CALLOC_STRUCT(gl_texture_image
);
547 * Free texture image data.
548 * This function is a fallback called via ctx->Driver.FreeTexImageData().
550 * \param texImage texture image.
552 * Free the texture image data if it's not marked as client data.
555 _mesa_free_texture_image_data(GLcontext
*ctx
,
556 struct gl_texture_image
*texImage
)
560 if (texImage
->Data
&& !texImage
->IsClientData
) {
561 /* free the old texture data */
562 _mesa_free_texmemory(texImage
->Data
);
565 texImage
->Data
= NULL
;
570 * Free texture image.
572 * \param texImage texture image.
574 * Free the texture image structure and the associated image data.
577 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
579 /* Free texImage->Data and/or any other driver-specific texture
582 ASSERT(ctx
->Driver
.FreeTexImageData
);
583 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
585 ASSERT(texImage
->Data
== NULL
);
586 if (texImage
->ImageOffsets
)
587 free(texImage
->ImageOffsets
);
593 * Test if a target is a proxy target.
595 * \param target texture target.
597 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
600 _mesa_is_proxy_texture(GLenum target
)
602 /* NUM_TEXTURE_TARGETS should match number of terms below */
603 assert(NUM_TEXTURE_TARGETS
== 7);
605 return (target
== GL_PROXY_TEXTURE_1D
||
606 target
== GL_PROXY_TEXTURE_2D
||
607 target
== GL_PROXY_TEXTURE_3D
||
608 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
609 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
610 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
611 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
616 * Get the texture object that corresponds to the target of the given texture unit.
618 * \param ctx GL context.
619 * \param texUnit texture unit.
620 * \param target texture target.
622 * \return pointer to the texture object on success, or NULL on failure.
624 * \sa gl_texture_unit.
626 struct gl_texture_object
*
627 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
632 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
633 case GL_PROXY_TEXTURE_1D
:
634 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
636 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
637 case GL_PROXY_TEXTURE_2D
:
638 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
640 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
641 case GL_PROXY_TEXTURE_3D
:
642 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
643 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
644 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
645 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
646 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
647 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
648 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
649 case GL_TEXTURE_CUBE_MAP_ARB
:
650 return ctx
->Extensions
.ARB_texture_cube_map
651 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
652 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
653 return ctx
->Extensions
.ARB_texture_cube_map
654 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
655 case GL_TEXTURE_RECTANGLE_NV
:
656 return ctx
->Extensions
.NV_texture_rectangle
657 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
658 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
659 return ctx
->Extensions
.NV_texture_rectangle
660 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
661 case GL_TEXTURE_1D_ARRAY_EXT
:
662 return ctx
->Extensions
.MESA_texture_array
663 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
664 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
665 return ctx
->Extensions
.MESA_texture_array
666 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
667 case GL_TEXTURE_2D_ARRAY_EXT
:
668 return ctx
->Extensions
.MESA_texture_array
669 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
670 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
671 return ctx
->Extensions
.MESA_texture_array
672 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
674 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
681 * Return pointer to texture object for given target on current texture unit.
683 struct gl_texture_object
*
684 _mesa_get_current_tex_object(GLcontext
*ctx
, GLenum target
)
686 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
687 return _mesa_select_tex_object(ctx
, texUnit
, target
);
692 * Get a texture image pointer from a texture object, given a texture
693 * target and mipmap level. The target and level parameters should
694 * have already been error-checked.
696 * \param ctx GL context.
697 * \param texObj texture unit.
698 * \param target texture target.
699 * \param level image level.
701 * \return pointer to the texture image structure, or NULL on failure.
703 struct gl_texture_image
*
704 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
705 GLenum target
, GLint level
)
707 const GLuint face
= _mesa_tex_target_to_face(target
);
711 ASSERT(level
< MAX_TEXTURE_LEVELS
);
713 return texObj
->Image
[face
][level
];
718 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
719 * it and install it. Only return NULL if passed a bad parameter or run
722 struct gl_texture_image
*
723 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
724 GLenum target
, GLint level
)
726 struct gl_texture_image
*texImage
;
731 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
733 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
735 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
739 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
747 * Return pointer to the specified proxy texture image.
748 * Note that proxy textures are per-context, not per-texture unit.
749 * \return pointer to texture image or NULL if invalid target, invalid
750 * level, or out of memory.
752 struct gl_texture_image
*
753 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
755 struct gl_texture_image
*texImage
;
762 case GL_PROXY_TEXTURE_1D
:
763 if (level
>= ctx
->Const
.MaxTextureLevels
)
765 texIndex
= TEXTURE_1D_INDEX
;
767 case GL_PROXY_TEXTURE_2D
:
768 if (level
>= ctx
->Const
.MaxTextureLevels
)
770 texIndex
= TEXTURE_2D_INDEX
;
772 case GL_PROXY_TEXTURE_3D
:
773 if (level
>= ctx
->Const
.Max3DTextureLevels
)
775 texIndex
= TEXTURE_3D_INDEX
;
777 case GL_PROXY_TEXTURE_CUBE_MAP
:
778 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
780 texIndex
= TEXTURE_CUBE_INDEX
;
782 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
785 texIndex
= TEXTURE_RECT_INDEX
;
787 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
788 if (level
>= ctx
->Const
.MaxTextureLevels
)
790 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
792 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
793 if (level
>= ctx
->Const
.MaxTextureLevels
)
795 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
801 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
803 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
805 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
808 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
809 /* Set the 'back' pointer */
810 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
817 * Get the maximum number of allowed mipmap levels.
819 * \param ctx GL context.
820 * \param target texture target.
822 * \return the maximum number of allowed mipmap levels for the given
823 * texture target, or zero if passed a bad target.
828 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
832 case GL_PROXY_TEXTURE_1D
:
834 case GL_PROXY_TEXTURE_2D
:
835 return ctx
->Const
.MaxTextureLevels
;
837 case GL_PROXY_TEXTURE_3D
:
838 return ctx
->Const
.Max3DTextureLevels
;
839 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
840 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
841 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
842 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
843 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
844 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
845 case GL_TEXTURE_CUBE_MAP_ARB
:
846 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
847 return ctx
->Extensions
.ARB_texture_cube_map
848 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
849 case GL_TEXTURE_RECTANGLE_NV
:
850 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
851 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
852 case GL_TEXTURE_1D_ARRAY_EXT
:
853 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
854 case GL_TEXTURE_2D_ARRAY_EXT
:
855 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
856 return ctx
->Extensions
.MESA_texture_array
857 ? ctx
->Const
.MaxTextureLevels
: 0;
859 return 0; /* bad target */
865 #if 000 /* not used anymore */
867 * glTexImage[123]D can accept a NULL image pointer. In this case we
868 * create a texture image with unspecified image contents per the OpenGL
872 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
874 const GLint components
= _mesa_components_in_format(format
);
875 const GLint numPixels
= width
* height
* depth
;
876 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
880 * Let's see if anyone finds this. If glTexImage2D() is called with
881 * a NULL image pointer then load the texture image with something
882 * interesting instead of leaving it indeterminate.
885 static const char message
[8][32] = {
889 " X X XXXX XXX XXXXX ",
892 " X X XXXXX XXX X X ",
896 GLubyte
*imgPtr
= data
;
898 for (h
= 0; h
< depth
; h
++) {
899 for (i
= 0; i
< height
; i
++) {
900 GLint srcRow
= 7 - (i
% 8);
901 for (j
= 0; j
< width
; j
++) {
902 GLint srcCol
= j
% 32;
903 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
904 for (k
= 0; k
< components
; k
++) {
920 * Reset the fields of a gl_texture_image struct to zero.
922 * \param img texture image structure.
924 * This is called when a proxy texture test fails, we set all the
925 * image members (except DriverData) to zero.
926 * It's also used in glTexImage[123]D as a safeguard to be sure all
927 * required fields get initialized properly by the Driver.TexImage[123]D
931 clear_teximage_fields(struct gl_texture_image
*img
)
934 img
->_BaseFormat
= 0;
935 img
->InternalFormat
= 0;
941 if (img
->ImageOffsets
) {
942 free(img
->ImageOffsets
);
943 img
->ImageOffsets
= NULL
;
952 img
->TexFormat
= MESA_FORMAT_NONE
;
953 img
->FetchTexelc
= NULL
;
954 img
->FetchTexelf
= NULL
;
959 * Initialize basic fields of the gl_texture_image struct.
961 * \param ctx GL context.
962 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
963 * \param img texture image structure to be initialized.
964 * \param width image width.
965 * \param height image height.
966 * \param depth image depth.
967 * \param border image border.
968 * \param internalFormat internal format.
970 * Fills in the fields of \p img with the given information.
971 * Note: width, height and depth include the border.
974 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
975 struct gl_texture_image
*img
,
976 GLsizei width
, GLsizei height
, GLsizei depth
,
977 GLint border
, GLenum internalFormat
)
986 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
987 ASSERT(img
->_BaseFormat
> 0);
988 img
->InternalFormat
= internalFormat
;
989 img
->Border
= border
;
991 img
->Height
= height
;
994 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
995 img
->WidthLog2
= logbase2(img
->Width2
);
997 if (height
== 1) { /* 1-D texture */
1002 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1003 img
->HeightLog2
= logbase2(img
->Height2
);
1006 if (depth
== 1) { /* 2-D texture */
1011 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1012 img
->DepthLog2
= logbase2(img
->Depth2
);
1015 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1017 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1018 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1019 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1020 img
->_IsPowerOfTwo
= GL_TRUE
;
1022 img
->_IsPowerOfTwo
= GL_FALSE
;
1024 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1025 img
->RowStride
= width
;
1026 /* Allocate the ImageOffsets array and initialize to typical values.
1027 * We allocate the array for 1D/2D textures too in order to avoid special-
1028 * case code in the texstore routines.
1030 if (img
->ImageOffsets
)
1031 free(img
->ImageOffsets
);
1032 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1033 for (i
= 0; i
< depth
; i
++) {
1034 img
->ImageOffsets
[i
] = i
* width
* height
;
1037 /* Compute Width/Height/DepthScale for mipmap lod computation */
1038 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1039 /* scale = 1.0 since texture coords directly map to texels */
1040 img
->WidthScale
= 1.0;
1041 img
->HeightScale
= 1.0;
1042 img
->DepthScale
= 1.0;
1045 img
->WidthScale
= (GLfloat
) img
->Width
;
1046 img
->HeightScale
= (GLfloat
) img
->Height
;
1047 img
->DepthScale
= (GLfloat
) img
->Depth
;
1050 img
->FetchTexelc
= NULL
;
1051 img
->FetchTexelf
= NULL
;
1056 * Free and clear fields of the gl_texture_image struct.
1058 * \param ctx GL context.
1059 * \param texImage texture image structure to be cleared.
1061 * After the call, \p texImage will have no data associated with it. Its
1062 * fields are cleared so that its parent object will test incomplete.
1065 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1067 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1068 clear_teximage_fields(texImage
);
1073 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1074 * level, width, height and depth against the ctx->Const limits for textures.
1076 * A hardware driver might override this function if, for example, the
1077 * max 3D texture size is 512x512x64 (i.e. not a cube).
1079 * Note that width, height, depth == 0 is not an error. However, a
1080 * texture with zero width/height/depth will be considered "incomplete"
1081 * and texturing will effectively be disabled.
1083 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1084 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1085 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1086 * \param level as passed to glTexImage
1087 * \param internalFormat as passed to glTexImage
1088 * \param format as passed to glTexImage
1089 * \param type as passed to glTexImage
1090 * \param width as passed to glTexImage
1091 * \param height as passed to glTexImage
1092 * \param depth as passed to glTexImage
1093 * \param border as passed to glTexImage
1094 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1097 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1098 GLint internalFormat
, GLenum format
, GLenum type
,
1099 GLint width
, GLint height
, GLint depth
, GLint border
)
1103 (void) internalFormat
;
1108 case GL_PROXY_TEXTURE_1D
:
1109 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1110 if (width
< 2 * border
|| width
> 2 + maxSize
||
1111 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1112 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1113 level
>= ctx
->Const
.MaxTextureLevels
) {
1114 /* bad width or level */
1118 case GL_PROXY_TEXTURE_2D
:
1119 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1120 if (width
< 2 * border
|| width
> 2 + maxSize
||
1121 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1122 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1123 height
< 2 * border
|| height
> 2 + maxSize
||
1124 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1125 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1126 level
>= ctx
->Const
.MaxTextureLevels
) {
1127 /* bad width or height or level */
1131 case GL_PROXY_TEXTURE_3D
:
1132 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1133 if (width
< 2 * border
|| width
> 2 + maxSize
||
1134 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1135 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1136 height
< 2 * border
|| height
> 2 + maxSize
||
1137 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1138 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1139 depth
< 2 * border
|| depth
> 2 + maxSize
||
1140 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1141 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1142 level
>= ctx
->Const
.Max3DTextureLevels
) {
1143 /* bad width or height or depth or level */
1147 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1148 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1149 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1151 /* bad width or height or level */
1155 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1156 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1157 if (width
< 2 * border
|| width
> 2 + maxSize
||
1158 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1159 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1160 height
< 2 * border
|| height
> 2 + maxSize
||
1161 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1162 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1163 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1164 /* bad width or height */
1168 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1169 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1170 if (width
< 2 * border
|| width
> 2 + maxSize
||
1171 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1172 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1173 level
>= ctx
->Const
.MaxTextureLevels
) {
1174 /* bad width or level */
1178 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1182 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1183 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1184 if (width
< 2 * border
|| width
> 2 + maxSize
||
1185 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1186 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1187 height
< 2 * border
|| height
> 2 + maxSize
||
1188 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1189 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1190 level
>= ctx
->Const
.MaxTextureLevels
) {
1191 /* bad width or height or level */
1194 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1199 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1206 * Helper function to determine whether a target supports compressed textures
1209 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1211 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1212 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1213 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1214 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1215 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1216 || ((ctx
->Extensions
.MESA_texture_array
&&
1217 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1218 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1223 * Test the glTexImage[123]D() parameters for errors.
1225 * \param ctx GL context.
1226 * \param target texture target given by the user.
1227 * \param level image level given by the user.
1228 * \param internalFormat internal format given by the user.
1229 * \param format pixel data format given by the user.
1230 * \param type pixel data type given by the user.
1231 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1232 * \param width image width given by the user.
1233 * \param height image height given by the user.
1234 * \param depth image depth given by the user.
1235 * \param border image border given by the user.
1237 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1239 * Verifies each of the parameters against the constants specified in
1240 * __GLcontextRec::Const and the supported extensions, and according to the
1241 * OpenGL specification.
1244 texture_error_check( GLcontext
*ctx
, GLenum target
,
1245 GLint level
, GLint internalFormat
,
1246 GLenum format
, GLenum type
,
1248 GLint width
, GLint height
,
1249 GLint depth
, GLint border
)
1251 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1252 GLboolean sizeOK
= GL_TRUE
;
1253 GLboolean colorFormat
, indexFormat
;
1254 GLenum proxy_target
;
1256 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1257 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1259 _mesa_error(ctx
, GL_INVALID_VALUE
,
1260 "glTexImage%dD(level=%d)", dimensions
, level
);
1266 if (border
< 0 || border
> 1 ||
1267 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1268 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1270 _mesa_error(ctx
, GL_INVALID_VALUE
,
1271 "glTexImage%dD(border=%d)", dimensions
, border
);
1276 if (width
< 0 || height
< 0 || depth
< 0) {
1278 _mesa_error(ctx
, GL_INVALID_VALUE
,
1279 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1284 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1285 * level, width, height and depth.
1287 if (dimensions
== 1) {
1288 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1289 proxy_target
= GL_PROXY_TEXTURE_1D
;
1294 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1298 else if (dimensions
== 2) {
1300 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1301 proxy_target
= GL_PROXY_TEXTURE_2D
;
1303 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1304 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1305 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1306 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1310 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1311 sizeOK
= (width
== height
);
1313 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1314 target
== GL_TEXTURE_RECTANGLE_NV
) {
1315 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1319 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1321 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1322 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1323 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1326 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1330 else if (dimensions
== 3) {
1331 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1332 proxy_target
= GL_PROXY_TEXTURE_3D
;
1334 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1335 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1336 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1339 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1344 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1348 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1349 internalFormat
, format
,
1350 type
, width
, height
,
1354 _mesa_error(ctx
, GL_INVALID_VALUE
,
1355 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1356 dimensions
, level
, width
, height
, depth
);
1361 /* Check internalFormat */
1362 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1364 _mesa_error(ctx
, GL_INVALID_VALUE
,
1365 "glTexImage%dD(internalFormat=%s)",
1366 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1371 /* Check incoming image format and type */
1372 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1373 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1374 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1377 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1378 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1379 dimensions
, format
, type
);
1384 /* make sure internal format and format basically agree */
1385 colorFormat
= _mesa_is_color_format(format
);
1386 indexFormat
= _mesa_is_index_format(format
);
1387 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1388 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1389 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1390 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1391 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1392 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1395 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1396 dimensions
, internalFormat
, format
);
1400 /* additional checks for ycbcr textures */
1401 if (internalFormat
== GL_YCBCR_MESA
) {
1402 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1403 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1404 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1406 _mesa_snprintf(message
, sizeof(message
),
1407 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1408 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1409 return GL_TRUE
; /* error */
1411 if (target
!= GL_TEXTURE_2D
&&
1412 target
!= GL_PROXY_TEXTURE_2D
&&
1413 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1414 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1422 _mesa_snprintf(message
, sizeof(message
),
1423 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1424 dimensions
, border
);
1425 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1431 /* additional checks for depth textures */
1432 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1433 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1434 if (target
!= GL_TEXTURE_1D
&&
1435 target
!= GL_PROXY_TEXTURE_1D
&&
1436 target
!= GL_TEXTURE_2D
&&
1437 target
!= GL_PROXY_TEXTURE_2D
&&
1438 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1439 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1441 _mesa_error(ctx
, GL_INVALID_ENUM
,
1442 "glTexImage(target/internalFormat)");
1447 /* additional checks for compressed textures */
1448 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1449 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1450 _mesa_error(ctx
, GL_INVALID_ENUM
,
1451 "glTexImage%dD(target)", dimensions
);
1456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1457 "glTexImage%dD(border!=0)", dimensions
);
1463 /* if we get here, the parameters are OK */
1469 * Test glTexSubImage[123]D() parameters for errors.
1471 * \param ctx GL context.
1472 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1473 * \param target texture target given by the user.
1474 * \param level image level given by the user.
1475 * \param xoffset sub-image x offset given by the user.
1476 * \param yoffset sub-image y offset given by the user.
1477 * \param zoffset sub-image z offset given by the user.
1478 * \param format pixel data format given by the user.
1479 * \param type pixel data type given by the user.
1480 * \param width image width given by the user.
1481 * \param height image height given by the user.
1482 * \param depth image depth given by the user.
1484 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1486 * Verifies each of the parameters against the constants specified in
1487 * __GLcontextRec::Const and the supported extensions, and according to the
1488 * OpenGL specification.
1491 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1492 GLenum target
, GLint level
,
1493 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1494 GLint width
, GLint height
, GLint depth
,
1495 GLenum format
, GLenum type
)
1498 if (dimensions
== 1) {
1499 if (target
!= GL_TEXTURE_1D
) {
1500 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1504 else if (dimensions
== 2) {
1505 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1506 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1507 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1508 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1512 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1513 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1514 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1518 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1519 if (!ctx
->Extensions
.MESA_texture_array
) {
1520 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1524 else if (target
!= GL_TEXTURE_2D
) {
1525 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1529 else if (dimensions
== 3) {
1530 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1531 if (!ctx
->Extensions
.MESA_texture_array
) {
1532 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1536 else if (target
!= GL_TEXTURE_3D
) {
1537 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1542 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1546 /* Basic level check */
1547 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1548 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1553 _mesa_error(ctx
, GL_INVALID_VALUE
,
1554 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1557 if (height
< 0 && dimensions
> 1) {
1558 _mesa_error(ctx
, GL_INVALID_VALUE
,
1559 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1562 if (depth
< 0 && dimensions
> 2) {
1563 _mesa_error(ctx
, GL_INVALID_VALUE
,
1564 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1568 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1569 _mesa_error(ctx
, GL_INVALID_ENUM
,
1570 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1571 dimensions
, format
, type
);
1580 * Do second part of glTexSubImage which depends on the destination texture.
1581 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1584 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1585 GLenum target
, GLint level
,
1586 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1587 GLint width
, GLint height
, GLint depth
,
1588 GLenum format
, GLenum type
,
1589 const struct gl_texture_image
*destTex
)
1592 /* undefined image level */
1593 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1597 if (xoffset
< -((GLint
)destTex
->Border
)) {
1598 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1602 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1603 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1607 if (dimensions
> 1) {
1608 if (yoffset
< -((GLint
)destTex
->Border
)) {
1609 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1613 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1614 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1619 if (dimensions
> 2) {
1620 if (zoffset
< -((GLint
)destTex
->Border
)) {
1621 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1624 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1625 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1630 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1633 if (!target_can_be_compressed(ctx
, target
)) {
1634 _mesa_error(ctx
, GL_INVALID_ENUM
,
1635 "glTexSubImage%dD(target=%s)", dimensions
,
1636 _mesa_lookup_enum_by_nr(target
));
1640 /* do tests which depend on compression block size */
1641 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1643 /* offset must be multiple of block size */
1644 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1646 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1647 dimensions
, xoffset
, yoffset
);
1650 /* size must be multiple of bw by bh or equal to whole texture size */
1651 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1653 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1656 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1657 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1658 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1668 * Test glCopyTexImage[12]D() parameters for errors.
1670 * \param ctx GL context.
1671 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1672 * \param target texture target given by the user.
1673 * \param level image level given by the user.
1674 * \param internalFormat internal format given by the user.
1675 * \param width image width given by the user.
1676 * \param height image height given by the user.
1677 * \param border texture border.
1679 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1681 * Verifies each of the parameters against the constants specified in
1682 * __GLcontextRec::Const and the supported extensions, and according to the
1683 * OpenGL specification.
1686 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1687 GLenum target
, GLint level
, GLint internalFormat
,
1688 GLint width
, GLint height
, GLint border
)
1694 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1695 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1696 _mesa_error(ctx
, GL_INVALID_VALUE
,
1697 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1701 /* Check that the source buffer is complete */
1702 if (ctx
->ReadBuffer
->Name
) {
1703 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1704 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1705 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1706 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1712 if (border
< 0 || border
> 1 ||
1713 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1714 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1718 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1720 _mesa_error(ctx
, GL_INVALID_VALUE
,
1721 "glCopyTexImage%dD(internalFormat)", dimensions
);
1725 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1727 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1731 /* NOTE: the format and type aren't really significant for
1732 * TestProxyTexImage(). Only the internalformat really matters.
1736 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1737 * level, width, height and depth.
1739 if (dimensions
== 1) {
1740 if (target
== GL_TEXTURE_1D
) {
1741 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1742 level
, internalFormat
,
1744 width
, 1, 1, border
);
1747 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1751 else if (dimensions
== 2) {
1752 if (target
== GL_TEXTURE_2D
) {
1753 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1754 level
, internalFormat
,
1756 width
, height
, 1, border
);
1758 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1759 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1760 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1761 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1764 sizeOK
= (width
== height
) &&
1765 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1766 level
, internalFormat
, format
, type
,
1767 width
, height
, 1, border
);
1769 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1770 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1771 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1774 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1775 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1776 level
, internalFormat
,
1778 width
, height
, 1, border
);
1780 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1781 if (!ctx
->Extensions
.MESA_texture_array
) {
1782 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1785 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1786 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1787 level
, internalFormat
,
1789 width
, height
, 1, border
);
1792 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1797 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1802 if (dimensions
== 1) {
1803 _mesa_error(ctx
, GL_INVALID_VALUE
,
1804 "glCopyTexImage1D(width=%d)", width
);
1807 ASSERT(dimensions
== 2);
1808 _mesa_error(ctx
, GL_INVALID_VALUE
,
1809 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1814 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1815 if (!target_can_be_compressed(ctx
, target
)) {
1816 _mesa_error(ctx
, GL_INVALID_ENUM
,
1817 "glCopyTexImage%dD(target)", dimensions
);
1821 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1822 "glCopyTexImage%dD(border!=0)", dimensions
);
1826 else if (_mesa_is_depth_format(internalFormat
)) {
1827 /* make sure we have depth/stencil buffers */
1828 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1830 "glCopyTexImage%dD(no depth)", dimensions
);
1834 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1835 /* make sure we have depth/stencil buffers */
1836 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1837 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1838 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1843 /* if we get here, the parameters are OK */
1849 * Test glCopyTexSubImage[12]D() parameters for errors.
1850 * Note that this is the first part of error checking.
1851 * See also copytexsubimage_error_check2() below for the second part.
1853 * \param ctx GL context.
1854 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1855 * \param target texture target given by the user.
1856 * \param level image level given by the user.
1858 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1861 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1862 GLenum target
, GLint level
)
1864 /* Check that the source buffer is complete */
1865 if (ctx
->ReadBuffer
->Name
) {
1866 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1867 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1868 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1869 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1875 if (dimensions
== 1) {
1876 if (target
!= GL_TEXTURE_1D
) {
1877 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1881 else if (dimensions
== 2) {
1882 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1883 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1884 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1885 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1889 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1890 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1891 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1895 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1896 if (!ctx
->Extensions
.MESA_texture_array
) {
1897 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1901 else if (target
!= GL_TEXTURE_2D
) {
1902 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1906 else if (dimensions
== 3) {
1907 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1908 (!ctx
->Extensions
.MESA_texture_array
))
1909 && (target
!= GL_TEXTURE_3D
)) {
1910 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1916 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1917 _mesa_error(ctx
, GL_INVALID_VALUE
,
1918 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1927 * Second part of error checking for glCopyTexSubImage[12]D().
1928 * \param xoffset sub-image x offset given by the user.
1929 * \param yoffset sub-image y offset given by the user.
1930 * \param zoffset sub-image z offset given by the user.
1931 * \param width image width given by the user.
1932 * \param height image height given by the user.
1935 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1936 GLenum target
, GLint level
,
1937 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1938 GLsizei width
, GLsizei height
,
1939 const struct gl_texture_image
*teximage
)
1941 /* check that dest tex image exists */
1943 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1944 "glCopyTexSubImage%dD(undefined texture level: %d)",
1951 _mesa_error(ctx
, GL_INVALID_VALUE
,
1952 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1955 if (dimensions
> 1 && height
< 0) {
1956 _mesa_error(ctx
, GL_INVALID_VALUE
,
1957 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1961 /* check x/y offsets */
1962 if (xoffset
< -((GLint
)teximage
->Border
)) {
1963 _mesa_error(ctx
, GL_INVALID_VALUE
,
1964 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1967 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1968 _mesa_error(ctx
, GL_INVALID_VALUE
,
1969 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1972 if (dimensions
> 1) {
1973 if (yoffset
< -((GLint
)teximage
->Border
)) {
1974 _mesa_error(ctx
, GL_INVALID_VALUE
,
1975 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1978 /* NOTE: we're adding the border here, not subtracting! */
1979 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1980 _mesa_error(ctx
, GL_INVALID_VALUE
,
1981 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1986 /* check z offset */
1987 if (dimensions
> 2) {
1988 if (zoffset
< -((GLint
)teximage
->Border
)) {
1989 _mesa_error(ctx
, GL_INVALID_VALUE
,
1990 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1993 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1994 _mesa_error(ctx
, GL_INVALID_VALUE
,
1995 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2000 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2001 if (!target_can_be_compressed(ctx
, target
)) {
2002 _mesa_error(ctx
, GL_INVALID_ENUM
,
2003 "glCopyTexSubImage%dD(target)", dimensions
);
2006 /* offset must be multiple of 4 */
2007 if ((xoffset
& 3) || (yoffset
& 3)) {
2008 _mesa_error(ctx
, GL_INVALID_VALUE
,
2009 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2012 /* size must be multiple of 4 */
2013 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2014 _mesa_error(ctx
, GL_INVALID_VALUE
,
2015 "glCopyTexSubImage%dD(width)", dimensions
);
2018 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2019 _mesa_error(ctx
, GL_INVALID_VALUE
,
2020 "glCopyTexSubImage%dD(height)", dimensions
);
2025 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2026 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2030 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2031 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2032 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2033 dimensions
, teximage
->_BaseFormat
);
2037 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2038 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2039 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2040 "glCopyTexSubImage%dD(no depth buffer)",
2045 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2046 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2047 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2048 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2054 /* if we get here, the parameters are OK */
2059 /** Callback info for walking over FBO hash table */
2063 struct gl_texture_object
*texObj
;
2069 * Check render to texture callback. Called from _mesa_HashWalk().
2072 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2074 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2075 const struct cb_info
*info
= (struct cb_info
*) userData
;
2076 GLcontext
*ctx
= info
->ctx
;
2077 const struct gl_texture_object
*texObj
= info
->texObj
;
2078 const GLuint level
= info
->level
, face
= info
->face
;
2080 /* If this is a user-created FBO */
2083 /* check if any of the FBO's attachments point to 'texObj' */
2084 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2085 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2086 if (att
->Type
== GL_TEXTURE
&&
2087 att
->Texture
== texObj
&&
2088 att
->TextureLevel
== level
&&
2089 att
->CubeMapFace
== face
) {
2090 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2091 /* Tell driver about the new renderbuffer texture */
2092 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2093 /* Mark fb status as indeterminate to force re-validation */
2102 * When a texture image is specified we have to check if it's bound to
2103 * any framebuffer objects (render to texture) in order to detect changes
2104 * in size or format since that effects FBO completeness.
2105 * Any FBOs rendering into the texture must be re-validated.
2108 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2109 GLuint face
, GLuint level
)
2111 /* Only check this texture if it's been marked as RenderToTexture */
2112 if (texObj
->_RenderToTexture
) {
2113 struct cb_info info
;
2115 info
.texObj
= texObj
;
2118 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2124 * If the texture object's GenerateMipmap flag is set and we've
2125 * changed the texture base level image, regenerate the rest of the
2126 * mipmap levels now.
2129 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2130 struct gl_texture_object
*texObj
, GLint level
)
2132 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2133 if (texObj
->GenerateMipmap
&&
2134 level
== texObj
->BaseLevel
&&
2135 level
< texObj
->MaxLevel
) {
2136 ASSERT(ctx
->Driver
.GenerateMipmap
);
2137 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2142 /** Debug helper: override the user-requested internal format */
2144 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2147 if (internalFormat
== GL_RGBA16F_ARB
||
2148 internalFormat
== GL_RGBA32F_ARB
) {
2149 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2152 else if (internalFormat
== GL_RGB16F_ARB
||
2153 internalFormat
== GL_RGB32F_ARB
) {
2154 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2157 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2158 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2159 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2160 return GL_LUMINANCE_ALPHA
;
2162 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2163 internalFormat
== GL_LUMINANCE32F_ARB
) {
2164 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2165 return GL_LUMINANCE
;
2167 else if (internalFormat
== GL_ALPHA16F_ARB
||
2168 internalFormat
== GL_ALPHA32F_ARB
) {
2169 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2173 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2174 internalFormat = GL_RGBA;
2178 return internalFormat
;
2181 return internalFormat
;
2187 * Called from the API. Note that width includes the border.
2190 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2191 GLsizei width
, GLint border
, GLenum format
,
2192 GLenum type
, const GLvoid
*pixels
)
2194 GLsizei postConvWidth
= width
;
2195 GET_CURRENT_CONTEXT(ctx
);
2196 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2198 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2199 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2200 _mesa_lookup_enum_by_nr(target
), level
,
2201 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2202 _mesa_lookup_enum_by_nr(format
),
2203 _mesa_lookup_enum_by_nr(type
), pixels
);
2205 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2207 #if FEATURE_convolve
2208 if (_mesa_is_color_format(internalFormat
)) {
2209 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2213 if (target
== GL_TEXTURE_1D
) {
2214 /* non-proxy target */
2215 struct gl_texture_object
*texObj
;
2216 struct gl_texture_image
*texImage
;
2217 const GLuint face
= _mesa_tex_target_to_face(target
);
2219 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2220 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2221 return; /* error was recorded */
2224 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2225 _mesa_update_state(ctx
);
2227 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2228 _mesa_lock_texture(ctx
, texObj
);
2230 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2232 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2235 if (texImage
->Data
) {
2236 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2239 ASSERT(texImage
->Data
== NULL
);
2241 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2242 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2243 postConvWidth
, 1, 1,
2244 border
, internalFormat
);
2246 /* Choose actual texture format */
2247 texImage
->TexFormat
=
2248 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2250 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2252 /* Give the texture to the driver. <pixels> may be null. */
2253 ASSERT(ctx
->Driver
.TexImage1D
);
2254 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2255 width
, border
, format
, type
, pixels
,
2256 &ctx
->Unpack
, texObj
, texImage
);
2258 ASSERT(texImage
->TexFormat
);
2260 _mesa_set_fetch_functions(texImage
, 1);
2262 check_gen_mipmap(ctx
, target
, texObj
, level
);
2264 update_fbo_texture(ctx
, texObj
, face
, level
);
2267 texObj
->_Complete
= GL_FALSE
;
2268 ctx
->NewState
|= _NEW_TEXTURE
;
2271 _mesa_unlock_texture(ctx
, texObj
);
2273 else if (target
== GL_PROXY_TEXTURE_1D
) {
2274 /* Proxy texture: check for errors and update proxy state */
2275 struct gl_texture_image
*texImage
;
2276 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2277 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2278 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2279 /* when error, clear all proxy texture image parameters */
2281 clear_teximage_fields(texImage
);
2284 /* no error, set the tex image parameters */
2286 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2287 postConvWidth
, 1, 1,
2288 border
, internalFormat
);
2289 texImage
->TexFormat
=
2290 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2294 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2301 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2302 GLsizei width
, GLsizei height
, GLint border
,
2303 GLenum format
, GLenum type
,
2304 const GLvoid
*pixels
)
2306 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2307 GET_CURRENT_CONTEXT(ctx
);
2308 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2310 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2311 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2312 _mesa_lookup_enum_by_nr(target
), level
,
2313 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2314 border
, _mesa_lookup_enum_by_nr(format
),
2315 _mesa_lookup_enum_by_nr(type
), pixels
);
2317 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2319 #if FEATURE_convolve
2320 if (_mesa_is_color_format(internalFormat
)) {
2321 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2326 if (target
== GL_TEXTURE_2D
||
2327 (ctx
->Extensions
.ARB_texture_cube_map
&&
2328 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2329 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2330 (ctx
->Extensions
.NV_texture_rectangle
&&
2331 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2332 (ctx
->Extensions
.MESA_texture_array
&&
2333 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2334 /* non-proxy target */
2335 struct gl_texture_object
*texObj
;
2336 struct gl_texture_image
*texImage
;
2337 const GLuint face
= _mesa_tex_target_to_face(target
);
2339 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2340 format
, type
, 2, postConvWidth
, postConvHeight
,
2342 return; /* error was recorded */
2345 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2346 _mesa_update_state(ctx
);
2348 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2349 _mesa_lock_texture(ctx
, texObj
);
2351 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2353 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2356 if (texImage
->Data
) {
2357 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2360 ASSERT(texImage
->Data
== NULL
);
2361 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2362 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2363 postConvWidth
, postConvHeight
, 1,
2364 border
, internalFormat
);
2366 /* Choose actual texture format */
2367 texImage
->TexFormat
=
2368 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2370 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2372 /* Give the texture to the driver. <pixels> may be null. */
2373 ASSERT(ctx
->Driver
.TexImage2D
);
2374 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2375 width
, height
, border
, format
, type
,
2376 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2378 ASSERT(texImage
->TexFormat
);
2380 _mesa_set_fetch_functions(texImage
, 2);
2382 check_gen_mipmap(ctx
, target
, texObj
, level
);
2384 update_fbo_texture(ctx
, texObj
, face
, level
);
2387 texObj
->_Complete
= GL_FALSE
;
2388 ctx
->NewState
|= _NEW_TEXTURE
;
2391 _mesa_unlock_texture(ctx
, texObj
);
2393 else if (target
== GL_PROXY_TEXTURE_2D
||
2394 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2395 ctx
->Extensions
.ARB_texture_cube_map
) ||
2396 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2397 ctx
->Extensions
.NV_texture_rectangle
) ||
2398 (ctx
->Extensions
.MESA_texture_array
&&
2399 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2400 /* Proxy texture: check for errors and update proxy state */
2401 struct gl_texture_image
*texImage
;
2402 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2403 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2404 format
, type
, 2, postConvWidth
, postConvHeight
,
2406 /* when error, clear all proxy texture image parameters */
2408 clear_teximage_fields(texImage
);
2411 /* no error, set the tex image parameters */
2412 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2413 postConvWidth
, postConvHeight
, 1,
2414 border
, internalFormat
);
2415 texImage
->TexFormat
=
2416 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2420 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2427 * Called by the API or display list executor.
2428 * Note that width and height include the border.
2431 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2432 GLsizei width
, GLsizei height
, GLsizei depth
,
2433 GLint border
, GLenum format
, GLenum type
,
2434 const GLvoid
*pixels
)
2436 GET_CURRENT_CONTEXT(ctx
);
2437 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2439 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2440 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2441 _mesa_lookup_enum_by_nr(target
), level
,
2442 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2443 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2444 _mesa_lookup_enum_by_nr(type
), pixels
);
2446 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2448 if (target
== GL_TEXTURE_3D
||
2449 (ctx
->Extensions
.MESA_texture_array
&&
2450 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2451 /* non-proxy target */
2452 struct gl_texture_object
*texObj
;
2453 struct gl_texture_image
*texImage
;
2454 const GLuint face
= _mesa_tex_target_to_face(target
);
2456 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2457 format
, type
, 3, width
, height
, depth
, border
)) {
2458 return; /* error was recorded */
2461 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2462 _mesa_update_state(ctx
);
2464 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2465 _mesa_lock_texture(ctx
, texObj
);
2467 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2469 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2472 if (texImage
->Data
) {
2473 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2476 ASSERT(texImage
->Data
== NULL
);
2477 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2478 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2479 width
, height
, depth
,
2480 border
, internalFormat
);
2482 /* Choose actual texture format */
2483 texImage
->TexFormat
=
2484 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2486 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2488 /* Give the texture to the driver. <pixels> may be null. */
2489 ASSERT(ctx
->Driver
.TexImage3D
);
2490 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2491 width
, height
, depth
, border
, format
, type
,
2492 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2494 ASSERT(texImage
->TexFormat
);
2496 _mesa_set_fetch_functions(texImage
, 3);
2498 check_gen_mipmap(ctx
, target
, texObj
, level
);
2500 update_fbo_texture(ctx
, texObj
, face
, level
);
2503 texObj
->_Complete
= GL_FALSE
;
2504 ctx
->NewState
|= _NEW_TEXTURE
;
2507 _mesa_unlock_texture(ctx
, texObj
);
2509 else if (target
== GL_PROXY_TEXTURE_3D
||
2510 (ctx
->Extensions
.MESA_texture_array
&&
2511 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2512 /* Proxy texture: check for errors and update proxy state */
2513 struct gl_texture_image
*texImage
;
2514 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2515 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2516 format
, type
, 3, width
, height
, depth
, border
)) {
2517 /* when error, clear all proxy texture image parameters */
2519 clear_teximage_fields(texImage
);
2522 /* no error, set the tex image parameters */
2523 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2524 depth
, border
, internalFormat
);
2525 texImage
->TexFormat
=
2526 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2530 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2537 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2538 GLsizei width
, GLsizei height
, GLsizei depth
,
2539 GLint border
, GLenum format
, GLenum type
,
2540 const GLvoid
*pixels
)
2542 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2543 depth
, border
, format
, type
, pixels
);
2547 #if FEATURE_OES_EGL_image
2549 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2551 struct gl_texture_object
*texObj
;
2552 struct gl_texture_image
*texImage
;
2553 GET_CURRENT_CONTEXT(ctx
);
2554 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2556 if (!ctx
->Extensions
.OES_EGL_image
) {
2557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2558 "glEGLImageTargetTexture2DOES(unsupported)");
2562 if (target
!= GL_TEXTURE_2D
) {
2563 _mesa_error(ctx
, GL_INVALID_ENUM
,
2564 "glEGLImageTargetTexture2D(target=%d)", target
);
2568 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2569 _mesa_update_state(ctx
);
2571 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2572 _mesa_lock_texture(ctx
, texObj
);
2574 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2576 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2579 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2581 ASSERT(texImage
->Data
== NULL
);
2582 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2583 texObj
, texImage
, image
);
2586 texObj
->_Complete
= GL_FALSE
;
2587 ctx
->NewState
|= _NEW_TEXTURE
;
2589 _mesa_unlock_texture(ctx
, texObj
);
2596 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2597 GLint xoffset
, GLsizei width
,
2598 GLenum format
, GLenum type
,
2599 const GLvoid
*pixels
)
2601 GLsizei postConvWidth
= width
;
2602 struct gl_texture_object
*texObj
;
2603 struct gl_texture_image
*texImage
;
2604 GET_CURRENT_CONTEXT(ctx
);
2605 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2607 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2608 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2609 _mesa_lookup_enum_by_nr(target
), level
,
2610 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2611 _mesa_lookup_enum_by_nr(type
), pixels
);
2613 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2614 _mesa_update_state(ctx
);
2616 #if FEATURE_convolve
2617 /* XXX should test internal format */
2618 if (_mesa_is_color_format(format
)) {
2619 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2623 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2624 postConvWidth
, 1, 1, format
, type
)) {
2625 return; /* error was detected */
2629 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2632 _mesa_lock_texture(ctx
, texObj
);
2634 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2636 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2637 postConvWidth
, 1, 1,
2638 format
, type
, texImage
)) {
2639 /* error was recorded */
2641 else if (width
> 0) {
2642 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2643 xoffset
+= texImage
->Border
;
2645 ASSERT(ctx
->Driver
.TexSubImage1D
);
2646 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2647 format
, type
, pixels
, &ctx
->Unpack
,
2650 check_gen_mipmap(ctx
, target
, texObj
, level
);
2652 ctx
->NewState
|= _NEW_TEXTURE
;
2655 _mesa_unlock_texture(ctx
, texObj
);
2660 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2661 GLint xoffset
, GLint yoffset
,
2662 GLsizei width
, GLsizei height
,
2663 GLenum format
, GLenum type
,
2664 const GLvoid
*pixels
)
2666 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2667 struct gl_texture_object
*texObj
;
2668 struct gl_texture_image
*texImage
;
2669 GET_CURRENT_CONTEXT(ctx
);
2670 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2672 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2673 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2674 _mesa_lookup_enum_by_nr(target
), level
,
2675 xoffset
, yoffset
, width
, height
,
2676 _mesa_lookup_enum_by_nr(format
),
2677 _mesa_lookup_enum_by_nr(type
), pixels
);
2679 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2680 _mesa_update_state(ctx
);
2682 #if FEATURE_convolve
2683 /* XXX should test internal format */
2684 if (_mesa_is_color_format(format
)) {
2685 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2690 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2691 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2692 return; /* error was detected */
2695 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2697 _mesa_lock_texture(ctx
, texObj
);
2699 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2701 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2702 postConvWidth
, postConvHeight
, 1,
2703 format
, type
, texImage
)) {
2704 /* error was recorded */
2706 else if (width
> 0 && height
>= 0) {
2707 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2708 xoffset
+= texImage
->Border
;
2709 yoffset
+= texImage
->Border
;
2711 ASSERT(ctx
->Driver
.TexSubImage2D
);
2712 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2713 width
, height
, format
, type
, pixels
,
2714 &ctx
->Unpack
, texObj
, texImage
);
2716 check_gen_mipmap(ctx
, target
, texObj
, level
);
2718 ctx
->NewState
|= _NEW_TEXTURE
;
2721 _mesa_unlock_texture(ctx
, texObj
);
2727 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2728 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2729 GLsizei width
, GLsizei height
, GLsizei depth
,
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
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2740 _mesa_lookup_enum_by_nr(target
), level
,
2741 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2742 _mesa_lookup_enum_by_nr(format
),
2743 _mesa_lookup_enum_by_nr(type
), pixels
);
2745 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2746 _mesa_update_state(ctx
);
2748 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2749 width
, height
, depth
, format
, type
)) {
2750 return; /* error was detected */
2753 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2755 _mesa_lock_texture(ctx
, texObj
);
2757 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2759 if (subtexture_error_check2(ctx
, 3, target
, level
,
2760 xoffset
, yoffset
, zoffset
,
2761 width
, height
, depth
,
2762 format
, type
, texImage
)) {
2763 /* error was recorded */
2765 else if (width
> 0 && height
> 0 && height
> 0) {
2766 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2767 xoffset
+= texImage
->Border
;
2768 yoffset
+= texImage
->Border
;
2769 zoffset
+= texImage
->Border
;
2771 ASSERT(ctx
->Driver
.TexSubImage3D
);
2772 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2773 xoffset
, yoffset
, zoffset
,
2774 width
, height
, depth
,
2775 format
, type
, pixels
,
2776 &ctx
->Unpack
, texObj
, texImage
);
2778 check_gen_mipmap(ctx
, target
, texObj
, level
);
2780 ctx
->NewState
|= _NEW_TEXTURE
;
2783 _mesa_unlock_texture(ctx
, texObj
);
2789 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2790 GLenum internalFormat
,
2792 GLsizei width
, GLint border
)
2794 struct gl_texture_object
*texObj
;
2795 struct gl_texture_image
*texImage
;
2796 GLsizei postConvWidth
= width
;
2797 const GLuint face
= _mesa_tex_target_to_face(target
);
2798 GET_CURRENT_CONTEXT(ctx
);
2799 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2801 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2802 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2803 _mesa_lookup_enum_by_nr(target
), level
,
2804 _mesa_lookup_enum_by_nr(internalFormat
),
2805 x
, y
, width
, border
);
2807 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2808 _mesa_update_state(ctx
);
2810 #if FEATURE_convolve
2811 if (_mesa_is_color_format(internalFormat
)) {
2812 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2816 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2817 postConvWidth
, 1, border
))
2820 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2822 _mesa_lock_texture(ctx
, texObj
);
2824 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2826 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2829 if (texImage
->Data
) {
2830 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2833 ASSERT(texImage
->Data
== NULL
);
2835 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2836 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2837 border
, internalFormat
);
2839 /* Choose actual texture format */
2840 texImage
->TexFormat
=
2841 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2843 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2845 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2846 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2847 x
, y
, width
, border
);
2849 ASSERT(texImage
->TexFormat
);
2851 _mesa_set_fetch_functions(texImage
, 1);
2853 check_gen_mipmap(ctx
, target
, texObj
, level
);
2855 update_fbo_texture(ctx
, texObj
, face
, level
);
2858 texObj
->_Complete
= GL_FALSE
;
2859 ctx
->NewState
|= _NEW_TEXTURE
;
2862 _mesa_unlock_texture(ctx
, texObj
);
2868 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2869 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2872 struct gl_texture_object
*texObj
;
2873 struct gl_texture_image
*texImage
;
2874 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2875 const GLuint face
= _mesa_tex_target_to_face(target
);
2876 GET_CURRENT_CONTEXT(ctx
);
2877 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2879 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2880 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2881 _mesa_lookup_enum_by_nr(target
), level
,
2882 _mesa_lookup_enum_by_nr(internalFormat
),
2883 x
, y
, width
, height
, border
);
2885 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2886 _mesa_update_state(ctx
);
2888 #if FEATURE_convolve
2889 if (_mesa_is_color_format(internalFormat
)) {
2890 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2895 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2896 postConvWidth
, postConvHeight
, border
))
2899 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2901 _mesa_lock_texture(ctx
, texObj
);
2903 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2906 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2909 if (texImage
->Data
) {
2910 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2913 ASSERT(texImage
->Data
== NULL
);
2915 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2916 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2917 postConvWidth
, postConvHeight
, 1,
2918 border
, internalFormat
);
2920 /* Choose actual texture format */
2921 texImage
->TexFormat
=
2922 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2924 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2926 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2927 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2928 x
, y
, width
, height
, border
);
2930 ASSERT(texImage
->TexFormat
);
2932 _mesa_set_fetch_functions(texImage
, 2);
2934 check_gen_mipmap(ctx
, target
, texObj
, level
);
2936 update_fbo_texture(ctx
, texObj
, face
, level
);
2939 texObj
->_Complete
= GL_FALSE
;
2940 ctx
->NewState
|= _NEW_TEXTURE
;
2943 _mesa_unlock_texture(ctx
, texObj
);
2948 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2949 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2951 struct gl_texture_object
*texObj
;
2952 struct gl_texture_image
*texImage
;
2953 GLsizei postConvWidth
= width
;
2957 GET_CURRENT_CONTEXT(ctx
);
2958 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2960 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2961 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2962 _mesa_lookup_enum_by_nr(target
),
2963 level
, xoffset
, x
, y
, width
);
2965 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2966 _mesa_update_state(ctx
);
2968 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2971 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2973 _mesa_lock_texture(ctx
, texObj
);
2975 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2977 #if FEATURE_convolve
2978 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2979 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2983 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2984 xoffset
, 0, 0, postConvWidth
, 1,
2986 /* error was recorded */
2989 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2990 xoffset
+= texImage
->Border
;
2992 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2994 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2995 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2996 xoffset
, x
, y
, width
);
2998 check_gen_mipmap(ctx
, target
, texObj
, level
);
3000 ctx
->NewState
|= _NEW_TEXTURE
;
3004 _mesa_unlock_texture(ctx
, texObj
);
3010 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3011 GLint xoffset
, GLint yoffset
,
3012 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3014 struct gl_texture_object
*texObj
;
3015 struct gl_texture_image
*texImage
;
3016 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3017 GET_CURRENT_CONTEXT(ctx
);
3018 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3020 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3021 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
3022 _mesa_lookup_enum_by_nr(target
),
3023 level
, xoffset
, yoffset
, x
, y
, width
, height
);
3025 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3026 _mesa_update_state(ctx
);
3028 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3031 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3033 _mesa_lock_texture(ctx
, texObj
);
3035 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3037 #if FEATURE_convolve
3038 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3039 _mesa_adjust_image_for_convolution(ctx
, 2,
3040 &postConvWidth
, &postConvHeight
);
3044 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
3045 xoffset
, yoffset
, 0,
3046 postConvWidth
, postConvHeight
,
3048 /* error was recorded */
3051 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3052 xoffset
+= texImage
->Border
;
3053 yoffset
+= texImage
->Border
;
3055 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3057 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3058 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
3059 x
, y
, width
, height
);
3061 check_gen_mipmap(ctx
, target
, texObj
, level
);
3063 ctx
->NewState
|= _NEW_TEXTURE
;
3067 _mesa_unlock_texture(ctx
, texObj
);
3073 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3074 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3075 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3077 struct gl_texture_object
*texObj
;
3078 struct gl_texture_image
*texImage
;
3079 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3080 GET_CURRENT_CONTEXT(ctx
);
3081 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3083 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3084 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
3085 _mesa_lookup_enum_by_nr(target
),
3086 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3088 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3089 _mesa_update_state(ctx
);
3091 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3094 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3096 _mesa_lock_texture(ctx
, texObj
);
3098 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3100 #if FEATURE_convolve
3101 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3102 _mesa_adjust_image_for_convolution(ctx
, 2,
3103 &postConvWidth
, &postConvHeight
);
3107 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3108 zoffset
, postConvWidth
, postConvHeight
,
3110 /* error was recored */
3113 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3114 xoffset
+= texImage
->Border
;
3115 yoffset
+= texImage
->Border
;
3116 zoffset
+= texImage
->Border
;
3118 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3120 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3121 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3122 xoffset
, yoffset
, zoffset
,
3123 x
, y
, width
, height
);
3125 check_gen_mipmap(ctx
, target
, texObj
, level
);
3127 ctx
->NewState
|= _NEW_TEXTURE
;
3131 _mesa_unlock_texture(ctx
, texObj
);
3137 /**********************************************************************/
3138 /****** Compressed Textures ******/
3139 /**********************************************************************/
3143 * Return expected size of a compressed texture.
3146 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3149 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3150 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3155 * Return compressed texture block size, in pixels.
3158 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3160 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3161 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3166 * Error checking for glCompressedTexImage[123]D().
3167 * \return error code or GL_NO_ERROR.
3170 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3171 GLenum target
, GLint level
,
3172 GLenum internalFormat
, GLsizei width
,
3173 GLsizei height
, GLsizei depth
, GLint border
,
3176 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3178 if (dimensions
== 1) {
3179 /* 1D compressed textures not allowed */
3180 return GL_INVALID_ENUM
;
3182 else if (dimensions
== 2) {
3183 if (target
== GL_PROXY_TEXTURE_2D
) {
3184 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3186 else if (target
== GL_TEXTURE_2D
) {
3187 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3189 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3190 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3191 return GL_INVALID_ENUM
; /*target*/
3192 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3194 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3195 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3196 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3197 return GL_INVALID_ENUM
; /*target*/
3198 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3201 return GL_INVALID_ENUM
; /*target*/
3204 else if (dimensions
== 3) {
3205 /* 3D compressed textures not allowed */
3206 return GL_INVALID_ENUM
;
3209 maxTextureSize
= 1 << (maxLevels
- 1);
3211 /* This will detect any invalid internalFormat value */
3212 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3213 return GL_INVALID_ENUM
;
3215 /* This should really never fail */
3216 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3217 return GL_INVALID_ENUM
;
3220 return GL_INVALID_VALUE
;
3223 * XXX We should probably use the proxy texture error check function here.
3225 if (width
< 1 || width
> maxTextureSize
||
3226 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3227 return GL_INVALID_VALUE
;
3229 if ((height
< 1 || height
> maxTextureSize
||
3230 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3232 return GL_INVALID_VALUE
;
3234 if ((depth
< 1 || depth
> maxTextureSize
||
3235 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3237 return GL_INVALID_VALUE
;
3239 /* For cube map, width must equal height */
3240 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3241 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3242 return GL_INVALID_VALUE
;
3244 if (level
< 0 || level
>= maxLevels
)
3245 return GL_INVALID_VALUE
;
3247 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3248 if (expectedSize
!= imageSize
)
3249 return GL_INVALID_VALUE
;
3251 #if FEATURE_EXT_texture_sRGB
3252 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3253 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3254 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3255 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3257 return GL_INVALID_OPERATION
;
3266 * Error checking for glCompressedTexSubImage[123]D().
3267 * \warning There are some bad assumptions here about the size of compressed
3268 * texture tiles (multiple of 4) used to test the validity of the
3269 * offset and size parameters.
3270 * \return error code or GL_NO_ERROR.
3273 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3274 GLenum target
, GLint level
,
3275 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3276 GLsizei width
, GLsizei height
, GLsizei depth
,
3277 GLenum format
, GLsizei imageSize
)
3279 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3283 if (dimensions
== 1) {
3284 /* 1D compressed textures not allowed */
3285 return GL_INVALID_ENUM
;
3287 else if (dimensions
== 2) {
3288 if (target
== GL_PROXY_TEXTURE_2D
) {
3289 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3291 else if (target
== GL_TEXTURE_2D
) {
3292 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3294 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3295 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3296 return GL_INVALID_ENUM
; /*target*/
3297 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3299 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3300 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3301 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3302 return GL_INVALID_ENUM
; /*target*/
3303 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3306 return GL_INVALID_ENUM
; /*target*/
3309 else if (dimensions
== 3) {
3310 /* 3D compressed textures not allowed */
3311 return GL_INVALID_ENUM
;
3314 maxTextureSize
= 1 << (maxLevels
- 1);
3316 /* this will catch any invalid compressed format token */
3317 if (!_mesa_is_compressed_format(ctx
, format
))
3318 return GL_INVALID_ENUM
;
3320 if (width
< 1 || width
> maxTextureSize
)
3321 return GL_INVALID_VALUE
;
3323 if ((height
< 1 || height
> maxTextureSize
)
3325 return GL_INVALID_VALUE
;
3327 if (level
< 0 || level
>= maxLevels
)
3328 return GL_INVALID_VALUE
;
3331 * do checks which depend on compression block size
3333 get_compressed_block_size(format
, &bw
, &bh
);
3335 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3336 return GL_INVALID_VALUE
;
3338 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3339 return GL_INVALID_VALUE
;
3341 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3342 return GL_INVALID_VALUE
;
3344 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3345 if (expectedSize
!= imageSize
)
3346 return GL_INVALID_VALUE
;
3353 * Do second part of glCompressedTexSubImage error checking.
3354 * \return GL_TRUE if error found, GL_FALSE otherwise.
3357 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3358 GLsizei width
, GLsizei height
,
3359 GLsizei depth
, GLenum format
,
3360 struct gl_texture_image
*texImage
)
3363 if ((GLint
) format
!= texImage
->InternalFormat
) {
3364 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3365 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3369 if (((width
== 1 || width
== 2) &&
3370 width
!= (GLsizei
) texImage
->Width
) ||
3371 (width
> (GLsizei
) texImage
->Width
)) {
3372 _mesa_error(ctx
, GL_INVALID_VALUE
,
3373 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3378 if (((height
== 1 || height
== 2) &&
3379 height
!= (GLsizei
) texImage
->Height
) ||
3380 (height
> (GLsizei
) texImage
->Height
)) {
3381 _mesa_error(ctx
, GL_INVALID_VALUE
,
3382 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3388 if (((depth
== 1 || depth
== 2) &&
3389 depth
!= (GLsizei
) texImage
->Depth
) ||
3390 (depth
> (GLsizei
) texImage
->Depth
)) {
3391 _mesa_error(ctx
, GL_INVALID_VALUE
,
3392 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3403 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3404 GLenum internalFormat
, GLsizei width
,
3405 GLint border
, GLsizei imageSize
,
3408 GET_CURRENT_CONTEXT(ctx
);
3409 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3411 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3412 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3413 _mesa_lookup_enum_by_nr(target
), level
,
3414 _mesa_lookup_enum_by_nr(internalFormat
),
3415 width
, border
, imageSize
, data
);
3417 if (target
== GL_TEXTURE_1D
) {
3418 /* non-proxy target */
3419 struct gl_texture_object
*texObj
;
3420 struct gl_texture_image
*texImage
;
3421 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3422 internalFormat
, width
, 1, 1, border
, imageSize
);
3424 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3428 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3430 _mesa_lock_texture(ctx
, texObj
);
3432 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3434 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3437 if (texImage
->Data
) {
3438 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3440 ASSERT(texImage
->Data
== NULL
);
3442 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3443 border
, internalFormat
);
3445 /* Choose actual texture format */
3446 texImage
->TexFormat
=
3447 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3449 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3451 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3452 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3453 internalFormat
, width
, border
,
3457 _mesa_set_fetch_functions(texImage
, 1);
3459 check_gen_mipmap(ctx
, target
, texObj
, level
);
3462 texObj
->_Complete
= GL_FALSE
;
3463 ctx
->NewState
|= _NEW_TEXTURE
;
3466 _mesa_unlock_texture(ctx
, texObj
);
3468 else if (target
== GL_PROXY_TEXTURE_1D
) {
3469 /* Proxy texture: check for errors and update proxy state */
3470 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3471 internalFormat
, width
, 1, 1, border
, imageSize
);
3473 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3474 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3475 internalFormat
, GL_NONE
, GL_NONE
,
3476 width
, 1, 1, border
);
3479 /* if error, clear all proxy texture image parameters */
3480 struct gl_texture_image
*texImage
;
3481 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3483 clear_teximage_fields(texImage
);
3486 /* store the teximage parameters */
3487 struct gl_texture_object
*texObj
;
3488 struct gl_texture_image
*texImage
;
3490 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3492 _mesa_lock_texture(ctx
, texObj
);
3494 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3495 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3496 border
, internalFormat
);
3498 _mesa_unlock_texture(ctx
, texObj
);
3502 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3508 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3509 GLenum internalFormat
, GLsizei width
,
3510 GLsizei height
, GLint border
, GLsizei imageSize
,
3513 GET_CURRENT_CONTEXT(ctx
);
3514 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3516 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3517 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3518 _mesa_lookup_enum_by_nr(target
), level
,
3519 _mesa_lookup_enum_by_nr(internalFormat
),
3520 width
, height
, border
, imageSize
, data
);
3523 switch (internalFormat
) {
3524 case GL_PALETTE4_RGB8_OES
:
3525 case GL_PALETTE4_RGBA8_OES
:
3526 case GL_PALETTE4_R5_G6_B5_OES
:
3527 case GL_PALETTE4_RGBA4_OES
:
3528 case GL_PALETTE4_RGB5_A1_OES
:
3529 case GL_PALETTE8_RGB8_OES
:
3530 case GL_PALETTE8_RGBA8_OES
:
3531 case GL_PALETTE8_R5_G6_B5_OES
:
3532 case GL_PALETTE8_RGBA4_OES
:
3533 case GL_PALETTE8_RGB5_A1_OES
:
3534 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3535 width
, height
, imageSize
, data
);
3540 if (target
== GL_TEXTURE_2D
||
3541 (ctx
->Extensions
.ARB_texture_cube_map
&&
3542 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3543 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3544 /* non-proxy target */
3545 struct gl_texture_object
*texObj
;
3546 struct gl_texture_image
*texImage
;
3548 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3549 internalFormat
, width
, height
, 1, border
, imageSize
);
3551 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3555 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3557 _mesa_lock_texture(ctx
, texObj
);
3559 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3561 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3564 if (texImage
->Data
) {
3565 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3567 ASSERT(texImage
->Data
== NULL
);
3569 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3570 border
, internalFormat
);
3572 /* Choose actual texture format */
3573 texImage
->TexFormat
=
3574 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3576 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3578 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3579 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3580 internalFormat
, width
, height
,
3581 border
, imageSize
, data
,
3584 _mesa_set_fetch_functions(texImage
, 2);
3586 check_gen_mipmap(ctx
, target
, texObj
, level
);
3589 texObj
->_Complete
= GL_FALSE
;
3590 ctx
->NewState
|= _NEW_TEXTURE
;
3593 _mesa_unlock_texture(ctx
, texObj
);
3595 else if (target
== GL_PROXY_TEXTURE_2D
||
3596 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3597 ctx
->Extensions
.ARB_texture_cube_map
)) {
3598 /* Proxy texture: check for errors and update proxy state */
3599 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3600 internalFormat
, width
, height
, 1, border
, imageSize
);
3602 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3603 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3604 internalFormat
, GL_NONE
, GL_NONE
,
3605 width
, height
, 1, border
);
3608 /* if error, clear all proxy texture image parameters */
3609 struct gl_texture_image
*texImage
;
3610 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3612 clear_teximage_fields(texImage
);
3615 /* store the teximage parameters */
3616 struct gl_texture_object
*texObj
;
3617 struct gl_texture_image
*texImage
;
3619 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3621 _mesa_lock_texture(ctx
, texObj
);
3623 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3624 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3625 border
, internalFormat
);
3627 _mesa_unlock_texture(ctx
, texObj
);
3631 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3638 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3639 GLenum internalFormat
, GLsizei width
,
3640 GLsizei height
, GLsizei depth
, GLint border
,
3641 GLsizei imageSize
, const GLvoid
*data
)
3643 GET_CURRENT_CONTEXT(ctx
);
3644 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3646 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3647 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3648 _mesa_lookup_enum_by_nr(target
), level
,
3649 _mesa_lookup_enum_by_nr(internalFormat
),
3650 width
, height
, depth
, border
, imageSize
, data
);
3652 if (target
== GL_TEXTURE_3D
) {
3653 /* non-proxy target */
3654 struct gl_texture_object
*texObj
;
3655 struct gl_texture_image
*texImage
;
3656 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3657 internalFormat
, width
, height
, depth
, border
, imageSize
);
3659 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3663 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3665 _mesa_lock_texture(ctx
, texObj
);
3667 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3669 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3672 if (texImage
->Data
) {
3673 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3675 ASSERT(texImage
->Data
== NULL
);
3677 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3678 width
, height
, depth
,
3679 border
, internalFormat
);
3681 /* Choose actual texture format */
3682 texImage
->TexFormat
=
3683 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3685 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3687 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3688 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3690 width
, height
, depth
,
3691 border
, imageSize
, data
,
3694 _mesa_set_fetch_functions(texImage
, 3);
3696 check_gen_mipmap(ctx
, target
, texObj
, level
);
3699 texObj
->_Complete
= GL_FALSE
;
3700 ctx
->NewState
|= _NEW_TEXTURE
;
3703 _mesa_unlock_texture(ctx
, texObj
);
3705 else if (target
== GL_PROXY_TEXTURE_3D
) {
3706 /* Proxy texture: check for errors and update proxy state */
3707 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3708 internalFormat
, width
, height
, depth
, border
, imageSize
);
3710 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3711 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3712 internalFormat
, GL_NONE
, GL_NONE
,
3713 width
, height
, depth
, border
);
3716 /* if error, clear all proxy texture image parameters */
3717 struct gl_texture_image
*texImage
;
3718 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3720 clear_teximage_fields(texImage
);
3723 /* store the teximage parameters */
3724 struct gl_texture_object
*texObj
;
3725 struct gl_texture_image
*texImage
;
3727 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3729 _mesa_lock_texture(ctx
, texObj
);
3731 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3732 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3733 depth
, border
, internalFormat
);
3735 _mesa_unlock_texture(ctx
, texObj
);
3739 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3746 * Common helper for glCompressedTexSubImage1/2/3D().
3749 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3750 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3751 GLsizei width
, GLsizei height
, GLsizei depth
,
3752 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3754 struct gl_texture_object
*texObj
;
3755 struct gl_texture_image
*texImage
;
3757 GET_CURRENT_CONTEXT(ctx
);
3758 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3760 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3761 xoffset
, 0, 0, /* pos */
3762 width
, height
, depth
, /* size */
3765 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3769 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3771 _mesa_lock_texture(ctx
, texObj
);
3773 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3776 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3777 format
, texImage
)) {
3778 /* error was recorded */
3780 else if (width
> 0 && height
> 0 && depth
> 0) {
3783 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3784 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3786 format
, imageSize
, data
,
3791 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3792 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3795 format
, imageSize
, data
,
3800 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3801 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3802 xoffset
, yoffset
, zoffset
,
3803 width
, height
, depth
,
3804 format
, imageSize
, data
,
3812 check_gen_mipmap(ctx
, target
, texObj
, level
);
3814 ctx
->NewState
|= _NEW_TEXTURE
;
3817 _mesa_unlock_texture(ctx
, texObj
);
3822 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3823 GLsizei width
, GLenum format
,
3824 GLsizei imageSize
, const GLvoid
*data
)
3826 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3827 format
, imageSize
, data
);
3832 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3833 GLint yoffset
, GLsizei width
, GLsizei height
,
3834 GLenum format
, GLsizei imageSize
,
3837 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3838 width
, height
, 1, format
, imageSize
, data
);
3843 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3844 GLint yoffset
, GLint zoffset
, GLsizei width
,
3845 GLsizei height
, GLsizei depth
, GLenum format
,
3846 GLsizei imageSize
, const GLvoid
*data
)
3848 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3849 width
, height
, depth
, format
, imageSize
, data
);