texture extents
This commit is contained in:
@@ -6,8 +6,9 @@ gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnText
|
|||||||
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
||||||
MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init];
|
MTLTextureDescriptor *textureDescriptor = [[MTLTextureDescriptor alloc] init];
|
||||||
textureDescriptor.pixelFormat = mtlGryphnFormatToMetalFormat(info.format);
|
textureDescriptor.pixelFormat = mtlGryphnFormatToMetalFormat(info.format);
|
||||||
textureDescriptor.width = info.width;
|
textureDescriptor.width = info.extent.width;
|
||||||
textureDescriptor.height = info.height;
|
textureDescriptor.height = info.extent.height;
|
||||||
|
textureDescriptor.depth = info.extent.depth;
|
||||||
|
|
||||||
texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor];
|
texture->texture->texture = [device->outputDevice->device newTextureWithDescriptor:textureDescriptor];
|
||||||
[textureDescriptor release];
|
[textureDescriptor release];
|
||||||
@@ -17,10 +18,10 @@ gnReturnCode createMetalTexture(gnTexture texture, gnDevice device, const gnText
|
|||||||
void metalTextureData(gnTextureHandle texture, void* pixelData) {
|
void metalTextureData(gnTextureHandle texture, void* pixelData) {
|
||||||
MTLRegion region = {
|
MTLRegion region = {
|
||||||
{ 0, 0, 0 },
|
{ 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
|
[texture->texture->texture replaceRegion:region
|
||||||
mipmapLevel:0
|
mipmapLevel:0
|
||||||
withBytes:pixelData
|
withBytes:pixelData
|
||||||
|
@@ -94,7 +94,7 @@ void VkTransitionImageLayout(gnDevice device, VkImage image, gnImageFormat forma
|
|||||||
gnEndVulkanTransferOperation(device, transferBuffer);
|
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);
|
VkCommandBuffer transferBuffer = gnBeginVulkanTransferOperation(device);
|
||||||
|
|
||||||
VkBufferImageCopy region = {
|
VkBufferImageCopy region = {
|
||||||
@@ -109,9 +109,9 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, uint32_t wi
|
|||||||
|
|
||||||
.imageOffset = (VkOffset3D){0, 0, 0},
|
.imageOffset = (VkOffset3D){0, 0, 0},
|
||||||
.imageExtent = (VkExtent3D){
|
.imageExtent = (VkExtent3D){
|
||||||
width,
|
extent.width,
|
||||||
height,
|
extent.height,
|
||||||
1
|
extent.depth
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,7 +130,7 @@ void VkCopyBufferToImage(VkGryphnBuffer buffer, VkGryphnImage image, uint32_t wi
|
|||||||
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
gnReturnCode createTexture(gnTexture texture, gnDevice device, const gnTextureInfo info) {
|
||||||
texture->texture = malloc(sizeof(struct gnPlatformTexture_t));
|
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_BGRA8_SRGB) { imageSize *= 4; }
|
||||||
if (info.format == GN_FORMAT_RGBA8_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,
|
.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED,
|
||||||
.samples = VK_SAMPLE_COUNT_1_BIT,
|
.samples = VK_SAMPLE_COUNT_1_BIT,
|
||||||
.extent = {
|
.extent = {
|
||||||
.width = info.width,
|
.width = info.extent.width,
|
||||||
.height = info.height,
|
.height = info.extent.height,
|
||||||
.depth = 1
|
.depth = info.extent.depth
|
||||||
},
|
},
|
||||||
.mipLevels = 1,
|
.mipLevels = 1,
|
||||||
.arrayLayers = 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);
|
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;
|
texture->texture->beenWrittenToo = gnFalse;
|
||||||
|
|
||||||
VkImageViewCreateInfo viewInfo = {
|
VkImageViewCreateInfo viewInfo = {
|
||||||
@@ -247,7 +244,7 @@ void textureData(gnTextureHandle texture, void* pixelData) {
|
|||||||
|
|
||||||
//gnDevice device, VkImage image, VkFormat format, VkImageLayout oldLayout, VkImageLayout newLayout
|
//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);
|
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);
|
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;
|
texture->texture->beenWrittenToo = gnTrue;
|
||||||
|
@@ -16,7 +16,6 @@ typedef struct gnPlatformTexture_t {
|
|||||||
VkSampler sampler;
|
VkSampler sampler;
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
uint32_t width, height;
|
|
||||||
gnBool beenWrittenToo;
|
gnBool beenWrittenToo;
|
||||||
} gnPlatformTexture;
|
} gnPlatformTexture;
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "stdint.h"
|
|
||||||
#include "utils/gryphn_image_format.h"
|
#include "utils/gryphn_image_format.h"
|
||||||
#include "utils/gryphn_error_code.h"
|
#include "utils/gryphn_error_code.h"
|
||||||
|
#include "utils/math/gryphn_vec3.h"
|
||||||
#include <gryphn_handles.h>
|
#include <gryphn_handles.h>
|
||||||
|
|
||||||
typedef enum gnTextureType {
|
typedef enum gnTextureType {
|
||||||
@@ -17,8 +17,7 @@ typedef enum gnTextureWrap {
|
|||||||
} gnTextureWrap;
|
} gnTextureWrap;
|
||||||
|
|
||||||
typedef struct gnTextureInfo {
|
typedef struct gnTextureInfo {
|
||||||
uint32_t width;
|
gnExtent3D extent;
|
||||||
uint32_t height;
|
|
||||||
gnTextureType type;
|
gnTextureType type;
|
||||||
gnImageFormat format;
|
gnImageFormat format;
|
||||||
gnTextureFilter minFilter, magFilter;
|
gnTextureFilter minFilter, magFilter;
|
||||||
|
Reference in New Issue
Block a user