Hey everyone!
EDIT: Oh, excuse me, after panically posting something here I managed it out, like always, sorry again. I simply forgot to glBindBufferBase before glGetBufferSubData, now it's perfect!( I think, lol ). I hope this will be useful for someone. Sorry and Thanks again!
I am using terrain displacement method in GLSL, so I want to get the data from it to game core and use it. ( Don't ask me why I am using displacement in GLSL, it's just easier and I can't get that good results in main code, lol ).
So, I got vertex array/buffer objects. Here's what I do:
// Initialization code
glGenVertexArrays( ...
glBindVertexArray( .... ...
// Bind generated data here. ( X, 0.0f, Z )
......
glGenBuffers( 1, &m_transformFeedback );
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, m_transformFeedback);
glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, m_map_size * sizeof( ncVec3 ), NULL, GL_DYNAMIC_COPY);
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, 0);
glGenQueries(1, &m_transformFeedbackQuery); // Temp, eats a lot of performance.
So this works okay, no errors. And here's how I render this:
// Bind vertex array with vertex buffers ( vertices, normals, uvs ).
......
// Drawing now.
glEnable(GL_RASTERIZER_DISCARD);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, m_transformFeedback);
glBeginQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN, m_transformFeedbackQuery); // temp
glBeginTransformFeedback(GL_TRIANGLES);
glDrawArrays( GL_TRIANGLE_STRIP, 0, m_map_size );
glEndTransformFeedback();
glEndQuery(GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN);
glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, 0);
glDisable(GL_RASTERIZER_DISCARD);
......
GLuint primitives;
// THIS RETURNS RIGHT NUMBER OF PRIMITIVES!
glGetQueryObjectuiv(m_transformFeedbackQuery, GL_QUERY_RESULT, &primitives);
g_Core->Print( LOG_INFO, "%i primitives written.\n", primitives );
// HERE I GOT NOTHING! It returns 1.0, 1.0, 1.0 or just 0.0, 0.0, 0.0
// tmapData is allocated or just static array, no difference, same result.
glGetBufferSubData( GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(tmapData), tmapData );
// Random numbers.
g_Core->Print( LOG_INFO, "%f %f %f\n", tmapData[53].x, tmapData[353].y, tmapData[3534].z );
Shader code:
glAttachProgram( vert and fragments )
const char * names[] = { "VertexOut" };
// GL_INTERLEAVED_ATTRIBS or GL_SEPARATED_ATTRIBS, not working yet :(
glTransformFeedbackVaryings( program, 1, names, GL_INTERLEAVED_ATTRIBS );
glLinkProgram( ...
// Vertex shader:
out vec3 vertexOut;
vec4 map_data = texture( gSampler[4], hmap_coord );
float displacement = u_map_scale * map_data.r;
vertex.y += displacement;
vertexOut = vertex; // Even tried to vertexOut = vec3(10.0, 10.0, 10.0);
What could be problem? I am only using vertex and fragment shader, no geometry ( don't want to )
Thanks in advance!