diff --git a/CMakeLists.txt b/CMakeLists.txt index 92ff59d22..3e22ba4b6 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -583,22 +583,14 @@ set(LOVE_SRC_MODULE_GRAPHICS_OPENGL src/modules/graphics/opengl/Graphics.h src/modules/graphics/opengl/Image.cpp src/modules/graphics/opengl/Image.h - src/modules/graphics/opengl/Mesh.cpp - src/modules/graphics/opengl/Mesh.h src/modules/graphics/opengl/OpenGL.cpp src/modules/graphics/opengl/OpenGL.h - src/modules/graphics/opengl/ParticleSystem.cpp - src/modules/graphics/opengl/ParticleSystem.h src/modules/graphics/opengl/Shader.cpp src/modules/graphics/opengl/Shader.h src/modules/graphics/opengl/ShaderStage.cpp src/modules/graphics/opengl/ShaderStage.h - src/modules/graphics/opengl/SpriteBatch.cpp - src/modules/graphics/opengl/SpriteBatch.h src/modules/graphics/opengl/StreamBuffer.cpp src/modules/graphics/opengl/StreamBuffer.h - src/modules/graphics/opengl/Text.cpp - src/modules/graphics/opengl/Text.h ) set(LOVE_SRC_MODULE_GRAPHICS diff --git a/platform/xcode/liblove.xcodeproj/project.pbxproj b/platform/xcode/liblove.xcodeproj/project.pbxproj index b152771a6..62116bc55 100644 --- a/platform/xcode/liblove.xcodeproj/project.pbxproj +++ b/platform/xcode/liblove.xcodeproj/project.pbxproj @@ -421,27 +421,15 @@ FA0B7D3C1A95902C000E1D17 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B931A95902C000E1D17 /* Image.cpp */; }; FA0B7D3D1A95902C000E1D17 /* Image.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B931A95902C000E1D17 /* Image.cpp */; }; FA0B7D3E1A95902C000E1D17 /* Image.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B941A95902C000E1D17 /* Image.h */; }; - FA0B7D3F1A95902C000E1D17 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B951A95902C000E1D17 /* Mesh.cpp */; }; - FA0B7D401A95902C000E1D17 /* Mesh.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B951A95902C000E1D17 /* Mesh.cpp */; }; - FA0B7D411A95902C000E1D17 /* Mesh.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B961A95902C000E1D17 /* Mesh.h */; }; FA0B7D421A95902C000E1D17 /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B971A95902C000E1D17 /* OpenGL.cpp */; }; FA0B7D431A95902C000E1D17 /* OpenGL.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B971A95902C000E1D17 /* OpenGL.cpp */; }; FA0B7D441A95902C000E1D17 /* OpenGL.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B981A95902C000E1D17 /* OpenGL.h */; }; - FA0B7D451A95902C000E1D17 /* ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B991A95902C000E1D17 /* ParticleSystem.cpp */; }; - FA0B7D461A95902C000E1D17 /* ParticleSystem.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B991A95902C000E1D17 /* ParticleSystem.cpp */; }; - FA0B7D471A95902C000E1D17 /* ParticleSystem.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B9A1A95902C000E1D17 /* ParticleSystem.h */; }; FA0B7D481A95902C000E1D17 /* Polyline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B9B1A95902C000E1D17 /* Polyline.cpp */; }; FA0B7D491A95902C000E1D17 /* Polyline.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B9B1A95902C000E1D17 /* Polyline.cpp */; }; FA0B7D4A1A95902C000E1D17 /* Polyline.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B9C1A95902C000E1D17 /* Polyline.h */; }; FA0B7D4B1A95902C000E1D17 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B9D1A95902C000E1D17 /* Shader.cpp */; }; FA0B7D4C1A95902C000E1D17 /* Shader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B9D1A95902C000E1D17 /* Shader.cpp */; }; FA0B7D4D1A95902C000E1D17 /* Shader.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7B9E1A95902C000E1D17 /* Shader.h */; }; - FA0B7D4E1A95902C000E1D17 /* SpriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B9F1A95902C000E1D17 /* SpriteBatch.cpp */; }; - FA0B7D4F1A95902C000E1D17 /* SpriteBatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7B9F1A95902C000E1D17 /* SpriteBatch.cpp */; }; - FA0B7D501A95902C000E1D17 /* SpriteBatch.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BA01A95902C000E1D17 /* SpriteBatch.h */; }; - FA0B7D511A95902C000E1D17 /* Text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BA11A95902C000E1D17 /* Text.cpp */; }; - FA0B7D521A95902C000E1D17 /* Text.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FA0B7BA11A95902C000E1D17 /* Text.cpp */; }; - FA0B7D531A95902C000E1D17 /* Text.h in Headers */ = {isa = PBXBuildFile; fileRef = FA0B7BA21A95902C000E1D17 /* Text.h */; }; 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 */; }; @@ -1480,20 +1468,12 @@ FA0B7B921A95902C000E1D17 /* Graphics.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Graphics.h; sourceTree = ""; }; FA0B7B931A95902C000E1D17 /* Image.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Image.cpp; sourceTree = ""; }; FA0B7B941A95902C000E1D17 /* Image.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Image.h; sourceTree = ""; }; - FA0B7B951A95902C000E1D17 /* Mesh.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Mesh.cpp; sourceTree = ""; }; - FA0B7B961A95902C000E1D17 /* Mesh.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Mesh.h; sourceTree = ""; }; FA0B7B971A95902C000E1D17 /* OpenGL.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = OpenGL.cpp; sourceTree = ""; }; FA0B7B981A95902C000E1D17 /* OpenGL.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OpenGL.h; sourceTree = ""; }; - FA0B7B991A95902C000E1D17 /* ParticleSystem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ParticleSystem.cpp; sourceTree = ""; }; - FA0B7B9A1A95902C000E1D17 /* ParticleSystem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ParticleSystem.h; sourceTree = ""; }; FA0B7B9B1A95902C000E1D17 /* Polyline.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Polyline.cpp; sourceTree = ""; }; FA0B7B9C1A95902C000E1D17 /* Polyline.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Polyline.h; sourceTree = ""; }; FA0B7B9D1A95902C000E1D17 /* Shader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Shader.cpp; sourceTree = ""; }; FA0B7B9E1A95902C000E1D17 /* Shader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Shader.h; sourceTree = ""; }; - FA0B7B9F1A95902C000E1D17 /* SpriteBatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SpriteBatch.cpp; sourceTree = ""; }; - FA0B7BA01A95902C000E1D17 /* SpriteBatch.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SpriteBatch.h; sourceTree = ""; }; - FA0B7BA11A95902C000E1D17 /* Text.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Text.cpp; sourceTree = ""; }; - 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 = ""; }; FA0B7BBC1A95902C000E1D17 /* Quad.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Quad.cpp; sourceTree = ""; }; @@ -2788,22 +2768,14 @@ FA0B7B921A95902C000E1D17 /* Graphics.h */, FA0B7B931A95902C000E1D17 /* Image.cpp */, FA0B7B941A95902C000E1D17 /* Image.h */, - FA0B7B951A95902C000E1D17 /* Mesh.cpp */, - FA0B7B961A95902C000E1D17 /* Mesh.h */, FA0B7B971A95902C000E1D17 /* OpenGL.cpp */, FA0B7B981A95902C000E1D17 /* OpenGL.h */, - FA0B7B991A95902C000E1D17 /* ParticleSystem.cpp */, - FA0B7B9A1A95902C000E1D17 /* ParticleSystem.h */, FA0B7B9D1A95902C000E1D17 /* Shader.cpp */, FA0B7B9E1A95902C000E1D17 /* Shader.h */, FA3C5E451F8D80CA0003C579 /* ShaderStage.cpp */, FA3C5E461F8D80CA0003C579 /* ShaderStage.h */, - FA0B7B9F1A95902C000E1D17 /* SpriteBatch.cpp */, - FA0B7BA01A95902C000E1D17 /* SpriteBatch.h */, FA7634481E28722A0066EF9E /* StreamBuffer.cpp */, FA7634491E28722A0066EF9E /* StreamBuffer.h */, - FA0B7BA11A95902C000E1D17 /* Text.cpp */, - FA0B7BA21A95902C000E1D17 /* Text.h */, ); path = opengl; sourceTree = ""; @@ -3606,7 +3578,6 @@ FA0B7D4A1A95902C000E1D17 /* Polyline.h in Headers */, FAF1405C1E20934C00F898D2 /* InitializeGlobals.h in Headers */, FA0B7DB31A95902C000E1D17 /* wrap_Image.h in Headers */, - FA0B7D531A95902C000E1D17 /* Text.h in Headers */, FAF140591E20934C00F898D2 /* Common.h in Headers */, FA0B7EC31A95902C000E1D17 /* threads.h in Headers */, FA0B7AC21A958EA3000E1D17 /* enet.h in Headers */, @@ -3748,7 +3719,6 @@ FA0B7E351A95902C000E1D17 /* WeldJoint.h in Headers */, FA0B7E2F1A95902C000E1D17 /* RopeJoint.h in Headers */, FA0B7D141A95902C000E1D17 /* Font.h in Headers */, - FA0B7D411A95902C000E1D17 /* Mesh.h in Headers */, FA0B7E591A95902C000E1D17 /* wrap_Joint.h in Headers */, FA0B79351A958E3B000E1D17 /* macosx.h in Headers */, FA0B7A631A958EA3000E1D17 /* b2ContactManager.h in Headers */, @@ -3756,7 +3726,6 @@ FA0B7A911A958EA3000E1D17 /* b2FrictionJoint.h in Headers */, FA0B7E291A95902C000E1D17 /* PulleyJoint.h in Headers */, FA6BDE5C1F31725300786805 /* Color.h in Headers */, - FA0B7D471A95902C000E1D17 /* ParticleSystem.h in Headers */, FA0B7E231A95902C000E1D17 /* PolygonShape.h in Headers */, FA0B791E1A958E3B000E1D17 /* config.h in Headers */, FAB17BE81ABFAA9000F9BA27 /* lz4.h in Headers */, @@ -3814,7 +3783,6 @@ FA0B7CF61A95902C000E1D17 /* File.h in Headers */, FA0B7E961A95902C000E1D17 /* Mpg123Decoder.h in Headers */, FADF54091E3D78F700012CC0 /* Video.h in Headers */, - FA0B7D501A95902C000E1D17 /* SpriteBatch.h in Headers */, FAA54ACB1F91660400A8FA7B /* TheoraVideoStream.h in Headers */, FA0B7DD51A95902C000E1D17 /* BezierCurve.h in Headers */, FA0B79271A958E3B000E1D17 /* int.h in Headers */, @@ -4151,7 +4119,6 @@ FA0B7D1F1A95902C000E1D17 /* ImageRasterizer.cpp in Sources */, FA0B7EA41A95902C000E1D17 /* SoundData.cpp in Sources */, FA0B7D041A95902C000E1D17 /* wrap_DroppedFile.cpp in Sources */, - FA0B7D461A95902C000E1D17 /* ParticleSystem.cpp in Sources */, FAF1406A1E20934C00F898D2 /* glslang_tab.cpp in Sources */, FA91591F1CF1ED7500A7053F /* halffloat.cpp in Sources */, FA8951A31AA2EDF300EC385A /* wrap_Event.cpp in Sources */, @@ -4239,7 +4206,6 @@ FA0B7DF21A95902C000E1D17 /* wrap_Cursor.cpp in Sources */, FA0B7E011A95902C000E1D17 /* CircleShape.cpp in Sources */, FA0B7E461A95902C000E1D17 /* wrap_Contact.cpp in Sources */, - FA0B7D401A95902C000E1D17 /* Mesh.cpp in Sources */, FA0B7D161A95902C000E1D17 /* Font.cpp in Sources */, FA0B7EB61A95902C000E1D17 /* wrap_System.cpp in Sources */, FA0B7DAC1A95902C000E1D17 /* STBHandler.cpp in Sources */, @@ -4353,7 +4319,6 @@ FA0B7E221A95902C000E1D17 /* PolygonShape.cpp in Sources */, FA0B7A651A958EA3000E1D17 /* b2Fixture.cpp in Sources */, FA28EBD61E352DB5003446F4 /* FenceSync.cpp in Sources */, - FA0B7D521A95902C000E1D17 /* Text.cpp in Sources */, FA0B7DA31A95902C000E1D17 /* PKMHandler.cpp in Sources */, FA0B7AB21A958EA3000E1D17 /* b2Rope.cpp in Sources */, FAB17BF61ABFC4B100F9BA27 /* lz4hc.c in Sources */, @@ -4392,7 +4357,6 @@ FA4F2C0E1DE936FE00CA37D7 /* tcp.c in Sources */, FA0B7D431A95902C000E1D17 /* OpenGL.cpp in Sources */, FA0B7DBF1A95902C000E1D17 /* JoystickModule.cpp in Sources */, - FA0B7D4F1A95902C000E1D17 /* SpriteBatch.cpp in Sources */, FAB2D5AB1AABDD8A008224A4 /* TrueTypeRasterizer.cpp in Sources */, FA0B7A9F1A958EA3000E1D17 /* b2PrismaticJoint.cpp in Sources */, FA1BA0AD1E16F9EE00AA2803 /* wrap_Canvas.cpp in Sources */, @@ -4521,7 +4485,6 @@ FA0B7EA31A95902C000E1D17 /* SoundData.cpp in Sources */, FA0B7D031A95902C000E1D17 /* wrap_DroppedFile.cpp in Sources */, FA0B79291A958E3B000E1D17 /* Matrix.cpp in Sources */, - FA0B7D451A95902C000E1D17 /* ParticleSystem.cpp in Sources */, FA8951A21AA2EDF300EC385A /* wrap_Event.cpp in Sources */, FAF140691E20934C00F898D2 /* glslang_tab.cpp in Sources */, FA0B7ABF1A958EA3000E1D17 /* host.c in Sources */, @@ -4608,7 +4571,6 @@ FA0B7DF11A95902C000E1D17 /* wrap_Cursor.cpp in Sources */, FA0B7E001A95902C000E1D17 /* CircleShape.cpp in Sources */, FA0B7E451A95902C000E1D17 /* wrap_Contact.cpp in Sources */, - FA0B7D3F1A95902C000E1D17 /* Mesh.cpp in Sources */, 217DFBE71D9F6D490055D849 /* inet.c in Sources */, FA0B7D151A95902C000E1D17 /* Font.cpp in Sources */, FA0B7EB51A95902C000E1D17 /* wrap_System.cpp in Sources */, @@ -4718,7 +4680,6 @@ FA0B7D551A95902C000E1D17 /* Buffer.cpp in Sources */, FA57FB981AE1993600F2AD6D /* noise1234.cpp in Sources */, FA0B7E211A95902C000E1D17 /* PolygonShape.cpp in Sources */, - FA0B7D511A95902C000E1D17 /* Text.cpp in Sources */, FA0B7DA21A95902C000E1D17 /* PKMHandler.cpp in Sources */, FA0B7ABA1A958EA3000E1D17 /* callbacks.c in Sources */, FAB17BF51ABFC4B100F9BA27 /* lz4hc.c in Sources */, @@ -4760,7 +4721,6 @@ FA0B7D421A95902C000E1D17 /* OpenGL.cpp in Sources */, FA0B7A671A958EA3000E1D17 /* b2Island.cpp in Sources */, FA0B7DBE1A95902C000E1D17 /* JoystickModule.cpp in Sources */, - FA0B7D4E1A95902C000E1D17 /* SpriteBatch.cpp in Sources */, FAB2D5AA1AABDD8A008224A4 /* TrueTypeRasterizer.cpp in Sources */, FA0B7ACD1A958EA3000E1D17 /* packet.c in Sources */, FA0B7A921A958EA3000E1D17 /* b2GearJoint.cpp in Sources */, diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 42ef895b5..f7731ca4f 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -26,8 +26,11 @@ #include "Polyline.h" #include "font/Font.h" #include "window/Window.h" +#include "SpriteBatch.h" +#include "ParticleSystem.h" #include "Font.h" #include "Video.h" +#include "Text.h" #include "common/deprecation.h" // C++ @@ -182,6 +185,16 @@ Video *Graphics::newVideo(love::video::VideoStream *stream, float dpiscale) return new Video(this, stream, dpiscale); } +love::graphics::SpriteBatch *Graphics::newSpriteBatch(Texture *texture, int size, vertex::Usage usage) +{ + return new SpriteBatch(this, texture, size, usage); +} + +love::graphics::ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size) +{ + return new ParticleSystem(this, texture, size); +} + ShaderStage *Graphics::newShaderStage(ShaderStage::StageType stage, const std::string &optsource) { if (stage == ShaderStage::STAGE_MAX_ENUM) @@ -238,6 +251,21 @@ Mesh *Graphics::newMesh(int vertexcount, PrimitiveType drawmode, vertex::Usage u return newMesh(Mesh::getDefaultVertexFormat(), vertexcount, drawmode, usage); } +love::graphics::Mesh *Graphics::newMesh(const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) +{ + return new Mesh(this, vertexformat, vertexcount, drawmode, usage); +} + +love::graphics::Mesh *Graphics::newMesh(const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) +{ + return new Mesh(this, vertexformat, data, datasize, drawmode, usage); +} + +love::graphics::Text *Graphics::newText(graphics::Font *font, const std::vector &text) +{ + return new Text(this, font, text); +} + void Graphics::cleanupCachedShaderStage(ShaderStage::StageType type, const std::string &hashkey) { cachedShaderStages[type].erase(hashkey); diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 7c591f484..7bb497685 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -380,9 +380,8 @@ public: Font *newDefaultFont(int size, font::TrueTypeRasterizer::Hinting hinting, const Texture::Filter &filter = Texture::defaultFilter); Video *newVideo(love::video::VideoStream *stream, float dpiscale); - virtual SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage) = 0; - - virtual ParticleSystem *newParticleSystem(Texture *texture, int size) = 0; + SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage); + ParticleSystem *newParticleSystem(Texture *texture, int size); virtual Canvas *newCanvas(const Canvas::Settings &settings) = 0; @@ -393,11 +392,10 @@ public: Mesh *newMesh(const std::vector &vertices, PrimitiveType drawmode, vertex::Usage usage); Mesh *newMesh(int vertexcount, PrimitiveType drawmode, vertex::Usage usage); + Mesh *newMesh(const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage); + Mesh *newMesh(const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage); - virtual Mesh *newMesh(const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) = 0; - virtual Mesh *newMesh(const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) = 0; - - virtual Text *newText(Font *font, const std::vector &text = {}) = 0; + Text *newText(Font *font, const std::vector &text = {}); bool validateShader(bool gles, const std::string &vertex, const std::string &pixel, std::string &err); @@ -761,6 +759,9 @@ public: Vector2 transformPoint(Vector2 point); Vector2 inverseTransformPoint(Vector2 point); + virtual void draw(PrimitiveType primtype, int vertexstart, int vertexcount, int instancecount, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) = 0; + virtual void drawIndexed(PrimitiveType primtype, int indexcount, int instancecount, IndexDataType datatype, Resource *indexbuffer, size_t indexoffset, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) = 0; + virtual void flushStreamDraws() = 0; StreamVertexData requestStreamDraw(const StreamDrawCommand &command); diff --git a/src/modules/graphics/Mesh.cpp b/src/modules/graphics/Mesh.cpp index e8153ecc7..ded75f39c 100644 --- a/src/modules/graphics/Mesh.cpp +++ b/src/modules/graphics/Mesh.cpp @@ -631,12 +631,12 @@ void Mesh::drawInstanced(Graphics *gfx, const Matrix4 &m, int instancecount) if (!attributes.isEnabled(ATTRIB_POS)) throw love::Exception("Mesh must have an enabled VertexPosition attribute to be drawn."); - bool useindexbuffer = useIndexBuffer && ibo != nullptr && indexCount > 0; + Graphics::TempTransform transform(gfx, m); int start = 0; int count = 0; - if (useindexbuffer) + if (useIndexBuffer && ibo != nullptr && indexCount > 0) { // Make sure the index buffer isn't mapped (sends data to GPU if needed.) ibo->unmap(); @@ -648,6 +648,10 @@ void Mesh::drawInstanced(Graphics *gfx, const Matrix4 &m, int instancecount) count = std::min(count, rangeCount); count = std::min(count, (int) indexCount - start); + + size_t offset = start * vertex::getIndexDataSize(indexDataType); + if (count > 0) + gfx->drawIndexed(primitiveType, count, instancecount, indexDataType, ibo, offset, attributes, buffers, texture); } else { @@ -658,12 +662,9 @@ void Mesh::drawInstanced(Graphics *gfx, const Matrix4 &m, int instancecount) count = std::min(count, rangeCount); count = std::min(count, (int) vertexCount - start); + + gfx->draw(primitiveType, start, count, instancecount, attributes, buffers, texture); } - - Graphics::TempTransform transform(gfx, m); - - if (count > 0) - drawInternal(start, count, instancecount, useindexbuffer, attributes, buffers); } } // graphics diff --git a/src/modules/graphics/Mesh.h b/src/modules/graphics/Mesh.h index b4e3361a4..40763bd8d 100644 --- a/src/modules/graphics/Mesh.h +++ b/src/modules/graphics/Mesh.h @@ -174,7 +174,7 @@ public: static std::vector getDefaultVertexFormat(); -protected: +private: friend class SpriteBatch; @@ -190,8 +190,6 @@ protected: void calculateAttributeSizes(); size_t getAttributeOffset(size_t attribindex) const; - virtual void drawInternal(int start, int count, int instancecount, bool useindexbuffer, const vertex::Attributes &attributes, const vertex::Buffers &buffers) const = 0; - std::vector vertexFormat; std::vector attributeSizes; diff --git a/src/modules/graphics/ParticleSystem.cpp b/src/modules/graphics/ParticleSystem.cpp index 77b71eb87..fb2041d53 100644 --- a/src/modules/graphics/ParticleSystem.cpp +++ b/src/modules/graphics/ParticleSystem.cpp @@ -167,6 +167,11 @@ ParticleSystem::~ParticleSystem() deleteBuffers(); } +ParticleSystem *ParticleSystem::clone() +{ + return new ParticleSystem(*this); +} + void ParticleSystem::resetOffset() { if (quads.empty()) @@ -1095,7 +1100,9 @@ void ParticleSystem::draw(Graphics *gfx, const Matrix4 &m) vertexbuffers.set(0, buffer, 0); Graphics::TempTransform transform(gfx, m); - drawInternal(vertexAttributes, vertexbuffers); + + int count = quadIndices.getIndexCount(getCount()); + gfx->drawIndexed(PRIMITIVE_TRIANGLES, count, 1, quadIndices.getType(), quadIndices.getBuffer(), 0, vertexAttributes, vertexbuffers, texture); } bool ParticleSystem::getConstant(const char *in, AreaSpreadDistribution &out) diff --git a/src/modules/graphics/ParticleSystem.h b/src/modules/graphics/ParticleSystem.h index 4088a20ec..d21a9c327 100644 --- a/src/modules/graphics/ParticleSystem.h +++ b/src/modules/graphics/ParticleSystem.h @@ -99,7 +99,7 @@ public: * duplicate any existing particles from this ParticleSystem, just the * settable parameters. **/ - virtual ParticleSystem *clone() = 0; + ParticleSystem *clone(); /** * Sets the texture used in the particle system. @@ -116,7 +116,7 @@ public: * Clears the current buffer and allocates the appropriate amount of space for the buffer. * @param size The new buffer size. **/ - virtual void setBufferSize(uint32 size); + void setBufferSize(uint32 size); /** * Returns the total amount of particles this ParticleSystem can have active @@ -547,7 +547,7 @@ public: static bool getConstant(InsertMode in, const char *&out); static std::vector getConstants(InsertMode); -protected: +private: // Represents a single particle. struct Particle @@ -584,7 +584,19 @@ protected: int quadIndex; }; - virtual void drawInternal(const vertex::Attributes &attributes, const vertex::Buffers &buffers) const = 0; + void resetOffset(); + + void createBuffers(size_t size); + void deleteBuffers(); + + void addParticle(float t); + Particle *removeParticle(Particle *p); + + // Called by addParticle. + void initParticle(Particle *p, float t); + void insertTop(Particle *p); + void insertBottom(Particle *p); + void insertRandom(Particle *p); // Pointer to the beginning of the allocated memory. Particle *pMem; @@ -693,22 +705,6 @@ protected: // Vertex index buffer. QuadIndices quadIndices; -private: - - void resetOffset(); - - void createBuffers(size_t size); - void deleteBuffers(); - - void addParticle(float t); - Particle *removeParticle(Particle *p); - - // Called by addParticle. - void initParticle(Particle *p, float t); - void insertTop(Particle *p); - void insertBottom(Particle *p); - void insertRandom(Particle *p); - static StringMap::Entry distributionsEntries[]; static StringMap distributions; diff --git a/src/modules/graphics/SpriteBatch.cpp b/src/modules/graphics/SpriteBatch.cpp index 66fa7d5f0..5e74e17fb 100644 --- a/src/modules/graphics/SpriteBatch.cpp +++ b/src/modules/graphics/SpriteBatch.cpp @@ -399,7 +399,7 @@ void SpriteBatch::draw(Graphics *gfx, const Matrix4 &m) Graphics::TempTransform transform(gfx, m); if (count > 0) - drawInternal(indexbytestart, indexcount, attributes, buffers); + gfx->drawIndexed(PRIMITIVE_TRIANGLES, indexcount, 1, quad_indices.getType(), quad_indices.getBuffer(), indexbytestart, attributes, buffers, texture); } } // graphics diff --git a/src/modules/graphics/SpriteBatch.h b/src/modules/graphics/SpriteBatch.h index 36c0daad9..7bd844737 100644 --- a/src/modules/graphics/SpriteBatch.h +++ b/src/modules/graphics/SpriteBatch.h @@ -109,7 +109,7 @@ public: // Implements Drawable. void draw(Graphics *gfx, const Matrix4 &m) override; -protected: +private: struct AttachedAttribute { @@ -123,8 +123,6 @@ protected: **/ void setBufferSize(int newsize); - virtual void drawInternal(size_t indexbytestart, size_t indexcount, const vertex::Attributes &attributes, const vertex::Buffers &buffers) = 0; - StrongRef texture; // Max number of sprites in the batch. diff --git a/src/modules/graphics/Text.cpp b/src/modules/graphics/Text.cpp index 2dad5cd80..eb19a47c9 100644 --- a/src/modules/graphics/Text.cpp +++ b/src/modules/graphics/Text.cpp @@ -266,7 +266,16 @@ void Text::draw(Graphics *gfx, const Matrix4 &m) Graphics::TempTransform transform(gfx, m); - drawInternal(draw_commands); + size_t elemsize = quadIndices.getElementSize(); + IndexDataType datatype = quadIndices.getType(); + Buffer *indexbuffer = quadIndices.getBuffer(); + + for (const Font::DrawCommand &cmd : draw_commands) + { + int count = (cmd.vertexcount / 4) * 6; + size_t offset = (cmd.startvertex / 4) * 6 * elemsize; + gfx->drawIndexed(PRIMITIVE_TRIANGLES, count, 1, datatype, indexbuffer, offset, vertexAttributes, vertexBuffers, cmd.texture); + } } } // graphics diff --git a/src/modules/graphics/Text.h b/src/modules/graphics/Text.h index 35b251a79..8294ff55c 100644 --- a/src/modules/graphics/Text.h +++ b/src/modules/graphics/Text.h @@ -66,7 +66,7 @@ public: // Implements Drawable. void draw(love::graphics::Graphics *gfx, const Matrix4 &m) override; -protected: +private: struct TextData { @@ -83,8 +83,6 @@ protected: void regenerateVertices(); void addTextData(const TextData &s); - virtual void drawInternal(const std::vector &commands) const = 0; - StrongRef font; vertex::Attributes vertexAttributes; diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 177c5f96d..a6f53f640 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -29,7 +29,6 @@ #include "math/MathModule.h" #include "window/Window.h" #include "Buffer.h" -#include "Text.h" #include "ShaderStage.h" #include "libraries/xxHash/xxhash.h" @@ -112,16 +111,6 @@ love::graphics::Image *Graphics::newImage(TextureType textype, PixelFormat forma return new Image(textype, format, width, height, slices, settings); } -love::graphics::SpriteBatch *Graphics::newSpriteBatch(Texture *texture, int size, vertex::Usage usage) -{ - return new SpriteBatch(this, texture, size, usage); -} - -love::graphics::ParticleSystem *Graphics::newParticleSystem(Texture *texture, int size) -{ - return new ParticleSystem(this, texture, size); -} - love::graphics::Canvas *Graphics::newCanvas(const Canvas::Settings &settings) { return new Canvas(settings); @@ -142,21 +131,6 @@ love::graphics::Buffer *Graphics::newBuffer(size_t size, const void *data, Buffe return new Buffer(size, data, type, usage, mapflags); } -love::graphics::Mesh *Graphics::newMesh(const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) -{ - return new Mesh(this, vertexformat, vertexcount, drawmode, usage); -} - -love::graphics::Mesh *Graphics::newMesh(const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) -{ - return new Mesh(this, vertexformat, data, datasize, drawmode, usage); -} - -love::graphics::Text *Graphics::newText(graphics::Font *font, const std::vector &text) -{ - return new Text(this, font, text); -} - void Graphics::setViewportSize(int width, int height, int pixelwidth, int pixelheight) { this->width = width; @@ -420,6 +394,30 @@ void Graphics::flushStreamDraws() streamBufferState.indexCount = 0; } +void Graphics::draw(PrimitiveType primtype, int vertexstart, int vertexcount, int instancecount, const vertex::Attributes &attribs, const vertex::Buffers &buffers, love::graphics::Texture *texture) +{ + gl.prepareDraw(); + gl.setVertexAttributes(attribs, buffers); + gl.bindTextureToUnit(texture, 0, false); + + GLenum glprimitivetype = OpenGL::getGLPrimitiveType(primtype); + gl.drawArrays(glprimitivetype, vertexstart, vertexcount, instancecount); +} + +void Graphics::drawIndexed(PrimitiveType primtype, int indexcount, int instancecount, IndexDataType datatype, Resource *indexbuffer, size_t indexoffset, const vertex::Attributes &attribs, const vertex::Buffers &buffers, love::graphics::Texture *texture) +{ + gl.prepareDraw(); + gl.setVertexAttributes(attribs, buffers); + gl.bindTextureToUnit(texture, 0, false); + + const void *gloffset = BUFFER_OFFSET(indexoffset); + GLenum glprimitivetype = OpenGL::getGLPrimitiveType(primtype); + GLenum gldatatype = OpenGL::getGLIndexDataType(datatype); + + gl.bindBuffer(BUFFER_INDEX, indexbuffer->getHandle()); + gl.drawElements(glprimitivetype, indexcount, gldatatype, gloffset, instancecount); +} + static void APIENTRY debugCB(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei /*len*/, const GLchar *msg, const GLvoid* /*usr*/) { // Human-readable strings for the debug info. diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index d1ef8a681..4bf34b200 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -37,11 +37,8 @@ #include "image/ImageData.h" #include "Image.h" -#include "SpriteBatch.h" -#include "ParticleSystem.h" #include "Canvas.h" #include "Shader.h" -#include "Mesh.h" namespace love { @@ -63,19 +60,9 @@ public: love::graphics::Image *newImage(const Image::Slices &data, const Image::Settings &settings) override; love::graphics::Image *newImage(TextureType textype, PixelFormat format, int width, int height, int slices, const Image::Settings &settings) override; - - love::graphics::SpriteBatch *newSpriteBatch(Texture *texture, int size, vertex::Usage usage) override; - love::graphics::ParticleSystem *newParticleSystem(Texture *texture, int size) override; - love::graphics::Canvas *newCanvas(const Canvas::Settings &settings) override; - love::graphics::Buffer *newBuffer(size_t size, const void *data, BufferType type, vertex::Usage usage, uint32 mapflags) override; - love::graphics::Mesh *newMesh(const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) override; - love::graphics::Mesh *newMesh(const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) override; - - love::graphics::Text *newText(love::graphics::Font *font, const std::vector &text = {}) override; - void setViewportSize(int width, int height, int pixelwidth, int pixelheight) override; bool setMode(int width, int height, int pixelwidth, int pixelheight, bool windowhasstencil) override; void unSetMode() override; @@ -84,6 +71,9 @@ public: void flushStreamDraws() override; + void draw(PrimitiveType primtype, int vertexstart, int vertexcount, int instancecount, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) override; + void drawIndexed(PrimitiveType primtype, int indexcount, int instancecount, IndexDataType datatype, Resource *indexbuffer, size_t indexoffset, const vertex::Attributes &attribs, const vertex::Buffers &buffers, Texture *texture) override; + void clear(OptionalColorf color, OptionalInt stencil, OptionalDouble depth) override; void clear(const std::vector &colors, OptionalInt stencil, OptionalDouble depth) override; diff --git a/src/modules/graphics/opengl/Mesh.cpp b/src/modules/graphics/opengl/Mesh.cpp deleted file mode 100644 index 6159c542b..000000000 --- a/src/modules/graphics/opengl/Mesh.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -// LOVE -#include "Mesh.h" -#include "common/Exception.h" -#include "Shader.h" -#include "graphics/Graphics.h" - -// C++ -#include -#include - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -Mesh::Mesh(graphics::Graphics *gfx, const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) - : love::graphics::Mesh(gfx, vertexformat, data, datasize, drawmode, usage) -{ -} - -Mesh::Mesh(graphics::Graphics *gfx, const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) - : love::graphics::Mesh(gfx, vertexformat, vertexcount, drawmode, usage) -{ -} - -Mesh::~Mesh() -{ -} - -void Mesh::drawInternal(int start, int count, int instancecount, bool useindexbuffer, const vertex::Attributes &attributes, const vertex::Buffers &buffers) const -{ - OpenGL::TempDebugGroup debuggroup("Mesh draw"); - - gl.setVertexAttributes(attributes, buffers); - gl.bindTextureToUnit(texture, 0, false); - gl.prepareDraw(); - - GLenum glprimitivetype = OpenGL::getGLPrimitiveType(primitiveType); - - if (useindexbuffer) - { - size_t elementsize = vertex::getIndexDataSize(indexDataType); - const void *indices = BUFFER_OFFSET(start * elementsize); - GLenum indextype = OpenGL::getGLIndexDataType(indexDataType); - - gl.bindBuffer(BUFFER_INDEX, (GLuint) ibo->getHandle()); - gl.drawElements(glprimitivetype, count, indextype, indices, instancecount); - } - else - { - gl.drawArrays(glprimitivetype, start, count, instancecount); - } -} - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/Mesh.h b/src/modules/graphics/opengl/Mesh.h deleted file mode 100644 index 28b30b417..000000000 --- a/src/modules/graphics/opengl/Mesh.h +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#pragma once - -// LOVE -#include "graphics/Mesh.h" -#include "OpenGL.h" - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -class Mesh final : public love::graphics::Mesh -{ -public: - - Mesh(graphics::Graphics *gfx, const std::vector &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage); - Mesh(graphics::Graphics *gfx, const std::vector &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage); - virtual ~Mesh(); - -protected: - - void drawInternal(int start, int count, int instancecount, bool useindexbuffer, const vertex::Attributes &attributes, const vertex::Buffers &buffers) const override; - -}; // Mesh - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp deleted file mode 100644 index 2616a0d5f..000000000 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -//LOVE -#include "ParticleSystem.h" -#include "graphics/Graphics.h" - -#include "OpenGL.h" - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -ParticleSystem::ParticleSystem(Graphics *gfx, Texture *texture, uint32 size) - : love::graphics::ParticleSystem(gfx, texture, size) -{ -} - -ParticleSystem::ParticleSystem(const ParticleSystem &p) - : love::graphics::ParticleSystem(p) -{ -} - -ParticleSystem::~ParticleSystem() -{ -} - -ParticleSystem *ParticleSystem::clone() -{ - return new ParticleSystem(*this); -} - -void ParticleSystem::drawInternal(const vertex::Attributes &attributes, const vertex::Buffers &buffers) const -{ - OpenGL::TempDebugGroup debuggroup("ParticleSystem draw"); - - gl.bindTextureToUnit(texture, 0, false); - gl.prepareDraw(); - - gl.setVertexAttributes(attributes, buffers); - - GLsizei count = (GLsizei) quadIndices.getIndexCount(getCount()); - GLenum gltype = OpenGL::getGLIndexDataType(quadIndices.getType()); - - gl.bindBuffer(BUFFER_INDEX, (GLuint) quadIndices.getBuffer()->getHandle()); - gl.drawElements(GL_TRIANGLES, count, gltype, BUFFER_OFFSET(0)); -} - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h deleted file mode 100644 index 411247018..000000000 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#ifndef LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H -#define LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H - -// LOVE -#include "graphics/ParticleSystem.h" - -namespace love -{ -namespace graphics -{ - -class Graphics; - -namespace opengl -{ - -class ParticleSystem final : public love::graphics::ParticleSystem -{ -public: - - ParticleSystem(Graphics *gfx, Texture *texture, uint32 buffer); - ParticleSystem(const ParticleSystem &p); - - virtual ~ParticleSystem(); - - ParticleSystem *clone() override; - -private: - - void drawInternal(const vertex::Attributes &attributes, const vertex::Buffers &buffers) const override; - -}; // ParticleSystem - -} // opengl -} // graphics -} // love - -#endif // LOVE_GRAPHICS_OPENGL_PARTICLE_SYSTEM_H diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp deleted file mode 100644 index 5e7525510..000000000 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#include "common/config.h" -#include "SpriteBatch.h" - -// OpenGL -#include "OpenGL.h" - -// LOVE -#include "graphics/Buffer.h" -#include "graphics/Texture.h" -#include "graphics/Graphics.h" - -// C++ -#include - -// C -#include - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -SpriteBatch::SpriteBatch(Graphics *gfx, Texture *texture, int size, vertex::Usage usage) - : love::graphics::SpriteBatch(gfx, texture, size, usage) -{ -} - -SpriteBatch::~SpriteBatch() -{ -} - -void SpriteBatch::drawInternal(size_t indexbytestart, size_t indexcount, const vertex::Attributes &attributes, const vertex::Buffers &buffers) -{ - OpenGL::TempDebugGroup debuggroup("SpriteBatch draw"); - - gl.setVertexAttributes(attributes, buffers); - gl.bindTextureToUnit(texture, 0, false); - - gl.prepareDraw(); - - gl.bindBuffer(BUFFER_INDEX, (GLuint) quad_indices.getBuffer()->getHandle()); - - const void *indices = BUFFER_OFFSET(indexbytestart); - GLenum gltype = OpenGL::getGLIndexDataType(quad_indices.getType()); - - gl.drawElements(GL_TRIANGLES, (GLsizei) indexcount, gltype, indices); -} - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h deleted file mode 100644 index 979c64dc9..000000000 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#pragma once - -// LOVE -#include "graphics/SpriteBatch.h" - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -class SpriteBatch final : public love::graphics::SpriteBatch -{ -public: - - SpriteBatch(Graphics *gfx, Texture *texture, int size, vertex::Usage usage); - virtual ~SpriteBatch(); - -protected: - - void drawInternal(size_t indexbytestart, size_t indexcount, const vertex::Attributes &attributes, const vertex::Buffers &buffers) override; - -}; // SpriteBatch - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/Text.cpp b/src/modules/graphics/opengl/Text.cpp deleted file mode 100644 index cacca30f7..000000000 --- a/src/modules/graphics/opengl/Text.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#include "Text.h" -#include "graphics/Graphics.h" -#include "OpenGL.h" - -#include - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -Text::Text(love::graphics::Graphics *gfx, love::graphics::Font *font, const std::vector &text) - : love::graphics::Text(gfx, font, text) -{ -} - -Text::~Text() -{ -} - -void Text::drawInternal(const std::vector &commands) const -{ - OpenGL::TempDebugGroup debuggroup("Text object draw"); - - gl.prepareDraw(); - gl.setVertexAttributes(vertexAttributes, vertexBuffers); - - const GLenum gltype = OpenGL::getGLIndexDataType(quadIndices.getType()); - const size_t elemsize = quadIndices.getElementSize(); - - gl.bindBuffer(BUFFER_INDEX, (GLuint) quadIndices.getBuffer()->getHandle()); - - // We need a separate draw call for every section of the text which uses a - // different texture than the previous section. - for (const Font::DrawCommand &cmd : commands) - { - GLsizei count = (cmd.vertexcount / 4) * 6; - size_t offset = (cmd.startvertex / 4) * 6 * elemsize; - - gl.bindTextureToUnit(cmd.texture, 0, false); - gl.drawElements(GL_TRIANGLES, count, gltype, BUFFER_OFFSET(offset)); - } -} - -} // opengl -} // graphics -} // love diff --git a/src/modules/graphics/opengl/Text.h b/src/modules/graphics/opengl/Text.h deleted file mode 100644 index e91a84bd5..000000000 --- a/src/modules/graphics/opengl/Text.h +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (c) 2006-2017 LOVE Development Team - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any damages - * arising from the use of this software. - * - * Permission is granted to anyone to use this software for any purpose, - * including commercial applications, and to alter it and redistribute it - * freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you must not - * claim that you wrote the original software. If you use this software - * in a product, an acknowledgment in the product documentation would be - * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. - **/ - -#pragma once - -// LOVE -#include "common/config.h" -#include "graphics/Text.h" - -namespace love -{ -namespace graphics -{ -namespace opengl -{ - -class Text final : public love::graphics::Text -{ -public: - - Text(love::graphics::Graphics *gfx, love::graphics::Font *font, const std::vector &text = {}); - virtual ~Text(); - -protected: - - void drawInternal(const std::vector &commands) const override; - -}; // Text - -} // opengl -} // graphics -} // love