Skip to content

Commit

Permalink
[Tests/Examples] Removed remaining dependenceis to <iostream> from te…
Browse files Browse the repository at this point in the history
…sts and examples.
  • Loading branch information
LukasBanana committed Jun 16, 2024
1 parent f22c4dc commit eaa1d70
Show file tree
Hide file tree
Showing 26 changed files with 185 additions and 144 deletions.
10 changes: 6 additions & 4 deletions examples/Cpp/ClothPhysics/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<int>(stiffnessFactor * 100.0f) << "% \r";
std::flush(std::cout);
LLGL::Log::Printf("stiffness: %d\% \r", static_cast<int>(stiffnessFactor * 100.0f));
::fflush(stdout);
}

// Update timer
Expand Down
2 changes: 1 addition & 1 deletion examples/Cpp/ExampleBase/ExampleBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions examples/Cpp/Instancing/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions examples/Cpp/MultiRenderer/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ void MyRenderer::CreateResources(const LLGL::ArrayView<TexturedVertex>& 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());
}
}

Expand Down Expand Up @@ -235,7 +235,7 @@ void MyRenderer::CreateResources(const LLGL::ArrayView<TexturedVertex>& 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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions examples/Cpp/PBR/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 9 additions & 7 deletions examples/Cpp/Queries/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<double>(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<unsigned>(stats.inputAssemblyPrimitives),
static_cast<unsigned>(stats.vertexShaderInvocations),
static_cast<unsigned>(stats.fragmentShaderInvocations),
static_cast<double>(elapsedTime)/1000000.0
);
::fflush(stdout);
}

void SetBoxTransformAndColor(const Gs::Matrix4f& matrix, const LLGL::ColorRGBAf& color)
Expand Down
8 changes: 5 additions & 3 deletions examples/Cpp/RenderTarget/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion examples/Cpp/ResourceBinding/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 5 additions & 3 deletions examples/Cpp/ShadowMapping/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 5 additions & 3 deletions examples/Cpp/StencilBuffer/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 12 additions & 6 deletions examples/Cpp/Tessellation/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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<double>(settings.tessLevelInner),
static_cast<double>(settings.tessLevelOuter)
);
::fflush(stdout);*/
}

private:
Expand Down
23 changes: 16 additions & 7 deletions examples/Cpp/Texturing/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -155,8 +158,8 @@ class Example_Texturing : public ExampleBase
}
colorMaps[1] = renderer->CreateTexture(texDesc, &imageView);
}
auto texCreationTime = static_cast<double>(timer.Stop()) / static_cast<double>(timer.GetFrequency());
std::cout << "texture creation time: " << (texCreationTime * 1000.0) << " ms" << std::endl;
double texCreationTime = static_cast<double>(timer.Stop()) / static_cast<double>(timer.GetFrequency());
LLGL::Log::Printf("texture creation time: %f ms\n", texCreationTime * 1000.0);

// Release image data
stbi_image_free(imageBuffer);
Expand Down Expand Up @@ -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
Expand Down
13 changes: 9 additions & 4 deletions examples/Cpp/VolumeRendering/Example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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<int>(settings.threshold*200.0f) << "% \r";
std::flush(std::cout);
LLGL::Log::Printf(
"density threshold: %d\% \r",
static_cast<int>(settings.threshold*200.0f)
);
::fflush(stdout);
}

// Rotate model around X and Y axes
Expand Down
18 changes: 9 additions & 9 deletions include/LLGL/Display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/Log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/RenderSystemFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
Expand Down
2 changes: 1 addition & 1 deletion include/LLGL/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<double>(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
*/
Expand Down
14 changes: 9 additions & 5 deletions tests/Test_Compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <LLGL/Utils/Parse.h>
#include <Gauss/Gauss.h>
#include <vector>
#include <iostream>

// Fill an array list of 4D-vectors for testing purposes
static std::vector<Gs::Vector4f> GetTestVector(std::size_t size)
Expand All @@ -29,6 +28,8 @@ int main()
{
try
{
LLGL::Log::RegisterCallbackStd();

// Setup profiler and debugger
auto debugger = std::make_shared<LLGL::RenderingDebugger>();

Expand Down Expand Up @@ -116,7 +117,7 @@ int main()
{
/* wait until the result is available */
}
std::cout << "compute shader duration: " << static_cast<double>(result) / 1000000 << " ms" << std::endl;
LLGL::Log::Printf("compute shader duration: %f ms\n", static_cast<double>(result) / 1000000);

// Wait until the GPU has completed all work, to be sure we can evaluate the storage buffer
renderer->GetCommandQueue()->WaitIdle();
Expand All @@ -125,14 +126,17 @@ int main()
if (auto mappedBuffer = renderer->MapBuffer(*storageBuffer, LLGL::CPUAccess::ReadOnly))
{
// Show result
auto vecBuffer = reinterpret_cast<const Gs::Vector4f*>(mappedBuffer);
std::cout << "compute shader output: average vector = " << vecBuffer[0] << std::endl;
auto* vecBuffer = reinterpret_cast<const Gs::Vector4f*>(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
Expand Down
Loading

0 comments on commit eaa1d70

Please sign in to comment.