~om26er/ubuntu/oneiric/nux/sru-819721

« back to all changes in this revision

Viewing changes to Nux/PaintLayer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-11-18 19:17:32 UTC
  • Revision ID: james.westby@ubuntu.com-20101118191732-rn35790vekj6o4my
Tags: upstream-0.9.4
ImportĀ upstreamĀ versionĀ 0.9.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it
 
5
 * under the terms of the GNU Lesser General Public License version 3, as
 
6
 * published by the  Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but
 
9
 * WITHOUT ANY WARRANTY; without even the implied warranties of
 
10
 * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
 
11
 * PURPOSE.  See the applicable version of the GNU Lesser General Public
 
12
 * License for more details.
 
13
 *
 
14
 * You should have received a copy of both the GNU Lesser General Public
 
15
 * License version 3 along with this program.  If not, see
 
16
 * <http://www.gnu.org/licenses/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#include "Nux.h"
 
24
#include "NuxGraphics/GraphicsEngine.h"
 
25
#include "NuxGraphics/RenderingPipe.h"
 
26
#include "Utils.h"
 
27
#include "PaintLayer.h"
 
28
 
 
29
namespace nux
 
30
{
 
31
 
 
32
  ColorLayer::ColorLayer (const Color &color, bool write_alpha, const ROPConfig &ROP)
 
33
  {
 
34
    m_color = color;
 
35
    m_write_alpha = write_alpha;
 
36
    m_rop = ROP;
 
37
  }
 
38
 
 
39
  void ColorLayer::Renderlayer (GraphicsEngine &GfxContext)
 
40
  {
 
41
    GfxContext.GetRenderStates().SetBlend (m_rop.Blend, m_rop.SrcBlend, m_rop.DstBlend);
 
42
    GfxContext.QRP_GLSL_Color (m_geometry.x, m_geometry.y, m_geometry.GetWidth(), m_geometry.GetHeight(), m_color);
 
43
 
 
44
    if (m_rop.Blend)
 
45
      GfxContext.GetRenderStates().SetBlend (false);
 
46
  }
 
47
 
 
48
  AbstractPaintLayer *ColorLayer::Clone() const
 
49
  {
 
50
    return new ColorLayer (*this);
 
51
  }
 
52
 
 
53
/////////////////////////////////////////////////////
 
54
  ShapeLayer::ShapeLayer (UXStyleImageRef image_style, const Color &color, unsigned long corners, bool write_alpha, const ROPConfig &ROP)
 
55
  {
 
56
    m_image_style = image_style;
 
57
    m_color = color;
 
58
    m_write_alpha = write_alpha;
 
59
    m_rop = ROP;
 
60
    m_rop.Blend = true;
 
61
    m_corners = corners;
 
62
  }
 
63
 
 
64
  void ShapeLayer::Renderlayer (GraphicsEngine &GfxContext)
 
65
  {
 
66
    GetPainter().PaintShapeCornerROP (GfxContext, m_geometry, m_color, m_image_style, m_corners, m_write_alpha, m_rop);
 
67
 
 
68
    if (m_rop.Blend)
 
69
      GfxContext.GetRenderStates().SetBlend (false);
 
70
  }
 
71
 
 
72
  AbstractPaintLayer *ShapeLayer::Clone() const
 
73
  {
 
74
    return new ShapeLayer (*this);
 
75
  }
 
76
 
 
77
/////////////////////////////////////////////////////
 
78
  SliceScaledTextureLayer::SliceScaledTextureLayer (UXStyleImageRef image_style, const Color &color, unsigned long corners, bool write_alpha, const ROPConfig &ROP)
 
79
  {
 
80
    m_image_style = image_style;
 
81
    m_color = color;
 
82
    m_write_alpha = write_alpha;
 
83
    m_rop = ROP;
 
84
    m_corners = corners;
 
85
  }
 
86
 
 
87
  void SliceScaledTextureLayer::Renderlayer (GraphicsEngine &GfxContext)
 
88
  {
 
89
    GetPainter().PaintTextureShape (GfxContext, m_geometry, m_image_style);
 
90
  }
 
91
 
 
92
  AbstractPaintLayer *SliceScaledTextureLayer::Clone() const
 
93
  {
 
94
    return new SliceScaledTextureLayer (*this);
 
95
  }
 
96
 
 
97
/////////////////////////////////////////////////////
 
98
  TextureLayer::TextureLayer (IntrusiveSP<IOpenGLBaseTexture> device_texture, TexCoordXForm texxform, const Color &color, bool write_alpha, const ROPConfig &ROP)
 
99
  {
 
100
    m_device_texture = device_texture;
 
101
    m_color = color;
 
102
    m_write_alpha = write_alpha;
 
103
    m_rop = ROP;
 
104
    m_texxform = texxform;
 
105
  }
 
106
 
 
107
  void TextureLayer::Renderlayer (GraphicsEngine &GfxContext)
 
108
  {
 
109
    t_u32 current_alpha_blend;
 
110
    t_u32 current_src_blend_factor;
 
111
    t_u32 current_dest_blend_factor;
 
112
    t_u32 current_red_mask;
 
113
    t_u32 current_green_mask;
 
114
    t_u32 current_blue_mask;
 
115
    t_u32 current_alpha_mask;
 
116
    
 
117
    // Get the current color mask and blend states. They will be restored later.
 
118
    GfxContext.GetRenderStates ().GetColorMask (current_red_mask, current_green_mask, current_blue_mask, current_alpha_mask);
 
119
    GfxContext.GetRenderStates ().GetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
 
120
 
 
121
    
 
122
    GfxContext.GetRenderStates ().SetColorMask (GL_TRUE, GL_TRUE, GL_TRUE, m_write_alpha ? GL_TRUE : GL_FALSE);
 
123
    GfxContext.GetRenderStates ().SetBlend (m_rop.Blend, m_rop.SrcBlend, m_rop.DstBlend);
 
124
    
 
125
    GfxContext.QRP_GLSL_1Tex (m_geometry.x, m_geometry.y, m_geometry.GetWidth(), m_geometry.GetHeight(), m_device_texture,
 
126
                              m_texxform, m_color);
 
127
    
 
128
    // Restore Color mask and blend states.
 
129
    GfxContext.GetRenderStates ().SetColorMask (current_red_mask, current_green_mask, current_blue_mask, current_alpha_mask);
 
130
    GfxContext.GetRenderStates ().SetBlend (current_alpha_blend, current_src_blend_factor, current_dest_blend_factor);
 
131
    
 
132
  }
 
133
 
 
134
  AbstractPaintLayer *TextureLayer::Clone() const
 
135
  {
 
136
    return new TextureLayer (*this);
 
137
  }
 
138
 
 
139
 
 
140
}