nux-1.16.0
PaintLayer.cpp
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #include "Nux.h"
00024 #include "NuxGraphics/GraphicsEngine.h"
00025 #include "NuxGraphics/RenderingPipe.h"
00026 #include "Utils.h"
00027 #include "PaintLayer.h"
00028 
00029 namespace nux
00030 {
00031 
00032   ColorLayer::ColorLayer (const Color &color, bool write_alpha, const ROPConfig &ROP)
00033   {
00034     _color = color;
00035     m_write_alpha = write_alpha;
00036     m_rop = ROP;
00037   }
00038 
00039   void ColorLayer::Renderlayer (GraphicsEngine &GfxContext)
00040   {
00041     t_u32 current_alpha_blend;
00042     t_u32 current_src_blend_factor;
00043     t_u32 current_dest_blend_factor;
00044 
00045     // Get the current blend states. They will be restored later.
00046     GfxContext.GetRenderStates ().GetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00047     
00048     GfxContext.GetRenderStates().SetBlend (m_rop.Blend, m_rop.SrcBlend, m_rop.DstBlend);
00049     GfxContext.QRP_Color (_geometry.x, _geometry.y, _geometry.GetWidth(), _geometry.GetHeight(), _color);
00050 
00051     // Restore the blend state
00052     GfxContext.GetRenderStates ().SetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00053   }
00054 
00055   AbstractPaintLayer *ColorLayer::Clone() const
00056   {
00057     return new ColorLayer(*this);
00058   }
00059 
00060   void ColorLayer::SetColor (const Color &color)
00061   {
00062     _color = color;
00063   }
00064 
00065   Color ColorLayer::GetColor() const
00066   {
00067     return _color;
00068   }
00069 
00071   ShapeLayer::ShapeLayer (UXStyleImageRef image_style, const Color &color, unsigned long corners, bool write_alpha, const ROPConfig &ROP)
00072   {
00073     m_image_style = image_style;
00074     m_color = color;
00075     m_write_alpha = write_alpha;
00076     m_rop = ROP;
00077     m_rop.Blend = true;
00078     m_corners = corners;
00079   }
00080 
00081   void ShapeLayer::Renderlayer (GraphicsEngine &GfxContext)
00082   {
00083     t_u32 current_alpha_blend;
00084     t_u32 current_src_blend_factor;
00085     t_u32 current_dest_blend_factor;
00086 
00087     // Get the current blend states. They will be restored later.
00088     GfxContext.GetRenderStates ().GetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00089     GetPainter().PaintShapeCornerROP (GfxContext, _geometry, m_color, m_image_style, m_corners, m_write_alpha, m_rop);
00090 
00091     GfxContext.GetRenderStates ().SetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00092   }
00093 
00094   AbstractPaintLayer *ShapeLayer::Clone() const
00095   {
00096     return new ShapeLayer (*this);
00097   }
00098 
00100   SliceScaledTextureLayer::SliceScaledTextureLayer (UXStyleImageRef image_style, const Color &color, unsigned long corners, bool write_alpha, const ROPConfig &ROP)
00101   {
00102     m_image_style = image_style;
00103     m_color = color;
00104     m_write_alpha = write_alpha;
00105     m_rop = ROP;
00106     m_corners = corners;
00107   }
00108 
00109   void SliceScaledTextureLayer::Renderlayer (GraphicsEngine &GfxContext)
00110   {
00111     GetPainter().PaintTextureShape (GfxContext, _geometry, m_image_style);
00112   }
00113 
00114   AbstractPaintLayer *SliceScaledTextureLayer::Clone() const
00115   {
00116     return new SliceScaledTextureLayer (*this);
00117   }
00118 
00120   TextureLayer::TextureLayer (ObjectPtr<IOpenGLBaseTexture> device_texture, TexCoordXForm texxform, const Color &color, bool write_alpha, const ROPConfig &ROP)
00121   {
00122     m_device_texture = device_texture;
00123     m_color = color;
00124     m_write_alpha = write_alpha;
00125     m_rop = ROP;
00126     m_texxform = texxform;
00127   }
00128 
00129   void TextureLayer::Renderlayer (GraphicsEngine &GfxContext)
00130   {
00131     t_u32 current_alpha_blend;
00132     t_u32 current_src_blend_factor;
00133     t_u32 current_dest_blend_factor;
00134     t_u32 current_red_mask;
00135     t_u32 current_green_mask;
00136     t_u32 current_blue_mask;
00137     t_u32 current_alpha_mask;
00138     
00139     // Get the current color mask and blend states. They will be restored later.
00140     GfxContext.GetRenderStates ().GetColorMask (current_red_mask, current_green_mask, current_blue_mask, current_alpha_mask);
00141     GfxContext.GetRenderStates ().GetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00142 
00143     
00144     GfxContext.GetRenderStates ().SetColorMask (GL_TRUE, GL_TRUE, GL_TRUE, m_write_alpha ? GL_TRUE : GL_FALSE);
00145     GfxContext.GetRenderStates ().SetBlend (m_rop.Blend, m_rop.SrcBlend, m_rop.DstBlend);
00146     
00147     GfxContext.QRP_1Tex (_geometry.x, _geometry.y, _geometry.GetWidth(), _geometry.GetHeight(), m_device_texture,
00148                               m_texxform, m_color);
00149     
00150     // Restore Color mask and blend states.
00151     GfxContext.GetRenderStates ().SetColorMask (current_red_mask, current_green_mask, current_blue_mask, current_alpha_mask);
00152     GfxContext.GetRenderStates ().SetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
00153     
00154   }
00155 
00156   AbstractPaintLayer *TextureLayer::Clone() const
00157   {
00158     return new TextureLayer (*this);
00159   }
00160 
00161   ObjectPtr< IOpenGLBaseTexture> TextureLayer::GetDeviceTexture ()
00162   {
00163     return m_device_texture;
00164   }
00165 
00166 
00167 }
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends