Mercurial > sdl-ios-xcode
comparison test/automated/render/render.c @ 3734:42356acbc993 gsoc2009_unit_tests
Finished last of the render testcases.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Sat, 18 Jul 2009 22:29:37 +0000 |
parents | ca544951b504 |
children | 27b4b4d71011 |
comparison
equal
deleted
inserted
replaced
3733:ca544951b504 | 3734:42356acbc993 |
---|---|
20 | 20 |
21 | 21 |
22 #define SCREEN_W 80 | 22 #define SCREEN_W 80 |
23 #define SCREEN_H 60 | 23 #define SCREEN_H 60 |
24 | 24 |
25 #define FACE_W img_face.width | |
26 #define FACE_H img_face.height | |
27 | |
25 | 28 |
26 /* | 29 /* |
27 * Prototypes. | 30 * Prototypes. |
28 */ | 31 */ |
29 static int render_compare( const char *msg, const SurfaceImage_t *s ); | 32 static int render_compare( const char *msg, const SurfaceImage_t *s ); |
30 static int render_clearScreen (void); | 33 static int render_clearScreen (void); |
31 /* Testcases. */ | 34 /* Testcases. */ |
32 static void render_testPrimitives (void); | 35 static int render_testPrimitives (void); |
33 static void render_testPrimitivesBlend (void); | 36 static int render_testPrimitivesBlend (void); |
34 static void render_testBlit (void); | 37 static int render_testBlit (void); |
35 static int render_testBlitBlendMode (void); | 38 static int render_testBlitBlendMode( SDL_TextureID tface, int mode ); |
36 static void render_testBlitBlend (void); | 39 static int render_testBlitBlend (void); |
37 | 40 |
38 | 41 |
39 /** | 42 /** |
40 * Compares screen pixels with image pixels. | 43 * Compares screen pixels with image pixels. |
41 */ | 44 */ |
42 static int render_compare( const char *msg, const SurfaceImage_t *s ) | 45 static int render_compare( const char *msg, const SurfaceImage_t *s ) |
43 { | 46 { |
47 (void) msg; | |
48 (void) s; | |
49 #if 0 | |
44 int ret; | 50 int ret; |
45 void *pix; | 51 void *pix; |
46 SDL_Surface *testsur; | 52 SDL_Surface *testsur; |
47 | |
48 #if 0 | |
49 | 53 |
50 /* Allocate pixel space. */ | 54 /* Allocate pixel space. */ |
51 pix = malloc( 4*80*60 ); | 55 pix = malloc( 4*80*60 ); |
52 if (SDL_ATassert( "malloc", pix!=NULL )) | 56 if (SDL_ATassert( "malloc", pix!=NULL )) |
53 return 1; | 57 return 1; |
107 | 111 |
108 | 112 |
109 /** | 113 /** |
110 * @brief Tests the SDL primitives for rendering. | 114 * @brief Tests the SDL primitives for rendering. |
111 */ | 115 */ |
112 static void render_testPrimitives (void) | 116 static int render_testPrimitives (void) |
113 { | 117 { |
114 int ret; | 118 int ret; |
115 int x, y; | 119 int x, y; |
116 SDL_Rect rect; | 120 SDL_Rect rect; |
117 | 121 |
118 /* Clear surface. */ | 122 /* Clear surface. */ |
119 if (render_clearScreen()) | 123 if (render_clearScreen()) |
120 return; | 124 return -1; |
121 | 125 |
122 /* Draw a rectangle. */ | 126 /* Draw a rectangle. */ |
123 rect.x = 40; | 127 rect.x = 40; |
124 rect.y = 0; | 128 rect.y = 0; |
125 rect.w = 40; | 129 rect.w = 40; |
126 rect.h = 80; | 130 rect.h = 80; |
127 ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE ); | 131 ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE ); |
128 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 132 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
129 return; | 133 return -1; |
130 ret = SDL_RenderFill( &rect ); | 134 ret = SDL_RenderFill( &rect ); |
131 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 135 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) |
132 return; | 136 return -1; |
133 | 137 |
134 /* Draw a rectangle. */ | 138 /* Draw a rectangle. */ |
135 rect.x = 10; | 139 rect.x = 10; |
136 rect.y = 10; | 140 rect.y = 10; |
137 rect.w = 60; | 141 rect.w = 60; |
138 rect.h = 40; | 142 rect.h = 40; |
139 ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE ); | 143 ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE ); |
140 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 144 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
141 return; | 145 return -1; |
142 ret = SDL_RenderFill( &rect ); | 146 ret = SDL_RenderFill( &rect ); |
143 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) | 147 if (SDL_ATassert( "SDL_RenderRect", ret == 0)) |
144 return; | 148 return -1; |
145 | 149 |
146 /* Draw some points like so: | 150 /* Draw some points like so: |
147 * X.X.X.X.. | 151 * X.X.X.X.. |
148 * .X.X.X.X. | 152 * .X.X.X.X. |
149 * X.X.X.X.. */ | 153 * X.X.X.X.. */ |
150 for (y=0; y<3; y++) { | 154 for (y=0; y<3; y++) { |
151 x = y % 2; | 155 x = y % 2; |
152 for (; x<80; x+=2) { | 156 for (; x<80; x+=2) { |
153 ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE ); | 157 ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE ); |
154 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 158 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
155 return; | 159 return -1; |
156 ret = SDL_RenderPoint( x, y ); | 160 ret = SDL_RenderPoint( x, y ); |
157 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) | 161 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) |
158 return; | 162 return -1; |
159 } | 163 } |
160 } | 164 } |
161 | 165 |
162 /* Draw some lines. */ | 166 /* Draw some lines. */ |
163 ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE ); | 167 ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE ); |
164 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 168 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
165 return; | 169 return -1; |
166 ret = SDL_RenderLine( 0, 30, 80, 30 ); | 170 ret = SDL_RenderLine( 0, 30, 80, 30 ); |
167 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 171 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) |
168 return; | 172 return -1; |
169 ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE ); | 173 ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE ); |
170 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 174 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
171 return; | 175 return -1; |
172 ret = SDL_RenderLine( 40, 30, 40, 60 ); | 176 ret = SDL_RenderLine( 40, 30, 40, 60 ); |
173 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 177 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) |
174 return; | 178 return -1; |
175 ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE ); | 179 ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE ); |
176 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 180 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
177 return; | 181 return -1; |
178 ret = SDL_RenderLine( 0, 60, 80, 0 ); | 182 ret = SDL_RenderLine( 0, 60, 80, 0 ); |
179 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 183 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) |
180 return; | 184 return -1; |
181 | 185 |
182 /* See if it's the same. */ | 186 /* See if it's the same. */ |
183 if (render_compare( "Primitives output not the same.", &img_primitives )) | 187 if (render_compare( "Primitives output not the same.", &img_primitives )) |
184 return; | 188 return -1; |
189 | |
190 return 0; | |
185 } | 191 } |
186 | 192 |
187 | 193 |
188 /** | 194 /** |
189 * @brief Tests the SDL primitives with alpha for rendering. | 195 * @brief Tests the SDL primitives with alpha for rendering. |
190 */ | 196 */ |
191 static void render_testPrimitivesBlend (void) | 197 static int render_testPrimitivesBlend (void) |
192 { | 198 { |
193 int ret; | 199 int ret; |
194 int i, j; | 200 int i, j; |
195 SDL_Rect rect; | 201 SDL_Rect rect; |
196 | 202 |
197 /* Clear surface. */ | 203 /* Clear surface. */ |
198 if (render_clearScreen()) | 204 if (render_clearScreen()) |
199 return; | 205 return -1; |
200 | 206 |
201 /* See if we can actually run the test. */ | 207 /* See if we can actually run the test. */ |
208 #if 0 | |
202 ret = 0; | 209 ret = 0; |
203 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); | 210 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); |
204 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); | 211 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); |
205 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); | 212 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); |
206 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | 213 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); |
207 if (ret != 0) | 214 if (ret != 0) |
208 return; | 215 return -1; |
216 #endif | |
209 | 217 |
210 /* Create some rectangles for each blend mode. */ | 218 /* Create some rectangles for each blend mode. */ |
211 ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 ); | 219 ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 ); |
212 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 220 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
213 return; | 221 return -1; |
214 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); | 222 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); |
215 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 223 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
216 return; | 224 return -1; |
217 ret = SDL_RenderFill( NULL ); | 225 ret = SDL_RenderFill( NULL ); |
218 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) | 226 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) |
219 return; | 227 return -1; |
220 rect.x = 10; | 228 rect.x = 10; |
221 rect.y = 25; | 229 rect.y = 25; |
222 rect.w = 40; | 230 rect.w = 40; |
223 rect.h = 25; | 231 rect.h = 25; |
224 ret = SDL_SetRenderDrawColor( 240, 10, 10, 75 ); | 232 ret = SDL_SetRenderDrawColor( 240, 10, 10, 75 ); |
225 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 233 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
226 return; | 234 return -1; |
227 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); | 235 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); |
228 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 236 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
229 return; | 237 return -1; |
230 ret = SDL_RenderFill( &rect ); | 238 ret = SDL_RenderFill( &rect ); |
231 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) | 239 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) |
232 return; | 240 return -1; |
233 rect.x = 30; | 241 rect.x = 30; |
234 rect.y = 40; | 242 rect.y = 40; |
235 rect.w = 45; | 243 rect.w = 45; |
236 rect.h = 15; | 244 rect.h = 15; |
237 ret = SDL_SetRenderDrawColor( 10, 240, 10, 100 ); | 245 ret = SDL_SetRenderDrawColor( 10, 240, 10, 100 ); |
238 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 246 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
239 return; | 247 return -1; |
240 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); | 248 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); |
241 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 249 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
242 return; | 250 return -1; |
243 ret = SDL_RenderFill( &rect ); | 251 ret = SDL_RenderFill( &rect ); |
244 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) | 252 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) |
245 return; | 253 return -1; |
246 rect.x = 25; | 254 rect.x = 25; |
247 rect.y = 25; | 255 rect.y = 25; |
248 rect.w = 25; | 256 rect.w = 25; |
249 rect.h = 25; | 257 rect.h = 25; |
250 ret = SDL_SetRenderDrawColor( 10, 10, 240, 125 ); | 258 ret = SDL_SetRenderDrawColor( 10, 10, 240, 125 ); |
251 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 259 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
252 return; | 260 return -1; |
253 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); | 261 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); |
254 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 262 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
255 return; | 263 return -1; |
256 ret = SDL_RenderFill( &rect ); | 264 ret = SDL_RenderFill( &rect ); |
257 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) | 265 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) |
258 return; | 266 return -1; |
259 | 267 |
260 /* Draw blended lines, lines for everyone. */ | 268 /* Draw blended lines, lines for everyone. */ |
261 for (i=0; i<SCREEN_W; i+=2) { | 269 for (i=0; i<SCREEN_W; i+=2) { |
262 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); | 270 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); |
263 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 271 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
264 return; | 272 return -1; |
265 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : | 273 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : |
266 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); | 274 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); |
267 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 275 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
268 return; | 276 return -1; |
269 ret = SDL_RenderLine( 0, 0, i, 59 ); | 277 ret = SDL_RenderLine( 0, 0, i, 59 ); |
270 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 278 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) |
271 return; | 279 return -1; |
272 } | 280 } |
273 for (i=0; i<SCREEN_H; i+=2) { | 281 for (i=0; i<SCREEN_H; i+=2) { |
274 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); | 282 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); |
275 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 283 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
276 return; | 284 return -1; |
277 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : | 285 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : |
278 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); | 286 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); |
279 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 287 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
280 return; | 288 return -1; |
281 ret = SDL_RenderLine( 0, 0, 79, i ); | 289 ret = SDL_RenderLine( 0, 0, 79, i ); |
282 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) | 290 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) |
283 return; | 291 return -1; |
284 } | 292 } |
285 | 293 |
286 /* Draw points. */ | 294 /* Draw points. */ |
287 for (j=0; j<SCREEN_H; j+=3) { | 295 for (j=0; j<SCREEN_H; j+=3) { |
288 for (i=0; i<SCREEN_W; i+=3) { | 296 for (i=0; i<SCREEN_W; i+=3) { |
289 ret = SDL_SetRenderDrawColor( j*4, i*3, j*4, i*3 ); | 297 ret = SDL_SetRenderDrawColor( j*4, i*3, j*4, i*3 ); |
290 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) | 298 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
291 return; | 299 return -1; |
292 ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : | 300 ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : |
293 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); | 301 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); |
294 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) | 302 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
295 return; | 303 return -1; |
296 ret = SDL_RenderPoint( i, j ); | 304 ret = SDL_RenderPoint( i, j ); |
297 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) | 305 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) |
298 return; | 306 return -1; |
299 } | 307 } |
300 } | 308 } |
301 | 309 |
302 /* See if it's the same. */ | 310 /* See if it's the same. */ |
303 if (render_compare( "Blended primitives output not the same.", &img_primitives )) | 311 if (render_compare( "Blended primitives output not the same.", &img_primitives )) |
304 return; | 312 return -1; |
313 | |
314 return 0; | |
305 } | 315 } |
306 | 316 |
307 | 317 |
308 /** | 318 /** |
309 * @brief Tests some blitting routines. | 319 * @brief Tests some blitting routines. |
310 */ | 320 */ |
311 static void render_testBlit (void) | 321 static int render_testBlit (void) |
312 { | 322 { |
313 int ret; | 323 int ret; |
314 SDL_Rect rect; | 324 SDL_Rect rect; |
315 SDL_Surface *face; | 325 SDL_Surface *face; |
316 SDL_TextureID tface; | 326 SDL_TextureID tface; |
317 int i, j, ni, nj; | 327 int i, j, ni, nj; |
318 | 328 |
319 /* Clear surface. */ | 329 /* Clear surface. */ |
320 if (render_clearScreen()) | 330 if (render_clearScreen()) |
321 return; | 331 return -1; |
322 | 332 |
323 /* Create face surface. */ | 333 /* Create face surface. */ |
324 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, | 334 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, |
325 img_face.width, img_face.height, 32, img_face.width*4, | 335 img_face.width, img_face.height, 32, img_face.width*4, |
326 RMASK, GMASK, BMASK, AMASK ); | 336 RMASK, GMASK, BMASK, AMASK ); |
327 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) | 337 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) |
328 return; | 338 return -1; |
329 tface = SDL_CreateTextureFromSurface( 0, face ); | 339 tface = SDL_CreateTextureFromSurface( 0, face ); |
330 if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0)) | 340 if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0)) |
331 return; | 341 return -1; |
332 | 342 |
333 /* Clean up. */ | 343 /* Clean up. */ |
334 SDL_FreeSurface( face ); | 344 SDL_FreeSurface( face ); |
335 | 345 |
336 /* Constant values. */ | 346 /* Constant values. */ |
345 /* Blitting. */ | 355 /* Blitting. */ |
346 rect.x = i; | 356 rect.x = i; |
347 rect.y = j; | 357 rect.y = j; |
348 ret = SDL_RenderCopy( tface, NULL, &rect ); | 358 ret = SDL_RenderCopy( tface, NULL, &rect ); |
349 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 359 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
350 return; | 360 return -1; |
351 } | 361 } |
352 } | 362 } |
353 | 363 |
354 /* See if it's the same. */ | 364 /* See if it's the same. */ |
355 if (render_compare( "Blit output not the same.", &img_blit )) | 365 if (render_compare( "Blit output not the same.", &img_blit )) |
356 return; | 366 return -1; |
357 | 367 |
358 /* Clear surface. */ | 368 /* Clear surface. */ |
359 if (render_clearScreen()) | 369 if (render_clearScreen()) |
360 return; | 370 return -1; |
361 | 371 |
362 /* Test blitting with colour mod. */ | 372 /* Test blitting with colour mod. */ |
363 for (j=0; j <= nj; j+=4) { | 373 for (j=0; j <= nj; j+=4) { |
364 for (i=0; i <= ni; i+=4) { | 374 for (i=0; i <= ni; i+=4) { |
365 /* Set colour mod. */ | 375 /* Set colour mod. */ |
366 ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j ); | 376 ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j ); |
367 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0)) | 377 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0)) |
368 return; | 378 return -1; |
369 | 379 |
370 /* Blitting. */ | 380 /* Blitting. */ |
371 rect.x = i; | 381 rect.x = i; |
372 rect.y = j; | 382 rect.y = j; |
373 ret = SDL_RenderCopy( tface, NULL, &rect ); | 383 ret = SDL_RenderCopy( tface, NULL, &rect ); |
374 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 384 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
375 return; | 385 return -1; |
376 } | 386 } |
377 } | 387 } |
378 | 388 |
379 /* See if it's the same. */ | 389 /* See if it's the same. */ |
380 if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).", | 390 if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).", |
381 &img_blitColour )) | 391 &img_blitColour )) |
382 return; | 392 return -1; |
383 | 393 |
384 /* Clear surface. */ | 394 /* Clear surface. */ |
385 if (render_clearScreen()) | 395 if (render_clearScreen()) |
386 return; | 396 return -1; |
387 | 397 |
388 /* Restore colour. */ | 398 /* Restore colour. */ |
389 ret = SDL_SetTextureColorMod( tface, 255, 255, 255 ); | 399 ret = SDL_SetTextureColorMod( tface, 255, 255, 255 ); |
390 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0)) | 400 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0)) |
391 return; | 401 return -1; |
392 | 402 |
393 /* Test blitting with colour mod. */ | 403 /* Test blitting with colour mod. */ |
394 for (j=0; j <= nj; j+=4) { | 404 for (j=0; j <= nj; j+=4) { |
395 for (i=0; i <= ni; i+=4) { | 405 for (i=0; i <= ni; i+=4) { |
396 /* Set alpha mod. */ | 406 /* Set alpha mod. */ |
397 ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i ); | 407 ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i ); |
398 if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0)) | 408 if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0)) |
399 return; | 409 return -1; |
400 | 410 |
401 /* Blitting. */ | 411 /* Blitting. */ |
402 rect.x = i; | 412 rect.x = i; |
403 rect.y = j; | 413 rect.y = j; |
404 ret = SDL_RenderCopy( tface, NULL, &rect ); | 414 ret = SDL_RenderCopy( tface, NULL, &rect ); |
405 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) | 415 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
406 return; | 416 return -1; |
407 } | 417 } |
408 } | 418 } |
409 | 419 |
410 /* See if it's the same. */ | 420 /* See if it's the same. */ |
411 if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).", | 421 if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).", |
412 &img_blitAlpha )) | 422 &img_blitAlpha )) |
413 return; | 423 return -1; |
414 | 424 |
415 /* Clean up. */ | 425 /* Clean up. */ |
416 SDL_DestroyTexture( tface ); | 426 SDL_DestroyTexture( tface ); |
417 } | 427 |
418 #if 0 | 428 return 0; |
429 } | |
419 | 430 |
420 | 431 |
421 /** | 432 /** |
422 * @brief Tests a blend mode. | 433 * @brief Tests a blend mode. |
423 */ | 434 */ |
424 static int render_testBlitBlendMode( SDL_Surface *face, int mode ) | 435 static int render_testBlitBlendMode( SDL_TextureID tface, int mode ) |
425 { | 436 { |
426 int ret; | 437 int ret; |
427 int i, j, ni, nj; | 438 int i, j, ni, nj; |
428 SDL_Rect rect; | 439 SDL_Rect rect; |
429 | 440 |
430 /* Clear surface. */ | 441 /* Clear surface. */ |
431 ret = SDL_FillRect( testsur, NULL, | 442 if (render_clearScreen()) |
432 SDL_MapRGB( testsur->format, 0, 0, 0 ) ); | 443 return -1; |
433 if (SDL_ATassert( "SDL_FillRect", ret == 0)) | |
434 return 1; | |
435 | 444 |
436 /* Steps to take. */ | 445 /* Steps to take. */ |
437 ni = testsur->w - face->w; | 446 ni = SCREEN_W - FACE_W; |
438 nj = testsur->h - face->h; | 447 nj = SCREEN_H - FACE_H; |
439 | 448 |
440 /* Constant values. */ | 449 /* Constant values. */ |
441 rect.w = face->w; | 450 rect.w = FACE_W; |
442 rect.h = face->h; | 451 rect.h = FACE_H; |
443 | 452 |
444 /* Test blend mode. */ | 453 /* Test blend mode. */ |
445 for (j=0; j <= nj; j+=4) { | 454 for (j=0; j <= nj; j+=4) { |
446 for (i=0; i <= ni; i+=4) { | 455 for (i=0; i <= ni; i+=4) { |
447 /* Set blend mode. */ | 456 /* Set blend mode. */ |
448 ret = SDL_SetSurfaceBlendMode( face, mode ); | 457 ret = SDL_SetRenderDrawBlendMode( mode ); |
449 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) | 458 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
450 return 1; | 459 return -1; |
451 | 460 |
452 /* Blitting. */ | 461 /* Blitting. */ |
453 rect.x = i; | 462 rect.x = i; |
454 rect.y = j; | 463 rect.y = j; |
455 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); | 464 ret = SDL_RenderCopy( tface, NULL, &rect ); |
456 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) | 465 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
457 return 1; | 466 return -1; |
458 } | 467 } |
459 } | 468 } |
460 | 469 |
461 return 0; | 470 return 0; |
462 } | 471 } |
463 | 472 |
464 | 473 |
465 /** | 474 /** |
466 * @brief Tests some more blitting routines. | 475 * @brief Tests some more blitting routines. |
467 */ | 476 */ |
468 static void render_testBlitBlend (void) | 477 static int render_testBlitBlend (void) |
469 { | 478 { |
470 int ret; | 479 int ret; |
471 SDL_Rect rect; | 480 SDL_Rect rect; |
472 SDL_Surface *face; | 481 SDL_Surface *face; |
482 SDL_TextureID tface; | |
473 int i, j, ni, nj; | 483 int i, j, ni, nj; |
474 int mode; | 484 int mode; |
475 | 485 |
476 SDL_ATbegin( "Blit Blending Tests" ); | |
477 | |
478 /* Clear surface. */ | 486 /* Clear surface. */ |
479 ret = SDL_FillRect( testsur, NULL, | 487 if (render_clearScreen()) |
480 SDL_MapRGB( testsur->format, 0, 0, 0 ) ); | 488 return -1; |
481 if (SDL_ATassert( "SDL_FillRect", ret == 0)) | 489 |
482 return; | 490 /* Create face surface. */ |
483 | |
484 /* Create the blit surface. */ | |
485 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, | 491 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, |
486 img_face.width, img_face.height, 32, img_face.width*4, | 492 img_face.width, img_face.height, 32, img_face.width*4, |
487 RMASK, GMASK, BMASK, AMASK ); | 493 RMASK, GMASK, BMASK, AMASK ); |
488 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) | 494 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) |
489 return; | 495 return -1; |
496 tface = SDL_CreateTextureFromSurface( 0, face ); | |
497 if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0)) | |
498 return -1; | |
499 | |
500 /* Clean up. */ | |
501 SDL_FreeSurface( face ); | |
490 | 502 |
491 /* Set alpha mod. */ | 503 /* Set alpha mod. */ |
492 ret = SDL_SetSurfaceAlphaMod( face, 100 ); | 504 ret = SDL_SetRenderDrawColor( 255, 255, 255, 100 ); |
493 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) | 505 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
494 return; | 506 return -1; |
495 | 507 |
496 /* Steps to take. */ | 508 /* Steps to take. */ |
497 ni = testsur->w - face->w; | 509 ni = SCREEN_W - FACE_W; |
498 nj = testsur->h - face->h; | 510 nj = SCREEN_H - FACE_H; |
499 | 511 |
500 /* Constant values. */ | 512 /* Constant values. */ |
501 rect.w = face->w; | 513 rect.w = face->w; |
502 rect.h = face->h; | 514 rect.h = face->h; |
503 | 515 |
504 /* Test None. */ | 516 /* Test None. */ |
505 if (render_testBlitBlendMode( face, SDL_BLENDMODE_NONE )) | 517 if (render_testBlitBlendMode( tface, SDL_BLENDMODE_NONE )) |
506 return; | 518 return -1; |
507 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_NONE).", | 519 /* See if it's the same. */ |
508 render_compare( testsur, &img_blendNone )==0 )) | 520 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).", |
509 return; | 521 &img_blitAlpha )) |
522 return -1; | |
510 | 523 |
511 /* Test Mask. */ | 524 /* Test Mask. */ |
512 if (render_testBlitBlendMode( face, SDL_BLENDMODE_MASK )) | 525 if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MASK )) |
513 return; | 526 return -1; |
514 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MASK).", | 527 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MASK).", |
515 render_compare( testsur, &img_blendMask )==0 )) | 528 &img_blendMask )) |
516 return; | 529 return -1; |
517 | 530 |
518 /* Test Blend. */ | 531 /* Test Blend. */ |
519 if (render_testBlitBlendMode( face, SDL_BLENDMODE_BLEND )) | 532 if (render_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND )) |
520 return; | 533 return -1; |
521 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_BLEND).", | 534 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).", |
522 render_compare( testsur, &img_blendBlend )==0 )) | 535 &img_blendBlend )) |
523 return; | 536 return -1; |
524 | 537 |
525 /* Test Add. */ | 538 /* Test Add. */ |
526 if (render_testBlitBlendMode( face, SDL_BLENDMODE_ADD )) | 539 if (render_testBlitBlendMode( tface, SDL_BLENDMODE_ADD )) |
527 return; | 540 return -1; |
528 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_ADD).", | 541 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).", |
529 render_compare( testsur, &img_blendAdd )==0 )) | 542 &img_blendAdd )) |
530 return; | 543 return -1; |
531 | 544 |
532 /* Test Mod. */ | 545 /* Test Mod. */ |
533 if (render_testBlitBlendMode( face, SDL_BLENDMODE_MOD )) | 546 if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MOD )) |
534 return; | 547 return -1; |
535 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MOD).", | 548 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).", |
536 render_compare( testsur, &img_blendMod )==0 )) | 549 &img_blendMod )) |
537 return; | 550 return -1; |
538 | 551 |
539 /* Clear surface. */ | 552 /* Clear surface. */ |
540 ret = SDL_FillRect( testsur, NULL, | 553 if (render_clearScreen()) |
541 SDL_MapRGB( testsur->format, 0, 0, 0 ) ); | 554 return -1; |
542 if (SDL_ATassert( "SDL_FillRect", ret == 0)) | |
543 return; | |
544 | 555 |
545 /* Loop blit. */ | 556 /* Loop blit. */ |
546 for (j=0; j <= nj; j+=4) { | 557 for (j=0; j <= nj; j+=4) { |
547 for (i=0; i <= ni; i+=4) { | 558 for (i=0; i <= ni; i+=4) { |
548 | 559 |
549 /* Set colour mod. */ | 560 /* Set colour mod. */ |
550 ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j ); | 561 ret = SDL_SetRenderDrawColor( (255/nj)*j, (255/ni)*i, (255/nj)*j, (100/ni)*i ); |
551 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0)) | 562 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) |
552 return; | 563 return -1; |
553 | |
554 /* Set alpha mod. */ | |
555 ret = SDL_SetSurfaceAlphaMod( face, (100/ni)*i ); | |
556 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) | |
557 return; | |
558 | 564 |
559 /* Crazy blending mode magic. */ | 565 /* Crazy blending mode magic. */ |
560 mode = (i/4*j/4) % 4; | 566 mode = (i/4*j/4) % 4; |
561 if (mode==0) mode = SDL_BLENDMODE_MASK; | 567 if (mode==0) mode = SDL_BLENDMODE_MASK; |
562 else if (mode==1) mode = SDL_BLENDMODE_BLEND; | 568 else if (mode==1) mode = SDL_BLENDMODE_BLEND; |
563 else if (mode==2) mode = SDL_BLENDMODE_ADD; | 569 else if (mode==2) mode = SDL_BLENDMODE_ADD; |
564 else if (mode==3) mode = SDL_BLENDMODE_MOD; | 570 else if (mode==3) mode = SDL_BLENDMODE_MOD; |
565 ret = SDL_SetSurfaceBlendMode( face, mode ); | 571 ret = SDL_SetRenderDrawBlendMode( mode ); |
566 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) | 572 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) |
567 return; | 573 return -1; |
568 | 574 |
569 /* Blitting. */ | 575 /* Blitting. */ |
570 rect.x = i; | 576 rect.x = i; |
571 rect.y = j; | 577 rect.y = j; |
572 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); | 578 ret = SDL_RenderCopy( tface, NULL, &rect ); |
573 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) | 579 if (SDL_ATassert( "SDL_RenderCopy", ret == 0)) |
574 return; | 580 return -1; |
575 } | 581 } |
576 } | 582 } |
577 | 583 |
578 /* Check to see if matches. */ | 584 /* Check to see if matches. */ |
579 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLEND_*).", | 585 if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_*).", |
580 render_compare( testsur, &img_blendAll )==0 )) | 586 &img_blendAll )) |
581 return; | 587 return -1; |
582 | 588 |
583 /* Clean up. */ | 589 /* Clean up. */ |
584 SDL_FreeSurface( face ); | 590 SDL_DestroyTexture( tface ); |
585 | 591 |
586 SDL_ATend(); | 592 return 0; |
587 } | 593 } |
588 #endif | |
589 | 594 |
590 | 595 |
591 /** | 596 /** |
592 * @brief Runs all the tests on the surface. | 597 * @brief Runs all the tests on the surface. |
593 * | 598 * |
594 * @param testsur Surface to run tests on. | 599 * @return 0 on success. |
595 */ | 600 */ |
596 void render_runTests (void) | 601 int render_runTests (void) |
597 { | 602 { |
603 int ret; | |
604 | |
605 /* No error. */ | |
606 ret = 0; | |
607 | |
598 /* Software surface blitting. */ | 608 /* Software surface blitting. */ |
599 render_testPrimitives(); | 609 ret |= render_testPrimitives(); |
600 render_testPrimitivesBlend(); | 610 if (ret) |
601 render_testBlit(); | 611 return -1; |
602 /* | 612 ret |= render_testPrimitivesBlend(); |
603 render_testBlitBlend(); | 613 if (ret) |
604 */ | 614 return -1; |
615 ret |= render_testBlit(); | |
616 if (ret) | |
617 return -1; | |
618 ret |= render_testBlitBlend(); | |
619 | |
620 return ret; | |
605 } | 621 } |
606 | 622 |
607 | 623 |
608 /** | 624 /** |
609 * @brief Entry point. | 625 * @brief Entry point. |
699 goto err; | 715 goto err; |
700 | 716 |
701 /* | 717 /* |
702 * Run tests. | 718 * Run tests. |
703 */ | 719 */ |
704 render_runTests(); | 720 if (render_runTests()) |
721 continue; | |
705 | 722 |
706 SDL_ATend(); | 723 SDL_ATend(); |
707 } | 724 } |
708 | 725 |
709 /* Exit the current renderer. */ | 726 /* Exit the current renderer. */ |