// #define ROAM_DEBUG
+#define OVERLAY_SLICE 0.01
+
/* Tessellation, "finding intersecting triangles" */
/* http://research.microsoft.com/pubs/70307/tr-2006-81.pdf */
/* http://www.opengl.org/wiki/Alpha_Blending */
static gboolean on_motion_notify(GritsOpenGL *opengl, GdkEventMotion *event, gpointer _)
{
opengl->mouse_queue = *event;
- gtk_widget_queue_draw(GTK_WIDGET(opengl));
+ grits_viewer_queue_draw(GRITS_VIEWER(opengl));
return FALSE;
}
/* Enable depth and alpha for world levels */
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.1);
+ glDepthRange(OVERLAY_SLICE, 1);
} else {
- /* Disable depth for Overlay/HUD levels */
- glDepthMask(FALSE);
+ /* Draw overlay in front of world */
+ glDepthRange(0, OVERLAY_SLICE);
}
/* Start ortho */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
#ifndef ROAM_DEBUG
+ g_mutex_lock(&opengl->sphere_lock);
roam_sphere_update_errors(opengl->sphere);
roam_sphere_split_merge(opengl->sphere);
+ g_mutex_unlock(&opengl->sphere_lock);
#endif
#ifdef ROAM_DEBUG
/* Testing */
if (kv == GDK_w) {
opengl->wireframe = !opengl->wireframe;
- gtk_widget_queue_draw(GTK_WIDGET(opengl));
+ grits_viewer_queue_draw(GRITS_VIEWER(opengl));
}
if (kv == GDK_p) {
opengl->pickmode = !opengl->pickmode;
- gtk_widget_queue_draw(GTK_WIDGET(opengl));
+ grits_viewer_queue_draw(GRITS_VIEWER(opengl));
}
#ifdef ROAM_DEBUG
else if (kv == GDK_n) roam_sphere_split_one(opengl->sphere);
else if (kv == GDK_p) roam_sphere_merge_one(opengl->sphere);
else if (kv == GDK_r) roam_sphere_split_merge(opengl->sphere);
else if (kv == GDK_u) roam_sphere_update_errors(opengl->sphere);
- gtk_widget_queue_draw(GTK_WIDGET(opengl));
+ grits_viewer_queue_draw(GRITS_VIEWER(opengl));
#endif
return FALSE;
}
glReadPixels(px, py, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &tmp);
pz = tmp;
}
+ pz = (pz-OVERLAY_SLICE) * (1.0/(1-OVERLAY_SLICE));
gluUnProject(px, py, pz,
opengl->sphere->view->model,
opengl->sphere->view->proj,
g_free(level);
}
-static gpointer grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
+static void grits_opengl_add(GritsViewer *_opengl, GritsObject *object,
gint num, gboolean sort)
{
g_assert(GRITS_IS_OPENGL(_opengl));
if (list->next)
list->next->prev = link;
list->next = link;
+ object->ref = link;
+ g_object_ref(object);
g_mutex_unlock(&opengl->objects_lock);
- return link;
}
-static GritsObject *grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
+void grits_opengl_remove(GritsViewer *_opengl, GritsObject *object)
{
g_assert(GRITS_IS_OPENGL(_opengl));
GritsOpenGL *opengl = GRITS_OPENGL(_opengl);
- GList *link = object->ref;
+ if (!object->ref)
+ return;
g_mutex_lock(&opengl->objects_lock);
+ GList *link = object->ref;
/* Just unlink and free it, link->prev is assured */
link->prev->next = link->next;
if (link->next)
link->next->prev = link->prev;
- g_mutex_unlock(&opengl->objects_lock);
- object->ref = NULL;
- object->viewer = NULL;
g_free(link);
+ object->ref = NULL;
g_object_unref(object);
- return object;
+ g_mutex_unlock(&opengl->objects_lock);
}
/****************