381ad14dcbf6d4e9bd39654bc1a0b487cbf1121f
1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "main/mtypes.h"
29 #include "main/enums.h"
30 #include "main/image.h"
31 #include "main/teximage.h"
32 #include "main/texstate.h"
34 #include "drivers/common/meta.h"
36 #include "intel_screen.h"
37 #include "intel_context.h"
38 #include "intel_buffers.h"
39 #include "intel_mipmap_tree.h"
40 #include "intel_regions.h"
41 #include "intel_fbo.h"
42 #include "intel_tex.h"
43 #include "intel_blit.h"
45 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
48 * Get the intel_region which is the source for any glCopyTex[Sub]Image call.
50 * Do the best we can using the blitter. A future project is to use
51 * the texture engine and fragment programs for these copies.
53 static const struct intel_region
*
54 get_teximage_source(struct intel_context
*intel
, GLenum internalFormat
)
56 struct intel_renderbuffer
*irb
;
58 DBG("%s %s\n", __FUNCTION__
,
59 _mesa_lookup_enum_by_nr(internalFormat
));
61 switch (internalFormat
) {
62 case GL_DEPTH_COMPONENT
:
63 case GL_DEPTH_COMPONENT16
:
64 irb
= intel_get_renderbuffer(intel
->ctx
.ReadBuffer
, BUFFER_DEPTH
);
65 if (irb
&& irb
->region
&& irb
->region
->cpp
== 2)
68 case GL_DEPTH24_STENCIL8_EXT
:
69 case GL_DEPTH_STENCIL_EXT
:
70 irb
= intel_get_renderbuffer(intel
->ctx
.ReadBuffer
, BUFFER_DEPTH
);
71 if (irb
&& irb
->region
&& irb
->region
->cpp
== 4)
77 irb
= intel_renderbuffer(intel
->ctx
.ReadBuffer
->_ColorReadBuffer
);
78 /* We're required to set alpha to 1.0 in this case, but we can't
79 * do that with the blitter, so fall back. We could use the 3D
80 * engine or do two passes with the blitter, but it doesn't seem
81 * worth it for this case. */
82 if (irb
->Base
._BaseFormat
== GL_RGB
)
88 return intel_readbuf_region(intel
);
96 do_copy_texsubimage(struct intel_context
*intel
,
98 struct intel_texture_image
*intelImage
,
99 GLenum internalFormat
,
100 GLint dstx
, GLint dsty
,
101 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
103 struct gl_context
*ctx
= &intel
->ctx
;
104 const struct intel_region
*src
;
106 intel_prepare_render(intel
);
107 src
= get_teximage_source(intel
, internalFormat
);
108 if (!intelImage
->mt
|| !src
|| !src
->buffer
) {
109 if (unlikely(INTEL_DEBUG
& DEBUG_FALLBACKS
))
110 fprintf(stderr
, "%s fail %p %p (0x%08x)\n",
111 __FUNCTION__
, intelImage
->mt
, src
, internalFormat
);
115 if (intelImage
->mt
->cpp
!= src
->cpp
) {
116 fallback_debug("%s fail %d vs %d cpp\n",
117 __FUNCTION__
, intelImage
->mt
->cpp
, src
->cpp
);
122 drm_intel_bo
*dst_bo
= intel_region_buffer(intel
,
123 intelImage
->mt
->region
,
125 GLuint image_x
, image_y
;
128 /* get dest x/y in destination texture */
129 intel_miptree_get_image_offset(intelImage
->mt
,
135 /* The blitter can't handle Y-tiled buffers. */
136 if (intelImage
->mt
->region
->tiling
== I915_TILING_Y
) {
140 if (ctx
->ReadBuffer
->Name
== 0) {
141 /* Flip vertical orientation for system framebuffers */
142 y
= ctx
->ReadBuffer
->Height
- (y
+ height
);
143 src_pitch
= -src
->pitch
;
145 /* reading from a FBO, y is already oriented the way we like */
146 src_pitch
= src
->pitch
;
149 /* blit from src buffer to texture */
150 if (!intelEmitCopyBlit(intel
,
156 intelImage
->mt
->region
->pitch
,
159 intelImage
->mt
->region
->tiling
,
160 src
->draw_x
+ x
, src
->draw_y
+ y
,
161 image_x
+ dstx
, image_y
+ dsty
,
173 intelCopyTexImage1D(struct gl_context
* ctx
, GLenum target
, GLint level
,
174 GLenum internalFormat
,
175 GLint x
, GLint y
, GLsizei width
, GLint border
)
177 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
178 struct gl_texture_object
*texObj
=
179 _mesa_select_tex_object(ctx
, texUnit
, target
);
180 struct gl_texture_image
*texImage
=
181 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
182 int srcx
, srcy
, dstx
, dsty
, height
;
187 /* Setup or redefine the texture object, mipmap tree and texture
188 * image. Don't populate yet.
190 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
192 GL_RGBA
, CHAN_TYPE
, NULL
,
193 &ctx
->DefaultPacking
, texObj
, texImage
);
199 if (!_mesa_clip_copytexsubimage(ctx
,
205 if (!do_copy_texsubimage(intel_context(ctx
), target
,
206 intel_texture_image(texImage
),
207 internalFormat
, 0, 0, x
, y
, width
, height
))
213 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
214 _mesa_meta_CopyTexImage1D(ctx
, target
, level
, internalFormat
, x
, y
,
220 intelCopyTexImage2D(struct gl_context
* ctx
, GLenum target
, GLint level
,
221 GLenum internalFormat
,
222 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
225 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
226 struct gl_texture_object
*texObj
=
227 _mesa_select_tex_object(ctx
, texUnit
, target
);
228 struct gl_texture_image
*texImage
=
229 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
230 int srcx
, srcy
, dstx
, dsty
;
235 /* Setup or redefine the texture object, mipmap tree and texture
236 * image. Don't populate yet.
238 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
239 width
, height
, border
,
240 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
,
241 &ctx
->DefaultPacking
, texObj
, texImage
);
247 if (!_mesa_clip_copytexsubimage(ctx
,
253 if (!do_copy_texsubimage(intel_context(ctx
), target
,
254 intel_texture_image(texImage
),
255 internalFormat
, 0, 0, x
, y
, width
, height
))
261 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
262 _mesa_meta_CopyTexImage2D(ctx
, target
, level
, internalFormat
, x
, y
,
263 width
, height
, border
);
268 intelCopyTexSubImage1D(struct gl_context
* ctx
, GLenum target
, GLint level
,
269 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
271 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
272 struct gl_texture_object
*texObj
=
273 _mesa_select_tex_object(ctx
, texUnit
, target
);
274 struct gl_texture_image
*texImage
=
275 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
276 GLenum internalFormat
= texImage
->InternalFormat
;
278 /* XXX need to check <border> as in above function? */
280 /* Need to check texture is compatible with source format.
283 if (!do_copy_texsubimage(intel_context(ctx
), target
,
284 intel_texture_image(texImage
),
285 internalFormat
, xoffset
, 0, x
, y
, width
, 1)) {
286 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
287 _mesa_meta_CopyTexSubImage1D(ctx
, target
, level
, xoffset
, x
, y
, width
);
293 intelCopyTexSubImage2D(struct gl_context
* ctx
, GLenum target
, GLint level
,
294 GLint xoffset
, GLint yoffset
,
295 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
297 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
298 struct gl_texture_object
*texObj
=
299 _mesa_select_tex_object(ctx
, texUnit
, target
);
300 struct gl_texture_image
*texImage
=
301 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
302 GLenum internalFormat
= texImage
->InternalFormat
;
304 /* Need to check texture is compatible with source format.
307 if (!do_copy_texsubimage(intel_context(ctx
), target
,
308 intel_texture_image(texImage
),
310 xoffset
, yoffset
, x
, y
, width
, height
)) {
312 fallback_debug("%s - fallback to swrast\n", __FUNCTION__
);
313 _mesa_meta_CopyTexSubImage2D(ctx
, target
, level
,
314 xoffset
, yoffset
, x
, y
, width
, height
);
320 intelInitTextureCopyImageFuncs(struct dd_function_table
*functions
)
322 functions
->CopyTexImage1D
= intelCopyTexImage1D
;
323 functions
->CopyTexImage2D
= intelCopyTexImage2D
;
324 functions
->CopyTexSubImage1D
= intelCopyTexSubImage1D
;
325 functions
->CopyTexSubImage2D
= intelCopyTexSubImage2D
;