NDEVR
API Documentation
ColorPositionShaderLogic.h
1#pragma once
2#include <NDEVR/GLComputeShader.h>
3#include <NDEVR/Matrix.h>
4#include <NDEVR/PointContainer.h>
5#include <NDEVR/Buffer.h>
6#include <NDEVR/RGBColor.h>
7namespace NDEVR
8{
16 class ColorPositionShaderLogic : public GLComputeShader
17 {
18 public:
19 ColorPositionShaderLogic();
44 static_assert(sizeof(UBO) == 176, "UBO size mismatch");
45
48 void runAll(Buffer<RGBColor>& last_colors);
55 void createImage(const Vector<2, uint04>& size);
59 void updateImage(const uint01* data, const Vector<2, uint04>& size);
62 template<class t_point_type>
64 {
65 if (m_size_i == 0)
66 {
67 active.clear();
68 return;
69 }
70 active.setSize(m_size_i);
71 //wait for previous calc to finish
72 m_gl->glMemoryBarrier(GL_SHADER_STORAGE_BARRIER_BIT | GL_BUFFER_UPDATE_BARRIER_BIT);
73 readBytes(m_ssboPos, active.locations.begin(), GLsizeiptr(sizeof(Vector<3, fltp04>) * m_size_i));
74 readBytes(m_ssboW, active.weights.begin(), GLsizeiptr(sizeof(uint04) * m_size_i));
75
76 }
77
80 void uploadInputs(const uint01* depth, Vector<2, uint04> size)
81 {
82 if (m_depth_image == 0)
83 createImage(size);
84 m_size_i = size[X] * size[Y];
85 ensureSSBO(m_ssboPos, GLsizeiptr(sizeof(Vector<3, fltp04>)) * m_size_i, GL_DYNAMIC_DRAW);
86 ensureSSBO(m_ssboW, GLsizeiptr(sizeof(uint04) * m_size_i), GL_DYNAMIC_DRAW);
87 updateImage(depth, size);
88
89 }
90
92 void setUBO(const UBO& u);
95 void setQtGL(QOpenGLFunctions_4_3_Core* gl);
96 protected:
98 QOpenGLShaderProgram* m_shader = nullptr;
99 bool has_normal = false;
100 GLuint m_depth_image = 0;
101 GLuint m_csA = 0;
102 GLuint m_uboU = 0;
103 GLuint m_ssboPos = 0;
104 GLuint m_tex = 0;
105 GLuint m_ssboW = 0;
107 };
108}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
void getInput(PointContainer< t_point_type > &active)
Read back computed 3D positions and weights from the GPU.
GLuint m_csA
Compute shader handle.
GLuint m_ssboPos
Shader storage buffer for output positions.
void updateImage(const uint01 *data, const Vector< 2, uint04 > &size)
Upload new depth data to the GPU texture.
Buffer< RGBColor > m_last_colors
Previously computed color buffer.
GLuint m_uboU
Uniform buffer object handle.
void uploadInputs(const uint01 *depth, Vector< 2, uint04 > size)
Upload depth data and ensure GPU storage buffers are large enough.
QOpenGLShaderProgram * m_shader
Compiled compute shader program.
void createUBOBuffer()
Create the GPU uniform buffer object for shader parameters.
void buildShader()
Compile and link the compute shader program.
void setQtGL(QOpenGLFunctions_4_3_Core *gl)
Set the OpenGL function pointer table used by this shader.
void runAll(Buffer< RGBColor > &last_colors)
Dispatch the compute shader and read back colors.
bool has_normal
Whether the shader outputs normals.
GLuint m_depth_image
GPU texture handle for the depth image.
GLuint m_ssboW
Shader storage buffer for output weights.
uint04 m_size_i
Total number of pixels being processed.
void createImage(const Vector< 2, uint04 > &size)
Create the GPU depth image texture.
void setUBO(const UBO &u)
Upload uniform buffer data to the GPU.
GLuint m_tex
Color texture handle.
Templated logic for doing matrix multiplication.
Definition Matrix.hpp:182
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 clear()
Clear all buffers, removing all points.
void setSize(uint04 size)
Resize all internal buffers to hold the given number of points.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
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...
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
Uniform buffer object layout for the color-position compute shader.
Vector< 4, fltp04 > cam_pos4
Camera position in world space (bytes 128..143).
Matrix< fltp04 > view_matrix
Camera view matrix (bytes 0..63).
float max_dist2
Maximum squared distance threshold.
Vector< 2, fltp04 > inv_f
Inverse focal length (bytes 80..87).
Vector< 2, fltp04 > f
Focal length in pixels (bytes 72..79).
Vector< 2, fltp04 > size_f
Frame size as float (bytes 88..95).
Vector< 2, uint04 > center_i
Frame center as integer pixels (bytes 96..103).
float k3
Radial distortion coefficient k3.
Vector< 2, fltp04 > pp
Principal point in pixels (bytes 64..71).
Vector< 2, uint04 > size_i
Frame size as integer pixels (bytes 104..111).
Vector< 4, uint04 > weight_info
Weight parameters: mode, bytes/pixel, max, reduce (bytes 160..175).
Vector< 4, fltp04 > k12p1p2
Distortion coefficients k1, k2, p1, p2 (bytes 112..127).
float max_error_percent_sqrd
Maximum error percentage squared for filtering.
float depth_scale
Scale factor converting raw depth to metres.