Jelajahi Sumber

Added some object labels in opengl so they're reflected on RenderDoc while on debug

Signed-off-by: Alexis Maiquez <almamu@almamu.com>
Alexis Maiquez 3 tahun lalu
induk
melakukan
261bc696df

+ 3 - 0
main.cpp

@@ -132,6 +132,9 @@ void initGLFW ()
     glfwWindowHint (GLFW_SAMPLES, 4);
     glfwWindowHint (GLFW_CONTEXT_VERSION_MAJOR, 2);
     glfwWindowHint (GLFW_CONTEXT_VERSION_MINOR, 1);
+
+    if (DEBUG)
+        glfwWindowHint (GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
 }
 
 void addPkg (CCombinedContainer* containers, const std::string& path, std::string pkgfile)

+ 6 - 1
src/WallpaperEngine/Assets/CContainer.cpp

@@ -13,7 +13,12 @@ ITexture* CContainer::readTexture (std::string filename)
 
     void* textureContents = this->readFile (filename, nullptr);
 
-    return new CTexture (textureContents);
+    ITexture* result = new CTexture (textureContents);
+
+    if (DEBUG)
+        glObjectLabel (GL_TEXTURE, result->getTextureID (), -1, filename.c_str ());
+
+    return result;
 }
 
 std::string CContainer::readVertexShader (const std::string& filename)

+ 4 - 0
src/WallpaperEngine/Render/CFBO.cpp

@@ -26,6 +26,10 @@ CFBO::CFBO (
     glBindTexture (GL_TEXTURE_2D, this->m_texture);
     // give OpenGL an empty image
     glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA8, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
+    // label stuff for debugging
+    if (DEBUG)
+        glObjectLabel (GL_TEXTURE, this->m_texture, -1, this->m_name.c_str ());
+
     // set filtering parameters, otherwise the texture is not rendered
     if (flags & TextureFlags::ClampUVs)
     {

+ 15 - 0
src/WallpaperEngine/Render/Objects/Effects/CPass.cpp

@@ -242,6 +242,14 @@ void CPass::render (CFBO* drawTo, ITexture* input, GLuint position, GLuint texco
             glEnableVertexAttribArray ((*cur)->id);
             glBindBuffer (GL_ARRAY_BUFFER, *(*cur)->value);
             glVertexAttribPointer ((*cur)->id, (*cur)->elements, (*cur)->type, GL_FALSE, 0, nullptr);
+
+            if (DEBUG)
+                glObjectLabel (GL_BUFFER, *(*cur)->value, -1, (
+                        "Image " + std::to_string (this->getMaterial ()->getImage ()->getId ()) +
+                        " Pass " + this->m_pass->getShader() +
+                        " " + (*cur)->name
+                    ).c_str ()
+                );
         }
     }
 
@@ -391,6 +399,13 @@ void CPass::setupShaders ()
         throw std::runtime_error (message);
     }
 
+    if (DEBUG)
+    {
+        glObjectLabel (GL_PROGRAM, this->m_programID, -1, this->m_pass->getShader ().c_str ());
+        glObjectLabel (GL_SHADER, vertexShaderID, -1, (this->m_pass->getShader () + ".vert").c_str ());
+        glObjectLabel (GL_SHADER, fragmentShaderID, -1, (this->m_pass->getShader () + ".frag").c_str ());
+    }
+
     // after being liked shaders can be dettached and deleted
     glDetachShader (this->m_programID, vertexShaderID);
     glDetachShader (this->m_programID, fragmentShaderID);