get all the commands to work

This commit is contained in:
Greg Wells
2025-06-29 14:40:09 -04:00
parent 67e5e6e36a
commit 8211876837
37 changed files with 295 additions and 154 deletions

View File

@@ -5,3 +5,7 @@
typedef struct gnPlatformTexture_t {
id<MTLTexture> texture;
} gnPlatformTexture;
gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnTextureInfo info);
void metalTextureData(gnTextureHandle texture, void* pixelData);
void metalDestroyTexture(gnTexture texture);

View File

@@ -0,0 +1,33 @@
#include "metal_texture.h"
#include "surface/metal_surface.h"
#include "devices/metal_output_devices.h"
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.width;
textureDescriptor.height = info.height;
texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor];
[textureDescriptor release];
return GN_SUCCESS;
}
void metalTextureData(gnTextureHandle texture, void* pixelData) {
MTLRegion region = {
{ 0, 0, 0 },
{texture->info.width, texture->info.height, 1}
};
NSUInteger bytesPerRow = 4 * texture->info.width; // TODO: fix this should not be set to 4
[texture->texture->texture replaceRegion:region
mipmapLevel:0
withBytes:pixelData
bytesPerRow:bytesPerRow];
}
void metalDestroyTexture(gnTexture texture) {
[texture->texture->texture release];
free(texture->texture);
}