Add:graphics_opengl:Option to use glu tesselator for opengles
authormartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 4 Mar 2012 20:37:07 +0000 (20:37 +0000)
committermartin-s <martin-s@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sun, 4 Mar 2012 20:37:07 +0000 (20:37 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@4967 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/graphics/opengl/graphics_opengl.c

index 46e9a6a..3397363 100644 (file)
 #include <GLES/gl.h>
 #include <GLES/egl.h>
 #endif
+#ifdef USE_GLUT_FOR_OPENGLES
+#define APIENTRY
+#define GLU_TESS_BEGIN                     100100
+#define GLU_TESS_VERTEX                    100101
+#define GLU_TESS_END                       100102
+#define GLU_TESS_COMBINE                   100105
+typedef struct GLUtesselator GLUtesselator;
+typedef double GLdouble;
+#endif
 #else
 #define glOrthof       glOrtho
 #undef USE_FLOAT
@@ -634,7 +643,61 @@ draw_image_es(struct graphics_priv *gr, struct point *p, int w, int h, unsigned
 }
 
 
-#else
+#endif
+
+static void
+get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
+{
+       if (gr->parent == NULL) {
+               point_out->x = 0;
+               point_out->y = 0;
+               return;
+       }
+       point_out->x = gr->p.x;
+       if (point_out->x < 0) {
+               point_out->x += gr->parent->width;
+       }
+
+       point_out->y = gr->p.y;
+       if (point_out->y < 0) {
+               point_out->y += gr->parent->height;
+       }
+}
+
+static void
+draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
+          struct point *p, int count)
+{
+       if ((gr->parent && !gr->parent->overlay_enabled)
+           || (gr->parent && gr->parent->overlay_enabled
+               && !gr->overlay_enabled)) {
+               return;
+       }
+#if !defined(USE_OPENGLES) || defined(USE_OPENGLES2)
+       glLineWidth(gc->linewidth);
+#endif
+       set_color(gr, gc);
+       graphics_priv_root->dirty = 1;
+
+#ifndef USE_OPENGLES
+       if (!gr->parent && 0 < gc->dash_count) {
+               glLineStipple(1, gc->dash_mask);
+               glEnable(GL_LINE_STIPPLE);
+       }
+#endif
+       draw_array(gr, p, count, GL_LINE_STRIP);
+#ifndef USE_OPENGLES
+       if (!gr->parent && 0 < gc->dash_count) {
+               glDisable(GL_LINE_STIPPLE);
+       }
+#endif
+}
+
+#if !defined(USE_OPENGLES) || defined(USE_GLUT_FOR_OPENGLES)
+static int tess_count;
+static struct point tess_array[512];
+static GLenum tess_type;
+
 const char *
 getPrimitiveType(GLenum type)
 {
@@ -678,9 +741,9 @@ getPrimitiveType(GLenum type)
 void APIENTRY
 tessBeginCB(GLenum which)
 {
-       glBegin(which);
-
        dbg(1, "glBegin( %s );\n", getPrimitiveType(which));
+       tess_type=which;
+       tess_count=0;
 }
 
 
@@ -688,9 +751,8 @@ tessBeginCB(GLenum which)
 void APIENTRY
 tessEndCB()
 {
-       glEnd();
-
        dbg(1, "glEnd();\n");
+       draw_array(graphics_priv_root, tess_array, tess_count, tess_type);
 }
 
 
@@ -700,63 +762,16 @@ tessVertexCB(const GLvoid * data)
 {
        // cast back to double type
        const GLdouble *ptr = (const GLdouble *) data;
-
-       glVertex3dv(ptr);
-
        dbg(1, "  glVertex3d();\n");
-}
-#endif
-
-static void
-get_overlay_pos(struct graphics_priv *gr, struct point *point_out)
-{
-       if (gr->parent == NULL) {
-               point_out->x = 0;
-               point_out->y = 0;
-               return;
-       }
-       point_out->x = gr->p.x;
-       if (point_out->x < 0) {
-               point_out->x += gr->parent->width;
-       }
-
-       point_out->y = gr->p.y;
-       if (point_out->y < 0) {
-               point_out->y += gr->parent->height;
-       }
-}
-
-static void
-draw_lines(struct graphics_priv *gr, struct graphics_gc_priv *gc,
-          struct point *p, int count)
-{
-       if ((gr->parent && !gr->parent->overlay_enabled)
-           || (gr->parent && gr->parent->overlay_enabled
-               && !gr->overlay_enabled)) {
-               return;
-       }
-#if !defined(USE_OPENGLES) || defined(USE_OPENGLES2)
-       glLineWidth(gc->linewidth);
-#endif
-       set_color(gr, gc);
-       graphics_priv_root->dirty = 1;
 
-#ifndef USE_OPENGLES
-       if (!gr->parent && 0 < gc->dash_count) {
-               glLineStipple(1, gc->dash_mask);
-               glEnable(GL_LINE_STIPPLE);
-       }
-#endif
-       draw_array(gr, p, count, GL_LINE_STRIP);
-#ifndef USE_OPENGLES
-       if (!gr->parent && 0 < gc->dash_count) {
-               glDisable(GL_LINE_STIPPLE);
-       }
-#endif
+       tess_array[tess_count].x=ptr[0];
+       tess_array[tess_count].y=ptr[1];
+       if (tess_count < 511)
+               tess_count++;
+       else
+               dbg(0,"overflow\n");
 }
 
-#ifdef USE_OPENGLES
-#else
 void APIENTRY
 tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
 {
@@ -766,6 +781,7 @@ tessCombineCB(GLdouble c[3], void *d[4], GLfloat w[4], void **out)
        nv[2] = c[2];
        *out = nv;
 }
+
 #endif
 
 
@@ -778,11 +794,11 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
                && !gr->overlay_enabled)) {
                return;
        }
-#ifdef USE_OPENGLES
        set_color(gr, gc);
+       graphics_priv_root->dirty = 1;
+#if defined(USE_OPENGLES) && !defined(USE_GLUT_FOR_OPENGLES)
        draw_array(gr, p, count, GL_LINE_STRIP);
 #else
-       graphics_priv_root->dirty = 1;
 
        GLUtesselator *tess = gluNewTess();     // create a tessellator
        if (!tess)
@@ -813,7 +829,6 @@ draw_polygon(struct graphics_priv *gr, struct graphics_gc_priv *gc,
        // and UV coords which are needed for actual drawing.
        // Here, we are looking at only vertex coods, so the 2nd and 3rd params are
        // pointing same address.
-       glColor4f(gc->fr, gc->fg, gc->fb, gc->fa);
        gluTessBeginPolygon(tess, 0);   // with NULL data
        gluTessBeginContour(tess);
        for (i = 0; i < count; i++) {