OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
libvgcode::OptionTemplate Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libvgcode/src/OptionTemplate.hpp>

Public Member Functions

 OptionTemplate ()=default
 ~OptionTemplate ()
 OptionTemplate (const OptionTemplate &other)=delete
 OptionTemplate (OptionTemplate &&other)=delete
OptionTemplate & operator= (const OptionTemplate &other)=delete
OptionTemplate & operator= (OptionTemplate &&other)=delete
void init (uint8_t resolution)
void shutdown ()
void render (size_t count)
size_t size_in_bytes_gpu () const

Private Attributes

uint8_t m_resolution { 0 }
uint8_t m_vertices_count { 0 }
unsigned int m_top_vao_id { 0 }
unsigned int m_top_vbo_id { 0 }
unsigned int m_bottom_vao_id { 0 }
unsigned int m_bottom_vbo_id { 0 }
size_t m_size_in_bytes_gpu { 0 }

Detailed Description

Constructor & Destructor Documentation

◆ OptionTemplate() [1/3]

libvgcode::OptionTemplate::OptionTemplate ( )
default

Referenced by OptionTemplate(), OptionTemplate(), operator=(), and operator=().

Here is the caller graph for this function:

◆ ~OptionTemplate()

libvgcode::OptionTemplate::~OptionTemplate ( )
inline
17{ shutdown(); }
void shutdown()
Definition OptionTemplate.cpp:95

References shutdown().

Here is the call graph for this function:

◆ OptionTemplate() [2/3]

libvgcode::OptionTemplate::OptionTemplate ( const OptionTemplate & other)
delete

References OptionTemplate().

Here is the call graph for this function:

◆ OptionTemplate() [3/3]

libvgcode::OptionTemplate::OptionTemplate ( OptionTemplate && other)
delete

References OptionTemplate().

Here is the call graph for this function:

Member Function Documentation

◆ init()

void libvgcode::OptionTemplate::init ( uint8_t resolution)
22{
23 if (m_top_vao_id != 0)
24 return;
25
26 m_resolution = std::clamp<uint8_t>(resolution, 3, 85);
27 m_vertices_count = static_cast<uint8_t>(3 * m_resolution);
28 const float step = 2.0f * PI / float(m_resolution);
29
30 //
31 // top and bottom cones (paired wedges)
32 //
33 std::vector<float> top_vertices;
34 top_vertices.reserve(6 * m_vertices_count);
35 std::vector<float> bottom_vertices;
36 bottom_vertices.reserve(6 * m_vertices_count);
37
38 const Vec3 top_apex = { 0.0f, 0.0f, 0.5f };
39 const Vec3 top_apex_normal = { 0.0f, 0.0f, 1.0f };
40 const Vec3 bottom_apex = { 0.0f, 0.0f, -0.5f };
41 const Vec3 bottom_apex_normal = { 0.0f, 0.0f, -1.0f };
42 for (uint8_t i = 0; i < m_resolution; ++i) {
43 const float curr_angle = float(i) * step;
44 const float next_angle = float(i + 1) * step;
45 const Vec3 curr_pos = { 0.5f * std::cos(curr_angle), 0.5f * std::sin(curr_angle), 0.0f };
46 const Vec3 next_pos = { 0.5f * std::cos(next_angle), 0.5f * std::sin(next_angle), 0.0f };
47 const Vec3 curr_norm = normalize(curr_pos);
48 const Vec3 next_norm = normalize(next_pos);
49
50 add_vertex(top_apex, top_apex_normal, top_vertices);
51 add_vertex(curr_pos, curr_norm, top_vertices);
52 add_vertex(next_pos, next_norm, top_vertices);
53
54 add_vertex(bottom_apex, bottom_apex_normal, bottom_vertices);
55 add_vertex(next_pos, next_norm, bottom_vertices);
56 add_vertex(curr_pos, curr_norm, bottom_vertices);
57 }
58
59 m_size_in_bytes_gpu += top_vertices.size() * sizeof(float);
60 m_size_in_bytes_gpu += bottom_vertices.size() * sizeof(float);
61
62 const size_t vertex_stride = 6 * sizeof(float);
63 const size_t position_offset = 0;
64 const size_t normal_offset = 3 * sizeof(float);
65
66 int curr_vertex_array;
67 glsafe(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &curr_vertex_array));
68 int curr_array_buffer;
69 glsafe(glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &curr_array_buffer));
70
75 glsafe(glBufferData(GL_ARRAY_BUFFER, top_vertices.size() * sizeof(float), top_vertices.data(), GL_STATIC_DRAW));
77 glsafe(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, vertex_stride, (const void*)position_offset));
79 glsafe(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, vertex_stride, (const void*)normal_offset));
80
85 glsafe(glBufferData(GL_ARRAY_BUFFER, bottom_vertices.size() * sizeof(float), bottom_vertices.data(), GL_STATIC_DRAW));
87 glsafe(glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, vertex_stride, (const void*)position_offset));
89 glsafe(glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, vertex_stride, (const void*)normal_offset));
90
91 glsafe(glBindBuffer(GL_ARRAY_BUFFER, curr_array_buffer));
92 glsafe(glBindVertexArray(curr_vertex_array));
93}
#define glsafe(cmd)
Definition OpenGLUtils.hpp:25
unsigned int m_bottom_vbo_id
Definition OptionTemplate.hpp:47
unsigned int m_top_vbo_id
Definition OptionTemplate.hpp:45
size_t m_size_in_bytes_gpu
Definition OptionTemplate.hpp:51
unsigned int m_bottom_vao_id
Definition OptionTemplate.hpp:46
uint8_t m_resolution
Definition OptionTemplate.hpp:39
unsigned int m_top_vao_id
Definition OptionTemplate.hpp:44
uint8_t m_vertices_count
Definition OptionTemplate.hpp:40
#define glGenBuffers
Definition gl.h:3769
#define glBindBuffer
Definition gl.h:3267
#define glBindVertexArray
Definition gl.h:3307
#define GL_ARRAY_BUFFER_BINDING
Definition gl.h:239
#define GL_FLOAT
Definition gl.h:660
#define glEnableVertexAttribArray
Definition gl.h:3673
#define glGetIntegerv
Definition gl.h:3873
#define GL_ARRAY_BUFFER
Definition gl.h:238
#define glGenVertexArrays
Definition gl.h:3791
#define glVertexAttribPointer
Definition gl.h:5315
#define glBufferData
Definition gl.h:3339
#define GL_STATIC_DRAW
Definition gl.h:1633
#define GL_FALSE
Definition gl.h:648
#define GL_VERTEX_ARRAY_BINDING
Definition gl.h:1989
Vec3 normalize(const Vec3 &v)
Definition Utils.cpp:32
std::array< float, 3 > Vec3
Definition Types.hpp:40
static constexpr float PI
Definition Types.hpp:17
void add_vertex(const Vec3 &position, const Vec3 &normal, std::vector< float > &vertices)
Definition Utils.cpp:15
void step(Coord &crd, const Dir d, const long n=1)
Definition MarchingSquares.hpp:213

References libvgcode::add_vertex(), GL_ARRAY_BUFFER, GL_ARRAY_BUFFER_BINDING, GL_FALSE, GL_FLOAT, GL_STATIC_DRAW, GL_VERTEX_ARRAY_BINDING, glBindBuffer, glBindVertexArray, glBufferData, glEnableVertexAttribArray, glGenBuffers, glGenVertexArrays, glGetIntegerv, glsafe, glVertexAttribPointer, m_bottom_vao_id, m_bottom_vbo_id, m_resolution, m_size_in_bytes_gpu, m_top_vao_id, m_top_vbo_id, m_vertices_count, libvgcode::normalize(), and libvgcode::PI.

Here is the call graph for this function:

◆ operator=() [1/2]

OptionTemplate & libvgcode::OptionTemplate::operator= ( const OptionTemplate & other)
delete

References OptionTemplate().

Here is the call graph for this function:

◆ operator=() [2/2]

OptionTemplate & libvgcode::OptionTemplate::operator= ( OptionTemplate && other)
delete

References OptionTemplate(), and count.

Here is the call graph for this function:

◆ render()

void libvgcode::OptionTemplate::render ( size_t count)
118{
119 if (m_top_vao_id == 0 || m_top_vbo_id == 0 || m_bottom_vao_id == 0 || m_bottom_vbo_id == 0 || count == 0)
120 return;
121
122 int curr_vertex_array;
123 glsafe(glGetIntegerv(GL_VERTEX_ARRAY_BINDING, &curr_vertex_array));
124
129 glsafe(glBindVertexArray(curr_vertex_array));
130}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
#define glDrawArraysInstanced
Definition gl.h:3625
#define GL_TRIANGLES
Definition gl.h:1887
int GLsizei
Definition gl.h:2065

References count, GL_TRIANGLES, GL_VERTEX_ARRAY_BINDING, glBindVertexArray, glDrawArraysInstanced, glGetIntegerv, glsafe, m_bottom_vao_id, m_bottom_vbo_id, m_top_vao_id, m_top_vbo_id, and m_vertices_count.

◆ shutdown()

void libvgcode::OptionTemplate::shutdown ( )
96{
97 if (m_bottom_vbo_id != 0) {
100 }
101 if (m_bottom_vao_id != 0) {
103 m_bottom_vao_id = 0;
104 }
105 if (m_top_vbo_id != 0) {
107 m_top_vbo_id = 0;
108 }
109 if (m_top_vao_id != 0) {
111 m_top_vao_id = 0;
112 }
113
115}
#define glDeleteVertexArrays
Definition gl.h:3591
#define glDeleteBuffers
Definition gl.h:3563

References glDeleteBuffers, glDeleteVertexArrays, glsafe, m_bottom_vao_id, m_bottom_vbo_id, m_size_in_bytes_gpu, m_top_vao_id, and m_top_vbo_id.

Referenced by ~OptionTemplate().

Here is the caller graph for this function:

◆ size_in_bytes_gpu()

size_t libvgcode::OptionTemplate::size_in_bytes_gpu ( ) const
inline
36{ return m_size_in_bytes_gpu; }

References m_size_in_bytes_gpu.

Member Data Documentation

◆ m_bottom_vao_id

unsigned int libvgcode::OptionTemplate::m_bottom_vao_id { 0 }
private
46{ 0 };

Referenced by init(), render(), and shutdown().

◆ m_bottom_vbo_id

unsigned int libvgcode::OptionTemplate::m_bottom_vbo_id { 0 }
private
47{ 0 };

Referenced by init(), render(), and shutdown().

◆ m_resolution

uint8_t libvgcode::OptionTemplate::m_resolution { 0 }
private
39{ 0 };

Referenced by init().

◆ m_size_in_bytes_gpu

size_t libvgcode::OptionTemplate::m_size_in_bytes_gpu { 0 }
private
51{ 0 };

Referenced by init(), shutdown(), and size_in_bytes_gpu().

◆ m_top_vao_id

unsigned int libvgcode::OptionTemplate::m_top_vao_id { 0 }
private
44{ 0 };

Referenced by init(), render(), and shutdown().

◆ m_top_vbo_id

unsigned int libvgcode::OptionTemplate::m_top_vbo_id { 0 }
private
45{ 0 };

Referenced by init(), render(), and shutdown().

◆ m_vertices_count

uint8_t libvgcode::OptionTemplate::m_vertices_count { 0 }
private
40{ 0 };

Referenced by init(), and render().


The documentation for this class was generated from the following files: