mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-26 08:49:37 +00:00
Ties everything together in an attempt to display RGB scans.
I'm actually just getting a mess of pixels, but it's something!
This commit is contained in:
parent
cd491bb6e0
commit
57fecdc09e
@ -40,7 +40,7 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
|
||||
id<MTLFunction> _vertexShader;
|
||||
id<MTLFunction> _fragmentShader;
|
||||
id<MTLRenderPipelineState> _gouraudPipeline;
|
||||
id<MTLRenderPipelineState> _scanPipeline;
|
||||
|
||||
// Buffers.
|
||||
id<MTLBuffer> _uniformsBuffer;
|
||||
@ -85,14 +85,6 @@ 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);
|
||||
|
||||
// Generate TEST 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;
|
||||
_gouraudPipeline = [view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
||||
}
|
||||
|
||||
return self;
|
||||
@ -115,11 +107,6 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
@discussion Called on the delegate when it is asked to render into the view
|
||||
*/
|
||||
- (void)drawInMTKView:(nonnull MTKView *)view {
|
||||
// Generate a command encoder for the view.
|
||||
id <MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
||||
MTLRenderPassDescriptor *const descriptor = view.currentRenderPassDescriptor;
|
||||
id <MTLRenderCommandEncoder> encoder = [commandBuffer renderCommandEncoderWithDescriptor:descriptor];
|
||||
|
||||
const Outputs::Display::ScanTarget::Modals *const newModals = _scanTarget.new_modals();
|
||||
if(newModals) {
|
||||
uniforms()->scale[0] = newModals->output_scale.x;
|
||||
@ -150,11 +137,25 @@ using BufferingScanTarget = Outputs::Display::BufferingScanTarget;
|
||||
offset:0
|
||||
bytesPerRow:BufferingScanTarget::WriteAreaWidth * _bytesPerInputPixel];
|
||||
_totalTextureBytes = BufferingScanTarget::WriteAreaWidth * BufferingScanTarget::WriteAreaHeight * _bytesPerInputPixel;
|
||||
|
||||
// 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;
|
||||
_scanPipeline = [view.device newRenderPipelineStateWithDescriptor:pipelineDescriptor error:nil];
|
||||
}
|
||||
|
||||
// Drawing. Just the test triangle, as described above.
|
||||
[encoder setRenderPipelineState:_gouraudPipeline];
|
||||
// Generate a command encoder for the view.
|
||||
id <MTLCommandBuffer> commandBuffer = [_commandQueue commandBuffer];
|
||||
MTLRenderPassDescriptor *const descriptor = view.currentRenderPassDescriptor;
|
||||
id <MTLRenderCommandEncoder> encoder = [commandBuffer renderCommandEncoderWithDescriptor:descriptor];
|
||||
|
||||
// Drawing. Just scans.
|
||||
[encoder setRenderPipelineState:_scanPipeline];
|
||||
|
||||
[encoder setFragmentTexture:_writeAreaTexture atIndex:0];
|
||||
[encoder setVertexBuffer:_scansBuffer offset:0 atIndex:0];
|
||||
[encoder setVertexBuffer:_uniformsBuffer offset:0 atIndex:1];
|
||||
|
||||
|
@ -51,6 +51,7 @@ struct Line {
|
||||
// This is an intermediate struct, which is TEMPORARY.
|
||||
struct ColouredVertex {
|
||||
float4 position [[position]];
|
||||
float2 textureCoordinates;
|
||||
};
|
||||
|
||||
|
||||
@ -81,9 +82,16 @@ vertex ColouredVertex scanVertexMain( constant Uniforms &uniforms [[buffer(1)]],
|
||||
0.0,
|
||||
1.0
|
||||
);
|
||||
output.textureCoordinates = float2(
|
||||
mix(scans[instanceID].endPoints[0].dataOffset, scans[instanceID].endPoints[1].dataOffset, float((vertexID&2) >> 1)),
|
||||
scans[instanceID].dataY);
|
||||
return output;
|
||||
}
|
||||
|
||||
fragment half4 scanFragmentMain(ColouredVertex vert [[stage_in]]) {
|
||||
return half4(1.0);
|
||||
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);
|
||||
|
||||
return half4(texture.sample(s, vert.textureCoordinates));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user