From ac90f8e60b1c971c342cdd98769388563e157557 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 15 Mar 2023 02:10:31 +0000 Subject: Populate super texture with fragments This is kinda buggy due to TexturePacker sorting its input array and the client having no idea the order of the results. --- assetFactory/assetFactory.cpp | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/assetFactory.cpp b/assetFactory/assetFactory.cpp index 276c258..77dd554 100644 --- a/assetFactory/assetFactory.cpp +++ b/assetFactory/assetFactory.cpp @@ -118,21 +118,25 @@ AssetFactory::createTexutre() const }); const auto [layout, outSize] = TexturePacker {imageSizes}.pack(); // * create texture - std::vector textureData(TexturePacker::area(outSize), {127, 127, 127, 255}); + texture = std::make_shared(outSize.x, outSize.y, TextureOptions {.wrap = GL_CLAMP_TO_EDGE}); std::transform(textureFragments.begin(), textureFragments.end(), std::inserter(textureFragmentPositions, textureFragmentPositions.end()), - [position = layout.begin(), size = imageSizes.begin(), outSize = outSize](const auto & tf) mutable { - const glm::vec4 positionFraction { - static_cast(position->x) / static_cast(outSize.x), - static_cast(position->y) / static_cast(outSize.y), - static_cast(position->x + size->x) / static_cast(outSize.x), - static_cast(position->y + size->y) / static_cast(outSize.y), + [position = layout.begin(), image = images.begin(), size = imageSizes.begin(), + outSize = glm::vec2 {outSize}](const auto & tf) mutable { + glm::vec4 positionFraction { + static_cast(position->x) / outSize.x, + static_cast(position->y) / outSize.y, + static_cast(position->x + size->x) / outSize.x, + static_cast(position->y + size->y) / outSize.y, }; + glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(position->x), static_cast(position->y), + static_cast(size->x), static_cast(size->y), GL_RGBA, GL_UNSIGNED_BYTE, + image->get()->data.data()); position++; + image++; size++; return decltype(textureFragmentPositions)::value_type {tf.first, positionFraction}; }); - texture = std::make_shared(outSize.x, outSize.y, textureData.data()); } } -- cgit v1.2.3