X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=src%2Fgis-opengl.c;h=a70c6a8ebb3e251fda82c3a24ab2b711a514d5af;hb=8dea961dcde28d572ebece717e2533737e3c2be2;hp=bb2095113d9830d2bc1ad874396b62a946136dea;hpb=cd2b3c70807c914687f9051b34a8fe029de300ee;p=grits diff --git a/src/gis-opengl.c b/src/gis-opengl.c index bb20951..a70c6a8 100644 --- a/src/gis-opengl.c +++ b/src/gis-opengl.c @@ -122,12 +122,10 @@ static void _set_visuals(GisOpenGL *opengl) /******************** * Object handleing * ********************/ -static void _draw_tile(GisOpenGL *opengl, GisTile *tile) +static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles) { if (!tile || !tile->data) return; - GList *triangles = roam_sphere_get_intersect(opengl->sphere, FALSE, - tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); if (!triangles) g_warning("GisOpenGL: _draw_tiles - No triangles to draw: edges=%f,%f,%f,%f", tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); @@ -191,18 +189,41 @@ static void _draw_tile(GisOpenGL *opengl, GisTile *tile) static void _draw_tiles(GisOpenGL *opengl, GisTile *tile) { /* Only draw children if possible */ - gboolean has_children = TRUE; + gboolean has_children = FALSE; GisTile *child; gis_tile_foreach(tile, child) - if (!child || !child->data) - has_children = FALSE; - if (has_children) - /* Only draw children */ - gis_tile_foreach(tile, child) - _draw_tiles(opengl, child); - else - /* No children, draw this tile */ - _draw_tile(opengl, tile); + if (child && child->data) + has_children = TRUE; + + GList *triangles = NULL; + if (has_children) { + /* TODO: simplify this */ + const gdouble rows = G_N_ELEMENTS(tile->children); + const gdouble cols = G_N_ELEMENTS(tile->children[0]); + const gdouble lat_dist = tile->edge.n - tile->edge.s; + const gdouble lon_dist = tile->edge.e - tile->edge.w; + const gdouble lat_step = lat_dist / rows; + const gdouble lon_step = lon_dist / cols; + int row, col; + gis_tile_foreach_index(tile, row, col) { + GisTile *child = tile->children[row][col]; + if (child && child->data) { + _draw_tiles(opengl, child); + } else { + const gdouble n = tile->edge.n-(lat_step*(row+0)); + const gdouble s = tile->edge.n-(lat_step*(row+1)); + const gdouble e = tile->edge.w+(lon_step*(col+1)); + const gdouble w = tile->edge.w+(lon_step*(col+0)); + GList *these = roam_sphere_get_intersect(opengl->sphere, FALSE, n, s, e, w); + triangles = g_list_concat(triangles, these); + } + } + } else { + triangles = roam_sphere_get_intersect(opengl->sphere, FALSE, + tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w); + } + if (triangles) + _draw_tile(opengl, tile, triangles); } static void _draw_marker(GisOpenGL *opengl, GisMarker *marker) @@ -212,6 +233,10 @@ static void _draw_marker(GisOpenGL *opengl, GisMarker *marker) gis_viewer_project(GIS_VIEWER(opengl), point->lat, point->lon, point->elev, &px, &py, &pz); + + gint win_width = GTK_WIDGET(opengl)->allocation.width; + gint win_height = GTK_WIDGET(opengl)->allocation.height; + py = win_height - py; if (pz > 1) return; @@ -223,8 +248,7 @@ static void _draw_marker(GisOpenGL *opengl, GisMarker *marker) glMatrixMode(GL_PROJECTION); glLoadIdentity(); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glOrtho(0, GTK_WIDGET(opengl)->allocation.width, - 0, GTK_WIDGET(opengl)->allocation.height, -1, 1); + glOrtho(0, win_width, win_height, 0, -1, 1); glTranslated(px - marker->xoff, py - marker->yoff, 0); @@ -233,11 +257,12 @@ static void _draw_marker(GisOpenGL *opengl, GisMarker *marker) glDisable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, marker->tex); + glDisable(GL_CULL_FACE); glBegin(GL_QUADS); - glTexCoord2f(1, 1); glVertex3f(width, 0 , 0); - glTexCoord2f(1, 0); glVertex3f(width, height, 0); - glTexCoord2f(0, 0); glVertex3f(0 , height, 0); - glTexCoord2f(0, 1); glVertex3f(0 , 0 , 0); + glTexCoord2f(1, 0); glVertex3f(width, 0 , 0); + glTexCoord2f(1, 1); glVertex3f(width, height, 0); + glTexCoord2f(0, 1); glVertex3f(0 , height, 0); + glTexCoord2f(0, 0); glVertex3f(0 , 0 , 0); glEnd(); } @@ -251,14 +276,23 @@ static void _draw_object(GisOpenGL *opengl, GisObject *object) //g_debug("GisOpenGL: draw_object"); /* Skip out of range objects */ if (object->lod > 0) { + /* LOD test */ gdouble eye[3], obj[3]; gis_viewer_get_location(GIS_VIEWER(opengl), &eye[0], &eye[1], &eye[2]); + gdouble elev = eye[2]; lle2xyz(eye[0], eye[1], eye[2], &eye[0], &eye[1], &eye[2]); lle2xyz(object->center.lat, object->center.lon, object->center.elev, &obj[0], &obj[1], &obj[2]); gdouble dist = distd(obj, eye); if (object->lod < dist) return; + + /* Horizon testing */ + gdouble c = EARTH_R+elev; + gdouble a = EARTH_R; + gdouble horizon = sqrt(c*c - a*a); + if (dist > horizon) + return; } /* Draw */ @@ -270,6 +304,8 @@ static void _draw_object(GisOpenGL *opengl, GisObject *object) } else if (GIS_IS_CALLBACK(object)) { _draw_callback(opengl, GIS_CALLBACK(object)); } else if (GIS_IS_TILE(object)) { + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); _draw_tiles(opengl, GIS_TILE(object)); } glPopAttrib(); @@ -321,21 +357,6 @@ struct RenderLevel { GList sorted; }; -static void on_realize(GisOpenGL *opengl, gpointer _) -{ - g_debug("GisOpenGL: on_realize"); - - GdkGLContext *glcontext = gtk_widget_get_gl_context(GTK_WIDGET(opengl)); - GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl)); - if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) - g_assert_not_reached(); - - _set_visuals(opengl); - g_mutex_lock(opengl->sphere_lock); - roam_sphere_update_errors(opengl->sphere); - g_mutex_unlock(opengl->sphere_lock); -} - static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpointer _) { g_debug("GisOpenGL: on_configure"); @@ -359,6 +380,19 @@ static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpoint return FALSE; } +static void on_realize(GisOpenGL *opengl, gpointer _) +{ + g_debug("GisOpenGL: on_realize"); + + GdkGLContext *glcontext = gtk_widget_get_gl_context(GTK_WIDGET(opengl)); + GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl)); + if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext)) + g_assert_not_reached(); + + _set_visuals(opengl); + on_configure(opengl, NULL, NULL); +} + static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data) { g_debug("GisOpenGL: _draw_level - level=%-4d", (int)key); @@ -441,9 +475,11 @@ static gboolean on_key_press(GisOpenGL *opengl, GdkEventKey *event, gpointer _) return FALSE; } -static gboolean _update_errors_cb(gpointer sphere) +static gboolean _update_errors_cb(gpointer _opengl) { - roam_sphere_update_errors(sphere); + GisOpenGL *opengl = _opengl; + roam_sphere_update_errors(opengl->sphere); + opengl->ue_source = 0; return FALSE; } static void on_view_changed(GisOpenGL *opengl, @@ -452,8 +488,9 @@ static void on_view_changed(GisOpenGL *opengl, g_debug("GisOpenGL: on_view_changed"); _set_visuals(opengl); #ifndef ROAM_DEBUG - opengl->ue_source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+30, - _update_errors_cb, opengl->sphere, NULL); + if (!opengl->ue_source) + opengl->ue_source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+30, + _update_errors_cb, opengl, NULL); //roam_sphere_update_errors(opengl->sphere); #endif }