diff --git a/projects/apis/metal/src/texture/metal_texture.m b/projects/apis/metal/src/texture/metal_texture.m index 4f8282a..5dde993 100644 --- a/projects/apis/metal/src/texture/metal_texture.m +++ b/projects/apis/metal/src/texture/metal_texture.m @@ -6,8 +6,9 @@ gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnText 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; + textureDescriptor.width = info.extent.width; + textureDescriptor.height = info.extent.height; + textureDescriptor.depth = info.extent.depth; texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor]; [textureDescriptor release]; @@ -17,10 +18,10 @@ gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnText void metalTextureData(gnTextureHandle texture, void* pixelData) { MTLRegion region = { { 0, 0, 0 }, - {texture->info.width, texture->info.height, 1} + {texture->info.extent.width, texture->info.extent.width, texture->info.extent.depth} }; - NSUInteger bytesPerRow = 4 * texture->info.width; // TODO: fix this should not be set to 4 + NSUInteger bytesPerRow = 4 * texture->info.extent.width; // TODO: fix this should not be set to 4 [texture->texture->texture replaceRegion:region mipmapLevel:0 withBytes:pixelData diff --git a/projects/apis/vulkan/src/textures/vulkan_texture.c b/projects/apis/vulkan/src/textures/vulkan_texture.c index ac98ef2..c8de674 100644 --- a/projects/apis/vulkan/src/textures/vulkan_texture.c +++ b/projects/apis/vulkan/src/textures/vulkan_texture.c @@ -94,7 +94,7 @@ void VkTransitionImageLayout(gnDevice device, VkImage image, gnImageFormat forma gnEndVulkanTransferOperation(device, transferBuffer); } -void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, uint32_t width, uint32_t height, gnDevice device) { +void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, gnExtent3D extent, gnDevice device) { VkCommandBuffer transferBuffer = gnBeginVulkanTransferOperation(device); VkBufferImageCopy region = { @@ -109,9 +109,9 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, uint32_t wi .imageOffset = (VkOffset3D){0, 0, 0}, .imageExtent = (VkExtent3D){ - width, - height, - 1 + extent.width, + extent.height, + extent.depth } }; @@ -130,7 +130,7 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, uint32_t wi gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) { texture->texture = malloc(sizeof(struct gnPlatformTexture_t)); - size_t imageSize = info.width * info.height; + size_t imageSize = info.extent.width * info.extent.height; if (info.format == GN_FORMAT_BGRA8_SRGB) { imageSize *= 4; } if (info.format == GN_FORMAT_RGBA8_SRGB) { imageSize *= 4; } @@ -148,9 +148,9 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn .initialLayout = VK_IMAGE_LAYOUT_UNDEFINED, .samples = VK_SAMPLE_COUNT_1_BIT, .extent = { - .width = info.width, - .height = info.height, - .depth = 1 + .width = info.extent.width, + .height = info.extent.height, + .depth = info.extent.depth }, .mipLevels = 1, .arrayLayers = 1, @@ -183,9 +183,6 @@ gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureIn vkBindImageMemory(device->outputDevice->device, texture->texture->image.image, texture->texture->image.memory, 0); - texture->texture->width = info.width; - texture->texture->height = info.height; - texture->texture->beenWrittenToo = gnFalse; VkImageViewCreateInfo viewInfo = { @@ -247,7 +244,7 @@ void textureData(gnTextureHandle texture, void* pixelData) { //gnDevice device, VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL); - VkCopyBufferToImage(texture->texture->buffer, texture->texture->image, texture->texture->width, texture->texture->height, texture->device); + VkCopyBufferToImage(texture->texture->buffer, texture->texture->image, texture->info.extent, texture->device); VkTransitionImageLayout(texture->device, texture->texture->image.image, texture->info.format, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); texture->texture->beenWrittenToo = gnTrue; diff --git a/projects/apis/vulkan/src/textures/vulkan_texture.h b/projects/apis/vulkan/src/textures/vulkan_texture.h index 307546b..eb67e35 100644 --- a/projects/apis/vulkan/src/textures/vulkan_texture.h +++ b/projects/apis/vulkan/src/textures/vulkan_texture.h @@ -16,7 +16,6 @@ typedef struct gnPlatformTexture_t { VkSampler sampler; size_t size; - uint32_t width, height; gnBool beenWrittenToo; } gnPlatformTexture; diff --git a/projects/core/src/textures/gryphn_texture.h b/projects/core/src/textures/gryphn_texture.h index 1b38f06..b56ec26 100644 --- a/projects/core/src/textures/gryphn_texture.h +++ b/projects/core/src/textures/gryphn_texture.h @@ -1,7 +1,7 @@ #pragma once -#include "stdint.h" #include "utils/gryphn_image_format.h" #include "utils/gryphn_error_code.h" +#include "utils/math/gryphn_vec3.h" #include typedef enum gnTextureType { @@ -17,8 +17,7 @@ typedef enum gnTextureWrap { } gnTextureWrap; typedef struct gnTextureInfo { - uint32_t width; - uint32_t height; + gnExtent3D extent; gnTextureType type; gnImageFormat format; gnTextureFilter minFilter, magFilter;