瀏覽代碼

~ changed readTexture for containers to produce a CTexture file ready to be used (simplifies loading textures)
~ fixed a write to null error on CDirectory that wasn't taking into account that length can be null

Signed-off-by: Alexis Maiquez <almamu@almamu.com>

Alexis Maiquez 5 年之前
父節點
當前提交
113d84173e

+ 4 - 2
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)

+ 2 - 5
src/WallpaperEngine/Assets/CContainer.h

@@ -5,6 +5,7 @@
 #pragma once
 
 #include <string>
+#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
          */

+ 3 - 1
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;
     }
 

+ 2 - 4
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 [] = {

+ 2 - 4
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));
     }
 }
 

+ 1 - 5
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<std::string, int> (*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 <std::string> (), &textureSize);
-                // now generate our opengl textureName
-                CTexture* texture = new CTexture (textureData);
-
+                CTexture* texture = this->m_container->readTexture ((*textureName).get <std::string> ());
                 // extract the texture number from the name
                 char value = name.at (std::string("g_Texture").length ());
                 // now convert it to integer