mirror of https://github.com/bjornbytes/lovr.git
lovr.graphics.prepare;
This commit is contained in:
parent
9f254fc783
commit
1f0f586952
|
@ -1,4 +1,5 @@
|
|||
#include "buffer.h"
|
||||
#include "graphics.h"
|
||||
#include "../util.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
|
@ -11,6 +12,7 @@ void lovrBufferDestroy(Buffer* buffer) {
|
|||
}
|
||||
|
||||
void lovrBufferDraw(Buffer* buffer) {
|
||||
lovrGraphicsPrepare();
|
||||
glBindVertexArray(buffer->vao);
|
||||
glEnableVertexAttribArray(0);
|
||||
int usingIbo = buffer->map.length > 0;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
typedef struct {
|
||||
Shader* activeShader;
|
||||
vec_mat4_t transforms;
|
||||
mat4 lastTransform;
|
||||
} GraphicsState;
|
||||
|
||||
static GraphicsState graphicsState;
|
||||
|
@ -20,6 +21,8 @@ static GraphicsState graphicsState;
|
|||
void lovrGraphicsInit() {
|
||||
vec_init(&graphicsState.transforms);
|
||||
vec_push(&graphicsState.transforms, mat4_init());
|
||||
graphicsState.lastTransform = mat4_init();
|
||||
memset(graphicsState.lastTransform, 0, 16);
|
||||
}
|
||||
|
||||
void lovrGraphicsClear(int color, int depth) {
|
||||
|
@ -40,6 +43,25 @@ void lovrGraphicsPresent() {
|
|||
glfwSwapBuffers(window);
|
||||
}
|
||||
|
||||
void lovrGraphicsPrepare() {
|
||||
Shader* shader = lovrGraphicsGetShader();
|
||||
|
||||
if (!shader) {
|
||||
return;
|
||||
}
|
||||
|
||||
mat4 transform = vec_last(&graphicsState.transforms);
|
||||
mat4 lastTransform = graphicsState.lastTransform;
|
||||
|
||||
if (!memcmp(transform, lastTransform, 16 * sizeof(float))) {
|
||||
return;
|
||||
}
|
||||
|
||||
int uniformId = lovrShaderGetUniformId(shader, "lovrTransform");
|
||||
lovrShaderSendFloatMat4(shader, uniformId, transform);
|
||||
memcpy(lastTransform, transform, 16 * sizeof(float));
|
||||
}
|
||||
|
||||
void lovrGraphicsGetClearColor(float* r, float* g, float* b, float* a) {
|
||||
GLfloat clearColor[4];
|
||||
glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef vec_t(mat4) vec_mat4_t;
|
|||
void lovrGraphicsInit();
|
||||
void lovrGraphicsClear(int color, int depth);
|
||||
void lovrGraphicsPresent();
|
||||
void lovrGraphicsPrepare();
|
||||
void lovrGraphicsGetClearColor(float* r, float* g, float* b, float* a);
|
||||
void lovrGraphicsSetClearColor(float r, float g, float b, float a);
|
||||
Shader* lovrGraphicsGetShader();
|
||||
|
|
Loading…
Reference in New Issue