1
0
Fork 0
forked from fte/fteqw

Try to fix alpha blend issues with the webgl port.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6065 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2021-10-05 05:05:06 +00:00
parent 7da9b4fcc4
commit 0eecce227e
3 changed files with 17 additions and 11 deletions

View file

@ -908,7 +908,7 @@ qboolean GL_LoadTextureMips(texid_t tex, const struct pendingtextureinfo *mips)
#ifdef FTE_TARGET_WEB #ifdef FTE_TARGET_WEB
if (encoding == PTI_WHOLEFILE) if (encoding == PTI_WHOLEFILE)
{ {
emscriptenfte_gl_loadtexturefile(tex->num, &tex->width, &tex->height, mips->mip[0].data, mips->mip[0].datasize, tex->ident); emscriptenfte_gl_loadtexturefile(tex->num, &tex->width, &tex->height, mips->mip[0].data, mips->mip[0].datasize, tex->ident, !!(tex->flags & IF_PREMULTIPLYALPHA), !(tex->flags & IF_NOMIPMAP));
return true; return true;
} }
#endif #endif

View file

@ -36,7 +36,7 @@ NORETURN void emscriptenfte_abortmainloop(const char *caller);
//we're trying to avoid including libpng+libjpeg+libogg in javascript due to it being redundant bloat. //we're trying to avoid including libpng+libjpeg+libogg in javascript due to it being redundant bloat.
//to use such textures/sounds, we can just 'directly' load them via webgl //to use such textures/sounds, we can just 'directly' load them via webgl
void emscriptenfte_gl_loadtexturefile(int gltexid, int *width, int *height, void *data, int datasize, const char *fname); void emscriptenfte_gl_loadtexturefile(int gltexid, int *width, int *height, void *data, int datasize, const char *fname, int premul, int genmips);
void emscriptenfte_al_loadaudiofile(int al_buf, void *data, int datasize); void emscriptenfte_al_loadaudiofile(int al_buf, void *data, int datasize);
//avoid all of emscripten's sdl emulation. //avoid all of emscripten's sdl emulation.

View file

@ -519,20 +519,21 @@ mergeInto(LibraryManager.library,
emscriptenfte_abortmainloop : function(fname) emscriptenfte_abortmainloop : function(fname)
{ {
fname = Pointer_stringify(fname); fname = Pointer_stringify(fname);
FTEC.aborted = true;
throw 'oh noes! something bad happened in ' + fname + '!\n' + Module['stackTrace'](); throw 'oh noes! something bad happened in ' + fname + '!\n' + Module['stackTrace']();
}, },
emscriptenfte_setupmainloop : function(fnc) emscriptenfte_setupmainloop : function(fnc)
{ {
Module['noExitRuntime'] = true; Module['noExitRuntime'] = true;
FTEC.aborted = false;
//Module.abort = abort = function(msg) {}; //Module.abort = abort = function(msg) {};
function step(timestamp)
Module["sched"] = function()
{ {
var dovsync = false; var dovsync = false;
var vr = false; var vr = false;
if (ABORT) if (FTE.aborted)
return; return;
if (FTEC.vrDisplay) if (FTEC.vrDisplay)
@ -554,15 +555,15 @@ mergeInto(LibraryManager.library,
if (dovsync) if (dovsync)
{ {
if (FTEC.vrDisplay) if (FTEC.vrDisplay)
FTEC.vrDisplay.requestAnimationFrame(Module["sched"]); FTEC.vrDisplay.requestAnimationFrame(step);
else else
Browser.requestAnimationFrame(Module["sched"]); Browser.requestAnimationFrame(step);
} }
else else
setTimeout(Module["sched"], 0); setTimeout(step, 0);
}; };
//don't start it instantly, so we can distinguish between types of errors (emscripten sucks!). //don't start it instantly, so we can distinguish between types of errors (emscripten sucks!).
setTimeout(Module["sched"], 1); setTimeout(step, 1);
}, },
emscriptenfte_ticks_ms : function() emscriptenfte_ticks_ms : function()
@ -1124,7 +1125,7 @@ console.log("onerror: " + _url);
} }
}, },
emscriptenfte_gl_loadtexturefile : function(texid, widthptr, heightptr, dataptr, datasize, fname) emscriptenfte_gl_loadtexturefile : function(texid, widthptr, heightptr, dataptr, datasize, fname, dopremul, genmips)
{ {
function encode64(data) { function encode64(data) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'; var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@ -1166,7 +1167,12 @@ console.log("onerror: " + _url);
} }
var oldtex = GLctx.getParameter(GLctx.TEXTURE_BINDING_2D); //blurgh, try to avoid breaking anything in this unexpected event. var oldtex = GLctx.getParameter(GLctx.TEXTURE_BINDING_2D); //blurgh, try to avoid breaking anything in this unexpected event.
GLctx.bindTexture(GLctx.TEXTURE_2D, gltex); GLctx.bindTexture(GLctx.TEXTURE_2D, gltex);
if (dopremul)
GLctx.pixelStorei(GLctx.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, img); GLctx.texImage2D(GLctx.TEXTURE_2D, 0, GLctx.RGBA, GLctx.RGBA, GLctx.UNSIGNED_BYTE, img);
if (dopremul)
GLctx.pixelStorei(GLctx.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
if (genmips)
GLctx.generateMipmap(GLctx.TEXTURE_2D); GLctx.generateMipmap(GLctx.TEXTURE_2D);
GLctx.bindTexture(GLctx.TEXTURE_2D, oldtex); GLctx.bindTexture(GLctx.TEXTURE_2D, oldtex);
}; };