Move love.graphics Image wrapper code out of the opengl subfolder

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-01-29 00:20:16 -04:00
parent 4a3319245b
commit 3616470a0a
11 changed files with 198 additions and 143 deletions
+68
View File
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2006-2017 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"
namespace love
{
namespace graphics
{
love::Type Image::type("Image", &Texture::type);
int Image::imageCount = 0;
Image::Image(const Settings &settings)
: settings(settings)
{
++imageCount;
}
Image::~Image()
{
--imageCount;
}
const Image::Settings &Image::getFlags() const
{
return settings;
}
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);
}
StringMap<Image::SettingType, Image::SETTING_MAX_ENUM>::Entry Image::settingTypeEntries[] =
{
{ "mipmaps", SETTING_MIPMAPS },
{ "linear", SETTING_LINEAR },
{ "pixeldensity", SETTING_PIXELDENSITY },
};
StringMap<Image::SettingType, Image::SETTING_MAX_ENUM> Image::settingTypes(Image::settingTypeEntries, sizeof(Image::settingTypeEntries));
} // graphics
} // love
+88
View File
@@ -0,0 +1,88 @@
/**
* Copyright (c) 2006-2017 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 "image/ImageData.h"
#include "image/CompressedImageData.h"
#include "Texture.h"
namespace love
{
namespace graphics
{
class Image : public Texture
{
public:
static love::Type type;
enum SettingType
{
SETTING_MIPMAPS,
SETTING_LINEAR,
SETTING_PIXELDENSITY,
SETTING_MAX_ENUM
};
struct Settings
{
bool mipmaps = false;
bool linear = false;
float pixeldensity = 1.0f;
};
Image(const Settings &settings);
virtual ~Image();
virtual const std::vector<StrongRef<love::image::ImageData>> &getImageData() const = 0;
virtual const std::vector<StrongRef<love::image::CompressedImageData>> &getCompressedData() const = 0;
virtual void setMipmapSharpness(float sharpness) = 0;
virtual float getMipmapSharpness() const = 0;
virtual bool isCompressed() const = 0;
virtual bool refresh(int xoffset, int yoffset, int w, int h) = 0;
const Settings &getFlags() const;
static bool getConstant(const char *in, SettingType &out);
static bool getConstant(SettingType in, const char *&out);
static int imageCount;
protected:
// The settings used to initialize this Image.
Settings settings;
static StringMap<SettingType, SETTING_MAX_ENUM>::Entry settingTypeEntries[];
static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
}; // Image
} // graphics
} // love
+4 -37
View File
@@ -43,10 +43,6 @@ namespace graphics
namespace opengl
{
love::Type Image::type("Image", &Texture::type);
int Image::imageCount = 0;
float Image::maxMipmapSharpness = 0.0f;
static int getMipmapCount(int basewidth, int baseheight)
@@ -92,10 +88,10 @@ static bool verifyMipmapLevels(const std::vector<T> &miplevels)
}
Image::Image(const std::vector<love::image::ImageData *> &imagedata, const Settings &settings)
: texture(0)
: love::graphics::Image(settings)
, texture(0)
, mipmapSharpness(defaultMipmapSharpness)
, compressed(false)
, settings(settings)
, sRGB(false)
, usingDefaultTexture(false)
, textureMemorySize(0)
@@ -119,15 +115,13 @@ Image::Image(const std::vector<love::image::ImageData *> &imagedata, const Setti
preload();
loadVolatile();
++imageCount;
}
Image::Image(const std::vector<love::image::CompressedImageData *> &compresseddata, const Settings &settings)
: texture(0)
: love::graphics::Image(settings)
, texture(0)
, mipmapSharpness(defaultMipmapSharpness)
, compressed(true)
, settings(settings)
, sRGB(false)
, usingDefaultTexture(false)
, textureMemorySize(0)
@@ -159,14 +153,11 @@ Image::Image(const std::vector<love::image::CompressedImageData *> &compressedda
preload();
loadVolatile();
++imageCount;
}
Image::~Image()
{
unloadVolatile();
--imageCount;
}
void Image::preload()
@@ -545,11 +536,6 @@ float Image::getMipmapSharpness() const
return mipmapSharpness;
}
const Image::Settings &Image::getFlags() const
{
return settings;
}
bool Image::isCompressed() const
{
return compressed;
@@ -565,25 +551,6 @@ bool Image::hasSRGBSupport()
return GLAD_ES_VERSION_3_0 || GLAD_EXT_sRGB || GLAD_VERSION_2_1 || GLAD_EXT_texture_sRGB;
}
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);
}
StringMap<Image::SettingType, Image::SETTING_MAX_ENUM>::Entry Image::settingTypeEntries[] =
{
{ "mipmaps", SETTING_MIPMAPS },
{ "linear", SETTING_LINEAR },
{ "pixeldensity", SETTING_PIXELDENSITY },
};
StringMap<Image::SettingType, Image::SETTING_MAX_ENUM> Image::settingTypes(Image::settingTypeEntries, sizeof(Image::settingTypeEntries));
} // opengl
} // graphics
} // love
+9 -75
View File
@@ -18,18 +18,10 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_OPENGL_IMAGE_H
#define LOVE_GRAPHICS_OPENGL_IMAGE_H
#pragma once
// LOVE
#include "common/config.h"
#include "common/Matrix.h"
#include "common/Vector.h"
#include "common/StringMap.h"
#include "common/math.h"
#include "image/ImageData.h"
#include "image/CompressedImageData.h"
#include "graphics/Texture.h"
#include "graphics/Image.h"
#include "graphics/Volatile.h"
// OpenGL
@@ -42,48 +34,11 @@ namespace graphics
namespace opengl
{
/**
* A drawable image based on OpenGL-textures. This class takes ImageData
* objects and create textures on the GPU for fast drawing.
*
* @author Anders Ruud
**/
class Image : public Texture, public Volatile
class Image : public love::graphics::Image, public Volatile
{
public:
static love::Type type;
enum SettingType
{
SETTING_MIPMAPS,
SETTING_LINEAR,
SETTING_PIXELDENSITY,
SETTING_MAX_ENUM
};
struct Settings
{
bool mipmaps = false;
bool linear = false;
float pixeldensity = 1.0f;
};
/**
* Creates a new Image. Not that anything is ready to use
* before load is called.
*
* @param data The data from which to load the image. Each element in the
* array is a mipmap level. If more than the base level is present, all
* mip levels must be present.
**/
Image(const std::vector<love::image::ImageData *> &data, const Settings &settings);
/**
* Creates a new Image with compressed image data.
*
* @param cdata The compressed data from which to load the image.
**/
Image(const std::vector<love::image::CompressedImageData *> &cdata, const Settings &settings);
virtual ~Image();
@@ -94,27 +49,16 @@ public:
ptrdiff_t getHandle() const override;
const std::vector<StrongRef<love::image::ImageData>> &getImageData() const;
const std::vector<StrongRef<love::image::CompressedImageData>> &getCompressedData() const;
const std::vector<StrongRef<love::image::ImageData>> &getImageData() const override;
const std::vector<StrongRef<love::image::CompressedImageData>> &getCompressedData() const override;
void setFilter(const Texture::Filter &f) override;
bool setWrap(const Texture::Wrap &w) override;
void setMipmapSharpness(float sharpness);
float getMipmapSharpness() const;
/**
* Whether this Image is using a compressed texture (via CompressedImageData).
**/
bool isCompressed() const;
/**
* Re-uploads the ImageData or CompressedImageData associated with this Image to
* the GPU.
**/
bool refresh(int xoffset, int yoffset, int w, int h);
const Settings &getFlags() const;
void setMipmapSharpness(float sharpness) override;
float getMipmapSharpness() const override;
bool isCompressed() const override;
bool refresh(int xoffset, int yoffset, int w, int h) override;
static bool isFormatSupported(PixelFormat pixelformat);
static bool hasSRGBSupport();
@@ -122,8 +66,6 @@ public:
static bool getConstant(const char *in, SettingType &out);
static bool getConstant(SettingType in, const char *&out);
static int imageCount;
private:
void preload();
@@ -151,9 +93,6 @@ private:
// Whether this Image is using a compressed texture.
bool compressed;
// The settings used to initialize this Image.
Settings settings;
bool sRGB;
// True if the image wasn't able to be properly created and it had to fall
@@ -164,13 +103,8 @@ private:
static float maxMipmapSharpness;
static StringMap<SettingType, SETTING_MAX_ENUM>::Entry settingTypeEntries[];
static StringMap<SettingType, SETTING_MAX_ENUM> settingTypes;
}; // Image
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_IMAGE_H
+1 -1
View File
@@ -24,7 +24,7 @@
// LOVE
#include "common/config.h"
#include "graphics/wrap_Font.h"
#include "wrap_Image.h"
#include "graphics/wrap_Image.h"
#include "graphics/wrap_Quad.h"
#include "wrap_SpriteBatch.h"
#include "wrap_ParticleSystem.h"
+2 -2
View File
@@ -474,9 +474,9 @@ int w_Mesh_getTexture(lua_State *L)
return 0;
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
if (dynamic_cast<Image *>(tex) != nullptr)
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
else if (dynamic_cast<Canvas *>(tex) != nullptr)
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -29,9 +29,6 @@
// C
#include <cstring>
// C++
#include <typeinfo>
namespace love
{
namespace graphics
@@ -70,9 +67,9 @@ int w_ParticleSystem_getTexture(lua_State *L)
Texture *tex = t->getTexture();
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
if (dynamic_cast<Image *>(tex) != nullptr)
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
else if (dynamic_cast<Canvas *>(tex) != nullptr)
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -135,9 +135,9 @@ int w_SpriteBatch_getTexture(lua_State *L)
Texture *tex = t->getTexture();
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
if (dynamic_cast<Image *>(tex) != nullptr)
luax_pushtype(L, Image::type, tex);
else if (typeid(*tex) == typeid(Canvas))
else if (dynamic_cast<Canvas *>(tex) != nullptr)
luax_pushtype(L, Canvas::type, tex);
else
return luaL_error(L, "Unable to determine texture type.");
@@ -25,8 +25,6 @@ namespace love
{
namespace graphics
{
namespace opengl
{
Image *luax_checkimage(lua_State *L, int idx)
{
@@ -156,6 +154,5 @@ extern "C" int luaopen_image(lua_State *L)
return luax_register_type(L, &Image::type, w_Texture_functions, w_Image_functions, nullptr);
}
} // opengl
} // graphics
} // love
@@ -18,27 +18,21 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
#define LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
#pragma once
// LOVE
#include "common/runtime.h"
#include "Image.h"
#include "graphics/wrap_Texture.h"
#include "wrap_Texture.h"
namespace love
{
namespace graphics
{
namespace opengl
{
const char *luax_imageSettingName(Image::SettingType settingtype);
Image *luax_checkimage(lua_State *L, int idx);
extern "C" int luaopen_image(lua_State *L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H