From eaa1d70c0460b4588ea0946488a73da3f5974798 Mon Sep 17 00:00:00 2001 From: Laura Hermanns Date: Sun, 16 Jun 2024 18:47:23 -0400 Subject: [PATCH] [Tests/Examples] Removed remaining dependenceis to from tests and examples. --- examples/Cpp/ClothPhysics/Example.cpp | 10 +++-- examples/Cpp/ExampleBase/ExampleBase.h | 2 +- examples/Cpp/Instancing/Example.cpp | 14 ++++--- examples/Cpp/MultiRenderer/Example.cpp | 6 +-- examples/Cpp/PBR/Example.cpp | 4 +- examples/Cpp/Queries/Example.cpp | 16 ++++---- examples/Cpp/RenderTarget/Example.cpp | 8 ++-- examples/Cpp/ResourceBinding/Example.cpp | 2 +- examples/Cpp/ShadowMapping/Example.cpp | 8 ++-- examples/Cpp/StencilBuffer/Example.cpp | 8 ++-- examples/Cpp/Tessellation/Example.cpp | 18 ++++++--- examples/Cpp/Texturing/Example.cpp | 23 ++++++++---- examples/Cpp/VolumeRendering/Example.cpp | 13 +++++-- include/LLGL/Display.h | 18 ++++----- include/LLGL/Log.h | 2 +- include/LLGL/RenderSystemFlags.h | 2 +- include/LLGL/Timer.h | 2 +- tests/Test_Compute.cpp | 14 ++++--- tests/Test_Display.cpp | 47 +++++++++++------------- tests/Test_Image.cpp | 4 +- tests/Test_JIT.cpp | 6 +-- tests/Test_OpenGL.cpp | 19 +++++----- tests/Test_Performance.cpp | 18 +++++---- tests/Test_ShaderReflect.cpp | 31 ++++++++-------- tests/Test_Vulkan.cpp | 15 ++++---- tests/Test_Window.cpp | 19 +++++----- 26 files changed, 185 insertions(+), 144 deletions(-) diff --git a/examples/Cpp/ClothPhysics/Example.cpp b/examples/Cpp/ClothPhysics/Example.cpp index 61aba7d94e..d758b5a03b 100644 --- a/examples/Cpp/ClothPhysics/Example.cpp +++ b/examples/Cpp/ClothPhysics/Example.cpp @@ -137,8 +137,10 @@ class Example_ClothPhysics : public ExampleBase particleBuffers[AttribNormal ]->SetDebugName("Particles.Normal"); // Show some information - std::cout << "press LEFT MOUSE BUTTON and move the mouse to rotate the camera" << std::endl; - std::cout << "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to change the cloth stiffness" << std::endl; + LLGL::Log::Printf( + "press LEFT MOUSE BUTTON and move the mouse to rotate the camera\n" + "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to change the cloth stiffness\n" + ); } // Generates the grid geometry for the cloth with triangle strip topology @@ -540,8 +542,8 @@ class Example_ClothPhysics : public ExampleBase { float delta = motion.x*0.01f; stiffnessFactor = std::max(0.5f, std::min(stiffnessFactor + delta, 1.0f)); - std::cout << "stiffness: " << static_cast(stiffnessFactor * 100.0f) << "% \r"; - std::flush(std::cout); + LLGL::Log::Printf("stiffness: %d\% \r", static_cast(stiffnessFactor * 100.0f)); + ::fflush(stdout); } // Update timer diff --git a/examples/Cpp/ExampleBase/ExampleBase.h b/examples/Cpp/ExampleBase/ExampleBase.h index a4214494df..299baa5afa 100644 --- a/examples/Cpp/ExampleBase/ExampleBase.h +++ b/examples/Cpp/ExampleBase/ExampleBase.h @@ -407,7 +407,7 @@ int RunExample(int argc, char* argv[]) } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); #ifdef _WIN32 system("pause"); #endif diff --git a/examples/Cpp/Instancing/Example.cpp b/examples/Cpp/Instancing/Example.cpp index 9057288c31..465e685733 100644 --- a/examples/Cpp/Instancing/Example.cpp +++ b/examples/Cpp/Instancing/Example.cpp @@ -74,9 +74,11 @@ class Example_Instancing : public ExampleBase resourceHeap->SetDebugName("ResourceHeap"); // Show info - std::cout << "press LEFT/RIGHT MOUSE BUTTON to rotate the camera around the scene" << std::endl; - std::cout << "press R KEY to reload the shader program" << std::endl; - std::cout << "press SPACE KEY to switch between pipeline states with and without alpha-to-coverage" << std::endl; + LLGL::Log::Printf( + "press LEFT/RIGHT MOUSE BUTTON to rotate the camera around the scene\n" + "press R KEY to reload the shader program\n" + "press SPACE KEY to switch between pipeline states with and without alpha-to-coverage\n" + ); } private: @@ -250,7 +252,7 @@ class Example_Instancing : public ExampleBase stbi_image_free(imageBuffer); // Show info - std::cout << "loaded texture: " << filename << std::endl; + LLGL::Log::Printf("loaded texture: %s\n", filename.c_str()); } // Create array texture object with 'numImages' layers @@ -375,9 +377,9 @@ class Example_Instancing : public ExampleBase { alphaToCoverageEnabled = !alphaToCoverageEnabled; if (alphaToCoverageEnabled) - std::cout << "Alpha-To-Coverage Enabled" << std::endl; + LLGL::Log::Printf("Alpha-To-Coverage Enabled\n"); else - std::cout << "Alpha-To-Coverage Disabled" << std::endl; + LLGL::Log::Printf("Alpha-To-Coverage Disabled\n"); } commands->Begin(); diff --git a/examples/Cpp/MultiRenderer/Example.cpp b/examples/Cpp/MultiRenderer/Example.cpp index d8b13743bc..0323dda6f5 100644 --- a/examples/Cpp/MultiRenderer/Example.cpp +++ b/examples/Cpp/MultiRenderer/Example.cpp @@ -205,7 +205,7 @@ void MyRenderer::CreateResources(const LLGL::ArrayView& vertices if (const LLGL::Report* report = shader->GetReport()) { if (*report->GetText() != '\0') - std::cerr << report->GetText() << std::endl; + LLGL::Log::Errorf("%s\n", report->GetText()); } } @@ -235,7 +235,7 @@ void MyRenderer::CreateResources(const LLGL::ArrayView& vertices if (const LLGL::Report* report = pipeline->GetReport()) { if (*report->GetText() != '\0') - std::cerr << report->GetText() << std::endl; + LLGL::Log::Errorf("%s\n", report->GetText()); } // Get command queue @@ -451,7 +451,7 @@ int main(int argc, char* argv[]) } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); #ifdef _WIN32 system("pause"); #endif diff --git a/examples/Cpp/PBR/Example.cpp b/examples/Cpp/PBR/Example.cpp index 1457a49c74..7c4c6c9b01 100644 --- a/examples/Cpp/PBR/Example.cpp +++ b/examples/Cpp/PBR/Example.cpp @@ -81,7 +81,7 @@ class Example_PBR : public ExampleBase CreateResourceHeaps(); // Print some information on the standard output - std::cout << "press TAB KEY to switch between five different texture samplers" << std::endl; + LLGL::Log::Printf("press TAB KEY to switch between five different texture samplers\n"); } private: @@ -221,7 +221,7 @@ class Example_PBR : public ExampleBase { // Print information about current texture const std::string path = FindResourcePath(filename); - std::cout << "load image: \"" << path << "\"" << std::endl; + LLGL::Log::Printf("load image: \"%s\"\n", path.c_str()); // Load image data from file (using STBI library, see http://nothings.org/stb_image.h) int w = 0, h = 0, n = 0; diff --git a/examples/Cpp/Queries/Example.cpp b/examples/Cpp/Queries/Example.cpp index 1060762ce3..088a9b85c9 100644 --- a/examples/Cpp/Queries/Example.cpp +++ b/examples/Cpp/Queries/Example.cpp @@ -66,7 +66,7 @@ class Example_Queries : public ExampleBase CreateResourceHeaps(); // Show info - std::cout << "press SPACE KEY to enable/disable animation of occluder" << std::endl; + LLGL::Log::Printf("press SPACE KEY to enable/disable animation of occluder\n"); } LLGL::VertexFormat CreateBuffers() @@ -185,12 +185,14 @@ class Example_Queries : public ExampleBase } // Print result - std::cout << "input assembly: " << stats.inputAssemblyPrimitives; - std::cout << ", vertex invocations: " << stats.vertexShaderInvocations; - std::cout << ", fragment invocations: " << stats.fragmentShaderInvocations; - std::cout << ", timing: " << static_cast(elapsedTime)/1000000.0 << " ms"; - std::cout << " \r"; - std::flush(std::cout); + LLGL::Log::Printf( + "input assembly: %u, vertex invocations: %u, fragment invocations: %u, timing: %f ms \r", + static_cast(stats.inputAssemblyPrimitives), + static_cast(stats.vertexShaderInvocations), + static_cast(stats.fragmentShaderInvocations), + static_cast(elapsedTime)/1000000.0 + ); + ::fflush(stdout); } void SetBoxTransformAndColor(const Gs::Matrix4f& matrix, const LLGL::ColorRGBAf& color) diff --git a/examples/Cpp/RenderTarget/Example.cpp b/examples/Cpp/RenderTarget/Example.cpp index 920f1af3c6..5e8ae03d9e 100644 --- a/examples/Cpp/RenderTarget/Example.cpp +++ b/examples/Cpp/RenderTarget/Example.cpp @@ -101,9 +101,11 @@ class Example_RenderTarget : public ExampleBase #endif // Show some information - std::cout << "press LEFT MOUSE BUTTON and move the mouse on the X-axis to rotate the OUTER cube" << std::endl; - std::cout << "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to rotate the INNER cube" << std::endl; - std::cout << "press RETURN KEY to save the render target texture to a PNG file" << std::endl; + LLGL::Log::Printf( + "press LEFT MOUSE BUTTON and move the mouse on the X-axis to rotate the OUTER cube\n" + "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to rotate the INNER cube\n" + "press RETURN KEY to save the render target texture to a PNG file\n" + ); } private: diff --git a/examples/Cpp/ResourceBinding/Example.cpp b/examples/Cpp/ResourceBinding/Example.cpp index 7636e48d36..5d40a438d6 100644 --- a/examples/Cpp/ResourceBinding/Example.cpp +++ b/examples/Cpp/ResourceBinding/Example.cpp @@ -62,7 +62,7 @@ class Example_ResourceBinding : public ExampleBase const auto caps = renderer->GetRenderingCaps(); // Show info - //std::cout << "press LEFT/RIGHT MOUSE BUTTON to rotate the camera around the scene" << std::endl; + //LLGL::Log::Printf("press LEFT/RIGHT MOUSE BUTTON to rotate the camera around the scene\n"); } private: diff --git a/examples/Cpp/ShadowMapping/Example.cpp b/examples/Cpp/ShadowMapping/Example.cpp index 4103b66f3e..6559a00a02 100644 --- a/examples/Cpp/ShadowMapping/Example.cpp +++ b/examples/Cpp/ShadowMapping/Example.cpp @@ -65,9 +65,11 @@ class Example_ShadowMapping : public ExampleBase #if 0 // Show some information - std::cout << "press LEFT MOUSE BUTTON and move the mouse on the X-axis to rotate the OUTER cube" << std::endl; - std::cout << "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to rotate the INNER cube" << std::endl; - std::cout << "press RETURN KEY to save the render target texture to a PNG file" << std::endl; + LLGL::Log::Printf( + "press LEFT MOUSE BUTTON and move the mouse on the X-axis to rotate the OUTER cube\n" + "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to rotate the INNER cube\n" + "press RETURN KEY to save the render target texture to a PNG file\n" + ); #endif } diff --git a/examples/Cpp/StencilBuffer/Example.cpp b/examples/Cpp/StencilBuffer/Example.cpp index ed8b67adb2..faf7568f70 100644 --- a/examples/Cpp/StencilBuffer/Example.cpp +++ b/examples/Cpp/StencilBuffer/Example.cpp @@ -58,9 +58,11 @@ class Example_StencilBuffer : public ExampleBase #if 0 // Show some information - std::cout << "press LEFT MOUSE BUTTON and move the mouse on the X-axis to rotate the OUTER cube" << std::endl; - std::cout << "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to rotate the INNER cube" << std::endl; - std::cout << "press RETURN KEY to save the render target texture to a PNG file" << std::endl; + LLGL::Log::Printf( + "press LEFT MOUSE BUTTON and move the mouse on the X-axis to rotate the OUTER cube\n" + "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to rotate the INNER cube\n" + "press RETURN KEY to save the render target texture to a PNG file\n" + ); #endif } diff --git a/examples/Cpp/Tessellation/Example.cpp b/examples/Cpp/Tessellation/Example.cpp index bac4828ff4..fd25078051 100644 --- a/examples/Cpp/Tessellation/Example.cpp +++ b/examples/Cpp/Tessellation/Example.cpp @@ -67,10 +67,12 @@ class Example_Tessellation : public ExampleBase CreatePipelines(); // Print some information on the standard output - std::cout << "press LEFT MOUSE BUTTON and move mouse on X axis to increase/decrease inner tessellation" << std::endl; - std::cout << "press RIGHT MOUSE BUTTON and move mouse on X axis to increase/decrease outer tessellation" << std::endl; - std::cout << "press MIDDLE MOUSE BUTTON and move mouse on X axis to increase/decrease twist" << std::endl; - std::cout << "press TAB KEY to switch between wireframe modes" << std::endl; + LLGL::Log::Printf( + "press LEFT MOUSE BUTTON and move mouse on X axis to increase/decrease inner tessellation\n" + "press RIGHT MOUSE BUTTON and move mouse on X axis to increase/decrease outer tessellation\n" + "press MIDDLE MOUSE BUTTON and move mouse on X axis to increase/decrease twist\n" + "press TAB KEY to switch between wireframe modes\n" + ); ShowTessLevel(); } @@ -198,8 +200,12 @@ class Example_Tessellation : public ExampleBase void ShowTessLevel() { - //std::cout << "tessellation level (inner = " << settings.tessLevelInner << ", outer = " << settings.tessLevelOuter << ") \r"; - //std::flush(std::cout); + /*LLGL::Log::Printf( + "tessellation level (inner = %f, outer = %f) \r", + static_cast(settings.tessLevelInner), + static_cast(settings.tessLevelOuter) + ); + ::fflush(stdout);*/ } private: diff --git a/examples/Cpp/Texturing/Example.cpp b/examples/Cpp/Texturing/Example.cpp index 2ae7c7967f..2cfe1ec281 100644 --- a/examples/Cpp/Texturing/Example.cpp +++ b/examples/Cpp/Texturing/Example.cpp @@ -54,9 +54,12 @@ class Example_Texturing : public ExampleBase CreateSamplers(); // Print some information on the standard output - std::cout << "press TAB KEY to switch between five different texture samplers" << std::endl; - std::cout << "texture: " << resourceLabels[0] << "\r"; - std::flush(std::cout); + LLGL::Log::Printf( + "press TAB KEY to switch between five different texture samplers\n" + "texture: %s\r", + resourceLabels[0] + ); + ::fflush(stdout); } LLGL::VertexFormat CreateBuffers() @@ -155,8 +158,8 @@ class Example_Texturing : public ExampleBase } colorMaps[1] = renderer->CreateTexture(texDesc, &imageView); } - auto texCreationTime = static_cast(timer.Stop()) / static_cast(timer.GetFrequency()); - std::cout << "texture creation time: " << (texCreationTime * 1000.0) << " ms" << std::endl; + double texCreationTime = static_cast(timer.Stop()) / static_cast(timer.GetFrequency()); + LLGL::Log::Printf("texture creation time: %f ms\n", texCreationTime * 1000.0); // Release image data stbi_image_free(imageBuffer); @@ -240,8 +243,14 @@ class Example_Texturing : public ExampleBase resourceIndex = ((resourceIndex - 1) % 4 + 4) % 4; else resourceIndex = (resourceIndex + 1) % 4; - std::cout << "texture: " << resourceLabels[resourceIndex] << std::string(30, ' ') << "\r"; - std::flush(std::cout); + + const std::string spaces(30, ' '); + LLGL::Log::Printf( + "texture: %s%s\r", + resourceLabels[resourceIndex], + spaces.c_str() + ); + ::fflush(stdout); } // Update scene constants diff --git a/examples/Cpp/VolumeRendering/Example.cpp b/examples/Cpp/VolumeRendering/Example.cpp index 8fc7da377c..d37e729396 100644 --- a/examples/Cpp/VolumeRendering/Example.cpp +++ b/examples/Cpp/VolumeRendering/Example.cpp @@ -71,8 +71,10 @@ class Example_VolumeRendering : public ExampleBase CreateResourceHeaps(); // Show some information - std::cout << "press LEFT MOUSE BUTTON and move the mouse to ROTATE the model" << std::endl; - std::cout << "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to change the DENSITY THRESHOLD" << std::endl; + LLGL::Log::Printf( + "press LEFT MOUSE BUTTON and move the mouse to ROTATE the model\n" + "press RIGHT MOUSE BUTTON and move the mouse on the X-axis to change the DENSITY THRESHOLD\n" + ); } private: @@ -317,8 +319,11 @@ class Example_VolumeRendering : public ExampleBase { float delta = mouseMotion.x*0.002f; settings.threshold = std::max(0.0f, std::min(settings.threshold + delta, 0.5f)); - std::cout << "density threshold: " << static_cast(settings.threshold*200.0f) << "% \r"; - std::flush(std::cout); + LLGL::Log::Printf( + "density threshold: %d\% \r", + static_cast(settings.threshold*200.0f) + ); + ::fflush(stdout); } // Rotate model around X and Y axes diff --git a/include/LLGL/Display.h b/include/LLGL/Display.h index 21e4324dcd..fad9b894e8 100644 --- a/include/LLGL/Display.h +++ b/include/LLGL/Display.h @@ -24,15 +24,15 @@ namespace LLGL \remarks Here is an example to print the attributes of all displays: \code for (Display* const * myDisplayList = LLGL::Display::GetList(); Display* myDisplay = *myDisplayList; ++myDisplayList) { - auto myDisplayOffset = myDisplay->GetOffset(); - auto myDisplayMode = myDisplay->GetDisplayMode(); - std::wcout << L"Display: \"" << myDisplay->GetDeviceName() << L"\"" << std::endl; - std::cout << "|-Primary = " << std::boolalpha << myDisplay->IsPrimary() << std::endl; - std::cout << "|-X = " << myDisplayOffset.x << std::endl; - std::cout << "|-Y = " << myDisplayOffset.y << std::endl; - std::cout << "|-Width = " << myDisplayMode.resolution.width << std::endl; - std::cout << "|-Height = " << myDisplayMode.resolution.height << std::endl; - std::cout << "`-Hz = " << myDisplayMode.refreshRate << std::endl; + LLGL::Offset2D myDisplayOffset = myDisplay->GetOffset(); + LLGL::DisplayMode myDisplayMode = myDisplay->GetDisplayMode(); + printf("Display: \"%s\"\n", myDisplay->GetDeviceName().c_str()); + printf("|-Primary = %s\n", myDisplay->IsPrimary() ? "yes" : "no"); + printf("|-X = %d\n", myDisplayOffset.x); + printf("|-Y = %d\n", myDisplayOffset.y); + printf("|-Width = %u\n", myDisplayMode.resolution.width); + printf("|-Height = %u\n", myDisplayMode.resolution.height); + printf("`-Hz = %u\n", myDisplayMode.refreshRate); } \endcode */ diff --git a/include/LLGL/Log.h b/include/LLGL/Log.h index e6e14e3488..2ddbe1840b 100644 --- a/include/LLGL/Log.h +++ b/include/LLGL/Log.h @@ -36,7 +36,7 @@ enum class ReportType Default = 0, /** - \brief Error message type. Usualyl forwarded to \c stderr \c std::cerr. + \brief Error message type. Usually forwarded to \c stderr or \c std::cerr. \see Errorf. */ Error, diff --git a/include/LLGL/RenderSystemFlags.h b/include/LLGL/RenderSystemFlags.h index b779f3f7ff..596a20b8a0 100644 --- a/include/LLGL/RenderSystemFlags.h +++ b/include/LLGL/RenderSystemFlags.h @@ -923,7 +923,7 @@ LLGL::ValidateRenderingCaps( myRenderer->GetRenderingCaps(), myRequirements, [](const std::string& info, const std::string& attrib) { - std::cerr << info << ": " << attrib << std::endl; + ::fprintf(stderr, "%s: %s\n", info.c_str(), attrib.c_str()); return true; } ); diff --git a/include/LLGL/Timer.h b/include/LLGL/Timer.h index d61902553f..a85ed5d068 100644 --- a/include/LLGL/Timer.h +++ b/include/LLGL/Timer.h @@ -34,7 +34,7 @@ const std::uint64_t startTime = LLGL::Timer::Tick(); // Some events ... const std::uint64_t endTime = LLGL::Timer::Tick(); const double elapsedSeconds = static_cast(endTime - startTime) / LLGL::Timer::Frequency(); -std::cout << "Elapsed time: " << elapsedSeconds * 1000.0 << "ms" << std::endl; +printf("Elapsed time: %f ms\n", elapsedSeconds * 1000.0); \endcode \see Frequency */ diff --git a/tests/Test_Compute.cpp b/tests/Test_Compute.cpp index 1de0f69868..fef2000b7e 100644 --- a/tests/Test_Compute.cpp +++ b/tests/Test_Compute.cpp @@ -9,7 +9,6 @@ #include #include #include -#include // Fill an array list of 4D-vectors for testing purposes static std::vector GetTestVector(std::size_t size) @@ -29,6 +28,8 @@ int main() { try { + LLGL::Log::RegisterCallbackStd(); + // Setup profiler and debugger auto debugger = std::make_shared(); @@ -116,7 +117,7 @@ int main() { /* wait until the result is available */ } - std::cout << "compute shader duration: " << static_cast(result) / 1000000 << " ms" << std::endl; + LLGL::Log::Printf("compute shader duration: %f ms\n", static_cast(result) / 1000000); // Wait until the GPU has completed all work, to be sure we can evaluate the storage buffer renderer->GetCommandQueue()->WaitIdle(); @@ -125,14 +126,17 @@ int main() if (auto mappedBuffer = renderer->MapBuffer(*storageBuffer, LLGL::CPUAccess::ReadOnly)) { // Show result - auto vecBuffer = reinterpret_cast(mappedBuffer); - std::cout << "compute shader output: average vector = " << vecBuffer[0] << std::endl; + auto* vecBuffer = reinterpret_cast(mappedBuffer); + LLGL::Log::Printf( + "compute shader output: average vector = ( %f | %f | %f | %f )\n", + vecBuffer[0].x, vecBuffer[0].y, vecBuffer[0].z, vecBuffer[0].w + ); } renderer->UnmapBuffer(*storageBuffer); } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); } #ifdef _WIN32 diff --git a/tests/Test_Display.cpp b/tests/Test_Display.cpp index 5339f1f6ec..e35f2b3655 100644 --- a/tests/Test_Display.cpp +++ b/tests/Test_Display.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #include #include @@ -15,22 +15,24 @@ int main(int argc, char* argv[]) { try { + LLGL::Log::RegisterCallbackStd(); + for (std::size_t i = 0; auto display = LLGL::Display::Get(i); ++i) { auto displayOffset = display->GetOffset(); auto displayMode = display->GetDisplayMode(); auto displayName = display->GetDeviceName(); - std::cout << "Display: \"" << displayName.c_str() << "\"" << std::endl; - std::cout << "|-Primary = " << std::boolalpha << display->IsPrimary() << std::endl; - std::cout << "|-X = " << displayOffset.x << std::endl; - std::cout << "|-Y = " << displayOffset.y << std::endl; - std::cout << "|-Width = " << displayMode.resolution.width << std::endl; - std::cout << "|-Height = " << displayMode.resolution.height << std::endl; - std::cout << "|-Hz = " << displayMode.refreshRate << std::endl; - std::cout << "|-Scale = " << display->GetScale() << std::endl; + LLGL::Log::Printf("Display: \"%s\"\n", displayName.c_str()); + LLGL::Log::Printf("|-Primary = %s\n", display->IsPrimary() ? "yes" : "no"); + LLGL::Log::Printf("|-X = %d\n", displayOffset.x); + LLGL::Log::Printf("|-Y = %d\n", displayOffset.y); + LLGL::Log::Printf("|-Width = %u\n", displayMode.resolution.width); + LLGL::Log::Printf("|-Height = %u\n", displayMode.resolution.height); + LLGL::Log::Printf("|-Hz = %u\n", displayMode.refreshRate); + LLGL::Log::Printf("|-Scale = %f\n", display->GetScale()); - std::cout << "`-Settings:" << std::endl; + LLGL::Log::Printf("`-Settings:\n"); auto supportedModes = display->GetSupportedDisplayModes(); for (std::size_t i = 0, n = supportedModes.size(); i < n; ++i) @@ -38,17 +40,12 @@ int main(int argc, char* argv[]) const auto& mode = supportedModes[i]; auto ratio = GetExtentRatio(mode.resolution); - if (i + 1 < n) - std::cout << " |-"; - else - std::cout << " `-"; - - std::cout << "Mode[" << i << "]:"; - std::cout << " Width = " << mode.resolution.width; - std::cout << ", Height = " << mode.resolution.height; - std::cout << ", Hz = " << mode.refreshRate; - std::cout << ", Ratio = " << ratio.width << ':' << ratio.height; - std::cout << std::endl; + LLGL::Log::Printf(i + 1 < n ? " |-" : " `-"); + LLGL::Log::Printf("Mode[%zu]:", i); + LLGL::Log::Printf(" Width = %u", mode.resolution.width); + LLGL::Log::Printf(", Height = %u", mode.resolution.height); + LLGL::Log::Printf(", Hz = %u", mode.refreshRate); + LLGL::Log::Printf(", Ratio = %u:%u\n", ratio.width, ratio.height); } } @@ -64,18 +61,18 @@ int main(int argc, char* argv[]) display->ResetDisplayMode(); } - std::cout << "Wainting"; + LLGL::Log::Printf("Wainting"); for (int i = 0; i < 5; ++i) { std::this_thread::sleep_for(std::chrono::seconds(1)); - std::cout << '.'; + LLGL::Log::Printf("."); } - std::cout << std::endl; + LLGL::Log::Printf("\n"); #endif } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); } #ifdef _WIN32 diff --git a/tests/Test_Image.cpp b/tests/Test_Image.cpp index d13a522777..760e25fcee 100644 --- a/tests/Test_Image.cpp +++ b/tests/Test_Image.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #define STB_IMAGE_IMPLEMENTATION #include @@ -118,7 +118,7 @@ int main(int argc, char* argv[]) } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + fprintf(stderr, "%s\n", e.what()); #ifdef _WIN32 system("pause"); #endif diff --git a/tests/Test_JIT.cpp b/tests/Test_JIT.cpp index 6794cf17ea..f539246b16 100644 --- a/tests/Test_JIT.cpp +++ b/tests/Test_JIT.cpp @@ -6,7 +6,7 @@ */ #include -#include +#include #if defined LLGL_ENABLE_JIT_COMPILER && defined LLGL_DEBUG @@ -25,7 +25,7 @@ int main() } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + ::fprintf(stderr, "%s\n", e.what()); } return 0; @@ -35,7 +35,7 @@ int main() int main() { - std::cerr << "LLGL was not compiled with LLGL_ENABLE_JIT_COMPILER" << std::endl; + ::fprintf(stderr, "LLGL was not compiled with LLGL_ENABLE_JIT_COMPILER\n"); return 0; } diff --git a/tests/Test_OpenGL.cpp b/tests/Test_OpenGL.cpp index dcd65166b9..ade2225098 100644 --- a/tests/Test_OpenGL.cpp +++ b/tests/Test_OpenGL.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include @@ -32,6 +31,8 @@ int main() { try { + LLGL::Log::RegisterCallbackStd(); + // Setup profiler and debugger std::shared_ptr debugger; @@ -188,7 +189,7 @@ int main() auto vertShader = renderer->CreateShader(vertShaderDesc); if (auto report = vertShader->GetReport()) - std::cerr << report->GetText() << std::endl; + LLGL::Log::Errorf("%s\n", report->GetText()); // Create fragment shader auto fragShaderSource = @@ -214,12 +215,12 @@ int main() #if 0//TODO // Reflect shader LLGL::ShaderReflection reflection; - vertShader.Reflect(reflection); - fragShader.Reflect(reflection); + vertShader->Reflect(reflection); + fragShader->Reflect(reflection); for (const auto& uniform : reflection.uniforms) { - std::cout << "uniform: name = \"" << uniform.name << "\", location = " << uniform.location << ", size = " << uniform.size << std::endl; + LLGL::Log::Printf("uniform: name = \"%s\", size = %u\n", uniform.name, uniform.arraySize); } #endif @@ -353,7 +354,7 @@ int main() auto storeBufferDescs = shaderProgram.QueryStorageBuffers(); for (const auto& desc : storeBufferDescs) - std::cout << "storage buffer: name = \"" << desc.name << '\"' << std::endl; + LLGL::Log::Printf("storage buffer: name = \"%s\"\n", desc.name.c_str()); } #endif @@ -435,7 +436,7 @@ int main() auto outputData = renderer->MapBuffer(*storage, LLGL::BufferCPUAccess::ReadOnly); { auto v = reinterpret_cast(outputData); - std::cout << "storage buffer output: " << *v << std::endl; + LLGL::Log::Printf("storage buffer output: ( %f | %f | %f | %f )\n", v[0].x, v[0].y, v[0].z, v[0].w); } renderer->UnmapBuffer(); } @@ -458,7 +459,7 @@ int main() if (prevResult != result) { prevResult = result; - std::cout << "query result = " << result << std::endl; + LLGL::Log::Printf("query result = %u", static_cast(result)); } hasQueryResult = false; } @@ -483,7 +484,7 @@ int main() } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); #ifdef _WIN32 system("pause"); #endif diff --git a/tests/Test_Performance.cpp b/tests/Test_Performance.cpp index f87c073143..ba5231162c 100644 --- a/tests/Test_Performance.cpp +++ b/tests/Test_Performance.cpp @@ -9,7 +9,6 @@ #include #include #include -#include static unsigned int g_seed; @@ -74,7 +73,7 @@ class PerformanceTest void CreateTextures(std::size_t numTextures) { // Create source image for textures - std::cout << "generate random image ..." << std::endl; + LLGL::Log::Printf("generate random image ...\n"); LLGL::Image image { @@ -102,11 +101,11 @@ class PerformanceTest } for (std::size_t i = 0; i < numTextures; ++i) { - std::cout << "create texture " << (i + 1) << '/' << numTextures << '\r'; + LLGL::Log::Printf("create texture %zu/%zu\r", (i + 1), numTextures); textures.push_back(renderer->CreateTexture(textureDesc, &imageDesc)); } - std::cout << std::endl; + LLGL::Log::Printf("\n"); } void MeasureTime(const std::string& title, const std::function& callback) @@ -127,8 +126,11 @@ class PerformanceTest { if (commandQueue->QueryResult(*timerQuery, 0, 1, &result, sizeof(result))) { - std::cout << title << std::endl; - std::cout << "\tduration: " << result << "ns (" << (static_cast(result) / 1000000.0) << "ms)" << "\n\n"; + LLGL::Log::Printf("%s\n", title.c_str()); + LLGL::Log::Printf( + "\tduration: %llu ns (%f ms)\n\n", + static_cast(result), (static_cast(result) / 1000000.0) + ); break; } } @@ -184,7 +186,7 @@ class PerformanceTest void Run() { - std::cout << std::endl << "run performance tests ..." << std::endl; + LLGL::Log::Printf("\nrun performance tests ...\n"); commands->Begin(); { @@ -207,6 +209,8 @@ class PerformanceTest int main(int argc, char* argv[]) { + LLGL::Log::RegisterCallbackStd(); + std::string rendererModule = "OpenGL"; TestConfig testConfig; diff --git a/tests/Test_ShaderReflect.cpp b/tests/Test_ShaderReflect.cpp index c2f4e6f7db..9e41e691a5 100644 --- a/tests/Test_ShaderReflect.cpp +++ b/tests/Test_ShaderReflect.cpp @@ -7,12 +7,13 @@ #include #include -#include int main() { try { + LLGL::Log::RegisterCallbackStd(); + // Setup profiler and debugger auto debugger = std::make_shared(); @@ -40,45 +41,45 @@ int main() LLGL::ShaderReflection reflect; computeShader->Reflect(reflect); - std::cout << "Resources:" << std::endl; + LLGL::Log::Printf("Resources:\n"); for (const LLGL::ShaderResourceReflection& resc : reflect.resources) { - std::cout << " " << resc.binding.name << " @ " << resc.binding.slot.index << std::endl; + LLGL::Log::Printf(" %s @ %u\n", resc.binding.name.c_str(), resc.binding.slot.index); } - std::cout << "Uniforms:" << std::endl; + LLGL::Log::Printf("Uniforms:\n"); for (const LLGL::UniformDescriptor& unif : reflect.uniforms) { - std::cout << " " << unif.name; + LLGL::Log::Printf(" %s", unif.name.c_str()); if (unif.arraySize > 0) - std::cout << '[' << unif.arraySize << ']'; - std::cout << std::endl; + LLGL::Log::Printf("[%u]", unif.arraySize); + LLGL::Log::Printf("\n"); } - std::cout << "Vertex Input Attributes:" << std::endl; + LLGL::Log::Printf("Vertex Input Attributes:\n"); for (const LLGL::VertexAttribute& attr : reflect.vertex.inputAttribs) { - std::cout << " " << attr.name << " @ " << attr.location << std::endl; + LLGL::Log::Printf(" %s @ %u\n", attr.name.c_str(), attr.location); } - std::cout << "Vertex Output Attributes:" << std::endl; + LLGL::Log::Printf("Vertex Output Attributes:\n"); for (const LLGL::VertexAttribute& attr : reflect.vertex.outputAttribs) { - std::cout << " " << attr.name << " @ " << attr.location << std::endl; + LLGL::Log::Printf(" %s @ %u\n", attr.name.c_str(), attr.location); } - std::cout << "Fragment Output Attributes:" << std::endl; + LLGL::Log::Printf("Fragment Output Attributes:\n"); for (const LLGL::FragmentAttribute& attr : reflect.fragment.outputAttribs) { - std::cout << " " << attr.name << " @ " << attr.location << std::endl; + LLGL::Log::Printf(" %s @ %u\n", attr.name.c_str(), attr.location); } const auto& workGroupSize = reflect.compute.workGroupSize; - std::cout << "Compute Work Group Size: " << workGroupSize.width << " x " << workGroupSize.height << " x " << workGroupSize.depth << std::endl; + LLGL::Log::Printf("Compute Work Group Size: %u x %u x %u\n", workGroupSize.width, workGroupSize.height, workGroupSize.depth); } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); } #ifdef _WIN32 diff --git a/tests/Test_Vulkan.cpp b/tests/Test_Vulkan.cpp index 7d92471818..563f87a3ce 100644 --- a/tests/Test_Vulkan.cpp +++ b/tests/Test_Vulkan.cpp @@ -10,7 +10,6 @@ #include #include #include -#include #define STB_IMAGE_IMPLEMENTATION #include @@ -42,6 +41,8 @@ int main() { try { + LLGL::Log::RegisterCallbackStd(); + #if TEST_CUSTOM_VKDEVICE && _WIN32 const char* vulkanInstanceExt[] = { VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_WIN32_SURFACE_EXTENSION_NAME }; @@ -124,10 +125,10 @@ int main() const auto& info = renderer->GetRendererInfo(); const auto& caps = renderer->GetRenderingCaps(); - std::cout << "Renderer: " << info.rendererName << std::endl; - std::cout << "Device: " << info.deviceName << std::endl; - std::cout << "Vendor: " << info.vendorName << std::endl; - std::cout << "Shading Language: " << info.shadingLanguageName << std::endl; + LLGL::Log::Printf("Renderer: %s\n", info.rendererName.c_str()); + LLGL::Log::Printf("Device: %s\n", info.deviceName.c_str()); + LLGL::Log::Printf("Vendor: %s\n", info.vendorName.c_str()); + LLGL::Log::Printf("Shading Language: %s\n", info.shadingLanguageName.c_str()); // Create swap-chain LLGL::SwapChainDescriptor swapChainDesc; @@ -299,7 +300,7 @@ int main() auto pipeline = renderer->CreatePipelineState(pipelineDesc); if (auto report = pipeline->GetReport()) - std::cerr << report->GetText() << std::endl; + LLGL::Log::Errorf("%s\n", report->GetText()); // Create query #if TEST_QUERY @@ -386,7 +387,7 @@ int main() } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); #ifdef _WIN32 system("pause"); #endif diff --git a/tests/Test_Window.cpp b/tests/Test_Window.cpp index 9b12d4da71..f4aebfb544 100644 --- a/tests/Test_Window.cpp +++ b/tests/Test_Window.cpp @@ -7,24 +7,23 @@ #include #include -#include #include #include static void printWindowSize(LLGL::Window& wnd) { - std::wcout << L"window: \"" << wnd.GetTitle() << L"\"" << std::endl; + LLGL::Log::Printf("window: \"%s\"\n", wnd.GetTitle().c_str()); auto s = wnd.GetSize(true); - std::wcout << " content size = " << s.width << " x " << s.height << std::endl; + LLGL::Log::Printf(" content size = %u x %u\n", s.width, s.height); s = wnd.GetSize(false); - std::wcout << " frame size = " << s.width << " x " << s.height << std::endl; + LLGL::Log::Printf(" frame size = %u x %u\n", s.width, s.height); }; static void printWindowPos(LLGL::Window& wnd) { auto p = wnd.GetPosition(); - std::wcout << "window pos: x = " << p.x << ", y = " << p.y << std::endl; + LLGL::Log::Printf("window pos: x = %d, y = %d\n", p.x, p.y); } class WindowEventHandler : public LLGL::Window::EventListener @@ -32,7 +31,7 @@ class WindowEventHandler : public LLGL::Window::EventListener public: void OnResize(LLGL::Window& sender, const LLGL::Extent2D& size) override { - std::wcout << "OnResize: " << size.width << " x " << size.height << std::endl; + LLGL::Log::Printf("OnResize: %u x %u\n", size.width, size.height); printWindowSize(sender); } }; @@ -41,6 +40,8 @@ int main() { try { + LLGL::Log::RegisterCallbackStd(); + // Create window LLGL::WindowDescriptor windowDesc; @@ -68,14 +69,14 @@ int main() } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); } LLGL::Extent2D desktopSize; if (auto display = LLGL::Display::GetPrimary()) desktopSize = display->GetDisplayMode().resolution; - std::wcout << "Screen Width = " << desktopSize.width << ", Screen Height = " << desktopSize.height << std::endl; + LLGL::Log::Printf("Screen Width = %u, Screen Heihgt = %u\n", desktopSize.width, desktopSize.height); while (LLGL::Surface::ProcessEvents() && !window->HasQuit() && !input.KeyPressed(LLGL::Key::Escape)) { @@ -151,7 +152,7 @@ int main() } catch (const std::exception& e) { - std::cerr << e.what() << std::endl; + LLGL::Log::Errorf("%s\n", e.what()); } return 0;