class ffw::GLVertexArray
Class List > ffw :: GLVertexArray
A Vertex Array Object (VAO) More...
Protected Attributes
Type | Name |
---|---|
GLuint | buffer |
Public Functions
Type | Name |
---|---|
GLVertexArray () Creates an empty OpenGL buffer object. | |
GLVertexArray (bool create) Creates an OpenGL vertex array buffer. | |
GLVertexArray (const GLVertexArray & other) = delete | |
GLVertexArray (GLVertexArray && other) | |
void | swap (GLVertexArray & other) |
virtual | ~GLVertexArray () |
bool | isCreated () const Returns true if the object has been allocated. |
void | destroy () Releases the resources. |
void | bind () const Binds the buffer object. |
void | unbind () const Unbinds the buffer object and sets the current buffer object to zero. |
GLuint | getHandle () const Returns the OpenGL named object (the handle) |
void | enableVertexAttribArray (GLint location) const Enables a vertex attrib array at a specific location. |
void | disableVertexAttribArray (GLint location) const Disables a vertex attrib array at a specific location. |
void | setAttributePointerf (GLint location, GLint size, GLsizei stride, const GLvoid * offset) const Specify the location and data format of the array of generic vertex attributes at a specific index. |
void | setAttributeDivisor (GLuint index, GLuint divisor) const Modify the rate at which generic vertex attributes advance during instanced rendering. |
GLVertexArray & | operator= (const GLVertexArray & other) = delete |
GLVertexArray & | operator= (GLVertexArray && other) |
Detailed Description
This is a vertex array object to be used with vertex buffer object (VBO). An example code below:
// Somewhere in your code
ffw::GLVertexBuffer vbo;
ffw::GLVertexArray vao;
ffw::GLProgram program;
// Initialization (only once)
try {
// Create our shader (optional).
program = ffw::GLProgram(...);
// This will create the VAO object.
// Once this line is completed, VAO is bound, so no need to
// manually bind it.
vao = ffw::GLVertexArray(true);
// This will create the VBO object using some random "vertices" data.
// Similarly as the VAO, this VBO is automatically bound after creation
// (after the constructor is called)
vbo = ffw::GLVertexBuffer(vertices, sizeof(vertices), GL_STATIC_DRAW);
// Because both VAO and VBO are bound (during creation), we can
// set the properties of the VAO by setting attribute pointers
vao.setAttributePointerf(program.getAttributeLocation("position"), 3, 6 * sizeof(float), (void*)(0 * sizeof(float)));
// Once we are done, we need to unbind the VAO so we won't
// accidentally modify it.
vao.unbind();
} catch (ffw::GLException& e) {
std::cerr << "Failed to initialize shaders: " << e.what() << std::endl;
return EXIT_FAILURE;
}
// Rendering (in a loop)
while (true) {
// Bind the shader program and the VAO.
// You do not need to bind the VBO! The VAO handles that for you!
program.bind();
vao.bind();
// Set the uniforms (if any) and draw the arrays
// Note that calling any functions that modify attribute values or pointers
// will also modify the VAO, therefore invaliding what we have done
// in the initialization. This includes "setAttributePointerf" and so on.
program.drawArrays(GL_TRIANGLES, 0, ...);
// Stop the program and unbind the VAO
program.unbind();
vao.unbind();
}
Protected Attributes Documentation
variable buffer
GLuint ffw::GLVertexArray::buffer;
Public Functions Documentation
function GLVertexArray (1/4)
ffw::GLVertexArray::GLVertexArray ()
Creates an empty OpenGL buffer object.
function GLVertexArray (2/4)
ffw::GLVertexArray::GLVertexArray (
bool create
)
Creates an OpenGL vertex array buffer.
Exception:
- GLException if something went wrong
function GLVertexArray (3/4)
ffw::GLVertexArray::GLVertexArray (
const GLVertexArray & other
) = delete
function GLVertexArray (4/4)
ffw::GLVertexArray::GLVertexArray (
GLVertexArray && other
)
function swap
void ffw::GLVertexArray::swap (
GLVertexArray & other
)
function ~GLVertexArray
virtual ffw::GLVertexArray::~GLVertexArray ()
function isCreated
bool ffw::GLVertexArray::isCreated () const
Returns true if the object has been allocated.
function destroy
void ffw::GLVertexArray::destroy ()
Releases the resources.
function bind
void ffw::GLVertexArray::bind () const
Binds the buffer object.
function unbind
void ffw::GLVertexArray::unbind () const
Unbinds the buffer object and sets the current buffer object to zero.
function getHandle
GLuint ffw::GLVertexArray::getHandle () const
Returns the OpenGL named object (the handle)
function enableVertexAttribArray
void ffw::GLVertexArray::enableVertexAttribArray (
GLint location
) const
Enables a vertex attrib array at a specific location.
Note:
This method is being called by setAttributePointerf
function disableVertexAttribArray
void ffw::GLVertexArray::disableVertexAttribArray (
GLint location
) const
Disables a vertex attrib array at a specific location.
function setAttributePointerf
void ffw::GLVertexArray::setAttributePointerf (
GLint location,
GLint size,
GLsizei stride,
const GLvoid * offset
) const
Specify the location and data format of the array of generic vertex attributes at a specific index.
Note:
This automatically calls enableVertexAttribArray with the location
function setAttributeDivisor
void ffw::GLVertexArray::setAttributeDivisor (
GLuint index,
GLuint divisor
) const
Modify the rate at which generic vertex attributes advance during instanced rendering.
function operator= (1/2)
GLVertexArray & ffw::GLVertexArray::operator= (
const GLVertexArray & other
) = delete
function operator= (2/2)
GLVertexArray & ffw::GLVertexArray::operator= (
GLVertexArray && other
)
The documentation for this class was generated from the following file: include/ffw/graphics/glvertexarray.h