xcal
基于 C++23 的现代图形渲染引擎
载入中...
搜索中...
未找到
circle.cc
浏览该文件的文档.
2//
3#include <xcal/public.h>
4
9#include <xcmath/xcmath.hpp>
10
11#define ROLE OpenGLObject
12#define LABEL Circle
15#include <xcmath/utils/show.hpp>
16#define SHADER_ID 0
18 return GL::ShaderProgram::from_file(SHADER_FILE("line.vs"),
19 SHADER_FILE("line.fs"));
20}
21
23 vao().bind();
24 vbo_ = GL::Buffer(_gl GL_ARRAY_BUFFER);
25 vbo_.bind();
26 const float_t radius = mobject_->radius();
27 _D("Create Circle: " << mobject_.mobject() << " with radius: " << radius
28 << " and depth: " << mobject_->pos().value().z());
29
30 // Generate vertices for circle using triangle fan
31 // Center vertex first, then circumference points
32 std::vector<_gl GLfloat> vertices;
33 vertices.reserve((segments_ + 2) *
34 6); // (center + segments + duplicate first
35 // point) * 6 floats per vertex
36
37 // Center vertex
38 vertices.insert(vertices.end(), {0.0f, 0.0f, mobject_->pos().value().z()});
39 vertices.insert(vertices.end(),
40 {mobject_->stroke_color().r(), mobject_->stroke_color().g(),
41 mobject_->stroke_color().b()});
42
43 // Circumference vertices
44 for (int i = 0; i <= segments_; ++i) {
45 float_t angle = 2.0f * xcmath::PI * i / segments_;
46 float_t x = radius * cos(angle);
47 float_t y = radius * sin(angle);
48 vertices.insert(vertices.end(), {x, y, mobject_->pos().value().z()});
49 vertices.insert(vertices.end(), {mobject_->stroke_color().r(),
50 mobject_->stroke_color().g(),
51 mobject_->stroke_color().b()});
52 }
53
54 vbo_.buffer_data(vertices.data(), vertices.size() * sizeof(float),
55 _gl GL_STATIC_DRAW);
56
57 _gl glEnableVertexAttribArray(0);
58 _gl glVertexAttribPointer(0, 3, _gl GL_FLOAT, _gl GL_FALSE,
59 6 * sizeof(float), // stride
60 (void*)(0 * sizeof(float))); // offset
61
62 // Color attribute: location 1, each vertex 3 floats, offset 3*float
63 _gl glEnableVertexAttribArray(1);
64 _gl glVertexAttribPointer(1, 3, _gl GL_FLOAT, _gl GL_FALSE,
65 6 * sizeof(float), // stride
66 (void*)(3 * sizeof(float))); // offset
67
69 vao().unbind();
70};
71
73 _I("Destroy Circle: " << this);
74 shader_program_.reset();
75 vbo_.destroy();
76};
77
79 vao().bind();
80 shader_program_->use();
81 shader_program_->uniform("model", mobject_.model_matrix());
82 _gl glDrawArrays(_gl GL_TRIANGLE_FAN, 0,
83 segments_ + 2); // +2 for center and duplicate first point
84 vao().unbind();
85};
86
88 : mobject_(mobject), vbo_(_gl GL_ARRAY_BUFFER) {
89 _I("Create Circle: " << this << " from mobject: " << mobject_.mobject());
90};
91
93void xcal::render::opengl::object::Circle::update_projection_view(
94 const xcmath::mat4<float_t>& projection_view) {
95 _D("Update view projection for Circle: "
96 << this << " with view_projection: " << projection_view);
97 shader_program_->uniform("projection_view", projection_view);
98}
圆形图形对象类
Definition circle.hpp:18
void buffer_data(const void *data, gl::GLuint size, gl::GLenum usage)
void render() const override
Definition circle.cc:78
Circle(mobject::Circle *mobject)
Definition circle.cc:87
GL::VertexArrayObject & vao()
Definition object.hpp:28
float float_t
Definition public.h:27
Compiler-specific type information handling for MSVC
Definition complex.hpp:12
constexpr long double PI
Pi constant
#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 circle.cc:16