Batch3D update
This commit is contained in:
+45
-39
@@ -54,6 +54,18 @@ void Batch3D::vertex(float x, float y, float z, float u, float v,
|
|||||||
buffer[index++] = b;
|
buffer[index++] = b;
|
||||||
buffer[index++] = a;
|
buffer[index++] = a;
|
||||||
}
|
}
|
||||||
|
void Batch3D::vertex(vec3 coord, float u, float v,
|
||||||
|
float r, float g, float b, float a) {
|
||||||
|
buffer[index++] = coord.x;
|
||||||
|
buffer[index++] = coord.y;
|
||||||
|
buffer[index++] = coord.z;
|
||||||
|
buffer[index++] = u;
|
||||||
|
buffer[index++] = v;
|
||||||
|
buffer[index++] = r;
|
||||||
|
buffer[index++] = g;
|
||||||
|
buffer[index++] = b;
|
||||||
|
buffer[index++] = a;
|
||||||
|
}
|
||||||
void Batch3D::vertex(vec3 point,
|
void Batch3D::vertex(vec3 point,
|
||||||
vec2 uvpoint,
|
vec2 uvpoint,
|
||||||
float r, float g, float b, float a) {
|
float r, float g, float b, float a) {
|
||||||
@@ -68,6 +80,29 @@ void Batch3D::vertex(vec3 point,
|
|||||||
buffer[index++] = a;
|
buffer[index++] = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Batch3D::face(const vec3& coord, float w, float h,
|
||||||
|
const vec3& axisX,
|
||||||
|
const vec3& axisY,
|
||||||
|
const UVRegion& region,
|
||||||
|
const vec4& tint) {
|
||||||
|
if (index + VERTEX_SIZE * 4 > capacity) {
|
||||||
|
render();
|
||||||
|
}
|
||||||
|
vertex(coord, region.u1, region.v1,
|
||||||
|
tint.r, tint.g, tint.b, tint.a);
|
||||||
|
vertex(coord + axisX * w, region.u2, region.v1,
|
||||||
|
tint.r, tint.g, tint.b, tint.a);
|
||||||
|
vertex(coord + axisX * w + axisY * h, region.u2, region.v2,
|
||||||
|
tint.r, tint.g, tint.b, tint.a);
|
||||||
|
|
||||||
|
vertex(coord, region.u1, region.v1,
|
||||||
|
tint.r, tint.g, tint.b, tint.a);
|
||||||
|
vertex(coord + axisX * w + axisY * h, region.u2, region.v2,
|
||||||
|
tint.r, tint.g, tint.b, tint.a);
|
||||||
|
vertex(coord + axisY * h, region.u1, region.v2,
|
||||||
|
tint.r, tint.g, tint.b, tint.a);
|
||||||
|
}
|
||||||
|
|
||||||
void Batch3D::texture(Texture* new_texture){
|
void Batch3D::texture(Texture* new_texture){
|
||||||
if (_texture == new_texture)
|
if (_texture == new_texture)
|
||||||
return;
|
return;
|
||||||
@@ -124,46 +159,17 @@ void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h){
|
|||||||
r,g,b,a);
|
r,g,b,a);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch3D::sprite(vec3 pos, vec3 up, vec3 right, float w, float h, int atlasRes, int index, vec4 tint){
|
inline vec4 do_tint(float value) {
|
||||||
float scale = 1.0f / (float)atlasRes;
|
return vec4(value, value, value, 1.0f);
|
||||||
float u = (index % atlasRes) * scale;
|
}
|
||||||
float v = 1.0f - ((index / atlasRes) * scale) - scale;
|
|
||||||
|
|
||||||
vertex(pos.x - right.x * w - up.x * h,
|
void Batch3D::blockCube(const vec3& size, const UVRegion(&texfaces)[6], ubyte group) {
|
||||||
pos.y - right.y * w - up.y * h,
|
face(vec3(0.0f, 0.0f, 0.0f), size.x, size.y, vec3(1, 0, 0), vec3(0, 1, 0), texfaces[5], do_tint(1.0));
|
||||||
pos.z - right.z * w - up.z * h,
|
face(vec3(size.x, 0.0f, -size.z), size.x, size.y, vec3(-1, 0, 0), vec3(0, 1, 0), texfaces[4], vec4(1.0f));
|
||||||
u, v,
|
face(vec3(0.0f, size.y, 0.0f), size.x, size.z, vec3(1, 0, 0), vec3(0, 0, -1), texfaces[3], vec4(1.0f));
|
||||||
tint.r,tint.g,tint.b,tint.a);
|
face(vec3(0.0f, 0.0f, -size.z), size.x, size.z, vec3(1, 0, 0), vec3(0, 0, 1), texfaces[2], vec4(1.0f));
|
||||||
|
face(vec3(0.0f, 0.0f, -size.z), size.z, size.y, vec3(0, 0, 1), vec3(0, 1, 0), texfaces[0], vec4(1.0f));
|
||||||
vertex(pos.x + right.x * w + up.x * h,
|
face(vec3(size.x, 0.0f, 0.0f), size.z, size.y, vec3(0, 0, -1), vec3(0, 1, 0), texfaces[1], vec4(1.0f));
|
||||||
pos.y + right.y * w + up.y * h,
|
|
||||||
pos.z + right.z * w + up.z * h,
|
|
||||||
u+scale, v+scale,
|
|
||||||
tint.r,tint.g,tint.b,tint.a);
|
|
||||||
|
|
||||||
vertex(pos.x - right.x * w - up.x * h,
|
|
||||||
pos.y + right.y * w + up.y * h,
|
|
||||||
pos.z - right.z * w - up.z * h,
|
|
||||||
u, v+scale,
|
|
||||||
tint.r,tint.g,tint.b,tint.a);
|
|
||||||
|
|
||||||
vertex(pos.x - right.x * w - up.x * h,
|
|
||||||
pos.y - right.y * w - up.y * h,
|
|
||||||
pos.z - right.z * w - up.z * h,
|
|
||||||
u, v,
|
|
||||||
tint.r,tint.g,tint.b,tint.a);
|
|
||||||
|
|
||||||
vertex(pos.x + right.x * w + up.x * h,
|
|
||||||
pos.y - right.y * w - up.y * h,
|
|
||||||
pos.z + right.z * w + up.z * h,
|
|
||||||
u+scale, v,
|
|
||||||
tint.r,tint.g,tint.b,tint.a);
|
|
||||||
|
|
||||||
vertex(pos.x + right.x * w + up.x * h,
|
|
||||||
pos.y + right.y * w + up.y * h,
|
|
||||||
pos.z + right.z * w + up.z * h,
|
|
||||||
u+scale, v+scale,
|
|
||||||
tint.r,tint.g,tint.b,tint.a);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Batch3D::render() {
|
void Batch3D::render() {
|
||||||
|
|||||||
+11
-2
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
#include "UVRegion.h"
|
||||||
|
|
||||||
class Mesh;
|
class Mesh;
|
||||||
class Texture;
|
class Texture;
|
||||||
@@ -21,18 +22,26 @@ class Batch3D {
|
|||||||
void vertex(float x, float y, float z,
|
void vertex(float x, float y, float z,
|
||||||
float u, float v,
|
float u, float v,
|
||||||
float r, float g, float b, float a);
|
float r, float g, float b, float a);
|
||||||
|
void vertex(glm::vec3 coord,
|
||||||
|
float u, float v,
|
||||||
|
float r, float g, float b, float a);
|
||||||
void vertex(glm::vec3 point, glm::vec2 uvpoint,
|
void vertex(glm::vec3 point, glm::vec2 uvpoint,
|
||||||
float r, float g, float b, float a);
|
float r, float g, float b, float a);
|
||||||
|
|
||||||
|
void face(const glm::vec3& coord, float w, float h,
|
||||||
|
const glm::vec3& axisX,
|
||||||
|
const glm::vec3& axisY,
|
||||||
|
const UVRegion& region,
|
||||||
|
const glm::vec4& tint);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Batch3D(size_t capacity);
|
Batch3D(size_t capacity);
|
||||||
~Batch3D();
|
~Batch3D();
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void texture(Texture* texture);
|
void texture(Texture* texture);
|
||||||
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h,
|
|
||||||
int atlasRes, int index, glm::vec4 tint);
|
|
||||||
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h);
|
void sprite(glm::vec3 pos, glm::vec3 up, glm::vec3 right, float w, float h);
|
||||||
|
void blockCube(const glm::vec3& size, const UVRegion(&texfaces)[6], ubyte group);
|
||||||
void render();
|
void render();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user