#include "LayerRenderingContext.h" #include "../ManagementContext/LayerManagmentContext.h" Texture* LayerRenderingContext::CompositeAll(std::vector layers) // TODO: remove parameter { if (!finalComposite) { SDL_GPUTextureCreateInfo creationInfo = {}; creationInfo.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM; // TODO: make this configurable creationInfo.width = LayerManagementContext::FinalWidth; creationInfo.height = LayerManagementContext::FinalHeight; creationInfo.layer_count_or_depth = 1; creationInfo.num_levels = 1; creationInfo.sample_count = SDL_GPU_SAMPLECOUNT_1; creationInfo.usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER; finalComposite = new Texture(creationInfo); } finalComposite->Clear({ 0.0f, 0.0f, 0.0f, 0.0f }); for (auto layer : layers) { layer->Composite(finalComposite); } return finalComposite; } #include "../LayerNodes/PaintLayerNode.h" Texture* LayerRenderingContext::CompositeReplacedSelectedLayer(Texture* replacement) { if (!finalComposite) { SDL_GPUTextureCreateInfo creationInfo = {}; creationInfo.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM; // TODO: make this configurable creationInfo.width = LayerManagementContext::FinalWidth; creationInfo.height = LayerManagementContext::FinalHeight; creationInfo.layer_count_or_depth = 1; creationInfo.num_levels = 1; creationInfo.sample_count = SDL_GPU_SAMPLECOUNT_1; creationInfo.usage = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER; finalComposite = new Texture(creationInfo); } finalComposite->Clear({ 0.0f, 0.0f, 0.0f, 0.0f }); for (auto layer : LayerManagementContext::Layers) { if (layer == LayerManagementContext::SelectedLayer) { PaintLayerNode* paintLayer = new PaintLayerNode(); paintLayer->Target = replacement; paintLayer->BlendMode = LayerManagementContext::SelectedLayer->BlendMode; paintLayer->Opacity = LayerManagementContext::SelectedLayer->Opacity; paintLayer->Composite(finalComposite); paintLayer->Target = nullptr; delete paintLayer; } else { layer->Composite(finalComposite); } } return finalComposite; }