2 * Original code: automated SDL platform test written by Edgar Simo "bobbens"
3 * Extended and extensively updated by aschiffler at ferzkopp dot net
11 /* ================= Test Case Implementation ================== */
13 #define TESTRENDER_SCREEN_W 80
14 #define TESTRENDER_SCREEN_H 60
16 #define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888
17 #define RENDER_COMPARE_AMASK 0xff000000 /**< Alpha bit mask. */
18 #define RENDER_COMPARE_RMASK 0x00ff0000 /**< Red bit mask. */
19 #define RENDER_COMPARE_GMASK 0x0000ff00 /**< Green bit mask. */
20 #define RENDER_COMPARE_BMASK 0x000000ff /**< Blue bit mask. */
22 #define ALLOWABLE_ERROR_OPAQUE 0
23 #define ALLOWABLE_ERROR_BLENDED 64
25 /* Test window and renderer */
26 SDL_Window *window = NULL;
27 SDL_Renderer *renderer = NULL;
29 /* Prototypes for helper functions */
31 static int _clearScreen (void);
32 static void _compare(SDL_Surface *reference, int allowable_error);
33 static int _hasTexAlpha(void);
34 static int _hasTexColor(void);
35 static SDL_Texture *_loadTestFace(void);
36 static int _hasBlendModes(void);
37 static int _hasDrawColor(void);
38 static int _isSupported(int code);
41 * Create software renderer for tests
43 void InitCreateRenderer(void *arg)
45 int posX = 100, posY = 100, width = 320, height = 240;
47 window = SDL_CreateWindow("render_testCreateRenderer", posX, posY, width, height, 0);
48 SDLTest_AssertPass("SDL_CreateWindow()");
49 SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
54 renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
55 SDLTest_AssertPass("SDL_CreateRenderer()");
56 SDLTest_AssertCheck(renderer != 0, "Check SDL_CreateRenderer result");
57 if (renderer == NULL) {
58 SDL_DestroyWindow(window);
64 * Destroy renderer for tests
66 void CleanupDestroyRenderer(void *arg)
68 if (renderer != NULL) {
69 SDL_DestroyRenderer(renderer);
71 SDLTest_AssertPass("SDL_DestroyRenderer()");
75 SDL_DestroyWindow(window);
77 SDLTest_AssertPass("SDL_DestroyWindow");
83 * @brief Tests call to SDL_GetNumRenderDrivers
86 * http://wiki.libsdl.org/moin.cgi/SDL_GetNumRenderDrivers
89 render_testGetNumRenderDrivers(void *arg)
92 n = SDL_GetNumRenderDrivers();
93 SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n);
94 return TEST_COMPLETED;
99 * @brief Tests the SDL primitives for rendering.
102 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
103 * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
104 * http://wiki.libsdl.org/moin.cgi/SDL_RenderDrawLine
107 int render_testPrimitives (void *arg)
112 SDL_Surface *referenceSurface = NULL;
119 /* Need drawcolor or just skip test. */
120 SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
122 /* Draw a rectangle. */
128 ret = SDL_SetRenderDrawColor(renderer, 13, 73, 200, SDL_ALPHA_OPAQUE );
129 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
131 ret = SDL_RenderFillRect(renderer, &rect );
132 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
134 /* Draw a rectangle. */
139 ret = SDL_SetRenderDrawColor(renderer, 200, 0, 100, SDL_ALPHA_OPAQUE );
140 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
142 ret = SDL_RenderFillRect(renderer, &rect );
143 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
145 /* Draw some points like so:
151 for (y=0; y<3; y++) {
152 for (x = y % 2; x<TESTRENDER_SCREEN_W; x+=2) {
153 ret = SDL_SetRenderDrawColor(renderer, x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE );
154 if (ret != 0) checkFailCount1++;
156 ret = SDL_RenderDrawPoint(renderer, x, y );
157 if (ret != 0) checkFailCount2++;
160 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
161 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount2);
163 /* Draw some lines. */
164 ret = SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE );
165 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor");
167 ret = SDL_RenderDrawLine(renderer, 0, 30, TESTRENDER_SCREEN_W, 30 );
168 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
170 ret = SDL_SetRenderDrawColor(renderer, 55, 55, 5, SDL_ALPHA_OPAQUE );
171 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
173 ret = SDL_RenderDrawLine(renderer, 40, 30, 40, 60 );
174 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
176 ret = SDL_SetRenderDrawColor(renderer, 5, 105, 105, SDL_ALPHA_OPAQUE );
177 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
179 ret = SDL_RenderDrawLine(renderer, 0, 0, 29, 29 );
180 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
182 ret = SDL_RenderDrawLine(renderer, 29, 30, 0, 59 );
183 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
185 ret = SDL_RenderDrawLine(renderer, 79, 0, 50, 29 );
186 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
188 ret = SDL_RenderDrawLine(renderer, 79, 59, 50, 30 );
189 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderDrawLine, expected: 0, got: %i", ret);
192 SDL_RenderPresent(renderer);
194 /* See if it's the same. */
195 referenceSurface = SDLTest_ImagePrimitives();
196 _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
199 SDL_FreeSurface(referenceSurface);
200 referenceSurface = NULL;
202 return TEST_COMPLETED;
206 * @brief Tests the SDL primitives with alpha for rendering.
209 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
210 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
211 * http://wiki.libsdl.org/moin.cgi/SDL_RenderFillRect
213 int render_testPrimitivesBlend (void *arg)
218 SDL_Surface *referenceSurface = NULL;
226 /* Need drawcolor and blendmode or just skip test. */
227 SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor");
228 SDLTest_AssertCheck(_hasBlendModes(), "_hasBlendModes");
230 /* Create some rectangles for each blend mode. */
231 ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, 0 );
232 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
234 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
235 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
237 ret = SDL_RenderFillRect(renderer, NULL );
238 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
244 ret = SDL_SetRenderDrawColor(renderer, 240, 10, 10, 75 );
245 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
247 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD );
248 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
250 ret = SDL_RenderFillRect(renderer, &rect );
251 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
257 ret = SDL_SetRenderDrawColor(renderer, 10, 240, 10, 100 );
258 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
260 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND );
261 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
263 ret = SDL_RenderFillRect(renderer, &rect );
264 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
270 ret = SDL_SetRenderDrawColor(renderer, 10, 10, 240, 125 );
271 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
273 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
274 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
276 ret = SDL_RenderFillRect(renderer, &rect );
277 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderFillRect, expected: 0, got: %i", ret);
280 /* Draw blended lines, lines for everyone. */
284 for (i=0; i<TESTRENDER_SCREEN_W; i+=2) {
285 ret = SDL_SetRenderDrawColor(renderer, 60+2*i, 240-2*i, 50, 3*i );
286 if (ret != 0) checkFailCount1++;
288 ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
289 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
290 if (ret != 0) checkFailCount2++;
292 ret = SDL_RenderDrawLine(renderer, 0, 0, i, 59 );
293 if (ret != 0) checkFailCount3++;
295 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
296 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
297 SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawLine, expected: 0, got: %i", checkFailCount3);
302 for (i=0; i<TESTRENDER_SCREEN_H; i+=2) {
303 ret = SDL_SetRenderDrawColor(renderer, 60+2*i, 240-2*i, 50, 3*i );
304 if (ret != 0) checkFailCount1++;
306 ret = SDL_SetRenderDrawBlendMode(renderer,(((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
307 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
308 if (ret != 0) checkFailCount2++;
310 ret = SDL_RenderDrawLine(renderer, 0, 0, 79, i );
311 if (ret != 0) checkFailCount3++;
313 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
314 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
315 SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawLine, expected: 0, got: %i", checkFailCount3);
321 for (j=0; j<TESTRENDER_SCREEN_H; j+=3) {
322 for (i=0; i<TESTRENDER_SCREEN_W; i+=3) {
323 ret = SDL_SetRenderDrawColor(renderer, j*4, i*3, j*4, i*3 );
324 if (ret != 0) checkFailCount1++;
326 ret = SDL_SetRenderDrawBlendMode(renderer, ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
327 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_NONE );
328 if (ret != 0) checkFailCount2++;
330 ret = SDL_RenderDrawPoint(renderer, i, j );
331 if (ret != 0) checkFailCount3++;
334 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
335 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetRenderDrawBlendMode, expected: 0, got: %i", checkFailCount2);
336 SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_RenderDrawPoint, expected: 0, got: %i", checkFailCount3);
339 SDL_RenderPresent(renderer);
341 /* See if it's the same. */
342 referenceSurface = SDLTest_ImagePrimitivesBlend();
343 _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
346 SDL_FreeSurface(referenceSurface);
347 referenceSurface = NULL;
349 return TEST_COMPLETED;
355 * @brief Tests some blitting routines.
358 * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
359 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
362 render_testBlit(void *arg)
367 SDL_Surface *referenceSurface = NULL;
376 /* Need drawcolor or just skip test. */
377 SDLTest_AssertCheck(_hasDrawColor(), "_hasDrawColor)");
379 /* Create face surface. */
380 tface = _loadTestFace();
381 SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
386 /* Constant values. */
387 ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
388 SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
391 ni = TESTRENDER_SCREEN_W - tw;
392 nj = TESTRENDER_SCREEN_H - th;
396 for (j=0; j <= nj; j+=4) {
397 for (i=0; i <= ni; i+=4) {
401 ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
402 if (ret != 0) checkFailCount1++;
405 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount1);
408 SDL_RenderPresent(renderer);
410 /* See if it's the same */
411 referenceSurface = SDLTest_ImageBlit();
412 _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
415 SDL_DestroyTexture( tface );
416 SDL_FreeSurface(referenceSurface);
417 referenceSurface = NULL;
419 return TEST_COMPLETED;
424 * @brief Blits doing color tests.
427 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
428 * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
429 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
432 render_testBlitColor (void *arg)
437 SDL_Surface *referenceSurface = NULL;
447 /* Create face surface. */
448 tface = _loadTestFace();
449 SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
454 /* Constant values. */
455 ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
456 SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
459 ni = TESTRENDER_SCREEN_W - tw;
460 nj = TESTRENDER_SCREEN_H - th;
462 /* Test blitting with color mod. */
465 for (j=0; j <= nj; j+=4) {
466 for (i=0; i <= ni; i+=4) {
468 ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
469 if (ret != 0) checkFailCount1++;
474 ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
475 if (ret != 0) checkFailCount2++;
478 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
479 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
482 SDL_RenderPresent(renderer);
484 /* See if it's the same. */
485 referenceSurface = SDLTest_ImageBlitColor();
486 _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
489 SDL_DestroyTexture( tface );
490 SDL_FreeSurface(referenceSurface);
491 referenceSurface = NULL;
493 return TEST_COMPLETED;
498 * @brief Tests blitting with alpha.
501 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
502 * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
503 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
506 render_testBlitAlpha (void *arg)
511 SDL_Surface *referenceSurface = NULL;
521 /* Need alpha or just skip test. */
522 SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
524 /* Create face surface. */
525 tface = _loadTestFace();
526 SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
531 /* Constant values. */
532 ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
533 SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
536 ni = TESTRENDER_SCREEN_W - tw;
537 nj = TESTRENDER_SCREEN_H - th;
539 /* Test blitting with alpha mod. */
542 for (j=0; j <= nj; j+=4) {
543 for (i=0; i <= ni; i+=4) {
545 ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i );
546 if (ret != 0) checkFailCount1++;
551 ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
552 if (ret != 0) checkFailCount2++;
555 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount1);
556 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
559 SDL_RenderPresent(renderer);
561 /* See if it's the same. */
562 referenceSurface = SDLTest_ImageBlitAlpha();
563 _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
566 SDL_DestroyTexture( tface );
567 SDL_FreeSurface(referenceSurface);
568 referenceSurface = NULL;
570 return TEST_COMPLETED;
573 /* Helper functions */
576 * @brief Tests a blend mode.
579 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureBlendMode
580 * http://wiki.libsdl.org/moin.cgi/SDL_RenderCopy
583 _testBlitBlendMode( SDL_Texture * tface, int mode )
596 /* Constant values. */
597 ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
598 SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
601 ni = TESTRENDER_SCREEN_W - tw;
602 nj = TESTRENDER_SCREEN_H - th;
604 /* Test blend mode. */
607 for (j=0; j <= nj; j+=4) {
608 for (i=0; i <= ni; i+=4) {
609 /* Set blend mode. */
610 ret = SDL_SetTextureBlendMode( tface, (SDL_BlendMode)mode );
611 if (ret != 0) checkFailCount1++;
616 ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
617 if (ret != 0) checkFailCount2++;
620 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureBlendMode, expected: 0, got: %i", checkFailCount1);
621 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount2);
626 * @brief Tests some more blitting routines.
629 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
630 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
631 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureBlendMode
632 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
635 render_testBlitBlend (void *arg)
640 SDL_Surface *referenceSurface = NULL;
650 SDLTest_AssertCheck(_hasBlendModes(), "_hasBlendModes");
651 SDLTest_AssertCheck(_hasTexColor(), "_hasTexColor");
652 SDLTest_AssertCheck(_hasTexAlpha(), "_hasTexAlpha");
654 /* Create face surface. */
655 tface = _loadTestFace();
656 SDLTest_AssertCheck(tface != NULL, "Verify _loadTestFace() result");
661 /* Constant values. */
662 ret = SDL_QueryTexture(tface, &tformat, &taccess, &tw, &th);
663 SDLTest_AssertCheck(ret == 0, "Verify result from SDL_QueryTexture, expected 0, got %i", ret);
666 ni = TESTRENDER_SCREEN_W - tw;
667 nj = TESTRENDER_SCREEN_H - th;
670 ret = SDL_SetTextureAlphaMod( tface, 100 );
671 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetTextureAlphaMod, expected: 0, got: %i", ret);
674 _testBlitBlendMode( tface, SDL_BLENDMODE_NONE );
675 referenceSurface = SDLTest_ImageBlitBlendNone();
677 /* Make current and compare */
678 SDL_RenderPresent(renderer);
679 _compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE );
680 SDL_FreeSurface(referenceSurface);
681 referenceSurface = NULL;
684 _testBlitBlendMode( tface, SDL_BLENDMODE_BLEND );
685 referenceSurface = SDLTest_ImageBlitBlend();
687 /* Make current and compare */
688 SDL_RenderPresent(renderer);
689 _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
690 SDL_FreeSurface(referenceSurface);
691 referenceSurface = NULL;
694 _testBlitBlendMode( tface, SDL_BLENDMODE_ADD );
695 referenceSurface = SDLTest_ImageBlitBlendAdd();
697 /* Make current and compare */
698 SDL_RenderPresent(renderer);
699 _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
700 SDL_FreeSurface(referenceSurface);
701 referenceSurface = NULL;
704 _testBlitBlendMode( tface, SDL_BLENDMODE_MOD);
705 referenceSurface = SDLTest_ImageBlitBlendMod();
707 /* Make current and compare */
708 SDL_RenderPresent(renderer);
709 _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED );
710 SDL_FreeSurface(referenceSurface);
711 referenceSurface = NULL;
721 for (j=0; j <= nj; j+=4) {
722 for (i=0; i <= ni; i+=4) {
725 ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
726 if (ret != 0) checkFailCount1++;
729 ret = SDL_SetTextureAlphaMod( tface, (100/ni)*i );
730 if (ret != 0) checkFailCount2++;
732 /* Crazy blending mode magic. */
733 mode = (i/4*j/4) % 4;
734 if (mode==0) mode = SDL_BLENDMODE_NONE;
735 else if (mode==1) mode = SDL_BLENDMODE_BLEND;
736 else if (mode==2) mode = SDL_BLENDMODE_ADD;
737 else if (mode==3) mode = SDL_BLENDMODE_MOD;
738 ret = SDL_SetTextureBlendMode( tface, (SDL_BlendMode)mode );
739 if (ret != 0) checkFailCount3++;
744 ret = SDL_RenderCopy(renderer, tface, NULL, &rect );
745 if (ret != 0) checkFailCount4++;
748 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
749 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", checkFailCount2);
750 SDLTest_AssertCheck(checkFailCount3 == 0, "Validate results from calls to SDL_SetTextureBlendMode, expected: 0, got: %i", checkFailCount3);
751 SDLTest_AssertCheck(checkFailCount4 == 0, "Validate results from calls to SDL_RenderCopy, expected: 0, got: %i", checkFailCount4);
754 SDL_DestroyTexture( tface );
757 SDL_RenderPresent(renderer);
759 /* Check to see if final image matches. */
760 referenceSurface = SDLTest_ImageBlitBlendAll();
761 _compare(referenceSurface, ALLOWABLE_ERROR_BLENDED);
762 SDL_FreeSurface(referenceSurface);
763 referenceSurface = NULL;
765 return TEST_COMPLETED;
770 * @brief Checks to see if functionality is supported. Helper function.
773 _isSupported( int code )
779 * @brief Test to see if we can vary the draw color. Helper function.
782 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
783 * http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawColor
794 ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100 );
795 if (!_isSupported(ret))
797 ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a );
798 if (!_isSupported(ret))
801 /* Restore natural. */
802 ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
803 if (!_isSupported(ret))
806 /* Something failed, consider not available. */
810 /* Not set properly, consider failed. */
811 else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
817 * @brief Test to see if we can vary the blend mode. Helper function.
820 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
821 * http://wiki.libsdl.org/moin.cgi/SDL_GetRenderDrawBlendMode
824 _hasBlendModes (void)
832 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND );
833 if (!_isSupported(ret))
835 ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
836 if (!_isSupported(ret))
838 ret = (mode != SDL_BLENDMODE_BLEND);
839 if (!_isSupported(ret))
841 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_ADD );
842 if (!_isSupported(ret))
844 ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
845 if (!_isSupported(ret))
847 ret = (mode != SDL_BLENDMODE_ADD);
848 if (!_isSupported(ret))
850 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_MOD );
851 if (!_isSupported(ret))
853 ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
854 if (!_isSupported(ret))
856 ret = (mode != SDL_BLENDMODE_MOD);
857 if (!_isSupported(ret))
859 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
860 if (!_isSupported(ret))
862 ret = SDL_GetRenderDrawBlendMode(renderer, &mode );
863 if (!_isSupported(ret))
865 ret = (mode != SDL_BLENDMODE_NONE);
866 if (!_isSupported(ret))
874 * @brief Loads the test image 'Face' as texture. Helper function.
877 * http://wiki.libsdl.org/moin.cgi/SDL_CreateTextureFromSurface
885 face = SDLTest_ImageFace();
890 tface = SDL_CreateTextureFromSurface(renderer, face);
892 SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
895 SDL_FreeSurface(face);
902 * @brief Test to see if can set texture color mode. Helper function.
905 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureColorMod
906 * http://wiki.libsdl.org/moin.cgi/SDL_GetTextureColorMod
907 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
918 tface = _loadTestFace();
922 /* See if supported. */
924 ret = SDL_SetTextureColorMod( tface, 100, 100, 100 );
925 if (!_isSupported(ret))
927 ret = SDL_GetTextureColorMod( tface, &r, &g, &b );
928 if (!_isSupported(ret))
932 SDL_DestroyTexture( tface );
936 else if ((r != 100) || (g != 100) || (b != 100))
942 * @brief Test to see if we can vary the alpha of the texture. Helper function.
945 * http://wiki.libsdl.org/moin.cgi/SDL_SetTextureAlphaMod
946 * http://wiki.libsdl.org/moin.cgi/SDL_GetTextureAlphaMod
947 * http://wiki.libsdl.org/moin.cgi/SDL_DestroyTexture
958 tface = _loadTestFace();
962 /* See if supported. */
964 ret = SDL_SetTextureAlphaMod( tface, 100 );
965 if (!_isSupported(ret))
967 ret = SDL_GetTextureAlphaMod( tface, &a );
968 if (!_isSupported(ret))
972 SDL_DestroyTexture( tface );
982 * @brief Compares screen pixels with image pixels. Helper function.
984 * @param s Image to compare against.
987 * http://wiki.libsdl.org/moin.cgi/SDL_RenderReadPixels
988 * http://wiki.libsdl.org/moin.cgi/SDL_CreateRGBSurfaceFrom
989 * http://wiki.libsdl.org/moin.cgi/SDL_FreeSurface
992 _compare(SDL_Surface *referenceSurface, int allowable_error)
997 SDL_Surface *testSurface;
1000 pixels = (Uint8 *)SDL_malloc(4*TESTRENDER_SCREEN_W*TESTRENDER_SCREEN_H);
1001 SDLTest_AssertCheck(pixels != NULL, "Validate allocated temp pixel buffer");
1002 if (pixels == NULL) return;
1004 /* Explicitly specify the rect in case the window isn't the expected size... */
1007 rect.w = TESTRENDER_SCREEN_W;
1008 rect.h = TESTRENDER_SCREEN_H;
1009 result = SDL_RenderReadPixels(renderer, &rect, RENDER_COMPARE_FORMAT, pixels, 80*4 );
1010 SDLTest_AssertCheck(result == 0, "Validate result from SDL_RenderReadPixels, expected: 0, got: %i", result);
1012 /* Create surface. */
1013 testSurface = SDL_CreateRGBSurfaceFrom(pixels, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4,
1014 RENDER_COMPARE_RMASK, RENDER_COMPARE_GMASK, RENDER_COMPARE_BMASK, RENDER_COMPARE_AMASK);
1015 SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceFrom is not NULL");
1017 /* Compare surface. */
1018 result = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error );
1019 SDLTest_AssertCheck(result == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", result);
1021 /*Create surface. */
1022 testSurface = SDL_CreateRGBSurfaceWithFormatFrom(pixels, TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, 32, TESTRENDER_SCREEN_W*4, RENDER_COMPARE_FORMAT);
1023 SDLTest_AssertCheck(testSurface != NULL, "Verify result from SDL_CreateRGBSurfaceWithFormatFrom is not NULL");
1025 /* Compare surface. */
1026 result = SDLTest_CompareSurfaces( testSurface, referenceSurface, allowable_error );
1027 SDLTest_AssertCheck(result == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", result);
1031 SDL_FreeSurface(testSurface);
1035 * @brief Clears the screen. Helper function.
1038 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawColor
1039 * http://wiki.libsdl.org/moin.cgi/SDL_RenderClear
1040 * http://wiki.libsdl.org/moin.cgi/SDL_RenderPresent
1041 * http://wiki.libsdl.org/moin.cgi/SDL_SetRenderDrawBlendMode
1049 ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE );
1050 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
1053 ret = SDL_RenderClear(renderer);
1054 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderClear, expected: 0, got: %i", ret);
1057 SDL_RenderPresent(renderer);
1060 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE );
1061 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
1063 ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE );
1064 SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
1069 /* ================= Test References ================== */
1071 /* Render test cases */
1073 static const SDLTest_TestCaseReference renderTest1 =
1074 { (SDLTest_TestCaseFp)render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED };
1076 static const SDLTest_TestCaseReference renderTest2 =
1077 { (SDLTest_TestCaseFp)render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED };
1079 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
1080 static const SDLTest_TestCaseReference renderTest3 =
1081 { (SDLTest_TestCaseFp)render_testPrimitivesBlend, "render_testPrimitivesBlend", "Tests rendering primitives with blending", TEST_DISABLED };
1083 static const SDLTest_TestCaseReference renderTest4 =
1084 { (SDLTest_TestCaseFp)render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED };
1086 static const SDLTest_TestCaseReference renderTest5 =
1087 { (SDLTest_TestCaseFp)render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED };
1089 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
1090 static const SDLTest_TestCaseReference renderTest6 =
1091 { (SDLTest_TestCaseFp)render_testBlitAlpha, "render_testBlitAlpha", "Tests blitting with alpha", TEST_DISABLED };
1093 /* TODO: rewrite test case, define new test data and re-enable; current implementation fails */
1094 static const SDLTest_TestCaseReference renderTest7 =
1095 { (SDLTest_TestCaseFp)render_testBlitBlend, "render_testBlitBlend", "Tests blitting with blending", TEST_DISABLED };
1097 /* Sequence of Render test cases */
1098 static const SDLTest_TestCaseReference *renderTests[] = {
1099 &renderTest1, &renderTest2, &renderTest3, &renderTest4, &renderTest5, &renderTest6, &renderTest7, NULL
1102 /* Render test suite (global) */
1103 SDLTest_TestSuiteReference renderTestSuite = {
1107 CleanupDestroyRenderer