memononen / nanovg

Antialiased 2D vector drawing library on top of OpenGL for UI and visualizations.
zlib License
5.15k stars 770 forks source link

Add Get GL Texture Id #639

Closed rgb2hsv closed 2 years ago

rgb2hsv commented 2 years ago

This PR adds the ability to retrieve the GL texture Id for an image allocated by NVG. The idea is that we would want to map a frame buffer to an existing NVG image to render a shader with some type of animation. It's better to use an existing NVG texture because it preserves z-order with other NVG components.

mulle-nat commented 2 years ago

There are already functions for this:

GLuint nvglImageHandleGLES2(NVGcontext* ctx, int image);
GLuint nvglImageHandleGLES3(NVGcontext* ctx, int image);
GLuint nvglImageHandleGL3(NVGcontext* ctx, int image);
GLuint nvglImageHandleGL2(NVGcontext* ctx, int image);
rgb2hsv commented 2 years ago

That's cool! But those functions aren't public in nanovg.h header so that the application can use them easily. As far as I know, you can include nanovg.h in lots of files, but nanovg_gl.h only once. Their name is also specific to the implementation, which is not ideal.

mulle-nat commented 2 years ago

Check #347 where I show, how to use nanovg_gl.h when not defining NANOVG_..._IMPLEMENTATION. I think the naming thing you can work around yourself fairly easily (just my opinion though).

rgb2hsv commented 2 years ago

Interesting .. sounds like a bit of a fluke related to the nvgCreateGL3 symbol being exported in one compilation and not in another because of how the defines are called (and compiler configured). The "include only once" behavior is an artifact of "header only" implementations as Mikko pointed out. Still think this PR will make things easier for anyone trying to add custom shaders in with their NVG (like me).

memononen commented 2 years ago

The function you implemented is OpenGL specific, so it should go into the OpenGL backend header, and the functionality already exists there.