~loic.molinari/nux/nux-sigc-trackable-base-class

« back to all changes in this revision

Viewing changes to NuxGraphics/RenderingPipeGLSL.cpp

  • Committer: Jay Taoko
  • Date: 2011-01-07 15:32:47 UTC
  • mfrom: (163.1.3 nux)
  • Revision ID: jay.taoko@canonical.com-20110107153247-644td0i1gimxgnzj
* Support for shader effects

Show diffs side-by-side

added added

removed removed

Lines of Context:
301
301
                        varying vec4 varyTexCoord1;                                 \n\
302
302
                        uniform vec4 color0;                                        \n\
303
303
                        uniform vec4 color1;                                        \n\
304
 
                        uniform vec4 noise_factor;                                  \n\
305
304
                        uniform sampler2D TextureObject0;                           \n\
306
305
                        uniform sampler2D TextureObject1;                           \n\
307
306
                        vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
402
401
    // other  attributes. Otherwise you get a bug on NVidia! Why is that???
403
402
 
404
403
    ////////////////////////////////////////////////////////////////////////////////////////////////////
405
 
    VSString =  TEXT (   "#version 110                                           \n\
 
404
    VSString =  TEXT (   "#version 110                                          \n\
406
405
                        uniform mat4 ViewProjectionMatrix;                      \n\
407
406
                        attribute vec4 AVertex;                                 \n\
408
407
                        attribute vec4 MyTextureCoord0;                         \n\
422
421
                        gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
423
422
                        }");
424
423
 
425
 
    PSString =  TEXT (   "#version 110                                               \n\
 
424
    PSString =  TEXT (   "#version 110                                              \n\
426
425
                        #extension GL_ARB_texture_rectangle : enable                \n\
427
426
                        varying vec4 varyTexCoord0;                                 \n\
428
427
                        varying vec4 varyTexCoord1;                                 \n\
446
445
                          vec4 b1 = color1*SampleTexture(TextureObject1, varyTexCoord1);  \n\
447
446
                          vec4 b2 = color2*SampleTexture(TextureObject2, varyTexCoord2);  \n\
448
447
                          vec4 b3 = color3*SampleTexture(TextureObject3, varyTexCoord3);  \n\
449
 
                          gl_FragColor = b0+b1+b2+b3;                              \n\
 
448
                          gl_FragColor = b0+b1+b2+b3;                                     \n\
450
449
                        }");
451
450
 
452
451
    //vec4(v.w, v.w, v.w, v.w)
501
500
        {                                                                                                     \n\
502
501
          return texture2D(TexObject, TexCoord.st);                                                           \n\
503
502
        }                                                                                                     \n\
504
 
        void main (void)                                                                                          \n\
505
 
        {                                                                                                               \n\
506
 
          vec4 TexColor = SampleTexture(TextureObject0, varyTexCoord0.st);                                        \n\
507
 
          vec4 result = pow(TexColor, exponent);                                                                  \n\
508
 
          gl_FragColor = color0*result;                                                                           \n\
 
503
        void main (void)                                                                                      \n\
 
504
        {                                                                                                           \n\
 
505
          vec4 TexColor = SampleTexture(TextureObject0, varyTexCoord0.st);                                    \n\
 
506
          vec4 result = pow(TexColor, exponent);                                                              \n\
 
507
          gl_FragColor = color0*result;                                                                       \n\
509
508
        }");
510
509
 
511
510
 
551
550
        void main ()                                                  \n\
552
551
        {                                                             \n\
553
552
          vec4 v = SampleTexture(TextureObject0, varyTexCoord0);      \n\
554
 
          gl_FragColor = vec4(v.a, v.a, v.a, v.a) * color0;  \n\
 
553
          gl_FragColor = vec4(v.a, v.a, v.a, v.a) * color0;           \n\
555
554
        }");
556
555
 
557
556
    _alpha_replicate_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram ();
576
575
    VSString = TEXT ("#version 120          \n\
577
576
        uniform mat4 ViewProjectionMatrix;  \n\
578
577
        attribute vec4 AVertex;             \n\
579
 
        attribute vec4 MyTextureCoord0;       \n\
 
578
        attribute vec4 MyTextureCoord0;     \n\
580
579
        attribute vec4 VertexColor;         \n\
581
580
        varying vec4 varyTexCoord0;         \n\
582
581
        varying vec4 varyVertexColor;       \n\
583
582
        void main()                         \n\
584
583
        {                                   \n\
585
 
          varyTexCoord0 = MyTextureCoord0;    \n\
 
584
          varyTexCoord0 = MyTextureCoord0;  \n\
586
585
          varyVertexColor = VertexColor;    \n\
587
586
          gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
588
587
        }");
597
596
        {                                                             \n\
598
597
          return texture2D(TexObject, TexCoord.st);                   \n\
599
598
        }                                                             \n\
600
 
        #define NUM_SAMPLES 55                                        \n\
 
599
        #define NUM_SAMPLES 7                                         \n\
601
600
        uniform float W[NUM_SAMPLES];                                 \n\
602
601
        void main()                                                   \n\
603
602
        {                                                             \n\
606
605
          vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);    \n\
607
606
          texCoord.x -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.x;     \n\
608
607
          texCoord.y += 0.0 / TextureSize0.y;                         \n\
609
 
          for (int i = 0; i < NUM_SAMPLES; i++)                       \n\
610
 
          {                                                           \n\
611
 
            sum += SampleTexture (TextureObject0, texCoord) * W[i];   \n\
612
 
            texCoord += delta;                                        \n\
613
 
          }                                                           \n\
 
608
          sum += SampleTexture (TextureObject0, texCoord) * W[0];     \n\
 
609
          texCoord += delta;                                          \n\
 
610
          sum += SampleTexture (TextureObject0, texCoord) * W[1];     \n\
 
611
          texCoord += delta;                                          \n\
 
612
          sum += SampleTexture (TextureObject0, texCoord) * W[2];     \n\
 
613
          texCoord += delta;                                          \n\
 
614
          sum += SampleTexture (TextureObject0, texCoord) * W[3];     \n\
 
615
          texCoord += delta;                                          \n\
 
616
          sum += SampleTexture (TextureObject0, texCoord) * W[4];     \n\
 
617
          texCoord += delta;                                          \n\
 
618
          sum += SampleTexture (TextureObject0, texCoord) * W[5];     \n\
 
619
          texCoord += delta;                                          \n\
 
620
          sum += SampleTexture (TextureObject0, texCoord) * W[6];     \n\
 
621
          texCoord += delta;                                          \n\
614
622
          gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w);           \n\
615
623
        }");
616
624
 
636
644
    VSString = TEXT ("#version 110          \n\
637
645
        uniform mat4 ViewProjectionMatrix;  \n\
638
646
        attribute vec4 AVertex;             \n\
639
 
        attribute vec4 MyTextureCoord0;       \n\
 
647
        attribute vec4 MyTextureCoord0;     \n\
640
648
        attribute vec4 VertexColor;         \n\
641
649
        varying vec4 varyTexCoord0;         \n\
642
650
        varying vec4 varyVertexColor;       \n\
643
651
        void main()                         \n\
644
652
        {                                   \n\
645
 
          varyTexCoord0 = MyTextureCoord0;    \n\
 
653
          varyTexCoord0 = MyTextureCoord0;  \n\
646
654
          varyVertexColor = VertexColor;    \n\
647
655
        gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
648
656
        }");
657
665
        {                                                             \n\
658
666
          return texture2D (TexObject, TexCoord.st);                  \n\
659
667
        }                                                             \n\
660
 
        #define NUM_SAMPLES 55                                        \n\
 
668
        #define NUM_SAMPLES 7                                         \n\
661
669
        uniform float W [NUM_SAMPLES];                                \n\
662
670
        void main ()                                                  \n\
663
671
        {                                                             \n\
666
674
          vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);    \n\
667
675
          texCoord.x += 0.0 / TextureSize0.x;                         \n\
668
676
          texCoord.y -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.y;     \n\
669
 
          for (int i = 0; i < NUM_SAMPLES; ++i)                       \n\
670
 
          {                                                           \n\
671
 
            sum += SampleTexture (TextureObject0, texCoord) * W[i];   \n\
672
 
            texCoord += delta;                                        \n\
673
 
          }                                                           \n\
 
677
          sum += SampleTexture (TextureObject0, texCoord) * W[0];     \n\
 
678
          texCoord += delta;                                          \n\
 
679
          sum += SampleTexture (TextureObject0, texCoord) * W[1];     \n\
 
680
          texCoord += delta;                                          \n\
 
681
          sum += SampleTexture (TextureObject0, texCoord) * W[2];     \n\
 
682
          texCoord += delta;                                          \n\
 
683
          sum += SampleTexture (TextureObject0, texCoord) * W[3];     \n\
 
684
          texCoord += delta;                                          \n\
 
685
          sum += SampleTexture (TextureObject0, texCoord) * W[4];     \n\
 
686
          texCoord += delta;                                          \n\
 
687
          sum += SampleTexture (TextureObject0, texCoord) * W[5];     \n\
 
688
          texCoord += delta;                                          \n\
 
689
          sum += SampleTexture (TextureObject0, texCoord) * W[6];     \n\
 
690
          texCoord += delta;                                          \n\
674
691
          gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w);           \n\
675
692
        }");
676
693
 
685
702
    _vertical_gauss_filter_prog->Link();
686
703
  }
687
704
  
 
705
  void GraphicsEngine::InitSLHorizontalHQGaussFilter ()
 
706
  {
 
707
    ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
 
708
    ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
 
709
    NString VSString;
 
710
    NString PSString;
 
711
 
 
712
 
 
713
    VSString = TEXT ("#version 120                        \n\
 
714
                     uniform mat4 ViewProjectionMatrix;   \n\
 
715
                     attribute vec4 AVertex;              \n\
 
716
                     attribute vec4 MyTextureCoord0;      \n\
 
717
                     attribute vec4 VertexColor;          \n\
 
718
                     varying vec4 varyTexCoord0;          \n\
 
719
                     varying vec4 varyVertexColor;        \n\
 
720
                     void main()                          \n\
 
721
                     {                                    \n\
 
722
                     varyTexCoord0 = MyTextureCoord0;     \n\
 
723
                     varyVertexColor = VertexColor;       \n\
 
724
                     gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
 
725
                     }");
 
726
 
 
727
 
 
728
    PSString = TEXT ("#version 120                                                \n\
 
729
                     varying vec4 varyTexCoord0;                                  \n\
 
730
                     varying vec4 varyVertexColor;                                \n\
 
731
                     uniform sampler2D TextureObject0;                            \n\
 
732
                     uniform vec2 TextureSize0;                                   \n\
 
733
                     vec4 SampleTexture(sampler2D TexObject, vec2 TexCoord)       \n\
 
734
                     {                                                            \n\
 
735
                     return texture2D(TexObject, TexCoord.st);                    \n\
 
736
                     }                                                            \n\
 
737
                     #define NUM_SAMPLES 55                                       \n\
 
738
                     uniform float W[NUM_SAMPLES];                                \n\
 
739
                     void main()                                                  \n\
 
740
                     {                                                            \n\
 
741
                     vec4 sum   = vec4 (0.0, 0.0, 0.0, 0.0);                      \n\
 
742
                     vec2 delta = vec2 (1.0 / TextureSize0.x, 0.0);               \n\
 
743
                     vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);     \n\
 
744
                     texCoord.x -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.x;      \n\
 
745
                     texCoord.y += 0.0 / TextureSize0.y;                          \n\
 
746
                     for (int i = 0; i < NUM_SAMPLES; i++)                        \n\
 
747
                     {                                                            \n\
 
748
                     sum += SampleTexture (TextureObject0, texCoord) * W[i];      \n\
 
749
                     texCoord += delta;                                           \n\
 
750
                     }                                                            \n\
 
751
                     gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w);            \n\
 
752
                     }");
 
753
 
 
754
    _horizontal_hq_gauss_filter_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
 
755
    VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
 
756
    PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
 
757
 
 
758
    _horizontal_hq_gauss_filter_prog->ClearShaderObjects();
 
759
    _horizontal_hq_gauss_filter_prog->AddShaderObject (VS);
 
760
    _horizontal_hq_gauss_filter_prog->AddShaderObject (PS);
 
761
    CHECKGL ( glBindAttribLocation (_horizontal_hq_gauss_filter_prog->GetOpenGLID(), 0, "AVertex") );
 
762
    _horizontal_hq_gauss_filter_prog->Link();
 
763
 
 
764
  }
 
765
 
 
766
  void GraphicsEngine::InitSLVerticalHQGaussFilter ()
 
767
  {
 
768
    ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
 
769
    ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
 
770
    NString VSString;
 
771
    NString PSString;
 
772
 
 
773
    VSString = TEXT ("#version 110                        \n\
 
774
                     uniform mat4 ViewProjectionMatrix;   \n\
 
775
                     attribute vec4 AVertex;              \n\
 
776
                     attribute vec4 MyTextureCoord0;      \n\
 
777
                     attribute vec4 VertexColor;          \n\
 
778
                     varying vec4 varyTexCoord0;          \n\
 
779
                     varying vec4 varyVertexColor;        \n\
 
780
                     void main()                          \n\
 
781
                     {                                    \n\
 
782
                     varyTexCoord0 = MyTextureCoord0;     \n\
 
783
                     varyVertexColor = VertexColor;       \n\
 
784
                     gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
 
785
                     }");
 
786
 
 
787
 
 
788
    PSString = TEXT ("#version 120                                                \n\
 
789
                     varying vec4 varyTexCoord0;                                  \n\
 
790
                     varying vec4 varyVertexColor;                                \n\
 
791
                     uniform sampler2D TextureObject0;                            \n\
 
792
                     uniform vec2 TextureSize0;                                   \n\
 
793
                     vec4 SampleTexture (sampler2D TexObject, vec2 TexCoord)      \n\
 
794
                     {                                                            \n\
 
795
                     return texture2D (TexObject, TexCoord.st);                   \n\
 
796
                     }                                                            \n\
 
797
                     #define NUM_SAMPLES 55                                       \n\
 
798
                     uniform float W [NUM_SAMPLES];                               \n\
 
799
                     void main ()                                                 \n\
 
800
                     {                                                            \n\
 
801
                     vec4 sum   = vec4 (0.0, 0.0, 0.0, 0.0);                      \n\
 
802
                     vec2 delta = vec2 (0.0, 1.0 / TextureSize0.y);               \n\
 
803
                     vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);     \n\
 
804
                     texCoord.x += 0.0 / TextureSize0.x;                          \n\
 
805
                     texCoord.y -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.y;      \n\
 
806
                     for (int i = 0; i < NUM_SAMPLES; ++i)                        \n\
 
807
                     {                                                            \n\
 
808
                     sum += SampleTexture (TextureObject0, texCoord) * W[i];      \n\
 
809
                     texCoord += delta;                                           \n\
 
810
                     }                                                            \n\
 
811
                     gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w);            \n\
 
812
                     }");
 
813
 
 
814
    _vertical_hq_gauss_filter_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
 
815
    VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
 
816
    PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
 
817
 
 
818
    _vertical_hq_gauss_filter_prog->ClearShaderObjects();
 
819
    _vertical_hq_gauss_filter_prog->AddShaderObject (VS);
 
820
    _vertical_hq_gauss_filter_prog->AddShaderObject (PS);
 
821
    CHECKGL ( glBindAttribLocation (_vertical_hq_gauss_filter_prog->GetOpenGLID(), 0, "AVertex") );
 
822
    _vertical_hq_gauss_filter_prog->Link();
 
823
  }
 
824
 
688
825
  void GraphicsEngine::InitSLColorMatrixFilter ()
689
826
  {
690
827
    ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
725
862
          float g = CM1[0]* tex0.r + CM1[1]* tex0.g + CM1[2]* tex0.b + CM1[3]* tex0.a + CM1[4]; \n\
726
863
          float b = CM2[0]* tex0.r + CM2[1]* tex0.g + CM2[2]* tex0.b + CM2[3]* tex0.a + CM2[4]; \n\
727
864
          float a = CM3[0]* tex0.r + CM3[1]* tex0.g + CM3[2]* tex0.b + CM3[3]* tex0.a + CM3[4]; \n\
728
 
          gl_FragColor = color0 * vec4(r, g, b, tex0.a);                               \n\
 
865
          gl_FragColor = color0 * vec4(r, g, b, tex0.a);                                        \n\
729
866
        }");
730
867
 
731
868
    _color_matrix_filter_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
1630
1767
    // Set the Gaussian weights
1631
1768
    {
1632
1769
      float *W;
1633
 
      GaussianWeights(&W, sigma, 55);
1634
 
      CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
 
1770
      GaussianWeights(&W, sigma, 7);
 
1771
      CHECKGL( glUniform1fv(WeightsLocation, 7, W) );
1635
1772
      delete(W);
1636
1773
    }
1637
1774
 
1699
1836
    // Set the Gaussian weights
1700
1837
    {
1701
1838
      float *W;
1702
 
      GaussianWeights(&W, sigma, 55);
1703
 
      CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
1704
 
      delete(W);
1705
 
    }
1706
 
 
1707
 
    CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
1708
 
 
1709
 
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
1710
 
    ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
1711
 
 
1712
 
    CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
1713
 
    CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
1714
 
 
1715
 
    if (TextureCoord0Location != -1)
1716
 
    {
1717
 
      CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
1718
 
      CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
1719
 
    }
1720
 
 
1721
 
    CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
1722
 
 
1723
 
    CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
1724
 
 
1725
 
    if (TextureCoord0Location != -1)
1726
 
      CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
1727
 
 
1728
 
    ShaderProg->End();
1729
 
  }
 
1839
      GaussianWeights(&W, sigma, 7);
 
1840
      CHECKGL( glUniform1fv(WeightsLocation, 7, W) );
 
1841
      delete(W);
 
1842
    }
 
1843
 
 
1844
    CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
 
1845
 
 
1846
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
 
1847
    ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
 
1848
 
 
1849
    CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
 
1850
    CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
 
1851
 
 
1852
    if (TextureCoord0Location != -1)
 
1853
    {
 
1854
      CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
 
1855
      CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
 
1856
    }
 
1857
 
 
1858
    CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
 
1859
 
 
1860
    CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
 
1861
 
 
1862
    if (TextureCoord0Location != -1)
 
1863
      CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
 
1864
 
 
1865
    ShaderProg->End();
 
1866
  }
 
1867
 
 
1868
  void GraphicsEngine::QRP_GLSL_HorizontalHQGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, float sigma)
 
1869
  {
 
1870
    m_quad_tex_stats++;
 
1871
    QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
 
1872
    float VtxBuffer[] =
 
1873
    {
 
1874
      x,          y,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
 
1875
      x,          y + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
 
1876
      x + width,  y + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
 
1877
      x + width,  y,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
 
1878
    };
 
1879
 
 
1880
    ObjectPtr<IOpenGLShaderProgram> ShaderProg;
 
1881
 
 
1882
    if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
 
1883
    {
 
1884
      return;
 
1885
    }
 
1886
 
 
1887
    ShaderProg = _horizontal_hq_gauss_filter_prog;
 
1888
 
 
1889
    CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
 
1890
    CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
1891
    ShaderProg->Begin ();
 
1892
 
 
1893
    int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
 
1894
    int WeightsLocation       = ShaderProg->GetUniformLocationARB ("W");
 
1895
    int TextureSizeLocation   = ShaderProg->GetUniformLocationARB ("TextureSize0");
 
1896
    int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
 
1897
    int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
 
1898
 
 
1899
    SetTexture (GL_TEXTURE0, device_texture);
 
1900
    CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
 
1901
 
 
1902
    sigma = Clamp <float> (sigma, 0.1f, 9.0f);
 
1903
    // Set the Gaussian weights
 
1904
    {
 
1905
      float *W;
 
1906
      GaussianWeights(&W, sigma, 55);
 
1907
      CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
 
1908
      delete(W);
 
1909
    }
 
1910
 
 
1911
    CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
 
1912
 
 
1913
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
 
1914
    ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
 
1915
 
 
1916
    CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
 
1917
    CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
 
1918
 
 
1919
    if (TextureCoord0Location != -1)
 
1920
    {
 
1921
      CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
 
1922
      CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
 
1923
    }
 
1924
 
 
1925
    CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
 
1926
 
 
1927
    CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
 
1928
 
 
1929
    if (TextureCoord0Location != -1)
 
1930
      CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
 
1931
 
 
1932
    ShaderProg->End();
 
1933
  }
 
1934
 
 
1935
  void GraphicsEngine::QRP_GLSL_VerticalHQGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, float sigma)
 
1936
  {
 
1937
    m_quad_tex_stats++;
 
1938
    QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
 
1939
    float VtxBuffer[] =
 
1940
    {
 
1941
      x,          y,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
 
1942
      x,          y + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
 
1943
      x + width,  y + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
 
1944
      x + width,  y,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
 
1945
    };
 
1946
 
 
1947
    ObjectPtr<IOpenGLShaderProgram> ShaderProg;
 
1948
 
 
1949
    if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
 
1950
    {
 
1951
      return;
 
1952
    }
 
1953
 
 
1954
    ShaderProg = _vertical_hq_gauss_filter_prog;
 
1955
 
 
1956
    CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
 
1957
    CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
 
1958
    ShaderProg->Begin ();
 
1959
 
 
1960
    int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
 
1961
    int WeightsLocation       = ShaderProg->GetUniformLocationARB ("W");
 
1962
    int TextureSizeLocation   = ShaderProg->GetUniformLocationARB ("TextureSize0");
 
1963
    int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
 
1964
    int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
 
1965
 
 
1966
 
 
1967
    SetTexture (GL_TEXTURE0, device_texture);
 
1968
 
 
1969
    CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
 
1970
 
 
1971
    sigma = Clamp <float> (sigma, 0.1f, 9.0f);
 
1972
    // Set the Gaussian weights
 
1973
    {
 
1974
      float *W;
 
1975
      GaussianWeights(&W, sigma, 55);
 
1976
      CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
 
1977
      delete(W);
 
1978
    }
 
1979
 
 
1980
    CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
 
1981
 
 
1982
    int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
 
1983
    ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
 
1984
 
 
1985
    CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
 
1986
    CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
 
1987
 
 
1988
    if (TextureCoord0Location != -1)
 
1989
    {
 
1990
      CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
 
1991
      CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
 
1992
    }
 
1993
 
 
1994
    CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
 
1995
 
 
1996
    CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
 
1997
 
 
1998
    if (TextureCoord0Location != -1)
 
1999
      CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
 
2000
 
 
2001
    ShaderProg->End();
 
2002
  }
 
2003
 
 
2004
 
 
2005
 
 
2006
 
 
2007
 
 
2008
 
 
2009
 
 
2010
 
 
2011
 
 
2012
 
 
2013
 
 
2014
 
 
2015
 
 
2016
 
 
2017
 
 
2018
 
 
2019
 
 
2020
 
1730
2021
 
1731
2022
  void GraphicsEngine::QRP_GLSL_ColorMatrix (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0,
1732
2023
    const Color &c0,
1809
2100
    int buffer_width, int buffer_height,
1810
2101
    ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
1811
2102
    const Color& c0,
1812
 
    float sigma)
 
2103
    float sigma, int num_pass)
1813
2104
  {
1814
2105
    //     _offscreen_color_rt0.Release ();
1815
2106
    //     _offscreen_color_rt1.Release ();
1819
2110
    int quad_width = device_texture->GetWidth ();
1820
2111
    int quad_height = device_texture->GetHeight ();
1821
2112
 
 
2113
    num_pass = Clamp<int> (num_pass, 1, 50);
 
2114
 
1822
2115
    ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGpuDevice ()->GetCurrentFrameBufferObject ();
1823
2116
    int previous_width = 0;
1824
2117
    int previous_height = 0;
1844
2137
 
1845
2138
    QRP_GLSL_1Tex(x, y, quad_width, quad_height, device_texture, texxform, Color::White);
1846
2139
 
1847
 
    for (int i = 0; i < 1; i++)
 
2140
    for (int i = 0; i < num_pass; i++)
1848
2141
    {
1849
2142
      SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, buffer_width, buffer_height);
1850
2143
      glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
2129
2422
    return _offscreen_color_rt3;
2130
2423
  }
2131
2424
 
 
2425
 
 
2426
  ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetHQBlur (
 
2427
    int x, int y,
 
2428
    int buffer_width, int buffer_height,
 
2429
    ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
 
2430
    const Color& c0,
 
2431
    float sigma, int num_pass)
 
2432
  {
 
2433
    //     _offscreen_color_rt0.Release ();
 
2434
    //     _offscreen_color_rt1.Release ();
 
2435
    //     _offscreen_depth_rt0.Release ();
 
2436
    //     _offscreen_depth_rt1.Release ();
 
2437
 
 
2438
    int quad_width = device_texture->GetWidth ();
 
2439
    int quad_height = device_texture->GetHeight ();
 
2440
 
 
2441
    num_pass = Clamp<int> (num_pass, 1, 50);
 
2442
 
 
2443
    ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGpuDevice ()->GetCurrentFrameBufferObject ();
 
2444
    int previous_width = 0;
 
2445
    int previous_height = 0;
 
2446
    if (prevFBO.IsValid ())
 
2447
    {
 
2448
      previous_width = prevFBO->GetWidth ();
 
2449
      previous_height = prevFBO->GetHeight ();
 
2450
    }
 
2451
    else
 
2452
    {
 
2453
      previous_width = _graphics_display.GetWindowWidth ();
 
2454
      previous_height = _graphics_display.GetWindowHeight ();
 
2455
    }
 
2456
 
 
2457
    CHECKGL (glClearColor (0, 0, 0, 0));
 
2458
    _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
 
2459
    _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
 
2460
    _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
 
2461
    _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
 
2462
 
 
2463
    SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
 
2464
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
2465
 
 
2466
    QRP_GLSL_1Tex(x, y, quad_width, quad_height, device_texture, texxform, Color::White);
 
2467
 
 
2468
    for (int i = 0; i < num_pass; i++)
 
2469
    {
 
2470
      SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, buffer_width, buffer_height);
 
2471
      glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
2472
      QRP_GLSL_HorizontalHQGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt0, texxform, c0, sigma);
 
2473
 
 
2474
      SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
 
2475
      glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
 
2476
      QRP_GLSL_VerticalHQGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt1, texxform, c0, sigma);
 
2477
    }
 
2478
 
 
2479
    _offscreen_fbo->Deactivate();
 
2480
 
 
2481
    if (prevFBO.IsValid ())
 
2482
    {
 
2483
      prevFBO->Activate(true);
 
2484
      SetContext(0, 0, previous_width, previous_height);
 
2485
      SetViewport(0, 0, previous_width, previous_height);
 
2486
      //Push2DWindow(previous_width, previous_height);
 
2487
    }
 
2488
    else
 
2489
    {
 
2490
      SetContext(0, 0, previous_width, previous_height);
 
2491
      SetViewport(0, 0, previous_width, previous_height);
 
2492
      //Push2DWindow(previous_width, previous_height);
 
2493
    }
 
2494
 
 
2495
    return _offscreen_color_rt0;
 
2496
  }
 
2497
 
 
2498
 
2132
2499
}
2133
2500