scenewalker-libretro/engine/mesh.hpp

107 lines
2.9 KiB
C++
Raw Permalink Normal View History

2013-11-27 20:56:41 +00:00
/*
* Scenewalker Tech demo
* Copyright (C) 2013 - Hans-Kristian Arntzen
* Copyright (C) 2013 - Daniel De Matteis
*
* InstancingViewer is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* InstancingViewer 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with InstancingViewer.
* If not, see <http://www.gnu.org/licenses/>.
*/
2013-05-10 16:59:30 +00:00
#ifndef MESH_HPP__
#define MESH_HPP__
#include "gl.hpp"
#include "shader.hpp"
#include "texture.hpp"
#include <vector>
#include <cstddef>
#include <memory>
#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
#include "glm/gtc/type_ptr.hpp"
#include "shared.hpp"
2013-05-10 16:59:30 +00:00
namespace GL
{
struct Vertex
{
glm::vec3 vert;
glm::vec3 normal;
glm::vec2 tex;
2013-05-10 16:59:30 +00:00
};
struct Material
{
Material() :
ambient(0, 0, 0),
diffuse(0, 0, 0),
specular(0, 0, 0),
specular_power(60.0),
alpha_mod(1.0f)
{}
glm::vec3 ambient;
glm::vec3 diffuse;
glm::vec3 specular;
float specular_power;
float alpha_mod;
std1::shared_ptr<Texture> diffuse_map;
2013-05-12 11:28:39 +00:00
std1::shared_ptr<Texture> ambient_map;
};
2013-05-10 16:59:30 +00:00
class Mesh
{
public:
Mesh();
~Mesh();
std1::shared_ptr<std::vector<Vertex> > get_vertex() const { return vertex; }
2013-05-14 00:33:51 +00:00
const Material& get_material() const { return material; }
void set_vertices(std::vector<Vertex> vertex);
void set_vertices(const std1::shared_ptr<std::vector<Vertex> >& vertex);
void set_vertex_type(GLenum type);
void set_material(const Material& material);
2013-05-12 19:46:08 +00:00
void set_blank(const std1::shared_ptr<Texture>& blank);
void set_shader(const std1::shared_ptr<Shader>& shader);
2013-05-10 16:59:30 +00:00
void set_model(const glm::mat4& model);
void set_view(const glm::mat4& view);
void set_projection(const glm::mat4& projection);
2013-05-14 00:07:53 +00:00
void set_eye(const glm::vec3& eye_pos);
2013-05-10 16:59:30 +00:00
2013-05-14 00:07:53 +00:00
void set_light_pos(const glm::vec3& light_pos);
void set_light_ambient(const glm::vec3& light_ambient);
2013-05-10 16:59:30 +00:00
void render();
private:
GLuint vbo;
GLenum vertex_type;
std1::shared_ptr<std::vector<Vertex> > vertex;
std1::shared_ptr<Shader> shader;
2013-05-12 19:46:08 +00:00
std1::shared_ptr<Texture> blank;
Material material;
2013-05-14 00:07:53 +00:00
glm::vec3 light_pos;
glm::vec3 light_ambient;
2013-05-14 00:07:53 +00:00
glm::vec3 eye_pos;
2013-05-10 16:59:30 +00:00
glm::mat4 model;
glm::mat4 view;
glm::mat4 projection;
glm::mat4 mvp;
};
}
#endif