OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ShaderRepeat.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_SHADERREPEAT_H
21 #define OPENXCOM_SHADERREPEAT_H
22 
23 #include <vector>
24 #include "ShaderDraw.h"
25 
26 namespace OpenXcom
27 {
28 
29 
30 template<typename Pixel>
31 class ShaderRepeat : public helper::ShaderBase<const Pixel>
32 {
33  int _off_x;
34  int _off_y;
35 
36 public:
38  friend struct helper::controler<ShaderRepeat<Pixel> >;
39 
40  inline ShaderRepeat(const Surface* s):
41  _base(s)
42  {
43  setOffset(0, 0);
44  }
45  inline ShaderRepeat(const std::vector<Pixel>& f, int max_x, int max_y):
46  _base(f, max_x, max_y)
47  {
48  setOffset(0, 0);
49  }
50 
51  inline void setOffset(int x, int y)
52  {
53  _off_x = x;
54  _off_y = y;
55  }
56  inline void addOffset(int x, int y)
57  {
58  _off_x += x;
59  _off_y += y;
60  }
61 };
62 
63 
64 namespace helper
65 {
66 
67 template<typename Pixel>
68 struct controler<ShaderRepeat<Pixel> >
69 {
70  typedef typename ShaderRepeat<Pixel>::PixelPtr PixelPtr;
71  typedef typename ShaderRepeat<Pixel>::PixelRef PixelRef;
72 
73  const PixelPtr _base;
74 
75  const GraphSubset _range_domain;
76  GraphSubset _range_image;
77 
78  const int _off_x;
79  const int _off_y;
80  const int _size_x;
81  const int _size_y;
82 
83 
84  int _curr_x;
85  int _curr_y;
86 
87  const int _pitch;
88 
89  PixelPtr _ptr_curr_x;
90  PixelPtr _ptr_curr_y;
91 
92  controler(const ShaderRepeat<Pixel>& f) :
93  _base(f.ptr()),
94  _range_domain(f.getDomain()),
95  _range_image(0,0),
96  _off_x(f._off_x),
97  _off_y(f._off_y),
98  _size_x(_range_domain.size_x()),
99  _size_y(_range_domain.size_y()),
100  _curr_x(0),
101  _curr_y(0),
102  _pitch(f.pitch()),
103  _ptr_curr_x(0),
104  _ptr_curr_y(0)
105  {
106 
107  }
108 
109  //not used
110  //inline const GraphSubset& get_range()
111 
112  inline void mod_range(GraphSubset&)
113  {
114  //nothing
115  }
116  inline void set_range(const GraphSubset& g)
117  {
118  _range_image = g;
119  }
120 
121  inline void mod_y(int&, int&)
122  {
123  _curr_y = ( _range_image.beg_y - _off_y)%_size_y;
124  if(_curr_y <0)
125  _curr_y += _size_y;
126  _ptr_curr_y = _base;
127  }
128  inline void set_y(const int& begin, const int&)
129  {
130  _curr_y = (_curr_y + begin)%_size_y;
131  _ptr_curr_y += (_range_domain.beg_y+_curr_y)*_pitch;
132  }
133  inline void inc_y()
134  {
135  ++_curr_y;
136  _ptr_curr_y += _pitch;
137  if(_curr_y == _size_y)
138  {
139  _curr_y = 0;
140  _ptr_curr_y -= _size_y*_pitch;
141  }
142  }
143 
144 
145  inline void mod_x(int&, int&)
146  {
147  _curr_x = ( _range_image.beg_x - _off_x)%_size_x;
148  if(_curr_x <0)
149  _curr_x += _size_x;
150  _ptr_curr_x = _ptr_curr_y;
151  }
152  inline void set_x(const int& begin, const int&)
153  {
154  _curr_x = (_curr_x + begin)%_size_x;
155  _ptr_curr_x += _range_domain.beg_x +_curr_x;
156  }
157  inline void inc_x()
158  {
159  ++_curr_x;
160  _ptr_curr_x += 1;
161  if(_curr_x == _size_x)
162  {
163  _curr_x = 0;
164  _ptr_curr_x -= _size_x;
165  }
166  }
167 
168  inline PixelRef get_ref()
169  {
170  return *_ptr_curr_x;
171  }
172 };
173 
174 }//namespace helper
175 }//namespace OpenXcom
176 
177 #endif /* OPENXCOM_SHADERREPEAT_H */
178 
helper class for handling implementation differences in different surfaces types Used in function Sha...
Definition: ShaderDrawHelper.h:419
This is surface argument to ShaderDraw.
Definition: ShaderDrawHelper.h:139
Definition: ShaderRepeat.h:31
void set_range(const GraphSubset &g)
set final drawing range.
Element that is blit (rendered) onto the screen.
Definition: Surface.h:39
Definition: GraphSubset.h:31
This is surface argument to ShaderDraw.
Definition: ShaderDrawHelper.h:63
void mod_range(GraphSubset &g)
function used only when SurfaceType is used as source surface.