multisampling in metal

This commit is contained in:
Greg Wells
2025-07-09 13:27:06 -04:00
parent 07d4e13f20
commit 89ea72b341
11 changed files with 59 additions and 20 deletions

View File

@@ -1,11 +1,16 @@
#pragma once
#include "textures/gryphn_texture.h"
#import <Metal/MTLTexture.h>
#import <Metal/MTLSampler.h>
typedef struct gnPlatformTexture_t {
id<MTLTexture> texture;
id<MTLSamplerState> sampler;
} gnPlatformTexture;
gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnTextureInfo info);
void metalTextureData(gnTextureHandle texture, void* pixelData);
void metalDestroyTexture(gnTexture texture);
NSUInteger mtlSampleCount(gnMultisampleCountFlags flags);

View File

@@ -16,18 +16,30 @@ NSUInteger mtlSampleCount(gnMultisampleCountFlags flags) {
gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init];
textureDescriptor.pixelFormat = mtlGryphnFormatToMetalFormat(info.format);
textureDescriptor.width = info.extent.width;
textureDescriptor.height = info.extent.height;
textureDescriptor.depth = info.extent.depth;
textureDescriptor.sampleCount = mtlSampleCount(info.samples);
if (textureDescriptor.sampleCount >= 2)
textureDescriptor.pixelFormat = mtlGryphnFormatToMetalFormat(info.format);
textureDescriptor.usage = MTLTextureUsageRenderTarget;
if (textureDescriptor.sampleCount >= 2) {
textureDescriptor.textureType = MTLTextureType2DMultisample;
else
}
else {
textureDescriptor.textureType = MTLTextureType2D;
}
MTLSamplerDescriptor *samplerDesc = [[MTLSamplerDescriptor alloc] init];
samplerDesc.minFilter = MTLSamplerMinMagFilterLinear;
samplerDesc.magFilter = MTLSamplerMinMagFilterLinear;
samplerDesc.mipFilter = MTLSamplerMipFilterNotMipmapped;
samplerDesc.sAddressMode = MTLSamplerAddressModeClampToEdge;
samplerDesc.tAddressMode = MTLSamplerAddressModeClampToEdge;
samplerDesc.normalizedCoordinates = YES;
texture->texture->sampler = [device->outputDevice->device newSamplerStateWithDescriptor:samplerDesc];
texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor];
[textureDescriptor release];
[samplerDesc release];
return GN_SUCCESS;
}