comparison test/automated/render/render.c @ 3733:ca544951b504 gsoc2009_unit_tests

Finished converting the blit testcase.
author Edgar Simo <bobbens@gmail.com>
date Wed, 15 Jul 2009 14:40:53 +0000
parents f5ddf1b670f0
children 42356acbc993
comparison
equal deleted inserted replaced
3732:e552b7acd45a 3733:ca544951b504
90 return -1; 90 return -1;
91 91
92 /* Clear screen. */ 92 /* Clear screen. */
93 ret = SDL_RenderFill( NULL ); 93 ret = SDL_RenderFill( NULL );
94 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) 94 if (SDL_ATassert( "SDL_RenderFill", ret == 0))
95 return -1;
96
97 /* Set defaults. */
98 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
99 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
100 return -1;
101 ret = SDL_SetRenderDrawColor( 255, 255, 255, SDL_ALPHA_OPAQUE );
102 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
95 return -1; 103 return -1;
96 104
97 return 0; 105 return 0;
98 } 106 }
99 107
188 196
189 /* Clear surface. */ 197 /* Clear surface. */
190 if (render_clearScreen()) 198 if (render_clearScreen())
191 return; 199 return;
192 200
201 /* See if we can actually run the test. */
202 ret = 0;
203 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
204 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
205 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
206 ret |= SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
207 if (ret != 0)
208 return;
209
193 /* Create some rectangles for each blend mode. */ 210 /* Create some rectangles for each blend mode. */
194 ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 ); 211 ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 );
195 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 212 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
196 return; 213 return;
197 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); 214 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
198 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 215 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
199 return; 216 return;
200 ret = SDL_RenderFill( NULL ); 217 ret = SDL_RenderFill( NULL );
201 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) 218 if (SDL_ATassert( "SDL_RenderFill", ret == 0))
202 return; 219 return;
203 rect.x = 10; 220 rect.x = 10;
206 rect.h = 25; 223 rect.h = 25;
207 ret = SDL_SetRenderDrawColor( 240, 10, 10, 75 ); 224 ret = SDL_SetRenderDrawColor( 240, 10, 10, 75 );
208 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 225 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
209 return; 226 return;
210 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); 227 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
211 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 228 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
212 return; 229 return;
213 ret = SDL_RenderFill( &rect ); 230 ret = SDL_RenderFill( &rect );
214 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) 231 if (SDL_ATassert( "SDL_RenderFill", ret == 0))
215 return; 232 return;
216 rect.x = 30; 233 rect.x = 30;
219 rect.h = 15; 236 rect.h = 15;
220 ret = SDL_SetRenderDrawColor( 10, 240, 10, 100 ); 237 ret = SDL_SetRenderDrawColor( 10, 240, 10, 100 );
221 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 238 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
222 return; 239 return;
223 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); 240 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
224 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 241 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
225 return; 242 return;
226 ret = SDL_RenderFill( &rect ); 243 ret = SDL_RenderFill( &rect );
227 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) 244 if (SDL_ATassert( "SDL_RenderFill", ret == 0))
228 return; 245 return;
229 rect.x = 25; 246 rect.x = 25;
232 rect.h = 25; 249 rect.h = 25;
233 ret = SDL_SetRenderDrawColor( 10, 10, 240, 125 ); 250 ret = SDL_SetRenderDrawColor( 10, 10, 240, 125 );
234 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 251 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
235 return; 252 return;
236 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); 253 ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
237 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 254 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
238 return; 255 return;
239 ret = SDL_RenderFill( &rect ); 256 ret = SDL_RenderFill( &rect );
240 if (SDL_ATassert( "SDL_RenderFill", ret == 0)) 257 if (SDL_ATassert( "SDL_RenderFill", ret == 0))
241 return; 258 return;
242 259
245 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); 262 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i );
246 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 263 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
247 return; 264 return;
248 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : 265 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
249 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); 266 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
250 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 267 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
251 return; 268 return;
252 ret = SDL_RenderLine( 0, 0, i, 59 ); 269 ret = SDL_RenderLine( 0, 0, i, 59 );
253 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) 270 if (SDL_ATassert( "SDL_RenderLine", ret == 0))
254 return; 271 return;
255 } 272 }
257 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i ); 274 ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i );
258 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 275 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
259 return; 276 return;
260 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND : 277 ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
261 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); 278 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
262 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 279 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
263 return; 280 return;
264 ret = SDL_RenderLine( 0, 0, 79, i ); 281 ret = SDL_RenderLine( 0, 0, 79, i );
265 if (SDL_ATassert( "SDL_RenderLine", ret == 0)) 282 if (SDL_ATassert( "SDL_RenderLine", ret == 0))
266 return; 283 return;
267 } 284 }
272 ret = SDL_SetRenderDrawColor( j*4, i*3, j*4, i*3 ); 289 ret = SDL_SetRenderDrawColor( j*4, i*3, j*4, i*3 );
273 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) 290 if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
274 return; 291 return;
275 ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND : 292 ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
276 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD ); 293 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
277 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) 294 if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
278 return; 295 return;
279 ret = SDL_RenderPoint( i, j ); 296 ret = SDL_RenderPoint( i, j );
280 if (SDL_ATassert( "SDL_RenderPoint", ret == 0)) 297 if (SDL_ATassert( "SDL_RenderPoint", ret == 0))
281 return; 298 return;
282 } 299 }
284 301
285 /* See if it's the same. */ 302 /* See if it's the same. */
286 if (render_compare( "Blended primitives output not the same.", &img_primitives )) 303 if (render_compare( "Blended primitives output not the same.", &img_primitives ))
287 return; 304 return;
288 } 305 }
289 #if 0
290 306
291 307
292 /** 308 /**
293 * @brief Tests some blitting routines. 309 * @brief Tests some blitting routines.
294 */ 310 */
295 static void render_testBlit (void) 311 static void render_testBlit (void)
296 { 312 {
297 int ret; 313 int ret;
298 SDL_Rect rect; 314 SDL_Rect rect;
299 SDL_Surface *face; 315 SDL_Surface *face;
316 SDL_TextureID tface;
300 int i, j, ni, nj; 317 int i, j, ni, nj;
301 318
302 SDL_ATbegin( "Blit Tests" );
303
304 /* Clear surface. */ 319 /* Clear surface. */
305 ret = SDL_FillRect( testsur, NULL, 320 if (render_clearScreen())
306 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
307 if (SDL_ATassert( "SDL_FillRect", ret == 0))
308 return; 321 return;
309 322
310 /* Create face surface. */ 323 /* Create face surface. */
311 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, 324 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
312 img_face.width, img_face.height, 32, img_face.width*4, 325 img_face.width, img_face.height, 32, img_face.width*4,
313 RMASK, GMASK, BMASK, AMASK ); 326 RMASK, GMASK, BMASK, AMASK );
314 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL)) 327 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
315 return; 328 return;
329 tface = SDL_CreateTextureFromSurface( 0, face );
330 if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0))
331 return;
332
333 /* Clean up. */
334 SDL_FreeSurface( face );
316 335
317 /* Constant values. */ 336 /* Constant values. */
318 rect.w = face->w; 337 rect.w = face->w;
319 rect.h = face->h; 338 rect.h = face->h;
320 ni = testsur->w - face->w; 339 ni = SCREEN_W - face->w;
321 nj = testsur->h - face->h; 340 nj = SCREEN_H - face->h;
322 341
323 /* Loop blit. */ 342 /* Loop blit. */
324 for (j=0; j <= nj; j+=4) { 343 for (j=0; j <= nj; j+=4) {
325 for (i=0; i <= ni; i+=4) { 344 for (i=0; i <= ni; i+=4) {
326 /* Blitting. */ 345 /* Blitting. */
327 rect.x = i; 346 rect.x = i;
328 rect.y = j; 347 rect.y = j;
329 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); 348 ret = SDL_RenderCopy( tface, NULL, &rect );
330 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) 349 if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
331 return; 350 return;
332 } 351 }
333 } 352 }
334 353
335 /* See if it's the same. */ 354 /* See if it's the same. */
336 if (SDL_ATassert( "Blitting output not the same (normal blit).", 355 if (render_compare( "Blit output not the same.", &img_blit ))
337 render_compare( testsur, &img_blit )==0 ))
338 return; 356 return;
339 357
340 /* Clear surface. */ 358 /* Clear surface. */
341 ret = SDL_FillRect( testsur, NULL, 359 if (render_clearScreen())
342 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
343 if (SDL_ATassert( "SDL_FillRect", ret == 0))
344 return; 360 return;
345 361
346 /* Test blitting with colour mod. */ 362 /* Test blitting with colour mod. */
347 for (j=0; j <= nj; j+=4) { 363 for (j=0; j <= nj; j+=4) {
348 for (i=0; i <= ni; i+=4) { 364 for (i=0; i <= ni; i+=4) {
349 /* Set colour mod. */ 365 /* Set colour mod. */
350 ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j ); 366 ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
351 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0)) 367 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0))
352 return; 368 return;
353 369
354 /* Blitting. */ 370 /* Blitting. */
355 rect.x = i; 371 rect.x = i;
356 rect.y = j; 372 rect.y = j;
357 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); 373 ret = SDL_RenderCopy( tface, NULL, &rect );
358 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) 374 if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
359 return; 375 return;
360 } 376 }
361 } 377 }
362 378
363 /* See if it's the same. */ 379 /* See if it's the same. */
364 if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceColorMod).", 380 if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).",
365 render_compare( testsur, &img_blitColour )==0 )) 381 &img_blitColour ))
366 return; 382 return;
367 383
368 /* Clear surface. */ 384 /* Clear surface. */
369 ret = SDL_FillRect( testsur, NULL, 385 if (render_clearScreen())
370 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
371 if (SDL_ATassert( "SDL_FillRect", ret == 0))
372 return; 386 return;
373 387
374 /* Restore colour. */ 388 /* Restore colour. */
375 ret = SDL_SetSurfaceColorMod( face, 255, 255, 255 ); 389 ret = SDL_SetTextureColorMod( tface, 255, 255, 255 );
376 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0)) 390 if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0))
377 return; 391 return;
378 392
379 /* Test blitting with colour mod. */ 393 /* Test blitting with colour mod. */
380 for (j=0; j <= nj; j+=4) { 394 for (j=0; j <= nj; j+=4) {
381 for (i=0; i <= ni; i+=4) { 395 for (i=0; i <= ni; i+=4) {
382 /* Set alpha mod. */ 396 /* Set alpha mod. */
383 ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i ); 397 ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i );
384 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) 398 if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0))
385 return; 399 return;
386 400
387 /* Blitting. */ 401 /* Blitting. */
388 rect.x = i; 402 rect.x = i;
389 rect.y = j; 403 rect.y = j;
390 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); 404 ret = SDL_RenderCopy( tface, NULL, &rect );
391 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) 405 if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
392 return; 406 return;
393 } 407 }
394 } 408 }
395 409
396 /* See if it's the same. */ 410 /* See if it's the same. */
397 if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceAlphaMod).", 411 if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
398 render_compare( testsur, &img_blitAlpha )==0 )) 412 &img_blitAlpha ))
399 return; 413 return;
400 414
401 /* Clean up. */ 415 /* Clean up. */
402 SDL_FreeSurface( face ); 416 SDL_DestroyTexture( tface );
403 417 }
404 SDL_ATend(); 418 #if 0
405 }
406 419
407 420
408 /** 421 /**
409 * @brief Tests a blend mode. 422 * @brief Tests a blend mode.
410 */ 423 */
582 */ 595 */
583 void render_runTests (void) 596 void render_runTests (void)
584 { 597 {
585 /* Software surface blitting. */ 598 /* Software surface blitting. */
586 render_testPrimitives(); 599 render_testPrimitives();
587 /*
588 render_testPrimitivesBlend(); 600 render_testPrimitivesBlend();
589 render_testBlit(); 601 render_testBlit();
602 /*
590 render_testBlitBlend(); 603 render_testBlitBlend();
591 */ 604 */
592 } 605 }
593 606
594 607