Move backend-agnostic Mesh and SpriteBatch code out of the opengl implementation folder.

--HG--
branch : minor
This commit is contained in:
Alex Szpakowski
2017-01-29 01:05:20 -04:00
parent 3616470a0a
commit c0e66eba83
22 changed files with 1440 additions and 1246 deletions
+145
View File
@@ -0,0 +1,145 @@
/**
* 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
// C
#include <cstring>
// C++
#include <unordered_map>
// LOVE
#include "common/math.h"
#include "common/Matrix.h"
#include "Drawable.h"
#include "Color.h"
#include "Mesh.h"
namespace love
{
namespace graphics
{
// Forward declarations.
class Graphics;
class Texture;
class Quad;
class Buffer;
class SpriteBatch : public Drawable
{
public:
static love::Type type;
SpriteBatch(Graphics *gfx, Texture *texture, int size, vertex::Usage usage);
virtual ~SpriteBatch();
int add(const Matrix4 &m, int index = -1);
int addq(Quad *quad, const Matrix4 &m, int index = -1);
void clear();
void flush();
void setTexture(Texture *newtexture);
Texture *getTexture() const;
/**
* Set the current color for this SpriteBatch. The sprites added
* after this call will use this color. Note that global color
* will not longer apply to the SpriteBatch if this is used.
*
* @param color The color to use for the following sprites.
*/
void setColor(const Color &color);
/**
* Disable per-sprite colors for this SpriteBatch. The next call to
* draw will use the global color for all sprites.
*/
void setColor();
/**
* Get the current color for this SpriteBatch. Returns NULL if no color is
* set.
**/
const Color *getColor() const;
/**
* Get the number of sprites currently in this SpriteBatch.
**/
int getCount() const;
/**
* Get the total number of sprites this SpriteBatch can currently hold.
**/
int getBufferSize() const;
/**
* Attaches a specific vertex attribute from a Mesh to this SpriteBatch.
* The vertex attribute will be used when drawing the SpriteBatch.
**/
void attachAttribute(const std::string &name, Mesh *mesh);
void setDrawRange(int start, int count);
void setDrawRange();
bool getDrawRange(int &start, int &count) const;
protected:
struct AttachedAttribute
{
StrongRef<Mesh> mesh;
int index;
};
/**
* Sets the total number of sprites this SpriteBatch can hold.
* Leaves existing sprite data intact when possible.
**/
void setBufferSize(int newsize);
void addv(const Vertex *v, const Matrix4 &m, int index);
StrongRef<Texture> texture;
// Max number of sprites in the batch.
int size;
// The next free element.
int next;
// Current color. This color, if present, will be applied to the next
// added sprite.
Color *color;
love::graphics::Buffer *array_buf;
QuadIndices quad_indices;
std::unordered_map<std::string, AttachedAttribute> attached_attributes;
int range_start;
int range_count;
}; // SpriteBatch
} // graphics
} // love