xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
line.cc
浏览该文件的文档.
2
3//
4#include <xcal/public.h>
5
10#include <xcmath/xcmath.hpp>
11
12#define ROLE OpenGLObject
13#define LABEL Line
16#include <xcmath/utils/show.hpp>
17static constexpr auto SHADER_ID = 0;
18static constexpr auto BUFFER_ID = 0;
19
21 return GL::ShaderProgram::from_file(SHADER_FILE("line1.vs"),
22 SHADER_FILE("line1.fs"));
23}
25 auto buffer =
26 std::make_shared<xcal::render::opengl::GL::Buffer>(_gl GL_ARRAY_BUFFER);
27 buffer->bind();
28 buffer->buffer_data(
29 std::array<_gl GLfloat, 6>{
30 -0.5f, -0.5f,
31 -0.5f, //
32 0.5f, 0.5f,
33 0.5f, //
34 },
35 _gl GL_STATIC_DRAW);
36 buffer->unbind();
37 return buffer;
38}
39using vao_sp = std::shared_ptr<xcal::render::opengl::GL::VertexArrayObject>;
40using vbo_sp = std::shared_ptr<xcal::render::opengl::GL::Buffer>;
41using shader_sp = std::shared_ptr<xcal::render::opengl::GL::ShaderProgram>;
42struct StaticLine {
47 using namespace xcal::render::opengl;
49 vao->bind();
51 vbo->bind();
52 _gl glEnableVertexAttribArray(0);
53 _gl glVertexAttribPointer(0, 3, _gl GL_FLOAT, _gl GL_FALSE,
54 3 * sizeof(float), // stride
55 (void*)nullptr); // offset
58 }
59};
60
62 return std::make_shared<StaticLine>();
63}
64
66 static_line_ = XCAL_STATIC_GLOBJECT(StaticLine, Line, 0);
67 _I("Create Line: " << this << " with mobject: " << mobject_.mobject());
68};
70 _I("Destroy Line: " << this);
71 static_line_ = nullptr;
72};
74 static_line_->vao->bind();
75 static_line_->shader_program->use();
76 update_ubo_data();
77 _gl glBindBufferBase(_gl GL_UNIFORM_BUFFER, 0, ubo_.id());
78 _gl glDrawArrays(_gl GL_LINES, 0, 2);
79 static_line_->vao->unbind();
80};
82 : mobject_(mobject), ubo_(_gl GL_UNIFORM_BUFFER) {
83 _I("Create Line: " << this << " from mobject: " << mobject_.mobject());
84};
85
87 const xcmath::mat4<float_t>& projection_view) {
88 _D("Update view projection for Line: " << this << " with view_projection: "
89 << projection_view);
90 static_line_->shader_program->uniform("projection_view", projection_view);
91};
93
94void xcal::render::opengl::object::Line::update_ubo_data() const {
95 if (mobject_->stroke_color().is_changed() ||
96 mobject_->direct().is_changed() ||
97 mobject_.model_matrix_should_update()) {
98 ubo_.bind();
99 ubo_data_.direction =
100 xcmath::vec4<float_t>{mobject_->direct().value(), 0.f};
101 ubo_data_.color = mobject_->stroke_color();
102 ubo_data_.model = mobject_.model_matrix().T();
103 ubo_.buffer_data(&ubo_data_, sizeof(ubo_data_), _gl GL_DYNAMIC_DRAW);
104 ubo_.unbind();
105 mobject_->stroke_color().reset_changed();
106 mobject_->direct().reset_changed();
107 }
108};
void update_projection_view(const xcmath::mat4< float_t > &view_projection) override
Definition line.cc:86
void render() const override
Definition line.cc:73
Line(mobject::Line *mobject)
Definition line.cc:81
xcmath::vec4< float_t > direction
Definition line.hpp:18
Matrix class template
Definition mat.hpp:27
Vector class template
Definition vec.hpp:206
#define XCAL_OPENGL_REGIST_OBJECT_IMPL(class_, type)
Definition object.hpp:50
#define XCAL_SHADER_INSTANCE(T, _id)
#define SHADER_FILE(name)
#define XCAL_DEFINE_STATIC_GLOBJECT(T, Catgory, Id)
#define XCAL_STATIC_GLOBJECT(T, Catgory, Id)
#define XCAL_BUFFER_INSTANCE(T, _id)
shader_sp shader_program
Definition line.cc:45
vbo_sp vbo
Definition line.cc:44
vao_sp vao
Definition line.cc:43
StaticLine()
Definition line.cc:46
#define SHADER_ID
Definition axis.cc:20
std::shared_ptr< xcal::render::opengl::GL::Buffer > vbo_sp
Definition line.cc:40
std::shared_ptr< xcal::render::opengl::GL::VertexArrayObject > vao_sp
Definition line.cc:39
std::shared_ptr< xcal::render::opengl::GL::ShaderProgram > shader_sp
Definition line.cc:41