modify to use dummy texture even without emscripten

master
Oli Larkin 2020-03-06 11:10:34 +00:00
parent 3e986cdf4b
commit 35dbc98160
1 changed files with 13 additions and 15 deletions

View File

@ -269,9 +269,7 @@ struct GLNVGcontext {
GLNVGblend blendFunc;
#endif
#ifdef __EMSCRIPTEN__
int dummyTex;
#endif
};
typedef struct GLNVGcontext GLNVGcontext;
@ -504,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;
@ -704,9 +704,9 @@ static int glnvg__renderCreate(void* uptr)
#endif
gl->fragSize = sizeof(GLNVGfragUniforms) + align - sizeof(GLNVGfragUniforms) % align;
#ifdef __EMSCRIPTEN__
gl->dummyTex = glnvg__renderCreateTexture(&gl, NVG_TEXTURE_ALPHA, 1, 1, 0, NULL);
#endif
// 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");
@ -981,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
@ -989,17 +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 {
#ifdef __EMSCRIPTEN__
GLNVGtexture* tex = glnvg__findTexture(gl, gl->dummyTex);
glnvg__bindTexture(gl, tex->tex);
#else
glnvg__bindTexture(gl, 0);
#endif
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)