Update documentation
This commit is contained in:
parent
9878070b4c
commit
19c25ba670
@ -109,6 +109,29 @@ partition "**Graphics**" {
|
|||||||
buffer objects, pools manage the memory used for buffers.
|
buffer objects, pools manage the memory used for buffers.
|
||||||
end note
|
end note
|
||||||
}
|
}
|
||||||
|
partition "**TextureLibraries**" {
|
||||||
|
:createTextureImage();
|
||||||
|
note right
|
||||||
|
This function imports the pixels from an image, puts them
|
||||||
|
into a buffer, and copies them from memory into a texture!
|
||||||
|
A bit complicated because we are moving and freeing lots of
|
||||||
|
memory, but quite useful.
|
||||||
|
end note
|
||||||
|
:createTextureImageView();
|
||||||
|
note right
|
||||||
|
This function creates a image view for the texture, just
|
||||||
|
builds a struct holding information about the texture, like
|
||||||
|
layers, mip levels, and etc.
|
||||||
|
end note
|
||||||
|
:createTextureSampler();
|
||||||
|
note right
|
||||||
|
This function is **incredibly** important. This builds a
|
||||||
|
texture sampler, information about what to do with the
|
||||||
|
texture once its created. This defines settings like
|
||||||
|
//UVW mode//, //Filtering//, //Anisotropy//, and
|
||||||
|
//Mipmap modes//
|
||||||
|
end note
|
||||||
|
}
|
||||||
partition "**Buffers**" {
|
partition "**Buffers**" {
|
||||||
:createVertexBuffer();
|
:createVertexBuffer();
|
||||||
note right
|
note right
|
||||||
@ -146,13 +169,13 @@ partition "**Buffers**" {
|
|||||||
therefore necessary. (see **createDescriptorSets()**)
|
therefore necessary. (see **createDescriptorSets()**)
|
||||||
end note
|
end note
|
||||||
}
|
}
|
||||||
:Graphics::createCommandBuffer();
|
:**Graphics**::createCommandBuffer();
|
||||||
note right
|
note right
|
||||||
This is the partner to the commandPool creator,
|
This is the partner to the commandPool creator,
|
||||||
storing the commands we wish to perform whilst
|
storing the commands we wish to perform whilst
|
||||||
waiting in a queue. These are very efficient.
|
waiting in a queue. These are very efficient.
|
||||||
end note
|
end note
|
||||||
:RenderPresent::createSyncObject();
|
:**RenderPresent**::createSyncObject();
|
||||||
note right
|
note right
|
||||||
This is **HEAVILY** documented, create Semaphores
|
This is **HEAVILY** documented, create Semaphores
|
||||||
and Fences, for halting and starting execution, basically
|
and Fences, for halting and starting execution, basically
|
||||||
|
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 67 KiB |
7988
lib/stb_image.h
7988
lib/stb_image.h
File diff suppressed because it is too large
Load Diff
@ -292,6 +292,7 @@ namespace DeviceControl {
|
|||||||
if(Global::enableValidationLayers) std::cout << "Destroyed Swap Chain safely\n" << std::endl;
|
if(Global::enableValidationLayers) std::cout << "Destroyed Swap Chain safely\n" << std::endl;
|
||||||
}
|
}
|
||||||
VkImageView devicelibrary::createImageView(VkImage image, VkFormat format) {
|
VkImageView devicelibrary::createImageView(VkImage image, VkFormat format) {
|
||||||
|
// This defines the parameters of a newly created image object!
|
||||||
VkImageViewCreateInfo viewInfo{};
|
VkImageViewCreateInfo viewInfo{};
|
||||||
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
|
||||||
viewInfo.image = image;
|
viewInfo.image = image;
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
#include <vulkan/vulkan_core.h>
|
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include <stb/stb_image.h>
|
#include <stb/stb_image.h>
|
||||||
#include "texture.h"
|
#include "texture.h"
|
||||||
@ -15,6 +14,7 @@ VkPipelineStageFlags destinationStage;
|
|||||||
|
|
||||||
namespace TextureLibraries {
|
namespace TextureLibraries {
|
||||||
void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
|
void createImage(uint32_t width, uint32_t height, VkFormat format, VkImageTiling tiling, VkImageUsageFlags usage, VkMemoryPropertyFlags properties, VkImage& image, VkDeviceMemory& imageMemory) {
|
||||||
|
// This function specifies all the data in an image object, this is called directly after the creation of an image object.
|
||||||
VkImageCreateInfo imageInfo{};
|
VkImageCreateInfo imageInfo{};
|
||||||
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
|
||||||
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
imageInfo.imageType = VK_IMAGE_TYPE_2D;
|
||||||
@ -69,7 +69,6 @@ namespace TextureLibraries {
|
|||||||
|
|
||||||
return commandBuffer;
|
return commandBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void endSingleTimeCommands(VkCommandBuffer commandBuffer) {
|
void endSingleTimeCommands(VkCommandBuffer commandBuffer) {
|
||||||
// This function takes a command buffer with the data we wish to execute and submits it to the graphics queue.
|
// This function takes a command buffer with the data we wish to execute and submits it to the graphics queue.
|
||||||
// Afterwards, it purges the command buffer.
|
// Afterwards, it purges the command buffer.
|
||||||
@ -85,7 +84,6 @@ namespace TextureLibraries {
|
|||||||
|
|
||||||
vkFreeCommandBuffers(Global::device, Global::commandPool, 1, &commandBuffer);
|
vkFreeCommandBuffers(Global::device, Global::commandPool, 1, &commandBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) {
|
void copyBuffer(VkBuffer srcBuffer, VkBuffer dstBuffer, VkDeviceSize size) {
|
||||||
// Copy 1 buffer to another.
|
// Copy 1 buffer to another.
|
||||||
VkCommandBuffer commandBuffer = beginSingleTimeCommands();
|
VkCommandBuffer commandBuffer = beginSingleTimeCommands();
|
||||||
@ -141,8 +139,7 @@ namespace TextureLibraries {
|
|||||||
|
|
||||||
endSingleTimeCommands(commandBuffer);
|
endSingleTimeCommands(commandBuffer);
|
||||||
}
|
}
|
||||||
|
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) {
|
||||||
void copyBufferToImage(VkBuffer buffer, VkImage image, uint32_t width, uint32_t height) {
|
|
||||||
//This handles copying from the buffer to the image, specifically what *parts* to copy to the image.
|
//This handles copying from the buffer to the image, specifically what *parts* to copy to the image.
|
||||||
VkCommandBuffer commandBuffer = beginSingleTimeCommands();
|
VkCommandBuffer commandBuffer = beginSingleTimeCommands();
|
||||||
|
|
||||||
@ -167,7 +164,10 @@ namespace TextureLibraries {
|
|||||||
|
|
||||||
endSingleTimeCommands(commandBuffer);
|
endSingleTimeCommands(commandBuffer);
|
||||||
}
|
}
|
||||||
|
// -------------------------------- Image Libraries ------------------------------- //
|
||||||
void texture::createTextureImage() {
|
void texture::createTextureImage() {
|
||||||
|
// Import pixels from image with data on color channels, width and height, and colorspace!
|
||||||
|
// Its a lot of kind of complicated memory calls to bring it from a file -> to a buffer -> to a image object.
|
||||||
int textureWidth, textureHeight, textureChannels;
|
int textureWidth, textureHeight, textureChannels;
|
||||||
stbi_uc* pixels = stbi_load("assets/textures/test.png", &textureWidth, &textureHeight, &textureChannels, STBI_rgb_alpha);
|
stbi_uc* pixels = stbi_load("assets/textures/test.png", &textureWidth, &textureHeight, &textureChannels, STBI_rgb_alpha);
|
||||||
|
|
||||||
@ -197,28 +197,42 @@ namespace TextureLibraries {
|
|||||||
vkFreeMemory(Global::device, stagingBufferMemory, nullptr);
|
vkFreeMemory(Global::device, stagingBufferMemory, nullptr);
|
||||||
}
|
}
|
||||||
void texture::createTextureImageView() {
|
void texture::createTextureImageView() {
|
||||||
|
// Create a texture image view, which is a struct of information about the image.
|
||||||
Global::textureImageView = deviceLibraries.createImageView(textureImage, VK_FORMAT_R8G8B8A8_SRGB);
|
Global::textureImageView = deviceLibraries.createImageView(textureImage, VK_FORMAT_R8G8B8A8_SRGB);
|
||||||
}
|
}
|
||||||
void texture::createTextureSampler() {
|
void texture::createTextureSampler() {
|
||||||
|
// Create a sampler to access and parse the texture object.
|
||||||
VkSamplerCreateInfo samplerInfo{};
|
VkSamplerCreateInfo samplerInfo{};
|
||||||
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||||
|
// These two options define the filtering method when sampling the texture.
|
||||||
|
// It also handles zooming in versus out, min vs mag!
|
||||||
samplerInfo.magFilter = VK_FILTER_LINEAR; // TODO: CUBIC
|
samplerInfo.magFilter = VK_FILTER_LINEAR; // TODO: CUBIC
|
||||||
samplerInfo.minFilter = VK_FILTER_LINEAR; // TODO: CUBIC
|
samplerInfo.minFilter = VK_FILTER_LINEAR; // TODO: CUBIC
|
||||||
|
|
||||||
|
// These options define UVW edge modes, ClampToEdge extends the last pixels to the edges when larger than the UVW.
|
||||||
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||||
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||||
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||||
|
|
||||||
VkPhysicalDeviceProperties properties{};
|
VkPhysicalDeviceProperties properties{};
|
||||||
vkGetPhysicalDeviceProperties(Global::physicalDevice, &properties);
|
vkGetPhysicalDeviceProperties(Global::physicalDevice, &properties);
|
||||||
|
// Enable or Disable Anisotropy, and set the amount.
|
||||||
samplerInfo.anisotropyEnable = VK_TRUE;
|
samplerInfo.anisotropyEnable = VK_TRUE;
|
||||||
samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
|
samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
|
||||||
|
|
||||||
|
// When sampling with Clamp to Border, the border color is defined here.
|
||||||
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
|
samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
|
||||||
|
// Normalizing coordinates changes texCoords from [0, texWidth] to [0, 1].
|
||||||
|
// This is what should ALWAYS be used, because it means you can use varying texture sizes.
|
||||||
|
// Another TODO: Normalizing
|
||||||
samplerInfo.unnormalizedCoordinates = VK_FALSE;
|
samplerInfo.unnormalizedCoordinates = VK_FALSE;
|
||||||
|
// Compare texels to a value and use the output in filtering!
|
||||||
|
// This is mainly used in percentage-closer filtering on shadow maps, this will be revisted eventually...
|
||||||
samplerInfo.compareEnable = VK_FALSE;
|
samplerInfo.compareEnable = VK_FALSE;
|
||||||
samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
|
samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||||
|
|
||||||
|
// Mipmaps are basically LoD's for textures, different resolutions to load based on distance.
|
||||||
|
// These settings simply describe how to apply mipmapping.
|
||||||
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
|
||||||
samplerInfo.mipLodBias = 0.0f;
|
samplerInfo.mipLodBias = 0.0f;
|
||||||
samplerInfo.minLod = 0.0f;
|
samplerInfo.minLod = 0.0f;
|
||||||
|
Loading…
Reference in New Issue
Block a user