Giter Site home page Giter Site logo

s_framebuffer isn't thread safe about metalnanovg HOT 7 OPEN

ollix avatar ollix commented on May 17, 2024
s_framebuffer isn't thread safe

from metalnanovg.

Comments (7)

olliwang avatar olliwang commented on May 17, 2024

nanovg itself is not thread safe as mentioned in memononen/nanovg#292.

s_framebuffer is only a weak reference to the currently binded framebuffer through mnvgBindFramebuffer(). Users should call mnvgBindFramebuffer(NULL) manually afterward. The logic behind mnvgCreateFramebuffer(), mnvgDeleteFramebuffer() and mnvgBindFramebuffer() basically follow the corresponded functions defined in nanovg_gl_utils.h.

from metalnanovg.

wtholliday avatar wtholliday commented on May 17, 2024

How unfortunate. Where is the global state in nanovg?

from metalnanovg.

wtholliday avatar wtholliday commented on May 17, 2024

I couldn't find any global state in nanovg itself. Perhaps it is ok to use different nanovg contexts on different threads? Obviously, you can't use a single context in multiple threads.

from metalnanovg.

olliwang avatar olliwang commented on May 17, 2024

I didn't test multithreading environment. But I think it's ok to move the global s_framebuffer into MNVGcontext and renamed to bindedFramebuffer.

from metalnanovg.

wtholliday avatar wtholliday commented on May 17, 2024

boundFramebuffer would be the grammatically correct name :)

from metalnanovg.

olliwang avatar olliwang commented on May 17, 2024

Thanks for correction. Do you have multithreading environment to test the result? There may need an additional mnvgUnbindFramebuffer() function to make the changes work. However, that would break the consistency of original nanovg APIs. Or, can you test the GL backend with multithreading environment? If it doesn't work anyway. Then no bother to make the changes.

from metalnanovg.

wtholliday avatar wtholliday commented on May 17, 2024

I'm only rendering on a single thread at a time.

The way I did it, calling mnvgBindFramebuffer(nvg, 0) unbinds.

Here's my change: wtholliday@e2c9b99

I think it's ok for the backend APIs to differ a little.

from metalnanovg.

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.