From f0fa63ba472fb5e346f9f5aeaaa51bd331aa3e65 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 17 Jun 2014 21:52:56 -0300 Subject: [PATCH 1/6] Backported commits 145524a and 7785b4b from minor into default (Added SpriteBatch:flush, deprecated SpriteBatch:bind/unbind, SpriteBatch:flush is called implicitly when the spritebatch is drawn.) --- src/modules/graphics/opengl/SpriteBatch.cpp | 59 +++++++------ src/modules/graphics/opengl/SpriteBatch.h | 7 +- src/modules/graphics/opengl/VertexBuffer.cpp | 85 +++++++++---------- src/modules/graphics/opengl/VertexBuffer.h | 18 +++- .../graphics/opengl/wrap_SpriteBatch.cpp | 17 ++-- .../graphics/opengl/wrap_SpriteBatch.h | 2 +- 6 files changed, 104 insertions(+), 84 deletions(-) diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index 8b311f514..b59618ee3 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -46,8 +46,10 @@ SpriteBatch::SpriteBatch(Texture *texture, int size, int usage) , size(size) , next(0) , color(0) - , array_buf(0) - , element_buf(0) + , array_buf(nullptr) + , element_buf(nullptr) + , buffer_used_offset(0) + , buffer_used_size(0) { if (size <= 0) throw love::Exception("Invalid SpriteBatch size."); @@ -160,18 +162,12 @@ void SpriteBatch::clear() next = 0; } -void *SpriteBatch::lock() +void SpriteBatch::flush() { VertexBuffer::Bind bind(*array_buf); + array_buf->unmap(buffer_used_offset, buffer_used_size); - return array_buf->map(); -} - -void SpriteBatch::unlock() -{ - VertexBuffer::Bind bind(*array_buf); - - array_buf->unmap(); + buffer_used_offset = buffer_used_size = 0; } void SpriteBatch::setTexture(Texture *newtexture) @@ -220,33 +216,31 @@ void SpriteBatch::setBufferSize(int newsize) return; // Map (lock) the old VertexBuffer to get a pointer to its data. - void *old_data = lock(); + void *old_data = nullptr; + { + VertexBuffer::Bind bind(*array_buf); + old_data = array_buf->map(); + } size_t vertex_size = sizeof(Vertex) * 4 * newsize; - VertexBuffer *new_array_buf = 0; - VertexIndex *new_element_buf = 0; - void *new_data = 0; + VertexBuffer *new_array_buf = nullptr; + VertexIndex *new_element_buf = nullptr; try { new_array_buf = VertexBuffer::Create(vertex_size, array_buf->getTarget(), array_buf->getUsage()); new_element_buf = new VertexIndex(newsize); - - // VBO::map can throw an exception. Also we want to scope the bind. - VertexBuffer::Bind bind(*new_array_buf); - new_data = new_array_buf->map(); } catch (love::Exception &) { delete new_array_buf; delete new_element_buf; - unlock(); throw; } // Copy as much of the old data into the new VertexBuffer as can fit. - memcpy(new_data, old_data, sizeof(Vertex) * 4 * std::min(newsize, size)); + new_array_buf->fill(0, sizeof(Vertex) * 4 * std::min(newsize, size), old_data); // We don't need to unmap the old VertexBuffer since we're deleting it. delete array_buf; @@ -258,8 +252,8 @@ void SpriteBatch::setBufferSize(int newsize) next = std::min(next, newsize); - // But we should unmap (unlock) the new one! - unlock(); + // The new VertexBuffer isn't mapped, so we should reset these variables. + buffer_used_offset = buffer_used_size = 0; } int SpriteBatch::getBufferSize() const @@ -269,7 +263,7 @@ int SpriteBatch::getBufferSize() const void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) { - const size_t vertex_offset = offsetof(Vertex, x); + const size_t pos_offset = offsetof(Vertex, x); const size_t texel_offset = offsetof(Vertex, s); const size_t color_offset = offsetof(Vertex, r); @@ -288,6 +282,10 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float VertexBuffer::Bind array_bind(*array_buf); VertexBuffer::Bind element_bind(*element_buf->getVertexBuffer()); + // Make sure the VBO isn't mapped when we draw (sends data to GPU if needed.) + array_buf->unmap(buffer_used_offset, buffer_used_size); + buffer_used_offset = buffer_used_size = 0; + Color curcolor = gl.getColor(); // Apply per-sprite color, if a color is set. @@ -298,7 +296,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float } glEnableClientState(GL_VERTEX_ARRAY); - glVertexPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(vertex_offset)); + glVertexPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(pos_offset)); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), array_buf->getPointer(texel_offset)); @@ -322,9 +320,18 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float void SpriteBatch::addv(const Vertex *v, int index) { - static const int sprite_size = 4 * sizeof(Vertex); // bytecount + static const size_t sprite_size = 4 * sizeof(Vertex); // bytecount + VertexBuffer::Bind bind(*array_buf); + + // Always keep the VBO mapped when adding data for now (it'll be unmapped + // on draw.) + array_buf->map(); + array_buf->fill(index * sprite_size, sprite_size, v); + + buffer_used_offset = std::min(buffer_used_offset, index * sprite_size); + buffer_used_size = std::max(buffer_used_size, (index + 1) * sprite_size - buffer_used_offset); } void SpriteBatch::setColorv(Vertex *v, const Color &color) diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h index 6f87f8fa5..1f3de1c99 100644 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ b/src/modules/graphics/opengl/SpriteBatch.h @@ -65,8 +65,7 @@ public: int addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1); void clear(); - void *lock(); - void unlock(); + void flush(); void setTexture(Texture *newtexture); Texture *getTexture(); @@ -142,6 +141,10 @@ private: VertexBuffer *array_buf; VertexIndex *element_buf; + // The portion of the vertex buffer that's been modified while mapped. + size_t buffer_used_offset; + size_t buffer_used_size; + static StringMap::Entry usageHintEntries[]; static StringMap usageHints; diff --git a/src/modules/graphics/opengl/VertexBuffer.cpp b/src/modules/graphics/opengl/VertexBuffer.cpp index d0e8c0f2f..9ec772865 100644 --- a/src/modules/graphics/opengl/VertexBuffer.cpp +++ b/src/modules/graphics/opengl/VertexBuffer.cpp @@ -89,7 +89,7 @@ void *VertexArray::map() return buf; } -void VertexArray::unmap() +void VertexArray::unmap(size_t /*usedOffset*/, size_t /*usedSize*/) { is_mapped = false; } @@ -119,14 +119,14 @@ const void *VertexArray::getPointer(size_t offset) const VBO::VBO(size_t size, GLenum target, GLenum usage, MemoryBacking backing) : VertexBuffer(size, target, usage, backing) , vbo(0) - , memory_map(0) + , memory_map(nullptr) , is_dirty(true) { if (!(GLEE_ARB_vertex_buffer_object || GLEE_VERSION_1_5)) throw love::Exception("Not supported"); if (getMemoryBacking() == BACKING_FULL) - memory_map = malloc(getSize()); + memory_map = (char *) malloc(getSize()); bool ok = load(false); @@ -153,7 +153,7 @@ void *VBO::map() if (!memory_map) { - memory_map = malloc(getSize()); + memory_map = (char * ) malloc(getSize()); if (!memory_map) throw love::Exception("Out of memory (oh the humanity!)"); } @@ -169,11 +169,28 @@ void *VBO::map() return memory_map; } -void VBO::unmap() +void VBO::unmapStatic(size_t offset, size_t size) +{ + // Upload the mapped data to the buffer. + glBufferSubDataARB(getTarget(), (GLintptr) offset, (GLsizeiptr) size, memory_map + offset); +} + +void VBO::unmapStream() +{ + // "orphan" current buffer to avoid implicit synchronisation on the GPU: + // http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf + glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), nullptr, getUsage()); + glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage()); +} + +void VBO::unmap(size_t usedOffset, size_t usedSize) { if (!is_mapped) return; + usedOffset = std::min(usedOffset, getSize()); + usedSize = std::min(usedSize, getSize() - usedOffset); + // VBO::bind is a no-op when the VBO is mapped, so we have to make sure it's // bound here. if (!is_bound) @@ -182,17 +199,23 @@ void VBO::unmap() is_bound = true; } - if (getUsage() == GL_STATIC_DRAW) + switch (getUsage()) { - // Upload the mapped data to the buffer. - glBufferSubDataARB(getTarget(), 0, (GLsizeiptr) getSize(), memory_map); - } - else - { - // "orphan" current buffer to avoid implicit synchronisation on the GPU: - // http://www.seas.upenn.edu/~pcozzi/OpenGLInsights/OpenGLInsights-AsynchronousBufferTransfers.pdf - glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), NULL, getUsage()); - glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), memory_map, getUsage()); + case GL_STATIC_DRAW: + unmapStatic(usedOffset, usedSize); + break; + case GL_STREAM_DRAW: + unmapStream(); + break; + case GL_DYNAMIC_DRAW: + default: + // It's probably more efficient to treat it like a streaming buffer if + // more than a third of its contents have been modified during the map(). + if (usedSize >= getSize() / 3) + unmapStream(); + else + unmapStatic(usedOffset, usedSize); + break; } is_mapped = false; @@ -218,31 +241,11 @@ void VBO::unbind() void VBO::fill(size_t offset, size_t size, const void *data) { if (is_mapped || getMemoryBacking() == BACKING_FULL) - memcpy(static_cast(memory_map) + offset, data, size); + memcpy(memory_map + offset, data, size); if (!is_mapped) { - // Not all systems have access to some faster paths... - if (GLEE_APPLE_flush_buffer_range) - { - void *mapdata = glMapBufferARB(getTarget(), GL_WRITE_ONLY); - - if (mapdata) - { - // We specified in VBO::load that we'll do manual flushing. - // Now we tell the driver it only needs to deal with the data - // we changed. - memcpy(static_cast(mapdata) + offset, data, size); - glFlushMappedBufferRangeAPPLE(getTarget(), (GLintptr) offset, (GLsizei) size); - } - - glUnmapBufferARB(getTarget()); - } - else - { - // Fall back to a possibly slower SubData (more chance of syncing.) - glBufferSubDataARB(getTarget(), (GLintptr) offset, (GLsizeiptr) size, data); - } + glBufferSubDataARB(getTarget(), (GLintptr) offset, (GLsizeiptr) size, data); if (getMemoryBacking() != BACKING_FULL) is_dirty = true; @@ -271,17 +274,11 @@ bool VBO::load(bool restore) VertexBuffer::Bind bind(*this); // Copy the old buffer only if 'restore' was requested. - const GLvoid *src = restore ? memory_map : 0; + const GLvoid *src = restore ? memory_map : nullptr; while (GL_NO_ERROR != glGetError()) /* clear error messages */; - // We don't want to flush the entire buffer when we just modify a small - // portion of it (VBO::fill without VBO::map), so we'll handle the flushing - // ourselves when we can. - if (GLEE_APPLE_flush_buffer_range) - glBufferParameteriAPPLE(getTarget(), GL_BUFFER_FLUSHING_UNMAP_APPLE, GL_FALSE); - // Note that if 'src' is '0', no data will be copied. glBufferDataARB(getTarget(), (GLsizeiptr) getSize(), src, getUsage()); GLenum err = glGetError(); diff --git a/src/modules/graphics/opengl/VertexBuffer.h b/src/modules/graphics/opengl/VertexBuffer.h index d29710cc4..cfaa42db1 100644 --- a/src/modules/graphics/opengl/VertexBuffer.h +++ b/src/modules/graphics/opengl/VertexBuffer.h @@ -28,6 +28,9 @@ // OpenGL #include "OpenGL.h" +// C +#include + namespace love { namespace graphics @@ -152,8 +155,12 @@ public: * when used to draw elements. * * The VertexBuffer must be bound to use this function. + * + * @param usedOffset The offset into the mapped buffer indicating the + * sub-range of data modified. Optional. + * @param usedSize The size of the sub-range of modified data. Optional. */ - virtual void unmap() = 0; + virtual void unmap(size_t usedOffset = 0, size_t usedSize = -1) = 0; /** * Bind the VertexBuffer to its specified target. @@ -294,7 +301,7 @@ public: // Implements VertexBuffer. virtual void *map(); - virtual void unmap(); + virtual void unmap(size_t usedOffset = 0, size_t usedSize = -1); virtual void bind(); virtual void unbind(); virtual void fill(size_t offset, size_t size, const void *data); @@ -328,7 +335,7 @@ public: // Implements VertexBuffer. virtual void *map(); - virtual void unmap(); + virtual void unmap(size_t usedOffset = 0, size_t usedSize = -1); virtual void bind(); virtual void unbind(); virtual void fill(size_t offset, size_t size, const void *data); @@ -355,12 +362,15 @@ private: */ void unload(bool save); + void unmapStatic(size_t offset, size_t size); + void unmapStream(); + // The VBO identifier. Assigned by OpenGL. GLuint vbo; // A pointer to mapped memory. Will be inialized on the first // call to map(). - void *memory_map; + char *memory_map; // Set if the buffer was modified while operating on gpu memory // and needs to be synchronized. diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp index 1200743e8..97d2675e8 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp @@ -118,17 +118,16 @@ int w_SpriteBatch_clear(lua_State *L) return 0; } -int w_SpriteBatch_bind(lua_State *L) +int w_SpriteBatch_bind(lua_State* /*L*/) { - SpriteBatch *t = luax_checkspritebatch(L, 1); - luax_catchexcept(L, [&](){ t->lock(); }); + // No-op (deprecated.) return 0; } -int w_SpriteBatch_unbind(lua_State *L) +int w_SpriteBatch_flush(lua_State *L) { SpriteBatch *t = luax_checkspritebatch(L, 1); - t->unlock(); + t->flush(); return 0; } @@ -239,8 +238,7 @@ static const luaL_Reg functions[] = { "add", w_SpriteBatch_add }, { "set", w_SpriteBatch_set }, { "clear", w_SpriteBatch_clear }, - { "bind", w_SpriteBatch_bind }, - { "unbind", w_SpriteBatch_unbind }, + { "flush", w_SpriteBatch_flush }, { "setTexture", w_SpriteBatch_setTexture }, { "getTexture", w_SpriteBatch_getTexture }, { "setColor", w_SpriteBatch_setColor }, @@ -252,6 +250,11 @@ static const luaL_Reg functions[] = // Deprecated since 0.9.1. { "setImage", w_SpriteBatch_setTexture }, { "getImage", w_SpriteBatch_getTexture }, + + // Deprecated since 0.9.2. + { "bind", w_SpriteBatch_bind }, + { "unbind", w_SpriteBatch_flush }, + { 0, 0 } }; diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.h b/src/modules/graphics/opengl/wrap_SpriteBatch.h index 76828b8f2..f40d588e5 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.h +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.h @@ -38,7 +38,7 @@ int w_SpriteBatch_set(lua_State *L); int w_SpriteBatch_setg(lua_State *L); int w_SpriteBatch_clear(lua_State *L); int w_SpriteBatch_bind(lua_State *L); -int w_SpriteBatch_unbind(lua_State *L); +int w_SpriteBatch_flush(lua_State *L); int w_SpriteBatch_setTexture(lua_State *L); int w_SpriteBatch_getTexture(lua_State *L); int w_SpriteBatch_setColor(lua_State *L); From c5d59107ad27de8651f2474ef18eb0b47a9ab3a5 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Wed, 18 Jun 2014 10:59:32 +0200 Subject: [PATCH 2/6] Modify desktop file to play nicer with file associations in newer versions of nautilus (gnome file browser) --- platform/unix/love.desktop.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/unix/love.desktop.in b/platform/unix/love.desktop.in index 3a9e2df12..94c9bb418 100644 --- a/platform/unix/love.desktop.in +++ b/platform/unix/love.desktop.in @@ -2,7 +2,7 @@ Name=LÖVE Comment=The unquestionably awesome 2D game engine MimeType=application/x-love-game; -Exec=@bindir@/love +Exec=@bindir@/love %f Type=Application Categories=Development;Game; Terminal=false From fb3aa060b2e45fb634c747855d3c646546b7ece4 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Wed, 18 Jun 2014 14:34:05 +0200 Subject: [PATCH 3/6] Fix Texture leak in Meshes --- src/modules/graphics/opengl/Mesh.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/graphics/opengl/Mesh.cpp b/src/modules/graphics/opengl/Mesh.cpp index 7d38a5710..ec79b4b2c 100644 --- a/src/modules/graphics/opengl/Mesh.cpp +++ b/src/modules/graphics/opengl/Mesh.cpp @@ -79,6 +79,9 @@ Mesh::Mesh(int vertexcount, Mesh::DrawMode mode) Mesh::~Mesh() { + if (texture) + texture->release(); + delete vbo; delete ibo; } From 2ae4e9cd5ae4a09318784f4a6a1ccfa620d453b0 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 18 Jun 2014 16:24:38 -0300 Subject: [PATCH 4/6] Fixed a potential memory leak in the love.physics World callbacks. --- src/modules/physics/box2d/World.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/physics/box2d/World.cpp b/src/modules/physics/box2d/World.cpp index bf6f6ee1b..400772ffd 100644 --- a/src/modules/physics/box2d/World.cpp +++ b/src/modules/physics/box2d/World.cpp @@ -131,6 +131,8 @@ bool World::ContactFilter::process(Fixture *a, Fixture *b) if (ref != 0) { + a->retain(); + b->retain(); lua_State *L = ref->getL(); ref->push(); luax_pushtype(L, "Fixture", PHYSICS_FIXTURE_T, a); @@ -318,11 +320,9 @@ bool World::ShouldCollide(b2Fixture *fixtureA, b2Fixture *fixtureB) Fixture *a = (Fixture *)Memoizer::find(fixtureA); if (!a) throw love::Exception("A fixture has escaped Memoizer!"); - a->retain(); Fixture *b = (Fixture *)Memoizer::find(fixtureB); if (!b) throw love::Exception("A fixture has escaped Memoizer!"); - b->retain(); return filter.process(a, b); } From 738cc0146810764c0a3501625dd5f12c33ebd2f2 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Wed, 18 Jun 2014 19:05:43 -0300 Subject: [PATCH 5/6] Increased version to 0.9.2. --- extra/windows/love.rc | Bin 3468 -> 3468 bytes platform/macosx/Info-Framework.plist | 4 ++-- platform/macosx/love-Info.plist | 2 +- src/common/version.h | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/extra/windows/love.rc b/extra/windows/love.rc index 8b5d9fb92b178185e314738c0bf529c9d2b8a491..8493de94e195a46395e7a71aadc92b4936f8b98a 100644 GIT binary patch delta 32 ocmeB??vdW0#=>YcS&&tH@&;zE$$!|mCI_)3FdA*%%yN?h0Gi_o(f|Me delta 32 ocmeB??vdW0#=>YgS&&tH@&;zE$$!|mCI_)3FdA;&%yN?h0Gh=K&;S4c diff --git a/platform/macosx/Info-Framework.plist b/platform/macosx/Info-Framework.plist index 9ac7b9f46..d2104642e 100644 --- a/platform/macosx/Info-Framework.plist +++ b/platform/macosx/Info-Framework.plist @@ -17,11 +17,11 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 0.9.1 + 0.9.2 CFBundleSignature LoVe CFBundleVersion - 0.9.1 + 0.9.2 NSPrincipalClass diff --git a/platform/macosx/love-Info.plist b/platform/macosx/love-Info.plist index c7585e930..3dbad5b89 100644 --- a/platform/macosx/love-Info.plist +++ b/platform/macosx/love-Info.plist @@ -46,7 +46,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.9.1 + 0.9.2 CFBundleSignature LoVe LSApplicationCategoryType diff --git a/src/common/version.h b/src/common/version.h index 5e3e15f72..68b5f6b9d 100644 --- a/src/common/version.h +++ b/src/common/version.h @@ -27,9 +27,9 @@ namespace love // Version stuff. const int VERSION_MAJOR = 0; const int VERSION_MINOR = 9; -const int VERSION_REV = 1; -const char *VERSION = "0.9.1"; -const char *VERSION_COMPATIBILITY[] = { VERSION, "0.9.0", 0 }; +const int VERSION_REV = 2; +const char *VERSION = "0.9.2"; +const char *VERSION_COMPATIBILITY[] = { VERSION, "0.9.1", "0.9.0", 0 }; const char *VERSION_CODENAME = "Baby Inspector"; } // love From 4c67a94ba313dbd823364fc542feaa6048fe2a39 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 19 Jun 2014 03:02:37 -0300 Subject: [PATCH 6/6] Hopefully fixed issue #898, and cleaned up code for love.graphics.getRendererInfo. --- src/modules/graphics/Graphics.cpp | 20 --------- src/modules/graphics/Graphics.h | 26 +++++------- src/modules/graphics/opengl/Graphics.cpp | 41 +++++++++---------- src/modules/graphics/opengl/Graphics.h | 7 ++-- src/modules/graphics/opengl/VertexBuffer.cpp | 1 - src/modules/graphics/opengl/VertexBuffer.h | 1 + src/modules/graphics/opengl/wrap_Canvas.cpp | 5 ++- src/modules/graphics/opengl/wrap_Graphics.cpp | 19 +++------ 8 files changed, 45 insertions(+), 75 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 76c96b54c..1b86bcdee 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -99,16 +99,6 @@ bool Graphics::getConstant(Support in, const char *&out) return support.find(in, out); } -bool Graphics::getConstant(const char *in, RendererInfo &out) -{ - return rendererInfo.find(in, out); -} - -bool Graphics::getConstant(RendererInfo in, const char *&out) -{ - return rendererInfo.find(in, out); -} - bool Graphics::getConstant(const char *in, SystemLimit &out) { return systemLimits.find(in, out); @@ -192,16 +182,6 @@ StringMap::Entry Graphics::suppor StringMap Graphics::support(Graphics::supportEntries, sizeof(Graphics::supportEntries)); -StringMap::Entry Graphics::rendererInfoEntries[] = -{ - { "name", Graphics::RENDERER_INFO_NAME }, - { "version", Graphics::RENDERER_INFO_VERSION }, - { "vendor", Graphics::RENDERER_INFO_VENDOR }, - { "device", Graphics::RENDERER_INFO_DEVICE }, -}; - -StringMap Graphics::rendererInfo(Graphics::rendererInfoEntries, sizeof(Graphics::rendererInfoEntries)); - StringMap::Entry Graphics::systemLimitEntries[] = { {"pointsize", Graphics::LIMIT_POINT_SIZE}, diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index caafdcd92..715abe36b 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -25,6 +25,9 @@ #include "common/Module.h" #include "common/StringMap.h" +// C++ +#include + namespace love { namespace graphics @@ -100,15 +103,6 @@ public: SUPPORT_MAX_ENUM }; - enum RendererInfo - { - RENDERER_INFO_NAME, - RENDERER_INFO_VERSION, - RENDERER_INFO_VENDOR, - RENDERER_INFO_DEVICE, - RENDERER_INFO_MAX_ENUM - }; - enum SystemLimit { LIMIT_POINT_SIZE, @@ -119,6 +113,14 @@ public: LIMIT_MAX_ENUM }; + struct RendererInfo + { + std::string name; + std::string version; + std::string vendor; + std::string device; + }; + virtual ~Graphics(); /** @@ -160,9 +162,6 @@ public: static bool getConstant(const char *in, Support &out); static bool getConstant(Support in, const char *&out); - static bool getConstant(const char *in, RendererInfo &out); - static bool getConstant(RendererInfo in, const char *&out); - static bool getConstant(const char *in, SystemLimit &out); static bool getConstant(SystemLimit in, const char *&out); @@ -189,9 +188,6 @@ private: static StringMap::Entry supportEntries[]; static StringMap support; - static StringMap::Entry rendererInfoEntries[]; - static StringMap rendererInfo; - static StringMap::Entry systemLimitEntries[]; static StringMap systemLimits; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 09e8c8301..728a0c195 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1061,31 +1061,30 @@ love::image::ImageData *Graphics::newScreenshot(love::image::Image *image, bool return img; } -std::string Graphics::getRendererInfo(Graphics::RendererInfo infotype) const +Graphics::RendererInfo Graphics::getRendererInfo() const { - const char *infostr = 0; + RendererInfo info; + info.name = "OpenGL"; - switch (infotype) - { - case Graphics::RENDERER_INFO_NAME: - default: - infostr = "OpenGL"; - break; - case Graphics::RENDERER_INFO_VERSION: - infostr = (const char *) glGetString(GL_VERSION); - break; - case Graphics::RENDERER_INFO_VENDOR: - infostr = (const char *) glGetString(GL_VENDOR); - break; - case Graphics::RENDERER_INFO_DEVICE: - infostr = (const char *) glGetString(GL_RENDERER); - break; - } + const char *str = (const char *) glGetString(GL_VERSION); + if (str) + info.version = str; + else + throw love::Exception("Cannot retrieve renderer version information."); - if (!infostr) - throw love::Exception("Cannot retrieve renderer information."); + str = (const char *) glGetString(GL_VENDOR); + if (str) + info.vendor = str; + else + throw love::Exception("Cannot retrieve renderer vendor information."); - return std::string(infostr); + str = (const char *) glGetString(GL_RENDERER); + if (str) + info.device = str; + else + throw love::Exception("Cannot retrieve renderer device information."); + + return info; } double Graphics::getSystemLimit(SystemLimit limittype) const diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index f21aa2801..b2ba4dfe2 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -444,12 +444,11 @@ public: love::image::ImageData *newScreenshot(love::image::Image *image, bool copyAlpha = true); /** - * Returns a string containing system-dependent renderer information. - * Returned string can vary greatly between systems! Do not rely on it for + * Returns system-dependent renderer information. + * Returned string s can vary greatly between systems! Do not rely on it for * anything! - * @param infotype The type of information to return. **/ - std::string getRendererInfo(Graphics::RendererInfo infotype) const; + RendererInfo getRendererInfo() const; /** * Gets the system-dependent numeric limit for the specified parameter. diff --git a/src/modules/graphics/opengl/VertexBuffer.cpp b/src/modules/graphics/opengl/VertexBuffer.cpp index 9ec772865..43c9282f9 100644 --- a/src/modules/graphics/opengl/VertexBuffer.cpp +++ b/src/modules/graphics/opengl/VertexBuffer.cpp @@ -21,7 +21,6 @@ #include "VertexBuffer.h" #include "common/Exception.h" -#include "common/config.h" #include #include diff --git a/src/modules/graphics/opengl/VertexBuffer.h b/src/modules/graphics/opengl/VertexBuffer.h index cfaa42db1..dc207e777 100644 --- a/src/modules/graphics/opengl/VertexBuffer.h +++ b/src/modules/graphics/opengl/VertexBuffer.h @@ -23,6 +23,7 @@ #define LOVE_GRAPHICS_OPENGL_VERTEX_BUFFER_H // LOVE +#include "common/config.h" #include "graphics/Volatile.h" // OpenGL diff --git a/src/modules/graphics/opengl/wrap_Canvas.cpp b/src/modules/graphics/opengl/wrap_Canvas.cpp index a145305c6..8d00e4dbe 100644 --- a/src/modules/graphics/opengl/wrap_Canvas.cpp +++ b/src/modules/graphics/opengl/wrap_Canvas.cpp @@ -146,10 +146,13 @@ static const luaL_Reg functions[] = { "clear", w_Canvas_clear }, { "getFormat", w_Canvas_getFormat }, { "getMSAA", w_Canvas_getMSAA }, - { "getFSAA", w_Canvas_getMSAA }, // For backward-compatibility. TODO: remove! // Deprecated since 0.9.1. { "getType", w_Canvas_getFormat }, + + // Deprecated since 0.9.2. + { "getFSAA", w_Canvas_getMSAA }, + { 0, 0 } }; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index 877867c93..d64f939d4 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -1067,20 +1067,13 @@ int w_hasCanvasFormat(lua_State *L) int w_getRendererInfo(lua_State *L) { - std::string name, version, vendor, device; - - luax_catchexcept(L, [&]() { - name = instance->getRendererInfo(Graphics::RENDERER_INFO_NAME); - version = instance->getRendererInfo(Graphics::RENDERER_INFO_VERSION); - vendor = instance->getRendererInfo(Graphics::RENDERER_INFO_VENDOR); - device = instance->getRendererInfo(Graphics::RENDERER_INFO_DEVICE); - }); - - luax_pushstring(L, name); - luax_pushstring(L, version); - luax_pushstring(L, vendor); - luax_pushstring(L, device); + Graphics::RendererInfo info; + luax_catchexcept(L, [&](){ info = instance->getRendererInfo(); }); + luax_pushstring(L, info.name); + luax_pushstring(L, info.version); + luax_pushstring(L, info.vendor); + luax_pushstring(L, info.device); return 4; }