Move more love.graphics backend-agnostic module code out of the opengl implementation file.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2016-12-30 14:32:11 -04:00
parent c7419e0e37
commit d94b363b39
4 changed files with 148 additions and 148 deletions
+124
View File
@@ -205,6 +205,67 @@ Graphics::StreamVertexData Graphics::requestStreamDraw(const StreamDrawRequest &
return d;
}
void Graphics::draw(Drawable *drawable, const Matrix4 &m)
{
drawable->draw(this, m);
}
void Graphics::draw(Texture *texture, Quad *quad, const Matrix4 &m)
{
texture->drawq(this, quad, m);
}
/**
* Primitives
**/
void Graphics::points(const float *coords, const Colorf *colors, size_t numpoints)
{
StreamDrawRequest req;
req.primitiveMode = vertex::PrimitiveMode::POINTS;
req.formats[0] = vertex::CommonFormat::XYf;
if (colors)
req.formats[1] = vertex::CommonFormat::RGBAub;
req.vertexCount = (int) numpoints;
StreamVertexData data = requestStreamDraw(req);
const Matrix4 &t = getTransform();
t.transform((Vector *) data.stream[0], (const Vector *) coords, req.vertexCount);
Color *colordata = (Color *) data.stream[1];
if (colors)
{
Colorf nc = getColor();
gammaCorrectColor(nc);
if (isGammaCorrect())
{
for (int i = 0; i < req.vertexCount; i++)
{
Colorf ci = colors[i];
gammaCorrectColor(ci);
ci *= nc;
unGammaCorrectColor(ci);
colordata[i] = toColor(ci);
}
}
else
{
for (int i = 0; i < req.vertexCount; i++)
colordata[i] = toColor(nc * colors[i]);
}
}
else
{
Color c = toColor(getColor());
for (int i = 0; i < req.vertexCount; i++)
colordata[i] = c;
}
}
int Graphics::calculateEllipsePoints(float rx, float ry) const
{
int points = (int) sqrtf(((rx + ry) / 2.0f) * 20.0f * (float) pixelScaleStack.back());
@@ -488,6 +549,69 @@ void Graphics::popTransform()
transformStack.pop_back();
}
void Graphics::rotate(float r)
{
transformStack.back().rotate(r);
}
void Graphics::scale(float x, float y)
{
transformStack.back().scale(x, y);
pixelScaleStack.back() *= (fabs(x) + fabs(y)) / 2.0;
}
void Graphics::translate(float x, float y)
{
transformStack.back().translate(x, y);
}
void Graphics::shear(float kx, float ky)
{
transformStack.back().shear(kx, ky);
}
void Graphics::origin()
{
transformStack.back().setIdentity();
pixelScaleStack.back() = 1;
}
void Graphics::applyTransform(love::math::Transform *transform)
{
Matrix4 &m = transformStack.back();
m *= transform->getMatrix();
float sx, sy;
m.getApproximateScale(sx, sy);
pixelScaleStack.back() = (sx + sy) / 2.0;
}
void Graphics::replaceTransform(love::math::Transform *transform)
{
const Matrix4 &m = transform->getMatrix();
transformStack.back() = m;
float sx, sy;
m.getApproximateScale(sx, sy);
pixelScaleStack.back() = (sx + sy) / 2.0;
}
Vector Graphics::transformPoint(Vector point)
{
Vector p;
transformStack.back().transform(&p, &point, 1);
return p;
}
Vector Graphics::inverseTransformPoint(Vector point)
{
Vector p;
// TODO: We should probably cache the inverse transform so we don't have to
// re-calculate it every time this is called.
transformStack.back().inverse().transform(&p, &point, 1);
return p;
}
bool Graphics::getConstant(const char *in, DrawMode &out)
{
return drawModes.find(in, out);
+24
View File
@@ -25,10 +25,12 @@
#include "common/config.h"
#include "common/Module.h"
#include "common/StringMap.h"
#include "common/Vector.h"
#include "StreamBuffer.h"
#include "vertex.h"
#include "Color.h"
#include "Texture.h"
#include "math/Transform.h"
// C++
#include <string>
@@ -333,6 +335,16 @@ public:
virtual LineStyle getLineStyle() const = 0;
virtual LineJoin getLineJoin() const = 0;
void draw(Drawable *drawable, const Matrix4 &m);
void draw(Texture *texture, Quad *quad, const Matrix4 &m);
/**
* Draws a point at (x,y).
* @param x Point along x-axis.
* @param y Point along y-axis.
**/
void points(const float *coords, const Colorf *colors, size_t numpoints);
/**
* Draws a series of lines connecting the given vertices.
* @param coords Vertex components (x1, y1, ..., xn, yn). If x1,y1 == xn,yn the line will be drawn closed.
@@ -416,6 +428,18 @@ public:
const Matrix4 &getTransform() const;
const Matrix4 &getProjection() const;
void rotate(float r);
void scale(float x, float y = 1.0f);
void translate(float x, float y);
void shear(float kx, float ky);
void origin();
void applyTransform(love::math::Transform *transform);
void replaceTransform(love::math::Transform *transform);
Vector transformPoint(Vector point);
Vector inverseTransformPoint(Vector point);
template <typename T>
T *getScratchBuffer(size_t count)
{
-124
View File
@@ -1775,16 +1775,6 @@ bool Graphics::isWireframe() const
return states.back().wireframe;
}
void Graphics::draw(Drawable *drawable, const Matrix4 &m)
{
drawable->draw(this, m);
}
void Graphics::draw(Texture *texture, Quad *quad, const Matrix4 &m)
{
texture->drawq(this, quad, m);
}
void Graphics::print(const std::vector<Font::ColoredString> &str, const Matrix4 &m)
{
checkSetDefaultFont();
@@ -1805,57 +1795,6 @@ void Graphics::printf(const std::vector<Font::ColoredString> &str, float wrap, F
state.font->printf(this, str, wrap, align, m, state.color);
}
/**
* Primitives
**/
void Graphics::points(const float *coords, const Colorf *colors, size_t numpoints)
{
StreamDrawRequest req;
req.primitiveMode = vertex::PrimitiveMode::POINTS;
req.formats[0] = vertex::CommonFormat::XYf;
if (colors)
req.formats[1] = vertex::CommonFormat::RGBAub;
req.vertexCount = (int) numpoints;
StreamVertexData data = requestStreamDraw(req);
const Matrix4 &t = getTransform();
t.transform((Vector *) data.stream[0], (const Vector *) coords, req.vertexCount);
Color *colordata = (Color *) data.stream[1];
if (colors)
{
Colorf nc = getColor();
gammaCorrectColor(nc);
if (isGammaCorrect())
{
for (int i = 0; i < req.vertexCount; i++)
{
Colorf ci = colors[i];
gammaCorrectColor(ci);
ci *= nc;
unGammaCorrectColor(ci);
colordata[i] = toColor(ci);
}
}
else
{
for (int i = 0; i < req.vertexCount; i++)
colordata[i] = toColor(nc * colors[i]);
}
}
else
{
Color c = toColor(getColor());
for (int i = 0; i < req.vertexCount; i++)
colordata[i] = c;
}
}
Graphics::RendererInfo Graphics::getRendererInfo() const
{
RendererInfo info;
@@ -1980,69 +1919,6 @@ void Graphics::pop()
stackTypes.pop_back();
}
void Graphics::rotate(float r)
{
transformStack.back().rotate(r);
}
void Graphics::scale(float x, float y)
{
transformStack.back().scale(x, y);
pixelScaleStack.back() *= (fabs(x) + fabs(y)) / 2.0;
}
void Graphics::translate(float x, float y)
{
transformStack.back().translate(x, y);
}
void Graphics::shear(float kx, float ky)
{
transformStack.back().shear(kx, ky);
}
void Graphics::origin()
{
transformStack.back().setIdentity();
pixelScaleStack.back() = 1;
}
void Graphics::applyTransform(love::math::Transform *transform)
{
Matrix4 &m = transformStack.back();
m *= transform->getMatrix();
float sx, sy;
m.getApproximateScale(sx, sy);
pixelScaleStack.back() = (sx + sy) / 2.0;
}
void Graphics::replaceTransform(love::math::Transform *transform)
{
const Matrix4 &m = transform->getMatrix();
transformStack.back() = m;
float sx, sy;
m.getApproximateScale(sx, sy);
pixelScaleStack.back() = (sx + sy) / 2.0;
}
Vector Graphics::transformPoint(Vector point)
{
Vector p;
transformStack.back().transform(&p, &point, 1);
return p;
}
Vector Graphics::inverseTransformPoint(Vector point)
{
Vector p;
// TODO: We should probably cache the inverse transform so we don't have to
// re-calculate it every time this is called.
transformStack.back().inverse().transform(&p, &point, 1);
return p;
}
} // opengl
} // graphics
} // love
-24
View File
@@ -38,8 +38,6 @@
#include "video/VideoStream.h"
#include "math/Transform.h"
#include "graphics/Font.h"
#include "Image.h"
#include "graphics/Quad.h"
@@ -308,9 +306,6 @@ public:
**/
bool isWireframe() const;
void draw(Drawable *drawable, const Matrix4 &m);
void draw(Texture *texture, Quad *quad, const Matrix4 &m);
/**
* Draws text at the specified coordinates
**/
@@ -321,13 +316,6 @@ public:
**/
void printf(const std::vector<Font::ColoredString> &str, float wrap, Font::AlignMode align, const Matrix4 &m);
/**
* Draws a point at (x,y).
* @param x Point along x-axis.
* @param y Point along y-axis.
**/
void points(const float *coords, const Colorf *colors, size_t numpoints);
void captureScreenshot(const ScreenshotInfo &info);
/**
@@ -352,18 +340,6 @@ public:
void push(StackType type = STACK_TRANSFORM);
void pop();
void rotate(float r);
void scale(float x, float y = 1.0f);
void translate(float x, float y);
void shear(float kx, float ky);
void origin();
void applyTransform(love::math::Transform *transform);
void replaceTransform(love::math::Transform *transform);
Vector transformPoint(Vector point);
Vector inverseTransformPoint(Vector point);
private:
struct DisplayState