1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-05 13:53:38 +00:00
lovr/src/graphics/mesh.h

82 lines
2.3 KiB
C
Raw Normal View History

#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"
#include "lib/glfw.h"
#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
#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,
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;
typedef struct Mesh Mesh;
2017-03-11 22:13:49 +00:00
typedef struct {
Mesh* mesh;
int attributeIndex;
int divisor;
bool enabled;
} MeshAttachment;
typedef map_t(MeshAttachment) map_attachment_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-10-31 08:14:09 +00:00
bool isMapped;
2017-03-12 01:27:18 +00:00
int mapStart;
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;
Material* material;
map_attachment_t attachments;
MeshAttachment layout[16];
bool isAttachment;
};
2017-03-11 22:13:49 +00:00
Mesh* lovrMeshCreate(VertexData* vertexData, MeshDrawMode drawMode, MeshUsage usage);
2018-02-26 08:59:03 +00:00
void lovrMeshDestroy(void* ref);
void lovrMeshAttachAttribute(Mesh* mesh, Mesh* other, const char* name, int divisor);
void lovrMeshDetachAttribute(Mesh* mesh, const char* name);
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);
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);
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);