Merged default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2014-06-05 03:02:50 -03:00
68 changed files with 1439 additions and 524 deletions
+1
View File
@@ -191,6 +191,7 @@ void Image::createMipmaps()
GL_RGBA,
GL_UNSIGNED_BYTE,
data->getData());
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_FALSE);
}
}
+30 -50
View File
@@ -39,7 +39,6 @@ Mesh::Mesh(const std::vector<Vertex> &verts, Mesh::DrawMode mode)
, ibo(nullptr)
, element_count(0)
, element_data_type(getGLDataTypeFromMax(verts.size()))
, instance_count(1)
, draw_mode(mode)
, range_min(-1)
, range_max(-1)
@@ -175,20 +174,7 @@ void Mesh::setVertexMap(const std::vector<uint32> &map)
GLenum datatype = getGLDataTypeFromMax(vertex_count);
// Calculate the size in bytes of the index buffer data.
size_t size = map.size();
switch (datatype)
{
case GL_UNSIGNED_BYTE:
size *= sizeof(uint8);
break;
case GL_UNSIGNED_SHORT:
size *= sizeof(uint16);
break;
case GL_UNSIGNED_INT:
default:
size *= sizeof(uint32);
break;
}
size_t size = map.size() * getGLDataTypeSize(datatype);
if (ibo && size > ibo->getSize())
{
@@ -232,10 +218,10 @@ void Mesh::setVertexMap(const std::vector<uint32> &map)
* Copies index data from a mapped buffer to a vector.
**/
template <typename T>
static void copyFromIndexBuffer(void *buffer, std::vector<uint32> &indices, size_t maxval)
static void copyFromIndexBuffer(void *buffer, size_t count, std::vector<uint32> &indices)
{
T *elems = (T *) buffer;
for (size_t i = 0; i < maxval; i++)
for (size_t i = 0; i < count; i++)
indices.push_back((uint32) elems[i]);
}
@@ -256,14 +242,14 @@ void Mesh::getVertexMap(std::vector<uint32> &map) const
switch (element_data_type)
{
case GL_UNSIGNED_BYTE:
copyFromIndexBuffer<uint8>(buffer, map, vertex_count);
copyFromIndexBuffer<uint8>(buffer, element_count, map);
break;
case GL_UNSIGNED_SHORT:
copyFromIndexBuffer<uint16>(buffer, map, vertex_count);
copyFromIndexBuffer<uint16>(buffer, element_count, map);
break;
case GL_UNSIGNED_INT:
default:
copyFromIndexBuffer<uint32>(buffer, map, vertex_count);
copyFromIndexBuffer<uint32>(buffer, element_count, map);
break;
}
}
@@ -273,16 +259,6 @@ size_t Mesh::getVertexMapCount() const
return element_count;
}
void Mesh::setInstanceCount(int count)
{
instance_count = std::max(count, 1);
}
int Mesh::getInstanceCount() const
{
return instance_count;
}
void Mesh::setTexture(Texture *tex)
{
tex->retain();
@@ -398,35 +374,29 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
int max = element_count - 1;
if (range_max >= 0)
max = std::min(std::max(range_max, 0), (int) element_count - 1);
max = std::min(range_max, max);
int min = 0;
if (range_min >= 0)
min = std::min(std::max(range_min, 0), max);
min = std::min(range_min, max);
const void *indices = ibo->getPointer(min * sizeof(uint32));
GLenum type = element_data_type;
const void *indices = ibo->getPointer(min * getGLDataTypeSize(type));
if (instance_count > 1)
gl.drawElementsInstanced(mode, max - min + 1, type, indices, instance_count);
else
glDrawElements(mode, max - min + 1, type, indices);
glDrawElements(mode, max - min + 1, type, indices);
}
else
{
int max = vertex_count - 1;
if (range_max >= 0)
max = std::min(std::max(range_max, 0), (int) vertex_count - 1);
max = std::min(range_max, max);
int min = 0;
if (range_min >= 0)
min = std::min(std::max(range_min, 0), max);
min = std::min(range_min, max);
// Normal non-indexed drawing (no custom vertex map.)
if (instance_count > 1)
gl.drawArraysInstanced(mode, min, max - min + 1, instance_count);
else
glDrawArrays(mode, min, max - min + 1);
glDrawArrays(mode, min, max - min + 1);
}
glDisableClientState(GL_VERTEX_ARRAY);
@@ -454,24 +424,34 @@ GLenum Mesh::getGLDrawMode(DrawMode mode) const
case DRAW_MODE_STRIP:
return GL_TRIANGLE_STRIP;
case DRAW_MODE_TRIANGLES:
default:
return GL_TRIANGLES;
case DRAW_MODE_POINTS:
return GL_POINTS;
default:
break;
}
return GL_TRIANGLES;
}
GLenum Mesh::getGLDataTypeFromMax(size_t maxvalue) const
{
if (maxvalue > LOVE_UINT16_MAX)
return GL_UNSIGNED_INT;
else if (maxvalue > LOVE_UINT8_MAX)
return GL_UNSIGNED_SHORT;
else
return GL_UNSIGNED_BYTE;
return GL_UNSIGNED_SHORT;
}
size_t Mesh::getGLDataTypeSize(GLenum datatype) const
{
switch (datatype)
{
case GL_UNSIGNED_BYTE:
return sizeof(uint8);
case GL_UNSIGNED_SHORT:
return sizeof(uint16);
case GL_UNSIGNED_INT:
return sizeof(uint32);
default:
return 0;
}
}
bool Mesh::getConstant(const char *in, Mesh::DrawMode &out)
+1 -11
View File
@@ -119,15 +119,6 @@ public:
**/
size_t getVertexMapCount() const;
/**
* Sets the number of instances of this Mesh to draw (uses hardware
* instancing when possible.)
* A custom vertex shader is necessary in order to introduce differences
* in each instance.
**/
void setInstanceCount(int count);
int getInstanceCount() const;
/**
* Sets the texture used when drawing the Mesh.
**/
@@ -171,6 +162,7 @@ private:
GLenum getGLDrawMode(DrawMode mode) const;
GLenum getGLDataTypeFromMax(size_t maxvalue) const;
size_t getGLDataTypeSize(GLenum datatype) const;
// Vertex buffer.
VertexBuffer *vbo;
@@ -181,8 +173,6 @@ private:
size_t element_count;
GLenum element_data_type;
int instance_count;
DrawMode draw_mode;
int range_min;
+2 -2
View File
@@ -40,7 +40,7 @@ int w_Canvas_renderTo(lua_State *L)
// Save the current Canvas so we can restore it when we're done.
Canvas *oldcanvas = Canvas::current;
EXCEPT_GUARD(canvas->startGrab();)
luax_catchexcept(L, [&](){ canvas->startGrab(); });
lua_settop(L, 2); // make sure the function is on top of the stack
lua_call(L, 0, 0);
@@ -69,7 +69,7 @@ int w_Canvas_getPixel(lua_State * L)
int y = luaL_checkint(L, 3);
unsigned char c[4];
EXCEPT_GUARD(canvas->getPixel(c, x, y);)
luax_catchexcept(L, [&](){ canvas->getPixel(c, x, y); });
lua_pushnumber(L, c[0]);
lua_pushnumber(L, c[1]);
+6 -6
View File
@@ -45,7 +45,7 @@ int w_Font_getWidth(lua_State *L)
Font *t = luax_checkfont(L, 1);
const char *str = luaL_checkstring(L, 2);
EXCEPT_GUARD(lua_pushinteger(L, t->getWidth(str));)
luax_catchexcept(L, [&](){ lua_pushinteger(L, t->getWidth(str)); });
return 1;
}
@@ -56,10 +56,10 @@ int w_Font_getWrap(lua_State *L)
float wrap = (float) luaL_checknumber(L, 3);
int max_width = 0, numlines = 0;
EXCEPT_GUARD(
luax_catchexcept(L, [&]() {
std::vector<std::string> lines = t->getWrap(str, wrap, &max_width);
numlines = lines.size();
)
});
lua_pushinteger(L, max_width);
lua_pushinteger(L, numlines);
@@ -96,7 +96,7 @@ int w_Font_setFilter(lua_State *L)
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
EXCEPT_GUARD(t->setFilter(f);)
luax_catchexcept(L, [&](){ t->setFilter(f); });
return 0;
}
@@ -143,7 +143,7 @@ int w_Font_hasGlyphs(lua_State *L)
int count = lua_gettop(L) - 1;
count = count < 1 ? 1 : count;
EXCEPT_GUARD(
luax_catchexcept(L, [&]() {
for (int i = 2; i < count + 2; i++)
{
if (lua_type(L, i) == LUA_TSTRING)
@@ -154,7 +154,7 @@ int w_Font_hasGlyphs(lua_State *L)
if (!hasglyph)
break;
}
)
});
luax_pushboolean(L, hasglyph);
return 1;
+76 -48
View File
@@ -22,7 +22,9 @@
#include "OpenGL.h"
#include "graphics/Texture.h"
#include "image/ImageData.h"
#include "image/Image.h"
#include "font/Rasterizer.h"
#include "filesystem/wrap_Filesystem.h"
#include "scripts/graphics.lua.h"
#include <cassert>
@@ -155,43 +157,59 @@ int w_newImage(lua_State *L)
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))
luax_convobj(L, 1, "filesystem", "newFileData");
bool releasedata = false;
// Convert to ImageData/CompressedData, if necessary.
if (luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
// Convert to ImageData / CompressedData, if necessary.
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
{
// Determine whether to convert to ImageData or CompressedData.
luax_getfunction(L, "image", "isCompressed");
lua_pushvalue(L, 1);
lua_call(L, 1, 1);
love::image::Image *image = (love::image::Image *) Module::findInstance("love.image.");
if (image == nullptr)
return luaL_error(L, "Cannot load images without the love.image module.");
bool compressed = luax_toboolean(L, -1);
lua_pop(L, 1);
love::filesystem::FileData *fdata = love::filesystem::luax_getfiledata(L, 1);
if (compressed)
luax_convobj(L, 1, "image", "newCompressedData");
if (image->isCompressed(fdata))
{
luax_catchexcept(L,
[&]() { cdata = image->newCompressedData(fdata); },
[&]() { fdata->release(); }
);
}
else
luax_convobj(L, 1, "image", "newImageData");
}
{
luax_catchexcept(L,
[&]() { data = image->newImageData(fdata); },
[&]() { fdata->release(); }
);
}
if (luax_istype(L, 1, IMAGE_COMPRESSED_DATA_T))
// Lua's GC won't release the image data, so we should do it ourselves.
releasedata = true;
}
else if (luax_istype(L, 1, IMAGE_COMPRESSED_DATA_T))
cdata = luax_checktype<love::image::CompressedData>(L, 1, "CompressedData", IMAGE_COMPRESSED_DATA_T);
else
data = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
if (!data && !cdata)
return luaL_error(L, "Error creating image.");
return luaL_error(L, "Error creating image (could not load data.)");
// Create the image.
Image *image = nullptr;
EXCEPT_GUARD(
if (cdata)
image = instance->newImage(cdata, format);
else if (data)
image = instance->newImage(data, format);
)
luax_catchexcept(L,
[&]() {
if (cdata)
image = instance->newImage(cdata, format);
else if (data)
image = instance->newImage(data, format);
},
[&]() {
if (releasedata && data)
data->release();
else if (releasedata && cdata)
cdata->release();
}
);
if (image == nullptr)
return luaL_error(L, "Could not load image.");
@@ -219,12 +237,8 @@ int w_newQuad(lua_State *L)
int w_newFont(lua_State *L)
{
// Convert to FileData, if necessary.
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
luax_convobj(L, 1, "filesystem", "newFileData");
// Convert to Rasterizer, if necessary.
if (luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
{
int idxs[] = {1, 2};
luax_convobj(L, idxs, 2, "font", "newRasterizer");
@@ -233,7 +247,9 @@ int w_newFont(lua_State *L)
love::font::Rasterizer *rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
Font *font = 0;
EXCEPT_GUARD(font = instance->newFont(rasterizer, instance->getDefaultFilter());)
luax_catchexcept(L, [&]() {
font = instance->newFont(rasterizer, instance->getDefaultFilter()); }
);
if (font == 0)
return luaL_error(L, "Could not load font.");
@@ -297,7 +313,9 @@ int w_newSpriteBatch(lua_State *L)
}
SpriteBatch *t = nullptr;
EXCEPT_GUARD(t = instance->newSpriteBatch(texture, size, usage);)
luax_catchexcept(L,
[&](){ t = instance->newSpriteBatch(texture, size, usage); }
);
luax_pushtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, t);
return 1;
@@ -311,7 +329,9 @@ int w_newParticleSystem(lua_State *L)
if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES)
return luaL_error(L, "Invalid ParticleSystem size");
EXCEPT_GUARD(t = instance->newParticleSystem(texture, int(size));)
luax_catchexcept(L,
[&](){ t = instance->newParticleSystem(texture, int(size)); }
);
luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, t);
return 1;
@@ -330,7 +350,9 @@ int w_newCanvas(lua_State *L)
return luaL_error(L, "Invalid Canvas format: %s", str);
Canvas *canvas = nullptr;
EXCEPT_GUARD(canvas = instance->newCanvas(width, height, format, fsaa);)
luax_catchexcept(L,
[&](){ canvas = instance->newCanvas(width, height, format, fsaa); }
);
if (canvas == nullptr)
return luaL_error(L, "Canvas not created, but no error thrown. I don't even...");
@@ -498,13 +520,13 @@ int w_newMesh(lua_State *L)
vertices.push_back(v);
}
EXCEPT_GUARD(t = instance->newMesh(vertices, mode);)
luax_catchexcept(L, [&](){ t = instance->newMesh(vertices, mode); });
t->setVertexColors(use_colors);
}
else
{
int count = luaL_checkint(L, 1);
EXCEPT_GUARD(t = instance->newMesh(count, mode);)
luax_catchexcept(L, [&](){ t = instance->newMesh(count, mode); });
}
if (tex)
@@ -643,7 +665,7 @@ int w_setBlendMode(lua_State *L)
if (!Graphics::getConstant(str, mode))
return luaL_error(L, "Invalid blend mode: %s", str);
EXCEPT_GUARD(instance->setBlendMode(mode);)
luax_catchexcept(L, [&](){ instance->setBlendMode(mode); });
return 0;
}
@@ -652,7 +674,7 @@ int w_getBlendMode(lua_State *L)
const char *str;
Graphics::BlendMode mode;
EXCEPT_GUARD(mode = instance->getBlendMode();)
luax_catchexcept(L, [&](){ mode = instance->getBlendMode(); });
if (!Graphics::getConstant(mode, str))
return luaL_error(L, "Unknown blend mode");
@@ -822,7 +844,7 @@ int w_newScreenshot(lua_State *L)
bool copyAlpha = luax_optboolean(L, 1, false);
love::image::ImageData *i = 0;
EXCEPT_GUARD(i = instance->newScreenshot(image, copyAlpha);)
luax_catchexcept(L, [&](){ i = instance->newScreenshot(image, copyAlpha); });
luax_pushtype(L, "ImageData", IMAGE_IMAGE_DATA_T, i);
return 1;
@@ -866,12 +888,12 @@ int w_setCanvas(lua_State *L)
attachments.push_back(luax_checkcanvas(L, i));
}
EXCEPT_GUARD(
luax_catchexcept(L, [&]() {
if (attachments.size() > 0)
canvas->startGrab(attachments);
else
canvas->startGrab();
)
});
return 0;
}
@@ -990,10 +1012,12 @@ int w_getRendererInfo(lua_State *L)
{
std::string name, version, vendor, device;
EXCEPT_GUARD(name = instance->getRendererInfo(Graphics::RENDERER_INFO_NAME);)
EXCEPT_GUARD(version = instance->getRendererInfo(Graphics::RENDERER_INFO_VERSION);)
EXCEPT_GUARD(vendor = instance->getRendererInfo(Graphics::RENDERER_INFO_VENDOR);)
EXCEPT_GUARD(device = instance->getRendererInfo(Graphics::RENDERER_INFO_DEVICE);)
luax_catchexcept(L, [&]() {
name = instance->getRendererInfo(Graphics::RENDERER_INFO_NAME);
version = instance->getRendererInfo(Graphics::RENDERER_INFO_VERSION);
vendor = instance->getRendererInfo(Graphics::RENDERER_INFO_VENDOR);
device = instance->getRendererInfo(Graphics::RENDERER_INFO_DEVICE);
});
luax_pushstring(L, name);
luax_pushstring(L, version);
@@ -1069,7 +1093,9 @@ int w_print(lua_State *L)
float kx = (float)luaL_optnumber(L, 9, 0.0f);
float ky = (float)luaL_optnumber(L, 10, 0.0f);
EXCEPT_GUARD(instance->print(str, x, y, angle, sx, sy, ox, oy, kx,ky);)
luax_catchexcept(L,
[&](){ instance->print(str, x, y, angle, sx, sy, ox, oy, kx,ky); }
);
return 0;
}
@@ -1105,7 +1131,9 @@ int w_printf(lua_State *L)
ky = (float) luaL_optnumber(L, 12, 0.0f);
}
EXCEPT_GUARD(instance->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky);)
luax_catchexcept(L,
[&](){ instance->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky); }
);
return 0;
}
@@ -1261,13 +1289,13 @@ int w_polygon(lua_State *L)
int w_push(lua_State *L)
{
EXCEPT_GUARD(instance->push();)
luax_catchexcept(L, [&](){ instance->push(); });
return 0;
}
int w_pop(lua_State *L)
{
EXCEPT_GUARD(instance->pop();)
luax_catchexcept(L, [&](){ instance->pop(); });
return 0;
}
@@ -1417,7 +1445,7 @@ extern "C" int luaopen_love_graphics(lua_State *L)
{
if (instance == 0)
{
EXCEPT_GUARD(instance = new Graphics();)
luax_catchexcept(L, [&](){ instance = new Graphics(); });
}
else
instance->retain();
+2 -2
View File
@@ -47,7 +47,7 @@ int w_Image_setMipmapFilter(lua_State *L)
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
}
EXCEPT_GUARD(t->setFilter(f);)
luax_catchexcept(L, [&](){ t->setFilter(f); });
float sharpness = (float) luaL_optnumber(L, 3, 0);
t->setMipmapSharpness(sharpness);
@@ -81,7 +81,7 @@ int w_Image_isCompressed(lua_State *L)
int w_Image_refresh(lua_State *L)
{
Image *i = luax_checkimage(L, 1);
EXCEPT_GUARD(i->refresh();)
luax_catchexcept(L, [&](){ i->refresh(); });
return 0;
}
+6 -26
View File
@@ -74,7 +74,7 @@ int w_Mesh_setVertex(lua_State *L)
v.a = luaL_optinteger(L, 10, 255);
}
EXCEPT_GUARD(t->setVertex(i, v);)
luax_catchexcept(L, [&](){ t->setVertex(i, v); });
return 0;
}
@@ -84,7 +84,7 @@ int w_Mesh_getVertex(lua_State *L)
size_t i = (size_t) (luaL_checkinteger(L, 2) - 1);
Vertex v;
EXCEPT_GUARD(v = t->getVertex(i);)
luax_catchexcept(L, [&](){ v = t->getVertex(i); });
lua_pushnumber(L, v.x);
lua_pushnumber(L, v.y);
@@ -134,7 +134,7 @@ int w_Mesh_setVertices(lua_State *L)
vertices.push_back(v);
}
EXCEPT_GUARD(t->setVertices(vertices);)
luax_catchexcept(L, [&](){ t->setVertices(vertices); });
return 0;
}
@@ -216,7 +216,7 @@ int w_Mesh_setVertexMap(lua_State *L)
vertexmap.push_back(uint32(luaL_checkinteger(L, i + 2) - 1));
}
EXCEPT_GUARD(t->setVertexMap(vertexmap);)
luax_catchexcept(L, [&](){ t->setVertexMap(vertexmap); });
return 0;
}
@@ -225,7 +225,7 @@ int w_Mesh_getVertexMap(lua_State *L)
Mesh *t = luax_checkmesh(L, 1);
std::vector<uint32> vertex_map;
EXCEPT_GUARD(t->getVertexMap(vertex_map);)
luax_catchexcept(L, [&](){ t->getVertexMap(vertex_map); });
size_t element_count = vertex_map.size();
@@ -240,20 +240,6 @@ int w_Mesh_getVertexMap(lua_State *L)
return 1;
}
int w_Mesh_setInstanceCount(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
t->setInstanceCount(luaL_checkint(L, 2));
return 0;
}
int w_Mesh_getInstanceCount(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
lua_pushinteger(L, t->getInstanceCount());
return 1;
}
int w_Mesh_setTexture(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
@@ -329,7 +315,7 @@ int w_Mesh_setDrawRange(lua_State *L)
{
int rangemin = luaL_checkint(L, 2) - 1;
int rangemax = luaL_checkint(L, 3) - 1;
EXCEPT_GUARD(t->setDrawRange(rangemin, rangemax);)
luax_catchexcept(L, [&](){ t->setDrawRange(rangemin, rangemax); });
}
return 0;
@@ -374,12 +360,6 @@ static const luaL_Reg functions[] =
{ "getVertexCount", w_Mesh_getVertexCount },
{ "setVertexMap", w_Mesh_setVertexMap },
{ "getVertexMap", w_Mesh_getVertexMap },
// Disabled for now, since implementation is incomplete and might change
// if/when VertexBuffers / custom vertex attributes are added.
// { "setInstanceCount", w_Mesh_setInstanceCount },
// { "getInstanceCount", w_Mesh_getInstanceCount },
{ "setTexture", w_Mesh_setTexture },
{ "getTexture", w_Mesh_getTexture },
{ "setDrawMode", w_Mesh_setDrawMode },
-2
View File
@@ -41,8 +41,6 @@ int w_Mesh_getVertices(lua_State *L);
int w_Mesh_getVertexCount(lua_State *L);
int w_Mesh_setVertexMap(lua_State *L);
int w_Mesh_getVertexMap(lua_State *L);
int w_Mesh_setInstanceCount(lua_State *L);
int w_Mesh_getInstanceCount(lua_State *L);
int w_Mesh_setTexture(lua_State *L);
int w_Mesh_getTexture(lua_State *L);
int w_Mesh_setDrawMode(lua_State *L);
@@ -49,7 +49,7 @@ int w_ParticleSystem_clone(lua_State *L)
ParticleSystem *t = luax_checkparticlesystem(L, 1);
ParticleSystem *clone = nullptr;
EXCEPT_GUARD(clone = t->clone();)
luax_catchexcept(L, [&](){ clone = t->clone(); });
luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, clone);
return 1;
@@ -90,7 +90,7 @@ int w_ParticleSystem_setBufferSize(lua_State *L)
if (arg1 < 1.0 || arg1 > ParticleSystem::MAX_PARTICLES)
return luaL_error(L, "Invalid buffer size");
EXCEPT_GUARD(t->setBufferSize((uint32) arg1);)
luax_catchexcept(L, [&](){ t->setBufferSize((uint32) arg1); });
return 0;
}
@@ -128,7 +128,7 @@ int w_ParticleSystem_setEmissionRate(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
float arg1 = (float) luaL_checknumber(L, 2);
EXCEPT_GUARD(t->setEmissionRate(arg1);)
luax_catchexcept(L, [&](){ t->setEmissionRate(arg1); });
return 0;
}
+5 -17
View File
@@ -232,22 +232,10 @@ int w_Shader_sendMatrix(lua_State *L)
lua_pop(L, 1 + dimension);
}
bool should_error = false;
try
{
shader->sendMatrix(name, dimension, values, count);
}
catch(love::Exception &e)
{
should_error = true;
lua_pushstring(L, e.what());
}
delete[] values;
if (should_error)
return luaL_error(L, "%s", lua_tostring(L, -1));
luax_catchexcept(L,
[&]() { shader->sendMatrix(name, dimension, values, count); },
[&]() { delete[] values; }
);
return 0;
}
@@ -258,7 +246,7 @@ int w_Shader_sendTexture(lua_State *L)
const char *name = luaL_checkstring(L, 2);
Texture *texture = luax_checktexture(L, 3);
EXCEPT_GUARD(shader->sendTexture(name, texture);)
luax_catchexcept(L, [&](){ shader->sendTexture(name, texture); });
return 0;
}
@@ -64,12 +64,12 @@ int w_SpriteBatch_add(lua_State *L)
float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
int id = 0;
EXCEPT_GUARD(
luax_catchexcept(L, [&]() {
if (quad)
id = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky);
else
id = t->add(x, y, a, sx, sy, ox, oy, kx, ky);
)
});
lua_pushinteger(L, id);
return 1;
@@ -101,12 +101,12 @@ int w_SpriteBatch_set(lua_State *L)
float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
EXCEPT_GUARD(
luax_catchexcept(L, [&]() {
if (quad)
t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, id);
else
t->add(x, y, a, sx, sy, ox, oy, kx, ky, id);
)
});
return 0;
}
@@ -216,7 +216,7 @@ int w_SpriteBatch_setBufferSize(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
int size = luaL_checkint(L, 2);
EXCEPT_GUARD(t->setBufferSize(size);)
luax_catchexcept(L, [&]() {t->setBufferSize(size); });
return 0;
}
+1 -1
View File
@@ -69,7 +69,7 @@ int w_Texture_setFilter(lua_State *L)
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
EXCEPT_GUARD(t->setFilter(f);)
luax_catchexcept(L, [&](){ t->setFilter(f); });
return 0;
}