From d98041b4ee29585977feb9e69b403d4804af5d5c Mon Sep 17 00:00:00 2001 From: Oli Larkin Date: Mon, 2 Mar 2020 23:18:05 +0000 Subject: [PATCH] Bind a dummy texture in setUniforms when compiling with emscripten fixes the WebGL error "RENDER WARNING: there is no texture bound to the unit 0"" in Chrome --- src/nanovg_gl.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/nanovg_gl.h b/src/nanovg_gl.h index 5332da1..046648b 100644 --- a/src/nanovg_gl.h +++ b/src/nanovg_gl.h @@ -268,6 +268,10 @@ struct GLNVGcontext { GLuint stencilFuncMask; GLNVGblend blendFunc; #endif + +#ifdef __EMSCRIPTEN__ + int dummyTex; +#endif }; typedef struct GLNVGcontext GLNVGcontext; @@ -704,6 +708,10 @@ static int glnvg__renderCreate(void* uptr) glFinish(); +#ifdef __EMSCRIPTEN__ + gl->dummyTex = 0; +#endif + return 1; } @@ -985,7 +993,15 @@ static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image) glnvg__bindTexture(gl, tex != NULL ? tex->tex : 0); glnvg__checkError(gl, "tex paint tex"); } else { +#ifdef __EMSCRIPTEN__ + if(gl->dummyTex == 0) { + gl->dummyTex = glnvg__renderCreateTexture(&gl, NVG_TEXTURE_ALPHA, 2, 2, 0, NULL); + } + GLNVGtexture* tex = glnvg__findTexture(gl, gl->dummyTex); + glnvg__bindTexture(gl, tex->tex); +#else glnvg__bindTexture(gl, 0); +#endif } }