mirror of https://github.com/bjornbytes/lovr.git
Fix bugs;
This commit is contained in:
parent
4e61d2ea3b
commit
ea331a12be
|
@ -930,7 +930,6 @@ int l_lovrGraphicsNewShaderBlock(lua_State* L) {
|
|||
|
||||
int l_lovrGraphicsNewCanvas(lua_State* L) {
|
||||
Attachment attachments[MAX_CANVAS_ATTACHMENTS];
|
||||
bool anonymous = false;
|
||||
int attachmentCount = 0;
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
|
@ -952,6 +951,8 @@ int l_lovrGraphicsNewCanvas(lua_State* L) {
|
|||
}
|
||||
|
||||
CanvasFlags flags = { .depth = DEPTH_D16, .stereo = true, .msaa = 0, .mipmaps = true };
|
||||
TextureFormat format = FORMAT_RGBA;
|
||||
bool anonymous = attachmentCount == 0;
|
||||
|
||||
if (lua_istable(L, index)) {
|
||||
lua_getfield(L, index, "depth");
|
||||
|
@ -976,18 +977,19 @@ int l_lovrGraphicsNewCanvas(lua_State* L) {
|
|||
|
||||
if (attachmentCount == 0) {
|
||||
lua_getfield(L, index, "format");
|
||||
if (lua_type(L, -1) == LUA_TSTRING) {
|
||||
TextureFormat format = luaL_checkoption(L, -1, "rgba", TextureFormats);
|
||||
Texture* texture = lovrTextureCreate(TEXTURE_2D, NULL, 0, true, flags.mipmaps, flags.msaa);
|
||||
lovrTextureAllocate(texture, width, height, 1, format);
|
||||
attachments[0] = (Attachment) { texture, 0, 0 };
|
||||
attachmentCount++;
|
||||
anonymous = true;
|
||||
}
|
||||
format = luaL_checkoption(L, -1, "rgba", TextureFormats);
|
||||
anonymous = lua_isnil(L, -1) || lua_toboolean(L, -1);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (anonymous) {
|
||||
Texture* texture = lovrTextureCreate(TEXTURE_2D, NULL, 0, true, flags.mipmaps, flags.msaa);
|
||||
lovrTextureAllocate(texture, width, height, 1, format);
|
||||
attachments[0] = (Attachment) { texture, 0, 0 };
|
||||
attachmentCount++;
|
||||
}
|
||||
|
||||
if (width == 0 && height == 0 && attachmentCount > 0) {
|
||||
width = lovrTextureGetWidth(attachments[0].texture, attachments[0].level);
|
||||
height = lovrTextureGetHeight(attachments[0].texture, attachments[0].level);
|
||||
|
|
|
@ -32,7 +32,6 @@ const Attachment* lovrCanvasGetAttachments(Canvas* canvas, int* count);
|
|||
void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count);
|
||||
void lovrCanvasBind(Canvas* canvas, bool willDraw);
|
||||
void lovrCanvasResolve(Canvas* canvas);
|
||||
void lovrCanvasBlit(Canvas* canvas);
|
||||
bool lovrCanvasIsStereo(Canvas* canvas);
|
||||
int lovrCanvasGetWidth(Canvas* canvas);
|
||||
int lovrCanvasGetHeight(Canvas* canvas);
|
||||
|
|
|
@ -71,7 +71,6 @@ void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const cha
|
|||
glfwWindowHint(GLFW_REFRESH_RATE, mode->refreshRate);
|
||||
}
|
||||
|
||||
state.msaa = msaa;
|
||||
state.window = glfwCreateWindow(w ? w : mode->width, h ? h : mode->height, title, fullscreen ? monitor : NULL, NULL);
|
||||
if (!state.window) {
|
||||
glfwTerminate();
|
||||
|
@ -118,10 +117,6 @@ int lovrGraphicsGetHeight() {
|
|||
return state.height;
|
||||
}
|
||||
|
||||
int lovrGraphicsGetMSAA() {
|
||||
return state.msaa;
|
||||
}
|
||||
|
||||
void lovrGraphicsSetCamera(Camera* camera, bool clear) {
|
||||
if (state.camera.canvas && (!camera || camera->canvas != state.camera.canvas)) {
|
||||
lovrCanvasResolve(state.camera.canvas);
|
||||
|
|
|
@ -137,7 +137,6 @@ typedef struct {
|
|||
typedef struct {
|
||||
bool initialized;
|
||||
bool gammaCorrect;
|
||||
int msaa;
|
||||
int width;
|
||||
int height;
|
||||
void* window;
|
||||
|
@ -160,7 +159,6 @@ void lovrGraphicsPresent();
|
|||
void lovrGraphicsCreateWindow(int w, int h, bool fullscreen, int msaa, const char* title, const char* icon);
|
||||
int lovrGraphicsGetWidth();
|
||||
int lovrGraphicsGetHeight();
|
||||
int lovrGraphicsGetMSAA();
|
||||
void lovrGraphicsSetCamera(Camera* camera, bool clear);
|
||||
#define lovrGraphicsGetSupported lovrGpuGetSupported
|
||||
#define lovrGraphicsGetLimits lovrGpuGetLimits
|
||||
|
@ -240,7 +238,7 @@ void lovrGpuClear(Canvas* canvas, Color* color, float* depth, int* stencil);
|
|||
void lovrGpuStencil(StencilAction action, int replaceValue, StencilCallback callback, void* userdata);
|
||||
void lovrGpuCompute(Shader* shader, int x, int y, int z);
|
||||
void lovrGpuPresent();
|
||||
void lovrGpuDirtyTexture(int slot);
|
||||
void lovrGpuDirtyTexture();
|
||||
const GpuFeatures* lovrGpuGetSupported();
|
||||
const GpuLimits* lovrGpuGetLimits();
|
||||
const GpuStats* lovrGpuGetStats();
|
||||
|
|
|
@ -866,9 +866,8 @@ void lovrGpuPresent() {
|
|||
#endif
|
||||
}
|
||||
|
||||
void lovrGpuDirtyTexture(int slot) {
|
||||
lovrAssert(slot >= 0 && slot < MAX_TEXTURES, "Invalid texture slot %d", slot);
|
||||
state.textures[slot] = NULL;
|
||||
void lovrGpuDirtyTexture() {
|
||||
state.textures[state.activeTexture] = NULL;
|
||||
}
|
||||
|
||||
const GpuFeatures* lovrGpuGetSupported() {
|
||||
|
@ -1247,7 +1246,7 @@ void lovrCanvasBind(Canvas* canvas, bool willDraw) {
|
|||
int slice = attachment->slice;
|
||||
int level = attachment->level;
|
||||
|
||||
if (texture->msaa) {
|
||||
if (canvas->flags.msaa) {
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, buffer, GL_RENDERBUFFER, texture->msaaId);
|
||||
}
|
||||
|
||||
|
@ -1311,14 +1310,6 @@ void lovrCanvasResolve(Canvas* canvas) {
|
|||
canvas->needsResolve = false;
|
||||
}
|
||||
|
||||
// Canvas must be resolved
|
||||
void lovrCanvasBlit(Canvas* canvas) {
|
||||
glBindFramebuffer(GL_READ_FRAMEBUFFER, canvas->flags.msaa ? canvas->resolveBuffer : canvas->framebuffer);
|
||||
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
|
||||
glBlitFramebuffer(0, 0, canvas->width, canvas->height, 0, 0, lovrGraphicsGetWidth(), lovrGraphicsGetHeight(), GL_COLOR_BUFFER_BIT, GL_LINEAR);
|
||||
state.framebuffer = 0;
|
||||
}
|
||||
|
||||
bool lovrCanvasIsStereo(Canvas* canvas) {
|
||||
return canvas->flags.stereo;
|
||||
}
|
||||
|
|
|
@ -690,10 +690,14 @@ static void openvrRenderTo(void (*callback)(void*), void* userdata) {
|
|||
VRTextureBounds_t right = { .5, 0, 1., 1. };
|
||||
state.compositor->Submit(EVREye_Eye_Left, &eyeTexture, &left, EVRSubmitFlags_Submit_Default);
|
||||
state.compositor->Submit(EVREye_Eye_Right, &eyeTexture, &right, EVRSubmitFlags_Submit_Default);
|
||||
lovrGpuDirtyTexture(0);
|
||||
lovrGpuDirtyTexture();
|
||||
|
||||
if (state.isMirrored) {
|
||||
lovrCanvasBlit(state.canvas);
|
||||
lovrGraphicsPushPipeline();
|
||||
lovrGraphicsSetColor((Color) { 1, 1, 1, 1 });
|
||||
lovrGraphicsSetShader(NULL);
|
||||
lovrGraphicsFill(attachments[0].texture);
|
||||
lovrGraphicsPopPipeline();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue