samplers and image views
This commit is contained in:
@@ -18,28 +18,30 @@ gnReturnCode gnCreateOutputDeviceFn(gnOutputDeviceHandle outputDevice, gnInstanc
|
|||||||
queueCreateInfos[i].pQueuePriorities = &queuePriority;
|
queueCreateInfos[i].pQueuePriorities = &queuePriority;
|
||||||
}
|
}
|
||||||
|
|
||||||
VkPhysicalDeviceFeatures deviceFeatures = {};
|
VkPhysicalDeviceFeatures deviceFeatures = {
|
||||||
|
.samplerAnisotropy = VK_TRUE
|
||||||
|
};
|
||||||
|
|
||||||
VkDeviceCreateInfo createInfo = {};
|
VkDeviceCreateInfo deviceCreateInfo = {
|
||||||
createInfo.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO;
|
.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
|
||||||
createInfo.queueCreateInfoCount = deviceInfo.queueInfoCount;
|
.queueCreateInfoCount = deviceInfo.queueInfoCount,
|
||||||
createInfo.pQueueCreateInfos = queueCreateInfos;
|
.pQueueCreateInfos = queueCreateInfos,
|
||||||
createInfo.pEnabledFeatures = &deviceFeatures;
|
.pEnabledFeatures = &deviceFeatures,
|
||||||
|
|
||||||
createInfo.enabledExtensionCount = deviceExtensionCount;
|
.enabledExtensionCount = deviceExtensionCount,
|
||||||
createInfo.ppEnabledExtensionNames = deviceExtensions;
|
.ppEnabledExtensionNames = deviceExtensions,
|
||||||
|
};
|
||||||
|
|
||||||
if (instance->debugger == NULL)
|
if (instance->debugger == NULL)
|
||||||
createInfo.enabledLayerCount = 0;
|
deviceCreateInfo.enabledLayerCount = 0;
|
||||||
else {
|
else {
|
||||||
const char* validation_layers[1] = { "VK_LAYER_KHRONOS_validation" };
|
const char* validation_layers[1] = { "VK_LAYER_KHRONOS_validation" };
|
||||||
createInfo.enabledLayerCount = 1;
|
deviceCreateInfo.enabledLayerCount = 1;
|
||||||
createInfo.ppEnabledLayerNames = validation_layers;
|
deviceCreateInfo.ppEnabledLayerNames = validation_layers;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vkCreateDevice(deviceInfo.physicalDevice.physicalDevice->device, &createInfo, NULL, &outputDevice->outputDevice->device) != VK_SUCCESS) {
|
if (vkCreateDevice(deviceInfo.physicalDevice.physicalDevice->device, &deviceCreateInfo, NULL, &outputDevice->outputDevice->device) != VK_SUCCESS)
|
||||||
return GN_FAILED_TO_CREATE_DEVICE;
|
return GN_FAILED_TO_CREATE_DEVICE;
|
||||||
}
|
|
||||||
|
|
||||||
outputDevice->outputDevice->queues = malloc(sizeof(VkQueue) * deviceInfo.queueInfoCount);
|
outputDevice->outputDevice->queues = malloc(sizeof(VkQueue) * deviceInfo.queueInfoCount);
|
||||||
for (int i = 0; i < deviceInfo.queueInfoCount; i++) {
|
for (int i = 0; i < deviceInfo.queueInfoCount; i++) {
|
||||||
|
@@ -6,7 +6,22 @@
|
|||||||
|
|
||||||
VkImageType vkGryphnTextureType(gnTextureType type) {
|
VkImageType vkGryphnTextureType(gnTextureType type) {
|
||||||
switch(type) {
|
switch(type) {
|
||||||
case GN_TEXTURE_2D: return VK_IMAGE_TYPE_3D;
|
case GN_TEXTURE_2D: return VK_IMAGE_TYPE_2D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkImageViewType vkGryphnTextureTypeView(gnTextureType type) {
|
||||||
|
switch(type) {
|
||||||
|
case GN_TEXTURE_2D: return VK_IMAGE_VIEW_TYPE_2D;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
VkSamplerAddressMode vkGryphnTextureWrap(gnTextureWrap wrap) {
|
||||||
|
switch(wrap) {
|
||||||
|
case GN_REPEAT: return VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||||
|
case GN_MIRRORED_REPEAT: return VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT;
|
||||||
|
case GN_CLAMP_TO_EDGE: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||||
|
case GN_CLAMP_TO_BORDER: return VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,6 +164,51 @@ gnReturnCode gnCreateTextureFn(gnTexture texture, gnDevice device, const gnTextu
|
|||||||
|
|
||||||
texture->texture->beenWrittenToo = gnFalse;
|
texture->texture->beenWrittenToo = gnFalse;
|
||||||
|
|
||||||
|
VkImageViewCreateInfo viewInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO,
|
||||||
|
.image = texture->texture->image.image,
|
||||||
|
.viewType = vkGryphnTextureTypeView(info.type),
|
||||||
|
.format = vkGryphnFormatToVulkanFormat(info.format),
|
||||||
|
|
||||||
|
.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT,
|
||||||
|
.subresourceRange.baseMipLevel = 0,
|
||||||
|
.subresourceRange.levelCount = 1,
|
||||||
|
.subresourceRange.baseArrayLayer = 0,
|
||||||
|
.subresourceRange.layerCount = 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (vkCreateImageView(device->outputDevice->device, &viewInfo, NULL, &texture->texture->image.imageView) != VK_SUCCESS)
|
||||||
|
return GN_FAILED_TO_CREATE_IMAGE_VIEW;
|
||||||
|
|
||||||
|
VkPhysicalDeviceProperties properties = {};
|
||||||
|
vkGetPhysicalDeviceProperties(device->physicalDevice.physicalDevice->device, &properties);
|
||||||
|
|
||||||
|
VkSamplerCreateInfo samplerInfo = {
|
||||||
|
.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
|
||||||
|
.minFilter = (info.minFilter == GN_FILTER_LINEAR) ? VK_FILTER_LINEAR : VK_FILTER_NEAREST,
|
||||||
|
.magFilter = (info.magFilter == GN_FILTER_LINEAR) ? VK_FILTER_LINEAR : VK_FILTER_NEAREST,
|
||||||
|
|
||||||
|
.addressModeU = vkGryphnTextureWrap(info.wrapU),
|
||||||
|
.addressModeV = vkGryphnTextureWrap(info.wrapV),
|
||||||
|
.addressModeW = vkGryphnTextureWrap(info.wrapW),
|
||||||
|
|
||||||
|
.anisotropyEnable = VK_TRUE,
|
||||||
|
.maxAnisotropy = properties.limits.maxSamplerAnisotropy,
|
||||||
|
.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK,
|
||||||
|
.unnormalizedCoordinates = VK_FALSE,
|
||||||
|
|
||||||
|
.compareEnable = VK_FALSE,
|
||||||
|
.compareOp = VK_COMPARE_OP_ALWAYS,
|
||||||
|
|
||||||
|
.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR,
|
||||||
|
.mipLodBias = 0.0f,
|
||||||
|
.minLod = 0.0f,
|
||||||
|
.maxLod = 0.0f,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (vkCreateSampler(device->outputDevice->device, &samplerInfo, NULL, &texture->texture->sampler) != VK_SUCCESS)
|
||||||
|
return GN_FAILED_TO_CREATE_SAMPLER;
|
||||||
|
|
||||||
return GN_SUCCESS;
|
return GN_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,10 +234,13 @@ void gnTextureDataFn(gnTextureHandle texture, void* pixelData) {
|
|||||||
|
|
||||||
void gnDestroyVulkanImage(VkGryphnImage* image, VkDevice device) {
|
void gnDestroyVulkanImage(VkGryphnImage* image, VkDevice device) {
|
||||||
vkDestroyImage(device, image->image, NULL);
|
vkDestroyImage(device, image->image, NULL);
|
||||||
|
vkDestroyImageView(device, image->imageView, NULL);
|
||||||
vkFreeMemory(device, image->memory, NULL);
|
vkFreeMemory(device, image->memory, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnDestroyTextureFn(gnTexture texture) {
|
void gnDestroyTextureFn(gnTexture texture) {
|
||||||
|
vkDestroySampler(texture->device->outputDevice->device, texture->texture->sampler, NULL);
|
||||||
|
|
||||||
gnDestroyVulkanBuffer(&texture->texture->buffer, texture->device->outputDevice->device);
|
gnDestroyVulkanBuffer(&texture->texture->buffer, texture->device->outputDevice->device);
|
||||||
gnDestroyVulkanImage(&texture->texture->image, texture->device->outputDevice->device);
|
gnDestroyVulkanImage(&texture->texture->image, texture->device->outputDevice->device);
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,7 @@ void gnDestroyVulkanImage(VkGryphnImage* image, VkDevice device);
|
|||||||
typedef struct gnPlatformTexture_t {
|
typedef struct gnPlatformTexture_t {
|
||||||
VkGryphnBuffer buffer;
|
VkGryphnBuffer buffer;
|
||||||
VkGryphnImage image;
|
VkGryphnImage image;
|
||||||
|
VkSampler sampler;
|
||||||
|
|
||||||
size_t size;
|
size_t size;
|
||||||
uint32_t width, height;
|
uint32_t width, height;
|
||||||
|
@@ -8,11 +8,21 @@ typedef enum gnTextureType {
|
|||||||
GN_TEXTURE_2D
|
GN_TEXTURE_2D
|
||||||
} gnTextureType;
|
} gnTextureType;
|
||||||
|
|
||||||
|
typedef enum gnTextureFilter {
|
||||||
|
GN_FILTER_LINEAR, GN_FILTER_NEAREST
|
||||||
|
} gnTextureFilter;
|
||||||
|
|
||||||
|
typedef enum gnTextureWrap {
|
||||||
|
GN_REPEAT, GN_MIRRORED_REPEAT, GN_CLAMP_TO_EDGE, GN_CLAMP_TO_BORDER
|
||||||
|
} gnTextureWrap;
|
||||||
|
|
||||||
typedef struct gnTextureInfo {
|
typedef struct gnTextureInfo {
|
||||||
uint32_t width;
|
uint32_t width;
|
||||||
uint32_t height;
|
uint32_t height;
|
||||||
gnTextureType type;
|
gnTextureType type;
|
||||||
gnImageFormat format;
|
gnImageFormat format;
|
||||||
|
gnTextureFilter minFilter, magFilter;
|
||||||
|
gnTextureWrap wrapU, wrapV, wrapW;
|
||||||
} gnTextureInfo;
|
} gnTextureInfo;
|
||||||
|
|
||||||
#ifdef GN_REVEAL_IMPL
|
#ifdef GN_REVEAL_IMPL
|
||||||
|
Reference in New Issue
Block a user