Browse Source

Update nanovg

gh-pages
falkTX 10 years ago
parent
commit
78458576f7
2 changed files with 19 additions and 37 deletions
  1. +9
    -9
      dgl/src/nanovg/nanovg.c
  2. +10
    -28
      dgl/src/nanovg/nanovg_gl.h

+ 9
- 9
dgl/src/nanovg/nanovg.c View File

@@ -1359,7 +1359,7 @@ static struct NVGvertex* nvg__bevelJoin(struct NVGvertex* dst, struct NVGpoint*
nvg__vset(dst, p1->x, p1->y, 0.5f,1); dst++;
}

nvg__vset(dst, p1->x + dlx1*rw, p1->y + dly1*rw, lu,1); dst++;
nvg__vset(dst, p1->x + dlx1*lw, p1->y + dly1*lw, lu,1); dst++;
nvg__vset(dst, rx1, ry1, ru,1); dst++;
}

@@ -1565,11 +1565,11 @@ static int nvg__expandStrokeAndFill(struct NVGcontext* ctx, int feats, float w,
dly = -dx;
if (lineCap == NVG_BUTT || lineCap == NVG_SQUARE) {
if (lineCap == NVG_BUTT) {
px = p0->x;
py = p0->y;
px = p0->x + dx*ctx->fringeWidth*0.5f;
py = p0->y + dy*ctx->fringeWidth*0.5f;
} else /*if (lineCap == NVG_SQUARE)*/ {
px = p0->x - dx*w;
py = p0->y - dy*w;
px = p0->x - dx*(w - ctx->fringeWidth);
py = p0->y - dy*(w - ctx->fringeWidth);
}
nvg__vset(dst, px + dlx*lw - dx*aa, py + dly*lw - dy*aa, lu,0); dst++;
nvg__vset(dst, px - dlx*rw - dx*aa, py - dly*rw - dy*aa, ru,0); dst++;
@@ -1617,11 +1617,11 @@ static int nvg__expandStrokeAndFill(struct NVGcontext* ctx, int feats, float w,
dly = -dx;
if (lineCap == NVG_BUTT || lineCap == NVG_SQUARE) {
if (lineCap == NVG_BUTT) {
px = p1->x;
py = p1->y;
px = p1->x - dx*ctx->fringeWidth*0.5f;
py = p1->y - dy*ctx->fringeWidth*0.5f;
} else /*if (lineCap == NVG_SQUARE)*/ {
px = p1->x + dx*w;
py = p1->y + dy*w;
px = p1->x + dx*(w - ctx->fringeWidth);
py = p1->y + dy*(w - ctx->fringeWidth);
}
nvg__vset(dst, px + dlx*lw, py + dly * lw, lu,1); dst++;
nvg__vset(dst, px - dlx*rw, py - dly * rw, ru,1); dst++;


+ 10
- 28
dgl/src/nanovg/nanovg_gl.h View File

@@ -77,11 +77,11 @@ void nvgDeleteGLES3(struct NVGcontext* ctx);
#include "nanovg.h"

enum GLNVGuniformLoc {
GLNVG_LOC_VIEWSIZE,
GLNVG_LOC_TEX,
#if NANOVG_GL_USE_UNIFORMBUFFER
GLNVG_LOC_VIEW,
GLNVG_LOC_FRAG,
#else
GLNVG_LOC_VIEWSIZE,
GLNVG_LOC_SCISSORMAT,
GLNVG_LOC_SCISSOREXT,
GLNVG_LOC_SCISSORSCALE,
@@ -92,7 +92,6 @@ enum GLNVGuniformLoc {
GLNVG_LOC_INNERCOL,
GLNVG_LOC_OUTERCOL,
GLNVG_LOC_STROKEMULT,
GLNVG_LOC_TEX,
GLNVG_LOC_TEXTYPE,
GLNVG_LOC_TYPE,
#endif
@@ -108,8 +107,7 @@ enum GLNVGshaderType {

#if NANOVG_GL_USE_UNIFORMBUFFER
enum GLNVGuniformBindings {
GLNVG_VIEW_BINDING = 0,
GLNVG_FRAG_BINDING = 1,
GLNVG_FRAG_BINDING = 0,
};
#endif

@@ -179,7 +177,6 @@ struct GLNVGcontext {
GLuint vertArr;
#endif
#if NANOVG_GL_USE_UNIFORMBUFFER
GLuint viewBuf;
GLuint fragBuf;
#endif
int fragSize;
@@ -348,11 +345,12 @@ static void glnvg__deleteShader(struct GLNVGshader* shader)

static void glnvg__getUniforms(struct GLNVGshader* shader)
{
shader->loc[GLNVG_LOC_VIEWSIZE] = glGetUniformLocation(shader->prog, "viewSize");
shader->loc[GLNVG_LOC_TEX] = glGetUniformLocation(shader->prog, "tex");

#if NANOVG_GL_USE_UNIFORMBUFFER
shader->loc[GLNVG_LOC_VIEW] = glGetUniformBlockIndex(shader->prog, "view");
shader->loc[GLNVG_LOC_FRAG] = glGetUniformBlockIndex(shader->prog, "frag");
#else
shader->loc[GLNVG_LOC_VIEWSIZE] = glGetUniformLocation(shader->prog, "viewSize");
shader->loc[GLNVG_LOC_SCISSORMAT] = glGetUniformLocation(shader->prog, "scissorMat");
shader->loc[GLNVG_LOC_SCISSOREXT] = glGetUniformLocation(shader->prog, "scissorExt");
shader->loc[GLNVG_LOC_SCISSORSCALE] = glGetUniformLocation(shader->prog, "scissorScale");
@@ -363,7 +361,6 @@ static void glnvg__getUniforms(struct GLNVGshader* shader)
shader->loc[GLNVG_LOC_INNERCOL] = glGetUniformLocation(shader->prog, "innerCol");
shader->loc[GLNVG_LOC_OUTERCOL] = glGetUniformLocation(shader->prog, "outerCol");
shader->loc[GLNVG_LOC_STROKEMULT] = glGetUniformLocation(shader->prog, "strokeMult");
shader->loc[GLNVG_LOC_TEX] = glGetUniformLocation(shader->prog, "tex");
shader->loc[GLNVG_LOC_TEXTYPE] = glGetUniformLocation(shader->prog, "texType");
shader->loc[GLNVG_LOC_TYPE] = glGetUniformLocation(shader->prog, "type");
#endif
@@ -397,13 +394,7 @@ static int glnvg__renderCreate(void* uptr)

static const char* fillVertShader =
"#ifdef NANOVG_GL3\n"
"#ifdef USE_UNIFORMBUFFER\n"
" layout(std140) uniform view {\n"
" vec2 viewSize;\n"
" };\n"
"#else\n"
" uniform vec2 viewSize;\n"
"#endif\n"
" in vec2 vertex;\n"
" in vec2 tcoord;\n"
" out vec2 ftcoord;\n"
@@ -561,8 +552,6 @@ static int glnvg__renderCreate(void* uptr)

#if NANOVG_GL_USE_UNIFORMBUFFER
// Create UBOs
glUniformBlockBinding(gl->shader.prog, gl->shader.loc[GLNVG_LOC_VIEW], GLNVG_VIEW_BINDING);
glGenBuffers(1, &gl->viewBuf);
glUniformBlockBinding(gl->shader.prog, gl->shader.loc[GLNVG_LOC_FRAG], GLNVG_FRAG_BINDING);
glGenBuffers(1, &gl->fragBuf);
glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, &align);
@@ -930,18 +919,13 @@ static void glnvg__renderFlush(void* uptr, int alphaBlend)
glEnableVertexAttribArray(1);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(struct NVGvertex), (const GLvoid*)(size_t)0);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(struct NVGvertex), (const GLvoid*)(0 + 2*sizeof(float)));
#if NANOVG_GL_USE_UNIFORMBUFFER
// once per frame set ubo for view
glBindBuffer(GL_UNIFORM_BUFFER, gl->viewBuf);
glBufferData(GL_UNIFORM_BUFFER, sizeof(gl->view), 0, GL_STREAM_DRAW);
glBufferData(GL_UNIFORM_BUFFER, sizeof(gl->view), gl->view, GL_STREAM_DRAW);
glBindBufferBase(GL_UNIFORM_BUFFER, GLNVG_VIEW_BINDING, gl->viewBuf);

glBindBuffer(GL_UNIFORM_BUFFER, gl->fragBuf);
#else
// Set view and texture just once per frame.
glUniform1i(gl->shader.loc[GLNVG_LOC_TEX], 0);
glUniform2fv(gl->shader.loc[GLNVG_LOC_VIEWSIZE], 1, gl->view);

#if NANOVG_GL_USE_UNIFORMBUFFER
glBindBuffer(GL_UNIFORM_BUFFER, gl->fragBuf);
#endif

for (i = 0; i < gl->ncalls; i++) {
@@ -1228,8 +1212,6 @@ static void glnvg__renderDelete(void* uptr)

#if NANOVG_GL3
#if NANOVG_GL_USE_UNIFORMBUFFER
if (gl->viewBuf != 0)
glDeleteBuffers(1, &gl->viewBuf);
if (gl->fragBuf != 0)
glDeleteBuffers(1, &gl->fragBuf);
#endif


Loading…
Cancel
Save