|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:49:56
|
Author: Lasse Karkkainen <tro...@tr...>
Date: Mon Feb 28 01:26:21 2011 +0100
Stereo3d shader cleanup and changed stereo viewport numbering.
---
data/shaders/stereo3d.geom | 42 +++++++++++-------------------------------
game/video_driver.cc | 8 ++++----
2 files changed, 15 insertions(+), 35 deletions(-)
diff --git a/data/shaders/stereo3d.geom b/data/shaders/stereo3d.geom
index b19f19b..4fa2f7a 100644
--- a/data/shaders/stereo3d.geom
+++ b/data/shaders/stereo3d.geom
@@ -1,6 +1,9 @@
#version 330
#extension GL_ARB_viewport_array : require
+uniform float sepFactor;
+uniform float z0;
+
layout(triangles) in;
layout(triangle_strip, max_vertices = 6) out;
@@ -12,47 +15,24 @@ out vec4 texCoord;
out vec3 normal;
out vec4 color;
-uniform float sepFactor;
-uniform float z0;
+int i;
-void passthru(in int i) {
+void passthru() {
gl_Position = gl_in[i].gl_Position;
texCoord = vTexCoord[i];
normal = vNormal[i];
color = vColor[i];
}
+// Process all the vertices, applying code to them before emitting (do-while to convince Nvidia of the code getting executed)
+#define PROCESS(code) i = 0; do { passthru(); code; EmitVertex(); } while (++i < gl_in.length()); EndPrimitive();
+
void main() {
- // Fix Nvidia compile warnings ("might be used uninitialized")
- gl_Position = vec4(0);
- texCoord = vec4(0);
- normal = vec3(0);
- color = vec4(0);
if (sepFactor == 0.0) {
- // No stereo
- gl_ViewportIndex = 0;
- for(int i=0; i < gl_in.length(); ++i) {
- passthru(i);
- EmitVertex();
- }
- EndPrimitive();
+ gl_ViewportIndex = 0; PROCESS(); // No stereo
} else {
- // Render the left eye
- gl_ViewportIndex = 0;
- for(int i=0; i < gl_in.length(); ++i) {
- passthru(i);
- gl_Position.x -= sepFactor * (gl_Position.z - z0);
- EmitVertex();
- }
- EndPrimitive();
- // Render the right eye
- gl_ViewportIndex = 1;
- for(int i=0; i < gl_in.length(); ++i) {
- passthru(i);
- gl_Position.x += sepFactor * (gl_Position.z - z0);
- EmitVertex();
- }
- EndPrimitive();
+ gl_ViewportIndex = 1; PROCESS(gl_Position.x -= sepFactor * (gl_Position.z - z0)); // Left eye
+ gl_ViewportIndex = 2; PROCESS(gl_Position.x += sepFactor * (gl_Position.z - z0)); // Right eye
}
}
diff --git a/game/video_driver.cc b/game/video_driver.cc
index 5a4e9ce..01c712d 100644
--- a/game/video_driver.cc
+++ b/game/video_driver.cc
@@ -178,8 +178,8 @@ void Window::render(boost::function<void (void)> drawFunc) {
{
UseFBO user(fbo);
view(0);
- glViewportIndexedf(0, 0, h / 2, w, h / 2);
- glViewportIndexedf(1, 0, 0, w, h / 2);
+ glViewportIndexedf(1, 0, h / 2, w, h / 2);
+ glViewportIndexedf(2, 0, 0, w, h / 2);
drawFunc();
}
glerror.check("Render to FBO");
@@ -240,8 +240,8 @@ void Window::view(unsigned num) {
if (num == 0) {
glViewport(vx, vy, vw, vh); // Drawable area of the window (excluding black bars)
} else {
- glViewportIndexedf(0, 0, vh / 2, vw, vh / 2); // Top half of the drawable area
- glViewportIndexedf(1, 0, 0, vw, vh / 2); // Bottom half of the drawable area
+ glViewportIndexedf(1, 0, vh / 2, vw, vh / 2); // Top half of the drawable area
+ glViewportIndexedf(2, 0, 0, vw, vh / 2); // Bottom half of the drawable area
}
}
|