89 lines
2.7 KiB
C++
89 lines
2.7 KiB
C++
/**
|
|
This file is a part of our_dick
|
|
Copyright (C) 2022 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 "ttt/board_gfx.hpp"
|
|
#include "ttt/board.hpp"
|
|
|
|
board_gfx::board_gfx(gfx::resource_manager& resman):
|
|
m_vbo((16 * sizeof(GLfloat) + 4 * sizeof(GLfloat) + 1 * sizeof(GLint)) * 9, gfx::ogl::buffer::usage::DYNAMIC_DRAW)
|
|
{
|
|
auto result = resman.emplace_texture_array("board_textures", 3);
|
|
m_textures = std::move(result.first);
|
|
if(result.second){
|
|
(*m_textures)[0].set_image(egn::image("assets/images/blank.jpg", true));
|
|
(*m_textures)[1].set_image(egn::image("assets/images/o.jpg", true));
|
|
(*m_textures)[2].set_image(egn::image("assets/images/x.jpg", true));
|
|
}
|
|
|
|
m_vao.bind_buffer(m_vbo, 0, 0, sizeof(GLfloat)*16 + sizeof(GLfloat)*4 + sizeof(GLint));
|
|
|
|
auto attrib = m_vao.get_attribute(2);
|
|
attrib.set_float_array(4, 0);
|
|
attrib.associate_with(0);
|
|
attrib.enable();
|
|
|
|
attrib = m_vao.get_attribute(3);
|
|
attrib.set_float_array(4, sizeof(GLfloat)*4);
|
|
attrib.associate_with(0);
|
|
attrib.enable();
|
|
|
|
attrib = m_vao.get_attribute(4);
|
|
attrib.set_float_array(4, sizeof(GLfloat)*8);
|
|
attrib.associate_with(0);
|
|
attrib.enable();
|
|
|
|
attrib = m_vao.get_attribute(5);
|
|
attrib.set_float_array(4, sizeof(GLfloat)*12);
|
|
attrib.associate_with(0);
|
|
attrib.enable();
|
|
|
|
attrib = m_vao.get_attribute(0);
|
|
attrib.set_int_array(1, sizeof(GLfloat)*16);
|
|
attrib.associate_with(0);
|
|
attrib.enable();
|
|
|
|
attrib = m_vao.get_attribute(1);
|
|
attrib.set_float_array(4, sizeof(GLfloat)*16 + sizeof(GLint));
|
|
attrib.associate_with(0);
|
|
attrib.enable();
|
|
}
|
|
|
|
void board_gfx::set_uniforms(gfx::ogl::shader_program& sh){
|
|
sh.get_uniform("textures").set(*m_textures, 0);
|
|
}
|
|
void board_gfx::bind_buffers(void){
|
|
m_vao.bind();
|
|
}
|
|
|
|
void board_gfx::buffer_tiles(const tile* t){
|
|
m_vbo.clear();
|
|
for(int i = 0;i < 9;++i){
|
|
GLint tex_id = (GLint)t[i].get_value();
|
|
m_vbo.buffer(t[i].model_matrix().raw(), sizeof(GLfloat)*16);
|
|
m_vbo.buffer(&tex_id, sizeof(GLint));
|
|
m_vbo.buffer(t[i].get_color().raw(), sizeof(GLfloat)*4);
|
|
}
|
|
}
|
|
|
|
void board_gfx::render(gfx::ogl::shader_program& shader){
|
|
set_uniforms(shader);
|
|
bind_buffers();
|
|
glDrawArrays(GL_POINTS, 0, 9);
|
|
}
|
|
|