Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualSamith

Posted 24 November 2013 - 12:24 PM

EDIT: totally misunderstood your question! As the others above have stated, you wouldn't put all geometry into a VBO. You would have a VBO per object or per surface or something. Then you would be able to draw those objects individually with separate uniforms.

 

 

In most cases your VBO will be initialized once with vertex data that's in "model space" and then you'll leave the VBO alone. When you want to transform the object into world space, you'll do that in the vertex shader. You can send your transformation matrices to the vertex shader with uniform buffers.

#version 410

in vec4 position;
in vec3 color;

out vec4 out_position;

uniform Transform {
    mat4 model_view_projection;
};

void main()
{
    out_position = position * model_view_projection;
}

In that code model_view_projection is a member of the Transform uniform buffer. On the CPU side you would make a buffer that contained your model-view-projection matrix, and then bind that buffer to the location of Transform before drawing.

 

This way you never have to update your VBO, and all transformations are done efficiently on the GPU.


#2Samith

Posted 24 November 2013 - 12:24 PM

EDIT: totally misunderstood your question! As the others above have state, you wouldn't put all geometry into a VBO. You would have a VBO per object or per surface or something. Then you would be able to draw those objects individually with separate uniforms.

 

 

In most cases your VBO will be initialized once with vertex data that's in "model space" and then you'll leave the VBO alone. When you want to transform the object into world space, you'll do that in the vertex shader. You can send your transformation matrices to the vertex shader with uniform buffers.

#version 410

in vec4 position;
in vec3 color;

out vec4 out_position;

uniform Transform {
    mat4 model_view_projection;
};

void main()
{
    out_position = position * model_view_projection;
}

In that code model_view_projection is a member of the Transform uniform buffer. On the CPU side you would make a buffer that contained your model-view-projection matrix, and then bind that buffer to the location of Transform before drawing.

 

This way you never have to update your VBO, and all transformations are done efficiently on the GPU.


#1Samith

Posted 24 November 2013 - 12:22 PM

In most cases your VBO will be initialized once with vertex data that's in "model space" and then you'll leave the VBO alone. When you want to transform the object into world space, you'll do that in the vertex shader. You can send your transformation matrices to the vertex shader with uniform buffers.

 

<code>

#version 410

 

in vec4 position;

in vec3 color;

 

out vec4 out_position;

 

uniform Transform {

    mat4 model_view_projection;

};

 

void main()

{

    out_position = position * model_view_projection;

}

</code>

 

In that code model_view_projection is a member of the Transform uniform buffer. On the CPU side you would make a buffer that contained your model-view-projection matrix, and then bind that buffer to the location of Transform before drawing.

 

This way you never have to update your VBO, and all transformations are done efficiently on the GPU.


PARTNERS