Coder Social home page Coder Social logo

Comments (5)

floooh avatar floooh commented on July 3, 2024

This isn't supported unfortunately. I had started to explore this idea in this abandondend multiwindow branch: https://github.com/floooh/sokol/tree/sapp-multiwindow, but was running into a lot of problems driving multiple MTKView in sokol_app.h in the same frame loop, the whole thing simply became too brittle before I gave up.

The sokol_gfx.h implementation would basically use the incomplete sg_context stuff (which currently only works for multiple GL contexts) and associate a context with each CAMetalLayer swapchain. But I also don't like this whole context idea anymore, it just doesn't quite fit into a "post-GL-API".

If I would ever revisit that idea, I would try to use regular pass objects instead which render into offscreen render targets, and then "somehow" blit those offscreen render targets into the various CAMetalLayer surfaces.

But this is definitely not at the top of the priority queue at the moment.

from sokol.

floooh avatar floooh commented on July 3, 2024

PS: if you're adventurous, you could try running multiple default-passes in one frame (like in this multiwindow-glfw sample: https://github.com/floooh/sokol-samples/blob/4e65abf8266911b124df931b674b65a6ec8fc4dd/glfw/multiwindow-glfw.c#L174-L199, but in the renderpass_descriptor_cb and drawable_cb callbacks which are passed into sokol-gfx the sg_setup() function, return a different MTLRenderPassDescriptor and MTLDrawable object for each default pass, so that each default pass renders into a different MTLDrawable obtained from a CAMetalLayer object.

For this to work you need to abandon sokol_app.h completely and only use sokol_gfx.h with your own window system glue.

from sokol.

danielchasehooper avatar danielchasehooper commented on July 3, 2024

We're not using sokol_app.h, so the drawable_cb approach may work for us. Thank you.

I was kind of curious why renderpass_descriptor_cb exists though. Is it just for use with MTKView? Is there ever a situation that its implementation would be anything other than:

const void* get_render_pass_descriptor(void) {
MTLRenderPassDescriptor *pass = [MTLRenderPassDescriptor renderPassDescriptor];
pass.colorAttachments[0].texture = currentDrawable.texture;
return pass;
}

(please ignore the fact that pass isn't retained anywhere, and that multiple calls to this function would create additional passes :) )

from sokol.

floooh avatar floooh commented on July 3, 2024

Yes, mainly because MTKView has a currentRenderPassDescriptor convenience method.

In sokol-gfx I'm just expecting such a pre-configured render-pass-descriptor for the default pass because it also references all the resources needed for handling things like MSAA antialiasing in the default pass (the alternative would be to pass the currentDrawable along with a matching depth-stencil texture and optionally multi-sampled texture to sokol-gfx, and sokol-gfx would then setup its own render pass descriptor (like it happens for offscreen passes).

Without MTKView, you can just create the RenderPassDescriptor similar to your code snippet, but you also need to take care of the depth-stencil texture and MSAA texture and configure the RenderPassDescriptor as described here under 'Discussion': https://developer.apple.com/documentation/metalkit/mtkview/1536024-currentrenderpassdescriptor?language=objc

from sokol.

floooh avatar floooh commented on July 3, 2024

...this should now also be fixed with #985.

from sokol.

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.