Output resolution parameter
This commit is contained in:
parent
da7c32cb10
commit
4466a55de6
@ -25,6 +25,8 @@ static const vector_float2 rect[] =
|
||||
id<MTLRenderPipelineState> pipeline_state;
|
||||
id<MTLCommandQueue> command_queue;
|
||||
id<MTLBuffer> mix_previous_buffer;
|
||||
id<MTLBuffer> output_resolution_buffer;
|
||||
vector_float2 output_resolution;
|
||||
}
|
||||
|
||||
- (void)createInternalView
|
||||
@ -46,13 +48,16 @@ static const vector_float2 rect[] =
|
||||
vertices = [device newBufferWithBytes:rect
|
||||
length:sizeof(rect)
|
||||
options:MTLResourceStorageModeShared];
|
||||
|
||||
|
||||
static const bool default_mix_value = false;
|
||||
mix_previous_buffer = [device newBufferWithBytes:&default_mix_value
|
||||
length:sizeof(default_mix_value)
|
||||
options:MTLResourceStorageModeShared];
|
||||
|
||||
output_resolution_buffer = [device newBufferWithBytes:&default_mix_value
|
||||
length:sizeof(default_mix_value)
|
||||
options:MTLResourceStorageModeShared];
|
||||
|
||||
[self loadShader];
|
||||
}
|
||||
|
||||
@ -92,6 +97,7 @@ static const vector_float2 rect[] =
|
||||
|
||||
- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size
|
||||
{
|
||||
output_resolution = (vector_float2){size.width, size.height};
|
||||
}
|
||||
|
||||
- (void)drawInMTKView:(nonnull MTKView *)view
|
||||
@ -113,12 +119,14 @@ static const vector_float2 rect[] =
|
||||
if(render_pass_descriptor != nil)
|
||||
{
|
||||
*(bool *)[mix_previous_buffer contents] = [self shouldBlendFrameWithPrevious];
|
||||
*(vector_float2 *)[output_resolution_buffer contents] = output_resolution;
|
||||
|
||||
id<MTLRenderCommandEncoder> render_encoder =
|
||||
[command_buffer renderCommandEncoderWithDescriptor:render_pass_descriptor];
|
||||
|
||||
[render_encoder setViewport:(MTLViewport){0.0, 0.0,
|
||||
view.bounds.size.width * view.window.backingScaleFactor,
|
||||
view.bounds.size.height * view.window.backingScaleFactor,
|
||||
output_resolution.x,
|
||||
output_resolution.y,
|
||||
-1.0, 1.0}];
|
||||
|
||||
[render_encoder setRenderPipelineState:pipeline_state];
|
||||
@ -131,6 +139,10 @@ static const vector_float2 rect[] =
|
||||
offset:0
|
||||
atIndex:0];
|
||||
|
||||
[render_encoder setFragmentBuffer:output_resolution_buffer
|
||||
offset:0
|
||||
atIndex:1];
|
||||
|
||||
[render_encoder setFragmentTexture:texture
|
||||
atIndex:0];
|
||||
|
||||
|
@ -36,10 +36,12 @@ static inline float4 texture(texture2d<half> texture, float2 pos)
|
||||
return float4(texture.sample(texture_sampler, pos));
|
||||
}
|
||||
|
||||
|
||||
fragment float4 fragment_shader(rasterizer_data in [[stage_in]],
|
||||
texture2d<half> image [[ texture(0) ]],
|
||||
texture2d<half> previous_image [[ texture(1) ]],
|
||||
constant bool *mix_previous [[ buffer(0) ]])
|
||||
constant bool *mix_previous [[ buffer(0) ]],
|
||||
constant float2 *output_resolution [[ buffer(1) ]])
|
||||
{
|
||||
in.texcoords.y = 1 - in.texcoords.y;
|
||||
if (*mix_previous) {
|
||||
|
Loading…
Reference in New Issue
Block a user