2018-09-26 00:10:09 +00:00
|
|
|
#include "data/modelData.h"
|
2018-12-19 07:53:51 +00:00
|
|
|
#include "graphics/opengl.h"
|
2019-09-07 22:07:07 +00:00
|
|
|
#include "core/map.h"
|
2018-07-04 20:51:35 +00:00
|
|
|
#include <stdbool.h>
|
2017-03-11 22:13:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2018-12-08 03:11:14 +00:00
|
|
|
#define MAX_ATTRIBUTES 16
|
2019-02-14 01:20:43 +00:00
|
|
|
#define MAX_ATTRIBUTE_NAME_LENGTH 32
|
2018-12-08 03:11:14 +00:00
|
|
|
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Buffer;
|
|
|
|
struct Material;
|
|
|
|
|
2018-12-08 03:11:14 +00:00
|
|
|
typedef struct {
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Buffer* buffer;
|
2019-01-27 22:29:06 +00:00
|
|
|
uint32_t offset;
|
|
|
|
unsigned stride : 8;
|
|
|
|
unsigned divisor : 8;
|
|
|
|
unsigned type : 3; // AttributeType
|
|
|
|
unsigned components : 3;
|
|
|
|
unsigned normalized : 1;
|
|
|
|
unsigned integer : 1;
|
|
|
|
unsigned disabled : 1;
|
2018-12-08 03:11:14 +00:00
|
|
|
} MeshAttribute;
|
|
|
|
|
2019-04-05 11:58:29 +00:00
|
|
|
typedef struct Mesh {
|
2018-12-19 07:53:51 +00:00
|
|
|
DrawMode mode;
|
2019-02-14 01:20:43 +00:00
|
|
|
char attributeNames[MAX_ATTRIBUTES][MAX_ATTRIBUTE_NAME_LENGTH];
|
2019-01-27 22:29:06 +00:00
|
|
|
MeshAttribute attributes[MAX_ATTRIBUTES];
|
|
|
|
uint8_t locations[MAX_ATTRIBUTES];
|
|
|
|
uint16_t enabledLocations;
|
|
|
|
uint16_t divisors[MAX_ATTRIBUTES];
|
2019-09-07 22:07:07 +00:00
|
|
|
map_t attributeMap;
|
2019-05-21 03:35:07 +00:00
|
|
|
uint32_t attributeCount;
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Buffer* vertexBuffer;
|
|
|
|
struct Buffer* indexBuffer;
|
2018-12-27 21:50:42 +00:00
|
|
|
uint32_t vertexCount;
|
2018-12-19 07:53:51 +00:00
|
|
|
uint32_t indexCount;
|
|
|
|
size_t indexSize;
|
2019-01-17 22:14:13 +00:00
|
|
|
size_t indexOffset;
|
2018-12-27 21:50:42 +00:00
|
|
|
uint32_t drawStart;
|
|
|
|
uint32_t drawCount;
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Material* material;
|
2018-12-19 07:53:51 +00:00
|
|
|
GPU_MESH_FIELDS
|
|
|
|
} Mesh;
|
2018-03-04 22:07:54 +00:00
|
|
|
|
2019-04-05 11:58:29 +00:00
|
|
|
Mesh* lovrMeshInit(Mesh* mesh, DrawMode mode, struct Buffer* vertexBuffer, uint32_t vertexCount);
|
2018-12-19 08:25:20 +00:00
|
|
|
#define lovrMeshCreate(...) lovrMeshInit(lovrAlloc(Mesh), __VA_ARGS__)
|
2018-02-26 08:59:03 +00:00
|
|
|
void lovrMeshDestroy(void* ref);
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Buffer* lovrMeshGetVertexBuffer(Mesh* mesh);
|
|
|
|
struct Buffer* lovrMeshGetIndexBuffer(Mesh* mesh);
|
|
|
|
void lovrMeshSetIndexBuffer(Mesh* mesh, struct Buffer* buffer, uint32_t indexCount, size_t indexSize, size_t offset);
|
2018-12-27 21:50:42 +00:00
|
|
|
uint32_t lovrMeshGetVertexCount(Mesh* mesh);
|
|
|
|
uint32_t lovrMeshGetIndexCount(Mesh* mesh);
|
|
|
|
size_t lovrMeshGetIndexSize(Mesh* mesh);
|
2018-12-08 03:11:14 +00:00
|
|
|
void lovrMeshAttachAttribute(Mesh* mesh, const char* name, MeshAttribute* attribute);
|
2018-03-13 23:12:12 +00:00
|
|
|
void lovrMeshDetachAttribute(Mesh* mesh, const char* name);
|
2019-01-27 22:29:06 +00:00
|
|
|
const MeshAttribute* lovrMeshGetAttribute(Mesh* mesh, const char* name);
|
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-12-27 21:50:42 +00:00
|
|
|
DrawMode lovrMeshGetDrawMode(Mesh* mesh);
|
|
|
|
void lovrMeshSetDrawMode(Mesh* mesh, DrawMode mode);
|
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);
|
2019-04-05 11:58:29 +00:00
|
|
|
struct Material* lovrMeshGetMaterial(Mesh* mesh);
|
|
|
|
void lovrMeshSetMaterial(Mesh* mesh, struct Material* material);
|