From 2d82f6efd8875c6f2e98bb811d70a7390b7be273 Mon Sep 17 00:00:00 2001 From: XProger Date: Tue, 8 May 2018 06:17:57 +0300 Subject: [PATCH] #15 fix WebGL build --- src/core.h | 40 ++++++++++++++++++------------------- src/format.h | 7 ++++--- src/gapi_gl.h | 13 ++++++------ src/platform/web/build.bat | 2 +- src/platform/web/index.html | 5 ++++- 5 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/core.h b/src/core.h index bd1d0ed..4aa887f 100644 --- a/src/core.h +++ b/src/core.h @@ -11,48 +11,48 @@ #define OS_PTHREAD_MT #ifdef WIN32 - #define _OS_WIN - #define _GAPI_GL + #define _OS_WIN 1 + #define _GAPI_GL 1 //#define _GAPI_VULKAN #include #undef OS_PTHREAD_MT #elif ANDROID - #define _OS_ANDROID - #define _GAPI_GL - #define _GAPI_GLES + #define _OS_ANDROID 1 + #define _GAPI_GL 1 + #define _GAPI_GLES 1 //#define _GAPI_VULKAN extern void osToggleVR(bool enable); #elif __RPI__ - #define _OS_RPI - #define _GAPI_GL - #define _GAPI_GLES + #define _OS_RPI 1 + #define _GAPI_GL 1 + #define _GAPI_GLES 1 #define DYNGEOM_NO_VBO #elif __linux__ - #define _OS_LINUX - #define _GAPI_GL + #define _OS_LINUX 1 + #define _GAPI_GL 1 #elif __APPLE__ - #define _GAPI_GL + #define _GAPI_GL 1 #include "TargetConditionals.h" #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR - #define _OS_IOS - #define _GAPI_GLES + #define _OS_IOS 1 + #define _GAPI_GLES 1 #else - #define _OS_MAC + #define _OS_MAC 1 #endif #elif __EMSCRIPTEN__ - #define _OS_WEB - #define _GAPI_GL - #define _GAPI_GLES + #define _OS_WEB 1 + #define _GAPI_GL 1 + #define _GAPI_GLES 1 #undef OS_FILEIO_CACHE #elif _PSP - #define _OS_PSP - #define _GAPI_SCEGU + #define _OS_PSP 1 + #define _GAPI_SCEGU 1 #define FFP #define TEX_SWIZZLE @@ -794,11 +794,11 @@ namespace Core { void setBlendMode(BlendMode mode) { renderState &= ~RS_BLEND; switch (mode) { - case bmNone : break; case bmAlpha : renderState |= RS_BLEND_ALPHA; break; case bmAdd : renderState |= RS_BLEND_ADD; break; case bmMult : renderState |= RS_BLEND_MULT; break; case bmPremult : renderState |= RS_BLEND_PREMULT; break; + default : ; } } diff --git a/src/format.h b/src/format.h index 05d7a32..ae78f67 100644 --- a/src/format.h +++ b/src/format.h @@ -3137,8 +3137,8 @@ namespace TR { stream.seek(tmpV * 4 + tmpT * 4); // skip vertices and triangles int q = 0; + uint32 info; while (1) { - uint32 info; if (!q) { stream.read(info); q = 3; @@ -3223,8 +3223,8 @@ namespace TR { } // read rectangles int q = 0; + uint32 info; while (1) { - uint32 info; if (!q) { stream.read(info); q = 3; @@ -3545,7 +3545,8 @@ namespace TR { uint16 tmpOffset; mesh.vCount = stream.read(tmp); mesh.flags.value = stream.read(tmp); - fOffset = stream.pos + stream.read(tmpOffset); + stream.read(tmpOffset); + fOffset = stream.pos + tmpOffset; } else { stream.read(mesh.flags.value); stream.read(mesh.vCount); diff --git a/src/gapi_gl.h b/src/gapi_gl.h index 8155ce2..f18ca03 100644 --- a/src/gapi_gl.h +++ b/src/gapi_gl.h @@ -122,6 +122,7 @@ #elif _OS_WEB #include #include + #include #include #include @@ -385,14 +386,14 @@ namespace GAPI { FormatDesc desc = formats[fmt]; #ifdef _OS_WEB // fucking firefox! - if (format == FMT_RGBA_FLOAT) { + if (fmt == FMT_RGBA_FLOAT) { if (Core::support.texFloat) { desc.ifmt = GL_RGBA; desc.type = GL_FLOAT; } } - if (format == FMT_RGBA_HALF) { + if (fmt == FMT_RGBA_HALF) { if (Core::support.texHalf) { desc.ifmt = GL_RGBA; desc.type = GL_HALF_FLOAT_OES; @@ -402,7 +403,7 @@ namespace GAPI { if ((fmt == FMT_RGBA_FLOAT && !Core::support.colorFloat) || (fmt == FMT_RGBA_HALF && !Core::support.colorHalf)) { desc.ifmt = GL_RGBA; #ifdef _GAPI_GLES - if (format == FMT_RGBA_HALF) + if (fmt == FMT_RGBA_HALF) desc.type = GL_HALF_FLOAT_OES; #endif } @@ -430,7 +431,7 @@ namespace GAPI { } void bind(int sampler) { - if (!this || (opt & OPT_PROXY)) return; + if (opt & OPT_PROXY) return; ASSERT(ID); if (Core::active.textures[sampler] != this) { @@ -813,7 +814,7 @@ namespace GAPI { } void resetState() { - if (glBindVertexArray) + if (Core::support.VAO) glBindVertexArray(0); glActiveTexture(GL_TEXTURE0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); @@ -990,7 +991,7 @@ namespace GAPI { ASSERT(pso->data != NULL); uint32 state = pso->renderState; - uint32 mask = mask; + uint32 mask = 0;//mask; if (Core::active.pso) mask ^= Core::active.pso->renderState; diff --git a/src/platform/web/build.bat b/src/platform/web/build.bat index a8acb87..35683bc 100644 --- a/src/platform/web/build.bat +++ b/src/platform/web/build.bat @@ -2,7 +2,7 @@ cls set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/tinf/tinflate.c set PROJ=OpenLara -set FLAGS=-O3 -Wno-deprecated-register --llvm-opts 2 -fmax-type-align=2 -std=c++11 -s ALLOW_MEMORY_GROWTH=1 -Wall -I../../ +set FLAGS=-O3 -ffast-math -Wno-deprecated-register --llvm-opts 2 -fmax-type-align=2 -std=c++11 -s ALLOW_MEMORY_GROWTH=1 -Wall -I../../ echo. call em++ %SRC% %FLAGS% -o %PROJ%.js --preload-file ./level/1/TITLE.PSX --preload-file ./audio/1/dummy --preload-file ./audio/2/dummy --preload-file ./audio/3/dummy --preload-file ./level/2/dummy --preload-file ./level/3/dummy gzip.exe -9 -f %PROJ%.data %PROJ%.js %PROJ%.js.mem \ No newline at end of file diff --git a/src/platform/web/index.html b/src/platform/web/index.html index 5988e87..1e71488 100644 --- a/src/platform/web/index.html +++ b/src/platform/web/index.html @@ -97,9 +97,12 @@ if (audioContext) { audioContext.resume(); window.removeEventListener('touchstart', userAction, false); + window.removeEventListener('click', userAction, false); + console.log("resume playback"); } }; window.addEventListener('touchstart', userAction, false); + window.addEventListener('click', userAction, false); var gl = canvasElement.getContext("webgl", {antialias:false, premultipliedAlpha: false}) || canvasElement.getContext("experimental-webgl", {antialias:false, premultipliedAlpha: false}); @@ -119,7 +122,7 @@ (.PHD, .PSX, .TR2)

OpenLara on github & facebook
-
last update: 20.04.2018
+
last update: 8.05.2018