From d0de60dc33df75fbcacb53a09568b14d0fd48cb9 Mon Sep 17 00:00:00 2001 From: Mel Date: Mon, 12 Jun 2023 17:09:55 +0200 Subject: Multithreaded world generation with Perlin --- src/GFX/Image/RawImage.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/GFX/Image/RawImage.cpp') diff --git a/src/GFX/Image/RawImage.cpp b/src/GFX/Image/RawImage.cpp index aca8fbc..1222fab 100644 --- a/src/GFX/Image/RawImage.cpp +++ b/src/GFX/Image/RawImage.cpp @@ -2,6 +2,19 @@ namespace MC::GFX::Image { +RawImage::RawImage(Util::Sampler<2, float>& sampler, uint32_t width, uint32_t height) + : m_pixels(), m_width(width), m_height(height) +{ + m_pixels.reserve(width * height); + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + auto result = sampler.sample({(float)x, (float)y}); + auto intensity = (uint8_t)(result * 255); + add({intensity, intensity, intensity}); + } + } +} + void RawImage::add(RawImage::Pixel pixel) { m_pixels.push_back(pixel); } @@ -26,4 +39,19 @@ uint8_t RawImage::channels() const { return m_channels; } +std::string RawImage::string() const { + std::stringstream str{}; + + bool comma = false; + str << "["; + for (const auto& pixel : m_pixels) { + if (comma) { str << ", "; } + str << "{r=" << (uint)pixel.r << ", g=" << (uint)pixel.g << ", b=" << (uint)pixel.r << "}"; + comma = true; + } + str << "]"; + + return str.str(); +} + } \ No newline at end of file -- cgit 1.4.1