2018-06-20 21:29:53 -07: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>
|
2019-01-21 13:03:40 -08:00
|
|
|
#import <QuartzCore/CAMetalLayer.h>
|
2018-06-29 22:57:48 -07:00
|
|
|
#import "RendererCommon.h"
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2018-06-29 22:57:48 -07:00
|
|
|
@interface Texture : NSObject
|
2018-07-03 22:28:33 -07:00
|
|
|
@property (nonatomic, readonly) id<MTLTexture> texture;
|
|
|
|
@property (nonatomic, readonly) id<MTLSamplerState> sampler;
|
2018-06-29 22:57:48 -07:00
|
|
|
@end
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2018-07-03 22:28:33 -07:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
NSUInteger offset;
|
|
|
|
__unsafe_unretained id<MTLBuffer> buffer;
|
|
|
|
} BufferRange;
|
|
|
|
|
2019-09-02 18:01:18 +02:00
|
|
|
typedef NS_ENUM(NSUInteger, ViewportResetMode) {
|
|
|
|
kFullscreenViewport,
|
|
|
|
kVideoViewport
|
|
|
|
};
|
|
|
|
|
2018-06-29 22:57:48 -07:00
|
|
|
/*! @brief Context contains the render state used by various components */
|
2018-06-20 21:29:53 -07:00
|
|
|
@interface Context : NSObject
|
|
|
|
|
2018-07-03 22:28:33 -07:00
|
|
|
@property (nonatomic, readonly) id<MTLDevice> device;
|
|
|
|
@property (nonatomic, readonly) id<MTLLibrary> library;
|
|
|
|
@property (nonatomic, readwrite) MTLClearColor clearColor;
|
2018-07-12 21:33:18 -07:00
|
|
|
@property (nonatomic, readwrite) video_viewport_t *viewport;
|
|
|
|
@property (nonatomic, readonly) Uniforms *uniforms;
|
2018-06-30 10:30:43 -07:00
|
|
|
|
2018-07-04 09:50:09 -07:00
|
|
|
/*! @brief Specifies whether rendering is synchronized with the display */
|
|
|
|
@property (nonatomic, readwrite) bool displaySyncEnabled;
|
|
|
|
|
2018-09-02 17:55:02 -07:00
|
|
|
/*! @brief captureEnabled allows previous frames to be read */
|
|
|
|
@property (nonatomic, readwrite) bool captureEnabled;
|
|
|
|
|
2018-06-30 10:30:43 -07:00
|
|
|
/*! @brief Returns the command buffer used for pre-render work,
|
2018-07-12 21:33:18 -07:00
|
|
|
* such as mip maps and shader effects
|
2018-06-30 10:30:43 -07:00
|
|
|
* */
|
2018-07-03 22:28:33 -07:00
|
|
|
@property (nonatomic, readonly) id<MTLCommandBuffer> blitCommandBuffer;
|
2018-06-30 10:30:43 -07:00
|
|
|
|
2018-06-20 21:29:53 -07:00
|
|
|
/*! @brief Returns the command buffer for the current frame */
|
2018-07-03 22:28:33 -07:00
|
|
|
@property (nonatomic, readonly) id<MTLCommandBuffer> commandBuffer;
|
|
|
|
@property (nonatomic, readonly) id<CAMetalDrawable> nextDrawable;
|
2018-06-30 10:30:43 -07:00
|
|
|
|
|
|
|
/*! @brief Main render encoder to back buffer */
|
2018-07-03 22:28:33 -07:00
|
|
|
@property (nonatomic, readonly) id<MTLRenderCommandEncoder> rce;
|
2018-06-20 21:29:53 -07:00
|
|
|
|
2018-06-29 22:57:48 -07: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 13:12:40 -07:00
|
|
|
- (id<MTLTexture>)newTexture:(struct texture_image)image mipmapped:(bool)mipmapped;
|
2018-07-17 20:59:06 -07:00
|
|
|
- (void)convertFormat:(RPixelFormat)fmt from:(id<MTLTexture>)src to:(id<MTLTexture>)dst;
|
2018-07-12 21:33:18 -07:00
|
|
|
- (id<MTLRenderPipelineState>)getStockShader:(int)index blend:(bool)blend;
|
|
|
|
|
2019-09-02 18:01:18 +02:00
|
|
|
/*! @brief resets the viewport for the main render encoder to \a mode */
|
|
|
|
- (void)resetRenderViewport:(ViewportResetMode)mode;
|
2018-07-12 21:33:18 -07:00
|
|
|
|
2018-11-06 07:51:40 -07:00
|
|
|
/*! @brief resets the scissor rect for the main render encoder to the drawable size */
|
|
|
|
- (void)resetScissorRect;
|
|
|
|
|
2018-07-12 21:33:18 -07:00
|
|
|
/*! @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-20 21:29:53 -07:00
|
|
|
|
2018-07-03 22:28:33 -07:00
|
|
|
- (bool)allocRange:(BufferRange *)range length:(NSUInteger)length;
|
|
|
|
|
2018-06-20 21:29:53 -07:00
|
|
|
/*! @brief begin marks the beginning of a frame */
|
|
|
|
- (void)begin;
|
|
|
|
|
|
|
|
/*! @brief end commits the command buffer */
|
|
|
|
- (void)end;
|
|
|
|
|
2018-11-29 22:04:43 -07:00
|
|
|
- (void)setRotation:(unsigned)rotation;
|
2018-09-02 17:55:02 -07:00
|
|
|
- (bool)readBackBuffer:(uint8_t *)buffer;
|
|
|
|
|
2018-06-20 21:29:53 -07:00
|
|
|
@end
|