| 1004 | } |
| 1005 | |
| 1006 | void |
| 1007 | HistogramPrivate::computeHistogram(Histogram::DisplayModeEnum channel) |
| 1008 | { |
| 1009 | // always running in the main thread |
| 1010 | assert( qApp && qApp->thread() == QThread::currentThread() ); |
| 1011 | assert( QOpenGLContext::currentContext() == context() ); |
| 1012 | |
| 1013 | GLenum attachment = colorAttachmentFromDisplayMode(channel); |
| 1014 | |
| 1015 | #ifdef DEBUG |
| 1016 | #pragma message WARN("TODO: ave currently bound VA, Buffer, and bound texture") |
| 1017 | #endif |
| 1018 | /*binding the VAO holding managing the VBO*/ |
| 1019 | glBindVertexArray(vaoID); |
| 1020 | /*binding the VBO sending vertices to the vertex shader*/ |
| 1021 | glBindBuffer(GL_ARRAY_BUFFER, vboID); |
| 1022 | /*each attribute will be a vec2f*/ |
| 1023 | glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0); |
| 1024 | /*enabling the VBO 0 of the VAO*/ |
| 1025 | glEnableVertexAttribArray(0); |
| 1026 | |
| 1027 | GLuint savedTexture; |
| 1028 | glGetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, (GLint*)&savedTexture); |
| 1029 | { |
| 1030 | GLProtectAttrib a(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT); |
| 1031 | |
| 1032 | /*start rendering to the histogram texture held by the _fboHistogram*/ |
| 1033 | startRenderingTo(fbohistogram, attachment, 256, 1); // modifies GL_TRANSFORM & GL_VIEWPORT |
| 1034 | |
| 1035 | /*clearing out the texture from previous computations*/ |
| 1036 | glClearColor(0.f, 0.f, 0.f, 0.f); |
| 1037 | glClear(GL_COLOR_BUFFER_BIT); |
| 1038 | /*enabling blending to add up the colors in texels : |
| 1039 | this results in pixels suming up */ |
| 1040 | glEnable(GL_BLEND); |
| 1041 | glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD); |
| 1042 | glBlendFuncSeparate(GL_ONE, GL_ONE, GL_ONE, GL_ONE); |
| 1043 | /*binding the input image*/ |
| 1044 | glActiveTexture(GL_TEXTURE0); |
| 1045 | |
| 1046 | glBindTexture( GL_TEXTURE_RECTANGLE_ARB, leftImageTexture->getTexID() ); |
| 1047 | /*making current the shader computing the histogram*/ |
| 1048 | activateHistogramComputingShader(channel); |
| 1049 | /*the number of vertices in the VBO*/ |
| 1050 | int vertexCount = leftImageTexture->w() * leftImageTexture->h(); |
| 1051 | /*sending vertices to the GPU, they're handled by the vertex shader*/ |
| 1052 | glDrawArrays(GL_POINTS, 0, vertexCount); |
| 1053 | /*stop computing*/ |
| 1054 | histogramComputingShader->release(); |
| 1055 | /*reset our context state*/ |
| 1056 | glDisable(GL_BLEND); |
| 1057 | glBindVertexArray(0); |
| 1058 | stopRenderingTo(); |
| 1059 | |
| 1060 | /*At this point we have the Histogram filled. From now on we can compute the maximum |
| 1061 | of the histogram with parallel reductions. 4 passes are needed : 256 -> 64 , |
| 1062 | 64 -> 16 , 16 -> 4, 4 -> 1 |
| 1063 | The last pass is done after the loop as it is done in a separate FBO. |
no test coverage detected