]> Pileus Git - grits/blobdiff - src/grits-opengl.c
libgis -> grits: Update functions/types/etc
[grits] / src / grits-opengl.c
index 6112fa08952b173dcaa90ca6ffa83882f760a422..05af312759ab97186d4ba5e1b6bf4fcba16145e6 100644 (file)
  */
 
 /**
- * SECTION:gis-opengl
+ * SECTION:grits-opengl
  * @short_description: OpenGL based virtual globe
  *
- * #GisOpenGL is the core rendering engine used by grits. Theoretically other
- * renderers could be writte, but they have not been. GisOpenGL uses the ROAM
- * algorithm for updating surface mesh the planet. The only thing GisOpenGL can
- * actually render on it's own is a wireframe of a sphere.
+ * #GritsOpenGL is the core rendering engine used by grits. Theoretically other
+ * renderers could be writte, but they have not been. GritsOpenGL uses the ROAM
+ * algorithm for updating surface mesh the planet. The only thing GritsOpenGL
+ * can actually render on it's own is a wireframe of a sphere.
  *
- * GisOpenGL relies on #GtkGlExt and requires (at least) OpenGL 2.0.
+ * GritsOpenGL relies on #GtkGlExt and requires (at least) OpenGL 2.0.
  */
 
 #include <config.h>
 /***********
  * Helpers *
  ***********/
-static void _set_visuals(GisOpenGL *opengl)
+static void _set_visuals(GritsOpenGL *opengl)
 {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
 
        /* Camera 1 */
        double lat, lon, elev, rx, ry, rz;
-       gis_viewer_get_location(GIS_VIEWER(opengl), &lat, &lon, &elev);
-       gis_viewer_get_rotation(GIS_VIEWER(opengl), &rx, &ry, &rz);
+       grits_viewer_get_location(GRITS_VIEWER(opengl), &lat, &lon, &elev);
+       grits_viewer_get_rotation(GRITS_VIEWER(opengl), &rx, &ry, &rz);
        glRotatef(rx, 1, 0, 0);
        glRotatef(rz, 0, 0, 1);
 
@@ -124,12 +124,12 @@ static void _set_visuals(GisOpenGL *opengl)
 /********************
  * Object handleing *
  ********************/
-static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles)
+static void _draw_tile(GritsOpenGL *opengl, GritsTile *tile, GList *triangles)
 {
        if (!tile || !tile->data)
                return;
        if (!triangles)
-               g_warning("GisOpenGL: _draw_tiles - No triangles to draw: edges=%f,%f,%f,%f",
+               g_warning("GritsOpenGL: _draw_tiles - No triangles to draw: edges=%f,%f,%f,%f",
                        tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
        //g_message("drawing %4d triangles for tile edges=%7.2f,%7.2f,%7.2f,%7.2f",
        //              g_list_length(triangles), tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
@@ -198,12 +198,12 @@ static void _draw_tile(GisOpenGL *opengl, GisTile *tile, GList *triangles)
        }
 }
 
-static void _draw_tiles(GisOpenGL *opengl, GisTile *tile)
+static void _draw_tiles(GritsOpenGL *opengl, GritsTile *tile)
 {
        /* Only draw children if possible */
        gboolean has_children = FALSE;
-       GisTile *child;
-       gis_tile_foreach(tile, child)
+       GritsTile *child;
+       grits_tile_foreach(tile, child)
                if (child && child->data)
                        has_children = TRUE;
 
@@ -217,8 +217,8 @@ static void _draw_tiles(GisOpenGL *opengl, GisTile *tile)
                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];
+               grits_tile_foreach_index(tile, row, col) {
+                       GritsTile *child = tile->children[row][col];
                        if (child && child->data) {
                                _draw_tiles(opengl, child);
                        } else {
@@ -240,11 +240,11 @@ static void _draw_tiles(GisOpenGL *opengl, GisTile *tile)
        g_list_free(triangles);
 }
 
-static void _draw_marker(GisOpenGL *opengl, GisMarker *marker)
+static void _draw_marker(GritsOpenGL *opengl, GritsMarker *marker)
 {
-       GisPoint *point = gis_object_center(marker);
+       GritsPoint *point = grits_object_center(marker);
        gdouble px, py, pz;
-       gis_viewer_project(GIS_VIEWER(opengl),
+       grits_viewer_project(GRITS_VIEWER(opengl),
                        point->lat, point->lon, point->elev,
                        &px, &py, &pz);
 
@@ -254,7 +254,7 @@ static void _draw_marker(GisOpenGL *opengl, GisMarker *marker)
        if (pz > 1)
                return;
 
-       //g_debug("GisOpenGL: draw_marker - %s pz=%f ", marker->label, pz);
+       //g_debug("GritsOpenGL: draw_marker - %s pz=%f ", marker->label, pz);
 
        cairo_surface_t *surface = cairo_get_target(marker->cairo);
        gdouble width  = cairo_image_surface_get_width(surface);
@@ -280,14 +280,14 @@ static void _draw_marker(GisOpenGL *opengl, GisMarker *marker)
        glEnd();
 }
 
-static void _draw_callback(GisOpenGL *opengl, GisCallback *callback)
+static void _draw_callback(GritsOpenGL *opengl, GritsCallback *callback)
 {
        callback->callback(callback, callback->user_data);
 }
 
-static void _draw_object(GisOpenGL *opengl, GisObject *object)
+static void _draw_object(GritsOpenGL *opengl, GritsObject *object)
 {
-       //g_debug("GisOpenGL: draw_object");
+       //g_debug("GritsOpenGL: draw_object");
        /* Skip hidden objects */
        if (object->hidden)
                return;
@@ -296,7 +296,7 @@ static void _draw_object(GisOpenGL *opengl, GisObject *object)
        if (object->lod > 0) {
                /* LOD test */
                gdouble eye[3], obj[3];
-               gis_viewer_get_location(GIS_VIEWER(opengl), &eye[0], &eye[1], &eye[2]);
+               grits_viewer_get_location(GRITS_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,
@@ -317,15 +317,15 @@ static void _draw_object(GisOpenGL *opengl, GisObject *object)
        glMatrixMode(GL_PROJECTION); glPushMatrix();
        glMatrixMode(GL_MODELVIEW);  glPushMatrix();
        glPushAttrib(GL_ALL_ATTRIB_BITS);
-       if (GIS_IS_MARKER(object)) {
-               _draw_marker(opengl, GIS_MARKER(object));
-       } else if (GIS_IS_CALLBACK(object)) {
-               _draw_callback(opengl, GIS_CALLBACK(object));
-       } else if (GIS_IS_TILE(object)) {
+       if (GRITS_IS_MARKER(object)) {
+               _draw_marker(opengl, GRITS_MARKER(object));
+       } else if (GRITS_IS_CALLBACK(object)) {
+               _draw_callback(opengl, GRITS_CALLBACK(object));
+       } else if (GRITS_IS_TILE(object)) {
                glEnable(GL_DEPTH_TEST);
                glDepthFunc(GL_LESS);
                g_mutex_lock(opengl->sphere_lock);
-               _draw_tiles(opengl, GIS_TILE(object));
+               _draw_tiles(opengl, GRITS_TILE(object));
                g_mutex_unlock(opengl->sphere_lock);
        }
        glPopAttrib();
@@ -333,11 +333,11 @@ static void _draw_object(GisOpenGL *opengl, GisObject *object)
        glMatrixMode(GL_MODELVIEW);  glPopMatrix();
 }
 
-static void _load_object(GisOpenGL *opengl, GisObject *object)
+static void _load_object(GritsOpenGL *opengl, GritsObject *object)
 {
-       //g_debug("GisOpenGL: load_object");
-       if (GIS_IS_MARKER(object)) {
-               GisMarker *marker = GIS_MARKER(object);
+       //g_debug("GritsOpenGL: load_object");
+       if (GRITS_IS_MARKER(object)) {
+               GritsMarker *marker = GRITS_MARKER(object);
                cairo_surface_t *surface = cairo_get_target(marker->cairo);
                gdouble width  = cairo_image_surface_get_width(surface);
                gdouble height = cairo_image_surface_get_height(surface);
@@ -356,11 +356,11 @@ static void _load_object(GisOpenGL *opengl, GisObject *object)
        }
 }
 
-static void _unload_object(GisOpenGL *opengl, GisObject *object)
+static void _unload_object(GritsOpenGL *opengl, GritsObject *object)
 {
-       //g_debug("GisOpenGL: unload_object");
-       if (GIS_IS_MARKER(object)) {
-               GisMarker *marker = GIS_MARKER(object);
+       //g_debug("GritsOpenGL: unload_object");
+       if (GRITS_IS_MARKER(object)) {
+               GritsMarker *marker = GRITS_MARKER(object);
                glDeleteTextures(1, &marker->tex);
        }
 }
@@ -377,9 +377,9 @@ struct RenderLevel {
        GList sorted;
 };
 
-static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpointer _)
+static gboolean on_configure(GritsOpenGL *opengl, GdkEventConfigure *event, gpointer _)
 {
-       g_debug("GisOpenGL: on_configure");
+       g_debug("GritsOpenGL: on_configure");
 
        /* wait for "realize" */
        if (!gdk_gl_context_get_current())
@@ -404,9 +404,9 @@ static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpoint
        return FALSE;
 }
 
-static void on_realize(GisOpenGL *opengl, gpointer _)
+static void on_realize(GritsOpenGL *opengl, gpointer _)
 {
-       g_debug("GisOpenGL: on_realize");
+       g_debug("GritsOpenGL: on_realize");
 
        GdkGLContext   *glcontext  = gtk_widget_get_gl_context(GTK_WIDGET(opengl));
        GdkGLDrawable  *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl));
@@ -419,8 +419,8 @@ static void on_realize(GisOpenGL *opengl, gpointer _)
 
 static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
 {
-       g_debug("GisOpenGL: _draw_level - level=%-4d", (int)key);
-       GisOpenGL *opengl = user_data;
+       g_debug("GritsOpenGL: _draw_level - level=%-4d", (int)key);
+       GritsOpenGL *opengl = user_data;
        struct RenderLevel *level = value;
        int nsorted = 0, nunsorted = 0;
        GList *cur = NULL;
@@ -429,25 +429,25 @@ static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
        glDepthMask(TRUE);
        glClear(GL_DEPTH_BUFFER_BIT);
        for (cur = level->unsorted.next; cur; cur = cur->next, nunsorted++)
-               _draw_object(opengl, GIS_OBJECT(cur->data));
+               _draw_object(opengl, GRITS_OBJECT(cur->data));
 
        /* Freeze depth buffer and draw transparent objects sorted */
        /* TODO: sorting */
        //glDepthMask(FALSE);
        glAlphaFunc(GL_GREATER, 0.1);
        for (cur = level->sorted.next; cur; cur = cur->next, nsorted++)
-               _draw_object(opengl, GIS_OBJECT(cur->data));
+               _draw_object(opengl, GRITS_OBJECT(cur->data));
 
        /* TODO: Prune empty levels */
 
-       g_debug("GisOpenGL: _draw_level - drew %d,%d objects",
+       g_debug("GritsOpenGL: _draw_level - drew %d,%d objects",
                        nunsorted, nsorted);
        return FALSE;
 }
 
-static gboolean on_expose(GisOpenGL *opengl, GdkEventExpose *event, gpointer _)
+static gboolean on_expose(GritsOpenGL *opengl, GdkEventExpose *event, gpointer _)
 {
-       g_debug("GisOpenGL: on_expose - begin");
+       g_debug("GritsOpenGL: on_expose - begin");
 
        glClear(GL_COLOR_BUFFER_BIT);
 
@@ -472,13 +472,13 @@ static gboolean on_expose(GisOpenGL *opengl, GdkEventExpose *event, gpointer _)
        GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl));
        gdk_gl_drawable_swap_buffers(gldrawable);
 
-       g_debug("GisOpenGL: on_expose - end\n");
+       g_debug("GritsOpenGL: on_expose - end\n");
        return FALSE;
 }
 
-static gboolean on_key_press(GisOpenGL *opengl, GdkEventKey *event, gpointer _)
+static gboolean on_key_press(GritsOpenGL *opengl, GdkEventKey *event, gpointer _)
 {
-       g_debug("GisOpenGL: on_key_press - key=%x, state=%x, plus=%x",
+       g_debug("GritsOpenGL: on_key_press - key=%x, state=%x, plus=%x",
                        event->keyval, event->state, GDK_plus);
 
        guint kv = event->keyval;
@@ -499,17 +499,17 @@ static gboolean on_key_press(GisOpenGL *opengl, GdkEventKey *event, gpointer _)
 
 static gboolean _update_errors_cb(gpointer _opengl)
 {
-       GisOpenGL *opengl = _opengl;
+       GritsOpenGL *opengl = _opengl;
        g_mutex_lock(opengl->sphere_lock);
        roam_sphere_update_errors(opengl->sphere);
        g_mutex_unlock(opengl->sphere_lock);
        opengl->ue_source = 0;
        return FALSE;
 }
-static void on_view_changed(GisOpenGL *opengl,
+static void on_view_changed(GritsOpenGL *opengl,
                gdouble _1, gdouble _2, gdouble _3)
 {
-       g_debug("GisOpenGL: on_view_changed");
+       g_debug("GritsOpenGL: on_view_changed");
        _set_visuals(opengl);
 #ifndef ROAM_DEBUG
        if (!opengl->ue_source)
@@ -519,9 +519,9 @@ static void on_view_changed(GisOpenGL *opengl,
 #endif
 }
 
-static gboolean on_idle(GisOpenGL *opengl)
+static gboolean on_idle(GritsOpenGL *opengl)
 {
-       //g_debug("GisOpenGL: on_idle");
+       //g_debug("GritsOpenGL: on_idle");
        g_mutex_lock(opengl->sphere_lock);
        if (roam_sphere_split_merge(opengl->sphere))
                gtk_widget_queue_draw(GTK_WIDGET(opengl));
@@ -531,37 +531,37 @@ static gboolean on_idle(GisOpenGL *opengl)
 
 
 /*********************
- * GisViewer methods *
+ * GritsViewer methods *
  *********************/
 /**
- * gis_opengl_new:
+ * grits_opengl_new:
  * @plugins: the plugins store to use
  * @prefs:   the preferences object to use
  *
  * Create a new OpenGL renderer.
  *
- * Returns: the new #GisOpenGL
+ * Returns: the new #GritsOpenGL
  */
-GisViewer *gis_opengl_new(GisPlugins *plugins, GisPrefs *prefs)
+GritsViewer *grits_opengl_new(GritsPlugins *plugins, GritsPrefs *prefs)
 {
-       g_debug("GisOpenGL: new");
-       GisViewer *opengl = g_object_new(GIS_TYPE_OPENGL, NULL);
-       gis_viewer_setup(opengl, plugins, prefs);
+       g_debug("GritsOpenGL: new");
+       GritsViewer *opengl = g_object_new(GRITS_TYPE_OPENGL, NULL);
+       grits_viewer_setup(opengl, plugins, prefs);
        return opengl;
 }
 
-static void gis_opengl_center_position(GisViewer *_opengl, gdouble lat, gdouble lon, gdouble elev)
+static void grits_opengl_center_position(GritsViewer *_opengl, gdouble lat, gdouble lon, gdouble elev)
 {
        glRotatef(lon, 0, 1, 0);
        glRotatef(-lat, 1, 0, 0);
        glTranslatef(0, 0, elev2rad(elev));
 }
 
-static void gis_opengl_project(GisViewer *_opengl,
+static void grits_opengl_project(GritsViewer *_opengl,
                gdouble lat, gdouble lon, gdouble elev,
                gdouble *px, gdouble *py, gdouble *pz)
 {
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        gdouble x, y, z;
        lle2xyz(lat, lon, elev, &x, &y, &z);
        gluProject(x, y, z,
@@ -571,10 +571,10 @@ static void gis_opengl_project(GisViewer *_opengl,
                px, py, pz);
 }
 
-static void gis_opengl_set_height_func(GisViewer *_opengl, GisTile *tile,
+static void grits_opengl_set_height_func(GritsViewer *_opengl, GritsTile *tile,
                RoamHeightFunc height_func, gpointer user_data, gboolean update)
 {
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        if (!tile)
                return;
        /* TODO: get points? */
@@ -597,7 +597,7 @@ static void gis_opengl_set_height_func(GisViewer *_opengl, GisTile *tile,
        g_mutex_unlock(opengl->sphere_lock);
 }
 
-static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
+static void _grits_opengl_clear_height_func_rec(RoamTriangle *root)
 {
        if (!root)
                return;
@@ -607,22 +607,22 @@ static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
                points[i]->height_data = NULL;
                roam_point_update_height(points[i]);
        }
-       _gis_opengl_clear_height_func_rec(root->kids[0]);
-       _gis_opengl_clear_height_func_rec(root->kids[1]);
+       _grits_opengl_clear_height_func_rec(root->kids[0]);
+       _grits_opengl_clear_height_func_rec(root->kids[1]);
 }
 
-static void gis_opengl_clear_height_func(GisViewer *_opengl)
+static void grits_opengl_clear_height_func(GritsViewer *_opengl)
 {
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        for (int i = 0; i < G_N_ELEMENTS(opengl->sphere->roots); i++)
-               _gis_opengl_clear_height_func_rec(opengl->sphere->roots[i]);
+               _grits_opengl_clear_height_func_rec(opengl->sphere->roots[i]);
 }
 
-static gpointer gis_opengl_add(GisViewer *_opengl, GisObject *object,
+static gpointer grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
                gint key, gboolean sort)
 {
-       g_assert(GIS_IS_OPENGL(_opengl));
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_assert(GRITS_IS_OPENGL(_opengl));
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        g_mutex_lock(opengl->objects_lock);
        _load_object(opengl, object);
        struct RenderLevel *level = g_tree_lookup(opengl->objects, (gpointer)key);
@@ -643,13 +643,13 @@ static gpointer gis_opengl_add(GisViewer *_opengl, GisObject *object,
        return link;
 }
 
-static GisObject *gis_opengl_remove(GisViewer *_opengl, gpointer _link)
+static GritsObject *grits_opengl_remove(GritsViewer *_opengl, gpointer _link)
 {
-       g_assert(GIS_IS_OPENGL(_opengl));
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_assert(GRITS_IS_OPENGL(_opengl));
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        g_mutex_lock(opengl->objects_lock);
        GList *link = _link;
-       GisObject *object = link->data;
+       GritsObject *object = link->data;
        _unload_object(opengl, object);
        /* Just unlink and free it, link->prev is assured */
        link->prev->next = link->next;
@@ -680,10 +680,10 @@ static void _objects_free(gpointer value)
        g_free(level);
 }
 
-G_DEFINE_TYPE(GisOpenGL, gis_opengl, GIS_TYPE_VIEWER);
-static void gis_opengl_init(GisOpenGL *opengl)
+G_DEFINE_TYPE(GritsOpenGL, grits_opengl, GRITS_TYPE_VIEWER);
+static void grits_opengl_init(GritsOpenGL *opengl)
 {
-       g_debug("GisOpenGL: init");
+       g_debug("GritsOpenGL: init");
        /* OpenGL setup */
        GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(
                        GDK_GL_MODE_RGBA   | GDK_GL_MODE_DEPTH |
@@ -715,10 +715,10 @@ static void gis_opengl_init(GisOpenGL *opengl)
        g_signal_connect(opengl, "location-changed", G_CALLBACK(on_view_changed), NULL);
        g_signal_connect(opengl, "rotation-changed", G_CALLBACK(on_view_changed), NULL);
 }
-static void gis_opengl_dispose(GObject *_opengl)
+static void grits_opengl_dispose(GObject *_opengl)
 {
-       g_debug("GisOpenGL: dispose");
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_debug("GritsOpenGL: dispose");
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        if (opengl->sm_source[0]) {
                g_source_remove(opengl->sm_source[0]);
                opengl->sm_source[0] = 0;
@@ -731,30 +731,30 @@ static void gis_opengl_dispose(GObject *_opengl)
                g_source_remove(opengl->ue_source);
                opengl->ue_source = 0;
        }
-       G_OBJECT_CLASS(gis_opengl_parent_class)->dispose(_opengl);
+       G_OBJECT_CLASS(grits_opengl_parent_class)->dispose(_opengl);
 }
-static void gis_opengl_finalize(GObject *_opengl)
+static void grits_opengl_finalize(GObject *_opengl)
 {
-       g_debug("GisOpenGL: finalize");
-       GisOpenGL *opengl = GIS_OPENGL(_opengl);
+       g_debug("GritsOpenGL: finalize");
+       GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
        roam_sphere_free(opengl->sphere);
        g_tree_destroy(opengl->objects);
        g_mutex_free(opengl->objects_lock);
        g_mutex_free(opengl->sphere_lock);
-       G_OBJECT_CLASS(gis_opengl_parent_class)->finalize(_opengl);
+       G_OBJECT_CLASS(grits_opengl_parent_class)->finalize(_opengl);
 }
-static void gis_opengl_class_init(GisOpenGLClass *klass)
+static void grits_opengl_class_init(GritsOpenGLClass *klass)
 {
-       g_debug("GisOpenGL: class_init");
+       g_debug("GritsOpenGL: class_init");
        GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
-       gobject_class->finalize = gis_opengl_finalize;
-       gobject_class->dispose = gis_opengl_dispose;
-
-       GisViewerClass *viewer_class = GIS_VIEWER_CLASS(klass);
-       viewer_class->center_position   = gis_opengl_center_position;
-       viewer_class->project           = gis_opengl_project;
-       viewer_class->clear_height_func = gis_opengl_clear_height_func;
-       viewer_class->set_height_func   = gis_opengl_set_height_func;
-       viewer_class->add               = gis_opengl_add;
-       viewer_class->remove            = gis_opengl_remove;
+       gobject_class->finalize = grits_opengl_finalize;
+       gobject_class->dispose = grits_opengl_dispose;
+
+       GritsViewerClass *viewer_class = GRITS_VIEWER_CLASS(klass);
+       viewer_class->center_position   = grits_opengl_center_position;
+       viewer_class->project           = grits_opengl_project;
+       viewer_class->clear_height_func = grits_opengl_clear_height_func;
+       viewer_class->set_height_func   = grits_opengl_set_height_func;
+       viewer_class->add               = grits_opengl_add;
+       viewer_class->remove            = grits_opengl_remove;
 }