Skip to content

Commit 8f6215e

Browse files
committed
Use new Logging class for all output
1 parent 4613e24 commit 8f6215e

21 files changed

+228
-174
lines changed

src/libprojectM/MilkdropPreset/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# Debugging options, for development purposes.
2-
option(ENABLE_DEBUG_MILKDROP_PRESET "Enable STDERR debug output in Milkdrop preset code (Debug builds only)" OFF)
3-
41
set(SHADER_FILES
52
Shaders/Blur1FragmentShaderGlsl330.frag
63
Shaders/Blur2FragmentShaderGlsl330.frag
@@ -151,13 +148,6 @@ if(NOT BUILD_SHARED_LIBS)
151148
)
152149
endif()
153150

154-
if(ENABLE_DEBUG_MILKDROP_PRESET)
155-
target_compile_definitions(MilkdropPreset
156-
PRIVATE
157-
MILKDROP_PRESET_DEBUG=1
158-
)
159-
endif()
160-
161151
set_target_properties(MilkdropPreset PROPERTIES
162152
FOLDER libprojectM
163153
)

src/libprojectM/MilkdropPreset/FinalComposite.cpp

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@
22

33
#include "PresetState.hpp"
44

5+
#include <Logging.hpp>
56
#include <Renderer/BlendMode.hpp>
67

78
#include <cstddef>
89

9-
#ifdef MILKDROP_PRESET_DEBUG
10-
#include <iostream>
11-
#endif
12-
1310
namespace libprojectM {
1411
namespace MilkdropPreset {
1512

@@ -45,29 +42,21 @@ void FinalComposite::LoadCompositeShader(const PresetState& presetState)
4542
try
4643
{
4744
m_compositeShader->LoadCode(presetState.compositeShader);
48-
#ifdef MILKDROP_PRESET_DEBUG
49-
std::cerr << "[Composite Shader] Loaded composite shader code." << std::endl;
50-
#endif
45+
LOG_DEBUG("[FinalComposite] Successfully loaded composite shader code.");
5146
}
5247
catch (Renderer::ShaderException& ex)
5348
{
54-
#ifdef MILKDROP_PRESET_DEBUG
55-
std::cerr << "[Composite Shader] Error loading composite warp shader code:" << ex.message() << std::endl;
56-
std::cerr << "[Composite Shader] Using fallback shader." << std::endl;
57-
#else
58-
(void) ex; // silence unused parameter warning
59-
#endif
49+
LOG_WARN("[FinalComposite] Error loading composite warp shader code: " + ex.message() + " - Using fallback shader.");
50+
6051
// Fall back to default shader
6152
m_compositeShader = std::make_unique<MilkdropShader>(MilkdropShader::ShaderType::CompositeShader);
6253
m_compositeShader->LoadCode(defaultCompositeShader);
6354
}
6455
}
6556
else
6657
{
58+
LOG_DEBUG("[FinalComposite] No composite shader code in preset, loading default.");
6759
m_compositeShader->LoadCode(defaultCompositeShader);
68-
#ifdef MILKDROP_PRESET_DEBUG
69-
std::cerr << "[Composite Shader] Loaded default composite shader code." << std::endl;
70-
#endif
7160
}
7261
}
7362
else
@@ -91,18 +80,12 @@ void FinalComposite::CompileCompositeShader(PresetState& presetState)
9180
try
9281
{
9382
m_compositeShader->LoadTexturesAndCompile(presetState);
94-
#ifdef MILKDROP_PRESET_DEBUG
95-
std::cerr << "[Composite Shader] Successfully compiled composite shader code." << std::endl;
96-
#endif
83+
LOG_DEBUG("[FinalComposite] Successfully compiled composite shader code.");
9784
}
9885
catch (Renderer::ShaderException& ex)
9986
{
100-
#ifdef MILKDROP_PRESET_DEBUG
101-
std::cerr << "[Composite Shader] Error compiling composite warp shader code:" << ex.message() << std::endl;
102-
std::cerr << "[Composite Shader] Using fallback shader." << std::endl;
103-
#else
104-
(void) ex; // silence unused parameter warning
105-
#endif
87+
LOG_WARN("[FinalComposite] Error compiling composite warp shader code - Using fallback shader.");
88+
10689
// Fall back to default shader
10790
m_compositeShader = std::make_unique<MilkdropShader>(MilkdropShader::ShaderType::CompositeShader);
10891
m_compositeShader->LoadCode(defaultCompositeShader);

src/libprojectM/MilkdropPreset/MilkdropPreset.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525
#include "MilkdropPresetExceptions.hpp"
2626
#include "PresetFileParser.hpp"
2727

28-
#ifdef MILKDROP_PRESET_DEBUG
29-
#include <iostream>
30-
#endif
28+
#include <Logging.hpp>
3129

3230
namespace libprojectM {
3331
namespace MilkdropPreset {
@@ -205,39 +203,33 @@ void MilkdropPreset::PerFrameUpdate()
205203

206204
void MilkdropPreset::Load(const std::string& pathname)
207205
{
208-
#ifdef MILKDROP_PRESET_DEBUG
209-
std::cerr << "[Preset] Loading preset from file \"" << pathname << "\"." << std::endl;
210-
#endif
206+
LOG_DEBUG("[MilkdropPreset] Loading preset from file \"" + pathname + "\".")
211207

212208
SetFilename(ParseFilename(pathname));
213209

214210
::libprojectM::PresetFileParser parser;
215211

216212
if (!parser.Read(pathname))
217213
{
218-
#ifdef MILKDROP_PRESET_DEBUG
219-
std::cerr << "[Preset] Could not parse preset file." << std::endl;
220-
#endif
221-
throw MilkdropPresetLoadException("Could not parse preset file \"" + pathname + "\"");
214+
const std::string error = "[MilkdropPreset] Could not parse preset file \"" + pathname + "\".";
215+
LOG_ERROR(error)
216+
throw MilkdropPresetLoadException(error);
222217
}
223218

224219
InitializePreset(parser);
225220
}
226221

227222
void MilkdropPreset::Load(std::istream& stream)
228223
{
229-
#ifdef MILKDROP_PRESET_DEBUG
230-
std::cerr << "[Preset] Loading preset from stream." << std::endl;
231-
#endif
224+
LOG_DEBUG("[MilkdropPreset] Loading preset from stream.");
232225

233226
::libprojectM::PresetFileParser parser;
234227

235228
if (!parser.Read(stream))
236229
{
237-
#ifdef MILKDROP_PRESET_DEBUG
238-
std::cerr << "[Preset] Could not parse preset data." << std::endl;
239-
#endif
240-
throw MilkdropPresetLoadException("Could not parse preset data.");
230+
const std::string error = "[MilkdropPreset] Could not parse preset data.";
231+
LOG_ERROR(error)
232+
throw MilkdropPresetLoadException(error);
241233
}
242234

243235
InitializePreset(parser);

src/libprojectM/MilkdropPreset/MilkdropPresetExceptions.hpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ namespace MilkdropPreset {
1212
class MilkdropPresetLoadException : public std::exception
1313
{
1414
public:
15-
inline MilkdropPresetLoadException(std::string message)
15+
MilkdropPresetLoadException(std::string message)
1616
: m_message(std::move(message))
1717
{
1818
}
1919

2020
virtual ~MilkdropPresetLoadException() = default;
2121

22+
const char* what() const noexcept override
23+
{
24+
return m_message.c_str();
25+
}
26+
2227
const std::string& message() const
2328
{
2429
return m_message;
@@ -35,13 +40,18 @@ class MilkdropPresetLoadException : public std::exception
3540
class MilkdropCompileException : public std::exception
3641
{
3742
public:
38-
inline MilkdropCompileException(std::string message)
43+
MilkdropCompileException(std::string message)
3944
: m_message(std::move(message))
4045
{
4146
}
4247

4348
virtual ~MilkdropCompileException() = default;
4449

50+
const char* what() const noexcept override
51+
{
52+
return m_message.c_str();
53+
}
54+
4555
const std::string& message() const
4656
{
4757
return m_message;

src/libprojectM/MilkdropPreset/MilkdropShader.cpp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <GLSLGenerator.h>
1010
#include <HLSLParser.h>
11+
#include <Logging.hpp>
1112

1213
#include <glm/gtc/matrix_transform.hpp>
1314
#include <glm/mat4x4.hpp>
@@ -331,10 +332,15 @@ auto MilkdropShader::Shader() -> Renderer::Shader&
331332

332333
void MilkdropShader::PreprocessPresetShader(std::string& program)
333334
{
335+
std::string shaderTypeString = "composite";
336+
if (m_type == ShaderType::WarpShader)
337+
{
338+
shaderTypeString = "warp";
339+
}
334340

335341
if (program.length() <= 0)
336342
{
337-
throw Renderer::ShaderException("Preset shader is declared, but empty.");
343+
throw Renderer::ShaderException("[MilkdropShader] Preset " + shaderTypeString + " shader is declared, but empty.");
338344
}
339345

340346
size_t found;
@@ -391,7 +397,8 @@ void PS(float4 _vDiffuse : COLOR,
391397
}
392398
else
393399
{
394-
throw Renderer::ShaderException("Preset shader is missing \"shader_body\" entry point.");
400+
LOG_DEBUG("[MilkdropShader] Failed " + shaderTypeString + " shader code:\n" + program);
401+
throw Renderer::ShaderException("[MilkdropShader] Preset " + shaderTypeString + " shader is missing \"shader_body\" entry point.");
395402
}
396403

397404
// replace the "{" immediately following shader_body with some variable declarations
@@ -407,7 +414,8 @@ void PS(float4 _vDiffuse : COLOR,
407414
}
408415
else
409416
{
410-
throw Renderer::ShaderException("Preset shader has no opening braces.");
417+
LOG_DEBUG("[MilkdropShader] Failed " + shaderTypeString + " shader code:\n" + program);
418+
throw Renderer::ShaderException("[MilkdropShader] Preset " + shaderTypeString + " shader has no opening braces.");
411419
}
412420

413421
// replace "}" with return statement (this can probably be optimized for the GLSL conversion...)
@@ -419,7 +427,8 @@ void PS(float4 _vDiffuse : COLOR,
419427
}
420428
else
421429
{
422-
throw Renderer::ShaderException("Preset shader has no closing brace.");
430+
LOG_DEBUG("[MilkdropShader] Failed " + shaderTypeString + " shader code:\n" + program);
431+
throw Renderer::ShaderException("[MilkdropShader] Preset " + shaderTypeString + " shader has no closing brace.");
423432
}
424433

425434
// Find matching closing brace and cut off excess text after shader's main function
@@ -591,7 +600,8 @@ void MilkdropShader::TranspileHLSLShader(const PresetState& presetState, std::st
591600
std::string sourcePreprocessed;
592601
if (!parser.ApplyPreprocessor("", program.c_str(), program.size(), sourcePreprocessed))
593602
{
594-
throw Renderer::ShaderException("Error translating HLSL " + shaderTypeString + " shader: Preprocessing failed.\nSource:\n" + program);
603+
LOG_DEBUG("[MilkdropShader] Failed " + shaderTypeString + " shader code:\n" + program);
604+
throw Renderer::ShaderException("Error translating HLSL " + shaderTypeString + " shader: Preprocessing failed.");
595605
}
596606

597607
// Remove previous shader declarations
@@ -644,17 +654,23 @@ void MilkdropShader::TranspileHLSLShader(const PresetState& presetState, std::st
644654
// First, parse HLSL into a tree
645655
if (!parser.Parse("", sourcePreprocessed.c_str(), sourcePreprocessed.size()))
646656
{
647-
throw Renderer::ShaderException("Error translating HLSL " + shaderTypeString + " shader: HLSL parsing failed.\nSource:\n" + sourcePreprocessed);
657+
LOG_DEBUG("[MilkdropShader] Failed " + shaderTypeString + " shader code:\n" + program);
658+
LOG_DEBUG("[MilkdropShader] Failed preprocessed " + shaderTypeString + " shader code:\n" + sourcePreprocessed);
659+
throw Renderer::ShaderException("[MilkdropShader] Error translating HLSL " + shaderTypeString + " shader: HLSL parsing failed.");
648660
}
649661

650662
// Then generate GLSL from the resulting parser tree
651663
if (!generator.Generate(&tree, M4::GLSLGenerator::Target_FragmentShader,
652664
MilkdropStaticShaders::Get()->GetGlslGeneratorVersion(),
653665
"PS", M4::GLSLGenerator::Options(M4::GLSLGenerator::Flag_AlternateNanPropagation)))
654666
{
655-
throw Renderer::ShaderException("Error translating HLSL " + shaderTypeString + " shader: GLSL generating failed.\nSource:\n" + sourcePreprocessed);
667+
LOG_DEBUG("[MilkdropShader] Failed " + shaderTypeString + " shader code:\n" + program);
668+
LOG_DEBUG("[MilkdropShader] Failed preprocessed " + shaderTypeString + " shader code:\n" + sourcePreprocessed);
669+
throw Renderer::ShaderException("[MilkdropShader] Error translating HLSL " + shaderTypeString + " shader: GLSL generating failed.\nSource:\n" + sourcePreprocessed);
656670
}
657671

672+
LOG_TRACE("[MilkdropShader] Transpiled GLSL " + shaderTypeString + " shader code:\n" + std::string(generator.GetResult()));
673+
658674
// Now we have GLSL source for the preset shader program (hopefully it's valid!)
659675
// Compile the preset shader fragment shader with the standard vertex shader and cross our fingers.
660676
if (m_type == ShaderType::WarpShader)

src/libprojectM/MilkdropPreset/PerFrameContext.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#include "MilkdropPresetExceptions.hpp"
44

5-
#ifdef MILKDROP_PRESET_DEBUG
6-
#include <iostream>
7-
#endif
5+
#include <Logging.hpp>
86

97
#define REG_VAR(var) \
108
var = projectm_eval_context_register_variable(perFrameCodeContext, #var);
@@ -126,16 +124,22 @@ void PerFrameContext::EvaluateInitCode(PresetState& state)
126124
auto* initCode = projectm_eval_code_compile(perFrameCodeContext, state.perFrameInitCode.c_str());
127125
if (initCode == nullptr)
128126
{
129-
#ifdef MILKDROP_PRESET_DEBUG
127+
std::string error;
130128
int line;
131129
int col;
132130
auto* errmsg = projectm_eval_get_error(perFrameCodeContext, &line, &col);
133131
if (errmsg)
134132
{
135-
std::cerr << "[Preset] Could not compile per-frame INIT code: " << errmsg << "(L" << line << " C" << col << ")" << std::endl;
133+
error = "[PerFrameContext] Could not compile per-frame INIT code: ";
134+
error += errmsg;
135+
error += "(L" + std::to_string(line) + " C" + std::to_string(col) + ")";
136136
}
137-
#endif
138-
throw MilkdropCompileException("Could not compile per-frame init code");
137+
else
138+
{
139+
error = "[PerFrameContext] Could not compile per-frame init code.";
140+
}
141+
LOG_DEBUG("[PerFrameContext] Failed per-frame INIT code:\n" + state.perFrameInitCode);
142+
throw MilkdropCompileException(error);
139143
}
140144

141145
projectm_eval_code_execute(initCode);
@@ -241,16 +245,22 @@ void PerFrameContext::CompilePerFrameCode(const std::string& perFrameCode)
241245
perFrameCodeHandle = projectm_eval_code_compile(perFrameCodeContext, perFrameCode.c_str());
242246
if (perFrameCodeHandle == nullptr)
243247
{
244-
#ifdef MILKDROP_PRESET_DEBUG
248+
std::string error;
245249
int line;
246250
int col;
247251
auto* errmsg = projectm_eval_get_error(perFrameCodeContext, &line, &col);
248252
if (errmsg)
249253
{
250-
std::cerr << "[Preset] Could not compile per-frame code: " << errmsg << "(L" << line << " C" << col << ")" << std::endl;
254+
error = "[PerFrameContext] Could not compile per-frame code: ";
255+
error += errmsg;
256+
error += "(L" + std::to_string(line) + " C" + std::to_string(col) + ")";
257+
}
258+
else
259+
{
260+
error = "[PerFrameContext] Could not compile per-frame code.";
251261
}
252-
#endif
253-
throw MilkdropCompileException("Could not compile per-frame code");
262+
LOG_DEBUG("[PerFrameContext] Failed per-frame code:\n" + perFrameCode);
263+
throw MilkdropCompileException(error);
254264
}
255265
}
256266

src/libprojectM/MilkdropPreset/PerPixelContext.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
#include "MilkdropPresetExceptions.hpp"
44

5-
#ifdef MILKDROP_PRESET_DEBUG
6-
#include <iostream>
7-
#endif
5+
#include <Logging.hpp>
86

97
#define REG_VAR(var) \
108
var = projectm_eval_context_register_variable(perPixelCodeContext, #var);
@@ -110,13 +108,22 @@ void PerPixelContext::CompilePerPixelCode(const std::string& perPixelCode)
110108
perPixelCodeHandle = projectm_eval_code_compile(perPixelCodeContext, perPixelCode.c_str());
111109
if (perPixelCodeHandle == nullptr)
112110
{
113-
#ifdef MILKDROP_PRESET_DEBUG
111+
std::string error;
114112
int line;
115113
int col;
116114
auto* errmsg = projectm_eval_get_error(perPixelCodeContext, &line, &col);
117-
std::cerr << "[Preset] Could not compile per-pixel code: " << errmsg << "(L" << line << " C" << col << ")" << std::endl;
118-
#endif
119-
throw MilkdropCompileException("Could not compile per-pixel code");
115+
if (errmsg)
116+
{
117+
error = "[PerPixelContext] Could not compile per-pixel code: ";
118+
error += errmsg;
119+
error += "(L" + std::to_string(line) + " C" + std::to_string(col) + ")";
120+
}
121+
else
122+
{
123+
error = "[PerPixelContext] Could not compile per-pixel code.";
124+
}
125+
LOG_DEBUG("[PerPixelContext] Failed per-pixel code:\n" + perPixelCode);
126+
throw MilkdropCompileException(error);
120127
}
121128
}
122129

0 commit comments

Comments
 (0)