Quellcode durchsuchen

+ added some default values for TextureMipmap as they were not being set automatically by the compiler sometimes (and thus breaking the texture load)
+ added helper to parse vector4 data from json
- removed some old, commented out code
+ added support for getting textures from the shader's code too (fixes masks on some backgrounds)
+ added support for shader varibles with default values from shader's source code

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

Alexis Maiquez vor 5 Jahren
Ursprung
Commit
65bfbe1493

+ 28 - 3
CMakeLists.txt

@@ -6,7 +6,8 @@ set(CMAKE_CXX_FLAGS "-fpermissive")
 set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
 set(OpenGL_GL_PREFERENCE "LEGACY")
 
-add_compile_definitions(DEBUG=1)
+# if you're developing you might find this debug option useful for shader output, although RenderDoc is encouraged
+add_compile_definitions(DEBUG=0)
 
 find_package(X11 REQUIRED)
 find_package(Xrandr REQUIRED)
@@ -21,7 +22,18 @@ find_package(LZ4 REQUIRED)
 find_package(FFmpeg REQUIRED)
 find_package(FreeImage REQUIRED)
 
-include_directories(${X11_INCLUDE_DIR} ${XRANDR_INCLUDE_DIR} ${GLEW_INCLUDE_DIR} ${glfw3_INCLUDE_DIR} ${LZ4_INCLUDE_DIR} ${SDL_INCLUDE_DIRS} ${SDL_MIXER_INCLUDE_DIRS} ${FFMPEG_INCLUDE_DIR} ${FREEIMAGE_INCLUDE_DIR} src include)
+include_directories(
+    ${X11_INCLUDE_DIR}
+    ${XRANDR_INCLUDE_DIR}
+    ${GLEW_INCLUDE_DIR}
+    ${glfw3_INCLUDE_DIR}
+    ${LZ4_INCLUDE_DIR}
+    ${SDL_INCLUDE_DIRS}
+    ${SDL_MIXER_INCLUDE_DIRS}
+    ${FFMPEG_INCLUDE_DIR}
+    ${FREEIMAGE_INCLUDE_DIR}
+    src
+    include)
 
 add_executable(
         wallengine
@@ -170,4 +182,17 @@ add_executable(
         src/WallpaperEngine/Core/Objects/Images/Materials/CPass.h
 )
 
-target_link_libraries(wallengine ${X11_LIBRARIES} ${XRANDR_LIBRARIES} ${X11_Xxf86vm_LIB} ${OPENGL_LIBRARIES} ${GLEW_LIBRARIES} ${GLFW3_LIBRARY} ${GLUT_LIBRARIES} ${ZLIB_LIBRARIES} ${LZ4_LIBRARY} ${SDL_LIBRARY} ${SDL_MIXER_LIBRARIES} ${FFMPEG_LIBRARIES} ${FREEIMAGE_LIBRARIES})
+target_link_libraries(wallengine
+    ${X11_LIBRARIES}
+    ${XRANDR_LIBRARIES}
+    ${X11_Xxf86vm_LIB}
+    ${OPENGL_LIBRARIES}
+    ${GLEW_LIBRARIES}
+    ${GLFW3_LIBRARY}
+    ${GLUT_LIBRARIES}
+    ${ZLIB_LIBRARIES}
+    ${LZ4_LIBRARY}
+    ${SDL_LIBRARY}
+    ${SDL_MIXER_LIBRARIES}
+    ${FFMPEG_LIBRARIES}
+    ${FREEIMAGE_LIBRARIES})

+ 5 - 5
src/WallpaperEngine/Assets/CTexture.cpp

@@ -63,6 +63,7 @@ CTexture::CTexture (void* fileData)
     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, this->m_header->mipmapCount - 1);
 
+    // TODO: ADD SUPPORT FOR .tex-json FILES AS THEY ALSO HAVE FLAGS LIKE THESE ONES
     // setup texture wrapping and filtering
     if (this->m_header->flags & TextureFlags::ClampUVs)
     {
@@ -229,10 +230,10 @@ void CTexture::parseHeader (char* fileData)
 
     this->m_header = new TextureHeader;
 
-    uint32_t* pointer = reinterpret_cast<uint32_t*> (fileData);
+    uint32_t* pointer = reinterpret_cast <uint32_t*> (fileData);
 
-    this->m_header->format = static_cast<TextureFormat>(*pointer ++);
-    this->m_header->flags = static_cast<TextureFlags> (*pointer ++);
+    this->m_header->format = static_cast <TextureFormat>(*pointer ++);
+    this->m_header->flags = static_cast <TextureFlags> (*pointer ++);
     this->m_header->textureWidth = *pointer ++;
     this->m_header->textureHeight = *pointer ++;
     this->m_header->width = *pointer ++;
@@ -243,7 +244,6 @@ void CTexture::parseHeader (char* fileData)
     // so get the current position back as string
     fileData = reinterpret_cast <char*> (pointer);
     // get the position of what comes after the texture data
-    char* afterFileData = fileData + 9;
     pointer = reinterpret_cast <uint32_t*> (fileData + 9);
 
     if (memcmp (fileData, "TEXB0003", 9) == 0)
@@ -252,7 +252,7 @@ void CTexture::parseHeader (char* fileData)
 
         // get back the pointer and use it
         pointer ++;
-        this->m_header->freeImageFormat = static_cast<FREE_IMAGE_FORMAT> (*pointer++);
+        this->m_header->freeImageFormat = static_cast <FREE_IMAGE_FORMAT> (*pointer++);
     }
     else if(memcmp (fileData, "TEXB0002", 9) == 0)
     {

+ 5 - 5
src/WallpaperEngine/Assets/CTexture.h

@@ -39,15 +39,15 @@ namespace WallpaperEngine::Assets
             ~TextureMipmap ();
 
             /** Width of the mipmap */
-            uint32_t width;
+            uint32_t width = 0;
             /** Height of the mipmap */
-            uint32_t height;
+            uint32_t height = 0;
             /** If the mipmap data is compressed */
-            uint32_t compression;
+            uint32_t compression = 0;
             /** Uncompressed size of the mipmap */
-            uint32_t uncompressedSize;
+            uint32_t uncompressedSize = 0;
             /** Compress size of the mipmap */
-            uint32_t compressedSize;
+            uint32_t compressedSize = 0;
             /** Pointer to the compressed data */
             char* compressedData = nullptr;
             /** Pointer to the uncompressed data */

+ 15 - 0
src/WallpaperEngine/Core/Core.cpp

@@ -3,6 +3,16 @@
 using namespace WallpaperEngine;
 using namespace WallpaperEngine::Core::Types;
 
+glm::vec4 Core::aToVector4 (const char* str)
+{
+    float x = strtof (str, const_cast <char**> (&str)); while (*str == ' ') str ++;
+    float y = strtof (str, const_cast <char**> (&str)); while (*str == ' ') str ++;
+    float z = strtof (str, const_cast <char**> (&str)); while (*str == ' ') str ++;
+    float w = strtof (str, const_cast <char**> (&str));
+
+    return {x, y, z, w};
+}
+
 glm::vec3 Core::aToVector3 (const char* str)
 {
     float x = strtof (str, const_cast <char**> (&str)); while (*str == ' ') str ++;
@@ -20,6 +30,11 @@ glm::vec2 Core::aToVector2 (const char* str)
     return {x, y};
 }
 
+glm::vec4 Core::aToVector4 (const std::string& str)
+{
+    return Core::aToVector4 (str.c_str ());
+}
+
 glm::vec3 Core::aToVector3 (const std::string& str)
 {
     return Core::aToVector3 (str.c_str ());

+ 2 - 0
src/WallpaperEngine/Core/Core.h

@@ -13,9 +13,11 @@ namespace WallpaperEngine::Core
 {
     using namespace WallpaperEngine::Core::Types;
 
+    glm::vec4 aToVector4 (const char* str);
     glm::vec3 aToVector3 (const char* str);
     glm::vec2 aToVector2 (const char* str);
 
+    glm::vec4 aToVector4 (const std::string& str);
     glm::vec3 aToVector3 (const std::string& str);
     glm::vec2 aToVector2 (const std::string& str);
 

+ 0 - 55
src/WallpaperEngine/Render/Objects/Effects/CMaterial.cpp

@@ -42,24 +42,6 @@ void CMaterial::generatePasses ()
         this->m_passes.emplace_back (new CPass (this, *cur));
 }
 
-// TODO: REWRITE THIS
-/*
-void CMaterial::OnSetConstants (irr::video::IMaterialRendererServices *services, int32_t userData)
-{
-    irr::s32 g_Texture0 = 0;
-
-    irr::video::IVideoDriver* driver = services->getVideoDriver ();
-
-    irr::core::matrix4 worldViewProj;
-    worldViewProj = driver->getTransform (irr::video::ETS_PROJECTION);
-    worldViewProj *= driver->getTransform (irr::video::ETS_VIEW);
-    worldViewProj *= driver->getTransform (irr::video::ETS_WORLD);
-
-
-    services->setPixelShaderConstant ("TextureSampler", &g_Texture0, 1);
-    services->setVertexShaderConstant ("g_ModelViewProjectionMatrix", worldViewProj.pointer(), 16);
-}
-*/
 void CMaterial::render (GLuint drawTo, GLuint inputTexture)
 {
     // get the orthogonal projection
@@ -82,41 +64,4 @@ void CMaterial::render (GLuint drawTo, GLuint inputTexture)
         // render the pass
         (*cur)->render (drawTo, inputTexture);
     }
-
-    // TODO: REWRITE THIS
-    /*
-    uint16_t indices [] =
-    {
-        3, 2, 1, 0
-    };
-
-    irr::video::IVideoDriver* driver = this->getImage ()->getSceneManager ()->getVideoDriver ();
-
-    auto mainCur = this->getPasses ().begin ();
-    auto mainEnd = this->getPasses ().end ();
-
-    for (; mainCur != mainEnd; mainCur ++)
-    {
-        // set the proper render target
-        driver->setRenderTarget ((*mainCur)->getOutputTexture (), true, true, IntegerColor (0, 0, 0, 0));
-        // set the material
-        driver->setMaterial ((*mainCur)->getMaterial ());
-        // draw it
-        driver->drawVertexPrimitiveList (
-            this->m_image->getVertex (), 4, indices, 1,
-            irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT
-        );
-    }
-
-    // render last pass' output into our output
-    // set the proper render target
-    driver->setRenderTarget (this->getOutputTexture (), true, true, IntegerColor (0, 0, 0, 0));
-    // set the material
-    driver->setMaterial (this->m_outputMaterial);
-    // draw it
-    driver->drawVertexPrimitiveList (
-        this->m_image->getVertex (), 4, indices, 1,
-        irr::video::EVT_STANDARD, irr::scene::EPT_QUADS, irr::video::EIT_16BIT
-    );
-     */
 }

+ 160 - 41
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp

@@ -102,6 +102,7 @@ void CPass::render (GLuint drawTo, GLuint input)
     // bind the input texture
     glActiveTexture (GL_TEXTURE0);
     glBindTexture (GL_TEXTURE_2D, input);
+    int lastTextureIndex = 0;
 
     // first bind the textures to their sampler place
     {
@@ -115,6 +116,42 @@ void CPass::render (GLuint drawTo, GLuint input)
             glActiveTexture (GL_TEXTURE0 + index);
             // bind the correct texture there
             glBindTexture (GL_TEXTURE_2D, (*cur)->getTextureID ());
+            // increase the number of textures counter
+            lastTextureIndex ++;
+        }
+    }
+
+    {
+        // load the extra textures needed (if any) from the shader
+        auto cur = this->m_fragShader->getTextures ().begin ();
+        auto end = this->m_fragShader->getTextures ().end ();
+
+        for (; cur != end; cur ++)
+        {
+            if ((*cur).first <= lastTextureIndex)
+                continue;
+
+            // set the active texture index
+            glActiveTexture (GL_TEXTURE0 + (*cur).first);
+            // bind the correct texture here
+            glBindTexture(GL_TEXTURE_2D, (*cur).second->getTextureID ());
+        }
+    }
+
+    {
+        // load the extra textures needed (if any) from the shader
+        auto cur = this->m_vertShader->getTextures ().begin ();
+        auto end = this->m_vertShader->getTextures ().end ();
+
+        for (; cur != end; cur ++)
+        {
+            if ((*cur).first <= lastTextureIndex)
+                continue;
+
+            // set the active texture index
+            glActiveTexture (GL_TEXTURE0 + (*cur).first);
+            // bind the correct texture here
+            glBindTexture(GL_TEXTURE_2D, (*cur).second->getTextureID ());
         }
     }
 
@@ -125,28 +162,30 @@ void CPass::render (GLuint drawTo, GLuint input)
 
         for (; cur != end; cur ++)
         {
-            switch ((*cur)->type)
+            UniformEntry* entry = (*cur).second;
+
+            switch (entry->type)
             {
                 case Double:
-                    glUniform1d ((*cur)->id, *reinterpret_cast <const double*> ((*cur)->value));
+                    glUniform1d (entry->id, *reinterpret_cast <const double*> (entry->value));
                     break;
                 case Float:
-                    glUniform1f ((*cur)->id, *reinterpret_cast <const float*> ((*cur)->value));
+                    glUniform1f (entry->id, *reinterpret_cast <const float*> (entry->value));
                     break;
                 case Integer:
-                    glUniform1i ((*cur)->id, *reinterpret_cast <const int*> ((*cur)->value));
+                    glUniform1i (entry->id, *reinterpret_cast <const int*> (entry->value));
                     break;
                 case Vector4:
-                    glUniform4fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec4*> ((*cur)->value)));
+                    glUniform4fv (entry->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec4*> (entry->value)));
                     break;
                 case Vector3:
-                    glUniform3fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec3*> ((*cur)->value)));
+                    glUniform3fv (entry->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec3*> (entry->value)));
                     break;
                 case Vector2:
-                    glUniform2fv ((*cur)->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec2*> ((*cur)->value)));
+                    glUniform2fv (entry->id, 1, glm::value_ptr (*reinterpret_cast <const glm::vec2*> (entry->value)));
                     break;
                 case Matrix4:
-                    glUniformMatrix4fv ((*cur)->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat4*> ((*cur)->value)));
+                    glUniformMatrix4fv (entry->id, 1, GL_FALSE, glm::value_ptr (*reinterpret_cast <const glm::mat4*> (entry->value)));
                     break;
             }
         }
@@ -291,6 +330,7 @@ void CPass::setupUniforms ()
     this->addUniform ("g_Texture7", 7);
     // register all the texture sizes required
     this->addUniform ("g_Texture0Resolution", this->m_material->getImage ()->getTexture ()->getResolution ());
+    int lastTextureIndex = 0;
     // register the extra texture resolutions
     {
         auto cur = this->m_textures.begin ();
@@ -303,6 +343,43 @@ void CPass::setupUniforms ()
             namestream << "g_Texture" << index << "Resolution";
 
             this->addUniform (namestream.str (), (*cur)->getResolution ());
+            lastTextureIndex ++;
+        }
+    }
+
+    // registers the extra texture resolutions from the shader
+    {
+        auto cur = this->m_fragShader->getTextures ().begin ();
+        auto end = this->m_fragShader->getTextures ().end ();
+
+        for (; cur != end; cur ++)
+        {
+            if ((*cur).first <= lastTextureIndex)
+                continue;
+
+            std::ostringstream namestream;
+
+            namestream << "g_Texture" << (*cur).first << "Resolution";
+
+            this->addUniform (namestream.str (), (*cur).second->getResolution ());
+        }
+    }
+
+    // registers the extra texture resolutions from the shader
+    {
+        auto cur = this->m_vertShader->getTextures ().begin ();
+        auto end = this->m_vertShader->getTextures ().end ();
+
+        for (; cur != end; cur ++)
+        {
+            if ((*cur).first <= lastTextureIndex)
+                continue;
+
+            std::ostringstream namestream;
+
+            namestream << "g_Texture" << (*cur).first << "Resolution";
+
+            this->addUniform (namestream.str (), (*cur).second->getResolution ());
         }
     }
 
@@ -340,8 +417,8 @@ void CPass::addUniform (const std::string& name, UniformType type, T value)
     T* newValue = new T (value);
 
     // uniform found, add it to the list
-    this->m_uniforms.emplace_back (
-        new UniformEntry (id, name, type, newValue)
+    this->m_uniforms.insert (
+        std::make_pair (name, new UniformEntry (id, name, type, newValue))
     );
 }
 
@@ -356,8 +433,8 @@ void CPass::addUniform (const std::string& name, UniformType type, T* value)
         return;
 
     // uniform found, add it to the list
-    this->m_uniforms.emplace_back (
-        new UniformEntry (id, name, type, value)
+    this->m_uniforms.insert (
+        std::make_pair (name, new UniformEntry (id, name, type, value))
     );
 }
 
@@ -385,41 +462,83 @@ void CPass::setupTextures ()
 
 void CPass::setupShaderVariables ()
 {
-    // find variables in the shaders and set the value with the constants if possible
-    auto cur = this->m_pass->getConstants ().begin ();
-    auto end = this->m_pass->getConstants ().end ();
-
-    for (; cur != end; cur ++)
     {
-        CShaderVariable* vertexVar = this->m_vertShader->findParameter ((*cur).first);
-        CShaderVariable* pixelVar = this->m_fragShader->findParameter ((*cur).first);
+        // find variables in the shaders and set the value with the constants if possible
+        auto cur = this->m_pass->getConstants ().begin ();
+        auto end = this->m_pass->getConstants ().end ();
 
-        // variable not found, can be ignored
-        if (vertexVar == nullptr && pixelVar == nullptr)
-            continue;
+        for (; cur != end; cur ++)
+        {
+            CShaderVariable* vertexVar = this->m_vertShader->findParameter ((*cur).first);
+            CShaderVariable* pixelVar = this->m_fragShader->findParameter ((*cur).first);
+
+            // variable not found, can be ignored
+            if (vertexVar == nullptr && pixelVar == nullptr)
+                continue;
 
-        // if both can be found, ensure they're the correct type
-        if (vertexVar != nullptr && pixelVar != nullptr)
+            // if both can be found, ensure they're the correct type
+            if (vertexVar != nullptr && pixelVar != nullptr)
+            {
+                if (vertexVar->getType () != pixelVar->getType ())
+                    throw std::runtime_error ("Pixel and vertex shader variable types do not match");
+            }
+
+            // get one instance of it
+            CShaderVariable* var = vertexVar == nullptr ? pixelVar : vertexVar;
+
+            // ensure the shader's and the constant are of the same type
+            // TODO: CHECK THIS, THERE'S SOME BACKGROUNDS WHERE THIS HAPPENS :/
+            /*if ((*cur).second->getType () != var->getType ())
+                throw std::runtime_error ("Constant and pixel/vertex variable are not of the same type");*/
+
+            // now determine the constant's type and register the correct uniform for it
+            if ((*cur).second->is <CShaderConstantFloat> ())
+                this->addUniform (var->getName (), (*cur).second->as <CShaderConstantFloat> ()->getValue ());
+            else if ((*cur).second->is <CShaderConstantInteger> ())
+                this->addUniform (var->getName (), (*cur).second->as <CShaderConstantInteger> ()->getValue ());
+            else if ((*cur).second->is <CShaderConstantVector3> ())
+                this->addUniform (var->getName (), (*cur).second->as <CShaderConstantVector3> ()->getValue ());
+        }
+    }
+
+    {
+        auto cur = this->m_vertShader->getParameters ().begin ();
+        auto end = this->m_vertShader->getParameters ().end ();
+
+        for (; cur != end; cur ++)
         {
-            if (vertexVar->getType () != pixelVar->getType ())
-                throw std::runtime_error ("Pixel and vertex shader variable types do not match");
+            if (this->m_uniforms.find ((*cur)->getName ()) != this->m_uniforms.end ())
+                continue;
+
+            if ((*cur)->is <CShaderVariableFloat> ())
+                this->addUniform ((*cur)->getName (), const_cast <float*> (reinterpret_cast <const float*> ((*cur)->as <CShaderVariableFloat> ()->getValue ())));
+            else if ((*cur)->is <CShaderVariableInteger> ())
+                this->addUniform ((*cur)->getName (), const_cast <int*> (reinterpret_cast <const int*> ((*cur)->as <CShaderVariableInteger> ()->getValue ())));
+            else if ((*cur)->is <CShaderVariableVector3> ())
+                this->addUniform ((*cur)->getName (), const_cast <glm::vec3*> (reinterpret_cast <const glm::vec3*> ((*cur)->as <CShaderVariableVector3> ()->getValue ())));
+            else if ((*cur)->is <CShaderVariableVector4> ())
+                this->addUniform ((*cur)->getName (), const_cast <glm::vec4*> (reinterpret_cast <const glm::vec4*> ((*cur)->as <CShaderVariableVector4> ()->getValue ())));
         }
+    }
+
+    {
+        auto cur = this->m_fragShader->getParameters ().begin ();
+        auto end = this->m_fragShader->getParameters ().end ();
 
-        // get one instance of it
-        CShaderVariable* var = vertexVar == nullptr ? pixelVar : vertexVar;
-
-        // ensure the shader's and the constant are of the same type
-        // TODO: CHECK THIS, THERE'S SOME BACKGROUNDS WHERE THIS HAPPENS :/
-        /*if ((*cur).second->getType () != var->getType ())
-            throw std::runtime_error ("Constant and pixel/vertex variable are not of the same type");*/
-
-        // now determine the constant's type and register the correct uniform for it
-        if ((*cur).second->is <CShaderConstantFloat> ())
-            this->addUniform (var->getName (), (*cur).second->as <CShaderConstantFloat> ()->getValue ());
-        else if ((*cur).second->is <CShaderConstantInteger> ())
-            this->addUniform (var->getName (), (*cur).second->as <CShaderConstantInteger> ()->getValue ());
-        else if ((*cur).second->is <CShaderConstantVector3> ())
-            this->addUniform (var->getName (), (*cur).second->as <CShaderConstantVector3> ()->getValue ());
+        for (; cur != end; cur ++)
+        {
+            if (this->m_uniforms.find ((*cur)->getName ()) != this->m_uniforms.end ())
+                continue;
+
+            if ((*cur)->is <CShaderVariableFloat> ())
+                this->addUniform ((*cur)->getName (), const_cast <float*> (reinterpret_cast <const float*> ((*cur)->as <CShaderVariableFloat> ()->getValue ())));
+            else if ((*cur)->is <CShaderVariableInteger> ())
+                this->addUniform ((*cur)->getName (), const_cast <int*> (reinterpret_cast <const int*> ((*cur)->as <CShaderVariableInteger> ()->getValue ())));
+            else if ((*cur)->is <CShaderVariableVector3> ())
+                this->addUniform ((*cur)->getName (), const_cast <glm::vec3*> (reinterpret_cast <const glm::vec3*> ((*cur)->as <CShaderVariableVector3> ()->getValue ())));
+            else if ((*cur)->is <CShaderVariableVector4> ())
+                this->addUniform ((*cur)->getName (), const_cast <glm::vec4*> (reinterpret_cast <const glm::vec4*> ((*cur)->as <CShaderVariableVector4> ()->getValue ())));
+        }
     }
 }
 

+ 1 - 1
src/WallpaperEngine/Render/Objects/Effects/CPass.h

@@ -87,7 +87,7 @@ namespace WallpaperEngine::Render::Objects::Effects
         Core::Objects::Images::Materials::CPass* m_pass;
         std::vector<CTexture*> m_textures;
         std::vector<AttribEntry*> m_attribs;
-        std::vector<UniformEntry*> m_uniforms;
+        std::map<std::string, UniformEntry*> m_uniforms;
         glm::mat4 m_modelViewProjectionMatrix;
 
         Render::Shaders::Compiler* m_fragShader;

+ 22 - 2
src/WallpaperEngine/Render/Shaders/Compiler.cpp

@@ -471,7 +471,7 @@ namespace WallpaperEngine::Render::Shaders
 
         finalCode += this->m_compiledContent;
 
-        if (this->m_recursive == false)
+        if (DEBUG && this->m_recursive == false)
         {
             if (this->m_type == Type_Vertex)
                 std::cout << "======================== COMPILED VERTEX SHADER " << this->m_file.c_str () << " ========================" << std::endl;
@@ -545,7 +545,7 @@ namespace WallpaperEngine::Render::Shaders
         if (type == "vec4")
         {
             parameter = new Variables::CShaderVariableVector4 (
-                WallpaperEngine::Core::aToVector3 (*defvalue)
+                WallpaperEngine::Core::aToVector4 (*defvalue)
             );
         }
         else if (type == "vec3")
@@ -593,12 +593,27 @@ namespace WallpaperEngine::Render::Shaders
             // samplers can have special requirements, check what sampler we're working with and create definitions
             // if needed
             auto combo = data.find ("combo");
+            auto textureName = data.find ("default");
 
             if (combo != data.end ())
             {
                 // 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);
+
+                // extract the texture number from the name
+                char value = name.at (std::string("g_Texture").length ());
+                // now convert it to integer
+                int index = value - '0';
+
+                this->m_textures.insert (
+                    std::make_pair (index, texture)
+                );
             }
 
             // samplers are not saved, we can ignore them for now
@@ -643,6 +658,11 @@ namespace WallpaperEngine::Render::Shaders
         return this->m_combos;
     }
 
+    const std::map <int, CTexture*>& Compiler::getTextures () const
+    {
+        return this->m_textures;
+    }
+
     std::vector<std::string> Compiler::sTypes =
     {
         "vec4", "vec3", "vec2", "float", "sampler2D", "mat4"

+ 9 - 0
src/WallpaperEngine/Render/Shaders/Compiler.h

@@ -6,6 +6,7 @@
 
 #include "WallpaperEngine/Core/Core.h"
 #include "WallpaperEngine/Assets/CContainer.h"
+#include "WallpaperEngine/Assets/CTexture.h"
 #include "WallpaperEngine/FileSystem/FileSystem.h"
 #include "WallpaperEngine/Core/Objects/Effects/Constants/CShaderConstant.h"
 #include "WallpaperEngine/Render/Shaders/Variables/CShaderVariable.h"
@@ -85,6 +86,10 @@ namespace WallpaperEngine::Render::Shaders
          * @return The list of combos available for this shader after compilation
          */
         const std::map <std::string, int>& getCombos () const;
+        /**
+         * @return The list of textures inferred from the shader's code
+         */
+        const std::map <int, CTexture*>& getTextures () const;
 
     private:
         /**
@@ -236,5 +241,9 @@ namespace WallpaperEngine::Render::Shaders
           * The container to load files from
           */
          CContainer* m_container;
+         /**
+          * List of textures that the shader expects (inferred from sampler2D and it's JSON data)
+          */
+         std::map<int, CTexture*> m_textures;
     };
 }