forked from OpenXcom/OpenXcom
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShaderRepeat.h
More file actions
173 lines (147 loc) · 3.26 KB
/
Copy pathShaderRepeat.h
File metadata and controls
173 lines (147 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#pragma once
/*
* Copyright 2010-2016 OpenXcom Developers.
*
* This file is part of OpenXcom.
*
* OpenXcom is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenXcom is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenXcom. If not, see <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include "ShaderDraw.h"
namespace OpenXcom
{
template<typename Pixel>
class ShaderRepeat : public helper::ShaderBase<const Pixel>
{
int _off_x;
int _off_y;
public:
typedef helper::ShaderBase<const Pixel> _base;
friend struct helper::controler<ShaderRepeat<Pixel> >;
inline ShaderRepeat(const Surface* s):
_base(s)
{
setOffset(0, 0);
}
inline ShaderRepeat(const std::vector<Pixel>& f, int max_x, int max_y):
_base(f, max_x, max_y)
{
setOffset(0, 0);
}
inline void setOffset(int x, int y)
{
_off_x = x;
_off_y = y;
}
inline void addOffset(int x, int y)
{
_off_x += x;
_off_y += y;
}
};
namespace helper
{
template<typename Pixel>
struct controler<ShaderRepeat<Pixel> >
{
typedef typename ShaderRepeat<Pixel>::PixelPtr PixelPtr;
typedef typename ShaderRepeat<Pixel>::PixelRef PixelRef;
const PixelPtr _base;
const GraphSubset _range_domain;
GraphSubset _range_image;
const int _off_x;
const int _off_y;
const int _size_x;
const int _size_y;
int _curr_x;
int _curr_y;
const int _pitch;
PixelPtr _ptr_curr_x;
PixelPtr _ptr_curr_y;
controler(const ShaderRepeat<Pixel>& f) :
_base(f.ptr()),
_range_domain(f.getDomain()),
_range_image(0,0),
_off_x(f._off_x),
_off_y(f._off_y),
_size_x(_range_domain.size_x()),
_size_y(_range_domain.size_y()),
_curr_x(0),
_curr_y(0),
_pitch(f.pitch()),
_ptr_curr_x(0),
_ptr_curr_y(0)
{
}
//not used
//inline const GraphSubset& get_range()
inline void mod_range(GraphSubset&)
{
//nothing
}
inline void set_range(const GraphSubset& g)
{
_range_image = g;
}
inline void mod_y(int&, int&)
{
_curr_y = ( _range_image.beg_y - _off_y)%_size_y;
if (_curr_y <0)
_curr_y += _size_y;
_ptr_curr_y = _base;
}
inline void set_y(const int& begin, const int&)
{
_curr_y = (_curr_y + begin)%_size_y;
_ptr_curr_y += (_range_domain.beg_y+_curr_y)*_pitch;
}
inline void inc_y()
{
++_curr_y;
_ptr_curr_y += _pitch;
if (_curr_y == _size_y)
{
_curr_y = 0;
_ptr_curr_y -= _size_y*_pitch;
}
}
inline void mod_x(int&, int&)
{
_curr_x = ( _range_image.beg_x - _off_x)%_size_x;
if (_curr_x <0)
_curr_x += _size_x;
_ptr_curr_x = _ptr_curr_y;
}
inline void set_x(const int& begin, const int&)
{
_curr_x = (_curr_x + begin)%_size_x;
_ptr_curr_x += _range_domain.beg_x +_curr_x;
}
inline void inc_x()
{
++_curr_x;
_ptr_curr_x += 1;
if (_curr_x == _size_x)
{
_curr_x = 0;
_ptr_curr_x -= _size_x;
}
}
inline PixelRef get_ref()
{
return *_ptr_curr_x;
}
};
}//namespace helper
}//namespace OpenXcom