mirror of
https://github.com/love2d/love.git
synced 2026-08-17 02:58:31 +02:00
Move love.graphics Image wrapper code out of the opengl subfolder
--HG-- branch : minor
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -1,161 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Image.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace graphics
|
||||
{
|
||||
namespace opengl
|
||||
{
|
||||
|
||||
Image *luax_checkimage(lua_State *L, int idx)
|
||||
{
|
||||
return luax_checktype<Image>(L, idx);
|
||||
}
|
||||
|
||||
int w_Image_setMipmapFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
Texture::Filter f = t->getFilter();
|
||||
|
||||
if (lua_isnoneornil(L, 2))
|
||||
f.mipmap = Texture::FILTER_NONE; // mipmapping is disabled if no argument is given
|
||||
else
|
||||
{
|
||||
const char *mipmapstr = luaL_checkstring(L, 2);
|
||||
if (!Texture::getConstant(mipmapstr, f.mipmap))
|
||||
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
|
||||
}
|
||||
|
||||
luax_catchexcept(L, [&](){ t->setFilter(f); });
|
||||
t->setMipmapSharpness((float) luaL_optnumber(L, 3, 0.0));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Image_getMipmapFilter(lua_State *L)
|
||||
{
|
||||
Image *t = luax_checkimage(L, 1);
|
||||
|
||||
const Texture::Filter &f = t->getFilter();
|
||||
|
||||
const char *mipmapstr;
|
||||
if (Texture::getConstant(f.mipmap, mipmapstr))
|
||||
lua_pushstring(L, mipmapstr);
|
||||
else
|
||||
lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
|
||||
|
||||
lua_pushnumber(L, t->getMipmapSharpness());
|
||||
return 2;
|
||||
}
|
||||
|
||||
int w_Image_isCompressed(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
luax_pushboolean(L, i->isCompressed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Image_refresh(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
|
||||
int xoffset = (int) luaL_optnumber(L, 2, 0);
|
||||
int yoffset = (int) luaL_optnumber(L, 3, 0);
|
||||
int w = (int) luaL_optnumber(L, 4, i->getWidth());
|
||||
int h = (int) luaL_optnumber(L, 5, i->getHeight());
|
||||
|
||||
luax_catchexcept(L, [&](){ i->refresh(xoffset, yoffset, w, h); });
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Image_getData(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
int n = 0;
|
||||
|
||||
if (i->isCompressed())
|
||||
{
|
||||
for (const auto &cdata : i->getCompressedData())
|
||||
{
|
||||
luax_pushtype(L, cdata.get());
|
||||
n++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (const auto &data : i->getImageData())
|
||||
{
|
||||
luax_pushtype(L, data.get());
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
const char *luax_imageSettingName(Image::SettingType settingtype)
|
||||
{
|
||||
const char *name = nullptr;
|
||||
Image::getConstant(settingtype, name);
|
||||
return name;
|
||||
}
|
||||
|
||||
int w_Image_getFlags(lua_State *L)
|
||||
{
|
||||
Image *i = luax_checkimage(L, 1);
|
||||
Image::Settings settings = i->getFlags();
|
||||
|
||||
lua_createtable(L, 0, 2);
|
||||
|
||||
lua_pushboolean(L, settings.mipmaps);
|
||||
lua_setfield(L, -2, luax_imageSettingName(Image::SETTING_MIPMAPS));
|
||||
|
||||
lua_pushboolean(L, settings.linear);
|
||||
lua_setfield(L, -2, luax_imageSettingName(Image::SETTING_LINEAR));
|
||||
|
||||
lua_pushnumber(L, settings.pixeldensity);
|
||||
lua_setfield(L, -2, luax_imageSettingName(Image::SETTING_PIXELDENSITY));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg w_Image_functions[] =
|
||||
{
|
||||
{ "setMipmapFilter", w_Image_setMipmapFilter },
|
||||
{ "getMipmapFilter", w_Image_getMipmapFilter },
|
||||
{ "isCompressed", w_Image_isCompressed },
|
||||
{ "refresh", w_Image_refresh },
|
||||
{ "getData", w_Image_getData },
|
||||
{ "getFlags", w_Image_getFlags },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
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
|
||||
@@ -1,44 +0,0 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
#define LOVE_GRAPHICS_OPENGL_WRAP_IMAGE_H
|
||||
|
||||
// LOVE
|
||||
#include "common/runtime.h"
|
||||
#include "Image.h"
|
||||
#include "graphics/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
|
||||
@@ -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.");
|
||||
|
||||
Reference in New Issue
Block a user