From b71eaf73cc722e24fc351bbbd5d4317a06c744a7 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 4 Feb 2020 20:52:57 -0400 Subject: [PATCH] Replaced some references to Image and Canvas with Texture. --- src/modules/graphics/Font.cpp | 28 ++++++++++---------- src/modules/graphics/Font.h | 4 +-- src/modules/graphics/Graphics.h | 6 ++--- src/modules/graphics/Video.cpp | 16 +++++------ src/modules/graphics/Video.h | 4 +-- src/modules/graphics/opengl/Canvas.cpp | 4 +-- src/modules/graphics/opengl/Graphics.cpp | 8 +++--- src/modules/graphics/opengl/Graphics.h | 8 +++--- src/modules/graphics/wrap_Graphics.cpp | 10 +++---- src/modules/graphics/wrap_Mesh.cpp | 3 +-- src/modules/graphics/wrap_ParticleSystem.cpp | 3 +-- src/modules/graphics/wrap_SpriteBatch.cpp | 3 +-- 12 files changed, 47 insertions(+), 50 deletions(-) diff --git a/src/modules/graphics/Font.cpp b/src/modules/graphics/Font.cpp index df325dd73..46730e969 100644 --- a/src/modules/graphics/Font.cpp +++ b/src/modules/graphics/Font.cpp @@ -125,7 +125,7 @@ bool Font::loadVolatile() { textureCacheID++; glyphs.clear(); - images.clear(); + textures.clear(); createTexture(); return true; } @@ -135,7 +135,7 @@ void Font::createTexture() auto gfx = Module::getInstance(Module::M_GRAPHICS); gfx->flushStreamDraws(); - Image *image = nullptr; + Texture *texture = nullptr; TextureSize size = {textureWidth, textureHeight}; TextureSize nextsize = getNextTextureSize(); bool recreatetexture = false; @@ -143,16 +143,16 @@ void Font::createTexture() // If we have an existing texture already, we'll try replacing it with a // larger-sized one rather than creating a second one. Having a single // texture reduces texture switches and draw calls when rendering. - if ((nextsize.width > size.width || nextsize.height > size.height) && !images.empty()) + if ((nextsize.width > size.width || nextsize.height > size.height) && !textures.empty()) { recreatetexture = true; size = nextsize; - images.pop_back(); + textures.pop_back(); } Image::Settings settings; - image = gfx->newImage(TEXTURE_2D, pixelFormat, size.width, size.height, 1, settings); - image->setSamplerState(samplerState); + texture = gfx->newImage(TEXTURE_2D, pixelFormat, size.width, size.height, 1, settings); + texture->setSamplerState(samplerState); { size_t bpp = getPixelFormatSize(pixelFormat); @@ -170,10 +170,10 @@ void Font::createTexture() } Rect rect = {0, 0, size.width, size.height}; - image->replacePixels(emptydata.data(), emptydata.size(), 0, 0, rect, false); + texture->replacePixels(emptydata.data(), emptydata.size(), 0, 0, rect, false); } - images.emplace_back(image, Acquire::NORETAIN); + textures.emplace_back(texture, Acquire::NORETAIN); textureWidth = size.width; textureHeight = size.height; @@ -200,7 +200,7 @@ void Font::createTexture() void Font::unloadVolatile() { glyphs.clear(); - images.clear(); + textures.clear(); } love::font::GlyphData *Font::getRasterizerGlyphData(uint32 glyph) @@ -268,11 +268,11 @@ const Font::Glyph &Font::addGlyph(uint32 glyph) // Don't waste space for empty glyphs. if (w > 0 && h > 0) { - Image *image = images.back(); - g.texture = image; + Texture *texture = textures.back(); + g.texture = texture; Rect rect = {textureX, textureY, gd->getWidth(), gd->getHeight()}; - image->replacePixels(gd->getData(), gd->getSize(), 0, 0, rect, false); + texture->replacePixels(gd->getData(), gd->getSize(), 0, 0, rect, false); double tX = (double) textureX, tY = (double) textureY; double tWidth = (double) textureWidth, tHeight = (double) textureHeight; @@ -926,8 +926,8 @@ void Font::setSamplerState(const SamplerState &s) samplerState.magFilter = s.magFilter; samplerState.maxAnisotropy = s.maxAnisotropy; - for (const auto &image : images) - image->setSamplerState(samplerState); + for (const auto &texture : textures) + texture->setSamplerState(samplerState); } const SamplerState &Font::getSamplerState() const diff --git a/src/modules/graphics/Font.h b/src/modules/graphics/Font.h index 20f5bc5c8..b1bbee8d7 100644 --- a/src/modules/graphics/Font.h +++ b/src/modules/graphics/Font.h @@ -33,7 +33,7 @@ #include "common/Vector.h" #include "font/Rasterizer.h" -#include "Image.h" +#include "Texture.h" #include "vertex.h" #include "Volatile.h" @@ -217,7 +217,7 @@ private: int textureWidth; int textureHeight; - std::vector> images; + std::vector> textures; // maps glyphs to glyph texture information std::unordered_map glyphs; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index cf4429e3b..24a42bf29 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -428,8 +428,8 @@ public: // Implements Module. virtual ModuleType getModuleType() const { return M_GRAPHICS; } - virtual Image *newImage(const Texture::Slices &data, const Image::Settings &settings) = 0; - virtual Image *newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) = 0; + 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; Quad *newQuad(Quad::Viewport v, double sw, double sh); Font *newFont(love::font::Rasterizer *data); @@ -439,7 +439,7 @@ public: SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage); ParticleSystem *newParticleSystem(Texture *texture, int size); - virtual Canvas *newCanvas(const Canvas::Settings &settings) = 0; + virtual Texture *newCanvas(const Canvas::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/Video.cpp b/src/modules/graphics/Video.cpp index b27d3c856..fe5207961 100644 --- a/src/modules/graphics/Video.cpp +++ b/src/modules/graphics/Video.cpp @@ -83,17 +83,17 @@ Video::Video(Graphics *gfx, love::video::VideoStream *stream, float dpiscale) for (int i = 0; i < 3; i++) { - Image *img = gfx->newImage(TEXTURE_2D, PIXELFORMAT_R8_UNORM, widths[i], heights[i], 1, settings); + Texture *tex = gfx->newImage(TEXTURE_2D, PIXELFORMAT_R8_UNORM, widths[i], heights[i], 1, settings); - img->setSamplerState(samplerState); + tex->setSamplerState(samplerState); size_t bpp = getPixelFormatSize(PIXELFORMAT_R8_UNORM); size_t size = bpp * widths[i] * heights[i]; Rect rect = {0, 0, widths[i], heights[i]}; - img->replacePixels(data[i], size, 0, 0, rect, false); + tex->replacePixels(data[i], size, 0, 0, rect, false); - images[i].set(img, Acquire::NORETAIN); + textures[i].set(tex, Acquire::NORETAIN); } } @@ -143,7 +143,7 @@ void Video::draw(Graphics *gfx, const Matrix4 &m) } if (Shader::current != nullptr) - Shader::current->setVideoTextures(images[0], images[1], images[2]); + Shader::current->setVideoTextures(textures[0], textures[1], textures[2]); gfx->flushStreamDraws(); } @@ -168,7 +168,7 @@ void Video::update() size_t size = bpp * widths[i] * heights[i]; Rect rect = {0, 0, widths[i], heights[i]}; - images[i]->replacePixels(data[i], size, 0, 0, rect, false); + textures[i]->replacePixels(data[i], size, 0, 0, rect, false); } } } @@ -211,8 +211,8 @@ void Video::setSamplerState(const SamplerState &s) samplerState.wrapV = s.wrapV; samplerState.maxAnisotropy = s.maxAnisotropy; - for (const auto &image : images) - image->setSamplerState(samplerState); + for (const auto &texture : textures) + texture->setSamplerState(samplerState); } const SamplerState &Video::getSamplerState() const diff --git a/src/modules/graphics/Video.h b/src/modules/graphics/Video.h index 65db27c32..871d8eb2e 100644 --- a/src/modules/graphics/Video.h +++ b/src/modules/graphics/Video.h @@ -23,7 +23,7 @@ // LOVE #include "common/math.h" #include "Drawable.h" -#include "Image.h" +#include "Texture.h" #include "vertex.h" #include "video/VideoStream.h" #include "audio/Source.h" @@ -74,7 +74,7 @@ private: Vertex vertices[4]; - StrongRef images[3]; + StrongRef textures[3]; StrongRef source; }; // Video diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index a00fc4594..56de9ca81 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -288,13 +288,13 @@ bool Canvas::loadVolatile() void Canvas::unloadVolatile() { - if (fbo != 0 || renderbuffer != 0 || texture != 0) + if (isRenderTarget() && (fbo != 0 || renderbuffer != 0 || texture != 0)) { // This is a bit ugly, but we need some way to destroy the cached FBO // when this Canvas' texture is destroyed. auto gfx = Module::getInstance(Module::M_GRAPHICS); if (gfx != nullptr) - gfx->cleanupCanvas(this); + gfx->cleanupRenderTexture(this); } if (fbo != 0) diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index f020e28ec..d61f7f57e 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -130,17 +130,17 @@ love::graphics::StreamBuffer *Graphics::newStreamBuffer(BufferType type, size_t return CreateStreamBuffer(type, size); } -love::graphics::Image *Graphics::newImage(const Texture::Slices &data, const Image::Settings &settings) +love::graphics::Texture *Graphics::newImage(const Texture::Slices &data, const Image::Settings &settings) { return new Image(data, settings); } -love::graphics::Image *Graphics::newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) +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::Canvas *Graphics::newCanvas(const Canvas::Settings &settings) +love::graphics::Texture *Graphics::newCanvas(const Canvas::Settings &settings) { return new Canvas(settings); } @@ -820,7 +820,7 @@ void Graphics::discard(OpenGL::FramebufferTarget target, const std::vector glDiscardFramebufferEXT(gltarget, (GLint) attachments.size(), &attachments[0]); } -void Graphics::cleanupCanvas(Canvas *texture) +void Graphics::cleanupRenderTexture(Texture *texture) { if (!texture->isRenderTarget()) return; diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 3a711d2c1..5745f8e99 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -60,9 +60,9 @@ public: // Implements Module. const char *getName() const override; - love::graphics::Image *newImage(const Texture::Slices &data, const Image::Settings &settings) override; - love::graphics::Image *newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) override; - love::graphics::Canvas *newCanvas(const Canvas::Settings &settings) 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::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; @@ -112,7 +112,7 @@ public: Shader::Language getShaderLanguageTarget() const override; // Internal use. - void cleanupCanvas(Canvas *canvas); + void cleanupRenderTexture(Texture *texture); private: diff --git a/src/modules/graphics/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp index d6c979061..da1d1fdea 100644 --- a/src/modules/graphics/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -759,7 +759,7 @@ getImageData(lua_State *L, int idx, bool allowcompressed, float *dpiscale) static int w__pushNewImage(lua_State *L, Texture::Slices &slices, const Image::Settings &settings) { - StrongRef i; + StrongRef i; luax_catchexcept(L, [&]() { i.set(instance()->newImage(slices, settings), Acquire::NORETAIN); }, [&](bool) { slices.clear(); } @@ -1246,11 +1246,11 @@ int w_newCanvas(lua_State *L) lua_pop(L, 1); } - Canvas *canvas = nullptr; - luax_catchexcept(L, [&](){ canvas = instance()->newCanvas(settings); }); + Texture *texture = nullptr; + luax_catchexcept(L, [&](){ texture = instance()->newCanvas(settings); }); - luax_pushtype(L, canvas); - canvas->release(); + luax_pushtype(L, texture); + texture->release(); return 1; } diff --git a/src/modules/graphics/wrap_Mesh.cpp b/src/modules/graphics/wrap_Mesh.cpp index 5f1814f56..3c9de2f5f 100644 --- a/src/modules/graphics/wrap_Mesh.cpp +++ b/src/modules/graphics/wrap_Mesh.cpp @@ -20,8 +20,7 @@ // LOVE #include "wrap_Mesh.h" -#include "Image.h" -#include "Canvas.h" +#include "Texture.h" #include "wrap_Texture.h" // C++ diff --git a/src/modules/graphics/wrap_ParticleSystem.cpp b/src/modules/graphics/wrap_ParticleSystem.cpp index 637dcc710..7458941fb 100644 --- a/src/modules/graphics/wrap_ParticleSystem.cpp +++ b/src/modules/graphics/wrap_ParticleSystem.cpp @@ -22,8 +22,7 @@ #include "wrap_ParticleSystem.h" #include "common/Vector.h" -#include "Image.h" -#include "Canvas.h" +#include "Texture.h" #include "wrap_Texture.h" // C diff --git a/src/modules/graphics/wrap_SpriteBatch.cpp b/src/modules/graphics/wrap_SpriteBatch.cpp index c98bd5d71..420ece908 100644 --- a/src/modules/graphics/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/wrap_SpriteBatch.cpp @@ -20,8 +20,7 @@ // LOVE #include "wrap_SpriteBatch.h" -#include "Image.h" -#include "Canvas.h" +#include "Texture.h" #include "wrap_Texture.h" namespace love