Refactor Buffer internals.

Allows buffers created with love.graphics.newBuffer to only allocate VRAM data. Previously they had a copy of their contents in RAM.
Also makes it easier to implement Buffers in other graphics APIs and to implement more types of Buffers in the future.
This commit is contained in:
Alex Szpakowski
2020-12-22 19:23:02 -04:00
parent a1861a8ff4
commit 1f9d98263d
23 changed files with 504 additions and 523 deletions
+8 -4
View File
@@ -30,6 +30,7 @@
#include "common/math.h"
#include "common/Matrix.h"
#include "common/Color.h"
#include "common/Range.h"
#include "Drawable.h"
#include "Mesh.h"
#include "vertex.h"
@@ -90,10 +91,13 @@ public:
int getBufferSize() const;
/**
* Attaches a specific vertex attribute from a Mesh to this SpriteBatch.
* Attaches a specific vertex attribute from a Buffer to this SpriteBatch.
* The vertex attribute will be used when drawing the SpriteBatch.
* If the attribute comes from a Mesh, it should be given as an argument as
* well, to make sure the SpriteBatch flushes its data to its Buffer when
* the SpriteBatch is drawn.
**/
void attachAttribute(const std::string &name, Buffer *buffer);
void attachAttribute(const std::string &name, Buffer *buffer, Mesh *mesh);
void setDrawRange(int start, int count);
void setDrawRange();
@@ -107,6 +111,7 @@ private:
struct AttachedAttribute
{
StrongRef<Buffer> buffer;
StrongRef<Mesh> mesh;
int index;
};
@@ -134,8 +139,7 @@ private:
StrongRef<love::graphics::Buffer> array_buf;
uint8 *vertex_data;
int modified_sprite_first;
int modified_sprite_last;
Range modified_sprites;
std::unordered_map<std::string, AttachedAttribute> attached_attributes;