2017-11-26 03:02:28 +00:00
|
|
|
#include "graphics/material.h"
|
2018-03-22 15:45:05 +00:00
|
|
|
#include "graphics/shader.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-03-13 23:12:12 +00:00
|
|
|
#include "lib/map/map.h"
|
2018-02-11 01:27:29 +00:00
|
|
|
#include "util.h"
|
2017-03-11 22:13:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-03-13 23:12:12 +00:00
|
|
|
#define MAX_ATTACHMENTS 16
|
|
|
|
|
2017-03-11 22:13:49 +00:00
|
|
|
typedef enum {
|
|
|
|
MESH_POINTS = GL_POINTS,
|
2017-11-26 03:49:22 +00:00
|
|
|
MESH_LINES = GL_LINES,
|
|
|
|
MESH_LINE_STRIP = GL_LINE_STRIP,
|
2018-03-22 05:03:03 +00:00
|
|
|
MESH_LINE_LOOP = GL_LINE_LOOP,
|
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-13 23:12:12 +00:00
|
|
|
Mesh* mesh;
|
|
|
|
int attributeIndex;
|
|
|
|
int divisor;
|
|
|
|
bool enabled;
|
2018-03-04 22:07:54 +00:00
|
|
|
} MeshAttachment;
|
|
|
|
|
2018-03-13 23:12:12 +00:00
|
|
|
typedef map_t(MeshAttachment) map_attachment_t;
|
2018-03-04 22:07:54 +00:00
|
|
|
|
|
|
|
struct Mesh {
|
2017-03-11 22:13:49 +00:00
|
|
|
Ref ref;
|
2018-03-21 21:48:46 +00:00
|
|
|
uint32_t count;
|
|
|
|
VertexFormat format;
|
|
|
|
MeshDrawMode drawMode;
|
|
|
|
MeshUsage usage;
|
|
|
|
#ifdef EMSCRIPTEN
|
|
|
|
VertexPointer data;
|
2018-02-11 01:27:29 +00:00
|
|
|
IndexPointer indices;
|
2018-03-21 21:48:46 +00:00
|
|
|
#endif
|
|
|
|
uint32_t indexCount;
|
2018-01-27 20:51:41 +00:00
|
|
|
size_t indexSize;
|
2018-03-21 21:48:46 +00:00
|
|
|
size_t indexCapacity;
|
|
|
|
bool mappedIndices;
|
|
|
|
bool mappedVertices;
|
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
|
|
|
int rangeStart;
|
|
|
|
int rangeCount;
|
2017-03-11 22:13:49 +00:00
|
|
|
GLuint vao;
|
|
|
|
GLuint vbo;
|
|
|
|
GLuint ibo;
|
2017-11-26 03:02:28 +00:00
|
|
|
Material* material;
|
2018-03-22 15:45:05 +00:00
|
|
|
float* pose;
|
2018-03-13 23:12:12 +00:00
|
|
|
map_attachment_t attachments;
|
2018-03-21 21:48:46 +00:00
|
|
|
MeshAttachment layout[MAX_ATTACHMENTS];
|
2018-03-13 23:12:12 +00:00
|
|
|
bool isAttachment;
|
2018-03-04 22:07:54 +00:00
|
|
|
};
|
2017-03-11 22:13:49 +00:00
|
|
|
|
2018-03-21 21:48:46 +00:00
|
|
|
Mesh* lovrMeshCreate(uint32_t count, VertexFormat format, MeshDrawMode drawMode, MeshUsage usage);
|
2018-02-26 08:59:03 +00:00
|
|
|
void lovrMeshDestroy(void* ref);
|
2018-03-13 23:12:12 +00:00
|
|
|
void lovrMeshAttachAttribute(Mesh* mesh, Mesh* other, const char* name, int divisor);
|
|
|
|
void lovrMeshDetachAttribute(Mesh* mesh, const char* name);
|
2018-03-22 16:40:35 +00:00
|
|
|
void lovrMeshBind(Mesh* mesh, Shader* shader, bool stereo);
|
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);
|
2017-10-31 08:14:09 +00:00
|
|
|
bool lovrMeshIsAttributeEnabled(Mesh* mesh, const char* name);
|
|
|
|
void lovrMeshSetAttributeEnabled(Mesh* mesh, const char* name, bool enabled);
|
2017-03-11 22:28:44 +00:00
|
|
|
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-03-22 15:45:05 +00:00
|
|
|
float* lovrMeshGetPose(Mesh* mesh);
|
|
|
|
void lovrMeshSetPose(Mesh* mesh, float* pose);
|
2018-03-21 21:48:46 +00:00
|
|
|
VertexPointer lovrMeshMapVertices(Mesh* mesh, uint32_t start, uint32_t count, bool read, bool write);
|
|
|
|
void lovrMeshUnmapVertices(Mesh* mesh);
|
|
|
|
IndexPointer lovrMeshReadIndices(Mesh* mesh, uint32_t* count, size_t* size);
|
|
|
|
IndexPointer lovrMeshWriteIndices(Mesh* mesh, uint32_t count, size_t size);
|
|
|
|
void lovrMeshUnmapIndices(Mesh* mesh);
|
2018-03-22 05:03:03 +00:00
|
|
|
void lovrMeshResize(Mesh* mesh, uint32_t count);
|