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-06-30 17:30:43 +00:00
|
|
|
|
|
|
|
/*! @brief Returns the command buffer used for pre-render work,
|
|
|
|
* such as mip maps for applying filters
|
|
|
|
* */
|
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;
|
|
|
|
- (void)convertFormat:(RPixelFormat)fmt from:(id<MTLBuffer>)src to:(id<MTLTexture>)dst;
|
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
|