refactor: Batch2D and Batch3D
This commit is contained in:
@@ -13,19 +13,18 @@ Batch2D::Batch2D(size_t capacity) : capacity(capacity), color(1.0f){
|
||||
{2}, {2}, {4}, {0}
|
||||
};
|
||||
|
||||
buffer = new float[capacity * B2D_VERTEX_SIZE];
|
||||
mesh = std::make_unique<Mesh>(buffer, 0, attrs);
|
||||
buffer = std::make_unique<float[]>(capacity * B2D_VERTEX_SIZE);
|
||||
mesh = std::make_unique<Mesh>(buffer.get(), 0, attrs);
|
||||
index = 0;
|
||||
|
||||
ubyte pixels[] = {
|
||||
0xFF, 0xFF, 0xFF, 0xFF
|
||||
};
|
||||
blank = std::make_unique<Texture>(pixels, 1, 1, ImageFormat::rgba8888);
|
||||
_texture = nullptr;
|
||||
currentTexture = nullptr;
|
||||
}
|
||||
|
||||
Batch2D::~Batch2D(){
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
void Batch2D::setPrimitive(DrawPrimitive primitive) {
|
||||
@@ -37,7 +36,7 @@ void Batch2D::setPrimitive(DrawPrimitive primitive) {
|
||||
}
|
||||
|
||||
void Batch2D::begin(){
|
||||
_texture = nullptr;
|
||||
currentTexture = nullptr;
|
||||
blank->bind();
|
||||
color = glm::vec4(1.0f);
|
||||
primitive = DrawPrimitive::triangle;
|
||||
@@ -73,14 +72,16 @@ void Batch2D::vertex(
|
||||
}
|
||||
|
||||
void Batch2D::texture(Texture* new_texture){
|
||||
if (_texture == new_texture)
|
||||
if (currentTexture == new_texture) {
|
||||
return;
|
||||
}
|
||||
flush();
|
||||
_texture = new_texture;
|
||||
if (new_texture == nullptr)
|
||||
currentTexture = new_texture;
|
||||
if (new_texture == nullptr) {
|
||||
blank->bind();
|
||||
else
|
||||
} else {
|
||||
new_texture->bind();
|
||||
}
|
||||
}
|
||||
|
||||
void Batch2D::untexture() {
|
||||
@@ -327,7 +328,7 @@ void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index
|
||||
void Batch2D::flush() {
|
||||
if (index == 0)
|
||||
return;
|
||||
mesh->reload(buffer, index / B2D_VERTEX_SIZE);
|
||||
mesh->reload(buffer.get(), index / B2D_VERTEX_SIZE);
|
||||
mesh->draw(gl::to_glenum(primitive));
|
||||
index = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user