attempts at making polys work all over - gl engine has problems though...

this is due to gl not handling complex (non convex) polys and glu's tesselator
doesnt work... for some reason...

well just need to make imlib2's polys anti-alias and that will get some handled
I need to fix the line rendering so it handles being clipped better.


SVN revision: 3575
This commit is contained in:
Carsten Haitzler 2000-10-12 13:57:49 +00:00
parent 53b3a6face
commit 46b738ad78
3 changed files with 400 additions and 0 deletions

View File

@ -2178,8 +2178,55 @@ __evas_gl_gradient_draw(Evas_GL_Graident *gr,
/* something is wrong here - GL experts? the polys dont get tesselated */
/* correctly */
/*
#ifdef HAVE_GLU
static void
__evas_gl_tess_begin_cb(GLenum which)
{
glBegin(which);
}
static void
__evas_gl_tess_end_cb(void)
{
glEnd();
}
static void
__evas_gl_tess_error_cb(GLenum errorcode)
{
}
static void
__evas_gl_tess_vertex_cb(GLvoid *vertex)
{
glVertex2dv(vertex);
}
static void
__evas_gl_tess_combine_cb(GLdouble coords[3],
GLdouble *vertex_data[4],
GLfloat weight[4], GLdouble **data_out)
{
GLdouble *vertex;
int i;
vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
vertex[0] = coords[0];
vertex[1] = coords[1];
vertex[2] = coords[2];
for (i = 3; i < 6; i++)
vertex[i] =
weight[0] * vertex_data[0][i] +
weight[1] * vertex_data[1][i] +
weight[2] * vertex_data[2][i] +
weight[3] * vertex_data[3][i];
*data_out = vertex;
}
#endif
*/
/************/
/* polygons */
@ -2190,6 +2237,94 @@ __evas_gl_poly_draw (Display *disp, Imlib_Image dstim, Window win,
Evas_List points,
int r, int g, int b, int a)
{
Evas_List l2;
float rr, gg, bb, aa;
static int dest_w = 0, dest_h = 0;
if ((__evas_current_win != win) || (__evas_current_disp != disp))
{
glXMakeCurrent(disp, win, __evas_gl_cx);
__evas_current_disp = disp;
__evas_current_win = win;
}
rr = (float)r / 255;
gg = (float)g / 255;
bb = (float)b / 255;
aa = (float)a / 255;
glColor4f(rr, gg, bb, aa);
glViewport(0, 0, win_w, win_h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, win_w, 0, win_h, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glScalef(1, -1, 1);
glTranslatef(0, -win_h, 0);
dest_w = win_w;
dest_h = win_h;
if (a < 255)
{
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
else
glDisable(GL_BLEND);
glEnable(GL_DITHER);
glDisable(GL_TEXTURE_2D);
glShadeModel(GL_FLAT);
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
/*
#ifdef HAVE_GLU
{
static void *tess = NULL;
if (!tess)
{
tess = gluNewTess();
gluTessCallback(tess, GLU_TESS_BEGIN, __evas_gl_tess_begin_cb);
gluTessCallback(tess, GLU_TESS_END, __evas_gl_tess_end_cb);
gluTessCallback(tess, GLU_TESS_ERROR, __evas_gl_tess_error_cb);
gluTessCallback(tess, GLU_TESS_VERTEX, __evas_gl_tess_vertex_cb);
gluTessCallback(tess, GLU_TESS_COMBINE, __evas_gl_tess_combine_cb);
gluTessProperty(tess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_ODD);
}
gluTessBeginPolygon(tess, NULL);
gluTessBeginContour(tess);
for (l2 = points; l2; l2 = l2->next)
{
Evas_Point p;
GLdouble glp[3];
p = l2->data;
glp[0] = p->x;
glp[1] = p->y;
glp[2] = 0;
gluTessVertex(tess, glp, glp);
}
gluTessEndContour(tess);
gluTessEndPolygon(tess);
}
#else
*/
/*
#warning "You do not have GLU and thus polygons that are not convex will not"
#warning "render correctly."
*/
glBegin(GL_POLYGON);
for (l2 = points; l2; l2 = l2->next)
{
Evas_Point p;
p = l2->data;
glVertex2d(p->x, p->y);
}
glEnd();
/*#endif*/
glEnable(GL_TEXTURE_2D);
}

View File

@ -692,6 +692,102 @@ __evas_image_poly_draw (Display *disp, Imlib_Image dstim, Window win,
Evas_List points,
int r, int g, int b, int a)
{
Evas_List l, l2;
int x, y, w, h;
imlib_context_set_color(r, g, b, a);
imlib_context_set_angle(0.0);
imlib_context_set_operation(IMLIB_OP_COPY);
imlib_context_set_color_modifier(NULL);
imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);
imlib_context_set_anti_alias(1);
imlib_context_set_blend(1);
x = y = w = h = 0;
if (points)
{
Evas_Point p;
p = points->data;
x = p->x;
y = p->y;
w = 1;
h = 1;
}
for (l2 = points; l2; l2 = l2->next)
{
Evas_Point p;
p = l2->data;
if (p->x < x)
{
w += x - p->x;
x = p->x;
}
if (p->x > (x + w))
w = p->x - x;
if (p->y < y)
{
h += y - p->y;
y = p->y;
}
if (p->y > (y + h))
h = p->y - y;
}
for(l = drawable_list; l; l = l->next)
{
Evas_Image_Drawable *dr;
dr = l->data;
if ((dr->im == dstim) && (dr->disp == disp))
{
Evas_List ll;
for (ll = dr->tmp_images; ll; ll = ll->next)
{
Evas_Image_Update *up;
up = ll->data;
/* if image intersects image update - render */
if (RECTS_INTERSECT(up->x, up->y, up->w, up->h,
x, y, w, h))
{
ImlibPolygon pol;
if (!up->image)
{
DATA32 *data;
up->image = imlib_create_image(up->w, up->h);
if (up->image)
{
imlib_context_set_image(up->image);
data = imlib_image_get_data();
memset(data, 0, up->w * up->h * sizeof(DATA32));
imlib_image_put_back_data(data);
imlib_image_set_has_alpha(1);
}
}
if (up->image)
{
imlib_context_set_image(up->image);
pol = imlib_polygon_new();
for (l2 = points; l2; l2 = l2->next)
{
Evas_Point p;
p = l2->data;
imlib_polygon_add_point(pol, p->x - up->x, p->y - up->y);
}
imlib_image_fill_polygon(pol);
imlib_polygon_free(pol);
}
}
}
}
}
}

View File

@ -816,6 +816,175 @@ __evas_x11_poly_draw (Display *disp, Imlib_Image dstim, Window win,
Evas_List points,
int r, int g, int b, int a)
{
Evas_List l, l2;
DATA32 pixel;
Imlib_Image im = NULL;
Pixmap pmap = 0, mask = 0, s_mask = 0;
int x, y, w, h;
imlib_context_set_color(r, g, b, a);
imlib_context_set_display(disp);
imlib_context_set_visual(__evas_visual);
imlib_context_set_colormap(__evas_cmap);
imlib_context_set_drawable(win);
imlib_context_set_dither_mask(1);
imlib_context_set_anti_alias(0);
imlib_context_set_dither(1);
imlib_context_set_blend(0);
imlib_context_set_angle(0.0);
imlib_context_set_operation(IMLIB_OP_COPY);
imlib_context_set_direction(IMLIB_TEXT_TO_RIGHT);
imlib_context_set_color_modifier(NULL);
x = y = w = h = 0;
if (points)
{
Evas_Point p;
p = points->data;
x = p->x;
y = p->y;
w = 1;
h = 1;
}
for (l2 = points; l2; l2 = l2->next)
{
Evas_Point p;
p = l2->data;
if (p->x < x)
{
w += x - p->x;
x = p->x;
}
if (p->x > (x + w))
w = p->x - x;
if (p->y < y)
{
h += y - p->y;
y = p->y;
}
if (p->y > (y + h))
h = p->y - y;
}
for(l = drawable_list; l; l = l->next)
{
Evas_X11_Drawable *dr;
dr = l->data;
if ((dr->win == win) && (dr->disp == disp))
{
Evas_List ll;
for (ll = dr->tmp_images; ll; ll = ll->next)
{
Evas_X11_Update *up;
up = ll->data;
/* if image intersects image update - render */
if (RECTS_INTERSECT(up->x, up->y, up->w, up->h,
x, y, w, h))
{
if (!up->p)
up->p = XCreatePixmap(disp, win, up->w, up->h, dr->depth);
if (!im)
{
pixel = (a << 24) | (r << 16) | (g << 8) | b;
im = imlib_create_image_using_data(1, 1, &pixel);
imlib_context_set_image(im);
if (a < 255) imlib_image_set_has_alpha(1);
if (!pmap)
imlib_render_pixmaps_for_whole_image_at_size(&pmap, &mask,
32, 32);
}
if (a < 255)
{
if (mask)
{
int xx, yy, ww, hh, x1, y1, xs, ys;
GC gc;
XGCValues gcv;
xx = x - up->x;
yy = y - up->y;
ww = w;
hh = h;
CLIP(xx, yy, ww, hh, 0, 0, up->w, up->h);
s_mask = XCreatePixmap(disp, win, ww, hh, 1);
gc = XCreateGC(disp, s_mask, 0, &gcv);
xs = (x - up->x) % 32;
if (xs > 0) xs = 0;
else
{
while (xs < 0) xs += 32;
xs -= 32;
}
ys = (y - up->y) % 32;
if (ys > 0) ys = 0;
else
{
while (ys < 0) ys += 32;
ys -= 32;
}
for (y1 = ys; y1 < hh; y1 += 32)
{
for (x1 = xs; x1 < ww; x1 += 32)
XCopyArea(disp, mask, s_mask, gc,
0, 0, 32, 32,
x1, y1);
}
XSetClipMask(disp, dr->gc, s_mask);
XSetClipOrigin(disp, dr->gc, xx, yy);
XFreeGC(disp, gc);
}
else
{
XSetClipMask(disp, dr->gc, None);
}
}
if (pmap)
{
XSetFillStyle(disp, dr->gc, FillTiled);
XSetTile(disp, dr->gc, pmap);
XSetTSOrigin(disp, dr->gc, x - up->x, y - up->y);
}
else
{
XSetFillStyle(disp, dr->gc, FillSolid);
XSetTile(disp, dr->gc, None);
}
{
XPoint *xpoints;
int point_count, i;
point_count = 0;
for (l2 = points; l2; l2 = l2->next) point_count++;
xpoints = malloc(point_count * sizeof(XPoint));
for (l2 = points, i = 0; l2; l2 = l2->next, i++)
{
Evas_Point p;
p = l2->data;
xpoints[i].x = p->x - up->x;
xpoints[i].y = p->y - up->y;
}
XFillPolygon(disp, up->p, dr->gc, xpoints,
point_count, Complex, CoordModeOrigin);
free(xpoints);
}
if (s_mask) XFreePixmap(disp, s_mask);
s_mask = 0;
}
}
}
}
if (pmap) imlib_free_pixmap_and_mask(pmap);
if (im)
{
imlib_context_set_image(im);
imlib_free_image();
}
}