Hi all,
I have checked the similar thread (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=242645) but it does not solve my problem. I am trying to do basic transform feedback by converting the nvidia opengl sdk (transform feedback fractal Cg example http://developer.download.nvidia.com/SDK/10/opengl/samples.html) to glsl. In the feedback func. after the calls to
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, vboID[1-current_buffer]);
glBeginTransformFeedback(feedback_prim);
glEnable(GL_RASTERIZER_DISCARD); // disable rasterization
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, query);
I attach my shaders using (glUseProgram(terrainShader)). After this call however I get no output. I have checked the error bit and its clear.
The shaders are also compiled and linked fine. What may be causing this. One more thing, if i move the shader program before the bindbufferbase call, there is no error but then the feedback does not work and i only get the base triangles without sub division but the query results is correct. If the shader is within the feedback calls given above, the query result is 0.
The terrain geometry shader for subdivision is this
#version 300
layout (lines_adjacency) in;
layout (points, max_vertices = 16) out;
uniform float rand_scale;// = 1.0,
uniform vec2 rand_xform;// = { 0.5, 0.5 },
uniform sampler2D rand_tex;
out vec4 color;
void main()
{
vec4 v[4];
for(int i=0;i<4;i++) {
v[i] = gl_in[i].gl_Position;
}
// calculate midpoints
vec4 e0 = (v[0] + v[1]) * 0.5;
vec4 e1 = (v[1] + v[2]) * 0.5;
vec4 e2 = (v[2] + v[3]) * 0.5;
vec4 e3 = (v[3] + v[0]) * 0.5;
vec4 m = (v[0] + v[1] + v[2] + v[3]) * 0.25;
// add random offsets
e0.y += texture(rand_tex, e0.xz*rand_xform.x+rand_xform.y).x*rand_scale;
e1.y += texture(rand_tex, e1.xz*rand_xform.x+rand_xform.y).x*rand_scale;
e2.y += texture(rand_tex, e2.xz*rand_xform.x+rand_xform.y).x*rand_scale;
e3.y += texture(rand_tex, e3.xz*rand_xform.x+rand_xform.y).x*rand_scale;
m.y += texture(rand_tex, m.xz*rand_xform.x+rand_xform.y).x*rand_scale;
gl_Position = v[0]; color=vec4(1,0,0,0); EmitVertex();
gl_Position = e0; color=vec4(1,0,0,0); EmitVertex();
gl_Position = m; color=vec4(1,0,0,0); EmitVertex();
gl_Position = e3; color=vec4(1,0,0,0); EmitVertex();
gl_Position = e0; color=vec4(0,0,1,0); EmitVertex();
gl_Position = v[1]; color=vec4(0,0,1,0); EmitVertex();
gl_Position = e1; color=vec4(0,0,1,0); EmitVertex();
gl_Position = m; color=vec4(0,0,1,0); EmitVertex();
gl_Position = m; color=vec4(0,1,0,0); EmitVertex();
gl_Position = e1; color=vec4(0,1,0,0); EmitVertex();
gl_Position = v[2]; color=vec4(0,1,0,0); EmitVertex();
gl_Position = e2; color=vec4(0,1,0,0); EmitVertex();
gl_Position = e3; color=vec4(1,0,1,0); EmitVertex();
gl_Position = m; color=vec4(1,0,1,0); EmitVertex();
gl_Position = e2; color=vec4(1,0,1,0); EmitVertex();
gl_Position = v[3]; color=vec4(1,0,1,0); EmitVertex();
}
and the terrain shading geometry shader is this
#version 330
layout (lines_adjacency) in;
layout (triangle_strip, max_vertices = 6) out;
vec3 lightDir=vec3(0,0,-1);
// calculate triangle normal
vec3 calcNormal(vec3 v0, vec3 v1, vec3 v2)
{
vec3 edge0 = v1 - v0;
vec3 edge1 = v2 - v0;
return normalize(cross(edge0, edge1));
}
in vec4 o_pos[];
in vec2 o_texcoord[];
in vec4 o_wpos[];
in vec4 o_color[];
out vec4 color;
void main() {
vec3 n = calcNormal(o_wpos[0].xyz, o_wpos[1].xyz, o_wpos[3].xyz);
float col = dot(n, lightDir);
vec3 n2 = calcNormal(o_wpos[1].xyz, o_wpos[2].xyz, o_wpos[3].xyz);
float col2 = dot(n2, lightDir);
gl_Position = gl_in[0].gl_Position;
color = vec4(col);
EmitVertex();
gl_Position = gl_in[1].gl_Position;
color = vec4(col);
EmitVertex();
gl_Position = gl_in[3].gl_Position;
color = vec4(col);
EmitVertex();
gl_Position = gl_in[2].gl_Position;
color = vec4(col2);
EmitVertex();
}