Updated to love-android changeset 3b5e5e182a00

This commit is contained in:
Martin Felis
2014-01-12 21:21:46 +01:00
parent 0ff0941068
commit 69b200b144
396 changed files with 52558 additions and 2317 deletions
-65
View File
@@ -1,65 +0,0 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_DRAWQABLE_H
#define LOVE_GRAPHICS_DRAWQABLE_H
// LOVE
#include "Drawable.h"
#include "Quad.h"
namespace love
{
namespace graphics
{
/**
* A DrawQable is anything that be drawn in part with a Quad object.
**/
class DrawQable : public Drawable
{
public:
/**
* Destructor.
**/
virtual ~DrawQable() {}
/**
* Draws the object with the specified transformation.
*
* @param quad The Quad object to use to draw the object.
* @param x The position of the object along the x-axis.
* @param y The position of the object along the y-axis.
* @param angle The angle of the object (in radians).
* @param sx The scale factor along the x-axis.
* @param sy The scale factor along the y-axis.
* @param ox The origin offset along the x-axis.
* @param oy The origin offset along the y-axis.
* @param kx Shear along the x-axis.
* @param ky Shear along the y-axis.
**/
virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
};
} // graphics
} // love
#endif // LOVE_GRAPHICS_DRAWQABLE_H
+2 -2
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -40,7 +40,7 @@ public:
/**
* Destructor.
**/
virtual ~Drawable();
virtual ~Drawable() {}
/**
* Draws the object with the specified transformation.
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
-96
View File
@@ -1,96 +0,0 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Image.h"
namespace love
{
namespace graphics
{
Image::Filter Image::defaultFilter;
Image::Filter::Filter()
: min(FILTER_LINEAR)
, mag(FILTER_LINEAR)
, mipmap(FILTER_NONE)
, anisotropy(1.0f)
{
}
Image::Wrap::Wrap()
: s(WRAP_CLAMP)
, t(WRAP_CLAMP)
{
}
Image::~Image()
{
}
void Image::setDefaultFilter(const Filter &f)
{
defaultFilter = f;
}
const Image::Filter &Image::getDefaultFilter()
{
return defaultFilter;
}
bool Image::getConstant(const char *in, FilterMode &out)
{
return filterModes.find(in, out);
}
bool Image::getConstant(FilterMode in, const char *&out)
{
return filterModes.find(in, out);
}
bool Image::getConstant(const char *in, WrapMode &out)
{
return wrapModes.find(in, out);
}
bool Image::getConstant(WrapMode in, const char *&out)
{
return wrapModes.find(in, out);
}
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM>::Entry Image::filterModeEntries[] =
{
{ "linear", Image::FILTER_LINEAR },
{ "nearest", Image::FILTER_NEAREST },
};
StringMap<Image::FilterMode, Image::FILTER_MAX_ENUM> Image::filterModes(Image::filterModeEntries, sizeof(Image::filterModeEntries));
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM>::Entry Image::wrapModeEntries[] =
{
{ "clamp", Image::WRAP_CLAMP },
{ "repeat", Image::WRAP_REPEAT },
};
StringMap<Image::WrapMode, Image::WRAP_MAX_ENUM> Image::wrapModes(Image::wrapModeEntries, sizeof(Image::wrapModeEntries));
} // graphics
} // love
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+130
View File
@@ -0,0 +1,130 @@
/**
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Texture.h"
namespace love
{
namespace graphics
{
Texture::Filter Texture::defaultFilter;
Texture::Filter::Filter()
: min(FILTER_LINEAR)
, mag(FILTER_LINEAR)
, mipmap(FILTER_NONE)
, anisotropy(1.0f)
{
}
Texture::Wrap::Wrap()
: s(WRAP_CLAMP)
, t(WRAP_CLAMP)
{
}
Texture::Texture()
: width(0)
, height(0)
, filter(getDefaultFilter())
, wrap()
, vertices()
{
}
Texture::~Texture()
{
}
int Texture::getWidth() const
{
return width;
}
int Texture::getHeight() const
{
return height;
}
const Texture::Filter &Texture::getFilter() const
{
return filter;
}
const Texture::Wrap &Texture::getWrap() const
{
return wrap;
}
const Vertex *Texture::getVertices() const
{
return vertices;
}
void Texture::setDefaultFilter(const Filter &f)
{
defaultFilter = f;
}
const Texture::Filter &Texture::getDefaultFilter()
{
return defaultFilter;
}
bool Texture::getConstant(const char *in, FilterMode &out)
{
return filterModes.find(in, out);
}
bool Texture::getConstant(FilterMode in, const char *&out)
{
return filterModes.find(in, out);
}
bool Texture::getConstant(const char *in, WrapMode &out)
{
return wrapModes.find(in, out);
}
bool Texture::getConstant(WrapMode in, const char *&out)
{
return wrapModes.find(in, out);
}
StringMap<Texture::FilterMode, Texture::FILTER_MAX_ENUM>::Entry Texture::filterModeEntries[] =
{
{ "linear", Texture::FILTER_LINEAR },
{ "nearest", Texture::FILTER_NEAREST },
};
StringMap<Texture::FilterMode, Texture::FILTER_MAX_ENUM> Texture::filterModes(Texture::filterModeEntries, sizeof(Texture::filterModeEntries));
StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM>::Entry Texture::wrapModeEntries[] =
{
{ "clamp", Texture::WRAP_CLAMP },
{ "repeat", Texture::WRAP_REPEAT },
};
StringMap<Texture::WrapMode, Texture::WRAP_MAX_ENUM> Texture::wrapModes(Texture::wrapModeEntries, sizeof(Texture::wrapModeEntries));
} // graphics
} // love
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,35 +18,40 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_IMAGE_H
#define LOVE_GRAPHICS_IMAGE_H
#ifndef LOVE_GRAPHICS_TEXTURE_H
#define LOVE_GRAPHICS_TEXTURE_H
// LOVE
#include "graphics/Volatile.h"
#include "graphics/DrawQable.h"
#include "common/StringMap.h"
#include "common/math.h"
#include "Drawable.h"
#include "Quad.h"
namespace love
{
namespace graphics
{
class Image : public DrawQable, public Volatile
/**
* Base class for 2D textures. All textures can be drawn with Quads, have a
* width and height, and have filter and wrap modes.
**/
class Texture : public Drawable
{
public:
enum WrapMode
{
WRAP_CLAMP = 1,
WRAP_CLAMP,
WRAP_REPEAT,
WRAP_MAX_ENUM
};
enum FilterMode
{
FILTER_LINEAR = 1,
FILTER_NEAREST,
FILTER_NONE,
FILTER_LINEAR,
FILTER_NEAREST,
FILTER_MAX_ENUM
};
@@ -66,17 +71,56 @@ public:
WrapMode t;
};
virtual ~Image();
Texture();
virtual ~Texture();
/**
* Draws the texture using the specified transformation with a Quad applied.
*
* @param quad The Quad object to use to draw the object.
* @param x The position of the object along the x-axis.
* @param y The position of the object along the y-axis.
* @param angle The angle of the object (in radians).
* @param sx The scale factor along the x-axis.
* @param sy The scale factor along the y-axis.
* @param ox The origin offset along the x-axis.
* @param oy The origin offset along the y-axis.
* @param kx Shear along the x-axis.
* @param ky Shear along the y-axis.
**/
virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const = 0;
virtual int getWidth() const;
virtual int getHeight() const;
virtual void setFilter(const Filter &f) = 0;
virtual const Filter &getFilter() const;
virtual void setWrap(const Wrap &w) = 0;
virtual const Wrap &getWrap() const;
virtual const Vertex *getVertices() const;
// The default filter.
static void setDefaultFilter(const Filter &f);
static const Filter &getDefaultFilter();
static bool getConstant(const char *in, FilterMode &out);
static bool getConstant(FilterMode in, const char *&out);
static bool getConstant(const char *in, WrapMode &out);
static bool getConstant(WrapMode in, const char *&out);
protected:
int width;
int height;
Filter filter;
Wrap wrap;
Vertex vertices[4];
private:
// The default texture filter.
@@ -84,12 +128,13 @@ private:
static StringMap<FilterMode, FILTER_MAX_ENUM>::Entry filterModeEntries[];
static StringMap<FilterMode, FILTER_MAX_ENUM> filterModes;
static StringMap<WrapMode, WRAP_MAX_ENUM>::Entry wrapModeEntries[];
static StringMap<WrapMode, WRAP_MAX_ENUM> wrapModes;
}; // Image
}; // Texture
} // graphics
} // love
#endif // LOVE_GRAPHICS_IMAGE_H
#endif // LOVE_GRAPHICS_TEXTURE_H
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+1 -1
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+142 -159
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -115,7 +115,8 @@ struct FramebufferStrategyCore : public FramebufferStrategy
glGenTextures(1, &img);
gl.bindTexture(img);
gl.setTextureFilter(Image::getDefaultFilter());
Texture::Filter filter = Texture::getDefaultFilter();
gl.setTextureFilter(filter);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
0, GL_RGBA, format, NULL);
@@ -183,7 +184,7 @@ struct FramebufferStrategyCore : public FramebufferStrategy
for (size_t i = 0; i < canvases.size(); i++)
{
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1 + i,
GL_TEXTURE_2D, canvases[i]->getTextureName(), 0);
GL_TEXTURE_2D, canvases[i]->getGLTexture(), 0);
drawbuffers.push_back(GL_COLOR_ATTACHMENT1 + i);
}
@@ -244,7 +245,8 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
glGenTextures(1, &img);
gl.bindTexture(img);
gl.setTextureFilter(Image::getDefaultFilter());
Texture::Filter filter = Texture::getDefaultFilter();
gl.setTextureFilter(filter);
glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height,
0, GL_RGBA, format, NULL);
@@ -312,7 +314,7 @@ struct FramebufferStrategyPackedEXT : public FramebufferStrategy
for (size_t i = 0; i < canvases.size(); i++)
{
glFramebufferTexture2DEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1_EXT + i,
GL_TEXTURE_2D, canvases[i]->getTextureName(), 0);
GL_TEXTURE_2D, canvases[i]->getGLTexture(), 0);
drawbuffers.push_back(GL_COLOR_ATTACHMENT1_EXT + i);
}
@@ -365,6 +367,7 @@ FramebufferStrategyPackedEXT strategyPackedEXT;
FramebufferStrategyEXT strategyEXT;
Canvas *Canvas::current = NULL;
OpenGL::Viewport Canvas::systemViewport = OpenGL::Viewport();
static void getStrategy()
{
@@ -387,37 +390,36 @@ static int maxFBOColorAttachments = 0;
static int maxDrawBuffers = 0;
Canvas::Canvas(int width, int height, TextureType texture_type)
: width(width)
, height(height)
, fbo(0)
: fbo(0)
, depth_stencil(0)
, img(0)
, texture_type(texture_type)
{
this->width = width;
this->height = height;
float w = static_cast<float>(width);
float h = static_cast<float>(height);
// world coordinates
vertices[0].x = 0;
vertices[0].y = h;
vertices[1].x = w;
vertices[0].y = 0;
vertices[1].x = 0;
vertices[1].y = h;
vertices[2].x = w;
vertices[2].y = 0;
vertices[3].x = 0;
vertices[2].y = h;
vertices[3].x = w;
vertices[3].y = 0;
// texture coordinates
vertices[0].s = 0;
vertices[0].t = 0;
vertices[1].s = 1;
vertices[1].t = 0;
vertices[1].s = 0;
vertices[1].t = 1;
vertices[2].s = 1;
vertices[2].t = 1;
vertices[3].s = 0;
vertices[3].t = 1;
settings.filter = Image::getDefaultFilter();
vertices[3].s = 1;
vertices[3].t = 0;
getStrategy();
@@ -433,36 +435,103 @@ Canvas::~Canvas()
unloadVolatile();
}
bool Canvas::isSupported()
bool Canvas::loadVolatile()
{
getStrategy();
return (strategy != &strategyNone);
}
fbo = depth_stencil = img = 0;
bool Canvas::isHDRSupported()
{
return GLAD_VERSION_3_0 || (isSupported() && GLAD_ARB_texture_float);
}
bool Canvas::isMultiCanvasSupported()
{
if (!(isSupported() && (GLAD_VERSION_2_0 || GLAD_ES_VERSION_3_0 || GLAD_ARB_draw_buffers)))
return false;
if (maxFBOColorAttachments == 0 || maxDrawBuffers == 0)
// glTexImage2D is guaranteed to error in this case.
if (width > gl.getMaxTextureSize() || height > gl.getMaxTextureSize())
{
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxFBOColorAttachments);
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
return false;
}
// system must support at least 4 simultanious active canvases
return maxFBOColorAttachments >= 4 && maxDrawBuffers >= 4;
status = strategy->createFBO(fbo, img, width, height, texture_type);
if (status != GL_FRAMEBUFFER_COMPLETE)
return false;
setFilter(filter);
setWrap(wrap);
clear(Color(0, 0, 0, 0));
return true;
}
void Canvas::bindDefaultCanvas()
void Canvas::unloadVolatile()
{
if (current != NULL)
current->stopGrab();
strategy->deleteFBO(fbo, depth_stencil, img);
fbo = depth_stencil = img = 0;
for (size_t i = 0; i < attachedCanvases.size(); i++)
attachedCanvases[i]->release();
attachedCanvases.clear();
}
void Canvas::drawv(const Matrix &t, const Vertex *v) const
{
gl.matrices.transform.push(gl.matrices.transform.top());
gl.matrices.transform.top() *= t;
gl.prepareDraw();
predraw();
gl.enableVertexAttribArray(OpenGL::ATTRIB_POS);
gl.enableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
gl.setVertexAttribArray(OpenGL::ATTRIB_POS, 2, GL_FLOAT, sizeof(Vertex), (GLvoid *) &v[0].x);
gl.setVertexAttribArray(OpenGL::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(Vertex), (GLvoid *) &v[0].s);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
gl.disableVertexAttribArray(OpenGL::ATTRIB_POS);
gl.disableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
postdraw();
gl.matrices.transform.pop();
}
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
drawv(t, vertices);
}
void Canvas::drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
const Vertex *v = quad->getVertices();
drawv(t, v);
}
void Canvas::setFilter(const Texture::Filter &f)
{
filter = f;
gl.bindTexture(img);
gl.setTextureFilter(filter);
}
void Canvas::setWrap(const Texture::Wrap &w)
{
wrap = w;
gl.bindTexture(img);
gl.setTextureWrap(wrap);
}
GLuint Canvas::getGLTexture() const
{
return img;
}
void Canvas::predraw() const
{
gl.bindTexture(img);
}
void Canvas::setupGrab()
@@ -476,12 +545,12 @@ void Canvas::setupGrab()
current->stopGrab();
// bind the framebuffer object.
glPushAttrib(GL_VIEWPORT_BIT | GL_TRANSFORM_BIT);
systemViewport = gl.getViewport();
strategy->bindFBO(fbo);
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
// Set up orthographic view (no depth)
gl.matrices.projection.push(Matrix::ortho(0.0, width, height, 0.0));
gl.matrices.projection.push(Matrix::ortho(0.0, width, 0.0, height));
// indicate we are using this fbo
current = this;
@@ -555,11 +624,20 @@ void Canvas::stopGrab()
if (current != this)
return;
if (depth_stencil != 0 && GLAD_EXT_discard_framebuffer)
{
// Hint for the driver that it doesn't need to save these buffers.
GLenum attachments[] = {GL_STENCIL_ATTACHMENT, GL_DEPTH_ATTACHMENT};
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments);
}
// bind default
strategy->bindFBO(gl.getDefaultFBO());
gl.matrices.projection.pop();
glPopAttrib();
current = NULL;
current = nullptr;
gl.setViewport(systemViewport);
}
void Canvas::clear(Color c)
@@ -571,7 +649,7 @@ void Canvas::clear(Color c)
if (current != this)
{
if (current != NULL)
if (current != nullptr)
previous = current->fbo;
strategy->bindFBO(fbo);
@@ -614,30 +692,6 @@ void Canvas::clear(Color c)
strategy->bindFBO(previous);
}
void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
drawv(t, vertices);
}
void Canvas::drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
static Matrix t;
t.setTransformation(x, y, angle, sx, sy, ox, oy, kx, ky);
const Vertex *v = quad->getVertices();
// flip texture coordinates vertically.
Vertex w[4];
memcpy(w, v, sizeof(Vertex) * 4);
for (size_t i = 0; i < 4; i++)
w[i].t = 1.0f - w[i].t;
drawv(t, w);
}
bool Canvas::checkCreateStencil()
{
// Do nothing if we've already created the stencil buffer.
@@ -662,7 +716,6 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
int row = 4 * width;
int size = row * height;
GLubyte *pixels = new GLubyte[size];
GLubyte *flipped = new GLubyte[size];
strategy->bindFBO(fbo);
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
@@ -671,15 +724,8 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
else
strategy->bindFBO(gl.getDefaultFBO());
GLubyte *src = pixels, *dst = flipped + size - row;
for (int i = 0; i < height; ++i, dst -= row, src += row)
memcpy(dst, src, row);
love::image::ImageData *img = image->newImageData(width, height, (void *)flipped, true);
// The new ImageData now owns the flipped data, so we don't delete it here.
delete[] pixels;
// The new ImageData now owns the pixel data, so we don't delete it here.
love::image::ImageData *img = image->newImageData(width, height, (void *)pixels, true);
return img;
}
@@ -696,99 +742,36 @@ void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
strategy->bindFBO(gl.getDefaultFBO());
}
const std::vector<Canvas *> &Canvas::getAttachedCanvases() const
bool Canvas::isSupported()
{
return attachedCanvases;
getStrategy();
return (strategy != &strategyNone);
}
void Canvas::setFilter(const Image::Filter &f)
bool Canvas::isHDRSupported()
{
settings.filter = f;
gl.bindTexture(img);
settings.filter.anisotropy = gl.setTextureFilter(f);
return GLAD_VERSION_3_0 || (isSupported() && GLAD_ARB_texture_float);
}
Image::Filter Canvas::getFilter() const
bool Canvas::isMultiCanvasSupported()
{
gl.bindTexture(img);
return gl.getTextureFilter();
}
void Canvas::setWrap(const Image::Wrap &w)
{
settings.wrap = w;
gl.bindTexture(img);
gl.setTextureWrap(w);
}
Image::Wrap Canvas::getWrap() const
{
return settings.wrap;
}
bool Canvas::loadVolatile()
{
fbo = depth_stencil = img = 0;
// glTexImage2D is guaranteed to error in this case.
if (width > gl.getMaxTextureSize() || height > gl.getMaxTextureSize())
{
status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
if (!(isSupported() && (GLAD_VERSION_2_0 || GLAD_ARB_draw_buffers)))
return false;
if (maxFBOColorAttachments == 0 || maxDrawBuffers == 0)
{
glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxFBOColorAttachments);
glGetIntegerv(GL_MAX_DRAW_BUFFERS, &maxDrawBuffers);
}
status = strategy->createFBO(fbo, img, width, height, texture_type);
if (status != GL_FRAMEBUFFER_COMPLETE)
return false;
setFilter(settings.filter);
setWrap(settings.wrap);
clear(Color(0, 0, 0, 0));
return true;
// system must support at least 4 simultanious active canvases
return maxFBOColorAttachments >= 4 && maxDrawBuffers >= 4;
}
void Canvas::unloadVolatile()
void Canvas::bindDefaultCanvas()
{
strategy->deleteFBO(fbo, depth_stencil, img);
fbo = depth_stencil = img = 0;
for (size_t i = 0; i < attachedCanvases.size(); i++)
attachedCanvases[i]->release();
attachedCanvases.clear();
}
int Canvas::getWidth()
{
return width;
}
int Canvas::getHeight()
{
return height;
}
void Canvas::drawv(const Matrix &t, const Vertex *v) const
{
gl.matrices.transform.push(gl.matrices.transform.top());
gl.matrices.transform.top() *= t;
gl.prepareDraw();
gl.bindTexture(img);
gl.enableVertexAttribArray(OpenGL::ATTRIB_POS);
gl.enableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
gl.setVertexAttribArray(OpenGL::ATTRIB_POS, 2, GL_FLOAT, sizeof(Vertex), (GLvoid *) &v[0].x);
gl.setVertexAttribArray(OpenGL::ATTRIB_TEXCOORD, 2, GL_FLOAT, sizeof(Vertex), (GLvoid *) &v[0].s);
glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
gl.disableVertexAttribArray(OpenGL::ATTRIB_POS);
gl.disableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
gl.matrices.transform.pop();
if (current != nullptr)
current->stopGrab();
}
bool Canvas::getConstant(const char *in, Canvas::TextureType &out)
+23 -42
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -21,14 +21,11 @@
#ifndef LOVE_GRAPHICS_OPENGL_CANVAS_H
#define LOVE_GRAPHICS_OPENGL_CANVAS_H
#include "graphics/DrawQable.h"
#include "graphics/Volatile.h"
#include "graphics/Image.h"
#include "graphics/Color.h"
#include "image/Image.h"
#include "image/ImageData.h"
#include "common/math.h"
#include "common/Matrix.h"
#include "Texture.h"
#include "OpenGL.h"
namespace love
@@ -38,7 +35,7 @@ namespace graphics
namespace opengl
{
class Canvas : public DrawQable, public Volatile
class Canvas : public Texture
{
public:
@@ -52,6 +49,20 @@ public:
Canvas(int width, int height, TextureType texture_type = TYPE_NORMAL);
virtual ~Canvas();
// Implements Volatile.
virtual bool loadVolatile();
virtual void unloadVolatile();
// Implements Drawable.
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
// Implements Texture.
virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
virtual void setFilter(const Texture::Filter &f);
virtual void setWrap(const Texture::Wrap &w);
virtual GLuint getGLTexture() const;
virtual void predraw() const;
/**
* @param canvases A list of other canvases to temporarily attach to this one,
* to allow drawing to multiple canvases at once.
@@ -62,13 +73,6 @@ public:
void clear(Color c);
virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
/**
* @copydoc DrawQable::drawq()
**/
void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
/**
* Create and attach a stencil buffer to this Canvas' framebuffer, if necessary.
**/
@@ -78,16 +82,10 @@ public:
void getPixel(unsigned char* pixel_rgba, int x, int y);
const std::vector<Canvas *> &getAttachedCanvases() const;
void setFilter(const Image::Filter &f);
Image::Filter getFilter() const;
void setWrap(const Image::Wrap &w);
Image::Wrap getWrap() const;
int getWidth();
int getHeight();
inline const std::vector<Canvas *> &getAttachedCanvases() const
{
return attachedCanvases;
}
inline GLenum getStatus() const
{
@@ -99,9 +97,6 @@ public:
return texture_type;
}
bool loadVolatile();
void unloadVolatile();
static bool isSupported();
static bool isHDRSupported();
static bool isMultiCanvasSupported();
@@ -112,33 +107,19 @@ public:
static Canvas *current;
static void bindDefaultCanvas();
GLuint getTextureName() const
{
return img;
}
// The viewport dimensions of the system (default) framebuffer.
static OpenGL::Viewport systemViewport;
private:
friend class Shader;
GLsizei width;
GLsizei height;
GLuint fbo;
GLuint depth_stencil;
GLuint img;
TextureType texture_type;
Vertex vertices[4];
GLenum status;
struct
{
Image::Filter filter;
Image::Wrap wrap;
} settings;
std::vector<Canvas *> attachedCanvases;
void setupGrab();
+9 -10
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -20,7 +20,6 @@
#include "common/config.h"
#include "Font.h"
#include "font/GlyphData.h"
#include "Image.h"
#include "libraries/utf8/utf8.h"
@@ -41,14 +40,14 @@ namespace opengl
const int Font::TEXTURE_WIDTHS[] = {128, 256, 256, 512, 512, 1024, 1024};
const int Font::TEXTURE_HEIGHTS[] = {128, 128, 256, 256, 512, 512, 1024};
Font::Font(love::font::Rasterizer *r, const Image::Filter &filter)
Font::Font(love::font::Rasterizer *r, const Texture::Filter &filter)
: rasterizer(r)
, height(r->getHeight())
, lineHeight(1)
, mSpacing(1)
, filter(filter)
{
this->filter.mipmap = Image::FILTER_NONE;
this->filter.mipmap = Texture::FILTER_NONE;
// Try to find the best texture size match for the font size. default to the
// largest texture size if no rough match is found.
@@ -94,7 +93,7 @@ Font::~Font()
unloadVolatile();
}
bool Font::initializeTexture(GLint format)
bool Font::initializeTexture(GLenum format)
{
GLint internalformat = (format == GL_LUMINANCE_ALPHA) ? GL_LUMINANCE_ALPHA : GL_RGBA;
@@ -130,7 +129,7 @@ void Font::createTexture()
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
GLint format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
GLenum format = (type == FONT_TRUETYPE ? GL_LUMINANCE_ALPHA : GL_RGBA);
// Initialize the texture, attempting smaller sizes if initialization fails.
bool initialized = false;
@@ -156,7 +155,7 @@ void Font::createTexture()
throw love::Exception("Could not create font texture!");
}
// Fill the texture with transparent black.
std::vector<GLubyte> emptyData(textureWidth * textureHeight * (type == FONT_TRUETYPE ? 2 : 4), 0);
glTexSubImage2D(GL_TEXTURE_2D,
@@ -520,18 +519,18 @@ float Font::getSpacing() const
return mSpacing;
}
void Font::setFilter(const Image::Filter &f)
void Font::setFilter(const Texture::Filter &f)
{
filter = f;
for (auto it = textures.begin(); it != textures.end(); ++it)
{
gl.bindTexture(*it);
filter.anisotropy = gl.setTextureFilter(f);
gl.setTextureFilter(filter);
}
}
const Image::Filter &Font::getFilter()
const Texture::Filter &Font::getFilter()
{
return filter;
}
+8 -7
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -29,7 +29,8 @@
// LOVE
#include "common/Object.h"
#include "font/Rasterizer.h"
#include "graphics/Image.h"
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
#include "OpenGL.h"
@@ -44,7 +45,7 @@ class Font : public Object, public Volatile
{
public:
Font(love::font::Rasterizer *r, const Image::Filter &filter = Image::getDefaultFilter());
Font(love::font::Rasterizer *r, const Texture::Filter &filter = Texture::getDefaultFilter());
virtual ~Font();
@@ -122,8 +123,8 @@ public:
**/
float getSpacing() const;
void setFilter(const Image::Filter &f);
const Image::Filter &getFilter();
void setFilter(const Texture::Filter &f);
const Texture::Filter &getFilter();
// Implements Volatile.
bool loadVolatile();
@@ -177,7 +178,7 @@ private:
};
};
bool initializeTexture(GLint format);
bool initializeTexture(GLenum format);
void createTexture();
Glyph *addGlyph(uint32 glyph);
Glyph *findGlyph(uint32 glyph);
@@ -199,7 +200,7 @@ private:
std::map<uint32, Glyph *> glyphs;
FontType type;
Image::Filter filter;
Texture::Filter filter;
static const int NUM_TEXTURE_SIZES = 7;
static const int TEXTURE_WIDTHS[NUM_TEXTURE_SIZES];
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,6 +18,7 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "common/config.h"
#include "common/math.h"
#include "common/Vector.h"
@@ -26,11 +27,15 @@
#include "window/sdl/Window.h"
#include "Polyline.h"
// C++
#include <vector>
#include <sstream>
#include <algorithm>
#include <iterator>
// C
#include <cmath>
namespace love
{
namespace graphics
@@ -126,11 +131,24 @@ void Graphics::setViewportSize(int width, int height)
if (!isCreated())
return;
// Set the viewport to top-left corner
// We want to affect the main screen, not any Canvas that's currently active
// (not that any *should* be active when this is called.)
Canvas *c = Canvas::current;
Canvas::bindDefaultCanvas();
// Set the viewport to top-left corner.
gl.setViewport(OpenGL::Viewport(0, 0, width, height));
// If a canvas was bound before this function was called, it needs to be
// made aware of the new system viewport size.
Canvas::systemViewport = gl.getViewport();
// Set up orthographic view (no depth)
gl.matrices.projection.top() = Matrix::ortho(0.0, width, height, 0.0);
// Restore the previously active Canvas.
if (c != nullptr)
c->startGrab(c->getAttachedCanvases());
}
bool Graphics::setMode(int width, int height)
@@ -188,7 +206,7 @@ bool Graphics::setMode(int width, int height)
gl.setTextureUnit(0);
// Set pixel row alignment
glPixelStorei(GL_UNPACK_ALIGNMENT, 2);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
// Reload all volatile objects.
if (!Volatile::loadAll())
@@ -234,19 +252,29 @@ void Graphics::reset()
discardStencil();
Canvas::bindDefaultCanvas();
Shader::detach();
origin();
restoreState(s);
pixel_size_stack.clear();
pixel_size_stack.reserve(5);
pixel_size_stack.push_back(1);
}
void Graphics::clear()
{
glClear(GL_COLOR_BUFFER_BIT);
GLbitfield buffers = GL_COLOR_BUFFER_BIT;
if (GLAD_EXT_discard_framebuffer)
buffers |= GL_STENCIL_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
glClear(buffers);
}
void Graphics::present()
{
if (GLAD_EXT_discard_framebuffer)
{
// Hint for the driver that it doesn't need to save these buffers.
GLenum attachments[] = {GL_STENCIL_ATTACHMENT, GL_DEPTH_ATTACHMENT};
glDiscardFramebufferEXT(GL_FRAMEBUFFER, 2, attachments);
}
currentWindow->swapBuffers();
}
@@ -329,7 +357,11 @@ Image *Graphics::newImage(love::image::ImageData *data)
{
// Create the image.
Image *image = new Image(data);
bool success;
if (!isCreated())
return image;
bool success = false;
try
{
success = image->load();
@@ -352,7 +384,11 @@ Image *Graphics::newImage(love::image::CompressedData *cdata)
{
// Create the image.
Image *image = new Image(cdata);
bool success;
if (!isCreated())
return image;
bool success = false;
try
{
success = image->load();
@@ -376,19 +412,19 @@ Quad *Graphics::newQuad(Quad::Viewport v, float sw, float sh)
return new Quad(v, sw, sh);
}
Font *Graphics::newFont(love::font::Rasterizer *r, const Image::Filter &filter)
Font *Graphics::newFont(love::font::Rasterizer *r, const Texture::Filter &filter)
{
return new Font(r, filter);
}
SpriteBatch *Graphics::newSpriteBatch(Image *image, int size, int usage)
SpriteBatch *Graphics::newSpriteBatch(Texture *texture, int size, int usage)
{
return new SpriteBatch(image, size, usage);
return new SpriteBatch(texture, size, usage);
}
ParticleSystem *Graphics::newParticleSystem(Image *image, int size)
ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size)
{
return new ParticleSystem(image, size);
return new ParticleSystem(texture, size);
}
Canvas *Graphics::newCanvas(int width, int height, Canvas::TextureType texture_type)
@@ -633,23 +669,23 @@ Graphics::BlendMode Graphics::getBlendMode() const
throw Exception("Unknown blend mode");
}
void Graphics::setDefaultFilter(const Image::Filter &f)
void Graphics::setDefaultFilter(const Texture::Filter &f)
{
Image::setDefaultFilter(f);
Texture::setDefaultFilter(f);
}
const Image::Filter &Graphics::getDefaultFilter() const
const Texture::Filter &Graphics::getDefaultFilter() const
{
return Image::getDefaultFilter();
return Texture::getDefaultFilter();
}
void Graphics::setDefaultMipmapFilter(Image::FilterMode filter, float sharpness)
void Graphics::setDefaultMipmapFilter(Texture::FilterMode filter, float sharpness)
{
Image::setDefaultMipmapFilter(filter);
Image::setDefaultMipmapSharpness(sharpness);
}
void Graphics::getDefaultMipmapFilter(Image::FilterMode *filter, float *sharpness) const
void Graphics::getDefaultMipmapFilter(Texture::FilterMode *filter, float *sharpness) const
{
*filter = Image::getDefaultMipmapFilter();
*sharpness = Image::getDefaultMipmapSharpness();
@@ -726,13 +762,13 @@ int Graphics::getMaxPointSize() const
void Graphics::print(const std::string &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky)
{
if (currentFont != 0)
if (currentFont != nullptr)
currentFont->print(str, x, y, 0.0, angle, sx, sy, ox, oy, kx, ky);
}
void Graphics::printf(const std::string &str, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky)
{
if (currentFont == 0)
if (currentFont == nullptr)
return;
if (wrap < 0.0f)
@@ -1073,7 +1109,7 @@ void Graphics::rotate(float r)
void Graphics::scale(float x, float y)
{
gl.matrices.transform.top().scale(x, y);
pixel_size_stack.back() *= 2. / double(x + y);
pixel_size_stack.back() *= 2. / (fabs(x) + fabs(y));
}
void Graphics::translate(float x, float y)
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -203,11 +203,11 @@ public:
/**
* Creates a Font object.
**/
Font *newFont(love::font::Rasterizer *data, const Image::Filter &filter = Image::Filter());
Font *newFont(love::font::Rasterizer *data, const Texture::Filter &filter = Texture::getDefaultFilter());
SpriteBatch *newSpriteBatch(Image *image, int size, int usage);
SpriteBatch *newSpriteBatch(Texture *texture, int size, int usage);
ParticleSystem *newParticleSystem(Image *image, int size);
ParticleSystem *newParticleSystem(Texture *texture, int size);
Canvas *newCanvas(int width, int height, Canvas::TextureType texture_type = Canvas::TYPE_NORMAL);
@@ -270,18 +270,18 @@ public:
/**
* Sets the default filter for images, canvases, and fonts.
**/
void setDefaultFilter(const Image::Filter &f);
void setDefaultFilter(const Texture::Filter &f);
/**
* Gets the default filter for images, canvases, and fonts.
**/
const Image::Filter &getDefaultFilter() const;
const Texture::Filter &getDefaultFilter() const;
/**
* Default Image mipmap filter mode and sharpness values.
**/
void setDefaultMipmapFilter(Image::FilterMode filter, float sharpness);
void getDefaultMipmapFilter(Image::FilterMode *filter, float *sharpness) const;
void setDefaultMipmapFilter(Texture::FilterMode filter, float sharpness);
void getDefaultMipmapFilter(Texture::FilterMode *filter, float *sharpness) const;
/**
* Sets the line width.
+22 -41
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -33,14 +33,12 @@ namespace opengl
float Image::maxMipmapSharpness = 0.0f;
Image::FilterMode Image::defaultMipmapFilter = Image::FILTER_NONE;
Texture::FilterMode Image::defaultMipmapFilter = Texture::FILTER_NONE;
float Image::defaultMipmapSharpness = 0.0f;
Image::Image(love::image::ImageData *data)
: data(data)
, cdata(0)
, width(data->getWidth())
, height(data->getHeight())
, cdata(nullptr)
, paddedWidth(width)
, paddedHeight(height)
, texture(0)
@@ -49,15 +47,16 @@ Image::Image(love::image::ImageData *data)
, compressed(false)
, usingDefaultTexture(false)
{
width = data->getWidth();
height = data->getHeight();
data->retain();
preload();
}
Image::Image(love::image::CompressedData *cdata)
: data(0)
: data(nullptr)
, cdata(cdata)
, width(cdata->getWidth(0))
, height(cdata->getHeight(0))
, paddedWidth(width)
, paddedHeight(height)
, texture(0)
@@ -66,34 +65,22 @@ Image::Image(love::image::CompressedData *cdata)
, compressed(true)
, usingDefaultTexture(false)
{
width = cdata->getWidth(0);
height = cdata->getHeight(0);
cdata->retain();
preload();
}
Image::~Image()
{
if (data != 0)
if (data != nullptr)
data->release();
if (cdata != 0)
if (cdata != nullptr)
cdata->release();
unload();
}
int Image::getWidth() const
{
return width;
}
int Image::getHeight() const
{
return height;
}
const Vertex *Image::getVertices() const
{
return vertices;
}
love::image::ImageData *Image::getImageData() const
{
return data;
@@ -144,6 +131,11 @@ void Image::postdraw() const
}
}
GLuint Image::getGLTexture() const
{
return texture;
}
void Image::uploadCompressedMipmaps()
{
if (!isCompressed() || !cdata || !hasCompressedTextureSupport(cdata->getFormat()))
@@ -246,7 +238,7 @@ void Image::checkMipmapsCreated()
mipmapsCreated = true;
}
void Image::setFilter(const Image::Filter &f)
void Image::setFilter(const Texture::Filter &f)
{
filter = f;
@@ -258,16 +250,11 @@ void Image::setFilter(const Image::Filter &f)
}
bind();
filter.anisotropy = gl.setTextureFilter(filter);
gl.setTextureFilter(filter);
checkMipmapsCreated();
}
const Image::Filter &Image::getFilter() const
{
return filter;
}
void Image::setWrap(const Image::Wrap &w)
void Image::setWrap(const Texture::Wrap &w)
{
wrap = w;
@@ -275,11 +262,6 @@ void Image::setWrap(const Image::Wrap &w)
gl.setTextureWrap(w);
}
const Image::Wrap &Image::getWrap() const
{
return wrap;
}
void Image::setMipmapSharpness(float sharpness)
{
if (hasMipmapSharpnessSupport())
@@ -331,7 +313,6 @@ void Image::preload()
vertices[3].s = 1;
vertices[3].t = 0;
filter = getDefaultFilter();
filter.mipmap = defaultMipmapFilter;
}
@@ -565,12 +546,12 @@ float Image::getDefaultMipmapSharpness()
return defaultMipmapSharpness;
}
void Image::setDefaultMipmapFilter(Image::FilterMode f)
void Image::setDefaultMipmapFilter(Texture::FilterMode f)
{
defaultMipmapFilter = f;
}
Image::FilterMode Image::getDefaultMipmapFilter()
Texture::FilterMode Image::getDefaultMipmapFilter()
{
return defaultMipmapFilter;
}
+9 -39
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -28,7 +28,7 @@
#include "common/math.h"
#include "image/ImageData.h"
#include "image/CompressedData.h"
#include "graphics/Image.h"
#include "Texture.h"
// OpenGL
#include "OpenGL.h"
@@ -46,7 +46,7 @@ namespace opengl
*
* @author Anders Ruud
**/
class Image : public love::graphics::Image
class Image : public Texture
{
public:
@@ -70,11 +70,6 @@ public:
**/
virtual ~Image();
int getWidth() const;
int getHeight() const;
const Vertex *getVertices() const;
love::image::ImageData *getImageData() const;
love::image::CompressedData *getCompressedData() const;
@@ -84,7 +79,7 @@ public:
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
/**
* @copydoc DrawQable::drawq()
* @copydoc Texture::drawq()
**/
void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
@@ -93,20 +88,13 @@ public:
* globally scales texture coordinates if the Image has NPOT dimensions and
* NPOT isn't supported, etc.
**/
void predraw() const;
void postdraw() const;
virtual void predraw() const;
virtual void postdraw() const;
/**
* Sets the filter mode.
* @param f The filter mode.
**/
void setFilter(const Image::Filter &f);
virtual GLuint getGLTexture() const;
const Image::Filter &getFilter() const;
void setWrap(const Image::Wrap &w);
const Image::Wrap &getWrap() const;
virtual void setFilter(const Texture::Filter &f);
virtual void setWrap(const Texture::Wrap &w);
void setMipmapSharpness(float sharpness);
float getMipmapSharpness() const;
@@ -150,12 +138,6 @@ private:
void drawv(const Matrix &t, const Vertex *v) const;
friend class Shader;
GLuint getTextureName() const
{
return texture;
}
// The ImageData from which the texture is created. May be null if
// Compressed image data was used to create the texture.
love::image::ImageData *data;
@@ -164,18 +146,12 @@ private:
// null if raw ImageData was used to create the texture.
love::image::CompressedData *cdata;
// Width and height of the hardware texture.
int width, height;
// Real dimensions of the texture, if it was auto-padded to POT size.
int paddedWidth, paddedHeight;
// OpenGL texture identifier.
GLuint texture;
// The source vertices of the image.
Vertex vertices[4];
// Mipmap texture LOD bias (sharpness) value.
float mipmapSharpness;
@@ -189,12 +165,6 @@ private:
// back to a default texture.
bool usingDefaultTexture;
// The image's filter mode
Image::Filter filter;
// The image's wrap mode
Image::Wrap wrap;
void preload();
void uploadTexturePadded();
+35 -18
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -36,8 +36,9 @@ Mesh::Mesh(const std::vector<Vertex> &verts, Mesh::DrawMode mode)
, ibo(nullptr)
, element_count(0)
, draw_mode(mode)
, image(nullptr)
, texture(nullptr)
, colors_enabled(false)
, wireframe(false)
{
setVertices(verts);
}
@@ -169,27 +170,27 @@ size_t Mesh::getVertexMapCount() const
return element_count;
}
void Mesh::setImage(Image *img)
void Mesh::setTexture(Texture *tex)
{
img->retain();
tex->retain();
if (image)
image->release();
if (texture)
texture->release();
image = img;
texture = tex;
}
void Mesh::setImage()
void Mesh::setTexture()
{
if (image)
image->release();
if (texture)
texture->release();
image = nullptr;
texture = nullptr;
}
Image *Mesh::getImage() const
Texture *Mesh::getTexture() const
{
return image;
return texture;
}
void Mesh::setDrawMode(Mesh::DrawMode mode)
@@ -212,6 +213,16 @@ bool Mesh::hasVertexColors() const
return colors_enabled;
}
void Mesh::setWireframe(bool enable)
{
wireframe = enable;
}
bool Mesh::isWireframe() const
{
return wireframe;
}
void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
const size_t pos_offset = offsetof(Vertex, x);
@@ -221,8 +232,8 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
if (vertex_count == 0)
return;
if (image)
image->predraw();
if (texture)
texture->predraw();
else
gl.bindTexture(0);
@@ -250,10 +261,13 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
gl.setVertexAttribArray(OpenGL::ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, sizeof(Vertex), vbo->getPointer(color_offset));
}
gl.prepareDraw();
if (wireframe && GLAD_VERSION_1_0)
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
GLenum mode = getGLDrawMode(draw_mode);
gl.prepareDraw();
if (ibo && element_count > 0)
{
VertexBuffer::Bind ibo_bind(*ibo);
@@ -273,6 +287,9 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
gl.disableVertexAttribArray(OpenGL::ATTRIB_POS);
gl.disableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
if (wireframe && GLAD_VERSION_1_0)
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
if (hasVertexColors())
{
gl.disableVertexAttribArray(OpenGL::ATTRIB_COLOR);
@@ -282,8 +299,8 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo
gl.matrices.transform.pop();
if (image)
image->postdraw();
if (texture)
texture->postdraw();
}
GLenum Mesh::getGLDrawMode(Mesh::DrawMode mode) const
+21 -10
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -26,7 +26,7 @@
#include "common/math.h"
#include "common/StringMap.h"
#include "graphics/Drawable.h"
#include "Image.h"
#include "Texture.h"
#include "VertexBuffer.h"
// C++
@@ -110,20 +110,20 @@ public:
size_t getVertexMapCount() const;
/**
* Sets the Image used when drawing the Mesh.
* Sets the texture used when drawing the Mesh.
**/
void setImage(Image *img);
void setTexture(Texture *texture);
/**
* Disables any Image from being used when drawing the Mesh.
* Disables any texture from being used when drawing the Mesh.
**/
void setImage();
void setTexture();
/**
* Gets the Image used when drawing the Mesh. May return null if no Image is
* set.
* Gets the texture used when drawing the Mesh. May return null if no
* texture is set.
**/
Image *getImage() const;
Texture *getTexture() const;
/**
* Sets the draw mode used when drawing the Mesh.
@@ -138,6 +138,15 @@ public:
void setVertexColors(bool enable);
bool hasVertexColors() const;
/**
* Sets whether the Mesh will be drawn as wireframe lines instead of filled
* triangles (has no effect for DRAW_MODE_POINTS.)
* This should only be used as a debugging tool. The wireframe lines do not
* behave the same as regular love.graphics lines.
**/
void setWireframe(bool enable);
bool isWireframe() const;
// Implements Drawable.
void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const;
@@ -158,11 +167,13 @@ private:
DrawMode draw_mode;
Image *image;
Texture *texture;
// Whether the per-vertex colors are used when drawing.
bool colors_enabled;
bool wireframe;
static StringMap<DrawMode, DRAW_MODE_MAX_ENUM>::Entry drawModeEntries[];
static StringMap<DrawMode, DRAW_MODE_MAX_ENUM> drawModes;
+58 -48
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -23,6 +23,7 @@
#include "OpenGL.h"
#include "Shader.h"
#include "Canvas.h"
#include "common/Exception.h"
// C++
@@ -102,7 +103,7 @@ bool OpenGL::initContext()
GLenum curgltextureunit;
glGetIntegerv(GL_ACTIVE_TEXTURE, (GLint *) &curgltextureunit);
state.curTextureUnit = curgltextureunit - GL_TEXTURE0;
state.curTextureUnit = (int) curgltextureunit - GL_TEXTURE0;
// Retrieve currently bound textures for each texture unit.
for (size_t i = 0; i < state.textureUnits.size(); i++)
@@ -238,6 +239,12 @@ void OpenGL::prepareDraw()
const Matrix &proj = matrices.projection.top();
Shader *shader = Shader::current;
// Make sure the active shader has the correct values for the built-in
// screen params uniform.
if (shader)
shader->checkSetScreenParams();
if (GLAD_ES_VERSION_2_0 && shader)
{
// Send built-in uniforms to the current shader.
@@ -363,8 +370,7 @@ void OpenGL::setViewport(const OpenGL::Viewport &v)
// glScissor starts from the lower left, so we compensate when setting the
// scissor. When the viewport is changed, we need to manually update the
// scissor again.
if (v.h != state.viewport.h)
setScissor(state.scissor);
setScissor(state.scissor);
}
OpenGL::Viewport OpenGL::getViewport() const
@@ -374,9 +380,15 @@ OpenGL::Viewport OpenGL::getViewport() const
void OpenGL::setScissor(const OpenGL::Viewport &v)
{
// We need to compensate for glScissor starting from the lower left of the
// viewport instead of the top left.
glScissor(v.x, state.viewport.h - (v.y + v.h), v.w, v.h);
if (Canvas::current)
glScissor(v.x, v.y, v.w, v.h);
else
{
// With no Canvas active, we need to compensate for glScissor starting
// from the lower left of the viewport instead of the top left.
glScissor(v.x, state.viewport.h - (v.y + v.h), v.w, v.h);
}
state.scissor = v;
}
@@ -413,7 +425,7 @@ void OpenGL::setTextureUnit(int textureunit)
if (state.textureUnits.size() > 1)
glActiveTexture(GL_TEXTURE0 + textureunit);
else
throw love::Exception("Multitexturing not supported.");
throw love::Exception("Multitexturing is not supported.");
}
state.curTextureUnit = textureunit;
@@ -460,26 +472,26 @@ void OpenGL::deleteTexture(GLuint texture)
glDeleteTextures(1, &texture);
}
float OpenGL::setTextureFilter(const graphics::Image::Filter &f)
float OpenGL::setTextureFilter(graphics::Texture::Filter &f)
{
GLint gmin, gmag;
if (f.mipmap == Image::FILTER_NONE)
if (f.mipmap == Texture::FILTER_NONE)
{
if (f.min == Image::FILTER_NEAREST)
if (f.min == Texture::FILTER_NEAREST)
gmin = GL_NEAREST;
else // f.min == Image::FILTER_LINEAR
else // f.min == Texture::FILTER_LINEAR
gmin = GL_LINEAR;
}
else
{
if (f.min == Image::FILTER_NEAREST && f.mipmap == Image::FILTER_NEAREST)
if (f.min == Texture::FILTER_NEAREST && f.mipmap == Texture::FILTER_NEAREST)
gmin = GL_NEAREST_MIPMAP_NEAREST;
else if (f.min == Image::FILTER_NEAREST && f.mipmap == Image::FILTER_LINEAR)
else if (f.min == Texture::FILTER_NEAREST && f.mipmap == Texture::FILTER_LINEAR)
gmin = GL_NEAREST_MIPMAP_LINEAR;
else if (f.min == Image::FILTER_LINEAR && f.mipmap == Image::FILTER_NEAREST)
else if (f.min == Texture::FILTER_LINEAR && f.mipmap == Texture::FILTER_NEAREST)
gmin = GL_LINEAR_MIPMAP_NEAREST;
else if (f.min == Image::FILTER_LINEAR && f.mipmap == Image::FILTER_LINEAR)
else if (f.min == Texture::FILTER_LINEAR && f.mipmap == Texture::FILTER_LINEAR)
gmin = GL_LINEAR_MIPMAP_LINEAR;
else
gmin = GL_LINEAR;
@@ -488,10 +500,10 @@ float OpenGL::setTextureFilter(const graphics::Image::Filter &f)
switch (f.mag)
{
case Image::FILTER_NEAREST:
case Texture::FILTER_NEAREST:
gmag = GL_NEAREST;
break;
case Image::FILTER_LINEAR:
case Texture::FILTER_LINEAR:
default:
gmag = GL_LINEAR;
break;
@@ -500,60 +512,58 @@ float OpenGL::setTextureFilter(const graphics::Image::Filter &f)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gmin);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gmag);
float anisotropy = 1.0f;
if (GLAD_EXT_texture_filter_anisotropic)
{
anisotropy = std::min(std::max(f.anisotropy, 1.0f), maxAnisotropy);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropy);
f.anisotropy = std::min(std::max(f.anisotropy, 1.0f), maxAnisotropy);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, f.anisotropy);
}
return anisotropy;
return f.anisotropy;
}
graphics::Image::Filter OpenGL::getTextureFilter()
Texture::Filter OpenGL::getTextureFilter()
{
GLint gmin, gmag;
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &gmin);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &gmag);
Image::Filter f;
Texture::Filter f;
switch (gmin)
{
case GL_NEAREST:
f.min = Image::FILTER_NEAREST;
f.mipmap = Image::FILTER_NONE;
f.min = Texture::FILTER_NEAREST;
f.mipmap = Texture::FILTER_NONE;
break;
case GL_NEAREST_MIPMAP_NEAREST:
f.min = f.mipmap = Image::FILTER_NEAREST;
f.min = f.mipmap = Texture::FILTER_NEAREST;
break;
case GL_NEAREST_MIPMAP_LINEAR:
f.min = Image::FILTER_NEAREST;
f.mipmap = Image::FILTER_LINEAR;
f.min = Texture::FILTER_NEAREST;
f.mipmap = Texture::FILTER_LINEAR;
break;
case GL_LINEAR_MIPMAP_NEAREST:
f.min = Image::FILTER_LINEAR;
f.mipmap = Image::FILTER_NEAREST;
f.min = Texture::FILTER_LINEAR;
f.mipmap = Texture::FILTER_NEAREST;
break;
case GL_LINEAR_MIPMAP_LINEAR:
f.min = f.mipmap = Image::FILTER_LINEAR;
f.min = f.mipmap = Texture::FILTER_LINEAR;
break;
case GL_LINEAR:
default:
f.min = Image::FILTER_LINEAR;
f.mipmap = Image::FILTER_NONE;
f.min = Texture::FILTER_LINEAR;
f.mipmap = Texture::FILTER_NONE;
break;
}
switch (gmag)
{
case GL_NEAREST:
f.mag = Image::FILTER_NEAREST;
f.mag = Texture::FILTER_NEAREST;
break;
case GL_LINEAR:
default:
f.mag = Image::FILTER_LINEAR;
f.mag = Texture::FILTER_LINEAR;
break;
}
@@ -563,16 +573,16 @@ graphics::Image::Filter OpenGL::getTextureFilter()
return f;
}
void OpenGL::setTextureWrap(const graphics::Image::Wrap &w)
void OpenGL::setTextureWrap(const graphics::Texture::Wrap &w)
{
GLint gs, gt;
switch (w.s)
{
case Image::WRAP_CLAMP:
case Texture::WRAP_CLAMP:
gs = GL_CLAMP_TO_EDGE;
break;
case Image::WRAP_REPEAT:
case Texture::WRAP_REPEAT:
default:
gs = GL_REPEAT;
break;
@@ -580,10 +590,10 @@ void OpenGL::setTextureWrap(const graphics::Image::Wrap &w)
switch (w.t)
{
case Image::WRAP_CLAMP:
case Texture::WRAP_CLAMP:
gt = GL_CLAMP_TO_EDGE;
break;
case Image::WRAP_REPEAT:
case Texture::WRAP_REPEAT:
default:
gt = GL_REPEAT;
break;
@@ -593,34 +603,34 @@ void OpenGL::setTextureWrap(const graphics::Image::Wrap &w)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, gt);
}
graphics::Image::Wrap OpenGL::getTextureWrap()
Texture::Wrap OpenGL::getTextureWrap()
{
GLint gs, gt;
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, &gs);
glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, &gt);
Image::Wrap w;
Texture::Wrap w;
switch (gs)
{
case GL_CLAMP_TO_EDGE:
w.s = Image::WRAP_CLAMP;
w.s = Texture::WRAP_CLAMP;
break;
case GL_REPEAT:
default:
w.s = Image::WRAP_REPEAT;
w.s = Texture::WRAP_REPEAT;
break;
}
switch (gt)
{
case GL_CLAMP_TO_EDGE:
w.t = Image::WRAP_CLAMP;
w.t = Texture::WRAP_CLAMP;
break;
case GL_REPEAT:
default:
w.t = Image::WRAP_REPEAT;
w.t = Texture::WRAP_REPEAT;
break;
}
+10 -10
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -23,7 +23,7 @@
// LOVE
#include "graphics/Color.h"
#include "graphics/Image.h"
#include "graphics/Texture.h"
#include "common/Matrix.h"
// GLAD
@@ -229,25 +229,25 @@ public:
void deleteTexture(GLuint texture);
/**
* Sets the image filter mode for the currently bound texture.
* Sets the texture filter mode for the currently bound texture.
* Returns the actual amount of anisotropic filtering set.
**/
float setTextureFilter(const graphics::Image::Filter &f);
float setTextureFilter(graphics::Texture::Filter &f);
/**
* Returns the image filter mode for the currently bound texture.
* Returns the texture filter mode for the currently bound texture.
**/
graphics::Image::Filter getTextureFilter();
graphics::Texture::Filter getTextureFilter();
/**
* Sets the image wrap mode for the currently bound texture.
* Sets the texture wrap mode for the currently bound texture.
**/
void setTextureWrap(const graphics::Image::Wrap &w);
void setTextureWrap(const graphics::Texture::Wrap &w);
/**
* Returns the image wrap mode for the currently bound texture.
* Returns the texture wrap mode for the currently bound texture.
**/
graphics::Image::Wrap getTextureWrap();
graphics::Texture::Wrap getTextureWrap();
/**
* Returns the maximum supported width or height of a texture.
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -58,30 +58,14 @@ float calculate_variation(float inner, float outer, float var)
} // anonymous namespace
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM>::Entry ParticleSystem::distributionsEntries[] = {
{ "none", ParticleSystem::DISTRIBUTION_NONE },
{ "uniform", ParticleSystem::DISTRIBUTION_UNIFORM },
{ "normal", ParticleSystem::DISTRIBUTION_NORMAL },
};
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM> ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries));
StringMap<ParticleSystem::InsertMode, ParticleSystem::INSERT_MODE_MAX_ENUM>::Entry ParticleSystem::insertModesEntries[] =
{
{ "top", ParticleSystem::INSERT_MODE_TOP },
{ "bottom", ParticleSystem::INSERT_MODE_BOTTOM },
{ "random", ParticleSystem::INSERT_MODE_RANDOM },
};
StringMap<ParticleSystem::InsertMode, ParticleSystem::INSERT_MODE_MAX_ENUM> ParticleSystem::insertModes(ParticleSystem::insertModesEntries, sizeof(ParticleSystem::insertModesEntries));
ParticleSystem::ParticleSystem(Image *image, uint32 size)
: pMem(NULL)
, pFree(NULL)
, pHead(NULL)
, pTail(NULL)
, particleVerts(NULL)
, ibo(NULL)
, image(image)
ParticleSystem::ParticleSystem(Texture *texture, uint32 size)
: pMem(nullptr)
, pFree(nullptr)
, pHead(nullptr)
, pTail(nullptr)
, particleVerts(nullptr)
, ibo(nullptr)
, texture(texture)
, active(true)
, insertMode(INSERT_MODE_TOP)
, maxParticles(0)
@@ -109,8 +93,8 @@ ParticleSystem::ParticleSystem(Image *image, uint32 size)
, spinStart(0)
, spinEnd(0)
, spinVariation(0)
, offsetX(float(image->getWidth())*0.5f)
, offsetY(float(image->getHeight())*0.5f)
, offsetX(float(texture->getWidth())*0.5f)
, offsetY(float(texture->getHeight())*0.5f)
{
if (size == 0 || size > MAX_PARTICLES)
throw love::Exception("Invalid ParticleSystem size.");
@@ -118,17 +102,69 @@ ParticleSystem::ParticleSystem(Image *image, uint32 size)
sizes.push_back(1.0f);
colors.push_back(Colorf(1.0f, 1.0f, 1.0f, 1.0f));
setBufferSize(size);
image->retain();
texture->retain();
}
ParticleSystem::ParticleSystem(const ParticleSystem &p)
: pMem(nullptr)
, pFree(nullptr)
, pHead(nullptr)
, pTail(nullptr)
, particleVerts(nullptr)
, texture(p.texture)
, active(p.active)
, insertMode(p.insertMode)
, maxParticles(p.maxParticles)
, activeParticles(0)
, emissionRate(p.emissionRate)
, emitCounter(0.0f)
, position(p.position)
, areaSpreadDistribution(p.areaSpreadDistribution)
, areaSpread(p.areaSpread)
, lifetime(p.lifetime)
, life(p.lifetime) // Initialize with the maximum life time.
, particleLifeMin(p.particleLifeMin)
, particleLifeMax(p.particleLifeMax)
, direction(p.direction)
, spread(p.spread)
, speedMin(p.speedMin)
, speedMax(p.speedMax)
, linearAccelerationMin(p.linearAccelerationMin)
, linearAccelerationMax(p.linearAccelerationMax)
, radialAccelerationMin(p.radialAccelerationMin)
, radialAccelerationMax(p.radialAccelerationMax)
, tangentialAccelerationMin(p.tangentialAccelerationMin)
, tangentialAccelerationMax(p.tangentialAccelerationMax)
, sizes(p.sizes)
, sizeVariation(p.sizeVariation)
, rotationMin(p.rotationMin)
, rotationMax(p.rotationMax)
, spinStart(p.spinStart)
, spinEnd(p.spinEnd)
, spinVariation(p.spinVariation)
, offsetX(p.offsetX)
, offsetY(p.offsetY)
, colors(p.colors)
{
setBufferSize(maxParticles);
if (texture != nullptr)
texture->retain();
}
ParticleSystem::~ParticleSystem()
{
if (this->image != 0)
this->image->release();
if (texture != nullptr)
texture->release();
deleteBuffers();
}
ParticleSystem *ParticleSystem::clone()
{
return new ParticleSystem(*this);
}
void ParticleSystem::createBuffers(size_t size)
{
try
@@ -157,9 +193,10 @@ void ParticleSystem::deleteBuffers()
delete[] particleVerts;
delete ibo;
pMem = NULL;
particleVerts = NULL;
ibo = NULL;
pMem = nullptr;
particleVerts = nullptr;
ibo = nullptr;
maxParticles = 0;
activeParticles = 0;
}
@@ -272,33 +309,33 @@ void ParticleSystem::initParticle(particle *p)
void ParticleSystem::insertTop(particle *p)
{
if (pHead == NULL)
if (pHead == nullptr)
{
pHead = p;
p->prev = NULL;
p->prev = nullptr;
}
else
{
pTail->next = p;
p->prev = pTail;
}
p->next = NULL;
p->next = nullptr;
pTail = p;
}
void ParticleSystem::insertBottom(particle *p)
{
if (pTail == NULL)
if (pTail == nullptr)
{
pTail = p;
p->next = NULL;
p->next = nullptr;
}
else
{
pHead->prev = p;
p->next = pHead;
}
p->prev = NULL;
p->prev = nullptr;
pHead = p;
}
@@ -313,7 +350,7 @@ void ParticleSystem::insertRandom(particle *p)
particle *pA = pHead;
if (pA)
pA->prev = p;
p->prev = NULL;
p->prev = nullptr;
p->next = pA;
pHead = p;
return;
@@ -336,7 +373,7 @@ ParticleSystem::particle *ParticleSystem::removeParticle(particle *p)
// The linked list is updated in this function and old pointers may be
// invalidated. The returned pointer will inform the caller of the new
// pointer to the next particle.
particle *pNext = NULL;
particle *pNext = nullptr;
// Removes the particle from the linked list.
if (p->prev)
@@ -376,17 +413,19 @@ ParticleSystem::particle *ParticleSystem::removeParticle(particle *p)
return pNext;
}
void ParticleSystem::setImage(Image *image)
void ParticleSystem::setTexture(Texture *texture)
{
Object::AutoRelease imagerelease(this->image);
Object::AutoRelease imagerelease(this->texture);
this->image = image;
this->image->retain();
this->texture = texture;
if (texture)
texture->retain();
}
Image *ParticleSystem::getImage() const
Texture *ParticleSystem::getTexture() const
{
return image;
return texture;
}
void ParticleSystem::setInsertMode(InsertMode mode)
@@ -700,12 +739,12 @@ void ParticleSystem::pause()
void ParticleSystem::reset()
{
if (pMem == NULL)
if (pMem == nullptr)
return;
pFree = pMem;
pHead = NULL;
pTail = NULL;
pHead = nullptr;
pTail = nullptr;
activeParticles = 0;
life = lifetime;
emitCounter = 0;
@@ -750,7 +789,7 @@ bool ParticleSystem::isFull() const
void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) const
{
uint32 pCount = getCount();
if (pCount == 0 || image == NULL || pMem == NULL || particleVerts == NULL)
if (pCount == 0 || texture == nullptr || pMem == nullptr || particleVerts == nullptr)
return;
Color curcolor = gl.getColor();
@@ -761,7 +800,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
gl.matrices.transform.push(gl.matrices.transform.top());
gl.matrices.transform.top() *= t;
const Vertex *imageVerts = image->getVertices();
const Vertex *textureVerts = texture->getVertices();
Vertex *pVerts = particleVerts;
particle *p = pHead;
@@ -770,13 +809,13 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
{
// particle vertices are image vertices transformed by particle information
t.setTransformation(p->position[0], p->position[1], p->rotation, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
t.transform(pVerts, imageVerts, 4);
t.transform(pVerts, textureVerts, 4);
// set the texture coordinate and color data for particle vertices
for (int v = 0; v < 4; v++)
{
pVerts[v].s = imageVerts[v].s;
pVerts[v].t = imageVerts[v].t;
pVerts[v].s = textureVerts[v].s;
pVerts[v].t = textureVerts[v].t;
// particle colors are stored as floats (0-1) but vertex colors are stored as unsigned bytes (0-255)
pVerts[v].r = (unsigned char) (p->color.r*255);
@@ -789,8 +828,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
p = p->next;
}
image->predraw();
texture->predraw();
gl.prepareDraw();
gl.enableVertexAttribArray(OpenGL::ATTRIB_POS);
@@ -810,7 +848,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
gl.disableVertexAttribArray(OpenGL::ATTRIB_TEXCOORD);
gl.disableVertexAttribArray(OpenGL::ATTRIB_COLOR);
image->postdraw();
texture->postdraw();
gl.matrices.transform.pop();
@@ -819,7 +857,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
void ParticleSystem::update(float dt)
{
if (pMem == NULL || dt == 0.0f)
if (pMem == nullptr || dt == 0.0f)
return;
// Make some more particles.
@@ -937,6 +975,24 @@ bool ParticleSystem::getConstant(InsertMode in, const char *&out)
return insertModes.find(in, out);
}
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM>::Entry ParticleSystem::distributionsEntries[] =
{
{ "none", ParticleSystem::DISTRIBUTION_NONE },
{ "uniform", ParticleSystem::DISTRIBUTION_UNIFORM },
{ "normal", ParticleSystem::DISTRIBUTION_NORMAL },
};
StringMap<ParticleSystem::AreaSpreadDistribution, ParticleSystem::DISTRIBUTION_MAX_ENUM> ParticleSystem::distributions(ParticleSystem::distributionsEntries, sizeof(ParticleSystem::distributionsEntries));
StringMap<ParticleSystem::InsertMode, ParticleSystem::INSERT_MODE_MAX_ENUM>::Entry ParticleSystem::insertModesEntries[] =
{
{ "top", ParticleSystem::INSERT_MODE_TOP },
{ "bottom", ParticleSystem::INSERT_MODE_BOTTOM },
{ "random", ParticleSystem::INSERT_MODE_RANDOM },
};
StringMap<ParticleSystem::InsertMode, ParticleSystem::INSERT_MODE_MAX_ENUM> ParticleSystem::insertModes(ParticleSystem::insertModesEntries, sizeof(ParticleSystem::insertModesEntries));
} // opengl
} // graphics
} // love
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -27,8 +27,8 @@
#include "common/Vector.h"
#include "graphics/Drawable.h"
#include "graphics/Color.h"
#include "Image.h"
#include "VertexBuffer.h"
#include "Texture.h"
// STL
#include <vector>
@@ -77,9 +77,10 @@ public:
static const uint32 MAX_PARTICLES = LOVE_INT32_MAX / 4;
/**
* Creates a particle system with the specified buffersize and image.
* Creates a particle system with the specified buffer size and texture.
**/
ParticleSystem(Image *image, uint32 buffer);
ParticleSystem(Texture *texture, uint32 buffer);
ParticleSystem(const ParticleSystem &p);
/**
* Deletes any allocated memory.
@@ -87,15 +88,22 @@ public:
virtual ~ParticleSystem();
/**
* Sets the image used in the particle system.
* @param image The new image.
* Creates an identical copy of this ParticleSystem. The clone does not
* duplicate any existing particles from this ParticleSystem, just the
* settable parameters.
**/
void setImage(Image *image);
ParticleSystem *clone();
/**
* Returns the image used when drawing the particle system.
* Sets the texture used in the particle system.
* @param texture The new texture.
**/
Image *getImage() const;
void setTexture(Texture *texture);
/**
* Returns the texture used when drawing the particle system.
**/
Texture *getTexture() const;
/**
* Clears the current buffer and allocates the appropriate amount of space for the buffer.
@@ -509,9 +517,6 @@ protected:
Colorf color;
};
// The max amount of particles.
int bufferSize;
// Pointer to the beginning of the allocated memory.
particle *pMem;
@@ -530,8 +535,8 @@ protected:
// Vertex index buffer.
VertexIndex *ibo;
// The image to be drawn.
Image *image;
// The texture to be drawn.
Texture *texture;
// Whether the particle emitter is active.
bool active;
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
+104 -79
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,11 +18,13 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "common/config.h"
#include "Shader.h"
#include "Graphics.h"
#include "Canvas.h"
// C++
#include <algorithm>
namespace love
@@ -64,27 +66,28 @@ Shader *Shader::defaultShader = nullptr;
Shader::ShaderSources Shader::defaultCode[Graphics::RENDERER_MAX_ENUM];
GLint Shader::maxTextureUnits = 0;
GLint Shader::maxTexUnits = 0;
std::vector<int> Shader::textureCounters;
Shader::Shader(const ShaderSources &sources)
: shaderSources(sources)
, program(0)
, builtinUniforms()
, lastCanvas((Canvas *) -1)
{
if (shaderSources.empty())
throw love::Exception("Cannot create shader: no source code!");
if (maxTextureUnits <= 0)
if (maxTexUnits <= 0)
{
GLint maxtexunits;
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &maxtexunits);
maxTextureUnits = std::max(maxtexunits - 1, 0);
maxTexUnits = std::max(maxtexunits - 1, 0);
}
// initialize global texture id counters if needed
if (textureCounters.size() < (size_t) maxTextureUnits)
textureCounters.resize(maxTextureUnits, 0);
if (textureCounters.size() < (size_t) maxTexUnits)
textureCounters.resize(maxTexUnits, 0);
// load shader source and create program object
loadVolatile();
@@ -249,13 +252,10 @@ void Shader::mapActiveUniforms()
u.name.erase(u.name.length() - 3);
}
// Store the uniform locations for any built-in extern variables, in ES.
if (GLAD_ES_VERSION_2_0)
{
BuiltinExtern builtin;
if (builtinNames.find(u.name.c_str(), builtin))
builtinUniforms[int(builtin)] = u.location;
}
// If this is a built-in (LOVE-created) uniform, store the location.
BuiltinExtern builtin;
if (builtinNames.find(u.name.c_str(), builtin))
builtinUniforms[int(builtin)] = u.location;
if (u.location != -1)
uniforms[u.name] = u;
@@ -265,8 +265,12 @@ void Shader::mapActiveUniforms()
bool Shader::loadVolatile()
{
// zero out active texture list
activeTextureUnits.clear();
activeTextureUnits.insert(activeTextureUnits.begin(), maxTextureUnits, 0);
activeTexUnits.clear();
activeTexUnits.insert(activeTexUnits.begin(), maxTexUnits, 0);
// Built-in uniform locations default to -1 (nonexistant.)
for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
builtinUniforms[i] = -1;
// Built-in uniform locations default to -1 (nonexistant.)
for (int i = 0; i < int(BUILTIN_MAX_ENUM); i++)
@@ -325,15 +329,15 @@ void Shader::unloadVolatile()
}
// decrement global texture id counters for texture units which had textures bound from this shader
for (size_t i = 0; i < activeTextureUnits.size(); ++i)
for (size_t i = 0; i < activeTexUnits.size(); ++i)
{
if (activeTextureUnits[i] > 0)
if (activeTexUnits[i] > 0)
textureCounters[i] = std::max(textureCounters[i] - 1, 0);
}
// active texture list is probably invalid, clear it
activeTextureUnits.clear();
activeTextureUnits.insert(activeTextureUnits.begin(), maxTextureUnits, 0);
activeTexUnits.clear();
activeTexUnits.insert(activeTexUnits.begin(), maxTexUnits, 0);
// same with uniform location list
uniforms.clear();
@@ -398,10 +402,10 @@ void Shader::attach(bool temporary)
{
// make sure all sent textures are properly bound to their respective texture units
// note: list potentially contains texture ids of deleted/invalid textures!
for (size_t i = 0; i < activeTextureUnits.size(); ++i)
for (size_t i = 0; i < activeTexUnits.size(); ++i)
{
if (activeTextureUnits[i] > 0)
gl.bindTextureToUnit(activeTextureUnits[i], i + 1, false);
if (activeTexUnits[i] > 0)
gl.bindTextureToUnit(activeTexUnits[i], i + 1, false);
}
// We always want to use texture unit 0 for everyhing else.
@@ -422,8 +426,8 @@ void Shader::detach()
if (current != nullptr)
{
glUseProgram(0);
current = nullptr;
current->release();
current = nullptr;
}
}
}
@@ -603,61 +607,53 @@ void Shader::sendMatrix(const std::string &name, int size, const GLfloat *m, int
}
}
void Shader::sendTexture(const std::string &name, GLuint texture)
void Shader::sendTexture(const std::string &name, Texture *texture)
{
GLuint gltex = texture->getGLTexture();
TemporaryAttacher attacher(this);
int textureunit = getTextureUnit(name);
int texunit = getTextureUnit(name);
const Uniform &u = getUniform(name);
checkSetUniformError(u, 1, 1, UNIFORM_SAMPLER);
// bind texture to assigned texture unit and send uniform to shader program
gl.bindTextureToUnit(texture, textureunit, false);
gl.bindTextureToUnit(gltex, texunit, false);
glUniform1i(u.location, textureunit);
glUniform1i(u.location, texunit);
// reset texture unit
gl.setTextureUnit(0);
// increment global shader texture id counter for this texture unit, if we haven't already
if (activeTextureUnits[textureunit-1] == 0)
++textureCounters[textureunit-1];
if (activeTexUnits[texunit-1] == 0)
++textureCounters[texunit-1];
// store texture id so it can be re-bound to the proper texture unit later
activeTextureUnits[textureunit-1] = texture;
activeTexUnits[texunit-1] = gltex;
retainObject(name, texture);
}
void Shader::retainTexture(const std::string &name, Object *texture)
void Shader::retainObject(const std::string &name, Object *object)
{
auto it = boundRetainables.find(name);
if (it != boundRetainables.end())
it->second->release();
texture->retain();
boundRetainables[name] = texture;
}
void Shader::sendImage(const std::string &name, Image &image)
{
sendTexture(name, image.getTextureName());
retainTexture(name, &image);
}
void Shader::sendCanvas(const std::string &name, Canvas &canvas)
{
sendTexture(name, canvas.getTextureName());
retainTexture(name, &canvas);
object->retain();
boundRetainables[name] = object;
}
int Shader::getTextureUnit(const std::string &name)
{
auto it = textureUnitPool.find(name);
auto it = texUnitPool.find(name);
if (it != textureUnitPool.end())
if (it != texUnitPool.end())
return it->second;
int textureunit = 1;
int texunit = 1;
// prefer texture units which are unused by all other shaders
auto freeunit_it = std::find(textureCounters.begin(), textureCounters.end(), 0);
@@ -665,32 +661,62 @@ int Shader::getTextureUnit(const std::string &name)
if (freeunit_it != textureCounters.end())
{
// we don't want to use unit 0
textureunit = std::distance(textureCounters.begin(), freeunit_it) + 1;
texunit = std::distance(textureCounters.begin(), freeunit_it) + 1;
}
else
{
// no completely unused texture units exist, try to use next free slot in our own list
auto nextunit_it = std::find(activeTextureUnits.begin(), activeTextureUnits.end(), 0);
auto nextunit_it = std::find(activeTexUnits.begin(), activeTexUnits.end(), 0);
if (nextunit_it == activeTextureUnits.end())
if (nextunit_it == activeTexUnits.end())
throw love::Exception("No more texture units available for shader.");
// we don't want to use unit 0
textureunit = std::distance(activeTextureUnits.begin(), nextunit_it) + 1;
texunit = std::distance(activeTexUnits.begin(), nextunit_it) + 1;
}
textureUnitPool[name] = textureunit;
return textureunit;
texUnitPool[name] = texunit;
return texunit;
}
bool Shader::hasBuiltinUniform(love::graphics::opengl::Shader::BuiltinExtern builtin) const
bool Shader::hasBuiltinExtern(BuiltinExtern builtin) const
{
return builtinUniforms[int(builtin)] != -1;
}
bool Shader::sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *vec, int count)
{
if (!hasBuiltinExtern(builtin))
return false;
GLint location = builtinUniforms[int(builtin)];
TemporaryAttacher attacher(this);
switch (size)
{
case 1:
glUniform1fv(location, count, vec);
break;
case 2:
glUniform2fv(location, count, vec);
break;
case 3:
glUniform3fv(location, count, vec);
break;
case 4:
glUniform4fv(location, count, vec);
break;
default:
return false;
}
return true;
}
bool Shader::sendBuiltinMatrix(BuiltinExtern builtin, int size, const GLfloat *m, int count)
{
if (!hasBuiltinUniform(builtin))
if (!hasBuiltinExtern(builtin))
return false;
GLint location = builtinUniforms[GLint(builtin)];
@@ -715,34 +741,32 @@ bool Shader::sendBuiltinMatrix(BuiltinExtern builtin, int size, const GLfloat *m
return true;
}
bool Shader::sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *vec, int count)
void Shader::checkSetScreenParams()
{
if (!hasBuiltinUniform(builtin))
return false;
if (lastCanvas == Canvas::current)
return;
GLint location = builtinUniforms[GLint(builtin)];
// In the shader, we do pixcoord.y = gl_FragCoord.y * params[0] + params[1].
// This lets us flip pixcoord.y when needed, to be consistent (Canvases
// have flipped y-values for pixel coordinates.)
GLfloat params[] = {0.0f, 0.0f};
TemporaryAttacher attacher(this);
switch (size)
if (Canvas::current != nullptr)
{
case 1:
glUniform1fv(location, count, vec);
break;
case 2:
glUniform2fv(location, count, vec);
break;
case 3:
glUniform3fv(location, count, vec);
break;
case 4:
glUniform4fv(location, count, vec);
break;
default:
return false;
// gl_FragCoord.y is flipped in Canvases, so we un-flip:
// pixcoord.y = gl_FragCoord.y * -1.0 + height.
params[0] = -1.0f;
params[1] = (float) Canvas::current->getHeight();
}
else
{
// No flipping: pixcoord.y = gl_FragCoord.y * 1.0 + 0.0.
params[0] = 1.0f;
params[1] = 0.0f;
}
return true;
sendBuiltinFloat(BUILTIN_SCREEN_PARAMS, 2, params, 1);
lastCanvas = Canvas::current;
}
std::string Shader::getGLSLVersion()
@@ -794,6 +818,7 @@ StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM>::Entry Shader::builti
{"ProjectionMatrix", Shader::BUILTIN_PROJECTION_MATRIX},
{"TransformProjectionMatrix", Shader::BUILTIN_TRANSFORM_PROJECTION_MATRIX},
{"love_PointSize", Shader::BUILTIN_POINT_SIZE},
{"love_ScreenParams", Shader::BUILTIN_SCREEN_PARAMS},
};
StringMap<Shader::BuiltinExtern, Shader::BUILTIN_MAX_ENUM> Shader::builtinNames(Shader::builtinNameEntries, sizeof(Shader::builtinNameEntries));
+19 -20
View File
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -26,8 +26,7 @@
#include "common/StringMap.h"
#include "graphics/Graphics.h"
#include "OpenGL.h"
#include "Image.h"
#include "Canvas.h"
#include "Texture.h"
// STL
#include <string>
@@ -40,6 +39,9 @@ namespace graphics
{
namespace opengl
{
class Canvas;
// A GLSL shader
class Shader : public Object, public Volatile
{
@@ -65,6 +67,7 @@ public:
BUILTIN_PROJECTION_MATRIX,
BUILTIN_TRANSFORM_PROJECTION_MATRIX,
BUILTIN_POINT_SIZE,
BUILTIN_SCREEN_PARAMS,
BUILTIN_MAX_ENUM
};
@@ -134,25 +137,19 @@ public:
void sendMatrix(const std::string &name, int size, const GLfloat *m, int count);
/**
* Send an image to this Shader as a uniform.
* Send a texture to this Shader as a uniform.
*
* @param name The name of the uniform variable in the source code.
**/
void sendImage(const std::string &name, Image &image);
/**
* Send a canvas to this Shader as a uniform.
*
* @param name The name of the uniform variable in the source code.
**/
void sendCanvas(const std::string &name, Canvas &canvas);
void sendTexture(const std::string &name, Texture *texture);
/**
* Internal use only.
**/
bool hasBuiltinUniform(BuiltinExtern builtin) const;
bool hasBuiltinExtern(BuiltinExtern builtin) const;
bool sendBuiltinMatrix(BuiltinExtern builtin, int size, const GLfloat *m, int count);
bool sendBuiltinFloat(BuiltinExtern builtin, int size, const GLfloat *m, int count);
void checkSetScreenParams();
static std::string getGLSLVersion();
static bool isSupported();
@@ -196,8 +193,7 @@ private:
int getTextureUnit(const std::string &name);
void sendTexture(const std::string &name, GLuint texture);
void retainTexture(const std::string &name, Object *texture);
void retainObject(const std::string &name, Object *object);
// Get any warnings or errors generated only by the shader program object.
std::string getProgramWarnings() const;
@@ -212,21 +208,24 @@ private:
// volatile
GLuint program;
// Locations for any built-in uniform variables.
// Location values for any built-in uniform variables.
GLint builtinUniforms[BUILTIN_MAX_ENUM];
// Uniform location buffer map
std::map<std::string, Uniform> uniforms;
// Texture unit pool for setting images
std::map<std::string, GLint> textureUnitPool; // textureUnitPool[name] = textureunit
std::vector<GLuint> activeTextureUnits; // activeTextureUnits[textureunit-1] = textureid
std::map<std::string, GLint> texUnitPool; // texUnitPool[name] = textureunit
std::vector<GLuint> activeTexUnits; // activeTexUnits[textureunit-1] = textureid
// Uniform name to retainable objects
std::map<std::string, Object*> boundRetainables;
// Pointer to the active Canvas when the screen params were last checked.
Canvas *lastCanvas;
// Max GPU texture units available for sent images
static GLint maxTextureUnits;
static GLint maxTexUnits;
// Counts total number of textures bound to each texture unit in all shaders
static std::vector<int> textureCounters;
@@ -239,7 +238,7 @@ private:
static StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM>::Entry attribNameEntries[];
static StringMap<OpenGL::VertexAttrib, OpenGL::ATTRIB_MAX_ENUM> attribNames;
// Names for the uniform matrices used in OpenGL ES 2.
// Names for the LOVE-defined built-in uniform variables.
static StringMap<BuiltinExtern, BUILTIN_MAX_ENUM>::Entry builtinNameEntries[];
static StringMap<BuiltinExtern, BUILTIN_MAX_ENUM> builtinNames;
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -25,8 +25,8 @@
#include "OpenGL.h"
// LOVE
#include "Image.h"
#include "VertexBuffer.h"
#include "Texture.h"
// C++
#include <algorithm>
@@ -41,8 +41,8 @@ namespace graphics
namespace opengl
{
SpriteBatch::SpriteBatch(Image *image, int size, int usage)
: image(image)
SpriteBatch::SpriteBatch(Texture *texture, int size, int usage)
: texture(texture)
, size(size)
, next(0)
, color(0)
@@ -87,12 +87,12 @@ SpriteBatch::SpriteBatch(Image *image, int size, int usage)
throw love::Exception("Out of memory.");
}
image->retain();
texture->retain();
}
SpriteBatch::~SpriteBatch()
{
image->release();
texture->release();
delete color;
delete array_buf;
@@ -106,7 +106,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl
return -1;
// Needed for colors.
memcpy(sprite, image->getVertices(), sizeof(Vertex)*4);
memcpy(sprite, texture->getVertices(), sizeof(Vertex) * 4);
// Transform.
static Matrix t;
@@ -170,17 +170,17 @@ void SpriteBatch::unlock()
array_buf->unmap();
}
void SpriteBatch::setImage(Image *newimage)
void SpriteBatch::setTexture(Texture *newtexture)
{
Object::AutoRelease imagerelease(image);
Object::AutoRelease imagerelease(texture);
newimage->retain();
image = newimage;
newtexture->retain();
texture = newtexture;
}
Image *SpriteBatch::getImage()
Texture *SpriteBatch::getTexture()
{
return image;
return texture;
}
void SpriteBatch::setColor(const Color &color)
@@ -278,9 +278,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
gl.matrices.transform.push(gl.matrices.transform.top());
gl.matrices.transform.top() *= t;
image->predraw();
gl.prepareDraw();
texture->predraw();
VertexBuffer::Bind array_bind(*array_buf);
VertexBuffer::Bind element_bind(*element_buf->getVertexBuffer());
@@ -300,6 +298,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
gl.setVertexAttribArray(OpenGL::ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, sizeof(Vertex), array_buf->getPointer(color_offset));
}
gl.prepareDraw();
glDrawElements(GL_TRIANGLES, element_buf->getIndexCount(next), element_buf->getType(), element_buf->getPointer(0));
gl.disableVertexAttribArray(OpenGL::ATTRIB_POS);
@@ -311,7 +310,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float
gl.setColor(curcolor);
}
image->postdraw();
texture->postdraw();
gl.matrices.transform.pop();
}
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -42,7 +42,7 @@ namespace opengl
{
// Forward declarations.
class Image;
class Texture;
class VertexBuffer;
class VertexIndex;
@@ -58,7 +58,7 @@ public:
USAGE_MAX_ENUM
};
SpriteBatch(Image *image, int size, int usage);
SpriteBatch(Texture *texture, int size, int usage);
virtual ~SpriteBatch();
int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1);
@@ -68,8 +68,8 @@ public:
void *lock();
void unlock();
void setImage(Image *newimage);
Image *getImage();
void setTexture(Texture *newtexture);
Texture *getTexture();
/**
* Set the current color for this SpriteBatch. The sprites added
@@ -127,7 +127,7 @@ private:
*/
void setColorv(Vertex *v, const Color &color);
Image *image;
Texture *texture;
// Max number of sprites in the batch.
int size;
@@ -0,0 +1,65 @@
/**
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#ifndef LOVE_GRAPHICS_OPENGL_TEXTURE_H
#define LOVE_GRAPHICS_OPENGL_TEXTURE_H
// LOVE
#include "graphics/Texture.h"
#include "graphics/Volatile.h"
#include "OpenGL.h"
namespace love
{
namespace graphics
{
namespace opengl
{
class Texture : public love::graphics::Texture, public Volatile
{
public:
virtual ~Texture() {}
/**
* Gets the OpenGL id for this texture.
**/
virtual GLuint getGLTexture() const = 0;
/**
* Any setup the texture might need to do before drawing, e.g. binding
* the OpenGL texture for use.
**/
virtual void predraw() const {}
/**
* Any cleanup the texture might need to do directly after drawing.
**/
virtual void postdraw() const {}
}; // Texture
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_TEXTURE_H
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -165,7 +165,7 @@ void *VBO::map()
if (is_dirty)
{
glGetBufferSubData(getTarget(), 0, getSize(), memory_map);
glGetBufferSubData(getTarget(), 0, (GLsizeiptr) getSize(), memory_map);
is_dirty = false;
}
@@ -189,8 +189,8 @@ void VBO::unmap()
// "orphan" current buffer to avoid implicit synchronisation on the GPU:
// http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf
glBufferData(getTarget(), getSize(), NULL, getUsage());
glBufferData(getTarget(), getSize(), memory_map, getUsage());
glBufferData(getTarget(), (GLsizeiptr) getSize(), NULL, getUsage());
glBufferData(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage());
is_mapped = false;
}
@@ -230,7 +230,7 @@ void VBO::fill(size_t offset, size_t size, const void *data)
// Now we tell the driver it only needs to deal with the data
// we changed.
memcpy(static_cast<char *>(mapdata) + offset, data, size);
glFlushMappedBufferRangeAPPLE(getTarget(), offset, size);
glFlushMappedBufferRangeAPPLE(getTarget(), (GLintptr) offset, (GLsizei) size);
}
glUnmapBuffer(getTarget());
@@ -238,7 +238,7 @@ void VBO::fill(size_t offset, size_t size, const void *data)
else
{
// Fall back to a possibly slower SubData (more chance of syncing.)
glBufferSubData(getTarget(), offset, size, data);
glBufferSubData(getTarget(), (GLintptr) offset, (GLsizeiptr) size, data);
}
if (getMemoryBacking() != BACKING_FULL)
@@ -280,7 +280,7 @@ bool VBO::load(bool restore)
glBufferParameteriAPPLE(getTarget(), GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE);
// Note that if 'src' is '0', no data will be copied.
glBufferData(getTarget(), getSize(), src, getUsage());
glBufferData(getTarget(), (GLsizeiptr) getSize(), src, getUsage());
GLenum err = glGetError();
return (GL_NO_ERROR == err);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,7 +18,6 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Graphics.h"
#include "wrap_Canvas.h"
namespace love
@@ -80,80 +79,6 @@ int w_Canvas_getPixel(lua_State * L)
return 4;
}
int w_Canvas_setFilter(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
Image::Filter f;
const char *minstr = luaL_checkstring(L, 2);
const char *magstr = luaL_optstring(L, 3, minstr);
if (!Image::getConstant(minstr, f.min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, f.mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
canvas->setFilter(f);
return 0;
}
int w_Canvas_getFilter(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
const Image::Filter f = canvas->getFilter();
const char *minstr;
const char *magstr;
Image::getConstant(f.min, minstr);
Image::getConstant(f.mag, magstr);
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
lua_pushnumber(L, f.anisotropy);
return 3;
}
int w_Canvas_setWrap(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
Image::Wrap w;
const char *sstr = luaL_checkstring(L, 2);
const char *tstr = luaL_optstring(L, 3, sstr);
if (!Image::getConstant(sstr, w.s))
return luaL_error(L, "Invalid wrap mode: %s", sstr);
if (!Image::getConstant(tstr, w.t))
return luaL_error(L, "Invalid wrap mode, %s", tstr);
canvas->setWrap(w);
return 0;
}
int w_Canvas_getWrap(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
const Image::Wrap w = canvas->getWrap();
const char *wrap_s;
const char *wrap_t;
Image::getConstant(w.s, wrap_s);
Image::getConstant(w.t, wrap_t);
lua_pushstring(L, wrap_s);
lua_pushstring(L, wrap_t);
return 2;
}
int w_Canvas_clear(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
@@ -186,28 +111,6 @@ int w_Canvas_clear(lua_State *L)
return 0;
}
int w_Canvas_getWidth(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
lua_pushnumber(L, canvas->getWidth());
return 1;
}
int w_Canvas_getHeight(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
lua_pushnumber(L, canvas->getHeight());
return 1;
}
int w_Canvas_getDimensions(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
lua_pushnumber(L, canvas->getWidth());
lua_pushnumber(L, canvas->getHeight());
return 2;
}
int w_Canvas_getType(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
@@ -220,17 +123,19 @@ int w_Canvas_getType(lua_State *L)
static const luaL_Reg functions[] =
{
// From wrap_Texture.
{ "getWidth", w_Texture_getWidth },
{ "getHeight", w_Texture_getHeight },
{ "getDimensions", w_Texture_getDimensions },
{ "setFilter", w_Texture_setFilter },
{ "getFilter", w_Texture_getFilter },
{ "setWrap", w_Texture_setWrap },
{ "getWrap", w_Texture_getWrap },
{ "renderTo", w_Canvas_renderTo },
{ "getImageData", w_Canvas_getImageData },
{ "getPixel", w_Canvas_getPixel },
{ "setFilter", w_Canvas_setFilter },
{ "getFilter", w_Canvas_getFilter },
{ "setWrap", w_Canvas_setWrap },
{ "getWrap", w_Canvas_getWrap },
{ "clear", w_Canvas_clear },
{ "getWidth", w_Canvas_getWidth },
{ "getHeight", w_Canvas_getHeight },
{ "getDimensions", w_Canvas_getDimensions },
{ "getType", w_Canvas_getType },
{ 0, 0 }
};
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -24,6 +24,7 @@
// LOVE
#include "common/runtime.h"
#include "Canvas.h"
#include "wrap_Texture.h"
namespace love
{
@@ -37,14 +38,7 @@ Canvas *luax_checkcanvas(lua_State *L, int idx);
int w_Canvas_renderTo(lua_State *L);
int w_Canvas_getImageData(lua_State *L);
int w_Canvas_getPixel(lua_State * L);
int w_Canvas_setFilter(lua_State *L);
int w_Canvas_getFilter(lua_State *L);
int w_Canvas_setWrap(lua_State *L);
int w_Canvas_getWrap(lua_State *L);
int w_Canvas_clear(lua_State *L);
int w_Canvas_getWidth(lua_State *L);
int w_Canvas_getHeight(lua_State *L);
int w_Canvas_getDimensions(lua_State *L);
int w_Canvas_getType(lua_State *L);
extern "C" int luaopen_canvas(lua_State *L);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -84,14 +84,14 @@ int w_Font_getLineHeight(lua_State *L)
int w_Font_setFilter(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
Image::Filter f = t->getFilter();
Texture::Filter f = t->getFilter();
const char *minstr = luaL_checkstring(L, 2);
const char *magstr = luaL_optstring(L, 3, minstr);
if (!Image::getConstant(minstr, f.min))
if (!Texture::getConstant(minstr, f.min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, f.mag))
if (!Texture::getConstant(magstr, f.mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
@@ -103,11 +103,11 @@ int w_Font_setFilter(lua_State *L)
int w_Font_getFilter(lua_State *L)
{
Font *t = luax_checkfont(L, 1);
const Image::Filter f = t->getFilter();
const Texture::Filter f = t->getFilter();
const char *minstr;
const char *magstr;
Image::getConstant(f.min, minstr);
Image::getConstant(f.mag, magstr);
Texture::getConstant(f.min, minstr);
Texture::getConstant(f.mag, magstr);
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
lua_pushnumber(L, f.anisotropy);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -20,7 +20,7 @@
#include "wrap_Graphics.h"
#include "OpenGL.h"
#include "graphics/DrawQable.h"
#include "graphics/Texture.h"
#include "image/ImageData.h"
#include "font/Rasterizer.h"
@@ -34,7 +34,7 @@ namespace graphics
namespace opengl
{
static Graphics *instance = 0;
static Graphics *instance = nullptr;
int w_reset(lua_State *)
{
@@ -237,7 +237,7 @@ int w_newFont(lua_State *L)
int w_newImageFont(lua_State *L)
{
// filter for glyphs
Image::Filter filter = instance->getDefaultFilter();
Texture::Filter filter = instance->getDefaultFilter();
// Convert to ImageData if necessary.
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T) || luax_istype(L, 1, FILESYSTEM_FILE_DATA_T))
@@ -277,7 +277,7 @@ int w_newImageFont(lua_State *L)
int w_newSpriteBatch(lua_State *L)
{
Image *image = luax_checkimage(L, 1);
Texture *texture = luax_checktexture(L, 1);
int size = luaL_optint(L, 2, 1000);
SpriteBatch::UsageHint usage = SpriteBatch::USAGE_DYNAMIC;
if (lua_gettop(L) > 2)
@@ -287,8 +287,8 @@ int w_newSpriteBatch(lua_State *L)
return luaL_error(L, "Invalid SpriteBatch usage hint: %s", usagestr);
}
SpriteBatch *t = 0;
EXCEPT_GUARD(t = instance->newSpriteBatch(image, size, usage);)
SpriteBatch *t = nullptr;
EXCEPT_GUARD(t = instance->newSpriteBatch(texture, size, usage);)
luax_pushtype(L, "SpriteBatch", GRAPHICS_SPRITE_BATCH_T, t);
return 1;
@@ -296,13 +296,13 @@ int w_newSpriteBatch(lua_State *L)
int w_newParticleSystem(lua_State *L)
{
Image *image = luax_checkimage(L, 1);
Texture *texture = luax_checktexture(L, 1);
lua_Number size = luaL_optnumber(L, 2, 1000);
ParticleSystem *t = 0;
if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES)
return luaL_error(L, "Invalid ParticleSystem size");
EXCEPT_GUARD(t = instance->newParticleSystem(image, int(size));)
EXCEPT_GUARD(t = instance->newParticleSystem(texture, int(size));)
luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, t);
return 1;
@@ -434,10 +434,10 @@ int w_newMesh(lua_State *L)
// Check first argument: mandatory table of vertices.
luaL_checktype(L, 1, LUA_TTABLE);
// Second argument: optional image.
Image *img = 0;
// Second argument: optional texture.
Texture *tex = nullptr;
if (!lua_isnoneornil(L, 2))
img = luax_checkimage(L, 2);
tex = luax_checktexture(L, 2);
// Third argument: optional draw mode.
const char *str = 0;
@@ -485,11 +485,11 @@ int w_newMesh(lua_State *L)
vertices.push_back(v);
}
Mesh *t = 0;
Mesh *t = nullptr;
EXCEPT_GUARD(t = instance->newMesh(vertices, mode);)
if (img)
t->setImage(img);
if (tex)
t->setTexture(tex);
t->setVertexColors(use_colors);
@@ -646,20 +646,20 @@ int w_getBlendMode(lua_State *L)
int w_setDefaultFilter(lua_State *L)
{
Image::FilterMode min;
Image::FilterMode mag;
Texture::FilterMode min;
Texture::FilterMode mag;
const char *minstr = luaL_checkstring(L, 1);
const char *magstr = luaL_optstring(L, 2, minstr);
if (!Image::getConstant(minstr, min))
if (!Texture::getConstant(minstr, min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, mag))
if (!Texture::getConstant(magstr, mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
float anisotropy = (float) luaL_optnumber(L, 3, 1.0);
Image::Filter f;
Texture::Filter f;
f.min = min;
f.mag = mag;
f.anisotropy = anisotropy;
@@ -671,12 +671,12 @@ int w_setDefaultFilter(lua_State *L)
int w_getDefaultFilter(lua_State *L)
{
const Image::Filter &f = instance->getDefaultFilter();
const Texture::Filter &f = instance->getDefaultFilter();
const char *minstr;
const char *magstr;
if (!Image::getConstant(f.min, minstr))
if (!Texture::getConstant(f.min, minstr))
return luaL_error(L, "Unknown minification filter mode");
if (!Image::getConstant(f.mag, magstr))
if (!Texture::getConstant(f.mag, magstr))
return luaL_error(L, "Unknown magnification filter mode");
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
@@ -686,11 +686,11 @@ int w_getDefaultFilter(lua_State *L)
int w_setDefaultMipmapFilter(lua_State *L)
{
Image::FilterMode filter = Image::FILTER_NONE;
Texture::FilterMode filter = Texture::FILTER_NONE;
if (!lua_isnoneornil(L, 1))
{
const char *str = luaL_checkstring(L, 1);
if (!Image::getConstant(str, filter))
if (!Texture::getConstant(str, filter))
return luaL_error(L, "Invalid filter mode: %s", str);
}
@@ -703,13 +703,13 @@ int w_setDefaultMipmapFilter(lua_State *L)
int w_getDefaultMipmapFilter(lua_State *L)
{
Image::FilterMode filter;
Texture::FilterMode filter;
float sharpness;
instance->getDefaultMipmapFilter(&filter, &sharpness);
const char *str;
if (Image::getConstant(filter, str))
if (Texture::getConstant(filter, str))
lua_pushstring(L, str);
else
lua_pushnil(L);
@@ -1034,14 +1034,14 @@ int w_getRendererInfo(lua_State *L)
int w_draw(lua_State *L)
{
Drawable *drawable = 0;
DrawQable *drawqable = 0;
Quad *quad = 0;
Drawable *drawable = nullptr;
Texture *texture = nullptr;
Quad *quad = nullptr;
int startidx = 2;
if (luax_istype(L, 2, GRAPHICS_QUAD_T))
{
drawqable = luax_checktype<DrawQable>(L, 1, "DrawQable", GRAPHICS_DRAWQABLE_T);
texture = luax_checktexture(L, 1);
quad = luax_totype<Quad>(L, 2, "Quad", GRAPHICS_QUAD_T);
startidx = 3;
}
@@ -1065,8 +1065,8 @@ int w_draw(lua_State *L)
float kx = (float) luaL_optnumber(L, startidx + 7, 0.0);
float ky = (float) luaL_optnumber(L, startidx + 8, 0.0);
if (drawqable && quad)
drawqable->drawq(quad, x, y, a, sx, sy, ox, oy, kx, ky);
if (texture && quad)
texture->drawq(quad, x, y, a, sx, sy, ox, oy, kx, ky);
else if (drawable)
drawable->draw(x, y, a, sx, sy, ox, oy, kx, ky);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -33,72 +33,17 @@ Image *luax_checkimage(lua_State *L, int idx)
return luax_checktype<Image>(L, idx, "Image", GRAPHICS_IMAGE_T);
}
int w_Image_getWidth(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getWidth());
return 1;
}
int w_Image_getHeight(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getHeight());
return 1;
}
int w_Image_getDimensions(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
lua_pushnumber(L, t->getWidth());
lua_pushnumber(L, t->getHeight());
return 2;
}
int w_Image_setFilter(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
Image::Filter f = t->getFilter();
const char *minstr = luaL_checkstring(L, 2);
const char *magstr = luaL_optstring(L, 3, minstr);
if (!Image::getConstant(minstr, f.min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Image::getConstant(magstr, f.mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
EXCEPT_GUARD(t->setFilter(f);)
return 0;
}
int w_Image_getFilter(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
const Image::Filter f = t->getFilter();
const char *minstr;
const char *magstr;
Image::getConstant(f.min, minstr);
Image::getConstant(f.mag, magstr);
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
lua_pushnumber(L, f.anisotropy);
return 3;
}
int w_Image_setMipmapFilter(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
Image::Filter f = t->getFilter();
Texture::Filter f = t->getFilter();
if (lua_isnoneornil(L, 2))
f.mipmap = Image::FILTER_NONE; // mipmapping is disabled if no argument is given
f.mipmap = Texture::FILTER_NONE; // mipmapping is disabled if no argument is given
else
{
const char *mipmapstr = luaL_checkstring(L, 2);
if (!Image::getConstant(mipmapstr, f.mipmap))
if (!Texture::getConstant(mipmapstr, f.mipmap))
return luaL_error(L, "Invalid filter mode: %s", mipmapstr);
}
@@ -114,10 +59,10 @@ int w_Image_getMipmapFilter(lua_State *L)
{
Image *t = luax_checkimage(L, 1);
const Image::Filter &f = t->getFilter();
const Texture::Filter &f = t->getFilter();
const char *mipmapstr;
if (Image::getConstant(f.mipmap, mipmapstr))
if (Texture::getConstant(f.mipmap, mipmapstr))
lua_pushstring(L, mipmapstr);
else
lua_pushnil(L); // only return a mipmap filter if mipmapping is enabled
@@ -126,38 +71,6 @@ int w_Image_getMipmapFilter(lua_State *L)
return 2;
}
int w_Image_setWrap(lua_State *L)
{
Image *i = luax_checkimage(L, 1);
Image::Wrap w;
const char *sstr = luaL_checkstring(L, 2);
const char *tstr = luaL_optstring(L, 3, sstr);
if (!Image::getConstant(sstr, w.s))
return luaL_error(L, "Invalid wrap mode: %s", sstr);
if (!Image::getConstant(tstr, w.t))
return luaL_error(L, "Invalid wrap mode, %s", tstr);
i->setWrap(w);
return 0;
}
int w_Image_getWrap(lua_State *L)
{
Image *i = luax_checkimage(L, 1);
const Image::Wrap w = i->getWrap();
const char *sstr;
const char *tstr;
Image::getConstant(w.s, sstr);
Image::getConstant(w.t, tstr);
lua_pushstring(L, sstr);
lua_pushstring(L, tstr);
return 2;
}
int w_Image_isCompressed(lua_State *L)
{
Image *i = luax_checkimage(L, 1);
@@ -204,13 +117,15 @@ int w_Image_getData(lua_State *L)
static const luaL_Reg functions[] =
{
{ "getWidth", w_Image_getWidth },
{ "getHeight", w_Image_getHeight },
{ "getDimensions", w_Image_getDimensions },
{ "setFilter", w_Image_setFilter },
{ "getFilter", w_Image_getFilter },
{ "setWrap", w_Image_setWrap },
{ "getWrap", w_Image_getWrap },
// From wrap_Texture.
{ "getWidth", w_Texture_getWidth },
{ "getHeight", w_Texture_getHeight },
{ "getDimensions", w_Texture_getDimensions },
{ "setFilter", w_Texture_setFilter },
{ "getFilter", w_Texture_getFilter },
{ "setWrap", w_Texture_setWrap },
{ "getWrap", w_Texture_getWrap },
{ "setMipmapFilter", w_Image_setMipmapFilter },
{ "getMipmapFilter", w_Image_getMipmapFilter },
{ "isCompressed", w_Image_isCompressed },
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -24,6 +24,7 @@
// LOVE
#include "common/runtime.h"
#include "Image.h"
#include "wrap_Texture.h"
namespace love
{
@@ -33,15 +34,8 @@ namespace opengl
{
Image *luax_checkimage(lua_State *L, int idx);
int w_Image_getWidth(lua_State *L);
int w_Image_getHeight(lua_State *L);
int w_Image_getDimensions(lua_State *L);
int w_Image_setFilter(lua_State *L);
int w_Image_getFilter(lua_State *L);
int w_Image_setMipmapFilter(lua_State *L);
int w_Image_getMipmapFilter(lua_State *L);
int w_Image_setWrap(lua_State *L);
int w_Image_getWrap(lua_State *L);
int w_Image_isCompressed(lua_State *L);
int w_Image_refresh(lua_State *L);
int w_Image_getData(lua_State *L);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -20,7 +20,12 @@
// LOVE
#include "wrap_Mesh.h"
#include "wrap_Image.h"
#include "Image.h"
#include "Canvas.h"
#include "wrap_Texture.h"
// C++
#include <typeinfo>
namespace love
{
@@ -231,31 +236,42 @@ int w_Mesh_getVertexMap(lua_State *L)
return 1;
}
int w_Mesh_setImage(lua_State *L)
int w_Mesh_setTexture(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
if (lua_isnoneornil(L, 2))
t->setImage();
t->setTexture();
else
{
Image *img = luax_checkimage(L, 2);
t->setImage(img);
Texture *tex = luax_checktexture(L, 2);
t->setTexture(tex);
}
return 0;
}
int w_Mesh_getImage(lua_State *L)
int w_Mesh_getTexture(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
Image *img = t->getImage();
Texture *tex = t->getTexture();
if (img == NULL)
if (tex == nullptr)
return 0;
img->retain();
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, img);
tex->retain();
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, tex);
else
{
tex->release();
return luaL_error(L, "Unable to determine texture type.");
}
return 1;
}
@@ -299,6 +315,20 @@ int w_Mesh_hasVertexColors(lua_State *L)
return 1;
}
int w_Mesh_setWireframe(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
t->setWireframe(luax_toboolean(L, 2));
return 0;
}
int w_Mesh_isWireframe(lua_State *L)
{
Mesh *t = luax_checkmesh(L, 1);
luax_pushboolean(L, t->isWireframe());
return 1;
}
static const luaL_Reg functions[] =
{
{ "setVertex", w_Mesh_setVertex },
@@ -308,12 +338,19 @@ static const luaL_Reg functions[] =
{ "getVertexCount", w_Mesh_getVertexCount },
{ "setVertexMap", w_Mesh_setVertexMap },
{ "getVertexMap", w_Mesh_getVertexMap },
{ "setImage", w_Mesh_setImage },
{ "getImage", w_Mesh_getImage },
{ "setTexture", w_Mesh_setTexture },
{ "getTexture", w_Mesh_getTexture },
{ "setDrawMode", w_Mesh_setDrawMode },
{ "getDrawMode", w_Mesh_getDrawMode },
{ "setVertexColors", w_Mesh_setVertexColors },
{ "hasVertexColors", w_Mesh_hasVertexColors },
{ "setWireframe", w_Mesh_setWireframe },
{ "isWireframe", w_Mesh_isWireframe },
// Deprecated since 0.9.1.
{ "setImage", w_Mesh_setTexture },
{ "getImage", w_Mesh_getTexture },
{ 0, 0 }
};
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -41,12 +41,14 @@ 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_setImage(lua_State *L);
int w_Mesh_getImage(lua_State *L);
int w_Mesh_setTexture(lua_State *L);
int w_Mesh_getTexture(lua_State *L);
int w_Mesh_setDrawMode(lua_State *L);
int w_Mesh_getDrawMode(lua_State *L);
int w_Mesh_setVertexColors(lua_State *L);
int w_Mesh_hasVertexColors(lua_State *L);
int w_Mesh_setWireframe(lua_State *L);
int w_Mesh_isWireframe(lua_State *L);
extern "C" int luaopen_mesh(lua_State *L);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,12 +18,20 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
// LOVE
#include "wrap_ParticleSystem.h"
#include "common/Vector.h"
#include "Image.h"
#include "Canvas.h"
#include "wrap_Texture.h"
// C
#include <cstring>
// C++
#include <typeinfo>
namespace love
{
namespace graphics
@@ -36,20 +44,42 @@ ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx)
return luax_checktype<ParticleSystem>(L, idx, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T);
}
int w_ParticleSystem_setImage(lua_State *L)
int w_ParticleSystem_clone(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
Image *i = luax_checkimage(L, 2);
t->setImage(i);
ParticleSystem *clone = nullptr;
EXCEPT_GUARD(clone = t->clone();)
luax_pushtype(L, "ParticleSystem", GRAPHICS_PARTICLE_SYSTEM_T, clone);
return 1;
}
int w_ParticleSystem_setTexture(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
Texture *tex = luax_checktexture(L, 2);
t->setTexture(tex);
return 0;
}
int w_ParticleSystem_getImage(lua_State *L)
int w_ParticleSystem_getTexture(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
Image *i = t->getImage();
i->retain();
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, i);
Texture *tex = t->getTexture();
tex->retain();
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, tex);
else
{
tex->release();
return luaL_error(L, "Unable to determine texture type.");
}
return 1;
}
@@ -604,8 +634,9 @@ int w_ParticleSystem_update(lua_State *L)
static const luaL_Reg functions[] =
{
{ "setImage", w_ParticleSystem_setImage },
{ "getImage", w_ParticleSystem_getImage },
{ "clone", w_ParticleSystem_clone },
{ "setTexture", w_ParticleSystem_setTexture },
{ "getTexture", w_ParticleSystem_getTexture },
{ "setBufferSize", w_ParticleSystem_setBufferSize },
{ "getBufferSize", w_ParticleSystem_getBufferSize },
{ "setInsertMode", w_ParticleSystem_setInsertMode },
@@ -656,6 +687,11 @@ static const luaL_Reg functions[] =
{ "isPaused", w_ParticleSystem_isPaused },
{ "isStopped", w_ParticleSystem_isStopped },
{ "update", w_ParticleSystem_update },
// Deprecated since 0.9.1.
{ "setImage", w_ParticleSystem_setTexture },
{ "getImage", w_ParticleSystem_getTexture },
{ 0, 0 }
};
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -23,7 +23,6 @@
// LOVE
#include "common/runtime.h"
#include "wrap_Image.h"
#include "ParticleSystem.h"
namespace love
@@ -34,8 +33,9 @@ namespace opengl
{
ParticleSystem *luax_checkparticlesystem(lua_State *L, int idx);
int w_ParticleSystem_setImage(lua_State *L);
int w_ParticleSystem_getImage(lua_State *L);
int w_ParticleSystem_clone(lua_State *L);
int w_ParticleSystem_setTexture(lua_State *L);
int w_ParticleSystem_getTexture(lua_State *L);
int w_ParticleSystem_setBufferSize(lua_State *L);
int w_ParticleSystem_getBufferSize(lua_State *L);
int w_ParticleSystem_setInsertMode(lua_State *L);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -19,8 +19,7 @@
**/
#include "wrap_Shader.h"
#include "wrap_Image.h"
#include "wrap_Canvas.h"
#include "wrap_Texture.h"
#include <string>
#include <iostream>
@@ -253,23 +252,13 @@ int w_Shader_sendMatrix(lua_State *L)
return 0;
}
int w_Shader_sendImage(lua_State *L)
int w_Shader_sendTexture(lua_State *L)
{
Shader *shader = luax_checkshader(L, 1);
const char *name = luaL_checkstring(L, 2);
Image *img = luax_checkimage(L, 3);
Texture *texture = luax_checktexture(L, 3);
EXCEPT_GUARD(shader->sendImage(name, *img);)
return 0;
}
int w_Shader_sendCanvas(lua_State *L)
{
Shader *shader = luax_checkshader(L, 1);
const char *name = luaL_checkstring(L, 2);
Canvas *canvas = luax_checkcanvas(L, 3);
EXCEPT_GUARD(shader->sendCanvas(name, *canvas);)
EXCEPT_GUARD(shader->sendTexture(name, texture);)
return 0;
}
@@ -318,7 +307,7 @@ static void w_convertMatrices(lua_State *L, int idx)
int w_Shader_send(lua_State *L)
{
int ttype = lua_type(L, 3);
Proxy *p = 0;
Proxy *p = nullptr;
switch (ttype)
{
@@ -328,13 +317,11 @@ int w_Shader_send(lua_State *L)
return w_Shader_sendFloat(L);
break;
case LUA_TUSERDATA:
// Image or Canvas.
// Texture (Image or Canvas).
p = (Proxy *) lua_touserdata(L, 3);
if (p->flags[GRAPHICS_IMAGE_ID])
return w_Shader_sendImage(L);
else if (p->flags[GRAPHICS_CANVAS_ID])
return w_Shader_sendCanvas(L);
if (p->flags[GRAPHICS_TEXTURE_ID])
return w_Shader_sendTexture(L);
break;
case LUA_TTABLE:
@@ -366,9 +353,13 @@ static const luaL_Reg functions[] =
{ "sendBoolean", w_Shader_sendInt },
{ "sendFloat", w_Shader_sendFloat },
{ "sendMatrix", w_Shader_sendMatrix },
{ "sendImage", w_Shader_sendImage },
{ "sendCanvas", w_Shader_sendCanvas },
{ "sendTexture", w_Shader_sendTexture },
{ "send", w_Shader_send },
// Deprecated since 0.9.1.
{ "sendImage", w_Shader_sendTexture },
{ "sendCanvas", w_Shader_sendTexture },
{ 0, 0 }
};
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -36,8 +36,7 @@ int w_Shader_getWarnings(lua_State *L);
int w_Shader_sendInt(lua_State *L);
int w_Shader_sendFloat(lua_State *L);
int w_Shader_sendMatrix(lua_State *L);
int w_Shader_sendImage(lua_State *L);
int w_Shader_sendCanvas(lua_State *L);
int w_Shader_sendTexture(lua_State *L);
int w_Shader_send(lua_State *L);
extern "C" int luaopen_shader(lua_State *L);
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,8 +18,14 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Image.h"
// LOVE
#include "wrap_SpriteBatch.h"
#include "Image.h"
#include "Canvas.h"
#include "wrap_Texture.h"
// C++
#include <typeinfo>
namespace love
{
@@ -36,7 +42,7 @@ SpriteBatch *luax_checkspritebatch(lua_State *L, int idx)
int w_SpriteBatch_add(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Quad *quad = 0;
Quad *quad = nullptr;
int startidx = 2;
if (luax_istype(L, 2, GRAPHICS_QUAD_T))
@@ -74,7 +80,7 @@ int w_SpriteBatch_set(lua_State *L)
SpriteBatch *t = luax_checkspritebatch(L, 1);
int id = luaL_checkinteger(L, 2);
Quad *quad = 0;
Quad *quad = nullptr;
int startidx = 3;
if (luax_istype(L, 3, GRAPHICS_QUAD_T))
@@ -126,20 +132,31 @@ int w_SpriteBatch_unbind(lua_State *L)
return 0;
}
int w_SpriteBatch_setImage(lua_State *L)
int w_SpriteBatch_setTexture(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Image *image = luax_checktype<Image>(L, 2, "Image", GRAPHICS_IMAGE_T);
t->setImage(image);
Texture *tex = luax_checktexture(L, 2);
t->setTexture(tex);
return 0;
}
int w_SpriteBatch_getImage(lua_State *L)
int w_SpriteBatch_getTexture(lua_State *L)
{
SpriteBatch *t = luax_checkspritebatch(L, 1);
Image *image = t->getImage();
image->retain();
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, image);
Texture *tex = t->getTexture();
tex->retain();
// FIXME: big hack right here.
if (typeid(*tex) == typeid(Image))
luax_pushtype(L, "Image", GRAPHICS_IMAGE_T, tex);
else if (typeid(*tex) == typeid(Canvas))
luax_pushtype(L, "Canvas", GRAPHICS_CANVAS_T, tex);
else
{
tex->release();
return luaL_error(L, "Unable to determine texture type.");
}
return 1;
}
@@ -224,13 +241,17 @@ static const luaL_Reg functions[] =
{ "clear", w_SpriteBatch_clear },
{ "bind", w_SpriteBatch_bind },
{ "unbind", w_SpriteBatch_unbind },
{ "setImage", w_SpriteBatch_setImage },
{ "getImage", w_SpriteBatch_getImage },
{ "setTexture", w_SpriteBatch_setTexture },
{ "getTexture", w_SpriteBatch_getTexture },
{ "setColor", w_SpriteBatch_setColor },
{ "getColor", w_SpriteBatch_getColor },
{ "getCount", w_SpriteBatch_getCount },
{ "setBufferSize", w_SpriteBatch_setBufferSize },
{ "getBufferSize", w_SpriteBatch_getBufferSize },
// Deprecated since 0.9.1.
{ "setImage", w_SpriteBatch_setTexture },
{ "getImage", w_SpriteBatch_getTexture },
{ 0, 0 }
};
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -39,8 +39,8 @@ int w_SpriteBatch_setg(lua_State *L);
int w_SpriteBatch_clear(lua_State *L);
int w_SpriteBatch_bind(lua_State *L);
int w_SpriteBatch_unbind(lua_State *L);
int w_SpriteBatch_setImage(lua_State *L);
int w_SpriteBatch_getImage(lua_State *L);
int w_SpriteBatch_setTexture(lua_State *L);
int w_SpriteBatch_getTexture(lua_State *L);
int w_SpriteBatch_setColor(lua_State *L);
int w_SpriteBatch_getColor(lua_State *L);
int w_SpriteBatch_getCount(lua_State *L);
@@ -0,0 +1,133 @@
/**
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "wrap_Texture.h"
namespace love
{
namespace graphics
{
namespace opengl
{
Texture *luax_checktexture(lua_State *L, int idx)
{
return luax_checktype<Texture>(L, idx, "Texture", GRAPHICS_TEXTURE_T);
}
int w_Texture_getWidth(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
lua_pushnumber(L, t->getWidth());
return 1;
}
int w_Texture_getHeight(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
lua_pushnumber(L, t->getHeight());
return 1;
}
int w_Texture_getDimensions(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
lua_pushnumber(L, t->getWidth());
lua_pushnumber(L, t->getHeight());
return 2;
}
int w_Texture_setFilter(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
Texture::Filter f = t->getFilter();
const char *minstr = luaL_checkstring(L, 2);
const char *magstr = luaL_optstring(L, 3, minstr);
if (!Texture::getConstant(minstr, f.min))
return luaL_error(L, "Invalid filter mode: %s", minstr);
if (!Texture::getConstant(magstr, f.mag))
return luaL_error(L, "Invalid filter mode: %s", magstr);
f.anisotropy = (float) luaL_optnumber(L, 4, 1.0);
EXCEPT_GUARD(t->setFilter(f);)
return 0;
}
int w_Texture_getFilter(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
const Texture::Filter f = t->getFilter();
const char *minstr = nullptr;
const char *magstr = nullptr;
if (!Texture::getConstant(f.min, minstr))
return luaL_error(L, "Unknown filter mode.");
if (!Texture::getConstant(f.mag, magstr))
return luaL_error(L, "Unknown filter mode.");
lua_pushstring(L, minstr);
lua_pushstring(L, magstr);
lua_pushnumber(L, f.anisotropy);
return 3;
}
int w_Texture_setWrap(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
Texture::Wrap w;
const char *sstr = luaL_checkstring(L, 2);
const char *tstr = luaL_optstring(L, 3, sstr);
if (!Texture::getConstant(sstr, w.s))
return luaL_error(L, "Invalid wrap mode: %s", sstr);
if (!Texture::getConstant(tstr, w.t))
return luaL_error(L, "Invalid wrap mode, %s", tstr);
t->setWrap(w);
return 0;
}
int w_Texture_getWrap(lua_State *L)
{
Texture *t = luax_checktexture(L, 1);
const Texture::Wrap w = t->getWrap();
const char *sstr = nullptr;
const char *tstr = nullptr;
if (!Texture::getConstant(w.s, sstr))
return luaL_error(L, "Unknown wrap mode.");
if (!Texture::getConstant(w.t, tstr))
return luaL_error(L, "Unknown wrap mode.");
lua_pushstring(L, sstr);
lua_pushstring(L, tstr);
return 2;
}
} // opengl
} // graphics
} // love
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2006-2013 LOVE Development Team
* Copyright (c) 2006-2014 LOVE Development Team
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
@@ -18,16 +18,30 @@
* 3. This notice may not be removed or altered from any source distribution.
**/
#include "Drawable.h"
#ifndef LOVE_GRAPHICS_OPENGL_WRAP_TEXTURE_H
#define LOVE_GRAPHICS_OPENGL_WRAP_TEXTURE_H
#include "Texture.h"
#include "common/runtime.h"
namespace love
{
namespace graphics
{
Drawable::~Drawable()
namespace opengl
{
}
Texture *luax_checktexture(lua_State *L, int idx);
int w_Texture_getWidth(lua_State *L);
int w_Texture_getHeight(lua_State *L);
int w_Texture_getDimensions(lua_State *L);
int w_Texture_setFilter(lua_State *L);
int w_Texture_getFilter(lua_State *L);
int w_Texture_setWrap(lua_State *L);
int w_Texture_getWrap(lua_State *L);
} // opengl
} // graphics
} // love
#endif // LOVE_GRAPHICS_OPENGL_WRAP_TEXTURE_H