Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: i dont know why transform feedback isnt working :(

  1. #1
    Intern Newbie
    Join Date
    Sep 2014
    Posts
    33

    i dont know why transform feedback isnt working :(

    hi, i believe i am doing everything right for transform feedback but i am getting 0's when i try to read the data back from the transform feedback buffer. Their is one thing i just realized i dont quite understand which is indexed binding points on a binding target, so that might be why, im gonna check my book to see what that means (i now understand this). its a short piece of code that i wrote and i would be grateful if someone would comb through it and tell me what is wrong. thanks
    Code :
    if (glewInit() != GLEW_OK)
    	{
    		printf("glew could not load");
    		exit(1);
    	}
     
    	const GLchar *varyings[] = {"colorstfout"};
     
            GLuint vao;
    	glGenVertexArrays(1, &vao);
    	glBindVertexArray(vao);
     
    	GLfloat feedback[12];
     
    	glClearColor(0, 1, 0, 1);
     
    	const char *vshaderambient = 
    	"#version 430 core\n"
    	//"uniform vec4 colorobject;\n"
    	//"uniform vec4 colorlight;\n"
    	//"uniform float intensity;\n"
    	"vec4 colorstfout;\n"
    	"void main()\n"
    	"{\n"
    	"colorstfout = vec4(.5, .5, .5, .5);\n"
    	//"colorstfout = min(colorobject + (colorobject + colorlight * intensity), vec4(1, 1, 1, 1));\n"
    	"}\n";
     
    	GLuint progambient, vambient, tfo, buffercolorout;
     
    	progambient = glCreateProgram();
    	vambient = glCreateShader(GL_VERTEX_SHADER);
    	glShaderSource(vambient, 1, &vshaderambient, NULL);
    	glCompileShader(vambient);
    	glAttachShader(progambient, vambient);
     
    	glLinkProgram(progambient);
     
    	glGenTransformFeedbacks(1, &tfo);
    	glBindTransformFeedback(GL_TRANSFORM_FEEDBACK, tfo);
     
    	glGenBuffers(1, &buffercolorout);
    	glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buffercolorout);
    	glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(GLfloat) * 12, NULL, GL_STREAM_READ);
     
    	glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buffercolorout);
     
    	glTransformFeedbackVaryings(progambient, 1, varyings, GL_SEPARATE_ATTRIBS);
     
    	glLinkProgram(progambient);
     
    	glBeginTransformFeedback(GL_TRIANGLES);
     
    	glDrawArrays(GL_TRIANGLES, 0, 3);
     
    	glEndTransformFeedback();
     
    	glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(feedback), feedback);
     
    	printf("\nfirst vertex: %f, %f, %f, %f\n", feedback[0], feedback[1], feedback[2], feedback[3]);
    	printf("\nsecond vertex: %f, %f, %f, %f\n", feedback[4], feedback[5], feedback[6], feedback[7]);
    	printf("\nthird vertex: %f, %f, %f, %f\n", feedback[8], feedback[9], feedback[10], feedback[11]);
    Last edited by a-sylum; 09-08-2015 at 11:51 AM. Reason: i now understand indices on binding targets)

  2. #2
    Intern Newbie
    Join Date
    Sep 2014
    Posts
    33
    i changed the code a bit and it is now working. here is a copy of the code i wrote:
    Code :
    if (glewInit() != GLEW_OK)
    	{
    		printf("glew could not load");
    		exit(1);
    	}
     
    	const GLchar *varyings[] = {"colorstfout"};
     
    	GLfloat feedback[12];
     
    	glClearColor(0, 1, 0, 1);
     
    	const char *vshaderambient = 
    	"#version 430 core\n"
    	//"uniform vec4 colorobject;\n"
    	//"uniform vec4 colorlight;\n"
    	//"uniform float intensity;\n"
    	"out vec4 colorstfout;\n"
    	"void main()\n"
    	"{\n"
    	"colorstfout = vec4(1, 1, 1, 1);\n"
    	//"colorstfout = min(colorobject + (colorobject + colorlight * intensity), vec4(1, 1, 1, 1));\n"
    	"}\n";
     
    	GLuint progambient, vambient, tfo, buffercolorout;
     
    	progambient = glCreateProgram();
    	vambient = glCreateShader(GL_VERTEX_SHADER);
    	glShaderSource(vambient, 1, &vshaderambient, NULL);
    	glCompileShader(vambient);
    	glAttachShader(progambient, vambient);
     
    	glTransformFeedbackVaryings(progambient, 1, varyings, GL_SEPARATE_ATTRIBS);
     
    	glLinkProgram(progambient);
    	glUseProgram(progambient);
     
    	glGenVertexArrays(1, &vao);
    	glBindVertexArray(vao);
     
    	glGenBuffers(1, &buffercolorout);
    	glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, buffercolorout);
    	glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, sizeof(GLfloat) * 12, NULL, GL_STREAM_READ);
     
    	glBindBufferRange(GL_TRANSFORM_FEEDBACK_BUFFER, 0, buffercolorout, 0, sizeof(GLfloat) * 12);
     
    	glEnable(GL_RASTERIZER_DISCARD);
     
    	glBeginTransformFeedback(GL_TRIANGLES);
     
    	glDrawArrays(GL_TRIANGLES, 0, 3);
     
    	glEndTransformFeedback();
     
    	glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, sizeof(feedback), feedback);
     
    	glFlush();
     
    	printf("\nfirst vertex: %f, %f, %f, %f\n", feedback[0], feedback[1], feedback[2], feedback[3]);
    	printf("\nsecond vertex: %f, %f, %f, %f\n", feedback[4], feedback[5], feedback[6], feedback[7]);
    	printf("\nthird vertex: %f, %f, %f, %f\n", feedback[8], feedback[9], feedback[10], feedback[11]);

    im gonna compare the two and find out what i did wrong. PEEEEEACE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •