diff --git a/CMakeLists.txt b/CMakeLists.txt index ed71c08e6..2561fded5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -506,6 +506,8 @@ set(LOVE_SRC_MODULE_GRAPHICS_ROOT src/modules/graphics/wrap_Canvas.h src/modules/graphics/wrap_Font.cpp src/modules/graphics/wrap_Font.h + src/modules/graphics/wrap_Graphics.cpp + src/modules/graphics/wrap_Graphics.h src/modules/graphics/wrap_Image.cpp src/modules/graphics/wrap_Image.h src/modules/graphics/wrap_Mesh.cpp @@ -555,8 +557,6 @@ set(LOVE_SRC_MODULE_GRAPHICS_OPENGL src/modules/graphics/opengl/Text.h src/modules/graphics/opengl/Video.cpp src/modules/graphics/opengl/Video.h - src/modules/graphics/opengl/wrap_Graphics.cpp - src/modules/graphics/opengl/wrap_Graphics.h ) set(LOVE_SRC_MODULE_GRAPHICS diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index a5b4924fc..2bf0a2193 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -456,9 +456,6 @@ FA0B7D551A95902C000E1D17 /* Buffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BA41A95902C000E1D17 /* Buffer.cpp */; }; FA0B7D561A95902C000E1D17 /* Buffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BA41A95902C000E1D17 /* Buffer.cpp */; }; FA0B7D571A95902C000E1D17 /* Buffer.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BA51A95902C000E1D17 /* Buffer.h */; }; - FA0B7D5E1A95902C000E1D17 /* wrap_Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BAA1A95902C000E1D17 /* wrap_Graphics.cpp */; }; - FA0B7D5F1A95902C000E1D17 /* wrap_Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BAA1A95902C000E1D17 /* wrap_Graphics.cpp */; }; - FA0B7D601A95902C000E1D17 /* wrap_Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BAB1A95902C000E1D17 /* wrap_Graphics.h */; }; FA0B7D791A95902C000E1D17 /* Quad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BBC1A95902C000E1D17 /* Quad.cpp */; }; FA0B7D7A1A95902C000E1D17 /* Quad.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BBC1A95902C000E1D17 /* Quad.cpp */; }; FA0B7D7B1A95902C000E1D17 /* Quad.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BBD1A95902C000E1D17 /* Quad.h */; }; @@ -1030,6 +1027,10 @@ FADF54341E3DAE6E00012CC0 /* wrap_SpriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF54321E3DAE6E00012CC0 /* wrap_SpriteBatch.cpp */; }; FADF54351E3DAE6E00012CC0 /* wrap_SpriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF54321E3DAE6E00012CC0 /* wrap_SpriteBatch.cpp */; }; FADF54361E3DAE6E00012CC0 /* wrap_SpriteBatch.h in Headers */ = {isa = PBXBuildFile; fileRef = FADF54331E3DAE6E00012CC0 /* wrap_SpriteBatch.h */; }; + FADF54381E3DAFBA00012CC0 /* wrap_Graphics.lua in Resources */ = {isa = PBXBuildFile; fileRef = FADF54371E3DAFBA00012CC0 /* wrap_Graphics.lua */; }; + FADF543B1E3DAFF700012CC0 /* wrap_Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF54391E3DAFF700012CC0 /* wrap_Graphics.cpp */; }; + FADF543C1E3DAFF700012CC0 /* wrap_Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FADF54391E3DAFF700012CC0 /* wrap_Graphics.cpp */; }; + FADF543D1E3DAFF700012CC0 /* wrap_Graphics.h in Headers */ = {isa = PBXBuildFile; fileRef = FADF543A1E3DAFF700012CC0 /* wrap_Graphics.h */; }; FAE272521C05A15B00A67640 /* ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAE272501C05A15B00A67640 /* ParticleSystem.cpp */; }; FAE272531C05A15B00A67640 /* ParticleSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = FAE272511C05A15B00A67640 /* ParticleSystem.h */; }; FAF140531E20934C00F898D2 /* CodeGen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FAF13FC21E20934C00F898D2 /* CodeGen.cpp */; }; @@ -1471,8 +1472,6 @@ FA0B7BA21A95902C000E1D17 /* Text.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Text.h; sourceTree = ""; }; FA0B7BA41A95902C000E1D17 /* Buffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Buffer.cpp; sourceTree = ""; }; FA0B7BA51A95902C000E1D17 /* Buffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Buffer.h; sourceTree = ""; }; - FA0B7BAA1A95902C000E1D17 /* wrap_Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Graphics.cpp; sourceTree = ""; }; - FA0B7BAB1A95902C000E1D17 /* wrap_Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Graphics.h; sourceTree = ""; }; FA0B7BBC1A95902C000E1D17 /* Quad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Quad.cpp; sourceTree = ""; }; FA0B7BBD1A95902C000E1D17 /* Quad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Quad.h; sourceTree = ""; }; FA0B7BBE1A95902C000E1D17 /* Texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; lineEnding = 0; path = Texture.cpp; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; @@ -1804,7 +1803,6 @@ FA620A301AA2F8DB005DB4C2 /* wrap_Texture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Texture.cpp; sourceTree = ""; }; FA620A311AA2F8DB005DB4C2 /* wrap_Texture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Texture.h; sourceTree = ""; }; FA620A391AA305F6005DB4C2 /* types.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = types.cpp; sourceTree = ""; }; - FA6AE6041B3335EC00583D5C /* wrap_Graphics.lua */ = {isa = PBXFileReference; lastKnownFileType = text; path = wrap_Graphics.lua; sourceTree = ""; }; FA7550A71AEBE276003E311E /* libluajit.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libluajit.a; sourceTree = ""; }; FA7634481E28722A0066EF9E /* StreamBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamBuffer.cpp; sourceTree = ""; }; FA7634491E28722A0066EF9E /* StreamBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamBuffer.h; sourceTree = ""; }; @@ -1864,6 +1862,9 @@ FADF542E1E3DABF600012CC0 /* SpriteBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpriteBatch.h; sourceTree = ""; }; FADF54321E3DAE6E00012CC0 /* wrap_SpriteBatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_SpriteBatch.cpp; sourceTree = ""; }; FADF54331E3DAE6E00012CC0 /* wrap_SpriteBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_SpriteBatch.h; sourceTree = ""; }; + FADF54371E3DAFBA00012CC0 /* wrap_Graphics.lua */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = wrap_Graphics.lua; sourceTree = ""; }; + FADF54391E3DAFF700012CC0 /* wrap_Graphics.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Graphics.cpp; sourceTree = ""; }; + FADF543A1E3DAFF700012CC0 /* wrap_Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Graphics.h; sourceTree = ""; }; FAE272501C05A15B00A67640 /* ParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParticleSystem.cpp; sourceTree = ""; }; FAE272511C05A15B00A67640 /* ParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParticleSystem.h; sourceTree = ""; }; FAF13FC21E20934C00F898D2 /* CodeGen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CodeGen.cpp; sourceTree = ""; }; @@ -2688,6 +2689,9 @@ FA1BA0AB1E16F9EE00AA2803 /* wrap_Canvas.h */, FA1BA0A01E16D97500AA2803 /* wrap_Font.cpp */, FA1BA0A11E16D97500AA2803 /* wrap_Font.h */, + FADF54391E3DAFF700012CC0 /* wrap_Graphics.cpp */, + FADF543A1E3DAFF700012CC0 /* wrap_Graphics.h */, + FADF54371E3DAFBA00012CC0 /* wrap_Graphics.lua */, FADF54191E3DA46C00012CC0 /* wrap_Image.cpp */, FADF541A1E3DA46C00012CC0 /* wrap_Image.h */, FADF54281E3DAADA00012CC0 /* wrap_Mesh.cpp */, @@ -2742,9 +2746,6 @@ FA0B7BA21A95902C000E1D17 /* Text.h */, FA27B3C31B4985D8008A9DCE /* Video.cpp */, FA27B3C41B4985D8008A9DCE /* Video.h */, - FA0B7BAA1A95902C000E1D17 /* wrap_Graphics.cpp */, - FA0B7BAB1A95902C000E1D17 /* wrap_Graphics.h */, - FA6AE6041B3335EC00583D5C /* wrap_Graphics.lua */, ); path = opengl; sourceTree = ""; @@ -3682,7 +3683,6 @@ FA0B7D851A95902C000E1D17 /* Image.h in Headers */, FA0B7E7D1A95902C000E1D17 /* wrap_World.h in Headers */, FA0B7EBD1A95902C000E1D17 /* LuaThread.h in Headers */, - FA0B7D601A95902C000E1D17 /* wrap_Graphics.h in Headers */, FADF53FF1E3D74F200012CC0 /* Text.h in Headers */, FA0B7DC01A95902C000E1D17 /* JoystickModule.h in Headers */, FA0B7E871A95902C000E1D17 /* CoreAudioDecoder.h in Headers */, @@ -3855,6 +3855,7 @@ FA0B7DE71A95902C000E1D17 /* Cursor.h in Headers */, 217DFBEC1D9F6D490055D849 /* ltn12.lua.h in Headers */, FA0B7DB61A95902C000E1D17 /* wrap_ImageData.h in Headers */, + FADF543D1E3DAFF700012CC0 /* wrap_Graphics.h in Headers */, 217DFBFE1D9F6D490055D849 /* socket.h in Headers */, FA0B7A971A958EA3000E1D17 /* b2Joint.h in Headers */, FA0B7A851A958EA3000E1D17 /* b2EdgeAndPolygonContact.h in Headers */, @@ -3969,6 +3970,7 @@ 217DFC0F1D9F6D490055D849 /* url.lua in Resources */, FADF54101E3D7CDD00012CC0 /* wrap_Video.lua in Resources */, 217DFBFC1D9F6D490055D849 /* smtp.lua in Resources */, + FADF54381E3DAFBA00012CC0 /* wrap_Graphics.lua in Resources */, 217DFBF01D9F6D490055D849 /* mbox.lua in Resources */, 217DFBE11D9F6D490055D849 /* ftp.lua in Resources */, 217DFBFF1D9F6D490055D849 /* socket.lua in Resources */, @@ -4166,7 +4168,6 @@ FA0B7D131A95902C000E1D17 /* Font.cpp in Sources */, FA0B7EC91A95902C000E1D17 /* threads.cpp in Sources */, FA0B7A781A958EA3000E1D17 /* b2CircleContact.cpp in Sources */, - FA0B7D5F1A95902C000E1D17 /* wrap_Graphics.cpp in Sources */, FAF1408D1E20934C00F898D2 /* PpAtom.cpp in Sources */, FA0B7A9C1A958EA3000E1D17 /* b2MouseJoint.cpp in Sources */, FAF140721E20934C00F898D2 /* Intermediate.cpp in Sources */, @@ -4224,6 +4225,7 @@ FA0B79391A958E3B000E1D17 /* Reference.cpp in Sources */, FA620A331AA2F8DB005DB4C2 /* wrap_Quad.cpp in Sources */, FA0B7E071A95902C000E1D17 /* DistanceJoint.cpp in Sources */, + FADF543C1E3DAFF700012CC0 /* wrap_Graphics.cpp in Sources */, FA0B7A331A958EA3000E1D17 /* b2Collision.cpp in Sources */, FA0B7E5E1A95902C000E1D17 /* wrap_MouseJoint.cpp in Sources */, FA0B7B3B1A958EA3000E1D17 /* wuff_memory.c in Sources */, @@ -4525,7 +4527,6 @@ FA0B7EC81A95902C000E1D17 /* threads.cpp in Sources */, 217DFBF91D9F6D490055D849 /* select.c in Sources */, FA0B7A6B1A958EA3000E1D17 /* b2World.cpp in Sources */, - FA0B7D5E1A95902C000E1D17 /* wrap_Graphics.cpp in Sources */, FAF1408C1E20934C00F898D2 /* PpAtom.cpp in Sources */, FA0B7A801A958EA3000E1D17 /* b2EdgeAndCircleContact.cpp in Sources */, FAF140711E20934C00F898D2 /* Intermediate.cpp in Sources */, @@ -4583,6 +4584,7 @@ FA0B7AD41A958EA3000E1D17 /* unix.c in Sources */, FA0B7A771A958EA3000E1D17 /* b2CircleContact.cpp in Sources */, FAB17BE01ABFAA2000F9BA27 /* Compressor.cpp in Sources */, + FADF543B1E3DAFF700012CC0 /* wrap_Graphics.cpp in Sources */, FA0B7D331A95902C000E1D17 /* Canvas.cpp in Sources */, FA0B7E941A95902C000E1D17 /* Mpg123Decoder.cpp in Sources */, FA0B7E8B1A95902C000E1D17 /* FLACDecoder.cpp in Sources */, diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 51b6ee9d7..149f4643a 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -35,6 +35,7 @@ #include "Shader.h" #include "Quad.h" #include "Mesh.h" +#include "Image.h" #include "math/Transform.h" #include "font/Rasterizer.h" #include "video/VideoStream.h" @@ -315,6 +316,9 @@ public: // Implements Module. virtual ModuleType getModuleType() const { return M_GRAPHICS; } + virtual Image *newImage(const std::vector &data, const Image::Settings &settings) = 0; + virtual Image *newImage(const std::vector &cdata, const Image::Settings &settings) = 0; + Quad *newQuad(Quad::Viewport v, double sw, double sh); virtual SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage) = 0; @@ -663,6 +667,13 @@ public: **/ virtual double getSystemLimit(SystemLimit limittype) const = 0; + /** + * Gets whether the specified pixel format is supported by Canvases or + * Images. + **/ + virtual bool isCanvasFormatSupported(PixelFormat format) const = 0; + virtual bool isImageFormatSupported(PixelFormat format) const = 0; + /** * Gets the renderer used by love.graphics. **/ diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 892e1d7e5..ecc63e744 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -103,12 +103,12 @@ love::graphics::StreamBuffer *Graphics::newStreamBuffer(BufferType type, size_t return CreateStreamBuffer(type, size); } -Image *Graphics::newImage(const std::vector &data, const Image::Settings &settings) +love::graphics::Image *Graphics::newImage(const std::vector &data, const Image::Settings &settings) { return new Image(data, settings); } -Image *Graphics::newImage(const std::vector &cdata, const Image::Settings &settings) +love::graphics::Image *Graphics::newImage(const std::vector &cdata, const Image::Settings &settings) { return new Image(cdata, settings); } @@ -1502,6 +1502,16 @@ bool Graphics::isSupported(Feature feature) const } } +bool Graphics::isCanvasFormatSupported(PixelFormat format) const +{ + return Canvas::isFormatSupported(format); +} + +bool Graphics::isImageFormatSupported(PixelFormat format) const +{ + return Image::isFormatSupported(format); +} + Shader::Language Graphics::getShaderLanguageTarget() const { if (gl.isCoreProfile()) diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 49c7d53dd..159c811c4 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -61,8 +61,8 @@ public: // Implements Module. const char *getName() const override; - Image *newImage(const std::vector &data, const Image::Settings &settings); - Image *newImage(const std::vector &cdata, const Image::Settings &settings); + love::graphics::Image *newImage(const std::vector &data, const Image::Settings &settings) override; + love::graphics::Image *newImage(const std::vector &cdata, const Image::Settings &settings) override; love::graphics::Font *newFont(love::font::Rasterizer *data, const Texture::Filter &filter = Texture::defaultFilter) override; @@ -127,6 +127,8 @@ public: bool isSupported(Feature feature) const override; double getSystemLimit(SystemLimit limittype) const override; + bool isCanvasFormatSupported(PixelFormat format) const override; + bool isImageFormatSupported(PixelFormat format) const override; Renderer getRenderer() const override; RendererInfo getRendererInfo() const override; Stats getStats() const override; diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/wrap_Graphics.cpp similarity index 97% rename from src/modules/graphics/opengl/wrap_Graphics.cpp rename to src/modules/graphics/wrap_Graphics.cpp index 1ccc58f44..aa42e8757 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/wrap_Graphics.cpp @@ -18,8 +18,9 @@ * 3. This notice may not be removed or altered from any source distribution. **/ +#include "common/config.h" #include "wrap_Graphics.h" -#include "graphics/Texture.h" +#include "Texture.h" #include "image/ImageData.h" #include "image/Image.h" #include "font/Rasterizer.h" @@ -29,6 +30,10 @@ #include "common/Reference.h" #include "math/wrap_Transform.h" +#ifdef LOVE_ENABLE_GRAPHICS_OPENGL +#include "opengl/Graphics.h" +#endif + #include #include #include @@ -44,8 +49,6 @@ namespace love { namespace graphics { -namespace opengl -{ #define instance() (Module::getInstance(Module::M_GRAPHICS)) @@ -213,7 +216,7 @@ int w_setCanvas(lua_State *L) } bool is_table = lua_istable(L, 1); - std::vector canvases; + std::vector canvases; if (is_table) { @@ -242,10 +245,10 @@ int w_setCanvas(lua_State *L) int w_getCanvas(lua_State *L) { - const std::vector canvases = instance()->getCanvas(); + const std::vector canvases = instance()->getCanvas(); int n = 0; - for (love::graphics::Canvas *c : canvases) + for (Canvas *c : canvases) { luax_pushtype(L, c); n++; @@ -629,7 +632,7 @@ int w_newImageFont(lua_State *L) love::font::Rasterizer *rasterizer = luax_checktype(L, 1); // Create the font. - love::graphics::Font *font = instance()->newFont(rasterizer, filter); + Font *font = instance()->newFont(rasterizer, filter); // Push the type. luax_pushtype(L, font); @@ -651,7 +654,7 @@ int w_newSpriteBatch(lua_State *L) return luaL_error(L, "Invalid usage hint: %s", usagestr); } - love::graphics::SpriteBatch *t = nullptr; + SpriteBatch *t = nullptr; luax_catchexcept(L, [&](){ t = instance()->newSpriteBatch(texture, size, usage); } ); @@ -667,7 +670,7 @@ int w_newParticleSystem(lua_State *L) Texture *texture = luax_checktexture(L, 1); lua_Number size = luaL_optnumber(L, 2, 1000); - love::graphics::ParticleSystem *t = nullptr; + ParticleSystem *t = nullptr; if (size < 1.0 || size > ParticleSystem::MAX_PARTICLES) return luaL_error(L, "Invalid ParticleSystem size"); @@ -708,7 +711,7 @@ int w_newCanvas(lua_State *L) settings.msaa = luax_intflag(L, 3, "msaa", settings.msaa); } - love::graphics::Canvas *canvas = nullptr; + Canvas *canvas = nullptr; luax_catchexcept(L, [&](){ canvas = instance()->newCanvas(width, height, settings); }); if (canvas == nullptr) @@ -820,7 +823,7 @@ int w_newShader(lua_State *L) bool should_error = false; try { - love::graphics::Shader *shader = instance()->newShader(source); + Shader *shader = instance()->newShader(source); luax_pushtype(L, shader); shader->release(); } @@ -882,9 +885,9 @@ static Mesh::DrawMode luax_optmeshdrawmode(lua_State *L, int idx, Mesh::DrawMode return def; } -static love::graphics::Mesh *newStandardMesh(lua_State *L) +static Mesh *newStandardMesh(lua_State *L) { - love::graphics::Mesh *t = nullptr; + Mesh *t = nullptr; Mesh::DrawMode drawmode = luax_optmeshdrawmode(L, 2, Mesh::DRAWMODE_FAN); vertex::Usage usage = luax_optmeshusage(L, 3, vertex::USAGE_DYNAMIC); @@ -938,9 +941,9 @@ static love::graphics::Mesh *newStandardMesh(lua_State *L) return t; } -static love::graphics::Mesh *newCustomMesh(lua_State *L) +static Mesh *newCustomMesh(lua_State *L) { - love::graphics::Mesh *t = nullptr; + Mesh *t = nullptr; // First argument is the vertex format, second is a table of vertices or // the number of vertices. @@ -1067,7 +1070,7 @@ int w_newMesh(lua_State *L) if (arg1type != LUA_TTABLE && arg1type != LUA_TNUMBER) luaL_argerror(L, 1, "table or number expected"); - love::graphics::Mesh *t = nullptr; + Mesh *t = nullptr; int arg2type = lua_type(L, 2); if (arg1type == LUA_TTABLE && (arg2type == LUA_TTABLE || arg2type == LUA_TNUMBER || arg2type == LUA_TUSERDATA)) @@ -1195,21 +1198,21 @@ int w_getBackgroundColor(lua_State *L) int w_setNewFont(lua_State *L) { int ret = w_newFont(L); - love::graphics::Font *font = luax_checktype(L, -1); + Font *font = luax_checktype(L, -1); instance()->setFont(font); return ret; } int w_setFont(lua_State *L) { - love::graphics::Font *font = luax_checktype(L, 1); + Font *font = luax_checktype(L, 1); instance()->setFont(font); return 0; } int w_getFont(lua_State *L) { - love::graphics::Font *f = nullptr; + Font *f = nullptr; luax_catchexcept(L, [&](){ f = instance()->getFont(); }); luax_pushtype(L, f); @@ -1445,14 +1448,14 @@ int w_setShader(lua_State *L) return 0; } - love::graphics::Shader *shader = luax_checkshader(L, 1); + Shader *shader = luax_checkshader(L, 1); instance()->setShader(shader); return 0; } int w_getShader(lua_State *L) { - love::graphics::Shader *shader = instance()->getShader(); + Shader *shader = instance()->getShader(); if (shader) luax_pushtype(L, shader); else @@ -1537,17 +1540,27 @@ static int w__getFormats(lua_State *L, bool (*isFormatSupported)(PixelFormat), b int w_getCanvasFormats(lua_State *L) { - return w__getFormats(L, Canvas::isFormatSupported, isPixelFormatCompressed); + const auto supported = [](PixelFormat format) -> bool + { + return instance()->isCanvasFormatSupported(format); + }; + + return w__getFormats(L, supported, isPixelFormatCompressed); } int w_getImageFormats(lua_State *L) { - const auto ignore = [](PixelFormat format) + const auto supported = [](PixelFormat format) -> bool + { + return instance()->isImageFormatSupported(format); + }; + + const auto ignore = [](PixelFormat format) -> bool { return !(image::ImageData::validPixelFormat(format) || isPixelFormatCompressed(format)); }; - return w__getFormats(L, Image::isFormatSupported, ignore); + return w__getFormats(L, supported, ignore); } int w_getRendererInfo(lua_State *L) @@ -1671,7 +1684,7 @@ int w_draw(lua_State *L) int w_drawInstanced(lua_State *L) { - love::graphics::Mesh *t = luax_checkmesh(L, 1); + Mesh *t = luax_checkmesh(L, 1); int instancecount = (int) luaL_checkinteger(L, 2); if (luax_istype(L, 3, math::Transform::type)) @@ -2301,7 +2314,11 @@ extern "C" int luaopen_love_graphics(lua_State *L) Graphics *instance = instance(); if (instance == nullptr) { - luax_catchexcept(L, [&](){ instance = new Graphics(); }); +#ifdef LOVE_ENABLE_GRAPHICS_OPENGL + luax_catchexcept(L, [&](){ instance = new love::graphics::opengl::Graphics(); }); +#else + return luaL_error(L, "LOVE was compiled without any love.graphics backend!"); +#endif } else instance->retain(); @@ -2323,6 +2340,5 @@ extern "C" int luaopen_love_graphics(lua_State *L) return n; } -} // opengl } // graphics } // love diff --git a/src/modules/graphics/opengl/wrap_Graphics.h b/src/modules/graphics/wrap_Graphics.h similarity index 68% rename from src/modules/graphics/opengl/wrap_Graphics.h rename to src/modules/graphics/wrap_Graphics.h index 6fa6ca2e5..d3c9fc63a 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.h +++ b/src/modules/graphics/wrap_Graphics.h @@ -18,34 +18,28 @@ * 3. This notice may not be removed or altered from any source distribution. **/ -#ifndef LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H -#define LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H +#pragma once // LOVE #include "common/config.h" -#include "graphics/wrap_Font.h" -#include "graphics/wrap_Image.h" -#include "graphics/wrap_Quad.h" -#include "graphics/wrap_SpriteBatch.h" -#include "graphics/wrap_ParticleSystem.h" -#include "graphics/wrap_Canvas.h" -#include "graphics/wrap_Shader.h" -#include "graphics/wrap_Mesh.h" -#include "graphics/wrap_Text.h" -#include "graphics/wrap_Video.h" +#include "wrap_Font.h" +#include "wrap_Image.h" +#include "wrap_Quad.h" +#include "wrap_SpriteBatch.h" +#include "wrap_ParticleSystem.h" +#include "wrap_Canvas.h" +#include "wrap_Shader.h" +#include "wrap_Mesh.h" +#include "wrap_Text.h" +#include "wrap_Video.h" #include "Graphics.h" namespace love { namespace graphics { -namespace opengl -{ extern "C" LOVE_EXPORT int luaopen_love_graphics(lua_State *L); -} // opengl } // graphics } // love - -#endif // LOVE_GRAPHICS_OPENGL_WRAP_GRAPHICS_H diff --git a/src/modules/graphics/opengl/wrap_Graphics.lua b/src/modules/graphics/wrap_Graphics.lua similarity index 100% rename from src/modules/graphics/opengl/wrap_Graphics.lua rename to src/modules/graphics/wrap_Graphics.lua