Browse Source

Replaced some references to Image and Canvas with Texture.

Alex Szpakowski 5 years ago
parent
commit
b71eaf73cc

+ 14 - 14
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<graphics::Graphics>(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

+ 2 - 2
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<StrongRef<love::graphics::Image>> images;
+	std::vector<StrongRef<love::graphics::Texture>> textures;
 
 	// maps glyphs to glyph texture information
 	std::unordered_map<uint32, Glyph> glyphs;

+ 3 - 3
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);

+ 8 - 8
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

+ 2 - 2
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<Image> images[3];
+	StrongRef<Texture> textures[3];
 	StrongRef<love::audio::Source> source;
 	
 }; // Video

+ 2 - 2
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<Graphics>(Module::M_GRAPHICS);
 		if (gfx != nullptr)
-			gfx->cleanupCanvas(this);
+			gfx->cleanupRenderTexture(this);
 	}
 
 	if (fbo != 0)

+ 4 - 4
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<bool>
 		glDiscardFramebufferEXT(gltarget, (GLint) attachments.size(), &attachments[0]);
 }
 
-void Graphics::cleanupCanvas(Canvas *texture)
+void Graphics::cleanupRenderTexture(Texture *texture)
 {
 	if (!texture->isRenderTarget())
 		return;

+ 4 - 4
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:
 

+ 5 - 5
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<Image> i;
+	StrongRef<Texture> 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;
 }
 

+ 1 - 2
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++

+ 1 - 2
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

+ 1 - 2
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