twn_draw: texture_region option for draw_billboard()
This commit is contained in:
@ -9,9 +9,10 @@
|
||||
#include <stb_ds.h>
|
||||
|
||||
|
||||
void draw_billboard(const char *texture,
|
||||
void draw_billboard(char const *texture,
|
||||
Vec3 position,
|
||||
Vec2 size,
|
||||
Rect const *texture_region,
|
||||
Color color,
|
||||
bool cylindrical)
|
||||
{
|
||||
@ -30,8 +31,12 @@ void draw_billboard(const char *texture,
|
||||
.cylindrical = cylindrical,
|
||||
.position = position,
|
||||
.size = size,
|
||||
.texture_region_opt_set = texture_region != NULL,
|
||||
};
|
||||
|
||||
if (texture_region)
|
||||
billboard.texture_region_opt = *texture_region;
|
||||
|
||||
struct SpaceBillboard *billboards = (struct SpaceBillboard *)(void *)batch_p->value.primitives;
|
||||
|
||||
arrpush(billboards, billboard);
|
||||
@ -81,10 +86,10 @@ void finally_draw_billboard_batch(struct MeshBatch const *batch,
|
||||
const float xr = srcrect.x / dims.w;
|
||||
const float yr = srcrect.y / dims.h;
|
||||
|
||||
const Vec2 uv0 = { xr, yr };
|
||||
const Vec2 uv1 = { xr, yr + hr };
|
||||
const Vec2 uv2 = { xr + wr, yr + hr };
|
||||
const Vec2 uv3 = { xr + wr, yr };
|
||||
const Vec2 uv0c = { xr, yr };
|
||||
const Vec2 uv1c = { xr, yr + hr };
|
||||
const Vec2 uv2c = { xr + wr, yr + hr };
|
||||
const Vec2 uv3c = { xr + wr, yr };
|
||||
|
||||
for (size_t batch_n = 0; batch_n <= (primitives_len - 1) / QUAD_ELEMENT_BUFFER_LENGTH; batch_n++) {
|
||||
|
||||
@ -107,6 +112,20 @@ void finally_draw_billboard_batch(struct MeshBatch const *batch,
|
||||
b = vec3_mul(right_minus_up, ((Vec3){billboard.size.x, billboard.size.y, billboard.size.x }));
|
||||
}
|
||||
|
||||
Vec2 uv0, uv1, uv2, uv3;
|
||||
if (billboard.texture_region_opt_set) {
|
||||
uv0 = (Vec2){ (srcrect.x + billboard.texture_region_opt.x) / dims.w,
|
||||
(srcrect.y + billboard.texture_region_opt.y) / dims.h };
|
||||
uv1 = (Vec2){ (srcrect.x + billboard.texture_region_opt.x) / dims.w,
|
||||
(srcrect.y + billboard.texture_region_opt.y + billboard.texture_region_opt.h) / dims.h };
|
||||
uv2 = (Vec2){ (srcrect.x + billboard.texture_region_opt.x + billboard.texture_region_opt.w) / dims.w,
|
||||
(srcrect.y + billboard.texture_region_opt.y + billboard.texture_region_opt.h) / dims.h };
|
||||
uv3 = (Vec2){ (srcrect.x + billboard.texture_region_opt.x + billboard.texture_region_opt.w) / dims.w,
|
||||
(srcrect.y + billboard.texture_region_opt.y) / dims.h };
|
||||
} else {
|
||||
uv0 = uv0c; uv1 = uv1c; uv2 = uv2c; uv3 = uv3c;
|
||||
}
|
||||
|
||||
struct ElementIndexedBillboard const payload = {
|
||||
/* flat shading is assumed, so we can skip setting the duplicates */
|
||||
.c0 = billboard.color,
|
||||
|
@ -121,6 +121,8 @@ typedef struct SpaceBillboard {
|
||||
Vec3 position;
|
||||
Vec2 size;
|
||||
Color color;
|
||||
m_option_list(
|
||||
Rect, texture_region )
|
||||
// TextureKey texture; /* is assumed from other places */
|
||||
bool cylindrical;
|
||||
} SpaceBillboard;
|
||||
|
Reference in New Issue
Block a user