2018-06-21 04:29:53 +00:00
|
|
|
//
|
|
|
|
// Context.h
|
|
|
|
// MetalRenderer
|
|
|
|
//
|
|
|
|
// Created by Stuart Carnie on 6/9/18.
|
|
|
|
// Copyright © 2018 Stuart Carnie. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import <Metal/Metal.h>
|
2018-06-30 05:57:48 +00:00
|
|
|
#import "RendererCommon.h"
|
2018-06-21 04:29:53 +00:00
|
|
|
|
2018-06-30 05:57:48 +00:00
|
|
|
@interface Texture : NSObject
|
2018-07-04 05:28:33 +00:00
|
|
|
@property (nonatomic, readonly) id<MTLTexture> texture;
|
|
|
|
@property (nonatomic, readonly) id<MTLSamplerState> sampler;
|
2018-06-30 05:57:48 +00:00
|
|
|
@end
|
2018-06-21 04:29:53 +00:00
|
|
|
|
2018-07-04 05:28:33 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
NSUInteger offset;
|
|
|
|
__unsafe_unretained id<MTLBuffer> buffer;
|
|
|
|
} BufferRange;
|
|
|
|
|
2018-06-30 05:57:48 +00:00
|
|
|
/*! @brief Context contains the render state used by various components */
|
2018-06-21 04:29:53 +00:00
|
|
|
@interface Context : NSObject
|
|
|
|
|
2018-07-04 05:28:33 +00:00
|
|
|
@property (nonatomic, readonly) id<MTLDevice> device;
|
|
|
|
@property (nonatomic, readonly) id<MTLLibrary> library;
|
|
|
|
@property (nonatomic, readwrite) MTLClearColor clearColor;
|
2018-07-13 04:33:18 +00:00
|
|
|
@property (nonatomic, readwrite) video_viewport_t *viewport;
|
|
|
|
@property (nonatomic, readonly) Uniforms *uniforms;
|
2018-06-30 17:30:43 +00:00
|
|
|
|
2018-07-04 16:50:09 +00:00
|
|
|
/*! @brief Specifies whether rendering is synchronized with the display */
|
|
|
|
@property (nonatomic, readwrite) bool displaySyncEnabled;
|
|
|
|
|
2018-06-30 17:30:43 +00:00
|
|
|
/*! @brief Returns the command buffer used for pre-render work,
|
2018-07-13 04:33:18 +00:00
|
|
|
* such as mip maps and shader effects
|
2018-06-30 17:30:43 +00:00
|
|
|
* */
|
2018-07-04 05:28:33 +00:00
|
|
|
@property (nonatomic, readonly) id<MTLCommandBuffer> blitCommandBuffer;
|
2018-06-30 17:30:43 +00:00
|
|
|
|
2018-06-21 04:29:53 +00:00
|
|
|
/*! @brief Returns the command buffer for the current frame */
|
2018-07-04 05:28:33 +00:00
|
|
|
@property (nonatomic, readonly) id<MTLCommandBuffer> commandBuffer;
|
|
|
|
@property (nonatomic, readonly) id<CAMetalDrawable> nextDrawable;
|
2018-06-30 17:30:43 +00:00
|
|
|
|
|
|
|
/*! @brief Main render encoder to back buffer */
|
2018-07-04 05:28:33 +00:00
|
|
|
@property (nonatomic, readonly) id<MTLRenderCommandEncoder> rce;
|
2018-06-21 04:29:53 +00:00
|
|
|
|
2018-06-30 05:57:48 +00:00
|
|
|
- (instancetype)initWithDevice:(id<MTLDevice>)d
|
|
|
|
layer:(CAMetalLayer *)layer
|
|
|
|
library:(id<MTLLibrary>)l;
|
|
|
|
|
|
|
|
- (Texture *)newTexture:(struct texture_image)image filter:(enum texture_filter_type)filter;
|
2018-07-04 20:12:40 +00:00
|
|
|
- (id<MTLTexture>)newTexture:(struct texture_image)image mipmapped:(bool)mipmapped;
|
2018-06-30 05:57:48 +00:00
|
|
|
- (void)convertFormat:(RPixelFormat)fmt from:(id<MTLBuffer>)src to:(id<MTLTexture>)dst;
|
2018-07-13 04:33:18 +00:00
|
|
|
- (id<MTLRenderPipelineState>)getStockShader:(int)index blend:(bool)blend;
|
|
|
|
|
|
|
|
/*! @brief resets the viewport for the main render encoder to the drawable size */
|
|
|
|
- (void)resetRenderViewport;
|
|
|
|
|
|
|
|
/*! @brief draws a quad at the specified position (normalized coordinates) using the main render encoder */
|
|
|
|
- (void)drawQuadX:(float)x y:(float)y w:(float)w h:(float)h
|
|
|
|
r:(float)r g:(float)g b:(float)b a:(float)a;
|
2018-06-21 04:29:53 +00:00
|
|
|
|
2018-07-04 05:28:33 +00:00
|
|
|
- (bool)allocRange:(BufferRange *)range length:(NSUInteger)length;
|
|
|
|
|
2018-06-21 04:29:53 +00:00
|
|
|
/*! @brief begin marks the beginning of a frame */
|
|
|
|
- (void)begin;
|
|
|
|
|
|
|
|
/*! @brief end commits the command buffer */
|
|
|
|
- (void)end;
|
|
|
|
|
|
|
|
@end
|