nanovg gl

This commit is contained in:
xianjimli 2020-04-28 11:59:08 +08:00
parent ebf79963bb
commit 3625701f4a
2 changed files with 34 additions and 26 deletions

View File

@ -234,6 +234,7 @@ struct GLNVGcontext {
int ctextures;
int textureId;
GLuint vertBuf;
float devicePixelRatio;
#if defined NANOVG_GL3
GLuint vertArr;
#endif
@ -996,10 +997,11 @@ static void glnvg__setUniforms(GLNVGcontext* gl, int uniformOffset, int image) {
}
static void glnvg__renderViewport(void* uptr, float width, float height, float devicePixelRatio) {
NVG_NOTUSED(devicePixelRatio);
//NVG_NOTUSED(devicePixelRatio);
GLNVGcontext* gl = (GLNVGcontext*)uptr;
gl->view[0] = width;
gl->view[1] = height;
gl->devicePixelRatio = devicePixelRatio;
}
static void glnvg__fill(GLNVGcontext* gl, GLNVGcall* call) {
@ -1547,6 +1549,7 @@ static void glnvg__renderTriangles(void* uptr, NVGpaint* paint,
GLNVGcontext* gl = (GLNVGcontext*)uptr;
GLNVGcall* call = glnvg__allocCall(gl);
GLNVGfragUniforms* frag;
float fringe = 1.0f / gl->devicePixelRatio;
if (call == NULL) return;
@ -1565,7 +1568,7 @@ static void glnvg__renderTriangles(void* uptr, NVGpaint* paint,
call->uniformOffset = glnvg__allocFragUniforms(gl, 1);
if (call->uniformOffset == -1) goto error;
frag = nvg__fragUniformPtr(gl, call->uniformOffset);
glnvg__convertPaint(gl, frag, paint, scissor, 1.0f, 1.0f, -1.0f);
glnvg__convertPaint(gl, frag, paint, scissor, 1.0f, fringe, -1.0f);
if(glnvg__VertsInScissor(verts, nverts, scissor) && glnvg_getSupportFastDraw(gl, scissor)) {
frag->type = NSVG_SHADER_FAST_FILLGLYPH;
} else {

View File

@ -200,43 +200,48 @@ vgcanvas_nanovg_screen_shader_info_t* vgcanvas_create_init_screen_shader() {
" void main(void) { \n"
" ftcoord = tcoord; \n"
#if defined(WITH_SCREEN_GL_FLIP_VERTICAL) && defined(WITH_SCREEN_GL_FLIP_HORIZONTAL)
" gl_Position = vec4(-g_vPosition.x, -g_vPosition.y, g_vPosition.z, 1.0); \n"
" gl_Position = vec4(-g_vPosition.x, -g_vPosition.y, g_vPosition.z, 1.0); \n"
#elif defined(WITH_SCREEN_GL_FLIP_VERTICAL)
" gl_Position = vec4(g_vPosition.x, -g_vPosition.y, g_vPosition.z, 1.0); \n"
" gl_Position = vec4(g_vPosition.x, -g_vPosition.y, g_vPosition.z, 1.0); \n"
#elif defined(WITH_SCREEN_GL_FLIP_HORIZONTAL)
" gl_Position = vec4(-g_vPosition.x, g_vPosition.y, g_vPosition.z, 1.0); \n"
" gl_Position = vec4(-g_vPosition.x, g_vPosition.y, g_vPosition.z, 1.0); \n"
#else
" gl_Position = vec4(g_vPosition.x, g_vPosition.y, g_vPosition.z, 1.0); \n"
" gl_Position = vec4(g_vPosition.x, g_vPosition.y, g_vPosition.z, 1.0); \n"
#endif
" } \n";
const char* fragment_shader =
" #ifdef NANOVG_GL3 \n"
" precision highp float; \n"
" in vec2 ftcoord; \n"
" out vec4 outColor; \n"
" #else \n"
" precision mediump float; \n"
" varying vec2 ftcoord; \n"
" #endif \n"
" uniform sampler2D screentexture; \n"
" void main() { \n"
" #ifdef NANOVG_GL3 \n"
" vec4 color = texture(screentexture, ftcoord); \n"
" #ifdef GL_ES \n"
" #if defined(GL_FRAGMENT_PRECISION_HIGH) || defined(NANOVG_GL3) \n"
" precision highp float; \n"
" #else \n"
" precision mediump float; \n"
" #endif \n"
" #endif \n"
" #ifdef NANOVG_GL3 \n"
" in vec2 ftcoord; \n"
" out vec4 outColor; \n"
" #else \n"
" varying vec2 ftcoord; \n"
" #endif \n"
" uniform sampler2D screentexture; \n"
" void main() { \n"
" #ifdef NANOVG_GL3 \n"
" vec4 color = texture(screentexture, ftcoord); \n"
#if defined(WITH_SCREEN_GL_BGRA)
" outColor = vec4(color.b, color.g, color.r, color.a); \n"
" outColor = vec4(color.b, color.g, color.r, color.a); \n"
#else
" outColor = vec4(color.r, color.g, color.b, color.a); \n"
" outColor = vec4(color.r, color.g, color.b, color.a); \n"
#endif
" #else \n"
" vec4 color = texture2D(screentexture, ftcoord); \n"
" #else \n"
" vec4 color = texture2D(screentexture, ftcoord); \n"
#if defined(WITH_SCREEN_GL_BGRA)
" gl_FragColor = vec4(color.b, color.g, color.r, color.a); \n"
" gl_FragColor = vec4(color.b, color.g, color.r, color.a); \n"
#else
" gl_FragColor = vec4(color.r, color.g, color.b, color.a); \n"
" gl_FragColor = vec4(color.r, color.g, color.b, color.a); \n"
#endif
" #endif \n"
" } \n";
" #endif \n"
" } \n";
vgcanvas_nanovg_screen_shader_info_t* shader_info =
(vgcanvas_nanovg_screen_shader_info_t*)TKMEM_ZALLOC(vgcanvas_nanovg_screen_shader_info_t);