mirror of
https://github.com/XProger/OpenLara.git
synced 2025-08-15 01:24:35 +02:00
#15 WebAssembly support
This commit is contained in:
@@ -208,6 +208,8 @@ struct ShaderCache {
|
||||
Shader *getShader(Core::Pass pass, Shader::Type type, int fx) {
|
||||
Shader *shader = shaders[pass][type][fx];
|
||||
#ifndef FFP
|
||||
if (shader == NULL)
|
||||
LOG("! NULL shader: %d %d %d\n", int(pass), int(type), int(fx));
|
||||
ASSERT(shader != NULL);
|
||||
#endif
|
||||
return shader;
|
||||
@@ -217,7 +219,8 @@ struct ShaderCache {
|
||||
Core::pass = pass;
|
||||
|
||||
Shader *shader = getShader(pass, type, fx);
|
||||
shader->bind();
|
||||
if (shader)
|
||||
shader->bind();
|
||||
|
||||
Core::setAlphaTest((fx & FX_ALPHA_TEST) != 0);
|
||||
}
|
||||
|
@@ -923,10 +923,12 @@ namespace GAPI {
|
||||
}
|
||||
|
||||
void setAlphaTest(bool enable) {
|
||||
#ifdef FFP
|
||||
if (enable)
|
||||
glEnable(GL_ALPHA_TEST);
|
||||
else
|
||||
glDisable(GL_ALPHA_TEST);
|
||||
#endif
|
||||
}
|
||||
|
||||
void setCullMode(int rsMask) {
|
||||
@@ -1014,10 +1016,8 @@ namespace GAPI {
|
||||
if (mask & RS_BLEND)
|
||||
setBlendMode(state & RS_BLEND);
|
||||
|
||||
#ifdef FFP
|
||||
if (mask & RS_DISCARD)
|
||||
setAlphaTest((state & RS_DISCARD) != 0);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -716,6 +716,8 @@ struct Level : IGame {
|
||||
inventory.toggle(0, Inventory::PAGE_OPTION);
|
||||
}
|
||||
|
||||
setClipParams(1.0f, NO_CLIP_PLANE);
|
||||
|
||||
effect = TR::Effect::NONE;
|
||||
cube360 = NULL;
|
||||
|
||||
@@ -2403,8 +2405,7 @@ struct Level : IGame {
|
||||
player = players[view];
|
||||
camera = player->camera;
|
||||
|
||||
params->clipHeight = NO_CLIP_PLANE;
|
||||
params->clipSign = 1.0f;
|
||||
setClipParams(1.0f, NO_CLIP_PLANE);
|
||||
params->waterHeight = params->clipHeight;
|
||||
|
||||
if (shadow) {
|
||||
|
@@ -15,7 +15,12 @@ AddEncoding gzip .gz
|
||||
Header set Content-Encoding: gzip
|
||||
</FilesMatch>
|
||||
|
||||
<FilesMatch "\.wasm\.gz$">
|
||||
ForceType application/octet-stream
|
||||
Header set Content-Encoding: gzip
|
||||
</FilesMatch>
|
||||
|
||||
RewriteEngine on
|
||||
RewriteCond %{HTTP:Accept-Encoding} gzip
|
||||
RewriteCond %{REQUEST_FILENAME}.gz -f
|
||||
RewriteRule ^(.+)\.(js|data|mem)$ $1.$2.gz [L]
|
||||
RewriteRule ^(.+)\.(js|data|mem|wasm)$ $1.$2.gz [L]
|
8
src/platform/web/build_wasm.bat
Normal file
8
src/platform/web/build_wasm.bat
Normal file
@@ -0,0 +1,8 @@
|
||||
@echo off
|
||||
cls
|
||||
set SRC=main.cpp ../../libs/stb_vorbis/stb_vorbis.c ../../libs/tinf/tinflate.c
|
||||
set PROJ=OpenLara_wasm
|
||||
set FLAGS=-s WASM=1 -O3 -ffast-math -Wno-deprecated-register --llvm-opts 2 -fmax-type-align=2 -std=c++11 -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%.wasm %PROJ%.js.mem load-wasm-worker.js
|
@@ -85,7 +85,7 @@
|
||||
var AudioContext = window.AudioContext || window.webkitAudioContext;
|
||||
if (!AudioContext) return;
|
||||
audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
var count = 2048;
|
||||
var count = 4096;
|
||||
var rate = 44100 / audioContext.sampleRate;
|
||||
var framesCount = Math.ceil(count * rate);
|
||||
var frames = Module._malloc(framesCount * 4); // interleaved short L, R
|
||||
@@ -103,13 +103,14 @@
|
||||
proc.connect(audioContext.destination);
|
||||
}
|
||||
|
||||
// for iOS to unlock audio context after user interaction
|
||||
// unlock audio context after user interaction
|
||||
var userAction = function() {
|
||||
if (audioContext) {
|
||||
audioContext.resume();
|
||||
window.removeEventListener('touchstart', userAction, false);
|
||||
window.removeEventListener('click', userAction, false);
|
||||
console.log("resume playback");
|
||||
if (audioContext && audioContext.state == "suspended") {
|
||||
audioContext.resume().then(function() {
|
||||
window.removeEventListener('touchstart', userAction, false);
|
||||
window.removeEventListener('click', userAction, false);
|
||||
console.log("resume playback");
|
||||
});
|
||||
}
|
||||
};
|
||||
window.addEventListener('touchstart', userAction, false);
|
||||
@@ -133,26 +134,33 @@
|
||||
<input type="button" value="Browse Level" onclick="document.getElementById('browseFile').click();" /> (.PHD, .PSX, .TR2)
|
||||
<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>
|
||||
<br><i>last update: 8.05.2018</i><br>
|
||||
<br><i>last update: 9.05.2018</i><br>
|
||||
</p>
|
||||
</span>
|
||||
|
||||
<script>
|
||||
(function() {
|
||||
var memoryInitializer = 'OpenLara.js.mem';
|
||||
if (typeof Module['locateFile'] === 'function') {
|
||||
memoryInitializer = Module['locateFile'](memoryInitializer);
|
||||
} else if (Module['memoryInitializerPrefixURL']) {
|
||||
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
|
||||
}
|
||||
var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
|
||||
xhr.open('GET', memoryInitializer, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.send(null);
|
||||
})();
|
||||
|
||||
var script = document.createElement('script');
|
||||
script.src = "OpenLara.js";
|
||||
|
||||
if ('WebAssembly' in window) {
|
||||
console.log("Start WebAssembly!");
|
||||
script.src = "OpenLara_wasm.js";
|
||||
} else {
|
||||
console.log("Start asm.js!");
|
||||
script.src = "OpenLara.js";
|
||||
(function() {
|
||||
var memoryInitializer = 'OpenLara.js.mem';
|
||||
if (typeof Module['locateFile'] === 'function') {
|
||||
memoryInitializer = Module['locateFile'](memoryInitializer);
|
||||
} else if (Module['memoryInitializerPrefixURL']) {
|
||||
memoryInitializer = Module['memoryInitializerPrefixURL'] + memoryInitializer;
|
||||
}
|
||||
var xhr = Module['memoryInitializerRequest'] = new XMLHttpRequest();
|
||||
xhr.open('GET', memoryInitializer, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.send(null);
|
||||
})();
|
||||
}
|
||||
|
||||
document.body.appendChild(script);
|
||||
|
||||
window.onbeforeunload = function () { // Ctrl+W
|
||||
|
@@ -133,7 +133,9 @@ struct Shader {
|
||||
}
|
||||
|
||||
void init() {
|
||||
bind();
|
||||
Core::active.shader = this;
|
||||
glUseProgram(ID);
|
||||
|
||||
for (int st = 0; st < sMAX; st++) {
|
||||
GLint idx = glGetUniformLocation(ID, (GLchar*)SamplerName[st]);
|
||||
if (idx != -1)
|
||||
|
Reference in New Issue
Block a user