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
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;
}
#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.
//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);
//avoid all of emscripten's sdl emulation.

View File

@ -519,20 +519,21 @@ mergeInto(LibraryManager.library,
emscriptenfte_abortmainloop : function(fname)
{
fname = Pointer_stringify(fname);
FTEC.aborted = true;
throw 'oh noes! something bad happened in ' + fname + '!\n' + Module['stackTrace']();
},
emscriptenfte_setupmainloop : function(fnc)
{
Module['noExitRuntime'] = true;
FTEC.aborted = false;
//Module.abort = abort = function(msg) {};
Module["sched"] = function()
function step(timestamp)
{
var dovsync = false;
var vr = false;
if (ABORT)
if (FTE.aborted)
return;
if (FTEC.vrDisplay)
@ -554,15 +555,15 @@ mergeInto(LibraryManager.library,
if (dovsync)
{
if (FTEC.vrDisplay)
FTEC.vrDisplay.requestAnimationFrame(Module["sched"]);
FTEC.vrDisplay.requestAnimationFrame(step);
else
Browser.requestAnimationFrame(Module["sched"]);
Browser.requestAnimationFrame(step);
}
else
setTimeout(Module["sched"], 0);
setTimeout(step, 0);
};
//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()
@ -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) {
var BASE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
@ -1166,8 +1167,13 @@ console.log("onerror: " + _url);
}
var oldtex = GLctx.getParameter(GLctx.TEXTURE_BINDING_2D); //blurgh, try to avoid breaking anything in this unexpected event.
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.generateMipmap(GLctx.TEXTURE_2D);
if (dopremul)
GLctx.pixelStorei(GLctx.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false);
if (genmips)
GLctx.generateMipmap(GLctx.TEXTURE_2D);
GLctx.bindTexture(GLctx.TEXTURE_2D, oldtex);
};
img.crossorigin = true;