2017-03-11 22:13:49 +00:00
|
|
|
#include "util.h"
|
2017-03-11 23:15:00 +00:00
|
|
|
#include "graphics/shader.h"
|
2017-03-11 22:13:49 +00:00
|
|
|
#include "graphics/texture.h"
|
|
|
|
#include "math/math.h"
|
2017-04-13 02:48:17 +00:00
|
|
|
#include "lib/glfw.h"
|
2017-03-11 22:13:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MESH_POINTS = GL_POINTS,
|
|
|
|
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;
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
MESH_FLOAT = GL_FLOAT,
|
2017-10-24 02:24:23 +00:00
|
|
|
MESH_BYTE = GL_UNSIGNED_BYTE,
|
2017-03-11 22:13:49 +00:00
|
|
|
MESH_INT = GL_INT
|
|
|
|
} MeshAttributeType;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
const char* name;
|
|
|
|
MeshAttributeType type;
|
|
|
|
int count;
|
|
|
|
} MeshAttribute;
|
|
|
|
|
|
|
|
typedef vec_t(MeshAttribute) MeshFormat;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Ref ref;
|
2017-06-18 23:19:26 +00:00
|
|
|
void* data;
|
2017-08-02 09:06:36 +00:00
|
|
|
size_t count;
|
2017-03-11 22:13:49 +00:00
|
|
|
int stride;
|
2017-03-11 22:47:13 +00:00
|
|
|
int enabledAttributes;
|
2017-03-11 23:15:00 +00:00
|
|
|
int attributesDirty;
|
2017-03-12 01:27:18 +00:00
|
|
|
int isMapped;
|
|
|
|
int mapStart;
|
2017-08-02 09:06:36 +00:00
|
|
|
size_t mapCount;
|
2017-03-11 22:13:49 +00:00
|
|
|
MeshFormat format;
|
|
|
|
MeshDrawMode drawMode;
|
|
|
|
MeshUsage usage;
|
|
|
|
GLuint vao;
|
|
|
|
GLuint vbo;
|
|
|
|
GLuint ibo;
|
2017-10-22 14:04:52 +00:00
|
|
|
void* indices;
|
|
|
|
size_t indexCount;
|
|
|
|
size_t indexSize;
|
2017-03-11 22:30:39 +00:00
|
|
|
int isRangeEnabled;
|
2017-03-11 22:13:49 +00:00
|
|
|
int rangeStart;
|
|
|
|
int rangeCount;
|
2017-03-11 23:15:00 +00:00
|
|
|
Shader* lastShader;
|
2017-03-11 22:13:49 +00:00
|
|
|
} Mesh;
|
|
|
|
|
2017-08-02 09:06:36 +00:00
|
|
|
Mesh* lovrMeshCreate(size_t count, MeshFormat* format, MeshDrawMode drawMode, MeshUsage usage);
|
2017-03-11 22:13:49 +00:00
|
|
|
void lovrMeshDestroy(const Ref* ref);
|
2017-03-11 22:28:44 +00:00
|
|
|
void lovrMeshDraw(Mesh* mesh, mat4 transform);
|
|
|
|
MeshFormat lovrMeshGetVertexFormat(Mesh* mesh);
|
|
|
|
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);
|
|
|
|
int lovrMeshGetVertexSize(Mesh* mesh);
|
2017-10-22 14:04:52 +00:00
|
|
|
void* lovrMeshGetVertexMap(Mesh* mesh, size_t* count);
|
|
|
|
void lovrMeshSetVertexMap(Mesh* mesh, void* data, size_t count);
|
2017-03-11 22:47:13 +00:00
|
|
|
int lovrMeshIsAttributeEnabled(Mesh* mesh, const char* name);
|
|
|
|
void lovrMeshSetAttributeEnabled(Mesh* mesh, const char* name, int enabled);
|
2017-03-11 22:30:39 +00:00
|
|
|
int 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-03-11 22:28:44 +00:00
|
|
|
Texture* lovrMeshGetTexture(Mesh* mesh);
|
|
|
|
void lovrMeshSetTexture(Mesh* mesh, Texture* texture);
|
2017-08-02 09:06:36 +00:00
|
|
|
void* lovrMeshMap(Mesh* mesh, int start, size_t count, int read, int write);
|
2017-03-12 01:27:18 +00:00
|
|
|
void lovrMeshUnmap(Mesh* mesh);
|