Giter Site home page Giter Site logo

sokol-multithread's Introduction

A simple wrapper for sokol_gfx (see https://github.com/floooh/sokol) enabling multithreaded rendering.

Typically you would use it as follows:

Render thread

  • create renderer instance, passing sg_desc to initialise sokol graphics
  • call renderer->set_default_pass_size() and again whenever back buffer size changes
  • call renderer->execute_commands() in render loop
  • call renderer->wait_for_flush() on termination
  • delete renderer instance

Update thread

  • call renderer->add_command_xxx() commands in a similar manner to how you would call sg_xxx() commands
  • call renderer->commit_commands() when you're done for the frame
  • call renderer->flush_commands() on termination, before exiting the thread

There is also a modified version of sokol_imgui.h as an example.

Resources

When creating or updating resources (buffers, images etc) it is up to the caller to ensure that any pointers passed into an add_command_xxx() call made in the update thread remain valid until the underlying sg_xxx() command has been issued from the render thread.

To help with this, you can optionally schedule clean-ups via the renderer->schedule_cleanup() function which allows user-provided callbacks to be called after all the commands to create the resources have been executed.

These cleanup calls can be used to free up the memory or clean-up any objects that own the memory and avoids the need for the wrapper to make any copies of data. For convenience, these calls are also made from the update thread from inside a later commit_commands() call.

sokol-multithread's People

Contributors

oviano avatar

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.