mirror of https://github.com/bjornbytes/lovr.git
Clean up;
This commit is contained in:
parent
671f0835c0
commit
21a869cc8b
|
@ -34,6 +34,7 @@ void lovrGraphicsDestroy() {
|
|||
}
|
||||
lovrGraphicsSetShader(NULL);
|
||||
lovrGraphicsSetFont(NULL);
|
||||
lovrGraphicsSetCanvas(NULL);
|
||||
for (int i = 0; i < MAX_DEFAULT_SHADERS; i++) {
|
||||
lovrRelease(state.defaultShaders[i]);
|
||||
}
|
||||
|
@ -128,10 +129,11 @@ void lovrGraphicsSetCamera(Camera* camera, bool clear) {
|
|||
if (!camera) {
|
||||
int width, height;
|
||||
lovrGraphicsGetDimensions(&width, &height);
|
||||
state.camera.stereo = false;
|
||||
state.camera.canvas = NULL;
|
||||
mat4_identity(state.camera.viewMatrix[0]);
|
||||
mat4_perspective(state.camera.projection[0], .01f, 100.f, 67 * M_PI / 180., (float) width / height);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
mat4_identity(state.camera.viewMatrix[i]);
|
||||
mat4_perspective(state.camera.projection[i], .01f, 100.f, 67 * M_PI / 180., (float) width / height);
|
||||
}
|
||||
} else {
|
||||
state.camera = *camera;
|
||||
}
|
||||
|
@ -152,6 +154,7 @@ void lovrGraphicsReset() {
|
|||
lovrGraphicsSetCamera(NULL, false);
|
||||
lovrGraphicsSetBackgroundColor((Color) { 0, 0, 0, 1 });
|
||||
lovrGraphicsSetBlendMode(BLEND_ALPHA, BLEND_ALPHA_MULTIPLY);
|
||||
lovrGraphicsSetCanvas(NULL);
|
||||
lovrGraphicsSetColor((Color) { 1, 1, 1, 1 });
|
||||
lovrGraphicsSetCullingEnabled(false);
|
||||
lovrGraphicsSetDefaultFilter((TextureFilter) { .mode = FILTER_TRILINEAR });
|
||||
|
|
|
@ -95,7 +95,6 @@ typedef struct {
|
|||
} GraphicsStats;
|
||||
|
||||
typedef struct {
|
||||
bool stereo;
|
||||
Canvas* canvas;
|
||||
float viewMatrix[2][16];
|
||||
float projection[2][16];
|
||||
|
|
|
@ -780,9 +780,6 @@ void lovrGpuDraw(DrawCommand* command) {
|
|||
#endif
|
||||
}
|
||||
|
||||
// Canvas
|
||||
lovrCanvasBind(canvas);
|
||||
|
||||
// Transform
|
||||
lovrShaderSetMatrices(shader, "lovrModel", command->transform, 0, 16);
|
||||
lovrShaderSetMatrices(shader, "lovrViews", command->camera.viewMatrix[0], 0, 32);
|
||||
|
@ -857,20 +854,22 @@ void lovrGpuDraw(DrawCommand* command) {
|
|||
// Bind attributes
|
||||
lovrMeshBind(mesh, shader);
|
||||
|
||||
bool stereo = canvas ? canvas->flags.stereo : command->camera.stereo;
|
||||
// Canvas
|
||||
bool stereo;
|
||||
int width, height;
|
||||
lovrCanvasBind(canvas);
|
||||
if (canvas) {
|
||||
stereo = canvas->flags.stereo;
|
||||
width = canvas->width;
|
||||
height = canvas->height;
|
||||
} else {
|
||||
stereo = true;
|
||||
lovrGraphicsGetDimensions(&width, &height);
|
||||
}
|
||||
int drawCount = 1 + (stereo == true && !state.singlepass);
|
||||
int viewWidth = width >> stereo;
|
||||
float viewports[2][4] = {
|
||||
{ 0, 0, viewWidth, height },
|
||||
{ viewWidth, 0, viewWidth, height },
|
||||
};
|
||||
|
||||
width >>= stereo == true;
|
||||
float viewports[2][4] = { { 0, 0, width, height }, { width, 0, width, height } };
|
||||
int drawCount = 1 + (stereo && !state.singlepass);
|
||||
|
||||
// Draw (TODEW)
|
||||
for (int i = 0; i < drawCount; i++) {
|
||||
|
@ -1321,14 +1320,9 @@ void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count
|
|||
}
|
||||
|
||||
void lovrCanvasBind(Canvas* canvas) {
|
||||
if (!canvas) {
|
||||
lovrGpuBindFramebuffer(0);
|
||||
return;
|
||||
}
|
||||
lovrGpuBindFramebuffer(canvas ? canvas->framebuffer : 0);
|
||||
|
||||
lovrGpuBindFramebuffer(canvas->framebuffer);
|
||||
|
||||
if (!canvas->dirty) {
|
||||
if (!canvas->dirty || !canvas) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ static void fakeRenderTo(void (*callback)(void*), void* userdata) {
|
|||
|
||||
int width, height;
|
||||
fakeGetDisplayDimensions(&width, &height);
|
||||
Camera camera = { .canvas = NULL, .stereo = true };
|
||||
Camera camera = { .canvas = NULL };
|
||||
mat4_perspective(camera.projection[0], state.clipNear, state.clipFar, 67 * M_PI / 180., (float) width / height);
|
||||
mat4_identity(camera.viewMatrix[0]);
|
||||
mat4_translate(camera.viewMatrix[0], 0, state.offset, 0);
|
||||
|
|
|
@ -90,7 +90,7 @@ static void onFrame(float* leftView, float* rightView, float* leftProjection, fl
|
|||
int width, height;
|
||||
webvrGetDisplayDimensions(&width, &height);
|
||||
|
||||
Camera camera = { .canvas = NULL, .stereo = true };
|
||||
Camera camera = { .canvas = NULL };
|
||||
memcpy(camera.projection[0], leftProjection, 16 * sizeof(float));
|
||||
memcpy(camera.projection[1], rightProjection, 16 * sizeof(float));
|
||||
memcpy(camera.viewMatrix[0], leftView, 16 * sizeof(float));
|
||||
|
|
Loading…
Reference in New Issue