nux-1.16.0
RenderingPipeGLSL.cpp
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 #include "NuxCore/NuxCore.h"
00023 #include "NuxImage/ImageSurface.h"
00024 #include "GpuDevice.h"
00025 #include "GLDeviceObjects.h"
00026 #include "GLResourceManager.h"
00027 #include "GLTextureResourceManager.h"
00028 #include "GLVertexResourceManager.h"
00029 #include "RenderingPipe.h"
00030 #include "GraphicsEngine.h"
00031 
00032 namespace nux
00033 {
00034 
00035 // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
00036 // other attributes. Otherwise you get a bug on NVidia! Why is that???
00037 // [Update]: it seems that the vertex attributes have to be declared in alphabetic order in the shader. It does not matter if the vertex
00038 // attribute is declared first in the alphabetic order.
00039 
00040 // For some other strange reason, on Intel GMA, the order in which attributes are used in the vertex shaders, is the order used to associated them with a
00041 // and attribute location. One has to make sure that the vertex attribute get index 0. So use the vertex attribute first. All of this does not make any sense.
00042 // Need more info from driver developers.
00043 
00044   void GraphicsEngine::InitSlColorShader()
00045   {
00046     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00047     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00048     NString VSString;
00049     NString PSString;
00050 
00051     VSString =  TEXT ("#version 110   \n\
00052                      uniform mat4 ViewProjectionMatrix;                 \n\
00053                      attribute vec4 AVertex;                            \n\
00054                      attribute vec4 VertexColor;                        \n\
00055                      void main()                                        \n\
00056                      {                                                  \n\
00057                          gl_Position = ViewProjectionMatrix * AVertex;  \n\
00058                          gl_FrontColor = VertexColor;                   \n\
00059                      }");
00060 
00061     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00062 
00063     PSString =  TEXT ("#version 110                  \n\
00064                      void main()                    \n\
00065                      {                              \n\
00066                          gl_FragColor = gl_Color;   \n\
00067                      }");
00068     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString) );
00069 
00070     m_SlColor = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00071     m_SlColor->ClearShaderObjects();
00072     m_SlColor->AddShaderObject (VS);
00073     m_SlColor->AddShaderObject (PS);
00074     m_SlColor->Link();
00075   }
00076 
00077   void GraphicsEngine::InitSlTextureShader()
00078   {
00079     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00080     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00081     NString VSString;
00082     NString PSString;
00083 
00084     VSString =  TEXT ("#version 110   \n\
00085                      attribute vec4 AVertex;                                 \n\
00086                      attribute vec4 MyTextureCoord0;                         \n\
00087                      attribute vec4 VertexColor;                             \n\
00088                      uniform mat4 ViewProjectionMatrix;                      \n\
00089                      varying vec4 varyTexCoord0;                             \n\
00090                      varying vec4 varyVertexColor;                           \n\
00091                      void main()                                             \n\
00092                      {                                                       \n\
00093                      gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
00094                      varyTexCoord0 = MyTextureCoord0;                        \n\
00095                      varyVertexColor = VertexColor;                          \n\
00096                      }");
00097 
00098     PSString =  TEXT ("#version 110                                               \n\
00099                      #extension GL_ARB_texture_rectangle : enable                \n\
00100                      varying vec4 varyTexCoord0;                                 \n\
00101                      varying vec4 varyVertexColor;                               \n\
00102                      #ifdef SAMPLERTEX2D                                         \n\
00103                      uniform sampler2D TextureObject0;                           \n\
00104                      vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
00105                      {                                                           \n\
00106                      return texture2D(TexObject, TexCoord.st);                   \n\
00107                      }                                                           \n\
00108                      #elif defined SAMPLERTEX2DRECT                              \n\
00109                      uniform sampler2DRect TextureObject0;                       \n\
00110                      vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
00111                      {                                                           \n\
00112                      return texture2DRect(TexObject, TexCoord.st);               \n\
00113                      }                                                           \n\
00114                      #endif                                                      \n\
00115                      void main()                                                 \n\
00116                      {                                                           \n\
00117                      vec4 v = SampleTexture(TextureObject0, varyTexCoord0);      \n\
00118                      gl_FragColor = v*varyVertexColor;                           \n\
00119                      }");
00120 
00121     // Textured 2D Primitive Shader
00122     m_SlTextureModColor = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00123     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00124     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00125 
00126     m_SlTextureModColor->ClearShaderObjects();
00127     m_SlTextureModColor->AddShaderObject (VS);
00128     m_SlTextureModColor->AddShaderObject (PS);
00129     CHECKGL ( glBindAttribLocation (m_SlTextureModColor->GetOpenGLID(), 0, "AVertex") );
00130     m_SlTextureModColor->Link();
00131   }
00132 
00133   void GraphicsEngine::InitSlColorModTexMaskAlpha()
00134   {
00135     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00136     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00137     NString VSString;
00138     NString PSString;
00139 
00140     VSString =  TEXT ("#version 110   \n\
00141                      attribute vec4 AVertex;                                 \n\
00142                      attribute vec4 MyTextureCoord0;                         \n\
00143                      attribute vec4 VertexColor;                             \n\
00144                      uniform mat4 ViewProjectionMatrix;                      \n\
00145                      varying vec4 varyTexCoord0;                             \n\
00146                      varying vec4 varyVertexColor;                           \n\
00147                      void main()                                             \n\
00148                      {                                                       \n\
00149                      gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
00150                      varyTexCoord0 = MyTextureCoord0;                        \n\
00151                      varyVertexColor = VertexColor;                          \n\
00152                      }");
00153 
00154     PSString =  TEXT ("#version 110                                                      \n\
00155                      #extension GL_ARB_texture_rectangle : enable                       \n\
00156                      varying vec4 varyTexCoord0;                                        \n\
00157                      varying vec4 varyVertexColor;                                      \n\
00158                      #ifdef SAMPLERTEX2D                                                \n\
00159                      uniform sampler2D TextureObject0;                                  \n\
00160                      vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)             \n\
00161                      {                                                                  \n\
00162                      return texture2D(TexObject, TexCoord.st);                          \n\
00163                      }                                                                  \n\
00164                      #elif defined SAMPLERTEX2DRECT                                     \n\
00165                      uniform sampler2DRect TextureObject0;                              \n\
00166                      vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)         \n\
00167                      {                                                                  \n\
00168                      return texture2DRect(TexObject, TexCoord.st);                      \n\
00169                      }                                                                  \n\
00170                      #endif                                                             \n\
00171                      void main()                                                        \n\
00172                      {                                                                  \n\
00173                      float alpha = SampleTexture(TextureObject0, varyTexCoord0).w;      \n\
00174                      gl_FragColor = vec4(varyVertexColor.xyz, alpha*varyVertexColor.a); \n\
00175                      }");
00176 
00177     m_SlColorModTexMaskAlpha = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00178     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00179     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00180     m_SlColorModTexMaskAlpha->ClearShaderObjects();
00181     m_SlColorModTexMaskAlpha->AddShaderObject (VS);
00182     m_SlColorModTexMaskAlpha->AddShaderObject (PS);
00183     CHECKGL ( glBindAttribLocation (m_SlColorModTexMaskAlpha->GetOpenGLID(), 0, "AVertex") );
00184     CHECKGL ( glBindAttribLocation (m_SlColorModTexMaskAlpha->GetOpenGLID(), 1, "MyTextureCoord0") );
00185     CHECKGL ( glBindAttribLocation (m_SlColorModTexMaskAlpha->GetOpenGLID(), 2, "VectexColor") );
00186     m_SlColorModTexMaskAlpha->Link();
00187 
00188     m_SlColorModTexRectMaskAlpha = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00189     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00190     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2DRECT") );
00191     m_SlColorModTexRectMaskAlpha->ClearShaderObjects();
00192     m_SlColorModTexRectMaskAlpha->AddShaderObject (VS);
00193     m_SlColorModTexRectMaskAlpha->AddShaderObject (PS);
00194     CHECKGL ( glBindAttribLocation (m_SlColorModTexRectMaskAlpha->GetOpenGLID(), 0, "AVertex") );
00195     CHECKGL ( glBindAttribLocation (m_SlColorModTexRectMaskAlpha->GetOpenGLID(), 1, "MyTextureCoord0") );
00196     CHECKGL ( glBindAttribLocation (m_SlColorModTexRectMaskAlpha->GetOpenGLID(), 2, "VectexColor") );
00197     m_SlColorModTexRectMaskAlpha->Link();
00198   }
00199 
00200   void GraphicsEngine::InitSl2TextureAdd()
00201   {
00202     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00203     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00204     NString VSString;
00205     NString PSString;
00206 
00207     // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
00208     // other  attributes. Otherwise you get a bug on NVidia! Why is that???
00209 
00211     VSString =  TEXT (  "#version 110                                           \n\
00212                         uniform mat4 ViewProjectionMatrix;                      \n\
00213                         attribute vec4 AVertex;                                 \n\
00214                         attribute vec4 MyTextureCoord0;                         \n\
00215                         attribute vec4 MyTextureCoord1;                         \n\
00216                         varying vec4 varyTexCoord0;                             \n\
00217                         varying vec4 varyTexCoord1;                             \n\
00218                         void main()                                             \n\
00219                         {                                                       \n\
00220                         varyTexCoord0 = MyTextureCoord0;                        \n\
00221                         varyTexCoord1 = MyTextureCoord1;                        \n\
00222                         gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
00223                         }");
00224 
00225     PSString =  TEXT (  "#version 110                                               \n\
00226                         #extension GL_ARB_texture_rectangle : enable                \n\
00227                         varying vec4 varyTexCoord0;                                 \n\
00228                         varying vec4 varyTexCoord1;                                 \n\
00229                         uniform vec4 color0;                                        \n\
00230                         uniform vec4 color1;                                        \n\
00231                         #ifdef SAMPLERTEX2D                                         \n\
00232                         uniform sampler2D TextureObject0;                           \n\
00233                         uniform sampler2D TextureObject1;                           \n\
00234                         vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
00235                         {                                                           \n\
00236                         return texture2D(TexObject, TexCoord.st);                   \n\
00237                         }                                                           \n\
00238                         #elif defined SAMPLERTEX2DRECT                              \n\
00239                         uniform sampler2DRect TextureObject0;                       \n\
00240                         uniform sampler2DRect TextureObject1;                       \n\
00241                         vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
00242                         {                                                           \n\
00243                         return texture2DRect(TexObject, TexCoord.st);               \n\
00244                         }                                                           \n\
00245                         #endif                                                      \n\
00246                         void main()                                                 \n\
00247                         {                                                           \n\
00248                         vec4 b0 = color0*SampleTexture(TextureObject0, varyTexCoord0);     \n\
00249                         vec4 b1 = color1*SampleTexture(TextureObject1, varyTexCoord1);     \n\
00250                         gl_FragColor = b0 + b1;                                             \n\
00251                         }");
00252 
00253     m_Sl2TextureAdd = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00254     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00255     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00256 
00257     m_Sl2TextureAdd->ClearShaderObjects();
00258     m_Sl2TextureAdd->AddShaderObject (VS);
00259     m_Sl2TextureAdd->AddShaderObject (PS);
00260     CHECKGL ( glBindAttribLocation (m_Sl2TextureAdd->GetOpenGLID(), 0, "AVertex") );
00261     m_Sl2TextureAdd->Link();
00262   }
00263 
00264   void GraphicsEngine::InitSl2TextureDepRead()
00265   {
00266     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00267     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00268     NString VSString;
00269     NString PSString;
00270 
00271     // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
00272     // other  attributes. Otherwise you get a bug on NVidia! Why is that???
00273 
00275     VSString =  TEXT (  "#version 110                                           \n\
00276                         uniform mat4 ViewProjectionMatrix;                      \n\
00277                         attribute vec4 AVertex;                                 \n\
00278                         attribute vec4 MyTextureCoord0;                         \n\
00279                         attribute vec4 MyTextureCoord1;                         \n\
00280                         varying vec4 varyTexCoord0;                             \n\
00281                         varying vec4 varyTexCoord1;                             \n\
00282                         void main()                                             \n\
00283                         {                                                       \n\
00284                         varyTexCoord0 = MyTextureCoord0;                        \n\
00285                         varyTexCoord1 = MyTextureCoord1;                        \n\
00286                         gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
00287                         }");
00288 
00289     PSString =  TEXT (  "#version 110                                               \n\
00290                         varying vec4 varyTexCoord0;                                 \n\
00291                         varying vec4 varyTexCoord1;                                 \n\
00292                         uniform vec4 color0;                                        \n\
00293                         uniform vec4 color1;                                        \n\
00294                         uniform sampler2D TextureObject0;                           \n\
00295                         uniform sampler2D TextureObject1;                           \n\
00296                         vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
00297                         {                                                           \n\
00298                           return texture2D(TexObject, TexCoord.st);                 \n\
00299                         }                                                           \n\
00300                         void main()                                                 \n\
00301                         {                                                           \n\
00302                           vec4 noise = SampleTexture (TextureObject0, varyTexCoord0); \n\
00303                           vec4 noise_bx2 = color0 * (2.0 * noise - vec4 (1.0, 1.0, 1.0, 1.0));     \n\
00304                           vec4 b1 = color1 * SampleTexture(TextureObject1, varyTexCoord1 + noise_bx2);     \n\
00305                           gl_FragColor = b1;                                          \n\
00306                         }");
00307 
00308     m_Sl2TextureDepRead = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00309     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00310     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString) );
00311 
00312     m_Sl2TextureDepRead->ClearShaderObjects();
00313     m_Sl2TextureDepRead->AddShaderObject (VS);
00314     m_Sl2TextureDepRead->AddShaderObject (PS);
00315     CHECKGL ( glBindAttribLocation (m_Sl2TextureDepRead->GetOpenGLID(), 0, "AVertex") );
00316     m_Sl2TextureDepRead->Link();
00317   }
00318 
00319   void GraphicsEngine::InitSl2TextureMod()
00320   {
00321     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00322     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00323     NString VSString;
00324     NString PSString;
00325 
00326     // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
00327     // other  attributes. Otherwise you get a bug on NVidia! Why is that???
00328 
00330     VSString =  TEXT (   "#version 110                                           \n\
00331                          uniform mat4 ViewProjectionMatrix;                      \n\
00332                          attribute vec4 AVertex;                                 \n\
00333                          attribute vec4 MyTextureCoord0;                         \n\
00334                          attribute vec4 MyTextureCoord1;                         \n\
00335                          varying vec4 varyTexCoord0;                             \n\
00336                          varying vec4 varyTexCoord1;                             \n\
00337                          void main()                                             \n\
00338                          {                                                       \n\
00339                          varyTexCoord0 = MyTextureCoord0;                        \n\
00340                          varyTexCoord1 = MyTextureCoord1;                        \n\
00341                          gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
00342                          }");
00343 
00344     PSString =  TEXT (   "#version 110                                               \n\
00345                          #extension GL_ARB_texture_rectangle : enable                \n\
00346                          varying vec4 varyTexCoord0;                                 \n\
00347                          varying vec4 varyTexCoord1;                                 \n\
00348                          uniform vec4 color0;                                        \n\
00349                          uniform vec4 color1;                                        \n\
00350                          #ifdef SAMPLERTEX2D                                         \n\
00351                          uniform sampler2D TextureObject0;                           \n\
00352                          uniform sampler2D TextureObject1;                           \n\
00353                          vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
00354                          {                                                           \n\
00355                          return texture2D(TexObject, TexCoord.st);                   \n\
00356                          }                                                           \n\
00357                          #elif defined SAMPLERTEX2DRECT                              \n\
00358                          uniform sampler2DRect TextureObject0;                       \n\
00359                          uniform sampler2DRect TextureObject1;                       \n\
00360                          vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
00361                          {                                                           \n\
00362                          return texture2DRect(TexObject, TexCoord.st);               \n\
00363                          }                                                           \n\
00364                          #endif                                                      \n\
00365                          void main()                                                 \n\
00366                          {                                                           \n\
00367                          vec4 b0 = color0*SampleTexture(TextureObject0, varyTexCoord0);     \n\
00368                          vec4 b1 = color1*SampleTexture(TextureObject1, varyTexCoord1);     \n\
00369                          gl_FragColor = b0 * b1;                                            \n\
00370                          }");
00371 
00372     m_Sl2TextureMod = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00373     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00374     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00375 
00376     m_Sl2TextureMod->ClearShaderObjects();
00377     m_Sl2TextureMod->AddShaderObject (VS);
00378     m_Sl2TextureMod->AddShaderObject (PS);
00379     CHECKGL ( glBindAttribLocation (m_Sl2TextureMod->GetOpenGLID(), 0, "AVertex") );
00380     m_Sl2TextureMod->Link();
00381   }
00382 
00383   void GraphicsEngine::InitSl4TextureAdd()
00384   {
00385     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00386     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00387     NString VSString;
00388     NString PSString;
00389 
00390     // For some strange reason, make sure that the attribute holding the vertex position has a name that comes first in alphabetic order before all
00391     // other  attributes. Otherwise you get a bug on NVidia! Why is that???
00392 
00394     VSString =  TEXT (   "#version 110                                          \n\
00395                         uniform mat4 ViewProjectionMatrix;                      \n\
00396                         attribute vec4 AVertex;                                 \n\
00397                         attribute vec4 MyTextureCoord0;                         \n\
00398                         attribute vec4 MyTextureCoord1;                         \n\
00399                         attribute vec4 MyTextureCoord2;                         \n\
00400                         attribute vec4 MyTextureCoord3;                         \n\
00401                         varying vec4 varyTexCoord0;                             \n\
00402                         varying vec4 varyTexCoord1;                             \n\
00403                         varying vec4 varyTexCoord2;                             \n\
00404                         varying vec4 varyTexCoord3;                             \n\
00405                         void main()                                             \n\
00406                         {                                                       \n\
00407                         varyTexCoord0 = MyTextureCoord0;                        \n\
00408                         varyTexCoord1 = MyTextureCoord1;                        \n\
00409                         varyTexCoord2 = MyTextureCoord2;                        \n\
00410                         varyTexCoord3 = MyTextureCoord3;                        \n\
00411                         gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
00412                         }");
00413 
00414     PSString =  TEXT (   "#version 110                                              \n\
00415                         #extension GL_ARB_texture_rectangle : enable                \n\
00416                         varying vec4 varyTexCoord0;                                 \n\
00417                         varying vec4 varyTexCoord1;                                 \n\
00418                         varying vec4 varyTexCoord2;                                 \n\
00419                         varying vec4 varyTexCoord3;                                 \n\
00420                         uniform vec4 color0;                                        \n\
00421                         uniform vec4 color1;                                        \n\
00422                         uniform vec4 color2;                                        \n\
00423                         uniform vec4 color3;                                        \n\
00424                         uniform sampler2D TextureObject0;                           \n\
00425                         uniform sampler2D TextureObject1;                           \n\
00426                         uniform sampler2D TextureObject2;                           \n\
00427                         uniform sampler2D TextureObject3;                           \n\
00428                         vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
00429                         {                                                           \n\
00430                         return texture2D(TexObject, TexCoord.st);                   \n\
00431                         }                                                           \n\
00432                         void main()                                                 \n\
00433                         {                                                           \n\
00434                           vec4 b0 = color0*SampleTexture(TextureObject0, varyTexCoord0);  \n\
00435                           vec4 b1 = color1*SampleTexture(TextureObject1, varyTexCoord1);  \n\
00436                           vec4 b2 = color2*SampleTexture(TextureObject2, varyTexCoord2);  \n\
00437                           vec4 b3 = color3*SampleTexture(TextureObject3, varyTexCoord3);  \n\
00438                           gl_FragColor = b0+b1+b2+b3;                                     \n\
00439                         }");
00440 
00441     //vec4(v.w, v.w, v.w, v.w)
00442 
00443     // Textured 2D Primitive Shader
00444     m_Sl4TextureAdd = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00445     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00446     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString) );
00447 
00448     m_Sl4TextureAdd->ClearShaderObjects();
00449     m_Sl4TextureAdd->AddShaderObject (VS);
00450     m_Sl4TextureAdd->AddShaderObject (PS);
00451     CHECKGL ( glBindAttribLocation (m_Sl4TextureAdd->GetOpenGLID(), 0, "AVertex") );
00452     m_Sl4TextureAdd->Link();
00453 
00454 //     // Textured Rect Primitive Shader
00455 //     m_4TexBlendRectProg = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00456 //     VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
00457 //     PS->SetShaderCode(TCHAR_TO_ANSI(*PSString), TEXT("#define SAMPLERTEX2DRECT"));
00458 //     m_4TexBlendRectProg->ClearShaderObjects();
00459 //     m_4TexBlendRectProg->AddShaderObject(VS);
00460 //     m_4TexBlendRectProg->AddShaderObject(PS);
00461 //     CHECKGL( glBindAttribLocation(m_4TexBlendRectProg->GetOpenGLID(), 0, "AVertex") );
00462 //     m_4TexBlendRectProg->Link();
00463   }
00464 
00465   void GraphicsEngine::InitSLPower ()
00466   {
00467     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00468     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00469     NString VSString;
00470     NString PSString;
00471 
00472     VSString =  TEXT ("#version 110                         \n\
00473         uniform mat4 ViewProjectionMatrix;                  \n\
00474         attribute vec4 AVertex;                             \n\
00475         attribute vec4 MyTextureCoord0;                     \n\
00476         varying vec4 varyTexCoord0;                         \n\
00477         void main()                                         \n\
00478         {                                                   \n\
00479           varyTexCoord0 = MyTextureCoord0;                  \n\
00480           gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00481         }");
00482 
00483     PSString =  TEXT ("#version 110                                                                           \n\
00484         varying vec4 varyTexCoord0;                                                                           \n\
00485         uniform sampler2D TextureObject0;                                                                     \n\
00486         uniform vec2 TextureSize0;                                                                            \n\
00487         uniform vec4 exponent;                                                                                \n\
00488         uniform vec4 color0;                                                                                  \n\
00489         vec4 SampleTexture(sampler2D TexObject, vec2 TexCoord)                                                \n\
00490         {                                                                                                     \n\
00491           return texture2D(TexObject, TexCoord.st);                                                           \n\
00492         }                                                                                                     \n\
00493         void main (void)                                                                                      \n\
00494         {                                                                                                           \n\
00495           vec4 TexColor = SampleTexture(TextureObject0, varyTexCoord0.st);                                    \n\
00496           vec4 result = pow(TexColor, exponent);                                                              \n\
00497           gl_FragColor = color0*result;                                                                       \n\
00498         }");
00499 
00500 
00501     _component_exponentiation_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00502     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString));
00503     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString));
00504 
00505     _component_exponentiation_prog->ClearShaderObjects();
00506     _component_exponentiation_prog->AddShaderObject (VS);
00507     _component_exponentiation_prog->AddShaderObject (PS);
00508     CHECKGL ( glBindAttribLocation (_component_exponentiation_prog->GetOpenGLID(), 0, "AVertex") );
00509     _component_exponentiation_prog->Link();
00510 
00511   }
00512 
00513   void GraphicsEngine::InitSLAlphaReplicate ()
00514   {
00515     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00516     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00517     NString VSString;
00518     NString PSString;
00519 
00520 
00521     VSString = TEXT ("#version 110                          \n\
00522         uniform mat4 ViewProjectionMatrix;                  \n\
00523         attribute vec4 AVertex;                             \n\
00524         attribute vec4 MyTextureCoord0;                     \n\
00525         varying vec4 varyTexCoord0;                         \n\
00526         void main()                                         \n\
00527         {                                                   \n\
00528           varyTexCoord0 = MyTextureCoord0;                  \n\
00529           gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00530         }");
00531 
00532     PSString = TEXT ("#version 110                                    \n\
00533         varying vec4 varyTexCoord0;                                   \n\
00534         uniform sampler2D TextureObject0;                             \n\
00535         uniform vec4 color0;                                          \n\
00536         vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)        \n\
00537         {                                                             \n\
00538           return texture2D(TexObject, TexCoord.st);                   \n\
00539         }                                                             \n\
00540         void main ()                                                  \n\
00541         {                                                             \n\
00542           vec4 v = SampleTexture(TextureObject0, varyTexCoord0);      \n\
00543           gl_FragColor = vec4(v.a, v.a, v.a, v.a) * color0;           \n\
00544         }");
00545 
00546     _alpha_replicate_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram ();
00547     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString));
00548     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString));
00549 
00550     _alpha_replicate_prog->ClearShaderObjects ();
00551     _alpha_replicate_prog->AddShaderObject (VS);
00552     _alpha_replicate_prog->AddShaderObject (PS);
00553     CHECKGL ( glBindAttribLocation (_alpha_replicate_prog->GetOpenGLID(), 0, "AVertex"));
00554     _alpha_replicate_prog->Link();
00555   }
00556 
00557   void GraphicsEngine::InitSLHorizontalGaussFilter ()
00558   {
00559     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00560     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00561     NString VSString;
00562     NString PSString;
00563 
00564 
00565     VSString = TEXT ("#version 120          \n\
00566         uniform mat4 ViewProjectionMatrix;  \n\
00567         attribute vec4 AVertex;             \n\
00568         attribute vec4 MyTextureCoord0;     \n\
00569         attribute vec4 VertexColor;         \n\
00570         varying vec4 varyTexCoord0;         \n\
00571         varying vec4 varyVertexColor;       \n\
00572         void main()                         \n\
00573         {                                   \n\
00574           varyTexCoord0 = MyTextureCoord0;  \n\
00575           varyVertexColor = VertexColor;    \n\
00576           gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00577         }");
00578 
00579 
00580     PSString = TEXT ("#version 120                                    \n\
00581         varying vec4 varyTexCoord0;                                   \n\
00582         varying vec4 varyVertexColor;                                 \n\
00583         uniform sampler2D TextureObject0;                             \n\
00584         uniform vec2 TextureSize0;                                    \n\
00585         vec4 SampleTexture(sampler2D TexObject, vec2 TexCoord)        \n\
00586         {                                                             \n\
00587           return texture2D(TexObject, TexCoord.st);                   \n\
00588         }                                                             \n\
00589         #define NUM_SAMPLES 7                                         \n\
00590         uniform float W[NUM_SAMPLES];                                 \n\
00591         void main()                                                   \n\
00592         {                                                             \n\
00593           vec4 sum   = vec4 (0.0, 0.0, 0.0, 0.0);                     \n\
00594           vec2 delta = vec2 (1.0 / TextureSize0.x, 0.0);              \n\
00595           vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);    \n\
00596           texCoord.x -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.x;     \n\
00597           texCoord.y += 0.0 / TextureSize0.y;                         \n\
00598           sum += SampleTexture (TextureObject0, texCoord) * W[0];     \n\
00599           texCoord += delta;                                          \n\
00600           sum += SampleTexture (TextureObject0, texCoord) * W[1];     \n\
00601           texCoord += delta;                                          \n\
00602           sum += SampleTexture (TextureObject0, texCoord) * W[2];     \n\
00603           texCoord += delta;                                          \n\
00604           sum += SampleTexture (TextureObject0, texCoord) * W[3];     \n\
00605           texCoord += delta;                                          \n\
00606           sum += SampleTexture (TextureObject0, texCoord) * W[4];     \n\
00607           texCoord += delta;                                          \n\
00608           sum += SampleTexture (TextureObject0, texCoord) * W[5];     \n\
00609           texCoord += delta;                                          \n\
00610           sum += SampleTexture (TextureObject0, texCoord) * W[6];     \n\
00611           texCoord += delta;                                          \n\
00612           gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w);           \n\
00613         }");
00614 
00615     _horizontal_gauss_filter_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00616     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00617     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00618 
00619     _horizontal_gauss_filter_prog->ClearShaderObjects();
00620     _horizontal_gauss_filter_prog->AddShaderObject (VS);
00621     _horizontal_gauss_filter_prog->AddShaderObject (PS);
00622     CHECKGL ( glBindAttribLocation (_horizontal_gauss_filter_prog->GetOpenGLID(), 0, "AVertex") );
00623     _horizontal_gauss_filter_prog->Link();
00624 
00625   }
00626   
00627   void GraphicsEngine::InitSLVerticalGaussFilter ()
00628   {
00629     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00630     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00631     NString VSString;
00632     NString PSString;
00633 
00634     VSString = TEXT ("#version 110          \n\
00635         uniform mat4 ViewProjectionMatrix;  \n\
00636         attribute vec4 AVertex;             \n\
00637         attribute vec4 MyTextureCoord0;     \n\
00638         attribute vec4 VertexColor;         \n\
00639         varying vec4 varyTexCoord0;         \n\
00640         varying vec4 varyVertexColor;       \n\
00641         void main()                         \n\
00642         {                                   \n\
00643           varyTexCoord0 = MyTextureCoord0;  \n\
00644           varyVertexColor = VertexColor;    \n\
00645         gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00646         }");
00647 
00648 
00649     PSString = TEXT ("#version 120                                    \n\
00650         varying vec4 varyTexCoord0;                                   \n\
00651         varying vec4 varyVertexColor;                                 \n\
00652         uniform sampler2D TextureObject0;                             \n\
00653         uniform vec2 TextureSize0;                                    \n\
00654         vec4 SampleTexture (sampler2D TexObject, vec2 TexCoord)       \n\
00655         {                                                             \n\
00656           return texture2D (TexObject, TexCoord.st);                  \n\
00657         }                                                             \n\
00658         #define NUM_SAMPLES 7                                         \n\
00659         uniform float W [NUM_SAMPLES];                                \n\
00660         void main ()                                                  \n\
00661         {                                                             \n\
00662           vec4 sum   = vec4 (0.0, 0.0, 0.0, 0.0);                     \n\
00663           vec2 delta = vec2 (0.0, 1.0 / TextureSize0.y);              \n\
00664           vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);    \n\
00665           texCoord.x += 0.0 / TextureSize0.x;                         \n\
00666           texCoord.y -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.y;     \n\
00667           sum += SampleTexture (TextureObject0, texCoord) * W[0];     \n\
00668           texCoord += delta;                                          \n\
00669           sum += SampleTexture (TextureObject0, texCoord) * W[1];     \n\
00670           texCoord += delta;                                          \n\
00671           sum += SampleTexture (TextureObject0, texCoord) * W[2];     \n\
00672           texCoord += delta;                                          \n\
00673           sum += SampleTexture (TextureObject0, texCoord) * W[3];     \n\
00674           texCoord += delta;                                          \n\
00675           sum += SampleTexture (TextureObject0, texCoord) * W[4];     \n\
00676           texCoord += delta;                                          \n\
00677           sum += SampleTexture (TextureObject0, texCoord) * W[5];     \n\
00678           texCoord += delta;                                          \n\
00679           sum += SampleTexture (TextureObject0, texCoord) * W[6];     \n\
00680           texCoord += delta;                                          \n\
00681           gl_FragColor = vec4 (sum.x, sum.y, sum.z, sum.w);           \n\
00682         }");
00683 
00684     _vertical_gauss_filter_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00685     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00686     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00687 
00688     _vertical_gauss_filter_prog->ClearShaderObjects();
00689     _vertical_gauss_filter_prog->AddShaderObject (VS);
00690     _vertical_gauss_filter_prog->AddShaderObject (PS);
00691     CHECKGL ( glBindAttribLocation (_vertical_gauss_filter_prog->GetOpenGLID(), 0, "AVertex") );
00692     _vertical_gauss_filter_prog->Link();
00693   }
00694   
00695   void GraphicsEngine::InitSLHorizontalHQGaussFilter(int sigma)
00696   {
00697     int k = Clamp<int>(sigma, NUX_MIN_GAUSSIAN_SIGMA, NUX_MAX_GAUSSIAN_SIGMA);
00698     if (_horizontal_hq_gauss_filter_prog[k-1].IsValid())
00699     {
00700       // Shader program already compiled
00701       return;
00702     }
00703 
00704     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00705     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00706     NString VSString;
00707     NString PSString;
00708 
00709 
00710     VSString = TEXT ("#version 120                        \n\
00711                      uniform mat4 ViewProjectionMatrix;   \n\
00712                      attribute vec4 AVertex;              \n\
00713                      attribute vec4 MyTextureCoord0;      \n\
00714                      attribute vec4 VertexColor;          \n\
00715                      varying vec4 varyTexCoord0;          \n\
00716                      varying vec4 varyVertexColor;        \n\
00717                      void main()                          \n\
00718                      {                                    \n\
00719                      varyTexCoord0 = MyTextureCoord0;     \n\
00720                      varyVertexColor = VertexColor;       \n\
00721                      gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00722                      }");
00723 
00724 
00725     PSString = TEXT ("#version 120                                                \n\
00726                      varying vec4 varyTexCoord0;                                  \n\
00727                      varying vec4 varyVertexColor;                                \n\
00728                      uniform sampler2D TextureObject0;                            \n\
00729                      uniform vec2 TextureSize0;                                   \n\
00730                      vec4 SampleTexture(sampler2D TexObject, vec2 TexCoord)       \n\
00731                      {                                                            \n\
00732                      return texture2D(TexObject, TexCoord.st);                    \n\
00733                      }                                                            \n\
00734                      #define NUM_SAMPLES %d                                       \n\
00735                      uniform float W[NUM_SAMPLES];                                \n\
00736                      void main()                                                  \n\
00737                      {                                                            \n\
00738                      vec4 sum   = vec4(0.0, 0.0, 0.0, 0.0);                       \n\
00739                      vec2 delta = vec2(1.0 / TextureSize0.x, 0.0);                \n\
00740                      vec2 texCoord = vec2(varyTexCoord0.s, varyTexCoord0.t);      \n\
00741                      texCoord.x -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.x;      \n\
00742                      texCoord.y += 0.0 / TextureSize0.y;                          \n\
00743                      for(int i = 0; i < NUM_SAMPLES; i++)                         \n\
00744                      {                                                            \n\
00745                      sum += SampleTexture(TextureObject0, texCoord) * W[i];       \n\
00746                      texCoord += delta;                                           \n\
00747                      }                                                            \n\
00748                      gl_FragColor = vec4(sum.x, sum.y, sum.z, 1.0);             \n\
00749                      }");
00750 
00751     int l = PSString.Size();
00752     char* shader_prog = new char[l+10];
00753     sprintf(shader_prog, PSString.GetTCharPtr(), 6 * k + 1);
00754 
00755     _horizontal_hq_gauss_filter_prog[k-1] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00756     VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
00757     PS->SetShaderCode(shader_prog, TEXT ("#define SAMPLERTEX2D"));
00758     delete [] shader_prog;
00759 
00760     _horizontal_hq_gauss_filter_prog[k-1]->ClearShaderObjects();
00761     _horizontal_hq_gauss_filter_prog[k-1]->AddShaderObject(VS);
00762     _horizontal_hq_gauss_filter_prog[k-1]->AddShaderObject(PS);
00763     CHECKGL(glBindAttribLocation(_horizontal_hq_gauss_filter_prog[k-1]->GetOpenGLID(), 0, "AVertex"));
00764     _horizontal_hq_gauss_filter_prog[k-1]->Link();
00765 
00766   }
00767 
00768   void GraphicsEngine::InitSLVerticalHQGaussFilter(int sigma)
00769   {
00770     int k = Clamp<int>(sigma, NUX_MIN_GAUSSIAN_SIGMA, NUX_MAX_GAUSSIAN_SIGMA);
00771     if (_vertical_hq_gauss_filter_prog[k-1].IsValid())
00772     {
00773       // Shader program already compiled
00774       return;
00775     }
00776 
00777     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00778     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00779     NString VSString;
00780     NString PSString;
00781 
00782     VSString = TEXT ("#version 110                        \n\
00783                      uniform mat4 ViewProjectionMatrix;   \n\
00784                      attribute vec4 AVertex;              \n\
00785                      attribute vec4 MyTextureCoord0;      \n\
00786                      attribute vec4 VertexColor;          \n\
00787                      varying vec4 varyTexCoord0;          \n\
00788                      varying vec4 varyVertexColor;        \n\
00789                      void main()                          \n\
00790                      {                                    \n\
00791                      varyTexCoord0 = MyTextureCoord0;     \n\
00792                      varyVertexColor = VertexColor;       \n\
00793                      gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00794                      }");
00795 
00796 
00797     PSString = TEXT ("#version 120                                                \n\
00798                      varying vec4 varyTexCoord0;                                  \n\
00799                      varying vec4 varyVertexColor;                                \n\
00800                      uniform sampler2D TextureObject0;                            \n\
00801                      uniform vec2 TextureSize0;                                   \n\
00802                      vec4 SampleTexture (sampler2D TexObject, vec2 TexCoord)      \n\
00803                      {                                                            \n\
00804                      return texture2D (TexObject, TexCoord.st);                   \n\
00805                      }                                                            \n\
00806                      #define NUM_SAMPLES %d                                       \n\
00807                      uniform float W [NUM_SAMPLES];                               \n\
00808                      void main ()                                                 \n\
00809                      {                                                            \n\
00810                      vec4 sum   = vec4 (0.0, 0.0, 0.0, 0.0);                      \n\
00811                      vec2 delta = vec2 (0.0, 1.0 / TextureSize0.y);               \n\
00812                      vec2 texCoord = vec2 (varyTexCoord0.s, varyTexCoord0.t);     \n\
00813                      texCoord.x += 0.0 / TextureSize0.x;                          \n\
00814                      texCoord.y -= ((NUM_SAMPLES - 1) / 2) / TextureSize0.y;      \n\
00815                      for (int i = 0; i < NUM_SAMPLES; ++i)                        \n\
00816                      {                                                            \n\
00817                      sum += SampleTexture (TextureObject0, texCoord) * W[i];      \n\
00818                      texCoord += delta;                                           \n\
00819                      }                                                            \n\
00820                      gl_FragColor = vec4 (sum.x, sum.y, sum.z, 1.0);            \n\
00821                      }");
00822 
00823     int l = PSString.Size();
00824     char* shader_prog = new char[l+10];
00825     sprintf(shader_prog, PSString.GetTCharPtr(), 6 * k + 1);
00826 
00827     _vertical_hq_gauss_filter_prog[k-1] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00828     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00829     PS->SetShaderCode (shader_prog, TEXT ("#define SAMPLERTEX2D") );
00830     delete [] shader_prog;
00831 
00832     _vertical_hq_gauss_filter_prog[k-1]->ClearShaderObjects();
00833     _vertical_hq_gauss_filter_prog[k-1]->AddShaderObject (VS);
00834     _vertical_hq_gauss_filter_prog[k-1]->AddShaderObject (PS);
00835     CHECKGL ( glBindAttribLocation (_vertical_hq_gauss_filter_prog[k-1]->GetOpenGLID(), 0, "AVertex") );
00836     _vertical_hq_gauss_filter_prog[k-1]->Link();
00837   }
00838 
00839   void GraphicsEngine::InitSLColorMatrixFilter ()
00840   {
00841     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00842     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00843     NString VSString;
00844     NString PSString;
00845 
00846 
00847     VSString = TEXT ("#version 110          \n\
00848         uniform mat4 ViewProjectionMatrix;  \n\
00849         attribute vec4 AVertex;             \n\
00850         attribute vec4 MyTextureCoord0;     \n\
00851         varying vec4 varyTexCoord0;         \n\
00852         void main()                         \n\
00853         {                                   \n\
00854           varyTexCoord0 = MyTextureCoord0;  \n\
00855           gl_Position =  ViewProjectionMatrix * (AVertex);  \n\
00856         }");
00857 
00858     PSString = TEXT ("#version 110                                  \n\
00859         #extension GL_ARB_texture_rectangle : enable                \n\
00860         varying vec4 varyTexCoord0;                                 \n\
00861         uniform sampler2D TextureObject0;                           \n\
00862         uniform vec4 color0;                                        \n\
00863         vec4 SampleTexture(sampler2D TexObject, vec2 TexCoord)      \n\
00864         {                                                           \n\
00865           return texture2D(TexObject, TexCoord.st);                 \n\
00866         }                                                           \n\
00867         // Color Matrix                                             \n\
00868         uniform float CM0[5];                                       \n\
00869         uniform float CM1[5];                                       \n\
00870         uniform float CM2[5];                                       \n\
00871         uniform float CM3[5];                                       \n\
00872         void main (void)                                            \n\
00873         {                                                                 \n\
00874           vec4 tex0 = SampleTexture(TextureObject0, varyTexCoord0.st); \n\
00875           float r = CM0[0]* tex0.r + CM0[1]* tex0.g + CM0[2]* tex0.b + CM0[3]* tex0.a + CM0[4]; \n\
00876           float g = CM1[0]* tex0.r + CM1[1]* tex0.g + CM1[2]* tex0.b + CM1[3]* tex0.a + CM1[4]; \n\
00877           float b = CM2[0]* tex0.r + CM2[1]* tex0.g + CM2[2]* tex0.b + CM2[3]* tex0.a + CM2[4]; \n\
00878           float a = CM3[0]* tex0.r + CM3[1]* tex0.g + CM3[2]* tex0.b + CM3[3]* tex0.a + CM3[4]; \n\
00879           gl_FragColor = color0 * vec4(r, g, b, tex0.a);                                        \n\
00880         }");
00881 
00882     _color_matrix_filter_prog = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00883     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
00884     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
00885 
00886     _color_matrix_filter_prog->ClearShaderObjects();
00887     _color_matrix_filter_prog->AddShaderObject (VS);
00888     _color_matrix_filter_prog->AddShaderObject (PS);
00889     CHECKGL ( glBindAttribLocation (_color_matrix_filter_prog->GetOpenGLID(), 0, "AVertex") );
00890     _color_matrix_filter_prog->Link();
00891   }
00892 
00893   void GraphicsEngine::QRP_GLSL_Color (int x, int y, int width, int height, const Color &color)
00894   {
00895     QRP_GLSL_Color (x, y, width, height, color, color, color, color);
00896   }
00897 
00898   void GraphicsEngine::QRP_GLSL_Color (int x, int y, int width, int height, const Color &c0, const Color &c1, const Color &c2, const Color &c3)
00899   {
00900     NUX_RETURN_IF_FALSE (m_SlColor.IsValid());
00901 
00902     m_quad_tex_stats++;
00903 
00904     float fx = x, fy = y;
00905     float VtxBuffer[] =
00906     {
00907       fx,          fy,          0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
00908       fx,          fy + height, 0.0f, 1.0f, c1.red, c1.green, c1.blue, c1.alpha,
00909       fx + width,  fy + height, 0.0f, 1.0f, c2.red, c2.green, c2.blue, c2.alpha,
00910       fx + width,  fy,          0.0f, 1.0f, c3.red, c3.green, c3.blue, c3.alpha,
00911     };
00912 
00913     ObjectPtr<IOpenGLShaderProgram> ShaderProg = m_SlColor;
00914 
00915     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
00916     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
00917     ShaderProg->Begin();
00918 
00919     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
00920     int VertexColorLocation = ShaderProg->GetAttributeLocation ("VertexColor");
00921 
00922     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
00923     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
00924     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
00925 
00926     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
00927     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer) );
00928 
00929     if (VertexColorLocation != -1)
00930     {
00931       CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation) );
00932       CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4) );
00933     }
00934 
00935     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
00936 
00937     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
00938 
00939     if (VertexColorLocation != -1)
00940       CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
00941 
00942     ShaderProg->End();
00943   }
00944 
00945   void GraphicsEngine::QRP_GLSL_1Tex (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform0, const Color &color0)
00946   {
00947     NUX_RETURN_IF_FALSE (m_SlTextureModColor.IsValid());
00948 
00949     m_quad_tex_stats++;
00950     QRP_Compute_Texture_Coord (width, height, DeviceTexture, texxform0);
00951     float fx = x, fy = y;
00952     float VtxBuffer[] =
00953     {
00954       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00955       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00956       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00957       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00958     };
00959 
00960     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
00961 
00962     if (DeviceTexture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType) )
00963     {
00964       ShaderProg = m_SlTextureModColor;
00965     }
00966 
00967 //     if(DeviceTexture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType) ||
00968 //         DeviceTexture->Type().IsDerivedFromType(IOpenGLAnimatedTexture::StaticObjectType))
00969 //     {
00970 //         ShaderProg = m_TexturedRectProg;
00971 //     }
00972 
00973     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
00974     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
00975     ShaderProg->Begin();
00976 
00977     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
00978     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
00979     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
00980     int VertexColorLocation = ShaderProg->GetAttributeLocation ("VertexColor");
00981 
00982     SetTexture (GL_TEXTURE0, DeviceTexture);
00983     CHECKGL ( glUniform1iARB (TextureObjectLocation, 0) );
00984 
00985     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
00986     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
00987     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
00988 
00989     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
00990     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
00991 
00992     if (TextureCoord0Location != -1)
00993     {
00994       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
00995       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
00996     }
00997 
00998     if (VertexColorLocation != -1)
00999     {
01000       CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation) );
01001       CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01002     }
01003 
01004     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01005 
01006     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01007 
01008     if (TextureCoord0Location != -1)
01009       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01010 
01011     if (VertexColorLocation != -1)
01012       CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
01013 
01014     ShaderProg->End();
01015   }
01016 
01017 // Render the texture alpha into RGB and modulated by a color.
01018   void GraphicsEngine::QRP_GLSL_ColorModTexAlpha (int x, int y, int width, int height,
01019       ObjectPtr< IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform, const Color &color)
01020   {
01021     NUX_RETURN_IF_FALSE (m_SlColorModTexMaskAlpha.IsValid());
01022 
01023     m_quad_tex_stats++;
01024     QRP_Compute_Texture_Coord (width, height, DeviceTexture, texxform);
01025 
01026     float fx = x, fy = y;
01027     float VtxBuffer[] =
01028     {
01029       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 0, color.red, color.green, color.blue, color.alpha,
01030       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 0, color.red, color.green, color.blue, color.alpha,
01031       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 0, color.red, color.green, color.blue, color.alpha,
01032       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 0, color.red, color.green, color.blue, color.alpha,
01033     };
01034 
01035     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01036 //     if(DeviceTexture->Type().IsDerivedFromType(IOpenGLTexture2D::StaticObjectType))
01037     {
01038       ShaderProg = m_SlColorModTexMaskAlpha;
01039     }
01040 
01041     if (DeviceTexture->Type().IsDerivedFromType (IOpenGLRectangleTexture::StaticObjectType) ||
01042         DeviceTexture->Type().IsDerivedFromType (IOpenGLAnimatedTexture::StaticObjectType) )
01043     {
01044       ShaderProg = m_SlColorModTexRectMaskAlpha;
01045     }
01046 
01047     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01048     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01049     ShaderProg->Begin();
01050 
01051     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01052     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01053     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01054     int VertexColorLocation = ShaderProg->GetAttributeLocation ("VertexColor");
01055 
01056     SetTexture (GL_TEXTURE0, DeviceTexture);
01057 
01058     if (TextureObjectLocation != -1)
01059     {
01060       CHECKGL ( glUniform1iARB (TextureObjectLocation, 0) );
01061     }
01062 
01063     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01064     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01065     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01066 
01067     if (VertexLocation != -1)
01068     {
01069       CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01070       CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
01071     }
01072 
01073     if (TextureCoord0Location != -1)
01074     {
01075       CHECKGL ( glEnableVertexAttribArray (TextureCoord0Location) );
01076       CHECKGL ( glVertexAttribPointer ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
01077     }
01078 
01079     if (VertexColorLocation != -1)
01080     {
01081       CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation) );
01082       CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01083     }
01084 
01085     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01086 
01087     if (VertexLocation != -1)
01088       CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01089 
01090     if (TextureCoord0Location != -1)
01091     {
01092       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01093     }
01094 
01095     if (VertexColorLocation != -1)
01096     {
01097       CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
01098     }
01099 
01100     ShaderProg->End();
01101   }
01102 
01103 // Blend 2 textures together
01104   void GraphicsEngine::QRP_GLSL_2Tex (int x, int y, int width, int height,
01105                                        ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm &texxform0, const Color &color0,
01106                                        ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm &texxform1, const Color &color1)
01107   {
01108     NUX_RETURN_IF_FALSE (m_Sl2TextureAdd.IsValid());
01109 
01110     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01111     ShaderProg = m_Sl2TextureAdd;
01112 
01113     QRP_Compute_Texture_Coord (width, height, DeviceTexture0, texxform0);
01114     QRP_Compute_Texture_Coord (width, height, DeviceTexture1, texxform1);
01115 
01116     float fx = x, fy = y;
01117     float VtxBuffer[] =
01118     {
01119       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
01120       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
01121       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
01122       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
01123     };
01124 
01125     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01126     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01127     ShaderProg->Begin();
01128 
01129     int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB ("TextureObject0");
01130     int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB ("TextureObject1");
01131     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01132     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01133     int TextureCoord1Location = ShaderProg->GetAttributeLocation ("MyTextureCoord1");
01134 
01135     int TextureCoef0Location = ShaderProg->GetUniformLocationARB ("color0");
01136     int TextureCoef1Location = ShaderProg->GetUniformLocationARB ("color1");
01137 
01138 
01139     SetTexture (GL_TEXTURE0, DeviceTexture0);
01140     SetTexture (GL_TEXTURE1, DeviceTexture1);
01141 
01142     CHECKGL ( glUniform1iARB (TextureObjectLocation0, 0) );
01143     CHECKGL ( glUniform1iARB (TextureObjectLocation1, 1) );
01144 
01145     CHECKGL ( glUniform4fARB (TextureCoef0Location, color0.red, color0.green, color0.blue, color0.alpha ) );
01146     CHECKGL ( glUniform4fARB (TextureCoef1Location, color1.red, color1.green, color1.blue, color1.alpha ) );
01147 
01148     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01149     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01150     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01151 
01152     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01153     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
01154 
01155     if (TextureCoord0Location != -1)
01156     {
01157       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01158       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
01159     }
01160 
01161     if (TextureCoord1Location != -1)
01162     {
01163       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord1Location) );
01164       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01165     }
01166 
01167     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01168 
01169     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01170 
01171     if (TextureCoord0Location != -1)
01172       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01173 
01174     if (TextureCoord1Location != -1)
01175       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord1Location) );
01176 
01177     ShaderProg->End();
01178   }
01179 
01180   void GraphicsEngine::QRP_GLSL_DisturbedTexture (
01181     int x, int y, int width, int height,
01182     ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm &texxform0, const Color& c0,
01183     ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm &texxform1, const Color& c1)
01184   {
01185     NUX_RETURN_IF_FALSE (m_Sl2TextureDepRead.IsValid());
01186 
01187     ObjectPtr<IOpenGLShaderProgram> ShaderProg = m_Sl2TextureDepRead;
01188 
01189     QRP_Compute_Texture_Coord (width, height, distorsion_texture, texxform0);
01190     QRP_Compute_Texture_Coord (width, height, src_device_texture, texxform1);
01191 
01192     float fx = x, fy = y;
01193     float VtxBuffer [] =
01194     {
01195       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
01196       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
01197       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
01198       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
01199     };
01200 
01201     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01202     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01203     ShaderProg->Begin();
01204 
01205     int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB ("TextureObject0");
01206     int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB ("TextureObject1");
01207     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01208     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01209     int TextureCoord1Location = ShaderProg->GetAttributeLocation ("MyTextureCoord1");
01210 
01211     int TextureCoef0Location = ShaderProg->GetUniformLocationARB ("color0");
01212     int TextureCoef1Location = ShaderProg->GetUniformLocationARB ("color1");
01213 
01214 
01215     SetTexture (GL_TEXTURE0, distorsion_texture);
01216     SetTexture (GL_TEXTURE1, src_device_texture);
01217 
01218     CHECKGL ( glUniform1iARB (TextureObjectLocation0, 0) );
01219     CHECKGL ( glUniform1iARB (TextureObjectLocation1, 1) );
01220 
01221     CHECKGL ( glUniform4fARB (TextureCoef0Location, c0.red, c0.green, c0.blue, c0.alpha ) );
01222     CHECKGL ( glUniform4fARB (TextureCoef1Location, c1.red, c1.green, c1.blue, c1.alpha ) );
01223 
01224     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01225     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01226     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01227 
01228     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01229     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
01230 
01231     if (TextureCoord0Location != -1)
01232     {
01233       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01234       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
01235     }
01236 
01237     if (TextureCoord1Location != -1)
01238     {
01239       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord1Location) );
01240       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01241     }
01242 
01243     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01244 
01245     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01246 
01247     if (TextureCoord0Location != -1)
01248       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01249 
01250     if (TextureCoord1Location != -1)
01251       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord1Location) );
01252 
01253     ShaderProg->End();
01254   }
01255 
01256   void GraphicsEngine::QRP_GLSL_2TexMod (int x, int y, int width, int height,
01257     ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm &texxform0, const Color &color0,
01258     ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm &texxform1, const Color &color1)
01259   {
01260     NUX_RETURN_IF_FALSE (m_Sl2TextureMod.IsValid());
01261 
01262     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01263     {
01264       ShaderProg = m_Sl2TextureMod;
01265     }
01266 
01267     QRP_Compute_Texture_Coord (width, height, DeviceTexture0, texxform0);
01268     QRP_Compute_Texture_Coord (width, height, DeviceTexture1, texxform1);
01269 
01270     float fx = x, fy = y;
01271     float VtxBuffer[] =
01272     {
01273       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
01274       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
01275       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
01276       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
01277     };
01278 
01279     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01280     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01281     ShaderProg->Begin();
01282 
01283     int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB ("TextureObject0");
01284     int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB ("TextureObject1");
01285     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01286     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01287     int TextureCoord1Location = ShaderProg->GetAttributeLocation ("MyTextureCoord1");
01288 
01289     int TextureCoef0Location = ShaderProg->GetUniformLocationARB ("color0");
01290     int TextureCoef1Location = ShaderProg->GetUniformLocationARB ("color1");
01291 
01292 
01293     SetTexture (GL_TEXTURE0, DeviceTexture0);
01294     SetTexture (GL_TEXTURE1, DeviceTexture1);
01295 
01296     CHECKGL ( glUniform1iARB (TextureObjectLocation0, 0) );
01297     CHECKGL ( glUniform1iARB (TextureObjectLocation1, 1) );
01298 
01299     CHECKGL ( glUniform4fARB (TextureCoef0Location, color0.red, color0.green, color0.blue, color0.alpha ) );
01300     CHECKGL ( glUniform4fARB (TextureCoef1Location, color1.red, color1.green, color1.blue, color1.alpha ) );
01301 
01302     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01303     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01304     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01305 
01306     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01307     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
01308 
01309     if (TextureCoord0Location != -1)
01310     {
01311       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01312       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
01313     }
01314 
01315     if (TextureCoord1Location != -1)
01316     {
01317       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord1Location) );
01318       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01319     }
01320 
01321     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01322 
01323     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01324 
01325     if (TextureCoord0Location != -1)
01326       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01327 
01328     if (TextureCoord1Location != -1)
01329       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord1Location) );
01330 
01331     ShaderProg->End();
01332   }
01333 
01334   void GraphicsEngine::QRP_GLSL_4Tex (int x, int y, int width, int height,
01335                                        ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm &texxform0, const Color &color0,
01336                                        ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm &texxform1, const Color &color1,
01337                                        ObjectPtr<IOpenGLBaseTexture> DeviceTexture2, TexCoordXForm &texxform2, const Color &color2,
01338                                        ObjectPtr<IOpenGLBaseTexture> DeviceTexture3, TexCoordXForm &texxform3, const Color &color3)
01339   {
01340     NUX_RETURN_IF_FALSE (m_Sl4TextureAdd.IsValid());
01341 
01342     QRP_Compute_Texture_Coord (width, height, DeviceTexture0, texxform0);
01343     QRP_Compute_Texture_Coord (width, height, DeviceTexture1, texxform1);
01344     QRP_Compute_Texture_Coord (width, height, DeviceTexture2, texxform2);
01345     QRP_Compute_Texture_Coord (width, height, DeviceTexture3, texxform3);
01346 
01347     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01348     ShaderProg = m_Sl4TextureAdd;
01349 
01350     float fx = x, fy = y;
01351     float VtxBuffer[] =
01352     {
01353       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 1.0f, texxform1.u0, texxform1.v0, 0, 1.0f, texxform2.u0, texxform2.v0, 0, 1.0f, texxform3.u0, texxform3.v0, 0, 1.0f,
01354       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 1.0f, texxform1.u0, texxform1.v1, 0, 1.0f, texxform2.u0, texxform2.v1, 0, 1.0f, texxform3.u0, texxform3.v1, 0, 1.0f,
01355       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 1.0f, texxform1.u1, texxform1.v1, 0, 1.0f, texxform2.u1, texxform2.v1, 0, 1.0f, texxform3.u1, texxform3.v1, 0, 1.0f,
01356       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 1.0f, texxform1.u1, texxform1.v0, 0, 1.0f, texxform2.u1, texxform2.v0, 0, 1.0f, texxform3.u1, texxform3.v0, 0, 1.0f,
01357     };
01358 
01359     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01360     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01361     ShaderProg->Begin();
01362 
01363     int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB ("TextureObject0");
01364     int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB ("TextureObject1");
01365     int TextureObjectLocation2 = ShaderProg->GetUniformLocationARB ("TextureObject2");
01366     int TextureObjectLocation3 = ShaderProg->GetUniformLocationARB ("TextureObject3");
01367     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01368     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01369     int TextureCoord1Location = ShaderProg->GetAttributeLocation ("MyTextureCoord1");
01370     int TextureCoord2Location = ShaderProg->GetAttributeLocation ("MyTextureCoord2");
01371     int TextureCoord3Location = ShaderProg->GetAttributeLocation ("MyTextureCoord3");
01372 
01373     int TextureCoef0Location = ShaderProg->GetUniformLocationARB ("color0");
01374     int TextureCoef1Location = ShaderProg->GetUniformLocationARB ("color1");
01375     int TextureCoef2Location = ShaderProg->GetUniformLocationARB ("color2");
01376     int TextureCoef3Location = ShaderProg->GetUniformLocationARB ("color3");
01377 
01378     SetTexture (GL_TEXTURE0, DeviceTexture0);
01379     SetTexture (GL_TEXTURE1, DeviceTexture1);
01380     SetTexture (GL_TEXTURE2, DeviceTexture2);
01381     SetTexture (GL_TEXTURE3, DeviceTexture3);
01382 
01383     CHECKGL ( glUniform1iARB (TextureObjectLocation0, 0) );
01384     CHECKGL ( glUniform1iARB (TextureObjectLocation1, 1) );
01385     CHECKGL ( glUniform1iARB (TextureObjectLocation2, 2) );
01386     CHECKGL ( glUniform1iARB (TextureObjectLocation3, 3) );
01387 
01388     CHECKGL ( glUniform4fARB (TextureCoef0Location, color0.red, color0.green, color0.blue, color0.alpha ) );
01389     CHECKGL ( glUniform4fARB (TextureCoef1Location, color1.red, color1.green, color1.blue, color1.alpha ) );
01390     CHECKGL ( glUniform4fARB (TextureCoef2Location, color2.red, color2.green, color2.blue, color2.alpha ) );
01391     CHECKGL ( glUniform4fARB (TextureCoef3Location, color3.red, color3.green, color3.blue, color3.alpha ) );
01392 
01393     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01394     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01395     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01396 
01397     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01398     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer) );
01399 
01400     if (TextureCoord0Location != -1)
01401     {
01402       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01403       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 4) );
01404     }
01405 
01406     if (TextureCoord1Location != -1)
01407     {
01408       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord1Location) );
01409       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 8) );
01410     }
01411 
01412     if (TextureCoord2Location != -1)
01413     {
01414       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord2Location) );
01415       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord2Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 12) );
01416     }
01417 
01418     if (TextureCoord3Location != -1)
01419     {
01420       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord3Location) );
01421       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord3Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 16) );
01422     }
01423 
01424     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01425 
01426     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01427 
01428     if (TextureCoord0Location != -1)
01429       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01430 
01431     if (TextureCoord1Location != -1)
01432       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord1Location) );
01433 
01434     if (TextureCoord2Location != -1)
01435       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord2Location) );
01436 
01437     if (TextureCoord3Location != -1)
01438       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord3Location) );
01439 
01440     ShaderProg->End();
01441   }
01443   void GraphicsEngine::QRP_GLSL_Triangle (int x0, int y0,
01444       int x1, int y1,
01445       int x2, int y2,
01446       Color c0)
01447   {
01448     QRP_GLSL_Triangle (x0, y0, x1, y1, x2, y2, c0, c0, c0);
01449   }
01450 
01451   void GraphicsEngine::QRP_GLSL_Triangle (int x0, int y0,
01452       int x1, int y1,
01453       int x2, int y2,
01454       Color c0, Color c1, Color c2)
01455   {
01456     NUX_RETURN_IF_FALSE (m_SlColor.IsValid());
01457 
01458     float VtxBuffer[] =
01459     {
01460       static_cast<float>(x0), static_cast<float>(y0), 0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
01461       static_cast<float>(x1), static_cast<float>(y1), 0.0f, 1.0f, c1.red, c1.green, c1.blue, c1.alpha,
01462       static_cast<float>(x2), static_cast<float>(y2), 0.0f, 1.0f, c2.red, c2.green, c2.blue, c2.alpha,
01463     };
01464 
01465     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01466     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01467 
01468     m_SlColor->Begin();
01469 
01470     int VertexLocation = m_SlColor->GetAttributeLocation ("AVertex");
01471     int VertexColorLocation = m_SlColor->GetAttributeLocation ("VertexColor");
01472 
01473     int     VPMatrixLocation = m_SlColor->GetUniformLocationARB ("ViewProjectionMatrix");
01474     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01475     m_SlColor->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01476 
01477     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01478     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer) );
01479 
01480     CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation) );
01481     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4) );
01482 
01483     CHECKGL ( glDrawArrays (GL_TRIANGLES, 0, 3) );
01484 
01485     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01486     CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
01487     m_SlColor->End();
01488 
01489     m_triangle_stats++;
01490   }
01491 
01493 // DRAW LINES       //
01495   void GraphicsEngine::QRP_GLSL_Line (int x0, int y0,
01496                                        int x1, int y1, Color c0)
01497   {
01498     QRP_GLSL_Line (x0, y0, x1, y1, c0, c0);
01499   }
01500 
01501   void GraphicsEngine::QRP_GLSL_Line (int x0, int y0,
01502                                        int x1, int y1, Color c0, Color c1)
01503   {
01504     NUX_RETURN_IF_FALSE (m_SlColor.IsValid());
01505 
01506     float VtxBuffer[] =
01507     {
01508       static_cast<float>(x0), static_cast<float>(y0), 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c0.red, c0.green, c0.blue, c0.alpha,
01509       static_cast<float>(x1), static_cast<float>(y1), 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c1.red, c1.green, c1.blue, c1.alpha,
01510     };
01511 
01512     ObjectPtr<IOpenGLShaderProgram> ShaderProg = m_SlColor;
01513 
01514 
01515     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01516     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01517     ShaderProg->Begin();
01518 
01519     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01520     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01521     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01522     int VertexColorLocation = ShaderProg->GetAttributeLocation ("VertexColor");
01523 
01524 
01525     CHECKGL ( glUniform1iARB (TextureObjectLocation, 0) );
01526 
01527     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01528     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01529     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01530 
01531     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01532     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
01533 
01534     if (TextureCoord0Location != -1)
01535     {
01536       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01537       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
01538     }
01539 
01540     if (VertexColorLocation != -1)
01541     {
01542       CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation) );
01543       CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01544     }
01545 
01546     CHECKGL ( glDrawArrays (GL_LINES, 0, 2) );
01547 
01548     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01549 
01550     if (TextureCoord0Location != -1)
01551       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01552 
01553     if (VertexColorLocation != -1)
01554       CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
01555 
01556     ShaderProg->End();
01557 
01558     m_line_stats++;
01559   }
01560 
01561   void GraphicsEngine::QRP_GLSL_QuadWireframe (int x0, int y0, int width, int height,
01562       Color c0,
01563       Color c1,
01564       Color c2,
01565       Color c3)
01566   {
01567     NUX_RETURN_IF_FALSE (m_SlColor.IsValid());
01568 
01569     float fx0 = x0, fy0 = y0;
01570     float VtxBuffer[] =
01571     {
01572       fx0, fy0,                             0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c0.red, c0.green, c0.blue, c0.alpha,
01573       fx0, fy0 + height - 1,                0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c1.red, c1.green, c1.blue, c1.alpha,
01574       fx0 + width - 1, fy0 + height - 1,    0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c2.red, c2.green, c2.blue, c2.alpha,
01575       fx0 + width - 1, fy0,                 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c3.red, c3.green, c3.blue, c3.alpha,
01576       fx0, fy0,                             0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, c0.red, c0.green, c0.blue, c0.alpha,
01577     };
01578 
01579     ObjectPtr<IOpenGLShaderProgram> ShaderProg = m_SlColor;
01580 
01581 
01582     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01583     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01584     ShaderProg->Begin();
01585 
01586     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01587     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
01588     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01589     int VertexColorLocation = ShaderProg->GetAttributeLocation ("VertexColor");
01590 
01591 
01592     CHECKGL ( glUniform1iARB (TextureObjectLocation, 0) );
01593 
01594     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01595     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01596     ShaderProg->SetUniformLocMatrix4fv ( (GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m) );
01597 
01598     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01599     CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer) );
01600 
01601     if (TextureCoord0Location != -1)
01602     {
01603       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01604       CHECKGL ( glVertexAttribPointerARB ( (GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4) );
01605     }
01606 
01607     if (VertexColorLocation != -1)
01608     {
01609       CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation) );
01610       CHECKGL ( glVertexAttribPointerARB ( (GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
01611     }
01612 
01613     CHECKGL ( glDrawArrays (GL_LINE_STRIP, 0, 5) );
01614 
01615     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01616 
01617     if (TextureCoord0Location != -1)
01618       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01619 
01620     if (VertexColorLocation != -1)
01621       CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
01622 
01623     ShaderProg->End();
01624 
01625     m_line_stats++;
01626   }
01627 
01628   void GraphicsEngine::QRP_GLSL_Power (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, Vector4 exponent)
01629   {
01630     NUX_RETURN_IF_FALSE (_component_exponentiation_prog.IsValid());
01631 
01632     m_quad_tex_stats++;
01633     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
01634     float fx = x, fy = y;
01635     float VtxBuffer[] =
01636     {
01637       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
01638       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
01639       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
01640       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
01641     };
01642 
01643     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01644 
01645     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
01646     {
01647       return;
01648     }
01649 
01650     ShaderProg = _component_exponentiation_prog;
01651 
01652     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0) );
01653     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0) );
01654     ShaderProg->Begin();
01655 
01656     int TextureObjectLocation   = ShaderProg->GetUniformLocationARB ("TextureObject0");
01657     int Color0Location          = ShaderProg->GetUniformLocationARB ("color0");
01658     int ExponentLocation        = ShaderProg->GetUniformLocationARB ("exponent");
01659     int VertexLocation          = ShaderProg->GetAttributeLocation ("AVertex");
01660     int TextureCoord0Location   = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01661 
01662 
01663     SetTexture (GL_TEXTURE0, device_texture);
01664     
01665     CHECKGL ( glUniform1iARB (TextureObjectLocation, 0));
01666 
01667     CHECKGL ( glUniform4fARB (ExponentLocation, exponent.x, exponent.y, exponent.z, exponent.w ));
01668 
01669     CHECKGL ( glUniform4fARB (Color0Location, c0.red, c0.green, c0.blue, c0.alpha));
01670 
01671     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01672     Matrix4 MVPMatrix =  GetOpenGLModelViewProjectionMatrix();
01673     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
01674 
01675     CHECKGL ( glEnableVertexAttribArrayARB (VertexLocation) );
01676     CHECKGL ( glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01677 
01678     if (TextureCoord0Location != -1)
01679     {
01680       CHECKGL ( glEnableVertexAttribArrayARB (TextureCoord0Location) );
01681       CHECKGL ( glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01682     }
01683 
01684     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
01685 
01686     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
01687 
01688     if (TextureCoord0Location != -1)
01689       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
01690 
01691     ShaderProg->End();
01692   }
01693 
01694   void GraphicsEngine::QRP_GLSL_AlphaReplicate (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0)
01695   {
01696     NUX_RETURN_IF_FALSE (_alpha_replicate_prog.IsValid());
01697 
01698     m_quad_tex_stats++;
01699     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
01700     float fx = x, fy = y;
01701     float VtxBuffer[] =
01702     {
01703       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
01704       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
01705       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
01706       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
01707     };
01708 
01709     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01710 
01711     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
01712     {
01713       return;
01714     }
01715 
01716     ShaderProg = _alpha_replicate_prog;
01717 
01718     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
01719     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01720     ShaderProg->Begin ();
01721 
01722     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01723     int Color0Location        = ShaderProg->GetUniformLocationARB ("color0");
01724     int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
01725     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01726 
01727 
01728     SetTexture (GL_TEXTURE0, device_texture);
01729 
01730     CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
01731 
01732     CHECKGL ( glUniform4fARB (Color0Location, c0.red, c0.green, c0.blue, c0.alpha));
01733 
01734     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01735     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01736     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
01737 
01738     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
01739     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01740 
01741     if (TextureCoord0Location != -1)
01742     {
01743       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
01744       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01745     }
01746 
01747     CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
01748 
01749     CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
01750 
01751     if (TextureCoord0Location != -1)
01752       CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
01753 
01754     ShaderProg->End();
01755   }
01756 
01757   void GraphicsEngine::QRP_GLSL_HorizontalGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, float sigma)
01758   {
01759     NUX_RETURN_IF_FALSE (_horizontal_gauss_filter_prog.IsValid());
01760 
01761     m_quad_tex_stats++;
01762     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
01763     float fx = x, fy = y;
01764     float VtxBuffer[] =
01765     {
01766       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
01767       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
01768       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
01769       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
01770     };
01771 
01772     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01773 
01774     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
01775     {
01776       return;
01777     }
01778 
01779     ShaderProg = _horizontal_gauss_filter_prog;
01780 
01781     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
01782     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01783     ShaderProg->Begin ();
01784 
01785     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01786     int WeightsLocation       = ShaderProg->GetUniformLocationARB ("W");
01787     int TextureSizeLocation   = ShaderProg->GetUniformLocationARB ("TextureSize0");
01788     int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
01789     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01790     
01791     SetTexture (GL_TEXTURE0, device_texture);
01792     CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
01793 
01794     sigma = Clamp <float> (sigma, 0.1f, 9.0f);
01795     // Set the Gaussian weights
01796     {
01797       float *W;
01798       GaussianWeights(&W, sigma, 7);
01799       CHECKGL( glUniform1fv(WeightsLocation, 7, W) );
01800       delete[] W;
01801     }
01802 
01803     CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
01804 
01805     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01806     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01807     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
01808 
01809     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
01810     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01811 
01812     if (TextureCoord0Location != -1)
01813     {
01814       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
01815       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01816     }
01817 
01818     CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
01819 
01820     CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
01821 
01822     if (TextureCoord0Location != -1)
01823       CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
01824 
01825     ShaderProg->End();
01826   }
01827 
01828   void GraphicsEngine::QRP_GLSL_VerticalGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, float sigma)
01829   {
01830     NUX_RETURN_IF_FALSE (_vertical_gauss_filter_prog.IsValid());
01831 
01832     m_quad_tex_stats++;
01833     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
01834     float fx = x, fy = y;
01835     float VtxBuffer[] =
01836     {
01837       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
01838       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
01839       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
01840       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
01841     };
01842 
01843     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01844 
01845     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
01846     {
01847       return;
01848     }
01849 
01850     ShaderProg = _vertical_gauss_filter_prog;
01851 
01852     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
01853     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01854     ShaderProg->Begin ();
01855 
01856     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01857     int WeightsLocation       = ShaderProg->GetUniformLocationARB ("W");
01858     int TextureSizeLocation   = ShaderProg->GetUniformLocationARB ("TextureSize0");
01859     int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
01860     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01861     
01862 
01863     SetTexture (GL_TEXTURE0, device_texture);
01864 
01865     CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
01866 
01867     sigma = Clamp <float> (sigma, 0.1f, 9.0f);
01868     // Set the Gaussian weights
01869     {
01870       float *W;
01871       GaussianWeights(&W, sigma, 7);
01872       CHECKGL( glUniform1fv(WeightsLocation, 7, W) );
01873       delete[] W;
01874     }
01875 
01876     CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
01877 
01878     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01879     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01880     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
01881 
01882     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
01883     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01884 
01885     if (TextureCoord0Location != -1)
01886     {
01887       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
01888       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01889     }
01890 
01891     CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
01892 
01893     CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
01894 
01895     if (TextureCoord0Location != -1)
01896       CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
01897 
01898     ShaderProg->End();
01899   }
01900 
01901   void GraphicsEngine::QRP_GLSL_HorizontalHQGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, float sigma)
01902   {
01903     int k = Clamp<float>(sigma, NUX_MIN_GAUSSIAN_SIGMA, NUX_MAX_GAUSSIAN_SIGMA);
01904 
01905     if (_horizontal_hq_gauss_filter_prog[k-1].IsValid() == false)
01906     {
01907       InitSLHorizontalHQGaussFilter(k);
01908     }
01909 
01910     m_quad_tex_stats++;
01911     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
01912     float fx = x, fy = y;
01913     float VtxBuffer[] =
01914     {
01915       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
01916       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
01917       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
01918       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
01919     };
01920 
01921     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01922 
01923     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
01924     {
01925       return;
01926     }
01927 
01928     ShaderProg = _horizontal_hq_gauss_filter_prog[k-1];
01929 
01930     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
01931     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01932     ShaderProg->Begin ();
01933 
01934     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
01935     int WeightsLocation       = ShaderProg->GetUniformLocationARB ("W");
01936     int TextureSizeLocation   = ShaderProg->GetUniformLocationARB ("TextureSize0");
01937     int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
01938     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
01939 
01940     SetTexture (GL_TEXTURE0, device_texture);
01941     CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
01942 
01943     sigma = Clamp <float> (sigma, 0.1f, NUX_MAX_GAUSSIAN_SIGMA);
01944     // Set the Gaussian weights
01945     {
01946       float *W;
01947       GaussianWeights(&W, sigma, 6*k+1);
01948       CHECKGL( glUniform1fv(WeightsLocation, 6*k+1, W) );
01949       delete[] W;
01950     }
01951 
01952     CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
01953 
01954     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
01955     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
01956     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
01957 
01958     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
01959     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01960 
01961     if (TextureCoord0Location != -1)
01962     {
01963       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
01964       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01965     }
01966 
01967     CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
01968 
01969     CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
01970 
01971     if (TextureCoord0Location != -1)
01972       CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
01973 
01974     ShaderProg->End();
01975   }
01976 
01977   void GraphicsEngine::QRP_GLSL_VerticalHQGauss (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color &c0, float sigma)
01978   {
01979     int k = Clamp<float>(sigma, NUX_MIN_GAUSSIAN_SIGMA, NUX_MAX_GAUSSIAN_SIGMA);
01980 
01981     if (_vertical_hq_gauss_filter_prog[k-1].IsValid() == false)
01982     {
01983       InitSLVerticalHQGaussFilter(k);
01984     }
01985 
01986     m_quad_tex_stats++;
01987     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
01988     float fx = x, fy = y;
01989     float VtxBuffer[] =
01990     {
01991       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
01992       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
01993       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
01994       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
01995     };
01996 
01997     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
01998 
01999     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
02000     {
02001       return;
02002     }
02003 
02004     ShaderProg = _vertical_hq_gauss_filter_prog[k-1];
02005 
02006     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
02007     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
02008     ShaderProg->Begin ();
02009 
02010     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
02011     int WeightsLocation       = ShaderProg->GetUniformLocationARB ("W");
02012     int TextureSizeLocation   = ShaderProg->GetUniformLocationARB ("TextureSize0");
02013     int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
02014     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
02015 
02016 
02017     SetTexture (GL_TEXTURE0, device_texture);
02018 
02019     CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
02020 
02021     sigma = Clamp <float> (sigma, 0.1f, NUX_MAX_GAUSSIAN_SIGMA);
02022     // Set the Gaussian weights
02023     {
02024       float *W;
02025       GaussianWeights(&W, sigma, 6*k+1);
02026       CHECKGL( glUniform1fv(WeightsLocation, 6*k+1, W) );
02027       delete[] W;
02028     }
02029 
02030     CHECKGL( glUniform2fARB(TextureSizeLocation, width, height) );
02031 
02032     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
02033     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
02034     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
02035 
02036     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
02037     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
02038 
02039     if (TextureCoord0Location != -1)
02040     {
02041       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
02042       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
02043     }
02044 
02045     CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
02046 
02047     CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
02048 
02049     if (TextureCoord0Location != -1)
02050       CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
02051 
02052     ShaderProg->End();
02053   }
02054 
02055   void GraphicsEngine::QRP_GLSL_ColorMatrix (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0,
02056     const Color &c0,
02057     Matrix4 color_matrix,
02058     Vector4 offset)
02059   {
02060     NUX_RETURN_IF_FALSE (_color_matrix_filter_prog.IsValid());
02061 
02062     m_quad_tex_stats++;
02063     QRP_Compute_Texture_Coord (width, height, device_texture, texxform0);
02064     float fx = x, fy = y;
02065     float VtxBuffer[] =
02066     {
02067       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0,
02068       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0,
02069       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0,
02070       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0,
02071     };
02072 
02073     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
02074 
02075     if (!device_texture->Type().IsDerivedFromType (IOpenGLTexture2D::StaticObjectType))
02076     {
02077       return;
02078     }
02079 
02080     ShaderProg = _color_matrix_filter_prog;
02081 
02082     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
02083     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
02084     ShaderProg->Begin ();
02085 
02086     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
02087     int Color0Location        = ShaderProg->GetUniformLocationARB ("color0");
02088     int MatrixRow0Location    = ShaderProg->GetUniformLocationARB ("CM0");
02089     int MatrixRow1Location    = ShaderProg->GetUniformLocationARB ("CM1");
02090     int MatrixRow2Location    = ShaderProg->GetUniformLocationARB ("CM2");
02091     int MatrixRow3Location    = ShaderProg->GetUniformLocationARB ("CM3");
02092 
02093     int VertexLocation        = ShaderProg->GetAttributeLocation ("AVertex");
02094     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
02095 
02096     SetTexture (GL_TEXTURE0, device_texture);
02097 
02098     CHECKGL (glUniform1iARB (TextureObjectLocation, 0));
02099 
02100     CHECKGL ( glUniform4fARB (Color0Location, c0.red, c0.green, c0.blue, c0.alpha));
02101 
02102     float v[5];
02103     v[0] = color_matrix.m[0][0]; v[1] = color_matrix.m[0][1]; v[2] = color_matrix.m[0][2]; v[3] = color_matrix.m[0][3]; v[4] = offset.x;
02104     CHECKGL (glUniform1fvARB (MatrixRow0Location, 5, v));
02105     v[0] = color_matrix.m[1][0]; v[1] = color_matrix.m[1][1]; v[2] = color_matrix.m[1][2]; v[3] = color_matrix.m[1][3]; v[4] = offset.y;
02106     CHECKGL (glUniform1fvARB (MatrixRow1Location, 5, v));
02107     v[0] = color_matrix.m[2][0]; v[1] = color_matrix.m[2][1]; v[2] = color_matrix.m[2][2]; v[3] = color_matrix.m[2][3]; v[4] = offset.z;
02108     CHECKGL (glUniform1fvARB (MatrixRow2Location, 5, v));
02109     v[0] = color_matrix.m[3][0]; v[1] = color_matrix.m[3][1]; v[2] = color_matrix.m[3][2]; v[3] = color_matrix.m[3][3]; v[4] = offset.w;
02110     CHECKGL (glUniform1fvARB (MatrixRow3Location, 5, v));
02111 
02112     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
02113     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
02114     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
02115 
02116     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
02117     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
02118 
02119     if (TextureCoord0Location != -1)
02120     {
02121       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
02122       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
02123     }
02124 
02125     CHECKGL (glDrawArrays (GL_TRIANGLE_FAN, 0, 4));
02126 
02127     CHECKGL (glDisableVertexAttribArrayARB (VertexLocation));
02128 
02129     if (TextureCoord0Location != -1)
02130       CHECKGL (glDisableVertexAttribArrayARB (TextureCoord0Location));
02131 
02132     ShaderProg->End();
02133   }
02134 
02135   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetBlurTexture (
02136     int x, int y,
02137     int buffer_width, int buffer_height,
02138     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
02139     const Color& c0,
02140     float sigma, int num_pass)
02141   {
02142     int quad_width = device_texture->GetWidth ();
02143     int quad_height = device_texture->GetHeight ();
02144 
02145     num_pass = Clamp<int> (num_pass, 1, 50);
02146 
02147     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02148     int previous_width = 0;
02149     int previous_height = 0;
02150     if (prevFBO.IsValid ())
02151     {
02152       previous_width = prevFBO->GetWidth();
02153       previous_height = prevFBO->GetHeight();
02154     }
02155     else
02156     {
02157       previous_width = _graphics_display.GetWindowWidth();
02158       previous_height = _graphics_display.GetWindowHeight();
02159     }
02160 
02161     CHECKGL (glClearColor(0, 0, 0, 0));
02162     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02163     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02164     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02165     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02166 
02167     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
02168     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02169 
02170     QRP_GLSL_1Tex(x, y, quad_width, quad_height, device_texture, texxform, color::White);
02171 
02172     TexCoordXForm texxform1;
02173     for (int i = 0; i < num_pass; i++)
02174     {
02175       SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, buffer_width, buffer_height);
02176       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02177       QRP_GLSL_HorizontalGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt0, texxform1, c0, sigma);
02178 
02179       SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
02180       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02181       QRP_GLSL_VerticalGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt1, texxform1, c0, sigma);
02182     }
02183 
02184     _offscreen_fbo->Deactivate();
02185 
02186     if (prevFBO.IsValid ())
02187     {
02188       prevFBO->Activate(true);
02189       SetViewport(0, 0, previous_width, previous_height);
02190     }
02191     else
02192     {
02193       SetViewport(0, 0, previous_width, previous_height);
02194     }
02195 
02196     return _offscreen_color_rt0;
02197   }
02198 
02199   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetPower (
02200     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &c0, const Vector4 &exponent)
02201   {
02202     int quad_width = device_texture->GetWidth ();
02203     int quad_height = device_texture->GetHeight ();
02204 
02205     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02206     int previous_width = 0;
02207     int previous_height = 0;
02208     if (prevFBO.IsValid ())
02209     {
02210       previous_width = prevFBO->GetWidth ();
02211       previous_height = prevFBO->GetHeight ();
02212     }
02213     else
02214     {
02215       previous_width = _graphics_display.GetWindowWidth ();
02216       previous_height = _graphics_display.GetWindowHeight ();
02217     }
02218 
02219     CHECKGL (glClearColor (0, 0, 0, 0));
02220     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02221     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02222     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02223     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02224 
02225     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02226     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02227     QRP_GLSL_1Tex(0, 0, quad_width, quad_height, device_texture, texxform, color::White);
02228 
02229     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width, quad_height);
02230     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02231     QRP_GLSL_Power(0, 0, quad_width, quad_height, _offscreen_color_rt0, texxform, c0, exponent);
02232 
02233     _offscreen_fbo->Deactivate();
02234 
02235     if (prevFBO.IsValid ())
02236     {
02237       prevFBO->Activate (true);
02238       SetViewport(0, 0, previous_width, previous_height);
02239     }
02240     else
02241     {
02242       SetViewport(0, 0, previous_width, previous_height);
02243     }
02244 
02245     return _offscreen_color_rt1;
02246   }
02247 
02248   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetAlphaTexture (
02249     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color & c0)
02250   {
02251     int quad_width = device_texture->GetWidth ();
02252     int quad_height = device_texture->GetHeight ();
02253 
02254     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02255     int previous_width = 0;
02256     int previous_height = 0;
02257     if (prevFBO.IsValid ())
02258     {
02259       previous_width = prevFBO->GetWidth ();
02260       previous_height = prevFBO->GetHeight ();
02261     }
02262     else
02263     {
02264       previous_width = _graphics_display.GetWindowWidth ();
02265       previous_height = _graphics_display.GetWindowHeight ();
02266     }
02267 
02268     CHECKGL (glClearColor (0, 0, 0, 0));
02269     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02270     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02271     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02272     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02273 
02274     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02275     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02276     QRP_GLSL_1Tex(0, 0, quad_width, quad_height, device_texture, texxform, color::White);
02277 
02278     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width, quad_height);
02279     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02280     QRP_GLSL_AlphaReplicate(0, 0, quad_width, quad_height, _offscreen_color_rt0, texxform, c0);
02281 
02282     _offscreen_fbo->Deactivate();
02283 
02284     if (prevFBO.IsValid ())
02285     {
02286       prevFBO->Activate (true);
02287       SetViewport(0, 0, previous_width, previous_height);
02288     }
02289     else
02290     {
02291       SetViewport(0, 0, previous_width, previous_height);
02292     }
02293 
02294     return _offscreen_color_rt1;
02295   }
02296 
02297   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetColorMatrixTexture (
02298     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
02299     const Color & c0, Matrix4 color_matrix, Vector4 offset)
02300   {
02301     int quad_width = device_texture->GetWidth ();
02302     int quad_height = device_texture->GetHeight ();
02303 
02304     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02305     int previous_width = 0;
02306     int previous_height = 0;
02307     if (prevFBO.IsValid ())
02308     {
02309       previous_width = prevFBO->GetWidth ();
02310       previous_height = prevFBO->GetHeight ();
02311     }
02312     else
02313     {
02314       previous_width = _graphics_display.GetWindowWidth ();
02315       previous_height = _graphics_display.GetWindowHeight ();
02316     }
02317 
02318     CHECKGL (glClearColor (0, 0, 0, 0));
02319     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02320     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02321     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02322     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02323 
02324     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02325     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02326     QRP_GLSL_1Tex(0, 0, quad_width, quad_height, device_texture, texxform, color::White);
02327 
02328     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width, quad_height);
02329     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02330     QRP_GLSL_ColorMatrix (0, 0, quad_width, quad_height, _offscreen_color_rt0, texxform, c0, color_matrix, offset);
02331 
02332     _offscreen_fbo->Deactivate();
02333 
02334     if (prevFBO.IsValid ())
02335     {
02336       prevFBO->Activate (true);
02337       SetViewport(0, 0, previous_width, previous_height);
02338     }
02339     else
02340     {
02341       SetViewport(0, 0, previous_width, previous_height);
02342     }
02343 
02344     return _offscreen_color_rt1;
02345   }
02346 
02347   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetLQBlur (
02348     int x, int y,
02349     int buffer_width, int buffer_height,
02350     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
02351     const Color& c0)
02352   {
02353     int quad_width = device_texture->GetWidth ();
02354     int quad_height = device_texture->GetHeight ();
02355 
02356     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02357     int previous_width = 0;
02358     int previous_height = 0;
02359     if (prevFBO.IsValid ())
02360     {
02361       previous_width  = prevFBO->GetWidth ();
02362       previous_height = prevFBO->GetHeight ();
02363     }
02364     else
02365     {
02366       previous_width  = _graphics_display.GetWindowWidth ();
02367       previous_height = _graphics_display.GetWindowHeight ();
02368     }
02369 
02370     CHECKGL (glClearColor (0, 0, 0, 0));
02371     texxform.mag_filter = TEXFILTER_LINEAR;
02372     texxform.min_filter = TEXFILTER_LINEAR;
02373 
02374     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width/2, quad_height/2);
02375     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02376     QRP_GLSL_1Tex (0, 0, quad_width / 2, quad_height / 2, device_texture, texxform, color::White);
02377 
02378     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width/4, quad_height/4);
02379     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02380     QRP_GLSL_1Tex (0, 0, quad_width / 4, quad_height / 4, _offscreen_color_rt0, texxform, color::White);
02381 
02382     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt2, _offscreen_depth_rt2, quad_width/8, quad_height/8);
02383     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02384     QRP_GLSL_1Tex (0, 0, quad_width / 8, quad_height / 8, _offscreen_color_rt1, texxform, color::White);
02385 
02386     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt3, _offscreen_depth_rt3, quad_width, quad_height);
02387     glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02388 
02389     TexCoordXForm texxform0;
02390     TexCoordXForm texxform1;
02391     TexCoordXForm texxform2;
02392     TexCoordXForm texxform3;
02393 
02394     texxform0.flip_v_coord = true;
02395     texxform2.flip_v_coord = true;
02396     QRP_GLSL_4Tex (0, 0, quad_width, quad_height,
02397       device_texture, texxform0, Color(0.25, 0.25, 0.25, 0.25),
02398       _offscreen_color_rt0, texxform1, Color(0.25, 0.25, 0.25, 0.25),
02399       _offscreen_color_rt1, texxform2, Color(0.25, 0.25, 0.25, 0.25),
02400       _offscreen_color_rt2, texxform3, Color(0.25, 0.25, 0.25, 0.25));
02401 
02402     _offscreen_fbo->Deactivate();
02403 
02404     if (prevFBO.IsValid ())
02405     {
02406       prevFBO->Activate (true);
02407       SetViewport(0, 0, previous_width, previous_height);
02408     }
02409     else
02410     {
02411       SetViewport(0, 0, previous_width, previous_height);
02412     }
02413     return _offscreen_color_rt3;
02414   }
02415 
02416 
02417   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetHQBlur (
02418     int x, int y,
02419     int buffer_width, int buffer_height,
02420     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
02421     const Color& c0,
02422     float sigma, int num_pass)
02423   {
02424     int quad_width = device_texture->GetWidth ();
02425     int quad_height = device_texture->GetHeight ();
02426 
02427     num_pass = Clamp<int> (num_pass, 1, 50);
02428 
02429     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02430     int previous_width = 0;
02431     int previous_height = 0;
02432     if (prevFBO.IsValid ())
02433     {
02434       previous_width = prevFBO->GetWidth ();
02435       previous_height = prevFBO->GetHeight ();
02436     }
02437     else
02438     {
02439       previous_width = _graphics_display.GetWindowWidth ();
02440       previous_height = _graphics_display.GetWindowHeight ();
02441     }
02442 
02443     CHECKGL (glClearColor (0, 0, 0, 0));
02444     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02445     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02446     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02447     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02448 
02449     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
02450     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02451 
02452     QRP_GLSL_1Tex(x, y, quad_width, quad_height, device_texture, texxform, color::White);
02453 
02454     TexCoordXForm texxform1;
02455     for (int i = 0; i < num_pass; i++)
02456     {
02457       SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, buffer_width, buffer_height);
02458       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02459       QRP_GLSL_HorizontalHQGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt0, texxform1, c0, sigma);
02460 
02461       SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
02462       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02463       QRP_GLSL_VerticalHQGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt1, texxform1, c0, sigma);
02464     }
02465 
02466     _offscreen_fbo->Deactivate();
02467 
02468     if (prevFBO.IsValid ())
02469     {
02470       prevFBO->Activate(true);
02471       SetViewport(0, 0, previous_width, previous_height);
02472     }
02473     else
02474     {
02475       SetViewport(0, 0, previous_width, previous_height);
02476     }
02477 
02478     return _offscreen_color_rt0;
02479   }
02480 
02481   void GraphicsEngine::QRP_GLSL_GetHQBlurFx (
02482     int x, int y,
02483     int buffer_width, int buffer_height,
02484     FxStructure *fx_structure, TexCoordXForm &texxform,
02485     const Color& c0, float sigma, int num_pass)
02486   {
02487     int quad_width = fx_structure->src_texture->GetWidth ();
02488     int quad_height = fx_structure->src_texture->GetHeight ();
02489 
02490     num_pass = Clamp<int> (num_pass, 1, 50);
02491 
02492     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02493     int previous_width = 0;
02494     int previous_height = 0;
02495     if (prevFBO.IsValid ())
02496     {
02497       previous_width = prevFBO->GetWidth ();
02498       previous_height = prevFBO->GetHeight ();
02499     }
02500     else
02501     {
02502       previous_width = _graphics_display.GetWindowWidth ();
02503       previous_height = _graphics_display.GetWindowHeight ();
02504     }
02505 
02506     CHECKGL (glClearColor (0, 0, 0, 0));
02507     fx_structure->src_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02508     fx_structure->src_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
02509     fx_structure->dst_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02510     fx_structure->dst_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
02511     fx_structure->temp_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02512     fx_structure->temp_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
02513 
02514     SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
02515     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02516 
02517     QRP_GLSL_1Tex(x, y, quad_width, quad_height, fx_structure->src_texture, texxform, color::White);
02518 
02519     TexCoordXForm texxform1;
02520     for (int i = 0; i < num_pass; i++)
02521     {
02522       SetFrameBufferHelper(_offscreen_fbo, fx_structure->temp_texture, _offscreen_depth_rt1, buffer_width, buffer_height);
02523       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02524       QRP_GLSL_HorizontalHQGauss(0, 0, buffer_width, buffer_height, fx_structure->dst_texture, texxform1, c0, sigma);
02525 
02526       SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
02527       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02528       QRP_GLSL_VerticalHQGauss(0, 0, buffer_width, buffer_height, fx_structure->temp_texture, texxform1, c0, sigma);
02529     }
02530 
02531     _offscreen_fbo->Deactivate();
02532 
02533     if (prevFBO.IsValid ())
02534     {
02535       prevFBO->Activate(true);
02536       SetViewport(0, 0, previous_width, previous_height);
02537     }
02538     else
02539     {
02540       SetViewport(0, 0, previous_width, previous_height);
02541     }
02542   }
02543 
02544   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetDisturbedTexture (
02545       int x, int y, int width, int height,
02546       ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm &texxform0, const Color& c0,
02547       ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm &texxform1, const Color& c1)
02548   {
02549     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02550     int previous_width = 0;
02551     int previous_height = 0;
02552     if (prevFBO.IsValid ())
02553     {
02554       previous_width = prevFBO->GetWidth ();
02555       previous_height = prevFBO->GetHeight ();
02556     }
02557     else
02558     {
02559       previous_width = _graphics_display.GetWindowWidth ();
02560       previous_height = _graphics_display.GetWindowHeight ();
02561     }
02562 
02563     CHECKGL(glClearColor(0, 0, 0, 0));
02564     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, width, height);
02565     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02566 
02567     QRP_GLSL_DisturbedTexture(x, y, width, height,
02568       distorsion_texture, texxform0, c0,
02569       src_device_texture, texxform1, c1);
02570 
02571     _offscreen_fbo->Deactivate();
02572 
02573     if (prevFBO.IsValid())
02574     {
02575       prevFBO->Activate(true);
02576       SetViewport(0, 0, previous_width, previous_height);
02577     }
02578     else
02579     {
02580       SetViewport(0, 0, previous_width, previous_height);
02581     }
02582 
02583     return _offscreen_color_rt0;
02584   }
02585 
02586   void GraphicsEngine::QRP_GLSL_GetDisturbedTextureFx(
02587     int x, int y, int width, int height,
02588     ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm &texxform0, const Color& c0,
02589     FxStructure *fx_structure, TexCoordXForm &texxform1, const Color& c1)
02590   {
02591     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02592     int previous_width = 0;
02593     int previous_height = 0;
02594     if (prevFBO.IsValid ())
02595     {
02596       previous_width = prevFBO->GetWidth ();
02597       previous_height = prevFBO->GetHeight ();
02598     }
02599     else
02600     {
02601       previous_width = _graphics_display.GetWindowWidth ();
02602       previous_height = _graphics_display.GetWindowHeight ();
02603     }
02604 
02605     CHECKGL(glClearColor(0, 0, 0, 0));
02606     SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, width, height);
02607     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02608 
02609     QRP_GLSL_DisturbedTexture(x, y, width, height,
02610       distorsion_texture, texxform0, c0,
02611       fx_structure->src_texture, texxform1, c1);
02612 
02613     _offscreen_fbo->Deactivate();
02614 
02615     if (prevFBO.IsValid())
02616     {
02617       prevFBO->Activate(true);
02618       SetViewport(0, 0, previous_width, previous_height);
02619     }
02620     else
02621     {
02622       SetViewport(0, 0, previous_width, previous_height);
02623     }
02624   }
02625 
02626   void GraphicsEngine::InitSlPixelateShader ()
02627   {
02628     ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
02629     ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
02630     NString VSString;
02631     NString PSString;
02632 
02633     VSString =  TEXT ("#version 110   \n\
02634                       attribute vec4 AVertex;                                 \n\
02635                       attribute vec4 MyTextureCoord0;                         \n\
02636                       attribute vec4 VertexColor;                             \n\
02637                       uniform mat4 ViewProjectionMatrix;                      \n\
02638                       varying vec4 varyTexCoord0;                             \n\
02639                       varying vec4 varyVertexColor;                           \n\
02640                       void main()                                             \n\
02641                       {                                                       \n\
02642                       gl_Position =  ViewProjectionMatrix * (AVertex);        \n\
02643                       varyTexCoord0 = MyTextureCoord0;                        \n\
02644                       varyVertexColor = VertexColor;                          \n\
02645                       }");
02646 
02647     PSString =  TEXT ("#version 110                                               \n\
02648                       #extension GL_ARB_texture_rectangle : enable                \n\
02649                       varying vec4 varyTexCoord0;                                 \n\
02650                       varying vec4 varyVertexColor;                               \n\
02651                       uniform vec4 pixel_size;                                    \n\
02652                       uniform vec4 pixel_size_inv;                                \n\
02653                       #ifdef SAMPLERTEX2D                                         \n\
02654                       uniform sampler2D TextureObject0;                           \n\
02655                       vec4 SampleTexture(sampler2D TexObject, vec4 TexCoord)      \n\
02656                       {                                                           \n\
02657                         return texture2D(TexObject, TexCoord.st);                 \n\
02658                       }                                                           \n\
02659                       #elif defined SAMPLERTEX2DRECT                              \n\
02660                       uniform sampler2DRect TextureObject0;                       \n\
02661                       vec4 SampleTexture(sampler2DRect TexObject, vec4 TexCoord)  \n\
02662                       {                                                           \n\
02663                         return texture2DRect(TexObject, TexCoord.st);             \n\
02664                       }                                                           \n\
02665                       #endif                                                      \n\
02666                       void main()                                                 \n\
02667                       {                                                           \n\
02668                         vec4 tex_coord = floor(varyTexCoord0 * pixel_size_inv) * pixel_size;          \n\
02669                         vec4 v = SampleTexture(TextureObject0, tex_coord);        \n\
02670                         gl_FragColor = v*varyVertexColor;                         \n\
02671                       }");
02672 
02673     // Textured 2D Primitive Shader
02674     m_SLPixelate = _graphics_display.m_DeviceFactory->CreateShaderProgram();
02675     VS->SetShaderCode (TCHAR_TO_ANSI (*VSString) );
02676     PS->SetShaderCode (TCHAR_TO_ANSI (*PSString), TEXT ("#define SAMPLERTEX2D") );
02677 
02678     m_SLPixelate->ClearShaderObjects();
02679     m_SLPixelate->AddShaderObject (VS);
02680     m_SLPixelate->AddShaderObject (PS);
02681     CHECKGL ( glBindAttribLocation (m_SLPixelate->GetOpenGLID(), 0, "AVertex") );
02682     m_SLPixelate->Link();
02683   }
02684 
02685   void GraphicsEngine::QRP_GLSL_Pixelate (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm &texxform0, const Color &color0, int pixel_size)
02686   {
02687     NUX_RETURN_IF_FALSE (m_SLPixelate.IsValid ());
02688 
02689     m_quad_tex_stats++;
02690     QRP_Compute_Texture_Coord (width, height, DeviceTexture, texxform0);
02691     float fx = x, fy = y;
02692     float VtxBuffer[] =
02693     {
02694       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
02695       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
02696       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
02697       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
02698     };
02699 
02700     float tex_width = DeviceTexture->GetWidth ();
02701     float tex_height = DeviceTexture->GetHeight ();
02702 
02703     ObjectPtr<IOpenGLShaderProgram> ShaderProg;
02704     ShaderProg = m_SLPixelate;
02705 
02706     CHECKGL (glBindBufferARB (GL_ARRAY_BUFFER_ARB, 0));
02707     CHECKGL (glBindBufferARB (GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
02708     ShaderProg->Begin();
02709 
02710     int TextureObjectLocation = ShaderProg->GetUniformLocationARB ("TextureObject0");
02711     int PixelSizeLocation = ShaderProg->GetUniformLocationARB ("pixel_size");
02712     int PixelSizeInvLocation = ShaderProg->GetUniformLocationARB ("pixel_size_inv");
02713     int VertexLocation = ShaderProg->GetAttributeLocation ("AVertex");
02714     int TextureCoord0Location = ShaderProg->GetAttributeLocation ("MyTextureCoord0");
02715     int VertexColorLocation = ShaderProg->GetAttributeLocation ("VertexColor");
02716 
02717     SetTexture (GL_TEXTURE0, DeviceTexture);
02718     CHECKGL ( glUniform1iARB (TextureObjectLocation, 0) );
02719 
02720     int     VPMatrixLocation = ShaderProg->GetUniformLocationARB ("ViewProjectionMatrix");
02721     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
02722     ShaderProg->SetUniformLocMatrix4fv ((GLint) VPMatrixLocation, 1, false, (GLfloat *) & (MVPMatrix.m));
02723 
02724     ShaderProg->SetUniform4f ((GLint) PixelSizeLocation, (float)pixel_size / (float)tex_width, (float)pixel_size / (float)tex_height, 1.0f, 1.0f);
02725     ShaderProg->SetUniform4f ((GLint) PixelSizeInvLocation, (float)tex_width / (float)pixel_size, (float)tex_height / (float)pixel_size, 1.0f, 1.0f);
02726 
02727     CHECKGL (glEnableVertexAttribArrayARB (VertexLocation));
02728     CHECKGL (glVertexAttribPointerARB ((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
02729 
02730     if (TextureCoord0Location != -1)
02731     {
02732       CHECKGL (glEnableVertexAttribArrayARB (TextureCoord0Location));
02733       CHECKGL (glVertexAttribPointerARB ((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
02734     }
02735 
02736     if (VertexColorLocation != -1)
02737     {
02738       CHECKGL ( glEnableVertexAttribArrayARB (VertexColorLocation));
02739       CHECKGL ( glVertexAttribPointerARB ((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8) );
02740     }
02741 
02742     CHECKGL ( glDrawArrays (GL_TRIANGLE_FAN, 0, 4) );
02743 
02744     CHECKGL ( glDisableVertexAttribArrayARB (VertexLocation) );
02745 
02746     if (TextureCoord0Location != -1)
02747       CHECKGL ( glDisableVertexAttribArrayARB (TextureCoord0Location) );
02748 
02749     if (VertexColorLocation != -1)
02750       CHECKGL ( glDisableVertexAttribArrayARB (VertexColorLocation) );
02751 
02752     ShaderProg->End();
02753   }
02754 
02755   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_GLSL_GetPixelBlocks (
02756     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color& c0, int pixel_size)
02757   {
02758     int quad_width = device_texture->GetWidth ();
02759     int quad_height = device_texture->GetHeight ();
02760 
02761     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject ();
02762     int previous_width = 0;
02763     int previous_height = 0;
02764     if (prevFBO.IsValid ())
02765     {
02766       previous_width = prevFBO->GetWidth ();
02767       previous_height = prevFBO->GetHeight ();
02768     }
02769     else
02770     {
02771       previous_width = _graphics_display.GetWindowWidth ();
02772       previous_height = _graphics_display.GetWindowHeight ();
02773     }
02774 
02775     CHECKGL(glClearColor(0, 0, 0, 0));
02776     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02777     CHECKGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
02778     QRP_GLSL_Pixelate(0, 0, quad_width, quad_height, device_texture, texxform0, color::White, pixel_size);
02779 
02780     _offscreen_fbo->Deactivate();
02781 
02782     if (prevFBO.IsValid())
02783     {
02784       prevFBO->Activate(true);
02785       SetViewport(0, 0, previous_width, previous_height);
02786     }
02787     else
02788     {
02789       SetViewport(0, 0, previous_width, previous_height);
02790     }
02791     return _offscreen_color_rt0;
02792   }
02793 
02794   void GraphicsEngine::QRP_GLSL_GetCopyTexture(
02795     int width, int height,
02796     ObjectPtr<IOpenGLBaseTexture>& dst_device_texture,
02797     ObjectPtr<IOpenGLBaseTexture>& src_device_texture,
02798     TexCoordXForm &texxform0, const Color& c0)
02799   {
02800     if (src_device_texture.IsValid() == false)
02801     {
02802       return;
02803     }
02804 
02805     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02806     int previous_width = 0;
02807     int previous_height = 0;
02808     
02809     if (prevFBO.IsValid())
02810     {
02811       previous_width = prevFBO->GetWidth();
02812       previous_height = prevFBO->GetHeight();
02813     }
02814     else
02815     {
02816       previous_width = _graphics_display.GetWindowWidth();
02817       previous_height = _graphics_display.GetWindowHeight();
02818     }
02819 
02820     if ((dst_device_texture.IsValid() == false) ||
02821       (dst_device_texture->GetWidth() != width) ||
02822       (dst_device_texture->GetHeight() != height) ||
02823       (dst_device_texture->GetPixelFormat() != src_device_texture->GetPixelFormat()))
02824     {
02825       dst_device_texture = _graphics_display.GetGpuDevice()->CreateTexture(width, height, 1, src_device_texture->GetPixelFormat());
02826     }
02827 
02828     CHECKGL(glClearColor(0, 0, 0, 0));
02829     ObjectPtr<IOpenGLBaseTexture> depth_buffer(NULL);
02830     SetFrameBufferHelper(_offscreen_fbo, dst_device_texture, depth_buffer, width, height);
02831     CHECKGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
02832 
02833     QRP_GLSL_1Tex(0, 0, width, height, src_device_texture, texxform0, c0);
02834 
02835     _offscreen_fbo->Deactivate();
02836 
02837     if (prevFBO.IsValid())
02838     {
02839       prevFBO->Activate(true);
02840       SetViewport(0, 0, previous_width, previous_height);
02841     }
02842     else
02843     {
02844       SetViewport(0, 0, previous_width, previous_height);
02845     }
02846   }
02847 
02848 }
02849 
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends