From f87738edb52ecb6d23e1905e066dfa86fe6260bf Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Tue, 10 Aug 2010 19:05:56 +0200 Subject: [PATCH 01/20] Added first review of vrld's FBO patch --- src/common/types.h | 2 + src/modules/graphics/opengl/Fbo.cpp | 103 ++++++++++++++++++ src/modules/graphics/opengl/Fbo.h | 46 ++++++++ src/modules/graphics/opengl/Graphics.cpp | 7 +- src/modules/graphics/opengl/Graphics.h | 53 ++++----- src/modules/graphics/opengl/wrap_Fbo.cpp | 58 ++++++++++ src/modules/graphics/opengl/wrap_Fbo.h | 25 +++++ src/modules/graphics/opengl/wrap_Graphics.cpp | 21 +++- src/modules/graphics/opengl/wrap_Graphics.h | 8 +- 9 files changed, 292 insertions(+), 31 deletions(-) create mode 100644 src/modules/graphics/opengl/Fbo.cpp create mode 100644 src/modules/graphics/opengl/Fbo.h create mode 100644 src/modules/graphics/opengl/wrap_Fbo.cpp create mode 100644 src/modules/graphics/opengl/wrap_Fbo.h diff --git a/src/common/types.h b/src/common/types.h index 063135094..ecbe1a773 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -52,6 +52,7 @@ namespace love GRAPHICS_PARTICLE_SYSTEM_ID, GRAPHICS_SPRITE_BATCH_ID, GRAPHICS_VERTEX_BUFFER_ID, + GRAPHICS_FBO_ID, // Image IMAGE_IMAGE_DATA_ID, @@ -116,6 +117,7 @@ namespace love const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_VERTEX_BUFFER_T = (bits(1) << GRAPHICS_VERTEX_BUFFER_ID) | GRAPHICS_DRAWABLE_T; + const bits GRAPHICS_FBO_T = (bits(1) << GRAPHICS_FBO_ID) | GRAPHICS_DRAWABLE_T; // Image. const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T; diff --git a/src/modules/graphics/opengl/Fbo.cpp b/src/modules/graphics/opengl/Fbo.cpp new file mode 100644 index 000000000..5ec3a4ce6 --- /dev/null +++ b/src/modules/graphics/opengl/Fbo.cpp @@ -0,0 +1,103 @@ +#include "Fbo.h" +#include + +namespace love +{ +namespace graphics +{ +namespace opengl +{ + + Fbo::Fbo(int width, int height) : + width(width), height(height) + { + // world coordinates + vertices[0].x = 0; vertices[0].y = 0; + vertices[1].x = 0; vertices[1].y = height; + vertices[2].x = width; vertices[2].y = height; + vertices[3].x = width; vertices[3].y = 0; + + // texture coordinates + vertices[0].s = 0; vertices[0].t = 1; + vertices[1].s = 0; vertices[1].t = 0; + vertices[2].s = 1; vertices[2].t = 0; + vertices[3].s = 1; vertices[3].t = 1; + + // generate depth buffer + glGenRenderbuffers(1, &depthbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + + // generate texture save target + glGenTextures(1, &img); + glBindTexture(GL_TEXTURE_2D, img); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + + // create framebuffer + glGenFramebuffers(1, &fbo); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, img, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, depthbuffer); + status_ = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + // unbind buffers and texture + glBindFramebuffer(GL_FRAMEBUFFER, 0); + } + + Fbo::~Fbo() + { + glDeleteTextures(1, &fbo); + glDeleteRenderbuffers(1, &depthbuffer); + glDeleteFramebuffers(1, &img); + } + + GLenum Fbo::status() const + { + return status_; + } + + void Fbo::bind() + { + glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glViewport(0, 0, width, height); + } + + void Fbo::unbind() + { + glBindFramebuffer(GL_FRAMEBUFFER, 0); + glPopAttrib(); + } + + void Fbo::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const + { + static Matrix t; + t.setTransformation(x, y, angle, sx, sy, ox, oy); + + glPushMatrix(); + glMultMatrixf((const GLfloat*)t.getElements()); + + glBindTexture(GL_TEXTURE_2D, img); + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + glVertexPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].x); + glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), (GLvoid*)&vertices[0].s); + glDrawArrays(GL_QUADS, 0, 4); + glDisableClientState(GL_TEXTURE_COORD_ARRAY); + glDisableClientState(GL_VERTEX_ARRAY); + + glPopMatrix(); + } + +} // opengl +} // graphics +} // love diff --git a/src/modules/graphics/opengl/Fbo.h b/src/modules/graphics/opengl/Fbo.h new file mode 100644 index 000000000..0fa6a9900 --- /dev/null +++ b/src/modules/graphics/opengl/Fbo.h @@ -0,0 +1,46 @@ +#ifndef LOVE_GRAPHICS_FBO_H +#define LOVE_GRAPHICS_FBO_H + +#include +#include +#include +#include "GLee.h" + +namespace love +{ +namespace graphics +{ +namespace opengl +{ + + class Fbo : public Drawable // Fbo vs. FBO? + { + public: + Fbo(int width, int height); + virtual ~Fbo(); + + GLenum status() const; //SERIOUS DISLIKE HERE + + void bind(); //DOUBTFUL ABOUT NAME + void unbind(); //Maybe start/stop? + //And what about clearing, clear() isn't entirely what I want either + //maybe make bind/start autoclear? + + virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; + + private: + GLsizei width; + GLsizei height; + GLuint fbo; + GLuint depthbuffer; + GLuint img; + GLenum status_; + + vertex vertices[4]; + }; + +} // opengl +} // graphics +} // love + +#endif // LOVE_GRAPHICS_FBO_H diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 4a958a7f1..b8216a2fa 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -306,7 +306,7 @@ namespace opengl { SDL_GL_SwapBuffers(); } - + void Graphics::setIcon(Image * image) { Uint32 rmask, gmask, bmask, amask; @@ -470,6 +470,11 @@ namespace opengl return new ParticleSystem(image, size); } + Fbo * Graphics::newFbo(int width, int height) + { + return new Fbo(width, height); + } + void Graphics::setColor(Color c) { glColor4ubv(&c.r); diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 2eaeb80fd..04163475e 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 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 @@ -43,6 +43,7 @@ #include "Quad.h" #include "SpriteBatch.h" #include "ParticleSystem.h" +#include "Fbo.h" namespace love { @@ -95,13 +96,13 @@ namespace opengl // Default values. DisplayState() { - color.r = 255; - color.g = 255; - color.b = 255; + color.r = 255; + color.g = 255; + color.b = 255; color.a = 255; - backgroundColor.r = 0; - backgroundColor.g = 0; - backgroundColor.b = 0; + backgroundColor.r = 0; + backgroundColor.g = 0; + backgroundColor.b = 0; backgroundColor.a = 255; blendMode = Graphics::BLEND_ALPHA; colorMode = Graphics::COLOR_MODULATE; @@ -126,7 +127,7 @@ namespace opengl Graphics(); virtual ~Graphics(); - + // Implements Module. const char * getName() const; @@ -165,18 +166,18 @@ namespace opengl * when the game reloads. **/ void reset(); - + /** * Clears the screen. **/ void clear(); /** - * Flips buffers. (Rendered geometry is + * Flips buffers. (Rendered geometry is * presented on screen). **/ void present(); - + /** * Sets the window's icon. **/ @@ -207,13 +208,13 @@ namespace opengl /** * This native Lua function gets available modes * from SDL and returns them as a table on the following format: - * - * { - * { width = 800, height = 600 }, + * + * { + * { width = 800, height = 600 }, * { width = 1024, height = 768 }, * ... * } - * + * * Only fullscreen modes are returned here, as all * window sizes are supported (normally). **/ @@ -245,7 +246,7 @@ namespace opengl **/ Image * newImage(love::filesystem::File * file); Image * newImage(love::image::ImageData * data); - + /** * Creates a Frame **/ @@ -255,11 +256,13 @@ namespace opengl * Creates a Font object. **/ Font * newFont(love::font::FontData * data); - + SpriteBatch * newSpriteBatch(Image * image, int size, int usage); ParticleSystem * newParticleSystem(Image * image, int size); - + + Fbo * newFbo(int width, int height); + /** * Sets the foreground color. **/ @@ -271,7 +274,7 @@ namespace opengl Color getColor(); /** - * Sets the background Color. + * Sets the background Color. **/ void setBackgroundColor(Color c); @@ -383,7 +386,7 @@ namespace opengl PointStyle getPointStyle(); /** - * Gets the maximum point size supported. + * Gets the maximum point size supported. * This may vary from computer to computer. **/ int getMaxPointSize(); @@ -406,7 +409,7 @@ namespace opengl void print(const char * str, float x, float y , float angle); /** - * Draws text at the specified coordinates, with rotation and + * Draws text at the specified coordinates, with rotation and * scaling. * @param x The x-coordinate. * @param y The y-coordinate. @@ -416,7 +419,7 @@ namespace opengl void print(const char * str, float x, float y , float angle, float s); /** - * Draws text at the specified coordinates, with rotation and + * Draws text at the specified coordinates, with rotation and * scaling along both axes. * @param x The x-coordinate. * @param y The y-coordinate. @@ -452,7 +455,7 @@ namespace opengl * @param y2 Second y-coordinate. **/ void line(float x1, float y1, float x2, float y2); - + /** * Draws a series of lines connecting the given vertices. * @param ... Vertex components (x1, y1, x2, y2, etc.) diff --git a/src/modules/graphics/opengl/wrap_Fbo.cpp b/src/modules/graphics/opengl/wrap_Fbo.cpp new file mode 100644 index 000000000..3af9e6be9 --- /dev/null +++ b/src/modules/graphics/opengl/wrap_Fbo.cpp @@ -0,0 +1,58 @@ +#include "wrap_Fbo.h" + +namespace love +{ +namespace graphics +{ +namespace opengl +{ + Fbo * luax_checkfbo(lua_State * L, int idx) + { + return luax_checktype(L, idx, "Fbo", GRAPHICS_FBO_T); + } + + int w_Fbo_render(lua_State * L) + { + Fbo * fbo = luax_checkfbo(L, 1); + if (!lua_isfunction(L, 2)) + return luaL_error(L, "Need a function to render to fbo"); + + fbo->bind(); + + lua_settop(L, 2); // make sure the function is on top of the stack + lua_pcall(L, 0, 0, 0); + + fbo->unbind(); + + return 0; + } + + int w_Fbo_bind(lua_State * L) + { + Fbo * fbo = luax_checkfbo(L, 1); + fbo->bind(); + return 0; + } + + int w_Fbo_unbind(lua_State * L) + { + Fbo * fbo = luax_checkfbo(L, 1); + fbo->unbind(); + return 0; + } + + static const luaL_Reg functions[] = { + { "render", w_Fbo_render }, + { "bind", w_Fbo_bind }, + { "unbind", w_Fbo_unbind }, + { 0, 0 } + }; + + int luaopen_fbo(lua_State * L) + { + return luax_register_type(L, "Fbo", functions); + } + +} // opengl +} // graphics +} // love diff --git a/src/modules/graphics/opengl/wrap_Fbo.h b/src/modules/graphics/opengl/wrap_Fbo.h new file mode 100644 index 000000000..03454a74e --- /dev/null +++ b/src/modules/graphics/opengl/wrap_Fbo.h @@ -0,0 +1,25 @@ +#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FBO_H +#define LOVE_GRAPHICS_OPENGL_WRAP_FBO_H + +// LOVE +#include +#include "Fbo.h" + +namespace love +{ +namespace graphics +{ +namespace opengl +{ + //see Fbo.h + Fbo * luax_checkfbo(lua_State * L, int idx); + int w_Fbo_render(lua_State * L); + int w_Fbo_bind(lua_State * L); + int w_Fbo_unbind(lua_State * L); + int luaopen_fbo(lua_State * L); + +} // opengl +} // graphics +} // love + +#endif // LOVE_GRAPHICS_OPENGL_WRAP_FBO_H diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 8b146f04b..f6b198f1d 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -84,7 +84,7 @@ namespace opengl instance->setIcon(image); return 0; } - + int w_setCaption(lua_State * L) { const char * str = luaL_checkstring(L, 1); @@ -292,6 +292,21 @@ namespace opengl return 1; } + int w_newFbo(lua_State * L) + { + int width, height; + width = luaL_checkint(L, 1); + height = luaL_checkint(L, 2); + Fbo * fbo = instance->newFbo(width, height); + + //and there we go with the status... still disliked + GLenum status = fbo->status(); + if (status != GL_FRAMEBUFFER_COMPLETE_EXT) + return luaL_error(L, "Cannot create FBO: %d", status); + luax_newtype(L, "Fbo", GRAPHICS_FBO_T, (void*)fbo); + return 1; + } + int w_setColor(lua_State * L) { Color c; @@ -829,6 +844,7 @@ namespace opengl { "newImageFont", w_newImageFont }, { "newSpriteBatch", w_newSpriteBatch }, { "newParticleSystem", w_newParticleSystem }, + { "newFbo", w_newFbo }, { "setColor", w_setColor }, { "getColor", w_getColor }, @@ -866,7 +882,7 @@ namespace opengl { "setCaption", w_setCaption }, { "getCaption", w_getCaption }, - + { "setIcon", w_setIcon }, { "getWidth", w_getWidth }, @@ -906,6 +922,7 @@ namespace opengl luaopen_frame, luaopen_spritebatch, luaopen_particlesystem, + luaopen_fbo, 0 }; diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 2ad3a95f7..5dc7c6e47 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -1,14 +1,14 @@ /** * Copyright (c) 2006-2010 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 @@ -28,6 +28,7 @@ #include "wrap_Quad.h" #include "wrap_SpriteBatch.h" #include "wrap_ParticleSystem.h" +#include "wrap_Fbo.h" #include "Graphics.h" namespace love @@ -58,6 +59,7 @@ namespace opengl int w_newImageFont(lua_State * L); int w_newSpriteBatch(lua_State * L); int w_newParticleSystem(lua_State * L); + int w_newFbo(lua_State * L); // commetns in function int w_setColor(lua_State * L); int w_getColor(lua_State * L); int w_setBackgroundColor(lua_State * L); From e5c2f063e89741a5e8f0c11ddfec008e12bec808 Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Wed, 11 Aug 2010 20:29:47 +0200 Subject: [PATCH 02/20] Add human readable error strings when creating the Fbo failed --- src/modules/graphics/opengl/Fbo.cpp | 30 +++++++++++++++++-- src/modules/graphics/opengl/Fbo.h | 7 ++++- src/modules/graphics/opengl/wrap_Graphics.cpp | 5 ++-- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/modules/graphics/opengl/Fbo.cpp b/src/modules/graphics/opengl/Fbo.cpp index 5ec3a4ce6..82ab67c1a 100644 --- a/src/modules/graphics/opengl/Fbo.cpp +++ b/src/modules/graphics/opengl/Fbo.cpp @@ -8,9 +8,35 @@ namespace graphics namespace opengl { + std::map Fbo::status_to_string; + Fbo::Fbo(int width, int height) : width(width), height(height) { + // maybe create status code messages + if (status_to_string.empty()) { + status_to_string[GL_FRAMEBUFFER_UNSUPPORTED] // the most important one + = "your opengl implementation does not support framebuffer objects"; + + status_to_string[GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT] + = "framebuffer has incomplete attachments"; + status_to_string[GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER] + = "incomplete draw buffer"; + + // the ones that should never, ever happen: + status_to_string[GL_FRAMEBUFFER_UNDEFINED] + = "default framebuffer does not exist"; + status_to_string[GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT] + = "framebuffer needs at least one image attached"; + status_to_string[GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER] + = "incomplete read buffer"; + status_to_string[GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE] + = "number of samples mismatch in attached buffers"; + // "Additionally, if an error occurs, zero is returned." and + // "GL_INVALID_ENUM is generated if target is not GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER or GL_FRAMEBUFFER." + status_to_string[0] = "Framebuffer hijacked by aliens"; + } + // world coordinates vertices[0].x = 0; vertices[0].y = 0; vertices[1].x = 0; vertices[1].y = height; @@ -58,9 +84,9 @@ namespace opengl glDeleteFramebuffers(1, &img); } - GLenum Fbo::status() const + const char* Fbo::statusMessage() const { - return status_; + status_to_string[statusCode()]; } void Fbo::bind() diff --git a/src/modules/graphics/opengl/Fbo.h b/src/modules/graphics/opengl/Fbo.h index 0fa6a9900..1f93242f5 100644 --- a/src/modules/graphics/opengl/Fbo.h +++ b/src/modules/graphics/opengl/Fbo.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "GLee.h" namespace love @@ -19,7 +20,9 @@ namespace opengl Fbo(int width, int height); virtual ~Fbo(); - GLenum status() const; //SERIOUS DISLIKE HERE + // for internal use (w_newFbo <-> love.graphics.newFbo) only + GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE + const char* statusMessage() const; void bind(); //DOUBTFUL ABOUT NAME void unbind(); //Maybe start/stop? @@ -37,6 +40,8 @@ namespace opengl GLenum status_; vertex vertices[4]; + + static std::map status_to_string; }; } // opengl diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index f6b198f1d..340562996 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -300,9 +300,8 @@ namespace opengl Fbo * fbo = instance->newFbo(width, height); //and there we go with the status... still disliked - GLenum status = fbo->status(); - if (status != GL_FRAMEBUFFER_COMPLETE_EXT) - return luaL_error(L, "Cannot create FBO: %d", status); + if (fbo->statusCode() != GL_FRAMEBUFFER_COMPLETE_EXT) + return luaL_error(L, "Cannot create FBO: %s", fbo->statusMessage()); luax_newtype(L, "Fbo", GRAPHICS_FBO_T, (void*)fbo); return 1; } From b734a39f4dcb33315a7b4a705731ef0f089fbbea Mon Sep 17 00:00:00 2001 From: Matthias Richter Date: Wed, 11 Aug 2010 21:10:31 +0200 Subject: [PATCH 03/20] Add color clearing on Fb::bind() (see love issue #17, comment #5) --- src/modules/graphics/opengl/Fbo.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/graphics/opengl/Fbo.cpp b/src/modules/graphics/opengl/Fbo.cpp index 82ab67c1a..4164289ad 100644 --- a/src/modules/graphics/opengl/Fbo.cpp +++ b/src/modules/graphics/opengl/Fbo.cpp @@ -94,6 +94,7 @@ namespace opengl glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClearColor(.0f, .0f, .0f, .0f); glViewport(0, 0, width, height); } From 9d35792fe5aa7394c68be7d9589bf929aa2ca036 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 13 Aug 2010 13:33:13 +0200 Subject: [PATCH 04/20] Did the name change --- src/common/types.h | 4 ++-- src/modules/graphics/opengl/Graphics.cpp | 4 ++-- src/modules/graphics/opengl/Graphics.h | 4 ++-- src/modules/graphics/opengl/wrap_Graphics.cpp | 14 +++++++------- src/modules/graphics/opengl/wrap_Graphics.h | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/common/types.h b/src/common/types.h index ecbe1a773..08ea9b7c7 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -52,7 +52,7 @@ namespace love GRAPHICS_PARTICLE_SYSTEM_ID, GRAPHICS_SPRITE_BATCH_ID, GRAPHICS_VERTEX_BUFFER_ID, - GRAPHICS_FBO_ID, + GRAPHICS_FRAMEBUFFER_ID, // Image IMAGE_IMAGE_DATA_ID, @@ -117,7 +117,7 @@ namespace love const bits GRAPHICS_PARTICLE_SYSTEM_T = (bits(1) << GRAPHICS_PARTICLE_SYSTEM_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_SPRITE_BATCH_T = (bits(1) << GRAPHICS_SPRITE_BATCH_ID) | GRAPHICS_DRAWABLE_T; const bits GRAPHICS_VERTEX_BUFFER_T = (bits(1) << GRAPHICS_VERTEX_BUFFER_ID) | GRAPHICS_DRAWABLE_T; - const bits GRAPHICS_FBO_T = (bits(1) << GRAPHICS_FBO_ID) | GRAPHICS_DRAWABLE_T; + const bits GRAPHICS_FRAMEBUFFER_T = (bits(1) << GRAPHICS_FRAMEBUFFER_ID) | GRAPHICS_DRAWABLE_T; // Image. const bits IMAGE_IMAGE_DATA_T = (bits(1) << IMAGE_IMAGE_DATA_ID) | DATA_T; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index b8216a2fa..83390d437 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -470,9 +470,9 @@ namespace opengl return new ParticleSystem(image, size); } - Fbo * Graphics::newFbo(int width, int height) + Framebuffer * Graphics::newFramebuffer(int width, int height) { - return new Fbo(width, height); + return new Framebuffer(width, height); } void Graphics::setColor(Color c) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 04163475e..1fc653abc 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -43,7 +43,7 @@ #include "Quad.h" #include "SpriteBatch.h" #include "ParticleSystem.h" -#include "Fbo.h" +#include "Framebuffer.h" namespace love { @@ -261,7 +261,7 @@ namespace opengl ParticleSystem * newParticleSystem(Image * image, int size); - Fbo * newFbo(int width, int height); + Framebuffer * newFramebuffer(int width, int height); /** * Sets the foreground color. diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 340562996..e67684492 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -292,17 +292,17 @@ namespace opengl return 1; } - int w_newFbo(lua_State * L) + int w_newFramebuffer(lua_State * L) { int width, height; width = luaL_checkint(L, 1); height = luaL_checkint(L, 2); - Fbo * fbo = instance->newFbo(width, height); + Framebuffer * Framebuffer = instance->newFramebuffer(width, height); //and there we go with the status... still disliked - if (fbo->statusCode() != GL_FRAMEBUFFER_COMPLETE_EXT) - return luaL_error(L, "Cannot create FBO: %s", fbo->statusMessage()); - luax_newtype(L, "Fbo", GRAPHICS_FBO_T, (void*)fbo); + if (Framebuffer->statusCode() != GL_FRAMEBUFFER_COMPLETE_EXT) + return luaL_error(L, "Cannot create Framebuffer: %s", Framebuffer->statusMessage()); + luax_newtype(L, "Framebuffer", GRAPHICS_FRAMEBUFFER_T, (void*)Framebuffer); return 1; } @@ -843,7 +843,7 @@ namespace opengl { "newImageFont", w_newImageFont }, { "newSpriteBatch", w_newSpriteBatch }, { "newParticleSystem", w_newParticleSystem }, - { "newFbo", w_newFbo }, + { "newFramebuffer", w_newFramebuffer }, { "setColor", w_setColor }, { "getColor", w_getColor }, @@ -921,7 +921,7 @@ namespace opengl luaopen_frame, luaopen_spritebatch, luaopen_particlesystem, - luaopen_fbo, + luaopen_framebuffer, 0 }; diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index 5dc7c6e47..d7d51ec89 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -28,7 +28,7 @@ #include "wrap_Quad.h" #include "wrap_SpriteBatch.h" #include "wrap_ParticleSystem.h" -#include "wrap_Fbo.h" +#include "wrap_Framebuffer.h" #include "Graphics.h" namespace love @@ -59,7 +59,7 @@ namespace opengl int w_newImageFont(lua_State * L); int w_newSpriteBatch(lua_State * L); int w_newParticleSystem(lua_State * L); - int w_newFbo(lua_State * L); // commetns in function + int w_newFramebuffer(lua_State * L); // commetns in function int w_setColor(lua_State * L); int w_getColor(lua_State * L); int w_setBackgroundColor(lua_State * L); From 6400273a73faff1194d2c3714117eeb0f3849e05 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 13 Aug 2010 13:35:42 +0200 Subject: [PATCH 05/20] File moves --- .../opengl/{Fbo.cpp => Framebuffer.cpp} | 16 ++--- .../graphics/opengl/{Fbo.h => Framebuffer.h} | 14 ++--- src/modules/graphics/opengl/wrap_Fbo.cpp | 58 ------------------- src/modules/graphics/opengl/wrap_Fbo.h | 25 -------- .../graphics/opengl/wrap_Framebuffer.cpp | 58 +++++++++++++++++++ .../graphics/opengl/wrap_Framebuffer.h | 25 ++++++++ 6 files changed, 98 insertions(+), 98 deletions(-) rename src/modules/graphics/opengl/{Fbo.cpp => Framebuffer.cpp} (91%) rename src/modules/graphics/opengl/{Fbo.h => Framebuffer.h} (73%) delete mode 100644 src/modules/graphics/opengl/wrap_Fbo.cpp delete mode 100644 src/modules/graphics/opengl/wrap_Fbo.h create mode 100644 src/modules/graphics/opengl/wrap_Framebuffer.cpp create mode 100644 src/modules/graphics/opengl/wrap_Framebuffer.h diff --git a/src/modules/graphics/opengl/Fbo.cpp b/src/modules/graphics/opengl/Framebuffer.cpp similarity index 91% rename from src/modules/graphics/opengl/Fbo.cpp rename to src/modules/graphics/opengl/Framebuffer.cpp index 4164289ad..1e5a76401 100644 --- a/src/modules/graphics/opengl/Fbo.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -1,4 +1,4 @@ -#include "Fbo.h" +#include "Framebuffer.h" #include namespace love @@ -8,9 +8,9 @@ namespace graphics namespace opengl { - std::map Fbo::status_to_string; + std::map Framebuffer::status_to_string; - Fbo::Fbo(int width, int height) : + Framebuffer::Framebuffer(int width, int height) : width(width), height(height) { // maybe create status code messages @@ -77,19 +77,19 @@ namespace opengl glBindFramebuffer(GL_FRAMEBUFFER, 0); } - Fbo::~Fbo() + Framebuffer::~Framebuffer() { glDeleteTextures(1, &fbo); glDeleteRenderbuffers(1, &depthbuffer); glDeleteFramebuffers(1, &img); } - const char* Fbo::statusMessage() const + const char* Framebuffer::statusMessage() const { status_to_string[statusCode()]; } - void Fbo::bind() + void Framebuffer::bind() { glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -98,13 +98,13 @@ namespace opengl glViewport(0, 0, width, height); } - void Fbo::unbind() + void Framebuffer::unbind() { glBindFramebuffer(GL_FRAMEBUFFER, 0); glPopAttrib(); } - void Fbo::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const + void Framebuffer::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const { static Matrix t; t.setTransformation(x, y, angle, sx, sy, ox, oy); diff --git a/src/modules/graphics/opengl/Fbo.h b/src/modules/graphics/opengl/Framebuffer.h similarity index 73% rename from src/modules/graphics/opengl/Fbo.h rename to src/modules/graphics/opengl/Framebuffer.h index 1f93242f5..53a9a5bc2 100644 --- a/src/modules/graphics/opengl/Fbo.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -1,5 +1,5 @@ -#ifndef LOVE_GRAPHICS_FBO_H -#define LOVE_GRAPHICS_FBO_H +#ifndef LOVE_GRAPHICS_FRAMEBUFFER_H +#define LOVE_GRAPHICS_FRAMEBUFFER_H #include #include @@ -14,13 +14,13 @@ namespace graphics namespace opengl { - class Fbo : public Drawable // Fbo vs. FBO? + class Framebuffer : public Drawable { public: - Fbo(int width, int height); - virtual ~Fbo(); + Framebuffer(int width, int height); + virtual ~Framebuffer(); - // for internal use (w_newFbo <-> love.graphics.newFbo) only + // for internal use (w_newFramebuffer <-> love.graphics.newFramebuffer) only GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE const char* statusMessage() const; @@ -48,4 +48,4 @@ namespace opengl } // graphics } // love -#endif // LOVE_GRAPHICS_FBO_H +#endif // LOVE_GRAPHICS_FRAMEBUFFER_H diff --git a/src/modules/graphics/opengl/wrap_Fbo.cpp b/src/modules/graphics/opengl/wrap_Fbo.cpp deleted file mode 100644 index 3af9e6be9..000000000 --- a/src/modules/graphics/opengl/wrap_Fbo.cpp +++ /dev/null @@ -1,58 +0,0 @@ -#include "wrap_Fbo.h" - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - Fbo * luax_checkfbo(lua_State * L, int idx) - { - return luax_checktype(L, idx, "Fbo", GRAPHICS_FBO_T); - } - - int w_Fbo_render(lua_State * L) - { - Fbo * fbo = luax_checkfbo(L, 1); - if (!lua_isfunction(L, 2)) - return luaL_error(L, "Need a function to render to fbo"); - - fbo->bind(); - - lua_settop(L, 2); // make sure the function is on top of the stack - lua_pcall(L, 0, 0, 0); - - fbo->unbind(); - - return 0; - } - - int w_Fbo_bind(lua_State * L) - { - Fbo * fbo = luax_checkfbo(L, 1); - fbo->bind(); - return 0; - } - - int w_Fbo_unbind(lua_State * L) - { - Fbo * fbo = luax_checkfbo(L, 1); - fbo->unbind(); - return 0; - } - - static const luaL_Reg functions[] = { - { "render", w_Fbo_render }, - { "bind", w_Fbo_bind }, - { "unbind", w_Fbo_unbind }, - { 0, 0 } - }; - - int luaopen_fbo(lua_State * L) - { - return luax_register_type(L, "Fbo", functions); - } - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/wrap_Fbo.h b/src/modules/graphics/opengl/wrap_Fbo.h deleted file mode 100644 index 03454a74e..000000000 --- a/src/modules/graphics/opengl/wrap_Fbo.h +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FBO_H -#define LOVE_GRAPHICS_OPENGL_WRAP_FBO_H - -// LOVE -#include -#include "Fbo.h" - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - //see Fbo.h - Fbo * luax_checkfbo(lua_State * L, int idx); - int w_Fbo_render(lua_State * L); - int w_Fbo_bind(lua_State * L); - int w_Fbo_unbind(lua_State * L); - int luaopen_fbo(lua_State * L); - -} // opengl -} // graphics -} // love - -#endif // LOVE_GRAPHICS_OPENGL_WRAP_FBO_H diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.cpp b/src/modules/graphics/opengl/wrap_Framebuffer.cpp new file mode 100644 index 000000000..d8c44a384 --- /dev/null +++ b/src/modules/graphics/opengl/wrap_Framebuffer.cpp @@ -0,0 +1,58 @@ +#include "wrap_Framebuffer.h" + +namespace love +{ +namespace graphics +{ +namespace opengl +{ + Framebuffer * luax_checkfbo(lua_State * L, int idx) + { + return luax_checktype(L, idx, "Framebuffer", GRAPHICS_FRAMEBUFFER_T); + } + + int w_Framebuffer_render(lua_State * L) + { + Framebuffer * fbo = luax_checkfbo(L, 1); + if (!lua_isfunction(L, 2)) + return luaL_error(L, "Need a function to render to fbo"); + + fbo->bind(); + + lua_settop(L, 2); // make sure the function is on top of the stack + lua_pcall(L, 0, 0, 0); + + fbo->unbind(); + + return 0; + } + + int w_Framebuffer_bind(lua_State * L) + { + Framebuffer * fbo = luax_checkfbo(L, 1); + fbo->bind(); + return 0; + } + + int w_Framebuffer_unbind(lua_State * L) + { + Framebuffer * fbo = luax_checkfbo(L, 1); + fbo->unbind(); + return 0; + } + + static const luaL_Reg functions[] = { + { "render", w_Framebuffer_render }, + { "bind", w_Framebuffer_bind }, + { "unbind", w_Framebuffer_unbind }, + { 0, 0 } + }; + + int luaopen_framebuffer(lua_State * L) + { + return luax_register_type(L, "Framebuffer", functions); + } + +} // opengl +} // graphics +} // love diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.h b/src/modules/graphics/opengl/wrap_Framebuffer.h new file mode 100644 index 000000000..0bdf9964f --- /dev/null +++ b/src/modules/graphics/opengl/wrap_Framebuffer.h @@ -0,0 +1,25 @@ +#ifndef LOVE_GRAPHICS_OPENGL_WRAP_FBO_H +#define LOVE_GRAPHICS_OPENGL_WRAP_FBO_H + +// LOVE +#include +#include "Framebuffer.h" + +namespace love +{ +namespace graphics +{ +namespace opengl +{ + //see Framebuffer.h + Framebuffer * luax_checkfbo(lua_State * L, int idx); + int w_Framebuffer_render(lua_State * L); + int w_Framebuffer_bind(lua_State * L); + int w_Framebuffer_unbind(lua_State * L); + int luaopen_framebuffer(lua_State * L); + +} // opengl +} // graphics +} // love + +#endif // LOVE_GRAPHICS_OPENGL_WRAP_FBO_H From 35093a5c4568b8a46aa333e5f7ecf3294bd5a3b6 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 13 Aug 2010 18:50:00 +0200 Subject: [PATCH 06/20] Change bind/unbind to grab/stop --- .hgignore | 4 ++++ src/modules/graphics/opengl/Framebuffer.cpp | 4 ++-- src/modules/graphics/opengl/Framebuffer.h | 6 ++---- src/modules/graphics/opengl/wrap_Framebuffer.cpp | 16 ++++++++-------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.hgignore b/.hgignore index 5869abae8..12c3162a3 100644 --- a/.hgignore +++ b/.hgignore @@ -7,6 +7,10 @@ glob:extra/reshax/Debug/ glob:extra/reshax/resources.h glob:extra/reshax/resources.cpp glob:*.obj +glob:*.o +glob:*.dirstamp +glob:*.m4 +glob:*.Po glob:*.dll glob:*.user glob:*.suo diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 1e5a76401..e2adb865d 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -89,7 +89,7 @@ namespace opengl status_to_string[statusCode()]; } - void Framebuffer::bind() + void Framebuffer::grab() { glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, fbo); @@ -98,7 +98,7 @@ namespace opengl glViewport(0, 0, width, height); } - void Framebuffer::unbind() + void Framebuffer::stop() { glBindFramebuffer(GL_FRAMEBUFFER, 0); glPopAttrib(); diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index 53a9a5bc2..8b134dd5f 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -24,10 +24,8 @@ namespace opengl GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE const char* statusMessage() const; - void bind(); //DOUBTFUL ABOUT NAME - void unbind(); //Maybe start/stop? - //And what about clearing, clear() isn't entirely what I want either - //maybe make bind/start autoclear? + void grab(); + void stop(); virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.cpp b/src/modules/graphics/opengl/wrap_Framebuffer.cpp index d8c44a384..4dd669428 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.cpp +++ b/src/modules/graphics/opengl/wrap_Framebuffer.cpp @@ -17,34 +17,34 @@ namespace opengl if (!lua_isfunction(L, 2)) return luaL_error(L, "Need a function to render to fbo"); - fbo->bind(); + fbo->grab(); lua_settop(L, 2); // make sure the function is on top of the stack lua_pcall(L, 0, 0, 0); - fbo->unbind(); + fbo->stop(); return 0; } - int w_Framebuffer_bind(lua_State * L) + int w_Framebuffer_grab(lua_State * L) { Framebuffer * fbo = luax_checkfbo(L, 1); - fbo->bind(); + fbo->grab(); return 0; } - int w_Framebuffer_unbind(lua_State * L) + int w_Framebuffer_stop(lua_State * L) { Framebuffer * fbo = luax_checkfbo(L, 1); - fbo->unbind(); + fbo->stop(); return 0; } static const luaL_Reg functions[] = { { "render", w_Framebuffer_render }, - { "bind", w_Framebuffer_bind }, - { "unbind", w_Framebuffer_unbind }, + { "grab", w_Framebuffer_grab }, + { "stop", w_Framebuffer_stop }, { 0, 0 } }; From ce0006d04c384e06b48f9ea65908e3cbca6e6e68 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 13 Aug 2010 21:04:32 +0200 Subject: [PATCH 07/20] Add guards to prevent fbo nesting --- src/modules/graphics/opengl/Framebuffer.cpp | 18 ++++++++++++++++-- src/modules/graphics/opengl/Framebuffer.h | 8 +++++--- .../graphics/opengl/wrap_Framebuffer.cpp | 15 +++++++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index e2adb865d..0881c468e 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -8,6 +8,7 @@ namespace graphics namespace opengl { + bool Framebuffer::isGrabbing = false; std::map Framebuffer::status_to_string; Framebuffer::Framebuffer(int width, int height) : @@ -89,19 +90,32 @@ namespace opengl status_to_string[statusCode()]; } - void Framebuffer::grab() + bool Framebuffer::grab() { + // don't allow nesting or forgetting Framebuffer::stop() + if (isGrabbing) + return false; + glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(.0f, .0f, .0f, .0f); glViewport(0, 0, width, height); + isGrabbing = true; + + return true; } - void Framebuffer::stop() + bool Framebuffer::stop() { + if (!isGrabbing) + return false; + glBindFramebuffer(GL_FRAMEBUFFER, 0); glPopAttrib(); + isGrabbing = false; + + return true; } void Framebuffer::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index 8b134dd5f..b09408cda 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -24,21 +24,23 @@ namespace opengl GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE const char* statusMessage() const; - void grab(); - void stop(); + bool grab(); + bool stop(); virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; private: + static bool isGrabbing; + GLsizei width; GLsizei height; GLuint fbo; GLuint depthbuffer; GLuint img; - GLenum status_; vertex vertices[4]; + GLenum status_; static std::map status_to_string; }; diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.cpp b/src/modules/graphics/opengl/wrap_Framebuffer.cpp index 4dd669428..ebd411b71 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.cpp +++ b/src/modules/graphics/opengl/wrap_Framebuffer.cpp @@ -17,12 +17,16 @@ namespace opengl if (!lua_isfunction(L, 2)) return luaL_error(L, "Need a function to render to fbo"); - fbo->grab(); + // prevent nesting + if (!fbo->grab()) + return luaL_error(L, "Cannot grab screen. May be caused by nesting or forgetting to stop()"); lua_settop(L, 2); // make sure the function is on top of the stack lua_pcall(L, 0, 0, 0); - fbo->stop(); + // fbo can be stopped in function. + if (!fbo->stop()) + return luaL_error(L, "Grabbing already stopped."); return 0; } @@ -30,14 +34,17 @@ namespace opengl int w_Framebuffer_grab(lua_State * L) { Framebuffer * fbo = luax_checkfbo(L, 1); - fbo->grab(); + // prevent nesting + if (!fbo->grab()) + return luaL_error(L, "Cannot grab screen. May be caused by nesting or forgetting to stop()"); return 0; } int w_Framebuffer_stop(lua_State * L) { Framebuffer * fbo = luax_checkfbo(L, 1); - fbo->stop(); + if (!fbo->stop()) + return luaL_error(L, "Grabbing already stopped."); return 0; } From f97d0871580dd06d752b26bb9c19a99aeb72ab96 Mon Sep 17 00:00:00 2001 From: vrld Date: Wed, 25 Aug 2010 17:28:51 +0200 Subject: [PATCH 08/20] Framebuffer status handling Remove Framebuffer::statusCode() and Framebuffer::statusMessage(). Introduce Framebuffer:getStatus() returning the value of glCheckFramebufferStatus(). Test if creation was successful in w_newFramebuffer(L), on failure throw useful error message. --- src/modules/graphics/opengl/Framebuffer.cpp | 30 ------------------- src/modules/graphics/opengl/Framebuffer.h | 5 +--- src/modules/graphics/opengl/wrap_Graphics.cpp | 22 +++++++++++--- 3 files changed, 19 insertions(+), 38 deletions(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 0881c468e..4a36940d1 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -9,34 +9,9 @@ namespace opengl { bool Framebuffer::isGrabbing = false; - std::map Framebuffer::status_to_string; - Framebuffer::Framebuffer(int width, int height) : width(width), height(height) { - // maybe create status code messages - if (status_to_string.empty()) { - status_to_string[GL_FRAMEBUFFER_UNSUPPORTED] // the most important one - = "your opengl implementation does not support framebuffer objects"; - - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT] - = "framebuffer has incomplete attachments"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER] - = "incomplete draw buffer"; - - // the ones that should never, ever happen: - status_to_string[GL_FRAMEBUFFER_UNDEFINED] - = "default framebuffer does not exist"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT] - = "framebuffer needs at least one image attached"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER] - = "incomplete read buffer"; - status_to_string[GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE] - = "number of samples mismatch in attached buffers"; - // "Additionally, if an error occurs, zero is returned." and - // "GL_INVALID_ENUM is generated if target is not GL_DRAW_FRAMEBUFFER, GL_READ_FRAMEBUFFER or GL_FRAMEBUFFER." - status_to_string[0] = "Framebuffer hijacked by aliens"; - } // world coordinates vertices[0].x = 0; vertices[0].y = 0; @@ -85,11 +60,6 @@ namespace opengl glDeleteFramebuffers(1, &img); } - const char* Framebuffer::statusMessage() const - { - status_to_string[statusCode()]; - } - bool Framebuffer::grab() { // don't allow nesting or forgetting Framebuffer::stop() diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index b09408cda..8e3e9ec31 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -20,9 +20,7 @@ namespace opengl Framebuffer(int width, int height); virtual ~Framebuffer(); - // for internal use (w_newFramebuffer <-> love.graphics.newFramebuffer) only - GLenum statusCode() const { return status_; } //SERIOUS DISLIKE HERE - const char* statusMessage() const; + unsigned int getStatus() const { return status_; } bool grab(); bool stop(); @@ -41,7 +39,6 @@ namespace opengl vertex vertices[4]; GLenum status_; - static std::map status_to_string; }; } // opengl diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index e67684492..fd3f04d0a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -297,12 +297,26 @@ namespace opengl int width, height; width = luaL_checkint(L, 1); height = luaL_checkint(L, 2); - Framebuffer * Framebuffer = instance->newFramebuffer(width, height); + Framebuffer * framebuffer = instance->newFramebuffer(width, height); //and there we go with the status... still disliked - if (Framebuffer->statusCode() != GL_FRAMEBUFFER_COMPLETE_EXT) - return luaL_error(L, "Cannot create Framebuffer: %s", Framebuffer->statusMessage()); - luax_newtype(L, "Framebuffer", GRAPHICS_FRAMEBUFFER_T, (void*)Framebuffer); + if (framebuffer->getStatus() != GL_FRAMEBUFFER_COMPLETE) { + switch (framebuffer->getStatus()) { + case GL_FRAMEBUFFER_UNSUPPORTED: + return luaL_error(L, "Cannot create Framebuffer: " + "Not supported by your OpenGL implementation"); + // remaining error codes are highly unlikely: + // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, + // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER + // GL_FRAMEBUFFER_UNDEFINED + // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT + // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER + // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE + default: + return luaL_error(L, "Cannot create Framebuffer: Aliens did it"); + } + } + luax_newtype(L, "Framebuffer", GRAPHICS_FRAMEBUFFER_T, (void*)framebuffer); return 1; } From 98feae1950aaee99fb4ff3bcb56fd6765457e938 Mon Sep 17 00:00:00 2001 From: vrld Date: Wed, 25 Aug 2010 17:38:06 +0200 Subject: [PATCH 09/20] Fix error messages on multiple Frambuffer:grab()/stop() --- .../graphics/opengl/wrap_Framebuffer.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.cpp b/src/modules/graphics/opengl/wrap_Framebuffer.cpp index ebd411b71..588cb92fb 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.cpp +++ b/src/modules/graphics/opengl/wrap_Framebuffer.cpp @@ -18,15 +18,17 @@ namespace opengl return luaL_error(L, "Need a function to render to fbo"); // prevent nesting - if (!fbo->grab()) - return luaL_error(L, "Cannot grab screen. May be caused by nesting or forgetting to stop()"); + if (!fbo->grab()) { + fbo->stop(); // stop grabbing so errormessage is shown + return luaL_error(L, "Framebuffer:grab(): Cannot grab screen. Be sure to match every Framebuffer:grab() with Framebuffer:stop()."); + } lua_settop(L, 2); // make sure the function is on top of the stack - lua_pcall(L, 0, 0, 0); + lua_call(L, 0, 0); // fbo can be stopped in function. if (!fbo->stop()) - return luaL_error(L, "Grabbing already stopped."); + return luaL_error(L, "Framebuffer:render(): Screengrabbing already stopped."); return 0; } @@ -35,8 +37,10 @@ namespace opengl { Framebuffer * fbo = luax_checkfbo(L, 1); // prevent nesting - if (!fbo->grab()) - return luaL_error(L, "Cannot grab screen. May be caused by nesting or forgetting to stop()"); + if (!fbo->grab()) { + fbo->stop(); // stop grabbing so errormessage is shown + return luaL_error(L, "Framebuffer:grab(): Cannot grab screen. Be sure to match every Framebuffer:grab() with Framebuffer:stop()."); + } return 0; } @@ -44,7 +48,7 @@ namespace opengl { Framebuffer * fbo = luax_checkfbo(L, 1); if (!fbo->stop()) - return luaL_error(L, "Grabbing already stopped."); + return luaL_error(L, "Framebuffer:stop(): Screengrabbing already stopped."); return 0; } From 9dea5e638f9bb040826409a5030da5e86e55f13c Mon Sep 17 00:00:00 2001 From: vrld Date: Thu, 26 Aug 2010 13:02:41 +0200 Subject: [PATCH 10/20] More descriptive error messages --- src/modules/graphics/opengl/wrap_Graphics.cpp | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index fd3f04d0a..2dd0f9b3f 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -297,6 +297,7 @@ namespace opengl int width, height; width = luaL_checkint(L, 1); height = luaL_checkint(L, 2); + glGetError(); // clear opengl error flag Framebuffer * framebuffer = instance->newFramebuffer(width, height); //and there we go with the status... still disliked @@ -306,14 +307,25 @@ namespace opengl return luaL_error(L, "Cannot create Framebuffer: " "Not supported by your OpenGL implementation"); // remaining error codes are highly unlikely: - // GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT, - // GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER - // GL_FRAMEBUFFER_UNDEFINED - // GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT - // GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER - // GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE + case GL_FRAMEBUFFER_UNDEFINED: + case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT: + case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT: + case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER: + case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER: + case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE: + return luaL_error(L, "Cannot create Framebuffer: " + "Error in implementation (please inform the love devs)"); default: - return luaL_error(L, "Cannot create Framebuffer: Aliens did it"); + // my intel hda card wrongly returns 0 to glCheckFramebufferStatus() but sets + // no error flag. I think it meant to return GL_FRAMEBUFFER_UNSUPPORTED, but who + // knows. + if (glGetError() == GL_NO_ERROR) + return luaL_error(L, "Cannot create Framebuffer: " + "May not be supported by your OpenGL implementation."); + // the remaining error is an indication of a serious fuckup since it should + // only be returned if glCheckFramebufferStatus() was called with the wrong + // arguments. + return luaL_error(L, "Cannot create Framebuffer: Aliens did it (OpenGL error code: %d)", glGetError()); } } luax_newtype(L, "Framebuffer", GRAPHICS_FRAMEBUFFER_T, (void*)framebuffer); From 320ac05fd1de797cd2e906d3bca05858a3c5b2fd Mon Sep 17 00:00:00 2001 From: vrld Date: Thu, 26 Aug 2010 20:44:30 +0200 Subject: [PATCH 11/20] Fix of http://bitbucket.org/bartbes/love-fbo/issue/7 Move fbo:grab() to love.graphics.setRenderTarget( fbo ) Move fbo:stop() to love.graphics.setRenderTarget( nil ) Rename fbo:render( func ) to fbo:renderTo( func ) --- src/modules/graphics/opengl/Framebuffer.cpp | 44 +++++++++++++------ src/modules/graphics/opengl/Framebuffer.h | 14 +++--- .../graphics/opengl/wrap_Framebuffer.cpp | 44 +++++-------------- .../graphics/opengl/wrap_Framebuffer.h | 4 +- src/modules/graphics/opengl/wrap_Graphics.cpp | 16 +++++++ src/modules/graphics/opengl/wrap_Graphics.h | 1 + 6 files changed, 67 insertions(+), 56 deletions(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 4a36940d1..1acc97af8 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -7,8 +7,8 @@ namespace graphics { namespace opengl { + Framebuffer* Framebuffer::current = NULL; - bool Framebuffer::isGrabbing = false; Framebuffer::Framebuffer(int width, int height) : width(width), height(height) { @@ -47,7 +47,7 @@ namespace opengl GL_TEXTURE_2D, img, 0); glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, depthbuffer); - status_ = glCheckFramebufferStatus(GL_FRAMEBUFFER); + status = glCheckFramebufferStatus(GL_FRAMEBUFFER); // unbind buffers and texture glBindFramebuffer(GL_FRAMEBUFFER, 0); @@ -55,37 +55,53 @@ namespace opengl Framebuffer::~Framebuffer() { + // reset framebuffer if still using this one + if (current == this) + stopGrab(); + + // clear fbo glDeleteTextures(1, &fbo); glDeleteRenderbuffers(1, &depthbuffer); glDeleteFramebuffers(1, &img); } - bool Framebuffer::grab() + void Framebuffer::bindDefaultBuffer() { - // don't allow nesting or forgetting Framebuffer::stop() - if (isGrabbing) - return false; + if (current != NULL) + current->stopGrab(); + } + void Framebuffer::startGrab() + { + // already grabbing + if (current == this) + return; + + // cleanup after previous fbo + if (current != NULL) + glPopAttrib(); + + // bind buffer and clear screen glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(.0f, .0f, .0f, .0f); glViewport(0, 0, width, height); - isGrabbing = true; - return true; + // indicate + current = this; } - bool Framebuffer::stop() + void Framebuffer::stopGrab() { - if (!isGrabbing) - return false; + // i am not grabbing. leave me alone + if (current != this) + return; + // bind default glBindFramebuffer(GL_FRAMEBUFFER, 0); glPopAttrib(); - isGrabbing = false; - - return true; + current = NULL; } void Framebuffer::draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index 8e3e9ec31..22b4025e6 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -20,16 +20,18 @@ namespace opengl Framebuffer(int width, int height); virtual ~Framebuffer(); - unsigned int getStatus() const { return status_; } + unsigned int getStatus() const { return status; } - bool grab(); - bool stop(); + static Framebuffer* current; + static void bindDefaultBuffer(); + + void startGrab(); + void stopGrab(); virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; - private: - static bool isGrabbing; + private: GLsizei width; GLsizei height; GLuint fbo; @@ -38,7 +40,7 @@ namespace opengl vertex vertices[4]; - GLenum status_; + GLenum status; }; } // opengl diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.cpp b/src/modules/graphics/opengl/wrap_Framebuffer.cpp index 588cb92fb..db882805f 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.cpp +++ b/src/modules/graphics/opengl/wrap_Framebuffer.cpp @@ -11,51 +11,29 @@ namespace opengl return luax_checktype(L, idx, "Framebuffer", GRAPHICS_FRAMEBUFFER_T); } - int w_Framebuffer_render(lua_State * L) + int w_Framebuffer_renderTo(lua_State * L) { + // As startGrab() clears the framebuffer, better not allow + // grabbing inside another grabbing + if (Framebuffer::current != NULL) { + Framebuffer::bindDefaultBuffer(); + return luaL_error(L, "Current render target not the default framebuffer!"); + } + Framebuffer * fbo = luax_checkfbo(L, 1); if (!lua_isfunction(L, 2)) return luaL_error(L, "Need a function to render to fbo"); - // prevent nesting - if (!fbo->grab()) { - fbo->stop(); // stop grabbing so errormessage is shown - return luaL_error(L, "Framebuffer:grab(): Cannot grab screen. Be sure to match every Framebuffer:grab() with Framebuffer:stop()."); - } - + fbo->startGrab(); lua_settop(L, 2); // make sure the function is on top of the stack lua_call(L, 0, 0); + fbo->stopGrab(); - // fbo can be stopped in function. - if (!fbo->stop()) - return luaL_error(L, "Framebuffer:render(): Screengrabbing already stopped."); - - return 0; - } - - int w_Framebuffer_grab(lua_State * L) - { - Framebuffer * fbo = luax_checkfbo(L, 1); - // prevent nesting - if (!fbo->grab()) { - fbo->stop(); // stop grabbing so errormessage is shown - return luaL_error(L, "Framebuffer:grab(): Cannot grab screen. Be sure to match every Framebuffer:grab() with Framebuffer:stop()."); - } - return 0; - } - - int w_Framebuffer_stop(lua_State * L) - { - Framebuffer * fbo = luax_checkfbo(L, 1); - if (!fbo->stop()) - return luaL_error(L, "Framebuffer:stop(): Screengrabbing already stopped."); return 0; } static const luaL_Reg functions[] = { - { "render", w_Framebuffer_render }, - { "grab", w_Framebuffer_grab }, - { "stop", w_Framebuffer_stop }, + { "renderTo", w_Framebuffer_renderTo }, { 0, 0 } }; diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.h b/src/modules/graphics/opengl/wrap_Framebuffer.h index 0bdf9964f..563a3abbd 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.h +++ b/src/modules/graphics/opengl/wrap_Framebuffer.h @@ -13,9 +13,7 @@ namespace opengl { //see Framebuffer.h Framebuffer * luax_checkfbo(lua_State * L, int idx); - int w_Framebuffer_render(lua_State * L); - int w_Framebuffer_bind(lua_State * L); - int w_Framebuffer_unbind(lua_State * L); + int w_Framebuffer_renderTo(lua_State * L); int luaopen_framebuffer(lua_State * L); } // opengl diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index fd3f04d0a..08baea2f3 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -595,6 +595,21 @@ namespace opengl return 1; } + int w_setRenderTarget(lua_State * L) + { + // called with nil -> reset to default buffer + if (lua_isnil(L, 1)) { + Framebuffer::bindDefaultBuffer(); + return 0; + } + + Framebuffer * fbo = luax_checkfbo(L, 1); + // this unbinds the previous fbo + fbo->startGrab(); + + return 0; + } + /** * Draws an Image at the specified coordinates, with rotation and * scaling along both axes. @@ -885,6 +900,7 @@ namespace opengl { "getPointStyle", w_getPointStyle }, { "getMaxPointSize", w_getMaxPointSize }, { "newScreenshot", w_newScreenshot }, + { "setRenderTarget", w_setRenderTarget }, { "draw", w_draw }, { "drawq", w_drawq }, diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/opengl/wrap_Graphics.h index d7d51ec89..776978351 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/opengl/wrap_Graphics.h @@ -84,6 +84,7 @@ namespace opengl int w_getPointStyle(lua_State * L); int w_getMaxPointSize(lua_State * L); int w_newScreenshot(lua_State * L); + int w_setRenderTarget(lua_State * L); int w_draw(lua_State * L); int w_drawq(lua_State * L); int w_drawTest(lua_State * L); From f9f7e83f0ed553f4286dc0e95d71ceebe0a13270 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 27 Aug 2010 13:51:11 +0200 Subject: [PATCH 12/20] Issue #7: Use GL_EXT_framebuffer_object when OpenGL version < 3.0 Add runtime check of OpenGL version and extensions. If OpenGL version >= 3.0, use core functions. Else check for framebuffer object extension and use EXT functions. If none of the above, do nothing but return GL_FRAMEBUFFER_COMPLETE. --- src/modules/graphics/opengl/Framebuffer.cpp | 214 +++++++++++++++++--- 1 file changed, 182 insertions(+), 32 deletions(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 1acc97af8..b62b95a77 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -1,6 +1,170 @@ #include "Framebuffer.h" #include +#include +#include +#include +#include +#include +#include +using namespace std; + +namespace { + + // functions to get opengl capabilities at runtime + vector tokenize(const string& str) + { + vector tokens; + + istringstream iss( str ); + copy(istream_iterator(iss), istream_iterator(), + back_inserter< vector >(tokens)); + return tokens; + } + + float getOpenGLVersionNumber() + { + vector tokens = tokenize( (const char*)glGetString(GL_VERSION) ); + stringstream toNumber( tokens.at(0) ); + + double version; + toNumber >> version; + return version; + } + + bool hasFramebufferExtension() + { + vector ext = tokenize( (const char*)glGetString(GL_EXTENSIONS) ); + return find(ext.begin(), ext.end(), "GL_EXT_framebuffer_object") != ext.end(); + } + + + // strategy for fbo creation, interchangable at runtime: + // none, opengl >= 3.0, extensions + struct FramebufferStrategy { + /// create a new framebuffer, depthbuffer and texture + /** + * @param[out] framebuffer Framebuffer name + * @param[out] depthbuffer Depthbuffer name + * @param[out] img Texture name + * @param[in] width Width of framebuffer + * @param[in] height Height of framebuffer + * @return Creation status + */ + virtual GLenum createFBO(GLuint& framebuffer, GLuint& depthbuffer, GLuint& img, int width, int height) + { return GL_FRAMEBUFFER_UNSUPPORTED; } + /// remove objects + /** + * @param[in] framebuffer Framebuffer name + * @param[in] depthbuffer Depthbuffer name + * @param[in] img Texture name + */ + virtual void deleteFBO(GLuint framebuffer, GLuint depthbuffer, GLuint img) {} + virtual void bindFBO(GLuint framebuffer) {} + }; + +#ifdef GL_VERSION_3_0 + struct FramebufferStrategyGL3 : public FramebufferStrategy { + virtual GLenum createFBO(GLuint& framebuffer, GLuint& depthbuffer, GLuint& img, int width, int height) + { + // generate depth buffer + glGenRenderbuffers(1, &depthbuffer); + glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer); + glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); + glBindRenderbuffer(GL_RENDERBUFFER, 0); + + // generate texture save target + glGenTextures(1, &img); + glBindTexture(GL_TEXTURE_2D, img); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + + // create framebuffer + glGenFramebuffers(1, &framebuffer); + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, + GL_TEXTURE_2D, img, 0); + glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, + GL_RENDERBUFFER, depthbuffer); + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); + + // unbind buffers and texture + glBindFramebuffer(GL_FRAMEBUFFER, 0); + return status; + } + virtual void deleteFBO(GLuint framebuffer, GLuint depthbuffer, GLuint img) + { + glDeleteTextures(1, &framebuffer); + glDeleteRenderbuffers(1, &depthbuffer); + glDeleteFramebuffers(1, &img); + } + + virtual void bindFBO(GLuint framebuffer) + { + glBindFramebuffer(GL_FRAMEBUFFER, framebuffer); + } + }; +#endif + + struct FramebufferStrategyEXT : public FramebufferStrategy { + + virtual GLenum createFBO(GLuint& framebuffer, GLuint& depthbuffer, GLuint& img, int width, int height) + { + // generate depth buffer + glGenRenderbuffersEXT(1, &depthbuffer); + glBindRenderbuffer(GL_RENDERBUFFER_EXT, depthbuffer); + glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, width, height); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); + + // generate texture save target + glGenTextures(1, &img); + glBindTexture(GL_TEXTURE_2D, img); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, + 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, 0); + + // create framebuffer + glGenFramebuffersEXT(1, &framebuffer); + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); + glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, + GL_TEXTURE_2D, img, 0); + glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, + GL_RENDERBUFFER_EXT, depthbuffer); + GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); + + // unbind buffers and texture + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + return status; + } + + virtual void deleteFBO(GLuint framebuffer, GLuint depthbuffer, GLuint img) + { + glDeleteTextures(1, &framebuffer); + glDeleteRenderbuffersEXT(1, &depthbuffer); + glDeleteFramebuffersEXT(1, &img); + } + + virtual void bindFBO(GLuint framebuffer) + { + glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer); + } + }; + + FramebufferStrategy* strategy = NULL; + + FramebufferStrategy strategyNone; +#ifdef GL_VERSION_3_0 + FramebufferStrategyGL3 strategyGL3; +#endif + FramebufferStrategyEXT strategyEXT; + +}; + namespace love { namespace graphics @@ -25,32 +189,21 @@ namespace opengl vertices[2].s = 1; vertices[2].t = 0; vertices[3].s = 1; vertices[3].t = 1; - // generate depth buffer - glGenRenderbuffers(1, &depthbuffer); - glBindRenderbuffer(GL_RENDERBUFFER, depthbuffer); - glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, width, height); - glBindRenderbuffer(GL_RENDERBUFFER, 0); + if (!strategy) { +#ifdef GL_VERSION_3_0 + if (getOpenGLVersionNumber() >= 3.0) + strategy = &strategyGL3; + else if (hasFramebufferExtension()) +#else + if (hasFramebufferExtension()) +#endif + strategy = &strategyEXT; + else + strategy = &strategyNone; + + } - // generate texture save target - glGenTextures(1, &img); - glBindTexture(GL_TEXTURE_2D, img); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, - 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glBindTexture(GL_TEXTURE_2D, 0); - - // create framebuffer - glGenFramebuffers(1, &fbo); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); - glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_TEXTURE_2D, img, 0); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, - GL_RENDERBUFFER, depthbuffer); - status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - - // unbind buffers and texture - glBindFramebuffer(GL_FRAMEBUFFER, 0); + status = strategy->createFBO(fbo, depthbuffer, img, width, height); } Framebuffer::~Framebuffer() @@ -59,10 +212,7 @@ namespace opengl if (current == this) stopGrab(); - // clear fbo - glDeleteTextures(1, &fbo); - glDeleteRenderbuffers(1, &depthbuffer); - glDeleteFramebuffers(1, &img); + strategy->deleteFBO(fbo, depthbuffer, img); } void Framebuffer::bindDefaultBuffer() @@ -83,12 +233,12 @@ namespace opengl // bind buffer and clear screen glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - glBindFramebuffer(GL_FRAMEBUFFER, fbo); + strategy->bindFBO(fbo); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(.0f, .0f, .0f, .0f); glViewport(0, 0, width, height); - // indicate + // indicate we are using this fbo current = this; } @@ -99,7 +249,7 @@ namespace opengl return; // bind default - glBindFramebuffer(GL_FRAMEBUFFER, 0); + strategy->bindFBO( 0 ); glPopAttrib(); current = NULL; } From ce6ca185f144b0d77084907cca0223187e06d560 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 27 Aug 2010 14:14:22 +0200 Subject: [PATCH 13/20] Issue #5: Add Framebuffer:getImageData() --- src/modules/graphics/opengl/Framebuffer.cpp | 33 +++++++++++++++++++ src/modules/graphics/opengl/Framebuffer.h | 5 +-- .../graphics/opengl/wrap_Framebuffer.cpp | 10 ++++++ .../graphics/opengl/wrap_Framebuffer.h | 1 + 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index b62b95a77..287db0048 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -1,6 +1,8 @@ #include "Framebuffer.h" #include +#include + #include #include #include @@ -275,6 +277,37 @@ namespace opengl glPopMatrix(); } + love::image::ImageData * Framebuffer::getImageData(love::image::Image * image) + { + int row = 4 * width; + int size = row * height; + + // see Graphics::newScreenshot. OpenGL reads from lower-left, + // but we need the pixels from upper-left. + GLubyte* pixels = new GLubyte[size]; + GLubyte* screenshot = new GLubyte[size]; + + strategy->bindFBO( fbo ); + glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels); + if (current) + strategy->bindFBO( current->fbo ); + else + strategy->bindFBO( 0 ); + + GLubyte* src = pixels - row; // second line of buffer + GLubyte* dst = screenshot + size; // end of buffer + + for (int i = 0; i < height; ++i) + memcpy(dst -= row, src += row, row); + + love::image::ImageData * img = image->newImageData(width, height, (void*)screenshot); + + delete[] screenshot; + delete[] pixels; + + return img; + } + } // opengl } // graphics } // love diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index 22b4025e6..3e356c5a4 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -2,7 +2,8 @@ #define LOVE_GRAPHICS_FRAMEBUFFER_H #include -#include +#include +#include #include #include #include "GLee.h" @@ -29,7 +30,7 @@ namespace opengl void stopGrab(); virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; - + love::image::ImageData * getImageData(love::image::Image * image); private: GLsizei width; diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.cpp b/src/modules/graphics/opengl/wrap_Framebuffer.cpp index db882805f..5bb67fdc9 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.cpp +++ b/src/modules/graphics/opengl/wrap_Framebuffer.cpp @@ -32,8 +32,18 @@ namespace opengl return 0; } + int w_Framebuffer_getImageData(lua_State * L) + { + Framebuffer * fbo = luax_checkfbo(L, 1); + love::image::Image * image = luax_getmodule(L, "image", MODULE_IMAGE_T); + love::image::ImageData * img = fbo->getImageData( image ); + luax_newtype(L, "ImageData", IMAGE_IMAGE_DATA_T, (void *)img); + return 1; + } + static const luaL_Reg functions[] = { { "renderTo", w_Framebuffer_renderTo }, + { "getImageData", w_Framebuffer_getImageData }, { 0, 0 } }; diff --git a/src/modules/graphics/opengl/wrap_Framebuffer.h b/src/modules/graphics/opengl/wrap_Framebuffer.h index 563a3abbd..ecb491604 100644 --- a/src/modules/graphics/opengl/wrap_Framebuffer.h +++ b/src/modules/graphics/opengl/wrap_Framebuffer.h @@ -14,6 +14,7 @@ namespace opengl //see Framebuffer.h Framebuffer * luax_checkfbo(lua_State * L, int idx); int w_Framebuffer_renderTo(lua_State * L); + int w_Framebuffer_getImageData(lua_State * L); int luaopen_framebuffer(lua_State * L); } // opengl From 9dd4be5e3170367fd2dd275582fd364bdae76274 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 27 Aug 2010 14:38:36 +0200 Subject: [PATCH 14/20] Issue #4: Now really clearing with 0 alpha --- src/modules/graphics/opengl/Framebuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 287db0048..34dd06bb2 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -236,8 +236,8 @@ namespace opengl // bind buffer and clear screen glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); strategy->bindFBO(fbo); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClearColor(.0f, .0f, .0f, .0f); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glViewport(0, 0, width, height); // indicate we are using this fbo From ee3b74e66d1e1e48bed28c5aebffe39a6db283e8 Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sat, 28 Aug 2010 12:28:56 -0500 Subject: [PATCH 15/20] updated Xcode project with Framebuffer files --- platform/macosx/love.xcodeproj/project.pbxproj | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index 501fa02dc..d059530c8 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -187,6 +187,8 @@ A98D914410507C97008E03F2 /* EncodedImageData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A98D914310507C97008E03F2 /* EncodedImageData.cpp */; }; A9B4BA9C1045937F001DBC80 /* ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9B4BA9A1045937F001DBC80 /* ParticleSystem.cpp */; }; A9B4BA9D1045937F001DBC80 /* wrap_ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9B4BA9B1045937F001DBC80 /* wrap_ParticleSystem.cpp */; }; + A9BD60741226C988007DEC63 /* Framebuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9BD60701226C988007DEC63 /* Framebuffer.cpp */; }; + A9BD60751226C988007DEC63 /* wrap_Framebuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9BD60721226C988007DEC63 /* wrap_Framebuffer.cpp */; }; A9CF0E8610B9EB1000E6F37E /* utf8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A9CF0E8510B9EB1000E6F37E /* utf8.cpp */; }; A9D307EA106635C3004FEDF8 /* physfs.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A9D307E9106635C3004FEDF8 /* physfs.framework */; }; A9D307F2106635D3004FEDF8 /* physfs.framework in Copy Frameworks */ = {isa = PBXBuildFile; fileRef = A9D307E9106635C3004FEDF8 /* physfs.framework */; }; @@ -598,6 +600,10 @@ A9B4BA991045937F001DBC80 /* wrap_ParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_ParticleSystem.h; sourceTree = ""; }; A9B4BA9A1045937F001DBC80 /* ParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParticleSystem.cpp; sourceTree = ""; }; A9B4BA9B1045937F001DBC80 /* wrap_ParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_ParticleSystem.cpp; sourceTree = ""; }; + A9BD60701226C988007DEC63 /* Framebuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Framebuffer.cpp; sourceTree = ""; }; + A9BD60711226C988007DEC63 /* Framebuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Framebuffer.h; sourceTree = ""; }; + A9BD60721226C988007DEC63 /* wrap_Framebuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Framebuffer.cpp; sourceTree = ""; }; + A9BD60731226C988007DEC63 /* wrap_Framebuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Framebuffer.h; sourceTree = ""; }; A9BFAA851137C1CE005FE0AD /* ThreadModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ThreadModule.h; sourceTree = ""; }; A9CF0E8410B9EB1000E6F37E /* utf8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = utf8.h; sourceTree = ""; }; A9CF0E8510B9EB1000E6F37E /* utf8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = utf8.cpp; sourceTree = ""; }; @@ -985,6 +991,8 @@ children = ( A93E6A8710420AC2007D418B /* Font.cpp */, A93E6A8810420AC2007D418B /* Font.h */, + A9BD60701226C988007DEC63 /* Framebuffer.cpp */, + A9BD60711226C988007DEC63 /* Framebuffer.h */, A93E6A8910420AC2007D418B /* GLee.c */, A93E6A8A10420AC2007D418B /* GLee.h */, A93E6A8B10420AC2007D418B /* Glyph.cpp */, @@ -1001,6 +1009,8 @@ A93E6A9610420AC2007D418B /* SpriteBatch.h */, A93E6A9910420AC2007D418B /* wrap_Font.cpp */, A93E6A9A10420AC2007D418B /* wrap_Font.h */, + A9BD60721226C988007DEC63 /* wrap_Framebuffer.cpp */, + A9BD60731226C988007DEC63 /* wrap_Framebuffer.h */, A93E6A9B10420AC2007D418B /* wrap_Glyph.cpp */, A93E6A9C10420AC2007D418B /* wrap_Glyph.h */, A93E6A9D10420AC3007D418B /* wrap_Graphics.cpp */, @@ -1660,6 +1670,8 @@ A946CE821172BCD7005E1462 /* wrap_EncodedImageData.cpp in Sources */, A946D3BB117681BD005E1462 /* FontData.cpp in Sources */, A946D3C611768D69005E1462 /* wrap_FontData.cpp in Sources */, + A9BD60741226C988007DEC63 /* Framebuffer.cpp in Sources */, + A9BD60751226C988007DEC63 /* wrap_Framebuffer.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; From 769842ce6e3856700ab27e8e37040754b56d96ad Mon Sep 17 00:00:00 2001 From: Bill Meltsner Date: Sat, 28 Aug 2010 13:02:28 -0500 Subject: [PATCH 16/20] made Framebuffer Volatile and fixed a few bugs --- src/modules/graphics/opengl/Framebuffer.cpp | 25 +++++++++++++++------ src/modules/graphics/opengl/Framebuffer.h | 6 ++++- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/modules/graphics/opengl/Framebuffer.cpp b/src/modules/graphics/opengl/Framebuffer.cpp index 34dd06bb2..0a372a1ab 100644 --- a/src/modules/graphics/opengl/Framebuffer.cpp +++ b/src/modules/graphics/opengl/Framebuffer.cpp @@ -99,9 +99,9 @@ namespace { } virtual void deleteFBO(GLuint framebuffer, GLuint depthbuffer, GLuint img) { - glDeleteTextures(1, &framebuffer); + glDeleteTextures(1, &img); glDeleteRenderbuffers(1, &depthbuffer); - glDeleteFramebuffers(1, &img); + glDeleteFramebuffers(1, &framebuffer); } virtual void bindFBO(GLuint framebuffer) @@ -117,7 +117,7 @@ namespace { { // generate depth buffer glGenRenderbuffersEXT(1, &depthbuffer); - glBindRenderbuffer(GL_RENDERBUFFER_EXT, depthbuffer); + glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuffer); glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, width, height); glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); @@ -146,9 +146,9 @@ namespace { virtual void deleteFBO(GLuint framebuffer, GLuint depthbuffer, GLuint img) { - glDeleteTextures(1, &framebuffer); + glDeleteTextures(1, &img); glDeleteRenderbuffersEXT(1, &depthbuffer); - glDeleteFramebuffersEXT(1, &img); + glDeleteFramebuffersEXT(1, &framebuffer); } virtual void bindFBO(GLuint framebuffer) @@ -205,7 +205,7 @@ namespace opengl } - status = strategy->createFBO(fbo, depthbuffer, img, width, height); + loadVolatile(); } Framebuffer::~Framebuffer() @@ -214,7 +214,7 @@ namespace opengl if (current == this) stopGrab(); - strategy->deleteFBO(fbo, depthbuffer, img); + unloadVolatile(); } void Framebuffer::bindDefaultBuffer() @@ -307,6 +307,17 @@ namespace opengl return img; } + + bool Framebuffer::loadVolatile() + { + status = strategy->createFBO(fbo, depthbuffer, img, width, height); + return (status == GL_FRAMEBUFFER_COMPLETE); + } + + void Framebuffer::unloadVolatile() + { + strategy->deleteFBO(fbo, depthbuffer, img); + } } // opengl } // graphics diff --git a/src/modules/graphics/opengl/Framebuffer.h b/src/modules/graphics/opengl/Framebuffer.h index 3e356c5a4..648d03026 100644 --- a/src/modules/graphics/opengl/Framebuffer.h +++ b/src/modules/graphics/opengl/Framebuffer.h @@ -2,6 +2,7 @@ #define LOVE_GRAPHICS_FRAMEBUFFER_H #include +#include #include #include #include @@ -15,7 +16,7 @@ namespace graphics namespace opengl { - class Framebuffer : public Drawable + class Framebuffer : public Drawable, public Volatile { public: Framebuffer(int width, int height); @@ -31,6 +32,9 @@ namespace opengl virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy) const; love::image::ImageData * getImageData(love::image::Image * image); + + bool loadVolatile(); + void unloadVolatile(); private: GLsizei width; From 78a793e08fd1c1ce48f0dbdb5089dd2c4b5129fd Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 3 Sep 2010 14:28:57 +0200 Subject: [PATCH 17/20] Add default width/height to love.graphics.newFramebuffer --- src/modules/graphics/opengl/wrap_Graphics.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 7cba064a5..efe0bf78d 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -294,9 +294,13 @@ namespace opengl int w_newFramebuffer(lua_State * L) { - int width, height; - width = luaL_checkint(L, 1); - height = luaL_checkint(L, 2); + // check if width and height are given. else default to screen dimensions. + int width = instance->getWidth(); + int height = instance->getHeight(); + if (lua_gettop(L) >= 2) { + width = luaL_optint(L, 1, instance->getWidth()); + height = luaL_optint(L, 2, instance->getHeight()); + } glGetError(); // clear opengl error flag Framebuffer * framebuffer = instance->newFramebuffer(width, height); From 9afc5dfb086b9afb39fb31e89df961ee5d2c8ab5 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 3 Sep 2010 14:46:01 +0200 Subject: [PATCH 18/20] On Error, switch to default framebuffer before showing bluescreen. Bluescreens might not be shown if the error happens with a render target different from the default framebuffer, because it gets rendered to the attached framebuffer object. Fix that. --- src/scripts/boot.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/scripts/boot.lua b/src/scripts/boot.lua index 8277a9a73..387a32300 100644 --- a/src/scripts/boot.lua +++ b/src/scripts/boot.lua @@ -787,6 +787,8 @@ function love.errhand(msg) return end + love.graphics.setRenderTarget() + -- Load. love.graphics.setScissor() love.graphics.setBackgroundColor(89, 157, 220) From 08c06f0fe0fafa5135ee36234ced5f188deb1e39 Mon Sep 17 00:00:00 2001 From: vrld Date: Fri, 3 Sep 2010 14:53:37 +0200 Subject: [PATCH 19/20] Allow zero arguments in love.graphics.setRenderTarget(), update boot.lua.h Calling love.graphics.setRenderTarget() as opposed to love.graphics.setRenderTarget( nil ) was an error before. fixed. --- src/modules/graphics/opengl/wrap_Graphics.cpp | 6 +- src/scripts/boot.lua.h | 180 +++++++++--------- 2 files changed, 94 insertions(+), 92 deletions(-) diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index efe0bf78d..33d3aaf38 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -294,7 +294,7 @@ namespace opengl int w_newFramebuffer(lua_State * L) { - // check if width and height are given. else default to screen dimensions. + // check if width and height are given. else default to screen dimensions. int width = instance->getWidth(); int height = instance->getHeight(); if (lua_gettop(L) >= 2) { @@ -613,8 +613,8 @@ namespace opengl int w_setRenderTarget(lua_State * L) { - // called with nil -> reset to default buffer - if (lua_isnil(L, 1)) { + // called with nil or none -> reset to default buffer + if (lua_isnone(L,1) || lua_isnil(L, 1)) { Framebuffer::bindDefaultBuffer(); return 0; } diff --git a/src/scripts/boot.lua.h b/src/scripts/boot.lua.h index c1d38313b..8519940ab 100644 --- a/src/scripts/boot.lua.h +++ b/src/scripts/boot.lua.h @@ -1157,102 +1157,104 @@ const unsigned char boot_lua[] = 0x74,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73, 0x2E,0x69,0x73,0x43,0x72,0x65,0x61,0x74,0x65,0x64,0x28,0x29,0x20,0x74,0x68, 0x65,0x6E,0x0D,0x0A,0x09,0x09,0x72,0x65,0x74,0x75,0x72,0x6E,0x0D,0x0A,0x09, - 0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x09,0x2D,0x2D,0x20,0x4C,0x6F,0x61,0x64, - 0x2E,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69, - 0x63,0x73,0x2E,0x73,0x65,0x74,0x53,0x63,0x69,0x73,0x73,0x6F,0x72,0x28,0x29, - 0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63, - 0x73,0x2E,0x73,0x65,0x74,0x42,0x61,0x63,0x6B,0x67,0x72,0x6F,0x75,0x6E,0x64, - 0x43,0x6F,0x6C,0x6F,0x72,0x28,0x38,0x39,0x2C,0x20,0x31,0x35,0x37,0x2C,0x20, - 0x32,0x32,0x30,0x29,0x0D,0x0A,0x09,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x66,0x6F, - 0x6E,0x74,0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68, - 0x69,0x63,0x73,0x2E,0x6E,0x65,0x77,0x46,0x6F,0x6E,0x74,0x28,0x6C,0x6F,0x76, - 0x65,0x2E,0x5F,0x76,0x65,0x72,0x61,0x5F,0x74,0x74,0x66,0x2C,0x20,0x31,0x34, - 0x29,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69, - 0x63,0x73,0x2E,0x73,0x65,0x74,0x46,0x6F,0x6E,0x74,0x28,0x66,0x6F,0x6E,0x74, - 0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70, - 0x68,0x69,0x63,0x73,0x2E,0x73,0x65,0x74,0x43,0x6F,0x6C,0x6F,0x72,0x28,0x32, - 0x35,0x35,0x2C,0x20,0x32,0x35,0x35,0x2C,0x20,0x32,0x35,0x35,0x2C,0x20,0x32, - 0x35,0x35,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x74, - 0x72,0x61,0x63,0x65,0x20,0x3D,0x20,0x64,0x65,0x62,0x75,0x67,0x2E,0x74,0x72, - 0x61,0x63,0x65,0x62,0x61,0x63,0x6B,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C, - 0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x63,0x6C, - 0x65,0x61,0x72,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x63,0x61,0x6C, - 0x20,0x65,0x72,0x72,0x20,0x3D,0x20,0x7B,0x7D,0x0D,0x0A,0x0D,0x0A,0x09,0x74, - 0x61,0x62,0x6C,0x65,0x2E,0x69,0x6E,0x73,0x65,0x72,0x74,0x28,0x65,0x72,0x72, - 0x2C,0x20,0x22,0x45,0x72,0x72,0x6F,0x72,0x5C,0x6E,0x22,0x29,0x0D,0x0A,0x09, - 0x74,0x61,0x62,0x6C,0x65,0x2E,0x69,0x6E,0x73,0x65,0x72,0x74,0x28,0x65,0x72, - 0x72,0x2C,0x20,0x6D,0x73,0x67,0x2E,0x2E,0x22,0x5C,0x6E,0x5C,0x6E,0x22,0x29, - 0x0D,0x0A,0x0D,0x0A,0x09,0x66,0x6F,0x72,0x20,0x6C,0x20,0x69,0x6E,0x20,0x73, - 0x74,0x72,0x69,0x6E,0x67,0x2E,0x67,0x6D,0x61,0x74,0x63,0x68,0x28,0x74,0x72, - 0x61,0x63,0x65,0x2C,0x20,0x22,0x28,0x2E,0x2D,0x29,0x5C,0x6E,0x22,0x29,0x20, - 0x64,0x6F,0x0D,0x0A,0x09,0x09,0x69,0x66,0x20,0x6E,0x6F,0x74,0x20,0x73,0x74, - 0x72,0x69,0x6E,0x67,0x2E,0x6D,0x61,0x74,0x63,0x68,0x28,0x6C,0x2C,0x20,0x22, - 0x62,0x6F,0x6F,0x74,0x2E,0x6C,0x75,0x61,0x22,0x29,0x20,0x74,0x68,0x65,0x6E, - 0x0D,0x0A,0x09,0x09,0x09,0x6C,0x20,0x3D,0x20,0x73,0x74,0x72,0x69,0x6E,0x67, - 0x2E,0x67,0x73,0x75,0x62,0x28,0x6C,0x2C,0x20,0x22,0x73,0x74,0x61,0x63,0x6B, - 0x20,0x74,0x72,0x61,0x63,0x65,0x62,0x61,0x63,0x6B,0x3A,0x22,0x2C,0x20,0x22, - 0x54,0x72,0x61,0x63,0x65,0x62,0x61,0x63,0x6B,0x5C,0x6E,0x22,0x29,0x0D,0x0A, - 0x09,0x09,0x09,0x74,0x61,0x62,0x6C,0x65,0x2E,0x69,0x6E,0x73,0x65,0x72,0x74, - 0x28,0x65,0x72,0x72,0x2C,0x20,0x6C,0x29,0x0D,0x0A,0x09,0x09,0x65,0x6E,0x64, - 0x0D,0x0A,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x63,0x61, - 0x6C,0x20,0x70,0x20,0x3D,0x20,0x74,0x61,0x62,0x6C,0x65,0x2E,0x63,0x6F,0x6E, - 0x63,0x61,0x74,0x28,0x65,0x72,0x72,0x2C,0x20,0x22,0x5C,0x6E,0x22,0x29,0x0D, - 0x0A,0x0D,0x0A,0x09,0x70,0x20,0x3D,0x20,0x73,0x74,0x72,0x69,0x6E,0x67,0x2E, - 0x67,0x73,0x75,0x62,0x28,0x70,0x2C,0x20,0x22,0x5C,0x74,0x22,0x2C,0x20,0x22, - 0x22,0x29,0x0D,0x0A,0x09,0x70,0x20,0x3D,0x20,0x73,0x74,0x72,0x69,0x6E,0x67, - 0x2E,0x67,0x73,0x75,0x62,0x28,0x70,0x2C,0x20,0x22,0x25,0x5B,0x73,0x74,0x72, - 0x69,0x6E,0x67,0x20,0x5C,0x22,0x28,0x2E,0x2D,0x29,0x5C,0x22,0x25,0x5D,0x22, - 0x2C,0x20,0x22,0x25,0x31,0x22,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x63, - 0x61,0x6C,0x20,0x66,0x75,0x6E,0x63,0x74,0x69,0x6F,0x6E,0x20,0x64,0x72,0x61, - 0x77,0x28,0x29,0x0D,0x0A,0x09,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61, - 0x70,0x68,0x69,0x63,0x73,0x2E,0x63,0x6C,0x65,0x61,0x72,0x28,0x29,0x0D,0x0A, - 0x09,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73, - 0x2E,0x70,0x72,0x69,0x6E,0x74,0x66,0x28,0x70,0x2C,0x20,0x37,0x30,0x2C,0x20, - 0x37,0x30,0x2C,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69, - 0x63,0x73,0x2E,0x67,0x65,0x74,0x57,0x69,0x64,0x74,0x68,0x28,0x29,0x20,0x2D, - 0x20,0x37,0x30,0x29,0x0D,0x0A,0x09,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72, - 0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x70,0x72,0x65,0x73,0x65,0x6E,0x74,0x28, - 0x29,0x0D,0x0A,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x09,0x64,0x72,0x61, - 0x77,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x65, - 0x2C,0x20,0x61,0x2C,0x20,0x62,0x2C,0x20,0x63,0x0D,0x0A,0x09,0x77,0x68,0x69, - 0x6C,0x65,0x20,0x74,0x72,0x75,0x65,0x20,0x64,0x6F,0x0D,0x0A,0x09,0x09,0x65, - 0x2C,0x20,0x61,0x2C,0x20,0x62,0x2C,0x20,0x63,0x20,0x3D,0x20,0x6C,0x6F,0x76, - 0x65,0x2E,0x65,0x76,0x65,0x6E,0x74,0x2E,0x77,0x61,0x69,0x74,0x28,0x29,0x0D, - 0x0A,0x0D,0x0A,0x09,0x09,0x69,0x66,0x20,0x65,0x20,0x3D,0x3D,0x20,0x22,0x71, - 0x22,0x20,0x74,0x68,0x65,0x6E,0x0D,0x0A,0x09,0x09,0x09,0x72,0x65,0x74,0x75, - 0x72,0x6E,0x0D,0x0A,0x09,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x09,0x09,0x69,0x66, - 0x20,0x65,0x20,0x3D,0x3D,0x20,0x22,0x6B,0x70,0x22,0x20,0x61,0x6E,0x64,0x20, - 0x61,0x20,0x3D,0x3D,0x20,0x22,0x65,0x73,0x63,0x61,0x70,0x65,0x22,0x20,0x74, - 0x68,0x65,0x6E,0x0D,0x0A,0x09,0x09,0x09,0x72,0x65,0x74,0x75,0x72,0x6E,0x0D, - 0x0A,0x09,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x09,0x09,0x64,0x72,0x61, - 0x77,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A, - 0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x0D,0x0A,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, + 0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72, + 0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x73,0x65,0x74,0x52,0x65,0x6E,0x64,0x65, + 0x72,0x54,0x61,0x72,0x67,0x65,0x74,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x2D, + 0x2D,0x20,0x4C,0x6F,0x61,0x64,0x2E,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E, + 0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x73,0x65,0x74,0x53,0x63,0x69, + 0x73,0x73,0x6F,0x72,0x28,0x29,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67, + 0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x73,0x65,0x74,0x42,0x61,0x63,0x6B, + 0x67,0x72,0x6F,0x75,0x6E,0x64,0x43,0x6F,0x6C,0x6F,0x72,0x28,0x38,0x39,0x2C, + 0x20,0x31,0x35,0x37,0x2C,0x20,0x32,0x32,0x30,0x29,0x0D,0x0A,0x09,0x6C,0x6F, + 0x63,0x61,0x6C,0x20,0x66,0x6F,0x6E,0x74,0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65, + 0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x6E,0x65,0x77,0x46,0x6F, + 0x6E,0x74,0x28,0x6C,0x6F,0x76,0x65,0x2E,0x5F,0x76,0x65,0x72,0x61,0x5F,0x74, + 0x74,0x66,0x2C,0x20,0x31,0x34,0x29,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E, + 0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x73,0x65,0x74,0x46,0x6F,0x6E, + 0x74,0x28,0x66,0x6F,0x6E,0x74,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x76, + 0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x73,0x65,0x74,0x43, + 0x6F,0x6C,0x6F,0x72,0x28,0x32,0x35,0x35,0x2C,0x20,0x32,0x35,0x35,0x2C,0x20, + 0x32,0x35,0x35,0x2C,0x20,0x32,0x35,0x35,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C, + 0x6F,0x63,0x61,0x6C,0x20,0x74,0x72,0x61,0x63,0x65,0x20,0x3D,0x20,0x64,0x65, + 0x62,0x75,0x67,0x2E,0x74,0x72,0x61,0x63,0x65,0x62,0x61,0x63,0x6B,0x28,0x29, + 0x0D,0x0A,0x0D,0x0A,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68, + 0x69,0x63,0x73,0x2E,0x63,0x6C,0x65,0x61,0x72,0x28,0x29,0x0D,0x0A,0x0D,0x0A, + 0x09,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x65,0x72,0x72,0x20,0x3D,0x20,0x7B,0x7D, + 0x0D,0x0A,0x0D,0x0A,0x09,0x74,0x61,0x62,0x6C,0x65,0x2E,0x69,0x6E,0x73,0x65, + 0x72,0x74,0x28,0x65,0x72,0x72,0x2C,0x20,0x22,0x45,0x72,0x72,0x6F,0x72,0x5C, + 0x6E,0x22,0x29,0x0D,0x0A,0x09,0x74,0x61,0x62,0x6C,0x65,0x2E,0x69,0x6E,0x73, + 0x65,0x72,0x74,0x28,0x65,0x72,0x72,0x2C,0x20,0x6D,0x73,0x67,0x2E,0x2E,0x22, + 0x5C,0x6E,0x5C,0x6E,0x22,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x66,0x6F,0x72,0x20, + 0x6C,0x20,0x69,0x6E,0x20,0x73,0x74,0x72,0x69,0x6E,0x67,0x2E,0x67,0x6D,0x61, + 0x74,0x63,0x68,0x28,0x74,0x72,0x61,0x63,0x65,0x2C,0x20,0x22,0x28,0x2E,0x2D, + 0x29,0x5C,0x6E,0x22,0x29,0x20,0x64,0x6F,0x0D,0x0A,0x09,0x09,0x69,0x66,0x20, + 0x6E,0x6F,0x74,0x20,0x73,0x74,0x72,0x69,0x6E,0x67,0x2E,0x6D,0x61,0x74,0x63, + 0x68,0x28,0x6C,0x2C,0x20,0x22,0x62,0x6F,0x6F,0x74,0x2E,0x6C,0x75,0x61,0x22, + 0x29,0x20,0x74,0x68,0x65,0x6E,0x0D,0x0A,0x09,0x09,0x09,0x6C,0x20,0x3D,0x20, + 0x73,0x74,0x72,0x69,0x6E,0x67,0x2E,0x67,0x73,0x75,0x62,0x28,0x6C,0x2C,0x20, + 0x22,0x73,0x74,0x61,0x63,0x6B,0x20,0x74,0x72,0x61,0x63,0x65,0x62,0x61,0x63, + 0x6B,0x3A,0x22,0x2C,0x20,0x22,0x54,0x72,0x61,0x63,0x65,0x62,0x61,0x63,0x6B, + 0x5C,0x6E,0x22,0x29,0x0D,0x0A,0x09,0x09,0x09,0x74,0x61,0x62,0x6C,0x65,0x2E, + 0x69,0x6E,0x73,0x65,0x72,0x74,0x28,0x65,0x72,0x72,0x2C,0x20,0x6C,0x29,0x0D, + 0x0A,0x09,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x0D, + 0x0A,0x09,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x70,0x20,0x3D,0x20,0x74,0x61,0x62, + 0x6C,0x65,0x2E,0x63,0x6F,0x6E,0x63,0x61,0x74,0x28,0x65,0x72,0x72,0x2C,0x20, + 0x22,0x5C,0x6E,0x22,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x70,0x20,0x3D,0x20,0x73, + 0x74,0x72,0x69,0x6E,0x67,0x2E,0x67,0x73,0x75,0x62,0x28,0x70,0x2C,0x20,0x22, + 0x5C,0x74,0x22,0x2C,0x20,0x22,0x22,0x29,0x0D,0x0A,0x09,0x70,0x20,0x3D,0x20, + 0x73,0x74,0x72,0x69,0x6E,0x67,0x2E,0x67,0x73,0x75,0x62,0x28,0x70,0x2C,0x20, + 0x22,0x25,0x5B,0x73,0x74,0x72,0x69,0x6E,0x67,0x20,0x5C,0x22,0x28,0x2E,0x2D, + 0x29,0x5C,0x22,0x25,0x5D,0x22,0x2C,0x20,0x22,0x25,0x31,0x22,0x29,0x0D,0x0A, + 0x0D,0x0A,0x09,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x66,0x75,0x6E,0x63,0x74,0x69, + 0x6F,0x6E,0x20,0x64,0x72,0x61,0x77,0x28,0x29,0x0D,0x0A,0x09,0x09,0x6C,0x6F, + 0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x63,0x6C,0x65, + 0x61,0x72,0x28,0x29,0x0D,0x0A,0x09,0x09,0x6C,0x6F,0x76,0x65,0x2E,0x67,0x72, + 0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x70,0x72,0x69,0x6E,0x74,0x66,0x28,0x70, + 0x2C,0x20,0x37,0x30,0x2C,0x20,0x37,0x30,0x2C,0x20,0x6C,0x6F,0x76,0x65,0x2E, + 0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x67,0x65,0x74,0x57,0x69,0x64, + 0x74,0x68,0x28,0x29,0x20,0x2D,0x20,0x37,0x30,0x29,0x0D,0x0A,0x09,0x09,0x6C, + 0x6F,0x76,0x65,0x2E,0x67,0x72,0x61,0x70,0x68,0x69,0x63,0x73,0x2E,0x70,0x72, + 0x65,0x73,0x65,0x6E,0x74,0x28,0x29,0x0D,0x0A,0x09,0x65,0x6E,0x64,0x0D,0x0A, + 0x0D,0x0A,0x09,0x64,0x72,0x61,0x77,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x6C, + 0x6F,0x63,0x61,0x6C,0x20,0x65,0x2C,0x20,0x61,0x2C,0x20,0x62,0x2C,0x20,0x63, + 0x0D,0x0A,0x09,0x77,0x68,0x69,0x6C,0x65,0x20,0x74,0x72,0x75,0x65,0x20,0x64, + 0x6F,0x0D,0x0A,0x09,0x09,0x65,0x2C,0x20,0x61,0x2C,0x20,0x62,0x2C,0x20,0x63, + 0x20,0x3D,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x65,0x76,0x65,0x6E,0x74,0x2E,0x77, + 0x61,0x69,0x74,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x09,0x69,0x66,0x20,0x65, + 0x20,0x3D,0x3D,0x20,0x22,0x71,0x22,0x20,0x74,0x68,0x65,0x6E,0x0D,0x0A,0x09, + 0x09,0x09,0x72,0x65,0x74,0x75,0x72,0x6E,0x0D,0x0A,0x09,0x09,0x65,0x6E,0x64, + 0x0D,0x0A,0x09,0x09,0x69,0x66,0x20,0x65,0x20,0x3D,0x3D,0x20,0x22,0x6B,0x70, + 0x22,0x20,0x61,0x6E,0x64,0x20,0x61,0x20,0x3D,0x3D,0x20,0x22,0x65,0x73,0x63, + 0x61,0x70,0x65,0x22,0x20,0x74,0x68,0x65,0x6E,0x0D,0x0A,0x09,0x09,0x09,0x72, + 0x65,0x74,0x75,0x72,0x6E,0x0D,0x0A,0x09,0x09,0x65,0x6E,0x64,0x0D,0x0A,0x0D, + 0x0A,0x09,0x09,0x64,0x72,0x61,0x77,0x28,0x29,0x0D,0x0A,0x0D,0x0A,0x09,0x65, + 0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x65,0x6E,0x64,0x0D,0x0A,0x0D,0x0A,0x0D,0x0A, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, - 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x0D,0x0A,0x2D,0x2D,0x20,0x54,0x68, - 0x65,0x20,0x72,0x6F,0x6F,0x74,0x20,0x6F,0x66,0x20,0x61,0x6C,0x6C,0x20,0x63, - 0x61,0x6C,0x6C,0x73,0x2E,0x0D,0x0A,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, + 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x0D, + 0x0A,0x2D,0x2D,0x20,0x54,0x68,0x65,0x20,0x72,0x6F,0x6F,0x74,0x20,0x6F,0x66, + 0x20,0x61,0x6C,0x6C,0x20,0x63,0x61,0x6C,0x6C,0x73,0x2E,0x0D,0x0A,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D, - 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x0D,0x0A,0x0D,0x0A,0x6C,0x6F,0x63,0x61,0x6C, + 0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x2D,0x0D,0x0A,0x0D, + 0x0A,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x72,0x65,0x73,0x75,0x6C,0x74,0x20,0x3D, + 0x20,0x78,0x70,0x63,0x61,0x6C,0x6C,0x28,0x6C,0x6F,0x76,0x65,0x2E,0x62,0x6F, + 0x6F,0x74,0x2C,0x20,0x65,0x72,0x72,0x6F,0x72,0x5F,0x70,0x72,0x69,0x6E,0x74, + 0x65,0x72,0x29,0x0D,0x0A,0x69,0x66,0x20,0x6E,0x6F,0x74,0x20,0x72,0x65,0x73, + 0x75,0x6C,0x74,0x20,0x74,0x68,0x65,0x6E,0x20,0x72,0x65,0x74,0x75,0x72,0x6E, + 0x20,0x65,0x6E,0x64,0x0D,0x0A,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x72,0x65,0x73, + 0x75,0x6C,0x74,0x20,0x3D,0x20,0x78,0x70,0x63,0x61,0x6C,0x6C,0x28,0x6C,0x6F, + 0x76,0x65,0x2E,0x69,0x6E,0x69,0x74,0x2C,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x65, + 0x72,0x72,0x68,0x61,0x6E,0x64,0x29,0x0D,0x0A,0x69,0x66,0x20,0x6E,0x6F,0x74, + 0x20,0x72,0x65,0x73,0x75,0x6C,0x74,0x20,0x74,0x68,0x65,0x6E,0x20,0x72,0x65, + 0x74,0x75,0x72,0x6E,0x20,0x65,0x6E,0x64,0x0D,0x0A,0x6C,0x6F,0x63,0x61,0x6C, 0x20,0x72,0x65,0x73,0x75,0x6C,0x74,0x20,0x3D,0x20,0x78,0x70,0x63,0x61,0x6C, - 0x6C,0x28,0x6C,0x6F,0x76,0x65,0x2E,0x62,0x6F,0x6F,0x74,0x2C,0x20,0x65,0x72, - 0x72,0x6F,0x72,0x5F,0x70,0x72,0x69,0x6E,0x74,0x65,0x72,0x29,0x0D,0x0A,0x69, - 0x66,0x20,0x6E,0x6F,0x74,0x20,0x72,0x65,0x73,0x75,0x6C,0x74,0x20,0x74,0x68, - 0x65,0x6E,0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,0x65,0x6E,0x64,0x0D,0x0A, - 0x6C,0x6F,0x63,0x61,0x6C,0x20,0x72,0x65,0x73,0x75,0x6C,0x74,0x20,0x3D,0x20, - 0x78,0x70,0x63,0x61,0x6C,0x6C,0x28,0x6C,0x6F,0x76,0x65,0x2E,0x69,0x6E,0x69, - 0x74,0x2C,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x65,0x72,0x72,0x68,0x61,0x6E,0x64, - 0x29,0x0D,0x0A,0x69,0x66,0x20,0x6E,0x6F,0x74,0x20,0x72,0x65,0x73,0x75,0x6C, - 0x74,0x20,0x74,0x68,0x65,0x6E,0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,0x65, - 0x6E,0x64,0x0D,0x0A,0x6C,0x6F,0x63,0x61,0x6C,0x20,0x72,0x65,0x73,0x75,0x6C, - 0x74,0x20,0x3D,0x20,0x78,0x70,0x63,0x61,0x6C,0x6C,0x28,0x6C,0x6F,0x76,0x65, - 0x2E,0x72,0x75,0x6E,0x2C,0x20,0x6C,0x6F,0x76,0x65,0x2E,0x65,0x72,0x72,0x68, - 0x61,0x6E,0x64,0x29,0x0D,0x0A,0x69,0x66,0x20,0x6E,0x6F,0x74,0x20,0x72,0x65, - 0x73,0x75,0x6C,0x74,0x20,0x74,0x68,0x65,0x6E,0x20,0x72,0x65,0x74,0x75,0x72, - 0x6E,0x20,0x65,0x6E,0x64,0x0D,0x0A, + 0x6C,0x28,0x6C,0x6F,0x76,0x65,0x2E,0x72,0x75,0x6E,0x2C,0x20,0x6C,0x6F,0x76, + 0x65,0x2E,0x65,0x72,0x72,0x68,0x61,0x6E,0x64,0x29,0x0D,0x0A,0x69,0x66,0x20, + 0x6E,0x6F,0x74,0x20,0x72,0x65,0x73,0x75,0x6C,0x74,0x20,0x74,0x68,0x65,0x6E, + 0x20,0x72,0x65,0x74,0x75,0x72,0x6E,0x20,0x65,0x6E,0x64,0x0D,0x0A, }; // [/boot.lua] From 639eca997d6a34afe18d55b2b72d7481beb76270 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Fri, 3 Sep 2010 15:30:13 +0200 Subject: [PATCH 20/20] Fixed two cases of inefficient usage of the lua api --- src/modules/graphics/opengl/wrap_Graphics.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 33d3aaf38..38e1c691c 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -295,12 +295,8 @@ namespace opengl int w_newFramebuffer(lua_State * L) { // check if width and height are given. else default to screen dimensions. - int width = instance->getWidth(); - int height = instance->getHeight(); - if (lua_gettop(L) >= 2) { - width = luaL_optint(L, 1, instance->getWidth()); - height = luaL_optint(L, 2, instance->getHeight()); - } + int width = luaL_optint(L, 1, instance->getWidth()); + int height = luaL_optint(L, 2, instance->getHeight()); glGetError(); // clear opengl error flag Framebuffer * framebuffer = instance->newFramebuffer(width, height); @@ -614,7 +610,7 @@ namespace opengl int w_setRenderTarget(lua_State * L) { // called with nil or none -> reset to default buffer - if (lua_isnone(L,1) || lua_isnil(L, 1)) { + if (lua_isnoneornil(L,1)) { Framebuffer::bindDefaultBuffer(); return 0; }