Skip to content

Commit 23a9d71

Browse files
committed
changed global OpenGLBindings object to per instance of OpenGLDepthPacketProcessor
1 parent a8f882f commit 23a9d71

File tree

1 file changed

+72
-9
lines changed

1 file changed

+72
-9
lines changed

examples/protonect/src/opengl_depth_packet_processor.cpp

Lines changed: 72 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,27 @@ ChangeCurrentOpenGLContext::~ChangeCurrentOpenGLContext()
6666
}
6767
}
6868

69-
static OpenGLBindings *gl()
69+
class WithOpenGLBindings
7070
{
71-
static OpenGLBindings bindings;
71+
private:
72+
OpenGLBindings *bindings;
73+
protected:
74+
WithOpenGLBindings() : bindings(0) {}
75+
virtual ~WithOpenGLBindings() {}
7276

73-
return &bindings;
74-
}
77+
virtual void onOpenGLBindingsChanged(OpenGLBindings *b) { }
78+
public:
79+
void gl(OpenGLBindings *bindings)
80+
{
81+
this->bindings = bindings;
82+
onOpenGLBindingsChanged(this->bindings);
83+
}
84+
85+
OpenGLBindings *gl()
86+
{
87+
return bindings;
88+
}
89+
};
7590

7691
std::string loadShaderSource(const std::string& filename)
7792
{
@@ -100,7 +115,7 @@ bool loadBufferFromFile(const std::string& filename, unsigned char *buffer, size
100115
return success;
101116
}
102117

103-
struct ShaderProgram
118+
struct ShaderProgram : public WithOpenGLBindings
104119
{
105120
GLuint program, vertex_shader, fragment_shader;
106121

@@ -232,7 +247,7 @@ typedef ImageFormat<12, GL_RGB32F, GL_RGB, GL_FLOAT> F32C3;
232247
typedef ImageFormat<16, GL_RGBA32F, GL_RGBA, GL_FLOAT> F32C4;
233248

234249
template<typename FormatT>
235-
struct Texture
250+
struct Texture : public WithOpenGLBindings
236251
{
237252
protected:
238253
size_t bytes_per_pixel, height, width;
@@ -315,7 +330,7 @@ struct Texture
315330
}
316331
};
317332

318-
struct OpenGLDepthPacketProcessorImpl
333+
struct OpenGLDepthPacketProcessorImpl : public WithOpenGLBindings
319334
{
320335
GLFWwindow *opengl_context_ptr;
321336
std::string shader_folder;
@@ -379,11 +394,53 @@ struct OpenGLDepthPacketProcessorImpl
379394
{
380395
}
381396

382-
~OpenGLDepthPacketProcessorImpl()
397+
virtual ~OpenGLDepthPacketProcessorImpl()
383398
{
399+
if(gl() != 0)
400+
{
401+
delete gl();
402+
gl(0);
403+
}
384404
glfwDestroyWindow(opengl_context_ptr);
385405
opengl_context_ptr = 0;
386406
}
407+
408+
virtual void onOpenGLBindingsChanged(OpenGLBindings *b)
409+
{
410+
lut11to16.gl(b);
411+
p0table[0].gl(b);
412+
p0table[1].gl(b);
413+
p0table[2].gl(b);
414+
x_table.gl(b);
415+
z_table.gl(b);
416+
417+
input_data.gl(b);
418+
419+
stage1_debug.gl(b);
420+
stage1_data[0].gl(b);
421+
stage1_data[1].gl(b);
422+
stage1_data[2].gl(b);
423+
stage1_infrared.gl(b);
424+
425+
filter1_data[0].gl(b);
426+
filter1_data[1].gl(b);
427+
filter1_max_edge_test.gl(b);
428+
filter1_debug.gl(b);
429+
430+
stage2_debug.gl(b);
431+
432+
stage2_depth.gl(b);
433+
stage2_depth_and_ir_sum.gl(b);
434+
435+
filter2_debug.gl(b);
436+
filter2_depth.gl(b);
437+
438+
stage1.gl(b);
439+
filter1.gl(b);
440+
stage2.gl(b);
441+
filter2.gl(b);
442+
debug.gl(b);
443+
}
387444

388445
void startTiming()
389446
{
@@ -408,7 +465,9 @@ struct OpenGLDepthPacketProcessorImpl
408465
{
409466
ChangeCurrentOpenGLContext ctx(opengl_context_ptr);
410467

411-
flextInit(opengl_context_ptr, gl());
468+
OpenGLBindings *b = new OpenGLBindings();
469+
flextInit(opengl_context_ptr, b);
470+
gl(b);
412471

413472
input_data.allocate(352, 424 * 10);
414473

@@ -705,6 +764,10 @@ OpenGLDepthPacketProcessor::OpenGLDepthPacketProcessor(void *parent_opengl_conte
705764
{
706765
GLFWwindow* parent_window = (GLFWwindow *)parent_opengl_context_ptr;
707766

767+
// init glfw - if already initialized nothing happens
768+
glfwInit();
769+
770+
// setup context
708771
glfwDefaultWindowHints();
709772
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
710773
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

0 commit comments

Comments
 (0)