diff --git a/src/WallpaperEngine/Assets/CContainer.cpp b/src/WallpaperEngine/Assets/CContainer.cpp index cec2788..c09fe04 100644 --- a/src/WallpaperEngine/Assets/CContainer.cpp +++ b/src/WallpaperEngine/Assets/CContainer.cpp @@ -5,12 +5,14 @@ using namespace WallpaperEngine::Assets; -void* CContainer::readTexture (std::string filename, uint32_t* length) +CTexture* CContainer::readTexture (std::string filename) { // get the texture's filename (usually .tex) filename = "materials/" + filename + ".tex"; - return this->readFile (filename, length); + void* textureContents = this->readFile (filename, nullptr); + + return new CTexture (textureContents); } std::string CContainer::readVertexShader (const std::string& filename) diff --git a/src/WallpaperEngine/Assets/CContainer.h b/src/WallpaperEngine/Assets/CContainer.h index 6969a0d..206633b 100644 --- a/src/WallpaperEngine/Assets/CContainer.h +++ b/src/WallpaperEngine/Assets/CContainer.h @@ -5,6 +5,7 @@ #pragma once #include +#include "WallpaperEngine/Assets/CTexture.h" namespace WallpaperEngine::Assets { @@ -26,17 +27,15 @@ namespace WallpaperEngine::Assets * Wrapper for readFile, appends the texture extension at the end of the filename * * @param filename The texture name (without the .tex) - * @param length The file's length after it's been read * * @return */ - void* readTexture (std::string filename, uint32_t* length); + CTexture* readTexture (std::string filename); /** * Wrapper for readFile, appends the .vert extension at the end and opens the given shader file * * @param filename - * @param length * * @return The shader code as an string to be used */ @@ -46,7 +45,6 @@ namespace WallpaperEngine::Assets * Wrapper for readFile, appends the .frag extension at the end and opens the given shader file * * @param filename - * @param length * * @return The shader code as an string to be used */ @@ -56,7 +54,6 @@ namespace WallpaperEngine::Assets * Wrapper for readFile, appends the .h extension at the end and opens the given shader file * * @param filename - * @param length * * @return The shader code as an string to be used */ diff --git a/src/WallpaperEngine/Assets/CDirectory.cpp b/src/WallpaperEngine/Assets/CDirectory.cpp index 73a55bf..77efe2c 100644 --- a/src/WallpaperEngine/Assets/CDirectory.cpp +++ b/src/WallpaperEngine/Assets/CDirectory.cpp @@ -22,7 +22,9 @@ void* CDirectory::readFile (std::string filename, uint32_t* length) if (it != this->m_cache.end ()) { - *length = (*it).second.length; + if (length != nullptr) + *length = (*it).second.length; + return (*it).second.address; } diff --git a/src/WallpaperEngine/Render/Objects/CImage.cpp b/src/WallpaperEngine/Render/Objects/CImage.cpp index dbb1d2a..6f40eb1 100644 --- a/src/WallpaperEngine/Render/Objects/CImage.cpp +++ b/src/WallpaperEngine/Render/Objects/CImage.cpp @@ -37,11 +37,9 @@ CImage::CImage (CScene* scene, Core::Objects::CImage* image) : uint32_t textureSize = 0; // get the first texture on the first pass (this one represents the image assigned to this object) - void* textureData = this->getScene ()->getContainer ()->readTexture ( - (*(*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ()), &textureSize + this->m_texture = this->getScene ()->getContainer ()->readTexture ( + (*(*this->m_image->getMaterial ()->getPasses ().begin ())->getTextures ().begin ()) ); - // now generate our opengl texture - this->m_texture = new CTexture (textureData); // build a list of vertices, these might need some change later (or maybe invert the camera) GLfloat data [] = { diff --git a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp index e47a53d..432cc53 100644 --- a/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp +++ b/src/WallpaperEngine/Render/Objects/Effects/CPass.cpp @@ -450,11 +450,9 @@ void CPass::setupTextures () uint32_t textureSize = 0; // get the first texture on the first pass (this one represents the image assigned to this object) - void* textureData = this->m_material->getImage ()->getContainer ()->readTexture ( - (*cur), &textureSize + this->m_textures.emplace_back ( + this->m_material->getImage ()->getContainer ()->readTexture ((*cur)) ); - // load a new texture and push it into the list - this->m_textures.emplace_back (new CTexture (textureData)); } } diff --git a/src/WallpaperEngine/Render/Shaders/Compiler.cpp b/src/WallpaperEngine/Render/Shaders/Compiler.cpp index bc96c9f..0f382b3 100644 --- a/src/WallpaperEngine/Render/Shaders/Compiler.cpp +++ b/src/WallpaperEngine/Render/Shaders/Compiler.cpp @@ -599,12 +599,8 @@ namespace WallpaperEngine::Render::Shaders // TODO: CHECK WHAT TEXTURE THIS REFERS TO // add the new combo to the list this->m_combos.insert (std::make_pair (*combo, 1)); - uint32_t textureSize = 0; // also ensure that the textureName is loaded and we know about it - void* textureData = this->m_container->readTexture ((*textureName).get (), &textureSize); - // now generate our opengl textureName - CTexture* texture = new CTexture (textureData); - + CTexture* texture = this->m_container->readTexture ((*textureName).get ()); // extract the texture number from the name char value = name.at (std::string("g_Texture").length ()); // now convert it to integer