Back to index

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