How to set frame rate in GLFW based metal application?

37 Views Asked by At

I am working on a metal renderer with the GLFW windowing api (the reason I use glfw is for portability). The problem is that the frame rate is capped at sixty which I do not want, after some googling I found you can modify the frame rate through an MTKView, though I cannot find how to get such an object.

The questions is, can I get the MTKView through glfw somehow, or rather, how should I modify the frame rate in this situation?

Some sample code:

...
CAMetalLayer* layer = [CAMetalLayer new];
...  
NSWindow* window = glfwGetCocoaWindow(glfwWindow);
window.contentView.layer = layer;
windwo.contentView.wantsLayer = YES;
...

I must say I am completely new to Metal and I am not sure if using glfw is the way to go, I do definitely want to use Glfw since I rely on it on windows with Vulkan and I found some code can be cross platform with glfw.

(edit) Rendering happens as follows:

    id <CAMetalDrawable> surface = ...;
    MTLRenderPassDescriptor* render_pass = ...;
    id <MTLCommandQueue> queue = ...;
    CAMetalLayer* layer = ...;
    id <MTLRenderCommandEncoder> command = ...;
    id <MTLRenderPipelineState> pipeline = ...;

    id <MTLCommandBuffer> command_buffer = [queue commandBuffer];
    render_pass.colorAttachments[0].texture = surface.texture;
    
    command = [command_buffer renderCommandEncoderWithDescriptor: render_pass];
    [command setRenderPipelineState: pipeline];
    [command endEncoding];
    
    [command_buffer presentDrawable: surface];
    [command_buffer commit];
    
    surface = [layer nextDrawable];

Thank you.

0

There are 0 best solutions below