2017-03-11 23:15:00 +00:00
|
|
|
#include "graphics/shader.h"
|
2017-11-26 03:02:28 +00:00
|
|
|
#include "graphics/material.h"
|
2018-02-11 01:27:29 +00:00
|
|
|
#include "data/vertexData.h"
|
2017-03-11 22:13:49 +00:00
|
|
|
#include "math/math.h"
|
2017-04-13 02:48:17 +00:00
|
|
|
#include "lib/glfw.h"
|
2018-02-11 01:27:29 +00:00
|
|
|
#include "util.h"
|
2017-03-11 22:13:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MESH_POINTS = GL_POINTS,
|
2017-11-26 03:49:22 +00:00
|
|
|
MESH_LINES = GL_LINES,
|
|
|
|
MESH_LINE_STRIP = GL_LINE_STRIP,
|
2017-03-11 22:13:49 +00:00
|
|
|
MESH_TRIANGLE_STRIP = GL_TRIANGLE_STRIP,
|
|
|
|
MESH_TRIANGLES = GL_TRIANGLES,
|
|
|
|
MESH_TRIANGLE_FAN = GL_TRIANGLE_FAN
|
|
|
|
} MeshDrawMode;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MESH_STATIC = GL_STATIC_DRAW,
|
|
|
|
MESH_DYNAMIC = GL_DYNAMIC_DRAW,
|
|
|
|
MESH_STREAM = GL_STREAM_DRAW
|
|
|
|
} MeshUsage;
|
|
|
|
|
2018-03-04 22:07:54 +00:00
|
|
|
typedef struct Mesh Mesh;
|
|
|
|
|
2017-03-11 22:13:49 +00:00
|
|
|
typedef struct {
|
2018-03-04 22:07:54 +00:00
|
|
|
Mesh *mesh;
|
|
|
|
int attribute;
|
|
|
|
int instanceDivisor;
|
|
|
|
} MeshAttachment;
|
|
|
|
|
|
|
|
typedef vec_t(MeshAttachment) vec_meshattachment_t;
|
|
|
|
|
|
|
|
struct Mesh {
|
2017-03-11 22:13:49 +00:00
|
|
|
Ref ref;
|
2018-02-11 01:27:29 +00:00
|
|
|
VertexData* vertexData;
|
|
|
|
IndexPointer indices;
|
2018-01-27 20:51:41 +00:00
|
|
|
size_t indexCount;
|
|
|
|
size_t indexSize;
|
2017-03-11 22:47:13 +00:00
|
|
|
int enabledAttributes;
|
2017-10-31 08:14:09 +00:00
|
|
|
bool attributesDirty;
|
|
|
|
bool isMapped;
|
2017-03-12 01:27:18 +00:00
|
|
|
int mapStart;
|
2017-08-02 09:06:36 +00:00
|
|
|
size_t mapCount;
|
2018-01-27 20:51:41 +00:00
|
|
|
bool isRangeEnabled;
|
|
|
|
int rangeStart;
|
|
|
|
int rangeCount;
|
2017-03-11 22:13:49 +00:00
|
|
|
MeshDrawMode drawMode;
|
|
|
|
MeshUsage usage;
|
|
|
|
GLuint vao;
|
|
|
|
GLuint vbo;
|
|
|
|
GLuint ibo;
|
2017-11-26 03:02:28 +00:00
|
|
|
Material* material;
|
2017-03-11 23:15:00 +00:00
|
|
|
Shader* lastShader;
|
2018-03-04 22:07:54 +00:00
|
|
|
vec_meshattachment_t attachments;
|
|
|
|
bool isAnAttachment;
|
|
|
|
};
|
2017-03-11 22:13:49 +00:00
|
|
|
|
2018-03-11 18:24:11 +00:00
|
|
|
Mesh* lovrMeshCreate(VertexData* vertexData, MeshDrawMode drawMode, MeshUsage usage);
|
2018-02-26 08:59:03 +00:00
|
|
|
void lovrMeshDestroy(void* ref);
|
2017-11-26 03:45:44 +00:00
|
|
|
void lovrMeshDraw(Mesh* mesh, mat4 transform, float* pose, int instances);
|
2018-01-27 02:58:36 +00:00
|
|
|
VertexFormat* lovrMeshGetVertexFormat(Mesh* mesh);
|
2017-03-11 22:28:44 +00:00
|
|
|
MeshDrawMode lovrMeshGetDrawMode(Mesh* mesh);
|
2017-10-22 14:20:40 +00:00
|
|
|
void lovrMeshSetDrawMode(Mesh* mesh, MeshDrawMode drawMode);
|
2017-03-11 22:28:44 +00:00
|
|
|
int lovrMeshGetVertexCount(Mesh* mesh);
|
2018-02-11 01:27:29 +00:00
|
|
|
IndexPointer lovrMeshGetVertexMap(Mesh* mesh, size_t* count);
|
2017-10-22 14:04:52 +00:00
|
|
|
void lovrMeshSetVertexMap(Mesh* mesh, void* data, size_t count);
|
2017-10-31 08:14:09 +00:00
|
|
|
bool lovrMeshIsAttributeEnabled(Mesh* mesh, const char* name);
|
|
|
|
void lovrMeshSetAttributeEnabled(Mesh* mesh, const char* name, bool enabled);
|
|
|
|
bool lovrMeshIsRangeEnabled(Mesh* mesh);
|
2017-03-11 22:28:44 +00:00
|
|
|
void lovrMeshSetRangeEnabled(Mesh* mesh, char isEnabled);
|
|
|
|
void lovrMeshGetDrawRange(Mesh* mesh, int* start, int* count);
|
2017-10-22 14:20:40 +00:00
|
|
|
void lovrMeshSetDrawRange(Mesh* mesh, int start, int count);
|
2017-11-26 03:02:28 +00:00
|
|
|
Material* lovrMeshGetMaterial(Mesh* mesh);
|
|
|
|
void lovrMeshSetMaterial(Mesh* mesh, Material* material);
|
2018-02-11 01:27:29 +00:00
|
|
|
VertexPointer lovrMeshMap(Mesh* mesh, int start, size_t count, bool read, bool write);
|
2017-03-12 01:27:18 +00:00
|
|
|
void lovrMeshUnmap(Mesh* mesh);
|
2018-03-04 22:07:54 +00:00
|
|
|
void lovrMeshAttach(Mesh *attachTo, Mesh* attachThis, int attribute, int instanceDivisor);
|