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