Back to index

nux  3.0.0
RenderingPipeTextureBlend.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010-2012 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  *              Robert Carr <racarr@canonical.com>
00020  */
00021 
00022 
00023 #include "NuxCore/NuxCore.h"
00024 #include "ImageSurface.h"
00025 #include "GpuDevice.h"
00026 #include "GLDeviceObjects.h"
00027 #include "GLResourceManager.h"
00028 #include "GLTextureResourceManager.h"
00029 #include "GLVertexResourceManager.h"
00030 #include "GraphicsEngine.h"
00031 
00032 #include "RenderingPipeTextureBlendShaderSource.h"
00033 
00034 namespace nux
00035 {
00036   const char* const
00037   GraphicsEngine::GetBlendModeBlendFunc(LayerBlendMode layer_blend_mode)
00038   {
00039     switch (layer_blend_mode)
00040       {
00041       case LAYER_BLEND_MODE_NORMAL:
00042        return BlendNormalShader;
00043         break;
00044       case LAYER_BLEND_MODE_OVERLAY:
00045        return BlendOverlayShader;
00046        break;
00047        
00048       default:
00049        return NULL;
00050       }
00051   }
00052 
00053 const char* const
00054 GraphicsEngine::GetBlendModeString(LayerBlendMode layer_blend_mode)
00055 {
00056   switch (layer_blend_mode)
00057     {
00058     case LAYER_BLEND_MODE_NORMAL:
00059       return "BlendNormal";
00060       break;
00061     case LAYER_BLEND_MODE_OVERLAY:
00062       return "BlendOverlay";
00063       break;
00064     default:
00065       return NULL;
00066     }
00067 }
00068 
00069 ObjectPtr<IOpenGLShaderProgram> GraphicsEngine::GetColorBlendOverTexProgram(LayerBlendMode layer_blend_mode)
00070 {
00071   if (blend_tex_color_prog_[layer_blend_mode].IsValid())
00072   {
00073     return blend_tex_color_prog_[layer_blend_mode];
00074   }
00075   
00076   ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00077   ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00078   
00079   NString VSString;
00080   NString PSString;
00081   
00082   VSString =
00083                     NUX_VERTEX_SHADER_HEADER
00084                     "attribute vec4 AVertex;                                 \n\
00085                     attribute vec4 MyTextureCoord0;                          \n\
00086                     attribute vec4 VertexColor;                              \n\
00087                     uniform mat4 ViewProjectionMatrix;                       \n\
00088                     varying vec4 varyTexCoord0;                              \n\
00089                     varying vec4 varyVertexColor;                            \n\
00090                     void main()                                              \n\
00091                     {                                                        \n\
00092                       gl_Position =  ViewProjectionMatrix*  (AVertex);       \n\
00093                       varyTexCoord0 = MyTextureCoord0;                       \n\
00094                       varyVertexColor = VertexColor;                         \n\
00095                     }";
00096 
00097   PSString =
00098                     NUX_FRAGMENT_SHADER_HEADER
00099                     "uniform vec4 color0;                                           \n\
00100                     uniform sampler2D TextureObject0;                               \n\
00101                     varying vec4 varyTexCoord0;                                     \n\
00102                     varying vec4 varyVertexColor;                                   \n\
00103                     %s                                                              \n\
00104                     void main()                                                     \n\
00105                     {                                                               \n\
00106                       vec4 tex = texture2D(TextureObject0, varyTexCoord0.st)*varyVertexColor;       \n\
00107                       gl_FragColor.rgb = mix(tex.rgb,%s(tex.rgb,color0.rgb),color0.a);  \n\
00108                       gl_FragColor.a = 1.0;                                         \n\
00109                     }";
00110 
00111     int l = PSString.Size();
00112     l += strlen(GetBlendModeBlendFunc(layer_blend_mode));
00113     l += strlen(GetBlendModeString(layer_blend_mode)) + 1;
00114     
00115     char* shader_prog = new char[l];
00116     sprintf(shader_prog, PSString.GetTCharPtr(), GetBlendModeBlendFunc(layer_blend_mode),
00117            GetBlendModeString(layer_blend_mode));
00118     
00119     blend_tex_color_prog_[layer_blend_mode] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00120     VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
00121     PS->SetShaderCode(shader_prog, "#define SAMPLERTEX2D");
00122     
00123     delete [] shader_prog;
00124     
00125     blend_tex_color_prog_[layer_blend_mode]->ClearShaderObjects();
00126     blend_tex_color_prog_[layer_blend_mode]->AddShaderObject(VS);
00127     blend_tex_color_prog_[layer_blend_mode]->AddShaderObject(PS);
00128     CHECKGL(glBindAttribLocation(blend_tex_color_prog_[layer_blend_mode]->GetOpenGLID(), 0, "AVertex"));
00129     blend_tex_color_prog_[layer_blend_mode]->Link();
00130     
00131     return blend_tex_color_prog_[layer_blend_mode];    
00132 }
00133 
00134   ObjectPtr<IOpenGLShaderProgram> GraphicsEngine::GetTexBlendOverColorProgram(LayerBlendMode layer_blend_mode)
00135 {
00136   if (blend_color_tex_prog_[layer_blend_mode].IsValid())
00137   {
00138     return blend_color_tex_prog_[layer_blend_mode];
00139   }
00140   
00141   ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00142   ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00143   
00144   NString VSString;
00145   NString PSString;
00146   
00147   VSString =
00148                 NUX_VERTEX_SHADER_HEADER
00149                 "attribute vec4 AVertex;                               \n\
00150                 attribute vec4 MyTextureCoord0;                        \n\
00151                 attribute vec4 VertexColor;                            \n\
00152                 uniform mat4 ViewProjectionMatrix;                     \n\
00153                 varying vec4 varyTexCoord0;                            \n\
00154                 varying vec4 varyVertexColor;                          \n\
00155                 void main()                                            \n\
00156                 {                                                      \n\
00157                   gl_Position =  ViewProjectionMatrix * (AVertex);     \n\
00158                   varyTexCoord0 = MyTextureCoord0;                     \n\
00159                   varyVertexColor = VertexColor;                       \n\
00160                 }";
00161 
00162     PSString =  
00163                 NUX_FRAGMENT_SHADER_HEADER
00164                 "uniform vec3 color0;                                       \n\
00165                 uniform float BlendOpacity;                                 \n\
00166                 uniform sampler2D TextureObject0;                           \n\
00167                 varying vec4 varyTexCoord0;                                 \n\
00168                 varying vec4 varyVertexColor;                               \n\
00169                 %s                                                          \n\
00170                 void main()                                                 \n\
00171                 {                                                           \n\
00172                   vec4 tex = texture2D(TextureObject0, varyTexCoord0.st) * varyVertexColor;     \n\
00173                   gl_FragColor.rgb = mix(color0,%s(color0.rgb,tex.rgb),tex.a);  \n\
00174                   gl_FragColor.a = 1.0;                                     \n\
00175                 }";
00176 
00177     int l = PSString.Size();
00178     l += strlen(GetBlendModeBlendFunc(layer_blend_mode));
00179     l += strlen(GetBlendModeString(layer_blend_mode)) + 1;
00180     
00181     char* shader_prog = new char[l];
00182     sprintf(shader_prog, PSString.GetTCharPtr(), GetBlendModeBlendFunc(layer_blend_mode),
00183            GetBlendModeString(layer_blend_mode));
00184     
00185     blend_color_tex_prog_[layer_blend_mode] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00186     VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
00187     PS->SetShaderCode(shader_prog, "#define SAMPLERTEX2D");
00188     
00189     delete [] shader_prog;
00190     
00191     blend_color_tex_prog_[layer_blend_mode]->ClearShaderObjects();
00192     blend_color_tex_prog_[layer_blend_mode]->AddShaderObject(VS);
00193     blend_color_tex_prog_[layer_blend_mode]->AddShaderObject(PS);
00194     CHECKGL(glBindAttribLocation(blend_color_tex_prog_[layer_blend_mode]->GetOpenGLID(), 0, "AVertex"));
00195     blend_color_tex_prog_[layer_blend_mode]->Link();
00196     
00197     return blend_color_tex_prog_[layer_blend_mode];
00198 }
00199 
00200 ObjectPtr<IOpenGLShaderProgram> GraphicsEngine::GetBlendTexTexProgram(LayerBlendMode layer_blend_mode)
00201 {
00202   if (blend_tex_tex_prog_[layer_blend_mode].IsValid())
00203   {
00204     return blend_tex_tex_prog_[layer_blend_mode];
00205   }
00206 
00207   ObjectPtr<IOpenGLVertexShader> VS = _graphics_display.m_DeviceFactory->CreateVertexShader();
00208   ObjectPtr<IOpenGLPixelShader> PS = _graphics_display.m_DeviceFactory->CreatePixelShader();
00209   
00210   NString VSString;
00211   NString PSString;
00212 
00213     VSString =      NUX_VERTEX_SHADER_HEADER
00214                     "uniform mat4 ViewProjectionMatrix;                     \n\
00215                     attribute vec4 AVertex;                                 \n\
00216                     attribute vec4 MyTextureCoord0;                         \n\
00217                     attribute vec4 MyTextureCoord1;                         \n\
00218                     varying vec4 varyTexCoord0;                             \n\
00219                     varying vec4 varyTexCoord1;                             \n\
00220                     void main()                                             \n\
00221                     {                                                       \n\
00222                       varyTexCoord0 = MyTextureCoord0;                      \n\
00223                       varyTexCoord1 = MyTextureCoord1;                      \n\
00224                       gl_Position =  ViewProjectionMatrix * (AVertex);      \n\
00225                     }";
00226   
00227     PSString =      NUX_FRAGMENT_SHADER_HEADER
00228                     "varying vec4 varyTexCoord0;                                \n\
00229                     varying vec4 varyTexCoord1;                                 \n\
00230                     uniform vec4 color0;                                        \n\
00231                     uniform vec4 color1;                                        \n\
00232                     uniform sampler2D TextureObject0;                           \n\
00233                     uniform sampler2D TextureObject1;                           \n\
00234                     %s                                                          \n\
00235                     void main()                                                 \n\
00236                     {                                                           \n\
00237                       vec4 bkg_tex = color0*texture2D(TextureObject0, varyTexCoord0.st);     \n\
00238                       vec4 frg_tex = color1*texture2D(TextureObject1, varyTexCoord1.st);     \n\
00239                       gl_FragColor = %s(bkg_tex.rgb, frg_tex.rgb);              \n\
00240                     }";
00241 
00242     int l = PSString.Size();
00243     l += strlen(GetBlendModeBlendFunc(layer_blend_mode));
00244     l += strlen(GetBlendModeString(layer_blend_mode)) + 1;
00245     
00246     char* shader_prog = new char[l];
00247     sprintf(shader_prog, PSString.GetTCharPtr(), GetBlendModeBlendFunc(layer_blend_mode),
00248            GetBlendModeString(layer_blend_mode));
00249     
00250     blend_tex_tex_prog_[layer_blend_mode] = _graphics_display.m_DeviceFactory->CreateShaderProgram();
00251     VS->SetShaderCode(TCHAR_TO_ANSI(*VSString));
00252     PS->SetShaderCode(shader_prog, "#define SAMPLERTEX2D");
00253     
00254     delete [] shader_prog;
00255     
00256     blend_tex_tex_prog_[layer_blend_mode]->ClearShaderObjects();
00257     blend_tex_tex_prog_[layer_blend_mode]->AddShaderObject(VS);
00258     blend_tex_tex_prog_[layer_blend_mode]->AddShaderObject(PS);
00259     CHECKGL(glBindAttribLocation(blend_tex_tex_prog_[layer_blend_mode]->GetOpenGLID(), 0, "AVertex"));
00260     blend_tex_tex_prog_[layer_blend_mode]->Link();
00261     
00262     return blend_tex_tex_prog_[layer_blend_mode];    
00263 }
00264 
00265 void GraphicsEngine::QRP_GLSL_ColorBlendOverTex(int x, int y, int width, int height,
00266           ObjectPtr<IOpenGLBaseTexture> bkg_device_texture, TexCoordXForm& texxform, const Color& color0,
00267           const Color& foreground_color,
00268           LayerBlendMode layer_blend_mode)
00269 {
00270   if (!UsingGLSLCodePath())
00271     return;
00272 
00273     ObjectPtr<IOpenGLShaderProgram> ShaderProg = GetColorBlendOverTexProgram(layer_blend_mode);
00274 
00275     m_quad_tex_stats++;
00276     QRP_Compute_Texture_Coord(width, height, bkg_device_texture, texxform);
00277     float fx = x, fy = y;
00278     float VtxBuffer[] =
00279     {
00280       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00281       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00282       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00283       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00284     };
00285     
00286     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00287     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00288     ShaderProg->Begin();
00289 
00290     int TextureObjectLocation = ShaderProg->GetUniformLocationARB("TextureObject0");
00291     int BlendColorLocation = ShaderProg->GetUniformLocationARB("color0");
00292     int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
00293     int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0"); 
00294     int VertexColorLocation = ShaderProg->GetAttributeLocation("VertexColor");
00295 
00296     SetTexture(GL_TEXTURE0, bkg_device_texture);
00297     CHECKGL(glUniform1iARB(TextureObjectLocation, 0));
00298     
00299     int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
00300     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
00301     ShaderProg->SetUniformLocMatrix4fv((GLint) VPMatrixLocation, 1, false, (GLfloat*) & (MVPMatrix.m));
00302 
00303     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00304     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00305 
00306     if (TextureCoord0Location != -1)
00307     {
00308       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00309       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00310     }
00311 
00312     if (VertexColorLocation != -1)
00313     {
00314       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
00315       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00316     }
00317     
00318     if (BlendColorLocation != -1)
00319     {
00320       CHECKGL(glUniform4fARB(BlendColorLocation, foreground_color.red, foreground_color.green, foreground_color.blue, foreground_color.alpha));
00321     }
00322 
00323     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00324 
00325     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00326 
00327     if (TextureCoord0Location != -1)
00328       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00329 
00330     if (VertexColorLocation != -1)
00331       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
00332 
00333     ShaderProg->End();;
00334 }
00335 
00336 void GraphicsEngine::QRP_GLSL_TexBlendOverColor(int x, int y, int width, int height,
00337           const Color& background_color,
00338           ObjectPtr<IOpenGLBaseTexture> frg_device_texture, TexCoordXForm& texxform0, const Color& color0,
00339           LayerBlendMode layer_blend_mode)
00340 {
00341   if (!UsingGLSLCodePath())
00342     return;
00343 
00344     ObjectPtr<IOpenGLShaderProgram> ShaderProg = GetTexBlendOverColorProgram(layer_blend_mode);
00345 
00346     m_quad_tex_stats++;
00347     QRP_Compute_Texture_Coord(width, height, frg_device_texture, texxform0);
00348     float fx = x, fy = y;
00349     float VtxBuffer[] =
00350     {
00351       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00352       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00353       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00354       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0, 0, color0.red, color0.green, color0.blue, color0.alpha,
00355     };
00356 
00357     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00358     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00359     ShaderProg->Begin();
00360 
00361     int TextureObjectLocation = ShaderProg->GetUniformLocationARB("TextureObject0");
00362     int BlendColorLocation    = ShaderProg->GetUniformLocationARB("color0");
00363     int VertexLocation        = ShaderProg->GetAttributeLocation("AVertex");
00364     int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0"); 
00365     int VertexColorLocation   = ShaderProg->GetAttributeLocation("VertexColor");
00366     int OpacityLocation       = ShaderProg->GetUniformLocationARB("BlendOpacity");
00367 
00368     SetTexture(GL_TEXTURE0, frg_device_texture);
00369     CHECKGL(glUniform1iARB(TextureObjectLocation, 0));
00370 
00371     int VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
00372     Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
00373     ShaderProg->SetUniformLocMatrix4fv((GLint) VPMatrixLocation, 1, false, (GLfloat*) & (MVPMatrix.m));
00374 
00375     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00376     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00377 
00378     if (TextureCoord0Location != -1)
00379     {
00380       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00381       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00382     }
00383 
00384     if (VertexColorLocation != -1)
00385     {
00386       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
00387       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00388     }
00389 
00390     if (BlendColorLocation != -1)
00391     {
00392       CHECKGL(glUniform3fARB(BlendColorLocation, background_color.red, background_color.green, background_color.blue));
00393     } 
00394     if (OpacityLocation != -1)
00395     {
00396       CHECKGL(glUniform1fARB(OpacityLocation, background_color.alpha));
00397     }
00398 
00399     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00400 
00401     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00402 
00403     if (TextureCoord0Location != -1)
00404       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00405 
00406     if (VertexColorLocation != -1)
00407       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
00408 
00409     ShaderProg->End();
00410 }
00411 
00412 void GraphicsEngine::QRP_GLSL_TexBlendOverTex(int x, int y, int width, int height,
00413           ObjectPtr<IOpenGLBaseTexture> bkg_device_texture, TexCoordXForm& texxform0, const Color& color0,
00414           ObjectPtr<IOpenGLBaseTexture> frg_device_texture, TexCoordXForm& texxform1, const Color& color1,
00415           LayerBlendMode layer_blend_mode)
00416 {
00417   if (!UsingGLSLCodePath())
00418     return;
00419 
00420   ObjectPtr <IOpenGLShaderProgram> ShaderProg = GetBlendTexTexProgram(layer_blend_mode);
00421   QRP_Compute_Texture_Coord(width, height, bkg_device_texture, texxform0);
00422   QRP_Compute_Texture_Coord(width, height, frg_device_texture, texxform1);
00423 
00424   float fx = x, fy = y;
00425   float VtxBuffer[] =
00426   {
00427     fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
00428     fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
00429     fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
00430     fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
00431   };
00432 
00433   CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00434   CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00435   ShaderProg->Begin();
00436 
00437   int TextureObjectLocation0 = ShaderProg->GetUniformLocationARB("TextureObject0");
00438   int TextureObjectLocation1 = ShaderProg->GetUniformLocationARB("TextureObject1");
00439   int VertexLocation = ShaderProg->GetAttributeLocation("AVertex");
00440   int TextureCoord0Location = ShaderProg->GetAttributeLocation("MyTextureCoord0");
00441   int TextureCoord1Location = ShaderProg->GetAttributeLocation("MyTextureCoord1");
00442   
00443   int TextureCoef0Location = ShaderProg->GetUniformLocationARB("color0");
00444   int TextureCoef1Location = ShaderProg->GetUniformLocationARB("color1");
00445 
00446 
00447   SetTexture(GL_TEXTURE0, bkg_device_texture);
00448   SetTexture(GL_TEXTURE1, frg_device_texture);
00449 
00450   CHECKGL(glUniform1iARB(TextureObjectLocation0, 0));
00451   CHECKGL(glUniform1iARB(TextureObjectLocation1, 1));
00452 
00453   CHECKGL(glUniform4fARB(TextureCoef0Location, color0.red, color0.green, color0.blue, color0.alpha ));
00454   CHECKGL(glUniform4fARB(TextureCoef1Location, color1.red, color1.green, color1.blue, color1.alpha ));
00455 
00456   int     VPMatrixLocation = ShaderProg->GetUniformLocationARB("ViewProjectionMatrix");
00457   Matrix4 MVPMatrix = GetOpenGLModelViewProjectionMatrix();
00458   ShaderProg->SetUniformLocMatrix4fv((GLint) VPMatrixLocation, 1, false, (GLfloat*) & (MVPMatrix.m));
00459 
00460   CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00461   CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00462 
00463   if (TextureCoord0Location != -1)
00464   {
00465     CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00466     CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00467   }
00468 
00469   if (TextureCoord1Location != -1)
00470   {
00471     CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
00472     CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00473   }
00474 
00475   CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00476 
00477   CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00478 
00479   if (TextureCoord0Location != -1)
00480     CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00481 
00482   if (TextureCoord1Location != -1)
00483     CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
00484 
00485   ShaderProg->End();
00486 }
00487 
00488 }
00489