2 /**************************************************************************
4 * Copyright 2003 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
29 #include "main/bufferobj.h"
30 #include "main/macros.h"
31 #include "main/mtypes.h"
33 #include "main/texobj.h"
34 #include "main/texstore.h"
35 #include "main/texcompress.h"
36 #include "main/enums.h"
38 #include "intel_batchbuffer.h"
39 #include "intel_context.h"
40 #include "intel_tex.h"
41 #include "intel_mipmap_tree.h"
42 #include "intel_blit.h"
44 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
47 intel_blit_texsubimage(struct gl_context
* ctx
,
48 struct gl_texture_image
*texImage
,
49 GLint xoffset
, GLint yoffset
,
50 GLint width
, GLint height
,
51 GLenum format
, GLenum type
, const void *pixels
,
52 const struct gl_pixelstore_attrib
*packing
)
54 struct intel_context
*intel
= intel_context(ctx
);
55 struct intel_texture_image
*intelImage
= intel_texture_image(texImage
);
57 /* Try to do a blit upload of the subimage if the texture is
63 /* The blitter can't handle Y tiling */
64 if (intelImage
->mt
->region
->tiling
== I915_TILING_Y
)
67 if (texImage
->TexObject
->Target
!= GL_TEXTURE_2D
)
70 if (!drm_intel_bo_busy(intelImage
->mt
->region
->bo
))
73 DBG("BLT subimage %s target %s level %d offset %d,%d %dx%d\n",
75 _mesa_enum_to_string(texImage
->TexObject
->Target
),
76 texImage
->Level
, xoffset
, yoffset
, width
, height
);
78 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1,
79 format
, type
, pixels
, packing
,
84 struct intel_mipmap_tree
*temp_mt
=
85 intel_miptree_create(intel
, GL_TEXTURE_2D
, texImage
->TexFormat
,
88 false, INTEL_MIPTREE_TILING_NONE
);
92 GLubyte
*dst
= intel_miptree_map_raw(intel
, temp_mt
);
96 if (!_mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
98 temp_mt
->region
->pitch
,
101 format
, type
, pixels
, packing
)) {
102 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
105 intel_miptree_unmap_raw(temp_mt
);
109 ret
= intel_miptree_blit(intel
,
112 intelImage
->mt
, texImage
->Level
, texImage
->Face
,
113 xoffset
, yoffset
, false,
114 width
, height
, GL_COPY
);
117 intel_miptree_release(&temp_mt
);
118 _mesa_unmap_teximage_pbo(ctx
, packing
);
123 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "intelTexSubImage");
124 intel_miptree_release(&temp_mt
);
125 _mesa_unmap_teximage_pbo(ctx
, packing
);
130 intelTexSubImage(struct gl_context
* ctx
,
132 struct gl_texture_image
*texImage
,
133 GLint xoffset
, GLint yoffset
, GLint zoffset
,
134 GLsizei width
, GLsizei height
, GLsizei depth
,
135 GLenum format
, GLenum type
,
136 const GLvoid
* pixels
,
137 const struct gl_pixelstore_attrib
*packing
)
139 /* The intel_blit_texsubimage() function only handles 2D images */
140 if (dims
!= 2 || !intel_blit_texsubimage(ctx
, texImage
,
143 format
, type
, pixels
, packing
)) {
144 _mesa_store_texsubimage(ctx
, dims
, texImage
,
145 xoffset
, yoffset
, zoffset
,
146 width
, height
, depth
,
147 format
, type
, pixels
, packing
);
152 intelInitTextureSubImageFuncs(struct dd_function_table
*functions
)
154 functions
->TexSubImage
= intelTexSubImage
;