summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Olšák <maraeo@gmail.com>2010-07-12 05:18:05 +0200
committerMarek Olšák <maraeo@gmail.com>2010-07-12 05:32:42 +0200
commit749e24521a31178d2b647aa2954c3eecd597b799 (patch)
treefb761feecd57b4c235b0c2e59eb414a1ea2fd740
parent3bd15a9e4336233b82b063ea7257eeeee7e03b07 (diff)
u_blitter: clean up the texcoord computations
-rw-r--r--src/gallium/auxiliary/util/u_blitter.c63
1 files changed, 35 insertions, 28 deletions
diff --git a/src/gallium/auxiliary/util/u_blitter.c b/src/gallium/auxiliary/util/u_blitter.c
index 42f2e02b8a0..6a042c6f6df 100644
--- a/src/gallium/auxiliary/util/u_blitter.c
+++ b/src/gallium/auxiliary/util/u_blitter.c
@@ -403,29 +403,45 @@ static void blitter_set_clear_color(struct blitter_context_priv *ctx,
}
}
+static void get_normalized_texcoords(struct pipe_resource *src,
+ struct pipe_subresource subsrc,
+ unsigned x1, unsigned y1,
+ unsigned x2, unsigned y2,
+ float out[4])
+{
+ out[0] = x1 / (float)u_minify(src->width0, subsrc.level);
+ out[1] = y1 / (float)u_minify(src->height0, subsrc.level);
+ out[2] = x2 / (float)u_minify(src->width0, subsrc.level);
+ out[3] = y2 / (float)u_minify(src->height0, subsrc.level);
+}
+
+static void set_texcoords_in_vertices(const float coord[4],
+ float *out, unsigned stride)
+{
+ out[0] = coord[0]; /*t0.s*/
+ out[1] = coord[1]; /*t0.t*/
+ out += stride;
+ out[0] = coord[2]; /*t1.s*/
+ out[1] = coord[1]; /*t1.t*/
+ out += stride;
+ out[0] = coord[2]; /*t2.s*/
+ out[1] = coord[3]; /*t2.t*/
+ out += stride;
+ out[0] = coord[0]; /*t3.s*/
+ out[1] = coord[3]; /*t3.t*/
+}
+
static void blitter_set_texcoords_2d(struct blitter_context_priv *ctx,
struct pipe_resource *src,
struct pipe_subresource subsrc,
unsigned x1, unsigned y1,
unsigned x2, unsigned y2)
{
- int i;
- float s1 = x1 / (float)u_minify(src->width0, subsrc.level);
- float t1 = y1 / (float)u_minify(src->height0, subsrc.level);
- float s2 = x2 / (float)u_minify(src->width0, subsrc.level);
- float t2 = y2 / (float)u_minify(src->height0, subsrc.level);
-
- ctx->vertices[0][1][0] = s1; /*t0.s*/
- ctx->vertices[0][1][1] = t1; /*t0.t*/
-
- ctx->vertices[1][1][0] = s2; /*t1.s*/
- ctx->vertices[1][1][1] = t1; /*t1.t*/
-
- ctx->vertices[2][1][0] = s2; /*t2.s*/
- ctx->vertices[2][1][1] = t2; /*t2.t*/
+ unsigned i;
+ float coord[4];
- ctx->vertices[3][1][0] = s1; /*t3.s*/
- ctx->vertices[3][1][1] = t2; /*t3.t*/
+ get_normalized_texcoords(src, subsrc, x1, y1, x2, y2, coord);
+ set_texcoords_in_vertices(coord, &ctx->vertices[0][1][0], 8);
for (i = 0; i < 4; i++) {
ctx->vertices[i][1][2] = 0; /*r*/
@@ -456,20 +472,11 @@ static void blitter_set_texcoords_cube(struct blitter_context_priv *ctx,
unsigned x2, unsigned y2)
{
int i;
- float s1 = x1 / (float)u_minify(src->width0, subsrc.level);
- float t1 = y1 / (float)u_minify(src->height0, subsrc.level);
- float s2 = x2 / (float)u_minify(src->width0, subsrc.level);
- float t2 = y2 / (float)u_minify(src->height0, subsrc.level);
+ float coord[4];
float st[4][2];
- st[0][0] = s1;
- st[0][1] = t1;
- st[1][0] = s2;
- st[1][1] = t1;
- st[2][0] = s2;
- st[2][1] = t2;
- st[3][0] = s1;
- st[3][1] = t2;
+ get_normalized_texcoords(src, subsrc, x1, y1, x2, y2, coord);
+ set_texcoords_in_vertices(coord, &st[0][0], 2);
util_map_texcoords2d_onto_cubemap(subsrc.face,
/* pointer, stride in floats */