More internal code cleanup

This commit is contained in:
Alex Szpakowski
2013-03-31 19:02:27 -03:00
parent eef4eed636
commit d5aa807747
19 changed files with 105 additions and 124 deletions
+1 -2
View File
@@ -507,7 +507,7 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
for (size_t i = 0; i < canvases.size(); i++)
canvases[i]->retain();
// release previously attached canvases
// release any old canvases
for (size_t i = 0; i < attachedCanvases.size(); i++)
attachedCanvases[i]->release();
@@ -687,7 +687,6 @@ void Canvas::unloadVolatile()
settings.wrap = getWrap();
strategy->deleteFBO(fbo, depth_stencil, img);
// release attached canvases
for (size_t i = 0; i < attachedCanvases.size(); i++)
attachedCanvases[i]->release();
+25 -25
View File
@@ -51,20 +51,20 @@ Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
{
// try to find the best texture size match for the font size
// default to the largest texture size if no rough match is found
texture_size_index = NUM_TEXTURE_SIZES - 1;
textureSizeIndex = NUM_TEXTURE_SIZES - 1;
for (int i = 0; i < NUM_TEXTURE_SIZES; i++)
{
// base our chosen texture width/height on a very rough guess of the total size taken up by the font's used glyphs
// the estimate is likely larger than the actual total size taken up, which is good since texture changes are expensive
if ((height * 0.8) * height * 95 <= TEXTURE_WIDTHS[i] * TEXTURE_HEIGHTS[i])
{
texture_size_index = i;
textureSizeIndex = i;
break;
}
}
texture_width = TEXTURE_WIDTHS[texture_size_index];
texture_height = TEXTURE_HEIGHTS[texture_size_index];
textureWidth = TEXTURE_WIDTHS[textureSizeIndex];
textureHeight = TEXTURE_HEIGHTS[textureSizeIndex];
love::font::GlyphData *gd = 0;
@@ -102,8 +102,8 @@ bool Font::initializeTexture(GLint format)
glTexImage2D(GL_TEXTURE_2D,
0,
internalformat,
(GLsizei)texture_width,
(GLsizei)texture_height,
(GLsizei)textureWidth,
(GLsizei)textureHeight,
0,
format,
GL_UNSIGNED_BYTE,
@@ -114,7 +114,7 @@ bool Font::initializeTexture(GLint format)
void Font::createTexture()
{
texture_x = texture_y = rowHeight = TEXTURE_PADDING;
textureX = textureY = rowHeight = TEXTURE_PADDING;
GLuint t;
glGenTextures(1, &t);
@@ -132,17 +132,17 @@ void Font::createTexture()
// try to initialize the texture, attempting smaller sizes if initialization fails
bool initialized = false;
while (texture_size_index >= 0)
while (textureSizeIndex >= 0)
{
texture_width = TEXTURE_WIDTHS[texture_size_index];
texture_height = TEXTURE_HEIGHTS[texture_size_index];
textureWidth = TEXTURE_WIDTHS[textureSizeIndex];
textureHeight = TEXTURE_HEIGHTS[textureSizeIndex];
initialized = initializeTexture(format);
if (initialized || texture_size_index <= 0)
if (initialized || textureSizeIndex <= 0)
break;
--texture_size_index;
--textureSizeIndex;
}
if (!initialized)
@@ -156,12 +156,12 @@ void Font::createTexture()
}
// Fill the texture with transparent black
std::vector<GLubyte> emptyData(texture_width * texture_height * (type == FONT_TRUETYPE ? 2 : 4), 0);
std::vector<GLubyte> emptyData(textureWidth * textureHeight * (type == FONT_TRUETYPE ? 2 : 4), 0);
glTexSubImage2D(GL_TEXTURE_2D,
0,
0, 0,
(GLsizei)texture_width,
(GLsizei)texture_height,
(GLsizei)textureWidth,
(GLsizei)textureHeight,
format,
GL_UNSIGNED_BYTE,
&emptyData[0]);
@@ -175,14 +175,14 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
int w = gd->getWidth();
int h = gd->getHeight();
if (texture_x + w + TEXTURE_PADDING > texture_width)
if (textureX + w + TEXTURE_PADDING > textureWidth)
{
// out of space - new row!
texture_x = TEXTURE_PADDING;
texture_y += rowHeight;
textureX = TEXTURE_PADDING;
textureY += rowHeight;
rowHeight = TEXTURE_PADDING;
}
if (texture_y + h + TEXTURE_PADDING > texture_height)
if (textureY + h + TEXTURE_PADDING > textureHeight)
{
// totally out of space - new texture!
createTexture();
@@ -203,8 +203,8 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
bindTexture(t);
glTexSubImage2D(GL_TEXTURE_2D,
0,
texture_x,
texture_y,
textureX,
textureY,
w, h,
(type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA),
GL_UNSIGNED_BYTE,
@@ -213,12 +213,12 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
g->texture = t;
Quad::Viewport v;
v.x = (float) texture_x;
v.y = (float) texture_y;
v.x = (float) textureX;
v.y = (float) textureY;
v.w = (float) w;
v.h = (float) h;
Quad q = Quad(v, (const float) texture_width, (const float) texture_height);
Quad q = Quad(v, (const float) textureWidth, (const float) textureHeight);
const vertex *verts = q.getVertices();
// copy vertex data to the glyph and set proper bearing
@@ -231,7 +231,7 @@ Font::Glyph *Font::addGlyph(unsigned int glyph)
}
if (w > 0)
texture_x += (w + TEXTURE_PADDING);
textureX += (w + TEXTURE_PADDING);
if (h > 0)
rowHeight = std::max(rowHeight, h + TEXTURE_PADDING);
+10 -6
View File
@@ -183,12 +183,16 @@ private:
float lineHeight;
float mSpacing; // modifies the spacing by multiplying it with this value
int texture_size_index;
int texture_width;
int texture_height;
int textureSizeIndex;
int textureWidth;
int textureHeight;
// vector of packed textures
std::vector<GLuint> textures;
// maps glyphs to glyph texture information
std::map<unsigned int, Glyph *> glyphs;
std::vector<GLuint> textures; // vector of packed textures
std::map<unsigned int, Glyph *> glyphs; // maps glyphs to quad information
FontType type;
Image::Filter filter;
@@ -198,7 +202,7 @@ private:
static const int TEXTURE_PADDING = 1;
int texture_x, texture_y;
int textureX, textureY;
int rowHeight;
bool initializeTexture(GLint format);
+7 -11
View File
@@ -272,33 +272,29 @@ bool Graphics::isCreated() const
int Graphics::getModes(lua_State *L) const
{
int n;
love::window::Window::WindowSize **modes = currentWindow->getFullscreenSizes(n);
love::window::Window::WindowSize *modes = currentWindow->getFullscreenSizes(n);
if (modes == 0)
return 0;
lua_newtable(L);
lua_createtable(L, n, 0);
for (int i = 0; i < n ; i++)
{
lua_pushinteger(L, i+1);
lua_newtable(L);
lua_createtable(L, 0, 2);
// Inner table attribs.
lua_pushstring(L, "width");
lua_pushinteger(L, modes[i]->width);
lua_settable(L, -3);
lua_pushinteger(L, modes[i].width);
lua_setfield(L, -2, "width");
lua_pushstring(L, "height");
lua_pushinteger(L, modes[i]->height);
lua_settable(L, -3);
lua_pushinteger(L, modes[i].height);
lua_setfield(L, -2, "height");
// Inner table attribs end.
lua_settable(L, -3);
delete modes[i];
}
delete[] modes;
+7 -4
View File
@@ -71,9 +71,12 @@ Shader::Shader(const ShaderSources &sources)
if (shaderSources.empty())
throw love::Exception("Cannot create shader: no source code!");
GLint maxtexunits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
maxTextureUnits = std::max(maxtexunits - 1, 0);
if (maxTextureUnits <= 0)
{
GLint maxtexunits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
maxTextureUnits = std::max(maxtexunits - 1, 0);
}
// initialize global texture id counters if needed
if (textureCounters.size() < (size_t) maxTextureUnits)
@@ -174,7 +177,7 @@ void Shader::createProgram(const std::vector<GLuint> &shaderids)
if (status == GL_FALSE)
{
const std::string warnings = getWarnings();
std::string warnings = getWarnings();
glDeleteProgram(program);
throw love::Exception("Cannot link shader program object:\n%s", warnings.c_str());
+7 -7
View File
@@ -179,14 +179,14 @@ int w_Canvas_clear(lua_State *L)
}
else if (lua_istable(L, 2))
{
lua_rawgeti(L, 2, 1);
c.r = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 2, 2);
c.g = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 2, 3);
c.b = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 2, 4);
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.g = (unsigned char)luaL_optint(L, -1, 255);
lua_pop(L, 4);
}
else
+15 -14
View File
@@ -601,14 +601,14 @@ int w_setColor(lua_State *L)
Color c;
if (lua_istable(L, 1))
{
lua_rawgeti(L, 1, 1);
c.r = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 1, 2);
c.g = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 1, 3);
c.b = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 1, 4);
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 1, 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);
lua_pop(L, 4);
}
else
@@ -637,14 +637,14 @@ int w_setBackgroundColor(lua_State *L)
Color c;
if (lua_istable(L, 1))
{
lua_rawgeti(L, 1, 1);
c.r = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 1, 2);
c.g = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 1, 3);
c.b = (unsigned char)luaL_checkint(L, -1);
lua_rawgeti(L, 1, 4);
for (int i = 1; i <= 4; i++)
lua_rawgeti(L, 1, 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);
lua_pop(L, 4);
}
else
@@ -985,6 +985,7 @@ int w_setCanvases(lua_State *L)
if (is_table)
{
// grab the first canvas in the array and attach the rest
lua_rawgeti(L, 1, 1);
canvas = luax_checkcanvas(L, -1);
lua_pop(L, 1);
@@ -158,18 +158,15 @@ int w_SpriteBatch_setColor(lua_State *L)
}
else if (lua_istable(L, 2))
{
lua_rawgeti(L, 2, 1);
c.r = (unsigned char) luaL_checkint(L, -1);
lua_pop(L, 1);
lua_rawgeti(L, 2, 2);
c.g = (unsigned char) luaL_checkint(L, -1);
lua_pop(L, 1);
lua_rawgeti(L, 2, 3);
c.b = (unsigned char) luaL_checkint(L, -1);
lua_pop(L, 1);
lua_rawgeti(L, 2, 4);
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);
lua_pop(L, 1);
lua_pop(L, 4);
}
else
{