[grits] Add split depth buffer for world/overlay



commit b702b739df3d3dd601b0661c8349810f1fa0e46f
Author: Andy Spencer <andy753421 gmail com>
Date:   Sun Jan 20 04:22:38 2013 +0000

    Add split depth buffer for world/overlay
    
    The top 1 percent gets used for the overlay/hud layers, while the back
    99 percent gets used for the world. This allows the HUD to use depth
    testing without interacting with the world.
    
    This fixes a bug in the compass rose.

 src/grits-opengl.c |    8 ++++++--
 src/plugins/env.c  |    2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/src/grits-opengl.c b/src/grits-opengl.c
index 0e803ba..861bfc9 100644
--- a/src/grits-opengl.c
+++ b/src/grits-opengl.c
@@ -40,6 +40,8 @@
 
 // #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 */
@@ -312,9 +314,10 @@ static void _draw_level(gpointer _level, gpointer _opengl)
 		/* 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 */
@@ -512,6 +515,7 @@ static void grits_opengl_unproject(GritsViewer *_opengl,
 		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,
diff --git a/src/plugins/env.c b/src/plugins/env.c
index 6312f3b..4b6ed79 100644
--- a/src/plugins/env.c
+++ b/src/plugins/env.c
@@ -327,7 +327,7 @@ GritsPluginEnv *grits_plugin_env_new(GritsViewer *viewer, GritsPrefs *prefs)
 
 	/* Add compass */
 	GritsCallback *compass = grits_callback_new(compass_expose, env);
-	grits_viewer_add(viewer, GRITS_OBJECT(compass), GRITS_LEVEL_HUD, FALSE);
+	grits_viewer_add(viewer, GRITS_OBJECT(compass), GRITS_LEVEL_HUD, TRUE);
 	g_signal_connect(compass, "clicked", G_CALLBACK(compass_click), viewer);
 	grits_object_set_cursor(GRITS_OBJECT(compass), GDK_CROSS);
 	env->refs = g_list_prepend(env->refs, compass);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]