Merged default into minor

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2014-06-16 03:09:04 -03:00
40 changed files with 376 additions and 117 deletions
+1 -1
View File
@@ -184,7 +184,7 @@ StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM>::Entry Graphics::syst
{"pointsize", Graphics::LIMIT_POINT_SIZE},
{"texturesize", Graphics::LIMIT_TEXTURE_SIZE},
{"multicanvas", Graphics::LIMIT_MULTI_CANVAS},
{"canvasfsaa", Graphics::LIMIT_CANVAS_FSAA},
{"canvasmsaa", Graphics::LIMIT_CANVAS_MSAA},
};
StringMap<Graphics::SystemLimit, Graphics::LIMIT_MAX_ENUM> Graphics::systemLimits(Graphics::systemLimitEntries, sizeof(Graphics::systemLimitEntries));
+1 -1
View File
@@ -102,7 +102,7 @@ public:
LIMIT_POINT_SIZE,
LIMIT_TEXTURE_SIZE,
LIMIT_MULTI_CANVAS,
LIMIT_CANVAS_FSAA,
LIMIT_CANVAS_MSAA,
LIMIT_MAX_ENUM
};
+37 -37
View File
@@ -417,15 +417,15 @@ static void getStrategy()
}
}
Canvas::Canvas(int width, int height, Format format, int fsaa)
Canvas::Canvas(int width, int height, Format format, int msaa)
: fbo(0)
, resolve_fbo(0)
, texture(0)
, fsaa_buffer(0)
, msaa_buffer(0)
, depth_stencil(0)
, format(format)
, fsaa_samples(fsaa)
, fsaa_dirty(false)
, msaa_samples(msaa)
, msaa_dirty(false)
{
this->width = width;
this->height = height;
@@ -467,7 +467,7 @@ Canvas::~Canvas()
unloadVolatile();
}
bool Canvas::createFSAAFBO(GLenum internalformat)
bool Canvas::createMSAAFBO(GLenum internalformat)
{
// Create our FBO without a texture.
status = strategy->createFBO(fbo, 0);
@@ -482,7 +482,7 @@ bool Canvas::createFSAAFBO(GLenum internalformat)
}
// Create and attach the MSAA buffer for our FBO.
if (strategy->createMSAABuffer(width, height, fsaa_samples, internalformat, fsaa_buffer))
if (strategy->createMSAABuffer(width, height, msaa_samples, internalformat, msaa_buffer))
status = GL_FRAMEBUFFER_COMPLETE;
else
status = GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
@@ -494,10 +494,10 @@ bool Canvas::createFSAAFBO(GLenum internalformat)
if (status != GL_FRAMEBUFFER_COMPLETE)
{
// Clean up.
strategy->deleteFBO(fbo, 0, fsaa_buffer);
strategy->deleteFBO(fbo, 0, msaa_buffer);
strategy->deleteFBO(resolve_fbo, 0, 0);
fbo = fsaa_buffer = resolve_fbo = 0;
fsaa_samples = 0;
fbo = msaa_buffer = resolve_fbo = 0;
msaa_samples = 0;
}
if (current != this)
@@ -509,7 +509,7 @@ bool Canvas::createFSAAFBO(GLenum internalformat)
bool Canvas::loadVolatile()
{
fbo = depth_stencil = texture = 0;
resolve_fbo = fsaa_buffer = 0;
resolve_fbo = msaa_buffer = 0;
status = GL_FRAMEBUFFER_COMPLETE;
// glTexImage2D is guaranteed to error in this case.
@@ -556,16 +556,16 @@ bool Canvas::loadVolatile()
glGetIntegerv(GL_MAX_SAMPLES, &max_samples);
}
if (fsaa_samples > max_samples)
fsaa_samples = max_samples;
if (msaa_samples > max_samples)
msaa_samples = max_samples;
// Try to create a FSAA FBO if requested.
bool fsaasuccess = false;
if (fsaa_samples > 1)
fsaasuccess = createFSAAFBO(internalformat);
// Try to create a MSAA FBO if requested.
bool msaasuccess = false;
if (msaa_samples > 1)
msaasuccess = createMSAAFBO(internalformat);
// On failure (or no requested FSAA), fall back to a regular FBO.
if (!fsaasuccess)
// On failure (or no requested MSAA), fall back to a regular FBO.
if (!msaasuccess)
status = strategy->createFBO(fbo, texture);
if (status != GL_FRAMEBUFFER_COMPLETE)
@@ -573,20 +573,20 @@ bool Canvas::loadVolatile()
clear(Color(0, 0, 0, 0));
fsaa_dirty = (fsaa_buffer != 0);
msaa_dirty = (msaa_buffer != 0);
return true;
}
void Canvas::unloadVolatile()
{
strategy->deleteFBO(fbo, depth_stencil, fsaa_buffer);
strategy->deleteFBO(fbo, depth_stencil, msaa_buffer);
strategy->deleteFBO(resolve_fbo, 0, 0);
gl.deleteTexture(texture);
fbo = depth_stencil = texture = 0;
resolve_fbo = fsaa_buffer = 0;
resolve_fbo = msaa_buffer = 0;
for (size_t i = 0; i < attachedCanvases.size(); i++)
attachedCanvases[i]->release();
@@ -705,8 +705,8 @@ void Canvas::setupGrab()
else if (screenHasSRGB)
glDisable(GL_FRAMEBUFFER_SRGB);
if (fsaa_buffer != 0)
fsaa_dirty = true;
if (msaa_buffer != 0)
msaa_dirty = true;
}
void Canvas::startGrab(const std::vector<Canvas *> &canvases)
@@ -723,8 +723,8 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
if ((int) canvases.size() + 1 > gl.getMaxRenderTargets())
throw love::Exception("This system can't simultaniously render to %d canvases.", canvases.size()+1);
if (fsaa_samples != 0)
throw love::Exception("Multi-canvas rendering is not supported with FSAA.");
if (msaa_samples != 0)
throw love::Exception("Multi-canvas rendering is not supported with MSAA.");
}
for (size_t i = 0; i < canvases.size(); i++)
@@ -735,8 +735,8 @@ void Canvas::startGrab(const std::vector<Canvas *> &canvases)
if (canvases[i]->getTextureFormat() != format)
throw love::Exception("All canvas arguments must have the same texture format.");
if (canvases[i]->getFSAA() != 0)
throw love::Exception("Multi-canvas rendering is not supported with FSAA.");
if (canvases[i]->getMSAA() != 0)
throw love::Exception("Multi-canvas rendering is not supported with MSAA.");
if (!canvaseschanged && canvases[i] != attachedCanvases[i])
canvaseschanged = true;
@@ -857,8 +857,8 @@ void Canvas::clear(Color c)
if (current != this)
strategy->bindFBO(previous);
if (fsaa_buffer != 0)
fsaa_dirty = true;
if (msaa_buffer != 0)
msaa_dirty = true;
}
bool Canvas::checkCreateStencil()
@@ -870,7 +870,7 @@ bool Canvas::checkCreateStencil()
if (current != this)
strategy->bindFBO(fbo);
bool success = strategy->createStencil(width, height, fsaa_samples, depth_stencil);
bool success = strategy->createStencil(width, height, msaa_samples, depth_stencil);
if (current && current != this)
strategy->bindFBO(current->fbo);
@@ -889,9 +889,9 @@ love::image::ImageData *Canvas::getImageData(love::image::Image *image)
GLubyte *pixels = new GLubyte[size];
// Our texture is attached to 'resolve_fbo' when we use MSAA.
if (fsaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object))
if (msaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object))
glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo);
else if (fsaa_samples > 1 && GLEE_EXT_framebuffer_multisample)
else if (msaa_samples > 1 && GLEE_EXT_framebuffer_multisample)
glBindFramebufferEXT(GL_READ_FRAMEBUFFER, resolve_fbo);
else
strategy->bindFBO(fbo);
@@ -913,9 +913,9 @@ void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
resolveMSAA();
// Our texture is attached to 'resolve_fbo' when we use MSAA.
if (fsaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object))
if (msaa_samples > 1 && (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object))
glBindFramebuffer(GL_READ_FRAMEBUFFER, resolve_fbo);
else if (fsaa_samples > 1 && GLEE_EXT_framebuffer_multisample)
else if (msaa_samples > 1 && GLEE_EXT_framebuffer_multisample)
glBindFramebufferEXT(GL_READ_FRAMEBUFFER, resolve_fbo);
else if (current != this)
strategy->bindFBO(fbo);
@@ -930,10 +930,10 @@ void Canvas::getPixel(unsigned char* pixel_rgba, int x, int y)
bool Canvas::resolveMSAA()
{
if (resolve_fbo == 0 || fsaa_buffer == 0)
if (resolve_fbo == 0 || msaa_buffer == 0)
return false;
if (!fsaa_dirty)
if (!msaa_dirty)
return true;
GLuint previous = 0;
@@ -961,7 +961,7 @@ bool Canvas::resolveMSAA()
strategy->bindFBO(previous);
if (current != this)
fsaa_dirty = false;
msaa_dirty = false;
return true;
}
+7 -7
View File
@@ -57,7 +57,7 @@ public:
FORMAT_MAX_ENUM
};
Canvas(int width, int height, Format format = FORMAT_NORMAL, int fsaa = 0);
Canvas(int width, int height, Format format = FORMAT_NORMAL, int msaa = 0);
virtual ~Canvas();
// Implements Volatile.
@@ -108,9 +108,9 @@ public:
return format;
}
inline int getFSAA() const
inline int getMSAA() const
{
return fsaa_samples;
return msaa_samples;
}
bool resolveMSAA();
@@ -133,7 +133,7 @@ public:
private:
bool createFSAAFBO(GLenum internalformat);
bool createMSAAFBO(GLenum internalformat);
static Format getSizedFormat(Format format);
static void convertFormat(Format format, GLenum &internalformat, GLenum &externalformat, GLenum &type);
@@ -142,7 +142,7 @@ private:
GLuint resolve_fbo;
GLuint texture;
GLuint fsaa_buffer;
GLuint msaa_buffer;
GLuint depth_stencil;
Format format;
@@ -151,8 +151,8 @@ private:
std::vector<Canvas *> attachedCanvases;
int fsaa_samples;
bool fsaa_dirty;
int msaa_samples;
bool msaa_dirty;
void setupGrab();
void drawv(const Matrix &t, const Vertex *v);
+3 -3
View File
@@ -497,7 +497,7 @@ ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size)
return new ParticleSystem(texture, size);
}
Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int fsaa)
Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int msaa)
{
if (!Canvas::isFormatSupported(format))
{
@@ -514,7 +514,7 @@ Canvas *Graphics::newCanvas(int width, int height, Canvas::Format format, int fs
while (GL_NO_ERROR != glGetError())
/* clear opengl error flag */;
Canvas *canvas = new Canvas(width, height, format, fsaa);
Canvas *canvas = new Canvas(width, height, format, msaa);
GLenum err = canvas->getStatus();
// everything ok, return canvas (early out)
@@ -1097,7 +1097,7 @@ double Graphics::getSystemLimit(SystemLimit limittype) const
case Graphics::LIMIT_MULTI_CANVAS:
limit = (double) gl.getMaxRenderTargets();
break;
case Graphics::LIMIT_CANVAS_FSAA:
case Graphics::LIMIT_CANVAS_MSAA:
if (GLEE_VERSION_3_0 || GLEE_ARB_framebuffer_object
|| GLEE_EXT_framebuffer_multisample)
{
+1 -1
View File
@@ -206,7 +206,7 @@ public:
ParticleSystem *newParticleSystem(Texture *texture, int size);
Canvas *newCanvas(int width, int height, Canvas::Format format = Canvas::FORMAT_NORMAL, int fsaa = 0);
Canvas *newCanvas(int width, int height, Canvas::Format format = Canvas::FORMAT_NORMAL, int msaa = 0);
Shader *newShader(const Shader::ShaderSources &sources);
@@ -146,12 +146,16 @@ ParticleSystem::ParticleSystem(const ParticleSystem &p)
, offsetX(p.offsetX)
, offsetY(p.offsetY)
, colors(p.colors)
, quads(p.quads)
, relativeRotation(p.relativeRotation)
{
setBufferSize(maxParticles);
if (texture != nullptr)
texture->retain();
for (Quad *quad : quads)
quad->retain();
}
ParticleSystem::~ParticleSystem()
@@ -159,6 +163,9 @@ ParticleSystem::~ParticleSystem()
if (texture != nullptr)
texture->release();
for (Quad *quad : quads)
quad->release();
deleteBuffers();
}
@@ -305,6 +312,8 @@ void ParticleSystem::initParticle(Particle *p, float t)
p->angle += atan2f(p->velocity.y, p->velocity.x);
p->color = colors[0];
p->quadIndex = 0;
}
void ParticleSystem::insertTop(Particle *p)
@@ -721,6 +730,30 @@ std::vector<Color> ParticleSystem::getColor() const
return ncolors;
}
void ParticleSystem::setQuads(const std::vector<Quad *> &newQuads)
{
for (Quad *quad : newQuads)
quad->retain();
for (Quad *quad : quads)
quad->release();
quads = newQuads;
}
void ParticleSystem::setQuads()
{
for (Quad *quad : quads)
quad->release();
quads.clear();
}
const std::vector<Quad *> &ParticleSystem::getQuads() const
{
return quads;
}
void ParticleSystem::setRelativeRotation(bool enable)
{
relativeRotation = enable;
@@ -820,9 +853,14 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo
Vertex *pVerts = particleVerts;
Particle *p = pHead;
bool useQuads = !quads.empty();
// set the vertex data for each particle (transformation, texcoords, color)
while (p)
{
if (useQuads)
textureVerts = quads[p->quadIndex]->getVertices();
// particle vertices are image vertices transformed by particle information
t.setTransformation(p->position[0], p->position[1], p->angle, p->size, p->size, offsetX, offsetY, 0.0f, 0.0f);
t.transform(pVerts, textureVerts, 4);
@@ -948,6 +986,15 @@ void ParticleSystem::update(float dt)
s -= (float)i; // 0 <= s <= 1
p->color = colors[i] * (1.0f - s) + colors[k] * s;
// Update the quad index.
k = quads.size();
if (k > 0)
{
s = t * (float) k; // [0:numquads-1] (clamped below)
i = (s > 0.0f) ? (size_t) s : 0;
p->quadIndex = (i < k) ? i : k - 1;
}
// Next particle.
p = p->next;
}
@@ -27,6 +27,7 @@
#include "common/Vector.h"
#include "graphics/Drawable.h"
#include "graphics/Color.h"
#include "graphics/Quad.h"
#include "Texture.h"
// STL
@@ -421,6 +422,17 @@ public:
**/
std::vector<Color> getColor() const;
/**
* Sets a list of Quads to use for particles over their lifetime.
**/
void setQuads(const std::vector<Quad *> &newQuads);
void setQuads();
/**
* Gets the Quads used when drawing the particles.
**/
const std::vector<Quad *> &getQuads() const;
/**
* sets whether particle angles & rotations are relative to their velocities.
**/
@@ -531,6 +543,8 @@ protected:
float spinEnd;
Colorf color;
int quadIndex;
};
// Pointer to the beginning of the allocated memory.
@@ -625,6 +639,9 @@ protected:
// Color.
std::vector<Colorf> colors;
// Quads.
std::vector<Quad *> quads;
bool relativeRotation;
void createBuffers(size_t size);
+3 -3
View File
@@ -122,10 +122,10 @@ int w_Canvas_getFormat(lua_State *L)
return 1;
}
int w_Canvas_getFSAA(lua_State *L)
int w_Canvas_getMSAA(lua_State *L)
{
Canvas *canvas = luax_checkcanvas(L, 1);
lua_pushinteger(L, canvas->getFSAA());
lua_pushinteger(L, canvas->getMSAA());
return 1;
}
@@ -145,7 +145,7 @@ static const luaL_Reg functions[] =
{ "getPixel", w_Canvas_getPixel },
{ "clear", w_Canvas_clear },
{ "getFormat", w_Canvas_getFormat },
{ "getFSAA", w_Canvas_getFSAA },
{ "getMSAA", w_Canvas_getMSAA },
{ 0, 0 }
};
+1 -1
View File
@@ -40,7 +40,7 @@ int w_Canvas_getImageData(lua_State *L);
int w_Canvas_getPixel(lua_State * L);
int w_Canvas_clear(lua_State *L);
int w_Canvas_getFormat(lua_State *L);
int w_Canvas_getFSAA(lua_State *L);
int w_Canvas_getMSAA(lua_State *L);
extern "C" int luaopen_canvas(lua_State *L);
} // opengl
@@ -351,7 +351,7 @@ int w_newCanvas(lua_State *L)
int width = luaL_optint(L, 1, instance->getWidth());
int height = luaL_optint(L, 2, instance->getHeight());
const char *str = luaL_optstring(L, 3, "normal");
int fsaa = luaL_optint(L, 4, 0);
int msaa = luaL_optint(L, 4, 0);
Canvas::Format format;
if (!Canvas::getConstant(str, format))
@@ -359,7 +359,7 @@ int w_newCanvas(lua_State *L)
Canvas *canvas = nullptr;
luax_catchexcept(L,
[&](){ canvas = instance->newCanvas(width, height, format, fsaa); }
[&](){ canvas = instance->newCanvas(width, height, format, msaa); }
);
if (canvas == nullptr)
@@ -569,6 +569,53 @@ int w_ParticleSystem_getColors(lua_State *L)
return colors.size();
}
int w_ParticleSystem_setQuads(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
std::vector<Quad *> quads;
if (lua_istable(L, 2))
{
for (size_t i = 1; i <= lua_objlen(L, 2); i++)
{
lua_rawgeti(L, 2, i);
Quad *q = luax_checktype<Quad>(L, -1, "Quad", GRAPHICS_QUAD_T);
quads.push_back(q);
lua_pop(L, 1);
}
}
else
{
for (int i = 2; i <= lua_gettop(L); i++)
{
Quad *q = luax_checktype<Quad>(L, i, "Quad", GRAPHICS_QUAD_T);
quads.push_back(q);
}
}
t->setQuads(quads);
return 0;
}
int w_ParticleSystem_getQuads(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
const std::vector<Quad *> quads = t->getQuads();
lua_createtable(L, (int) quads.size(), 0);
for (size_t i = 0; i < quads.size(); i++)
{
quads[i]->retain();
luax_pushtype(L, "Quad", GRAPHICS_QUAD_T, quads[i]);
lua_rawseti(L, -2, i + 1);
}
return 1;
}
int w_ParticleSystem_setRelativeRotation(lua_State *L)
{
ParticleSystem *t = luax_checkparticlesystem(L, 1);
@@ -699,6 +746,8 @@ static const luaL_Reg functions[] =
{ "getSpinVariation", w_ParticleSystem_getSpinVariation },
{ "setColors", w_ParticleSystem_setColors },
{ "getColors", w_ParticleSystem_getColors },
{ "setQuads", w_ParticleSystem_setQuads },
{ "getQuads", w_ParticleSystem_getQuads },
{ "setOffset", w_ParticleSystem_setOffset },
{ "getOffset", w_ParticleSystem_getOffset },
{ "setRelativeRotation", w_ParticleSystem_setRelativeRotation },
@@ -75,6 +75,8 @@ int w_ParticleSystem_setSpinVariation(lua_State *L);
int w_ParticleSystem_getSpinVariation(lua_State *L);
int w_ParticleSystem_setColors(lua_State *L);
int w_ParticleSystem_getColors(lua_State *L);
int w_ParticleSystem_setQuads(lua_State *L);
int w_ParticleSystem_getQuads(lua_State *L);
int w_ParticleSystem_setOffset(lua_State *L);
int w_ParticleSystem_getOffset(lua_State *L);
int w_ParticleSystem_setRelativeRotation(lua_State *L);