|
32 | 32 | #include <GLFW/glfw3.h> |
33 | 33 |
|
34 | 34 | #include <fstream> |
35 | | - |
| 35 | +#include <string> |
| 36 | +#include <map> |
36 | 37 |
|
37 | 38 | #include <stdint.h> |
38 | 39 |
|
@@ -117,6 +118,8 @@ bool loadBufferFromFile(const std::string& filename, unsigned char *buffer, size |
117 | 118 |
|
118 | 119 | struct ShaderProgram : public WithOpenGLBindings |
119 | 120 | { |
| 121 | + typedef std::map<std::string, int> FragDataMap; |
| 122 | + FragDataMap frag_data_map_; |
120 | 123 | GLuint program, vertex_shader, fragment_shader; |
121 | 124 |
|
122 | 125 | char error_buffer[2048]; |
@@ -144,6 +147,11 @@ struct ShaderProgram : public WithOpenGLBindings |
144 | 147 | gl()->glShaderSource(fragment_shader, 1, &src_, &length_); |
145 | 148 | } |
146 | 149 |
|
| 150 | + void bindFragDataLocation(const std::string &name, int output) |
| 151 | + { |
| 152 | + frag_data_map_[name] = output; |
| 153 | + } |
| 154 | + |
147 | 155 | void build() |
148 | 156 | { |
149 | 157 | GLint status; |
@@ -172,6 +180,11 @@ struct ShaderProgram : public WithOpenGLBindings |
172 | 180 | gl()->glAttachShader(program, vertex_shader); |
173 | 181 | gl()->glAttachShader(program, fragment_shader); |
174 | 182 |
|
| 183 | + for(FragDataMap::iterator it = frag_data_map_.begin(); it != frag_data_map_.end(); ++it) |
| 184 | + { |
| 185 | + gl()->glBindFragDataLocation(program, it->second, it->first.c_str()); |
| 186 | + } |
| 187 | + |
175 | 188 | gl()->glLinkProgram(program); |
176 | 189 |
|
177 | 190 | gl()->glGetProgramiv(program, GL_LINK_STATUS, &status); |
@@ -469,24 +482,39 @@ struct OpenGLDepthPacketProcessorImpl : public WithOpenGLBindings, public WithPe |
469 | 482 |
|
470 | 483 | stage1.setVertexShader(loadShaderSource(shader_folder + "default.vs")); |
471 | 484 | stage1.setFragmentShader(loadShaderSource(shader_folder + "stage1.fs")); |
| 485 | + stage1.bindFragDataLocation("Debug", 0); |
| 486 | + stage1.bindFragDataLocation("A", 1); |
| 487 | + stage1.bindFragDataLocation("B", 2); |
| 488 | + stage1.bindFragDataLocation("Norm", 3); |
| 489 | + stage1.bindFragDataLocation("Infrared", 4); |
472 | 490 | stage1.build(); |
473 | 491 |
|
474 | 492 | filter1.setVertexShader(loadShaderSource(shader_folder + "default.vs")); |
475 | 493 | filter1.setFragmentShader(loadShaderSource(shader_folder + "filter1.fs")); |
| 494 | + filter1.bindFragDataLocation("Debug", 0); |
| 495 | + filter1.bindFragDataLocation("FilterA", 1); |
| 496 | + filter1.bindFragDataLocation("FilterB", 2); |
| 497 | + filter1.bindFragDataLocation("MaxEdgeTest", 3); |
476 | 498 | filter1.build(); |
477 | 499 |
|
478 | 500 | stage2.setVertexShader(loadShaderSource(shader_folder + "default.vs")); |
479 | 501 | stage2.setFragmentShader(loadShaderSource(shader_folder + "stage2.fs")); |
| 502 | + stage2.bindFragDataLocation("Debug", 0); |
| 503 | + stage2.bindFragDataLocation("Depth", 1); |
| 504 | + stage2.bindFragDataLocation("DepthAndIrSum", 2); |
480 | 505 | stage2.build(); |
481 | 506 |
|
482 | 507 | filter2.setVertexShader(loadShaderSource(shader_folder + "default.vs")); |
483 | 508 | filter2.setFragmentShader(loadShaderSource(shader_folder + "filter2.fs")); |
| 509 | + filter2.bindFragDataLocation("Debug", 0); |
| 510 | + filter2.bindFragDataLocation("FilterDepth", 1); |
484 | 511 | filter2.build(); |
485 | 512 |
|
486 | 513 | if(do_debug) |
487 | 514 | { |
488 | 515 | debug.setVertexShader(loadShaderSource(shader_folder + "default.vs")); |
489 | 516 | debug.setFragmentShader(loadShaderSource(shader_folder + "debug.fs")); |
| 517 | + debug.bindFragDataLocation("Debug", 0); |
490 | 518 | debug.build(); |
491 | 519 | } |
492 | 520 |
|
@@ -545,11 +573,11 @@ struct OpenGLDepthPacketProcessorImpl : public WithOpenGLBindings, public WithPe |
545 | 573 | gl()->glBindBuffer(GL_ARRAY_BUFFER, square_vbo); |
546 | 574 | gl()->glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); |
547 | 575 |
|
548 | | - GLint position_attr = stage1.getAttributeLocation("Position"); |
| 576 | + GLint position_attr = stage1.getAttributeLocation("InputPosition"); |
549 | 577 | gl()->glVertexAttribPointer(position_attr, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)0); |
550 | 578 | gl()->glEnableVertexAttribArray(position_attr); |
551 | 579 |
|
552 | | - GLint texcoord_attr = stage1.getAttributeLocation("TexCoord"); |
| 580 | + GLint texcoord_attr = stage1.getAttributeLocation("InputTexCoord"); |
553 | 581 | gl()->glVertexAttribPointer(texcoord_attr, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (GLvoid*)(2 * sizeof(float))); |
554 | 582 | gl()->glEnableVertexAttribArray(texcoord_attr); |
555 | 583 | } |
@@ -751,11 +779,11 @@ OpenGLDepthPacketProcessor::OpenGLDepthPacketProcessor(void *parent_opengl_conte |
751 | 779 | // setup context |
752 | 780 | glfwDefaultWindowHints(); |
753 | 781 | glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); |
754 | | - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); |
| 782 | + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1); |
755 | 783 | #ifdef __APPLE__ |
756 | 784 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); |
757 | 785 | #endif |
758 | | - glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 786 | + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE); |
759 | 787 | glfwWindowHint(GLFW_VISIBLE, debug ? GL_TRUE : GL_FALSE); |
760 | 788 |
|
761 | 789 | GLFWwindow* window = glfwCreateWindow(1024, 848, "OpenGLDepthPacketProcessor", 0, parent_window); |
|
0 commit comments