ui update,many fixes

This commit is contained in:
lllzebralll
2022-12-08 01:03:12 +03:00
parent f04bac6b43
commit a1f9155498
12 changed files with 312 additions and 208 deletions
+117 -96
View File
@@ -62,7 +62,7 @@ void Batch2D::vertex(vec2 point,
void Batch2D::texture(Texture* new_texture){
if (_texture == new_texture)
return;
render();
render(GL_TRIANGLES);
_texture = new_texture;
if (new_texture == nullptr)
blank->bind();
@@ -70,21 +70,39 @@ void Batch2D::texture(Texture* new_texture){
new_texture->bind();
}
void Batch2D::point(float x, float y, float r, float g, float b, float a){
// if (index + 6*VERTEX_SIZE >= capacity)
// render(GL_TRIANGLES);
vertex(x, y, 0, 0, r,g,b,a);
render(GL_POINTS);
}
void Batch2D::line(float x1, float y1, float x2, float y2, float r, float g, float b, float a){
// if (index + 6*VERTEX_SIZE >= capacity)
// render(GL_TRIANGLES);
vertex(x1, y1, 0, 0, r,g,b,a);
vertex(x2, y2, 1, 1, r,g,b,a);
render(GL_LINES);
}
void Batch2D::rect(float x, float y, float w, float h){
const float r = color.r;
const float g = color.g;
const float b = color.b;
const float a = color.a;
if (index + 6*VERTEX_SIZE >= capacity)
render();
// if (index + 6*VERTEX_SIZE >= capacity)
// render(GL_TRIANGLES);
vertex(x, y, 0, 0, r,g,b,a);
vertex(x+w, y+h, 1, 1, r,g,b,a);
vertex(x, y+h, 0, 1, r,g,b,a);
vertex(x+w, y+h, 1, 1, r,g,b,a);
vertex(x, y, 0, 0, r,g,b,a);
vertex(x+w, y, 1, 0, r,g,b,a);
vertex(x+w, y+h, 1, 1, r,g,b,a);
vertex(x+w, y, 1, 0, r,g,b,a);
render(GL_TRIANGLES);
}
void Batch2D::rect(
@@ -96,8 +114,8 @@ void Batch2D::rect(
bool flippedX,
bool flippedY,
vec4 tint) {
if (index + 6*VERTEX_SIZE >= capacity)
render();
// if (index + 6*VERTEX_SIZE >= capacity)
// render(GL_TRIANGLES);
float centerX = w*ox;
float centerY = h*oy;
@@ -179,96 +197,14 @@ void Batch2D::rect(
vertex(x1, y1, u1, v1, tint.r, tint.g, tint.b, tint.a);
vertex(x3, y3, u3, v3, tint.r, tint.g, tint.b, tint.a);
vertex(x4, y4, u4, v4, tint.r, tint.g, tint.b, tint.a);
}
void Batch2D::sprite(Sprite* sprite) {
vec2 position = sprite->position;
vec2 size = sprite->size;
vec2 origin = sprite->origin;
texture(sprite->texture);
rect(
position.x, position.y,
size.x, size.y,
origin.x, origin.y,
sprite->angle,
sprite->region,
sprite->flippedX,
sprite->flippedY,
sprite->color);
}
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint){
float scale = 1.0f / (float)atlasRes;
float u = (index % atlasRes) * scale;
float v = 1.0f - ((index / atlasRes) * scale) - scale;
rect(x, y, w, h, u, v, scale, scale, tint.r, tint.g, tint.b, tint.a);
}
void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int index[6], vec4 tint){
float scale = 1.0f / (float)atlasRes;
float uu = (index[3] % atlasRes) * scale;
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
float uf = (index[0] % atlasRes) * scale;
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
// if (this->index + 18*VERTEX_SIZE >= capacity)
render();
float ar = 0.88f;
float ox = x + (w * 0.5f);
float sx = w * 0.5f * ar;
vec2 points[7] = {vec2(ox, y+(h*0.5f)),
vec2(ox-sx, y+(h*0.25f)),
vec2(ox, y),
vec2(ox+sx, y+(h*0.25f)),
vec2(ox+sx, y+(h*0.75f)),
vec2(ox, y+h),
vec2(ox-sx, y+(h*0.75f))};
vec2 uvpoints[8] = {vec2(uu, vu),
vec2(uu+scale, vu),
vec2(uu+scale, vu+scale),
vec2(uu, vu+scale),
vec2(uf, vf),
vec2(uf+scale, vf),
vec2(uf+scale, vf+scale),
vec2(uf, vf+scale)};
vertex(points[0], uvpoints[3], tint.r, tint.g, tint.b, tint.a);
vertex(points[1], uvpoints[0], tint.r, tint.g, tint.b, tint.a);
vertex(points[2], uvpoints[1], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[3], tint.r, tint.g, tint.b, tint.a);
vertex(points[2], uvpoints[1], tint.r, tint.g, tint.b, tint.a);
vertex(points[3], uvpoints[2], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
vertex(points[3], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
vertex(points[4], uvpoints[5], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
vertex(points[4], uvpoints[5], tint.r, tint.g, tint.b, tint.a);
vertex(points[5], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
vertex(points[5], uvpoints[5], tint.r, tint.g, tint.b, tint.a);
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
glDisable(GL_MULTISAMPLE);
render();
glEnable(GL_MULTISAMPLE);
render(GL_TRIANGLES);
}
void Batch2D::rect(float x, float y, float w, float h,
float u, float v, float tx, float ty,
float r, float g, float b, float a){
if (index + 6*VERTEX_SIZE >= capacity)
render();
// if (index + 6*VERTEX_SIZE >= capacity)
// render(GL_TRIANGLES);
vertex(x, y, u, v+ty, r,g,b,a);
vertex(x+w, y+h, u+tx, v, r,g,b,a);
vertex(x, y+h, u, v, r,g,b,a);
@@ -276,6 +212,7 @@ void Batch2D::rect(float x, float y, float w, float h,
vertex(x, y, u, v+ty, r,g,b,a);
vertex(x+w, y, u+tx, v+ty, r,g,b,a);
vertex(x+w, y+h, u+tx, v, r,g,b,a);
render(GL_TRIANGLES);
}
void Batch2D::rect(float x, float y, float w, float h,
@@ -284,8 +221,8 @@ void Batch2D::rect(float x, float y, float w, float h,
float r2, float g2, float b2,
float r3, float g3, float b3,
float r4, float g4, float b4, int sh){
if (index + 30*VERTEX_SIZE >= capacity)
render();
// if (index + 30*VERTEX_SIZE >= capacity)
// render(GL_TRIANGLES);
vec2 v0 = vec2(x+h/2,y+h/2);
vec2 v1 = vec2(x+w-sh,y);
vec2 v2 = vec2(x+sh,y);
@@ -336,10 +273,94 @@ void Batch2D::rect(float x, float y, float w, float h,
vertex(v6, vec2(0, 0), r2,g2,b2,1.0f);
vertex(v9, vec2(0, 0), r2,g2,b2,1.0f);
vertex(v1, vec2(0, 0), r2,g2,b2,1.0f);
render(GL_TRIANGLES);
}
void Batch2D::render() {
void Batch2D::sprite(Sprite* sprite) {
vec2 position = sprite->position;
vec2 size = sprite->size;
vec2 origin = sprite->origin;
texture(sprite->texture);
rect(
position.x, position.y,
size.x, size.y,
origin.x, origin.y,
sprite->angle,
sprite->region,
sprite->flippedX,
sprite->flippedY,
sprite->color);
}
void Batch2D::sprite(float x, float y, float w, float h, int atlasRes, int index, vec4 tint){
float scale = 1.0f / (float)atlasRes;
float u = (index % atlasRes) * scale;
float v = 1.0f - ((index / atlasRes) * scale) - scale;
rect(x, y, w, h, u, v, scale, scale, tint.r, tint.g, tint.b, tint.a);
}
void Batch2D::blockSprite(float x, float y, float w, float h, int atlasRes, int index[6], vec4 tint){
float scale = 1.0f / (float)atlasRes;
float uu = (index[3] % atlasRes) * scale;
float vu = 1.0f - ((index[3] / atlasRes) * scale) - scale;
float uf = (index[0] % atlasRes) * scale;
float vf = 1.0f - ((index[0] / atlasRes) * scale) - scale;
// if (this->index + 18*VERTEX_SIZE >= capacity)
// render();
float ar = 0.88f;
float ox = x + (w * 0.5f);
float sx = w * 0.5f * ar;
vec2 points[7] = {vec2(ox, y+(h*0.5f)),
vec2(ox-sx, y+(h*0.25f)),
vec2(ox, y),
vec2(ox+sx, y+(h*0.25f)),
vec2(ox+sx, y+(h*0.75f)),
vec2(ox, y+h),
vec2(ox-sx, y+(h*0.75f))};
vec2 uvpoints[8] = {vec2(uu, vu),
vec2(uu+scale, vu),
vec2(uu+scale, vu+scale),
vec2(uu, vu+scale),
vec2(uf, vf),
vec2(uf+scale, vf),
vec2(uf+scale, vf+scale),
vec2(uf, vf+scale)};
vertex(points[0], uvpoints[3], tint.r, tint.g, tint.b, tint.a);
vertex(points[1], uvpoints[0], tint.r, tint.g, tint.b, tint.a);
vertex(points[2], uvpoints[1], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[3], tint.r, tint.g, tint.b, tint.a);
vertex(points[2], uvpoints[1], tint.r, tint.g, tint.b, tint.a);
vertex(points[3], uvpoints[2], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
vertex(points[3], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
vertex(points[4], uvpoints[5], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
vertex(points[4], uvpoints[5], tint.r, tint.g, tint.b, tint.a);
vertex(points[5], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
vertex(points[5], uvpoints[5], tint.r, tint.g, tint.b, tint.a);
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
vertex(points[0], uvpoints[6], tint.r, tint.g, tint.b, tint.a);
vertex(points[6], uvpoints[4], tint.r, tint.g, tint.b, tint.a);
vertex(points[1], uvpoints[7], tint.r, tint.g, tint.b, tint.a);
glDisable(GL_MULTISAMPLE);
render(GL_TRIANGLES);
glEnable(GL_MULTISAMPLE);
}
void Batch2D::render(unsigned int gl_primitive) {
mesh->reload(buffer, index / VERTEX_SIZE);
mesh->draw(GL_TRIANGLES);
mesh->draw(gl_primitive);
index = 0;
}