247 lines
7.9 KiB
C++
247 lines
7.9 KiB
C++
/**
|
|
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/>.
|
|
*/
|
|
|
|
#include "graphics/vao.hpp"
|
|
#include <utility> //exchange, swap
|
|
|
|
namespace gfx{
|
|
|
|
void vertex_attribute::enable_array_mode(){
|
|
glBindVertexArray(m_vao);
|
|
glEnableVertexAttribArray(m_index);
|
|
}
|
|
void vertex_attribute::disable_array_mode(){
|
|
glBindVertexArray(m_vao);
|
|
glEnableVertexAttribArray(m_index);
|
|
}
|
|
void vertex_attribute::set_float_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * stride, (void*)(sizeof(GLfloat) * offset));
|
|
}
|
|
void vertex_attribute::set_double_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_DOUBLE, GL_FALSE, sizeof(GLdouble) * stride, (void*)(sizeof(GLdouble) * offset));
|
|
}
|
|
void vertex_attribute::set_byte_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_BYTE, GL_FALSE, sizeof(GLbyte) * stride, (void*)(sizeof(GLbyte) * offset));
|
|
}
|
|
void vertex_attribute::set_ubyte_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_UNSIGNED_BYTE, GL_FALSE, sizeof(GLubyte) * stride, (void*)(sizeof(GLubyte) * offset));
|
|
}
|
|
void vertex_attribute::set_short_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_SHORT, GL_FALSE, sizeof(GLshort) * stride, (void*)(sizeof(GLshort) * offset));
|
|
}
|
|
void vertex_attribute::set_ushort_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_UNSIGNED_SHORT, GL_FALSE, sizeof(GLushort) * stride, (void*)(sizeof(GLushort) * offset));
|
|
}
|
|
void vertex_attribute::set_int_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_INT, GL_FALSE, sizeof(GLint) * stride, (void*)(sizeof(GLint) * offset));
|
|
}
|
|
void vertex_attribute::set_uint_pointer(GLint size, GLsizei stride, GLsizei offset){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribPointer(m_index, size, GL_UNSIGNED_INT, GL_FALSE, sizeof(GLuint) * stride, (void*)(sizeof(GLuint) * offset));
|
|
}
|
|
void vertex_attribute::set(GLfloat x){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib1f(m_index, x);
|
|
}
|
|
void vertex_attribute::set(GLshort x){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib1s(m_index, x);
|
|
}
|
|
void vertex_attribute::set(GLdouble x){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib1d(m_index, x);
|
|
}
|
|
void vertex_attribute::set(GLint x){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI1i(m_index, x);
|
|
}
|
|
void vertex_attribute::set(GLuint x){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI1ui(m_index, x);
|
|
}
|
|
void vertex_attribute::set(GLfloat x, GLfloat y){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib2f(m_index, x, y);
|
|
}
|
|
void vertex_attribute::set(GLshort x, GLshort y){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib2s(m_index, x, y);
|
|
}
|
|
void vertex_attribute::set(GLdouble x, GLdouble y){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib2d(m_index, x, y);
|
|
}
|
|
void vertex_attribute::set(GLint x, GLint y){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI2i(m_index, x, y);
|
|
}
|
|
void vertex_attribute::set(GLuint x, GLuint y){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI2ui(m_index, x, y);
|
|
}
|
|
void vertex_attribute::set(GLfloat x, GLfloat y, GLfloat z){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib3f(m_index, x, y, z);
|
|
}
|
|
void vertex_attribute::set(GLshort x, GLshort y, GLshort z){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib3s(m_index, x, y, z);
|
|
}
|
|
void vertex_attribute::set(GLdouble x, GLdouble y, GLdouble z){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib3d(m_index, x, y, z);
|
|
}
|
|
void vertex_attribute::set(GLint x, GLint y, GLint z){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI3i(m_index, x, y, z);
|
|
}
|
|
void vertex_attribute::set(GLuint x, GLuint y, GLuint z){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI3ui(m_index, x, y, z);
|
|
}
|
|
void vertex_attribute::set(GLfloat x, GLfloat y, GLfloat z, GLfloat w){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4f(m_index, x, y, z, w);
|
|
}
|
|
void vertex_attribute::set(GLshort x, GLshort y, GLshort z, GLshort w){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4s(m_index, x, y, z, w);
|
|
}
|
|
void vertex_attribute::set(GLdouble x, GLdouble y, GLdouble z, GLdouble w){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4d(m_index, x, y, z, w);
|
|
}
|
|
void vertex_attribute::set(GLint x, GLint y, GLint z, GLint w){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI4i(m_index, x, y, z, w);
|
|
}
|
|
void vertex_attribute::set(GLuint x, GLuint y, GLuint z, GLuint w){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI4ui(m_index, x, y, z, w);
|
|
}
|
|
void vertex_attribute::set(const vec2<GLfloat>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib2fv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec2<GLshort>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib2sv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec2<GLdouble>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib2dv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec2<GLint>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI2iv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec2<GLuint>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI2uiv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec3<GLfloat>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib3fv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec3<GLshort>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib3sv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec3<GLdouble>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib3dv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec3<GLint>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI3iv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec3<GLuint>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttribI3uiv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLfloat>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4fv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLshort>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4sv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLdouble>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4dv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLint>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4iv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLuint>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4uiv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLbyte>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4bv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLubyte>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4ubv(m_index, v);
|
|
}
|
|
void vertex_attribute::set(const vec4<GLushort>& v){
|
|
glBindVertexArray(m_vao);
|
|
glVertexAttrib4usv(m_index, v);
|
|
}
|
|
|
|
|
|
vao::vao(){
|
|
glGenVertexArrays(1, &m_buffer);
|
|
}
|
|
vao::vao(vao&& v):
|
|
m_buffer(std::exchange(v.m_buffer, 0)){}
|
|
vao::~vao(){
|
|
if(m_buffer)
|
|
glDeleteVertexArrays(1, &m_buffer);
|
|
}
|
|
vao& vao::operator=(vao&& v){
|
|
std::swap(m_buffer, v.m_buffer);
|
|
return *this;
|
|
}
|
|
GLuint vao::raw()const{
|
|
return m_buffer;
|
|
}
|
|
|
|
vertex_attribute vao::get_attribute(int index){
|
|
return vertex_attribute(m_buffer, index);
|
|
}
|
|
void vao::bind(){
|
|
glBindVertexArray(m_buffer);
|
|
}
|
|
void vao::unbind(){
|
|
glBindVertexArray(0);
|
|
}
|
|
|
|
|
|
}
|