Remerge oculus mobile and master branches (to get lovrCanvasCreateFromHandle)

This commit is contained in:
mcc 2018-10-25 00:06:39 -04:00
commit b892d0143f
10 changed files with 59 additions and 38 deletions

View File

@ -10,7 +10,6 @@ only_commits:
before_build:
- cd C:\projects\lovr
- git submodule update --init
- md build
- cd build
- cmake -DCMAKE_BUILD_TYPE=%configuration% ..

View File

@ -45,7 +45,7 @@ if(EMSCRIPTEN)
"-s FORCE_FILESYSTEM=1 "
"-s ALLOW_MEMORY_GROWTH=1 "
"-s \"EXPORTED_FUNCTIONS=[ "
"'_main','_lovrRun','_lovrQuit','_lovrDestroy',"
"'_main','_lovrRun','_lovrQuit',"
"'_mat4_identity','_mat4_invert','_mat4_multiply','_mat4_rotateQuat','_mat4_transform','_mat4_transformDirection','_mat4_translate',"
"'_quat_fromMat4','_quat_getAngleAxis'"
"]\" "
@ -294,7 +294,10 @@ if(LOVR_ENABLE_HEADSET AND LOVR_USE_OPENVR)
endif()
# Oculus SDK
if (LOVR_ENABLE_HEADSET AND LOVR_USE_OCULUS AND LOVR_OCULUS_PATH)
if (LOVR_ENABLE_HEADSET AND LOVR_USE_OCULUS)
if(NOT LOVR_OCULUS_PATH)
message(FATAL_ERROR "LOVR_USE_OCULUS requires the LOVR_OCULUS_PATH to be set to the location of the Oculus Desktop SDK")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(OCULUS_BUILD_TYPE "Release")
else()
@ -311,10 +314,12 @@ if (LOVR_ENABLE_HEADSET AND LOVR_USE_OCULUS AND LOVR_OCULUS_PATH)
endif()
# pthreads
if(NOT WIN32)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(LOVR_PTHREADS Threads::Threads)
if(LOVR_ENABLE_THREAD)
if(NOT WIN32 AND NOT EMSCRIPTEN)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(LOVR_PTHREADS Threads::Threads)
endif()
endif()
# LÖVR

View File

@ -36,13 +36,13 @@ void luax_checkvariant(lua_State* L, int index, Variant* variant) {
variant->type = TYPE_STRING;
size_t length;
const char* string = lua_tolstring(L, index, &length);
variant->value.string = malloc(length + 1);
strcpy(variant->value.string, string);
variant->value.string = calloc(1, length + 1);
memcpy(variant->value.string, string, length);
break;
case LUA_TUSERDATA:
variant->type = TYPE_OBJECT;
variant->value.ref = lua_touserdata(L, index);
variant->value.ref = *(Ref**) lua_touserdata(L, index);
lovrRetain(variant->value.ref);
break;

View File

@ -360,12 +360,17 @@ int luaopen_lovr_filesystem(lua_State* L) {
luax_atexit(L, lovrFilesystemDestroy);
lua_getglobal(L, "arg");
lua_rawgeti(L, -1, -2);
lua_rawgeti(L, -2, 1);
const char* arg0 = lua_tostring(L, -2);
const char* arg1 = lua_tostring(L, -1);
lovrFilesystemInit(arg0, arg1);
lua_pop(L, 3);
if (lua_istable(L, -1)) {
lua_rawgeti(L, -1, -2);
lua_rawgeti(L, -2, 1);
const char* arg0 = lua_tostring(L, -2);
const char* arg1 = lua_tostring(L, -1);
lovrFilesystemInit(arg0, arg1);
lua_pop(L, 3);
} else {
lua_pop(L, 1);
lovrFilesystemInit(NULL, NULL);
}
luax_registerloader(L, moduleLoader, 2);
luax_registerloader(L, libraryLoader, 3);

View File

@ -136,20 +136,20 @@ int l_lovrTransformSetOrthographic(lua_State* L) {
float right = luaL_checknumber(L, 3);
float top = luaL_checknumber(L, 4);
float bottom = luaL_checknumber(L, 5);
float near = luaL_checknumber(L, 6);
float far = luaL_checknumber(L, 7);
mat4_orthographic(transform->matrix, left, right, top, bottom, near, far);
float clipNear = luaL_checknumber(L, 6);
float clipFar = luaL_checknumber(L, 7);
mat4_orthographic(transform->matrix, left, right, top, bottom, clipNear, clipFar);
lua_pushvalue(L, 1);
return 1;
}
int l_lovrTransformSetPerspective(lua_State* L) {
Transform* transform = luax_checktype(L, 1, Transform);
float near = luaL_checknumber(L, 2);
float far = luaL_checknumber(L, 3);
float clipNear = luaL_checknumber(L, 2);
float clipFar = luaL_checknumber(L, 3);
float fov = luaL_checknumber(L, 4);
float aspect = luaL_checknumber(L, 5);
mat4_perspective(transform->matrix, near, far, fov, aspect);
mat4_perspective(transform->matrix, clipNear, clipFar, fov, aspect);
lua_pushvalue(L, 1);
return 1;
}

View File

@ -31,6 +31,7 @@ void lovrAudioInit() {
lovrThrow("Unable to create OpenAL context");
}
#if ALC_SOFT_HRTF
static LPALCRESETDEVICESOFT alcResetDeviceSOFT;
alcResetDeviceSOFT = (LPALCRESETDEVICESOFT) alcGetProcAddress(device, "alcResetDeviceSOFT");
state.isSpatialized = alcIsExtensionPresent(device, "ALC_SOFT_HRTF");
@ -38,6 +39,7 @@ void lovrAudioInit() {
if (state.isSpatialized) {
alcResetDeviceSOFT(device, (ALCint[]) { ALC_HRTF_SOFT, ALC_TRUE, 0 });
}
#endif
state.device = device;
state.context = context;

View File

@ -24,6 +24,7 @@ typedef struct {
typedef struct Canvas Canvas;
Canvas* lovrCanvasCreate(int width, int height, CanvasFlags flags);
Canvas* lovrCanvasCreateFromHandle(uint32_t handle);
void lovrCanvasDestroy(void* ref);
const Attachment* lovrCanvasGetAttachments(Canvas* canvas, int* count);
void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count);

View File

@ -132,7 +132,7 @@ struct Canvas {
uint32_t depthBuffer;
Attachment attachments[MAX_CANVAS_ATTACHMENTS];
Attachment depth;
int count;
int attachmentCount;
bool needsAttach;
bool needsResolve;
};
@ -838,7 +838,7 @@ void lovrGpuClear(Canvas* canvas, Color* color, float* depth, int* stencil) {
if (color) {
gammaCorrectColor(color);
int count = canvas ? canvas->count : 1;
int count = canvas ? canvas->attachmentCount : 1;
for (int i = 0; i < count; i++) {
glClearBufferfv(GL_COLOR, i, (float[]) { color->r, color->g, color->b, color->a });
}
@ -1232,12 +1232,21 @@ Canvas* lovrCanvasCreate(int width, int height, CanvasFlags flags) {
return canvas;
}
Canvas* lovrCanvasCreateFromHandle(uint32_t handle) {
Canvas* canvas = lovrAlloc(Canvas, lovrCanvasDestroy);
if (!canvas) return NULL;
canvas->framebuffer = handle;
return canvas;
}
void lovrCanvasDestroy(void* ref) {
Canvas* canvas = ref;
glDeleteFramebuffers(1, &canvas->framebuffer);
glDeleteRenderbuffers(1, &canvas->depthBuffer);
glDeleteFramebuffers(1, &canvas->resolveBuffer);
for (int i = 0; i < canvas->count; i++) {
for (int i = 0; i < canvas->attachmentCount; i++) {
lovrRelease(canvas->attachments[i].texture);
}
lovrRelease(canvas->depth.texture);
@ -1245,7 +1254,7 @@ void lovrCanvasDestroy(void* ref) {
}
const Attachment* lovrCanvasGetAttachments(Canvas* canvas, int* count) {
if (count) *count = canvas->count;
if (count) *count = canvas->attachmentCount;
return canvas->attachments;
}
@ -1253,7 +1262,7 @@ void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count
lovrAssert(count > 0, "A Canvas must have at least one attached Texture");
lovrAssert(count <= MAX_CANVAS_ATTACHMENTS, "Only %d textures can be attached to a Canvas, got %d\n", MAX_CANVAS_ATTACHMENTS, count);
if (!canvas->needsAttach && count == canvas->count && !memcmp(canvas->attachments, attachments, count * sizeof(Attachment))) {
if (!canvas->needsAttach && count == canvas->attachmentCount && !memcmp(canvas->attachments, attachments, count * sizeof(Attachment))) {
return;
}
@ -1268,12 +1277,12 @@ void lovrCanvasSetAttachments(Canvas* canvas, Attachment* attachments, int count
lovrRetain(texture);
}
for (int i = 0; i < canvas->count; i++) {
for (int i = 0; i < canvas->attachmentCount; i++) {
lovrRelease(canvas->attachments[i].texture);
}
memcpy(canvas->attachments, attachments, count * sizeof(Attachment));
canvas->count = count;
canvas->attachmentCount = count;
canvas->needsAttach = true;
}
@ -1292,7 +1301,7 @@ void lovrCanvasBind(Canvas* canvas, bool willDraw) {
// We need to synchronize if any of the Canvas attachments have pending writes on them
#ifndef EMSCRIPTEN
for (int i = 0; i < canvas->count; i++) {
for (int i = 0; i < canvas->attachmentCount; i++) {
Texture* texture = canvas->attachments[i].texture;
if (texture->incoherent && (texture->incoherent >> BARRIER_CANVAS) & 1) {
lovrGpuSync(1 << BARRIER_CANVAS);
@ -1307,7 +1316,7 @@ void lovrCanvasBind(Canvas* canvas, bool willDraw) {
}
GLenum buffers[MAX_CANVAS_ATTACHMENTS] = { GL_NONE };
for (int i = 0; i < canvas->count; i++) {
for (int i = 0; i < canvas->attachmentCount; i++) {
GLenum buffer = buffers[i] = GL_COLOR_ATTACHMENT0 + i;
Attachment* attachment = &canvas->attachments[i];
Texture* texture = attachment->texture;
@ -1325,7 +1334,7 @@ void lovrCanvasBind(Canvas* canvas, bool willDraw) {
case TEXTURE_VOLUME: glFramebufferTextureLayer(GL_READ_FRAMEBUFFER, buffer, texture->id, level, slice); break;
}
}
glDrawBuffers(canvas->count, buffers);
glDrawBuffers(canvas->attachmentCount, buffers);
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch (status) {
@ -1350,23 +1359,23 @@ void lovrCanvasResolve(Canvas* canvas) {
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, canvas->resolveBuffer);
state.framebuffer = canvas->resolveBuffer;
if (canvas->count == 1) {
if (canvas->attachmentCount == 1) {
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
} else {
GLenum buffers[MAX_CANVAS_ATTACHMENTS] = { GL_NONE };
for (int i = 0; i < canvas->count; i++) {
for (int i = 0; i < canvas->attachmentCount; i++) {
buffers[i] = GL_COLOR_ATTACHMENT0 + i;
glReadBuffer(i);
glDrawBuffers(1, &buffers[i]);
glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
}
glReadBuffer(0);
glDrawBuffers(canvas->count, buffers);
glDrawBuffers(canvas->attachmentCount, buffers);
}
}
if (canvas->flags.mipmaps) {
for (int i = 0; i < canvas->count; i++) {
for (int i = 0; i < canvas->attachmentCount; i++) {
Texture* texture = canvas->attachments[i].texture;
if (texture->mipmapCount > 1) {
lovrGpuBindTexture(texture, 0);

View File

@ -1,6 +1,5 @@
#include <stdint.h>
#include <stddef.h>
#include "lib/vec/vec.h"
#pragma once

View File

@ -3,6 +3,7 @@
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
// Thomas Wang's 64-bit integer hashing function:
// https://web.archive.org/web/20110807030012/http://www.cris.com/%7ETtwang/tech/inthash.htm
@ -47,7 +48,7 @@ void lovrRandomGeneratorSetSeed(RandomGenerator* generator, Seed seed) {
}
void lovrRandomGeneratorGetState(RandomGenerator* generator, char* state, size_t length) {
snprintf(state, length, "0x%16llx", generator->state.b64);
snprintf(state, length, "0x%" PRIx64, generator->state.b64);
}
int lovrRandomGeneratorSetState(RandomGenerator* generator, const char* state) {