mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Merged default into minor
--HG-- branch : minor
This commit is contained in:
@@ -36,14 +36,14 @@ public:
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
DRAW_LINE = 1,
|
||||
DRAW_LINE,
|
||||
DRAW_FILL,
|
||||
DRAW_MAX_ENUM
|
||||
};
|
||||
|
||||
enum AlignMode
|
||||
{
|
||||
ALIGN_LEFT = 1,
|
||||
ALIGN_LEFT,
|
||||
ALIGN_CENTER,
|
||||
ALIGN_RIGHT,
|
||||
ALIGN_JUSTIFY,
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
enum BlendMode
|
||||
{
|
||||
BLEND_ALPHA = 1,
|
||||
BLEND_ALPHA,
|
||||
BLEND_ADD,
|
||||
BLEND_SUBTRACT,
|
||||
BLEND_MULTIPLY,
|
||||
@@ -64,14 +64,14 @@ public:
|
||||
|
||||
enum LineStyle
|
||||
{
|
||||
LINE_ROUGH = 1,
|
||||
LINE_ROUGH,
|
||||
LINE_SMOOTH,
|
||||
LINE_MAX_ENUM
|
||||
};
|
||||
|
||||
enum LineJoin
|
||||
{
|
||||
LINE_JOIN_NONE = 1,
|
||||
LINE_JOIN_NONE,
|
||||
LINE_JOIN_MITER,
|
||||
LINE_JOIN_BEVEL,
|
||||
LINE_JOIN_MAX_ENUM
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
|
||||
enum Support
|
||||
{
|
||||
SUPPORT_HDR_CANVAS = 1,
|
||||
SUPPORT_HDR_CANVAS,
|
||||
SUPPORT_MULTI_CANVAS,
|
||||
SUPPORT_DXT,
|
||||
SUPPORT_BC5,
|
||||
@@ -90,7 +90,7 @@ public:
|
||||
|
||||
enum RendererInfo
|
||||
{
|
||||
RENDERER_INFO_NAME = 1,
|
||||
RENDERER_INFO_NAME,
|
||||
RENDERER_INFO_VERSION,
|
||||
RENDERER_INFO_VENDOR,
|
||||
RENDERER_INFO_DEVICE,
|
||||
|
||||
@@ -109,16 +109,6 @@ bool Texture::getConstant(WrapMode in, const char *&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[] =
|
||||
{
|
||||
{ "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::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
|
||||
} // love
|
||||
|
||||
@@ -55,14 +55,6 @@ public:
|
||||
FILTER_MAX_ENUM
|
||||
};
|
||||
|
||||
enum Format
|
||||
{
|
||||
FORMAT_NORMAL,
|
||||
FORMAT_HDR,
|
||||
FORMAT_SRGB,
|
||||
FORMAT_MAX_ENUM
|
||||
};
|
||||
|
||||
struct Filter
|
||||
{
|
||||
Filter();
|
||||
@@ -119,9 +111,6 @@ public:
|
||||
static bool getConstant(const char *in, WrapMode &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:
|
||||
|
||||
int width;
|
||||
@@ -143,9 +132,6 @@ private:
|
||||
static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[];
|
||||
static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes;
|
||||
|
||||
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
|
||||
static StringMap<Format, FORMAT_MAX_ENUM> formats;
|
||||
|
||||
}; // Texture
|
||||
|
||||
} // graphics
|
||||
|
||||
@@ -417,7 +417,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)
|
||||
, resolve_fbo(0)
|
||||
, texture(0)
|
||||
@@ -525,33 +525,21 @@ bool Canvas::loadVolatile()
|
||||
setFilter(filter);
|
||||
setWrap(wrap);
|
||||
|
||||
GLint internalformat;
|
||||
GLenum textype;
|
||||
switch (format)
|
||||
{
|
||||
case Texture::FORMAT_HDR:
|
||||
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;
|
||||
}
|
||||
GLenum internalformat = GL_RGBA;
|
||||
GLenum externalformat = GL_RGBA;
|
||||
GLenum textype = GL_UNSIGNED_BYTE;
|
||||
|
||||
convertFormat(format, internalformat, externalformat, textype);
|
||||
|
||||
while (glGetError() != GL_NO_ERROR)
|
||||
/* Clear the error buffer. */;
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
internalformat,
|
||||
(GLint) internalformat,
|
||||
width, height,
|
||||
0,
|
||||
GL_RGBA,
|
||||
externalformat,
|
||||
textype,
|
||||
nullptr);
|
||||
|
||||
@@ -975,41 +963,193 @@ bool Canvas::resolveMSAA()
|
||||
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_RG11B10F:
|
||||
internalformat = GL_R11F_G11F_B10F;
|
||||
externalformat = GL_RGB;
|
||||
type = GL_UNSIGNED_INT_10F_11F_11F_REV;
|
||||
break;
|
||||
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()
|
||||
{
|
||||
getStrategy();
|
||||
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()
|
||||
{
|
||||
// system must support at least 4 simultanious active canvases.
|
||||
return gl.getMaxRenderTargets() >= 4;
|
||||
}
|
||||
|
||||
bool Canvas::supportedFormats[] = {false};
|
||||
bool Canvas::checkedFormats[] = {false};
|
||||
|
||||
bool Canvas::isFormatSupported(Canvas::Format format)
|
||||
{
|
||||
if (!isSupported())
|
||||
return false;
|
||||
|
||||
bool supported = true;
|
||||
format = getSizedFormat(format);
|
||||
|
||||
switch (format)
|
||||
{
|
||||
case FORMAT_RGBA8:
|
||||
case FORMAT_RGBA4:
|
||||
case FORMAT_RGB5A1:
|
||||
case FORMAT_RGB10A2:
|
||||
supported = true;
|
||||
break;
|
||||
case FORMAT_RGB565:
|
||||
supported = GLEE_VERSION_4_2 || GLEE_ARB_ES2_compatibility;
|
||||
break;
|
||||
case FORMAT_RG11B10F:
|
||||
supported = GLEE_VERSION_3_0 || GLEE_EXT_packed_float;
|
||||
break;
|
||||
case FORMAT_RGBA16F:
|
||||
case FORMAT_RGBA32F:
|
||||
supported = GLEE_VERSION_3_0 || GLEE_ARB_texture_float;
|
||||
break;
|
||||
case FORMAT_SRGB:
|
||||
supported = GLEE_VERSION_3_0 || ((GLEE_ARB_framebuffer_sRGB || GLEE_EXT_framebuffer_sRGB)
|
||||
&& (GLEE_VERSION_2_1 || GLEE_EXT_texture_sRGB));
|
||||
break;
|
||||
default:
|
||||
supported = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!supported)
|
||||
return false;
|
||||
|
||||
if (checkedFormats[format])
|
||||
return supportedFormats[format];
|
||||
|
||||
// Even though we might have the necessary OpenGL version or extension,
|
||||
// drivers are still allowed to throw FRAMEBUFFER_UNSUPPORTED when attaching
|
||||
// a texture to a FBO whose format the driver doesn't like. So we should
|
||||
// test with an actual FBO.
|
||||
|
||||
GLenum internalformat = GL_RGBA;
|
||||
GLenum externalformat = GL_RGBA;
|
||||
GLenum textype = GL_UNSIGNED_BYTE;
|
||||
convertFormat(format, internalformat, externalformat, textype);
|
||||
|
||||
GLuint texture = 0;
|
||||
glGenTextures(1, &texture);
|
||||
gl.bindTexture(texture);
|
||||
|
||||
Texture::Filter f;
|
||||
f.min = f.mag = Texture::FILTER_NEAREST;
|
||||
gl.setTextureFilter(f);
|
||||
|
||||
Texture::Wrap w;
|
||||
gl.setTextureWrap(w);
|
||||
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, 2, 2, 0, externalformat, textype, nullptr);
|
||||
|
||||
GLuint fbo = 0;
|
||||
supported = (strategy->createFBO(fbo, texture) == GL_FRAMEBUFFER_COMPLETE);
|
||||
strategy->deleteFBO(fbo, 0, 0);
|
||||
|
||||
gl.deleteTexture(texture);
|
||||
|
||||
// Cache the result so we don't do this for every isFormatSupported call.
|
||||
checkedFormats[format] = true;
|
||||
supportedFormats[format] = supported;
|
||||
|
||||
return supported;
|
||||
}
|
||||
|
||||
void Canvas::bindDefaultCanvas()
|
||||
{
|
||||
if (current != nullptr)
|
||||
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},
|
||||
{"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
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include "image/Image.h"
|
||||
#include "image/ImageData.h"
|
||||
#include "common/Matrix.h"
|
||||
#include "common/StringMap.h"
|
||||
#include "Texture.h"
|
||||
#include "OpenGL.h"
|
||||
|
||||
@@ -39,7 +40,24 @@ class Canvas : public Texture
|
||||
{
|
||||
public:
|
||||
|
||||
Canvas(int width, int height, Texture::Format format = Texture::FORMAT_NORMAL, int fsaa = 0);
|
||||
// Different Canvas render target formats.
|
||||
enum Format
|
||||
{
|
||||
FORMAT_NORMAL, // Usually RGBA8 or a similar fallback. Always supported.
|
||||
FORMAT_HDR, // Usually RGBA16F. Not always supported.
|
||||
FORMAT_RGBA8, // RGBA with 8 bits per component.
|
||||
FORMAT_RGBA4, // RGBA with 4 bits per component.
|
||||
FORMAT_RGB5A1, // RGB with 5 bits per component, and A with 1 bit.
|
||||
FORMAT_RGB565, // RGB with 5, 6, and 5 bits each, respectively.
|
||||
FORMAT_RGB10A2, // RGB with 10 bits each, and A with 2 bits.
|
||||
FORMAT_RG11B10F, // Floating point [0, +inf]. RG with 11 FP bits each, and B with 10 FP bits.
|
||||
FORMAT_RGBA16F, // Floating point [-inf, +inf]. RGBA with 16 FP bits per component.
|
||||
FORMAT_RGBA32F, // Floating point [-inf, +inf]. RGBA with 32 FP bits per component.
|
||||
FORMAT_SRGB, // sRGB with 8 bits per component, plus 8 bit linear A.
|
||||
FORMAT_MAX_ENUM
|
||||
};
|
||||
|
||||
Canvas(int width, int height, Format format = FORMAT_NORMAL, int fsaa = 0);
|
||||
virtual ~Canvas();
|
||||
|
||||
// Implements Volatile.
|
||||
@@ -85,7 +103,7 @@ public:
|
||||
return status;
|
||||
}
|
||||
|
||||
inline Texture::Format getTextureFormat() const
|
||||
inline Format getTextureFormat() const
|
||||
{
|
||||
return format;
|
||||
}
|
||||
@@ -98,9 +116,8 @@ public:
|
||||
bool resolveMSAA();
|
||||
|
||||
static bool isSupported();
|
||||
static bool isHDRSupported();
|
||||
static bool isSRGBSupported();
|
||||
static bool isMultiCanvasSupported();
|
||||
static bool isFormatSupported(Format format);
|
||||
|
||||
static Canvas *current;
|
||||
static void bindDefaultCanvas();
|
||||
@@ -111,10 +128,16 @@ public:
|
||||
// Whether the main screen should have linear -> sRGB conversions enabled.
|
||||
static bool screenHasSRGB;
|
||||
|
||||
static bool getConstant(const char *in, Format &out);
|
||||
static bool getConstant(Format in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
bool createFSAAFBO(GLenum internalformat);
|
||||
|
||||
static Format getSizedFormat(Format format);
|
||||
static void convertFormat(Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type);
|
||||
|
||||
GLuint fbo;
|
||||
GLuint resolve_fbo;
|
||||
|
||||
@@ -134,6 +157,12 @@ private:
|
||||
void setupGrab();
|
||||
void drawv(const Matrix &t, const Vertex *v);
|
||||
|
||||
static bool supportedFormats[FORMAT_MAX_ENUM];
|
||||
static bool checkedFormats[FORMAT_MAX_ENUM];
|
||||
|
||||
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
|
||||
static StringMap<Format, FORMAT_MAX_ENUM> formats;
|
||||
|
||||
}; // Canvas
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -142,7 +142,7 @@ private:
|
||||
|
||||
enum FontType
|
||||
{
|
||||
FONT_TRUETYPE = 1,
|
||||
FONT_TRUETYPE,
|
||||
FONT_IMAGE,
|
||||
FONT_UNKNOWN
|
||||
};
|
||||
|
||||
@@ -428,7 +428,7 @@ void Graphics::discardStencil()
|
||||
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.
|
||||
Image *image = new Image(data, format);
|
||||
@@ -455,7 +455,7 @@ Image *Graphics::newImage(love::image::ImageData *data, Texture::Format format)
|
||||
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.
|
||||
Image *image = new Image(cdata, format);
|
||||
@@ -502,13 +502,14 @@ ParticleSystem *Graphics::newParticleSystem(Texture *texture, int 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())
|
||||
throw Exception("HDR Canvases are not supported by your OpenGL implementation");
|
||||
|
||||
if (format == Texture::FORMAT_SRGB && !Canvas::isSRGBSupported())
|
||||
throw Exception("sRGB Canvases are not supported by your OpenGL implementation");
|
||||
if (!Canvas::isFormatSupported(format))
|
||||
{
|
||||
const char *fstr = "rgba8";
|
||||
Canvas::getConstant(format, fstr);
|
||||
throw love::Exception("The %s canvas format is not supported by your OpenGL implementation.", fstr);
|
||||
}
|
||||
|
||||
if (width > gl.getMaxTextureSize())
|
||||
throw Exception("Cannot create canvas: width of %d pixels is too large for this system.", width);
|
||||
@@ -559,8 +560,8 @@ Canvas *Graphics::newCanvas(int width, int height, Texture::Format format, int f
|
||||
}
|
||||
|
||||
canvas->release();
|
||||
throw Exception(error_string.str().c_str());
|
||||
return NULL; // never reached
|
||||
throw Exception("%s", error_string.str().c_str());
|
||||
return nullptr; // never reached
|
||||
}
|
||||
|
||||
Shader *Graphics::newShader(const Shader::ShaderSources &sources)
|
||||
|
||||
@@ -192,8 +192,8 @@ public:
|
||||
/**
|
||||
* 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::CompressedData *cdata, Texture::Format format = Texture::FORMAT_NORMAL);
|
||||
Image *newImage(love::image::ImageData *data, Image::Format format = Image::FORMAT_NORMAL);
|
||||
Image *newImage(love::image::CompressedData *cdata, Image::Format format = Image::FORMAT_NORMAL);
|
||||
|
||||
Quad *newQuad(Quad::Viewport v, float sw, float sh);
|
||||
|
||||
@@ -206,7 +206,7 @@ public:
|
||||
|
||||
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);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ float Image::maxMipmapSharpness = 0.0f;
|
||||
Texture::FilterMode Image::defaultMipmapFilter = Texture::FILTER_NONE;
|
||||
float Image::defaultMipmapSharpness = 0.0f;
|
||||
|
||||
Image::Image(love::image::ImageData *data, Texture::Format format)
|
||||
Image::Image(love::image::ImageData *data, Format format)
|
||||
: data(data)
|
||||
, cdata(nullptr)
|
||||
, texture(0)
|
||||
@@ -53,7 +53,7 @@ Image::Image(love::image::ImageData *data, Texture::Format format)
|
||||
preload();
|
||||
}
|
||||
|
||||
Image::Image(love::image::CompressedData *cdata, Texture::Format format)
|
||||
Image::Image(love::image::CompressedData *cdata, Format format)
|
||||
: data(nullptr)
|
||||
, cdata(cdata)
|
||||
, texture(0)
|
||||
@@ -420,7 +420,7 @@ bool Image::refresh()
|
||||
return true;
|
||||
}
|
||||
|
||||
Texture::Format Image::getFormat() const
|
||||
Image::Format Image::getFormat() const
|
||||
{
|
||||
return format;
|
||||
}
|
||||
@@ -556,6 +556,24 @@ bool Image::hasSRGBSupport()
|
||||
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
|
||||
} // graphics
|
||||
} // love
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#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/CompressedData.h"
|
||||
@@ -50,20 +51,27 @@ class Image : public Texture
|
||||
{
|
||||
public:
|
||||
|
||||
enum Format
|
||||
{
|
||||
FORMAT_NORMAL,
|
||||
FORMAT_SRGB,
|
||||
FORMAT_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
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.
|
||||
*
|
||||
* @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.
|
||||
@@ -120,7 +128,7 @@ public:
|
||||
**/
|
||||
bool refresh();
|
||||
|
||||
Texture::Format getFormat() const;
|
||||
Format getFormat() const;
|
||||
|
||||
static void setDefaultMipmapSharpness(float sharpness);
|
||||
static float getDefaultMipmapSharpness();
|
||||
@@ -131,6 +139,9 @@ public:
|
||||
static bool hasCompressedTextureSupport(image::CompressedData::Format format);
|
||||
static bool hasSRGBSupport();
|
||||
|
||||
static bool getConstant(const char *in, Format &out);
|
||||
static bool getConstant(Format in, const char *&out);
|
||||
|
||||
private:
|
||||
|
||||
void uploadDefaultTexture();
|
||||
@@ -157,8 +168,8 @@ private:
|
||||
// Whether this Image is using a compressed texture.
|
||||
bool compressed;
|
||||
|
||||
// The format to interpret the texture's data as.
|
||||
Texture::Format format;
|
||||
// The format to interpret the image's data as.
|
||||
Format format;
|
||||
|
||||
// True if the image wasn't able to be properly created and it had to fall
|
||||
// back to a default texture.
|
||||
@@ -179,6 +190,9 @@ private:
|
||||
|
||||
GLenum getCompressedFormat(image::CompressedData::Format cformat) const;
|
||||
|
||||
static StringMap<Format, FORMAT_MAX_ENUM>::Entry formatEntries[];
|
||||
static StringMap<Format, FORMAT_MAX_ENUM> formats;
|
||||
|
||||
}; // Image
|
||||
|
||||
} // opengl
|
||||
|
||||
@@ -98,10 +98,9 @@ Shader::~Shader()
|
||||
detach();
|
||||
|
||||
for (auto it = boundRetainables.begin(); it != boundRetainables.end(); ++it)
|
||||
{
|
||||
it->second->release();
|
||||
boundRetainables.erase(it);
|
||||
}
|
||||
|
||||
boundRetainables.clear();
|
||||
|
||||
unloadVolatile();
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ public:
|
||||
|
||||
enum UsageHint
|
||||
{
|
||||
USAGE_DYNAMIC = 1,
|
||||
USAGE_DYNAMIC,
|
||||
USAGE_STATIC,
|
||||
USAGE_STREAM,
|
||||
USAGE_MAX_ENUM
|
||||
|
||||
@@ -115,10 +115,18 @@ void VertexBuffer::unmap()
|
||||
is_bound = true;
|
||||
}
|
||||
|
||||
// "orphan" current buffer to avoid implicit synchronisation on the GPU:
|
||||
// http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf
|
||||
glBufferData(getTarget(), (GLsizeiptr) getSize(), NULL, getUsage());
|
||||
glBufferData(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage());
|
||||
if (getUsage() == GL_STATIC_DRAW)
|
||||
{
|
||||
// Upload the mapped data to the buffer.
|
||||
glBufferSubData(getTarget(), 0, (GLsizeiptr) getSize(), memory_map);
|
||||
}
|
||||
else
|
||||
{
|
||||
// "orphan" current buffer to avoid implicit synchronisation on the GPU:
|
||||
// http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf
|
||||
glBufferData(getTarget(), (GLsizeiptr) getSize(), NULL, getUsage());
|
||||
glBufferData(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage());
|
||||
}
|
||||
|
||||
is_mapped = false;
|
||||
}
|
||||
|
||||
@@ -113,10 +113,10 @@ int w_Canvas_clear(lua_State *L)
|
||||
int w_Canvas_getFormat(lua_State *L)
|
||||
{
|
||||
Canvas *canvas = luax_checkcanvas(L, 1);
|
||||
Texture::Format format = canvas->getTextureFormat();
|
||||
Canvas::Format format = canvas->getTextureFormat();
|
||||
const char *str;
|
||||
if (!Texture::getConstant(format, str))
|
||||
return luaL_error(L, "Unknown texture format.");
|
||||
if (!Canvas::getConstant(format, str))
|
||||
return luaL_error(L, "Unknown Canvas format.");
|
||||
|
||||
lua_pushstring(L, str);
|
||||
return 1;
|
||||
|
||||
@@ -149,14 +149,11 @@ int w_newImage(lua_State *L)
|
||||
love::image::ImageData *data = 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);
|
||||
|
||||
if (fstr != nullptr && !Texture::getConstant(fstr, format))
|
||||
return luaL_error(L, "Invalid texture format: %s", fstr);
|
||||
|
||||
if (format == Texture::FORMAT_HDR) // For now...
|
||||
return luaL_error(L, "HDR images are not supported.");
|
||||
if (fstr != nullptr && !Image::getConstant(fstr, format))
|
||||
return luaL_error(L, "Invalid Image format: %s", fstr);
|
||||
|
||||
// Convert to FileData, if necessary.
|
||||
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
@@ -328,9 +325,9 @@ int w_newCanvas(lua_State *L)
|
||||
const char *str = luaL_optstring(L, 3, "normal");
|
||||
int fsaa = luaL_optint(L, 4, 0);
|
||||
|
||||
Texture::Format format;
|
||||
if (!Texture::getConstant(str, format))
|
||||
return luaL_error(L, "Invalid texture format: %s", str);
|
||||
Canvas::Format format;
|
||||
if (!Canvas::getConstant(str, format))
|
||||
return luaL_error(L, "Invalid Canvas format: %s", str);
|
||||
|
||||
Canvas *canvas = nullptr;
|
||||
EXCEPT_GUARD(canvas = instance->newCanvas(width, height, format, fsaa);)
|
||||
@@ -944,7 +941,7 @@ int w_isSupported(lua_State *L)
|
||||
switch (support)
|
||||
{
|
||||
case Graphics::SUPPORT_HDR_CANVAS:
|
||||
if (!Canvas::isHDRSupported())
|
||||
if (!Canvas::isFormatSupported(Canvas::FORMAT_HDR))
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_MULTI_CANVAS:
|
||||
@@ -964,7 +961,7 @@ int w_isSupported(lua_State *L)
|
||||
supported = false;
|
||||
break;
|
||||
case Graphics::SUPPORT_SRGB:
|
||||
if (!Canvas::isSRGBSupported())
|
||||
if (!Canvas::isFormatSupported(Canvas::FORMAT_SRGB))
|
||||
supported = false;
|
||||
break;
|
||||
default:
|
||||
@@ -977,6 +974,18 @@ int w_isSupported(lua_State *L)
|
||||
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)
|
||||
{
|
||||
std::string name, version, vendor, device;
|
||||
@@ -1351,6 +1360,7 @@ static const luaL_Reg functions[] =
|
||||
{ "getShader", w_getShader },
|
||||
|
||||
{ "isSupported", w_isSupported },
|
||||
{ "hasCanvasFormat", w_hasCanvasFormat },
|
||||
{ "getRendererInfo", w_getRendererInfo },
|
||||
{ "getSystemLimit", w_getSystemLimit },
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ int w_getCanvas(lua_State *L);
|
||||
int w_setShader(lua_State *L);
|
||||
int w_getShader(lua_State *L);
|
||||
int w_isSupported(lua_State *L);
|
||||
int w_hasCanvasFormat(lua_State *L);
|
||||
int w_getRendererInfo(lua_State *L);
|
||||
int w_getSystemLimit(lua_State *L);
|
||||
int w_draw(lua_State *L);
|
||||
|
||||
Reference in New Issue
Block a user