mirror of https://github.com/bjornbytes/lovr.git
Morganization; Fix some Canvas issues;
This commit is contained in:
parent
f57810cd7a
commit
2cf0e15eb0
|
@ -876,10 +876,6 @@ int l_lovrGraphicsNewCanvas(lua_State* L) {
|
|||
lua_pop(L, 1);
|
||||
}
|
||||
|
||||
if (!lovrCanvasSupportsFormat(format)) {
|
||||
return luaL_error(L, "Unsupported texture format for canvas");
|
||||
}
|
||||
|
||||
Canvas* canvas = lovrCanvasCreate(width, height, format, flags);
|
||||
luax_pushtype(L, Canvas, canvas);
|
||||
lovrRelease(canvas);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#include "graphics/font.h"
|
||||
#include "graphics/gpu.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include "graphics/texture.h"
|
||||
#include "data/rasterizer.h"
|
||||
|
@ -278,7 +277,7 @@ void lovrFontAddGlyph(Font* font, Glyph* glyph) {
|
|||
glyph->y = atlas->y;
|
||||
|
||||
// Paste glyph into texture
|
||||
gpuBindTexture(font->texture, 0);
|
||||
lovrGpuBindTexture(font->texture, 0);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, atlas->x, atlas->y, glyph->tw, glyph->th, GL_RGB, GL_UNSIGNED_BYTE, glyph->data);
|
||||
|
||||
// Advance atlas cursor
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
#include "graphics/canvas.h"
|
||||
#include "graphics/font.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include "graphics/material.h"
|
||||
#include "graphics/mesh.h"
|
||||
#include "graphics/shader.h"
|
||||
#include "graphics/texture.h"
|
||||
#include "math/math.h"
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef void (*gpuProc)(void);
|
||||
|
||||
void gpuInit(bool srgb, gpuProc (*getProcAddress)(const char*));
|
||||
void gpuDestroy();
|
||||
void gpuClear(Canvas** canvas, int canvasCount, Color* color, float* depth, int* stencil);
|
||||
void gpuDraw(DrawCommand* command);
|
||||
void gpuPresent();
|
||||
|
||||
// Ephemeral
|
||||
void gpuBindFramebuffer(uint32_t framebuffer);
|
||||
void gpuBindIndexBuffer(uint32_t indexBuffer);
|
||||
void gpuBindTexture(Texture* texture, int slot);
|
||||
void gpuBindVertexArray(uint32_t vertexArray);
|
||||
void gpuBindVertexBuffer(uint32_t vertexBuffer);
|
||||
Texture* gpuGetTexture(int slot);
|
||||
void gpuSetViewport(uint32_t viewport[4]);
|
||||
void gpuUseProgram(uint32_t program);
|
|
@ -1,5 +1,4 @@
|
|||
#include "graphics/graphics.h"
|
||||
#include "graphics/gpu.h"
|
||||
#include "data/rasterizer.h"
|
||||
#include "event/event.h"
|
||||
#include "math/mat4.h"
|
||||
|
@ -37,13 +36,13 @@ void lovrGraphicsDestroy() {
|
|||
lovrRelease(state.defaultMaterial);
|
||||
lovrRelease(state.defaultFont);
|
||||
lovrRelease(state.defaultMesh);
|
||||
gpuDestroy();
|
||||
lovrGpuDestroy();
|
||||
memset(&state, 0, sizeof(GraphicsState));
|
||||
}
|
||||
|
||||
void lovrGraphicsPresent() {
|
||||
glfwSwapBuffers(state.window);
|
||||
gpuPresent();
|
||||
lovrGpuPresent();
|
||||
}
|
||||
|
||||
void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const char* title, const char* icon) {
|
||||
|
@ -95,7 +94,7 @@ void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const cha
|
|||
|
||||
glfwSwapInterval(0);
|
||||
#endif
|
||||
gpuInit(state.gammaCorrect, glfwGetProcAddress);
|
||||
lovrGpuInit(state.gammaCorrect, glfwGetProcAddress);
|
||||
VertexFormat format;
|
||||
vertexFormatInit(&format);
|
||||
vertexFormatAppend(&format, "lovrPosition", ATTR_FLOAT, 3);
|
||||
|
@ -122,8 +121,9 @@ void lovrGraphicsSetCamera(Camera* camera, bool clear) {
|
|||
}
|
||||
|
||||
if (clear) {
|
||||
int canvasCount = state.camera.canvas != NULL;
|
||||
Color backgroundColor = lovrGraphicsGetBackgroundColor();
|
||||
gpuClear(&state.camera.canvas, 1, &backgroundColor, &(float) { 1. }, &(int) { 0 });
|
||||
lovrGpuClear(&state.camera.canvas, canvasCount, &backgroundColor, &(float) { 1. }, &(int) { 0 });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -356,9 +356,9 @@ VertexPointer lovrGraphicsGetVertexPointer(uint32_t count) {
|
|||
void lovrGraphicsClear(Color* color, float* depth, int* stencil) {
|
||||
Pipeline* pipeline = &state.pipelines[state.pipeline];
|
||||
if (pipeline->canvasCount > 0) {
|
||||
gpuClear(pipeline->canvas, pipeline->canvasCount, color, depth, stencil);
|
||||
lovrGpuClear(pipeline->canvas, pipeline->canvasCount, color, depth, stencil);
|
||||
} else {
|
||||
gpuClear(&state.camera.canvas, 1, color, depth, stencil);
|
||||
lovrGpuClear(&state.camera.canvas, 1, color, depth, stencil);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -411,7 +411,7 @@ void lovrGraphicsDraw(DrawOptions* draw) {
|
|||
mat4_multiply(command.transform, draw->transform);
|
||||
}
|
||||
|
||||
gpuDraw(&command);
|
||||
lovrGpuDraw(&command);
|
||||
}
|
||||
|
||||
void lovrGraphicsPoints(uint32_t count) {
|
||||
|
|
|
@ -83,8 +83,8 @@ typedef struct {
|
|||
typedef struct {
|
||||
Canvas* canvas;
|
||||
uint32_t viewport[4];
|
||||
mat4 viewMatrix;
|
||||
mat4 projection;
|
||||
float viewMatrix[16];
|
||||
float projection[16];
|
||||
} Camera;
|
||||
|
||||
typedef struct {
|
||||
|
@ -226,3 +226,16 @@ void lovrGraphicsSkybox(Texture* texture, float angle, float ax, float ay, float
|
|||
void lovrGraphicsPrint(const char* str, mat4 transform, float wrap, HorizontalAlign halign, VerticalAlign valign);
|
||||
void lovrGraphicsStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata);
|
||||
void lovrGraphicsFill(Texture* texture);
|
||||
|
||||
// GPU
|
||||
|
||||
typedef void (*gpuProc)(void);
|
||||
|
||||
void lovrGpuInit(bool srgb, gpuProc (*getProcAddress)(const char*));
|
||||
void lovrGpuDestroy();
|
||||
void lovrGpuClear(Canvas** canvas, int canvasCount, Color* color, float* depth, int* stencil);
|
||||
void lovrGpuDraw(DrawCommand* command);
|
||||
void lovrGpuPresent();
|
||||
|
||||
void lovrGpuBindTexture(Texture* texture, int slot);
|
||||
Texture* lovrGpuGetTexture(int slot);
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -276,6 +276,7 @@ static ModelData* fakeControllerNewModelData(Controller* controller) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#include <stdio.h>
|
||||
static void fakeRenderTo(void (*callback)(void*), void* userdata) {
|
||||
if (!state.window || !state.mirrored) {
|
||||
return;
|
||||
|
@ -283,23 +284,17 @@ static void fakeRenderTo(void (*callback)(void*), void* userdata) {
|
|||
|
||||
int width, height;
|
||||
fakeGetDisplayDimensions(&width, &height);
|
||||
Camera camera = { .viewport = { 0, 0, width, height } };
|
||||
|
||||
float projection[16];
|
||||
mat4_perspective(projection, state.clipNear, state.clipFar, 67 * M_PI / 180., (float) width / height);
|
||||
|
||||
float viewMatrix[16];
|
||||
mat4_identity(viewMatrix);
|
||||
mat4_translate(viewMatrix, 0, state.offset, 0);
|
||||
mat4_multiply(viewMatrix, state.transform);
|
||||
mat4_invert(viewMatrix);
|
||||
mat4_perspective(camera.projection, state.clipNear, state.clipFar, 67 * M_PI / 180., (float) width / height);
|
||||
mat4_identity(camera.viewMatrix);
|
||||
mat4_translate(camera.viewMatrix, 0, state.offset, 0);
|
||||
mat4_multiply(camera.viewMatrix, state.transform);
|
||||
mat4_invert(camera.viewMatrix);
|
||||
|
||||
for (int eye = 0; eye < 2; eye++) {
|
||||
lovrGraphicsSetCamera(&(Camera) {
|
||||
.viewport = { width * eye, 0, width, height },
|
||||
.viewMatrix = viewMatrix,
|
||||
.projection = projection
|
||||
}, eye == 0);
|
||||
|
||||
camera.viewport[0] = width * eye;
|
||||
lovrGraphicsSetCamera(&camera, eye == 0);
|
||||
callback(userdata);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "event/event.h"
|
||||
#include "graphics/graphics.h"
|
||||
#include "graphics/gpu.h"
|
||||
#include "graphics/canvas.h"
|
||||
#include "math/mat4.h"
|
||||
#include "math/quat.h"
|
||||
|
@ -666,35 +665,35 @@ static ModelData* openvrControllerNewModelData(Controller* controller) {
|
|||
}
|
||||
|
||||
static void openvrRenderTo(void (*callback)(void*), void* userdata) {
|
||||
float head[16], eye[16], projection[16], view[16];
|
||||
float head[16], eye[16];
|
||||
|
||||
ensureCanvas();
|
||||
state.isRendering = true;
|
||||
state.compositor->WaitGetPoses(state.renderPoses, 16, NULL, 0);
|
||||
mat4_fromMat34(head, state.renderPoses[state.headsetIndex].mDeviceToAbsoluteTracking.m);
|
||||
|
||||
Camera camera = {
|
||||
.canvas = state.canvas,
|
||||
.viewport = { 0, 0, state.renderWidth, state.renderHeight }
|
||||
};
|
||||
|
||||
for (int i = 0; i < 2; i++) {
|
||||
EVREye vrEye = (i == 0) ? EVREye_Eye_Left : EVREye_Eye_Right;
|
||||
mat4_fromMat44(projection, state.system->GetProjectionMatrix(vrEye, state.clipNear, state.clipFar).m);
|
||||
mat4_identity(view);
|
||||
mat4_translate(view, 0, state.offset, 0);
|
||||
mat4_multiply(view, head);
|
||||
mat4_multiply(view, mat4_fromMat34(eye, state.system->GetEyeToHeadTransform(vrEye).m));
|
||||
mat4_invert(view);
|
||||
|
||||
lovrGraphicsSetCamera(&(Camera) {
|
||||
.canvas = state.canvas,
|
||||
.viewport = { state.renderWidth * i, 0, state.renderWidth, state.renderHeight },
|
||||
.viewMatrix = view,
|
||||
.projection = projection
|
||||
}, i == 0);
|
||||
mat4_fromMat44(camera.projection, state.system->GetProjectionMatrix(vrEye, state.clipNear, state.clipFar).m);
|
||||
mat4_identity(camera.viewMatrix);
|
||||
mat4_translate(camera.viewMatrix, 0, state.offset, 0);
|
||||
mat4_multiply(camera.viewMatrix, head);
|
||||
mat4_multiply(camera.viewMatrix, mat4_fromMat34(eye, state.system->GetEyeToHeadTransform(vrEye).m));
|
||||
mat4_invert(camera.viewMatrix);
|
||||
|
||||
camera.viewport[0] = state.renderWidth * i;
|
||||
lovrGraphicsSetCamera(&camera, i == 0);
|
||||
callback(userdata);
|
||||
}
|
||||
|
||||
// Submit
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
Texture* oldTexture = gpuGetTexture(0);
|
||||
Texture* oldTexture = lovrGpuGetTexture(0);
|
||||
uintptr_t texture = (uintptr_t) lovrTextureGetId((Texture*) state.canvas);
|
||||
EColorSpace colorSpace = lovrGraphicsIsGammaCorrect() ? EColorSpace_ColorSpace_Linear : EColorSpace_ColorSpace_Gamma;
|
||||
Texture_t eyeTexture = { (void*) texture, ETextureType_TextureType_OpenGL, colorSpace };
|
||||
|
|
Loading…
Reference in New Issue