2#include <NDEVR/GLComputeShader.h>
3#include <NDEVR/Matrix.h>
4#include <NDEVR/PointContainer.h>
5#include <NDEVR/RGBColor.h>
15 class ViewPortSmoothShaderLogic :
public GLComputeShader
18 ViewPortSmoothShaderLogic();
22 struct alignas(16)
UBO {
41 float k3, max_dist2, max_dist2_relax, max_error_percent_sqrd;
49 static_assert(
sizeof(
UBO) == 192,
"UBO size mismatch");
50 static_assert(
alignof(
UBO) == 16,
"bad alignment");
51 static_assert(offsetof(
UBO, pp) == 64,
"bad offset pp");
52 static_assert(offsetof(
UBO, size_i) == 104,
"bad offset size_i");
53 static_assert(offsetof(
UBO, k12p1p2) == 112,
"bad offset k12p1p2");
54 static_assert(offsetof(
UBO, cam_pos4) == 128,
"bad offset cam_pos4");
55 static_assert(offsetof(
UBO, k3) == 144,
"bad offset k3");
56 static_assert(offsetof(
UBO, weightsA) == 160,
"bad offset weightsA");
57 static_assert(offsetof(
UBO, counts) == 176,
"bad offset counts");
70 template<
class t_po
int_type>
74 m_gl->glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT);
84 for (
uint04 i = 0; i < count; i++)
89 if (active.
weights[i] >= record_weight)
99 active.
data[offset] = active.
data[i];
109 template<
class t_po
int_type>
117 m_gl->glBindBuffer(GL_SHADER_STORAGE_BUFFER,
m_ssboPxKey);
121 m_gl->glBufferData(GL_SHADER_STORAGE_BUFFER
122 , GLsizeiptr(
sizeof(
uint04) * pix_count)
123 ,
nullptr, GL_DYNAMIC_DRAW);
125 const GLuint fill = 0xFFFFFFFFu;
126 m_gl->glClearBufferData(GL_SHADER_STORAGE_BUFFER, GL_R32UI,
127 GL_RED_INTEGER, GL_UNSIGNED_INT, &fill);
134 m_gl->glBindBuffer(GL_SHADER_STORAGE_BUFFER,
m_ssboOutIdx);
135 m_gl->glBufferData(GL_SHADER_STORAGE_BUFFER
137 ,
nullptr, GL_DYNAMIC_DRAW);
141 m_gl->glBindBuffer(GL_SHADER_STORAGE_BUFFER,
m_ssboInPos);
142 m_gl->glBufferData(GL_SHADER_STORAGE_BUFFER
144 ,
nullptr, GL_DYNAMIC_DRAW);
149 m_gl->glBufferData(GL_SHADER_STORAGE_BUFFER
151 ,
nullptr, GL_DYNAMIC_DRAW);
155 m_gl->glBindBuffer(GL_SHADER_STORAGE_BUFFER,
m_ssboInW);
156 m_gl->glBufferData(GL_SHADER_STORAGE_BUFFER
158 ,
nullptr, GL_DYNAMIC_DRAW);
160 m_gl->glBindBuffer(GL_SHADER_STORAGE_BUFFER,
m_ssboInPos);
161 m_gl->glBufferSubData(GL_SHADER_STORAGE_BUFFER
166 m_gl->glBufferSubData(GL_SHADER_STORAGE_BUFFER
167 , 0, GLsizeiptr(
sizeof(
uint04)) * active.
size()
170 m_gl->glBindBuffer(GL_SHADER_STORAGE_BUFFER,
m_ssboInW);
171 m_gl->glBufferSubData(GL_SHADER_STORAGE_BUFFER
172 , 0, GLsizeiptr(
sizeof(
uint04)) * active.
size()
189 static void ReadBytes(QOpenGLFunctions_4_3_Core* gl, GLenum target, GLuint buf,
void* dst, GLsizeiptr bytes);
The equivelent of std::vector but with a bit more control.
void add(t_type &&object)
Adds object to the end of the buffer.
Templated logic for doing matrix multiplication.
A templated container for 3D point cloud data with per-point positions, typed attributes,...
Buffer< Vertex< 3, fltp04 > > locations
3D positions of each point
Buffer< uint04 > weights
Per-point confidence weights.
void setSize(uint04 size)
Resize all internal buffers to hold the given number of points.
Buffer< t_point_type > data
Per-point attribute data.
uint04 size() const
Get the number of points in the container.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
A point in N-dimensional space, used primarily for spatial location information.
GLuint m_uboU
Uniform buffer object handle.
uint04 m_last_size
Number of points in the last upload.
void buildShader()
Compile and link the compute shader program.
uint04 m_px_key_size
Allocated size of the per-pixel key buffer.
GLuint m_ssboInW
Input weight storage buffer.
Buffer< uint04 > m_temp_idx
CPU-side copy of the output index buffer.
Buffer< RGBColor > m_colors
CPU-side color buffer for GPU upload/download.
GLuint m_ssboOutIdx
Output index buffer indicating kept points.
uint04 m_out_size
Allocated size of the output index buffer.
GLuint m_ssboInPos
Input position storage buffer.
void runAll(uint04 count)
Dispatch the compute shader over the given number of points.
QOpenGLShaderProgram * m_shader
Compiled compute shader program.
void uploadInputs(const PointContainer< t_point_type > &active, uint04 pix_count)
Upload point cloud data to GPU storage buffers for the smooth pass.
void setUBO(const UBO &u)
Upload uniform buffer data to the GPU.
static void ReadBytes(QOpenGLFunctions_4_3_Core *gl, GLenum target, GLuint buf, void *dst, GLsizeiptr bytes)
Read bytes from a GPU buffer into CPU memory.
GLuint m_ssboInColor
Input color storage buffer.
GLuint m_ssboPxKey
Per-pixel key buffer for duplicate detection.
void createUBOBuffer()
Create the GPU uniform buffer object for shader parameters.
void setQtGL(QOpenGLFunctions_4_3_Core *gl)
Set the OpenGL function pointer table used by this shader.
void getInput(PointContainer< t_point_type > &active, PointContainer< t_point_type > &inactive, uint04 record_weight)
Read back smoothed points from the GPU, partitioning into active and inactive sets.
GLuint m_csA
Compute shader handle.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Uniform buffer object layout for the viewport smooth compute shader.