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

89 lines
2.6 KiB
C
Raw Normal View History

#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"
#include "lib/glfw.h"
#include "lib/map/map.h"
2018-02-11 01:27:29 +00:00
#include "util.h"
2018-07-04 20:51:35 +00:00
#include <stdbool.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,
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;
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-03-21 21:48:46 +00:00
uint32_t count;
VertexFormat format;
MeshDrawMode drawMode;
MeshUsage usage;
VertexPointer data;
2018-02-11 01:27:29 +00:00
IndexPointer indices;
2018-03-21 21:48:46 +00:00
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;
2018-06-04 02:00:31 +00:00
uint32_t dirtyStart;
uint32_t dirtyEnd;
uint32_t rangeStart;
uint32_t rangeCount;
2017-03-11 22:13:49 +00:00
GLuint vao;
GLuint vbo;
GLuint ibo;
Material* material;
2018-03-22 15:45:05 +00:00
float* pose;
map_attachment_t attachments;
2018-03-21 21:48:46 +00:00
MeshAttachment layout[MAX_ATTACHMENTS];
bool isAttachment;
};
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);
void lovrMeshAttachAttribute(Mesh* mesh, Mesh* other, const char* name, int divisor);
void lovrMeshDetachAttribute(Mesh* mesh, const char* name);
void lovrMeshBind(Mesh* mesh, Shader* shader);
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);
2018-06-04 02:00:31 +00:00
void lovrMeshGetDrawRange(Mesh* mesh, uint32_t* start, uint32_t* count);
void lovrMeshSetDrawRange(Mesh* mesh, uint32_t start, uint32_t count);
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-06-04 02:00:31 +00:00
VertexPointer lovrMeshMapVertices(Mesh* mesh, uint32_t start, uint32_t count, bool read, bool write);
2018-03-21 21:48:46 +00:00
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);