static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image) { glBindBufferRange(GL_UNIFORM_BUFFER, GFX_NVG_BINDING_FRAG_UBO, gfx::dynBuffer, uniformOffset, sizeof(GLNVGfragUniforms)); if (image != 0) { GLNVGtexture* tex = glnvg__findTexture(gl, image); glBindTextureUnit(0, tex ? tex->tex : 0); } else { glBindTextureUnit(0, 0); } }
static int glnvg__renderGetTextureSize(void* uptr, int image, int* w, int* h) { GLNVGcontext* gl = (GLNVGcontext*)uptr; GLNVGtexture* tex = glnvg__findTexture(gl, image); if (tex == NULL) return 0; *w = tex->width; *h = tex->height; return 1; }
static int glnvg__renderUpdateTexture(void* uptr, int image, int x, int y, int w, int h, const unsigned char* data) { GLNVGcontext* gl = (GLNVGcontext*)uptr; GLNVGtexture* tex = glnvg__findTexture(gl, image); if (tex == NULL) return 0; glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glPixelStorei(GL_UNPACK_ROW_LENGTH, tex->width); glPixelStorei(GL_UNPACK_SKIP_PIXELS, x); glPixelStorei(GL_UNPACK_SKIP_ROWS, y); if (tex->type == NVG_TEXTURE_RGBA) glTextureSubImage2D(tex->tex, 0, x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, data); else glTextureSubImage2D(tex->tex, 0, x, y, w, h, GL_RED, GL_UNSIGNED_BYTE, data); glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); return 1; }
bgfx::TextureHandle nvglImageHandle(NVGcontext* _ctx, int32_t _image) { GLNVGcontext* gl = (GLNVGcontext*)nvgInternalParams(_ctx)->userPtr; GLNVGtexture* tex = glnvg__findTexture(gl, _image); return tex->id; }
static int glnvg__convertPaint(GLNVGcontext* gl, GLNVGfragUniforms* frag, NVGpaint* paint, NVGscissor* scissor, float width, float fringe, float strokeThr) { PROFILER_CPU_TIMESLICE("NVG backend convertPaint"); GLNVGtexture* tex = NULL; float invxform[6]; mem_zero(frag); frag->innerCol = glnvg__premulColor(paint->innerColor); frag->outerCol = glnvg__premulColor(paint->outerColor); if (scissor->extent[0] < -0.5f || scissor->extent[1] < -0.5f) { mem_zero(frag->scissorMat); frag->scissorExt[0] = 1.0f; frag->scissorExt[1] = 1.0f; frag->scissorScale[0] = 1.0f; frag->scissorScale[1] = 1.0f; } else { nvgTransformInverse(invxform, scissor->xform); glnvg__xformToMat3x4(frag->scissorMat, invxform); frag->scissorExt[0] = scissor->extent[0]; frag->scissorExt[1] = scissor->extent[1]; frag->scissorScale[0] = ml::sqrt(scissor->xform[0] * scissor->xform[0] + scissor->xform[2] * scissor->xform[2]) / fringe; frag->scissorScale[1] = ml::sqrt(scissor->xform[1] * scissor->xform[1] + scissor->xform[3] * scissor->xform[3]) / fringe; } mem_copy(frag->extent, paint->extent, sizeof(frag->extent)); frag->strokeMult = (width*0.5f + fringe*0.5f) / fringe; frag->strokeThr = strokeThr; if (paint->image != 0) { tex = glnvg__findTexture(gl, paint->image); if (tex == NULL) return 0; if ((tex->flags & NVGL_TEXTURE_FLIP_Y) != 0) { float flipped[6]; nvgTransformScale(flipped, 1.0f, -1.0f); nvgTransformMultiply(flipped, paint->xform); nvgTransformInverse(invxform, flipped); } else { nvgTransformInverse(invxform, paint->xform); } frag->type = NSVG_SHADER_FILLIMG; if (tex->type == NVG_TEXTURE_RGBA) frag->texType = (tex->flags & NVGL_TEXTURE_PREMULTIPLIED) ? 0 : 1; else frag->texType = 2; // printf("frag->texType = %d\n", frag->texType); } else { frag->type = NSVG_SHADER_FILLGRAD; frag->radius = paint->radius; frag->feather = paint->feather; nvgTransformInverse(invxform, paint->xform); } glnvg__xformToMat3x4(frag->paintMat, invxform); return 1; }