Back to index

nux  3.0.0
GraphicsEngine.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010-2012 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef OPENGLENGINE_H
00024 #define OPENGLENGINE_H
00025 
00026 #include "GLResource.h"
00027 #include "GpuDevice.h"
00028 #include "GLDeviceObjects.h"
00029 #include "GLResourceManager.h"
00030 #include "GLTextureResourceManager.h"
00031 #include "GLVertexResourceManager.h"
00032 #include "GLRenderStates.h"
00033 #include "FontTexture.h"
00034 #include "RenderingPipe.h"
00035 #include "GLShader.h"
00036 
00037 #if defined(NUX_OS_WINDOWS)
00038   #include "GraphicsDisplay.h"
00039   #include "GLWindowManager.h"
00040 #elif defined(NUX_OS_LINUX)
00041   #include "GraphicsDisplay.h"
00042   #include "GLWindowManager.h"
00043 #endif
00044 
00045 #define NUX_MAX_GAUSSIAN_SIGMA 11
00046 #define NUX_MIN_GAUSSIAN_SIGMA 1
00047 
00048 #ifndef NUX_OPENGLES_20
00049   #define NUX_VERTEX_SHADER_HEADER "#version 110               \n"
00050 #else
00051   #define NUX_VERTEX_SHADER_HEADER 
00052 #endif
00053 
00054 #ifndef NUX_OPENGLES_20
00055   #define NUX_FRAGMENT_SHADER_HEADER "#version 110               \n"
00056 #else
00057   #define NUX_FRAGMENT_SHADER_HEADER "precision mediump float;   \n"
00058 #endif
00059 
00060 namespace nux
00061 {
00062   class FontTexture;
00063   class FontRenderer;
00064   class FilePath;
00065   class BaseTexture;
00066   class TextureRectangle;
00067 
00068   class ROPConfig
00069   {
00070   public:
00071     ROPConfig();
00072     ~ROPConfig();
00073 
00074     bool Blend;
00075     unsigned int SrcBlend;
00076     unsigned int DstBlend;
00077 
00078     static ROPConfig Default;
00079   };
00080 
00081   class BlendOperator
00082   {
00083   public:
00084     BlendOperator();
00085     ~BlendOperator();
00086 
00087     void EnableBlending(bool enable);
00088     void SetPorterDuffOperator(PorterDuffOperator op);
00089     void SetCustomBlendOperator(unsigned int src_blend, unsigned int dst_blend);
00090 
00091     bool  _enable;
00092     unsigned int _src_blend;
00093     unsigned int _dst_blend;
00094   };
00095 
00096   typedef struct
00097   {
00098     int x;
00099     int y;
00100     int width;
00101     int height;
00102 
00103   } OpenGLContext;
00104 
00105   class FxStructure
00106   {
00107   public:
00108     FxStructure();
00109     ~FxStructure();
00110     ObjectPtr<IOpenGLBaseTexture> dst_texture;
00111     ObjectPtr<IOpenGLBaseTexture> src_texture;
00112     ObjectPtr<IOpenGLBaseTexture> temp_texture;
00113   };
00114 
00115   typedef enum
00116   {
00117     LAYER_BLEND_MODE_NORMAL,
00118     LAYER_BLEND_MODE_LIGHTEN,
00119     LAYER_BLEND_MODE_DARKEN,
00120     LAYER_BLEND_MODE_MULTIPLY,
00121     LAYER_BLEND_MODE_AVERAGE,
00122     LAYER_BLEND_MODE_ADD,
00123     LAYER_BLEND_MODE_SUBTRACT,
00124     LAYER_BLEND_MODE_DIFFERENCE,
00125     LAYER_BLEND_MODE_NEGATION,
00126     LAYER_BLEND_MODE_EXCLUSION,
00127     LAYER_BLEND_MODE_SCREEN,
00128     LAYER_BLEND_MODE_OVERLAY,
00129     LAYER_BLEND_MODE_SOFT_LIGHT,
00130     LAYER_BLEND_MODE_HARD_LIGHT,
00131     LAYER_BLEND_MODE_COLOR_DODGE,
00132     LAYER_BLEND_MODE_LINEAR_DODGE,
00133     LAYER_BLEND_MODE_COLOR_BURN,
00134     LAYER_BLEND_MODE_LINEAR_BLUR,
00135     LAYER_BLEND_MODE_LINEAR_LIGHT,
00136     LAYER_BLEND_MODE_VIVID_LIGHT,
00137     LAYER_BLEND_MODE_PIN_LIGHT,
00138     LAYER_BLEND_MODE_HARD_MIX,
00139     LAYER_BLEND_MODE_REFLECT,
00140     LAYER_BLEND_MODE_GLOW,
00141     LAYER_BLEND_MODE_PHOENIX,
00142     LAYER_BLEND_MODE_OPACITY,
00143     LAYER_BLEND_MODE_LAST
00144   } LayerBlendMode;
00145 
00146 
00148 
00151   class GraphicsEngine
00152   {
00153   public:
00158     GraphicsEngine(GraphicsDisplay& GlWindow, bool create_rendering_data = true);
00159     ~GraphicsEngine();
00160 
00161     void SetContext(int x, int y, int width, int height);
00162     void GetContextSize(int& w, int& h) const;
00163     int GetContextWidth() const;
00164     int GetContextHeight() const;
00165     int GetContextX() const;
00166     int GetContextY() const;
00167 
00168     void GetWindowSize(int& w, int& h) const;
00169     int GetWindowWidth() const;
00170     int GetWindowHeight() const;
00171 
00172     OpenGLContext m_CurrrentContext;
00173 
00174     // Load Textures
00175     BaseTexture* Load2DTextureFile(const char* filename);
00176     BaseTexture* Load2DRectangleTextureFile(const char* filename);
00177     BaseTexture* Load2DTextureFileGenerateAlpha(const char* filename, int red, int green, int blue);
00178 
00179     void SetTexture(int TextureUnit, BaseTexture* Texture);
00180     void SetTexture(int TextureUnit, ObjectPtr< IOpenGLBaseTexture > Texture);
00181     void EnableTextureMode(int TextureUnit, int TextureMode);
00182     void DisableTextureMode(int TextureUnit, int TextureMode);
00183     void DisableAllTextureMode(int TextureUnit);
00184 
00186     // DRAW TEXTURE  //
00188 
00189     // Neutral
00190     void QRP_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
00191     void QRP_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
00192     void QRP_Color(int x, int y, int width, int height, const Color& c0);
00193     void QRP_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3);
00194     void QRP_ColorModTexAlpha(int x, int y, int width, int height,
00195       ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform0, const Color& color);
00196 
00197     void QRP_2Tex(int x, int y, int width, int height,
00198       ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00199       ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1);
00200 
00201     void QRP_2TexMod(int x, int y, int width, int height,
00202       ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00203       ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1);
00204 
00205     void QRP_4Tex(int x, int y, int width, int height,
00206       ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00207       ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1,
00208       ObjectPtr<IOpenGLBaseTexture> DeviceTexture2, TexCoordXForm& texxform2, const Color& color2,
00209       ObjectPtr<IOpenGLBaseTexture> DeviceTexture3, TexCoordXForm& texxform3, const Color& color3);
00210 
00211     void QRP_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, Color c0);
00212     void QRP_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, Color c0, Color c1, Color c2);
00213     void QRP_Line(int x0, int y0, int x1, int y1, Color c0);
00214     void QRP_Line(int x0, int y0, int x1, int y1, Color c0, Color c1);
00215     void QRP_QuadWireframe(int x0, int y0, int width, int height, Color c0, Color c1, Color c2, Color c3);
00216 
00217 
00218     ObjectPtr<IOpenGLBaseTexture> QRP_GetBlurTexture(
00219       int x, int y,
00220       int buffer_width, int buffer_height,
00221       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00222       const Color& c0,
00223       float sigma = 1.0f, int num_pass = 1);
00224 
00225     ObjectPtr<IOpenGLBaseTexture> QRP_GetAlphaTexture(
00226       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00227       const Color& c0);
00228 
00229     ObjectPtr<IOpenGLBaseTexture> QRP_GetColorMatrixTexture(
00230       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00231       const Color& c0,
00232       Matrix4 color_matrix, Vector4 offset);
00233 
00234     ObjectPtr<IOpenGLBaseTexture> QRP_GetPower(
00235       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, const Vector4& exponent);
00236 
00237     ObjectPtr<IOpenGLBaseTexture> QRP_GetLQBlur(
00238       int x, int y, int buffer_width, int buffer_height,
00239       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00240       const Color& c0);
00241 
00242     ObjectPtr<IOpenGLBaseTexture> QRP_GetHQBlur(
00243       int x, int y, int buffer_width, int buffer_height,
00244       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00245       const Color& c0, float sigma = 1.0f, int num_pass = 1);
00246 
00247     void QRP_DisturbedTexture(
00248       int x, int y, int width, int height,
00249       ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm& texxform0, const Color& c0,
00250       ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm& texxform1, const Color& c1);
00251 
00252          ObjectPtr<IOpenGLBaseTexture> QRP_GetPixelBlocks(
00253                 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform0, const Color& c0, int pixel_size);
00254 
00255     void QRP_GetCopyTexture(
00256       int width, int height,
00257       ObjectPtr<IOpenGLBaseTexture>& dst_device_texture,
00258       ObjectPtr<IOpenGLBaseTexture>& src_device_texture,
00259       TexCoordXForm& texxform0, const Color& c0);
00260 
00261     // ASM
00262     void QRP_ASM_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> Tex0, TexCoordXForm& texxform, const Color& color0);
00263     void QRP_ASM_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
00264 
00265     void QRP_ASM_Color(int x, int y, int width, int height, const Color& c0);
00266     void QRP_ASM_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3);
00267     void QRP_ASM_ColorModTexAlpha(int x, int y, int width, int height,
00268                                ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform0, const Color& color);
00269 
00270     void QRP_ASM_2Tex(int x, int y, int width, int height,
00271                    ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00272                    ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1);
00273 
00274     void QRP_ASM_2TexMod(int x, int y, int width, int height,
00275       ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00276       ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1);
00277 
00278     void QRP_ASM_4Tex(int x, int y, int width, int height,
00279                    ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00280                    ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1,
00281                    ObjectPtr<IOpenGLBaseTexture> DeviceTexture2, TexCoordXForm& texxform2, const Color& color2,
00282                    ObjectPtr<IOpenGLBaseTexture> DeviceTexture3, TexCoordXForm& texxform3, const Color& color3);
00283 
00284     void QRP_ASM_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, Color c0);
00285     void QRP_ASM_Triangle(int x0, int y0, int x1, int y1, int x2, int y2, Color c0, Color c1, Color c2);
00286     void QRP_ASM_Line(int x0, int y0, int x1, int y1, Color c0);
00287     void QRP_ASM_Line(int x0, int y0, int x1, int y1, Color c0, Color c1);
00288     void QRP_ASM_QuadWireframe(int x0, int y0, int width, int height, Color c0, Color c1, Color c2, Color c3);
00289 
00290     void QRP_ASM_Power  (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, Vector4 exponent);
00291     void QRP_ASM_AlphaReplicate  (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0);
00292     void QRP_ASM_HorizontalGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
00293     void QRP_ASM_VerticalGauss   (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
00294     void QRP_ASM_ColorMatrix     (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, Matrix4 color_matrix, Vector4 offset);
00295 
00297 
00306     ObjectPtr<IOpenGLBaseTexture> QRP_ASM_GetBlurTexture(
00307       int x, int y, int buffer_width, int buffer_height,
00308       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& color, float sigma = 1.0f, int num_pass = 1);
00309 
00310     void QRP_ASM_GetBlurTextureFx(
00311       int x, int y, int buffer_width, int buffer_height,
00312       FxStructure* fx_structure, TexCoordXForm& texxform, const Color& color, float sigma = 1.0f, int num_pass = 1);
00313 
00315 
00321     ObjectPtr<IOpenGLBaseTexture> QRP_ASM_GetAlphaTexture(
00322       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& color);
00323 
00325 
00333     ObjectPtr<IOpenGLBaseTexture> QRP_ASM_GetColorMatrixTexture(
00334       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00335       const Color& c, Matrix4 color_matrix, Vector4 offset);
00336 
00338 
00346     ObjectPtr<IOpenGLBaseTexture> QRP_ASM_GetPower(
00347       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, const Vector4& exponent);
00348 
00349     ObjectPtr<IOpenGLBaseTexture> QRP_ASM_GetLQBlur(
00350       int x, int y, int buffer_width, int buffer_height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00351       const Color& c0);
00352 
00353     ObjectPtr<IOpenGLBaseTexture> QRP_ASM_GetHQBlur(
00354       int x, int y, int buffer_width, int buffer_height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00355       const Color& c0, float sigma = 1.0f, int num_pass = 1);
00356 
00357     void QRP_ASM_DisturbedTexture(
00358       int x, int y, int width, int height,
00359       ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm& texxform0, const Color& c0,
00360       ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm& texxform1, const Color& c1);
00361 
00363 
00370     ObjectPtr<IOpenGLBaseTexture>  QRP_ASM_GetPixelBlocks(
00371                 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform0, const Color& color, int pixel_size);
00372 
00373     void QRP_ASM_GetCopyTexture(
00374       int width, int height,
00375       ObjectPtr<IOpenGLBaseTexture>& dst_device_texture,
00376       ObjectPtr<IOpenGLBaseTexture>& src_device_texture,
00377       TexCoordXForm& texxform0, const Color& c0);
00378 
00379     // GLSL
00380 
00381     void QRP_GLSL_1Tex(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0);
00382     void QRP_GLSL_Pixelate(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform, const Color& c0, int pixel_size);
00383 
00384     void QRP_GLSL_Color(int x, int y, int width, int height, const Color& c0);
00385     void QRP_GLSL_Color(int x, int y, int width, int height, const Color& c0, const Color& c1, const Color& c2, const Color& c3);
00386     void QRP_GLSL_ColorModTexAlpha(int x, int y, int width, int height,
00387                                     ObjectPtr<IOpenGLBaseTexture> DeviceTexture, TexCoordXForm& texxform0, const Color& color);
00388 
00389     void QRP_GLSL_2Tex(int x, int y, int width, int height,
00390                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00391                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1);
00392 
00393     void QRP_GLSL_2TexMod(int x, int y, int width, int height,
00394       ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00395       ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1);
00396 
00397 
00398     void QRP_GLSL_4Tex(int x, int y, int width, int height,
00399                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture0, TexCoordXForm& texxform0, const Color& color0,
00400                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture1, TexCoordXForm& texxform1, const Color& color1,
00401                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture2, TexCoordXForm& texxform2, const Color& color2,
00402                         ObjectPtr<IOpenGLBaseTexture> DeviceTexture3, TexCoordXForm& texxform3, const Color& color3);
00403 
00404     void QRP_GLSL_Triangle      (int x0, int y0, int x1, int y1, int x2, int y2, Color c0);
00405     void QRP_GLSL_Triangle      (int x0, int y0, int x1, int y1, int x2, int y2, Color c0, Color c1, Color c2);
00406     void QRP_GLSL_Line          (int x0, int y0, int x1, int y1, Color c0);
00407     void QRP_GLSL_Line          (int x0, int y0, int x1, int y1, Color c0, Color c1);
00408     void QRP_GLSL_QuadWireframe(int x0, int y0, int width, int height, Color c0, Color c1, Color c2, Color c3);
00409 
00410     void QRP_GLSL_Power           (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, Vector4 exponent);
00411     void QRP_GLSL_AlphaReplicate  (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0);
00412     void QRP_GLSL_HorizontalGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
00413     void QRP_GLSL_VerticalGauss   (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
00414     void QRP_GLSL_HorizontalHQGauss(int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
00415     void QRP_GLSL_VerticalHQGauss   (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, float sigma = 1.0f);
00416     void QRP_GLSL_ColorMatrix     (int x, int y, int width, int height, ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, Matrix4 color_matrix, Vector4 offset);
00417 
00426     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetBlurTexture(
00427       int x, int y,
00428       int buffer_width, int buffer_height,
00429       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00430       const Color& c0,
00431       float sigma = 1.0f, int num_pass = 1);
00432 
00433     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetAlphaTexture(
00434       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00435       const Color& c0);
00436 
00437     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetColorMatrixTexture(
00438       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00439       const Color& c0,
00440       Matrix4 color_matrix, Vector4 offset);
00441 
00442     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetPower(
00443       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform, const Color& c0, const Vector4& exponent);
00444 
00445     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetLQBlur(
00446       int x, int y,
00447       int buffer_width, int buffer_height,
00448       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00449       const Color& c0);
00450 
00451     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetHQBlur(
00452       int x, int y,
00453       int buffer_width, int buffer_height,
00454       ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform,
00455       const Color& c0, float sigma = 1.0f, int num_pass = 1);
00456 
00457     void QRP_GLSL_GetHQBlurFx(
00458       int x, int y,
00459       int buffer_width, int buffer_height,
00460       FxStructure* fx_structure, TexCoordXForm& texxform,
00461       const Color& c0, float sigma = 1.0f, int num_pass = 1);
00462 
00463     void QRP_GLSL_DisturbedTexture(
00464       int x, int y, int width, int height,
00465       ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm& texxform0, const Color& c0,
00466       ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm& texxform1, const Color& c1);
00467 
00468     ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetDisturbedTexture(
00469       int x, int y, int width, int height,
00470       ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm& texxform0, const Color& c0,
00471       ObjectPtr<IOpenGLBaseTexture> src_device_texture, TexCoordXForm& texxform1, const Color& c1);
00472 
00473     void QRP_GLSL_GetDisturbedTextureFx(
00474       int x, int y, int width, int height,
00475       ObjectPtr<IOpenGLBaseTexture> distorsion_texture, TexCoordXForm& texxform0, const Color& c0,
00476       FxStructure* fx_structure, TexCoordXForm& texxform1, const Color& c1);
00477 
00479 
00486          ObjectPtr<IOpenGLBaseTexture> QRP_GLSL_GetPixelBlocks(
00487                 ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm& texxform0, const Color& c0, int pixel_size);
00488 
00489     void QRP_GLSL_GetCopyTexture(
00490       int width, int height,
00491       ObjectPtr<IOpenGLBaseTexture>& dst_device_texture,
00492       ObjectPtr<IOpenGLBaseTexture>& src_device_texture,
00493       TexCoordXForm& texxform0, const Color& c0);
00494 
00496     // DRAW CLIPPING    //
00498 
00499     mutable std::vector<Rect> ClippingRect;
00500     void PushClippingRectangle(Rect rect);
00501     void PopClippingRectangle();
00502     void EmptyClippingRegion();
00504     void ApplyClippingRectangle();
00505     
00506     void SetGlobalClippingRectangle(Rect rect);
00507     void DisableGlobalClippingRectangle();
00508 
00510 
00513     void SetClippingRectangle(const Rect& rect);
00514 
00516     void SetOpenGLClippingRectangle(int x, int y, unsigned int width, unsigned int height);
00517 
00518     Rect GetClippingRegion() const;
00519     int GetNumberOfClippingRegions() const;
00520     
00521     void AddClipOffset(int x, int y);  
00522     void PushClipOffset(int x, int y);
00523     void PopClipOffset();
00524 
00525     void ClearAreaColorDepthStencil(int x, int y, int width, int height, Color clearcolor, float cleardepth, int clearstencil);
00526     void ClearAreaColor(int x, int y, int width, int height, Color clearcolor);
00527     void ClearAreaDepthStencil(int x, int y, int width, int height, float cleardepth, int clearstencil);
00528 
00529     void Set3DView(int w, int h);
00530 
00532     void Push2DWindow(int w, int h);
00533     void Pop2DWindow();
00534     void Push2DModelViewMatrix(Matrix4 mat);
00535     Matrix4 Pop2DModelViewMatrix();
00536     void Clear2DModelViewMatrix();
00537     std::list<Matrix4> m_2DModelViewMatricesStack;
00538 
00539     void SetViewport(int x, int y, int w, int h);
00540     Rect GetViewportRect() const;
00541     int  GetViewportWidth() const;
00542     int  GetViewportHeight() const;
00543     int  GetViewportX() const;
00544     int  GetViewportY() const;
00545 
00546     void  GetViewportSize(int& viewport_width, int& viewport_height) const;
00547 
00548     void SetScissor(int x, int y, int w, int h);
00549 
00557     void SetScissorOffset(int x, int y);
00558 
00559     Rect GetScissorRect();
00560     void EnableScissoring(bool b);
00561 
00562 
00563 //     void LoadPainterImages();
00564 //     const PainterImage* GetImage(UXStyleImageRef style);
00565 //     Rect GetImageGeometry(UXStyleImageRef style);
00566 //     std::list<PainterImage*> m_PainterImageList;
00567 
00568     int RenderColorText(ObjectPtr<FontTexture> Font, int x, int y, const NString& Str,
00569                          const Color& TextColor,
00570                          bool WriteAlphaChannel,
00571                          int NumCharacter);
00572 
00573     int RenderColorTextLineStatic(ObjectPtr<FontTexture> Font, const PageBBox& pageSize, const NString& Str,
00574                                    const Color& TextColor,
00575                                    bool WriteAlphaChannel,
00576                                    TextAlignment alignment);
00577 
00578     int RenderColorTextLineEdit(ObjectPtr<FontTexture> Font, const PageBBox& pageSize, const NString& Str,
00579                                  const Color& TextColor,
00580                                  bool WriteAlphaChannel,
00581                                  const Color& SelectedTextColor,
00582                                  const Color& SelectedTextBackgroundColor,
00583                                  const Color& TextBlinkColor,
00584                                  const Color& CursorColor,
00585                                  bool ShowCursor, unsigned int CursorPosition,
00586                                  int offset = 0, int selection_start = 0, int selection_end = 0);
00587 
00588     ObjectPtr <IOpenGLBaseTexture> CreateTextureFromBackBuffer(int x, int y, int width, int height);
00589 
00590     //Statistics
00591     void ResetStats();
00592 
00599     ObjectPtr<CachedResourceData> CacheResource(ResourceData* Resource);
00600 
00605     void UpdateResource(ResourceData* Resource);
00606 
00607     bool FlushCachedResourceData(ResourceData* Resource);
00608     bool IsResourceCached(ResourceData* Resource);
00609     NResourceCache ResourceCache;
00610 
00611     Matrix4 GetProjectionMatrix();
00613     Matrix4 GetOpenGLProjectionMatrix();
00614     
00615     void SetProjectionMatrix(const Matrix4& matrix);
00616     
00618 
00624     void SetOrthographicProjectionMatrix(int viewport_width, int viewport_height);
00625 
00627     void ResetProjectionMatrix();
00628 
00629     Matrix4 GetModelViewMatrix();
00631     Matrix4 GetOpenGLModelViewMatrix();
00632 
00633     Matrix4 GetModelViewProjectionMatrix();
00634     Matrix4 GetOpenGLModelViewProjectionMatrix();
00635 
00636     GpuRenderStates& GetRenderStates()
00637     {
00638       return *_graphics_display.m_DeviceFactory->_gpu_render_states;
00639     }
00640     void ResetRenderStates()
00641     {
00642       _graphics_display.m_DeviceFactory->_gpu_render_states->ResetStateChangeToDefault();
00643     }
00644     void VerifyRenderStates()
00645     {
00646       _graphics_display.m_DeviceFactory->_gpu_render_states->CheckStateChange();
00647     }
00648 
00649     ObjectPtr<FontTexture> GetFont();
00650     ObjectPtr<FontTexture> GetBoldFont();
00651 
00653 
00656     bool UsingGLSLCodePath();
00657 
00659 
00662     bool UsingARBProgramCodePath();
00663 
00665     void PushModelViewMatrix(const Matrix4& matrix);
00666 
00668     void PushIdentityModelViewMatrix();
00669 
00671 
00674     void Push2DTranslationModelViewMatrix(float tx, float ty, float tz);
00675 
00677 
00680     bool PopModelViewMatrix();
00681 
00683     void ResetModelViewMatrixStack();
00684 
00686 
00689     void SetModelViewMatrix(const Matrix4& matrix);
00690 
00692     void ApplyModelViewMatrix();
00693 
00695 
00701     Rect ModelViewXFormRect(const Rect& rect);
00702 
00704 
00707     int ModelViewStackDepth();
00708 
00709 
00710 
00712     void PushProjectionMatrix(const Matrix4& matrix);
00713 
00715 
00718     bool PopProjectionMatrix();
00719 
00721 
00724     int ProjectionStackDepth();
00725 
00726 
00727 
00728 
00729 
00731     void PushPorterDuffBlend(const PorterDuffOperator& porter_duff_op);
00732 
00734     void PushDisableBlend();
00735 
00737 
00741     void PushBlend(unsigned int src_blend, unsigned int dst_blend);
00742 
00744 
00747     bool PopBlend();
00748 
00750 
00753     int BlendStackDepth();
00754 
00756 
00762     void QRP_GLSL_ColorBlendOverTex(int x, int y, int width, int height,
00763           ObjectPtr<IOpenGLBaseTexture> bkg_device_texture, TexCoordXForm& texxform, const Color& color0,
00764           const Color& foreground_color,
00765           LayerBlendMode layer_blend_mode);
00766 
00768 
00774     void QRP_GLSL_TexBlendOverColor(int x, int y, int width, int height,
00775           const Color& background_color,
00776           ObjectPtr<IOpenGLBaseTexture> frg_device_texture, TexCoordXForm& texxform0, const Color& color0,
00777           LayerBlendMode layer_blend_mode);
00778 
00780 
00786     void QRP_GLSL_TexBlendOverTex(int x, int y, int width, int height,
00787           ObjectPtr<IOpenGLBaseTexture> bkg_device_texture, TexCoordXForm& texxform0, const Color& color0,
00788           ObjectPtr<IOpenGLBaseTexture> frg_device_texture, TexCoordXForm& texxform1, const Color& color1,
00789           LayerBlendMode layer_blend_mode);
00790 
00791 
00792   private:
00793 
00794     ObjectPtr<FontTexture> _normal_font;    
00795     ObjectPtr<FontTexture> _bold_font;      
00796 
00797     void InitShaders();
00798 
00800     void GaussianWeights(float **weights, float sigma, unsigned int num_tap);
00801 
00803     void SetFrameBufferHelper(
00804       ObjectPtr<IOpenGLFrameBufferObject>& fbo,
00805       ObjectPtr<IOpenGLBaseTexture>& colorbuffer,
00806       ObjectPtr<IOpenGLBaseTexture>& depthbuffer,
00807       int width, int height);
00808 
00809 #ifndef NUX_OPENGLES_20
00810     void InitAsmColorShader();
00812     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmColor;
00813 
00814     void InitAsmTextureShader();
00816     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTextureModColor;
00818     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmTextureRectModColor;
00819 
00820     void InitAsmPixelateShader();
00822     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPixelate;
00824     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPixelateRect;
00825 
00826     void InitAsmColorModTexMaskAlpha();
00829     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmColorModTexMaskAlpha;
00830     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmColorModTexRectMaskAlpha;
00831 
00832     void InitAsm2TextureAdd();
00834     ObjectPtr<IOpenGLAsmShaderProgram> m_Asm2TextureAdd;
00835     ObjectPtr<IOpenGLAsmShaderProgram> m_Asm2TextureRectAdd;
00836 
00837     void InitAsm2TextureMod();
00839     ObjectPtr<IOpenGLAsmShaderProgram> m_Asm2TextureMod;
00840     ObjectPtr<IOpenGLAsmShaderProgram> m_Asm2TextureRectMod;
00841 
00842     void InitAsm4TextureAdd();
00844     ObjectPtr<IOpenGLAsmShaderProgram> m_Asm4TextureAdd;
00845     ObjectPtr<IOpenGLAsmShaderProgram> m_Asm4TextureRectAdd;
00846 
00847     void InitAsmPower();
00849 
00852     ObjectPtr<IOpenGLAsmShaderProgram> _asm_tex_component_exponentiation_prog;
00853     ObjectPtr<IOpenGLAsmShaderProgram> _asm_texrect_component_exponentiation_prog;
00854 
00855     void InitAsmAlphaReplicate();
00857 
00860     ObjectPtr<IOpenGLAsmShaderProgram> _asm_tex_alpha_replicate_prog;
00861     ObjectPtr<IOpenGLAsmShaderProgram> _asm_texrect_alpha_replicate_prog;
00862 
00863     void InitAsmSeparableGaussFilter();
00865     ObjectPtr<IOpenGLAsmShaderProgram> _asm_tex_separable_gauss_filter_prog;
00866     ObjectPtr<IOpenGLAsmShaderProgram> _asm_texrect_separable_gauss_filter_prog;
00867 
00868 //     void InitAsmSeparableGaussFilter2();
00869 //     //! Gauss horizontal filter.
00870 //     ObjectPtr<IOpenGLAsmShaderProgram> _asm_tex_separable_gauss_filter_prog2;
00871 //     ObjectPtr<IOpenGLAsmShaderProgram> _asm_texrect_separable_gauss_filter_prog2;
00872 
00873     void InitAsmColorMatrixFilter();
00875     ObjectPtr<IOpenGLAsmShaderProgram> _asm_tex_color_matrix_filter_prog;
00876     ObjectPtr<IOpenGLAsmShaderProgram> _asm_texrect_color_matrix_filter_prog;
00877 
00878     void InitAsm2TextureDepRead();
00879     ObjectPtr<IOpenGLAsmShaderProgram> m_ASM2TextureDepRead;
00880     ObjectPtr<IOpenGLAsmShaderProgram> m_ASM2TextureRectDepRead;
00881 
00882     void InitAsmBlendModes();
00883 
00884     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPSBNormal;
00885     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPSBLighten;
00886     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPSBDarken;
00887     ObjectPtr<IOpenGLAsmShaderProgram> m_AsmPSBMultiply;
00888 #endif
00889 
00890     void InitSlColorShader();
00892     ObjectPtr<IOpenGLShaderProgram> m_SlColor;
00893 
00894     void InitSlTextureShader();
00896     ObjectPtr<IOpenGLShaderProgram> m_SlTextureModColor;
00897 
00898     void InitSlPixelateShader();
00900     ObjectPtr<IOpenGLShaderProgram> m_SLPixelate;
00901 
00902     void InitSlColorModTexMaskAlpha();
00905     ObjectPtr<IOpenGLShaderProgram> m_SlColorModTexMaskAlpha;
00906     ObjectPtr<IOpenGLShaderProgram> m_SlColorModTexRectMaskAlpha;
00907 
00908     void InitSl2TextureAdd();
00911     ObjectPtr<IOpenGLShaderProgram> m_Sl2TextureAdd;
00912 
00913     void InitSl2TextureDepRead();
00916     ObjectPtr<IOpenGLShaderProgram> m_Sl2TextureDepRead;
00917 
00918 
00919     void InitSl2TextureMod();
00922     ObjectPtr<IOpenGLShaderProgram> m_Sl2TextureMod;
00923 
00924     void InitSl4TextureAdd();
00926     ObjectPtr<IOpenGLShaderProgram> m_Sl4TextureAdd;
00927 
00928     void InitSLPower();
00930 
00933     ObjectPtr<IOpenGLShaderProgram> _component_exponentiation_prog;
00934 
00935     void InitSLAlphaReplicate();
00937 
00940     ObjectPtr<IOpenGLShaderProgram> _alpha_replicate_prog;
00941 
00942     void InitSLHorizontalGaussFilter();
00944     ObjectPtr<IOpenGLShaderProgram> _horizontal_gauss_filter_prog;
00945     
00946     void InitSLVerticalGaussFilter();
00948     ObjectPtr<IOpenGLShaderProgram> _vertical_gauss_filter_prog;
00949     
00950 
00951     void InitSLHorizontalHQGaussFilter(int sigma);
00953     ObjectPtr<IOpenGLShaderProgram> _horizontal_hq_gauss_filter_prog[NUX_MAX_GAUSSIAN_SIGMA];
00954 
00955     void InitSLVerticalHQGaussFilter(int sigma);
00957     ObjectPtr<IOpenGLShaderProgram> _vertical_hq_gauss_filter_prog[NUX_MAX_GAUSSIAN_SIGMA];
00958 
00959 
00960 
00961     void InitSLColorMatrixFilter();
00963     ObjectPtr<IOpenGLShaderProgram> _color_matrix_filter_prog;
00964 
00965     void InitSlBlendModes();
00966 
00967     void InitBlendModeNormal();
00968     void InitBlendModeLighten();
00969     void InitBlendModeDarken();
00970 
00971     ObjectPtr<IOpenGLShaderProgram> shader_layer_blend_normal_;
00972     ObjectPtr<IOpenGLShaderProgram> shader_layer_blend_lighten_;
00973     ObjectPtr<IOpenGLShaderProgram> shader_layer_blend_darken_;
00974     ObjectPtr<IOpenGLShaderProgram> shader_layer_blend_multiply_;
00975 
00976     // Blend modes
00977     ObjectPtr<IOpenGLShaderProgram> blend_tex_color_prog_[LAYER_BLEND_MODE_LAST];
00978     ObjectPtr<IOpenGLShaderProgram> blend_color_tex_prog_[LAYER_BLEND_MODE_LAST];
00979     ObjectPtr<IOpenGLShaderProgram> blend_tex_tex_prog_[LAYER_BLEND_MODE_LAST];
00980     
00981     const char* const GetBlendModeBlendFunc(LayerBlendMode layer_blend_mode);
00982     const char* const GetBlendModeString(LayerBlendMode layer_blend_mode);
00983     
00984     ObjectPtr <IOpenGLShaderProgram> GetColorBlendOverTexProgram(LayerBlendMode layer_blend_mode);
00985     ObjectPtr <IOpenGLShaderProgram> GetTexBlendOverColorProgram(LayerBlendMode layer_blend_mode);
00986     ObjectPtr <IOpenGLShaderProgram> GetBlendTexTexProgram(LayerBlendMode layer_blend_mode);
00987 
00988 
00989 
00991     void EvaluateGpuCaps();
00992 
00993     bool _use_glsl_shaders; 
00994 
00995     ObjectPtr<IOpenGLFrameBufferObject> _offscreen_fbo;
00996     ObjectPtr<IOpenGLBaseTexture> _offscreen_color_rt0;
00997     ObjectPtr<IOpenGLBaseTexture> _offscreen_depth_rt0;
00998     ObjectPtr<IOpenGLBaseTexture> _offscreen_color_rt1;
00999     ObjectPtr<IOpenGLBaseTexture> _offscreen_depth_rt1;
01000     ObjectPtr<IOpenGLBaseTexture> _offscreen_color_rt2;
01001     ObjectPtr<IOpenGLBaseTexture> _offscreen_depth_rt2;
01002     ObjectPtr<IOpenGLBaseTexture> _offscreen_color_rt3;
01003     ObjectPtr<IOpenGLBaseTexture> _offscreen_depth_rt3;
01004 
01005     Matrix4 _projection_matrix;
01006     Matrix4 _model_view_matrix;
01007     
01008     std::list<Matrix4>   _model_view_stack;
01009     std::list<BlendOperator> _blend_stack;
01010 
01012     GraphicsDisplay& _graphics_display;
01013 
01014     Rect _viewport;
01015     Rect _scissor;
01016     int _clip_offset_x;
01017     int _clip_offset_y;
01018     Rect _clipping_rect;
01019 
01020 
01022 
01027     bool _global_clipping_enabled;
01028 
01030     Rect _global_clipping_rect;
01031 
01032     std::list<Point> _clip_offset_stack;
01033 
01034     FontRenderer* _font_renderer;
01035 
01036     //Statistics
01037     mutable long m_quad_stats;
01038     mutable long m_quad_tex_stats;
01039     mutable long m_triangle_stats;
01040     mutable long m_triangle_tex_stats;
01041     mutable long m_line_stats;
01042 
01043     GraphicsEngine(const GraphicsEngine&);
01044     // Does not make sense for a singleton. This is a self assignment.
01045     GraphicsEngine& operator = (const GraphicsEngine&);
01046     // Declare operator address-of as private
01047     GraphicsEngine* operator & ();
01048   };
01049 
01050 }
01051 
01052 #endif // OPENGLENGINE_H
01053