From 872ceb365d5ab30320fbca454de59837c08ea7dc Mon Sep 17 00:00:00 2001 From: bjorn Date: Wed, 19 Apr 2017 21:44:35 -0700 Subject: [PATCH] WIP; --- CMakeLists.txt | 6 ++++-- src/headset/webvr.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5d71a9a2..5c50e823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,7 @@ add_executable(lovr ${LOVR_SRC} ${LOVR_HEADSET}) if(EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".html") - add_definitions(-s USE_ZLIB=1 -s ASSERTIONS=2 -s FULL_ES2=1) + add_definitions(-s USE_ZLIB=1 -s ASSERTIONS=2 -s FULL_ES2=1 -O3 -s AGGRESSIVE_VARIABLE_ELIMINATION=1 -s OUTLINING_LIMIT=15000) set(ZLIB_FOUND 1) set(ZLIB_LIBRARIES "-s USE_ZLIB=1") set(ZLIB_INCLUDE_DIR .) @@ -198,7 +198,9 @@ elseif(NOT EMSCRIPTEN) endif() # FreeType -if (WIN32 OR EMSCRIPTEN) +if (EMSCRIPTEN) + add_definitions(-s USE_FREETYPE=1) +elseif (WIN32) set(BUILD_SHARED_LIBS OFF) set(FREETYPE_NO_DIST TRUE CACHE BOOL "") add_subdirectory(deps/freetype freetype) diff --git a/src/headset/webvr.c b/src/headset/webvr.c index 40047317..2231476c 100644 --- a/src/headset/webvr.c +++ b/src/headset/webvr.c @@ -1,22 +1,41 @@ #include "headset/headset.h" #include "graphics/graphics.h" +#include #include #include static headsetRenderCallback renderCallback; static void onRequestAnimationFrame(void* userdata) { - lovrGraphicsSetBackgroundColor(1, 0, 0, 1); lovrGraphicsClear(1, 1); - printf("Yay rendering!\n"); + int width = emscripten_vr_get_display_width(); int height = emscripten_vr_get_display_height(); - glViewport(0, 0, width, height); - renderCallback(EYE_LEFT, userdata); + float projection[16]; + float transform[16]; - glViewport(width, 0, width, height); + mat4_set(projection, emscripten_vr_get_projection_matrix(0)); + mat4_set(transform, emscripten_vr_get_view_matrix(0)); + + lovrGraphicsPush(); + lovrGraphicsOrigin(); + lovrGraphicsMatrixTransform(transform); + lovrGraphicsSetProjection(projection); + lovrGraphicsSetViewport(0, 0, width / 2, height); + renderCallback(EYE_LEFT, userdata); + lovrGraphicsPop(); + + mat4_set(projection, emscripten_vr_get_projection_matrix(1)); + mat4_set(transform, emscripten_vr_get_view_matrix(1)); + + lovrGraphicsPush(); + lovrGraphicsOrigin(); + lovrGraphicsMatrixTransform(transform); + lovrGraphicsSetProjection(projection); + lovrGraphicsSetViewport(width / 2, 0, width / 2, height); renderCallback(EYE_RIGHT, userdata); + lovrGraphicsPop(); } void lovrHeadsetInit() { @@ -48,7 +67,8 @@ void lovrHeadsetSetMirrored(int mirror) { } void lovrHeadsetGetDisplayDimensions(int* width, int* height) { - *width = *height = 0; + *width = emscripten_vr_get_display_width(); + *height = emscripten_vr_get_display_height(); } void lovrHeadsetGetClipDistance(float* near, float* far) {