diff --git a/CMakeLists.txt b/CMakeLists.txt index 52d259cb6..1413f57ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -518,8 +518,6 @@ source_group("modules\\font\\freetype" FILES ${LOVE_SRC_MODULE_FONT_FREETYPE}) set(LOVE_SRC_MODULE_GRAPHICS_ROOT src/modules/graphics/Buffer.cpp src/modules/graphics/Buffer.h - src/modules/graphics/Canvas.cpp - src/modules/graphics/Canvas.h src/modules/graphics/Deprecations.cpp src/modules/graphics/Deprecations.h src/modules/graphics/Drawable.cpp @@ -528,8 +526,6 @@ set(LOVE_SRC_MODULE_GRAPHICS_ROOT src/modules/graphics/Font.h src/modules/graphics/Graphics.cpp src/modules/graphics/Graphics.h - src/modules/graphics/Image.cpp - src/modules/graphics/Image.h src/modules/graphics/Mesh.cpp src/modules/graphics/Mesh.h src/modules/graphics/ParticleSystem.cpp diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index 44419670b..73496ae8a 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -787,9 +787,6 @@ FA1BA0A21E16D97500AA2803 /* wrap_Font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA1BA0A01E16D97500AA2803 /* wrap_Font.cpp */; }; FA1BA0A31E16D97500AA2803 /* wrap_Font.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA1BA0A01E16D97500AA2803 /* wrap_Font.cpp */; }; FA1BA0A41E16D97500AA2803 /* wrap_Font.h in Headers */ = {isa = PBXBuildFile; fileRef = FA1BA0A11E16D97500AA2803 /* wrap_Font.h */; }; - FA1BA0A71E16F20600AA2803 /* Canvas.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA1BA0A51E16F20600AA2803 /* Canvas.cpp */; }; - FA1BA0A81E16F20600AA2803 /* Canvas.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA1BA0A51E16F20600AA2803 /* Canvas.cpp */; }; - FA1BA0A91E16F20600AA2803 /* Canvas.h in Headers */ = {isa = PBXBuildFile; fileRef = FA1BA0A61E16F20600AA2803 /* Canvas.h */; }; FA1BA0B11E16FD0800AA2803 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA1BA0AF1E16FD0800AA2803 /* Shader.cpp */; }; FA1BA0B21E16FD0800AA2803 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA1BA0AF1E16FD0800AA2803 /* Shader.cpp */; }; FA1BA0B31E16FD0800AA2803 /* Shader.h in Headers */ = {isa = PBXBuildFile; fileRef = FA1BA0B01E16FD0800AA2803 /* Shader.h */; }; @@ -1057,9 +1054,6 @@ FADF540E1E3D7CDD00012CC0 /* wrap_Video.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF540A1E3D7CDD00012CC0 /* wrap_Video.cpp */; }; FADF540F1E3D7CDD00012CC0 /* wrap_Video.h in Headers */ = {isa = PBXBuildFile; fileRef = FADF540B1E3D7CDD00012CC0 /* wrap_Video.h */; }; FADF54101E3D7CDD00012CC0 /* wrap_Video.lua in Resources */ = {isa = PBXBuildFile; fileRef = FADF540C1E3D7CDD00012CC0 /* wrap_Video.lua */; }; - FADF54161E3DA08E00012CC0 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF54141E3DA08E00012CC0 /* Image.cpp */; }; - FADF54171E3DA08E00012CC0 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF54141E3DA08E00012CC0 /* Image.cpp */; }; - FADF54181E3DA08E00012CC0 /* Image.h in Headers */ = {isa = PBXBuildFile; fileRef = FADF54151E3DA08E00012CC0 /* Image.h */; }; FADF54201E3DA52C00012CC0 /* wrap_ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF541E1E3DA52C00012CC0 /* wrap_ParticleSystem.cpp */; }; FADF54211E3DA52C00012CC0 /* wrap_ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF541E1E3DA52C00012CC0 /* wrap_ParticleSystem.cpp */; }; FADF54221E3DA52C00012CC0 /* wrap_ParticleSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = FADF541F1E3DA52C00012CC0 /* wrap_ParticleSystem.h */; }; @@ -1799,8 +1793,6 @@ FA1BA09C1E16CFCE00AA2803 /* Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Font.h; sourceTree = ""; }; FA1BA0A01E16D97500AA2803 /* wrap_Font.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Font.cpp; sourceTree = ""; }; FA1BA0A11E16D97500AA2803 /* wrap_Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Font.h; sourceTree = ""; }; - FA1BA0A51E16F20600AA2803 /* Canvas.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Canvas.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; - FA1BA0A61E16F20600AA2803 /* Canvas.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = Canvas.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; FA1BA0AF1E16FD0800AA2803 /* Shader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Shader.cpp; sourceTree = ""; }; FA1BA0B01E16FD0800AA2803 /* Shader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Shader.h; sourceTree = ""; }; FA1BA0B51E17043400AA2803 /* wrap_Shader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Shader.cpp; sourceTree = ""; }; @@ -2001,8 +1993,6 @@ FADF540A1E3D7CDD00012CC0 /* wrap_Video.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Video.cpp; sourceTree = ""; }; FADF540B1E3D7CDD00012CC0 /* wrap_Video.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Video.h; sourceTree = ""; }; FADF540C1E3D7CDD00012CC0 /* wrap_Video.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = wrap_Video.lua; sourceTree = ""; }; - FADF54141E3DA08E00012CC0 /* Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Image.cpp; sourceTree = ""; }; - FADF54151E3DA08E00012CC0 /* Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Image.h; sourceTree = ""; }; FADF541E1E3DA52C00012CC0 /* wrap_ParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_ParticleSystem.cpp; sourceTree = ""; }; FADF541F1E3DA52C00012CC0 /* wrap_ParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_ParticleSystem.h; sourceTree = ""; }; FADF54231E3DA5BA00012CC0 /* Mesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Mesh.cpp; sourceTree = ""; }; @@ -2827,8 +2817,6 @@ children = ( FADF53F61E3C7ACD00012CC0 /* Buffer.cpp */, FADF53F71E3C7ACD00012CC0 /* Buffer.h */, - FA1BA0A51E16F20600AA2803 /* Canvas.cpp */, - FA1BA0A61E16F20600AA2803 /* Canvas.h */, FA9D53AA1F5307E900125C6B /* Deprecations.cpp */, FA9D53AB1F5307E900125C6B /* Deprecations.h */, FA9D8DDC1DEF842A002CD881 /* Drawable.cpp */, @@ -2837,8 +2825,6 @@ FA1BA09C1E16CFCE00AA2803 /* Font.h */, FA0B7B8A1A95902C000E1D17 /* Graphics.cpp */, FA0B7B8B1A95902C000E1D17 /* Graphics.h */, - FADF54141E3DA08E00012CC0 /* Image.cpp */, - FADF54151E3DA08E00012CC0 /* Image.h */, FADF54231E3DA5BA00012CC0 /* Mesh.cpp */, FADF54241E3DA5BA00012CC0 /* Mesh.h */, FA0B7B8C1A95902C000E1D17 /* opengl */, @@ -3959,7 +3945,6 @@ FAB17BE81ABFAA9000F9BA27 /* lz4.h in Headers */, FA0B7E6B1A95902C000E1D17 /* wrap_PulleyJoint.h in Headers */, FA0B7E051A95902C000E1D17 /* Contact.h in Headers */, - FA1BA0A91E16F20600AA2803 /* Canvas.h in Headers */, FA0B7A691A958EA3000E1D17 /* b2Island.h in Headers */, FA4F2BE41DE6650600CA37D7 /* Transform.h in Headers */, FA0B7E0E1A95902C000E1D17 /* Fixture.h in Headers */, @@ -4037,7 +4022,6 @@ FA0B7A601A958EA3000E1D17 /* b2Body.h in Headers */, FA0B7EAB1A95902C000E1D17 /* wrap_Sound.h in Headers */, FA0B7B2C1A958EA3000E1D17 /* checked.h in Headers */, - FADF54181E3DA08E00012CC0 /* Image.h in Headers */, FA0B7D2A1A95902C000E1D17 /* wrap_GlyphData.h in Headers */, FACA02F11F5E396B0084B28F /* DataModule.h in Headers */, FA0B7E741A95902C000E1D17 /* wrap_Shape.h in Headers */, @@ -4645,9 +4629,7 @@ FA0B7EAD1A95902C000E1D17 /* wrap_SoundData.cpp in Sources */, FA0B7E2E1A95902C000E1D17 /* RopeJoint.cpp in Sources */, FA0B7CE01A95902C000E1D17 /* Source.cpp in Sources */, - FADF54171E3DA08E00012CC0 /* Image.cpp in Sources */, FA0B7ECF1A95902C000E1D17 /* wrap_LuaThread.cpp in Sources */, - FA1BA0A81E16F20600AA2803 /* Canvas.cpp in Sources */, FA0B7AA51A958EA3000E1D17 /* b2RevoluteJoint.cpp in Sources */, FA0B7EA11A95902C000E1D17 /* Sound.cpp in Sources */, FA0B7DE61A95902C000E1D17 /* Cursor.cpp in Sources */, @@ -5044,9 +5026,7 @@ FA4F2BE31DE6650600CA37D7 /* Transform.cpp in Sources */, FA0B7EA01A95902C000E1D17 /* Sound.cpp in Sources */, FA0B7DE51A95902C000E1D17 /* Cursor.cpp in Sources */, - FADF54161E3DA08E00012CC0 /* Image.cpp in Sources */, FA0B7EDB1A95902D000E1D17 /* Touch.cpp in Sources */, - FA1BA0A71E16F20600AA2803 /* Canvas.cpp in Sources */, FA0B7CE81A95902C000E1D17 /* Event.cpp in Sources */, FA0B7ACF1A958EA3000E1D17 /* peer.c in Sources */, FA0B7ADE1A958EA3000E1D17 /* lodepng.cpp in Sources */, diff --git a/src/modules/graphics/Canvas.cpp b/src/modules/graphics/Canvas.cpp deleted file mode 100644 index c13b1e038..000000000 --- a/src/modules/graphics/Canvas.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/** - * Copyright (c) 2006-2020 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#include "Canvas.h" -#include "Graphics.h" - -namespace love -{ -namespace graphics -{ - -love::Type Canvas::type("Canvas", &Texture::type); - -Canvas::Canvas(const Settings &settings) - : Texture(settings.type) -{ - this->settings = settings; - - renderTarget = true; - sRGB = false; - requestedMSAA = settings.msaa; - - mipmapsMode = settings.mipmaps; - width = settings.width; - height = settings.height; - pixelWidth = (int) ((width * settings.dpiScale) + 0.5); - pixelHeight = (int) ((height * settings.dpiScale) + 0.5); - - format = settings.format; - - if (texType == TEXTURE_VOLUME) - depth = settings.layers; - else if (texType == TEXTURE_2D_ARRAY) - layers = settings.layers; - - if (width <= 0 || height <= 0 || layers <= 0) - throw love::Exception("Canvas dimensions must be greater than 0."); - - if (texType != TEXTURE_2D && settings.msaa > 1) - throw love::Exception("MSAA is only supported for Canvases with the 2D texture type."); - - if (settings.readable.hasValue) - readable = settings.readable.value; - else - readable = !isPixelFormatDepthStencil(format); - - if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1) - throw love::Exception("Readable depth/stencil Canvases with MSAA are not currently supported."); - - if ((!readable || settings.msaa > 1) && mipmapsMode != MIPMAPS_NONE) - throw love::Exception("Non-readable and MSAA textures cannot have mipmaps."); - - if (mipmapsMode != MIPMAPS_NONE) - mipmapCount = getTotalMipmapCount(pixelWidth, pixelHeight, depth); - - auto gfx = Module::getInstance(Module::M_GRAPHICS); - const Graphics::Capabilities &caps = gfx->getCapabilities(); - - if (!gfx->isPixelFormatSupported(format, renderTarget, readable, sRGB)) - { - const char *fstr = "rgba8"; - const char *readablestr = ""; - if (readable != !isPixelFormatDepthStencil(format)) - readablestr = readable ? " readable" : " non-readable"; - love::getConstant(format, fstr); - throw love::Exception("The %s%s canvas format is not supported by your graphics drivers.", fstr, readablestr); - } - - if (getRequestedMSAA() > 1 && texType != TEXTURE_2D) - throw love::Exception("MSAA is only supported for 2D texture types."); - - if (!readable && texType != TEXTURE_2D) - throw love::Exception("Non-readable pixel formats are only supported for 2D texture types."); - - if (!caps.textureTypes[texType]) - { - const char *textypestr = "unknown"; - Texture::getConstant(texType, textypestr); - throw love::Exception("%s textures are not supported on this system!", textypestr); - } - - validateDimensions(true); -} - -Canvas::~Canvas() -{ -} - -bool Canvas::getConstant(const char *in, SettingType &out) -{ - return settingTypes.find(in, out); -} - -bool Canvas::getConstant(SettingType in, const char *&out) -{ - return settingTypes.find(in, out); -} - -const char *Canvas::getConstant(SettingType in) -{ - const char *name = nullptr; - getConstant(in, name); - return name; -} - -std::vector Canvas::getConstants(SettingType) -{ - return settingTypes.getNames(); -} - -StringMap::Entry Canvas::settingTypeEntries[] = -{ - // Width / height / layers are currently omittted because they're separate - // arguments to newCanvas in the wrapper code. - { "mipmaps", SETTING_MIPMAPS }, - { "format", SETTING_FORMAT }, - { "type", SETTING_TYPE }, - { "dpiscale", SETTING_DPI_SCALE }, - { "msaa", SETTING_MSAA }, - { "readable", SETTING_READABLE }, -}; - -StringMap Canvas::settingTypes(Canvas::settingTypeEntries, sizeof(Canvas::settingTypeEntries)); - -} // graphics -} // love - diff --git a/src/modules/graphics/Canvas.h b/src/modules/graphics/Canvas.h deleted file mode 100644 index 9c77152b2..000000000 --- a/src/modules/graphics/Canvas.h +++ /dev/null @@ -1,89 +0,0 @@ -/** -* Copyright (c) 2006-2020 LOVE Development Team -* -* This software is provided 'as-is', without any express or implied -* warranty. In no event will the authors be held liable for any damages -* arising from the use of this software. -* -* Permission is granted to anyone to use this software for any purpose, -* including commercial applications, and to alter it and redistribute it -* freely, subject to the following restrictions: -* -* 1. The origin of this software must not be misrepresented; you must not -* claim that you wrote the original software. If you use this software -* in a product, an acknowledgment in the product documentation would be -* appreciated but is not required. -* 2. Altered source versions must be plainly marked as such, and must not be -* misrepresented as being the original software. -* 3. This notice may not be removed or altered from any source distribution. -**/ - -#pragma once - -#include "image/Image.h" -#include "image/ImageData.h" -#include "Texture.h" -#include "common/Optional.h" -#include "common/StringMap.h" - -namespace love -{ -namespace graphics -{ - -class Graphics; - -class Canvas : public Texture -{ -public: - - static love::Type type; - - enum SettingType - { - SETTING_WIDTH, - SETTING_HEIGHT, - SETTING_LAYERS, - SETTING_MIPMAPS, - SETTING_FORMAT, - SETTING_TYPE, - SETTING_DPI_SCALE, - SETTING_MSAA, - SETTING_READABLE, - SETTING_MAX_ENUM - }; - - struct Settings - { - int width = 1; - int height = 1; - int layers = 1; // depth for 3D textures - MipmapsMode mipmaps = MIPMAPS_NONE; - PixelFormat format = PIXELFORMAT_NORMAL; - TextureType type = TEXTURE_2D; - float dpiScale = 1.0f; - int msaa = 0; - OptionalBool readable; - }; - - Canvas(const Settings &settings); - virtual ~Canvas(); - - static bool getConstant(const char *in, SettingType &out); - static bool getConstant(SettingType in, const char *&out); - static const char *getConstant(SettingType in); - static std::vector getConstants(SettingType); - -protected: - - Settings settings; - -private: - - static StringMap::Entry settingTypeEntries[]; - static StringMap settingTypes; - -}; // Canvas - -} // graphics -} // love diff --git a/src/modules/graphics/Font.cpp b/src/modules/graphics/Font.cpp index 46730e969..97f82572a 100644 --- a/src/modules/graphics/Font.cpp +++ b/src/modules/graphics/Font.cpp @@ -150,8 +150,11 @@ void Font::createTexture() textures.pop_back(); } - Image::Settings settings; - texture = gfx->newImage(TEXTURE_2D, pixelFormat, size.width, size.height, 1, settings); + Texture::Settings settings; + settings.format = pixelFormat; + settings.width = size.width; + settings.height = size.height; + texture = gfx->newImage(settings, nullptr); texture->setSamplerState(samplerState); { diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index c0a5a2f1f..c76c0afc3 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -820,7 +820,7 @@ Texture *Graphics::getTemporaryTexture(PixelFormat format, int w, int h, int sam if (texture == nullptr) { - Canvas::Settings settings; + Texture::Settings settings; settings.format = format; settings.width = w; settings.height = h; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 24a42bf29..f7bf99529 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -32,13 +32,11 @@ #include "StreamBuffer.h" #include "vertex.h" #include "Texture.h" -#include "Canvas.h" #include "Font.h" #include "ShaderStage.h" #include "Shader.h" #include "Quad.h" #include "Mesh.h" -#include "Image.h" #include "Deprecations.h" #include "renderstate.h" #include "math/Transform.h" @@ -428,8 +426,7 @@ public: // Implements Module. virtual ModuleType getModuleType() const { return M_GRAPHICS; } - virtual Texture *newImage(const Texture::Slices &data, const Image::Settings &settings) = 0; - virtual Texture *newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) = 0; + virtual Texture *newImage(const Texture::Settings &settings, const Texture::Slices *data) = 0; Quad *newQuad(Quad::Viewport v, double sw, double sh); Font *newFont(love::font::Rasterizer *data); @@ -439,7 +436,7 @@ public: SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage); ParticleSystem *newParticleSystem(Texture *texture, int size); - virtual Texture *newCanvas(const Canvas::Settings &settings) = 0; + virtual Texture *newCanvas(const Texture::Settings &settings) = 0; ShaderStage *newShaderStage(ShaderStage::StageType stage, const std::string &source); Shader *newShader(const std::string &vertex, const std::string &pixel); diff --git a/src/modules/graphics/Image.cpp b/src/modules/graphics/Image.cpp deleted file mode 100644 index 63d3694b7..000000000 --- a/src/modules/graphics/Image.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/** - * Copyright (c) 2006-2020 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#include "Image.h" -#include "Graphics.h" - -// C++ -#include - -namespace love -{ -namespace graphics -{ - -love::Type Image::type("Image", &Texture::type); - -Image::Image(TextureType textype, const Settings &settings) - : Texture(textype) - , settings(settings) -{ - renderTarget = false; - sRGB = isGammaCorrect() && !settings.linear; -} - -Image::Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings) - : Image(textype, settings) -{ - if (isPixelFormatCompressed(format)) - throw love::Exception("This constructor is only supported for non-compressed pixel formats."); - - if (textype == TEXTURE_2D_ARRAY) - layers = slices; - else if (textype == TEXTURE_VOLUME) - depth = slices; - - init(format, width, height, 1, settings); -} - -Image::Image(const Slices &slices, const Settings &settings) - : Image(slices.getTextureType(), settings) -{ - int dataMipmaps = 1; - if (slices.validate() && slices.getMipmapCount() > 1) - dataMipmaps = slices.getMipmapCount(); - - if (texType == TEXTURE_2D_ARRAY) - this->layers = slices.getSliceCount(); - else if (texType == TEXTURE_VOLUME) - this->depth = slices.getSliceCount(); - - love::image::ImageDataBase *slice = slices.get(0, 0); - init(slice->getFormat(), slice->getWidth(), slice->getHeight(), dataMipmaps, settings); -} - -Image::~Image() -{ -} - -void Image::init(PixelFormat fmt, int w, int h, int dataMipmaps, const Settings &settings) -{ - Graphics *gfx = Module::getInstance(Module::M_GRAPHICS); - if (gfx != nullptr && !gfx->isPixelFormatSupported(fmt, renderTarget, readable, sRGB)) - { - const char *str; - if (love::getConstant(fmt, str)) - { - throw love::Exception("Cannot create image: " - "%s%s images are not supported on this system.", sRGB ? "sRGB " : "", str); - } - else - throw love::Exception("cannot create image: format is not supported on this system."); - } - - pixelWidth = w; - pixelHeight = h; - mipmapsMode = settings.mipmaps ? MIPMAPS_MANUAL : MIPMAPS_NONE; - - width = (int) (pixelWidth / settings.dpiScale + 0.5); - height = (int) (pixelHeight / settings.dpiScale + 0.5); - - format = fmt; - - if (mipmapsMode == MIPMAPS_NONE || (isCompressed() && dataMipmaps <= 1)) - mipmapCount = 1; - else - mipmapCount = getTotalMipmapCount(w, h, depth); - - initQuad(); -} - -bool Image::getConstant(const char *in, SettingType &out) -{ - return settingTypes.find(in, out); -} - -bool Image::getConstant(SettingType in, const char *&out) -{ - return settingTypes.find(in, out); -} - -const char *Image::getConstant(SettingType in) -{ - const char *name = nullptr; - getConstant(in, name); - return name; -} - -std::vector Image::getConstants(SettingType) -{ - return settingTypes.getNames(); -} - -StringMap::Entry Image::settingTypeEntries[] = -{ - { "mipmaps", SETTING_MIPMAPS }, - { "linear", SETTING_LINEAR }, - { "dpiscale", SETTING_DPI_SCALE }, -}; - -StringMap Image::settingTypes(Image::settingTypeEntries, sizeof(Image::settingTypeEntries)); - -} // graphics -} // love diff --git a/src/modules/graphics/Image.h b/src/modules/graphics/Image.h deleted file mode 100644 index 9893f7d8f..000000000 --- a/src/modules/graphics/Image.h +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2006-2020 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#pragma once - -// LOVE -#include "common/config.h" -#include "common/StringMap.h" -#include "common/math.h" -#include "Texture.h" - -namespace love -{ -namespace graphics -{ - -class Image : public Texture -{ -public: - - static love::Type type; - - enum SettingType - { - SETTING_MIPMAPS, - SETTING_LINEAR, - SETTING_DPI_SCALE, - SETTING_MAX_ENUM - }; - - struct Settings - { - bool mipmaps = false; - bool linear = false; - float dpiScale = 1.0f; - }; - - virtual ~Image(); - - static bool getConstant(const char *in, SettingType &out); - static bool getConstant(SettingType in, const char *&out); - static const char *getConstant(SettingType in); - static std::vector getConstants(SettingType); - -protected: - - Image(const Slices &data, const Settings &settings); - Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings); - - // The settings used to initialize this Image. - Settings settings; - -private: - - Image(TextureType textype, const Settings &settings); - - void init(PixelFormat fmt, int w, int h, int dataMipmaps, const Settings &settings); - - static StringMap::Entry settingTypeEntries[]; - static StringMap settingTypes; - -}; // Image - -} // graphics -} // love diff --git a/src/modules/graphics/Texture.cpp b/src/modules/graphics/Texture.cpp index 2f0131f00..3a7e73061 100644 --- a/src/modules/graphics/Texture.cpp +++ b/src/modules/graphics/Texture.cpp @@ -159,28 +159,122 @@ love::Type Texture::type("Texture", &Drawable::type); int Texture::textureCount = 0; int64 Texture::totalGraphicsMemory = 0; -Texture::Texture(TextureType texType) - : texType(texType) - , format(PIXELFORMAT_UNKNOWN) - , renderTarget(false) +Texture::Texture(const Settings &settings, const Slices *slices) + : texType(settings.type) + , format(settings.format) + , renderTarget(settings.renderTarget) , readable(true) - , mipmapsMode(MIPMAPS_NONE) - , sRGB(false) - , width(0) - , height(0) - , depth(1) - , layers(1) + , mipmapsMode(settings.mipmaps) + , sRGB(isGammaCorrect() && !settings.linear) + , width(settings.width) + , height(settings.height) + , depth(settings.type == TEXTURE_VOLUME ? settings.layers : 1) + , layers(settings.type == TEXTURE_2D_ARRAY ? settings.layers : 1) , mipmapCount(1) , pixelWidth(0) , pixelHeight(0) - , requestedMSAA(1) + , requestedMSAA(settings.msaa) , samplerState() , graphicsMemorySize(0) , usingDefaultTexture(false) { auto gfx = Module::getInstance(Module::M_GRAPHICS); - if (gfx != nullptr) - samplerState = gfx->getDefaultSamplerState(); + + if (slices != nullptr && slices->getMipmapCount() > 0 && slices->getSliceCount() > 0) + { + texType = slices->getTextureType(); + + int dataMipmaps = 1; + if (slices->validate() && slices->getMipmapCount() > 1) + dataMipmaps = slices->getMipmapCount(); + + love::image::ImageDataBase *slice = slices->get(0, 0); + + format = slice->getFormat(); + + pixelWidth = slice->getWidth(); + pixelHeight = slice->getHeight(); + + if (texType == TEXTURE_2D_ARRAY) + layers = slices->getSliceCount(); + else if (texType == TEXTURE_VOLUME) + depth = slices->getSliceCount(); + + width = (int) (pixelWidth / settings.dpiScale + 0.5); + height = (int) (pixelHeight / settings.dpiScale + 0.5); + + if (isCompressed() && dataMipmaps <= 1) + mipmapsMode = MIPMAPS_NONE; + } + else + { + if (isCompressed()) + throw love::Exception("Compressed textures must be created with initial data."); + + pixelWidth = (int) ((width * settings.dpiScale) + 0.5); + pixelHeight = (int) ((height * settings.dpiScale) + 0.5); + } + + if (settings.readable.hasValue) + readable = settings.readable.value; + else + readable = !isPixelFormatDepthStencil(format); + + format = gfx->getSizedFormat(format, renderTarget, readable, sRGB); + + if (mipmapsMode == MIPMAPS_AUTO && isCompressed()) + mipmapsMode = MIPMAPS_MANUAL; + + if (mipmapsMode != MIPMAPS_NONE) + mipmapCount = getTotalMipmapCount(pixelWidth, pixelHeight, depth); + + if (pixelWidth <= 0 || pixelHeight <= 0 || layers <= 0 || depth <= 0) + throw love::Exception("Texture dimensions must be greater than 0."); + + if (texType != TEXTURE_2D && requestedMSAA > 1) + throw love::Exception("MSAA is only supported for textures with the 2D texture type."); + + if (readable && isPixelFormatDepthStencil(format) && settings.msaa > 1) + throw love::Exception("Readable depth/stencil textures with MSAA are not currently supported."); + + if ((!readable || settings.msaa > 1) && mipmapsMode != MIPMAPS_NONE) + throw love::Exception("Non-readable and MSAA textures cannot have mipmaps."); + + if (!readable && texType != TEXTURE_2D) + throw love::Exception("Non-readable pixel formats are only supported for 2D texture types."); + + if (isCompressed() && renderTarget) + throw love::Exception("Compressed textures cannot be render targets."); + + if (!gfx->isPixelFormatSupported(format, renderTarget, readable, sRGB)) + { + const char *fstr = "unknown"; + love::getConstant(format, fstr); + + const char *readablestr = ""; + if (readable != !isPixelFormatDepthStencil(format)) + readablestr = readable ? " readable" : " non-readable"; + + const char *rtstr = ""; + if (renderTarget) + rtstr = " as a render target"; + + throw love::Exception("The %s%s pixel format is not supported%s on this system.", fstr, readablestr, rtstr); + } + + if (!gfx->getCapabilities().textureTypes[texType]) + { + const char *textypestr = "unknown"; + Texture::getConstant(texType, textypestr); + throw love::Exception("%s textures are not supported on this system.", textypestr); + } + + validateDimensions(!renderTarget); + + samplerState = gfx->getDefaultSamplerState(); + + initQuad(); + ++textureCount; } @@ -780,6 +874,42 @@ bool Texture::Slices::validate() const return true; } +static StringMap::Entry texTypeEntries[] = +{ + { "2d", TEXTURE_2D }, + { "volume", TEXTURE_VOLUME }, + { "array", TEXTURE_2D_ARRAY }, + { "cube", TEXTURE_CUBE }, +}; + +static StringMap texTypes(texTypeEntries, sizeof(texTypeEntries)); + +static StringMap::Entry mipmapEntries[] = +{ + { "none", Texture::MIPMAPS_NONE }, + { "manual", Texture::MIPMAPS_MANUAL }, + { "auto", Texture::MIPMAPS_AUTO }, +}; + +static StringMap mipmapModes(mipmapEntries, sizeof(mipmapEntries)); + +static StringMap::Entry settingTypeEntries[] = +{ + { "width", Texture::SETTING_WIDTH }, + { "height", Texture::SETTING_HEIGHT }, + { "layers", Texture::SETTING_LAYERS }, + { "mipmaps", Texture::SETTING_MIPMAPS }, + { "format", Texture::SETTING_FORMAT }, + { "linear", Texture::SETTING_LINEAR }, + { "type", Texture::SETTING_TYPE }, + { "dpiscale", Texture::SETTING_DPI_SCALE }, + { "msaa", Texture::SETTING_MSAA }, + { "rendertarget", Texture::SETTING_RENDER_TARGET }, + { "readable", Texture::SETTING_READABLE }, +}; + +static StringMap settingTypes(settingTypeEntries, sizeof(settingTypeEntries)); + bool Texture::getConstant(const char *in, TextureType &out) { return texTypes.find(in, out); @@ -795,25 +925,6 @@ std::vector Texture::getConstants(TextureType) return texTypes.getNames(); } -StringMap::Entry Texture::texTypeEntries[] = -{ - { "2d", TEXTURE_2D }, - { "volume", TEXTURE_VOLUME }, - { "array", TEXTURE_2D_ARRAY }, - { "cube", TEXTURE_CUBE }, -}; - -StringMap Texture::texTypes(Texture::texTypeEntries, sizeof(Texture::texTypeEntries)); - -static StringMap::Entry mipmapEntries[] = -{ - { "none", Texture::MIPMAPS_NONE }, - { "manual", Texture::MIPMAPS_MANUAL }, - { "auto", Texture::MIPMAPS_AUTO }, -}; - -static StringMap mipmapModes(mipmapEntries, sizeof(mipmapEntries)); - bool Texture::getConstant(const char *in, MipmapsMode &out) { return mipmapModes.find(in, out); @@ -829,5 +940,27 @@ std::vector Texture::getConstants(MipmapsMode) return mipmapModes.getNames(); } +bool Texture::getConstant(const char *in, SettingType &out) +{ + return settingTypes.find(in, out); +} + +bool Texture::getConstant(SettingType in, const char *&out) +{ + return settingTypes.find(in, out); +} + +const char *Texture::getConstant(SettingType in) +{ + const char *name = nullptr; + getConstant(in, name); + return name; +} + +std::vector Texture::getConstants(SettingType) +{ + return settingTypes.getNames(); +} + } // graphics } // love diff --git a/src/modules/graphics/Texture.h b/src/modules/graphics/Texture.h index 57172898a..1b583be8d 100644 --- a/src/modules/graphics/Texture.h +++ b/src/modules/graphics/Texture.h @@ -137,6 +137,38 @@ public: MIPMAPS_MAX_ENUM }; + enum SettingType + { + SETTING_WIDTH, + SETTING_HEIGHT, + SETTING_LAYERS, + SETTING_MIPMAPS, + SETTING_FORMAT, + SETTING_LINEAR, + SETTING_TYPE, + SETTING_DPI_SCALE, + SETTING_MSAA, + SETTING_RENDER_TARGET, + SETTING_READABLE, + SETTING_MAX_ENUM + }; + + // Size and format will be overridden by ImageData when supplied. + struct Settings + { + int width = 1; + int height = 1; + int layers = 1; // depth for 3D textures + TextureType type = TEXTURE_2D; + MipmapsMode mipmaps = MIPMAPS_NONE; + PixelFormat format = PIXELFORMAT_NORMAL; + bool linear = false; + float dpiScale = 1.0f; + int msaa = 0; + bool renderTarget = false; + OptionalBool readable; + }; + struct Slices { public: @@ -169,7 +201,7 @@ public: static int64 totalGraphicsMemory; - Texture(TextureType texType); + Texture(const Settings &settings, const Slices *slices); virtual ~Texture(); // Drawable. @@ -234,6 +266,11 @@ public: static bool getConstant(MipmapsMode in, const char *&out); static std::vector getConstants(MipmapsMode); + static bool getConstant(const char *in, SettingType &out); + static bool getConstant(SettingType in, const char *&out); + static const char *getConstant(SettingType in); + static std::vector getConstants(SettingType); + protected: void initQuad(); @@ -276,11 +313,6 @@ protected: // back to a default texture. bool usingDefaultTexture; -private: - - static StringMap::Entry texTypeEntries[]; - static StringMap texTypes; - }; // Texture } // graphics diff --git a/src/modules/graphics/Video.cpp b/src/modules/graphics/Video.cpp index fe5207961..92d387cd3 100644 --- a/src/modules/graphics/Video.cpp +++ b/src/modules/graphics/Video.cpp @@ -79,11 +79,14 @@ Video::Video(Graphics *gfx, love::video::VideoStream *stream, float dpiscale) const unsigned char *data[3] = {frame->yplane, frame->cbplane, frame->crplane}; - Image::Settings settings; + Texture::Settings settings; for (int i = 0; i < 3; i++) { - Texture *tex = gfx->newImage(TEXTURE_2D, PIXELFORMAT_R8_UNORM, widths[i], heights[i], 1, settings); + settings.width = widths[i]; + settings.height = heights[i]; + settings.format = PIXELFORMAT_R8_UNORM; + Texture *tex = gfx->newImage(settings, nullptr); tex->setSamplerState(samplerState); diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index 56de9ca81..6f5b46881 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -183,7 +183,7 @@ static bool createRenderbuffer(int width, int height, int &samples, PixelFormat } Canvas::Canvas(const Settings &settings) - : love::graphics::Canvas(settings) + : love::graphics::Texture(settings, nullptr) , fbo(0) , texture(0) , renderbuffer(0) @@ -346,7 +346,7 @@ ptrdiff_t Canvas::getHandle() const love::image::ImageData *Canvas::newImageData(love::image::Image *module, int slice, int mipmap, const Rect &r) { - love::image::ImageData *data = love::graphics::Canvas::newImageData(module, slice, mipmap, r); + love::image::ImageData *data = love::graphics::Texture::newImageData(module, slice, mipmap, r); bool isSRGB = false; OpenGL::TextureFormat fmt = gl.convertPixelFormat(data->getFormat(), false, isSRGB); diff --git a/src/modules/graphics/opengl/Canvas.h b/src/modules/graphics/opengl/Canvas.h index d1bc3cb1c..158f134b0 100644 --- a/src/modules/graphics/opengl/Canvas.h +++ b/src/modules/graphics/opengl/Canvas.h @@ -24,7 +24,7 @@ #include "common/config.h" #include "common/Color.h" #include "common/int.h" -#include "graphics/Canvas.h" +#include "graphics/Texture.h" #include "graphics/Volatile.h" #include "OpenGL.h" @@ -35,7 +35,7 @@ namespace graphics namespace opengl { -class Canvas final : public love::graphics::Canvas, public Volatile +class Canvas final : public love::graphics::Texture, public Volatile { public: diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index d61f7f57e..4cc54eb22 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -130,17 +130,12 @@ love::graphics::StreamBuffer *Graphics::newStreamBuffer(BufferType type, size_t return CreateStreamBuffer(type, size); } -love::graphics::Texture *Graphics::newImage(const Texture::Slices &data, const Image::Settings &settings) +love::graphics::Texture *Graphics::newImage(const Texture::Settings &settings, const Texture::Slices *data) { - return new Image(data, settings); + return new Image(settings, data); } -love::graphics::Texture *Graphics::newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) -{ - return new Image(textype, format, width, height, slices, settings); -} - -love::graphics::Texture *Graphics::newCanvas(const Canvas::Settings &settings) +love::graphics::Texture *Graphics::newCanvas(const Texture::Settings &settings) { return new Canvas(settings); } diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 5745f8e99..1375feca9 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -60,9 +60,8 @@ public: // Implements Module. const char *getName() const override; - love::graphics::Texture *newImage(const Texture::Slices &data, const Image::Settings &settings) override; - love::graphics::Texture *newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) override; - love::graphics::Texture *newCanvas(const Canvas::Settings &settings) override; + love::graphics::Texture *newImage(const Texture::Settings &settings, const Texture::Slices *data) override; + love::graphics::Texture *newCanvas(const Texture::Settings &settings) override; love::graphics::Buffer *newBuffer(size_t size, const void *data, BufferType type, vertex::Usage usage, uint32 mapflags) override; void setViewportSize(int width, int height, int pixelwidth, int pixelheight) override; diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 95750aad5..233e7a291 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -33,19 +33,13 @@ namespace graphics namespace opengl { -Image::Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings) - : love::graphics::Image(textype, format, width, height, slices, settings) - , slices(textype) - , texture(0) -{ - loadVolatile(); -} - -Image::Image(const Slices &slices, const Settings &settings) - : love::graphics::Image(slices, settings) - , slices(slices) +Image::Image(const Settings &settings, const Slices *data) + : love::graphics::Texture(settings, data) + , slices(settings.type) , texture(0) { + if (data != nullptr) + slices = *data; loadVolatile(); } diff --git a/src/modules/graphics/opengl/Image.h b/src/modules/graphics/opengl/Image.h index c660903c2..f2811e827 100644 --- a/src/modules/graphics/opengl/Image.h +++ b/src/modules/graphics/opengl/Image.h @@ -21,7 +21,7 @@ #pragma once // LOVE -#include "graphics/Image.h" +#include "graphics/Texture.h" #include "graphics/Volatile.h" // OpenGL @@ -34,12 +34,11 @@ namespace graphics namespace opengl { -class Image final : public love::graphics::Image, public Volatile +class Image final : public love::graphics::Texture, public Volatile { public: - Image(const Slices &data, const Settings &settings); - Image(TextureType textype, PixelFormat format, int width, int height, int slices, const Settings &settings); + Image(const Settings &settings, const Slices *data); virtual ~Image(); diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index da1d1fdea..2989d5f0f 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -700,19 +700,19 @@ static void parseDPIScale(Data *d, float *dpiscale) } } -static Image::Settings w__optImageSettings(lua_State *L, int idx, bool &setdpiscale) +static Texture::Settings w__optImageSettings(lua_State *L, int idx, bool &setdpiscale) { - Image::Settings s; + Texture::Settings s; setdpiscale = false; if (!lua_isnoneornil(L, idx)) { - luax_checktablefields(L, idx, "image setting name", Image::getConstant); + luax_checktablefields(L, idx, "image setting name", Texture::getConstant); - s.mipmaps = luax_boolflag(L, idx, Image::getConstant(Image::SETTING_MIPMAPS), s.mipmaps); - s.linear = luax_boolflag(L, idx, Image::getConstant(Image::SETTING_LINEAR), s.linear); + s.mipmaps = luax_boolflag(L, idx, "mipmaps", false) ? Texture::MIPMAPS_MANUAL : Texture::MIPMAPS_NONE; + s.linear = luax_boolflag(L, idx, Texture::getConstant(Texture::SETTING_LINEAR), s.linear); - lua_getfield(L, idx, Image::getConstant(Image::SETTING_DPI_SCALE)); + lua_getfield(L, idx, Texture::getConstant(Texture::SETTING_DPI_SCALE)); if (lua_isnumber(L, -1)) { s.dpiScale = (float) lua_tonumber(L, -1); @@ -757,11 +757,11 @@ getImageData(lua_State *L, int idx, bool allowcompressed, float *dpiscale) return std::make_pair(idata, cdata); } -static int w__pushNewImage(lua_State *L, Texture::Slices &slices, const Image::Settings &settings) +static int w__pushNewImage(lua_State *L, Texture::Slices &slices, const Texture::Settings &settings) { StrongRef i; luax_catchexcept(L, - [&]() { i.set(instance()->newImage(slices, settings), Acquire::NORETAIN); }, + [&]() { i.set(instance()->newImage(settings, &slices), Acquire::NORETAIN); }, [&](bool) { slices.clear(); } ); @@ -776,7 +776,7 @@ int w_newCubeImage(lua_State *L) Texture::Slices slices(TEXTURE_CUBE); bool dpiscaleset = false; - Image::Settings settings = w__optImageSettings(L, 2, dpiscaleset); + Texture::Settings settings = w__optImageSettings(L, 2, dpiscaleset); float *autodpiscale = dpiscaleset ? nullptr : &settings.dpiScale; auto imagemodule = Module::getInstance(Module::M_IMAGE); @@ -870,7 +870,7 @@ int w_newArrayImage(lua_State *L) Texture::Slices slices(TEXTURE_2D_ARRAY); bool dpiscaleset = false; - Image::Settings settings = w__optImageSettings(L, 2, dpiscaleset); + Texture::Settings settings = w__optImageSettings(L, 2, dpiscaleset); float *autodpiscale = dpiscaleset ? nullptr : &settings.dpiScale; if (lua_istable(L, 1)) @@ -936,7 +936,7 @@ int w_newVolumeImage(lua_State *L) Texture::Slices slices(TEXTURE_VOLUME); bool dpiscaleset = false; - Image::Settings settings = w__optImageSettings(L, 2, dpiscaleset); + Texture::Settings settings = w__optImageSettings(L, 2, dpiscaleset); float *autodpiscale = dpiscaleset ? nullptr : &settings.dpiScale; if (lua_istable(L, 1)) @@ -1007,7 +1007,7 @@ int w_newImage(lua_State *L) Texture::Slices slices(TEXTURE_2D); bool dpiscaleset = false; - Image::Settings settings = w__optImageSettings(L, 2, dpiscaleset); + Texture::Settings settings = w__optImageSettings(L, 2, dpiscaleset); float *autodpiscale = dpiscaleset ? nullptr : &settings.dpiScale; if (lua_istable(L, 1)) @@ -1185,7 +1185,8 @@ int w_newCanvas(lua_State *L) { luax_checkgraphicscreated(L); - Canvas::Settings settings; + Texture::Settings settings; + settings.renderTarget = true; // check if width and height are given. else default to screen dimensions. settings.width = (int) luaL_optinteger(L, 1, instance()->getWidth()); @@ -1205,12 +1206,12 @@ int w_newCanvas(lua_State *L) if (!lua_isnoneornil(L, startidx)) { - luax_checktablefields(L, startidx, "canvas setting name", Canvas::getConstant); + luax_checktablefields(L, startidx, "texture setting name", Texture::getConstant); - settings.dpiScale = (float) luax_numberflag(L, startidx, Canvas::getConstant(Canvas::SETTING_DPI_SCALE), settings.dpiScale); - settings.msaa = luax_intflag(L, startidx, Canvas::getConstant(Canvas::SETTING_MSAA), settings.msaa); + settings.dpiScale = (float) luax_numberflag(L, startidx, Texture::getConstant(Texture::SETTING_DPI_SCALE), settings.dpiScale); + settings.msaa = luax_intflag(L, startidx, Texture::getConstant(Texture::SETTING_MSAA), settings.msaa); - lua_getfield(L, startidx, Canvas::getConstant(Canvas::SETTING_FORMAT)); + lua_getfield(L, startidx, Texture::getConstant(Texture::SETTING_FORMAT)); if (!lua_isnoneornil(L, -1)) { const char *str = luaL_checkstring(L, -1); @@ -1219,7 +1220,7 @@ int w_newCanvas(lua_State *L) } lua_pop(L, 1); - lua_getfield(L, startidx, Canvas::getConstant(Canvas::SETTING_TYPE)); + lua_getfield(L, startidx, Texture::getConstant(Texture::SETTING_TYPE)); if (!lua_isnoneornil(L, -1)) { const char *str = luaL_checkstring(L, -1); @@ -1228,7 +1229,7 @@ int w_newCanvas(lua_State *L) } lua_pop(L, 1); - lua_getfield(L, startidx, Canvas::getConstant(Canvas::SETTING_READABLE)); + lua_getfield(L, startidx, Texture::getConstant(Texture::SETTING_READABLE)); if (!lua_isnoneornil(L, -1)) { settings.readable.hasValue = true; @@ -1236,7 +1237,7 @@ int w_newCanvas(lua_State *L) } lua_pop(L, 1); - lua_getfield(L, startidx, Canvas::getConstant(Canvas::SETTING_MIPMAPS)); + lua_getfield(L, startidx, Texture::getConstant(Texture::SETTING_MIPMAPS)); if (!lua_isnoneornil(L, -1)) { const char *str = luaL_checkstring(L, -1);