Nux

Merge lp:~unity-team/nux/linear-sample-blur into lp:nux

Proposed by Nicolas d'Offay
Status: Merged
Approved by: Nicolas d'Offay
Approved revision: 725
Merged at revision: 751
Proposed branch: lp:~unity-team/nux/linear-sample-blur
Merge into: lp:nux
Diff against target: 551 lines (+465/-5)
3 files modified
NuxGraphics/GraphicsEngine.cpp (+42/-0)
NuxGraphics/GraphicsEngine.h (+26/-0)
NuxGraphics/RenderingPipeGLSL.cpp (+397/-5)
To merge this branch: bzr merge lp:~unity-team/nux/linear-sample-blur
Reviewer Review Type Date Requested Status
Nicolas d'Offay (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+144099@code.launchpad.net

Commit message

Added linear sample gaussian blur shader which halves the loop count of our vertical and horizontal blur drastically improving performance.

To post a comment you must log in.
Revision history for this message
Nicolas d'Offay (nicolas-doffay) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NuxGraphics/GraphicsEngine.cpp'
--- NuxGraphics/GraphicsEngine.cpp 2012-11-28 15:16:41 +0000
+++ NuxGraphics/GraphicsEngine.cpp 2013-01-21 12:52:20 +0000
@@ -1335,6 +1335,48 @@
1335 SetViewport(0, 0, width, height);1335 SetViewport(0, 0, width, height);
1336 Push2DWindow(width, height);1336 Push2DWindow(width, height);
1337 }1337 }
1338
1339 /*! Description - This function calculates position offsets for our gaussian weight values to utilise the GPU bilinear sampling
1340 * which gets neighbouring pixel's data in just one sample. This serves to halve the loop for both vertical and
1341 * horizontal blur shaders.
1342 * Params - First two parameters are the weight and weight offsets which are passed as uniforms to our shader.
1343 * our sigma dictates how strong our blur will be.
1344 * Return - We return our loop count which is a #define in our vertical and horizontal shaders.
1345 */
1346 int GraphicsEngine::LinearSampleGaussianWeights(std::vector<float>& weights, std::vector<float>& offsets,
1347 float sigma)
1348 {
1349 //Calculate our support which is used as our loop count.
1350 int support = int(sigma * 3.0f);
1351
1352 weights.push_back(exp(-(0*0)/(2*sigma*sigma))/(sqrt(2*constants::pi)*sigma));
1353
1354 float total = weights.back();
1355
1356 //Our first weight has an offset of 0.
1357 offsets.push_back(0);
1358
1359 for (int i = 1; i <= support; i++)
1360 {
1361 float w1 = exp(-(i*i)/(2*sigma*sigma))/(sqrt(2*constants::pi)*sigma);
1362 float w2 = exp(-((i+1)*(i+1))/(2*sigma*sigma))/(sqrt(2*constants::pi)*sigma);
1363
1364 weights.push_back(w1 + w2);
1365 total += 2.0f * weights[i];
1366
1367 //Calculate our offset to utilise our GPU's bilinear sampling capability. By sampling in between texel we get the data of
1368 //neighbouring pixels with only one sample.
1369 offsets.push_back((i * w1 + (i + 1) * w2) / weights[i]);
1370 }
1371
1372 //Normalise our weights.
1373 for (int i = 0; i < support; i++)
1374 {
1375 weights[i] /= total;
1376 }
1377
1378 return support;
1379 }
13381380
1339 void GraphicsEngine::GaussianWeights(float **weights, float sigma, unsigned int num_tap)1381 void GraphicsEngine::GaussianWeights(float **weights, float sigma, unsigned int num_tap)
1340 {1382 {
13411383
=== modified file 'NuxGraphics/GraphicsEngine.h'
--- NuxGraphics/GraphicsEngine.h 2012-11-12 20:59:56 +0000
+++ NuxGraphics/GraphicsEngine.h 2013-01-21 12:52:20 +0000
@@ -434,6 +434,8 @@
434 void QRP_GLSL_VerticalGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);434 void QRP_GLSL_VerticalGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
435 void QRP_GLSL_HorizontalHQGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);435 void QRP_GLSL_HorizontalHQGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
436 void QRP_GLSL_VerticalHQGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);436 void QRP_GLSL_VerticalHQGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
437 void QRP_GLSL_HorizontalLSGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
438 void QRP_GLSL_VerticalLSGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
437 void QRP_GLSL_ColorMatrix (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, Matrix4 color_matrix, Vector4 offset);439 void QRP_GLSL_ColorMatrix (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, Matrix4 color_matrix, Vector4 offset);
438440
439 /*!441 /*!
@@ -450,6 +452,13 @@
450 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,452 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
451 const Color& c0,453 const Color& c0,
452 float sigma = 1.0f, int num_pass = 1);454 float sigma = 1.0f, int num_pass = 1);
455
456 ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetLSBlurTexture(
457 int x, int y,
458 int buffer_width, int buffer_height,
459 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
460 const Color& c0,
461 float sigma = 1.0f, int num_pass = 1);
453462
454 ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetAlphaTexture(463 ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetAlphaTexture(
455 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,464 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
@@ -480,6 +489,12 @@
480 int buffer_width, int buffer_height,489 int buffer_width, int buffer_height,
481 FxStructure* fx_structure, TexCoordXForm& texxform,490 FxStructure* fx_structure, TexCoordXForm& texxform,
482 const Color& c0, float sigma = 1.0f, int num_pass = 1);491 const Color& c0, float sigma = 1.0f, int num_pass = 1);
492
493 void QRP_GLSL_GetLSBlurFx(
494 int x, int y,
495 int buffer_width, int buffer_height,
496 FxStructure *fx_structure, TexCoordXForm &texxform,
497 const Color& c0, float sigma = 1.0f, int num_pass = 1);
483498
484 void QRP_GLSL_DisturbedTexture(499 void QRP_GLSL_DisturbedTexture(
485 int x, int y, int width, int height,500 int x, int y, int width, int height,
@@ -842,6 +857,9 @@
842857
843 //! Helper function to compute a Gaussian filter weights858 //! Helper function to compute a Gaussian filter weights
844 void GaussianWeights(float **weights, float sigma, unsigned int num_tap);859 void GaussianWeights(float **weights, float sigma, unsigned int num_tap);
860
861 int LinearSampleGaussianWeights(std::vector<float>& weights, std::vector<float>& offsets,
862 float sigma);
845863
846 //! Helper function to set an fbo864 //! Helper function to set an fbo
847 void SetFrameBufferHelper(865 void SetFrameBufferHelper(
@@ -1009,6 +1027,14 @@
1009 void InitSLVerticalHQGaussFilter(int sigma);1027 void InitSLVerticalHQGaussFilter(int sigma);
1010 //! Gauss vertical filter.1028 //! Gauss vertical filter.
1011 ObjectPtr<IOpenGLShaderProgram> _vertical_hq_gauss_filter_prog[NUX_MAX_GAUSSIAN_SIGMA];1029 ObjectPtr<IOpenGLShaderProgram> _vertical_hq_gauss_filter_prog[NUX_MAX_GAUSSIAN_SIGMA];
1030
1031 void InitSLHorizontalLSGaussFilter(int k);
1032 //! Gauss horizontal filter.
1033 ObjectPtr<IOpenGLShaderProgram> _horizontal_ls_gauss_filter_prog[NUX_MAX_GAUSSIAN_SIGMA];
1034
1035 void InitSLVerticalLSGaussFilter(int k);
1036 //! Gauss vertical filter.
1037 ObjectPtr<IOpenGLShaderProgram> _vertical_ls_gauss_filter_prog[NUX_MAX_GAUSSIAN_SIGMA];
10121038
1013 void InitSLColorMatrixFilter();1039 void InitSLColorMatrixFilter();
1014 //! Color matrix filter.1040 //! Color matrix filter.
10151041
=== modified file 'NuxGraphics/RenderingPipeGLSL.cpp'
--- NuxGraphics/RenderingPipeGLSL.cpp 2012-11-12 20:59:56 +0000
+++ NuxGraphics/RenderingPipeGLSL.cpp 2013-01-21 12:52:20 +0000
@@ -629,6 +629,118 @@
629 CHECKGL(glBindAttribLocation(_vertical_hq_gauss_filter_prog[k-1]->GetOpenGLID(), 0, "AVertex"));629 CHECKGL(glBindAttribLocation(_vertical_hq_gauss_filter_prog[k-1]->GetOpenGLID(), 0, "AVertex"));
630 _vertical_hq_gauss_filter_prog[k-1]->Link();630 _vertical_hq_gauss_filter_prog[k-1]->Link();
631 }631 }
632
633 void GraphicsEngine::InitSLHorizontalLSGaussFilter(int k)
634 {
635 if (_horizontal_ls_gauss_filter_prog[k-1].IsValid())
636 {
637 // Shader program already compiled
638 return;
639 }
640
641 ObjectPtr<IOpenGLVertexShader> vs = _graphics_display.m_DeviceFactory->CreateVertexShader();
642 ObjectPtr<IOpenGLPixelShader> ps = _graphics_display.m_DeviceFactory->CreatePixelShader();
643
644 std::string vs_string = NUX_VERTEX_SHADER_HEADER
645 "uniform mat4 view_projection_matrix; \n\
646 attribute vec4 vertex; \n\
647 attribute vec4 tex_coord; \n\
648 varying vec4 v_tex_coord; \n\
649 void main() \n\
650 { \n\
651 v_tex_coord = tex_coord; \n\
652 gl_Position = view_projection_matrix * vertex; \n\
653 }";
654
655 std::string ps_string = NUX_FRAGMENT_SHADER_HEADER
656 "varying vec4 v_tex_coord; \n\
657 uniform sampler2D tex_object; \n\
658 uniform vec2 tex_size; \n\
659 #define NUM_SAMPLES %d \n\
660 uniform float weights[NUM_SAMPLES]; \n\
661 uniform float offsets[NUM_SAMPLES]; \n\
662 void main() \n\
663 { \n\
664 vec3 acc = texture2D(tex_object, v_tex_coord.st).rgb*weights[0];\n\
665 for (int i = 1; i < NUM_SAMPLES; i++) \n\
666 { \n\
667 acc += texture2D(tex_object, (v_tex_coord.st+(vec2(offsets[i], 0.0)/tex_size))).rgb*weights[i]; \n\
668 acc += texture2D(tex_object, (v_tex_coord.st-(vec2(offsets[i], 0.0)/tex_size))).rgb*weights[i]; \n\
669 } \n\
670 gl_FragColor = vec4(acc, 1.0); \n\
671 }";
672
673 int l = ps_string.length();
674 char* shader_prog = new char[l+10];
675 sprintf(shader_prog, ps_string.c_str(), k);
676
677 _horizontal_ls_gauss_filter_prog[k-1] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
678 vs->SetShaderCode(vs_string.c_str());
679 ps->SetShaderCode(shader_prog);
680 delete[] shader_prog;
681
682 _horizontal_ls_gauss_filter_prog[k-1]->ClearShaderObjects();
683 _horizontal_ls_gauss_filter_prog[k-1]->AddShaderObject(vs);
684 _horizontal_ls_gauss_filter_prog[k-1]->AddShaderObject(ps);
685 CHECKGL(glBindAttribLocation(_horizontal_ls_gauss_filter_prog[k-1]->GetOpenGLID(), 0, "vertex"));
686 _horizontal_ls_gauss_filter_prog[k-1]->Link();
687 }
688
689 void GraphicsEngine::InitSLVerticalLSGaussFilter(int k)
690 {
691 if (_vertical_ls_gauss_filter_prog[k-1].IsValid())
692 {
693 // Shader program already compiled
694 return;
695 }
696
697 ObjectPtr<IOpenGLVertexShader> vs = _graphics_display.m_DeviceFactory->CreateVertexShader();
698 ObjectPtr<IOpenGLPixelShader> ps = _graphics_display.m_DeviceFactory->CreatePixelShader();
699
700 std::string vs_string = NUX_VERTEX_SHADER_HEADER
701 "uniform mat4 view_projection_matrix; \n\
702 attribute vec4 vertex; \n\
703 attribute vec4 tex_coord; \n\
704 varying vec4 v_tex_coord; \n\
705 void main() \n\
706 { \n\
707 v_tex_coord = tex_coord; \n\
708 gl_Position = view_projection_matrix * vertex; \n\
709 }";
710
711 std::string ps_string = NUX_FRAGMENT_SHADER_HEADER
712 "varying vec4 v_tex_coord; \n\
713 uniform sampler2D tex_object; \n\
714 uniform vec2 tex_size; \n\
715 #define NUM_SAMPLES %d \n\
716 uniform float weights[NUM_SAMPLES]; \n\
717 uniform float offsets[NUM_SAMPLES]; \n\
718 void main() \n\
719 { \n\
720 vec3 acc = texture2D(tex_object, v_tex_coord.st).rgb*weights[0]; \n\
721 for (int i = 1; i < NUM_SAMPLES; i++) \n\
722 { \n\
723 acc += texture2D(tex_object, (v_tex_coord.st+(vec2(0.0, offsets[i])/tex_size))).rgb*weights[i]; \n\
724 acc += texture2D(tex_object, (v_tex_coord.st-(vec2(0.0, offsets[i])/tex_size))).rgb*weights[i]; \n\
725 } \n\
726 gl_FragColor = vec4(acc, 1.0); \n\
727 }";
728
729 int l = ps_string.length();
730 char* shader_prog = new char[l+10];
731 sprintf(shader_prog, ps_string.c_str(), k);
732
733 _vertical_ls_gauss_filter_prog[k-1] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
734 vs->SetShaderCode(vs_string.c_str());
735 ps->SetShaderCode(shader_prog);
736 delete[] shader_prog;
737
738 _vertical_ls_gauss_filter_prog[k-1]->ClearShaderObjects();
739 _vertical_ls_gauss_filter_prog[k-1]->AddShaderObject(vs);
740 _vertical_ls_gauss_filter_prog[k-1]->AddShaderObject(ps);
741 CHECKGL(glBindAttribLocation(_vertical_ls_gauss_filter_prog[k-1]->GetOpenGLID(), 0, "vertex"));
742 _vertical_ls_gauss_filter_prog[k-1]->Link();
743 }
632744
633 void GraphicsEngine::InitSLColorMatrixFilter()745 void GraphicsEngine::InitSLColorMatrixFilter()
634 {746 {
@@ -1982,6 +2094,155 @@
19822094
1983 ShaderProg->End();2095 ShaderProg->End();
1984 }2096 }
2097
2098 void GraphicsEngine::QRP_GLSL_HorizontalLSGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color & /* c0 */, float sigma)
2099 {
2100 std::vector<float> weights(0);
2101 std::vector<float> offsets(0);
2102
2103 int num_samples = LinearSampleGaussianWeights(weights, offsets, sigma);
2104
2105 if (_horizontal_ls_gauss_filter_prog[num_samples-1].IsValid() == false)
2106 {
2107 InitSLHorizontalLSGaussFilter(num_samples);
2108 }
2109
2110 m_quad_tex_stats++;
2111 QRP_Compute_Texture_Coord(width, height, device_texture, texxform0);
2112 float fx = x, fy = y;
2113 float vtx_buffer[] =
2114 {
2115 fx, fy, 0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
2116 fx, fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
2117 fx + width, fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
2118 fx + width, fy, 0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
2119 };
2120
2121 ObjectPtr<IOpenGLShaderProgram> shader_prog;
2122
2123 if (!device_texture->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
2124 {
2125 return;
2126 }
2127
2128 shader_prog = _horizontal_ls_gauss_filter_prog[num_samples-1];
2129
2130 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
2131 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
2132 shader_prog->Begin();
2133
2134 int tex_object_location = shader_prog->GetUniformLocationARB("tex_object");
2135 int weights_location = shader_prog->GetUniformLocationARB("weights");
2136 int offsets_location = shader_prog->GetUniformLocationARB("offsets");
2137 int tex_size_location = shader_prog->GetUniformLocationARB("tex_size");
2138 int vertex_location = shader_prog->GetAttributeLocation("vertex");
2139 int tex_coord_location = shader_prog->GetAttributeLocation("tex_coord");
2140
2141 SetTexture(GL_TEXTURE0, device_texture);
2142 CHECKGL(glUniform1iARB(tex_object_location, 0));
2143
2144 CHECKGL(glUniform1fv(weights_location, weights.size(), &weights[0]));
2145 CHECKGL(glUniform1fv(offsets_location, offsets.size(), &offsets[0]));
2146
2147 CHECKGL(glUniform2fARB(tex_size_location, width, height));
2148
2149 int VPMatrixLocation = shader_prog->GetUniformLocationARB("view_projection_matrix");
2150 Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
2151 shader_prog->SetUniformLocMatrix4fv((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
2152
2153 CHECKGL(glEnableVertexAttribArrayARB(vertex_location));
2154 CHECKGL(glVertexAttribPointerARB((GLuint) vertex_location, 4, GL_FLOAT, GL_FALSE, 32, vtx_buffer));
2155
2156 if (tex_coord_location != -1)
2157 {
2158 CHECKGL(glEnableVertexAttribArrayARB(tex_coord_location));
2159 CHECKGL(glVertexAttribPointerARB((GLuint) tex_coord_location, 4, GL_FLOAT, GL_FALSE, 32, vtx_buffer + 4));
2160 }
2161
2162 CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
2163
2164 CHECKGL(glDisableVertexAttribArrayARB(vertex_location));
2165
2166 if (tex_coord_location != -1)
2167 CHECKGL(glDisableVertexAttribArrayARB(tex_coord_location));
2168
2169 shader_prog->End();
2170 }
2171
2172 void GraphicsEngine::QRP_GLSL_VerticalLSGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color & /* c0 */, float sigma)
2173 {
2174 std::vector<float> weights(0);
2175 std::vector<float> offsets(0);
2176
2177 int num_samples = LinearSampleGaussianWeights(weights, offsets, sigma);
2178
2179 if (_vertical_ls_gauss_filter_prog[num_samples-1].IsValid() == false)
2180 {
2181 InitSLVerticalLSGaussFilter(num_samples);
2182 }
2183
2184 m_quad_tex_stats++;
2185 QRP_Compute_Texture_Coord(width, height, device_texture, texxform0);
2186 float fx = x, fy = y;
2187 float vtx_buffer[] =
2188 {
2189 fx, fy, 0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
2190 fx, fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
2191 fx + width, fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
2192 fx + width, fy, 0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
2193 };
2194
2195 ObjectPtr<IOpenGLShaderProgram> shader_prog;
2196
2197 if (!device_texture->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
2198 {
2199 return;
2200 }
2201
2202 shader_prog = _vertical_ls_gauss_filter_prog[num_samples-1];
2203
2204 CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
2205 CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
2206 shader_prog->Begin();
2207
2208 int tex_object_location = shader_prog->GetUniformLocationARB("tex_object");
2209 int weights_location = shader_prog->GetUniformLocationARB("weights");
2210 int offsets_location = shader_prog->GetUniformLocationARB("offsets");
2211 int tex_size_location = shader_prog->GetUniformLocationARB("tex_size");
2212 int vertex_location = shader_prog->GetAttributeLocation("vertex");
2213 int tex_coord_location = shader_prog->GetAttributeLocation("tex_coord");
2214
2215 SetTexture(GL_TEXTURE0, device_texture);
2216
2217 CHECKGL(glUniform1iARB(tex_object_location, 0));
2218
2219 CHECKGL(glUniform1fv(weights_location, weights.size(), &weights[0]));
2220 CHECKGL(glUniform1fv(offsets_location, offsets.size(), &offsets[0]));
2221
2222 CHECKGL(glUniform2fARB(tex_size_location, width, height));
2223
2224 int VPMatrixLocation = shader_prog->GetUniformLocationARB("view_projection_matrix");
2225 Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
2226 shader_prog->SetUniformLocMatrix4fv((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
2227
2228 CHECKGL(glEnableVertexAttribArrayARB(vertex_location));
2229 CHECKGL(glVertexAttribPointerARB((GLuint) vertex_location, 4, GL_FLOAT, GL_FALSE, 32, vtx_buffer));
2230
2231 if (tex_coord_location != -1)
2232 {
2233 CHECKGL(glEnableVertexAttribArrayARB(tex_coord_location));
2234 CHECKGL(glVertexAttribPointerARB((GLuint) tex_coord_location, 4, GL_FLOAT, GL_FALSE, 32, vtx_buffer + 4));
2235 }
2236
2237 CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
2238
2239 CHECKGL(glDisableVertexAttribArrayARB(vertex_location));
2240
2241 if (tex_coord_location != -1)
2242 CHECKGL(glDisableVertexAttribArrayARB(tex_coord_location));
2243
2244 shader_prog->End();
2245 }
19852246
1986 void GraphicsEngine::QRP_GLSL_ColorMatrix(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0,2247 void GraphicsEngine::QRP_GLSL_ColorMatrix(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0,
1987 const Color &c0,2248 const Color &c0,
@@ -2133,6 +2394,72 @@
21332394
2134 return _offscreen_color_rt0;2395 return _offscreen_color_rt0;
2135 }2396 }
2397
2398 ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetLSBlurTexture(
2399 int x, int y,
2400 int buffer_width, int buffer_height,
2401 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
2402 const Color& c0,
2403 float sigma, int num_pass)
2404 {
2405 int quad_width = device_texture->GetWidth();
2406 int quad_height = device_texture->GetHeight();
2407
2408 num_pass = Clamp<int> (num_pass, 1, 50);
2409
2410 ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
2411 int previous_width = 0;
2412 int previous_height = 0;
2413 if (prevFBO.IsValid())
2414 {
2415 previous_width = prevFBO->GetWidth();
2416 previous_height = prevFBO->GetHeight();
2417 }
2418 else
2419 {
2420 previous_width = _graphics_display.GetWindowWidth();
2421 previous_height = _graphics_display.GetWindowHeight();
2422 }
2423
2424 CHECKGL(glClearColor(0, 0, 0, 0));
2425 _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
2426 _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
2427 _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
2428 _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
2429
2430 SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
2431 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2432
2433 QRP_GLSL_1Tex(x, y, quad_width, quad_height, device_texture, texxform, color::White);
2434
2435 TexCoordXForm texxform1;
2436 for (int i = 0; i < num_pass; i++)
2437 {
2438 SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, buffer_width, buffer_height);
2439 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2440 QRP_GLSL_HorizontalLSGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt0, texxform1, c0, sigma);
2441
2442 SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
2443 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2444 QRP_GLSL_VerticalLSGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt1, texxform1, c0, sigma);
2445 }
2446
2447 _offscreen_fbo->Deactivate();
2448
2449 if (prevFBO.IsValid())
2450 {
2451 prevFBO->Activate(true);
2452 SetViewport(0, 0, previous_width, previous_height);
2453 SetOrthographicProjectionMatrix(previous_width, previous_height);
2454 }
2455 else
2456 {
2457 SetViewport(0, 0, previous_width, previous_height);
2458 SetOrthographicProjectionMatrix(previous_width, previous_height);
2459 }
2460
2461 return _offscreen_color_rt0;
2462 }
21362463
2137 ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetPower(2464 ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetPower(
2138 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &c0, const Vector4 &exponent)2465 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &c0, const Vector4 &exponent)
@@ -2469,11 +2796,76 @@
2469 {2796 {
2470 SetFrameBufferHelper(_offscreen_fbo, fx_structure->temp_texture, _offscreen_depth_rt1, buffer_width, buffer_height);2797 SetFrameBufferHelper(_offscreen_fbo, fx_structure->temp_texture, _offscreen_depth_rt1, buffer_width, buffer_height);
2471 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);2798 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2472 QRP_GLSL_HorizontalHQGauss(0, 0, buffer_width, buffer_height, fx_structure->dst_texture, texxform1, c0, sigma);2799 QRP_GLSL_HorizontalGauss(0, 0, buffer_width, buffer_height, fx_structure->dst_texture, texxform1, c0, sigma);
24732800
2474 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);2801 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
2475 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);2802 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2476 QRP_GLSL_VerticalHQGauss(0, 0, buffer_width, buffer_height, fx_structure->temp_texture, texxform1, c0, sigma);2803 QRP_GLSL_VerticalGauss(0, 0, buffer_width, buffer_height, fx_structure->temp_texture, texxform1, c0, sigma);
2804 }
2805
2806 _offscreen_fbo->Deactivate();
2807
2808 if (prevFBO.IsValid())
2809 {
2810 prevFBO->Activate(true);
2811 SetViewport(0, 0, previous_width, previous_height);
2812 SetOrthographicProjectionMatrix(previous_width, previous_height);
2813 }
2814 else
2815 {
2816 SetViewport(0, 0, previous_width, previous_height);
2817 SetOrthographicProjectionMatrix(previous_width, previous_height);
2818 }
2819 }
2820
2821 void GraphicsEngine::QRP_GLSL_GetLSBlurFx(
2822 int x, int y,
2823 int buffer_width, int buffer_height,
2824 FxStructure *fx_structure, TexCoordXForm &texxform,
2825 const Color& c0, float sigma, int num_pass)
2826 {
2827 int quad_width = fx_structure->src_texture->GetWidth();
2828 int quad_height = fx_structure->src_texture->GetHeight();
2829
2830 num_pass = Clamp<int> (num_pass, 1, 50);
2831
2832 ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
2833 int previous_width = 0;
2834 int previous_height = 0;
2835 if (prevFBO.IsValid())
2836 {
2837 previous_width = prevFBO->GetWidth();
2838 previous_height = prevFBO->GetHeight();
2839 }
2840 else
2841 {
2842 previous_width = _graphics_display.GetWindowWidth();
2843 previous_height = _graphics_display.GetWindowHeight();
2844 }
2845
2846 CHECKGL(glClearColor(0, 0, 0, 0));
2847 fx_structure->src_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
2848 fx_structure->src_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
2849 fx_structure->dst_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
2850 fx_structure->dst_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
2851 fx_structure->temp_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
2852 fx_structure->temp_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
2853
2854 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
2855 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2856
2857 QRP_GLSL_1Tex(x, y, quad_width, quad_height, fx_structure->src_texture, texxform, color::White);
2858
2859 TexCoordXForm texxform1;
2860 for (int i = 0; i < num_pass; i++)
2861 {
2862 SetFrameBufferHelper(_offscreen_fbo, fx_structure->temp_texture, _offscreen_depth_rt1, buffer_width, buffer_height);
2863 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2864 QRP_GLSL_HorizontalLSGauss(0, 0, buffer_width, buffer_height, fx_structure->dst_texture, texxform1, c0, sigma);
2865
2866 SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
2867 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2868 QRP_GLSL_VerticalLSGauss(0, 0, buffer_width, buffer_height, fx_structure->temp_texture, texxform1, c0, sigma);
2477 }2869 }
24782870
2479 _offscreen_fbo->Deactivate();2871 _offscreen_fbo->Deactivate();

Subscribers

People subscribed via source and target branches