handle screen rotation correctly & fix: srgb

This commit is contained in:
Samuliak 2024-07-02 20:31:59 +02:00
parent 05fd1d5c29
commit 1df81c373c
3 changed files with 51 additions and 11 deletions

View file

@ -118,9 +118,8 @@ void RendererMTL::initGraphicsContext(SDL_Window* window) {
MTL::RenderPipelineDescriptor* displayPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
displayPipelineDescriptor->setVertexFunction(vertexDisplayFunction);
displayPipelineDescriptor->setFragmentFunction(fragmentDisplayFunction);
// HACK
auto* displayColorAttachment = displayPipelineDescriptor->colorAttachments()->object(0);
displayColorAttachment->setPixelFormat(MTL::PixelFormat::PixelFormatBGRA8Unorm_sRGB);
displayColorAttachment->setPixelFormat(MTL::PixelFormat::PixelFormatBGRA8Unorm);
error = nullptr;
displayPipeline = device->newRenderPipelineState(displayPipelineDescriptor, &error);
@ -128,6 +127,22 @@ void RendererMTL::initGraphicsContext(SDL_Window* window) {
Helpers::panic("Error creating display pipeline state: %s", error->description()->cString(NS::ASCIIStringEncoding));
}
// Blit
MTL::Function* vertexBlitFunction = library->newFunction(NS::String::string("vertexBlit", NS::ASCIIStringEncoding));
MTL::Function* fragmentBlitFunction = library->newFunction(NS::String::string("fragmentBlit", NS::ASCIIStringEncoding));
MTL::RenderPipelineDescriptor* blitPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
blitPipelineDescriptor->setVertexFunction(vertexBlitFunction);
blitPipelineDescriptor->setFragmentFunction(fragmentBlitFunction);
auto* blitColorAttachment = blitPipelineDescriptor->colorAttachments()->object(0);
blitColorAttachment->setPixelFormat(MTL::PixelFormat::PixelFormatBGRA8Unorm);
error = nullptr;
blitPipeline = device->newRenderPipelineState(blitPipelineDescriptor, &error);
if (error) {
Helpers::panic("Error creating blit pipeline state: %s", error->description()->cString(NS::ASCIIStringEncoding));
}
// Draw
MTL::Function* vertexDrawFunction = library->newFunction(NS::String::string("vertexDraw", NS::ASCIIStringEncoding));
MTL::Function* fragmentDrawFunction = library->newFunction(NS::String::string("fragmentDraw", NS::ASCIIStringEncoding));
@ -135,7 +150,7 @@ void RendererMTL::initGraphicsContext(SDL_Window* window) {
MTL::RenderPipelineDescriptor* drawPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
drawPipelineDescriptor->setVertexFunction(vertexDrawFunction);
drawPipelineDescriptor->setFragmentFunction(fragmentDrawFunction);
// HACK
auto* drawColorAttachment = drawPipelineDescriptor->colorAttachments()->object(0);
drawColorAttachment->setPixelFormat(MTL::PixelFormatRGBA8Unorm);
drawColorAttachment->setBlendingEnabled(true);
@ -281,7 +296,7 @@ void RendererMTL::displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize,
colorAttachment->setStoreAction(MTL::StoreActionStore);
MTL::RenderCommandEncoder* renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
renderCommandEncoder->setRenderPipelineState(displayPipeline);
renderCommandEncoder->setRenderPipelineState(blitPipeline);
renderCommandEncoder->setFragmentTexture(srcFramebuffer->texture, 0);
renderCommandEncoder->setFragmentSamplerState(basicSampler, 0);