Abstracted lower level drawing code, moved all type-specific drawing code out of opengl backend, deleted obsolete files

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-10-26 20:58:19 -03:00
parent 7ffb04f019
commit e3fd489373
22 changed files with 109 additions and 630 deletions
+28
View File
@@ -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<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage)
{
return new Mesh(this, vertexformat, vertexcount, drawmode, usage);
}
love::graphics::Mesh *Graphics::newMesh(const std::vector<Mesh::AttribFormat> &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<Font::ColoredString> &text)
{
return new Text(this, font, text);
}
void Graphics::cleanupCachedShaderStage(ShaderStage::StageType type, const std::string &hashkey)
{
cachedShaderStages[type].erase(hashkey);
+8 -7
View File
@@ -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<Vertex> &vertices, PrimitiveType drawmode, vertex::Usage usage);
Mesh *newMesh(int vertexcount, PrimitiveType drawmode, vertex::Usage usage);
Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage);
Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage);
virtual Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) = 0;
virtual Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) = 0;
virtual Text *newText(Font *font, const std::vector<Font::ColoredString> &text = {}) = 0;
Text *newText(Font *font, const std::vector<Font::ColoredString> &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);
+8 -7
View File
@@ -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
+1 -3
View File
@@ -174,7 +174,7 @@ public:
static std::vector<AttribFormat> 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<AttribFormat> vertexFormat;
std::vector<size_t> attributeSizes;
+8 -1
View File
@@ -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)
+16 -20
View File
@@ -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<std::string> 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<AreaSpreadDistribution, DISTRIBUTION_MAX_ENUM>::Entry distributionsEntries[];
static StringMap<AreaSpreadDistribution, DISTRIBUTION_MAX_ENUM> distributions;
+1 -1
View File
@@ -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
+1 -3
View File
@@ -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> texture;
// Max number of sprites in the batch.
+10 -1
View File
@@ -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
+1 -3
View File
@@ -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<Font::DrawCommand> &commands) const = 0;
StrongRef<Font> font;
vertex::Attributes vertexAttributes;
+24 -26
View File
@@ -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<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage)
{
return new Mesh(this, vertexformat, vertexcount, drawmode, usage);
}
love::graphics::Mesh *Graphics::newMesh(const std::vector<Mesh::AttribFormat> &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<Font::ColoredString> &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.
+3 -13
View File
@@ -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<Mesh::AttribFormat> &vertexformat, int vertexcount, PrimitiveType drawmode, vertex::Usage usage) override;
love::graphics::Mesh *newMesh(const std::vector<Mesh::AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage) override;
love::graphics::Text *newText(love::graphics::Font *font, const std::vector<Font::ColoredString> &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<OptionalColorf> &colors, OptionalInt stencil, OptionalDouble depth) override;
-79
View File
@@ -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 <algorithm>
#include <limits>
namespace love
{
namespace graphics
{
namespace opengl
{
Mesh::Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &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<AttribFormat> &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
-50
View File
@@ -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<AttribFormat> &vertexformat, const void *data, size_t datasize, PrimitiveType drawmode, vertex::Usage usage);
Mesh(graphics::Graphics *gfx, const std::vector<AttribFormat> &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
@@ -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
@@ -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
@@ -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 <algorithm>
// C
#include <stddef.h>
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
-48
View File
@@ -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
-69
View File
@@ -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 <algorithm>
namespace love
{
namespace graphics
{
namespace opengl
{
Text::Text(love::graphics::Graphics *gfx, love::graphics::Font *font, const std::vector<Font::ColoredString> &text)
: love::graphics::Text(gfx, font, text)
{
}
Text::~Text()
{
}
void Text::drawInternal(const std::vector<Font::DrawCommand> &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
-49
View File
@@ -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<Font::ColoredString> &text = {});
virtual ~Text();
protected:
void drawInternal(const std::vector<Font::DrawCommand> &commands) const override;
}; // Text
} // opengl
} // graphics
} // love