mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Merged default into minor.
--HG-- branch : minor
This commit is contained in:
@@ -117,6 +117,7 @@ public:
|
||||
return actual_samples;
|
||||
}
|
||||
|
||||
static Format getSizedFormat(Format format);
|
||||
static bool isSupported();
|
||||
static bool isMultiFormatMultiCanvasSupported();
|
||||
static bool isFormatSupported(Format format);
|
||||
@@ -143,7 +144,6 @@ private:
|
||||
|
||||
void drawv(const Matrix4 &t, const Vertex *v);
|
||||
|
||||
static Format getSizedFormat(Format format);
|
||||
static void convertFormat(Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type);
|
||||
static size_t getFormatBitsPerPixel(Format format);
|
||||
|
||||
|
||||
@@ -459,17 +459,23 @@ void Graphics::clear(const std::vector<OptionalColorf> &colors)
|
||||
if (colors.size() == 0)
|
||||
return;
|
||||
|
||||
if (states.back().canvases.size() == 0)
|
||||
size_t numcanvases = states.back().canvases.size();
|
||||
|
||||
if (numcanvases > 0 && colors.size() != numcanvases)
|
||||
throw love::Exception("Number of clear colors must match the number of active canvases (%ld)", states.back().canvases.size());
|
||||
|
||||
// We want to take the single-color codepath if there's no active Canvas, or
|
||||
// if there's only one active Canvas. The multi-color codepath (in the loop
|
||||
// below) assumes MRT functions are available, and also may call more
|
||||
// expensive GL functions which are unnecessary if only one Canvas is active.
|
||||
if (numcanvases <= 1)
|
||||
{
|
||||
if (colors[0].enabled)
|
||||
clear({colors[0].r, colors[0].g, colors[0].b, colors[0].a});
|
||||
clear(colors[0].toColor());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (colors.size() != states.back().canvases.size())
|
||||
throw love::Exception("Number of clear colors must match the number of active canvases (%ld)", states.back().canvases.size());
|
||||
|
||||
bool drawbuffermodified = false;
|
||||
|
||||
for (int i = 0; i < (int) colors.size(); i++)
|
||||
@@ -840,11 +846,14 @@ ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size)
|
||||
|
||||
Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int msaa)
|
||||
{
|
||||
if (!Canvas::isSupported())
|
||||
throw love::Exception("Canvases are not supported by your OpenGL drivers!");
|
||||
|
||||
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);
|
||||
Canvas::getConstant(Canvas::getSizedFormat(format), fstr);
|
||||
throw love::Exception("The %s canvas format is not supported by your OpenGL drivers.", fstr);
|
||||
}
|
||||
|
||||
if (width > gl.getMaxTextureSize())
|
||||
@@ -868,7 +877,7 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int ms
|
||||
switch (err)
|
||||
{
|
||||
case GL_FRAMEBUFFER_UNSUPPORTED:
|
||||
error_string << "Not supported by your OpenGL implementation.";
|
||||
error_string << "Not supported by your OpenGL drivers.";
|
||||
break;
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
|
||||
error_string << "Texture format cannot be rendered to on this system.";
|
||||
@@ -879,14 +888,14 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int ms
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER:
|
||||
case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
|
||||
error_string << "Error in implementation.";
|
||||
error_string << "Error in graphics driver.";
|
||||
break;
|
||||
default:
|
||||
// my intel hda card wrongly returns 0 to glCheckFramebufferStatus() but sets
|
||||
// no error flag. I think it meant to return GL_FRAMEBUFFER_UNSUPPORTED, but who
|
||||
// knows.
|
||||
if (glGetError() == GL_NO_ERROR)
|
||||
error_string << "May not be supported by your OpenGL implementation.";
|
||||
error_string << "May not be supported by your OpenGL drivers.";
|
||||
// the remaining error is an indication of a serious fuckup since it should
|
||||
// only be returned if glCheckFramebufferStatus() was called with the wrong
|
||||
// arguments.
|
||||
|
||||
@@ -66,6 +66,8 @@ public:
|
||||
{
|
||||
float r, g, b, a;
|
||||
bool enabled;
|
||||
|
||||
Colorf toColor() const { return Colorf(r, g, b, a); }
|
||||
};
|
||||
|
||||
Graphics();
|
||||
|
||||
@@ -47,6 +47,13 @@ namespace opengl
|
||||
|
||||
#define instance() (Module::getInstance<Graphics>(Module::M_GRAPHICS))
|
||||
|
||||
static int luax_checkgraphicscreated(lua_State *L)
|
||||
{
|
||||
if (!instance()->isCreated())
|
||||
return luaL_error(L, "love.graphics cannot function without a window!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_reset(lua_State *)
|
||||
{
|
||||
instance()->reset();
|
||||
@@ -290,6 +297,8 @@ static const char *imageFlagName(Image::FlagType flagtype)
|
||||
|
||||
int w_newImage(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
std::vector<love::image::ImageData *> data;
|
||||
std::vector<love::image::CompressedImageData *> cdata;
|
||||
|
||||
@@ -400,6 +409,8 @@ int w_newImage(lua_State *L)
|
||||
|
||||
int w_newQuad(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
Quad::Viewport v;
|
||||
v.x = luaL_checknumber(L, 1);
|
||||
v.y = luaL_checknumber(L, 2);
|
||||
@@ -417,6 +428,8 @@ int w_newQuad(lua_State *L)
|
||||
|
||||
int w_newFont(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
Font *font = nullptr;
|
||||
|
||||
// Convert to Rasterizer, if necessary.
|
||||
@@ -443,6 +456,8 @@ int w_newFont(lua_State *L)
|
||||
|
||||
int w_newImageFont(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
// filter for glyphs
|
||||
Texture::Filter filter = instance()->getDefaultFilter();
|
||||
|
||||
@@ -483,6 +498,8 @@ int w_newImageFont(lua_State *L)
|
||||
|
||||
int w_newSpriteBatch(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
Texture *texture = luax_checktexture(L, 1);
|
||||
int size = (int) luaL_optnumber(L, 2, 1000);
|
||||
Mesh::Usage usage = Mesh::USAGE_DYNAMIC;
|
||||
@@ -505,6 +522,8 @@ int w_newSpriteBatch(lua_State *L)
|
||||
|
||||
int w_newParticleSystem(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
Texture *texture = luax_checktexture(L, 1);
|
||||
lua_Number size = luaL_optnumber(L, 2, 1000);
|
||||
ParticleSystem *t = 0;
|
||||
@@ -522,6 +541,8 @@ int w_newParticleSystem(lua_State *L)
|
||||
|
||||
int w_newCanvas(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
// check if width and height are given. else default to screen dimensions.
|
||||
int width = (int) luaL_optnumber(L, 1, instance()->getWidth());
|
||||
int height = (int) luaL_optnumber(L, 2, instance()->getHeight());
|
||||
@@ -547,6 +568,8 @@ int w_newCanvas(lua_State *L)
|
||||
|
||||
int w_newShader(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
// clamp stack to 2 elements
|
||||
lua_settop(L, 2);
|
||||
|
||||
@@ -848,6 +871,8 @@ static Mesh *newCustomMesh(lua_State *L)
|
||||
|
||||
int w_newMesh(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
// Check first argument: table or number of vertices.
|
||||
int arg1type = lua_type(L, 1);
|
||||
if (arg1type != LUA_TTABLE && arg1type != LUA_TNUMBER)
|
||||
@@ -868,6 +893,8 @@ int w_newMesh(lua_State *L)
|
||||
|
||||
int w_newText(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
Font *font = luax_checkfont(L, 1);
|
||||
Text *t = nullptr;
|
||||
|
||||
@@ -888,6 +915,8 @@ int w_newText(lua_State *L)
|
||||
|
||||
int w_newVideo(lua_State *L)
|
||||
{
|
||||
luax_checkgraphicscreated(L);
|
||||
|
||||
if (!luax_istype(L, 1, VIDEO_VIDEO_STREAM_ID))
|
||||
luax_convobj(L, 1, "video", "newVideoStream");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user