/** 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 . */ #ifndef OUR_DICK_GRAPHICS_OGL_VAO_HPP #define OUR_DICK_GRAPHICS_OGL_VAO_HPP #include "gl_include.hpp" #include "math/math.hpp" #include "vbo.hpp" namespace gfx::ogl{ 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&&); GLuint raw()const; //Set the instanced divisor of this binding point. Used with instanced rendering. void set_instance_divisor(GLuint binding, GLuint divisor); void bind_buffer(const vbo& buffer, GLuint bind_point, GLuint offset, GLuint stride); void bind_element_buffer(const vbo& buffer); //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(); //disable use as an array attribute. used for static data in attributes during rendering void disable(); //Associate this attribute's location with the given buffer binding location void associate_with(GLuint buffer_binding); //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_array(GLint size, GLsizei offset); void set_double_array(GLint size, GLsizei offset); void set_byte_array(GLint size, GLsizei offset); void set_ubyte_array(GLint size, GLsizei offset); void set_short_array(GLint size, GLsizei offset); void set_ushort_array(GLint size, GLsizei offset); void set_int_array(GLint size, GLsizei offset); void set_uint_array(GLint size, GLsizei offset); }; } #endif