summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKenneth Graunke <kenneth@whitecape.org>2011-01-06 17:46:33 -0800
committerKenneth Graunke <kenneth@whitecape.org>2011-01-21 21:43:41 -0800
commit21ad8ec8d63007add27bd9607e03e304be3be4e6 (patch)
tree28b666de5c51aa07e28d37a84b5c49fbf6cc4e96
parent79608966af8920e35859a54c7288101a6e5db53c (diff)
Use textureOffsetoffset
-rwxr-xr-xsrc/main.cpp9
-rw-r--r--src/sobel.frag29
-rw-r--r--src/sobel.vert6
3 files changed, 14 insertions, 30 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 0d6d677..1dc2633 100755
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -38,25 +38,18 @@ static GLuint prog;
#define VERTEX_SLOT 0
static GLuint sampler_slot;
-static GLuint width_slot;
-static GLuint height_slot;
static void
Redisplay()
{
Scene::Render();
- int viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
-
glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(prog);
glBindTexture(GL_TEXTURE_2D, Scene::fbo_tex);
glUniform1i(sampler_slot, 0);
- glUniform1f(width_slot, float(viewport[2]));
- glUniform1f(height_slot, float(viewport[3]));
GLfloat quad[4][2] = {{-1, 1}, {-1, -1}, {1, 1}, {1, -1}};
@@ -87,8 +80,6 @@ setup_shader()
exit(-1);
sampler_slot = glGetUniformLocation(prog, "sampler");
- width_slot = glGetUniformLocation(prog, "width");
- height_slot = glGetUniformLocation(prog, "height");
}
diff --git a/src/sobel.frag b/src/sobel.frag
index 9d329f7..dd07bf5 100644
--- a/src/sobel.frag
+++ b/src/sobel.frag
@@ -1,27 +1,20 @@
-#version 120
+#version 130
-varying vec2 texcoord;
+in vec2 texcoord;
uniform sampler2D sampler;
-uniform float width;
-uniform float height;
-
-// Texel offsets
-float off_x = 1/width;
-float off_y = 1/height;
-
void main(void)
{
// http://www.roborealm.com/help/Sobel.php
- vec4 p1 = texture2D(sampler, texcoord - off_x - off_y);
- vec4 p2 = texture2D(sampler, texcoord - off_y);
- vec4 p3 = texture2D(sampler, texcoord + off_x - off_y);
- vec4 p4 = texture2D(sampler, texcoord - off_x );
- vec4 p5 = texture2D(sampler, texcoord );
- vec4 p6 = texture2D(sampler, texcoord + off_x );
- vec4 p7 = texture2D(sampler, texcoord - off_x + off_y);
- vec4 p8 = texture2D(sampler, texcoord + off_y);
- vec4 p9 = texture2D(sampler, texcoord + off_x + off_y);
+ vec4 p1 = textureOffset(sampler, texcoord, ivec2(-1, -1));
+ vec4 p2 = textureOffset(sampler, texcoord, ivec2( 0, -1));
+ vec4 p3 = textureOffset(sampler, texcoord, ivec2( 1, -1));
+ vec4 p4 = textureOffset(sampler, texcoord, ivec2(-1, 0));
+ vec4 p5 = textureOffset(sampler, texcoord, ivec2( 0, 0));
+ vec4 p6 = textureOffset(sampler, texcoord, ivec2( 1, 0));
+ vec4 p7 = textureOffset(sampler, texcoord, ivec2(-1, 1));
+ vec4 p8 = textureOffset(sampler, texcoord, ivec2( 0, 1));
+ vec4 p9 = textureOffset(sampler, texcoord, ivec2( 1, 1));
vec4 Gx = p1+2*p2+p3-p7-2*p8-p9;
vec4 Gy = p3+2*p6+p9-p1-2*p4-p7;
diff --git a/src/sobel.vert b/src/sobel.vert
index 2bbcbe4..99ca619 100644
--- a/src/sobel.vert
+++ b/src/sobel.vert
@@ -1,7 +1,7 @@
-#version 120
+#version 130
-attribute vec2 vertex;
-varying vec2 texcoord;
+in vec2 vertex;
+out vec2 texcoord;
void main(void)
{