فهرست منبع

Simplified image rendering code a bit so it's easier to follow
Improved detection of macros for shaders

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

Alexis Maiquez 3 سال پیش
والد
کامیت
cb6f05ff27

+ 19 - 53
src/WallpaperEngine/Render/Objects/CImage.cpp

@@ -216,12 +216,6 @@ void CImage::setup ()
     if (this->m_initialized)
         return;
 
-    // generate the main material used to copy the image to the correct texture
-    this->m_copyMaterial = new Effects::CMaterial (
-        new CEffect (this, new Core::Objects::CEffect ("", "", "", "", this->m_image)),
-        this->m_image->getMaterial ()
-    );
-
     // generate the main material used to render the image
     this->m_material = new Effects::CMaterial (
         new CEffect (this, new Core::Objects::CEffect ("", "", "", "", this->m_image)),
@@ -267,27 +261,14 @@ void CImage::pinpongFramebuffer (CFBO** drawTo, ITexture** asInput)
 
 void CImage::simpleRender ()
 {
-    ITexture* input = this->m_mainFBO;
-
-    // FIXME: THIS IS A QUICK HACK FOR ANIMATED IMAGES, IF ANY OF THOSE HAVE ANY EFFECT ON THEM THIS WILL LIKELY BREAK
-    if (this->getTexture ()->isAnimated () == true)
-    {
-        input = this->getTexture ();
-    }
-    else
-    {
-        // first render to the composite layer
-        auto cur = this->m_copyMaterial->getPasses ().begin ();
-        auto end = this->m_copyMaterial->getPasses ().end ();
-
-        for (; cur != end; cur ++)
-            (*cur)->render (this->m_mainFBO, this->getTexture (), *this->getCopySpacePosition (), *this->getTexCoordCopy (), this->m_modelViewProjectionPass);
-    }
+    ITexture* input = this->getTexture ();
 
     // a simple material renders directly to the screen
     auto cur = this->m_material->getPasses ().begin ();
     auto end = this->m_material->getPasses ().end ();
 
+    glColorMask (true, true, true, false);
+
     for (; cur != end; cur ++)
         (*cur)->render (this->getScene ()->getFBO (), input, *this->getSceneSpacePosition (), *this->getTexCoordPass (), this->m_modelViewProjectionScreen);
 }
@@ -295,16 +276,9 @@ void CImage::simpleRender ()
 void CImage::complexRender ()
 {
     // start drawing to the main framebuffer
-    CFBO* drawTo = this->m_mainFBO;
+    CFBO* drawTo = this->m_currentMainFBO;
     ITexture* asInput = this->getTexture ();
 
-    // do the first pass render into the main framebuffer
-    auto cur = this->m_copyMaterial->getPasses ().begin ();
-    auto end = this->m_copyMaterial->getPasses ().end ();
-
-    for (; cur != end; cur ++)
-        (*cur)->render (drawTo, asInput, *this->getCopySpacePosition (), *this->getTexCoordCopy (), this->m_modelViewProjectionPass);
-
     // render all the other materials
     auto effectCur = this->getEffects ().begin ();
     auto effectEnd = this->getEffects ().end ();
@@ -316,14 +290,18 @@ void CImage::complexRender ()
 
         for (; materialCur != materialEnd; materialCur ++)
         {
+            CFBO* prevDrawTo = drawTo;
+            GLuint spacePosition = *this->getCopySpacePosition ();
+
             // set viewport and target texture if needed
             if ((*materialCur)->getMaterial ()->hasTarget () == true)
             {
                 // setup target texture
                 std::string target = (*materialCur)->getMaterial ()->getTarget ();
                 drawTo = (*effectCur)->findFBO (target);
+                spacePosition = *this->getPassSpacePosition ();
 
-                // not a local FBO, so try that one now
+                // not a local fbo, try to find a scene fbo with the same name
                 if (drawTo == nullptr)
                     // this one throws if no fbo was found
                     drawTo = this->getScene ()->findFBO (target);
@@ -334,32 +312,25 @@ void CImage::complexRender ()
 
             for (; passCur != passEnd; passCur ++)
             {
-                GLuint spacePosition = *this->getPassSpacePosition ();
-                glm::mat4 projection = this->m_modelViewProjectionPass;
+                (*passCur)->render (drawTo, asInput, spacePosition, *this->getTexCoordPass (), this->m_modelViewProjectionPass);
 
-                // ping-pong only if there's a target
                 if ((*materialCur)->getMaterial ()->hasTarget () == false)
-                {
                     this->pinpongFramebuffer (&drawTo, &asInput);
-                    spacePosition = *this->getCopySpacePosition ();
-                    projection = this->m_modelViewProjectionScreen;
-                }
-
-                (*passCur)->render (drawTo, asInput, spacePosition, *this->getTexCoordPass (), this->m_modelViewProjectionPass);
             }
+
+            if ((*materialCur)->getMaterial ()->hasTarget () == true)
+                drawTo = prevDrawTo;
         }
     }
 
+    // the render has to happen anyway unless it's visible as it might be used by other images
     if (this->getImage ()->isVisible () == false)
         return;
 
-    // pinpong the framebuffer so we know exactly what we're drawing to the scene
-    this->pinpongFramebuffer (&drawTo, &asInput);
-
     // final step, this one might need more changes, should passes render directly to the output instead of an intermediate framebuffer?
     // do the first pass render into the main framebuffer
-    cur = this->m_material->getPasses ().begin ();
-    end = this->m_material->getPasses ().end ();
+    auto cur = this->m_material->getPasses ().begin ();
+    auto end = this->m_material->getPasses ().end ();
 
     glColorMask (true, true, true, false);
 
@@ -373,17 +344,12 @@ void CImage::render ()
     if (this->m_initialized == false)
         return;
 
-    // first and foremost reset the framebuffer switching
-    this->m_currentMainFBO = this->m_mainFBO;
-    this->m_currentSubFBO = this->m_subFBO;
+    // reset the framebuffers so the drawing always happens on the same order
+    this->m_currentMainFBO = this->m_subFBO;
+    this->m_currentSubFBO = this->m_mainFBO;
 
     glColorMask (true, true, true, true);
 
-    // clear the main framebuffer
-    glBindFramebuffer (GL_FRAMEBUFFER, this->m_mainFBO->getFramebuffer ());
-    // attach the main texture
-    glClear (GL_COLOR_BUFFER_BIT);
-
     // check if there's more than one pass and do different things based on that
     if (this->m_effects.empty () == true)
         this->simpleRender ();

+ 0 - 1
src/WallpaperEngine/Render/Objects/CImage.h

@@ -80,7 +80,6 @@ namespace WallpaperEngine::Render::Objects
 
         std::vector<CEffect*> m_effects;
         Effects::CMaterial* m_material;
-        Effects::CMaterial* m_copyMaterial;
 
         double m_animationTime;
 

+ 18 - 1
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp

@@ -249,7 +249,7 @@ void CPass::render (CFBO* drawTo, ITexture* input, GLuint position, GLuint texco
     glBindBuffer (GL_ARRAY_BUFFER, position);
     glDrawArrays (GL_TRIANGLES, 0, 6);
 
-    // disable vertex attribs array
+    // disable vertex attribs array and textures
     {
         auto cur = this->m_attribs.begin ();
         auto end = this->m_attribs.end ();
@@ -257,6 +257,23 @@ void CPass::render (CFBO* drawTo, ITexture* input, GLuint position, GLuint texco
         for (; cur != end; cur ++)
             glDisableVertexAttribArray ((*cur)->id);
     }
+
+    // unbind all the used textures
+    glActiveTexture (GL_TEXTURE0);
+    glBindTexture (GL_TEXTURE_2D, 0);
+
+    // continue on the map from the second texture
+    if (this->m_finalTextures.empty () == false)
+    {
+        auto cur = this->m_finalTextures.begin ();
+        auto end = this->m_finalTextures.end ();
+
+        for (; cur != end; cur ++)
+        {
+            glActiveTexture (GL_TEXTURE0 + (*cur).first);
+            glBindTexture (GL_TEXTURE_2D, 0);
+        }
+    }
 }
 
 GLuint CPass::compileShader (Render::Shaders::Compiler* shader, GLuint type)

+ 7 - 3
src/WallpaperEngine/Render/Shaders/Compiler.cpp

@@ -689,6 +689,11 @@ namespace WallpaperEngine::Render::Shaders
         }
         else if (type == "sampler2D")
         {
+            if (this->m_file.find ("effects/blur_combine") != std::string::npos)
+            {
+                int i = 0;
+            }
+
             // samplers can have special requirements, check what sampler we're working with and create definitions
             // if needed
             auto combo = data.find ("combo");
@@ -700,9 +705,8 @@ namespace WallpaperEngine::Render::Shaders
 
             if (combo != data.end ())
             {
-
-                // if the texture exists, add the combo
-                if (this->m_passTextures.size () > index)
+                // if the texture exists (and is not null), add to the combo
+                if (this->m_passTextures.size () > index && (this->m_passTextures.at (index) != "" || textureName != data.end ()))
                 {
                     // add the new combo to the list
                     this->m_combos->insert (std::make_pair <std::string, int> (*combo, 1));