Merge pull request #567 from olilarkin/fix-webgl-warning

Bind a dummy texture in setUniforms when compiling with emscripten
master
Mikko Mononen 2020-03-11 23:12:37 +02:00 committed by GitHub
commit bff4734a9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 5 deletions

View File

@ -268,6 +268,8 @@ struct GLNVGcontext {
GLuint stencilFuncMask;
GLNVGblend blendFunc;
#endif
int dummyTex;
};
typedef struct GLNVGcontext GLNVGcontext;
@ -500,6 +502,8 @@ static void glnvg__getUniforms(GLNVGshader* shader)
#endif
}
static int glnvg__renderCreateTexture(void* uptr, int type, int w, int h, int imageFlags, const unsigned char* data);
static int glnvg__renderCreate(void* uptr)
{
GLNVGcontext* gl = (GLNVGcontext*)uptr;
@ -700,6 +704,10 @@ static int glnvg__renderCreate(void* uptr)
#endif
gl->fragSize = sizeof(GLNVGfragUniforms) + align - sizeof(GLNVGfragUniforms) % align;
// Some platforms does not allow to have samples to unset textures.
// Create empty one which is bound when there's no texture specified.
gl->dummyTex = glnvg__renderCreateTexture(gl, NVG_TEXTURE_ALPHA, 1, 1, 0, NULL);
glnvg__checkError(gl, "create done");
glFinish();
@ -973,6 +981,7 @@ static GLNVGfragUniforms* nvg__fragUniformPtr(GLNVGcontext* gl, int i);
static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image)
{
GLNVGtexture* tex = NULL;
#if NANOVG_GL_USE_UNIFORMBUFFER
glBindBufferRange(GL_UNIFORM_BUFFER, GLNVG_FRAG_BINDING, gl->fragBuf, uniformOffset, sizeof(GLNVGfragUniforms));
#else
@ -981,12 +990,14 @@ static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image)
#endif
if (image != 0) {
GLNVGtexture* tex = glnvg__findTexture(gl, image);
glnvg__bindTexture(gl, tex != NULL ? tex->tex : 0);
glnvg__checkError(gl, "tex paint tex");
} else {
glnvg__bindTexture(gl, 0);
tex = glnvg__findTexture(gl, image);
}
// If no image is set, use empty texture
if (tex == NULL) {
tex = glnvg__findTexture(gl, gl->dummyTex);
}
glnvg__bindTexture(gl, tex != NULL ? tex->tex : 0);
glnvg__checkError(gl, "tex paint tex");
}
static void glnvg__renderViewport(void* uptr, float width, float height, float devicePixelRatio)