21 #include "hx3d/graphics/ordered_batch.hpp" 23 #include "hx3d/graphics/cameras/camera.hpp" 25 #include "hx3d/core/core.hpp" 27 #include "hx3d/graphics/shader.hpp" 28 #include "hx3d/graphics/texture.hpp" 29 #include "hx3d/graphics/font.hpp" 31 #include "hx3d/utils/log.hpp" 32 #include "hx3d/utils/assets.hpp" 37 OrderedBatch::OrderedBatch(): BaseBatch() {}
40 if (_shader ==
nullptr) {
41 Log.
Error(
"Attempt to draw without shader.");
46 _shader->setUniformMatrix4f(
"u_projection", _camera->projection);
47 _shader->setUniformMatrix4f(
"u_view", _camera->view);
55 for (
auto& pair: _meshes) {
56 auto& model = pair.first;
57 Mesh* mesh = pair.second;
59 _shader->setUniformMatrix4f(
"u_model", model);
66 for (
auto& pair: _funcTexts) {
68 auto& func = pair.second;
79 auto& shader = text.
getFont()->getShader();
81 shader->setUniformMatrix4f(
"u_model", model);
82 shader->setUniformMatrix4f(
"u_view", _camera->view);
83 shader->setUniformMatrix4f(
"u_projection", _camera->projection);
87 _shader->setUniformMatrix4f(
"u_view", _camera->view);
88 _shader->setUniformMatrix4f(
"u_projection", _camera->projection);
99 float oldX = text.transform.position.x;
100 if (text.isCenterAligned())
101 text.transform.position.x -= text.getLength() / 2;
103 glm::mat4 model = text.transform.compute();
104 text.transform.position.x = oldX;
106 auto& shader = text.getFont()->getShader();
108 shader->setUniformMatrix4f(
"u_model", model);
109 shader->setUniformMatrix4f(
"u_view", _camera->view);
110 shader->setUniformMatrix4f(
"u_projection", _camera->projection);
114 _shader->setUniformMatrix4f(
"u_view", _camera->view);
115 _shader->setUniformMatrix4f(
"u_projection", _camera->projection);
128 unsigned int pos = 0;
129 for (pos = 0; pos < _meshes.size(); ++pos) {
130 auto& pair = _meshes[pos];
131 Mesh* m = pair.second;
138 _meshes.insert(_meshes.begin() + pos, std::make_pair(mesh.
transform.
compute(), &mesh));
142 _texts.push_back(text);
146 _funcTexts.push_back(std::make_pair(text,
function));
bool isCenterAligned()
Is the text center aligned ?
static void use(Ptr< Shader > shader)
Use the shader as the current shader.
virtual void end() override
End the batching.
void Error(const std::string fmt,...)
Write an error message.
virtual void draw(Mesh &mesh) override
Draw the mesh.
static hx3d::LogImpl Log
Current log implementation.
virtual void begin() override
Begin the batching.
int getCharacterSize()
Get the character size.
static void disable()
Clear the current shader.
Transform transform
Mesh transformation.
Displayable 2D/3D element.
Math function definition.
float getLength()
Get the text length.
virtual void draw(Ptr< Shader > shader)
Draw the mesh using a shader.
static void disable()
Clear the current texture for drawing.
static void use(Ptr< Texture > texture)
Use the current texture for drawing.
Ptr< Font > getFont()
Get the text font.
void functionDraw(Ptr< Shader > shader, math::Function function)
Draw the text following a function.