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
+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