1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-10 12:29:01 +00:00

Does just enough to get 8-bit RGB and 1-bit luminance machines to display.

Assuming an 'RGB' output.
This commit is contained in:
Thomas Harte 2020-08-09 21:19:07 -04:00
parent c1dc42a094
commit 28d933d5d6
2 changed files with 34 additions and 10 deletions

View File

@ -85,6 +85,9 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
_scanTarget.set_write_area(reinterpret_cast<uint8_t *>(_writeAreaBuffer.contents));
_scanTarget.set_line_buffer(reinterpret_cast<BufferingScanTarget::Line *>(_linesBuffer.contents), _lineMetadataBuffer, NumBufferedLines);
_scanTarget.set_scan_buffer(reinterpret_cast<BufferingScanTarget::Scan *>(_scansBuffer.contents), NumBufferedScans);
// Set initial aspect-ratio multiplier.
[self mtkView:view drawableSizeWillChange:view.drawableSize];
}
return self;
@ -124,7 +127,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
case 2: pixelFormat = MTLPixelFormatRG8Unorm; break;
case 4: pixelFormat = MTLPixelFormatRGBA8Unorm; break;
}
MTLTextureDescriptor *textureDescriptor = [MTLTextureDescriptor
MTLTextureDescriptor *const textureDescriptor = [MTLTextureDescriptor
texture2DDescriptorWithPixelFormat:pixelFormat
width:BufferingScanTarget::WriteAreaWidth
height:BufferingScanTarget::WriteAreaHeight
@ -132,18 +135,29 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
textureDescriptor.resourceOptions = SharedResourceOptionsTexture;
// TODO: the call below is the only reason why this project now requires macOS 10.13; is it all that helpful versus just uploading each frame?
const NSUInteger bytesPerRow = BufferingScanTarget::WriteAreaWidth * _bytesPerInputPixel;
_writeAreaTexture = [_writeAreaBuffer
newTextureWithDescriptor:textureDescriptor
offset:0
bytesPerRow:BufferingScanTarget::WriteAreaWidth * _bytesPerInputPixel];
_totalTextureBytes = BufferingScanTarget::WriteAreaWidth * BufferingScanTarget::WriteAreaHeight * _bytesPerInputPixel;
bytesPerRow:bytesPerRow];
_totalTextureBytes = bytesPerRow * BufferingScanTarget::WriteAreaHeight;
// Generate pipeline.
id<MTLLibrary> library = [view.device newDefaultLibrary];
MTLRenderPipelineDescriptor *pipelineDescriptor = [[MTLRenderPipelineDescriptor alloc] init];
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"scanVertexMain"];
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"scanFragmentMain"];
pipelineDescriptor.colorAttachments[0].pixelFormat = view.colorPixelFormat;
// TODO: logic somewhat more complicated than this, probably
pipelineDescriptor.vertexFunction = [library newFunctionWithName:@"scanVertexMain"];
switch(newModals->input_data_type) {
default:
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"scanFragmentMainRGB"];
break;
case Outputs::Display::InputDataType::Luminance1:
pipelineDescriptor.fragmentFunction = [library newFunctionWithName:@"scanFragmentMainL1"];
break;
}
_scanPipeline = [view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
}

View File

@ -88,10 +88,20 @@ vertex ColouredVertex scanVertexMain( constant Uniforms &uniforms [[buffer(1)]],
return output;
}
fragment half4 scanFragmentMain(ColouredVertex vert [[stage_in]], texture2d<float> texture [[texture(0)]]) {
constexpr sampler s(coord::pixel,
address::clamp_to_zero, // This really makes no difference here; anything Metal will accept will do.
filter::nearest);
namespace {
constexpr sampler standardSampler( coord::pixel,
address::clamp_to_edge, // Although arbitrary, stick with this address mode for compatibility all the way to MTLFeatureSet_iOS_GPUFamily1_v1.
filter::nearest);
return half4(texture.sample(s, vert.textureCoordinates) * 32.0f); // Multiply by 32 is _TEMPORARY TEST CODE_ [/ nonsense].
}
// MARK: - Input formst to RGB conversions.
fragment half4 scanFragmentMainRGB (ColouredVertex vert [[stage_in]], texture2d<float> texture [[texture(0)]]) {
return half4(texture.sample(standardSampler, vert.textureCoordinates));
}
fragment half4 scanFragmentMainL1(ColouredVertex vert [[stage_in]], texture2d<float> texture [[texture(0)]]) {
return half4(half3(texture.sample(standardSampler, vert.textureCoordinates).r * 255.0), 1.0);
}