Преглед изворни кода

removed stale todos, texture labels and slot index fixed, malformed #includes are now guarded

UwU пре 5 дана
родитељ
комит
d62bef19c7

+ 0 - 1
src/WallpaperEngine/Audio/AudioStream.cpp

@@ -43,7 +43,6 @@ int audio_read_thread (void* arg) {
 	    continue;
 	}
 
-	// TODO: PROPERLY IMPLEMENT THIS
 	if (packet->stream_index == stream->getAudioStream ()) {
 	    stream->queuePacket (packet);
 	} else {

+ 0 - 2
src/WallpaperEngine/Data/Parsers/EffectParser.cpp

@@ -57,8 +57,6 @@ std::vector<EffectPassUniquePtr> EffectParser::parseEffectPasses (const JSON& it
 	const auto command = cur.optional ("command");
 	const auto material = cur.optional ("material");
 
-	// TODO: can target be set if material is set?
-
 	result.push_back (
 	    std::make_unique<EffectPass> (EffectPass {
 		.material = material.has_value () ? MaterialParser::load (project, *material)

+ 12 - 1
src/WallpaperEngine/Render/CTexture.cpp

@@ -111,6 +111,18 @@ CTexture::CTexture (RenderContext& context, TextureUniquePtr header) :
     }
 }
 
+void CTexture::label (const std::string& name) const {
+#if !NDEBUG
+    const bool video = this->m_header->isVideoMp4 || this->m_header->flags & TextureFlags_Video;
+    const uint32_t count = video ? 1 : this->m_header->imageCount;
+
+    for (uint32_t i = 0; i < count; i++) {
+	const std::string text = count == 1 ? name : name + " [" + std::to_string (i) + "]";
+	glObjectLabel (GL_TEXTURE, this->m_textureID[i], -1, text.c_str ());
+    }
+#endif /* DEBUG */
+}
+
 CTexture::~CTexture () {
     // release the player first so nothing else keeps using it via null references
     this->m_player.reset ();
@@ -166,7 +178,6 @@ GLint CTexture::setupInternalFormat () const {
 }
 
 void CTexture::setupOpenGLParameters (const uint32_t textureID) const {
-    // TODO: label elements too
     glBindTexture (GL_TEXTURE_2D, this->m_textureID[textureID]);
 
     glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);

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

@@ -11,6 +11,7 @@
 #include <mpv/client.h>
 #include <mpv/render.h>
 #include <mpv/render_gl.h>
+#include <string>
 #include <vector>
 
 namespace WallpaperEngine::Render {
@@ -47,6 +48,8 @@ public:
     void update () const override;
     bool isReady () const override;
     [[nodiscard]] GLPlayer* getPlayer () const override { return this->m_player.get (); }
+    /** Debug label for every image of the texture, shows up in renderdoc/apitrace */
+    void label (const std::string& name) const;
 
 private:
     [[nodiscard]] const Texture& getHeader () const;

+ 0 - 2
src/WallpaperEngine/Render/Objects/CImage.cpp

@@ -1833,8 +1833,6 @@ void CImage::addEffectPasses (const ImageEffect& effect) {
 	);
     }
 
-    // TODO: MAKE USE OF ZIP OPERATOR IN BOOST? WAY OVERKILL JUST FOR THIS...
-
     auto curEffect = effect.effect->passes.begin ();
     auto endEffect = effect.effect->passes.end ();
     auto curOverride = effect.passOverrides.begin ();

+ 53 - 17
src/WallpaperEngine/Render/Shaders/ShaderUnit.cpp

@@ -2,8 +2,10 @@
 
 #include "WallpaperEngine/Logging/Log.h"
 #include <cctype>
+#include <charconv>
 #include <exception>
 #include <mutex>
+#include <optional>
 #include <regex>
 #include <stack>
 #include <string>
@@ -64,6 +66,26 @@ using namespace WallpaperEngine::Render;
 using namespace WallpaperEngine::Data::Builders;
 using namespace WallpaperEngine::Render::Shaders;
 
+namespace {
+// the quoted filename of the #include at start, or nothing if the quotes aren't on the same line
+std::optional<std::string> includeFilename (const std::string& source, const size_t start) {
+    const size_t lineEnd = std::min (source.find ('\n', start), source.size ());
+    const size_t quoteStart = source.find ('"', start);
+
+    if (quoteStart >= lineEnd) {
+	return std::nullopt;
+    }
+
+    const size_t quoteEnd = source.find ('"', quoteStart + 1);
+
+    if (quoteEnd >= lineEnd) {
+	return std::nullopt;
+    }
+
+    return source.substr (quoteStart + 1, quoteEnd - quoteStart - 1);
+}
+} // namespace
+
 ShaderUnit::ShaderUnit (
     const GLSLContext::UnitType type, std::string file, std::string content, const AssetLocator& assetLocator,
     const ShaderConstantMap& constants, const TextureMap& passTextures, const TextureMap& overrideTextures,
@@ -135,10 +157,18 @@ void ShaderUnit::preprocessVariables () {
 void ShaderUnit::preprocessIncludes () {
     size_t start = 0, end = 0;
     while ((start = this->m_preprocessed.find ("#include", end)) != std::string::npos) {
-	// TODO: CHECK FOR ERRORS HERE, MALFORMED INCLUDES WILL NOT BE PROPERLY HANDLED
-	const size_t quoteStart = this->m_preprocessed.find_first_of ('"', start) + 1;
-	const size_t quoteEnd = this->m_preprocessed.find_first_of ('"', quoteStart);
-	const std::string filename = this->m_preprocessed.substr (quoteStart, quoteEnd - quoteStart);
+	const auto parsed = includeFilename (this->m_preprocessed, start);
+
+	// comment out just the "#i" so the string length/offsets are unaffected
+	this->m_preprocessed = this->m_preprocessed.replace (start, 2, "//");
+	end = start;
+
+	if (!parsed.has_value ()) {
+	    sLog.error ("Malformed #include directive in shader ", this->m_file);
+	    continue;
+	}
+
+	const std::string& filename = *parsed;
 
 	// a missing include isn't necessarily an error - it may come from commented-out content
 	std::string content;
@@ -157,12 +187,7 @@ void ShaderUnit::preprocessIncludes () {
 	    content += " but was not found\n";
 	}
 
-	// comment out just the "#i" so the string length/offsets are unaffected
-	this->m_preprocessed = this->m_preprocessed.replace (start, 2, "//");
-
 	this->m_includes += content;
-
-	end = start;
     }
 
     // resolve #include directives found inside already-included content too
@@ -170,10 +195,16 @@ void ShaderUnit::preprocessIncludes () {
 
     while ((start = this->m_includes.find ("#include", end)) != std::string::npos) {
 	const size_t lineEnd = this->m_includes.find_first_of ('\n', start);
-	// TODO: CHECK FOR ERRORS HERE, MALFORMED INCLUDES WILL NOT BE PROPERLY HANDLED
-	const size_t quoteStart = this->m_includes.find_first_of ('"', start) + 1;
-	const size_t quoteEnd = this->m_includes.find_first_of ('"', quoteStart);
-	const std::string filename = this->m_includes.substr (quoteStart, quoteEnd - quoteStart);
+	const auto parsed = includeFilename (this->m_includes, start);
+	end = start;
+
+	if (!parsed.has_value ()) {
+	    sLog.error ("Malformed #include directive in an include of shader ", this->m_file);
+	    this->m_includes = this->m_includes.replace (start, 2, "//");
+	    continue;
+	}
+
+	const std::string& filename = *parsed;
 
 	// a missing include isn't necessarily an error - it may come from commented-out content
 	std::string content;
@@ -193,7 +224,6 @@ void ShaderUnit::preprocessIncludes () {
 	}
 
 	this->m_includes = this->m_includes.replace (start, lineEnd - start, content);
-	end = start;
     }
 
     // place the accumulated include contents right before the main function
@@ -802,11 +832,17 @@ void ShaderUnit::parseParameterConfiguration (
     } else if (type == "sampler2D" || type == "sampler2DComparison") {
 	const auto textureName = data.find ("default");
 	// TODO: CREATE TEXTURE WITH THE GIVEN COLOR
-	const char value = name.at (std::string ("g_Texture").length ());
 	const auto requireany = data.find ("requireany");
 	const auto require = data.find ("require");
-	// TODO: BETTER CONVERSION HERE
-	size_t index = value - '0';
+	constexpr std::string_view prefix = "g_Texture";
+	size_t index = 0;
+	const char* digits = name.data () + std::min (name.size (), prefix.size ());
+	const char* nameEnd = name.data () + name.size ();
+
+	if (!name.starts_with (prefix) || std::from_chars (digits, nameEnd, index).ptr != nameEnd) {
+	    sLog.error ("Cannot determine texture slot for ", name, " in shader ", this->m_file);
+	    return;
+	}
 	// TODO: SUPPORT USER TEXTURES!!
 
 	if (combo != data.end ()) {

+ 1 - 4
src/WallpaperEngine/Render/TextureCache.cpp

@@ -258,10 +258,7 @@ std::shared_ptr<const TextureProvider> TextureCache::resolve (const std::string&
 	    parsedTexture = buildRawTexture (filename, *raw);
 	}
 	auto texture = std::make_shared<CTexture> (this->getContext (), std::move (parsedTexture));
-
-#if !NDEBUG
-	glObjectLabel (GL_TEXTURE, texture->getTextureID (0), -1, filename.c_str ());
-#endif
+	texture->label (filename);
 
 	this->m_textureCache.insert_or_assign (key, texture);
 

+ 0 - 1
src/WallpaperEngine/Render/Wallpapers/CScene.cpp

@@ -60,7 +60,6 @@ CScene::CScene (
 	this->expandCanvasToContent (*scene, width, height, canvasWidth, canvasHeight);
     }
 
-    // TODO: CONVERSION
     this->m_camera->setOrthogonalProjection (width, height, canvasWidth, canvasHeight);
 
     // needed before scene setup below, which creates FBOs

+ 0 - 1
src/WallpaperEngine/WebBrowser/CEF/BrowserApp.cpp

@@ -40,7 +40,6 @@ void BrowserApp::OnBeforeCommandLineProcessing (const CefString& process_type, C
     command_line->AppendSwitch ("--disable-breakpad");
     command_line->AppendSwitch ("--disable-field-trial-config");
     command_line->AppendSwitch ("--no-experiments");
-    // TODO: activate mock-keychain switch for process_type.empty() if we ever support macOS
 }
 
 void BrowserApp::OnBeforeChildProcessLaunch (CefRefPtr<CefCommandLine> command_line) {