From 29b3f8627e5d9e54fe19de5336dff06983b61345 Mon Sep 17 00:00:00 2001 From: "Grayson Riffe (Laptop)" Date: Fri, 27 Aug 2021 22:37:02 -0500 Subject: [PATCH] Added AssetPack and basic assets --- NothinFancy/NothinFancy.vcxproj | 2 ++ NothinFancy/NothinFancy.vcxproj.filters | 6 ++++ NothinFancy/src/Assets.cpp | 34 ++++++++++++++++++++ NothinFancy/src/Renderer/Drawable/Entity.cpp | 1 + NothinFancy/src/Renderer/Texture.cpp | 2 +- NothinFancy/src/include/Assets.h | 32 ++++++++++++++++++ NothinFancy/src/include/NothinFancy.h | 1 + 7 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 NothinFancy/src/Assets.cpp create mode 100644 NothinFancy/src/include/Assets.h diff --git a/NothinFancy/NothinFancy.vcxproj b/NothinFancy/NothinFancy.vcxproj index ff1b237..64cbbf2 100644 --- a/NothinFancy/NothinFancy.vcxproj +++ b/NothinFancy/NothinFancy.vcxproj @@ -208,6 +208,7 @@ + @@ -222,6 +223,7 @@ + diff --git a/NothinFancy/NothinFancy.vcxproj.filters b/NothinFancy/NothinFancy.vcxproj.filters index dcf212a..9998290 100644 --- a/NothinFancy/NothinFancy.vcxproj.filters +++ b/NothinFancy/NothinFancy.vcxproj.filters @@ -54,6 +54,9 @@ Source Files + + Source Files + @@ -107,6 +110,9 @@ Header Files + + Header Files + diff --git a/NothinFancy/src/Assets.cpp b/NothinFancy/src/Assets.cpp new file mode 100644 index 0000000..f06dfef --- /dev/null +++ b/NothinFancy/src/Assets.cpp @@ -0,0 +1,34 @@ +#include "Assets.h" + +#include "Utility.h" + +namespace nf { + Asset::~Asset() { + + } + + AGeometry::~AGeometry() { + delete[] m_vertexBufferData; + delete[] m_indexBufferData; + delete[] m_textureCoordinatesBufferData; + } + + ATexture::~ATexture() { + delete[] m_data; + } + + AssetPack::AssetPack() { + + } + + void AssetPack::load(const char* packName) { + std::string path = "assets/" + (std::string)packName + ".nfpack"; + std::string contents = readFile(path.c_str(), true); + } + + AssetPack::~AssetPack() { + for (auto curr : m_assets) { + delete curr.second; + } + } +} \ No newline at end of file diff --git a/NothinFancy/src/Renderer/Drawable/Entity.cpp b/NothinFancy/src/Renderer/Drawable/Entity.cpp index c3237a2..dedd125 100644 --- a/NothinFancy/src/Renderer/Drawable/Entity.cpp +++ b/NothinFancy/src/Renderer/Drawable/Entity.cpp @@ -13,6 +13,7 @@ namespace nf { void Entity::create(const void* vertexBufferData, const size_t vertexBufferSize, const void* indexBufferData, size_t indexBufferCount, const void* textureCoordinatesBufferData, size_t textureCoordinatesBufferSize, const char* textureName) { m_model = new Model; m_model->create(vertexBufferData, vertexBufferSize, indexBufferData, indexBufferCount, textureCoordinatesBufferData, textureCoordinatesBufferSize, textureName); + //TODO: Replace this with getting the information from the AGeometry and ATexture structs } void Entity::setPosition(float x, float y, float z) { diff --git a/NothinFancy/src/Renderer/Texture.cpp b/NothinFancy/src/Renderer/Texture.cpp index 3c28c01..c5b192b 100644 --- a/NothinFancy/src/Renderer/Texture.cpp +++ b/NothinFancy/src/Renderer/Texture.cpp @@ -17,7 +17,7 @@ namespace nf { unsigned char* texture = stbi_load(textureName, &width, &height, &nChannels, 0); //TODO: Load from memory if (!texture) - Error("Texture failed to load from memory!"); + Error("Texture \"" + (std::string)textureName + "\" failed to load from memory!"); glBindTexture(GL_TEXTURE_2D, m_id); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); diff --git a/NothinFancy/src/include/Assets.h b/NothinFancy/src/include/Assets.h new file mode 100644 index 0000000..73a759e --- /dev/null +++ b/NothinFancy/src/include/Assets.h @@ -0,0 +1,32 @@ +#pragma once +#include +#include + +namespace nf { + struct Asset { + virtual ~Asset(); + }; + + struct AGeometry : Asset { + const float* m_vertexBufferData; + const unsigned int* m_indexBufferData; + const float* m_textureCoordinatesBufferData; + ~AGeometry() override; + }; + + struct ATexture : Asset { + const void* m_data; + ~ATexture() override; + }; + + class AssetPack { + public: + AssetPack(); + + void load(const char* packName); + + ~AssetPack(); + private: + std::unordered_map m_assets; + }; +} \ No newline at end of file diff --git a/NothinFancy/src/include/NothinFancy.h b/NothinFancy/src/include/NothinFancy.h index b791908..c23eafb 100644 --- a/NothinFancy/src/include/NothinFancy.h +++ b/NothinFancy/src/include/NothinFancy.h @@ -131,5 +131,6 @@ namespace nf { Renderer* m_renderer; }; } +#include "Assets.h" #include "Input.h" #include "Utility.h" \ No newline at end of file