2 * Copyright (C) 2009-2010 Andy Spencer <andy753421@gmail.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @short_description: OpenGL based virtual globe
22 * #GisOpenGL is the core rendering engine used by libgis. Theoretically other
23 * renderers could be writte, but they have not been. GisOpenGL uses the ROAM
24 * algorithm for updating surface mesh the planet. The only thing GisOpenGL can
25 * actually render on it's own is a wireframe of a sphere.
27 * GisOpenGL relies on #GtkGlExt and requires (at least) OpenGL 2.0.
33 #include <gdk/gdkkeysyms.h>
35 #include <gtk/gtkgl.h>
39 #include "gis-opengl.h"
43 #include "objects/gis-object.h"
44 #include "objects/gis-marker.h"
45 #include "objects/gis-callback.h"
49 /* Tessellation, "finding intersecting triangles" */
50 /* http://research.microsoft.com/pubs/70307/tr-2006-81.pdf */
51 /* http://www.opengl.org/wiki/Alpha_Blending */
56 static void _set_visuals(GisOpenGL *opengl)
58 glMatrixMode(GL_MODELVIEW);
62 double lat, lon, elev, rx, ry, rz;
63 gis_viewer_get_location(GIS_VIEWER(opengl), &lat, &lon, &elev);
64 gis_viewer_get_rotation(GIS_VIEWER(opengl), &rx, &ry, &rz);
65 glRotatef(rx, 1, 0, 0);
66 glRotatef(rz, 0, 0, 1);
70 float light_ambient[] = {0.7f, 0.7f, 0.7f, 1.0f};
71 float light_diffuse[] = {2.0f, 2.0f, 2.0f, 1.0f};
73 float light_ambient[] = {0.2f, 0.2f, 0.2f, 1.0f};
74 float light_diffuse[] = {5.0f, 5.0f, 5.0f, 1.0f};
76 float light_position[] = {-13*EARTH_R, 1*EARTH_R, 3*EARTH_R, 1.0f};
77 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
78 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
79 glLightfv(GL_LIGHT0, GL_POSITION, light_position);
81 glEnable(GL_LIGHTING);
83 float material_ambient[] = {0.2, 0.2, 0.2, 1.0};
84 float material_diffuse[] = {0.8, 0.8, 0.8, 1.0};
85 float material_specular[] = {0.1, 0.1, 0.1, 1.0};
86 float material_emission[] = {0.0, 0.0, 0.0, 1.0};
87 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, material_ambient);
88 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, material_diffuse);
89 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, material_specular);
90 glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, material_emission);
91 glDisable(GL_TEXTURE_2D);
92 glDisable(GL_COLOR_MATERIAL);
95 glTranslatef(0, 0, -elev2rad(elev));
96 glRotatef(lat, 1, 0, 0);
97 glRotatef(-lon, 0, 1, 0);
99 glDisable(GL_ALPHA_TEST);
101 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
106 glEnable(GL_CULL_FACE);
110 glDepthFunc(GL_LEQUAL);
111 glEnable(GL_DEPTH_TEST);
113 glEnable(GL_LINE_SMOOTH);
115 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
116 //glShadeModel(GL_FLAT);
118 roam_sphere_update_view(opengl->sphere);
122 /********************
124 ********************/
125 static void _draw_tile(GisOpenGL *opengl, GisTile *tile)
127 if (!tile || !tile->data)
129 GList *triangles = roam_sphere_get_intersect(opengl->sphere, FALSE,
130 tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
132 g_warning("GisOpenGL: _draw_tiles - No triangles to draw: edges=%f,%f,%f,%f",
133 tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
134 //g_message("drawing %4d triangles for tile edges=%7.2f,%7.2f,%7.2f,%7.2f",
135 // g_list_length(triangles), tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
136 for (GList *cur = triangles; cur; cur = cur->next) {
137 RoamTriangle *tri = cur->data;
139 gdouble lat[3] = {tri->p.r->lat, tri->p.m->lat, tri->p.l->lat};
140 gdouble lon[3] = {tri->p.r->lon, tri->p.m->lon, tri->p.l->lon};
142 if (lon[0] < -90 || lon[1] < -90 || lon[2] < -90) {
143 if (lon[0] > 90) lon[0] -= 360;
144 if (lon[1] > 90) lon[1] -= 360;
145 if (lon[2] > 90) lon[2] -= 360;
148 gdouble n = tile->edge.n;
149 gdouble s = tile->edge.s;
150 gdouble e = tile->edge.e;
151 gdouble w = tile->edge.w;
153 gdouble londist = e - w;
154 gdouble latdist = n - s;
157 {(lon[0]-w)/londist, 1-(lat[0]-s)/latdist},
158 {(lon[1]-w)/londist, 1-(lat[1]-s)/latdist},
159 {(lon[2]-w)/londist, 1-(lat[2]-s)/latdist},
162 //if ((lat[0] == 90 && (xy[0][0] < 0 || xy[0][0] > 1)) ||
163 // (lat[1] == 90 && (xy[1][0] < 0 || xy[1][0] > 1)) ||
164 // (lat[2] == 90 && (xy[2][0] < 0 || xy[2][0] > 1)))
165 // g_message("w,e=%4.f,%4.f "
167 // "%4.1f,%4.0f,%4.2f,%4.2f "
168 // "%4.1f,%4.0f,%4.2f,%4.2f "
169 // "%4.1f,%4.0f,%4.2f,%4.2f ",
171 // lat[0], lon[0], xy[0][0], xy[0][1],
172 // lat[1], lon[1], xy[1][0], xy[1][1],
173 // lat[2], lon[2], xy[2][0], xy[2][1]);
176 if (lat[0] == 90 || lat[0] == -90) xy[0][0] = 0.5;
177 if (lat[1] == 90 || lat[1] == -90) xy[1][0] = 0.5;
178 if (lat[2] == 90 || lat[2] == -90) xy[2][0] = 0.5;
180 glEnable(GL_TEXTURE_2D);
181 glBindTexture(GL_TEXTURE_2D, *(guint*)tile->data);
182 glBegin(GL_TRIANGLES);
183 glNormal3dv(tri->p.r->norm); glTexCoord2dv(xy[0]); glVertex3dv((double*)tri->p.r);
184 glNormal3dv(tri->p.m->norm); glTexCoord2dv(xy[1]); glVertex3dv((double*)tri->p.m);
185 glNormal3dv(tri->p.l->norm); glTexCoord2dv(xy[2]); glVertex3dv((double*)tri->p.l);
188 g_list_free(triangles);
191 static void _draw_tiles(GisOpenGL *opengl, GisTile *tile)
193 /* Only draw children if possible */
194 gboolean has_children = TRUE;
196 gis_tile_foreach(tile, child)
197 if (!child || !child->data)
198 has_children = FALSE;
200 /* Only draw children */
201 gis_tile_foreach(tile, child)
202 _draw_tiles(opengl, child);
204 /* No children, draw this tile */
205 _draw_tile(opengl, tile);
208 static void _draw_marker(GisOpenGL *opengl, GisMarker *marker)
210 GisPoint *point = gis_object_center(marker);
212 gis_viewer_project(GIS_VIEWER(opengl),
213 point->lat, point->lon, point->elev,
218 //g_debug("GisOpenGL: draw_marker - %s pz=%f ", marker->label, pz);
220 cairo_surface_t *surface = cairo_get_target(marker->cairo);
221 gdouble width = cairo_image_surface_get_width(surface);
222 gdouble height = cairo_image_surface_get_height(surface);
224 glMatrixMode(GL_PROJECTION); glLoadIdentity();
225 glMatrixMode(GL_MODELVIEW); glLoadIdentity();
226 glOrtho(0, GTK_WIDGET(opengl)->allocation.width,
227 0, GTK_WIDGET(opengl)->allocation.height, -1, 1);
228 glTranslated(px - marker->xoff,
229 py - marker->yoff, 0);
231 glDisable(GL_LIGHTING);
232 glDisable(GL_COLOR_MATERIAL);
233 glDisable(GL_DEPTH_TEST);
234 glEnable(GL_TEXTURE_2D);
235 glBindTexture(GL_TEXTURE_2D, marker->tex);
237 glTexCoord2f(1, 1); glVertex3f(width, 0 , 0);
238 glTexCoord2f(1, 0); glVertex3f(width, height, 0);
239 glTexCoord2f(0, 0); glVertex3f(0 , height, 0);
240 glTexCoord2f(0, 1); glVertex3f(0 , 0 , 0);
244 static void _draw_callback(GisOpenGL *opengl, GisCallback *callback)
246 callback->callback(callback, callback->user_data);
249 static void _draw_object(GisOpenGL *opengl, GisObject *object)
251 //g_debug("GisOpenGL: draw_object");
252 /* Skip out of range objects */
253 if (object->lod > 0) {
254 gdouble eye[3], obj[3];
255 gis_viewer_get_location(GIS_VIEWER(opengl), &eye[0], &eye[1], &eye[2]);
256 lle2xyz(eye[0], eye[1], eye[2], &eye[0], &eye[1], &eye[2]);
257 lle2xyz(object->center.lat, object->center.lon, object->center.elev,
258 &obj[0], &obj[1], &obj[2]);
259 gdouble dist = distd(obj, eye);
260 if (object->lod < dist)
265 glMatrixMode(GL_PROJECTION); glPushMatrix();
266 glMatrixMode(GL_MODELVIEW); glPushMatrix();
267 glPushAttrib(GL_ALL_ATTRIB_BITS);
268 if (GIS_IS_MARKER(object)) {
269 _draw_marker(opengl, GIS_MARKER(object));
270 } else if (GIS_IS_CALLBACK(object)) {
271 _draw_callback(opengl, GIS_CALLBACK(object));
272 } else if (GIS_IS_TILE(object)) {
273 _draw_tiles(opengl, GIS_TILE(object));
276 glMatrixMode(GL_PROJECTION); glPopMatrix();
277 glMatrixMode(GL_MODELVIEW); glPopMatrix();
280 static void _load_object(GisOpenGL *opengl, GisObject *object)
282 g_debug("GisOpenGL: load_object");
283 if (GIS_IS_MARKER(object)) {
284 GisMarker *marker = GIS_MARKER(object);
285 cairo_surface_t *surface = cairo_get_target(marker->cairo);
286 gdouble width = cairo_image_surface_get_width(surface);
287 gdouble height = cairo_image_surface_get_height(surface);
289 glEnable(GL_TEXTURE_2D);
290 glGenTextures(1, &marker->tex);
291 glBindTexture(GL_TEXTURE_2D, marker->tex);
293 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
294 glPixelStorei(GL_PACK_ALIGNMENT, 1);
295 glTexImage2D(GL_TEXTURE_2D, 0, 4, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
296 cairo_image_surface_get_data(surface));
297 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
298 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
299 g_debug("load_texture: %d", marker->tex);
303 static void _unload_object(GisOpenGL *opengl, GisObject *object)
305 g_debug("GisOpenGL: unload_object");
306 if (GIS_IS_MARKER(object)) {
307 GisMarker *marker = GIS_MARKER(object);
308 glDeleteTextures(1, &marker->tex);
316 /* The unsorted/sroted GLists are blank head nodes,
317 * This way us we can remove objects from the level just by fixing up links
318 * I.e. we don't need to do a lookup to remove an object if we have its GList */
324 static void on_realize(GisOpenGL *opengl, gpointer _)
326 g_debug("GisOpenGL: on_realize");
328 GdkGLContext *glcontext = gtk_widget_get_gl_context(GTK_WIDGET(opengl));
329 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl));
330 if (!gdk_gl_drawable_gl_begin(gldrawable, glcontext))
331 g_assert_not_reached();
333 _set_visuals(opengl);
334 g_mutex_lock(opengl->sphere_lock);
335 roam_sphere_update_errors(opengl->sphere);
336 g_mutex_unlock(opengl->sphere_lock);
339 static gboolean on_configure(GisOpenGL *opengl, GdkEventConfigure *event, gpointer _)
341 g_debug("GisOpenGL: on_configure");
343 double width = GTK_WIDGET(opengl)->allocation.width;
344 double height = GTK_WIDGET(opengl)->allocation.height;
346 /* Setup OpenGL Window */
347 glViewport(0, 0, width, height);
348 glMatrixMode(GL_PROJECTION);
350 double ang = atan(height/FOV_DIST);
351 gluPerspective(rad2deg(ang)*2, width/height, 1, 10*EARTH_R);
354 g_mutex_lock(opengl->sphere_lock);
355 roam_sphere_update_errors(opengl->sphere);
356 g_mutex_unlock(opengl->sphere_lock);
362 static gboolean _draw_level(gpointer key, gpointer value, gpointer user_data)
364 g_debug("GisOpenGL: _draw_level - level=%-4d", (int)key);
365 GisOpenGL *opengl = user_data;
366 struct RenderLevel *level = value;
367 int nsorted = 0, nunsorted = 0;
370 /* Draw opaque objects without sorting */
372 glClear(GL_DEPTH_BUFFER_BIT);
373 for (cur = level->unsorted.next; cur; cur = cur->next, nunsorted++)
374 _draw_object(opengl, GIS_OBJECT(cur->data));
376 /* Freeze depth buffer and draw transparent objects sorted */
378 //glDepthMask(FALSE);
379 glAlphaFunc(GL_GREATER, 0.1);
380 for (cur = level->sorted.next; cur; cur = cur->next, nsorted++)
381 _draw_object(opengl, GIS_OBJECT(cur->data));
383 /* TODO: Prune empty levels */
385 g_debug("GisOpenGL: _draw_level - drew %d,%d objects",
390 static gboolean on_expose(GisOpenGL *opengl, GdkEventExpose *event, gpointer _)
392 g_debug("GisOpenGL: on_expose - begin");
394 glClear(GL_COLOR_BUFFER_BIT);
396 _set_visuals(opengl);
398 glColor4f(0.0, 0.0, 9.0, 0.6);
399 glDisable(GL_TEXTURE_2D);
400 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
401 roam_sphere_draw(opengl->sphere);
402 //roam_sphere_draw_normals(opengl->sphere);
404 g_tree_foreach(opengl->objects, _draw_level, opengl);
405 if (opengl->wireframe) {
406 glClear(GL_DEPTH_BUFFER_BIT);
407 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
408 roam_sphere_draw(opengl->sphere);
412 GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable(GTK_WIDGET(opengl));
413 gdk_gl_drawable_swap_buffers(gldrawable);
415 g_debug("GisOpenGL: on_expose - end\n");
419 static gboolean on_key_press(GisOpenGL *opengl, GdkEventKey *event, gpointer _)
421 g_debug("GisOpenGL: on_key_press - key=%x, state=%x, plus=%x",
422 event->keyval, event->state, GDK_plus);
424 guint kv = event->keyval;
428 opengl->wireframe = !opengl->wireframe;
429 gtk_widget_queue_draw(GTK_WIDGET(opengl));
432 else if (kv == GDK_n) roam_sphere_split_one(opengl->sphere);
433 else if (kv == GDK_p) roam_sphere_merge_one(opengl->sphere);
434 else if (kv == GDK_r) roam_sphere_split_merge(opengl->sphere);
435 else if (kv == GDK_u) roam_sphere_update_errors(opengl->sphere);
437 gtk_widget_queue_draw(GTK_WIDGET(opengl));
444 static gboolean _update_errors_cb(gpointer sphere)
446 roam_sphere_update_errors(sphere);
449 static void on_view_changed(GisOpenGL *opengl,
450 gdouble _1, gdouble _2, gdouble _3)
452 g_debug("GisOpenGL: on_view_changed");
453 _set_visuals(opengl);
455 opengl->ue_source = g_idle_add_full(G_PRIORITY_HIGH_IDLE+30,
456 _update_errors_cb, opengl->sphere, NULL);
457 //roam_sphere_update_errors(opengl->sphere);
461 static gboolean on_idle(GisOpenGL *opengl)
463 //g_debug("GisOpenGL: on_idle");
465 g_mutex_lock(opengl->sphere_lock);
466 if (roam_sphere_split_merge(opengl->sphere))
467 gtk_widget_queue_draw(GTK_WIDGET(opengl));
468 g_mutex_unlock(opengl->sphere_lock);
474 /*********************
475 * GisViewer methods *
476 *********************/
479 * @plugins: the plugins store to use
480 * @prefs: the preferences object to use
482 * Create a new OpenGL renderer.
484 * Returns: the new #GisOpenGL
486 GisViewer *gis_opengl_new(GisPlugins *plugins, GisPrefs *prefs)
488 g_debug("GisOpenGL: new");
489 GisViewer *opengl = g_object_new(GIS_TYPE_OPENGL, NULL);
490 gis_viewer_setup(opengl, plugins, prefs);
494 static void gis_opengl_center_position(GisViewer *_opengl, gdouble lat, gdouble lon, gdouble elev)
496 GisOpenGL *opengl = GIS_OPENGL(_opengl);
497 glRotatef(lon, 0, 1, 0);
498 glRotatef(-lat, 1, 0, 0);
499 glTranslatef(0, 0, elev2rad(elev));
502 static void gis_opengl_project(GisViewer *_opengl,
503 gdouble lat, gdouble lon, gdouble elev,
504 gdouble *px, gdouble *py, gdouble *pz)
506 GisOpenGL *opengl = GIS_OPENGL(_opengl);
508 lle2xyz(lat, lon, elev, &x, &y, &z);
510 opengl->sphere->view->model,
511 opengl->sphere->view->proj,
512 opengl->sphere->view->view,
516 static void gis_opengl_set_height_func(GisViewer *_opengl, GisTile *tile,
517 RoamHeightFunc height_func, gpointer user_data, gboolean update)
519 GisOpenGL *opengl = GIS_OPENGL(_opengl);
522 /* TODO: get points? */
523 g_mutex_lock(opengl->sphere_lock);
524 GList *triangles = roam_sphere_get_intersect(opengl->sphere, TRUE,
525 tile->edge.n, tile->edge.s, tile->edge.e, tile->edge.w);
526 for (GList *cur = triangles; cur; cur = cur->next) {
527 RoamTriangle *tri = cur->data;
528 RoamPoint *points[] = {tri->p.l, tri->p.m, tri->p.r, tri->split};
529 for (int i = 0; i < G_N_ELEMENTS(points); i++) {
530 if (tile->edge.n >= points[i]->lat && points[i]->lat >= tile->edge.s &&
531 tile->edge.e >= points[i]->lon && points[i]->lon >= tile->edge.w) {
532 points[i]->height_func = height_func;
533 points[i]->height_data = user_data;
534 roam_point_update_height(points[i]);
538 g_list_free(triangles);
539 g_mutex_unlock(opengl->sphere_lock);
542 static void _gis_opengl_clear_height_func_rec(RoamTriangle *root)
546 RoamPoint *points[] = {root->p.l, root->p.m, root->p.r, root->split};
547 for (int i = 0; i < G_N_ELEMENTS(points); i++) {
548 points[i]->height_func = NULL;
549 points[i]->height_data = NULL;
550 roam_point_update_height(points[i]);
552 _gis_opengl_clear_height_func_rec(root->kids[0]);
553 _gis_opengl_clear_height_func_rec(root->kids[1]);
556 static void gis_opengl_clear_height_func(GisViewer *_opengl)
558 GisOpenGL *opengl = GIS_OPENGL(_opengl);
559 for (int i = 0; i < G_N_ELEMENTS(opengl->sphere->roots); i++)
560 _gis_opengl_clear_height_func_rec(opengl->sphere->roots[i]);
563 static gpointer gis_opengl_add(GisViewer *_opengl, GisObject *object,
564 gint key, gboolean sort)
566 g_assert(GIS_IS_OPENGL(_opengl));
567 GisOpenGL *opengl = GIS_OPENGL(_opengl);
568 _load_object(opengl, object);
569 struct RenderLevel *level = g_tree_lookup(opengl->objects, (gpointer)key);
571 level = g_new0(struct RenderLevel, 1);
572 g_tree_insert(opengl->objects, (gpointer)key, level);
574 GList *list = sort ? &level->sorted : &level->unsorted;
575 /* Put the link in the list */
576 GList *next = g_new0(GList, 1);
579 next->next = list->next;
584 static GisObject *gis_opengl_remove(GisViewer *_opengl, gpointer _link)
586 g_assert(GIS_IS_OPENGL(_opengl));
587 GisOpenGL *opengl = GIS_OPENGL(_opengl);
589 GisObject *object = link->data;
590 _unload_object(opengl, object);
591 /* Just unlink and free it, link->prev is assured */
592 link->prev->next = link->next;
594 link->next->prev = link->prev;
596 g_object_unref(object);
603 static int _objects_cmp(gconstpointer _a, gconstpointer _b, gpointer _)
605 gint a = (int)_a, b = (int)_b;
609 static void _objects_free(gpointer value)
611 struct RenderLevel *level = value;
612 if (level->sorted.next)
613 g_list_free(level->sorted.next);
614 if (level->unsorted.next)
615 g_list_free(level->unsorted.next);
619 G_DEFINE_TYPE(GisOpenGL, gis_opengl, GIS_TYPE_VIEWER);
620 static void gis_opengl_init(GisOpenGL *opengl)
622 g_debug("GisOpenGL: init");
624 GdkGLConfig *glconfig = gdk_gl_config_new_by_mode(
625 GDK_GL_MODE_RGBA | GDK_GL_MODE_DEPTH |
626 GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA);
628 g_error("Failed to create glconfig");
629 if (!gtk_widget_set_gl_capability(GTK_WIDGET(opengl),
630 glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE))
631 g_error("GL lacks required capabilities");
632 g_object_unref(glconfig);
634 opengl->objects = g_tree_new_full(_objects_cmp, NULL, NULL, _objects_free);
635 opengl->sphere = roam_sphere_new(opengl);
636 opengl->sphere_lock = g_mutex_new();
639 opengl->sm_source[0] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+30, 33, (GSourceFunc)on_idle, opengl, NULL);
640 opengl->sm_source[1] = g_timeout_add_full(G_PRIORITY_HIGH_IDLE+10, 500, (GSourceFunc)on_idle, opengl, NULL);
643 gtk_widget_add_events(GTK_WIDGET(opengl), GDK_KEY_PRESS_MASK);
644 g_signal_connect(opengl, "realize", G_CALLBACK(on_realize), NULL);
645 g_signal_connect(opengl, "configure-event", G_CALLBACK(on_configure), NULL);
646 g_signal_connect(opengl, "expose-event", G_CALLBACK(on_expose), NULL);
648 g_signal_connect(opengl, "key-press-event", G_CALLBACK(on_key_press), NULL);
650 g_signal_connect(opengl, "location-changed", G_CALLBACK(on_view_changed), NULL);
651 g_signal_connect(opengl, "rotation-changed", G_CALLBACK(on_view_changed), NULL);
653 static void gis_opengl_dispose(GObject *_opengl)
655 g_debug("GisOpenGL: dispose");
656 GisOpenGL *opengl = GIS_OPENGL(_opengl);
657 if (opengl->sm_source[0]) {
658 g_source_remove(opengl->sm_source[0]);
659 opengl->sm_source[0] = 0;
661 if (opengl->sm_source[1]) {
662 g_source_remove(opengl->sm_source[1]);
663 opengl->sm_source[1] = 0;
665 if (opengl->ue_source) {
666 g_source_remove(opengl->ue_source);
667 opengl->ue_source = 0;
669 G_OBJECT_CLASS(gis_opengl_parent_class)->dispose(_opengl);
671 static void gis_opengl_finalize(GObject *_opengl)
673 g_debug("GisOpenGL: finalize");
674 GisOpenGL *opengl = GIS_OPENGL(_opengl);
675 roam_sphere_free(opengl->sphere);
676 g_tree_destroy(opengl->objects);
677 g_mutex_free(opengl->sphere_lock);
678 G_OBJECT_CLASS(gis_opengl_parent_class)->finalize(_opengl);
680 static void gis_opengl_class_init(GisOpenGLClass *klass)
682 g_debug("GisOpenGL: class_init");
683 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
684 gobject_class->finalize = gis_opengl_finalize;
685 gobject_class->dispose = gis_opengl_dispose;
687 GisViewerClass *viewer_class = GIS_VIEWER_CLASS(klass);
688 viewer_class->center_position = gis_opengl_center_position;
689 viewer_class->project = gis_opengl_project;
690 viewer_class->clear_height_func = gis_opengl_clear_height_func;
691 viewer_class->set_height_func = gis_opengl_set_height_func;
692 viewer_class->add = gis_opengl_add;
693 viewer_class->remove = gis_opengl_remove;