~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/mesa/drivers/dri/radeon/radeon_tex_copy.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
 
39
39
static GLboolean
40
40
do_copy_texsubimage(struct gl_context *ctx,
41
 
                    GLenum target, GLint level,
42
41
                    struct radeon_tex_obj *tobj,
43
42
                    radeon_texture_image *timg,
44
43
                    GLint dstx, GLint dsty,
 
44
                    struct radeon_renderbuffer *rrb,
45
45
                    GLint x, GLint y,
46
46
                    GLsizei width, GLsizei height)
47
47
{
48
48
    radeonContextPtr radeon = RADEON_CONTEXT(ctx);
49
 
    struct radeon_renderbuffer *rrb;
 
49
    const GLuint face = timg->base.Base.Face;
 
50
    const GLuint level = timg->base.Base.Level;
50
51
    unsigned src_bpp;
51
52
    unsigned dst_bpp;
52
53
    gl_format src_mesaformat;
53
54
    gl_format dst_mesaformat;
54
 
    unsigned src_width;
55
 
    unsigned dst_width;
56
55
    unsigned flip_y;
57
56
 
58
57
    if (!radeon->vtbl.blit) {
59
58
        return GL_FALSE;
60
59
    }
61
60
 
62
 
    if (_mesa_get_format_bits(timg->base.TexFormat, GL_DEPTH_BITS) > 0) {
63
 
        if (ctx->ReadBuffer->_DepthBuffer && ctx->ReadBuffer->_DepthBuffer->Wrapped) {
64
 
            rrb = radeon_renderbuffer(ctx->ReadBuffer->_DepthBuffer->Wrapped);
65
 
        } else {
66
 
            rrb = radeon_renderbuffer(ctx->ReadBuffer->_DepthBuffer);
67
 
        }
 
61
    // This is software renderbuffer, fallback to swrast
 
62
    if (!rrb) {
 
63
        return GL_FALSE;
 
64
    }
 
65
 
 
66
    if (_mesa_get_format_bits(timg->base.Base.TexFormat, GL_DEPTH_BITS) > 0) {
 
67
        /* copying depth values */
68
68
        flip_y = ctx->ReadBuffer->Attachment[BUFFER_DEPTH].Type == GL_NONE;
69
69
    } else {
70
 
        rrb = radeon_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer);
 
70
        /* copying color */
71
71
        flip_y = ctx->ReadBuffer->Attachment[BUFFER_COLOR0].Type == GL_NONE;
72
72
    }
73
73
 
74
 
    // This is software renderbuffer, fallback to swrast
75
 
    if (!rrb) {
76
 
        return GL_FALSE;
77
 
    }
78
 
 
79
74
    if (!timg->mt) {
80
75
        radeon_validate_texture_miptree(ctx, &tobj->base);
81
76
    }
83
78
    assert(rrb->bo);
84
79
    assert(timg->mt);
85
80
    assert(timg->mt->bo);
86
 
    assert(timg->base.Width >= dstx + width);
87
 
    assert(timg->base.Height >= dsty + height);
 
81
    assert(timg->base.Base.Width >= dstx + width);
 
82
    assert(timg->base.Base.Height >= dsty + height);
88
83
 
89
84
    intptr_t src_offset = rrb->draw_offset;
90
 
    intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, _mesa_tex_target_to_face(target), level);
 
85
    intptr_t dst_offset = radeon_miptree_image_offset(timg->mt, face, level);
91
86
 
92
87
    if (0) {
93
88
        fprintf(stderr, "%s: copying to face %d, level %d\n",
94
 
                __FUNCTION__, _mesa_tex_target_to_face(target), level);
 
89
                __FUNCTION__, face, level);
95
90
        fprintf(stderr, "to: x %d, y %d, offset %d\n", dstx, dsty, (uint32_t) dst_offset);
96
91
        fprintf(stderr, "from (%dx%d) width %d, height %d, offset %d, pitch %d\n",
97
 
                x, y, rrb->base.Width, rrb->base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp);
 
92
                x, y, rrb->base.Base.Width, rrb->base.Base.Height, (uint32_t) src_offset, rrb->pitch/rrb->cpp);
98
93
        fprintf(stderr, "src size %d, dst size %d\n", rrb->bo->size, timg->mt->bo->size);
99
94
 
100
95
    }
101
96
 
102
 
    src_mesaformat = rrb->base.Format;
103
 
    dst_mesaformat = timg->base.TexFormat;
104
 
    src_width = rrb->base.Width;
105
 
    dst_width = timg->base.Width;
 
97
    src_mesaformat = rrb->base.Base.Format;
 
98
    dst_mesaformat = timg->base.Base.TexFormat;
106
99
    src_bpp = _mesa_get_format_bytes(src_mesaformat);
107
100
    dst_bpp = _mesa_get_format_bytes(dst_mesaformat);
108
 
    if (!radeon->vtbl.check_blit(dst_mesaformat)) {
 
101
    if (!radeon->vtbl.check_blit(dst_mesaformat, rrb->pitch / rrb->cpp)) {
109
102
            /* depth formats tend to be special */
110
103
            if (_mesa_get_format_bits(dst_mesaformat, GL_DEPTH_BITS) > 0)
111
104
                    return GL_FALSE;
133
126
 
134
127
    /* blit from src buffer to texture */
135
128
    return radeon->vtbl.blit(ctx, rrb->bo, src_offset, src_mesaformat, rrb->pitch/rrb->cpp,
136
 
                             src_width, rrb->base.Height, x, y,
 
129
                             rrb->base.Base.Width, rrb->base.Base.Height, x, y,
137
130
                             timg->mt->bo, dst_offset, dst_mesaformat,
138
131
                             timg->mt->levels[level].rowstride / dst_bpp,
139
 
                             dst_width, timg->base.Height,
 
132
                             timg->base.Base.Width, timg->base.Base.Height,
140
133
                             dstx, dsty, width, height, flip_y);
141
134
}
142
135
 
143
136
void
144
 
radeonCopyTexImage2D(struct gl_context *ctx, GLenum target, GLint level,
145
 
                     GLenum internalFormat,
146
 
                     GLint x, GLint y, GLsizei width, GLsizei height,
147
 
                     GLint border)
148
 
{
149
 
    struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
150
 
    struct gl_texture_object *texObj =
151
 
        _mesa_select_tex_object(ctx, texUnit, target);
152
 
    struct gl_texture_image *texImage =
153
 
        _mesa_select_tex_image(ctx, texObj, target, level);
154
 
    int srcx, srcy, dstx, dsty;
155
 
 
156
 
    radeonContextPtr radeon = RADEON_CONTEXT(ctx);
157
 
    radeon_prepare_render(radeon);
158
 
 
159
 
    if (border)
160
 
        goto fail;
161
 
 
162
 
    /* Setup or redefine the texture object, mipmap tree and texture
163
 
     * image.  Don't populate yet.
164
 
     */
165
 
    ctx->Driver.TexImage2D(ctx, target, level, internalFormat,
166
 
                           width, height, border,
167
 
                           GL_RGBA, GL_UNSIGNED_BYTE, NULL,
168
 
                           &ctx->DefaultPacking, texObj, texImage);
169
 
 
170
 
    srcx = x;
171
 
    srcy = y;
172
 
    dstx = 0;
173
 
    dsty = 0;
174
 
    if (!_mesa_clip_copytexsubimage(ctx,
175
 
                                    &dstx, &dsty,
176
 
                                    &srcx, &srcy,
177
 
                                    &width, &height)) {
178
 
        return;
179
 
    }
180
 
 
181
 
    if (!do_copy_texsubimage(ctx, target, level,
182
 
                             radeon_tex_obj(texObj), (radeon_texture_image *)texImage,
183
 
                             0, 0, x, y, width, height)) {
184
 
        goto fail;
185
 
    }
186
 
 
187
 
    return;
188
 
 
189
 
fail:
190
 
    radeon_print(RADEON_FALLBACKS, RADEON_NORMAL,
191
 
                 "Falling back to sw for glCopyTexImage2D (internalFormat %s, border %d)\n",
192
 
                 _mesa_lookup_enum_by_nr(internalFormat), border);
193
 
 
194
 
    _mesa_meta_CopyTexImage2D(ctx, target, level, internalFormat, x, y,
195
 
                              width, height, border);
196
 
}
197
 
 
198
 
void
199
 
radeonCopyTexSubImage2D(struct gl_context *ctx, GLenum target, GLint level,
 
137
radeonCopyTexSubImage2D(struct gl_context *ctx,
 
138
                        struct gl_texture_image *texImage,
200
139
                        GLint xoffset, GLint yoffset,
 
140
                        struct gl_renderbuffer *rb,
201
141
                        GLint x, GLint y,
202
142
                        GLsizei width, GLsizei height)
203
143
{
204
 
    struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
205
 
    struct gl_texture_object *texObj = _mesa_select_tex_object(ctx, texUnit, target);
206
 
    struct gl_texture_image *texImage = _mesa_select_tex_image(ctx, texObj, target, level);
207
 
 
208
144
    radeonContextPtr radeon = RADEON_CONTEXT(ctx);
209
145
    radeon_prepare_render(radeon);
210
146
 
211
 
    if (!do_copy_texsubimage(ctx, target, level,
212
 
                             radeon_tex_obj(texObj), (radeon_texture_image *)texImage,
213
 
                             xoffset, yoffset, x, y, width, height)) {
 
147
    if (!do_copy_texsubimage(ctx,
 
148
                             radeon_tex_obj(texImage->TexObject),
 
149
                             (radeon_texture_image *)texImage,
 
150
                             xoffset, yoffset,
 
151
                             radeon_renderbuffer(rb),                                                        x, y, width, height)) {
214
152
 
215
153
        radeon_print(RADEON_FALLBACKS, RADEON_NORMAL,
216
154
                     "Falling back to sw for glCopyTexSubImage2D\n");
217
155
 
218
 
        _mesa_meta_CopyTexSubImage2D(ctx, target, level,
219
 
                                     xoffset, yoffset, x, y, width, height);
 
156
        _mesa_meta_CopyTexSubImage2D(ctx, texImage,
 
157
                                     xoffset, yoffset,
 
158
                                     rb, x, y, width, height);
220
159
    }
221
160
}