couch/core/Mesh.h

112 lines
2.8 KiB
C
Raw Permalink Normal View History

2021-01-27 15:15:40 -06:00
/**
@file
@author Dane Johnson <dane@danejohnson.org>
@section LICENSE
Couch Copyright (C) 2021 Dane Johnson
This program comes with ABSOLUTELY NO WARRANTY; without event the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for details at
https://www.gnu.org/licenses/gpl-3.0.html
This is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License as published
by the Free Software Foundation; either version 3 of the License,
or (at your option) any later version.
@section DESCRIPTION
Meshes and their subclasses are anything that can be rendered
on screen. They are divided into submeshes, each of which
can have its own material properties.
*/
2021-01-13 10:42:57 -06:00
#ifndef MESH_H
#define MESH_H
2021-01-20 14:54:54 -06:00
#include <vector>
2021-01-30 15:34:27 -06:00
#include <exception>
2021-01-18 18:25:47 -06:00
2021-01-13 10:42:57 -06:00
#include "types.h"
2021-01-14 11:52:01 -06:00
#include "Spatial.h"
2021-01-13 10:42:57 -06:00
#include "Vertex.h"
#include "Index.h"
#include "Material.h"
2021-01-13 10:42:57 -06:00
2021-01-20 14:54:54 -06:00
#include "Shaders/Shader.h"
class SubMesh {
2021-01-13 10:42:57 -06:00
public:
2021-01-20 14:54:54 -06:00
SubMesh();
SubMesh(VertexList vertices, IndexList indices);
2021-01-13 10:42:57 -06:00
VertexList vertices;
IndexList indices;
2021-01-20 15:16:44 -06:00
Material material;
2021-01-20 14:54:54 -06:00
void Draw(Shader *shader);
2021-01-24 16:37:35 -06:00
SubMesh *Duplicate();
2021-01-20 14:54:54 -06:00
private:
Id VAO, VBO, EBO;
void SetupSubMesh();
friend class Mesh;
2021-01-20 14:54:54 -06:00
};
typedef std::vector<SubMesh*> SubMeshList;
2021-01-27 15:15:40 -06:00
/**
Mesh and its subclasses are anything that can be rendered on screen.
A mesh is made up of submeshes, each of which can have one material
property.
*/
2021-01-20 14:54:54 -06:00
class Mesh : public Spatial {
public:
~Mesh();
2021-01-27 15:15:40 -06:00
/**
@return The number of submeshes this mesh is made up of
*/
int GetNumSubmeshes();
/**
Get the material property of a submesh
@param submesh The index of the submesh who's material is desired
@return The material property
*/
2021-01-20 20:49:12 -06:00
Material GetMaterial(int submesh);
2021-01-27 15:15:40 -06:00
/**
Set the material property of a submesh
@param submesh The index of the submesh to update
@param material The desired material property
*/
2021-01-20 15:16:44 -06:00
void SetMaterial(int submesh, Material material);
2021-01-27 15:15:40 -06:00
/**
Create a new mesh from a Wavefront file.
A submesh will be generated for each material on the mesh.
Material properties will be generated based on the .mat
file, if present
@param filename The name of the file containing the mesh.
@return A new mesh prefab
*/
2021-01-18 18:25:47 -06:00
static Mesh *FromFile(const char *filename);
2021-01-27 15:15:40 -06:00
/**
Draw this mesh, by calling Draw on all submeshes.
The shader will be updated on each call to the material
property of the submesh
@param shader The shader program to use to draw
*/
2021-01-20 14:54:54 -06:00
virtual void Draw(Shader *shader);
2021-01-27 15:15:40 -06:00
2021-01-24 16:37:35 -06:00
virtual Mesh *Create();
virtual Mesh *Duplicate();
virtual Mesh *Instance();
2021-01-27 15:15:40 -06:00
virtual Name GetType() const;
2021-01-20 14:54:54 -06:00
protected:
SubMeshList submeshes;
virtual void SetupMesh();
2021-01-30 19:39:25 -06:00
friend class MeshCollisionShape;
2021-01-13 10:42:57 -06:00
};
#endif /* MESH_H */