add <image ...> atlases support

This commit is contained in:
MihailRis
2024-06-30 22:05:12 +03:00
parent c0dca31e98
commit 2dffdf757c
7 changed files with 56 additions and 17 deletions
+11 -4
View File
@@ -39,6 +39,7 @@ void Batch2D::setPrimitive(DrawPrimitive primitive) {
void Batch2D::begin(){
currentTexture = nullptr;
blank->bind();
region = blank->getUVRegion();
color = glm::vec4(1.0f);
primitive = DrawPrimitive::triangle;
}
@@ -50,8 +51,8 @@ void Batch2D::vertex(
) {
buffer[index++] = x;
buffer[index++] = y;
buffer[index++] = u;
buffer[index++] = v;
buffer[index++] = u * region.getWidth() + region.u1;
buffer[index++] = v * region.getHeight() + region.v1;
buffer[index++] = r;
buffer[index++] = g;
buffer[index++] = b;
@@ -64,8 +65,8 @@ void Batch2D::vertex(
) {
buffer[index++] = point.x;
buffer[index++] = point.y;
buffer[index++] = uvpoint.x;
buffer[index++] = uvpoint.y;
buffer[index++] = uvpoint.x * region.getWidth() + region.u1;
buffer[index++] = uvpoint.y * region.getHeight() + region.v1;
buffer[index++] = r;
buffer[index++] = g;
buffer[index++] = b;
@@ -80,8 +81,10 @@ void Batch2D::texture(Texture* new_texture){
currentTexture = new_texture;
if (new_texture == nullptr) {
blank->bind();
region = blank->getUVRegion();
} else {
new_texture->bind();
region = currentTexture->getUVRegion();
}
}
@@ -89,6 +92,10 @@ void Batch2D::untexture() {
texture(nullptr);
}
void Batch2D::setRegion(UVRegion region) {
this->region = region;
}
void Batch2D::point(float x, float y, float r, float g, float b, float a){
if (index + 6*B2D_VERTEX_SIZE >= capacity)
flush();