Back to index

nux  3.0.0
RenderingPipeAsm.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 #ifndef NUX_OPENGLES_20
00023 
00024 #include "GLResource.h"
00025 #include "IOpenGLBaseTexture.h"
00026 #include "RenderingPipe.h"
00027 #include "GraphicsEngine.h"
00028 
00029 namespace nux
00030 {
00031 
00032 // Conventional Attribute Binding      Generic Attribute Binding
00033 // ------------------------------      -------------------------
00034 // vertex.position                     vertex.attrib[0]
00035 // vertex.weight                       vertex.attrib[1]
00036 // vertex.weight[0]                    vertex.attrib[1]
00037 // vertex.normal                       vertex.attrib[2]
00038 // vertex.color                        vertex.attrib[3]
00039 // vertex.color.primary                vertex.attrib[3]
00040 // vertex.color.secondary              vertex.attrib[4]
00041 // vertex.fogcoord                     vertex.attrib[5]
00042 // vertex.texcoord                     vertex.attrib[8]
00043 // vertex.texcoord[0]                  vertex.attrib[8]
00044 // vertex.texcoord[1]                  vertex.attrib[9]
00045 // vertex.texcoord[2]                  vertex.attrib[10]
00046 // vertex.texcoord[3]                  vertex.attrib[11]
00047 // vertex.texcoord[4]                  vertex.attrib[12]
00048 // vertex.texcoord[5]                  vertex.attrib[13]
00049 // vertex.texcoord[6]                  vertex.attrib[14]
00050 // vertex.texcoord[7]                  vertex.attrib[15]
00051 // vertex.texcoord[n]                  vertex.attrib[8+n]
00052 
00053 // # Vertex Attribute Registers
00054 // # attribute Register                Components      Underlying State
00055 // # vertex.position                   (x,y,z,w)       object position
00056 // # vertex.weight                     (w,w,w,w)       vertex weights 0-3
00057 // # vertex.weight[n]                  (w,w,w,w)       vertex weights n-n+3
00058 // # vertex.normal                     (x,y,z,1)       NORMAL
00059 // # vertex.color                      (r,g,b,a)       primary color
00060 // # vertex.color.primary              (r,g,b,a)       primary color
00061 // # vertex.color.secondary            (r,g,b,a)       secondary color
00062 // # vertex.fogcoord                   (f,0,0,1)       fog coordinate
00063 // # vertex.texcoord                   (s,t,r,q)       texture coordinate, unit 0
00064 // # vertex.texcoord[n]                (s,t,r,q)       texture coordinate, unit n
00065 // # vertex.matrixindex                (i,i,i,i)       vertex matrix indices 0-3
00066 // # vertex.matrixindex[n]             (i,i,i,i)       vertex matrix indices n-n+3
00067 // # vertex.attrib[n]                  (x,y,z,w)       generic vertex attribute n
00068 //
00069 //
00070 // # Result Register                   Components      Description
00071 // # result.position                   (x,y,z,w)       position in clip coordinates
00072 // # result.color                      (r,g,b,a)       front-facing, primary color
00073 // # result.color.primary              (r,g,b,a)       front-facing, primary color
00074 // # result.color.front                (r,g,b,a)       front-facing, primary color
00075 // # result.color.front.primary        (r,g,b,a)       front-facing, primary color
00076 // # result.color.front.secondary      (r,g,b,a)       front-facing, secondary color
00077 // # result.color.back                 (r,g,b,a)       back-facing, primary color
00078 // # result.color.back.primary         (r,g,b,a)       back-facing, primary color
00079 // # result.color.back.secondary       (r,g,b,a)       back-facing, secondary color
00080 // # result.fogcoord                   (f,*,*,*)       fog coordinate
00081 // # result.pointsize                  (s,*,*,*)       point size
00082 // # result.texcoord                   (s,t,r,q)       texture coordinate, unit 0
00083 // # result.color.secondary            (r,g,b,a)       front-facing, secondary color
00084 // # result.texcoord[n]                (s,t,r,q)       texture coordinate, unit n
00085 
00086 // # Fragment Attribute Binding  Components  Underlying State
00087 // # --------------------------  ----------  ----------------------------
00088 // # fragment.color              (r,g,b,a)   primary color
00089 // # fragment.color.primary      (r,g,b,a)   primary color
00090 // # fragment.color.secondary    (r,g,b,a)   secondary color
00091 // # fragment.texcoord           (s,t,r,q)   texture coordinate, unit 0
00092 // # fragment.texcoord[n]        (s,t,r,q)   texture coordinate, unit n
00093 // # fragment.fogcoord           (f,0,0,1)   fog distance/coordinate
00094 // # fragment.position           (x,y,z,1/w) window position
00095 
00096 
00097 // # Fragment Program Results       Components  Description
00098 // # -----------------------------  ----------  ----------------------------
00099 // # result.color                   (r,g,b,a)   color
00100 // # result.depth                   (*,*,d,*)   depth coordinate
00101 
00102 
00103   void GraphicsEngine::InitAsmColorShader()
00104   {
00105     NString AsmVtx = 
00106         "!!ARBvp1.0                                 \n\
00107         ATTRIB iPos         = vertex.position;      \n\
00108         ATTRIB iColor       = vertex.attrib[3];     \n\
00109         PARAM  mvp[4]       = {state.matrix.mvp};   \n\
00110         OUTPUT oPos         = result.position;      \n\
00111         OUTPUT oColor       = result.color;         \n\
00112         # Transform the vertex to clip coordinates. \n\
00113         DP4   oPos.x, mvp[0], iPos;      \n\
00114         DP4   oPos.y, mvp[1], iPos;      \n\
00115         DP4   oPos.z, mvp[2], iPos;      \n\
00116         DP4   oPos.w, mvp[3], iPos;      \n\
00117         MOV   oColor, iColor;            \n\
00118         END";
00119 
00120     NString AsmFrg = 
00121         "!!ARBfp1.0                                     \n\
00122         MOV result.color, fragment.color;               \n\
00123         END";
00124 
00125     m_AsmColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00126     m_AsmColor->LoadVertexShader(AsmVtx.GetTCharPtr());
00127     m_AsmColor->LoadPixelShader(AsmFrg.GetTCharPtr());
00128     m_AsmColor->Link();
00129   }
00130 
00131   void GraphicsEngine::InitAsmTextureShader()
00132   {
00133     NString AsmVtx = 
00134         "!!ARBvp1.0                                 \n\
00135         ATTRIB iPos         = vertex.position;      \n\
00136         ATTRIB iColor       = vertex.attrib[3];     \n\
00137         PARAM  mvp[4]       = {state.matrix.mvp};   \n\
00138         OUTPUT oPos         = result.position;      \n\
00139         OUTPUT oColor       = result.color;         \n\
00140         OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00141         # Transform the vertex to clip coordinates. \n\
00142         DP4   oPos.x, mvp[0], iPos;                     \n\
00143         DP4   oPos.y, mvp[1], iPos;                     \n\
00144         DP4   oPos.z, mvp[2], iPos;                     \n\
00145         DP4   oPos.w, mvp[3], iPos;                     \n\
00146         MOV   oColor, iColor;                           \n\
00147         MOV   oTexCoord0, vertex.attrib[8];             \n\
00148         END";
00149 
00150     NString AsmFrg = 
00151         "!!ARBfp1.0                                       \n\
00152         TEMP tex0;                                        \n\
00153         TEX tex0, fragment.texcoord[0], texture[0], 2D;   \n\
00154         MUL result.color, fragment.color, tex0;           \n\
00155         END";
00156 
00157     NString AsmFrgRect = 
00158       "!!ARBfp1.0                                       \n\
00159       TEMP tex0;                                        \n\
00160       TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\
00161       MUL result.color, fragment.color, tex0;           \n\
00162       END";
00163 
00164     m_AsmTextureModColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00165     m_AsmTextureModColor->LoadVertexShader(AsmVtx.GetTCharPtr());
00166     m_AsmTextureModColor->LoadPixelShader(AsmFrg.GetTCharPtr());
00167     m_AsmTextureModColor->Link();
00168 
00169     m_AsmTextureRectModColor = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00170     m_AsmTextureRectModColor->LoadVertexShader(AsmVtx.GetTCharPtr());
00171     m_AsmTextureRectModColor->LoadPixelShader(AsmFrgRect.GetTCharPtr());
00172     m_AsmTextureRectModColor->Link();
00173   }
00174 
00175   void GraphicsEngine::InitAsmColorModTexMaskAlpha()
00176   {
00177     NString AsmVtx = 
00178         "!!ARBvp1.0                                 \n\
00179         OUTPUT oPos         = result.position;      \n\
00180         OUTPUT oColor       = result.color;         \n\
00181         OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00182         # Transform the vertex to clip coordinates. \n\
00183         DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
00184         DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
00185         DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
00186         DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
00187         MOV   oColor, vertex.attrib[3];             \n\
00188         MOV   oTexCoord0, vertex.attrib[8];         \n\
00189         END";
00190 
00191     NString AsmFrg = 
00192       "!!ARBfp1.0                                         \n\
00193       TEMP tex0;                                          \n\
00194       TEMP temp;                                          \n\
00195       TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00196       MOV temp, fragment.color;                           \n\
00197       MUL temp.w, fragment.color, tex0.wwww;              \n\
00198       MOV result.color, temp;                             \n\
00199       END";
00200 
00201     NString AsmFrgRect = 
00202       "!!ARBfp1.0                                         \n\
00203       TEMP tex0;                                          \n\
00204       TEMP temp;                                          \n\
00205       TEX tex0, fragment.texcoord[0], texture[0], RECT;   \n\
00206       MOV temp, fragment.color;                           \n\
00207       MUL temp.w, fragment.color, tex0.wwww;              \n\
00208       MOV result.color, temp;                             \n\
00209       END";
00210 
00211     m_AsmColorModTexMaskAlpha = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00212     m_AsmColorModTexMaskAlpha->LoadVertexShader(AsmVtx.GetTCharPtr());
00213     m_AsmColorModTexMaskAlpha->LoadPixelShader(AsmFrg.GetTCharPtr());
00214     m_AsmColorModTexMaskAlpha->Link();
00215 
00216     m_AsmColorModTexRectMaskAlpha = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00217     m_AsmColorModTexRectMaskAlpha->LoadVertexShader(AsmVtx.GetTCharPtr());
00218     m_AsmColorModTexRectMaskAlpha->LoadPixelShader(AsmFrgRect.GetTCharPtr());
00219     m_AsmColorModTexRectMaskAlpha->Link();
00220   }
00221 
00222   void GraphicsEngine::InitAsm2TextureAdd()
00223   {
00224     NString AsmVtx = 
00225         "!!ARBvp1.0                                 \n\
00226         ATTRIB iPos         = vertex.position;      \n\
00227         OUTPUT oPos         = result.position;      \n\
00228         OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00229         OUTPUT oTexCoord1   = result.texcoord[1];   \n\
00230         # Transform the vertex to clip coordinates. \n\
00231         DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
00232         DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
00233         DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
00234         DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
00235         MOV   oTexCoord0, vertex.attrib[8];       \n\
00236         MOV   oTexCoord1, vertex.attrib[9];       \n\
00237         END";
00238 
00239     NString AsmFrg = 
00240         "!!ARBfp1.0                                         \n\
00241         PARAM color0 = program.local[0];                    \n\
00242         PARAM color1 = program.local[1];                    \n\
00243         TEMP tex0;                                          \n\
00244         TEMP tex1;                                          \n\
00245         TEMP temp;                                          \n\
00246         TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00247         MUL temp, color0, tex0;                             \n\
00248         TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00249         MAD temp, color1, tex1, temp;                       \n\
00250         MOV result.color, temp;                             \n\
00251         END";
00252 
00253     NString AsmFrgRect = 
00254       "!!ARBfp1.0                                         \n\
00255       PARAM color0 = program.local[0];                    \n\
00256       PARAM color1 = program.local[1];                    \n\
00257       TEMP tex0;                                          \n\
00258       TEMP tex1;                                          \n\
00259       TEMP temp;                                          \n\
00260       TEX tex0, fragment.texcoord[0], texture[0], RECT;   \n\
00261       MUL temp, color0, tex0;                             \n\
00262       TEX tex1, fragment.texcoord[1], texture[1], RECT;   \n\
00263       MAD temp, color1, tex1, temp;                       \n\
00264       MOV result.color, temp;                             \n\
00265       END";
00266 
00267     m_Asm2TextureAdd = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00268     m_Asm2TextureAdd->LoadVertexShader(AsmVtx.GetTCharPtr());
00269     m_Asm2TextureAdd->LoadPixelShader(AsmFrg.GetTCharPtr());
00270     m_Asm2TextureAdd->Link();
00271 
00272     m_Asm2TextureRectAdd = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00273     m_Asm2TextureRectAdd->LoadVertexShader(AsmVtx.GetTCharPtr());
00274     m_Asm2TextureRectAdd->LoadPixelShader(AsmFrgRect.GetTCharPtr());
00275     m_Asm2TextureRectAdd->Link();
00276   }
00277 
00278   void GraphicsEngine::InitAsm2TextureDepRead()
00279   {
00280     NString AsmVtx = 
00281       "!!ARBvp1.0                                 \n\
00282       ATTRIB iPos         = vertex.position;      \n\
00283       OUTPUT oPos         = result.position;      \n\
00284       OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00285       OUTPUT oTexCoord1   = result.texcoord[1];   \n\
00286       # Transform the vertex to clip coordinates. \n\
00287       DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
00288       DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
00289       DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
00290       DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
00291       MOV   oTexCoord0, vertex.attrib[8];       \n\
00292       MOV   oTexCoord1, vertex.attrib[9];       \n\
00293       END";
00294 
00295     NString AsmFrg = 
00296       "!!ARBfp1.0                                         \n\
00297       PARAM color0 = program.local[0];                    \n\
00298       PARAM color1 = program.local[1];                    \n\
00299       TEMP tex0;                                          \n\
00300       TEMP tex1;                                          \n\
00301       TEMP temp;                                          \n\
00302       TEMP temp0;                                          \n\
00303       TEMP temp1;                                          \n\
00304       TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00305       MAD temp, {2.0, 2.0, 2.0, 2.0}, tex0, {-1.0, -1.0, -1.0, -1.0}; \n\
00306       MUL temp0, color0, temp;                             \n\
00307       ADD temp1, texture[1];                         \n\
00308       TEX tex1, fragment.texcoord[1], texture[1], 2D;           \n\
00309       MUL result.color, color1, tex1;                     \n\
00310       END";
00311 
00312     NString AsmFrgRect = 
00313       "!!ARBfp1.0                                         \n\
00314       PARAM color0 = program.local[0];                    \n\
00315       PARAM color1 = program.local[1];                    \n\
00316       TEMP tex0;                                          \n\
00317       TEMP tex1;                                          \n\
00318       TEMP temp;                                          \n\
00319       TEX tex0, fragment.texcoord[0], texture[0], RECT;   \n\
00320       MAD temp, {2.0, 2.0, 2.0, 2.0}, tex0, {-1.0, -1.0, -1.0, -1.0}; \n\
00321       MUL temp, color0, tex0;                             \n\
00322       TEX tex1, fragment.texcoord[1], temp, RECT;         \n\
00323       MUL result.color, color1, tex1;                     \n\
00324       END";
00325 
00326     m_ASM2TextureDepRead = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00327     m_ASM2TextureDepRead->LoadVertexShader(AsmVtx.GetTCharPtr());
00328     m_ASM2TextureDepRead->LoadPixelShader(AsmFrg.GetTCharPtr());
00329     m_ASM2TextureDepRead->Link();
00330 
00331     m_ASM2TextureRectDepRead = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00332     m_ASM2TextureRectDepRead->LoadVertexShader(AsmVtx.GetTCharPtr());
00333     m_ASM2TextureRectDepRead->LoadPixelShader(AsmFrgRect.GetTCharPtr());
00334     m_ASM2TextureRectDepRead->Link();
00335   }
00336 
00337   void GraphicsEngine::InitAsm2TextureMod()
00338   {
00339     NString AsmVtx = 
00340       "!!ARBvp1.0                                 \n\
00341       ATTRIB iPos         = vertex.position;      \n\
00342       OUTPUT oPos         = result.position;      \n\
00343       OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00344       OUTPUT oTexCoord1   = result.texcoord[1];   \n\
00345       # Transform the vertex to clip coordinates. \n\
00346       DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
00347       DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
00348       DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
00349       DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
00350       MOV   oTexCoord0, vertex.attrib[8];       \n\
00351       MOV   oTexCoord1, vertex.attrib[9];       \n\
00352       END";
00353 
00354     NString AsmFrg = 
00355       "!!ARBfp1.0                                         \n\
00356       PARAM color0 = program.local[0];                    \n\
00357       PARAM color1 = program.local[1];                    \n\
00358       TEMP tex0;                                          \n\
00359       TEMP tex1;                                          \n\
00360       TEMP temp0;                                         \n\
00361       TEMP temp1;                                         \n\
00362       TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00363       MUL temp0, color0, tex0;                            \n\
00364       TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00365       MUL temp1, color1, tex1;                            \n\
00366       MUL result.color, temp0, temp1;                     \n\
00367       END";
00368 
00369     NString AsmFrgRect = 
00370       "!!ARBfp1.0                                         \n\
00371       PARAM color0 = program.local[0];                    \n\
00372       PARAM color1 = program.local[1];                    \n\
00373       TEMP tex0;                                          \n\
00374       TEMP tex1;                                          \n\
00375       TEMP temp0;                                         \n\
00376       TEMP temp1;                                         \n\
00377       TEX tex0, fragment.texcoord[0], texture[0], RECT;   \n\
00378       MUL temp0, color0, tex0;                            \n\
00379       TEX tex1, fragment.texcoord[1], texture[1], RECT;   \n\
00380       MUL temp1, color1, tex1;                            \n\
00381       MUL result.color, temp0, temp1;                     \n\
00382       END";
00383 
00384     m_Asm2TextureMod = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00385     m_Asm2TextureMod->LoadVertexShader(AsmVtx.GetTCharPtr());
00386     m_Asm2TextureMod->LoadPixelShader(AsmFrg.GetTCharPtr());
00387     m_Asm2TextureMod->Link();
00388 
00389     m_Asm2TextureRectMod = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00390     m_Asm2TextureRectMod->LoadVertexShader(AsmVtx.GetTCharPtr());
00391     m_Asm2TextureRectMod->LoadPixelShader(AsmFrgRect.GetTCharPtr());
00392     m_Asm2TextureRectMod->Link();
00393   }
00394 
00395   void GraphicsEngine::InitAsm4TextureAdd()
00396   {
00397     NString AsmVtx = 
00398         "!!ARBvp1.0                                 \n\
00399         ATTRIB iPos         = vertex.position;      \n\
00400         OUTPUT oPos         = result.position;      \n\
00401         OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00402         OUTPUT oTexCoord1   = result.texcoord[1];   \n\
00403         OUTPUT oTexCoord2   = result.texcoord[2];   \n\
00404         OUTPUT oTexCoord3   = result.texcoord[3];   \n\
00405         # Transform the vertex to clip coordinates. \n\
00406         DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
00407         DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
00408         DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
00409         DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
00410         MOV   oTexCoord0, vertex.attrib[8];       \n\
00411         MOV   oTexCoord1, vertex.attrib[9];       \n\
00412         MOV   oTexCoord2, vertex.attrib[10];       \n\
00413         MOV   oTexCoord3, vertex.attrib[11];       \n\
00414         END";
00415 
00416     NString AsmFrg = 
00417         "!!ARBfp1.0                                         \n\
00418         PARAM color0 = program.local[0];                    \n\
00419         PARAM color1 = program.local[1];                    \n\
00420         PARAM color2 = program.local[2];                    \n\
00421         PARAM color3 = program.local[3];                    \n\
00422         TEMP tex0;                                          \n\
00423         TEMP tex1;                                          \n\
00424         TEMP tex2;                                          \n\
00425         TEMP tex3;                                          \n\
00426         TEMP temp;                                          \n\
00427         TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00428         MUL temp, color0, tex0;                             \n\
00429         TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00430         MAD temp, color1, tex1, temp;                       \n\
00431         TEX tex2, fragment.texcoord[2], texture[2], 2D;     \n\
00432         MAD temp, color2, tex2, temp;                       \n\
00433         TEX tex3, fragment.texcoord[3], texture[3], 2D;     \n\
00434         MAD temp, color3, tex3, temp;                       \n\
00435         MOV result.color, temp;                             \n\
00436         END";
00437 
00438     NString AsmFrgRect = 
00439       "!!ARBfp1.0                                         \n\
00440       PARAM color0 = program.local[0];                    \n\
00441       PARAM color1 = program.local[1];                    \n\
00442       PARAM color2 = program.local[2];                    \n\
00443       PARAM color3 = program.local[3];                    \n\
00444       TEMP tex0;                                          \n\
00445       TEMP tex1;                                          \n\
00446       TEMP tex2;                                          \n\
00447       TEMP tex3;                                          \n\
00448       TEMP temp;                                          \n\
00449       TEX tex0, fragment.texcoord[0], texture[0], RECT;   \n\
00450       MUL temp, color0, tex0;                             \n\
00451       TEX tex1, fragment.texcoord[1], texture[1], RECT;   \n\
00452       MAD temp, color1, tex1, temp;                       \n\
00453       TEX tex2, fragment.texcoord[2], texture[2], RECT;   \n\
00454       MAD temp, color2, tex2, temp;                       \n\
00455       TEX tex3, fragment.texcoord[3], texture[3], RECT;   \n\
00456       MAD temp, color3, tex3, temp;                       \n\
00457       MOV result.color, temp;                             \n\
00458       END";
00459 
00460     m_Asm4TextureAdd = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00461     m_Asm4TextureAdd->LoadVertexShader(AsmVtx.GetTCharPtr());
00462     m_Asm4TextureAdd->LoadPixelShader(AsmFrg.GetTCharPtr());
00463     m_Asm4TextureAdd->Link();
00464 
00465     m_Asm4TextureRectAdd = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00466     m_Asm4TextureRectAdd->LoadVertexShader(AsmVtx.GetTCharPtr());
00467     m_Asm4TextureRectAdd->LoadPixelShader(AsmFrgRect.GetTCharPtr());
00468     m_Asm4TextureRectAdd->Link();
00469   }
00470 
00471   void GraphicsEngine::InitAsmBlendModes()
00472   {
00473     NString AsmVtx = 
00474                        "!!ARBvp1.0                                 \n\
00475         OUTPUT oPos         = result.position;      \n\
00476         OUTPUT oTexCoord0   = result.texcoord[0];   \n\
00477         OUTPUT oTexCoord1   = result.texcoord[1];   \n\
00478         # Transform the vertex to clip coordinates. \n\
00479         DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
00480         DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
00481         DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
00482         DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
00483         MOV   oTexCoord0, vertex.attrib[8];       \n\
00484         MOV   oTexCoord1, vertex.attrib[9];       \n\
00485         END";
00486 
00487     NString AsmPSBNormal = 
00488                              "!!ARBfp1.0                                         \n\
00489         TEMP tex0;                                          \n\
00490         TEMP tex1;                                          \n\
00491         TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00492         TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00493         MOV result.color, tex0;                             \n\
00494         END";
00495 
00496     m_AsmPSBNormal = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00497     m_AsmPSBNormal->LoadVertexShader(AsmVtx.GetTCharPtr());
00498     m_AsmPSBNormal->LoadPixelShader(AsmPSBNormal.GetTCharPtr());
00499     m_AsmPSBNormal->Link();
00500 
00501     // Lighten
00502     NString AsmPSBLighten = 
00503                               "!!ARBfp1.0                                         \n\
00504         TEMP tex0;                                          \n\
00505         TEMP tex1;                                          \n\
00506         TEMP temp;                                          \n\
00507         TEMP cmpres;                                        \n\
00508         TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00509         TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00510         SUB temp, tex0, tex1;                               \n\
00511         CMP cmpres, temp, tex1, tex0;                       \n\
00512         MOV result.color, temp;                             \n\
00513         END";
00514 
00515     m_AsmPSBLighten = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00516     m_AsmPSBLighten->LoadVertexShader(AsmVtx.GetTCharPtr());
00517     m_AsmPSBLighten->LoadPixelShader(AsmPSBLighten.GetTCharPtr());
00518     m_AsmPSBLighten->Link();
00519 
00520     // Darken
00521     NString AsmPSBDarken = 
00522                              "!!ARBfp1.0                                         \n\
00523         TEMP tex0;                                          \n\
00524         TEMP tex1;                                          \n\
00525         TEMP temp;                                          \n\
00526         TEMP cmpres;                                        \n\
00527         TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00528         TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00529         SUB temp, tex1, tex0;                               \n\
00530         CMP cmpres, temp, tex1, tex0;                       \n\
00531         MOV result.color, temp;                             \n\
00532         END";
00533 
00534     m_AsmPSBDarken = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00535     m_AsmPSBDarken->LoadVertexShader(AsmVtx.GetTCharPtr());
00536     m_AsmPSBDarken->LoadPixelShader(AsmPSBDarken.GetTCharPtr());
00537     m_AsmPSBDarken->Link();
00538 
00539     // Multiply
00540     NString AsmPSBMultiply = 
00541                                "!!ARBfp1.0                                         \n\
00542         TEMP tex0;                                          \n\
00543         TEMP tex1;                                          \n\
00544         TEMP temp;                                          \n\
00545         TEX tex0, fragment.texcoord[0], texture[0], 2D;     \n\
00546         TEX tex1, fragment.texcoord[1], texture[1], 2D;     \n\
00547         MUL result.color, tex0, tex1;                       \n\
00548         END";
00549 
00550     m_AsmPSBMultiply = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
00551     m_AsmPSBMultiply->LoadVertexShader(AsmVtx.GetTCharPtr());
00552     m_AsmPSBMultiply->LoadPixelShader(AsmPSBMultiply.GetTCharPtr());
00553     m_AsmPSBMultiply->Link();
00554   }
00555 
00556 
00557 
00558   void GraphicsEngine::QRP_ASM_Color(int x, int y, int width, int height, const Color &c0)
00559   {
00560     QRP_ASM_Color(x, y, width, height, c0, c0, c0, c0);
00561   }
00562 
00563   void GraphicsEngine::QRP_ASM_Color(int x, int y, int width, int height, const Color &c0, const Color &c1, const Color &c2, const Color &c3)
00564   {
00565     NUX_RETURN_IF_FALSE(m_AsmColor.IsValid());
00566 
00567     float fx = x, fy = y;
00568     float VtxBuffer[] =
00569     {
00570       fx,          fy,          0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
00571       fx,          fy + height, 0.0f, 1.0f, c1.red, c1.green, c1.blue, c1.alpha,
00572       fx + width,  fy + height, 0.0f, 1.0f, c2.red, c2.green, c2.blue, c2.alpha,
00573       fx + width,  fy,          0.0f, 1.0f, c3.red, c3.green, c3.blue, c3.alpha,
00574     };
00575 
00576     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00577     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00578 
00579     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmColor;
00580 
00581     shader_program->Begin();
00582 
00583     CHECKGL(glMatrixMode(GL_MODELVIEW));
00584     CHECKGL(glLoadIdentity());
00585     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
00586     CHECKGL(glMatrixMode(GL_PROJECTION));
00587     CHECKGL(glLoadIdentity());
00588     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
00589 
00590 
00591     int VertexLocation          = VTXATTRIB_POSITION;
00592     int VertexColorLocation     = VTXATTRIB_COLOR;
00593 
00594     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00595     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
00596 
00597     if (VertexColorLocation != -1)
00598     {
00599       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
00600       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
00601     }
00602 
00603     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00604 
00605     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00606 
00607     if (VertexColorLocation != -1)
00608       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
00609 
00610     shader_program->End();
00611   }
00612 
00613   void GraphicsEngine::QRP_ASM_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)
00614   {
00615     NUX_RETURN_IF_FALSE(m_AsmTextureModColor.IsValid());
00616     NUX_RETURN_IF_FALSE(m_AsmTextureRectModColor.IsValid());
00617 
00618     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
00619     float fx = x, fy = y;
00620     float VtxBuffer[] =
00621     {
00622       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00623       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00624       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00625       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00626     };
00627 
00628     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00629     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00630     
00631     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmTextureModColor;
00632     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
00633     {
00634       shader_program = m_AsmTextureRectModColor;
00635     }
00636     shader_program->Begin();
00637 
00638     SetTexture(GL_TEXTURE0, device_texture);
00639 
00640     CHECKGL(glMatrixMode(GL_MODELVIEW));
00641     CHECKGL(glLoadIdentity());
00642     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
00643     CHECKGL(glMatrixMode(GL_PROJECTION));
00644     CHECKGL(glLoadIdentity());
00645     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
00646 
00647 
00648     int VertexLocation          = VTXATTRIB_POSITION;
00649     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
00650     int VertexColorLocation     = VTXATTRIB_COLOR;
00651 
00652     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00653     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00654 
00655     if (TextureCoord0Location != -1)
00656     {
00657       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00658       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00659     }
00660 
00661     if (VertexColorLocation != -1)
00662     {
00663       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
00664       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00665     }
00666 
00667     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00668 
00669     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00670 
00671     if (TextureCoord0Location != -1)
00672       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00673 
00674     if (VertexColorLocation != -1)
00675       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
00676 
00677     shader_program->End();
00678   }
00679 
00680   void GraphicsEngine::QRP_ASM_ColorModTexAlpha(int x, int y, int width, int height,
00681       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color)
00682   {
00683     NUX_RETURN_IF_FALSE(m_AsmColorModTexMaskAlpha.IsValid());
00684     NUX_RETURN_IF_FALSE(m_AsmColorModTexRectMaskAlpha.IsValid());
00685 
00686     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
00687 
00688     float fx = x, fy = y;
00689     float VtxBuffer[] =
00690     {
00691       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00692       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00693       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00694       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
00695     };
00696 
00697     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00698     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00699 
00700     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmColorModTexMaskAlpha;
00701     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
00702     {
00703       shader_program = m_AsmColorModTexRectMaskAlpha;
00704     }
00705     shader_program->Begin();
00706 
00707     SetTexture(GL_TEXTURE0, device_texture);
00708 
00709     CHECKGL(glMatrixMode(GL_MODELVIEW));
00710     CHECKGL(glLoadIdentity());
00711     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
00712     CHECKGL(glMatrixMode(GL_PROJECTION));
00713     CHECKGL(glLoadIdentity());
00714     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
00715 
00716 
00717     int VertexLocation          = VTXATTRIB_POSITION;
00718     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
00719     int VertexColorLocation     = VTXATTRIB_COLOR;
00720 
00721     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00722     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00723 
00724     if (TextureCoord0Location != -1)
00725     {
00726       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00727       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00728     }
00729 
00730     if (VertexColorLocation != -1)
00731     {
00732       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
00733       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00734     }
00735 
00736     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00737 
00738     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00739 
00740     if (TextureCoord0Location != -1)
00741       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00742 
00743     if (VertexColorLocation != -1)
00744       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
00745 
00746     shader_program->End();
00747   }
00748 
00749   void GraphicsEngine::QRP_ASM_2Tex(int x, int y, int width, int height,
00750                                   ObjectPtr<IOpenGLBaseTexture> device_texture0, TexCoordXForm &texxform0, const Color &color0,
00751                                   ObjectPtr<IOpenGLBaseTexture> device_texture1, TexCoordXForm &texxform1, const Color &color1)
00752   {
00753     NUX_RETURN_IF_FALSE(m_Asm2TextureAdd.IsValid());
00754     NUX_RETURN_IF_FALSE(m_Asm2TextureRectAdd.IsValid());
00755 
00756     QRP_Compute_Texture_Coord(width, height, device_texture0, texxform0);
00757     QRP_Compute_Texture_Coord(width, height, device_texture1, texxform1);
00758 
00759     float fx = x, fy = y;
00760     float VtxBuffer[] =
00761     {
00762       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
00763       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
00764       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
00765       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
00766     };
00767 
00768     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00769     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00770 
00771     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_Asm2TextureAdd;
00772     if (device_texture0->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
00773     {
00774       shader_program = m_Asm2TextureRectAdd;
00775     }
00776     shader_program->Begin();
00777 
00778     SetTexture(GL_TEXTURE0, device_texture0);
00779     SetTexture(GL_TEXTURE1, device_texture1);
00780 
00781     CHECKGL(glMatrixMode(GL_MODELVIEW));
00782     CHECKGL(glLoadIdentity());
00783     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
00784     CHECKGL(glMatrixMode(GL_PROJECTION));
00785     CHECKGL(glLoadIdentity());
00786     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
00787 
00788     int VertexLocation          = VTXATTRIB_POSITION;
00789     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
00790     int TextureCoord1Location   = VTXATTRIB_TEXCOORD1;
00791 
00792     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, color0.red, color0.green, color0.blue, color0.alpha ));
00793     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, color1.red, color1.green, color1.blue, color1.alpha ));
00794 
00795     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00796     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00797 
00798     if (TextureCoord0Location != -1)
00799     {
00800       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00801       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00802     }
00803 
00804     if (TextureCoord1Location != -1)
00805     {
00806       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
00807       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00808     }
00809 
00810     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00811 
00812     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00813 
00814     if (TextureCoord0Location != -1)
00815       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00816 
00817     if (TextureCoord1Location != -1)
00818       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
00819 
00820     shader_program->End();
00821   }
00822 
00823   void GraphicsEngine::QRP_ASM_DisturbedTexture(
00824     int x, int y, int width, int height,
00825     ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm &texxform0, const Color& c0,
00826     ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm &texxform1, const Color& c1)
00827   {
00828     NUX_RETURN_IF_FALSE(m_ASM2TextureDepRead.IsValid());
00829     NUX_RETURN_IF_FALSE(m_ASM2TextureRectDepRead.IsValid());
00830 
00831     QRP_Compute_Texture_Coord(width, height, distorsion_texture, texxform0);
00832     QRP_Compute_Texture_Coord(width, height, src_device_texture, texxform1);
00833 
00834     float fx = x, fy = y;
00835     float VtxBuffer[] =
00836     {
00837       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
00838       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
00839       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
00840       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
00841     };
00842 
00843     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00844     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00845 
00846     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_ASM2TextureDepRead;
00847     if (src_device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
00848     {
00849       shader_program = m_ASM2TextureRectDepRead;
00850     }
00851     shader_program->Begin();
00852 
00853     SetTexture(GL_TEXTURE0, distorsion_texture);
00854     SetTexture(GL_TEXTURE1, src_device_texture);
00855 
00856     CHECKGL(glMatrixMode(GL_MODELVIEW));
00857     CHECKGL(glLoadIdentity());
00858     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
00859     CHECKGL(glMatrixMode(GL_PROJECTION));
00860     CHECKGL(glLoadIdentity());
00861     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
00862 
00863     int VertexLocation          = VTXATTRIB_POSITION;
00864     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
00865     int TextureCoord1Location   = VTXATTRIB_TEXCOORD1;
00866 
00867     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, c0.red, c0.green, c0.blue, c0.alpha ));
00868     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, c1.red, c1.green, c1.blue, c1.alpha ));
00869 
00870     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00871     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00872 
00873     if (TextureCoord0Location != -1)
00874     {
00875       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00876       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00877     }
00878 
00879     if (TextureCoord1Location != -1)
00880     {
00881       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
00882       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00883     }
00884 
00885     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00886 
00887     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00888 
00889     if (TextureCoord0Location != -1)
00890       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00891 
00892     if (TextureCoord1Location != -1)
00893       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
00894 
00895     shader_program->End();
00896   }
00897 
00898   void GraphicsEngine::QRP_ASM_2TexMod(int x, int y, int width, int height,
00899     ObjectPtr<IOpenGLBaseTexture> device_texture0, TexCoordXForm &texxform0, const Color &color0,
00900     ObjectPtr<IOpenGLBaseTexture> device_texture1, TexCoordXForm &texxform1, const Color &color1)
00901   {
00902     NUX_RETURN_IF_FALSE(m_Asm2TextureMod.IsValid());
00903     NUX_RETURN_IF_FALSE(m_Asm2TextureRectMod.IsValid());
00904 
00905     QRP_Compute_Texture_Coord(width, height, device_texture0, texxform0);
00906     QRP_Compute_Texture_Coord(width, height, device_texture1, texxform1);
00907 
00908     float fx = x, fy = y;
00909     float VtxBuffer[] =
00910     {
00911       fx,          fy,          0.0f, 1.0f, texxform0.u0, texxform0.v0, 0.0f, 1.0f, texxform1.u0, texxform1.v0, 0.0f, 1.0f,
00912       fx,          fy + height, 0.0f, 1.0f, texxform0.u0, texxform0.v1, 0.0f, 1.0f, texxform1.u0, texxform1.v1, 0.0f, 1.0f,
00913       fx + width,  fy + height, 0.0f, 1.0f, texxform0.u1, texxform0.v1, 0.0f, 1.0f, texxform1.u1, texxform1.v1, 0.0f, 1.0f,
00914       fx + width,  fy,          0.0f, 1.0f, texxform0.u1, texxform0.v0, 0.0f, 1.0f, texxform1.u1, texxform1.v0, 0.0f, 1.0f,
00915     };
00916 
00917     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00918     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00919 
00920     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_Asm2TextureMod;
00921     if (device_texture0->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
00922     {
00923       shader_program = m_Asm2TextureRectMod;
00924     }
00925     shader_program->Begin();
00926 
00927     SetTexture(GL_TEXTURE0, device_texture0);
00928     SetTexture(GL_TEXTURE1, device_texture1);
00929 
00930     CHECKGL(glMatrixMode(GL_MODELVIEW));
00931     CHECKGL(glLoadIdentity());
00932     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
00933     CHECKGL(glMatrixMode(GL_PROJECTION));
00934     CHECKGL(glLoadIdentity());
00935     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
00936 
00937     int VertexLocation          = VTXATTRIB_POSITION;
00938     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
00939     int TextureCoord1Location   = VTXATTRIB_TEXCOORD1;
00940 
00941     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, color0.red, color0.green, color0.blue, color0.alpha ));
00942     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, color1.red, color1.green, color1.blue, color1.alpha ));
00943 
00944     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
00945     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
00946 
00947     if (TextureCoord0Location != -1)
00948     {
00949       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
00950       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
00951     }
00952 
00953     if (TextureCoord1Location != -1)
00954     {
00955       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
00956       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
00957     }
00958 
00959     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
00960 
00961     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
00962 
00963     if (TextureCoord0Location != -1)
00964       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
00965 
00966     if (TextureCoord1Location != -1)
00967       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
00968 
00969     shader_program->End();
00970   }
00971 
00972   void GraphicsEngine::QRP_ASM_4Tex(int x, int y, int width, int height,
00973                                   ObjectPtr<IOpenGLBaseTexture> device_texture0, TexCoordXForm &texxform0, const Color &color0,
00974                                   ObjectPtr<IOpenGLBaseTexture> device_texture1, TexCoordXForm &texxform1, const Color &color1,
00975                                   ObjectPtr<IOpenGLBaseTexture> device_texture2, TexCoordXForm &texxform2, const Color &color2,
00976                                   ObjectPtr<IOpenGLBaseTexture> device_texture3, TexCoordXForm &texxform3, const Color &color3)
00977   {
00978     NUX_RETURN_IF_FALSE(m_Asm4TextureAdd.IsValid());
00979     NUX_RETURN_IF_FALSE(m_Asm4TextureRectAdd.IsValid());
00980 
00981     QRP_Compute_Texture_Coord(width, height, device_texture0, texxform0);
00982     QRP_Compute_Texture_Coord(width, height, device_texture1, texxform1);
00983     QRP_Compute_Texture_Coord(width, height, device_texture2, texxform1);
00984     QRP_Compute_Texture_Coord(width, height, device_texture3, texxform1);
00985 
00986     float fx = x, fy = y;
00987     float VtxBuffer[] =
00988     {
00989       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,
00990       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,
00991       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,
00992       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,
00993     };
00994 
00995     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
00996     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
00997 
00998     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_Asm4TextureAdd;
00999     if (device_texture0->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
01000     {
01001       shader_program = m_Asm4TextureRectAdd;
01002     }
01003     shader_program->Begin();
01004 
01005     SetTexture(GL_TEXTURE0, device_texture0);
01006     SetTexture(GL_TEXTURE1, device_texture1);
01007     SetTexture(GL_TEXTURE2, device_texture1);
01008     SetTexture(GL_TEXTURE3, device_texture1);
01009 
01010     CHECKGL(glMatrixMode(GL_MODELVIEW));
01011     CHECKGL(glLoadIdentity());
01012     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01013     CHECKGL(glMatrixMode(GL_PROJECTION));
01014     CHECKGL(glLoadIdentity());
01015     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01016 
01017     int VertexLocation          = VTXATTRIB_POSITION;
01018     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
01019     int TextureCoord1Location   = VTXATTRIB_TEXCOORD1;
01020     int TextureCoord2Location   = VTXATTRIB_TEXCOORD2;
01021     int TextureCoord3Location   = VTXATTRIB_TEXCOORD3;
01022 
01023     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, color0.red, color0.green, color0.blue, color0.alpha ));
01024     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, color1.red, color1.green, color1.blue, color1.alpha ));
01025     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, color2.red, color2.green, color2.blue, color2.alpha ));
01026     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 3, color3.red, color3.green, color3.blue, color3.alpha ));
01027 
01028     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01029     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer));
01030 
01031     if (TextureCoord0Location != -1)
01032     {
01033       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
01034       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 4));
01035     }
01036 
01037     if (TextureCoord1Location != -1)
01038     {
01039       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
01040       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 8));
01041     }
01042 
01043     if (TextureCoord2Location != -1)
01044     {
01045       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord2Location));
01046       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord2Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 12));
01047     }
01048 
01049     if (TextureCoord3Location != -1)
01050     {
01051       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord3Location));
01052       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord3Location, 4, GL_FLOAT, GL_FALSE, 80, VtxBuffer + 16));
01053     }
01054 
01055     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
01056 
01057     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01058 
01059     if (TextureCoord0Location != -1)
01060       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
01061 
01062     if (TextureCoord1Location != -1)
01063       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
01064 
01065     if (TextureCoord2Location != -1)
01066       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord2Location));
01067 
01068     if (TextureCoord3Location != -1)
01069       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord3Location));
01070 
01071     shader_program->End();
01072   }
01073 
01075   void GraphicsEngine::QRP_ASM_Triangle(int x0, int y0,
01076                                       int x1, int y1,
01077                                       int x2, int y2,
01078                                       Color c0)
01079   {
01080     QRP_ASM_Triangle(x0, y0, x1, y1, x2, y2, c0, c0, c0);
01081   }
01082 
01083   void GraphicsEngine::QRP_ASM_Triangle(int x0, int y0,
01084                                       int x1, int y1,
01085                                       int x2, int y2,
01086                                       Color c0, Color c1, Color c2)
01087   {
01088     NUX_RETURN_IF_FALSE(m_AsmColor.IsValid());
01089 
01090     float VtxBuffer[] =
01091     {
01092       static_cast<float>(x0), static_cast<float>(y0), 0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
01093       static_cast<float>(x1), static_cast<float>(y1), 0.0f, 1.0f, c1.red, c1.green, c1.blue, c1.alpha,
01094       static_cast<float>(x2), static_cast<float>(y2), 0.0f, 1.0f, c2.red, c2.green, c2.blue, c2.alpha,
01095     };
01096 
01097     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01098     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01099 
01100     ObjectPtr<IOpenGLAsmShaderProgram> ShaderProg = m_AsmColor;
01101 
01102     ShaderProg->Begin();
01103 
01104     CHECKGL(glMatrixMode(GL_MODELVIEW));
01105     CHECKGL(glLoadIdentity());
01106     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01107     CHECKGL(glMatrixMode(GL_PROJECTION));
01108     CHECKGL(glLoadIdentity());
01109     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01110 
01111     int VertexLocation          = VTXATTRIB_POSITION;
01112     int VertexColorLocation     = VTXATTRIB_COLOR;
01113 
01114     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01115     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01116 
01117     CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
01118     CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01119 
01120     CHECKGL(glDrawArrays(GL_TRIANGLES, 0, 3));
01121 
01122     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01123     CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
01124     ShaderProg->End();
01125 
01126     m_triangle_stats++;
01127   }
01128 
01130 // DRAW LINES       //
01132   void GraphicsEngine::QRP_ASM_Line(int x0, int y0,
01133                                   int x1, int y1, Color c0)
01134   {
01135     QRP_ASM_Line(x0, y0, x1, y1, c0, c0);
01136   }
01137 
01138   void GraphicsEngine::QRP_ASM_Line(int x0, int y0,
01139                                   int x1, int y1, Color c0, Color c1)
01140   {
01141     NUX_RETURN_IF_FALSE(m_AsmColor.IsValid());
01142 
01143     float VtxBuffer[] =
01144     {
01145       static_cast<float>(x0), static_cast<float>(y0), 0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
01146       static_cast<float>(x1), static_cast<float>(y1), 0.0f, 1.0f, c1.red, c1.green, c1.blue, c1.alpha,
01147     };
01148 
01149     ObjectPtr<IOpenGLAsmShaderProgram> ShaderProg = m_AsmColor;
01150 
01151 
01152     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01153     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01154     ShaderProg->Begin();
01155 
01156     CHECKGL(glMatrixMode(GL_MODELVIEW));
01157     CHECKGL(glLoadIdentity());
01158     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01159     CHECKGL(glMatrixMode(GL_PROJECTION));
01160     CHECKGL(glLoadIdentity());
01161     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01162 
01163     int VertexLocation          = VTXATTRIB_POSITION;
01164     int VertexColorLocation     = VTXATTRIB_COLOR;
01165 
01166     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01167     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01168 
01169     if (VertexColorLocation != -1)
01170     {
01171       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
01172       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01173     }
01174 
01175     CHECKGL(glDrawArrays(GL_LINES, 0, 2));
01176 
01177     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01178 
01179     if (VertexColorLocation != -1)
01180       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
01181 
01182     ShaderProg->End();
01183 
01184     m_line_stats++;
01185   }
01186 
01187   void GraphicsEngine::QRP_ASM_QuadWireframe(int x0, int y0, int width, int height,
01188       Color c0,
01189       Color c1,
01190       Color c2,
01191       Color c3)
01192   {
01193     NUX_RETURN_IF_FALSE(m_AsmColor.IsValid());
01194 
01195     float fx0 = x0, fy0 = y0;
01196     float VtxBuffer[] =
01197     {
01198       fx0, fy0,                             0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
01199       fx0, fy0 + height - 1,                0.0f, 1.0f, c1.red, c1.green, c1.blue, c1.alpha,
01200       fx0 + width - 1, fy0 + height - 1,    0.0f, 1.0f, c2.red, c2.green, c2.blue, c2.alpha,
01201       fx0 + width - 1, fy0,                 0.0f, 1.0f, c3.red, c3.green, c3.blue, c3.alpha,
01202       fx0, fy0,                             0.0f, 1.0f, c0.red, c0.green, c0.blue, c0.alpha,
01203     };
01204 
01205     ObjectPtr<IOpenGLAsmShaderProgram> ShaderProg = m_AsmColor;
01206 
01207     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01208     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01209     ShaderProg->Begin();
01210 
01211     CHECKGL(glMatrixMode(GL_MODELVIEW));
01212     CHECKGL(glLoadIdentity());
01213     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01214     CHECKGL(glMatrixMode(GL_PROJECTION));
01215     CHECKGL(glLoadIdentity());
01216     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01217 
01218     int VertexLocation          = VTXATTRIB_POSITION;
01219     int VertexColorLocation     = VTXATTRIB_COLOR;
01220 
01221     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01222     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01223 
01224     if (VertexColorLocation != -1)
01225     {
01226       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
01227       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01228     }
01229 
01230     CHECKGL(glDrawArrays(GL_LINE_STRIP, 0, 5));
01231 
01232     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01233 
01234     if (VertexColorLocation != -1)
01235       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
01236 
01237     ShaderProg->End();
01238 
01239     m_line_stats++;
01240   }
01241 
01242   void GraphicsEngine::InitAsmPower()
01243   {
01244     NString AsmVtx = 
01245       "!!ARBvp1.0                                 \n\
01246       ATTRIB iPos         = vertex.position;      \n\
01247       OUTPUT oPos         = result.position;      \n\
01248       OUTPUT oTexCoord0   = result.texcoord[0];   \n\
01249       # Transform the vertex to clip coordinates. \n\
01250       DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
01251       DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
01252       DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
01253       DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
01254       MOV   oTexCoord0, vertex.attrib[8];       \n\
01255       END";
01256 
01257 
01258     NString AsmFrg = 
01259       "!!ARBfp1.0                                       \n\
01260       PARAM color0 = program.local[0];                  \n\
01261       PARAM exponent = program.local[1];                \n\
01262       TEMP tex0;                                        \n\
01263       TEMP final;                                       \n\
01264       TEX tex0, fragment.texcoord[0], texture[0], 2D;   \n\
01265       POW final.r, tex0.r, exponent.r;             \n\
01266       POW final.g, tex0.g, exponent.g;             \n\
01267       POW final.b, tex0.b, exponent.b;             \n\
01268       MOV final.a, tex0.a;                         \n\
01269       MUL result.color, color0, final;             \n\
01270       END";
01271 
01272     NString AsmFrgRect = 
01273       "!!ARBfp1.0                                       \n\
01274       PARAM color0 = program.local[0];                  \n\
01275       PARAM exponent = program.local[1];                \n\
01276       TEMP tex0;                                        \n\
01277       TEMP final;                                       \n\
01278       TEX tex0, fragment.texcoord[0], texture[0], RECT;   \n\
01279       POW final.r, tex0.r, exponent.r;             \n\
01280       POW final.g, tex0.g, exponent.g;             \n\
01281       POW final.b, tex0.b, exponent.b;             \n\
01282       MOV final.a, tex0.a;                         \n\
01283       MUL result.color, color0, final;             \n\
01284       END";
01285 
01286     _asm_tex_component_exponentiation_prog = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
01287     _asm_tex_component_exponentiation_prog->LoadVertexShader(AsmVtx.GetTCharPtr());
01288     _asm_tex_component_exponentiation_prog->LoadPixelShader(AsmFrg.GetTCharPtr());
01289     _asm_tex_component_exponentiation_prog->Link();
01290   }
01291 
01292   void GraphicsEngine::QRP_ASM_Power  (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &c0, Vector4 exponent)
01293   {
01294     NUX_RETURN_IF_FALSE(_asm_tex_component_exponentiation_prog.IsValid());
01295     NUX_RETURN_IF_FALSE(_asm_texrect_component_exponentiation_prog.IsValid());
01296 
01297     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
01298     float fx = x, fy = y;
01299     float VtxBuffer[] =
01300     {
01301       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f,
01302       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f,
01303       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f,
01304       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f,
01305     };
01306 
01307     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01308     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01309 
01310     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = _asm_tex_component_exponentiation_prog;
01311     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
01312     {
01313       shader_program = _asm_texrect_component_exponentiation_prog;
01314     }
01315     shader_program->Begin();
01316 
01317     SetTexture(GL_TEXTURE0, device_texture);
01318 
01319     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, c0.red, c0.green, c0.blue, c0.alpha));
01320     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, exponent.x, exponent.y, exponent.z, exponent.w));
01321 
01322     CHECKGL(glMatrixMode(GL_MODELVIEW));
01323     CHECKGL(glLoadIdentity());
01324     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01325     CHECKGL(glMatrixMode(GL_PROJECTION));
01326     CHECKGL(glLoadIdentity());
01327     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01328 
01329 
01330     int VertexLocation          = VTXATTRIB_POSITION;
01331     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
01332 
01333     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01334     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01335 
01336     if (TextureCoord0Location != -1)
01337     {
01338       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
01339       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01340     }
01341 
01342     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
01343 
01344     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01345 
01346     if (TextureCoord0Location != -1)
01347       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
01348 
01349     shader_program->End();
01350   }
01351 
01352   void GraphicsEngine::InitAsmAlphaReplicate()
01353   {
01354     NString AsmVtx = 
01355       "!!ARBvp1.0                                 \n\
01356       ATTRIB iPos         = vertex.position;      \n\
01357       OUTPUT oPos         = result.position;      \n\
01358       OUTPUT oTexCoord0   = result.texcoord[0];   \n\
01359       # Transform the vertex to clip coordinates. \n\
01360       DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
01361       DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
01362       DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
01363       DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
01364       MOV   oTexCoord0, vertex.attrib[8];       \n\
01365       END";
01366 
01367 
01368     NString AsmFrg = 
01369       "!!ARBfp1.0                                     \n\
01370       PARAM color0 = program.local[0];                \n\
01371       TEMP tex0;                                      \n\
01372       TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\
01373       MUL result.color, color0, tex0.aaaa;            \n\
01374       END";
01375 
01376     NString AsmFrgRect = 
01377       "!!ARBfp1.0                                       \n\
01378       PARAM color0 = program.local[0];                  \n\
01379       TEMP tex0;                                        \n\
01380       TEX tex0, fragment.texcoord[0], texture[0], RECT; \n\
01381       MUL result.color, color0, tex0.aaaa;              \n\
01382       END";
01383 
01384     _asm_tex_alpha_replicate_prog = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
01385     _asm_tex_alpha_replicate_prog->LoadVertexShader(AsmVtx.GetTCharPtr());
01386     _asm_tex_alpha_replicate_prog->LoadPixelShader(AsmFrg.GetTCharPtr());
01387     _asm_tex_alpha_replicate_prog->Link();
01388 
01389   }
01390 
01391   void GraphicsEngine::QRP_ASM_AlphaReplicate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
01392     const Color &c0)
01393   {
01394     NUX_RETURN_IF_FALSE(_asm_tex_alpha_replicate_prog.IsValid());
01395     NUX_RETURN_IF_FALSE(_asm_texrect_alpha_replicate_prog.IsValid());
01396 
01397     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
01398     float fx = x, fy = y;
01399     float VtxBuffer[] =
01400     {
01401       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f,
01402       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f,
01403       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f,
01404       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f,
01405     };
01406 
01407     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01408     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01409 
01410     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = _asm_tex_alpha_replicate_prog;
01411     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
01412     {
01413       shader_program = _asm_texrect_alpha_replicate_prog;
01414     }
01415     shader_program->Begin();
01416 
01417     SetTexture(GL_TEXTURE0, device_texture);
01418 
01419     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, c0.red, c0.green, c0.blue, c0.alpha));
01420 
01421     CHECKGL(glMatrixMode(GL_MODELVIEW));
01422     CHECKGL(glLoadIdentity());
01423     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01424     CHECKGL(glMatrixMode(GL_PROJECTION));
01425     CHECKGL(glLoadIdentity());
01426     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01427 
01428 
01429     int VertexLocation          = VTXATTRIB_POSITION;
01430     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
01431 
01432     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01433     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01434 
01435     if (TextureCoord0Location != -1)
01436     {
01437       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
01438       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01439     }
01440 
01441     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
01442 
01443     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01444 
01445     if (TextureCoord0Location != -1)
01446       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
01447 
01448     shader_program->End();
01449   }
01450 
01451   void GraphicsEngine::InitAsmColorMatrixFilter()
01452   {
01453     NString AsmVtx = 
01454       "!!ARBvp1.0                                               \n\
01455       ATTRIB iPos         = vertex.position;                    \n\
01456       OUTPUT oPos         = result.position;                    \n\
01457       OUTPUT oTexCoord0   = result.texcoord[0];                 \n\
01458       # Transform the vertex to clip coordinates.               \n\
01459       DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;   \n\
01460       DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;   \n\
01461       DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;   \n\
01462       DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;   \n\
01463       MOV   oTexCoord0, vertex.attrib[8];                       \n\
01464       END";
01465 
01466 
01467     NString AsmFrg = 
01468       "!!ARBfp1.0                                     \n\
01469       PARAM color0 = program.local[0];                \n\
01470       PARAM CM0 = program.local[1];                   \n\
01471       PARAM CM1 = program.local[2];                   \n\
01472       PARAM CM2 = program.local[3];                   \n\
01473       PARAM CM3 = program.local[4];                   \n\
01474       PARAM offset = program.local[5];                \n\
01475       TEMP tex0;                                      \n\
01476       TEMP final;                                     \n\
01477       TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\
01478       MAD final.r, tex0, CM0, offset.r;               \n\
01479       MAD final.g, tex0, CM1, offset.g;               \n\
01480       MAD final.b, tex0, CM2, offset.b;               \n\
01481       MAD final.a, tex0, CM3, offset.a;               \n\
01482       MUL result.color, color0, final;                \n\
01483       END";
01484 
01485     NString AsmFrgRect = 
01486       "!!ARBfp1.0                                     \n\
01487       PARAM color0 = program.local[0];                \n\
01488       PARAM CM0 = program.local[1];                   \n\
01489       PARAM CM1 = program.local[2];                   \n\
01490       PARAM CM2 = program.local[3];                   \n\
01491       PARAM CM3 = program.local[4];                   \n\
01492       PARAM offset = program.local[5];                \n\
01493       TEMP tex0;                                      \n\
01494       TEMP final;                                     \n\
01495       TEX tex0, fragment.texcoord[0], texture[0], 2D; \n\
01496       MAD final.r, tex0, CM0, offset.r;               \n\
01497       MAD final.g, tex0, CM1, offset.g;               \n\
01498       MAD final.b, tex0, CM2, offset.b;               \n\
01499       MAD final.a, tex0, CM3, offset.a;               \n\
01500       MUL result.color, color0, final;                \n\
01501       END";
01502 
01503     _asm_tex_color_matrix_filter_prog = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
01504     _asm_tex_color_matrix_filter_prog->LoadVertexShader(AsmVtx.GetTCharPtr());
01505     _asm_tex_color_matrix_filter_prog->LoadPixelShader(AsmFrg.GetTCharPtr());
01506     _asm_tex_color_matrix_filter_prog->Link();
01507 
01508     _asm_texrect_color_matrix_filter_prog = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
01509     _asm_texrect_color_matrix_filter_prog->LoadVertexShader(AsmVtx.GetTCharPtr());
01510     _asm_texrect_color_matrix_filter_prog->LoadPixelShader(AsmFrgRect.GetTCharPtr());
01511     _asm_texrect_color_matrix_filter_prog->Link();
01512   }
01513 
01514   void GraphicsEngine::QRP_ASM_ColorMatrix  (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
01515     const Color &c0, Matrix4 color_matrix, Vector4 offset)
01516   {
01517     NUX_RETURN_IF_FALSE(_asm_tex_color_matrix_filter_prog.IsValid());
01518     NUX_RETURN_IF_FALSE(_asm_texrect_color_matrix_filter_prog.IsValid());
01519 
01520     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
01521     float fx = x, fy = y;
01522     float VtxBuffer[] =
01523     {
01524       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f,
01525       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f,
01526       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f,
01527       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f,
01528     };
01529 
01530     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01531     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01532 
01533     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = _asm_tex_color_matrix_filter_prog;
01534     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
01535     {
01536       shader_program = _asm_texrect_color_matrix_filter_prog;
01537     }
01538     shader_program->Begin();
01539 
01540     SetTexture(GL_TEXTURE0, device_texture);
01541 
01542     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, c0.red, c0.green, c0.blue, c0.alpha));
01543     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, color_matrix.m[0][0], color_matrix.m[0][1], color_matrix.m[0][2], color_matrix.m[0][3]));
01544     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 2, color_matrix.m[1][0], color_matrix.m[1][1], color_matrix.m[1][2], color_matrix.m[1][3]));
01545     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 3, color_matrix.m[2][0], color_matrix.m[2][1], color_matrix.m[2][2], color_matrix.m[2][3]));
01546     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 4, color_matrix.m[3][0], color_matrix.m[3][1], color_matrix.m[3][2], color_matrix.m[3][3]));
01547     CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 5, offset.x, offset.y, offset.z, offset.w));
01548 
01549     CHECKGL(glMatrixMode(GL_MODELVIEW));
01550     CHECKGL(glLoadIdentity());
01551     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01552     CHECKGL(glMatrixMode(GL_PROJECTION));
01553     CHECKGL(glLoadIdentity());
01554     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01555 
01556 
01557     int VertexLocation          = VTXATTRIB_POSITION;
01558     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
01559 
01560     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01561     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer));
01562 
01563     if (TextureCoord0Location != -1)
01564     {
01565       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
01566       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 32, VtxBuffer + 4));
01567     }
01568 
01569     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
01570 
01571     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01572 
01573     if (TextureCoord0Location != -1)
01574       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
01575 
01576     shader_program->End();
01577   }
01578 
01579   void GraphicsEngine::InitAsmSeparableGaussFilter()
01580   {
01581     NString AsmVtx = 
01582       "!!ARBvp1.0                                 \n\
01583       ATTRIB iPos         = vertex.position;      \n\
01584       OUTPUT oPos         = result.position;      \n\
01585       OUTPUT oTexCoord0   = result.texcoord[0];   \n\
01586       OUTPUT oTexCoord1   = result.texcoord[1];   \n\
01587       OUTPUT oTexCoord2   = result.texcoord[2];   \n\
01588       OUTPUT oTexCoord3   = result.texcoord[3];   \n\
01589       OUTPUT oTexCoord4   = result.texcoord[4];   \n\
01590       OUTPUT oTexCoord5   = result.texcoord[5];   \n\
01591       OUTPUT oTexCoord6   = result.texcoord[6];   \n\
01592       # Transform the vertex to clip coordinates. \n\
01593       DP4   oPos.x, state.matrix.mvp.row[0], vertex.position;      \n\
01594       DP4   oPos.y, state.matrix.mvp.row[1], vertex.position;      \n\
01595       DP4   oPos.z, state.matrix.mvp.row[2], vertex.position;      \n\
01596       DP4   oPos.w, state.matrix.mvp.row[3], vertex.position;      \n\
01597       MOV   oTexCoord0, vertex.attrib[8];         \n\
01598       MOV   oTexCoord1, vertex.attrib[9];         \n\
01599       MOV   oTexCoord2, vertex.attrib[10];        \n\
01600       MOV   oTexCoord3, vertex.attrib[11];        \n\
01601       MOV   oTexCoord4, vertex.attrib[12];        \n\
01602       MOV   oTexCoord5, vertex.attrib[13];        \n\
01603       MOV   oTexCoord6, vertex.attrib[14];        \n\
01604       END";
01605 
01606 
01607     NString AsmFrg = 
01608       "!!ARBfp1.0                                                   \n\
01609       TEMP tex0;                                                    \n\
01610       TEMP final;                                                   \n\
01611       MOV final, {0, 0, 0, 0};                                      \n\
01612       TEX tex0, fragment.texcoord[0], texture[0], 2D;               \n\
01613       MAD final, tex0, program.local[0], final;                     \n\
01614       TEX tex0, fragment.texcoord[1], texture[0], 2D;               \n\
01615       MAD final, tex0, program.local[1], final;                     \n\
01616       TEX tex0, fragment.texcoord[2], texture[0], 2D;               \n\
01617       MAD final, tex0, program.local[2], final;                     \n\
01618       TEX tex0, fragment.texcoord[3], texture[0], 2D;               \n\
01619       MAD final, tex0, program.local[3], final;                     \n\
01620       TEX tex0, fragment.texcoord[4], texture[0], 2D;               \n\
01621       MAD final, tex0, program.local[4], final;                     \n\
01622       TEX tex0, fragment.texcoord[5], texture[0], 2D;               \n\
01623       MAD final, tex0, program.local[5], final;                     \n\
01624       TEX tex0, fragment.texcoord[6], texture[0], 2D;               \n\
01625       MAD final, tex0, program.local[6], final;                     \n\
01626       MOV result.color, final;                                      \n\
01627       END";
01628 
01629 
01630     NString AsmFrgRect = 
01631       "!!ARBfp1.0                                                   \n\
01632       TEMP tex0;                                                    \n\
01633       TEMP final;                                                   \n\
01634       MOV final, {0, 0, 0, 0};                                      \n\
01635       TEX tex0, fragment.texcoord[0], texture[0], RECT;             \n\
01636       MAD final, tex0, program.local[0], final;                     \n\
01637       TEX tex0, fragment.texcoord[1], texture[0], RECT;             \n\
01638       MAD final, tex0, program.local[1], final;                     \n\
01639       TEX tex0, fragment.texcoord[2], texture[0], RECT;             \n\
01640       MAD final, tex0, program.local[2], final;                     \n\
01641       TEX tex0, fragment.texcoord[3], texture[0], RECT;             \n\
01642       MAD final, tex0, program.local[3], final;                     \n\
01643       TEX tex0, fragment.texcoord[4], texture[0], RECT;             \n\
01644       MAD final, tex0, program.local[4], final;                     \n\
01645       TEX tex0, fragment.texcoord[5], texture[0], RECT;             \n\
01646       MAD final, tex0, program.local[5], final;                     \n\
01647       TEX tex0, fragment.texcoord[6], texture[0], RECT;             \n\
01648       MAD final, tex0, program.local[6], final;                     \n\
01649       MOV result.color, final;                                      \n\
01650       END";
01651 
01652     _asm_tex_separable_gauss_filter_prog = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
01653     _asm_tex_separable_gauss_filter_prog->LoadVertexShader(AsmVtx.GetTCharPtr());
01654     _asm_tex_separable_gauss_filter_prog->LoadPixelShader(AsmFrg.GetTCharPtr());
01655     _asm_tex_separable_gauss_filter_prog->Link();
01656 
01657     _asm_texrect_separable_gauss_filter_prog = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
01658     _asm_texrect_separable_gauss_filter_prog->LoadVertexShader(AsmVtx.GetTCharPtr());
01659     _asm_texrect_separable_gauss_filter_prog->LoadPixelShader(AsmFrgRect.GetTCharPtr());
01660     _asm_texrect_separable_gauss_filter_prog->Link();
01661   }
01662 
01663   void GraphicsEngine::QRP_ASM_HorizontalGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &c0, float sigma)
01664   {
01665     NUX_RETURN_IF_FALSE(_asm_tex_separable_gauss_filter_prog.IsValid());
01666     NUX_RETURN_IF_FALSE(_asm_texrect_separable_gauss_filter_prog.IsValid());
01667 
01668     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
01669 
01670     float delta = 1.0f / device_texture->GetWidth();
01671 
01672     float fx = x, fy = y;
01673     float VtxBuffer[] =
01674     {
01675       fx,          fy,          0.0f, 1.0f, 
01676       texxform.u0 - 3.0f * delta, texxform.v0, 0, 1.0f,
01677       texxform.u0 - 2.0f * delta, texxform.v0, 0, 1.0f,
01678       texxform.u0 - 1.0f * delta, texxform.v0, 0, 1.0f,
01679       texxform.u0 + 0.0f * delta, texxform.v0, 0, 1.0f,
01680       texxform.u0 + 1.0f * delta, texxform.v0, 0, 1.0f,
01681       texxform.u0 + 2.0f * delta, texxform.v0, 0, 1.0f,
01682       texxform.u0 + 3.0f * delta, texxform.v0, 0, 1.0f,
01683       fx,          fy + height, 0.0f, 1.0f,
01684       texxform.u0 - 3.0f * delta, texxform.v1, 0, 1.0f,
01685       texxform.u0 - 2.0f * delta, texxform.v1, 0, 1.0f,
01686       texxform.u0 - 1.0f * delta, texxform.v1, 0, 1.0f,
01687       texxform.u0 + 0.0f * delta, texxform.v1, 0, 1.0f,
01688       texxform.u0 + 1.0f * delta, texxform.v1, 0, 1.0f,
01689       texxform.u0 + 2.0f * delta, texxform.v1, 0, 1.0f,
01690       texxform.u0 + 3.0f * delta, texxform.v1, 0, 1.0f,
01691       fx + width,  fy + height, 0.0f, 1.0f,
01692       texxform.u1 - 3.0f * delta, texxform.v1, 0, 1.0f,
01693       texxform.u1 - 2.0f * delta, texxform.v1, 0, 1.0f,
01694       texxform.u1 - 1.0f * delta, texxform.v1, 0, 1.0f,
01695       texxform.u1 + 0.0f * delta, texxform.v1, 0, 1.0f,
01696       texxform.u1 + 1.0f * delta, texxform.v1, 0, 1.0f,
01697       texxform.u1 + 2.0f * delta, texxform.v1, 0, 1.0f,
01698       texxform.u1 + 3.0f * delta, texxform.v1, 0, 1.0f,
01699       fx + width,  fy,          0.0f, 1.0f,
01700       texxform.u1 - 3.0f * delta, texxform.v0, 0, 1.0f,
01701       texxform.u1 - 2.0f * delta, texxform.v0, 0, 1.0f,
01702       texxform.u1 - 1.0f * delta, texxform.v0, 0, 1.0f,
01703       texxform.u1 + 0.0f * delta, texxform.v0, 0, 1.0f,
01704       texxform.u1 + 1.0f * delta, texxform.v0, 0, 1.0f,
01705       texxform.u1 + 2.0f * delta, texxform.v0, 0, 1.0f,
01706       texxform.u1 + 3.0f * delta, texxform.v0, 0, 1.0f,
01707     };
01708 
01709     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01710     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01711 
01712     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = _asm_tex_separable_gauss_filter_prog;
01713     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
01714     {
01715       shader_program = _asm_texrect_separable_gauss_filter_prog;
01716     }
01717     shader_program->Begin();
01718 
01719     SetTexture(GL_TEXTURE0, device_texture);
01720 
01721     // Set the Gaussian weights
01722     {
01723       float *W;
01724       GaussianWeights(&W, 1, 7);
01725 
01726       for (int i = 0; i < 7; i++)
01727       {
01728         CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, i, W[i], W[i], W[i], W[i]));
01729       }
01730       delete[] W;
01731     }
01732 
01733     CHECKGL(glMatrixMode(GL_MODELVIEW));
01734     CHECKGL(glLoadIdentity());
01735     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01736     CHECKGL(glMatrixMode(GL_PROJECTION));
01737     CHECKGL(glLoadIdentity());
01738     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01739 
01740 
01741     int VertexLocation          = VTXATTRIB_POSITION;
01742     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
01743     int TextureCoord1Location   = VTXATTRIB_TEXCOORD1;
01744     int TextureCoord2Location   = VTXATTRIB_TEXCOORD2;
01745     int TextureCoord3Location   = VTXATTRIB_TEXCOORD3;
01746     int TextureCoord4Location   = VTXATTRIB_TEXCOORD4;
01747     int TextureCoord5Location   = VTXATTRIB_TEXCOORD5;
01748     int TextureCoord6Location   = VTXATTRIB_TEXCOORD6;
01749 
01750     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01751     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer));
01752 
01753     //if(TextureCoord0Location != -1)
01754     {
01755       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
01756       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
01757       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord2Location));
01758       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord3Location));
01759       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord4Location));
01760       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord5Location));
01761       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord6Location));
01762 
01763       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 4));
01764       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 8));
01765       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord2Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 12));
01766       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord3Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 16));
01767       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord4Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 20));
01768       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord5Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 24));
01769       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord6Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 28));
01770     }
01771 
01772     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
01773 
01774     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01775 
01776     if (TextureCoord0Location != -1)
01777       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
01778     if (TextureCoord1Location != -1)
01779       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
01780     if (TextureCoord2Location != -1)
01781       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord2Location));
01782     if (TextureCoord3Location != -1)
01783       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord3Location));
01784     if (TextureCoord4Location != -1)
01785       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord4Location));
01786     if (TextureCoord5Location != -1)
01787       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord5Location));
01788     if (TextureCoord6Location != -1)
01789       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord6Location));
01790 
01791     shader_program->End();
01792   }
01793 
01794   void GraphicsEngine::QRP_ASM_VerticalGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &c0, float sigma)
01795   {
01796     NUX_RETURN_IF_FALSE(_asm_tex_separable_gauss_filter_prog.IsValid());
01797     NUX_RETURN_IF_FALSE(_asm_texrect_separable_gauss_filter_prog.IsValid());
01798 
01799     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
01800 
01801     float delta = 1.0f / device_texture->GetHeight();
01802 
01803     float fx = x, fy = y;
01804     float VtxBuffer[] =
01805     {
01806       fx,          fy,          0.0f, 1.0f,
01807       texxform.u0, texxform.v0 - 3.0f * delta, 0, 1.0f,
01808       texxform.u0, texxform.v0 - 2.0f * delta, 0, 1.0f,
01809       texxform.u0, texxform.v0 - 1.0f * delta, 0, 1.0f,
01810       texxform.u0, texxform.v0 + 0.0f * delta, 0, 1.0f,
01811       texxform.u0, texxform.v0 + 1.0f * delta, 0, 1.0f,
01812       texxform.u0, texxform.v0 + 2.0f * delta, 0, 1.0f,
01813       texxform.u0, texxform.v0 + 3.0f * delta, 0, 1.0f,
01814       fx,          fy + height, 0.0f, 1.0f,
01815       texxform.u0, texxform.v1 - 3.0f * delta, 0, 1.0f,
01816       texxform.u0, texxform.v1 - 2.0f * delta, 0, 1.0f,
01817       texxform.u0, texxform.v1 - 1.0f * delta, 0, 1.0f,
01818       texxform.u0, texxform.v1 + 0.0f * delta, 0, 1.0f,
01819       texxform.u0, texxform.v1 + 1.0f * delta, 0, 1.0f,
01820       texxform.u0, texxform.v1 + 2.0f * delta, 0, 1.0f,
01821       texxform.u0, texxform.v1 + 3.0f * delta, 0, 1.0f,
01822       fx + width,  fy + height, 0.0f, 1.0f,
01823       texxform.u1, texxform.v1 - 3.0f * delta, 0, 1.0f,
01824       texxform.u1, texxform.v1 - 2.0f * delta, 0, 1.0f,
01825       texxform.u1, texxform.v1 - 1.0f * delta, 0, 1.0f,
01826       texxform.u1, texxform.v1 + 0.0f * delta, 0, 1.0f,
01827       texxform.u1, texxform.v1 + 1.0f * delta, 0, 1.0f,
01828       texxform.u1, texxform.v1 + 2.0f * delta, 0, 1.0f,
01829       texxform.u1, texxform.v1 + 3.0f * delta, 0, 1.0f,
01830       fx + width,  fy,          0.0f, 1.0f,
01831       texxform.u1, texxform.v0 - 3.0f * delta, 0, 1.0f,
01832       texxform.u1, texxform.v0 - 2.0f * delta, 0, 1.0f,
01833       texxform.u1, texxform.v0 - 1.0f * delta, 0, 1.0f,
01834       texxform.u1, texxform.v0 + 0.0f * delta, 0, 1.0f,
01835       texxform.u1, texxform.v0 + 1.0f * delta, 0, 1.0f,
01836       texxform.u1, texxform.v0 + 2.0f * delta, 0, 1.0f,
01837       texxform.u1, texxform.v0 + 3.0f * delta, 0, 1.0f,
01838     };
01839 
01840     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
01841     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
01842 
01843     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = _asm_tex_separable_gauss_filter_prog;
01844     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
01845     {
01846       shader_program = _asm_texrect_separable_gauss_filter_prog;
01847     }
01848     shader_program->Begin();
01849 
01850     SetTexture(GL_TEXTURE0, device_texture);
01851 
01852     // Set the Gaussian weights
01853     {
01854       float *W;
01855       GaussianWeights(&W, 1, 7);
01856 
01857       for (int i = 0; i < 7; i++)
01858       {
01859         CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, i, W[i], W[i], W[i], W[i]));
01860       }
01861       delete[] W;
01862     }
01863 
01864     CHECKGL(glMatrixMode(GL_MODELVIEW));
01865     CHECKGL(glLoadIdentity());
01866     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
01867     CHECKGL(glMatrixMode(GL_PROJECTION));
01868     CHECKGL(glLoadIdentity());
01869     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
01870 
01871 
01872     int VertexLocation          = VTXATTRIB_POSITION;
01873     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
01874     int TextureCoord1Location   = VTXATTRIB_TEXCOORD1;
01875     int TextureCoord2Location   = VTXATTRIB_TEXCOORD2;
01876     int TextureCoord3Location   = VTXATTRIB_TEXCOORD3;
01877     int TextureCoord4Location   = VTXATTRIB_TEXCOORD4;
01878     int TextureCoord5Location   = VTXATTRIB_TEXCOORD5;
01879     int TextureCoord6Location   = VTXATTRIB_TEXCOORD6;
01880 
01881     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
01882     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer));
01883 
01884     //if(TextureCoord0Location != -1)
01885     {
01886       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
01887       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord1Location));
01888       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord2Location));
01889       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord3Location));
01890       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord4Location));
01891       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord5Location));
01892       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord6Location));
01893 
01894       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 4));
01895       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord1Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 8));
01896       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord2Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 12));
01897       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord3Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 16));
01898       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord4Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 20));
01899       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord5Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 24));
01900       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord6Location, 4, GL_FLOAT, GL_FALSE, 128, VtxBuffer + 28));
01901     }
01902 
01903     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
01904 
01905     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
01906 
01907     if (TextureCoord0Location != -1)
01908       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
01909     if (TextureCoord1Location != -1)
01910       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord1Location));
01911     if (TextureCoord2Location != -1)
01912       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord2Location));
01913     if (TextureCoord3Location != -1)
01914       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord3Location));
01915     if (TextureCoord4Location != -1)
01916       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord4Location));
01917     if (TextureCoord5Location != -1)
01918       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord5Location));
01919     if (TextureCoord6Location != -1)
01920       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord6Location));
01921 
01922     shader_program->End();
01923   }
01924 
01925   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetBlurTexture(
01926     int x, int y,
01927     int buffer_width, int buffer_height,
01928     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
01929     const Color& c0,
01930     float sigma, int num_pass)
01931   {
01932     //     _offscreen_color_rt0.Release();
01933     //     _offscreen_color_rt1.Release();
01934     //     _offscreen_depth_rt0.Release();
01935     //     _offscreen_depth_rt1.Release();
01936 
01937     int quad_width = device_texture->GetWidth();
01938     int quad_height = device_texture->GetHeight();
01939 
01940     num_pass = Clamp<int> (num_pass, 1, 5);
01941 
01942     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
01943     int previous_width = 0;
01944     int previous_height = 0;
01945     if (prevFBO.IsValid())
01946     {
01947       previous_width = prevFBO->GetWidth();
01948       previous_height = prevFBO->GetHeight();
01949     }
01950     else
01951     {
01952       previous_width = _graphics_display.GetWindowWidth();
01953       previous_height = _graphics_display.GetWindowHeight();
01954     }
01955 
01956     CHECKGL(glClearColor(0, 0, 0, 0));
01957     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
01958     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
01959     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
01960     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
01961 
01962     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
01963     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
01964 
01965     QRP_ASM_1Tex(x, y, quad_width, quad_height, device_texture, texxform, color::White);
01966 
01967     TexCoordXForm texxform1;
01968     for (int i = 0; i < num_pass; i++)
01969     {
01970       SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, buffer_width, buffer_height);
01971       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
01972       QRP_ASM_HorizontalGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt0, texxform1, c0);
01973 
01974       SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, buffer_width, buffer_height);
01975       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
01976       QRP_ASM_VerticalGauss(0, 0, buffer_width, buffer_height, _offscreen_color_rt1, texxform1, c0);
01977     }
01978 
01979     _offscreen_fbo->Deactivate();
01980 
01981     if (prevFBO.IsValid())
01982     {
01983       prevFBO->Activate(true);
01984       SetViewport(0, 0, previous_width, previous_height);
01985     }
01986     else
01987     {
01988       SetViewport(0, 0, previous_width, previous_height);
01989     }
01990 
01991     return _offscreen_color_rt0;
01992   }
01993 
01994   void GraphicsEngine::QRP_ASM_GetBlurTextureFx(
01995       int x, int y, int buffer_width, int buffer_height,
01996       FxStructure *fx_structure, TexCoordXForm &texxform, const Color& color, float sigma, int num_pass)
01997   {
01998     int quad_width = fx_structure->src_texture->GetWidth();
01999     int quad_height = fx_structure->src_texture->GetHeight();
02000 
02001     num_pass = Clamp<int> (num_pass, 1, 5);
02002 
02003     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02004     int previous_width = 0;
02005     int previous_height = 0;
02006     if (prevFBO.IsValid())
02007     {
02008       previous_width = prevFBO->GetWidth();
02009       previous_height = prevFBO->GetHeight();
02010     }
02011     else
02012     {
02013       previous_width = _graphics_display.GetWindowWidth();
02014       previous_height = _graphics_display.GetWindowHeight();
02015     }
02016 
02017     CHECKGL(glClearColor(0, 0, 0, 0));
02018     fx_structure->src_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02019     fx_structure->src_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
02020     fx_structure->dst_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02021     fx_structure->dst_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
02022     fx_structure->temp_texture->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02023     fx_structure->temp_texture->SetFiltering(GL_NEAREST, GL_NEAREST);
02024         
02025     SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
02026     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02027 
02028     QRP_ASM_1Tex(x, y, quad_width, quad_height, fx_structure->src_texture, texxform, color::White);
02029 
02030     TexCoordXForm texxform1;
02031     for (int i = 0; i < num_pass; i++)
02032     {
02033       SetFrameBufferHelper(_offscreen_fbo, fx_structure->temp_texture, _offscreen_depth_rt1, buffer_width, buffer_height);
02034       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02035       QRP_ASM_HorizontalGauss(0, 0, buffer_width, buffer_height, fx_structure->dst_texture, texxform1, color);
02036 
02037       SetFrameBufferHelper(_offscreen_fbo, fx_structure->dst_texture, _offscreen_depth_rt0, buffer_width, buffer_height);
02038       glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02039       QRP_ASM_VerticalGauss(0, 0, buffer_width, buffer_height, fx_structure->temp_texture, texxform1, color);
02040     }
02041 
02042     _offscreen_fbo->Deactivate();
02043 
02044     if (prevFBO.IsValid())
02045     {
02046       prevFBO->Activate(true);
02047       SetViewport(0, 0, previous_width, previous_height);
02048     }
02049     else
02050     {
02051       SetViewport(0, 0, previous_width, previous_height);
02052     }
02053   }      
02054 
02055   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetPower(
02056     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color & c0, const Vector4 &exponent)
02057   {
02058     int quad_width = device_texture->GetWidth();
02059     int quad_height = device_texture->GetHeight();
02060 
02061     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02062     int previous_width = 0;
02063     int previous_height = 0;
02064     if (prevFBO.IsValid())
02065     {
02066       previous_width = prevFBO->GetWidth();
02067       previous_height = prevFBO->GetHeight();
02068     }
02069     else
02070     {
02071       previous_width = _graphics_display.GetWindowWidth();
02072       previous_height = _graphics_display.GetWindowHeight();
02073     }
02074 
02075     CHECKGL(glClearColor(0, 0, 0, 0));
02076     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02077     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02078     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02079     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02080 
02081     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02082     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02083     QRP_ASM_1Tex(0, 0, quad_width, quad_height, device_texture, texxform, color::White);
02084 
02085     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width, quad_height);
02086     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02087     QRP_ASM_Power(0, 0, quad_width, quad_height, _offscreen_color_rt0, texxform, c0, exponent);
02088 
02089     _offscreen_fbo->Deactivate();
02090 
02091     if (prevFBO.IsValid())
02092     {
02093       prevFBO->Activate(true);
02094       SetViewport(0, 0, previous_width, previous_height);
02095     }
02096     else
02097     {
02098       SetViewport(0, 0, previous_width, previous_height);
02099     }
02100 
02101     return _offscreen_color_rt1;
02102   }
02103 
02104   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetAlphaTexture(
02105     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
02106     const Color & c0)
02107   {
02108     //     _offscreen_color_rt0.Release();
02109     //     _offscreen_color_rt1.Release();
02110     //     _offscreen_depth_rt0.Release();
02111     //     _offscreen_depth_rt1.Release();
02112 
02113     int quad_width = device_texture->GetWidth();
02114     int quad_height = device_texture->GetHeight();
02115 
02116     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02117     int previous_width = 0;
02118     int previous_height = 0;
02119     if (prevFBO.IsValid())
02120     {
02121       previous_width = prevFBO->GetWidth();
02122       previous_height = prevFBO->GetHeight();
02123     }
02124     else
02125     {
02126       previous_width = _graphics_display.GetWindowWidth();
02127       previous_height = _graphics_display.GetWindowHeight();
02128     }
02129 
02130     CHECKGL(glClearColor(0, 0, 0, 0));
02131     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02132     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02133     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02134     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02135 
02136     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02137     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02138     QRP_ASM_1Tex(0, 0, quad_width, quad_height, device_texture, texxform, color::White);
02139 
02140     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width, quad_height);
02141     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02142     QRP_ASM_AlphaReplicate(0, 0, quad_width, quad_height, _offscreen_color_rt0, texxform, c0);
02143 
02144     _offscreen_fbo->Deactivate();
02145 
02146     if (prevFBO.IsValid())
02147     {
02148       prevFBO->Activate(true);
02149       SetViewport(0, 0, previous_width, previous_height);
02150     }
02151     else
02152     {
02153       SetViewport(0, 0, previous_width, previous_height);
02154     }
02155 
02156     return _offscreen_color_rt1;
02157   }
02158 
02159   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetColorMatrixTexture(
02160     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color & c0, Matrix4 color_matrix, Vector4 offset)
02161   {
02162     int quad_width = device_texture->GetWidth();
02163     int quad_height = device_texture->GetHeight();
02164 
02165     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02166     int previous_width = 0;
02167     int previous_height = 0;
02168     if (prevFBO.IsValid())
02169     {
02170       previous_width = prevFBO->GetWidth();
02171       previous_height = prevFBO->GetHeight();
02172     }
02173     else
02174     {
02175       previous_width = _graphics_display.GetWindowWidth();
02176       previous_height = _graphics_display.GetWindowHeight();
02177     }
02178 
02179     CHECKGL(glClearColor(0, 0, 0, 0));
02180     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02181     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02182     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02183     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02184 
02185     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02186     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02187     QRP_ASM_1Tex(0, 0, quad_width, quad_height, device_texture, texxform, color::White);
02188 
02189     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width, quad_height);
02190     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02191     QRP_ASM_ColorMatrix(0, 0, quad_width, quad_height, _offscreen_color_rt0, texxform, c0, color_matrix, offset);
02192 
02193     _offscreen_fbo->Deactivate();
02194 
02195     if (prevFBO.IsValid())
02196     {
02197       prevFBO->Activate(true);
02198       SetViewport(0, 0, previous_width, previous_height);
02199     }
02200     else
02201     {
02202       SetViewport(0, 0, previous_width, previous_height);
02203     }
02204 
02205     return _offscreen_color_rt1;
02206   }
02207 
02208   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetLQBlur(
02209     int x, int y,
02210     int buffer_width, int buffer_height,
02211     ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform,
02212     const Color& c0)
02213   {
02214     //     _offscreen_color_rt0.Release();
02215     //     _offscreen_color_rt1.Release();
02216     //     _offscreen_depth_rt0.Release();
02217     //     _offscreen_depth_rt1.Release();
02218 
02219     int quad_width = device_texture->GetWidth();
02220     int quad_height = device_texture->GetHeight();
02221 
02222     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02223     int previous_width = 0;
02224     int previous_height = 0;
02225     if (prevFBO.IsValid())
02226     {
02227       previous_width  = prevFBO->GetWidth();
02228       previous_height = prevFBO->GetHeight();
02229     }
02230     else
02231     {
02232       previous_width  = _graphics_display.GetWindowWidth();
02233       previous_height = _graphics_display.GetWindowHeight();
02234     }
02235 
02236     CHECKGL(glClearColor(0, 0, 0, 0));
02237     _offscreen_color_rt0->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02238     _offscreen_color_rt0->SetFiltering(GL_NEAREST, GL_NEAREST);
02239     _offscreen_color_rt1->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02240     _offscreen_color_rt1->SetFiltering(GL_NEAREST, GL_NEAREST);
02241     _offscreen_color_rt2->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02242     _offscreen_color_rt2->SetFiltering(GL_NEAREST, GL_NEAREST);
02243     _offscreen_color_rt3->SetWrap(GL_CLAMP, GL_CLAMP, GL_CLAMP);
02244     _offscreen_color_rt3->SetFiltering(GL_NEAREST, GL_NEAREST);
02245 
02246     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width/2, quad_height/2);
02247     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02248     QRP_ASM_1Tex(0, 0, quad_width / 2, quad_height / 2, device_texture, texxform, color::White);
02249 
02250     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt1, _offscreen_depth_rt1, quad_width/4, quad_height/4);
02251     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02252     QRP_ASM_1Tex(0, 0, quad_width / 4, quad_height / 4, _offscreen_color_rt0, texxform, color::White);
02253 
02254     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt2, _offscreen_depth_rt2, quad_width/8, quad_height/8);
02255     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02256     QRP_ASM_1Tex(0, 0, quad_width / 8, quad_height / 8, _offscreen_color_rt1, texxform, color::White);
02257 
02258     SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt3, _offscreen_depth_rt3, quad_width, quad_height);
02259     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
02260 
02261     TexCoordXForm texxform0;
02262     TexCoordXForm texxform1;
02263     TexCoordXForm texxform2;
02264     TexCoordXForm texxform3;
02265 
02266     texxform0.flip_v_coord = true;
02267     texxform2.flip_v_coord = true;
02268     QRP_ASM_4Tex(0, 0, quad_width, quad_height,
02269       device_texture, texxform0, Color(0.25, 0.25, 0.25, 0.25),
02270       _offscreen_color_rt0, texxform1, Color(0.25, 0.25, 0.25, 0.25),
02271       _offscreen_color_rt1, texxform2, Color(0.25, 0.25, 0.25, 0.25),
02272       _offscreen_color_rt2, texxform3, Color(0.25, 0.25, 0.25, 0.25));
02273 
02274     _offscreen_fbo->Deactivate();
02275 
02276     if (prevFBO.IsValid())
02277     {
02278       prevFBO->Activate(true);
02279       SetViewport(0, 0, previous_width, previous_height);
02280     }
02281     else
02282     {
02283       SetViewport(0, 0, previous_width, previous_height);
02284     }
02285     return _offscreen_color_rt3;
02286   }
02287 
02288   void GraphicsEngine::InitAsmPixelateShader()
02289   {
02290     NString AsmVtx = 
02291       "!!ARBvp1.0                                 \n\
02292       ATTRIB iPos         = vertex.position;      \n\
02293       ATTRIB iColor       = vertex.attrib[3];     \n\
02294       PARAM  mvp[4]       = {state.matrix.mvp};   \n\
02295       OUTPUT oPos         = result.position;      \n\
02296       OUTPUT oColor       = result.color;         \n\
02297       OUTPUT oTexCoord0   = result.texcoord[0];   \n\
02298       # Transform the vertex to clip coordinates. \n\
02299       DP4   oPos.x, mvp[0], iPos;                     \n\
02300       DP4   oPos.y, mvp[1], iPos;                     \n\
02301       DP4   oPos.z, mvp[2], iPos;                     \n\
02302       DP4   oPos.w, mvp[3], iPos;                     \n\
02303       MOV   oColor, iColor;                           \n\
02304       MOV   oTexCoord0, vertex.attrib[8];             \n\
02305       END";
02306 
02307     NString AsmFrg = 
02308       "!!ARBfp1.0                                       \n\
02309       TEMP tex0;                                        \n\
02310       TEMP tex_coord;                                   \n\
02311       PARAM pixel_size = program.local [0];             \n\
02312       PARAM pixel_size_inv = program.local [1];         \n\
02313       MUL tex_coord, fragment.texcoord[0], pixel_size_inv; \n\
02314       FLR tex_coord, tex_coord;                         \n\
02315       MUL tex_coord, tex_coord, pixel_size;  \n\
02316       TEX tex0, tex_coord, texture[0], 2D;              \n\
02317       MUL result.color, fragment.color, tex0;           \n\
02318       END";
02319 
02320     NString AsmFrgRect = 
02321       "!!ARBfp1.0                                       \n\
02322       TEMP tex0;                                        \n\
02323       TEMP tex_coord;                                   \n\
02324       PARAM pixel_size = program.local [0];             \n\
02325       PARAM pixel_size_inv = program.local [1];         \n\
02326       MUL tex_coord, fragment.texcoord[0], pixel_size_inv; \n\
02327       FLR tex_coord, tex_coord;                         \n\
02328       MUL tex_coord, tex_coord, pixel_size;  \n\
02329       TEX tex0, tex_coord, texture[0], RECT;            \n\
02330       MUL result.color, fragment.color, tex0;           \n\
02331       END";
02332 
02333     m_AsmPixelate = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
02334     m_AsmPixelate->LoadVertexShader(AsmVtx.GetTCharPtr());
02335     m_AsmPixelate->LoadPixelShader(AsmFrg.GetTCharPtr());
02336     m_AsmPixelate->Link();
02337 
02338     m_AsmPixelateRect = GetGraphicsDisplay()->GetGpuDevice()->CreateAsmShaderProgram();
02339     m_AsmPixelateRect->LoadVertexShader(AsmVtx.GetTCharPtr());
02340     m_AsmPixelateRect->LoadPixelShader(AsmFrgRect.GetTCharPtr());
02341     m_AsmPixelateRect->Link();
02342   }
02343 
02344   void GraphicsEngine::QRP_ASM_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform, const Color &color, int pixel_size)
02345   {
02346     NUX_RETURN_IF_FALSE(m_AsmPixelate.IsValid());
02347     NUX_RETURN_IF_FALSE(m_AsmPixelateRect.IsValid());
02348 
02349     if (pixel_size <= 0)
02350       pixel_size = 1;
02351 
02352     QRP_Compute_Texture_Coord(width, height, device_texture, texxform);
02353     float fx = x, fy = y;
02354     float VtxBuffer[] =
02355     {
02356       fx,          fy,          0.0f, 1.0f, texxform.u0, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
02357       fx,          fy + height, 0.0f, 1.0f, texxform.u0, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
02358       fx + width,  fy + height, 0.0f, 1.0f, texxform.u1, texxform.v1, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
02359       fx + width,  fy,          0.0f, 1.0f, texxform.u1, texxform.v0, 0, 1.0f, color.red, color.green, color.blue, color.alpha,
02360     };
02361 
02362     float tex_width = device_texture->GetWidth();
02363     float tex_height = device_texture->GetHeight();
02364 
02365     CHECKGL(glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0));
02366     CHECKGL(glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0));
02367 
02368     bool rectangle_texture = false;
02369     ObjectPtr<IOpenGLAsmShaderProgram> shader_program = m_AsmPixelate;
02370     if (device_texture->Type().IsDerivedFromType(IOpenGLRectangleTexture::StaticObjectType))
02371     {
02372       shader_program = m_AsmPixelateRect;
02373       rectangle_texture = true;
02374     }
02375     shader_program->Begin();
02376 
02377     SetTexture(GL_TEXTURE0, device_texture);
02378 
02379     CHECKGL(glMatrixMode(GL_MODELVIEW));
02380     CHECKGL(glLoadIdentity());
02381     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLModelViewMatrix().m));
02382     CHECKGL(glMatrixMode(GL_PROJECTION));
02383     CHECKGL(glLoadIdentity());
02384     CHECKGL(glLoadMatrixf((FLOAT *) GetOpenGLProjectionMatrix().m));
02385 
02386     int VertexLocation          = VTXATTRIB_POSITION;
02387     int TextureCoord0Location   = VTXATTRIB_TEXCOORD0;
02388     int VertexColorLocation     = VTXATTRIB_COLOR;
02389 
02390     if (rectangle_texture == false)
02391     {
02392       CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, (float)pixel_size/(float)tex_width, (float)pixel_size/(float)tex_height, 1.0f, 1.0f));
02393       CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, (float)tex_width/(float)pixel_size, (float)tex_height/(float)pixel_size, 1.0f, 1.0f));
02394     }
02395     else
02396     {
02397       CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 0, pixel_size, pixel_size, 1.0f, 1.0f));
02398       CHECKGL(glProgramLocalParameter4fARB(GL_FRAGMENT_PROGRAM_ARB, 1, 1.0f/pixel_size, 1.0f/pixel_size, 1.0f, 1.0f));
02399     }
02400 
02401     CHECKGL(glEnableVertexAttribArrayARB(VertexLocation));
02402     CHECKGL(glVertexAttribPointerARB((GLuint) VertexLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer));
02403 
02404     if (TextureCoord0Location != -1)
02405     {
02406       CHECKGL(glEnableVertexAttribArrayARB(TextureCoord0Location));
02407       CHECKGL(glVertexAttribPointerARB((GLuint) TextureCoord0Location, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 4));
02408     }
02409 
02410     if (VertexColorLocation != -1)
02411     {
02412       CHECKGL(glEnableVertexAttribArrayARB(VertexColorLocation));
02413       CHECKGL(glVertexAttribPointerARB((GLuint) VertexColorLocation, 4, GL_FLOAT, GL_FALSE, 48, VtxBuffer + 8));
02414     }
02415 
02416     CHECKGL(glDrawArrays(GL_TRIANGLE_FAN, 0, 4));
02417 
02418     CHECKGL(glDisableVertexAttribArrayARB(VertexLocation));
02419 
02420     if (TextureCoord0Location != -1)
02421       CHECKGL(glDisableVertexAttribArrayARB(TextureCoord0Location));
02422 
02423     if (VertexColorLocation != -1)
02424       CHECKGL(glDisableVertexAttribArrayARB(VertexColorLocation));
02425 
02426     shader_program->End();
02427   }
02428 
02429   ObjectPtr<IOpenGLBaseTexture> GraphicsEngine::QRP_ASM_GetPixelBlocks(
02430          ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm &texxform0, const Color& c0, int pixel_size)
02431   {
02432          int quad_width = device_texture->GetWidth();
02433          int quad_height = device_texture->GetHeight();
02434 
02435          ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02436          int previous_width = 0;
02437          int previous_height = 0;
02438          if (prevFBO.IsValid())
02439          {
02440                 previous_width  = prevFBO->GetWidth();
02441                 previous_height = prevFBO->GetHeight();
02442          }
02443          else
02444          {
02445                 previous_width  = _graphics_display.GetWindowWidth();
02446                 previous_height = _graphics_display.GetWindowHeight();
02447          }
02448 
02449     CHECKGL(glClearColor(0, 0, 0, 0));
02450          SetFrameBufferHelper(_offscreen_fbo, _offscreen_color_rt0, _offscreen_depth_rt0, quad_width, quad_height);
02451          CHECKGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
02452          QRP_ASM_Pixelate(0, 0, quad_width, quad_height, device_texture, texxform0, c0, pixel_size);
02453 
02454          _offscreen_fbo->Deactivate();
02455 
02456          if (prevFBO.IsValid())
02457          {
02458                 prevFBO->Activate(true);
02459                 SetViewport(0, 0, previous_width, previous_height);
02460          }
02461          else
02462          {
02463                 SetViewport(0, 0, previous_width, previous_height);
02464          }
02465          return _offscreen_color_rt0;
02466   }
02467 
02468   void GraphicsEngine::QRP_ASM_GetCopyTexture(
02469     int width, int height,
02470     ObjectPtr<IOpenGLBaseTexture>& dst_device_texture,
02471     ObjectPtr<IOpenGLBaseTexture>& src_device_texture,
02472     TexCoordXForm &texxform0, const Color& c0)
02473   {
02474     if (src_device_texture.IsValid() == false)
02475     {
02476       return;
02477     }
02478 
02479     ObjectPtr<IOpenGLFrameBufferObject> prevFBO = GetGraphicsDisplay()->GetGpuDevice()->GetCurrentFrameBufferObject();
02480     int previous_width = 0;
02481     int previous_height = 0;
02482 
02483     if (prevFBO.IsValid())
02484     {
02485       previous_width = prevFBO->GetWidth();
02486       previous_height = prevFBO->GetHeight();
02487     }
02488     else
02489     {
02490       previous_width = _graphics_display.GetWindowWidth();
02491       previous_height = _graphics_display.GetWindowHeight();
02492     }
02493 
02494     if ((dst_device_texture.IsValid() == false) ||
02495       (dst_device_texture->GetWidth() != width) ||
02496       (dst_device_texture->GetHeight() != height) ||
02497       (dst_device_texture->GetPixelFormat() != src_device_texture->GetPixelFormat()))
02498     {
02499       dst_device_texture = _graphics_display.GetGpuDevice()->CreateTexture(width, height, 1, src_device_texture->GetPixelFormat());
02500     }
02501 
02502     CHECKGL(glClearColor(0, 0, 0, 0));
02503     ObjectPtr<IOpenGLBaseTexture> depth_buffer(NULL);
02504     SetFrameBufferHelper(_offscreen_fbo, dst_device_texture, depth_buffer, width, height);
02505     CHECKGL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT));
02506 
02507     QRP_ASM_1Tex(0, 0, width, height, src_device_texture, texxform0, c0);
02508 
02509     _offscreen_fbo->Deactivate();
02510 
02511     if (prevFBO.IsValid())
02512     {
02513       prevFBO->Activate(true);
02514       SetViewport(0, 0, previous_width, previous_height);
02515     }
02516     else
02517     {
02518       SetViewport(0, 0, previous_width, previous_height);
02519     }
02520   }
02521 }
02522 #endif // NUX_OPENGLES_20
02523