Giter Site home page Giter Site logo

GLES2 issues about nanovg HOT 13 CLOSED

memononen avatar memononen commented on August 16, 2024
GLES2 issues

from nanovg.

Comments (13)

memononen avatar memononen commented on August 16, 2024

I made a potential fix for this. Can you check if it works properly?
If I add the client API hint and version + precision, I'm not able to test it anymore on my machine, but the code works fine if I comment out those two things. Please note that I added the changes behind a NANOVG_GLES2 define which you need to define before including nanovg_gl2.h

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

That works.

But, I have an additional request :)

My code does runtime detection of OpenGL version, and therefore I am compiling in all of the GL2, GLES2, GL3 renderers, each in separate compilation units, but linking all in to a single static library. To avoid collisions, can NANOVG_GLES2 modify the names of the two non-static functions? Otherwise I won't be able to simultaneously compile in GL2 and GLES2 support. Alternatively, could we dispatch GL2 vs GLES2 (vs GLES3?) with a runtime option to nvgCreateGL2?

#ifdef NANOVG_GLES2
struct NVGcontext* nvgCreateGLES2(int atlasw, int atlash, int edgeaa);
void nvgDeleteGLES2(struct NVGcontext* ctx);
#else
struct NVGcontext* nvgCreateGL2(int atlasw, int atlash, int edgeaa);
void nvgDeleteGL2(struct NVGcontext* ctx);
#endif

Also, why not reduce NANOVG_GLES2 + NANOVG_GL2_IMPLEMENTATION to NANOVG_GLES2_IMPLEMENTATION?

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

Sorry, one other thing, I would actually prefer GL_ALPHA over GL_LUMINANCE. Even though this is the GL(ES2) backend, this way it could still compile with only glcorearb.h, which contains GL_ALPHA, but not GL_LUMINANCE.

from nanovg.

memononen avatar memononen commented on August 16, 2024

NANOVG_GLES2_IMPLEMENTATION and the different name for create is good idea, I'll do that.
I was using luminance as it behaved really close to red in shaders, alpha should not be hard to do.
I'm not familiar with glcorearb.h, in what case it is used?

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

glcorearb.h only includes what is required for the desktop OpenGL 3.2+ core profile, which my code restricts itself to, even when supporting OpenGL (ES) 2.

I didn't realize there was a difference between luminance in alpha in terms of it's behavior in shaders. If that's the case, then never mind. It was really just an internal need for my project, which I can deal with.

from nanovg.

memononen avatar memononen commented on August 16, 2024

Ah, now got the glcorearb.h, thanks for clarifying it :)

According to the docs GL_RED should be available in ES 3.0 [1]
Generally I would like to use GL_ALPHA format, as it makes it easy to use it in the pixel shader, it exands to (1,1,1,a), so same texture lookup can be used to rgba and alpha textures. 3.2 core profile does not support that, which requires to to use GL_RED for single channel textures. This shader line deals with it:
" color = texType == 0 ? color : vec4(1,1,1,color.x);\n"
Since luminance expands to L,L,L,1 the same shader can be used for luminance and red.

I'd like to use GL_RED in the gl3 back end for ES 3.0 too, do you know if that compiles fine?

[1] http://www.khronos.org/registry/gles/specs/3.0/es_spec_3.0.0.pdf

from nanovg.

memononen avatar memononen commented on August 16, 2024

I tried to use NANOVG_GLES2_IMPLEMENTATION, but that does not allow me to change the create function to nvgCreateGLESx() as the header in mean to work without specifying the implementation. Do you have preferences on that?

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

Ah ok, the only other thing for it to run on my system with a GLES3 context is that the internal format has to be GL_R8 rather than GL_RED:

glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_RED, GL_UNSIGNED_BYTE, data);

The other command works with

glTexSubImage2D(GL_TEXTURE_2D, 0, x,y, w,h, GL_RED, GL_UNSIGNED_BYTE, data);

from nanovg.

memononen avatar memononen commented on August 16, 2024

Update with your most recent comments, can you try it out?

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

The GLES3 version compiles and runs fine with the latest changes.

I see what you mean regarding the defines. How about having something in nanovg_gl2.h where

#ifdef NANOVG_GLES2_IMPLEMENTATION
#  define NANOVG_GLES2
#endif

so that internally nanovg_gl2.h interprets NANOVG_GLES2_IMPLEMENTATION as implying NANOVG_GLES2 so that the user only needs to write a single #define:

// just include NanoVG GLES2 prototypes
#define NANOVG_GLES2
#include <nanovg_gl2.h>
// include NanoVG GLES2 prototypes and implementation
#define NANOVG_GLES2_IMPLEMENTATION
#include <nanovg_gl2.h>

from nanovg.

memononen avatar memononen commented on August 16, 2024

That sounds like good solution.

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

Sorry, I messed that up... Fixing it

from nanovg.

andrewcorrigan avatar andrewcorrigan commented on August 16, 2024

I think everything from this discussion is resolved.

from nanovg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.