|
@@ -15,8 +15,8 @@ |
|
|
// misrepresented as being the original software. |
|
|
// misrepresented as being the original software. |
|
|
// 3. This notice may not be removed or altered from any source distribution. |
|
|
// 3. This notice may not be removed or altered from any source distribution. |
|
|
// |
|
|
// |
|
|
#ifndef NANOVG_GL3_H |
|
|
|
|
|
#define NANOVG_GL3_H |
|
|
|
|
|
|
|
|
#ifndef NANOVG_GL_H |
|
|
|
|
|
#define NANOVG_GL_H |
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
#ifdef __cplusplus |
|
|
extern "C" { |
|
|
extern "C" { |
|
@@ -38,7 +38,7 @@ extern "C" { |
|
|
# define NANOVG_GLES3 1 |
|
|
# define NANOVG_GLES3 1 |
|
|
# define NANOVG_GL_IMPLEMENTATION 1 |
|
|
# define NANOVG_GL_IMPLEMENTATION 1 |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined NANOVG_GL2 |
|
|
#if defined NANOVG_GL2 |
|
|
|
|
|
|
|
@@ -62,11 +62,21 @@ void nvgDeleteGLES3(struct NVGcontext* ctx); |
|
|
|
|
|
|
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
enum NVGLtextureflags { |
|
|
|
|
|
NVGL_TEXTURE_FLIP_Y = 0x01, |
|
|
|
|
|
NVGL_TEXTURE_NODELETE = 0x02, |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
int nvglCreateImageFromHandle(struct NVGcontext* ctx, GLuint textureId, int flags); |
|
|
|
|
|
GLuint nvglImageHandle(struct NVGcontext* ctx, int image); |
|
|
|
|
|
void nvglImageFlags(struct NVGcontext* ctx, int image, int flags); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus |
|
|
#ifdef __cplusplus |
|
|
} |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
#endif /* NANOVG_GL_H */ |
|
|
|
|
|
|
|
|
#ifdef NANOVG_GL_IMPLEMENTATION |
|
|
#ifdef NANOVG_GL_IMPLEMENTATION |
|
|
|
|
|
|
|
@@ -123,6 +133,7 @@ struct GLNVGtexture { |
|
|
GLuint tex; |
|
|
GLuint tex; |
|
|
int width, height; |
|
|
int width, height; |
|
|
int type; |
|
|
int type; |
|
|
|
|
|
int flags; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
enum GLNVGcallType { |
|
|
enum GLNVGcallType { |
|
@@ -242,7 +253,7 @@ static int glnvg__deleteTexture(struct GLNVGcontext* gl, int id) |
|
|
int i; |
|
|
int i; |
|
|
for (i = 0; i < gl->ntextures; i++) { |
|
|
for (i = 0; i < gl->ntextures; i++) { |
|
|
if (gl->textures[i].id == id) { |
|
|
if (gl->textures[i].id == id) { |
|
|
if (gl->textures[i].tex != 0) |
|
|
|
|
|
|
|
|
if (gl->textures[i].tex != 0 && (gl->textures[i].flags & NVGL_TEXTURE_NODELETE) == 0) |
|
|
glDeleteTextures(1, &gl->textures[i].tex); |
|
|
glDeleteTextures(1, &gl->textures[i].tex); |
|
|
memset(&gl->textures[i], 0, sizeof(gl->textures[i])); |
|
|
memset(&gl->textures[i], 0, sizeof(gl->textures[i])); |
|
|
return 1; |
|
|
return 1; |
|
@@ -707,9 +718,6 @@ static int glnvg__convertPaint(struct GLNVGcontext* gl, struct GLNVGfragUniforms |
|
|
frag->innerCol = paint->innerColor; |
|
|
frag->innerCol = paint->innerColor; |
|
|
frag->outerCol = paint->outerColor; |
|
|
frag->outerCol = paint->outerColor; |
|
|
|
|
|
|
|
|
nvgTransformInverse(invxform, paint->xform); |
|
|
|
|
|
glnvg__xformToMat3x4(frag->paintMat, invxform); |
|
|
|
|
|
|
|
|
|
|
|
if (scissor->extent[0] < 0.5f || scissor->extent[1] < 0.5f) { |
|
|
if (scissor->extent[0] < 0.5f || scissor->extent[1] < 0.5f) { |
|
|
memset(frag->scissorMat, 0, sizeof(frag->scissorMat)); |
|
|
memset(frag->scissorMat, 0, sizeof(frag->scissorMat)); |
|
|
frag->scissorExt[0] = 1.0f; |
|
|
frag->scissorExt[0] = 1.0f; |
|
@@ -724,19 +732,32 @@ static int glnvg__convertPaint(struct GLNVGcontext* gl, struct GLNVGfragUniforms |
|
|
frag->scissorScale[0] = sqrtf(scissor->xform[0]*scissor->xform[0] + scissor->xform[2]*scissor->xform[2]) / fringe; |
|
|
frag->scissorScale[0] = sqrtf(scissor->xform[0]*scissor->xform[0] + scissor->xform[2]*scissor->xform[2]) / fringe; |
|
|
frag->scissorScale[1] = sqrtf(scissor->xform[1]*scissor->xform[1] + scissor->xform[3]*scissor->xform[3]) / fringe; |
|
|
frag->scissorScale[1] = sqrtf(scissor->xform[1]*scissor->xform[1] + scissor->xform[3]*scissor->xform[3]) / fringe; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
memcpy(frag->extent, paint->extent, sizeof(frag->extent)); |
|
|
memcpy(frag->extent, paint->extent, sizeof(frag->extent)); |
|
|
frag->strokeMult = (width*0.5f + fringe*0.5f) / fringe; |
|
|
frag->strokeMult = (width*0.5f + fringe*0.5f) / fringe; |
|
|
|
|
|
|
|
|
if (paint->image != 0) { |
|
|
if (paint->image != 0) { |
|
|
tex = glnvg__findTexture(gl, paint->image); |
|
|
tex = glnvg__findTexture(gl, paint->image); |
|
|
if (tex == NULL) return 0; |
|
|
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; |
|
|
frag->type = NSVG_SHADER_FILLIMG; |
|
|
frag->texType = tex->type == NVG_TEXTURE_RGBA ? 0 : 1; |
|
|
frag->texType = tex->type == NVG_TEXTURE_RGBA ? 0 : 1; |
|
|
} else { |
|
|
} else { |
|
|
frag->type = NSVG_SHADER_FILLGRAD; |
|
|
frag->type = NSVG_SHADER_FILLGRAD; |
|
|
frag->radius = paint->radius; |
|
|
frag->radius = paint->radius; |
|
|
frag->feather = paint->feather; |
|
|
frag->feather = paint->feather; |
|
|
|
|
|
nvgTransformInverse(invxform, paint->xform); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
glnvg__xformToMat3x4(frag->paintMat, invxform); |
|
|
|
|
|
|
|
|
return 1; |
|
|
return 1; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -1226,7 +1247,7 @@ static void glnvg__renderDelete(void* uptr) |
|
|
glDeleteBuffers(1, &gl->vertBuf); |
|
|
glDeleteBuffers(1, &gl->vertBuf); |
|
|
|
|
|
|
|
|
for (i = 0; i < gl->ntextures; i++) { |
|
|
for (i = 0; i < gl->ntextures; i++) { |
|
|
if (gl->textures[i].tex != 0) |
|
|
|
|
|
|
|
|
if (gl->textures[i].tex != 0 && (gl->textures[i].flags & NVGL_TEXTURE_NODELETE) == 0) |
|
|
glDeleteTextures(1, &gl->textures[i].tex); |
|
|
glDeleteTextures(1, &gl->textures[i].tex); |
|
|
} |
|
|
} |
|
|
free(gl->textures); |
|
|
free(gl->textures); |
|
@@ -1294,4 +1315,36 @@ void nvgDeleteGLES3(struct NVGcontext* ctx) |
|
|
nvgDeleteInternal(ctx); |
|
|
nvgDeleteInternal(ctx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
int nvglCreateImageFromHandle(struct NVGcontext* ctx, GLuint textureId, int flags) |
|
|
|
|
|
{ |
|
|
|
|
|
struct GLNVGcontext* gl = (struct GLNVGcontext*)nvgInternalParams(ctx)->userPtr; |
|
|
|
|
|
struct GLNVGtexture* tex = glnvg__allocTexture(gl); |
|
|
|
|
|
|
|
|
|
|
|
if (tex == NULL) return 0; |
|
|
|
|
|
|
|
|
|
|
|
tex->tex = textureId; |
|
|
|
|
|
tex->type = NVG_TEXTURE_RGBA; |
|
|
|
|
|
tex->flags = 0; |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, tex->tex); |
|
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &tex->width); |
|
|
|
|
|
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &tex->height); |
|
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0); |
|
|
|
|
|
|
|
|
|
|
|
return tex->id; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GLuint nvglImageHandle(struct NVGcontext* ctx, int image) |
|
|
|
|
|
{ |
|
|
|
|
|
struct GLNVGcontext* gl = (struct GLNVGcontext*)nvgInternalParams(ctx)->userPtr; |
|
|
|
|
|
struct GLNVGtexture* tex = glnvg__findTexture(gl, image); |
|
|
|
|
|
return tex->tex; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void nvglImageFlags(struct NVGcontext* ctx, int image, int flags) |
|
|
|
|
|
{ |
|
|
|
|
|
struct GLNVGcontext* gl = (struct GLNVGcontext*)nvgInternalParams(ctx)->userPtr; |
|
|
|
|
|
struct GLNVGtexture* tex = glnvg__findTexture(gl, image); |
|
|
|
|
|
tex->flags = flags; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#endif /* NANOVG_GL_IMPLEMENTATION */ |