Estella 0.113.0
A fast 2D and 3D game engine powered by WebAssembly and ECS
Loading...
Searching...
No Matches
BatchVertex.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
3#pragma once
4
7#include <glm/glm.hpp>
8
9namespace esengine {
10
11inline constexpr i32 BATCH_SLOT_BITS = 3;
14inline constexpr i32 BATCH_DITHER_BIT = 1 << 8;
15inline constexpr i32 BATCH_DITHER_PHASE_BIT = 1 << 9;
16
18 return static_cast<i32>(mode) << BATCH_SLOT_BITS;
19}
20
21inline f32 withTextureSlot(f32 texIndex, i32 slot) {
22 return static_cast<f32>(((static_cast<i32>(texIndex) >> BATCH_SLOT_BITS) << BATCH_SLOT_BITS) | slot);
23}
24
34 glm::vec3 position;
36 glm::vec2 texCoord;
37 f32 texIndex = 0.0f;
38 // How far to push the SDF text edge outward, in the atlas's own distance units
39 // (0.5 = one spread). An outline is the glyph drawn once more with this raised,
40 // which is a real dilation of the distance field — the alternative, stamping the
41 // glyph around itself, stops looking like the glyph once the ring is wide.
42 // Per-vertex rather than per-draw so labels of different styles still batch;
43 // everything that is not SDF text leaves it at 0.
44 f32 sdfBias = 0.0f;
45};
46
47inline u32 packColor(f32 r, f32 g, f32 b, f32 a) {
48 auto clamp = [](f32 v) -> u8 {
49 return static_cast<u8>(std::min(std::max(v, 0.0f), 1.0f) * 255.0f + 0.5f);
50 };
51 return static_cast<u32>(clamp(r)) | (static_cast<u32>(clamp(g)) << 8)
52 | (static_cast<u32>(clamp(b)) << 16) | (static_cast<u32>(clamp(a)) << 24);
53}
54
55inline u32 packColor(const glm::vec4& c) {
56 return packColor(c.r, c.g, c.b, c.a);
57}
58
59} // namespace esengine
Core type definitions and utilities for ESEngine.
std::int32_t i32
Signed 32-bit integer.
Definition Types.hpp:54
f32 withTextureSlot(f32 texIndex, i32 slot)
i32 batchGlyphModeBits(TextGlyphMode mode)
constexpr i32 BATCH_DITHER_BIT
constexpr i32 BATCH_SLOT_BITS
constexpr i32 BATCH_DITHER_PHASE_BIT
u32 packColor(f32 r, f32 g, f32 b, f32 a)
std::uint32_t u32
Unsigned 32-bit integer.
Definition Types.hpp:45
std::uint8_t u8
Unsigned 8-bit integer.
Definition Types.hpp:41
float f32
32-bit floating point
Definition Types.hpp:59
One vertex of the shared batch stream.