Engine integration (iOS, Metal, sokol_gfx)
Posted: 30 Apr 2021, 09:57
Hi everyone!
We have a custom cross-platform engine that is deployed pretty much everywhere (Windows, Web via emscripten, iOS, etc). As our rendering layer we are using sokol_gfx (https://github.com/floooh/sokol), which basically is a wrapper around opengl/d3d11/metal.
Up til now we have been able to integrate sokol_gfx rendering with platform specific renderers in the Noesis App Framework, example of our D3D11 integration:
This has worked fine until now, but now we are starting to expand to iOS and are hitting a road block with the Metal integration. We think we have managed to extract the following metal context members from sokol:
But it has not at all been obvious how to go from there to running the Application Framework's Metal renderer. This is on us of course (we are not super familiar with either objective-c or Metal).
We are wondering if there are any easier / more minimal metal integrations samples we could look at?
Thanks for the help and have a nice day! :)
We have a custom cross-platform engine that is deployed pretty much everywhere (Windows, Web via emscripten, iOS, etc). As our rendering layer we are using sokol_gfx (https://github.com/floooh/sokol), which basically is a wrapper around opengl/d3d11/metal.
Up til now we have been able to integrate sokol_gfx rendering with platform specific renderers in the Noesis App Framework, example of our D3D11 integration:
Code: Select all
// Grab D3D11 stuff from sokol
ID3D11DeviceContext* ctx =
reinterpret_cast<ID3D11DeviceContext*>(const_cast<void*>(sapp_d3d11_get_device_context()));
ID3D11RenderTargetView* rtv =
reinterpret_cast<ID3D11RenderTargetView*>(const_cast<void*>(sapp_d3d11_get_render_target_view()));
ID3D11DepthStencilView* dsv =
reinterpret_cast<ID3D11DepthStencilView*>(const_cast<void*>(sapp_d3d11_get_depth_stencil_view()));
// Set D3D11 render targets and clear for noesis app framework
ctx->OMSetRenderTargets(1, &rtv, dsv);
float clearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
ctx->ClearDepthStencilView(dsv, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
// Rendering is done in the active framebuffer
state->view->GetRenderer()->Render();
// Signal to sokol_gfx that we have directly called the underlying 3D API.
sg_reset_state_cache();
Code: Select all
id<MTLDevice> device = (__bridge id<MTLDevice>)sapp_metal_get_device();
id<CAMetalDrawable> drawable = (__bridge id<CAMetalDrawable>)sapp_metal_get_drawable();
MTLRenderPassDescriptor* renderPassDescriptor = (__bridge MTLRenderPassDescriptor*)sapp_metal_get_renderpass_descriptor();
We are wondering if there are any easier / more minimal metal integrations samples we could look at?
Thanks for the help and have a nice day! :)