[cairo-commit] libglc/src glc.c,1.7,1.8 glc_util.c,1.2,1.3 glcint.h,1.6,1.7
Peter Nilsson
commit at pdx.freedesktop.org
Fri Dec 5 07:22:18 PST 2003
Committed by: peter
Update of /cvs/cairo/libglc/src
In directory pdx:/tmp/cvs-serv9713/src
Modified Files:
glc.c glc_util.c glcint.h
Log Message:
Added support for combined repeat and transformations
Index: glc.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** glc.c 4 Dec 2003 19:18:08 -0000 1.7
--- glc.c 5 Dec 2003 15:22:16 -0000 1.8
***************
*** 101,105 ****
double tx1, tx2, ty1, ty2;
glc_point_t tl, bl, br, tr;
! glc_region_box_t ibounds;
int x_draw_offset = 0, y_draw_offset = 0;
--- 101,105 ----
double tx1, tx2, ty1, ty2;
glc_point_t tl, bl, br, tr;
! glc_region_box_t ibounds, clip;
int x_draw_offset = 0, y_draw_offset = 0;
***************
*** 236,353 ****
break;
}
! glScissor (x_dst, dst->height - (y_dst + height), width, height);
glColorMask (src->red, src->green, src->blue, src->alpha);
glc_set_operator (op);
!
! if (src->repeat && (!src->disable_transform_and_repeat)) {
! /* Source should be repeated. */
!
! if (texture_width == src->width && texture_height == src->height) {
! /* CASE 1: Repeat and power of two sized texture, GL can do repeat
! for us. */
! double repeat_factor_x, repeat_factor_y;
! glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
! glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
! bl.x = tl.x = x_dst;
! tr.y = tl.y = y_dst;
! tr.x = br.x = x_dst + width;
! bl.y = br.y = y_dst + height;
!
! /* Shift coordinates with source offset */
! if (x_src) {
! tl.x -= x_src;
! bl.x -= x_src;
! }
! if (y_src) {
! tl.y -= y_src;
! tr.y -= y_src;
! }
! /* Align with top left edge */
! bl.y += texture_height - (((int) (br.y - tl.y)) % texture_height);
! br.y += texture_height - (((int) (br.y - tl.y)) % texture_height);
!
! repeat_factor_x = (br.x - tl.x) / (double) texture_width;
! repeat_factor_y = (br.y - tl.y) / (double) texture_height;
!
! tx1 = ty1 = 0.0;
! tx2 = repeat_factor_x;
! ty2 = repeat_factor_y;
! glBegin (GL_QUADS);
! glTexCoord2d (tx1, ty2);
! glVertex2d (x_draw_offset + tl.x, y_draw_offset + tl.y);
! glTexCoord2d (tx2, ty2);
! glVertex2d (x_draw_offset + tr.x, y_draw_offset + tr.y);
! glTexCoord2d (tx2, ty1);
! glVertex2d (x_draw_offset + br.x, y_draw_offset + br.y);
! glTexCoord2d (tx1, ty1);
! glVertex2d (x_draw_offset + bl.x, y_draw_offset + bl.y);
! glEnd ();
! } else {
! /* CASE 2: Repeat and not power of two sized texture, manual repeat
! must be done. */
! int tx1i, tx2i, ty1i, ty2i;
!
! glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
! glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
!
! tx1i = 0;
! ty2i = texture_height;
! tx2i = src->width;
! ty1i = texture_height - src->height;
!
! /* Normalizing texture coordinates */
! tx1 = (double) tx1i / (double) src->width;
! ty1 = (double) ty1i / (double) src->height;
! tx2 = (double) tx2i / (double) src->width;
! ty2 = (double) ty2i / (double) src->height;
! /* Scale texture coordinates to real texture size */
! tx1 *= width_factor;
! tx2 *= width_factor;
! ty1 *= height_factor;
! ty2 *= height_factor;
!
! tr.y = tl.y = y_dst - y_src;
! bl.y = br.y = y_dst + src->height - y_src;
- while (tl.y < (y_dst + height)) {
- bl.x = tl.x = x_dst - x_src;
- tr.x = br.x = x_dst + src->width - x_src;
-
- while (tl.x < (x_dst + width)) {
- glBegin (GL_QUADS);
- glTexCoord2d (tx1, ty2);
- glVertex2d (x_draw_offset + tl.x, y_draw_offset + tl.y);
- glTexCoord2d (tx2, ty2);
- glVertex2d (x_draw_offset + tr.x, y_draw_offset + tr.y);
- glTexCoord2d (tx2, ty1);
- glVertex2d (x_draw_offset + br.x, y_draw_offset + br.y);
- glTexCoord2d (tx1, ty1);
- glVertex2d (x_draw_offset + bl.x, y_draw_offset + bl.y);
- glEnd ();
-
- bl.x += src->width;
- tl.x += src->width;
- tr.x += src->width;
- br.x += src->width;
- }
-
- bl.y += src->height;
- tl.y += src->height;
- tr.y += src->height;
- br.y += src->height;
- }
- }
} else {
! /* CASE 3: No repeat. Transformation should be used if set. */
int tx1i, tx2i, ty1i, ty2i;
!
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
--- 236,303 ----
break;
}
!
! clip.x1 = x_dst;
! clip.y1 = y_dst;
! clip.x2 = clip.x1 + width;
! clip.y2 = clip.y1 + height;
!
! glScissor (clip.x1, dst->height - (clip.y1 + height),
! clip.x2 - clip.x1, clip.y2 - clip.y1);
glColorMask (src->red, src->green, src->blue, src->alpha);
glc_set_operator (op);
!
! if ((!src->transform) &&
! (!src->disable_transform_and_repeat) && src->repeat &&
! texture_width == src->width && texture_height == src->height) {
! /* CASE 1: Repeat, no transformation and power of two sized texture,
! GL can do repeat for us. */
! double repeat_factor_x, repeat_factor_y;
! glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
! glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
! bl.x = tl.x = x_dst;
! tr.y = tl.y = y_dst;
! tr.x = br.x = x_dst + width;
! bl.y = br.y = y_dst + height;
! /* Shift coordinates with source offset */
! if (x_src) {
! tl.x -= x_src;
! bl.x -= x_src;
! }
! if (y_src) {
! tl.y -= y_src;
! tr.y -= y_src;
! }
! /* Align with top left edge */
! bl.y += texture_height - (((int) (br.y - tl.y)) % texture_height);
! br.y += texture_height - (((int) (br.y - tl.y)) % texture_height);
! repeat_factor_x = (br.x - tl.x) / (double) texture_width;
! repeat_factor_y = (br.y - tl.y) / (double) texture_height;
! tx1 = ty1 = 0.0;
! tx2 = repeat_factor_x;
! ty2 = repeat_factor_y;
! glBegin (GL_QUADS);
! glTexCoord2d (tx1, ty2);
! glVertex2d (x_draw_offset + tl.x, y_draw_offset + tl.y);
! glTexCoord2d (tx2, ty2);
! glVertex2d (x_draw_offset + tr.x, y_draw_offset + tr.y);
! glTexCoord2d (tx2, ty1);
! glVertex2d (x_draw_offset + br.x, y_draw_offset + br.y);
! glTexCoord2d (tx1, ty1);
! glVertex2d (x_draw_offset + bl.x, y_draw_offset + bl.y);
! glEnd ();
} else {
! /* CASE 2: Either none power of two sized texture or transformation is set. */
int tx1i, tx2i, ty1i, ty2i;
! double save_tlx, save_trx, save_blx, save_brx;
!
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
***************
*** 413,429 ****
ty1 *= height_factor;
ty2 *= height_factor;
!
! glBegin (GL_QUADS);
! glTexCoord2d (tx1, ty2);
! glVertex2d (x_draw_offset + tl.x, y_draw_offset + tl.y);
! glTexCoord2d (tx2, ty2);
! glVertex2d (x_draw_offset + tr.x, y_draw_offset + tr.y);
! glTexCoord2d (tx2, ty1);
! glVertex2d (x_draw_offset + br.x, y_draw_offset + br.y);
! glTexCoord2d (tx1, ty1);
! glVertex2d (x_draw_offset + bl.x, y_draw_offset + bl.y);
! glEnd ();
! }
glDisable (GL_TEXTURE_2D);
--- 363,425 ----
ty1 *= height_factor;
ty2 *= height_factor;
!
! save_tlx = tl.x;
! save_blx = bl.x;
! save_trx = tr.x;
! save_brx = br.x;
!
! do {
! do {
! /* Clip to original source area if repeat and transform are both used. */
! if ((!src->disable_transform_and_repeat) && src->transform && src->repeat) {
! glc_region_box_t src_clip, intersect_clip;
!
! src_clip.x1 = x_draw_offset + tl.x;
! src_clip.y1 = y_draw_offset + tl.y;
! src_clip.x2 = src_clip.x1 + src->width;
! src_clip.y2 = src_clip.y1 + src->height;
!
! glc_intersect_region (&clip, &src_clip, &intersect_clip);
!
! glScissor (intersect_clip.x1,
! dst->height -
! (intersect_clip.y1 + (intersect_clip.y2 - intersect_clip.y1)),
! intersect_clip.x2 - intersect_clip.x1,
! intersect_clip.y2 - intersect_clip.y1);
! }
!
! glBegin (GL_QUADS);
! glTexCoord2d (tx1, ty2);
! glVertex2d (x_draw_offset + tl.x, y_draw_offset + tl.y);
! glTexCoord2d (tx2, ty2);
! glVertex2d (x_draw_offset + tr.x, y_draw_offset + tr.y);
! glTexCoord2d (tx2, ty1);
! glVertex2d (x_draw_offset + br.x, y_draw_offset + br.y);
! glTexCoord2d (tx1, ty1);
! glVertex2d (x_draw_offset + bl.x, y_draw_offset + bl.y);
! glEnd ();
!
! bl.x += src->width;
! tl.x += src->width;
! tr.x += src->width;
! br.x += src->width;
!
! } while ((!src->disable_transform_and_repeat) && src->repeat &&
! (tl.x < (x_dst + width)));
!
! bl.y += src->height;
! tl.y += src->height;
! tr.y += src->height;
! br.y += src->height;
+ tl.x = save_tlx;
+ bl.x = save_blx;
+ tr.x = save_trx;
+ br.x = save_brx;
+
+ } while ((!src->disable_transform_and_repeat) && src->repeat &&
+ (tl.y < (y_dst + height)));
+ }
+
glDisable (GL_TEXTURE_2D);
Index: glc_util.c
===================================================================
RCS file: /cvs/cairo/libglc/src/glc_util.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** glc_util.c 3 Dec 2003 16:55:50 -0000 1.2
--- glc_util.c 5 Dec 2003 15:22:16 -0000 1.3
***************
*** 62,63 ****
--- 62,81 ----
*y_draw_offset = (ibounds->y1 > 0)? -ibounds->y1: 0;
}
+
+ void
+ glc_intersect_region (glc_region_box_t *box1,
+ glc_region_box_t *box2,
+ glc_region_box_t *return_box)
+ {
+ return_box->x1 = (box1->x1 >= box2->x1)? box1->x1: box2->x1;
+ return_box->x2 = (box1->x2 <= box2->x2)? box1->x2: box2->x2;
+ return_box->y1 = (box1->y1 >= box2->y1)? box1->y1: box2->y1;
+ return_box->y2 = (box1->y2 <= box2->y2)? box1->y2: box2->y2;
+
+ if (return_box->x1 >= return_box->x2)
+ return_box->x1 = return_box->x2 = 0;
+
+ if (return_box->y1 >= return_box->y2)
+ return_box->y1 = return_box->y2 = 0;
+ }
+
Index: glcint.h
===================================================================
RCS file: /cvs/cairo/libglc/src/glcint.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** glcint.h 5 Dec 2003 01:55:31 -0000 1.6
--- glcint.h 5 Dec 2003 15:22:16 -0000 1.7
***************
*** 112,115 ****
--- 112,120 ----
int *y_draw_offset);
+ extern void __internal_linkage
+ glc_intersect_region (glc_region_box_t *box1,
+ glc_region_box_t *box2,
+ glc_region_box_t *return_box);
+
extern GLuint __internal_linkage
glc_texture_create (int width,
More information about the cairo-commit
mailing list