OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShaderDraw.h
1 /*
2  * Copyright 2010-2014 OpenXcom Developers.
3  *
4  * This file is part of OpenXcom.
5  *
6  * OpenXcom is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * OpenXcom is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OPENXCOM_SHADERDRAW_H
21 #define OPENXCOM_SHADERDRAW_H
22 
23 #include "ShaderDrawHelper.h"
24 
25 namespace OpenXcom
26 {
27 
38 template<typename ColorFunc, typename DestType, typename Src0Type, typename Src1Type, typename Src2Type, typename Src3Type>
39 static inline void ShaderDraw(const DestType& dest_frame, const Src0Type& src0_frame, const Src1Type& src1_frame, const Src2Type& src2_frame, const Src3Type& src3_frame)
40 {
41  //creating helper objects
42  helper::controler<DestType> dest(dest_frame);
43  helper::controler<Src0Type> src0(src0_frame);
44  helper::controler<Src1Type> src1(src1_frame);
45  helper::controler<Src2Type> src2(src2_frame);
46  helper::controler<Src3Type> src3(src3_frame);
47 
48  //get basic draw range in 2d space
49  GraphSubset end_temp = dest.get_range();
50 
51  //intersections with src ranges
52  src0.mod_range(end_temp);
53  src1.mod_range(end_temp);
54  src2.mod_range(end_temp);
55  src3.mod_range(end_temp);
56 
57  const GraphSubset end = end_temp;
58  if(end.size_x() == 0 || end.size_y() == 0)
59  return;
60  //set final draw range in 2d space
61  dest.set_range(end);
62  src0.set_range(end);
63  src1.set_range(end);
64  src2.set_range(end);
65  src3.set_range(end);
66 
67 
68  int begin_y = 0, end_y = end.size_y();
69  //determining iteration range in y-axis
70  dest.mod_y(begin_y, end_y);
71  src0.mod_y(begin_y, end_y);
72  src1.mod_y(begin_y, end_y);
73  src2.mod_y(begin_y, end_y);
74  src3.mod_y(begin_y, end_y);
75  if(begin_y>=end_y)
76  return;
77  //set final iteration range
78  dest.set_y(begin_y, end_y);
79  src0.set_y(begin_y, end_y);
80  src1.set_y(begin_y, end_y);
81  src2.set_y(begin_y, end_y);
82  src3.set_y(begin_y, end_y);
83 
84  //iteration on y-axis
85  for(int y = end_y-begin_y; y>0; --y, dest.inc_y(), src0.inc_y(), src1.inc_y(), src2.inc_y(), src3.inc_y())
86  {
87  int begin_x = 0, end_x = end.size_x();
88  //determining iteration range in x-axis
89  dest.mod_x(begin_x, end_x);
90  src0.mod_x(begin_x, end_x);
91  src1.mod_x(begin_x, end_x);
92  src2.mod_x(begin_x, end_x);
93  src3.mod_x(begin_x, end_x);
94  if(begin_x>=end_x)
95  continue;
96  //set final iteration range
97  dest.set_x(begin_x, end_x);
98  src0.set_x(begin_x, end_x);
99  src1.set_x(begin_x, end_x);
100  src2.set_x(begin_x, end_x);
101  src3.set_x(begin_x, end_x);
102 
103  //iteration on x-axis
104  for(int x = end_x-begin_x; x>0; --x, dest.inc_x(), src0.inc_x(), src1.inc_x(), src2.inc_x(), src3.inc_x())
105  {
106  ColorFunc::func(dest.get_ref(), src0.get_ref(), src1.get_ref(), src2.get_ref(), src3.get_ref());
107  }
108  }
109 
110 }
111 
112 template<typename ColorFunc, typename DestType, typename Src0Type, typename Src1Type, typename Src2Type>
113 static inline void ShaderDraw(const DestType& dest_frame, const Src0Type& src0_frame, const Src1Type& src1_frame, const Src2Type& src2_frame)
114 {
115  ShaderDraw<ColorFunc>(dest_frame, src0_frame, src1_frame, src2_frame, helper::Nothing());
116 }
117 template<typename ColorFunc, typename DestType, typename Src0Type, typename Src1Type>
118 static inline void ShaderDraw(const DestType& dest_frame, const Src0Type& src0_frame, const Src1Type& src1_frame)
119 {
120  ShaderDraw<ColorFunc>(dest_frame, src0_frame, src1_frame, helper::Nothing(), helper::Nothing());
121 }
122 template<typename ColorFunc, typename DestType, typename Src0Type>
123 static inline void ShaderDraw(const DestType& dest_frame, const Src0Type& src0_frame)
124 {
125  ShaderDraw<ColorFunc>(dest_frame, src0_frame, helper::Nothing(), helper::Nothing(), helper::Nothing());
126 }
127 template<typename ColorFunc, typename DestType>
128 static inline void ShaderDraw(const DestType& dest_frame)
129 {
130  ShaderDraw<ColorFunc>(dest_frame, helper::Nothing(), helper::Nothing(), helper::Nothing(), helper::Nothing());
131 }
132 
133 template<typename T>
134 static inline helper::Scalar<T> ShaderScalar(T& t)
135 {
136  return helper::Scalar<T>(t);
137 }
138 template<typename T>
139 static inline helper::Scalar<const T> ShaderScalar(const T& t)
140 {
141  return helper::Scalar<const T>(t);
142 }
143 
144 namespace helper
145 {
146 
147 const Uint8 ColorGroup = 15<<4;
148 const Uint8 ColorShade = 15;
149 const Uint8 ColorShadeMax = 15;
150 const Uint8 BLACK = 15;
151 
152 }//namespace helper
153 
154 }//namespace OpenXcom
155 
156 
157 #endif /* OPENXCOM_SHADERDRAW_H */
158