Add vao RAII class

This commit is contained in:
rexy712
2020-08-31 10:12:10 -07:00
parent f6bc17f71b
commit aad6db9b29
2 changed files with 373 additions and 0 deletions

131
include/graphics/vao.hpp Normal file
View File

@@ -0,0 +1,131 @@
/**
This file is a part of our_dick
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OUR_DICK_GRAPHICS_VAO_HPP
#define OUR_DICK_GRAPHICS_VAO_HPP
#include "gl_include.hpp"
#include "math/math.hpp"
namespace graphics{
using namespace math;
class vertex_attribute;
//class representing a vertex array object
class vao
{
private:
GLuint m_buffer; //handle to the vertex array
public:
//create a default initialized opengl vao
vao();
vao(const vao&) = delete;
vao(vao&&);
~vao();
vao& operator=(const vao&) = delete;
vao& operator=(vao&&);
//Get access to a generic vertex attribute within this vao
vertex_attribute get_attribute(int index);
//bind this vao for use with rendering program
void bind();
//unbind this vao and rebind state machine to 0
void unbind();
};
//class representing a generic vertex attribute in a vao
class vertex_attribute
{
private:
GLuint m_vao; //handle to vertex array object
int m_index; //index of this attribute
public:
constexpr vertex_attribute(GLuint vao, int index):
m_vao(vao),
m_index(index){}
constexpr vertex_attribute(const vertex_attribute&) = default;
constexpr vertex_attribute(vertex_attribute&&) = default;
~vertex_attribute() = default;
constexpr vertex_attribute& operator=(const vertex_attribute&) = default;
constexpr vertex_attribute& operator=(vertex_attribute&&) = default;
//enable use as an array attribute (most likely what is desired)
void enable_array_mode();
//disable use as an array attribute. used for static data in attributes during rendering
void disable_array_mode();
//setters for use in array mode. Same arguments as glVertexAttribPointer but these take arguments
//as object counts rather than bytes. a valid vbo must be bound to buffers::array_buffer before these are called.
void set_float_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_double_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_byte_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_ubyte_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_short_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_ushort_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_int_pointer(GLint size, GLsizei stride, GLsizei offset);
void set_uint_pointer(GLint size, GLsizei stride, GLsizei offset);
//setters for use in non array mode
void set(GLfloat);
void set(GLshort);
void set(GLdouble);
void set(GLint);
void set(GLuint);
void set(GLfloat, GLfloat);
void set(GLshort, GLshort);
void set(GLdouble, GLdouble);
void set(GLint, GLint);
void set(GLuint, GLuint);
void set(GLfloat, GLfloat, GLfloat);
void set(GLshort, GLshort, GLshort);
void set(GLdouble, GLdouble, GLdouble);
void set(GLint, GLint, GLint);
void set(GLuint, GLuint, GLuint);
void set(GLfloat, GLfloat, GLfloat, GLfloat);
void set(GLshort, GLshort, GLshort, GLshort);
void set(GLdouble, GLdouble, GLdouble, GLdouble);
void set(GLint, GLint, GLint, GLint);
void set(GLuint, GLuint, GLuint, GLuint);
void set(const vec2<GLfloat>&);
void set(const vec2<GLshort>&);
void set(const vec2<GLdouble>&);
void set(const vec2<GLint>&);
void set(const vec2<GLuint>&);
void set(const vec3<GLfloat>&);
void set(const vec3<GLshort>&);
void set(const vec3<GLdouble>&);
void set(const vec3<GLint>&);
void set(const vec3<GLuint>&);
void set(const vec4<GLfloat>&);
void set(const vec4<GLshort>&);
void set(const vec4<GLdouble>&);
void set(const vec4<GLint>&);
void set(const vec4<GLuint>&);
void set(const vec4<GLbyte>&);
void set(const vec4<GLubyte>&);
void set(const vec4<GLushort>&);
};
}
#endif