From b8b670e0ae28d1c736465335777065b87b00448c Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Tue, 18 Oct 2016 22:06:52 -0300 Subject: [PATCH] Simplify Drawable code --HG-- branch : minor --- src/modules/graphics/Drawable.h | 15 ++------- src/modules/graphics/Texture.h | 13 +------- src/modules/graphics/opengl/Canvas.cpp | 12 +++---- src/modules/graphics/opengl/Canvas.h | 14 ++++----- src/modules/graphics/opengl/Font.cpp | 12 +++---- src/modules/graphics/opengl/Font.h | 18 ++--------- src/modules/graphics/opengl/Graphics.cpp | 8 ++--- src/modules/graphics/opengl/Graphics.h | 31 +++---------------- src/modules/graphics/opengl/Image.cpp | 12 +++---- src/modules/graphics/opengl/Image.h | 14 ++++----- src/modules/graphics/opengl/Mesh.cpp | 4 +-- src/modules/graphics/opengl/Mesh.h | 2 +- .../graphics/opengl/ParticleSystem.cpp | 4 +-- src/modules/graphics/opengl/ParticleSystem.h | 2 +- src/modules/graphics/opengl/SpriteBatch.cpp | 18 +++++------ src/modules/graphics/opengl/SpriteBatch.h | 8 ++--- src/modules/graphics/opengl/Text.cpp | 14 ++++----- src/modules/graphics/opengl/Text.h | 9 +++--- src/modules/graphics/opengl/Video.cpp | 4 +-- src/modules/graphics/opengl/Video.h | 8 +++-- src/modules/graphics/opengl/wrap_Graphics.cpp | 18 ++++++----- .../graphics/opengl/wrap_SpriteBatch.cpp | 6 ++-- src/modules/graphics/opengl/wrap_Text.cpp | 6 ++-- 23 files changed, 93 insertions(+), 159 deletions(-) diff --git a/src/modules/graphics/Drawable.h b/src/modules/graphics/Drawable.h index 05ce5ba73..cc8919ce9 100644 --- a/src/modules/graphics/Drawable.h +++ b/src/modules/graphics/Drawable.h @@ -23,6 +23,7 @@ // LOVE #include "common/Object.h" +#include "common/Matrix.h" namespace love { @@ -43,19 +44,9 @@ public: virtual ~Drawable() {} /** - * Draws the object with the specified transformation. - * - * @param x The position of the object along the x-axis. - * @param y The position of the object along the y-axis. - * @param angle The angle of the object (in radians). - * @param sx The scale factor along the x-axis. - * @param sy The scale factor along the y-axis. - * @param ox The origin offset along the x-axis. - * @param oy The origin offset along the y-axis. - * @param kx Shear along the x-axis. - * @param ky Shear along the y-axis. + * Draws the object with the specified transformation matrix. **/ - virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) = 0; + virtual void draw(const Matrix4 &m) = 0; }; } // graphics diff --git a/src/modules/graphics/Texture.h b/src/modules/graphics/Texture.h index db680604a..70fc932a2 100644 --- a/src/modules/graphics/Texture.h +++ b/src/modules/graphics/Texture.h @@ -76,19 +76,8 @@ public: /** * Draws the texture using the specified transformation with a Quad applied. - * - * @param quad The Quad object to use to draw the object. - * @param x The position of the object along the x-axis. - * @param y The position of the object along the y-axis. - * @param angle The angle of the object (in radians). - * @param sx The scale factor along the x-axis. - * @param sy The scale factor along the y-axis. - * @param ox The origin offset along the x-axis. - * @param oy The origin offset along the y-axis. - * @param kx Shear along the x-axis. - * @param ky Shear along the y-axis. **/ - virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) = 0; + virtual void drawq(Quad *quad, const Matrix4 &m) = 0; virtual int getWidth() const; virtual int getHeight() const; diff --git a/src/modules/graphics/opengl/Canvas.cpp b/src/modules/graphics/opengl/Canvas.cpp index bf05f820b..4e79a766a 100644 --- a/src/modules/graphics/opengl/Canvas.cpp +++ b/src/modules/graphics/opengl/Canvas.cpp @@ -322,18 +322,14 @@ void Canvas::drawv(const Matrix4 &t, const Vertex *v) gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); } -void Canvas::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Canvas::draw(const Matrix4 &m) { - Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - - drawv(t, vertices); + drawv(m, vertices); } -void Canvas::drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Canvas::drawq(Quad *quad, const Matrix4 &m) { - Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - - drawv(t, quad->getVertices()); + drawv(m, quad->getVertices()); } void Canvas::setFilter(const Texture::Filter &f) diff --git a/src/modules/graphics/opengl/Canvas.h b/src/modules/graphics/opengl/Canvas.h index 7f7a9ec84..03d829bd9 100644 --- a/src/modules/graphics/opengl/Canvas.h +++ b/src/modules/graphics/opengl/Canvas.h @@ -70,17 +70,17 @@ public: virtual ~Canvas(); // Implements Volatile. - virtual bool loadVolatile(); - virtual void unloadVolatile(); + bool loadVolatile() override; + void unloadVolatile() override; // Implements Drawable. - virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void draw(const Matrix4 &m) override; // Implements Texture. - virtual void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); - virtual void setFilter(const Texture::Filter &f); - virtual bool setWrap(const Texture::Wrap &w); - virtual const void *getHandle() const; + void drawq(Quad *quad, const Matrix4 &m) override; + void setFilter(const Texture::Filter &f) override; + bool setWrap(const Texture::Wrap &w) override; + const void *getHandle() const override; /** * @param canvases A list of other canvases to temporarily attach to this one, diff --git a/src/modules/graphics/opengl/Font.cpp b/src/modules/graphics/opengl/Font.cpp index 71fa1d69b..77cf1f760 100644 --- a/src/modules/graphics/opengl/Font.cpp +++ b/src/modules/graphics/opengl/Font.cpp @@ -703,7 +703,7 @@ void Font::printv(const Matrix4 &t, const std::vector &drawcommands drawVertices(drawcommands, false); } -void Font::print(const std::vector &text, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Font::print(const std::vector &text, const Matrix4 &m) { ColoredCodepoints codepoints; getCodepointsFromString(text, codepoints); @@ -711,12 +711,10 @@ void Font::print(const std::vector &text, float x, float y, float std::vector vertices; std::vector drawcommands = generateVertices(codepoints, vertices); - Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - - printv(t, drawcommands, vertices); + printv(m, drawcommands, vertices); } -void Font::printf(const std::vector &text, float x, float y, float wrap, AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Font::printf(const std::vector &text, float wrap, AlignMode align, const Matrix4 &m) { ColoredCodepoints codepoints; getCodepointsFromString(text, codepoints); @@ -724,9 +722,7 @@ void Font::printf(const std::vector &text, float x, float y, floa std::vector vertices; std::vector drawcommands = generateVerticesFormatted(codepoints, wrap, align, vertices); - Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - - printv(t, drawcommands, vertices); + printv(m, drawcommands, vertices); } int Font::getWidth(const std::string &str) diff --git a/src/modules/graphics/opengl/Font.h b/src/modules/graphics/opengl/Font.h index 644908006..ed55a41a4 100644 --- a/src/modules/graphics/opengl/Font.h +++ b/src/modules/graphics/opengl/Font.h @@ -115,22 +115,10 @@ public: static void getCodepointsFromString(const std::vector &strs, ColoredCodepoints &codepoints); /** - * Prints the text at the designated position with rotation and scaling. - * - * @param text A string. - * @param x The x-coordinate. - * @param y The y-coordinate. - * @param angle The amount of rotation. - * @param sx Scale along the x axis. - * @param sy Scale along the y axis. - * @param ox The origin offset along the x-axis. - * @param oy The origin offset along the y-axis. - * @param kx Shear along the x axis. - * @param ky Shear along the y axis. + * Draws the text at the designated position with a transformation applied. **/ - void print(const std::vector &text, float x, float y, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f, float ox = 0.0f, float oy = 0.0f, float kx = 0.0f, float ky = 0.0f); - - void printf(const std::vector &text, float x, float y, float wrap, AlignMode align, float angle = 0.0f, float sx = 1.0f, float sy = 1.0f, float ox = 0.0f, float oy = 0.0f, float kx = 0.0f, float ky = 0.0f); + void print(const std::vector &text, const Matrix4 &m); + void printf(const std::vector &text, float wrap, AlignMode align, const Matrix4 &m); /** * Returns the height of the font. diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index 2c7a629dd..5732fe847 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -1258,24 +1258,24 @@ bool Graphics::isWireframe() const return states.back().wireframe; } -void Graphics::print(const std::vector &str, float x, float y , float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Graphics::print(const std::vector &str, const Matrix4 &m) { checkSetDefaultFont(); DisplayState &state = states.back(); if (state.font.get() != nullptr) - state.font->print(str, x, y, angle, sx, sy, ox, oy, kx, ky); + state.font->print(str, m); } -void Graphics::printf(const std::vector &str, float x, float y, float wrap, Font::AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Graphics::printf(const std::vector &str, float wrap, Font::AlignMode align, const Matrix4 &m) { checkSetDefaultFont(); DisplayState &state = states.back(); if (state.font.get() != nullptr) - state.font->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky); + state.font->printf(str, wrap, align, m); } /** diff --git a/src/modules/graphics/opengl/Graphics.h b/src/modules/graphics/opengl/Graphics.h index 0fab48f16..2a4e0ecb8 100644 --- a/src/modules/graphics/opengl/Graphics.h +++ b/src/modules/graphics/opengl/Graphics.h @@ -331,37 +331,14 @@ public: bool isWireframe() const; /** - * Draws text at the specified coordinates, with rotation and - * scaling along both axes. - * @param x The x-coordinate. - * @param y The y-coordinate. - * @param angle The amount of rotation. - * @param sx The scale factor along the x-axis. (1 = normal). - * @param sy The scale factor along the y-axis. (1 = normal). - * @param ox The origin offset along the x-axis. - * @param oy The origin offset along the y-axis. - * @param kx Shear along the x-axis. - * @param ky Shear along the y-axis. + * Draws text at the specified coordinates **/ - void print(const std::vector &str, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void print(const std::vector &str, const Matrix4 &m); /** - * Draw formatted text on screen at the specified coordinates. - * - * @param str A string of text. - * @param x The x-coordinate. - * @param y The y-coordinate. - * @param wrap The maximum width of the text area. - * @param align Where to align the text. - * @param angle The amount of rotation. - * @param sx The scale factor along the x-axis. (1 = normal). - * @param sy The scale factor along the y-axis. (1 = normal). - * @param ox The origin offset along the x-axis. - * @param oy The origin offset along the y-axis. - * @param kx Shear along the x-axis. - * @param ky Shear along the y-axis. + * Draws formatted text on screen at the specified coordinates. **/ - void printf(const std::vector &str, float x, float y, float wrap, Font::AlignMode align, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void printf(const std::vector &str, float wrap, Font::AlignMode align, const Matrix4 &m); /** * Draws a point at (x,y). diff --git a/src/modules/graphics/opengl/Image.cpp b/src/modules/graphics/opengl/Image.cpp index 53b717f5f..67ebd99b7 100644 --- a/src/modules/graphics/opengl/Image.cpp +++ b/src/modules/graphics/opengl/Image.cpp @@ -460,18 +460,14 @@ void Image::drawv(const Matrix4 &t, const Vertex *v) gl.drawArrays(GL_TRIANGLE_STRIP, 0, 4); } -void Image::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Image::draw(const Matrix4 &m) { - Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - - drawv(t, vertices); + drawv(m, vertices); } -void Image::drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Image::drawq(Quad *quad, const Matrix4 &m) { - Matrix4 t(x, y, angle, sx, sy, ox, oy, kx, ky); - - drawv(t, quad->getVertices()); + drawv(m, quad->getVertices()); } const void *Image::getHandle() const diff --git a/src/modules/graphics/opengl/Image.h b/src/modules/graphics/opengl/Image.h index e7a3f0cd9..0df3df0cf 100644 --- a/src/modules/graphics/opengl/Image.h +++ b/src/modules/graphics/opengl/Image.h @@ -85,26 +85,26 @@ public: virtual ~Image(); // Implements Volatile. - bool loadVolatile(); - void unloadVolatile(); + bool loadVolatile() override; + void unloadVolatile() override; /** * @copydoc Drawable::draw() **/ - void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void draw(const Matrix4 &m) override; /** * @copydoc Texture::drawq() **/ - void drawq(Quad *quad, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void drawq(Quad *quad, const Matrix4 &m) override; - virtual const void *getHandle() const; + const void *getHandle() const override; const std::vector> &getImageData() const; const std::vector> &getCompressedData() const; - virtual void setFilter(const Texture::Filter &f); - virtual bool setWrap(const Texture::Wrap &w); + void setFilter(const Texture::Filter &f) override; + bool setWrap(const Texture::Wrap &w) override; void setMipmapSharpness(float sharpness); float getMipmapSharpness() const; diff --git a/src/modules/graphics/opengl/Mesh.cpp b/src/modules/graphics/opengl/Mesh.cpp index e28768f44..0a77c58b4 100644 --- a/src/modules/graphics/opengl/Mesh.cpp +++ b/src/modules/graphics/opengl/Mesh.cpp @@ -574,7 +574,7 @@ int Mesh::bindAttributeToShaderInput(int attributeindex, const std::string &inpu return attriblocation; } -void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Mesh::draw(const Matrix4 &m) { if (vertexCount <= 0) return; @@ -606,8 +606,6 @@ void Mesh::draw(float x, float y, float angle, float sx, float sy, float ox, flo else gl.bindTexture(gl.getDefaultTexture()); - Matrix4 m(x, y, angle, sx, sy, ox, oy, kx, ky); - OpenGL::TempTransform transform(gl); transform.get() *= m; diff --git a/src/modules/graphics/opengl/Mesh.h b/src/modules/graphics/opengl/Mesh.h index c3bea02b2..19ba61097 100644 --- a/src/modules/graphics/opengl/Mesh.h +++ b/src/modules/graphics/opengl/Mesh.h @@ -197,7 +197,7 @@ public: int bindAttributeToShaderInput(int attributeindex, const std::string &inputname); // Implements Drawable. - void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) override; + void draw(const Matrix4 &m) override; static GLenum getGLBufferUsage(Usage usage); diff --git a/src/modules/graphics/opengl/ParticleSystem.cpp b/src/modules/graphics/opengl/ParticleSystem.cpp index 2900a8e1b..40d991c14 100644 --- a/src/modules/graphics/opengl/ParticleSystem.cpp +++ b/src/modules/graphics/opengl/ParticleSystem.cpp @@ -84,7 +84,7 @@ void ParticleSystem::setBufferSize(uint32 size) createVertices(size); } -void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void ParticleSystem::draw(const Matrix4 &m) { uint32 pCount = getCount(); @@ -94,7 +94,7 @@ void ParticleSystem::draw(float x, float y, float angle, float sx, float sy, flo OpenGL::TempDebugGroup debuggroup("ParticleSystem draw"); OpenGL::TempTransform transform(gl); - transform.get() *= Matrix4(x, y, angle, sx, sy, ox, oy, kx, ky); + transform.get() *= m; const Vertex *textureVerts = texture->getVertices(); Vertex *pVerts = particleVerts; diff --git a/src/modules/graphics/opengl/ParticleSystem.h b/src/modules/graphics/opengl/ParticleSystem.h index d9e7f1ca0..8fbdcb0c7 100644 --- a/src/modules/graphics/opengl/ParticleSystem.h +++ b/src/modules/graphics/opengl/ParticleSystem.h @@ -43,7 +43,7 @@ public: ParticleSystem *clone() override; void setBufferSize(uint32 size) override; - void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) override; + void draw(const Matrix4 &m) override; private: diff --git a/src/modules/graphics/opengl/SpriteBatch.cpp b/src/modules/graphics/opengl/SpriteBatch.cpp index dcf9e8eac..be22ab81c 100644 --- a/src/modules/graphics/opengl/SpriteBatch.cpp +++ b/src/modules/graphics/opengl/SpriteBatch.cpp @@ -66,7 +66,7 @@ SpriteBatch::~SpriteBatch() delete array_buf; } -int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/) +int SpriteBatch::add(const Matrix4 &m, int index /*= -1*/) { if (index < -1 || index >= size) throw love::Exception("Invalid sprite index: %d", index + 1); @@ -74,9 +74,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl if (index == -1 && next >= size) setBufferSize(size * 2); - Matrix3 t(x, y, a, sx, sy, ox, oy, kx, ky); - - addv(texture->getVertices(), t, (index == -1) ? next : index); + addv(texture->getVertices(), m, (index == -1) ? next : index); // Increment counter. if (index == -1) @@ -85,7 +83,7 @@ int SpriteBatch::add(float x, float y, float a, float sx, float sy, float ox, fl return index; } -int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index /*= -1*/) +int SpriteBatch::addq(Quad *quad, const Matrix4 &m, int index /*= -1*/) { if (index < -1 || index >= size) throw love::Exception("Invalid sprite index: %d", index + 1); @@ -93,9 +91,7 @@ int SpriteBatch::addq(Quad *quad, float x, float y, float a, float sx, float sy, if (index == -1 && next >= size) setBufferSize(size * 2); - Matrix3 t(x, y, a, sx, sy, ox, oy, kx, ky); - - addv(quad->getVertices(), t, (index == -1) ? next : index); + addv(quad->getVertices(), m, (index == -1) ? next : index); // Increment counter. if (index == -1) @@ -249,7 +245,7 @@ bool SpriteBatch::getDrawRange(int &start, int &count) const return true; } -void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void SpriteBatch::draw(const Matrix4 &m) { const size_t pos_offset = offsetof(Vertex, x); const size_t texel_offset = offsetof(Vertex, s); @@ -261,7 +257,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float OpenGL::TempDebugGroup debuggroup("SpriteBatch draw"); OpenGL::TempTransform transform(gl); - transform.get() *= Matrix4(x, y, angle, sx, sy, ox, oy, kx, ky); + transform.get() *= m; gl.bindTexture(*(GLuint *) texture->getHandle()); @@ -320,7 +316,7 @@ void SpriteBatch::draw(float x, float y, float angle, float sx, float sy, float gl.drawElements(GL_TRIANGLES, (GLsizei) quad_indices.getIndexCount(count), quad_indices.getType(), indices); } -void SpriteBatch::addv(const Vertex *v, const Matrix3 &m, int index) +void SpriteBatch::addv(const Vertex *v, const Matrix4 &m, int index) { // Needed for colors. Vertex sprite[4] = {v[0], v[1], v[2], v[3]}; diff --git a/src/modules/graphics/opengl/SpriteBatch.h b/src/modules/graphics/opengl/SpriteBatch.h index 9e865b1b2..f33726f5a 100644 --- a/src/modules/graphics/opengl/SpriteBatch.h +++ b/src/modules/graphics/opengl/SpriteBatch.h @@ -55,8 +55,8 @@ public: SpriteBatch(Texture *texture, int size, Mesh::Usage usage); virtual ~SpriteBatch(); - int add(float x, float y, float a, float sx, float sy, float ox, float oy, float kx, float ky, int index = -1); - 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); + int add(const Matrix4 &m, int index = -1); + int addq(Quad *quad, const Matrix4 &m, int index = -1); void clear(); void flush(); @@ -106,7 +106,7 @@ public: bool getDrawRange(int &start, int &count) const; // Implements Drawable. - void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void draw(const Matrix4 &m) override; private: @@ -122,7 +122,7 @@ private: **/ void setBufferSize(int newsize); - void addv(const Vertex *v, const Matrix3 &m, int index); + void addv(const Vertex *v, const Matrix4 &m, int index); /** * Set the color for vertices. diff --git a/src/modules/graphics/opengl/Text.cpp b/src/modules/graphics/opengl/Text.cpp index 3db229c80..9fcbc2e1e 100644 --- a/src/modules/graphics/opengl/Text.cpp +++ b/src/modules/graphics/opengl/Text.cpp @@ -182,21 +182,19 @@ void Text::set(const std::vector &text, float wrap, Font::A Font::ColoredCodepoints codepoints; Font::getCodepointsFromString(text, codepoints); - addTextData({codepoints, wrap, align, {}, false, false, Matrix3()}); + addTextData({codepoints, wrap, align, {}, false, false, Matrix4()}); } -int Text::add(const std::vector &text, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +int Text::add(const std::vector &text, const Matrix4 &m) { - return addf(text, -1.0f, Font::ALIGN_MAX_ENUM, x, y, angle, sx, sy, ox, oy, kx, ky); + return addf(text, -1.0f, Font::ALIGN_MAX_ENUM, m); } -int Text::addf(const std::vector &text, float wrap, Font::AlignMode align, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +int Text::addf(const std::vector &text, float wrap, Font::AlignMode align, const Matrix4 &m) { Font::ColoredCodepoints codepoints; Font::getCodepointsFromString(text, codepoints); - Matrix3 m(x, y, angle, sx, sy, ox, oy, kx, ky); - addTextData({codepoints, wrap, align, {}, true, true, m}); return (int) text_data.size() - 1; @@ -210,7 +208,7 @@ void Text::clear() vert_offset = 0; } -void Text::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Text::draw(const Matrix4 &m) { if (vbo == nullptr || draw_commands.empty()) return; @@ -227,7 +225,7 @@ void Text::draw(float x, float y, float angle, float sx, float sy, float ox, flo const size_t stride = sizeof(Font::GlyphVertex); OpenGL::TempTransform transform(gl); - transform.get() *= Matrix4(x, y, angle, sx, sy, ox, oy, kx, ky); + transform.get() *= m; { GLBuffer::Bind bind(*vbo); diff --git a/src/modules/graphics/opengl/Text.h b/src/modules/graphics/opengl/Text.h index 9293a57cb..c1ef777cd 100644 --- a/src/modules/graphics/opengl/Text.h +++ b/src/modules/graphics/opengl/Text.h @@ -44,12 +44,13 @@ public: void set(const std::vector &text); void set(const std::vector &text, float wrap, Font::AlignMode align); - int add(const std::vector &text, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); - int addf(const std::vector &text, float wrap, Font::AlignMode align, float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + int add(const std::vector &text, const Matrix4 &m); + int addf(const std::vector &text, float wrap, Font::AlignMode align, const Matrix4 &m); + void clear(); // Implements Drawable. - virtual void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); + void draw(const Matrix4 &m) override; void setFont(Font *f); Font *getFont() const; @@ -74,7 +75,7 @@ private: Font::TextInfo text_info; bool use_matrix; bool append_vertices; - Matrix3 matrix; + Matrix4 matrix; }; void uploadVertices(const std::vector &vertices, size_t vertoffset); diff --git a/src/modules/graphics/opengl/Video.cpp b/src/modules/graphics/opengl/Video.cpp index d6ce3d2ed..eb8e3b3db 100644 --- a/src/modules/graphics/opengl/Video.cpp +++ b/src/modules/graphics/opengl/Video.cpp @@ -114,7 +114,7 @@ love::video::VideoStream *Video::getStream() return stream; } -void Video::draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky) +void Video::draw(const Matrix4 &m) { update(); @@ -130,7 +130,7 @@ void Video::draw(float x, float y, float angle, float sx, float sy, float ox, fl shader->setVideoTextures(textures[0], textures[1], textures[2]); OpenGL::TempTransform transform(gl); - transform.get() *= Matrix4(x, y, angle, sx, sy, ox, oy, kx, ky); + transform.get() *= m; gl.useVertexAttribArrays(ATTRIBFLAG_POS | ATTRIBFLAG_TEXCOORD); diff --git a/src/modules/graphics/opengl/Video.h b/src/modules/graphics/opengl/Video.h index bbc92525a..2f9593f74 100644 --- a/src/modules/graphics/opengl/Video.h +++ b/src/modules/graphics/opengl/Video.h @@ -44,11 +44,13 @@ public: ~Video(); // Volatile - bool loadVolatile(); - void unloadVolatile(); + bool loadVolatile() override; + void unloadVolatile() override; + + // Drawable + void draw(const Matrix4 &m) override; love::video::VideoStream *getStream(); - void draw(float x, float y, float angle, float sx, float sy, float ox, float oy, float kx, float ky); love::audio::Source *getSource(); void setSource(love::audio::Source *source); diff --git a/src/modules/graphics/opengl/wrap_Graphics.cpp b/src/modules/graphics/opengl/wrap_Graphics.cpp index e301e78b3..db7d3eb3b 100644 --- a/src/modules/graphics/opengl/wrap_Graphics.cpp +++ b/src/modules/graphics/opengl/wrap_Graphics.cpp @@ -1551,11 +1551,13 @@ int w_draw(lua_State *L) float kx = (float) luaL_optnumber(L, startidx + 7, 0.0); float ky = (float) luaL_optnumber(L, startidx + 8, 0.0); + Matrix4 m(x, y, a, sx, sy, ox, oy, kx, ky); + luax_catchexcept(L, [&]() { if (texture && quad) - texture->drawq(quad, x, y, a, sx, sy, ox, oy, kx, ky); + texture->drawq(quad, m); else if (drawable) - drawable->draw(x, y, a, sx, sy, ox, oy, kx, ky); + drawable->draw(m); }); return 0; @@ -1576,9 +1578,9 @@ int w_print(lua_State *L) float kx = (float)luaL_optnumber(L, 9, 0.0f); float ky = (float)luaL_optnumber(L, 10, 0.0f); - luax_catchexcept(L, - [&](){ instance()->print(str, x, y, angle, sx, sy, ox, oy, kx,ky); } - ); + Matrix4 m(x, y, angle, sx, sy, ox, oy, kx, ky); + + luax_catchexcept(L, [&](){ instance()->print(str, m); }); return 0; } @@ -1616,9 +1618,9 @@ int w_printf(lua_State *L) ky = (float) luaL_optnumber(L, 12, 0.0f); } - luax_catchexcept(L, - [&](){ instance()->printf(str, x, y, wrap, align, angle, sx, sy, ox, oy, kx, ky); } - ); + Matrix4 m(x, y, angle, sx, sy, ox, oy, kx, ky); + + luax_catchexcept(L, [&](){ instance()->printf(str, wrap, align, m); }); return 0; } diff --git a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp index e1eed3773..06b0312da 100644 --- a/src/modules/graphics/opengl/wrap_SpriteBatch.cpp +++ b/src/modules/graphics/opengl/wrap_SpriteBatch.cpp @@ -61,11 +61,13 @@ static inline int w_SpriteBatch_add_or_set(lua_State *L, SpriteBatch *t, int sta float kx = (float) luaL_optnumber(L, startidx + 7, 0.0); float ky = (float) luaL_optnumber(L, startidx + 8, 0.0); + Matrix4 m(x, y, a, sx, sy, ox, oy, kx, ky); + luax_catchexcept(L, [&]() { if (quad) - index = t->addq(quad, x, y, a, sx, sy, ox, oy, kx, ky, index); + index = t->addq(quad, m, index); else - index = t->add(x, y, a, sx, sy, ox, oy, kx, ky, index); + index = t->add(m, index); }); return index; diff --git a/src/modules/graphics/opengl/wrap_Text.cpp b/src/modules/graphics/opengl/wrap_Text.cpp index 7f404c2a8..bd365e9a6 100644 --- a/src/modules/graphics/opengl/wrap_Text.cpp +++ b/src/modules/graphics/opengl/wrap_Text.cpp @@ -139,8 +139,9 @@ int w_Text_add(lua_State *L) float kx = (float) luaL_optnumber(L, 10, 0.0); float ky = (float) luaL_optnumber(L, 11, 0.0); + Matrix4 m(x, y, a, sx, sy, ox, oy, kx, ky); int index = 0; - luax_catchexcept(L, [&](){ index = t->add(text, x, y, a, sx, sy, ox, oy, kx, ky); }); + luax_catchexcept(L, [&](){ index = t->add(text, m); }); lua_pushnumber(L, index + 1); return 1; @@ -171,8 +172,9 @@ int w_Text_addf(lua_State *L) float kx = (float) luaL_optnumber(L, 12, 0.0); float ky = (float) luaL_optnumber(L, 13, 0.0); + Matrix4 m(x, y, a, sx, sy, ox, oy, kx, ky); int index = 0; - luax_catchexcept(L, [&](){ index = t->addf(text, wrap, align, x, y, a, sx, sy, ox, oy, kx, ky); }); + luax_catchexcept(L, [&](){ index = t->addf(text, wrap, align, m); }); lua_pushnumber(L, index + 1); return 1;