114 lines
2.8 KiB
C++
114 lines
2.8 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/>.
|
|
*/
|
|
|
|
#ifndef OUR_DICK_GRAPHICS_MESH_HPP
|
|
#define OUR_DICK_GRAPHICS_MESH_HPP
|
|
|
|
#include "math/vec.hpp"
|
|
#include "vao.hpp"
|
|
#include "vbo.hpp"
|
|
#include "shader_program.hpp"
|
|
#include "material.hpp"
|
|
|
|
#include <vector>
|
|
#include <cstdlib> //size_t
|
|
|
|
namespace gfx{
|
|
|
|
struct vertex {
|
|
math::vec3<float> position;
|
|
math::vec4<float> color;
|
|
math::vec2<float> tex_coords;
|
|
};
|
|
|
|
class vertex_mesh
|
|
{
|
|
protected:
|
|
std::vector<vertex> m_vertices;
|
|
|
|
gfx::vao m_vao;
|
|
gfx::vbo m_vbo;
|
|
|
|
public:
|
|
vertex_mesh(const std::vector<vertex>& verts);
|
|
vertex_mesh(std::vector<vertex>&& verts);
|
|
vertex_mesh(const vertex* verts, size_t nverts);
|
|
|
|
vertex_mesh(const vertex_mesh&) = delete;
|
|
vertex_mesh(vertex_mesh&&) = default;
|
|
~vertex_mesh() = default;
|
|
|
|
vertex_mesh& operator=(const vertex_mesh&) = delete;
|
|
vertex_mesh& operator=(vertex_mesh&&) = default;
|
|
|
|
void configure();
|
|
|
|
const vertex& get_vertex(size_t index)const;
|
|
void set_vertex(size_t index, const vertex& v);
|
|
|
|
void render(shader_program& shader);
|
|
};
|
|
|
|
class material_mesh
|
|
{
|
|
protected:
|
|
std::vector<const material*> m_materials;
|
|
|
|
public:
|
|
material_mesh(const std::vector<const material*>& textures);
|
|
material_mesh(std::vector<const material*>&& textures);
|
|
material_mesh(const material** texs, size_t ntexs);
|
|
|
|
const material* get_material(size_t index)const;
|
|
void set_material(size_t index, const material& new_texture);
|
|
void set_material(size_t index, const material* new_texture);
|
|
|
|
void render(shader_program& shader);
|
|
};
|
|
|
|
class unified_mesh
|
|
{
|
|
protected:
|
|
vertex_mesh m_v_mesh;
|
|
material_mesh m_m_mesh;
|
|
|
|
public:
|
|
unified_mesh(vertex_mesh&& v, const material_mesh& m);
|
|
unified_mesh(vertex_mesh&& v, material_mesh&& m);
|
|
unified_mesh(const unified_mesh&) = delete; //vao is uncopiable
|
|
unified_mesh(unified_mesh&&) = default;
|
|
~unified_mesh() = default;
|
|
|
|
unified_mesh& operator=(const unified_mesh&) = delete;
|
|
unified_mesh& operator=(unified_mesh&&) = default;
|
|
|
|
vertex_mesh& vertex();
|
|
const vertex_mesh& vertex()const;
|
|
|
|
material_mesh& material();
|
|
const material_mesh& material()const;
|
|
|
|
void configure();
|
|
|
|
void render(shader_program& shader);
|
|
};
|
|
|
|
}
|
|
|
|
#endif
|