4b5fe7be9f5c22dd5b02e5011353802dd45a2aa4
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"
33 #include "main/mipmap.h"
35 #include "drivers/common/meta.h"
37 #include "intel_screen.h"
38 #include "intel_context.h"
39 #include "intel_batchbuffer.h"
40 #include "intel_buffers.h"
41 #include "intel_mipmap_tree.h"
42 #include "intel_regions.h"
43 #include "intel_fbo.h"
44 #include "intel_tex.h"
45 #include "intel_blit.h"
47 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
50 * Get the intel_region which is the source for any glCopyTex[Sub]Image call.
52 * Do the best we can using the blitter. A future project is to use
53 * the texture engine and fragment programs for these copies.
55 static const struct intel_region
*
56 get_teximage_source(struct intel_context
*intel
, GLenum internalFormat
)
58 struct intel_renderbuffer
*irb
;
60 DBG("%s %s\n", __FUNCTION__
,
61 _mesa_lookup_enum_by_nr(internalFormat
));
63 switch (internalFormat
) {
64 case GL_DEPTH_COMPONENT
:
65 case GL_DEPTH_COMPONENT16
:
66 irb
= intel_get_renderbuffer(intel
->ctx
.ReadBuffer
, BUFFER_DEPTH
);
67 if (irb
&& irb
->region
&& irb
->region
->cpp
== 2)
70 case GL_DEPTH24_STENCIL8_EXT
:
71 case GL_DEPTH_STENCIL_EXT
:
72 irb
= intel_get_renderbuffer(intel
->ctx
.ReadBuffer
, BUFFER_DEPTH
);
73 if (irb
&& irb
->region
&& irb
->region
->cpp
== 4)
80 return intel_readbuf_region(intel
);
88 do_copy_texsubimage(struct intel_context
*intel
,
90 struct intel_texture_image
*intelImage
,
91 GLenum internalFormat
,
92 GLint dstx
, GLint dsty
,
93 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
95 GLcontext
*ctx
= &intel
->ctx
;
96 const struct intel_region
*src
= get_teximage_source(intel
, internalFormat
);
98 if (!intelImage
->mt
|| !src
) {
99 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
100 fprintf(stderr
, "%s fail %p %p (0x%08x)\n",
101 __FUNCTION__
, intelImage
->mt
, src
, internalFormat
);
105 if (intelImage
->mt
->cpp
!= src
->cpp
) {
106 if (INTEL_DEBUG
& DEBUG_FALLBACKS
)
107 fprintf(stderr
, "%s fail %d vs %d cpp\n",
108 __FUNCTION__
, intelImage
->mt
->cpp
, src
->cpp
);
113 LOCK_HARDWARE(intel
);
115 drm_intel_bo
*dst_bo
= intel_region_buffer(intel
,
116 intelImage
->mt
->region
,
118 const GLint orig_x
= x
;
119 const GLint orig_y
= y
;
120 GLuint image_x
, image_y
;
123 /* get dest x/y in destination texture */
124 intel_miptree_get_image_offset(intelImage
->mt
,
129 /* Update dst for clipped src. Need to also clip the source rect. */
133 /* Can't blit to tiled buffers with non-tile-aligned offset. */
134 if (intelImage
->mt
->region
->tiling
== I915_TILING_Y
) {
135 UNLOCK_HARDWARE(intel
);
139 if (ctx
->ReadBuffer
->Name
== 0) {
140 /* reading from a window, adjust x, y */
141 const __DRIdrawablePrivate
*dPriv
= intel
->driReadDrawable
;
142 y
= dPriv
->y
+ (dPriv
->h
- (y
+ height
));
145 /* Invert the data coming from the source rectangle due to GL
146 * and hardware disagreeing on where y=0 is.
148 * It appears that our offsets and pitches get mangled
149 * appropriately by the hardware, and we don't need to adjust them
152 src_pitch
= -src
->pitch
;
154 /* reading from a FBO, y is already oriented the way we like */
155 src_pitch
= src
->pitch
;
158 /* blit from src buffer to texture */
159 if (!intelEmitCopyBlit(intel
,
165 intelImage
->mt
->pitch
,
168 intelImage
->mt
->region
->tiling
,
169 x
, y
, image_x
+ dstx
, image_y
+ dsty
,
172 UNLOCK_HARDWARE(intel
);
177 UNLOCK_HARDWARE(intel
);
184 intelCopyTexImage1D(GLcontext
* ctx
, GLenum target
, GLint level
,
185 GLenum internalFormat
,
186 GLint x
, GLint y
, GLsizei width
, GLint border
)
188 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
189 struct gl_texture_object
*texObj
=
190 _mesa_select_tex_object(ctx
, texUnit
, target
);
191 struct gl_texture_image
*texImage
=
192 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
193 int srcx
, srcy
, dstx
, dsty
, height
;
198 /* Setup or redefine the texture object, mipmap tree and texture
199 * image. Don't populate yet.
201 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
203 GL_RGBA
, CHAN_TYPE
, NULL
,
204 &ctx
->DefaultPacking
, texObj
, texImage
);
210 if (!_mesa_clip_copytexsubimage(ctx
,
216 if (!do_copy_texsubimage(intel_context(ctx
), target
,
217 intel_texture_image(texImage
),
218 internalFormat
, 0, 0, x
, y
, width
, height
))
224 _mesa_meta_CopyTexImage1D(ctx
, target
, level
, internalFormat
, x
, y
,
230 intelCopyTexImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
231 GLenum internalFormat
,
232 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
235 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
236 struct gl_texture_object
*texObj
=
237 _mesa_select_tex_object(ctx
, texUnit
, target
);
238 struct gl_texture_image
*texImage
=
239 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
240 int srcx
, srcy
, dstx
, dsty
;
245 /* Setup or redefine the texture object, mipmap tree and texture
246 * image. Don't populate yet.
248 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
249 width
, height
, border
,
250 GL_RGBA
, GL_UNSIGNED_BYTE
, NULL
,
251 &ctx
->DefaultPacking
, texObj
, texImage
);
257 if (!_mesa_clip_copytexsubimage(ctx
,
263 if (!do_copy_texsubimage(intel_context(ctx
), target
,
264 intel_texture_image(texImage
),
265 internalFormat
, 0, 0, x
, y
, width
, height
))
271 _mesa_meta_CopyTexImage2D(ctx
, target
, level
, internalFormat
, x
, y
,
272 width
, height
, border
);
277 intelCopyTexSubImage1D(GLcontext
* ctx
, GLenum target
, GLint level
,
278 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
280 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
281 struct gl_texture_object
*texObj
=
282 _mesa_select_tex_object(ctx
, texUnit
, target
);
283 struct gl_texture_image
*texImage
=
284 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
285 GLenum internalFormat
= texImage
->InternalFormat
;
287 /* XXX need to check <border> as in above function? */
289 /* Need to check texture is compatible with source format.
292 if (!do_copy_texsubimage(intel_context(ctx
), target
,
293 intel_texture_image(texImage
),
294 internalFormat
, xoffset
, 0, x
, y
, width
, 1)) {
295 _mesa_meta_CopyTexSubImage1D(ctx
, target
, level
, xoffset
, x
, y
, width
);
301 intelCopyTexSubImage2D(GLcontext
* ctx
, GLenum target
, GLint level
,
302 GLint xoffset
, GLint yoffset
,
303 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
305 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
306 struct gl_texture_object
*texObj
=
307 _mesa_select_tex_object(ctx
, texUnit
, target
);
308 struct gl_texture_image
*texImage
=
309 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
310 GLenum internalFormat
= texImage
->InternalFormat
;
312 /* Need to check texture is compatible with source format.
315 if (!do_copy_texsubimage(intel_context(ctx
), target
,
316 intel_texture_image(texImage
),
318 xoffset
, yoffset
, x
, y
, width
, height
)) {
320 DBG("%s - fallback to _mesa_meta_CopyTexSubImage2D\n", __FUNCTION__
);
322 _mesa_meta_CopyTexSubImage2D(ctx
, target
, level
,
323 xoffset
, yoffset
, x
, y
, width
, height
);
329 intelInitTextureCopyImageFuncs(struct dd_function_table
*functions
)
331 functions
->CopyTexImage1D
= intelCopyTexImage1D
;
332 functions
->CopyTexImage2D
= intelCopyTexImage2D
;
333 functions
->CopyTexSubImage1D
= intelCopyTexSubImage1D
;
334 functions
->CopyTexSubImage2D
= intelCopyTexSubImage2D
;