From 906f615a9e5f5eba4f48b049c27e25ba486cf9b8 Mon Sep 17 00:00:00 2001 From: Sasha Szpakowski Date: Mon, 15 Jul 2024 17:55:31 -0300 Subject: [PATCH] disallow texture:replacePixels and non-canvas textures for depth/stencil pixel formats. --- src/modules/graphics/Graphics.cpp | 16 +++++++++++----- src/modules/graphics/Texture.cpp | 6 ++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 915d12f88..5c6f3c517 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -547,6 +547,7 @@ Texture *Graphics::getDefaultTexture(TextureType type, DataBaseType dataType, bo Texture::Settings settings; settings.type = type; + settings.readable.set(true); switch (dataType) { @@ -564,6 +565,8 @@ Texture *Graphics::getDefaultTexture(TextureType type, DataBaseType dataType, bo if (depthSample) { + settings.renderTarget = true; + if (isPixelFormatSupported(PIXELFORMAT_DEPTH16_UNORM, PIXELFORMATUSAGE_SAMPLE)) settings.format = PIXELFORMAT_DEPTH16_UNORM; else if (isPixelFormatSupported(PIXELFORMAT_DEPTH24_UNORM, PIXELFORMATUSAGE_SAMPLE)) @@ -597,12 +600,15 @@ Texture *Graphics::getDefaultTexture(TextureType type, DataBaseType dataType, bo tex->setSamplerState(s); - uint8 pixel[] = {255, 255, 255, 255}; - if (isPixelFormatInteger(settings.format)) - pixel[0] = pixel[1] = pixel[2] = pixel[3] = 1; + if (!depthSample) + { + uint8 pixel[] = {255, 255, 255, 255}; + if (isPixelFormatInteger(settings.format)) + pixel[0] = pixel[1] = pixel[2] = pixel[3] = 1; - for (int slice = 0; slice < (type == TEXTURE_CUBE ? 6 : 1); slice++) - tex->replacePixels(pixel, sizeof(pixel), slice, 0, {0, 0, 1, 1}, false); + for (int slice = 0; slice < (type == TEXTURE_CUBE ? 6 : 1); slice++) + tex->replacePixels(pixel, sizeof(pixel), slice, 0, {0, 0, 1, 1}, false); + } defaultTextures[type][dataType][depthsampleindex] = tex; diff --git a/src/modules/graphics/Texture.cpp b/src/modules/graphics/Texture.cpp index bd777df3d..1cb91dbc7 100644 --- a/src/modules/graphics/Texture.cpp +++ b/src/modules/graphics/Texture.cpp @@ -284,6 +284,9 @@ Texture::Texture(Graphics *gfx, const Settings &settings, const Slices *slices) if (isCompressed() && renderTarget) throw love::Exception("Compressed textures cannot be render targets."); + if (isPixelFormatDepthStencil(format) && !renderTarget) + throw love::Exception("Depth or stencil pixel formats are only supported with render target textures."); + for (PixelFormat viewformat : viewFormats) { if (getLinearPixelFormat(viewformat) == getLinearPixelFormat(format)) @@ -582,6 +585,9 @@ void Texture::replacePixels(love::image::ImageDataBase *d, int slice, int mipmap if (getMSAA() > 1) throw love::Exception("replacePixels cannot be called on a MSAA Texture."); + if (isPixelFormatDepthStencil(format)) + throw love::Exception("replacePixels cannot be called on depth or stencil Textures."); + auto gfx = Module::getInstance(Module::M_GRAPHICS); if (gfx != nullptr && gfx->isRenderTargetActive(this)) throw love::Exception("replacePixels cannot be called on this Texture while it's an active render target.");