Explorar o código

~ fix videos not being rendered properly
~ fix some combos not having the correct casing for shaders

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

Alexis Maiquez %!s(int64=5) %!d(string=hai) anos
pai
achega
93456940e3

+ 4 - 1
src/WallpaperEngine/Core/Objects/Images/Materials/CPass.cpp

@@ -92,7 +92,10 @@ void CPass::setTexture (int index, const std::string& texture)
 
 void CPass::insertCombo (const std::string& name, int value)
 {
-    this->m_combos.insert (std::pair <std::string, int> (name, value));
+    std::string uppercase = std::string (name);
+
+    std::transform (uppercase.begin (), uppercase.end (), uppercase.begin (), ::toupper);
+    this->m_combos.insert (std::pair <std::string, int> (uppercase, value));
 }
 
 const std::vector<std::string>& CPass::getTextures () const

+ 2 - 0
src/WallpaperEngine/Render/CScene.cpp

@@ -38,6 +38,8 @@ CScene::CScene (Core::CScene* scene, CContainer* container) :
         if (object != nullptr)
             this->m_objects.emplace_back (object);
     }
+
+    this->setupFramebuffers ();
 }
 
 CCamera* CScene::getCamera () const

+ 19 - 6
src/WallpaperEngine/Render/CVideo.cpp

@@ -63,12 +63,12 @@ CVideo::CVideo (Core::CVideo* video, CContainer* container) :
 
     // inverted positions so the final texture is rendered properly
     GLfloat position [] = {
-        -1.0f, 1.0f, 0.0f,
-        1.0, 1.0f, 0.0f,
-        -1.0f, -1.0f, 0.0f,
-        -1.0f, -1.0f, 0.0f,
+        1.0f, -1.0f, 0.0f,
+        -1.0, -1.0f, 0.0f,
+        1.0f, 1.0f, 0.0f,
         1.0f, 1.0f, 0.0f,
-        1.0f, -1.0f, 0.0f
+        -1.0f, -1.0f, 0.0f,
+        -1.0f, 1.0f, 0.0f
     };
 
     glGenBuffers (1, &this->m_texCoordBuffer);
@@ -92,6 +92,7 @@ CVideo::CVideo (Core::CVideo* video, CContainer* container) :
     glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, m_codecCtx->width, m_codecCtx->height, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr);
 
     this->setupShaders ();
+    this->setupFramebuffers ();
 }
 
 void CVideo::setSize (int width, int height)
@@ -121,9 +122,11 @@ void CVideo::renderFrame ()
     getNextFrame ();
     writeFrameToImage ();
 
+    glViewport (0, 0, this->getWidth (), this->getHeight ());
+    
     // do the actual rendering
     // write to default's framebuffer
-    glBindFramebuffer (GL_FRAMEBUFFER, GL_NONE);
+    glBindFramebuffer (GL_FRAMEBUFFER, this->getWallpaperFramebuffer());
 
     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     glDisable (GL_BLEND);
@@ -333,4 +336,14 @@ void CVideo::setupShaders ()
     this->a_TexCoord = glGetAttribLocation (this->m_shader, "a_TexCoord");
 }
 
+int CVideo::getWidth ()
+{
+    return this->m_codecCtx->width;
+}
+
+int CVideo::getHeight ()
+{
+    return this->m_codecCtx->height;
+}
+
 const std::string CVideo::Type = "video";

+ 3 - 0
src/WallpaperEngine/Render/CVideo.h

@@ -21,6 +21,9 @@ namespace WallpaperEngine::Render
 
         Core::CVideo* getVideo ();
 
+        int getWidth ();
+        int getHeight ();
+
     protected:
         void renderFrame () override;
 

+ 16 - 12
src/WallpaperEngine/Render/CWallpaper.cpp

@@ -1,5 +1,6 @@
 #include "CWallpaper.h"
 #include "CScene.h"
+#include "CVideo.h"
 
 #include <utility>
 #include <glm/glm.hpp>
@@ -12,7 +13,6 @@ CWallpaper::CWallpaper (Core::CWallpaper* wallpaperData, std::string type, CCont
     m_wallpaperData (wallpaperData),
     m_type (std::move(type))
 {
-    this->setupFramebuffers ();
     this->setupShaders ();
 
     GLfloat texCoords [] = {
@@ -199,7 +199,14 @@ void CWallpaper::render (glm::vec4 viewport, bool newFrame)
         windowWidth = projection->getWidth ();
         windowHeight = projection->getHeight ();
     }
-    // TODO: SUPPORT VIDEO
+    else if (this->is <WallpaperEngine::Render::CVideo> ())
+    {
+        auto video = this->as <WallpaperEngine::Render::CVideo> ();
+
+        windowWidth = video->getWidth ();
+        windowHeight = video->getHeight ();
+    }
+
     float widthRatio = windowWidth / viewport.z;
     float heightRatio = windowHeight / viewport.w;
 
@@ -250,15 +257,6 @@ void CWallpaper::render (glm::vec4 viewport, bool newFrame)
     glBindBuffer (GL_ARRAY_BUFFER, this->m_positionBuffer);
     glBufferData (GL_ARRAY_BUFFER, sizeof (position), position, GL_STATIC_DRAW);
 
-    /*
-        -1.0f, 1.0f, 0.0f,
-        1.0, 1.0f, 0.0f,
-        -1.0f, -1.0f, 0.0f,
-        -1.0f, -1.0f, 0.0f,
-        1.0f, 1.0f, 0.0f,
-        1.0f, -1.0f, 0.0f
-     */
-
     glViewport (viewport.x, viewport.y, viewport.z, viewport.w);
 
     // write to default's framebuffer
@@ -319,7 +317,13 @@ void CWallpaper::createFramebuffer (GLuint* framebuffer, GLuint* depthbuffer, GL
         windowWidth = projection->getWidth ();
         windowHeight = projection->getHeight ();
     }
-    // TODO: SUPPORT VIDEO
+    else if (this->is <WallpaperEngine::Render::CVideo> ())
+    {
+        auto video = this->as <WallpaperEngine::Render::CVideo> ();
+
+        windowWidth = video->getWidth ();
+        windowHeight = video->getHeight ();
+    }
 
     GLenum drawBuffers [1] = {GL_COLOR_ATTACHMENT0};
     // create the main framebuffer

+ 5 - 5
src/WallpaperEngine/Render/CWallpaper.h

@@ -62,6 +62,11 @@ namespace WallpaperEngine::Render
          */
         virtual void renderFrame () = 0;
 
+        /**
+         * Setups OpenGL's framebuffers for ping-pong and scene rendering
+         */
+        void setupFramebuffers ();
+
         void createFramebuffer (GLuint* framebuffer, GLuint* depthbuffer, GLuint* texture);
 
         CContainer* m_container;
@@ -117,11 +122,6 @@ namespace WallpaperEngine::Render
         GLint g_Texture0;
         GLint a_Position;
         GLint a_TexCoord;
-
-        /**
-         * Setups OpenGL's framebuffers for ping-pong and scene rendering
-         */
-        void setupFramebuffers ();
         /**
          * Setups OpenGL's shaders for this wallpaper backbuffer
          */