Glide Plugin GLES2 port from mupen64plus-ae, but with special FrameSkip code
[mupen64plus-pandora.git] / source / gles2glide64 / src / Glide64 / MiClWr8b.h
CommitLineData
98e75f2d 1/*
2* Glide64 - Glide video plugin for Nintendo 64 emulators.
3* Copyright (c) 2002 Dave2001
4* Copyright (c) 2003-2009 Sergey 'Gonetz' Lipski
5*
6* This program 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 2 of the License, or
9* any later version.
10*
11* This program 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 this program; if not, write to the Free Software
18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21//****************************************************************
22//
23// Glide64 - Glide Plugin for Nintendo 64 emulators
24// Project started on December 29th, 2001
25//
26// Authors:
27// Dave2001, original author, founded the project in 2001, left it in 2002
28// Gugaman, joined the project in 2002, left it in 2002
29// Sergey 'Gonetz' Lipski, joined the project in 2002, main author since fall of 2002
30// Hiroshi 'KoolSmoky' Morii, joined the project in 2007
31//
32//****************************************************************
33//
34// To modify Glide64:
35// * Write your name and (optional)email, commented by your work, so I know who did it, and so that you can find which parts you modified when it comes time to send it to me.
36// * Do NOT send me the whole project or file that you modified. Take out your modified code sections, and tell me where to put them. If people sent the whole thing, I would have many different versions, but no idea how to combine them all.
37//
38//****************************************************************
39
40//****************************************************************
41// 8-bit Horizontal Mirror
42
43static inline void mirror8bS(uint8_t *tex, uint8_t *start, int width, int height, int mask, int line, int full, int count)
44{
45 uint8_t *v8;
46 int v9;
47 int v10;
48
49 v8 = start;
50 v9 = height;
51 do
52 {
53 v10 = 0;
54 do
55 {
56 if ( width & (v10 + width) )
57 *v8++ = *(&tex[mask] - (mask & v10));
58 else
59 *v8++ = tex[mask & v10];
60 ++v10;
61 }
62 while ( v10 != count );
63 v8 += line;
64 tex += full;
65 --v9;
66 }
67 while ( v9 );
68}
69
70static inline void wrap8bS(uint8_t *tex, uint8_t *start, int height, int mask, int line, int full, int count)
71{
72 uint32_t *v7;
73 int v8;
74 int v9;
75
76 v7 = (uint32_t *)start;
77 v8 = height;
78 do
79 {
80 v9 = 0;
81 do
82 {
83 *v7 = *(uint32_t *)&tex[4 * (mask & v9)];
84 ++v7;
85 ++v9;
86 }
87 while ( v9 != count );
88 v7 = (uint32_t *)((char *)v7 + line);
89 tex += full;
90 --v8;
91 }
92 while ( v8 );
93}
94
95static inline void clamp8bS(uint8_t *tex, uint8_t *constant, int height, int line, int full, int count)
96{
97 uint8_t *v6;
98 uint8_t *v7;
99 int v8;
100 uint8_t v9;
101 int v10;
102
103 v6 = constant;
104 v7 = tex;
105 v8 = height;
106 do
107 {
108 v9 = *v6;
109 v10 = count;
110 do
111 {
112 *v7++ = v9;
113 --v10;
114 }
115 while ( v10 );
116 v6 += full;
117 v7 += line;
118 --v8;
119 }
120 while ( v8 );
121}
122
123void Mirror8bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)
124{
125 if (mask == 0) return;
126
127 wxUint32 mask_width = (1 << mask);
128 wxUint32 mask_mask = (mask_width-1);
129 if (mask_width >= max_width) return;
130 int count = max_width - mask_width;
131 if (count <= 0) return;
132 int line_full = real_width;
133 int line = line_full - (count);
134 if (line < 0) return;
135 unsigned char * start = tex + (mask_width);
136 mirror8bS (tex, start, mask_width, height, mask_mask, line, line_full, count);
137}
138
139//****************************************************************
140// 8-bit Horizontal Wrap (like mirror) ** UNTESTED **
141
142
143void Wrap8bS (unsigned char * tex, wxUint32 mask, wxUint32 max_width, wxUint32 real_width, wxUint32 height)
144{
145 if (mask == 0) return;
146
147 wxUint32 mask_width = (1 << mask);
148 wxUint32 mask_mask = (mask_width-1) >> 2;
149 if (mask_width >= max_width) return;
150 int count = (max_width - mask_width) >> 2;
151 if (count <= 0) return;
152 int line_full = real_width;
153 int line = line_full - (count << 2);
154 if (line < 0) return;
155 unsigned char * start = tex + (mask_width);
156 wrap8bS (tex, start, height, mask_mask, line, line_full, count);
157}
158
159//****************************************************************
160// 8-bit Horizontal Clamp
161
162
163void Clamp8bS (unsigned char * tex, wxUint32 width, wxUint32 clamp_to, wxUint32 real_width, wxUint32 real_height)
164{
165 if (real_width <= width) return;
166
167 unsigned char * dest = tex + (width);
168 unsigned char * constant = dest-1;
169 int count = clamp_to - width;
170
171 int line_full = real_width;
172 int line = width;
173 clamp8bS (dest, constant, real_height, line, line_full, count);
174}
175
176//****************************************************************
177// 8-bit Vertical Mirror
178
179void Mirror8bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)
180{
181 if (mask == 0) return;
182
183 wxUint32 mask_height = (1 << mask);
184 wxUint32 mask_mask = mask_height-1;
185 if (max_height <= mask_height) return;
186 int line_full = real_width;
187
188 unsigned char * dst = tex + mask_height * line_full;
189
190 for (wxUint32 y=mask_height; y<max_height; y++)
191 {
192 if (y & mask_height)
193 {
194 // mirrored
195 memcpy ((void*)dst, (void*)(tex + (mask_mask - (y & mask_mask)) * line_full), line_full);
196 }
197 else
198 {
199 // not mirrored
200 memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);
201 }
202
203 dst += line_full;
204 }
205}
206
207//****************************************************************
208// 8-bit Vertical Wrap
209
210void Wrap8bT (unsigned char * tex, wxUint32 mask, wxUint32 max_height, wxUint32 real_width)
211{
212 if (mask == 0) return;
213
214 wxUint32 mask_height = (1 << mask);
215 wxUint32 mask_mask = mask_height-1;
216 if (max_height <= mask_height) return;
217 int line_full = real_width;
218
219 unsigned char * dst = tex + mask_height * line_full;
220
221 for (wxUint32 y=mask_height; y<max_height; y++)
222 {
223 // not mirrored
224 memcpy ((void*)dst, (void*)(tex + (y & mask_mask) * line_full), line_full);
225
226 dst += line_full;
227 }
228}
229
230//****************************************************************
231// 8-bit Vertical Clamp
232
233void Clamp8bT (unsigned char * tex, wxUint32 height, wxUint32 real_width, wxUint32 clamp_to)
234{
235 int line_full = real_width;
236 unsigned char * dst = tex + height * line_full;
237 unsigned char * const_line = dst - line_full;
238
239 for (wxUint32 y=height; y<clamp_to; y++)
240 {
241 memcpy ((void*)dst, (void*)const_line, line_full);
242 dst += line_full;
243 }
244}
245