Renamed CompressedData:getNumMipmaps to CompressedData:getMipmapCount; Improved type-checking error messages for some functions which expect function arguments

This commit is contained in:
Alex Szpakowski
2013-05-02 17:26:50 -04:00
parent 77c6efd8fd
commit 3bf43dadd8
14 changed files with 43 additions and 44 deletions
+7 -7
View File
@@ -645,14 +645,15 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
{
strategy->bindFBO( fbo );
if (current != this)
strategy->bindFBO(fbo);
glReadPixels(x, height - y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixel_rgba);
if (current)
strategy->bindFBO( current->fbo );
else
strategy->bindFBO( 0 );
if (current && current != this)
strategy->bindFBO(current->fbo);
else if (!current)
strategy->bindFBO(0);
}
const std::vector<Canvas *> &Canvas::getAttachedCanvases() const
@@ -692,8 +693,7 @@ bool Canvas::loadVolatile()
setFilter(settings.filter);
setWrap(settings.wrap);
Color c;
c.r = c.g = c.b = c.a = 0;
Color c(0, 0, 0, 0);
clear(c);
return true;
}
+3 -1
View File
@@ -880,7 +880,9 @@ void Graphics::printf(const char *str, float x, float y, float wrap, AlignMode a
if (currentFont == 0)
return;
using namespace std;
using std::string;
using std::vector;
string text(str);
vector<string> lines_to_draw = currentFont->getWrap(text, wrap);
+4 -4
View File
@@ -131,21 +131,21 @@ void Image::uploadCompressedMipmaps()
bind();
int numMipmaps = cdata->getNumMipmaps();
int mipmapcount = cdata->getMipmapCount();
// We have to inform OpenGL if the image doesn't have all mipmap levels.
if (GLEE_VERSION_1_2 || GLEE_SGIS_texture_lod)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, numMipmaps - 1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipmapcount - 1);
}
else if (cdata->getWidth(numMipmaps-1) > 1 || cdata->getHeight(numMipmaps-1) > 1)
else if (cdata->getWidth(mipmapcount-1) > 1 || cdata->getHeight(mipmapcount-1) > 1)
{
// Telling OpenGL to ignore certain levels isn't always supported.
throw love::Exception("Cannot load mipmaps: "
"compressed image does not have all required levels.");
}
for (int i = 1; i < numMipmaps; i++)
for (int i = 1; i < mipmapcount; i++)
{
glCompressedTexImage2DARB(GL_TEXTURE_2D,
i,
+9 -10
View File
@@ -44,8 +44,7 @@ int w_Canvas_renderTo(lua_State *L)
}
Canvas *canvas = luax_checkcanvas(L, 1);
if (!lua_isfunction(L, 2))
return luaL_error(L, "Need a function to render to canvas.");
luaL_checktype(L, 2, LUA_TFUNCTION);
try
{
@@ -182,19 +181,19 @@ int w_Canvas_clear(lua_State *L)
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 2, i);
c.r = (unsigned char)luaL_checkint(L, -4);
c.g = (unsigned char)luaL_checkint(L, -3);
c.b = (unsigned char)luaL_checkint(L, -2);
c.a = (unsigned char)luaL_optint(L, -1, 255);
c.r = (unsigned char)luaL_checkinteger(L, -4);
c.g = (unsigned char)luaL_checkinteger(L, -3);
c.b = (unsigned char)luaL_checkinteger(L, -2);
c.a = (unsigned char)luaL_optinteger(L, -1, 255);
lua_pop(L, 4);
}
else
{
c.r = (unsigned char)luaL_checkint(L, 2);
c.g = (unsigned char)luaL_checkint(L, 3);
c.b = (unsigned char)luaL_checkint(L, 4);
c.a = (unsigned char)luaL_optint(L, 5, 255);
c.r = (unsigned char)luaL_checkinteger(L, 2);
c.g = (unsigned char)luaL_checkinteger(L, 3);
c.b = (unsigned char)luaL_checkinteger(L, 4);
c.a = (unsigned char)luaL_optinteger(L, 5, 255);
}
canvas->clear(c);
@@ -241,8 +241,7 @@ int w_getScissor(lua_State *L)
int w_newStencil(lua_State *L)
{
// just return the function
if (!lua_isfunction(L, 1))
return luaL_typerror(L, 1, "function");
luaL_checktype(L, 1, LUA_TFUNCTION);
lua_settop(L, 1);
return 1;
}
@@ -256,8 +255,7 @@ static int setStencil(lua_State *L, bool invert)
return 0;
}
if (!lua_isfunction(L, 1))
return luaL_typerror(L, 1, "mask");
luaL_checktype(L, 1, LUA_TFUNCTION);
instance->defineStencil();
lua_call(L, lua_gettop(L) - 1, 0); // call mask(...)
+1 -1
View File
@@ -55,7 +55,7 @@ void *CompressedData::getData() const
return 0;
}
int CompressedData::getNumMipmaps() const
int CompressedData::getMipmapCount() const
{
return dataImages.size();
}
+2 -2
View File
@@ -77,10 +77,10 @@ public:
virtual int getSize() const;
/**
* Gets the number of mipmaps in this CompressedData.
* Gets the number of mipmaps in this Compressed Image Data.
* Includes the base image level.
**/
int getNumMipmaps() const;
int getMipmapCount() const;
/**
* Gets the size in bytes of a sub-image at the specified mipmap level.
+6 -6
View File
@@ -40,7 +40,7 @@ int w_CompressedData_getString(lua_State *L)
size_t totalsize = 0;
for (int i = 0; i < t->getNumMipmaps(); i++)
for (int i = 0; i < t->getMipmapCount(); i++)
totalsize += t->getSize(i);
if (totalsize == 0)
@@ -60,7 +60,7 @@ int w_CompressedData_getString(lua_State *L)
}
size_t curpos = 0;
for (int i = 0; i < t->getNumMipmaps(); i++)
for (int i = 0; i < t->getMipmapCount(); i++)
{
memcpy(&datastr[curpos], t->getData(i), t->getSize(i));
curpos += t->getSize(i);
@@ -79,7 +79,7 @@ int w_CompressedData_getSize(lua_State *L)
size_t totalsize = 0;
for (int i = 0; i < t->getNumMipmaps(); i++)
for (int i = 0; i < t->getMipmapCount(); i++)
totalsize += t->getSize(i);
lua_pushnumber(L, (lua_Number) totalsize);
@@ -140,10 +140,10 @@ int w_CompressedData_getDimensions(lua_State *L)
return 2;
}
int w_CompressedData_getNumMipmaps(lua_State *L)
int w_CompressedData_getMipmapCount(lua_State *L)
{
CompressedData *t = luax_checkcompresseddata(L, 1);
lua_pushinteger(L, t->getNumMipmaps());
lua_pushinteger(L, t->getMipmapCount());
return 1;
}
@@ -172,7 +172,7 @@ static const luaL_Reg functions[] =
{ "getWidth", w_CompressedData_getWidth },
{ "getHeight", w_CompressedData_getHeight },
{ "getDimensions", w_CompressedData_getDimensions },
{ "getNumMipmaps", w_CompressedData_getNumMipmaps },
{ "getMipmapCount", w_CompressedData_getMipmapCount },
{ "getType", w_CompressedData_getType },
{ 0, 0 },
};
+1 -1
View File
@@ -36,7 +36,7 @@ int w_CompressedData_getSize(lua_State *L);
int w_CompressedData_getWidth(lua_State *L);
int w_CompressedData_getHeight(lua_State *L);
int w_CompressedData_getDimensions(lua_State *L);
int w_CompressedData_getNumMipmaps(lua_State *L);
int w_CompressedData_getMipmapCount(lua_State *L);
int w_CompressedData_getType(lua_State *L);
extern "C" int luaopen_compresseddata(lua_State *L);
+1 -2
View File
@@ -101,8 +101,7 @@ int w_ImageData_mapPixel(lua_State *L)
{
ImageData *t = luax_checkimagedata(L, 1);
if (!lua_isfunction(L, 2))
return luaL_error(L, "Function expected");
luaL_checktype(L, 2, LUA_TFUNCTION);
int w = t->getWidth();
int h = t->getHeight();
+3 -2
View File
@@ -116,12 +116,12 @@ static const luaL_Reg modules[] = {
{ "love.image", luaopen_love_image },
{ "love.joystick", luaopen_love_joystick },
{ "love.keyboard", luaopen_love_keyboard },
{ "love.math", luaopen_love_math },
{ "love.mouse", luaopen_love_mouse },
{ "love.physics", luaopen_love_physics },
{ "love.sound", luaopen_love_sound },
{ "love.timer", luaopen_love_timer },
{ "love.thread", luaopen_love_thread },
{ "love.math", luaopen_love_math },
{ "love.boot", luaopen_love_boot },
{ 0, 0 }
};
@@ -242,7 +242,8 @@ int w__openConsole(lua_State * L)
int luaopen_love_boot(lua_State *L)
{
if (luaL_loadbuffer(L, (const char *)love::boot_lua, sizeof(love::boot_lua), "boot.lua") == 0)
lua_call(L, 0, 1);
lua_call(L, 0, 1);
return 1;
}
+4 -1
View File
@@ -18,14 +18,17 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "MathModule.h"
#include "common/math.h"
// STL
#include <cmath>
#include <list>
#include <iostream>
using namespace std;
using std::list;
using std::vector;
using love::vertex;
namespace
-1
View File
@@ -32,7 +32,6 @@
#include "libraries/noise1234/simplexnoise1234.h"
// STL
#include <limits>
#include <vector>
namespace love