2
* Original code: automated SDL platform test written by Edgar Simo "bobbens"
3
* Extended and extensively updated by aschiffler at ferzkopp dot net
6
#include <SDL3/SDL_test.h>
7
#include "testautomation_images.h"
8
#include "testautomation_suites.h"
10
/* ================= Test Case Implementation ================== */
12
#define TESTRENDER_SCREEN_W 80
13
#define TESTRENDER_SCREEN_H 60
16
#define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888
17
#define RENDER_COLOR_CLEAR 0xFF000000
18
#define RENDER_COLOR_GREEN 0xFF00FF00
20
#define ALLOWABLE_ERROR_OPAQUE 0
21
#define ALLOWABLE_ERROR_BLENDED 0
23
#define CHECK_FUNC(FUNC, PARAMS) \
25
int result = FUNC PARAMS; \
27
SDLTest_AssertCheck(result == 0, "Validate result from %s, expected: 0, got: %i, %s", #FUNC, result, SDL_GetError()); \
31
/* Test window and renderer */
32
static SDL_Window *window = NULL;
33
static SDL_Renderer *renderer = NULL;
35
/* Prototypes for helper functions */
37
static int clearScreen(void);
38
static void compare(SDL_Surface *reference, int allowable_error);
39
static void compare2x(SDL_Surface *reference, int allowable_error);
40
static SDL_Texture *loadTestFace(void);
41
static int hasDrawColor(void);
42
static int isSupported(int code);
45
* Create software renderer for tests
47
static void InitCreateRenderer(void *arg)
49
int width = 320, height = 240;
50
const char *renderer_name = NULL;
52
window = SDL_CreateWindow("render_testCreateRenderer", width, height, 0);
53
SDLTest_AssertPass("SDL_CreateWindow()");
54
SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
59
renderer = SDL_CreateRenderer(window, renderer_name);
60
SDLTest_AssertPass("SDL_CreateRenderer()");
61
SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError());
62
if (renderer == NULL) {
63
SDL_DestroyWindow(window);
69
* Destroy renderer for tests
71
static void CleanupDestroyRenderer(void *arg)
74
SDL_DestroyRenderer(renderer);
76
SDLTest_AssertPass("SDL_DestroyRenderer()");
80
SDL_DestroyWindow(window);
82
SDLTest_AssertPass("SDL_DestroyWindow");
87
* Tests call to SDL_GetNumRenderDrivers
89
* \sa SDL_GetNumRenderDrivers
91
static int render_testGetNumRenderDrivers(void *arg)
94
n = SDL_GetNumRenderDrivers();
95
SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n);
96
return TEST_COMPLETED;
100
* Tests the SDL primitives for rendering.
102
* \sa SDL_SetRenderDrawColor
103
* \sa SDL_RenderFillRect
107
static 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
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 13, 73, 200, SDL_ALPHA_OPAQUE))
129
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
131
/* Draw a rectangle. */
136
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE))
137
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
139
/* Draw some points like so:
145
for (y = 0; y < 3; y++) {
146
for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) {
147
ret = SDL_SetRenderDrawColor(renderer, (Uint8)(x * y), (Uint8)(x * y / 2), (Uint8)(x * y / 3), SDL_ALPHA_OPAQUE);
152
ret = SDL_RenderPoint(renderer, (float)x, (float)y);
158
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
159
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", checkFailCount2);
161
/* Draw some lines. */
162
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
163
CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, TESTRENDER_SCREEN_W, 30.0f))
164
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 55, 55, 5, SDL_ALPHA_OPAQUE))
165
CHECK_FUNC(SDL_RenderLine, (renderer, 40.0f, 30.0f, 40.0f, 60.0f))
166
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 5, 105, 105, SDL_ALPHA_OPAQUE))
167
CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 29.0f, 29.0f))
168
CHECK_FUNC(SDL_RenderLine, (renderer, 29.0f, 30.0f, 0.0f, 59.0f))
169
CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 0.0f, 50.0f, 29.0f))
170
CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 59.0f, 50.0f, 30.0f))
172
/* See if it's the same. */
173
referenceSurface = SDLTest_ImagePrimitives();
174
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
177
SDL_RenderPresent(renderer);
180
SDL_DestroySurface(referenceSurface);
181
referenceSurface = NULL;
183
return TEST_COMPLETED;
187
* Tests the SDL primitives for rendering within a viewport.
189
* \sa SDL_SetRenderDrawColor
190
* \sa SDL_RenderFillRect
194
static int render_testPrimitivesWithViewport(void *arg)
197
SDL_Surface *surface;
206
CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
208
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 255, 255, SDL_ALPHA_OPAQUE))
209
CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 1.0f, 1.0f));
215
CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
217
surface = SDL_RenderReadPixels(renderer, NULL);
220
CHECK_FUNC(SDL_ReadSurfacePixel, (surface, 0, 0, &r, &g, &b, &a));
221
SDLTest_AssertCheck(r == 0xFF && g == 0xFF && b == 0xFF && a == 0xFF, "Validate diagonal line drawing with viewport, expected 0xFFFFFFFF, got 0x%.2x%.2x%.2x%.2x", r, g, b, a);
222
SDL_DestroySurface(surface);
224
SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
227
return TEST_COMPLETED;
231
* Tests some blitting routines.
233
* \sa SDL_RenderTexture
234
* \sa SDL_DestroyTexture
236
static int render_testBlit(void *arg)
241
SDL_Surface *referenceSurface = NULL;
249
/* Need drawcolor or just skip test. */
250
SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor)");
252
/* Create face surface. */
253
tface = loadTestFace();
254
SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
259
/* Constant values. */
260
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
263
ni = TESTRENDER_SCREEN_W - tw;
264
nj = TESTRENDER_SCREEN_H - th;
268
for (j = 0; j <= nj; j += 4) {
269
for (i = 0; i <= ni; i += 4) {
273
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
279
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount1);
281
/* See if it's the same */
282
referenceSurface = SDLTest_ImageBlit();
283
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
286
SDL_RenderPresent(renderer);
289
SDL_DestroyTexture(tface);
290
SDL_DestroySurface(referenceSurface);
291
referenceSurface = NULL;
293
return TEST_COMPLETED;
297
* Tests tiled blitting routines.
299
static int render_testBlitTiled(void *arg)
304
SDL_Surface *referenceSurface = NULL;
305
SDL_Surface *referenceSurface2x = NULL;
307
/* Create face surface. */
308
tface = loadTestFace();
309
SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
313
SDL_SetTextureScaleMode(tface, SDL_SCALEMODE_NEAREST); /* So 2x scaling is pixel perfect */
315
/* Tiled blit - 1.0 scale */
323
rect.w = (float)TESTRENDER_SCREEN_W;
324
rect.h = (float)TESTRENDER_SCREEN_H;
325
ret = SDL_RenderTextureTiled(renderer, tface, NULL, 1.0f, &rect);
326
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret);
328
/* See if it's the same */
329
referenceSurface = SDLTest_ImageBlitTiled();
330
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
333
SDL_RenderPresent(renderer);
336
/* Tiled blit - 2.0 scale */
344
rect.w = (float)TESTRENDER_SCREEN_W * 2;
345
rect.h = (float)TESTRENDER_SCREEN_H * 2;
346
ret = SDL_RenderTextureTiled(renderer, tface, NULL, 2.0f, &rect);
347
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret);
349
/* See if it's the same */
350
referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
351
SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
352
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret);
353
compare2x(referenceSurface2x, ALLOWABLE_ERROR_OPAQUE);
356
SDL_RenderPresent(renderer);
360
SDL_DestroyTexture(tface);
361
SDL_DestroySurface(referenceSurface);
362
SDL_DestroySurface(referenceSurface2x);
363
referenceSurface = NULL;
365
return TEST_COMPLETED;
368
static const Uint8 COLOR_SEPARATION = 85;
370
static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height)
379
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
384
rect.w = surface->w - left_width - right_width;
386
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
389
rect.x = surface->w - right_width;
391
rect.w = right_width;
393
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
399
rect.h = surface->h - top_height - bottom_height;
400
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
405
rect.w = surface->w - right_width - left_width;
406
rect.h = surface->h - top_height - bottom_height;
407
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
410
rect.x = surface->w - right_width;
412
rect.w = right_width;
413
rect.h = surface->h - top_height - bottom_height;
414
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
418
rect.y = surface->h - bottom_height;
420
rect.h = bottom_height;
421
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
425
rect.y = surface->h - bottom_height;
426
rect.w = surface->w - left_width - right_width;
427
rect.h = bottom_height;
428
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
431
rect.x = surface->w - right_width;
432
rect.y = surface->h - bottom_height;
433
rect.w = right_width;
434
rect.h = bottom_height;
435
SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
439
* Tests 9-grid blitting.
441
static int render_testBlit9Grid(void *arg)
443
SDL_Surface *referenceSurface = NULL;
444
SDL_Surface *source = NULL;
445
SDL_Texture *texture;
450
/* Create source surface */
451
source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
452
SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
453
for (y = 0; y < 3; ++y) {
454
for (x = 0; x < 3; ++x) {
455
SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
458
texture = SDL_CreateTextureFromSurface(renderer, source);
459
SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
460
ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
461
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_SetTextureScaleMode, expected: 0, got: %i", ret);
463
/* 9-grid blit - 1.0 scale */
465
SDLTest_Log("9-grid blit - 1.0 scale");
466
/* Create reference surface */
467
SDL_DestroySurface(referenceSurface);
468
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
469
SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
470
Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
478
rect.w = (float)TESTRENDER_SCREEN_W;
479
rect.h = (float)TESTRENDER_SCREEN_H;
480
ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect);
481
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret);
483
/* See if it's the same */
484
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
487
SDL_RenderPresent(renderer);
490
/* 9-grid blit - 2.0 scale */
492
SDLTest_Log("9-grid blit - 2.0 scale");
493
/* Create reference surface */
494
SDL_DestroySurface(referenceSurface);
495
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
496
SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
497
Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
505
rect.w = (float)TESTRENDER_SCREEN_W;
506
rect.h = (float)TESTRENDER_SCREEN_H;
507
ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect);
508
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret);
510
/* See if it's the same */
511
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
514
SDL_RenderPresent(renderer);
518
SDL_DestroySurface(source);
519
SDL_DestroyTexture(texture);
521
/* Create complex source surface */
522
source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
523
SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
524
SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
525
SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
526
SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
527
SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
528
SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
530
SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
531
SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
532
SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
533
SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
534
SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
536
SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
537
SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
538
SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
539
SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
540
SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
542
SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
543
SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
544
SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
545
SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
546
SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
548
SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
549
SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
550
SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
551
SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
552
SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
554
texture = SDL_CreateTextureFromSurface(renderer, source);
555
SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
556
ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
557
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_SetTextureScaleMode, expected: 0, got: %i", ret);
559
/* complex 9-grid blit - 1.0 scale */
561
SDLTest_Log("complex 9-grid blit - 1.0 scale");
562
/* Create reference surface */
563
SDL_DestroySurface(referenceSurface);
564
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
565
SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
566
Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
574
rect.w = (float)TESTRENDER_SCREEN_W;
575
rect.h = (float)TESTRENDER_SCREEN_H;
576
ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect);
577
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret);
579
/* See if it's the same */
580
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
583
SDL_RenderPresent(renderer);
586
/* complex 9-grid blit - 2.0 scale */
588
SDLTest_Log("complex 9-grid blit - 2.0 scale");
589
/* Create reference surface */
590
SDL_DestroySurface(referenceSurface);
591
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
592
SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
593
Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
601
rect.w = (float)TESTRENDER_SCREEN_W;
602
rect.h = (float)TESTRENDER_SCREEN_H;
603
ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect);
604
SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret);
606
/* See if it's the same */
607
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
610
SDL_RenderPresent(renderer);
614
SDL_DestroySurface(referenceSurface);
615
SDL_DestroySurface(source);
616
SDL_DestroyTexture(texture);
618
return TEST_COMPLETED;
622
* Blits doing color tests.
624
* \sa SDL_SetTextureColorMod
625
* \sa SDL_RenderTexture
626
* \sa SDL_DestroyTexture
628
static int render_testBlitColor(void *arg)
633
SDL_Surface *referenceSurface = NULL;
642
/* Create face surface. */
643
tface = loadTestFace();
644
SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
649
/* Constant values. */
650
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
653
ni = TESTRENDER_SCREEN_W - (int)tw;
654
nj = TESTRENDER_SCREEN_H - (int)th;
656
/* Test blitting with color mod. */
659
for (j = 0; j <= nj; j += 4) {
660
for (i = 0; i <= ni; i += 4) {
662
ret = SDL_SetTextureColorMod(tface, (Uint8)((255 / nj) * j), (Uint8)((255 / ni) * i), (Uint8)((255 / nj) * j));
670
ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
676
SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
677
SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount2);
679
/* See if it's the same. */
680
referenceSurface = SDLTest_ImageBlitColor();
681
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
684
SDL_RenderPresent(renderer);
687
SDL_DestroyTexture(tface);
688
SDL_DestroySurface(referenceSurface);
689
referenceSurface = NULL;
691
return TEST_COMPLETED;
694
typedef enum TestRenderOperation
699
TEST_RENDER_COPY_XRGB,
700
TEST_RENDER_COPY_ARGB,
701
} TestRenderOperation;
704
* Helper that tests a specific operation and blend mode, -1 for color mod, -2 for alpha mod
706
static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFormat dst_format)
708
/* Allow up to 2 delta from theoretical value to account for rounding error.
709
* We allow 2 rounding errors because the software renderer breaks drawing operations into alpha multiplication and a separate blend operation.
711
const int MAXIMUM_ERROR = 2;
713
SDL_Texture *src = NULL;
716
Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
717
Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
718
Uint8 expectedR, expectedG, expectedB, expectedA;
719
Uint8 actualR, actualG, actualB, actualA;
720
int deltaR, deltaG, deltaB, deltaA;
721
const char *operation = "UNKNOWN";
722
const char *mode_name = "UNKNOWN";
724
/* Create dst surface */
725
dst = SDL_CreateTexture(renderer, dst_format, SDL_TEXTUREACCESS_TARGET, 3, 3);
726
SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
730
if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
731
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
732
ret = SDL_GetTextureBlendMode(dst, &blendMode);
733
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_GetTextureBlendMode(), expected: 0, got: %i", ret);
734
SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode);
737
/* Set as render target */
738
SDL_SetRenderTarget(renderer, dst);
741
if (!SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
744
ret = SDL_SetRenderDrawColor(renderer, dstR, dstG, dstB, dstA);
745
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawColor(), expected: 0, got: %i", ret);
746
ret = SDL_RenderClear(renderer);
747
SDLTest_AssertPass("Call to SDL_RenderClear()");
748
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_RenderClear, expected: 0, got: %i", ret);
750
if (op == TEST_RENDER_COPY_XRGB || op == TEST_RENDER_COPY_ARGB) {
753
/* Create src surface */
754
src = SDL_CreateTexture(renderer, op == TEST_RENDER_COPY_XRGB ? SDL_PIXELFORMAT_RGBX32 : SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 1, 1);
755
SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
761
if (op == TEST_RENDER_COPY_XRGB) {
768
SDL_UpdateTexture(src, NULL, pixels, sizeof(pixels));
770
/* Set blend mode. */
772
ret = SDL_SetTextureBlendMode(src, (SDL_BlendMode)mode);
773
SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
774
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: 0, got: %i", mode, ret);
776
ret = SDL_SetTextureBlendMode(src, SDL_BLENDMODE_BLEND);
777
SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
778
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: 0, got: %i", mode, ret);
782
ret = SDL_SetRenderDrawColor(renderer, srcR, srcG, srcB, srcA);
783
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawColor(), expected: 0, got: %i", ret);
785
/* Set blend mode. */
787
ret = SDL_SetRenderDrawBlendMode(renderer, (SDL_BlendMode)mode);
788
SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
789
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: 0, got: %i", mode, ret);
791
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
792
SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
793
SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: 0, got: %i", mode, ret);
797
/* Test blend mode. */
798
#define FLOAT(X) ((float)X / 255.0f)
801
mode_name = "color modulation";
802
ret = SDL_SetTextureColorMod(src, srcR, srcG, srcB);
803
SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", ret);
804
expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
805
expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
806
expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
807
expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
810
mode_name = "alpha modulation";
811
ret = SDL_SetTextureAlphaMod(src, srcA);
812
SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", ret);
813
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstR) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
814
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstG) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
815
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstB) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
816
expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
818
case SDL_BLENDMODE_NONE:
819
mode_name = "SDL_BLENDMODE_NONE";
823
expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
825
case SDL_BLENDMODE_BLEND:
826
mode_name = "SDL_BLENDMODE_BLEND";
827
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
828
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
829
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
830
expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
832
case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
833
mode_name = "SDL_BLENDMODE_BLEND_PREMULTIPLIED";
834
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
835
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
836
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
837
expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
839
case SDL_BLENDMODE_ADD:
840
mode_name = "SDL_BLENDMODE_ADD";
841
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
842
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
843
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
846
case SDL_BLENDMODE_ADD_PREMULTIPLIED:
847
mode_name = "SDL_BLENDMODE_ADD_PREMULTIPLIED";
848
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
849
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
850
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
853
case SDL_BLENDMODE_MOD:
854
mode_name = "SDL_BLENDMODE_MOD";
855
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
856
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
857
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
860
case SDL_BLENDMODE_MUL:
861
mode_name = "SDL_BLENDMODE_MUL";
862
expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
863
expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
864
expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
868
SDLTest_LogError("Invalid blending mode: %d", mode);
873
case TEST_RENDER_POINT:
874
operation = "render point";
875
ret = SDL_RenderPoint(renderer, 0.0f, 0.0f);
876
SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret);
878
case TEST_RENDER_LINE:
879
operation = "render line";
880
ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 2.0f, 2.0f);
881
SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderLine, expected: 0, got: %i", ret);
883
case TEST_RENDER_RECT:
884
operation = "render rect";
885
ret = SDL_RenderFillRect(renderer, NULL);
886
SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret);
888
case TEST_RENDER_COPY_XRGB:
889
case TEST_RENDER_COPY_ARGB:
890
operation = (op == TEST_RENDER_COPY_XRGB) ? "render XRGB" : "render ARGB";
891
ret = SDL_RenderTexture(renderer, src, NULL, NULL);
892
SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", ret);
895
SDLTest_LogError("Invalid blending operation: %d", op);
899
result = SDL_RenderReadPixels(renderer, NULL);
900
SDL_ReadSurfacePixel(result, 0, 0, &actualR, &actualG, &actualB, &actualA);
901
deltaR = SDL_abs((int)actualR - expectedR);
902
deltaG = SDL_abs((int)actualG - expectedG);
903
deltaB = SDL_abs((int)actualB - expectedB);
904
deltaA = SDL_abs((int)actualA - expectedA);
906
deltaR <= MAXIMUM_ERROR &&
907
deltaG <= MAXIMUM_ERROR &&
908
deltaB <= MAXIMUM_ERROR &&
909
deltaA <= MAXIMUM_ERROR,
910
"Checking %s %s operation results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
911
operation, mode_name,
912
expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
915
SDL_DestroySurface(result);
916
SDL_DestroyTexture(src);
917
SDL_DestroyTexture(dst);
920
static void testBlendMode(int mode)
922
const TestRenderOperation operations[] = {
926
TEST_RENDER_COPY_XRGB,
927
TEST_RENDER_COPY_ARGB
929
const SDL_PixelFormat dst_formats[] = {
930
SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
934
for (i = 0; i < SDL_arraysize(operations); ++i) {
935
for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
936
TestRenderOperation op = operations[i];
939
if (op != TEST_RENDER_COPY_XRGB && op != TEST_RENDER_COPY_ARGB) {
940
/* Unsupported mode for this operation */
944
testBlendModeOperation(op, mode, dst_formats[j]);
950
* Tests render operations with blend modes
952
static int render_testBlendModes(void *arg)
956
testBlendMode(SDL_BLENDMODE_NONE);
957
testBlendMode(SDL_BLENDMODE_BLEND);
958
testBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
959
testBlendMode(SDL_BLENDMODE_ADD);
960
testBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
961
testBlendMode(SDL_BLENDMODE_MOD);
962
testBlendMode(SDL_BLENDMODE_MUL);
964
return TEST_COMPLETED;
970
static int render_testViewport(void *arg)
972
SDL_Surface *referenceSurface;
975
viewport.x = TESTRENDER_SCREEN_W / 3;
976
viewport.y = TESTRENDER_SCREEN_H / 3;
977
viewport.w = TESTRENDER_SCREEN_W / 2;
978
viewport.h = TESTRENDER_SCREEN_H / 2;
980
/* Create expected result */
981
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
982
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
983
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
988
/* Set the viewport and do a fill operation */
989
CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
990
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
991
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
992
CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
994
/* Check to see if final image matches. */
995
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
998
* Verify that clear ignores the viewport
1001
/* Create expected result */
1002
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
1004
/* Clear surface. */
1007
/* Set the viewport and do a clear operation */
1008
CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
1009
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
1010
CHECK_FUNC(SDL_RenderClear, (renderer))
1011
CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
1013
/* Check to see if final image matches. */
1014
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1017
SDL_RenderPresent(renderer);
1019
SDL_DestroySurface(referenceSurface);
1021
return TEST_COMPLETED;
1027
static int render_testClipRect(void *arg)
1029
SDL_Surface *referenceSurface;
1032
cliprect.x = TESTRENDER_SCREEN_W / 3;
1033
cliprect.y = TESTRENDER_SCREEN_H / 3;
1034
cliprect.w = TESTRENDER_SCREEN_W / 2;
1035
cliprect.h = TESTRENDER_SCREEN_H / 2;
1037
/* Create expected result */
1038
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
1039
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
1040
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN))
1042
/* Clear surface. */
1045
/* Set the cliprect and do a fill operation */
1046
CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
1047
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
1048
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
1049
CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
1051
/* Check to see if final image matches. */
1052
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1055
* Verify that clear ignores the cliprect
1058
/* Create expected result */
1059
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
1061
/* Clear surface. */
1064
/* Set the cliprect and do a clear operation */
1065
CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
1066
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
1067
CHECK_FUNC(SDL_RenderClear, (renderer))
1068
CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
1070
/* Check to see if final image matches. */
1071
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1074
SDL_RenderPresent(renderer);
1076
SDL_DestroySurface(referenceSurface);
1078
return TEST_COMPLETED;
1084
static int render_testLogicalSize(void *arg)
1086
SDL_Surface *referenceSurface;
1091
SDL_RendererLogicalPresentation set_presentation_mode;
1092
SDL_ScaleMode set_scale_mode;
1094
const int factor = 2;
1096
viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor;
1097
viewport.y = ((TESTRENDER_SCREEN_H / 4) / factor) * factor;
1098
viewport.w = ((TESTRENDER_SCREEN_W / 2) / factor) * factor;
1099
viewport.h = ((TESTRENDER_SCREEN_H / 2) / factor) * factor;
1101
/* Create expected result */
1102
referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
1103
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
1104
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
1106
/* Clear surface. */
1109
/* Set the logical size and do a fill operation */
1110
CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
1111
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor,
1112
SDL_LOGICAL_PRESENTATION_LETTERBOX,
1113
SDL_SCALEMODE_NEAREST))
1114
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
1115
SDLTest_AssertCheck(
1116
set_w == (w / factor) &&
1117
set_h == (h / factor) &&
1118
set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX &&
1119
set_scale_mode == SDL_SCALEMODE_NEAREST,
1120
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
1121
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
1122
SDLTest_AssertCheck(
1123
set_rect.x == 0.0f &&
1124
set_rect.y == 0.0f &&
1125
set_rect.w == 320.0f &&
1126
set_rect.h == 240.0f,
1127
"Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
1128
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
1129
rect.x = (float)viewport.x / factor;
1130
rect.y = (float)viewport.y / factor;
1131
rect.w = (float)viewport.w / factor;
1132
rect.h = (float)viewport.h / factor;
1133
CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
1134
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
1135
SDL_LOGICAL_PRESENTATION_DISABLED,
1136
SDL_SCALEMODE_NEAREST))
1137
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
1138
SDLTest_AssertCheck(
1141
set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED &&
1142
set_scale_mode == SDL_SCALEMODE_NEAREST,
1143
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
1144
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
1145
SDLTest_AssertCheck(
1146
set_rect.x == 0.0f &&
1147
set_rect.y == 0.0f &&
1148
set_rect.w == 320.0f &&
1149
set_rect.h == 240.0f,
1150
"Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
1152
/* Check to see if final image matches. */
1153
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1155
/* Clear surface. */
1158
/* Set the logical size and viewport and do a fill operation */
1159
CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
1160
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor,
1161
SDL_LOGICAL_PRESENTATION_LETTERBOX,
1162
SDL_SCALEMODE_NEAREST))
1163
viewport.x = (TESTRENDER_SCREEN_W / 4) / factor;
1164
viewport.y = (TESTRENDER_SCREEN_H / 4) / factor;
1165
viewport.w = (TESTRENDER_SCREEN_W / 2) / factor;
1166
viewport.h = (TESTRENDER_SCREEN_H / 2) / factor;
1167
CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
1168
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
1169
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
1170
CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
1171
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
1172
SDL_LOGICAL_PRESENTATION_DISABLED,
1173
SDL_SCALEMODE_NEAREST))
1175
/* Check to see if final image matches. */
1176
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1179
* Test a logical size that isn't the same aspect ratio as the window
1182
viewport.x = (TESTRENDER_SCREEN_W / 4);
1184
viewport.w = TESTRENDER_SCREEN_W;
1185
viewport.h = TESTRENDER_SCREEN_H;
1187
/* Create expected result */
1188
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
1189
CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
1191
/* Clear surface. */
1194
/* Set the logical size and do a fill operation */
1195
CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
1196
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer,
1197
w - 2 * (TESTRENDER_SCREEN_W / 4),
1199
SDL_LOGICAL_PRESENTATION_LETTERBOX,
1200
SDL_SCALEMODE_LINEAR))
1201
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
1202
SDLTest_AssertCheck(
1203
set_w == w - 2 * (TESTRENDER_SCREEN_W / 4) &&
1205
set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX &&
1206
set_scale_mode == SDL_SCALEMODE_LINEAR,
1207
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
1208
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
1209
SDLTest_AssertCheck(
1210
set_rect.x == 20.0f &&
1211
set_rect.y == 0.0f &&
1212
set_rect.w == 280.0f &&
1213
set_rect.h == 240.0f,
1214
"Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
1215
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
1216
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
1217
CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
1218
SDL_LOGICAL_PRESENTATION_DISABLED,
1219
SDL_SCALEMODE_NEAREST))
1220
CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
1221
SDLTest_AssertCheck(
1224
set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED &&
1225
set_scale_mode == SDL_SCALEMODE_NEAREST,
1226
"Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
1227
CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
1228
SDLTest_AssertCheck(
1229
set_rect.x == 0.0f &&
1230
set_rect.y == 0.0f &&
1231
set_rect.w == 320.0f &&
1232
set_rect.h == 240.0f,
1233
"Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
1235
/* Check to see if final image matches. */
1236
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1238
/* Clear surface. */
1242
SDL_RenderPresent(renderer);
1244
SDL_DestroySurface(referenceSurface);
1246
return TEST_COMPLETED;
1249
/* Helper functions */
1252
* Checks to see if functionality is supported. Helper function.
1255
isSupported(int code)
1261
* Test to see if we can vary the draw color. Helper function.
1263
* \sa SDL_SetRenderDrawColor
1264
* \sa SDL_GetRenderDrawColor
1275
ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100);
1276
if (!isSupported(ret)) {
1279
ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
1280
if (!isSupported(ret)) {
1284
/* Restore natural. */
1285
ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
1286
if (!isSupported(ret)) {
1290
/* Something failed, consider not available. */
1294
/* Not set properly, consider failed. */
1295
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) {
1302
* Loads the test image 'Face' as texture. Helper function.
1304
* \sa SDL_CreateTextureFromSurface
1312
face = SDLTest_ImageFace();
1317
tface = SDL_CreateTextureFromSurface(renderer, face);
1319
SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
1322
SDL_DestroySurface(face);
1328
* Compares screen pixels with image pixels. Helper function.
1330
* \param referenceSurface Image to compare against.
1331
* \param allowable_error allowed difference from the reference image
1333
* \sa SDL_RenderReadPixels
1334
* \sa SDL_CreateSurfaceFrom
1335
* \sa SDL_DestroySurface
1337
static void compare(SDL_Surface *referenceSurface, int allowable_error)
1341
SDL_Surface *surface, *testSurface;
1343
/* Explicitly specify the rect in case the window isn't the expected size... */
1346
rect.w = TESTRENDER_SCREEN_W;
1347
rect.h = TESTRENDER_SCREEN_H;
1349
surface = SDL_RenderReadPixels(renderer, &rect);
1351
SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
1355
testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
1356
SDL_DestroySurface(surface);
1358
SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
1362
/* Compare surface. */
1363
ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
1364
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
1367
SDL_DestroySurface(testSurface);
1369
static void compare2x(SDL_Surface *referenceSurface, int allowable_error)
1373
SDL_Surface *surface, *testSurface;
1375
/* Explicitly specify the rect in case the window isn't the expected size... */
1378
rect.w = TESTRENDER_SCREEN_W * 2;
1379
rect.h = TESTRENDER_SCREEN_H * 2;
1381
surface = SDL_RenderReadPixels(renderer, &rect);
1383
SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
1387
testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
1388
SDL_DestroySurface(surface);
1390
SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
1394
/* Compare surface. */
1395
ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
1396
SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
1399
SDL_DestroySurface(testSurface);
1403
* Clears the screen. Helper function.
1405
* \sa SDL_SetRenderDrawColor
1406
* \sa SDL_RenderClear
1407
* \sa SDL_RenderPresent
1408
* \sa SDL_SetRenderDrawBlendMode
1416
SDL_RenderPresent(renderer);
1419
ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
1420
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
1423
ret = SDL_RenderClear(renderer);
1424
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderClear, expected: 0, got: %i", ret);
1427
ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
1428
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
1430
ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
1431
SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
1437
* Tests geometry UV wrapping
1439
static int render_testUVWrapping(void *arg)
1441
SDL_Vertex vertices[6];
1442
SDL_Vertex *verts = vertices;
1443
SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
1446
float min_U = -0.5f;
1448
float min_V = -0.5f;
1451
SDL_Surface *referenceSurface = NULL;
1453
/* Clear surface. */
1456
/* Create face surface. */
1457
tface = loadTestFace();
1458
SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
1459
if (tface == NULL) {
1460
return TEST_ABORTED;
1463
CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
1466
rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
1467
rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
1475
* Draw sprite2 as triangles that can be recombined as rect by software renderer
1479
verts->position.x = rect.x;
1480
verts->position.y = rect.y;
1481
verts->color = color;
1482
verts->tex_coord.x = min_U;
1483
verts->tex_coord.y = min_V;
1486
verts->position.x = rect.x + rect.w;
1487
verts->position.y = rect.y;
1488
verts->color = color;
1489
verts->tex_coord.x = max_U;
1490
verts->tex_coord.y = min_V;
1493
verts->position.x = rect.x + rect.w;
1494
verts->position.y = rect.y + rect.h;
1495
verts->color = color;
1496
verts->tex_coord.x = max_U;
1497
verts->tex_coord.y = max_V;
1500
verts->position.x = rect.x;
1501
verts->position.y = rect.y;
1502
verts->color = color;
1503
verts->tex_coord.x = min_U;
1504
verts->tex_coord.y = min_V;
1507
verts->position.x = rect.x + rect.w;
1508
verts->position.y = rect.y + rect.h;
1509
verts->color = color;
1510
verts->tex_coord.x = max_U;
1511
verts->tex_coord.y = max_V;
1514
verts->position.x = rect.x;
1515
verts->position.y = rect.y + rect.h;
1516
verts->color = color;
1517
verts->tex_coord.x = min_U;
1518
verts->tex_coord.y = max_V;
1521
/* Blit sprites as triangles onto the screen */
1522
SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0);
1524
/* See if it's the same */
1525
referenceSurface = SDLTest_ImageWrappingSprite();
1526
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
1529
SDL_RenderPresent(renderer);
1532
SDL_DestroyTexture(tface);
1533
SDL_DestroySurface(referenceSurface);
1534
referenceSurface = NULL;
1536
return TEST_COMPLETED;
1539
/* ================= Test References ================== */
1541
/* Render test cases */
1542
static const SDLTest_TestCaseReference renderTestGetNumRenderDrivers = {
1543
(SDLTest_TestCaseFp)render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED
1546
static const SDLTest_TestCaseReference renderTestPrimitives = {
1547
(SDLTest_TestCaseFp)render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED
1550
static const SDLTest_TestCaseReference renderTestPrimitivesWithViewport = {
1551
(SDLTest_TestCaseFp)render_testPrimitivesWithViewport, "render_testPrimitivesWithViewport", "Tests rendering primitives within a viewport", TEST_ENABLED
1554
static const SDLTest_TestCaseReference renderTestBlit = {
1555
(SDLTest_TestCaseFp)render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED
1558
static const SDLTest_TestCaseReference renderTestBlitTiled = {
1559
(SDLTest_TestCaseFp)render_testBlitTiled, "render_testBlitTiled", "Tests tiled blitting", TEST_ENABLED
1562
static const SDLTest_TestCaseReference renderTestBlit9Grid = {
1563
(SDLTest_TestCaseFp)render_testBlit9Grid, "render_testBlit9Grid", "Tests 9-grid blitting", TEST_ENABLED
1566
static const SDLTest_TestCaseReference renderTestBlitColor = {
1567
(SDLTest_TestCaseFp)render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED
1570
static const SDLTest_TestCaseReference renderTestBlendModes = {
1571
(SDLTest_TestCaseFp)render_testBlendModes, "render_testBlendModes", "Tests rendering blend modes", TEST_ENABLED
1574
static const SDLTest_TestCaseReference renderTestViewport = {
1575
(SDLTest_TestCaseFp)render_testViewport, "render_testViewport", "Tests viewport", TEST_ENABLED
1578
static const SDLTest_TestCaseReference renderTestClipRect = {
1579
(SDLTest_TestCaseFp)render_testClipRect, "render_testClipRect", "Tests clip rect", TEST_ENABLED
1582
static const SDLTest_TestCaseReference renderTestLogicalSize = {
1583
(SDLTest_TestCaseFp)render_testLogicalSize, "render_testLogicalSize", "Tests logical size", TEST_ENABLED
1586
static const SDLTest_TestCaseReference renderTestUVWrapping = {
1587
(SDLTest_TestCaseFp)render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED
1590
/* Sequence of Render test cases */
1591
static const SDLTest_TestCaseReference *renderTests[] = {
1592
&renderTestGetNumRenderDrivers,
1593
&renderTestPrimitives,
1594
&renderTestPrimitivesWithViewport,
1596
&renderTestBlitTiled,
1597
&renderTestBlit9Grid,
1598
&renderTestBlitColor,
1599
&renderTestBlendModes,
1600
&renderTestViewport,
1601
&renderTestClipRect,
1602
&renderTestLogicalSize,
1603
&renderTestUVWrapping,
1607
/* Render test suite (global) */
1608
SDLTest_TestSuiteReference renderTestSuite = {
1612
CleanupDestroyRenderer