summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/src/renderer_mtl.h
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/bgfx/src/renderer_mtl.h')
-rw-r--r--3rdparty/bgfx/src/renderer_mtl.h466
1 files changed, 357 insertions, 109 deletions
diff --git a/3rdparty/bgfx/src/renderer_mtl.h b/3rdparty/bgfx/src/renderer_mtl.h
index 41ba78725ce..495f7abf499 100644
--- a/3rdparty/bgfx/src/renderer_mtl.h
+++ b/3rdparty/bgfx/src/renderer_mtl.h
@@ -13,17 +13,17 @@
#import <QuartzCore/CAMetalLayer.h>
#import <Metal/Metal.h>
-#ifdef BX_PLATFORM_IOS
+#if BX_PLATFORM_IOS
# import <UIKit/UIKit.h>
-#endif // BX_PLATFORM_IOS
+#endif // BX_PLATFORM_*
namespace bgfx { namespace mtl
{
- //c++ wrapper
- // objects with creation functions starting with 'new' has a refcount 1 after creation, object must be destroyed with release.
- // commandBuffer, commandEncoders are autoreleased objects. Needs AutoreleasePool!
+ // c++ wrapper
+ // objects with creation functions starting with 'new' has a refcount 1 after creation, object must be destroyed with release.
+ // commandBuffer, commandEncoders are autoreleased objects. Needs AutoreleasePool!
-#define MTL_CLASS(name) \
+#define MTL_CLASS(name) \
class name \
{ \
public: \
@@ -35,104 +35,200 @@ namespace bgfx { namespace mtl
typedef void (*mtlCallback)(void* userData);
- //TODO: ??MTLBlitCommandEncoder??
MTL_CLASS(Buffer)
- void* contents() { return m_obj.contents; }
- uint32_t length() { return (uint32_t)m_obj.length; }
+ void* contents()
+ {
+ return m_obj.contents;
+ }
+
+ uint32_t length()
+ {
+ return (uint32_t)m_obj.length;
+ }
MTL_CLASS_END
MTL_CLASS(CommandBuffer)
// Creating Command Encoders
- id<MTLRenderCommandEncoder> renderCommandEncoderWithDescriptor( MTLRenderPassDescriptor *_renderPassDescriptor){
+ id<MTLRenderCommandEncoder> renderCommandEncoderWithDescriptor( MTLRenderPassDescriptor* _renderPassDescriptor){
return [m_obj renderCommandEncoderWithDescriptor:_renderPassDescriptor];
}
- id<MTLComputeCommandEncoder> computeCommandEncoder() { return [m_obj computeCommandEncoder]; }
+
+ id<MTLComputeCommandEncoder> computeCommandEncoder()
+ {
+ return [m_obj computeCommandEncoder];
+ }
// Scheduling and Executing Commands
- void enqueue() { [m_obj enqueue]; }
- void commit() { [m_obj commit]; }
- void addCompletedHandler(mtlCallback _cb, void* _data) { [m_obj addCompletedHandler:^(id <MTLCommandBuffer> cmdb){ _cb(_data); }]; }
- void presentDrawable(id<MTLDrawable> _drawable) { [m_obj presentDrawable:_drawable]; }
- void waitUntilCompleted() { [m_obj waitUntilCompleted]; }
+ void enqueue()
+ {
+ [m_obj enqueue];
+ }
+
+ void commit()
+ {
+ [m_obj commit];
+ }
+
+ void addCompletedHandler(mtlCallback _cb, void* _data)
+ {
+ [m_obj addCompletedHandler:^(id <MTLCommandBuffer>){ _cb(_data); }];
+ }
+
+ void presentDrawable(id<MTLDrawable> _drawable)
+ {
+ [m_obj presentDrawable:_drawable];
+ }
+
+ void waitUntilCompleted()
+ {
+ [m_obj waitUntilCompleted];
+ }
MTL_CLASS_END
MTL_CLASS(CommandQueue)
- id<MTLCommandBuffer> commandBuffer() { return [m_obj commandBuffer]; }
- id<MTLCommandBuffer> commandBufferWithUnretainedReferences() { return [m_obj commandBufferWithUnretainedReferences]; }
+ id<MTLCommandBuffer> commandBuffer()
+ {
+ return [m_obj commandBuffer];
+ }
+
+ id<MTLCommandBuffer> commandBufferWithUnretainedReferences()
+ {
+ return [m_obj commandBufferWithUnretainedReferences];
+ }
MTL_CLASS_END
MTL_CLASS(ComputeCommandEncoder)
- void setComputePipelineState(id<MTLComputePipelineState> _state) { [m_obj setComputePipelineState:_state]; }
+ void setComputePipelineState(id<MTLComputePipelineState> _state)
+ {
+ [m_obj setComputePipelineState:_state];
+ }
- void setBuffer(id<MTLBuffer> _buffer, NSUInteger _offset, NSUInteger _index) { [m_obj setBuffer:_buffer offset:_offset atIndex:_index]; }
+ void setBuffer(id<MTLBuffer> _buffer, NSUInteger _offset, NSUInteger _index)
+ {
+ [m_obj setBuffer:_buffer offset:_offset atIndex:_index];
+ }
- void setTexture(id<MTLTexture> _texture, NSUInteger _index) { [m_obj setTexture:_texture atIndex:_index]; }
+ void setTexture(id<MTLTexture> _texture, NSUInteger _index)
+ {
+ [m_obj setTexture:_texture atIndex:_index];
+ }
- void setSamplerState(id<MTLSamplerState> _sampler, NSUInteger _index) { [m_obj setSamplerState:_sampler atIndex:_index]; }
+ void setSamplerState(id<MTLSamplerState> _sampler, NSUInteger _index)
+ {
+ [m_obj setSamplerState:_sampler atIndex:_index];
+ }
- void endEncoding() {[m_obj endEncoding] ;}
+ void endEncoding()
+ {
+ [m_obj endEncoding];
+ }
MTL_CLASS_END
MTL_CLASS(Device)
- bool supportsFeatureSet(MTLFeatureSet _featureSet) { return [m_obj supportsFeatureSet:_featureSet]; }
+ bool supportsFeatureSet(MTLFeatureSet _featureSet)
+ {
+ return [m_obj supportsFeatureSet:_featureSet];
+ }
- id<MTLLibrary> newLibraryWithData(const void* _data) {
+ id<MTLLibrary> newLibraryWithData(const void* _data)
+ {
NSError* error;
id<MTLLibrary> lib = [m_obj newLibraryWithData:(dispatch_data_t)_data error:&error];
- BX_WARN(error==NULL,"newLibraryWithData failed:%s", [error.localizedDescription UTF8String] );
+ BX_WARN(NULL == error
+ , "newLibraryWithData failed: %s"
+ , error.localizedDescription.UTF8String
+ );
return lib;
}
- id<MTLLibrary> newLibraryWithSource(const char* _source) {
+
+ id<MTLLibrary> newLibraryWithSource(const char* _source)
+ {
NSError* error;
id<MTLLibrary> lib = [m_obj newLibraryWithSource:@(_source) options:nil error:&error];
- if (error!=nil) NSLog(@"Shader compilation failed:%@", error.localizedDescription);
//TODO: sometimes prints null as paremeter. string is too large
- BX_WARN(error==NULL,"Shader compilation failed:%s", [error.localizedDescription UTF8String]);
+ BX_WARN(NULL == error
+ , "Shader compilation failed: %s"
+ , error.localizedDescription.UTF8String
+ );
return lib;
}
- id<MTLCommandQueue> newCommandQueue() { return [m_obj newCommandQueue]; }
- id<MTLCommandQueue> newCommandQueueWithMaxCommandBufferCount(NSUInteger _maxCommandBufferCount) { return [m_obj newCommandQueueWithMaxCommandBufferCount:_maxCommandBufferCount]; }
+ id<MTLCommandQueue> newCommandQueue()
+ {
+ return [m_obj newCommandQueue];
+ }
+
+ id<MTLCommandQueue> newCommandQueueWithMaxCommandBufferCount(NSUInteger _maxCommandBufferCount)
+ {
+ return [m_obj newCommandQueueWithMaxCommandBufferCount:_maxCommandBufferCount];
+ }
// Creating Resources
- id<MTLBuffer> newBufferWithLength(unsigned int _length, MTLResourceOptions _options) { return [m_obj newBufferWithLength:_length options:_options ]; }
- id<MTLBuffer> newBufferWithBytes(const void *_pointer, NSUInteger _length, MTLResourceOptions _options) { return [m_obj newBufferWithBytes:_pointer length:_length options:_options]; }
+ id<MTLBuffer> newBufferWithLength(unsigned int _length, MTLResourceOptions _options)
+ {
+ return [m_obj newBufferWithLength:_length options:_options ];
+ }
- id<MTLTexture> newTextureWithDescriptor(MTLTextureDescriptor * _descriptor) { return [m_obj newTextureWithDescriptor:_descriptor]; }
- id<MTLSamplerState> newSamplerStateWithDescriptor(MTLSamplerDescriptor * _descriptor) { return [m_obj newSamplerStateWithDescriptor:_descriptor]; }
+ id<MTLBuffer> newBufferWithBytes(const void* _pointer, NSUInteger _length, MTLResourceOptions _options)
+ {
+ return [m_obj newBufferWithBytes:_pointer length:_length options:_options];
+ }
+
+ id<MTLTexture> newTextureWithDescriptor(MTLTextureDescriptor* _descriptor)
+ {
+ return [m_obj newTextureWithDescriptor:_descriptor];
+ }
+
+ id<MTLSamplerState> newSamplerStateWithDescriptor(MTLSamplerDescriptor* _descriptor)
+ {
+ return [m_obj newSamplerStateWithDescriptor:_descriptor];
+ }
// Creating Command Objects Needed to Render Graphics
- id<MTLDepthStencilState> newDepthStencilStateWithDescriptor(MTLDepthStencilDescriptor * _descriptor) { return [m_obj newDepthStencilStateWithDescriptor:_descriptor]; }
+ id<MTLDepthStencilState> newDepthStencilStateWithDescriptor(MTLDepthStencilDescriptor* _descriptor)
+ {
+ return [m_obj newDepthStencilStateWithDescriptor:_descriptor];
+ }
- id <MTLRenderPipelineState> newRenderPipelineStateWithDescriptor(MTLRenderPipelineDescriptor *_descriptor)
+ id <MTLRenderPipelineState> newRenderPipelineStateWithDescriptor(MTLRenderPipelineDescriptor* _descriptor)
{
- NSError *error;
+ NSError* error;
id <MTLRenderPipelineState> state = [m_obj newRenderPipelineStateWithDescriptor:_descriptor error:&error];
- BX_WARN(error==NULL,"newRenderPipelineStateWithDescriptor failed:%s", [error.localizedDescription UTF8String] );
+ BX_WARN(NULL == error
+ , "newRenderPipelineStateWithDescriptor failed: %s"
+ , error.localizedDescription.UTF8String
+ );
return state;
}
- id <MTLRenderPipelineState> newRenderPipelineStateWithDescriptor(MTLRenderPipelineDescriptor *_descriptor, MTLPipelineOption _options, MTLRenderPipelineReflection** _reflection)
+ id <MTLRenderPipelineState> newRenderPipelineStateWithDescriptor(MTLRenderPipelineDescriptor* _descriptor, MTLPipelineOption _options, MTLRenderPipelineReflection** _reflection)
{
- NSError *error;
+ NSError* error;
id <MTLRenderPipelineState> state = [m_obj newRenderPipelineStateWithDescriptor:_descriptor options:_options reflection:_reflection error:&error];
- BX_WARN(error==NULL,"newRenderPipelineStateWithDescriptor failed:%s", [error.localizedDescription UTF8String] );
+ BX_WARN(NULL == error
+ , "newRenderPipelineStateWithDescriptor failed: %s"
+ , error.localizedDescription.UTF8String
+ );
return state;
}
// Creating Command Objects Needed to Perform Computational Tasks
id <MTLComputePipelineState> newComputePipelineStateWithFunction(id <MTLFunction> _computeFunction)
{
- NSError *error;
+ NSError* error;
id <MTLComputePipelineState> state = [m_obj newComputePipelineStateWithFunction:_computeFunction error:&error];
- BX_WARN(error==NULL,"newComputePipelineStateWithFunction failed:%s", [error.localizedDescription UTF8String] );
+
+ BX_WARN(NULL == error
+ , "newComputePipelineStateWithFunction failed: %s"
+ , error.localizedDescription.UTF8String
+ );
return state;
}
MTL_CLASS_END
MTL_CLASS(Function)
- NSArray *vertexAttributes() { return m_obj.vertexAttributes; }
+ NSArray* vertexAttributes() { return m_obj.vertexAttributes; }
MTL_CLASS_END
MTL_CLASS(Library)
@@ -141,27 +237,92 @@ namespace bgfx { namespace mtl
MTL_CLASS(RenderCommandEncoder)
// Setting Graphics Rendering State
- void setBlendColor(float _red, float _green, float _blue, float _alpha) { [m_obj setBlendColorRed:_red green:_green blue:_blue alpha:_alpha]; }
- void setCullMode(MTLCullMode _cullMode) { [m_obj setCullMode:_cullMode]; }
- void setDepthBias(float _depthBias, float _slopeScale, float _clamp) { [m_obj setDepthBias:_depthBias slopeScale:_slopeScale clamp:_clamp]; }
- void setDepthStencilState(id<MTLDepthStencilState> _depthStencilState) { [m_obj setDepthStencilState:_depthStencilState];}
- void setFrontFacingWinding(MTLWinding _frontFacingWinding) { [m_obj setFrontFacingWinding:_frontFacingWinding]; }
- void setRenderPipelineState(id<MTLRenderPipelineState> _pipelineState) { [m_obj setRenderPipelineState:_pipelineState]; }
- void setScissorRect(MTLScissorRect _rect) { [m_obj setScissorRect:_rect]; }
- void setStencilReferenceValue(uint32_t _ref) { [m_obj setStencilReferenceValue:_ref]; }
- void setTriangleFillMode(MTLTriangleFillMode _fillMode) { [m_obj setTriangleFillMode:_fillMode]; }
- void setViewport(MTLViewport _viewport) { [m_obj setViewport:_viewport]; }
- void setVisibilityResultMode(MTLVisibilityResultMode _mode, NSUInteger _offset) { [m_obj setVisibilityResultMode:_mode offset:_offset]; }
+ void setBlendColor(float _red, float _green, float _blue, float _alpha)
+ {
+ [m_obj setBlendColorRed:_red green:_green blue:_blue alpha:_alpha];
+ }
+
+ void setCullMode(MTLCullMode _cullMode)
+ {
+ [m_obj setCullMode:_cullMode];
+ }
+
+ void setDepthBias(float _depthBias, float _slopeScale, float _clamp)
+ {
+ [m_obj setDepthBias:_depthBias slopeScale:_slopeScale clamp:_clamp];
+ }
+
+ void setDepthStencilState(id<MTLDepthStencilState> _depthStencilState)
+ {
+ [m_obj setDepthStencilState:_depthStencilState];
+ }
+
+ void setFrontFacingWinding(MTLWinding _frontFacingWinding)
+ {
+ [m_obj setFrontFacingWinding:_frontFacingWinding];
+ }
+
+ void setRenderPipelineState(id<MTLRenderPipelineState> _pipelineState)
+ {
+ [m_obj setRenderPipelineState:_pipelineState];
+ }
+
+ void setScissorRect(MTLScissorRect _rect)
+ {
+ [m_obj setScissorRect:_rect];
+ }
+
+ void setStencilReferenceValue(uint32_t _ref)
+ {
+ [m_obj setStencilReferenceValue:_ref];
+ }
+
+ void setTriangleFillMode(MTLTriangleFillMode _fillMode)
+ {
+ [m_obj setTriangleFillMode:_fillMode];
+ }
+
+ void setViewport(MTLViewport _viewport)
+ {
+ [m_obj setViewport:_viewport];
+ }
+
+ void setVisibilityResultMode(MTLVisibilityResultMode _mode, NSUInteger _offset)
+ {
+ [m_obj setVisibilityResultMode:_mode offset:_offset];
+ }
// Specifying Resources for a Vertex Function
- void setVertexBuffer(id<MTLBuffer> _buffer, NSUInteger _offset, NSUInteger _index) { [m_obj setVertexBuffer:_buffer offset:_offset atIndex:_index]; }
- void setVertexSamplerState(id<MTLSamplerState> _sampler, NSUInteger _index) { [m_obj setVertexSamplerState:_sampler atIndex:_index]; }
- void setVertexTexture(id<MTLTexture> _texture, NSUInteger _index) { [m_obj setVertexTexture:_texture atIndex:_index]; }
+ void setVertexBuffer(id<MTLBuffer> _buffer, NSUInteger _offset, NSUInteger _index)
+ {
+ [m_obj setVertexBuffer:_buffer offset:_offset atIndex:_index];
+ }
+
+ void setVertexSamplerState(id<MTLSamplerState> _sampler, NSUInteger _index)
+ {
+ [m_obj setVertexSamplerState:_sampler atIndex:_index];
+ }
+
+ void setVertexTexture(id<MTLTexture> _texture, NSUInteger _index)
+ {
+ [m_obj setVertexTexture:_texture atIndex:_index];
+ }
// Specifying Resources for a Fragment Function
- void setFragmentBuffer(id<MTLBuffer> _buffer, NSUInteger _offset, NSUInteger _index) { [m_obj setFragmentBuffer:_buffer offset:_offset atIndex:_index]; }
- void setFragmentSamplerState(id<MTLSamplerState> _sampler, NSUInteger _index) { [m_obj setFragmentSamplerState:_sampler atIndex:_index]; }
- void setFragmentTexture(id<MTLTexture> _texture, NSUInteger _index) { [m_obj setFragmentTexture:_texture atIndex:_index]; }
+ void setFragmentBuffer(id<MTLBuffer> _buffer, NSUInteger _offset, NSUInteger _index)
+ {
+ [m_obj setFragmentBuffer:_buffer offset:_offset atIndex:_index];
+ }
+
+ void setFragmentSamplerState(id<MTLSamplerState> _sampler, NSUInteger _index)
+ {
+ [m_obj setFragmentSamplerState:_sampler atIndex:_index];
+ }
+
+ void setFragmentTexture(id<MTLTexture> _texture, NSUInteger _index)
+ {
+ [m_obj setFragmentTexture:_texture atIndex:_index];
+ }
//Drawing Geometric Primitives
//NOTE: not exposing functions without instanceCount, it seems they are just wrappers
@@ -170,29 +331,66 @@ namespace bgfx { namespace mtl
[m_obj drawIndexedPrimitives:_primitiveType indexCount:_indexCount indexType:_indexType indexBuffer:_indexBuffer indexBufferOffset:_indexBufferOffset instanceCount:_instanceCount];
}
- void drawPrimitives(MTLPrimitiveType _primitiveType, NSUInteger _vertexStart, NSUInteger _vertexCount, NSUInteger _instanceCount) {
- [m_obj drawPrimitives:_primitiveType vertexStart:_vertexStart vertexCount:_vertexCount instanceCount:_instanceCount];}
+ void drawPrimitives(MTLPrimitiveType _primitiveType, NSUInteger _vertexStart, NSUInteger _vertexCount, NSUInteger _instanceCount)
+ {
+ [m_obj drawPrimitives:_primitiveType vertexStart:_vertexStart vertexCount:_vertexCount instanceCount:_instanceCount];
+ }
- void insertDebugSignpost(const char* _string) { [m_obj insertDebugSignpost:@(_string)]; }
- void pushDebugGroup(const char* _string) { [m_obj pushDebugGroup:@(_string)]; }
- void popDebugGroup() { [m_obj popDebugGroup]; }
+ void insertDebugSignpost(const char* _string)
+ {
+ [m_obj insertDebugSignpost:@(_string)];
+ }
- void endEncoding() { [m_obj endEncoding]; }
+ void pushDebugGroup(const char* _string)
+ {
+ [m_obj pushDebugGroup:@(_string)];
+ }
+
+ void popDebugGroup()
+ {
+ [m_obj popDebugGroup];
+ }
+
+ void endEncoding()
+ {
+ [m_obj endEncoding];
+ }
MTL_CLASS_END
MTL_CLASS(Texture)
// Copying Data into a Texture Image
- void replaceRegion(MTLRegion _region, NSUInteger _level, NSUInteger _slice, const void *_pixelBytes, NSUInteger _bytesPerRow, NSUInteger _bytesPerImage) { [m_obj replaceRegion:_region mipmapLevel:_level slice:_slice withBytes:_pixelBytes bytesPerRow:_bytesPerRow bytesPerImage:_bytesPerImage]; }
+ void replaceRegion(MTLRegion _region, NSUInteger _level, NSUInteger _slice, const void* _pixelBytes, NSUInteger _bytesPerRow, NSUInteger _bytesPerImage)
+ {
+ [m_obj replaceRegion:_region mipmapLevel:_level slice:_slice withBytes:_pixelBytes bytesPerRow:_bytesPerRow bytesPerImage:_bytesPerImage];
+ }
// Copying Data from a Texture Image
- void getBytes(void *_pixelBytes, NSUInteger _bytesPerRow, NSUInteger _bytesPerImage, MTLRegion _region, NSUInteger _mipmapLevel, NSUInteger _slice) { [m_obj getBytes:_pixelBytes bytesPerRow:_bytesPerRow bytesPerImage:_bytesPerImage fromRegion:_region mipmapLevel:_mipmapLevel slice:_slice]; }
+ void getBytes(void* _pixelBytes, NSUInteger _bytesPerRow, NSUInteger _bytesPerImage, MTLRegion _region, NSUInteger _mipmapLevel, NSUInteger _slice)
+ {
+ [m_obj getBytes:_pixelBytes bytesPerRow:_bytesPerRow bytesPerImage:_bytesPerImage fromRegion:_region mipmapLevel:_mipmapLevel slice:_slice];
+ }
// Creating Textures by Reusing Image Data
- id<MTLTexture> newTextureViewWithPixelFormat(MTLPixelFormat _pixelFormat) { return [m_obj newTextureViewWithPixelFormat:_pixelFormat]; }
+ id<MTLTexture> newTextureViewWithPixelFormat(MTLPixelFormat _pixelFormat)
+ {
+ return [m_obj newTextureViewWithPixelFormat:_pixelFormat];
+ }
+
//properties
- uint32_t width() { return (uint32_t)m_obj.width; }
- uint32_t height() { return (uint32_t)m_obj.height; }
- MTLPixelFormat pixelFormat() const { return m_obj.pixelFormat; }
+ uint32_t width()
+ {
+ return (uint32_t)m_obj.width;
+ }
+
+ uint32_t height()
+ {
+ return (uint32_t)m_obj.height;
+ }
+
+ MTLPixelFormat pixelFormat() const
+ {
+ return m_obj.pixelFormat;
+ }
MTL_CLASS_END
typedef id<MTLComputePipelineState> ComputePipelineState;
@@ -200,52 +398,105 @@ namespace bgfx { namespace mtl
typedef id<MTLRenderPipelineState> RenderPipelineState;
typedef id<MTLSamplerState> SamplerState;
- //descriptors
+ //descriptors
//NOTE: [class new] is same as [[class alloc] init]
typedef MTLRenderPipelineDescriptor* RenderPipelineDescriptor;
- RenderPipelineDescriptor newRenderPipelineDescriptor() { return [MTLRenderPipelineDescriptor new]; }
- void reset(RenderPipelineDescriptor _desc) { [_desc reset]; };
+
+ inline RenderPipelineDescriptor newRenderPipelineDescriptor()
+ {
+ return [MTLRenderPipelineDescriptor new];
+ }
+
+ inline void reset(RenderPipelineDescriptor _desc)
+ {
+ [_desc reset];
+ }
typedef MTLRenderPipelineColorAttachmentDescriptor* RenderPipelineColorAttachmentDescriptor;
typedef MTLDepthStencilDescriptor* DepthStencilDescriptor;
- MTLDepthStencilDescriptor* newDepthStencilDescriptor() { return [MTLDepthStencilDescriptor new]; }
+
+ inline MTLDepthStencilDescriptor* newDepthStencilDescriptor()
+ {
+ return [MTLDepthStencilDescriptor new];
+ }
typedef MTLStencilDescriptor* StencilDescriptor;
- MTLStencilDescriptor* newStencilDescriptor() { return [MTLStencilDescriptor new]; }
+
+ inline MTLStencilDescriptor* newStencilDescriptor()
+ {
+ return [MTLStencilDescriptor new];
+ }
typedef MTLRenderPassColorAttachmentDescriptor* RenderPassColorAttachmentDescriptor;
typedef MTLRenderPassDepthAttachmentDescriptor* RenderPassDepthAttachmentDescriptor;
typedef MTLRenderPassStencilAttachmentDescriptor* RenderPassStencilAttachmentDescriptor;
typedef MTLRenderPassDescriptor* RenderPassDescriptor;
- MTLRenderPassDescriptor* newRenderPassDescriptor() { return [MTLRenderPassDescriptor new]; }
+
+ inline MTLRenderPassDescriptor* newRenderPassDescriptor()
+ {
+ return [MTLRenderPassDescriptor new];
+ }
typedef MTLVertexDescriptor* VertexDescriptor;
- MTLVertexDescriptor* newVertexDescriptor() { return [MTLVertexDescriptor new]; }
- void reset(VertexDescriptor _desc) { [_desc reset]; };
+
+ inline MTLVertexDescriptor* newVertexDescriptor()
+ {
+ return [MTLVertexDescriptor new];
+ }
+
+ inline void reset(VertexDescriptor _desc)
+ {
+ [_desc reset];
+ }
typedef MTLSamplerDescriptor* SamplerDescriptor;
- MTLSamplerDescriptor* newSamplerDescriptor() { return [MTLSamplerDescriptor new]; }
+
+ inline MTLSamplerDescriptor* newSamplerDescriptor()
+ {
+ return [MTLSamplerDescriptor new];
+ }
typedef MTLTextureDescriptor* TextureDescriptor;
- MTLTextureDescriptor* newTextureDescriptor() { return [MTLTextureDescriptor new]; }
+
+ inline MTLTextureDescriptor* newTextureDescriptor()
+ {
+ return [MTLTextureDescriptor new];
+ }
typedef MTLRenderPipelineReflection* RenderPipelineReflection;
- //helper functions
- void release(NSObject* _obj) { [_obj release]; }
- void retain(NSObject* _obj) { [_obj retain]; }
- const char* utf8String(NSString* _str) { return [_str UTF8String]; }
+ //helper functions
+ inline void release(NSObject* _obj)
+ {
+ [_obj release];
+ }
+
+ inline void retain(NSObject* _obj)
+ {
+ [_obj retain];
+ }
+
+ inline const char* utf8String(NSString* _str)
+ {
+ return [_str UTF8String];
+ }
-#define MTL_RELEASE(_obj) \
- [_obj release]; \
- _obj = nil;
+#define MTL_RELEASE(_obj) \
+ BX_MACRO_BLOCK_BEGIN \
+ [_obj release]; \
+ _obj = nil; \
+ BX_MACRO_BLOCK_END
-#ifdef BX_PLATFORM_IOS
- bool OsVersionEqualOrGreater(const char* _version) { return ([[[UIDevice currentDevice] systemVersion] compare:@(_version) options:NSNumericSearch] != NSOrderedAscending); }
+#if BX_PLATFORM_IOS
+ inline bool OsVersionEqualOrGreater(const char* _version)
+ {
+ return ([[[UIDevice currentDevice] systemVersion] compare:@(_version) options:NSNumericSearch] != NSOrderedAscending);
+ }
//TODO: this could be in bx ?
-#endif
+#endif //
+
// end of c++ wrapper
template <typename Ty>
@@ -359,20 +610,19 @@ namespace bgfx { namespace mtl
Function m_function;
};
-
struct ProgramMtl
{
ProgramMtl()
: m_vsh(NULL)
, m_fsh(NULL)
- , m_processedUniforms(false)
, m_vshConstantBuffer(NULL)
, m_fshConstantBuffer(NULL)
- , m_numPredefined(0)
, m_vshConstantBufferSize(0)
, m_vshConstantBufferAlignmentMask(0)
, m_fshConstantBufferSize(0)
, m_fshConstantBufferAlignmentMask(0)
+ , m_numPredefined(0)
+ , m_processedUniforms(false)
{
}
@@ -383,22 +633,22 @@ namespace bgfx { namespace mtl
StateCacheT<RenderPipelineState> m_renderPipelineStateCache;
- uint8_t m_used[Attrib::Count+1]; // dense
+ uint8_t m_used[Attrib::Count+1]; // dense
uint32_t m_attributes[Attrib::Count]; // sparse
uint32_t m_instanceData[BGFX_CONFIG_MAX_INSTANCE_DATA_COUNT+1];
const ShaderMtl* m_vsh;
const ShaderMtl* m_fsh;
+ UniformBuffer* m_vshConstantBuffer;
+ UniformBuffer* m_fshConstantBuffer;
- bool m_processedUniforms;
uint32_t m_vshConstantBufferSize;
uint32_t m_vshConstantBufferAlignmentMask;
uint32_t m_fshConstantBufferSize;
uint32_t m_fshConstantBufferAlignmentMask;
- ConstantBuffer* m_fshConstantBuffer;
- ConstantBuffer* m_vshConstantBuffer;
PredefinedUniform m_predefined[PredefinedUniform::Count*2];
uint8_t m_numPredefined;
+ bool m_processedUniforms;
};
struct TextureMtl
@@ -407,8 +657,8 @@ namespace bgfx { namespace mtl
: m_ptr(NULL)
, m_ptrStencil(NULL)
, m_sampler(NULL)
- , m_numMips(0)
, m_flags(0)
+ , m_numMips(0)
{
}
@@ -433,10 +683,9 @@ namespace bgfx { namespace mtl
struct FrameBufferMtl
{
FrameBufferMtl()
- : //m_swapChain(NULL) //TODO: swapchain
- m_denseIdx(UINT16_MAX)
- , m_num(0)
+ : m_denseIdx(UINT16_MAX)
, m_pixelFormatHash(0)
+ , m_num(0)
{
m_depthHandle.idx = invalidHandle;
}
@@ -455,12 +704,11 @@ namespace bgfx { namespace mtl
TextureHandle m_colorHandle[BGFX_CONFIG_MAX_FRAME_BUFFER_ATTACHMENTS-1];
TextureHandle m_depthHandle;
- uint8_t m_num; // number of color handles
+ uint8_t m_num; // number of color handles
};
-
-#endif
-
} /* namespace metal */ } // namespace bgfx
+#endif // BGFX_CONFIG_RENDERER_METAL
+
#endif // BGFX_RENDERER_METAL_H_HEADER_GUARD