1
0
mirror of https://github.com/XProger/OpenLara.git synced 2025-08-18 10:51:23 +02:00

#15 fix WebGL build

This commit is contained in:
XProger
2018-05-08 06:17:57 +03:00
parent a64e18e416
commit 2d82f6efd8
5 changed files with 36 additions and 31 deletions

View File

@@ -11,48 +11,48 @@
#define OS_PTHREAD_MT #define OS_PTHREAD_MT
#ifdef WIN32 #ifdef WIN32
#define _OS_WIN #define _OS_WIN 1
#define _GAPI_GL #define _GAPI_GL 1
//#define _GAPI_VULKAN //#define _GAPI_VULKAN
#include <windows.h> #include <windows.h>
#undef OS_PTHREAD_MT #undef OS_PTHREAD_MT
#elif ANDROID #elif ANDROID
#define _OS_ANDROID #define _OS_ANDROID 1
#define _GAPI_GL #define _GAPI_GL 1
#define _GAPI_GLES #define _GAPI_GLES 1
//#define _GAPI_VULKAN //#define _GAPI_VULKAN
extern void osToggleVR(bool enable); extern void osToggleVR(bool enable);
#elif __RPI__ #elif __RPI__
#define _OS_RPI #define _OS_RPI 1
#define _GAPI_GL #define _GAPI_GL 1
#define _GAPI_GLES #define _GAPI_GLES 1
#define DYNGEOM_NO_VBO #define DYNGEOM_NO_VBO
#elif __linux__ #elif __linux__
#define _OS_LINUX #define _OS_LINUX 1
#define _GAPI_GL #define _GAPI_GL 1
#elif __APPLE__ #elif __APPLE__
#define _GAPI_GL #define _GAPI_GL 1
#include "TargetConditionals.h" #include "TargetConditionals.h"
#if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
#define _OS_IOS #define _OS_IOS 1
#define _GAPI_GLES #define _GAPI_GLES 1
#else #else
#define _OS_MAC #define _OS_MAC 1
#endif #endif
#elif __EMSCRIPTEN__ #elif __EMSCRIPTEN__
#define _OS_WEB #define _OS_WEB 1
#define _GAPI_GL #define _GAPI_GL 1
#define _GAPI_GLES #define _GAPI_GLES 1
#undef OS_FILEIO_CACHE #undef OS_FILEIO_CACHE
#elif _PSP #elif _PSP
#define _OS_PSP #define _OS_PSP 1
#define _GAPI_SCEGU #define _GAPI_SCEGU 1
#define FFP #define FFP
#define TEX_SWIZZLE #define TEX_SWIZZLE
@@ -794,11 +794,11 @@ namespace Core {
void setBlendMode(BlendMode mode) { void setBlendMode(BlendMode mode) {
renderState &= ~RS_BLEND; renderState &= ~RS_BLEND;
switch (mode) { switch (mode) {
case bmNone : break;
case bmAlpha : renderState |= RS_BLEND_ALPHA; break; case bmAlpha : renderState |= RS_BLEND_ALPHA; break;
case bmAdd : renderState |= RS_BLEND_ADD; break; case bmAdd : renderState |= RS_BLEND_ADD; break;
case bmMult : renderState |= RS_BLEND_MULT; break; case bmMult : renderState |= RS_BLEND_MULT; break;
case bmPremult : renderState |= RS_BLEND_PREMULT; break; case bmPremult : renderState |= RS_BLEND_PREMULT; break;
default : ;
} }
} }

View File

@@ -3137,8 +3137,8 @@ namespace TR {
stream.seek(tmpV * 4 + tmpT * 4); // skip vertices and triangles stream.seek(tmpV * 4 + tmpT * 4); // skip vertices and triangles
int q = 0; int q = 0;
while (1) {
uint32 info; uint32 info;
while (1) {
if (!q) { if (!q) {
stream.read(info); stream.read(info);
q = 3; q = 3;
@@ -3223,8 +3223,8 @@ namespace TR {
} }
// read rectangles // read rectangles
int q = 0; int q = 0;
while (1) {
uint32 info; uint32 info;
while (1) {
if (!q) { if (!q) {
stream.read(info); stream.read(info);
q = 3; q = 3;
@@ -3545,7 +3545,8 @@ namespace TR {
uint16 tmpOffset; uint16 tmpOffset;
mesh.vCount = stream.read(tmp); mesh.vCount = stream.read(tmp);
mesh.flags.value = stream.read(tmp); mesh.flags.value = stream.read(tmp);
fOffset = stream.pos + stream.read(tmpOffset); stream.read(tmpOffset);
fOffset = stream.pos + tmpOffset;
} else { } else {
stream.read(mesh.flags.value); stream.read(mesh.flags.value);
stream.read(mesh.vCount); stream.read(mesh.vCount);

View File

@@ -122,6 +122,7 @@
#elif _OS_WEB #elif _OS_WEB
#include <emscripten/emscripten.h> #include <emscripten/emscripten.h>
#include <emscripten/html5.h> #include <emscripten/html5.h>
#include <GLES/gl.h>
#include <GLES3/gl3.h> #include <GLES3/gl3.h>
#include <GLES3/gl2ext.h> #include <GLES3/gl2ext.h>
@@ -385,14 +386,14 @@ namespace GAPI {
FormatDesc desc = formats[fmt]; FormatDesc desc = formats[fmt];
#ifdef _OS_WEB // fucking firefox! #ifdef _OS_WEB // fucking firefox!
if (format == FMT_RGBA_FLOAT) { if (fmt == FMT_RGBA_FLOAT) {
if (Core::support.texFloat) { if (Core::support.texFloat) {
desc.ifmt = GL_RGBA; desc.ifmt = GL_RGBA;
desc.type = GL_FLOAT; desc.type = GL_FLOAT;
} }
} }
if (format == FMT_RGBA_HALF) { if (fmt == FMT_RGBA_HALF) {
if (Core::support.texHalf) { if (Core::support.texHalf) {
desc.ifmt = GL_RGBA; desc.ifmt = GL_RGBA;
desc.type = GL_HALF_FLOAT_OES; 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)) { if ((fmt == FMT_RGBA_FLOAT && !Core::support.colorFloat) || (fmt == FMT_RGBA_HALF && !Core::support.colorHalf)) {
desc.ifmt = GL_RGBA; desc.ifmt = GL_RGBA;
#ifdef _GAPI_GLES #ifdef _GAPI_GLES
if (format == FMT_RGBA_HALF) if (fmt == FMT_RGBA_HALF)
desc.type = GL_HALF_FLOAT_OES; desc.type = GL_HALF_FLOAT_OES;
#endif #endif
} }
@@ -430,7 +431,7 @@ namespace GAPI {
} }
void bind(int sampler) { void bind(int sampler) {
if (!this || (opt & OPT_PROXY)) return; if (opt & OPT_PROXY) return;
ASSERT(ID); ASSERT(ID);
if (Core::active.textures[sampler] != this) { if (Core::active.textures[sampler] != this) {
@@ -813,7 +814,7 @@ namespace GAPI {
} }
void resetState() { void resetState() {
if (glBindVertexArray) if (Core::support.VAO)
glBindVertexArray(0); glBindVertexArray(0);
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
@@ -990,7 +991,7 @@ namespace GAPI {
ASSERT(pso->data != NULL); ASSERT(pso->data != NULL);
uint32 state = pso->renderState; uint32 state = pso->renderState;
uint32 mask = mask; uint32 mask = 0;//mask;
if (Core::active.pso) if (Core::active.pso)
mask ^= Core::active.pso->renderState; mask ^= Core::active.pso->renderState;

View File

@@ -2,7 +2,7 @@
cls cls
set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/tinf/tinflate.c set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/tinf/tinflate.c
set PROJ=OpenLara 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. 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 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 gzip.exe -9 -f %PROJ%.data %PROJ%.js %PROJ%.js.mem

View File

@@ -97,9 +97,12 @@
if (audioContext) { if (audioContext) {
audioContext.resume(); audioContext.resume();
window.removeEventListener('touchstart', userAction, false); window.removeEventListener('touchstart', userAction, false);
window.removeEventListener('click', userAction, false);
console.log("resume playback");
} }
}; };
window.addEventListener('touchstart', userAction, false); 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}); var gl = canvasElement.getContext("webgl", {antialias:false, premultipliedAlpha: false}) || canvasElement.getContext("experimental-webgl", {antialias:false, premultipliedAlpha: false});
@@ -119,7 +122,7 @@
<input type="button" value="Browse Level" onclick="document.getElementById('browseFile').click();" /> (.PHD, .PSX, .TR2) <input type="button" value="Browse Level" onclick="document.getElementById('browseFile').click();" /> (.PHD, .PSX, .TR2)
<p style="margin:8px"> <p style="margin:8px">
OpenLara on <a target="_blank" href="https://github.com/XProger/OpenLara">github</a> & <a target="_blank" href="https://www.facebook.com/OpenLaraTR">facebook</a><br> OpenLara on <a target="_blank" href="https://github.com/XProger/OpenLara">github</a> & <a target="_blank" href="https://www.facebook.com/OpenLaraTR">facebook</a><br>
<br><i>last update: 20.04.2018</i><br> <br><i>last update: 8.05.2018</i><br>
</p> </p>
</span> </span>