Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGL 3 context sharing is broken #631

Open
lochnessdragon opened this issue May 12, 2022 · 5 comments
Open

OpenGL 3 context sharing is broken #631

lochnessdragon opened this issue May 12, 2022 · 5 comments

Comments

@lochnessdragon
Copy link

I'm trying to use NanoVG to render to multiple windows whilst sharing the same OpenGL context to resolve the reasons outlined in Issue #379. However, since the OpenGL 3 implementation uses VAOs, this breaks rendering on the second window.

Expected:

  • I'd expect both windows to render the content correctly.

Actual:

  • The second window doesn't render anything and the error 0x000501 after tex paint tex is printed to the console.

To recreate:

  • Create a window with an OpenGL3 context
  • Create an OpenGL 3 NanoVG object
  • Create a second window w/ a shared context
  • Render something to both windows
lochnessdragon pushed a commit to lochnessdragon/nanovg that referenced this issue May 13, 2022
@nidefawl
Copy link

I added a comment to your commit.

Is the VAO all that is needed to enable context sharing?

I would rather have nvgAddGlContext/nvgRemoveGlContext that sets up the VAO for the nvg+GL combo.
That way I can control the contexts at a higher level instead of calling glIsVertexArray each render flush.

@mulle-nat
Copy link
Contributor

I am sharing textures (not vertex arrays) between contexts successfully. I extended the nanovg API with these three methods:

// @mulle-nanovg@ >
// This is like nvglCreateImageFromHandleGL3
// In order to share images, the windows these
// contexts belong to, must have been created with object sharing.
// Returns handle to the image.
int nvgCreateImageTexture(NVGcontext* ctx, int w, int h, int imageFlags, int type, void **texture);

// Get the OpenGL/Vulkan texture opaque handle (OpenGL is really unsigned int)
void nvgImageTextureInfo( NVGcontext* ctx, int image, int *imageFlags, int *type, void **texture);

// Relinquish OpenGL/Vulkan texture id, so it won't be deleted when the
// image is deleted
void nvgForgetImageTexture(NVGcontext* ctx, int image);
// @mulle-nanovg@ <

In essence what this does is make an OpenGL texture known to nanovg and usuable as the image int and then make nanovg forget it again. nanovg doesn't actually manage the OpenGL texture with this API and retain count management is done above nanovg to keep it simple.

One could extend this scheme to other OpenGL objects besides textures, but if it's just to offload code into nanovg, that could be done elsewhere, it would kill the "nano" in nanovg IMO.

@ib00
Copy link

ib00 commented Dec 30, 2022

Are these three extensions available somewhere?

@mulle-nat
Copy link
Contributor

Not yet. I plan to release my stuff, but I am already a year behind 😩

@mulle-nat
Copy link
Contributor

I put my nanovg fork out there (not really a release yet). The relevant API tidbits for this issue are in the header and source. The actual work is done via the callbacks declared in struct NVGparams and defined in nanovg_gl.h.

As explained above this is very lowlevel and the actual texture sharing logic is implemented on top of it. But without these functions, you couldn't get nanovg to use a shared texture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants