+static void gis_opengl_set_height_func(GisViewer *_self, GisTile *tile,
+ RoamHeightFunc height_func, gpointer user_data, gboolean update)
+{
+ GisOpenGL *self = GIS_OPENGL(_self);
+ if (!tile)
+ return;
+ /* TODO: get points? */
+ g_mutex_lock(self->sphere_lock);
+ GList *triangles = roam_sphere_get_intersect(self->sphere, TRUE,
+ tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
+ for (GList *cur = triangles; cur; cur = cur->next) {
+ RoamTriangle *tri = cur->data;
+ RoamPoint *points[] = {tri->p.l, tri->p.m, tri->p.r, tri->split};
+ for (int i = 0; i < G_N_ELEMENTS(points); i++) {
+ if (tile->edge.n >= points[i]->lat && points[i]->lat >= tile->edge.s &&
+ tile->edge.e >= points[i]->lon && points[i]->lon >= tile->edge.w) {
+ points[i]->height_func = height_func;
+ points[i]->height_data = user_data;
+ roam_point_update_height(points[i]);
+ }
+ }
+ }
+ g_list_free(triangles);
+ g_mutex_unlock(self->sphere_lock);
+}
+
+static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
+{
+ if (!root)
+ return;
+ RoamPoint *points[] = {root->p.l, root->p.m, root->p.r, root->split};
+ for (int i = 0; i < G_N_ELEMENTS(points); i++) {
+ points[i]->height_func = NULL;
+ 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]);
+}
+
+static void gis_opengl_clear_height_func(GisViewer *_self)
+{
+ GisOpenGL *self = GIS_OPENGL(_self);
+ for (int i = 0; i < G_N_ELEMENTS(self->sphere->roots); i++)
+ _gis_opengl_clear_height_func_rec(self->sphere->roots[i]);
+}
+
+static gpointer gis_opengl_add(GisViewer *_self, GisObject *object,
+ gint key, gboolean sort)
+{
+ g_assert(GIS_IS_OPENGL(_self));
+ GisOpenGL *self = GIS_OPENGL(_self);
+ _load_object(self, object);
+ struct RenderLevel *level = g_tree_lookup(self->objects, (gpointer)key);
+ if (!level) {
+ level = g_new0(struct RenderLevel, 1);
+ g_tree_insert(self->objects, (gpointer)key, level);
+ }
+ GList *list = sort ? &level->sorted : &level->unsorted;
+ /* Put the link in the list */
+ GList *next = g_new0(GList, 1);
+ next->data = object;
+ next->prev = list;
+ next->next = list->next;
+ list->next = next;
+ return next;
+}
+
+static GisObject *gis_opengl_remove(GisViewer *_self, gpointer _link)
+{
+ g_assert(GIS_IS_OPENGL(_self));
+ GisOpenGL *self = GIS_OPENGL(_self);
+ GList *link = _link;
+ GisObject *object = link->data;
+ _unload_object(self, object);
+ /* Just unlink and free it, link->prev is assured */
+ link->prev->next = link->next;
+ if (link->next)
+ link->next->prev = link->prev;
+ g_free(link);
+ g_object_unref(object);
+ return object;
+}
+
+/****************
+ * GObject code *
+ ****************/
+static int _objects_cmp(gconstpointer _a, gconstpointer _b, gpointer _)
+{
+ gint a = (int)_a, b = (int)_b;
+ return a < b ? -1 :
+ a > b ? 1 : 0;
+}
+static void _objects_free(gpointer value)
+{
+ struct RenderLevel *level = value;
+ if (level->sorted.next)
+ g_list_free(level->sorted.next);
+ if (level->unsorted.next)
+ g_list_free(level->unsorted.next);
+ g_free(level);
+}
+
+G_DEFINE_TYPE(GisOpenGL, gis_opengl, GIS_TYPE_VIEWER);
+static void gis_opengl_init(GisOpenGL *self)
+{
+ g_debug("GisOpenGL: init");