mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-16 18:59:48 +12:00
handle screen rotation correctly & fix: srgb
This commit is contained in:
parent
05fd1d5c29
commit
1df81c373c
3 changed files with 51 additions and 11 deletions
|
@ -44,6 +44,7 @@ class RendererMTL final : public Renderer {
|
||||||
|
|
||||||
// Pipelines
|
// Pipelines
|
||||||
MTL::RenderPipelineState* displayPipeline;
|
MTL::RenderPipelineState* displayPipeline;
|
||||||
|
MTL::RenderPipelineState* blitPipeline;
|
||||||
MTL::RenderPipelineState* drawPipeline;
|
MTL::RenderPipelineState* drawPipeline;
|
||||||
|
|
||||||
// Active state
|
// Active state
|
||||||
|
|
|
@ -118,9 +118,8 @@ void RendererMTL::initGraphicsContext(SDL_Window* window) {
|
||||||
MTL::RenderPipelineDescriptor* displayPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
MTL::RenderPipelineDescriptor* displayPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||||
displayPipelineDescriptor->setVertexFunction(vertexDisplayFunction);
|
displayPipelineDescriptor->setVertexFunction(vertexDisplayFunction);
|
||||||
displayPipelineDescriptor->setFragmentFunction(fragmentDisplayFunction);
|
displayPipelineDescriptor->setFragmentFunction(fragmentDisplayFunction);
|
||||||
// HACK
|
|
||||||
auto* displayColorAttachment = displayPipelineDescriptor->colorAttachments()->object(0);
|
auto* displayColorAttachment = displayPipelineDescriptor->colorAttachments()->object(0);
|
||||||
displayColorAttachment->setPixelFormat(MTL::PixelFormat::PixelFormatBGRA8Unorm_sRGB);
|
displayColorAttachment->setPixelFormat(MTL::PixelFormat::PixelFormatBGRA8Unorm);
|
||||||
|
|
||||||
error = nullptr;
|
error = nullptr;
|
||||||
displayPipeline = device->newRenderPipelineState(displayPipelineDescriptor, &error);
|
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));
|
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
|
// Draw
|
||||||
MTL::Function* vertexDrawFunction = library->newFunction(NS::String::string("vertexDraw", NS::ASCIIStringEncoding));
|
MTL::Function* vertexDrawFunction = library->newFunction(NS::String::string("vertexDraw", NS::ASCIIStringEncoding));
|
||||||
MTL::Function* fragmentDrawFunction = library->newFunction(NS::String::string("fragmentDraw", 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();
|
MTL::RenderPipelineDescriptor* drawPipelineDescriptor = MTL::RenderPipelineDescriptor::alloc()->init();
|
||||||
drawPipelineDescriptor->setVertexFunction(vertexDrawFunction);
|
drawPipelineDescriptor->setVertexFunction(vertexDrawFunction);
|
||||||
drawPipelineDescriptor->setFragmentFunction(fragmentDrawFunction);
|
drawPipelineDescriptor->setFragmentFunction(fragmentDrawFunction);
|
||||||
// HACK
|
|
||||||
auto* drawColorAttachment = drawPipelineDescriptor->colorAttachments()->object(0);
|
auto* drawColorAttachment = drawPipelineDescriptor->colorAttachments()->object(0);
|
||||||
drawColorAttachment->setPixelFormat(MTL::PixelFormatRGBA8Unorm);
|
drawColorAttachment->setPixelFormat(MTL::PixelFormatRGBA8Unorm);
|
||||||
drawColorAttachment->setBlendingEnabled(true);
|
drawColorAttachment->setBlendingEnabled(true);
|
||||||
|
@ -281,7 +296,7 @@ void RendererMTL::displayTransfer(u32 inputAddr, u32 outputAddr, u32 inputSize,
|
||||||
colorAttachment->setStoreAction(MTL::StoreActionStore);
|
colorAttachment->setStoreAction(MTL::StoreActionStore);
|
||||||
|
|
||||||
MTL::RenderCommandEncoder* renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
|
MTL::RenderCommandEncoder* renderCommandEncoder = commandBuffer->renderCommandEncoder(renderPassDescriptor);
|
||||||
renderCommandEncoder->setRenderPipelineState(displayPipeline);
|
renderCommandEncoder->setRenderPipelineState(blitPipeline);
|
||||||
renderCommandEncoder->setFragmentTexture(srcFramebuffer->texture, 0);
|
renderCommandEncoder->setFragmentTexture(srcFramebuffer->texture, 0);
|
||||||
renderCommandEncoder->setFragmentSamplerState(basicSampler, 0);
|
renderCommandEncoder->setFragmentSamplerState(basicSampler, 0);
|
||||||
|
|
||||||
|
|
|
@ -1,21 +1,47 @@
|
||||||
#include <metal_stdlib>
|
#include <metal_stdlib>
|
||||||
using namespace metal;
|
using namespace metal;
|
||||||
|
|
||||||
struct DisplayVertexOut {
|
struct BasicVertexOut {
|
||||||
float4 position [[position]];
|
float4 position [[position]];
|
||||||
float2 uv;
|
float2 uv;
|
||||||
};
|
};
|
||||||
|
|
||||||
vertex DisplayVertexOut vertexDisplay(uint vid [[vertex_id]]) {
|
constant float4 displayPositions[4] = {
|
||||||
DisplayVertexOut out;
|
float4(-1.0, -1.0, 0.0, 1.0),
|
||||||
|
float4( 1.0, -1.0, 0.0, 1.0),
|
||||||
|
float4(-1.0, 1.0, 0.0, 1.0),
|
||||||
|
float4( 1.0, 1.0, 0.0, 1.0)
|
||||||
|
};
|
||||||
|
|
||||||
|
constant float2 displayTexCoord[4] = {
|
||||||
|
float2(0.0, 1.0),
|
||||||
|
float2(0.0, 0.0),
|
||||||
|
float2(1.0, 1.0),
|
||||||
|
float2(1.0, 0.0)
|
||||||
|
};
|
||||||
|
|
||||||
|
vertex BasicVertexOut vertexDisplay(uint vid [[vertex_id]]) {
|
||||||
|
BasicVertexOut out;
|
||||||
|
out.position = displayPositions[vid];
|
||||||
|
out.uv = displayTexCoord[vid];
|
||||||
|
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
fragment float4 fragmentDisplay(BasicVertexOut in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler samplr [[sampler(0)]]) {
|
||||||
|
return tex.sample(samplr, in.uv);
|
||||||
|
}
|
||||||
|
|
||||||
|
vertex BasicVertexOut vertexBlit(uint vid [[vertex_id]]) {
|
||||||
|
BasicVertexOut out;
|
||||||
out.uv = float2((vid << 1) & 2, vid & 2);
|
out.uv = float2((vid << 1) & 2, vid & 2);
|
||||||
out.position = float4(out.uv * 2.0f + -1.0f, 0.0f, 1.0f);
|
out.position = float4(out.uv * 2.0 - 1.0, 0.0, 1.0);
|
||||||
out.position.y = -out.position.y;
|
out.position.y = -out.position.y;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment float4 fragmentDisplay(DisplayVertexOut in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler samplr [[sampler(0)]]) {
|
fragment float4 fragmentBlit(BasicVertexOut in [[stage_in]], texture2d<float> tex [[texture(0)]], sampler samplr [[sampler(0)]]) {
|
||||||
return tex.sample(samplr, in.uv);
|
return tex.sample(samplr, in.uv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,8 +111,6 @@ vertex DrawVertexOut vertexDraw(DrawVertexIn in [[stage_in]], constant PicaRegs&
|
||||||
|
|
||||||
// Position
|
// Position
|
||||||
out.position = in.position;
|
out.position = in.position;
|
||||||
// HACK: rotate the position
|
|
||||||
out.position.xy = -out.position.yx;
|
|
||||||
// Flip the y position
|
// Flip the y position
|
||||||
out.position.y = -out.position.y;
|
out.position.y = -out.position.y;
|
||||||
// in.position.z is in range of [-1 ... 1], convert it to [0 ... 1]
|
// in.position.z is in range of [-1 ... 1], convert it to [0 ... 1]
|
||||||
|
|
Loading…
Add table
Reference in a new issue