Added support for several specific Canvas formats. Also added love.graphics.hasCanvasFormat.

The list includes RGBA with 4-bit components, RGBA with 10-bit R, G, and B components and a 2-bit alpha component, RGB with 9-bit RGB components and a 5-bit exponent component (for HDR rendering), and several more.

--HG--
branch : Canvas-formats
This commit is contained in:
Alex Szpakowski
2014-05-13 20:54:58 -03:00
parent 6a491ed0f0
commit 408a593113
11 changed files with 249 additions and 110 deletions
-20
View File
@@ -109,16 +109,6 @@ bool Texture::getConstant(WrapMode in, const char *&out)
return wrapModes.find(in, out); return wrapModes.find(in, out);
} }
bool Texture::getConstant(const char *in, Format &out)
{
return formats.find(in, out);
}
bool Texture::getConstant(Format in, const char *&out)
{
return formats.find(in, out);
}
StringMap<Texture::FilterMode, Texture::FILTER_MAX_ENUM>::Entry Texture::filterModeEntries[] = StringMap<Texture::FilterMode, Texture::FILTER_MAX_ENUM>::Entry Texture::filterModeEntries[] =
{ {
{ "linear", Texture::FILTER_LINEAR }, { "linear", Texture::FILTER_LINEAR },
@@ -135,15 +125,5 @@ StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM>::Entry Texture::wrapModeEnt
StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM> Texture::wrapModes(Texture::wrapModeEntries, sizeof(Texture::wrapModeEntries)); StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM> Texture::wrapModes(Texture::wrapModeEntries, sizeof(Texture::wrapModeEntries));
StringMap<Texture::Format, Texture::FORMAT_MAX_ENUM>::Entry Texture::formatEntries[] =
{
{"normal", Texture::FORMAT_NORMAL},
{"hdr", Texture::FORMAT_HDR},
{"srgb", Texture::FORMAT_SRGB},
};
StringMap<Texture::Format, Texture::FORMAT_MAX_ENUM> Texture::formats(Texture::formatEntries, sizeof(Texture::formatEntries));
} // graphics } // graphics
} // love } // love
-14
View File
@@ -55,14 +55,6 @@ public:
FILTER_MAX_ENUM FILTER_MAX_ENUM
}; };
enum Format
{
FORMAT_NORMAL,
FORMAT_HDR,
FORMAT_SRGB,
FORMAT_MAX_ENUM
};
struct Filter struct Filter
{ {
Filter(); Filter();
@@ -119,9 +111,6 @@ public:
static bool getConstant(const char *in, WrapMode &out); static bool getConstant(const char *in, WrapMode &out);
static bool getConstant(WrapMode in, const char *&out); static bool getConstant(WrapMode in, const char *&out);
static bool getConstant(const char *in, Format &out);
static bool getConstant(Format in, const char *&out);
protected: protected:
int width; int width;
@@ -143,9 +132,6 @@ private:
static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[]; static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[];
static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes; static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes;
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
static StringMap<Format, FORMAT_MAX_ENUM> formats;
}; // Texture }; // Texture
} // graphics } // graphics
+139 -37
View File
@@ -423,7 +423,7 @@ static void getStrategy()
} }
} }
Canvas::Canvas(int width, int height, Texture::Format format, int fsaa) Canvas::Canvas(int width, int height, Format format, int fsaa)
: fbo(0) : fbo(0)
, resolve_fbo(0) , resolve_fbo(0)
, texture(0) , texture(0)
@@ -525,39 +525,33 @@ bool Canvas::loadVolatile()
return false; return false;
} }
if (!isFormatSupported(format))
{
status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
return false;
}
glGenTextures(1, &texture); glGenTextures(1, &texture);
gl.bindTexture(texture); gl.bindTexture(texture);
setFilter(filter); setFilter(filter);
setWrap(wrap); setWrap(wrap);
GLint internalformat; GLenum internalformat = GL_RGBA;
GLenum textype; GLenum externalformat = GL_RGBA;
switch (format) GLenum textype = GL_UNSIGNED_BYTE;
{
case Texture::FORMAT_HDR: convertFormat(format, internalformat, externalformat, textype);
internalformat = GL_RGBA16F;
textype = GL_FLOAT;
break;
case Texture::FORMAT_SRGB:
internalformat = GL_SRGB8_ALPHA8;
textype = GL_UNSIGNED_BYTE;
break;
case Texture::FORMAT_NORMAL:
default:
internalformat = GL_RGBA8;
textype = GL_UNSIGNED_BYTE;
}
while (glGetError() != GL_NO_ERROR) while (glGetError() != GL_NO_ERROR)
/* Clear the error buffer. */; /* Clear the error buffer. */;
glTexImage2D(GL_TEXTURE_2D, glTexImage2D(GL_TEXTURE_2D,
0, 0,
internalformat, (GLint) internalformat,
width, height, width, height,
0, 0,
GL_RGBA, externalformat,
textype, textype,
nullptr); nullptr);
@@ -981,41 +975,149 @@ bool Canvas::resolveMSAA()
return true; return true;
} }
Canvas::Format Canvas::getSizedFormat(Canvas::Format format)
{
switch (format)
{
case FORMAT_NORMAL:
return FORMAT_RGBA8;
case FORMAT_HDR:
return FORMAT_RGBA16F;
default:
return format;
}
}
void Canvas::convertFormat(Canvas::Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type)
{
format = getSizedFormat(format);
externalformat = GL_RGBA;
switch (format)
{
case FORMAT_RGBA8:
default:
internalformat = GL_RGBA8;
type = GL_UNSIGNED_BYTE;
break;
case FORMAT_RGBA4:
internalformat = GL_RGBA4;
type = GL_UNSIGNED_SHORT_4_4_4_4;
break;
case FORMAT_RGB5A1:
internalformat = GL_RGB5_A1;
type = GL_UNSIGNED_SHORT_5_5_5_1;
break;
case FORMAT_RGB565:
internalformat = GL_RGB565;
externalformat = GL_RGB;
type = GL_UNSIGNED_SHORT_5_6_5;
break;
case FORMAT_RGB10A2:
internalformat = GL_RGB10_A2;
type = GL_UNSIGNED_INT_10_10_10_2;
break;
case FORMAT_RGB9E5:
internalformat = GL_RGB9_E5;
externalformat = GL_RGB;
type = GL_RGB9_E5;
case FORMAT_RG11B10F:
internalformat = GL_R11F_G11F_B10F;
externalformat = GL_RGB;
type = GL_UNSIGNED_INT_10F_11F_11F_REV;
case FORMAT_RGBA16F:
internalformat = GL_RGBA16F;
type = GL_FLOAT;
break;
case FORMAT_RGBA32F:
internalformat = GL_RGBA32F;
type = GL_FLOAT;
break;
case FORMAT_SRGB:
internalformat = GL_SRGB8_ALPHA8;
type = GL_UNSIGNED_BYTE;
break;
}
}
bool Canvas::isSupported() bool Canvas::isSupported()
{ {
getStrategy(); getStrategy();
return (strategy != &strategyNone); return (strategy != &strategyNone);
} }
bool Canvas::isHDRSupported()
{
return GLEE_VERSION_3_0 || (isSupported() && GLEE_ARB_texture_float);
}
bool Canvas::isSRGBSupported()
{
if (GLEE_VERSION_3_0)
return true;
if (!isSupported())
return false;
return (GLEE_ARB_framebuffer_sRGB || GLEE_EXT_framebuffer_sRGB)
&& GLEE_EXT_texture_sRGB;
}
bool Canvas::isMultiCanvasSupported() bool Canvas::isMultiCanvasSupported()
{ {
// system must support at least 4 simultanious active canvases. // system must support at least 4 simultanious active canvases.
return gl.getMaxRenderTargets() >= 4; return gl.getMaxRenderTargets() >= 4;
} }
bool Canvas::isFormatSupported(Canvas::Format format)
{
if (!isSupported())
return false;
format = getSizedFormat(format);
switch (format)
{
case FORMAT_RGBA8:
case FORMAT_RGBA4:
case FORMAT_RGB5A1:
case FORMAT_RGB10A2:
return true;
case FORMAT_RGB565:
return GLEE_VERSION_4_2 || GLEE_ARB_ES2_compatibility;
case FORMAT_RGB9E5:
return GLEE_VERSION_3_0 || GLEE_EXT_texture_shared_exponent;
case FORMAT_RG11B10F:
return GLEE_VERSION_3_0 || (GLEE_ARB_texture_float && GLEE_ARB_color_buffer_float
&& GLEE_EXT_packed_float);
case FORMAT_RGBA16F:
case FORMAT_RGBA32F:
return GLEE_VERSION_3_0 || (GLEE_ARB_texture_float && GLEE_ARB_color_buffer_float);
case FORMAT_SRGB:
return GLEE_VERSION_3_0 || ((GLEE_ARB_framebuffer_sRGB || GLEE_EXT_framebuffer_sRGB)
&& (GLEE_VERSION_2_1 || GLEE_EXT_texture_sRGB));
default:
return false;
}
}
void Canvas::bindDefaultCanvas() void Canvas::bindDefaultCanvas()
{ {
if (current != nullptr) if (current != nullptr)
current->stopGrab(); current->stopGrab();
} }
bool Canvas::getConstant(const char *in, Format &out)
{
return formats.find(in, out);
}
bool Canvas::getConstant(Format in, const char *&out)
{
return formats.find(in, out);
}
StringMap<Canvas::Format, Canvas::FORMAT_MAX_ENUM>::Entry Canvas::formatEntries[] =
{
{"normal", Canvas::FORMAT_NORMAL},
{"hdr", Canvas::FORMAT_HDR},
{"rgba8", Canvas::FORMAT_RGBA8},
{"rgba4", Canvas::FORMAT_RGBA4},
{"rgb5a1", Canvas::FORMAT_RGB5A1},
{"rgb565", Canvas::FORMAT_RGB565},
{"rgb10a2", Canvas::FORMAT_RGB10A2},
{"rgb9e5", Canvas::FORMAT_RGB9E5},
{"rg11b10f", Canvas::FORMAT_RG11B10F},
{"rgba16f", Canvas::FORMAT_RGBA16F},
{"rgba32f", Canvas::FORMAT_RGBA32F},
{"srgb", Canvas::FORMAT_SRGB},
};
StringMap<Canvas::Format, Canvas::FORMAT_MAX_ENUM> Canvas::formats(Canvas::formatEntries, sizeof(Canvas::formatEntries));
} // opengl } // opengl
} // graphics } // graphics
} // love } // love
+31 -4
View File
@@ -25,6 +25,7 @@
#include "image/Image.h" #include "image/Image.h"
#include "image/ImageData.h" #include "image/ImageData.h"
#include "common/Matrix.h" #include "common/Matrix.h"
#include "common/StringMap.h"
#include "Texture.h" #include "Texture.h"
#include "OpenGL.h" #include "OpenGL.h"
@@ -39,7 +40,25 @@ class Canvas : public Texture
{ {
public: public:
Canvas(int width, int height, Texture::Format format = Texture::FORMAT_NORMAL, int fsaa = 0); // Different Canvas render target formats.
enum Format
{
FORMAT_NORMAL,
FORMAT_HDR,
FORMAT_RGBA8,
FORMAT_RGBA4,
FORMAT_RGB5A1,
FORMAT_RGB565,
FORMAT_RGB10A2,
FORMAT_RGB9E5,
FORMAT_RG11B10F,
FORMAT_RGBA16F,
FORMAT_RGBA32F,
FORMAT_SRGB,
FORMAT_MAX_ENUM
};
Canvas(int width, int height, Format format = FORMAT_NORMAL, int fsaa = 0);
virtual ~Canvas(); virtual ~Canvas();
// Implements Volatile. // Implements Volatile.
@@ -85,7 +104,7 @@ public:
return status; return status;
} }
inline Texture::Format getTextureFormat() const inline Format getTextureFormat() const
{ {
return format; return format;
} }
@@ -98,9 +117,8 @@ public:
bool resolveMSAA(); bool resolveMSAA();
static bool isSupported(); static bool isSupported();
static bool isHDRSupported();
static bool isSRGBSupported();
static bool isMultiCanvasSupported(); static bool isMultiCanvasSupported();
static bool isFormatSupported(Format format);
static Canvas *current; static Canvas *current;
static void bindDefaultCanvas(); static void bindDefaultCanvas();
@@ -111,10 +129,16 @@ public:
// Whether the main screen should have linear -> sRGB conversions enabled. // Whether the main screen should have linear -> sRGB conversions enabled.
static bool screenHasSRGB; static bool screenHasSRGB;
static bool getConstant(const char *in, Format &out);
static bool getConstant(Format in, const char *&out);
private: private:
bool createFSAAFBO(GLenum internalformat); bool createFSAAFBO(GLenum internalformat);
static Format getSizedFormat(Format format);
static void convertFormat(Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type);
GLuint fbo; GLuint fbo;
GLuint resolve_fbo; GLuint resolve_fbo;
@@ -134,6 +158,9 @@ private:
void setupGrab(); void setupGrab();
void drawv(const Matrix &t, const Vertex *v); void drawv(const Matrix &t, const Vertex *v);
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
static StringMap<Format, FORMAT_MAX_ENUM> formats;
}; // Canvas }; // Canvas
} // opengl } // opengl
+11 -10
View File
@@ -409,7 +409,7 @@ void Graphics::discardStencil()
activeStencil = false; activeStencil = false;
} }
Image *Graphics::newImage(love::image::ImageData *data, Texture::Format format) Image *Graphics::newImage(love::image::ImageData *data, Image::Format format)
{ {
// Create the image. // Create the image.
Image *image = new Image(data, format); Image *image = new Image(data, format);
@@ -436,7 +436,7 @@ Image *Graphics::newImage(love::image::ImageData *data, Texture::Format format)
return image; return image;
} }
Image *Graphics::newImage(love::image::CompressedData *cdata, Texture::Format format) Image *Graphics::newImage(love::image::CompressedData *cdata, Image::Format format)
{ {
// Create the image. // Create the image.
Image *image = new Image(cdata, format); Image *image = new Image(cdata, format);
@@ -483,13 +483,14 @@ ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size)
return new ParticleSystem(texture, size); return new ParticleSystem(texture, size);
} }
Canvas *Graphics::newCanvas(int width, int height, Texture::Format format, int fsaa) Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int fsaa)
{ {
if (format == Texture::FORMAT_HDR && !Canvas::isHDRSupported()) if (!Canvas::isFormatSupported(format))
throw Exception("HDR Canvases are not supported by your OpenGL implementation"); {
const char *fstr = "rgba8";
if (format == Texture::FORMAT_SRGB && !Canvas::isSRGBSupported()) Canvas::getConstant(format, fstr);
throw Exception("sRGB Canvases are not supported by your OpenGL implementation"); throw love::Exception("The %s canvas format is not supported by your OpenGL implementation.", fstr);
}
if (width > gl.getMaxTextureSize()) if (width > gl.getMaxTextureSize())
throw Exception("Cannot create canvas: width of %d pixels is too large for this system.", width); throw Exception("Cannot create canvas: width of %d pixels is too large for this system.", width);
@@ -540,8 +541,8 @@ Canvas *Graphics::newCanvas(int width, int height, Texture::Format format, int f
} }
canvas->release(); canvas->release();
throw Exception(error_string.str().c_str()); throw Exception("%s", error_string.str().c_str());
return NULL; // never reached return nullptr; // never reached
} }
Shader *Graphics::newShader(const Shader::ShaderSources &sources) Shader *Graphics::newShader(const Shader::ShaderSources &sources)
+3 -3
View File
@@ -194,8 +194,8 @@ public:
/** /**
* Creates an Image object with padding and/or optimization. * Creates an Image object with padding and/or optimization.
**/ **/
Image *newImage(love::image::ImageData *data, Texture::Format format = Texture::FORMAT_NORMAL); Image *newImage(love::image::ImageData *data, Image::Format format = Image::FORMAT_NORMAL);
Image *newImage(love::image::CompressedData *cdata, Texture::Format format = Texture::FORMAT_NORMAL); Image *newImage(love::image::CompressedData *cdata, Image::Format format = Image::FORMAT_NORMAL);
Quad *newQuad(Quad::Viewport v, float sw, float sh); Quad *newQuad(Quad::Viewport v, float sw, float sh);
@@ -208,7 +208,7 @@ public:
ParticleSystem *newParticleSystem(Texture *texture, int size); ParticleSystem *newParticleSystem(Texture *texture, int size);
Canvas *newCanvas(int width, int height, Texture::Format format = Texture::FORMAT_NORMAL, int fsaa = 0); Canvas *newCanvas(int width, int height, Canvas::Format format = Canvas::FORMAT_NORMAL, int fsaa = 0);
Shader *newShader(const Shader::ShaderSources &sources); Shader *newShader(const Shader::ShaderSources &sources);
+21 -3
View File
@@ -36,7 +36,7 @@ float Image::maxMipmapSharpness = 0.0f;
Texture::FilterMode Image::defaultMipmapFilter = Texture::FILTER_NONE; Texture::FilterMode Image::defaultMipmapFilter = Texture::FILTER_NONE;
float Image::defaultMipmapSharpness = 0.0f; float Image::defaultMipmapSharpness = 0.0f;
Image::Image(love::image::ImageData *data, Texture::Format format) Image::Image(love::image::ImageData *data, Format format)
: data(data) : data(data)
, cdata(nullptr) , cdata(nullptr)
, paddedWidth(width) , paddedWidth(width)
@@ -55,7 +55,7 @@ Image::Image(love::image::ImageData *data, Texture::Format format)
preload(); preload();
} }
Image::Image(love::image::CompressedData *cdata, Texture::Format format) Image::Image(love::image::CompressedData *cdata, Format format)
: data(nullptr) : data(nullptr)
, cdata(cdata) , cdata(cdata)
, paddedWidth(width) , paddedWidth(width)
@@ -504,7 +504,7 @@ bool Image::refresh()
return true; return true;
} }
Texture::Format Image::getFormat() const Image::Format Image::getFormat() const
{ {
return format; return format;
} }
@@ -663,6 +663,24 @@ bool Image::hasSRGBSupport()
return GLEE_VERSION_2_1 || GLEE_EXT_texture_sRGB; return GLEE_VERSION_2_1 || GLEE_EXT_texture_sRGB;
} }
bool Image::getConstant(const char *in, Format &out)
{
return formats.find(in, out);
}
bool Image::getConstant(Format in, const char *&out)
{
return formats.find(in, out);
}
StringMap<Image::Format, Image::FORMAT_MAX_ENUM>::Entry Image::formatEntries[] =
{
{"normal", Image::FORMAT_NORMAL},
{"srgb", Image::FORMAT_SRGB},
};
StringMap<Image::Format, Image::FORMAT_MAX_ENUM> Image::formats(Image::formatEntries, sizeof(Image::formatEntries));
} // opengl } // opengl
} // graphics } // graphics
} // love } // love
+19 -5
View File
@@ -25,6 +25,7 @@
#include "common/config.h" #include "common/config.h"
#include "common/Matrix.h" #include "common/Matrix.h"
#include "common/Vector.h" #include "common/Vector.h"
#include "common/StringMap.h"
#include "common/math.h" #include "common/math.h"
#include "image/ImageData.h" #include "image/ImageData.h"
#include "image/CompressedData.h" #include "image/CompressedData.h"
@@ -50,20 +51,27 @@ class Image : public Texture
{ {
public: public:
enum Format
{
FORMAT_NORMAL,
FORMAT_SRGB,
FORMAT_MAX_ENUM
};
/** /**
* Creates a new Image. Not that anything is ready to use * Creates a new Image. Not that anything is ready to use
* before load is called. * before load is called.
* *
* @param data The data from which to load the image. * @param data The data from which to load the image.
**/ **/
Image(love::image::ImageData *data, Texture::Format format = Texture::FORMAT_NORMAL); Image(love::image::ImageData *data, Format format = FORMAT_NORMAL);
/** /**
* Creates a new Image with compressed image data. * Creates a new Image with compressed image data.
* *
* @param cdata The compressed data from which to load the image. * @param cdata The compressed data from which to load the image.
**/ **/
Image(love::image::CompressedData *cdata, Texture::Format format = Texture::FORMAT_NORMAL); Image(love::image::CompressedData *cdata, Format format = FORMAT_NORMAL);
/** /**
* Destructor. Deletes the hardware texture and other resources. * Destructor. Deletes the hardware texture and other resources.
@@ -120,7 +128,7 @@ public:
**/ **/
bool refresh(); bool refresh();
Texture::Format getFormat() const; Format getFormat() const;
static void setDefaultMipmapSharpness(float sharpness); static void setDefaultMipmapSharpness(float sharpness);
static float getDefaultMipmapSharpness(); static float getDefaultMipmapSharpness();
@@ -137,6 +145,9 @@ public:
static bool hasSRGBSupport(); static bool hasSRGBSupport();
static bool getConstant(const char *in, Format &out);
static bool getConstant(Format in, const char *&out);
private: private:
void uploadDefaultTexture(); void uploadDefaultTexture();
@@ -166,8 +177,8 @@ private:
// Whether this Image is using a compressed texture. // Whether this Image is using a compressed texture.
bool compressed; bool compressed;
// The format to interpret the texture's data as. // The format to interpret the image's data as.
Texture::Format format; Format format;
// True if the image wasn't able to be properly created and it had to fall // True if the image wasn't able to be properly created and it had to fall
// back to a default texture. // back to a default texture.
@@ -189,6 +200,9 @@ private:
GLenum getCompressedFormat(image::CompressedData::Format cformat) const; GLenum getCompressedFormat(image::CompressedData::Format cformat) const;
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
static StringMap<Format, FORMAT_MAX_ENUM> formats;
}; // Image }; // Image
} // opengl } // opengl
+3 -3
View File
@@ -113,10 +113,10 @@ int w_Canvas_clear(lua_State *L)
int w_Canvas_getFormat(lua_State *L) int w_Canvas_getFormat(lua_State *L)
{ {
Canvas *canvas = luax_checkcanvas(L, 1); Canvas *canvas = luax_checkcanvas(L, 1);
Texture::Format format = canvas->getTextureFormat(); Canvas::Format format = canvas->getTextureFormat();
const char *str; const char *str;
if (!Texture::getConstant(format, str)) if (!Canvas::getConstant(format, str))
return luaL_error(L, "Unknown texture format."); return luaL_error(L, "Unknown Canvas format.");
lua_pushstring(L, str); lua_pushstring(L, str);
return 1; return 1;
+21 -11
View File
@@ -155,14 +155,11 @@ int w_newImage(lua_State *L)
love::image::ImageData *data = nullptr; love::image::ImageData *data = nullptr;
love::image::CompressedData *cdata = nullptr; love::image::CompressedData *cdata = nullptr;
Texture::Format format = Texture::FORMAT_NORMAL; Image::Format format = Image::FORMAT_NORMAL;
const char *fstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2); const char *fstr = lua_isnoneornil(L, 2) ? nullptr : luaL_checkstring(L, 2);
if (fstr != nullptr && !Texture::getConstant(fstr, format)) if (fstr != nullptr && !Image::getConstant(fstr, format))
return luaL_error(L, "Invalid texture format: %s", fstr); return luaL_error(L, "Invalid Image format: %s", fstr);
if (format == Texture::FORMAT_HDR) // For now...
return luaL_error(L, "HDR images are not supported.");
// Convert to FileData, if necessary. // Convert to FileData, if necessary.
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T)) if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
@@ -334,9 +331,9 @@ int w_newCanvas(lua_State *L)
const char *str = luaL_optstring(L, 3, "normal"); const char *str = luaL_optstring(L, 3, "normal");
int fsaa = luaL_optint(L, 4, 0); int fsaa = luaL_optint(L, 4, 0);
Texture::Format format; Canvas::Format format;
if (!Texture::getConstant(str, format)) if (!Canvas::getConstant(str, format))
return luaL_error(L, "Invalid texture format: %s", str); return luaL_error(L, "Invalid Canvas format: %s", str);
Canvas *canvas = nullptr; Canvas *canvas = nullptr;
EXCEPT_GUARD(canvas = instance->newCanvas(width, height, format, fsaa);) EXCEPT_GUARD(canvas = instance->newCanvas(width, height, format, fsaa);)
@@ -985,7 +982,7 @@ int w_isSupported(lua_State *L)
supported = false; supported = false;
break; break;
case Graphics::SUPPORT_HDR_CANVAS: case Graphics::SUPPORT_HDR_CANVAS:
if (!Canvas::isHDRSupported()) if (!Canvas::isFormatSupported(Canvas::FORMAT_HDR))
supported = false; supported = false;
break; break;
case Graphics::SUPPORT_MULTI_CANVAS: case Graphics::SUPPORT_MULTI_CANVAS:
@@ -1021,7 +1018,7 @@ int w_isSupported(lua_State *L)
supported = false; supported = false;
break; break;
case Graphics::SUPPORT_SRGB: case Graphics::SUPPORT_SRGB:
if (!Canvas::isSRGBSupported()) if (!Canvas::isFormatSupported(Canvas::FORMAT_SRGB))
supported = false; supported = false;
break; break;
default: default:
@@ -1034,6 +1031,18 @@ int w_isSupported(lua_State *L)
return 1; return 1;
} }
int w_hasCanvasFormat(lua_State *L)
{
const char *str = luaL_checkstring(L, 1);
Canvas::Format format;
if (!Canvas::getConstant(str, format))
return luaL_error(L, "Invalid canvas format: %s", str);
luax_pushboolean(L, Canvas::isFormatSupported(format));
return 1;
}
int w_getRendererInfo(lua_State *L) int w_getRendererInfo(lua_State *L)
{ {
std::string name, version, vendor, device; std::string name, version, vendor, device;
@@ -1410,6 +1419,7 @@ static const luaL_Reg functions[] =
{ "getShader", w_getShader }, { "getShader", w_getShader },
{ "isSupported", w_isSupported }, { "isSupported", w_isSupported },
{ "hasCanvasFormat", w_hasCanvasFormat },
{ "getRendererInfo", w_getRendererInfo }, { "getRendererInfo", w_getRendererInfo },
{ "getSystemLimit", w_getSystemLimit }, { "getSystemLimit", w_getSystemLimit },
@@ -93,6 +93,7 @@ int w_getCanvas(lua_State *L);
int w_setShader(lua_State *L); int w_setShader(lua_State *L);
int w_getShader(lua_State *L); int w_getShader(lua_State *L);
int w_isSupported(lua_State *L); int w_isSupported(lua_State *L);
int w_hasCanvasFormat(lua_State *L);
int w_getRendererInfo(lua_State *L); int w_getRendererInfo(lua_State *L);
int w_getSystemLimit(lua_State *L); int w_getSystemLimit(lua_State *L);
int w_draw(lua_State *L); int w_draw(lua_State *L);