mirror of https://github.com/bjornbytes/lovr.git
Rename primitive data structures;
This commit is contained in:
parent
88a32fd951
commit
76f94e8ade
|
@ -62,11 +62,11 @@ void lovrGraphicsInit() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Allocations
|
// Allocations
|
||||||
glGenBuffers(1, &state.buffer.vbo);
|
glGenBuffers(1, &state.streamVBO);
|
||||||
glGenBuffers(1, &state.buffer.ibo);
|
glGenBuffers(1, &state.streamIBO);
|
||||||
glGenVertexArrays(1, &state.buffer.vao);
|
glGenVertexArrays(1, &state.streamVAO);
|
||||||
vec_init(&state.buffer.data);
|
vec_init(&state.streamData);
|
||||||
vec_init(&state.buffer.indices);
|
vec_init(&state.streamIndices);
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
state.depthTest = -1;
|
state.depthTest = -1;
|
||||||
|
@ -95,11 +95,11 @@ void lovrGraphicsDestroy() {
|
||||||
lovrRelease(&state.skyboxShader->ref);
|
lovrRelease(&state.skyboxShader->ref);
|
||||||
lovrRelease(&state.fullscreenShader->ref);
|
lovrRelease(&state.fullscreenShader->ref);
|
||||||
lovrRelease(&state.defaultTexture->ref);
|
lovrRelease(&state.defaultTexture->ref);
|
||||||
glDeleteBuffers(1, &state.buffer.vbo);
|
glDeleteBuffers(1, &state.streamVBO);
|
||||||
glDeleteBuffers(1, &state.buffer.ibo);
|
glDeleteBuffers(1, &state.streamIBO);
|
||||||
glDeleteVertexArrays(1, &state.buffer.vao);
|
glDeleteVertexArrays(1, &state.streamVAO);
|
||||||
vec_deinit(&state.buffer.data);
|
vec_deinit(&state.streamData);
|
||||||
vec_deinit(&state.buffer.indices);
|
vec_deinit(&state.streamIndices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrGraphicsReset() {
|
void lovrGraphicsReset() {
|
||||||
|
@ -395,25 +395,25 @@ void lovrGraphicsMatrixTransform(mat4 transform) {
|
||||||
// Primitives
|
// Primitives
|
||||||
|
|
||||||
static void lovrGraphicsSetShapeData(float* data, int length) {
|
static void lovrGraphicsSetShapeData(float* data, int length) {
|
||||||
vec_clear(&state.buffer.data);
|
vec_clear(&state.streamData);
|
||||||
vec_pusharr(&state.buffer.data, data, length);
|
vec_pusharr(&state.streamData, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lovrGraphicsSetIndexData(unsigned int* data, int length) {
|
static void lovrGraphicsSetIndexData(unsigned int* data, int length) {
|
||||||
vec_clear(&state.buffer.indices);
|
vec_clear(&state.streamIndices);
|
||||||
vec_pusharr(&state.buffer.indices, data, length);
|
vec_pusharr(&state.streamIndices, data, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lovrGraphicsDrawPrimitive(GLenum mode, int hasNormals, int hasTexCoords, int useIndices) {
|
static void lovrGraphicsDrawPrimitive(GLenum mode, int hasNormals, int hasTexCoords, int useIndices) {
|
||||||
int stride = 3 + (hasNormals ? 3 : 0) + (hasTexCoords ? 2 : 0);
|
int stride = 3 + (hasNormals ? 3 : 0) + (hasTexCoords ? 2 : 0);
|
||||||
int strideBytes = stride * sizeof(float);
|
int strideBytes = stride * sizeof(float);
|
||||||
float* data = state.buffer.data.data;
|
float* data = state.streamData.data;
|
||||||
unsigned int* indices = state.buffer.indices.data;
|
unsigned int* indices = state.streamIndices.data;
|
||||||
|
|
||||||
lovrGraphicsPrepare();
|
lovrGraphicsPrepare();
|
||||||
lovrGraphicsBindVertexArray(state.buffer.vao);
|
lovrGraphicsBindVertexArray(state.streamVAO);
|
||||||
lovrGraphicsBindVertexBuffer(state.buffer.vbo);
|
lovrGraphicsBindVertexBuffer(state.streamVBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, state.buffer.data.length * sizeof(float), data, GL_STREAM_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, state.streamData.length * sizeof(float), data, GL_STREAM_DRAW);
|
||||||
glEnableVertexAttribArray(LOVR_SHADER_POSITION);
|
glEnableVertexAttribArray(LOVR_SHADER_POSITION);
|
||||||
glVertexAttribPointer(LOVR_SHADER_POSITION, 3, GL_FLOAT, GL_FALSE, strideBytes, (void*) 0);
|
glVertexAttribPointer(LOVR_SHADER_POSITION, 3, GL_FLOAT, GL_FALSE, strideBytes, (void*) 0);
|
||||||
|
|
||||||
|
@ -433,11 +433,11 @@ static void lovrGraphicsDrawPrimitive(GLenum mode, int hasNormals, int hasTexCoo
|
||||||
}
|
}
|
||||||
|
|
||||||
if (useIndices) {
|
if (useIndices) {
|
||||||
lovrGraphicsBindIndexBuffer(state.buffer.ibo);
|
lovrGraphicsBindIndexBuffer(state.streamIBO);
|
||||||
glBufferData(GL_ELEMENT_ARRAY_BUFFER, state.buffer.indices.length * sizeof(unsigned int), indices, GL_STREAM_DRAW);
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, state.streamIndices.length * sizeof(unsigned int), indices, GL_STREAM_DRAW);
|
||||||
glDrawElements(mode, state.buffer.indices.length, GL_UNSIGNED_INT, NULL);
|
glDrawElements(mode, state.streamIndices.length, GL_UNSIGNED_INT, NULL);
|
||||||
} else {
|
} else {
|
||||||
glDrawArrays(mode, 0, state.buffer.data.length / stride);
|
glDrawArrays(mode, 0, state.streamData.length / stride);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -620,15 +620,15 @@ void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, floa
|
||||||
int dataSize = stride * ((capped && r1) * (segments + 2) + (capped && r2) * (segments + 2) + 2 * (segments + 1));
|
int dataSize = stride * ((capped && r1) * (segments + 2) + (capped && r2) * (segments + 2) + 2 * (segments + 1));
|
||||||
int indexSize = 3 * segments * ((capped && r1) + (capped && r2) + 2);
|
int indexSize = 3 * segments * ((capped && r1) + (capped && r2) + 2);
|
||||||
|
|
||||||
vec_clear(&state.buffer.data);
|
vec_clear(&state.streamData);
|
||||||
vec_reserve(&state.buffer.data, dataSize);
|
vec_reserve(&state.streamData, dataSize);
|
||||||
state.buffer.data.length = 0;
|
state.streamData.length = 0;
|
||||||
float* data = state.buffer.data.data;
|
float* data = state.streamData.data;
|
||||||
|
|
||||||
vec_clear(&state.buffer.indices);
|
vec_clear(&state.streamIndices);
|
||||||
vec_reserve(&state.buffer.indices, indexSize);
|
vec_reserve(&state.streamIndices, indexSize);
|
||||||
state.buffer.indices.length = 0;
|
state.streamIndices.length = 0;
|
||||||
unsigned int* indices = state.buffer.indices.data;
|
unsigned int* indices = state.streamIndices.data;
|
||||||
|
|
||||||
vec3_init(p, n);
|
vec3_init(p, n);
|
||||||
|
|
||||||
|
@ -647,20 +647,20 @@ void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, floa
|
||||||
vec3_normalize(axis);
|
vec3_normalize(axis);
|
||||||
|
|
||||||
#define PUSH_CYLINDER_VERTEX(x, y, z, nx, ny, nz) \
|
#define PUSH_CYLINDER_VERTEX(x, y, z, nx, ny, nz) \
|
||||||
data[state.buffer.data.length++] = x; \
|
data[state.streamData.length++] = x; \
|
||||||
data[state.buffer.data.length++] = y; \
|
data[state.streamData.length++] = y; \
|
||||||
data[state.buffer.data.length++] = z; \
|
data[state.streamData.length++] = z; \
|
||||||
data[state.buffer.data.length++] = nx; \
|
data[state.streamData.length++] = nx; \
|
||||||
data[state.buffer.data.length++] = ny; \
|
data[state.streamData.length++] = ny; \
|
||||||
data[state.buffer.data.length++] = nz;
|
data[state.streamData.length++] = nz;
|
||||||
|
|
||||||
#define PUSH_CYLINDER_TRIANGLE(i1, i2, i3) \
|
#define PUSH_CYLINDER_TRIANGLE(i1, i2, i3) \
|
||||||
indices[state.buffer.indices.length++] = i1; \
|
indices[state.streamIndices.length++] = i1; \
|
||||||
indices[state.buffer.indices.length++] = i2; \
|
indices[state.streamIndices.length++] = i2; \
|
||||||
indices[state.buffer.indices.length++] = i3;
|
indices[state.streamIndices.length++] = i3;
|
||||||
|
|
||||||
// Ring
|
// Ring
|
||||||
int ringOffset = state.buffer.data.length / 6;
|
int ringOffset = state.streamData.length / 6;
|
||||||
for (int i = 0; i <= segments; i++) {
|
for (int i = 0; i <= segments; i++) {
|
||||||
float theta = i * (2 * M_PI) / segments;
|
float theta = i * (2 * M_PI) / segments;
|
||||||
|
|
||||||
|
@ -673,7 +673,7 @@ void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, floa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Top
|
// Top
|
||||||
int topOffset = state.buffer.data.length / 6;
|
int topOffset = state.streamData.length / 6;
|
||||||
if (capped && r1 != 0) {
|
if (capped && r1 != 0) {
|
||||||
PUSH_CYLINDER_VERTEX(x1, y1, z1, axis[0], axis[1], axis[2]);
|
PUSH_CYLINDER_VERTEX(x1, y1, z1, axis[0], axis[1], axis[2]);
|
||||||
|
|
||||||
|
@ -684,7 +684,7 @@ void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, floa
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom
|
// Bottom
|
||||||
int bottomOffset = state.buffer.data.length / 6;
|
int bottomOffset = state.streamData.length / 6;
|
||||||
if (capped && r2 != 0) {
|
if (capped && r2 != 0) {
|
||||||
PUSH_CYLINDER_VERTEX(x2, y2, z2, -axis[0], -axis[1], -axis[2]);
|
PUSH_CYLINDER_VERTEX(x2, y2, z2, -axis[0], -axis[1], -axis[2]);
|
||||||
|
|
||||||
|
@ -716,8 +716,8 @@ void lovrGraphicsCylinder(float x1, float y1, float z1, float x2, float y2, floa
|
||||||
}
|
}
|
||||||
|
|
||||||
void lovrGraphicsSphere(Texture* texture, mat4 transform, int segments, Skybox* skybox) {
|
void lovrGraphicsSphere(Texture* texture, mat4 transform, int segments, Skybox* skybox) {
|
||||||
vec_clear(&state.buffer.data);
|
vec_clear(&state.streamData);
|
||||||
vec_clear(&state.buffer.indices);
|
vec_clear(&state.streamIndices);
|
||||||
|
|
||||||
for (int i = 0; i <= segments; i++) {
|
for (int i = 0; i <= segments; i++) {
|
||||||
float v = i / (float) segments;
|
float v = i / (float) segments;
|
||||||
|
@ -728,18 +728,18 @@ void lovrGraphicsSphere(Texture* texture, mat4 transform, int segments, Skybox*
|
||||||
float y = cos(v * M_PI);
|
float y = cos(v * M_PI);
|
||||||
float z = sin(u * 2 * M_PI) * sin(v * M_PI);
|
float z = sin(u * 2 * M_PI) * sin(v * M_PI);
|
||||||
|
|
||||||
vec_push(&state.buffer.data, x);
|
vec_push(&state.streamData, x);
|
||||||
vec_push(&state.buffer.data, y);
|
vec_push(&state.streamData, y);
|
||||||
vec_push(&state.buffer.data, z);
|
vec_push(&state.streamData, z);
|
||||||
|
|
||||||
if (!skybox) {
|
if (!skybox) {
|
||||||
vec_push(&state.buffer.data, x);
|
vec_push(&state.streamData, x);
|
||||||
vec_push(&state.buffer.data, y);
|
vec_push(&state.streamData, y);
|
||||||
vec_push(&state.buffer.data, z);
|
vec_push(&state.streamData, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
vec_push(&state.buffer.data, u);
|
vec_push(&state.streamData, u);
|
||||||
vec_push(&state.buffer.data, v);
|
vec_push(&state.streamData, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -749,12 +749,12 @@ void lovrGraphicsSphere(Texture* texture, mat4 transform, int segments, Skybox*
|
||||||
for (int j = 0; j < segments; j++) {
|
for (int j = 0; j < segments; j++) {
|
||||||
unsigned int index0 = offset0 + j;
|
unsigned int index0 = offset0 + j;
|
||||||
unsigned int index1 = offset1 + j;
|
unsigned int index1 = offset1 + j;
|
||||||
vec_push(&state.buffer.indices, index0);
|
vec_push(&state.streamIndices, index0);
|
||||||
vec_push(&state.buffer.indices, index1);
|
vec_push(&state.streamIndices, index1);
|
||||||
vec_push(&state.buffer.indices, index0 + 1);
|
vec_push(&state.streamIndices, index0 + 1);
|
||||||
vec_push(&state.buffer.indices, index1);
|
vec_push(&state.streamIndices, index1);
|
||||||
vec_push(&state.buffer.indices, index1 + 1);
|
vec_push(&state.streamIndices, index1 + 1);
|
||||||
vec_push(&state.buffer.indices, index0 + 1);
|
vec_push(&state.streamIndices, index0 + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -859,7 +859,7 @@ void lovrGraphicsPrint(const char* str, mat4 transform, float wrap, HorizontalAl
|
||||||
Font* font = lovrGraphicsGetFont();
|
Font* font = lovrGraphicsGetFont();
|
||||||
float scale = 1 / font->pixelDensity;
|
float scale = 1 / font->pixelDensity;
|
||||||
float offsety;
|
float offsety;
|
||||||
lovrFontRender(font, str, wrap, halign, valign, &state.buffer.data, &offsety);
|
lovrFontRender(font, str, wrap, halign, valign, &state.streamData, &offsety);
|
||||||
|
|
||||||
lovrGraphicsPush();
|
lovrGraphicsPush();
|
||||||
lovrGraphicsMatrixTransform(transform);
|
lovrGraphicsMatrixTransform(transform);
|
||||||
|
|
|
@ -73,7 +73,6 @@ typedef struct {
|
||||||
Texture* defaultTexture;
|
Texture* defaultTexture;
|
||||||
float transforms[MAX_TRANSFORMS + INTERNAL_TRANSFORMS][16];
|
float transforms[MAX_TRANSFORMS + INTERNAL_TRANSFORMS][16];
|
||||||
int transform;
|
int transform;
|
||||||
|
|
||||||
Color backgroundColor;
|
Color backgroundColor;
|
||||||
BlendMode blendMode;
|
BlendMode blendMode;
|
||||||
BlendAlphaMode blendAlphaMode;
|
BlendAlphaMode blendAlphaMode;
|
||||||
|
@ -88,15 +87,11 @@ typedef struct {
|
||||||
Shader* shader;
|
Shader* shader;
|
||||||
Winding winding;
|
Winding winding;
|
||||||
int wireframe;
|
int wireframe;
|
||||||
|
uint32_t streamVAO;
|
||||||
struct {
|
uint32_t streamVBO;
|
||||||
GLuint vao;
|
uint32_t streamIBO;
|
||||||
GLuint vbo;
|
vec_float_t streamData;
|
||||||
GLuint ibo;
|
vec_uint_t streamIndices;
|
||||||
vec_float_t data;
|
|
||||||
vec_uint_t indices;
|
|
||||||
} buffer;
|
|
||||||
|
|
||||||
CanvasState canvases[MAX_CANVASES];
|
CanvasState canvases[MAX_CANVASES];
|
||||||
int canvas;
|
int canvas;
|
||||||
Texture* texture;
|
Texture* texture;
|
||||||
|
|
Loading…
Reference in New Issue