xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
axis.cc
浏览该文件的文档.
1#include <array>
4
5//
6#include <xcal/public.h>
7
13#include <xcmath/xcmath.hpp>
14
15#define ROLE OpenGLObject
16#define LABEL Axis
19#include <xcmath/utils/show.hpp>
20#define SHADER_ID 0
22 return GL::ShaderProgram::from_file(SHADER_FILE("line.vs"),
23 SHADER_FILE("line.fs"));
24}
25
27 vao().bind();
28 vbo_ = GL::Buffer(_gl GL_ARRAY_BUFFER);
29 auto vertices = std::array<_gl GLfloat, 6 * 7>{0};
30 // {-1.0f,
31 // 0.0f,
32 // 0.0f,
33 // mobject_->stroke_color().r(),
34 // mobject_->stroke_color().g(),
35 // mobject_->stroke_color().b(),
36 // mobject_->stroke_color().a(),
37 // 1.0f,
38 // 0.0f,
39 // 0.0f,
40 // mobject_->stroke_color().r(),
41 // mobject_->stroke_color().g(),
42 // mobject_->stroke_color().b(),
43 // mobject_->stroke_color().a(),
44 // 0.0f,
45 // -1.0f,
46 // 0.0f,
47 // mobject_->stroke_color().r(),
48 // mobject_->stroke_color().g(),
49 // mobject_->stroke_color().b(),
50 // mobject_->stroke_color().a(),
51 // 0.0f,
52 // 1.0f,
53 // 0.0f,
54 // mobject_->stroke_color().r(),
55 // mobject_->stroke_color().g(),
56 // mobject_->stroke_color().b(),
57 // mobject_->stroke_color().a(),
58 // 0.0f,
59 // 0.0f,
60 // -1.0f,
61 // mobject_->stroke_color().r(),
62 // mobject_->stroke_color().g(),
63 // mobject_->stroke_color().b(),
64 // mobject_->stroke_color().a(),
65 // 0.0f,
66 // 0.0f,
67 // 1.0f,
68 // mobject_->stroke_color().r(),
69 // mobject_->stroke_color().g(),
70 // mobject_->stroke_color().b(),
71 // mobject_->stroke_color().a()};
72 vbo_.bind();
73 vbo_.buffer_data(vertices, _gl GL_STATIC_DRAW);
74
75 _gl glVertexAttribFormat(0, 3, _gl GL_FLOAT, _gl GL_FALSE, 0);
76 _gl glVertexAttribFormat(1, 4, _gl GL_FLOAT, _gl GL_FALSE,
77 3 * sizeof(_gl GLfloat));
78 _gl glVertexAttribBinding(0, 0);
79 _gl glVertexAttribBinding(1, 0);
80
81 _gl glBindVertexBuffer(0, vbo_.id(), 0, 7 * sizeof(_gl GLfloat));
82
83 _gl glEnableVertexAttribArray(0);
84 _gl glEnableVertexAttribArray(1);
85 vao().unbind();
86
87 shader_program_ =
89 SHADER_ID>::instance();
90 vao().unbind();
91}
92
94 _I("Destroy Axis: " << this);
95 shader_program_.reset();
96 vbo_.destroy();
97};
98
100 vao().bind();
101 shader_program_->use();
102 shader_program_->uniform("model", mobject_.model_matrix());
103 _gl glDrawArrays(_gl GL_LINES, 0, 6);
104 vao().unbind();
105};
106
108 : mobject_(mobject), vbo_(_gl GL_ARRAY_BUFFER) {
109 _I("Create Axis: " << this << " from mobject: " << mobject_.mobject());
110};
111
113 const xcmath::mat4<float_t>& projection_view) {
114 _D("Update view projection for Axis: " << this << " with view_projection: "
115 << projection_view);
116 shader_program_->uniform("projection_view", projection_view);
117}
118
void buffer_data(const void *data, gl::GLuint size, gl::GLenum usage)
void update_projection_view(const xcmath::mat4< float_t > &projection_view) override
Definition axis.cc:112
Axis3D(mobject::Axis3D *mobject)
Definition axis.cc:107
void render() const override
Definition axis.cc:99
GL::VertexArrayObject & vao()
Definition object.hpp:28
Matrix class template
Definition mat.hpp:27
#define XCAL_OPENGL_REGIST_OBJECT_IMPL(class_, type)
Definition object.hpp:50
#define XCAL_SHADER_INSTANCE(T, _id)
#define SHADER_FILE(name)
#define SHADER_ID
Definition axis.cc:20