From 5f305f96090a8290ec3eaeed54e1f983c7296ca9 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Tue, 20 Sep 2022 18:13:13 +0800 Subject: [PATCH] Added SHTextureLibrary stub --- .../MiddleEnd/Textures/SHTextureLibrary.cpp | 41 +++++ .../MiddleEnd/Textures/SHTextureLibrary.h | 142 ++++++++++++++++++ 2 files changed, 183 insertions(+) create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp create mode 100644 SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp new file mode 100644 index 00000000..97b72977 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.cpp @@ -0,0 +1,41 @@ +/************************************************************************************//*! +\file SHTextureLibrary.cpp +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Sep 20, 2022 +\brief Contains definitions for all of the functions of the classes that deal + with storage and management of buffers for textures. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#include "SHpch.h" +#include "SHTextureLibrary.h" + +#include "Graphics/Devices/SHVkLogicalDevice.h" +#include "Graphics/Buffers/SHVkBuffer.h" +#include "Graphics/Commands/SHVkCommandBuffer.h" +#include "Graphics/SHVkUtil.h" + +namespace SHADE +{ + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + Handle SHTextureLibrary::Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData) + { + return {}; + } + + void SHTextureLibrary::Remove(Handle mesh) + { + + } + + void SHTextureLibrary::BuildBuffers(Handle device, Handle cmdBuffer) + { + + } + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h new file mode 100644 index 00000000..a0167cba --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Textures/SHTextureLibrary.h @@ -0,0 +1,142 @@ +/************************************************************************************//*! +\file SHTextureLibrary.h +\author Tng Kah Wei, kahwei.tng, 390009620 +\par email: kahwei.tng\@digipen.edu +\date Sep 20, 2022 +\brief Contains definitions for all of the classes that deal with storage and + management of textures. + +Copyright (C) 2022 DigiPen Institute of Technology. +Reproduction or disclosure of this file or its contents without the prior written consent +of DigiPen Institute of Technology is prohibited. +*//*************************************************************************************/ +#pragma once + +// STL Includes +#include +// Project Includes +#include "Resource/Handle.h" +#include "Resource/ResourceLibrary.h" +#include "Math/SHMath.h" + +namespace SHADE +{ + /*---------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*---------------------------------------------------------------------------------*/ + class SHVkBuffer; + class SHVkLogicalDevice; + class SHVkCommandBuffer; + + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + class SHTexture + { + public: + /*-----------------------------------------------------------------------------*/ + /* Type Definitions */ + /*-----------------------------------------------------------------------------*/ + using PixelChannel = uint8_t; + + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + }; + /***********************************************************************************/ + /*! + \brief + Manages storage for all textures in the Graphics System as a single set of + textures. + */ + /***********************************************************************************/ + class SHTextureLibrary + { + public: + /*-----------------------------------------------------------------------------*/ + /* Usage Functions */ + /*-----------------------------------------------------------------------------*/ + /*******************************************************************************/ + /*! + + \brief + Adds a texture to the Texture Library. But this does not mean that the + textures have been added yet. A call to "BuildBuffers()" is required to + transfer all textures into the GPU. + + \param pixelCount + Number of pixels in this Mesh. + \param positions + Pointer to the first in a contiguous array of SHMathVec3s that define vertex + positions. + + \return + Handle to the created Texture. This is not valid to be used until a call to + BuildBuffers(). + + */ + /*******************************************************************************/ + Handle Add(uint32_t pixelCount, const SHTexture::PixelChannel* const pixelData); + /*******************************************************************************/ + /*! + + \brief + Removes a mesh from the Texture Library. But this does not mean that the + textures have been removed yet. A call to "BuildBuffers()" is required to + finalise all changes. + + \param mesh + Handle to the mesh to remove. + + */ + /*******************************************************************************/ + void Remove(Handle mesh); + /***************************************************************************/ + /*! + + \brief + Finalises all changes to the Texture Library into the GPU buffers. + + \param device + Device used to create and update the buffers. + \param cmdBuffer + Command buffer used to set up transfers of data in the GPU memory. This + call must be preceded by calls to cmdBuffer's BeginRecording() and ended + with EndRecording(). Do recall to also submit the cmdBuffer to a transfer + queue. + */ + /***************************************************************************/ + void BuildBuffers(Handle device, Handle cmdBuffer); + + /*-----------------------------------------------------------------------------*/ + /* Getter Functions */ + /*-----------------------------------------------------------------------------*/ + Handle GetTextureBuffer() const noexcept { return texStorageBuffer; } + + private: + /*-----------------------------------------------------------------------------*/ + /* Type Definition */ + /*-----------------------------------------------------------------------------*/ + struct AddJob + { + uint32_t PixelCount = 0; + const SHTexture::PixelChannel* PixelData = nullptr; + Handle Handle; + }; + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + // Manipulation Queues + std::vector addJobs; + std::vector> removeJobs; + // Tracking + ResourceLibrary textures{}; + std::vector> texOrder; + // CPU Storage + std::vector texStorage; + // GPU Storage + Handle texStorageBuffer{}; + // Flags + bool isDirty = true; + }; +}