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