685
702
_vertical_gauss_filter_prog->Link();
705
void GraphicsEngine::InitSLHorizontalHQGaussFilter ()
707
ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
708
ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
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\
722
varyTexCoord0 = MyTextureCoord0; \n\
723
varyVertexColor = VertexColor; \n\
724
gl_Position = ViewProjectionMatrix * (AVertex); \n\
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\
735
return texture2D(TexObject, TexCoord.st); \n\
737
#define NUM_SAMPLES 55 \n\
738
uniform float W[NUM_SAMPLES]; \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\
748
sum += SampleTexture (TextureObject0, texCoord) * W[i]; \n\
749
texCoord += delta; \n\
751
gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w); \n\
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") );
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();
766
void GraphicsEngine::InitSLVerticalHQGaussFilter ()
768
ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
769
ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
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\
782
varyTexCoord0 = MyTextureCoord0; \n\
783
varyVertexColor = VertexColor; \n\
784
gl_Position = ViewProjectionMatrix * (AVertex); \n\
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\
795
return texture2D (TexObject, TexCoord.st); \n\
797
#define NUM_SAMPLES 55 \n\
798
uniform float W [NUM_SAMPLES]; \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\
808
sum += SampleTexture (TextureObject0, texCoord) * W[i]; \n\
809
texCoord += delta; \n\
811
gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w); \n\
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") );
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();
688
825
void GraphicsEngine::InitSLColorMatrixFilter ()
690
827
ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
1699
1836
// Set the Gaussian weights
1702
GaussianWeights(&W, sigma, 55);
1703
CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
1707
CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
1709
int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
1710
ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
1712
CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
1713
CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
1715
if (TextureCoord0Location != -1)
1717
CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
1718
CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
1721
CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
1723
CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
1725
if (TextureCoord0Location != -1)
1726
CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
1839
GaussianWeights(&W, sigma, 7);
1840
CHECKGL( glUniform1fv(WeightsLocation, 7, W) );
1844
CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
1846
int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
1847
ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
1849
CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
1850
CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
1852
if (TextureCoord0Location != -1)
1854
CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
1855
CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
1858
CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
1860
CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
1862
if (TextureCoord0Location != -1)
1863
CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
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)
1871
QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
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,
1880
ObjectPtr<IOpenGLShaderProgram> ShaderProg;
1882
if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
1887
ShaderProg = _horizontal_hq_gauss_filter_prog;
1889
CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
1890
CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
1891
ShaderProg->Begin ();
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");
1899
SetTexture (GL_TEXTURE0, device_texture);
1900
CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
1902
sigma = Clamp <float> (sigma, 0.1f, 9.0f);
1903
// Set the Gaussian weights
1906
GaussianWeights(&W, sigma, 55);
1907
CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
1911
CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
1913
int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
1914
ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
1916
CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
1917
CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
1919
if (TextureCoord0Location != -1)
1921
CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
1922
CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
1925
CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
1927
CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
1929
if (TextureCoord0Location != -1)
1930
CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
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)
1938
QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
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,
1947
ObjectPtr<IOpenGLShaderProgram> ShaderProg;
1949
if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
1954
ShaderProg = _vertical_hq_gauss_filter_prog;
1956
CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
1957
CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
1958
ShaderProg->Begin ();
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");
1967
SetTexture (GL_TEXTURE0, device_texture);
1969
CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
1971
sigma = Clamp <float> (sigma, 0.1f, 9.0f);
1972
// Set the Gaussian weights
1975
GaussianWeights(&W, sigma, 55);
1976
CHECKGL( glUniform1fv(WeightsLocation, 55, W) );
1980
CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
1982
int VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
1983
ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (GetModelViewProjectionMatrix().m));
1985
CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
1986
CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
1988
if (TextureCoord0Location != -1)
1990
CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
1991
CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
1994
CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
1996
CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
1998
if (TextureCoord0Location != -1)
1999
CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
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,
2129
2422
return _offscreen_color_rt3;
2426
ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetHQBlur (
2428
int buffer_width, int buffer_height,
2429
ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
2431
float sigma, int num_pass)
2433
// _offscreen_color_rt0.Release ();
2434
// _offscreen_color_rt1.Release ();
2435
// _offscreen_depth_rt0.Release ();
2436
// _offscreen_depth_rt1.Release ();
2438
int quad_width = device_texture->GetWidth ();
2439
int quad_height = device_texture->GetHeight ();
2441
num_pass = Clamp<int> (num_pass, 1, 50);
2443
ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGpuDevice ()->GetCurrentFrameBufferObject ();
2444
int previous_width = 0;
2445
int previous_height = 0;
2446
if (prevFBO.IsValid ())
2448
previous_width = prevFBO->GetWidth ();
2449
previous_height = prevFBO->GetHeight ();
2453
previous_width = _graphics_display.GetWindowWidth ();
2454
previous_height = _graphics_display.GetWindowHeight ();
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);
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);
2466
QRP_GLSL_1Tex(x, y, quad_width, quad_height, device_texture, texxform, Color::White);
2468
for (int i = 0; i < num_pass; i++)
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);
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);
2479
_offscreen_fbo->Deactivate();
2481
if (prevFBO.IsValid ())
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);
2490
SetContext(0, 0, previous_width, previous_height);
2491
SetViewport(0, 0, previous_width, previous_height);
2492
//Push2DWindow(previous_width, previous_height);
2495
return _offscreen_color_rt0;