Atlas - testautomation_render.c
Home / ext / SDL / test Lines: 1 | Size: 92591 bytes [Download] [Show on GitHub] [Search similar files] [Raw] [Raw (proxy)][FILE BEGIN]1/** 2 * Original code: automated SDL platform test written by Edgar Simo "bobbens" 3 * Extended and extensively updated by aschiffler at ferzkopp dot net 4 */ 5#include <SDL3/SDL.h> 6#include <SDL3/SDL_test.h> 7#include "testautomation_images.h" 8#include "testautomation_suites.h" 9 10/* ================= Test Case Implementation ================== */ 11 12#define TESTRENDER_WINDOW_W 320 13#define TESTRENDER_WINDOW_H 240 14#define TESTRENDER_SCREEN_W 80 15#define TESTRENDER_SCREEN_H 60 16 17 18#define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888 19#define RENDER_COLOR_CLEAR 0xFF000000 20#define RENDER_COLOR_GREEN 0xFF00FF00 21 22#define ALLOWABLE_ERROR_OPAQUE 0 23#define ALLOWABLE_ERROR_BLENDED 0 24 25#define CHECK_FUNC(FUNC, PARAMS) \ 26{ \ 27 bool result = FUNC PARAMS; \ 28 if (!result) { \ 29 SDLTest_AssertCheck(result, "Validate result from %s, expected: true, got: false, %s", #FUNC, SDL_GetError()); \ 30 } \ 31} 32 33/* Test window and renderer */ 34static SDL_Window *window = NULL; 35static SDL_Renderer *renderer = NULL; 36 37/* Prototypes for helper functions */ 38 39static int clearScreen(void); 40static void compare(SDL_Surface *reference, int allowable_error); 41static void compare2x(SDL_Surface *reference, int allowable_error); 42static SDL_Texture *loadTestFace(void); 43static bool isSupported(int code); 44static bool hasDrawColor(void); 45 46/** 47 * Create software renderer for tests 48 */ 49static void SDLCALL InitCreateRenderer(void **arg) 50{ 51 const char *renderer_name = NULL; 52 renderer = NULL; 53 window = SDL_CreateWindow("render_testCreateRenderer", TESTRENDER_WINDOW_W, TESTRENDER_WINDOW_H, 0); 54 SDLTest_AssertPass("SDL_CreateWindow()"); 55 SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result"); 56 if (window == NULL) { 57 return; 58 } 59 60 renderer = SDL_CreateRenderer(window, renderer_name); 61 SDLTest_AssertPass("SDL_CreateRenderer()"); 62 SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError()); 63 if (renderer == NULL) { 64 SDL_DestroyWindow(window); 65 return; 66 } 67} 68 69/** 70 * Destroy renderer for tests 71 */ 72static void SDLCALL CleanupDestroyRenderer(void *arg) 73{ 74 if (renderer) { 75 SDL_DestroyRenderer(renderer); 76 renderer = NULL; 77 SDLTest_AssertPass("SDL_DestroyRenderer()"); 78 } 79 80 if (window) { 81 SDL_DestroyWindow(window); 82 window = NULL; 83 SDLTest_AssertPass("SDL_DestroyWindow"); 84 } 85} 86 87/** 88 * Tests call to SDL_GetNumRenderDrivers 89 * 90 * \sa SDL_GetNumRenderDrivers 91 */ 92static int SDLCALL render_testGetNumRenderDrivers(void *arg) 93{ 94 int n; 95 n = SDL_GetNumRenderDrivers(); 96 SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n); 97 return TEST_COMPLETED; 98} 99 100/** 101 * Tests the SDL primitives for rendering. 102 * 103 * \sa SDL_SetRenderDrawColor 104 * \sa SDL_RenderFillRect 105 * \sa SDL_RenderLine 106 * 107 */ 108static int SDLCALL render_testPrimitives(void *arg) 109{ 110 int ret; 111 int x, y; 112 SDL_FRect rect; 113 SDL_Surface *referenceSurface = NULL; 114 int checkFailCount1; 115 int checkFailCount2; 116 117 /* Clear surface. */ 118 clearScreen(); 119 120 /* Need drawcolor or just skip test. */ 121 SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor"); 122 123 /* Draw a rectangle. */ 124 rect.x = 40.0f; 125 rect.y = 0.0f; 126 rect.w = 40.0f; 127 rect.h = 80.0f; 128 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 13, 73, 200, SDL_ALPHA_OPAQUE)) 129 CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect)) 130 131 /* Draw a rectangle with negative width and height. */ 132 rect.x = 10.0f + 60.0f; 133 rect.y = 10.0f + 40.0f; 134 rect.w = -60.0f; 135 rect.h = -40.0f; 136 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE)) 137 CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect)) 138 139 /* Draw a rectangle with zero width and height. */ 140 rect.x = 10.0f; 141 rect.y = 10.0f; 142 rect.w = 0.0f; 143 rect.h = 0.0f; 144 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 0, 0, SDL_ALPHA_OPAQUE)) 145 CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect)) 146 147 /* Draw some points like so: 148 * X.X.X.X.. 149 * .X.X.X.X. 150 * X.X.X.X.. */ 151 checkFailCount1 = 0; 152 checkFailCount2 = 0; 153 for (y = 0; y < 3; y++) { 154 for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) { 155 ret = SDL_SetRenderDrawColor(renderer, (Uint8)(x * y), (Uint8)(x * y / 2), (Uint8)(x * y / 3), SDL_ALPHA_OPAQUE); 156 if (!ret) { 157 checkFailCount1++; 158 } 159 160 ret = SDL_RenderPoint(renderer, (float)x, (float)y); 161 if (!ret) { 162 checkFailCount2++; 163 } 164 } 165 } 166 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1); 167 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", checkFailCount2); 168 169 /* Draw some lines. */ 170 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 171 CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, TESTRENDER_SCREEN_W, 30.0f)) 172 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 55, 55, 5, SDL_ALPHA_OPAQUE)) 173 CHECK_FUNC(SDL_RenderLine, (renderer, 40.0f, 30.0f, 40.0f, 60.0f)) 174 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 5, 105, 105, SDL_ALPHA_OPAQUE)) 175 CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 29.0f, 29.0f)) 176 CHECK_FUNC(SDL_RenderLine, (renderer, 29.0f, 30.0f, 0.0f, 59.0f)) 177 CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 0.0f, 50.0f, 29.0f)) 178 CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 59.0f, 50.0f, 30.0f)) 179 180 /* See if it's the same. */ 181 referenceSurface = SDLTest_ImagePrimitives(); 182 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 183 184 /* Make current */ 185 SDL_RenderPresent(renderer); 186 187 /* Clean up. */ 188 SDL_DestroySurface(referenceSurface); 189 referenceSurface = NULL; 190 191 return TEST_COMPLETED; 192} 193 194/** 195 * Tests the SDL primitives for rendering within a viewport. 196 * 197 * \sa SDL_SetRenderDrawColor 198 * \sa SDL_RenderFillRect 199 * \sa SDL_RenderLine 200 * 201 */ 202static int SDLCALL render_testPrimitivesWithViewport(void *arg) 203{ 204 SDL_Rect viewport; 205 SDL_Surface *surface; 206 207 /* Clear surface. */ 208 clearScreen(); 209 210 viewport.x = 2; 211 viewport.y = 2; 212 viewport.w = 2; 213 viewport.h = 2; 214 CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport)); 215 216 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 255, 255, SDL_ALPHA_OPAQUE)) 217 CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 1.0f, 1.0f)); 218 219 viewport.x = 3; 220 viewport.y = 3; 221 viewport.w = 1; 222 viewport.h = 1; 223 CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport)); 224 225 surface = SDL_RenderReadPixels(renderer, NULL); 226 if (surface) { 227 Uint8 r, g, b, a; 228 CHECK_FUNC(SDL_ReadSurfacePixel, (surface, 0, 0, &r, &g, &b, &a)); 229 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); 230 SDL_DestroySurface(surface); 231 } else { 232 SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError()); 233 } 234 235 return TEST_COMPLETED; 236} 237 238/** 239 * Tests some blitting routines. 240 * 241 * \sa SDL_RenderTexture 242 * \sa SDL_DestroyTexture 243 */ 244static int SDLCALL render_testBlit(void *arg) 245{ 246 int ret; 247 SDL_FRect rect; 248 SDL_Texture *tface; 249 SDL_Surface *referenceSurface = NULL; 250 int i, j, ni, nj; 251 int checkFailCount1; 252 253 /* Clear surface. */ 254 clearScreen(); 255 256 /* Need drawcolor or just skip test. */ 257 SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor)"); 258 259 /* Create face surface. */ 260 tface = loadTestFace(); 261 SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result"); 262 if (tface == NULL) { 263 return TEST_ABORTED; 264 } 265 266 /* Constant values. */ 267 rect.w = (float)tface->w; 268 rect.h = (float)tface->h; 269 ni = TESTRENDER_SCREEN_W - tface->w; 270 nj = TESTRENDER_SCREEN_H - tface->h; 271 272 /* Loop blit. */ 273 checkFailCount1 = 0; 274 for (j = 0; j <= nj; j += 4) { 275 for (i = 0; i <= ni; i += 4) { 276 /* Blitting. */ 277 rect.x = (float)i; 278 rect.y = (float)j; 279 ret = SDL_RenderTexture(renderer, tface, NULL, &rect); 280 if (!ret) { 281 checkFailCount1++; 282 } 283 } 284 } 285 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount1); 286 287 /* See if it's the same */ 288 referenceSurface = SDLTest_ImageBlit(); 289 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 290 291 /* Make current */ 292 SDL_RenderPresent(renderer); 293 294 /* Clean up. */ 295 SDL_DestroyTexture(tface); 296 SDL_DestroySurface(referenceSurface); 297 referenceSurface = NULL; 298 299 return TEST_COMPLETED; 300} 301 302/** 303 * Tests tiled blitting routines. 304 */ 305static int SDLCALL render_testBlitTiled(void *arg) 306{ 307 int ret; 308 SDL_FRect rect; 309 SDL_Texture *tface; 310 SDL_Surface *referenceSurface = NULL; 311 SDL_Surface *referenceSurface2x = NULL; 312 313 /* Create face surface. */ 314 tface = loadTestFace(); 315 SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result"); 316 if (tface == NULL) { 317 return TEST_ABORTED; 318 } 319 SDL_SetTextureScaleMode(tface, SDL_SCALEMODE_NEAREST); /* So 2x scaling is pixel perfect */ 320 321 /* Tiled blit - 1.0 scale */ 322 { 323 /* Clear surface. */ 324 clearScreen(); 325 326 /* Tiled blit. */ 327 rect.x = 0.0f; 328 rect.y = 0.0f; 329 rect.w = (float)TESTRENDER_SCREEN_W; 330 rect.h = (float)TESTRENDER_SCREEN_H; 331 ret = SDL_RenderTextureTiled(renderer, tface, NULL, 1.0f, &rect); 332 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i", ret); 333 334 /* See if it's the same */ 335 referenceSurface = SDLTest_ImageBlitTiled(); 336 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 337 338 /* Make current */ 339 SDL_RenderPresent(renderer); 340 } 341 342 /* Tiled blit - 2.0 scale */ 343 { 344 /* Clear surface. */ 345 clearScreen(); 346 347 /* Tiled blit. */ 348 rect.x = 0.0f; 349 rect.y = 0.0f; 350 rect.w = (float)TESTRENDER_SCREEN_W * 2; 351 rect.h = (float)TESTRENDER_SCREEN_H * 2; 352 ret = SDL_RenderTextureTiled(renderer, tface, NULL, 2.0f, &rect); 353 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i", ret); 354 355 /* See if it's the same */ 356 referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format); 357 SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST); 358 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret); 359 compare2x(referenceSurface2x, ALLOWABLE_ERROR_OPAQUE); 360 361 /* Make current */ 362 SDL_RenderPresent(renderer); 363 } 364 365 /* Clean up. */ 366 SDL_DestroyTexture(tface); 367 SDL_DestroySurface(referenceSurface); 368 SDL_DestroySurface(referenceSurface2x); 369 referenceSurface = NULL; 370 371 return TEST_COMPLETED; 372} 373 374static const Uint8 COLOR_SEPARATION = 85; 375 376static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height) 377{ 378 SDL_Rect rect; 379 380 // Upper left 381 rect.x = 0; 382 rect.y = 0; 383 rect.w = left_width; 384 rect.h = top_height; 385 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0)); 386 387 // Top 388 rect.x = left_width; 389 rect.y = 0; 390 rect.w = surface->w - left_width - right_width; 391 rect.h = top_height; 392 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0)); 393 394 // Upper right 395 rect.x = surface->w - right_width; 396 rect.y = 0; 397 rect.w = right_width; 398 rect.h = top_height; 399 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0)); 400 401 // Left 402 rect.x = 0; 403 rect.y = top_height; 404 rect.w = left_width; 405 rect.h = surface->h - top_height - bottom_height; 406 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0)); 407 408 // Center 409 rect.x = left_width; 410 rect.y = top_height; 411 rect.w = surface->w - right_width - left_width; 412 rect.h = surface->h - top_height - bottom_height; 413 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0)); 414 415 // Right 416 rect.x = surface->w - right_width; 417 rect.y = top_height; 418 rect.w = right_width; 419 rect.h = surface->h - top_height - bottom_height; 420 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0)); 421 422 // Lower left 423 rect.x = 0; 424 rect.y = surface->h - bottom_height; 425 rect.w = left_width; 426 rect.h = bottom_height; 427 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0)); 428 429 // Bottom 430 rect.x = left_width; 431 rect.y = surface->h - bottom_height; 432 rect.w = surface->w - left_width - right_width; 433 rect.h = bottom_height; 434 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0)); 435 436 // Lower right 437 rect.x = surface->w - right_width; 438 rect.y = surface->h - bottom_height; 439 rect.w = right_width; 440 rect.h = bottom_height; 441 SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0)); 442} 443 444/** 445 * Tests 9-grid blitting. 446 */ 447static int SDLCALL render_testBlit9Grid(void *arg) 448{ 449 SDL_Surface *referenceSurface = NULL; 450 SDL_Surface *source = NULL; 451 SDL_Texture *texture; 452 int x, y; 453 SDL_FRect rect; 454 int ret = 0; 455 456 /* Create source surface */ 457 source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32); 458 SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL"); 459 for (y = 0; y < 3; ++y) { 460 for (x = 0; x < 3; ++x) { 461 SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255); 462 } 463 } 464 texture = SDL_CreateTextureFromSurface(renderer, source); 465 SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL"); 466 ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); 467 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret); 468 469 /* 9-grid blit - 1.0 scale */ 470 { 471 SDLTest_Log("9-grid blit - 1.0 scale"); 472 /* Create reference surface */ 473 SDL_DestroySurface(referenceSurface); 474 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 475 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 476 Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1); 477 478 /* Clear surface. */ 479 clearScreen(); 480 481 /* Tiled blit. */ 482 rect.x = 0.0f; 483 rect.y = 0.0f; 484 rect.w = (float)TESTRENDER_SCREEN_W; 485 rect.h = (float)TESTRENDER_SCREEN_H; 486 ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect); 487 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret); 488 489 /* See if it's the same */ 490 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 491 492 /* Make current */ 493 SDL_RenderPresent(renderer); 494 } 495 496 /* 9-grid blit - 2.0 scale */ 497 { 498 SDLTest_Log("9-grid blit - 2.0 scale"); 499 /* Create reference surface */ 500 SDL_DestroySurface(referenceSurface); 501 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 502 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 503 Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2); 504 505 /* Clear surface. */ 506 clearScreen(); 507 508 /* Tiled blit. */ 509 rect.x = 0.0f; 510 rect.y = 0.0f; 511 rect.w = (float)TESTRENDER_SCREEN_W; 512 rect.h = (float)TESTRENDER_SCREEN_H; 513 ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect); 514 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret); 515 516 /* See if it's the same */ 517 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 518 519 /* Make current */ 520 SDL_RenderPresent(renderer); 521 } 522 523 /* Clean up. */ 524 SDL_DestroySurface(source); 525 SDL_DestroyTexture(texture); 526 527 /* Create complex source surface */ 528 source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32); 529 SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL"); 530 SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 531 SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 532 SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 533 SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 534 SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 535 536 SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 537 SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 538 SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 539 SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 540 SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 541 542 SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 543 SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 544 SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 545 SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 546 SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 547 548 SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 549 SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 550 SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 551 SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 552 SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 553 554 SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 555 SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 556 SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 557 SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 558 SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 559 560 texture = SDL_CreateTextureFromSurface(renderer, source); 561 SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL"); 562 ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); 563 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret); 564 565 /* complex 9-grid blit - 1.0 scale */ 566 { 567 SDLTest_Log("complex 9-grid blit - 1.0 scale"); 568 /* Create reference surface */ 569 SDL_DestroySurface(referenceSurface); 570 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 571 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 572 Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2); 573 574 /* Clear surface. */ 575 clearScreen(); 576 577 /* Tiled blit. */ 578 rect.x = 0.0f; 579 rect.y = 0.0f; 580 rect.w = (float)TESTRENDER_SCREEN_W; 581 rect.h = (float)TESTRENDER_SCREEN_H; 582 ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect); 583 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret); 584 585 /* See if it's the same */ 586 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 587 588 /* Make current */ 589 SDL_RenderPresent(renderer); 590 } 591 592 /* complex 9-grid blit - 2.0 scale */ 593 { 594 SDLTest_Log("complex 9-grid blit - 2.0 scale"); 595 /* Create reference surface */ 596 SDL_DestroySurface(referenceSurface); 597 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 598 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 599 Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4); 600 601 /* Clear surface. */ 602 clearScreen(); 603 604 /* Tiled blit. */ 605 rect.x = 0.0f; 606 rect.y = 0.0f; 607 rect.w = (float)TESTRENDER_SCREEN_W; 608 rect.h = (float)TESTRENDER_SCREEN_H; 609 ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect); 610 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret); 611 612 /* See if it's the same */ 613 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 614 615 /* Make current */ 616 SDL_RenderPresent(renderer); 617 } 618 619 /* Clean up. */ 620 SDL_DestroySurface(referenceSurface); 621 SDL_DestroySurface(source); 622 SDL_DestroyTexture(texture); 623 624 return TEST_COMPLETED; 625} 626 627/** 628 * Tests tiled 9-grid blitting. 629 */ 630static int SDLCALL render_testBlit9GridTiled(void *arg) 631{ 632 SDL_Surface *referenceSurface = NULL; 633 SDL_Surface *source = NULL; 634 SDL_Texture *texture; 635 int x, y; 636 SDL_FRect rect; 637 int ret = 0; 638 639 /* Create source surface */ 640 source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32); 641 SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL"); 642 for (y = 0; y < 3; ++y) { 643 for (x = 0; x < 3; ++x) { 644 SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255); 645 } 646 } 647 texture = SDL_CreateTextureFromSurface(renderer, source); 648 SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL"); 649 ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); 650 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret); 651 652 /* Tiled 9-grid blit - 1.0 scale */ 653 { 654 SDLTest_Log("tiled 9-grid blit - 1.0 scale"); 655 /* Create reference surface */ 656 SDL_DestroySurface(referenceSurface); 657 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 658 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 659 Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1); 660 661 /* Clear surface. */ 662 clearScreen(); 663 664 /* Tiled blit. */ 665 rect.x = 0.0f; 666 rect.y = 0.0f; 667 rect.w = (float)TESTRENDER_SCREEN_W; 668 rect.h = (float)TESTRENDER_SCREEN_H; 669 ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect, 1.0f); 670 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret); 671 672 /* See if it's the same */ 673 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 674 675 /* Make current */ 676 SDL_RenderPresent(renderer); 677 } 678 679 /* Tiled 9-grid blit - 2.0 scale */ 680 { 681 SDLTest_Log("tiled 9-grid blit - 2.0 scale"); 682 /* Create reference surface */ 683 SDL_DestroySurface(referenceSurface); 684 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 685 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 686 Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2); 687 688 /* Clear surface. */ 689 clearScreen(); 690 691 /* Tiled blit. */ 692 rect.x = 0.0f; 693 rect.y = 0.0f; 694 rect.w = (float)TESTRENDER_SCREEN_W; 695 rect.h = (float)TESTRENDER_SCREEN_H; 696 ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect, 2.0f); 697 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret); 698 699 /* See if it's the same */ 700 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 701 702 /* Make current */ 703 SDL_RenderPresent(renderer); 704 } 705 706 /* Clean up. */ 707 SDL_DestroySurface(source); 708 SDL_DestroyTexture(texture); 709 710 /* Create complex source surface */ 711 source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32); 712 SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL"); 713 SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 714 SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 715 SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 716 SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 717 SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255); 718 719 SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 720 SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 721 SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 722 SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 723 SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 724 725 SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 726 SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 727 SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 728 SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 729 SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255); 730 731 SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 732 SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 733 SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 734 SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 735 SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 736 737 SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 738 SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 739 SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 740 SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 741 SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255); 742 743 texture = SDL_CreateTextureFromSurface(renderer, source); 744 SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL"); 745 ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); 746 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret); 747 748 /* complex tiled 9-grid blit - 1.0 scale */ 749 { 750 SDLTest_Log("complex tiled 9-grid blit - 1.0 scale"); 751 /* Create reference surface */ 752 SDL_DestroySurface(referenceSurface); 753 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 754 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 755 Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2); 756 757 /* Clear surface. */ 758 clearScreen(); 759 760 /* Tiled blit. */ 761 rect.x = 0.0f; 762 rect.y = 0.0f; 763 rect.w = (float)TESTRENDER_SCREEN_W; 764 rect.h = (float)TESTRENDER_SCREEN_H; 765 ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect, 1.0f); 766 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret); 767 768 /* See if it's the same */ 769 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 770 771 /* Make current */ 772 SDL_RenderPresent(renderer); 773 } 774 775 /* complex tiled 9-grid blit - 2.0 scale */ 776 { 777 SDLTest_Log("complex tiled 9-grid blit - 2.0 scale"); 778 /* Create reference surface */ 779 SDL_DestroySurface(referenceSurface); 780 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32); 781 SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL"); 782 Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4); 783 784 /* Clear surface. */ 785 clearScreen(); 786 787 /* Tiled blit. */ 788 rect.x = 0.0f; 789 rect.y = 0.0f; 790 rect.w = (float)TESTRENDER_SCREEN_W; 791 rect.h = (float)TESTRENDER_SCREEN_H; 792 ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect, 2.0f); 793 SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret); 794 795 /* See if it's the same */ 796 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 797 798 /* Make current */ 799 SDL_RenderPresent(renderer); 800 } 801 802 /* Clean up. */ 803 SDL_DestroySurface(referenceSurface); 804 SDL_DestroySurface(source); 805 SDL_DestroyTexture(texture); 806 807 return TEST_COMPLETED; 808} 809 810/** 811 * Blits doing color tests. 812 * 813 * \sa SDL_SetTextureColorMod 814 * \sa SDL_RenderTexture 815 * \sa SDL_DestroyTexture 816 */ 817static int SDLCALL render_testBlitColor(void *arg) 818{ 819 int ret; 820 SDL_FRect rect; 821 SDL_Texture *tface; 822 SDL_Surface *referenceSurface = NULL; 823 int i, j, ni, nj; 824 int checkFailCount1; 825 int checkFailCount2; 826 827 /* Clear surface. */ 828 clearScreen(); 829 830 /* Create face surface. */ 831 tface = loadTestFace(); 832 SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result"); 833 if (tface == NULL) { 834 return TEST_ABORTED; 835 } 836 837 /* Constant values. */ 838 rect.w = (float)tface->w; 839 rect.h = (float)tface->h; 840 ni = TESTRENDER_SCREEN_W - tface->w; 841 nj = TESTRENDER_SCREEN_H - tface->h; 842 843 /* Test blitting with color mod. */ 844 checkFailCount1 = 0; 845 checkFailCount2 = 0; 846 for (j = 0; j <= nj; j += 4) { 847 for (i = 0; i <= ni; i += 4) { 848 /* Set color mod. */ 849 ret = SDL_SetTextureColorMod(tface, (Uint8)((255 / nj) * j), (Uint8)((255 / ni) * i), (Uint8)((255 / nj) * j)); 850 if (!ret) { 851 checkFailCount1++; 852 } 853 854 /* Blitting. */ 855 rect.x = (float)i; 856 rect.y = (float)j; 857 ret = SDL_RenderTexture(renderer, tface, NULL, &rect); 858 if (!ret) { 859 checkFailCount2++; 860 } 861 } 862 } 863 SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1); 864 SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount2); 865 866 /* See if it's the same. */ 867 referenceSurface = SDLTest_ImageBlitColor(); 868 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 869 870 /* Make current */ 871 SDL_RenderPresent(renderer); 872 873 /* Clean up. */ 874 SDL_DestroyTexture(tface); 875 SDL_DestroySurface(referenceSurface); 876 referenceSurface = NULL; 877 878 return TEST_COMPLETED; 879} 880 881typedef enum TestRenderOperation 882{ 883 TEST_RENDER_POINT, 884 TEST_RENDER_LINE, 885 TEST_RENDER_RECT, 886 TEST_RENDER_COPY_XRGB, 887 TEST_RENDER_COPY_ARGB, 888} TestRenderOperation; 889 890/** 891 * Helper that tests a specific operation and blend mode, -1 for color mod, -2 for alpha mod 892 */ 893static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFormat dst_format) 894{ 895 /* Allow up to 2 delta from theoretical value to account for rounding error. 896 * We allow 2 rounding errors because the software renderer breaks drawing operations into alpha multiplication and a separate blend operation. 897 */ 898 const int MAXIMUM_ERROR = 2; 899 int ret; 900 SDL_Texture *src = NULL; 901 SDL_Texture *dst; 902 SDL_Surface *result; 903 Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100; 904 Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128; 905 Uint8 expectedR, expectedG, expectedB, expectedA; 906 Uint8 actualR, actualG, actualB, actualA; 907 int deltaR, deltaG, deltaB, deltaA; 908 const char *operation = "UNKNOWN"; 909 const char *mode_name = "UNKNOWN"; 910 911 /* Create dst surface */ 912 dst = SDL_CreateTexture(renderer, dst_format, SDL_TEXTUREACCESS_TARGET, 3, 3); 913 SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL"); 914 if (dst == NULL) { 915 return; 916 } 917 if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) { 918 SDL_BlendMode blendMode = SDL_BLENDMODE_NONE; 919 ret = SDL_GetTextureBlendMode(dst, &blendMode); 920 SDLTest_AssertCheck(ret == true, "Verify result from SDL_GetTextureBlendMode(), expected: true, got: %i", ret); 921 SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode); 922 } 923 924 /* Set as render target */ 925 SDL_SetRenderTarget(renderer, dst); 926 927 /* Clear surface. */ 928 if (!SDL_ISPIXELFORMAT_ALPHA(dst_format)) { 929 dstA = 255; 930 } 931 ret = SDL_SetRenderDrawColor(renderer, dstR, dstG, dstB, dstA); 932 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i", ret); 933 ret = SDL_RenderClear(renderer); 934 SDLTest_AssertPass("Call to SDL_RenderClear()"); 935 SDLTest_AssertCheck(ret == true, "Verify result from SDL_RenderClear, expected: true, got: %i", ret); 936 937 if (op == TEST_RENDER_COPY_XRGB || op == TEST_RENDER_COPY_ARGB) { 938 Uint8 pixels[4]; 939 940 /* Create src surface */ 941 src = SDL_CreateTexture(renderer, op == TEST_RENDER_COPY_XRGB ? SDL_PIXELFORMAT_RGBX32 : SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 1, 1); 942 SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL"); 943 if (src == NULL) { 944 return; 945 } 946 947 /* Clear surface. */ 948 if (op == TEST_RENDER_COPY_XRGB) { 949 srcA = 255; 950 } 951 pixels[0] = srcR; 952 pixels[1] = srcG; 953 pixels[2] = srcB; 954 pixels[3] = srcA; 955 SDL_UpdateTexture(src, NULL, pixels, sizeof(pixels)); 956 957 /* Set blend mode. */ 958 if (mode >= 0) { 959 ret = SDL_SetTextureBlendMode(src, (SDL_BlendMode)mode); 960 SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()"); 961 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i", mode, ret); 962 } else { 963 ret = SDL_SetTextureBlendMode(src, SDL_BLENDMODE_BLEND); 964 SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()"); 965 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i", mode, ret); 966 } 967 } else { 968 /* Set draw color */ 969 ret = SDL_SetRenderDrawColor(renderer, srcR, srcG, srcB, srcA); 970 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i", ret); 971 972 /* Set blend mode. */ 973 if (mode >= 0) { 974 ret = SDL_SetRenderDrawBlendMode(renderer, (SDL_BlendMode)mode); 975 SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()"); 976 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i", mode, ret); 977 } else { 978 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND); 979 SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()"); 980 SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i", mode, ret); 981 } 982 } 983 984 /* Test blend mode. */ 985#define FLOAT(X) ((float)X / 255.0f) 986 switch (mode) { 987 case -1: 988 mode_name = "color modulation"; 989 ret = SDL_SetTextureColorMod(src, srcR, srcG, srcB); 990 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetTextureColorMod, expected: true, got: %i", ret); 991 expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 992 expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 993 expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 994 expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 995 break; 996 case -2: 997 mode_name = "alpha modulation"; 998 ret = SDL_SetTextureAlphaMod(src, srcA); 999 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetTextureAlphaMod, expected: true, got: %i", ret); 1000 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); 1001 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); 1002 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); 1003 expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f); 1004 break; 1005 case SDL_BLENDMODE_NONE: 1006 mode_name = "SDL_BLENDMODE_NONE"; 1007 expectedR = srcR; 1008 expectedG = srcG; 1009 expectedB = srcB; 1010 expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255; 1011 break; 1012 case SDL_BLENDMODE_BLEND: 1013 mode_name = "SDL_BLENDMODE_BLEND"; 1014 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1015 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1016 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1017 expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1018 break; 1019 case SDL_BLENDMODE_BLEND_PREMULTIPLIED: 1020 mode_name = "SDL_BLENDMODE_BLEND_PREMULTIPLIED"; 1021 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1022 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1023 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1024 expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1025 break; 1026 case SDL_BLENDMODE_ADD: 1027 mode_name = "SDL_BLENDMODE_ADD"; 1028 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f); 1029 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f); 1030 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f); 1031 expectedA = dstA; 1032 break; 1033 case SDL_BLENDMODE_ADD_PREMULTIPLIED: 1034 mode_name = "SDL_BLENDMODE_ADD_PREMULTIPLIED"; 1035 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f); 1036 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f); 1037 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f); 1038 expectedA = dstA; 1039 break; 1040 case SDL_BLENDMODE_MOD: 1041 mode_name = "SDL_BLENDMODE_MOD"; 1042 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f); 1043 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f); 1044 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f); 1045 expectedA = dstA; 1046 break; 1047 case SDL_BLENDMODE_MUL: 1048 mode_name = "SDL_BLENDMODE_MUL"; 1049 expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1050 expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1051 expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f); 1052 expectedA = dstA; 1053 break; 1054 default: 1055 SDLTest_LogError("Invalid blending mode: %d", mode); 1056 return; 1057 } 1058 1059 switch (op) { 1060 case TEST_RENDER_POINT: 1061 operation = "render point"; 1062 ret = SDL_RenderPoint(renderer, 0.0f, 0.0f); 1063 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret); 1064 break; 1065 case TEST_RENDER_LINE: 1066 operation = "render line"; 1067 ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 2.0f, 2.0f); 1068 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderLine, expected: true, got: %i", ret); 1069 break; 1070 case TEST_RENDER_RECT: 1071 operation = "render rect"; 1072 ret = SDL_RenderFillRect(renderer, NULL); 1073 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret); 1074 break; 1075 case TEST_RENDER_COPY_XRGB: 1076 case TEST_RENDER_COPY_ARGB: 1077 operation = (op == TEST_RENDER_COPY_XRGB) ? "render XRGB" : "render ARGB"; 1078 ret = SDL_RenderTexture(renderer, src, NULL, NULL); 1079 SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderTexture, expected: true, got: %i", ret); 1080 break; 1081 default: 1082 SDLTest_LogError("Invalid blending operation: %d", op); 1083 return; 1084 } 1085 1086 result = SDL_RenderReadPixels(renderer, NULL); 1087 SDL_ReadSurfacePixel(result, 0, 0, &actualR, &actualG, &actualB, &actualA); 1088 deltaR = SDL_abs((int)actualR - expectedR); 1089 deltaG = SDL_abs((int)actualG - expectedG); 1090 deltaB = SDL_abs((int)actualB - expectedB); 1091 deltaA = SDL_abs((int)actualA - expectedA); 1092 SDLTest_AssertCheck( 1093 deltaR <= MAXIMUM_ERROR && 1094 deltaG <= MAXIMUM_ERROR && 1095 deltaB <= MAXIMUM_ERROR && 1096 deltaA <= MAXIMUM_ERROR, 1097 "Checking %s %s operation results, expected %d,%d,%d,%d, got %d,%d,%d,%d", 1098 operation, mode_name, 1099 expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA); 1100 1101 /* Clean up */ 1102 SDL_DestroySurface(result); 1103 SDL_DestroyTexture(src); 1104 SDL_DestroyTexture(dst); 1105} 1106 1107static void testBlendMode(int mode) 1108{ 1109 const TestRenderOperation operations[] = { 1110 TEST_RENDER_POINT, 1111 TEST_RENDER_LINE, 1112 TEST_RENDER_RECT, 1113 TEST_RENDER_COPY_XRGB, 1114 TEST_RENDER_COPY_ARGB 1115 }; 1116 const SDL_PixelFormat dst_formats[] = { 1117 SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888 1118 }; 1119 int i, j; 1120 1121 for (i = 0; i < SDL_arraysize(operations); ++i) { 1122 for (j = 0; j < SDL_arraysize(dst_formats); ++j) { 1123 TestRenderOperation op = operations[i]; 1124 1125 if (mode < 0) { 1126 if (op != TEST_RENDER_COPY_XRGB && op != TEST_RENDER_COPY_ARGB) { 1127 /* Unsupported mode for this operation */ 1128 continue; 1129 } 1130 } 1131 testBlendModeOperation(op, mode, dst_formats[j]); 1132 } 1133 } 1134} 1135 1136/** 1137 * Tests render operations with blend modes 1138 */ 1139static int SDLCALL render_testBlendModes(void *arg) 1140{ 1141 testBlendMode(-1); 1142 testBlendMode(-2); 1143 testBlendMode(SDL_BLENDMODE_NONE); 1144 testBlendMode(SDL_BLENDMODE_BLEND); 1145 testBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED); 1146 testBlendMode(SDL_BLENDMODE_ADD); 1147 testBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED); 1148 testBlendMode(SDL_BLENDMODE_MOD); 1149 testBlendMode(SDL_BLENDMODE_MUL); 1150 1151 return TEST_COMPLETED; 1152} 1153 1154/** 1155 * Test viewport 1156 */ 1157static int SDLCALL render_testViewport(void *arg) 1158{ 1159 SDL_Surface *referenceSurface; 1160 SDL_Rect viewport; 1161 1162 viewport.x = TESTRENDER_SCREEN_W / 3; 1163 viewport.y = TESTRENDER_SCREEN_H / 3; 1164 viewport.w = TESTRENDER_SCREEN_W / 2; 1165 viewport.h = TESTRENDER_SCREEN_H / 2; 1166 1167 /* Create expected result */ 1168 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT); 1169 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR)) 1170 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN)) 1171 1172 /* Clear surface. */ 1173 clearScreen(); 1174 1175 /* Set the viewport and do a fill operation */ 1176 CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport)) 1177 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1178 CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL)) 1179 CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL)) 1180 1181 /* Check to see if final image matches. */ 1182 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1183 1184 /* 1185 * Verify that clear ignores the viewport 1186 */ 1187 1188 /* Create expected result */ 1189 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN)) 1190 1191 /* Clear surface. */ 1192 clearScreen(); 1193 1194 /* Set the viewport and do a clear operation */ 1195 CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport)) 1196 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1197 CHECK_FUNC(SDL_RenderClear, (renderer)) 1198 CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL)) 1199 1200 /* Check to see if final image matches. */ 1201 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1202 1203 /* Make current */ 1204 SDL_RenderPresent(renderer); 1205 1206 SDL_DestroySurface(referenceSurface); 1207 1208 return TEST_COMPLETED; 1209} 1210 1211static int SDLCALL render_testRGBSurfaceNoAlpha(void* arg) 1212{ 1213 SDL_Surface *surface; 1214 SDL_Renderer *software_renderer; 1215 SDL_Surface *surface2; 1216 SDL_Texture *texture2; 1217 bool result; 1218 SDL_FRect dest_rect; 1219 SDL_FPoint point; 1220 const SDL_PixelFormatDetails *format_details; 1221 Uint8 r, g, b, a; 1222 1223 SDLTest_AssertPass("About to call SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32)"); 1224 surface = SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32); 1225 SDLTest_AssertCheck(surface != NULL, "Returned surface must be not NULL"); 1226 if (surface == NULL) { 1227 return TEST_ABORTED; 1228 } 1229 1230 SDLTest_AssertPass("About to call SDL_GetPixelFormatDetails(surface->format)"); 1231 format_details = SDL_GetPixelFormatDetails(surface->format); 1232 SDLTest_AssertCheck(format_details != NULL, "Result must be non-NULL, is %p", format_details); 1233 if (format_details == NULL) { 1234 SDL_DestroySurface(surface); 1235 return TEST_ABORTED; 1236 } 1237 1238 SDLTest_AssertCheck(format_details->bits_per_pixel == 32, "format_details->bits_per_pixel is %d, should be %d", format_details->bits_per_pixel, 32); 1239 SDLTest_AssertCheck(format_details->bytes_per_pixel == 4, "format_details->bytes_per_pixel is %d, should be %d", format_details->bytes_per_pixel, 4); 1240 1241 SDLTest_AssertPass("About to call SDL_CreateSoftwareRenderer(surface)"); 1242 software_renderer = SDL_CreateSoftwareRenderer(surface); 1243 SDLTest_AssertCheck(software_renderer != NULL, "Returned renderer must be not NULL"); 1244 if (software_renderer == NULL) { 1245 SDL_DestroySurface(surface); 1246 return TEST_ABORTED; 1247 } 1248 1249 SDLTest_AssertPass("About to call SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32)"); 1250 surface2 = SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32); 1251 SDLTest_AssertCheck(surface2 != NULL, "Returned surface must be not NULL"); 1252 if (surface2 == NULL) { 1253 SDL_DestroySurface(surface); 1254 SDL_DestroyRenderer(software_renderer); 1255 return TEST_ABORTED; 1256 } 1257 1258 SDLTest_AssertPass("About to call SDL_FillRect(surface2, NULL, 0)"); 1259 result = SDL_FillSurfaceRect(surface2, NULL, SDL_MapRGB(SDL_GetPixelFormatDetails(surface2->format), NULL, 0, 0, 0)); 1260 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1261 1262 SDLTest_AssertPass("About to call SDL_CreateTextureFromSurface(software_renderer, surface2)"); 1263 texture2 = SDL_CreateTextureFromSurface(software_renderer, surface2); 1264 SDLTest_AssertCheck(texture2 != NULL, "Returned texture is not NULL"); 1265 1266 SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0xaa, 0xbb, 0xcc, 0x0)"); 1267 result = SDL_SetRenderDrawColor(software_renderer, 0xaa, 0xbb, 0xcc, 0x0); 1268 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1269 1270 SDLTest_AssertPass("About to call SDL_RenderClear(renderer)"); 1271 result = SDL_RenderClear(software_renderer); 1272 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1273 1274 SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0x0)"); 1275 result = SDL_SetRenderDrawColor(software_renderer, 0x0, 0x0, 0x0, 0x0); 1276 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1277 1278 dest_rect.x = 32; 1279 dest_rect.y = 32; 1280 dest_rect.w = (float)surface2->w; 1281 dest_rect.h = (float)surface2->h; 1282 point.x = 0; 1283 point.y = 0; 1284 SDLTest_AssertPass("About to call SDL_RenderCopy(software_renderer, texture, NULL, &{%g, %g, %g, %g})", 1285 dest_rect.x, dest_rect.h, dest_rect.w, dest_rect.h); 1286 result = SDL_RenderTextureRotated(software_renderer, texture2, NULL, &dest_rect, 180, &point, SDL_FLIP_NONE); 1287 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1288 1289 SDLTest_AssertPass("About to call SDL_RenderPresent(software_renderer)"); 1290 SDL_RenderPresent(software_renderer); 1291 1292 SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(0, 0)"); 1293 result = SDL_ReadSurfacePixel(surface, 0, 0, &r, &g, &b, &a); 1294 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1295 SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE, 1296 "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}", 1297 r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE); 1298 1299 SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(15, 15)"); 1300 result = SDL_ReadSurfacePixel(surface, 15, 15, &r, &g, &b, &a); 1301 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1302 SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE, 1303 "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}", 1304 r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE); 1305 1306 SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(16, 16)"); 1307 result = SDL_ReadSurfacePixel(surface, 16, 16, &r, &g, &b, &a); 1308 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1309 SDLTest_AssertCheck(r == 0x00 && g == 0x00 && b == 0x00 && a == SDL_ALPHA_OPAQUE, 1310 "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}", 1311 r, g, b, a, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE); 1312 1313 SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(31, 31)"); 1314 result = SDL_ReadSurfacePixel(surface, 31, 31, &r, &g, &b, &a); 1315 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1316 SDLTest_AssertCheck(r == 0x00 && g == 0x00 && b == 0x00 && a == SDL_ALPHA_OPAQUE, 1317 "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}", 1318 r, g, b, a, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE); 1319 1320 SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(32, 32)"); 1321 result = SDL_ReadSurfacePixel(surface, 32, 32, &r, &g, &b, &a); 1322 SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true); 1323 SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE, 1324 "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}", 1325 r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE); 1326 1327 SDL_DestroyTexture(texture2); 1328 SDL_DestroySurface(surface2); 1329 SDL_DestroyRenderer(software_renderer); 1330 SDL_DestroySurface(surface); 1331 return TEST_COMPLETED; 1332} 1333 1334/** 1335 * Test clip rect 1336 */ 1337static int SDLCALL render_testClipRect(void *arg) 1338{ 1339 SDL_Surface *referenceSurface; 1340 SDL_Rect cliprect; 1341 1342 cliprect.x = TESTRENDER_SCREEN_W / 3; 1343 cliprect.y = TESTRENDER_SCREEN_H / 3; 1344 cliprect.w = TESTRENDER_SCREEN_W / 2; 1345 cliprect.h = TESTRENDER_SCREEN_H / 2; 1346 1347 /* Create expected result */ 1348 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT); 1349 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR)) 1350 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN)) 1351 1352 /* Clear surface. */ 1353 clearScreen(); 1354 1355 /* Set the cliprect and do a fill operation */ 1356 CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect)) 1357 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1358 CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL)) 1359 CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL)) 1360 1361 /* Check to see if final image matches. */ 1362 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1363 1364 /* 1365 * Verify that clear ignores the cliprect 1366 */ 1367 1368 /* Create expected result */ 1369 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN)) 1370 1371 /* Clear surface. */ 1372 clearScreen(); 1373 1374 /* Set the cliprect and do a clear operation */ 1375 CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect)) 1376 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1377 CHECK_FUNC(SDL_RenderClear, (renderer)) 1378 CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL)) 1379 1380 /* Check to see if final image matches. */ 1381 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1382 1383 /* Make current */ 1384 SDL_RenderPresent(renderer); 1385 1386 SDL_DestroySurface(referenceSurface); 1387 1388 return TEST_COMPLETED; 1389} 1390 1391/** 1392 * Test logical size 1393 */ 1394static int SDLCALL render_testLogicalSize(void *arg) 1395{ 1396 SDL_Surface *referenceSurface; 1397 SDL_Rect viewport; 1398 SDL_FRect rect; 1399 int w = 0, h = 0; 1400 int set_w, set_h; 1401 SDL_RendererLogicalPresentation set_presentation_mode; 1402 SDL_FRect set_rect; 1403 const int factor = 2; 1404 1405 SDL_GetWindowSize(window, &w, &h); 1406 if (w != TESTRENDER_WINDOW_W || h != TESTRENDER_WINDOW_H) { 1407 SDLTest_Log("Skipping test render_testLogicalSize: expected window %dx%d, got %dx%d", TESTRENDER_WINDOW_W, TESTRENDER_WINDOW_H, w, h); 1408 return TEST_SKIPPED; 1409 } 1410 1411 viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor; 1412 viewport.y = ((TESTRENDER_SCREEN_H / 4) / factor) * factor; 1413 viewport.w = ((TESTRENDER_SCREEN_W / 2) / factor) * factor; 1414 viewport.h = ((TESTRENDER_SCREEN_H / 2) / factor) * factor; 1415 1416 /* Create expected result */ 1417 referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT); 1418 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR)) 1419 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN)) 1420 1421 /* Clear surface. */ 1422 clearScreen(); 1423 1424 /* Set the logical size and do a fill operation */ 1425 CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h)) 1426 CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX)) 1427 CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode)) 1428 SDLTest_AssertCheck( 1429 set_w == (w / factor) && 1430 set_h == (h / factor) && 1431 set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX, 1432 "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode); 1433 CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect)) 1434 SDLTest_AssertCheck( 1435 set_rect.x == 0.0f && 1436 set_rect.y == 0.0f && 1437 set_rect.w == (float)w && 1438 set_rect.h == (float)h, 1439 "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h); 1440 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1441 rect.x = (float)viewport.x / factor; 1442 rect.y = (float)viewport.y / factor; 1443 rect.w = (float)viewport.w / factor; 1444 rect.h = (float)viewport.h / factor; 1445 CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect)) 1446 CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED)) 1447 CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode)) 1448 SDLTest_AssertCheck( 1449 set_w == 0 && 1450 set_h == 0 && 1451 set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED, 1452 "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode); 1453 CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect)) 1454 SDLTest_AssertCheck( 1455 set_rect.x == 0.0f && 1456 set_rect.y == 0.0f && 1457 set_rect.w == (float)w && 1458 set_rect.h == (float)h, 1459 "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h); 1460 1461 /* Check to see if final image matches. */ 1462 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1463 1464 /* Clear surface. */ 1465 clearScreen(); 1466 1467 /* Set the logical size and viewport and do a fill operation */ 1468 CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h)) 1469 CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX)) 1470 viewport.x = (TESTRENDER_SCREEN_W / 4) / factor; 1471 viewport.y = (TESTRENDER_SCREEN_H / 4) / factor; 1472 viewport.w = (TESTRENDER_SCREEN_W / 2) / factor; 1473 viewport.h = (TESTRENDER_SCREEN_H / 2) / factor; 1474 CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport)) 1475 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1476 CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL)) 1477 CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL)) 1478 CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED)) 1479 1480 /* Check to see if final image matches. */ 1481 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1482 1483 /* 1484 * Test a logical size that isn't the same aspect ratio as the window 1485 */ 1486 1487 viewport.x = (TESTRENDER_SCREEN_W / 4); 1488 viewport.y = 0; 1489 viewport.w = TESTRENDER_SCREEN_W; 1490 viewport.h = TESTRENDER_SCREEN_H; 1491 1492 /* Create expected result */ 1493 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR)) 1494 CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN)) 1495 1496 /* Clear surface. */ 1497 clearScreen(); 1498 1499 /* Set the logical size and do a fill operation */ 1500 CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h)) 1501 CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 1502 w - 2 * (TESTRENDER_SCREEN_W / 4), 1503 h, 1504 SDL_LOGICAL_PRESENTATION_LETTERBOX)) 1505 CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode)) 1506 SDLTest_AssertCheck( 1507 set_w == w - 2 * (TESTRENDER_SCREEN_W / 4) && 1508 set_h == h && 1509 set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX, 1510 "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode); 1511 CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect)) 1512 SDLTest_AssertCheck( 1513 set_rect.x == 20.0f && 1514 set_rect.y == 0.0f && 1515 set_rect.w == 280.0f && 1516 set_rect.h == 240.0f, 1517 "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h); 1518 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE)) 1519 CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL)) 1520 CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED)) 1521 CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode)) 1522 SDLTest_AssertCheck( 1523 set_w == 0 && 1524 set_h == 0 && 1525 set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED, 1526 "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode); 1527 CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect)) 1528 SDLTest_AssertCheck( 1529 set_rect.x == 0.0f && 1530 set_rect.y == 0.0f && 1531 set_rect.w == 320.0f && 1532 set_rect.h == 240.0f, 1533 "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h); 1534 1535 /* Check to see if final image matches. */ 1536 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1537 1538 /* Clear surface. */ 1539 clearScreen(); 1540 1541 /* Make current */ 1542 SDL_RenderPresent(renderer); 1543 1544 SDL_DestroySurface(referenceSurface); 1545 1546 return TEST_COMPLETED; 1547} 1548 1549/** 1550 * @brief Tests setting and getting texture scale mode. 1551 * 1552 * \sa 1553 * http://wiki.libsdl.org/SDL2/SDL_SetTextureScaleMode 1554 * http://wiki.libsdl.org/SDL2/SDL_GetTextureScaleMode 1555 */ 1556static int SDLCALL render_testGetSetTextureScaleMode(void *arg) 1557{ 1558 const struct { 1559 const char *name; 1560 SDL_ScaleMode mode; 1561 } modes[] = { 1562 { "SDL_SCALEMODE_NEAREST", SDL_SCALEMODE_NEAREST }, 1563 { "SDL_SCALEMODE_LINEAR", SDL_SCALEMODE_LINEAR }, 1564 { "SDL_SCALEMODE_PIXELART", SDL_SCALEMODE_PIXELART }, 1565 }; 1566 size_t i; 1567 1568 for (i = 0; i < SDL_arraysize(modes); i++) { 1569 SDL_Texture *texture; 1570 bool result; 1571 SDL_ScaleMode actual_mode = SDL_SCALEMODE_NEAREST; 1572 1573 SDL_ClearError(); 1574 SDLTest_AssertPass("About to call SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16)"); 1575 texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16); 1576 SDLTest_AssertCheck(texture != NULL, "SDL_CreateTexture must return a non-NULL texture"); 1577 SDLTest_AssertPass("About to call SDL_SetTextureScaleMode(texture, %s)", modes[i].name); 1578 result = SDL_SetTextureScaleMode(texture, modes[i].mode); 1579 SDLTest_AssertCheck(result == true, "SDL_SetTextureScaleMode returns %d, expected %d", result, true); 1580 SDLTest_AssertPass("About to call SDL_GetTextureScaleMode(texture)"); 1581 result = SDL_GetTextureScaleMode(texture, &actual_mode); 1582 SDLTest_AssertCheck(result == true, "SDL_SetTextureScaleMode returns %d, expected %d", result, true); 1583 SDLTest_AssertCheck(actual_mode == modes[i].mode, "SDL_GetTextureScaleMode must return %s (%d), actual=%d", 1584 modes[i].name, modes[i].mode, actual_mode); 1585 } 1586 return TEST_COMPLETED; 1587} 1588 1589/* Helper functions */ 1590 1591/** 1592 * Checks to see if functionality is supported. Helper function. 1593 */ 1594static bool isSupported(int code) 1595{ 1596 return (code != false); 1597} 1598 1599/** 1600 * Test to see if we can vary the draw color. Helper function. 1601 * 1602 * \sa SDL_SetRenderDrawColor 1603 * \sa SDL_GetRenderDrawColor 1604 */ 1605static bool hasDrawColor(void) 1606{ 1607 int ret, fail; 1608 Uint8 r, g, b, a; 1609 1610 fail = 0; 1611 1612 /* Set color. */ 1613 ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100); 1614 if (!isSupported(ret)) { 1615 fail = 1; 1616 } 1617 ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a); 1618 if (!isSupported(ret)) { 1619 fail = 1; 1620 } 1621 1622 /* Restore natural. */ 1623 ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); 1624 if (!isSupported(ret)) { 1625 fail = 1; 1626 } 1627 1628 /* Something failed, consider not available. */ 1629 if (fail) { 1630 return false; 1631 } 1632 /* Not set properly, consider failed. */ 1633 else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) { 1634 return false; 1635 } 1636 return true; 1637} 1638 1639/** 1640 * Loads the test image 'Face' as texture. Helper function. 1641 * 1642 * \sa SDL_CreateTextureFromSurface 1643 */ 1644static SDL_Texture * 1645loadTestFace(void) 1646{ 1647 SDL_Surface *face; 1648 SDL_Texture *tface; 1649 1650 face = SDLTest_ImageFace(); 1651 if (!face) { 1652 return NULL; 1653 } 1654 1655 tface = SDL_CreateTextureFromSurface(renderer, face); 1656 if (!tface) { 1657 SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError()); 1658 } 1659 1660 SDL_DestroySurface(face); 1661 1662 return tface; 1663} 1664 1665/** 1666 * Compares screen pixels with image pixels. Helper function. 1667 * 1668 * \param referenceSurface Image to compare against. 1669 * \param allowable_error allowed difference from the reference image 1670 * 1671 * \sa SDL_RenderReadPixels 1672 * \sa SDL_CreateSurfaceFrom 1673 * \sa SDL_DestroySurface 1674 */ 1675static void compare(SDL_Surface *referenceSurface, int allowable_error) 1676{ 1677 int ret; 1678 SDL_Rect rect; 1679 SDL_Surface *surface, *testSurface; 1680 1681 /* Explicitly specify the rect in case the window isn't the expected size... */ 1682 rect.x = 0; 1683 rect.y = 0; 1684 rect.w = TESTRENDER_SCREEN_W; 1685 rect.h = TESTRENDER_SCREEN_H; 1686 1687 surface = SDL_RenderReadPixels(renderer, &rect); 1688 if (!surface) { 1689 SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError()); 1690 return; 1691 } 1692 1693 testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT); 1694 SDL_DestroySurface(surface); 1695 if (!testSurface) { 1696 SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError()); 1697 return; 1698 } 1699 1700 /* Compare surface. */ 1701 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error); 1702 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); 1703 1704 /* Clean up. */ 1705 SDL_DestroySurface(testSurface); 1706} 1707static void compare2x(SDL_Surface *referenceSurface, int allowable_error) 1708{ 1709 int ret; 1710 SDL_Rect rect; 1711 SDL_Surface *surface, *testSurface; 1712 1713 /* Explicitly specify the rect in case the window isn't the expected size... */ 1714 rect.x = 0; 1715 rect.y = 0; 1716 rect.w = TESTRENDER_SCREEN_W * 2; 1717 rect.h = TESTRENDER_SCREEN_H * 2; 1718 1719 surface = SDL_RenderReadPixels(renderer, &rect); 1720 if (!surface) { 1721 SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError()); 1722 return; 1723 } 1724 1725 testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT); 1726 SDL_DestroySurface(surface); 1727 if (!testSurface) { 1728 SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError()); 1729 return; 1730 } 1731 1732 /* Compare surface. */ 1733 ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error); 1734 SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret); 1735 1736 /* Clean up. */ 1737 SDL_DestroySurface(testSurface); 1738} 1739 1740/** 1741 * Clears the screen. Helper function. 1742 * 1743 * \sa SDL_SetRenderDrawColor 1744 * \sa SDL_RenderClear 1745 * \sa SDL_RenderPresent 1746 * \sa SDL_SetRenderDrawBlendMode 1747 */ 1748static int 1749clearScreen(void) 1750{ 1751 int ret; 1752 1753 /* Make current */ 1754 SDL_RenderPresent(renderer); 1755 1756 /* Set color. */ 1757 ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE); 1758 SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawColor, expected: true, got: %i", ret); 1759 1760 /* Clear screen. */ 1761 ret = SDL_RenderClear(renderer); 1762 SDLTest_AssertCheck(ret == true, "Validate result from SDL_RenderClear, expected: true, got: %i", ret); 1763 1764 /* Set defaults. */ 1765 ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); 1766 SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawBlendMode, expected: true, got: %i", ret); 1767 1768 ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE); 1769 SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawColor, expected: true, got: %i", ret); 1770 1771 return 0; 1772} 1773 1774/** 1775 * Tests geometry UV clamping 1776 */ 1777static int SDLCALL render_testUVClamping(void *arg) 1778{ 1779 SDL_Vertex vertices[6]; 1780 SDL_Vertex *verts = vertices; 1781 SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f }; 1782 SDL_FRect rect; 1783 float min_U = -0.5f; 1784 float max_U = 1.5f; 1785 float min_V = -0.5f; 1786 float max_V = 1.5f; 1787 SDL_Texture *tface; 1788 SDL_Surface *referenceSurface = NULL; 1789 1790 /* Clear surface. */ 1791 clearScreen(); 1792 1793 /* Create face surface. */ 1794 tface = loadTestFace(); 1795 SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result"); 1796 if (tface == NULL) { 1797 return TEST_ABORTED; 1798 } 1799 1800 rect.w = (float)tface->w * 2; 1801 rect.h = (float)tface->h * 2; 1802 rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2; 1803 rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2; 1804 1805 /* 1806 * 0--1 1807 * | /| 1808 * |/ | 1809 * 3--2 1810 * 1811 * Draw sprite2 as triangles that can be recombined as rect by software renderer 1812 */ 1813 1814 /* 0 */ 1815 verts->position.x = rect.x; 1816 verts->position.y = rect.y; 1817 verts->color = color; 1818 verts->tex_coord.x = min_U; 1819 verts->tex_coord.y = min_V; 1820 verts++; 1821 /* 1 */ 1822 verts->position.x = rect.x + rect.w; 1823 verts->position.y = rect.y; 1824 verts->color = color; 1825 verts->tex_coord.x = max_U; 1826 verts->tex_coord.y = min_V; 1827 verts++; 1828 /* 2 */ 1829 verts->position.x = rect.x + rect.w; 1830 verts->position.y = rect.y + rect.h; 1831 verts->color = color; 1832 verts->tex_coord.x = max_U; 1833 verts->tex_coord.y = max_V; 1834 verts++; 1835 /* 0 */ 1836 verts->position.x = rect.x; 1837 verts->position.y = rect.y; 1838 verts->color = color; 1839 verts->tex_coord.x = min_U; 1840 verts->tex_coord.y = min_V; 1841 verts++; 1842 /* 2 */ 1843 verts->position.x = rect.x + rect.w; 1844 verts->position.y = rect.y + rect.h; 1845 verts->color = color; 1846 verts->tex_coord.x = max_U; 1847 verts->tex_coord.y = max_V; 1848 verts++; 1849 /* 3 */ 1850 verts->position.x = rect.x; 1851 verts->position.y = rect.y + rect.h; 1852 verts->color = color; 1853 verts->tex_coord.x = min_U; 1854 verts->tex_coord.y = max_V; 1855 verts++; 1856 1857 /* Set texture address mode to clamp */ 1858 SDL_SetRenderTextureAddressMode(renderer, SDL_TEXTURE_ADDRESS_CLAMP, SDL_TEXTURE_ADDRESS_CLAMP); 1859 1860 /* Blit sprites as triangles onto the screen */ 1861 SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0); 1862 1863 /* See if it's the same */ 1864 referenceSurface = SDLTest_ImageClampedSprite(); 1865 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1866 1867 /* Make current */ 1868 SDL_RenderPresent(renderer); 1869 1870 /* Clean up. */ 1871 SDL_DestroyTexture(tface); 1872 SDL_DestroySurface(referenceSurface); 1873 referenceSurface = NULL; 1874 1875 return TEST_COMPLETED; 1876} 1877 1878/** 1879 * Tests geometry UV wrapping 1880 */ 1881static int SDLCALL render_testUVWrapping(void *arg) 1882{ 1883 SDL_Vertex vertices[6]; 1884 SDL_Vertex *verts = vertices; 1885 SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f }; 1886 SDL_FRect rect; 1887 float min_U = -0.5f; 1888 float max_U = 1.5f; 1889 float min_V = -0.5f; 1890 float max_V = 1.5f; 1891 SDL_Texture *tface; 1892 SDL_Surface *referenceSurface = NULL; 1893 1894 /* Clear surface. */ 1895 clearScreen(); 1896 1897 /* Create face surface. */ 1898 tface = loadTestFace(); 1899 SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result"); 1900 if (tface == NULL) { 1901 return TEST_ABORTED; 1902 } 1903 1904 rect.w = (float)tface->w * 2; 1905 rect.h = (float)tface->h * 2; 1906 rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2; 1907 rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2; 1908 1909 /* 1910 * 0--1 1911 * | /| 1912 * |/ | 1913 * 3--2 1914 * 1915 * Draw sprite2 as triangles that can be recombined as rect by software renderer 1916 */ 1917 1918 /* 0 */ 1919 verts->position.x = rect.x; 1920 verts->position.y = rect.y; 1921 verts->color = color; 1922 verts->tex_coord.x = min_U; 1923 verts->tex_coord.y = min_V; 1924 verts++; 1925 /* 1 */ 1926 verts->position.x = rect.x + rect.w; 1927 verts->position.y = rect.y; 1928 verts->color = color; 1929 verts->tex_coord.x = max_U; 1930 verts->tex_coord.y = min_V; 1931 verts++; 1932 /* 2 */ 1933 verts->position.x = rect.x + rect.w; 1934 verts->position.y = rect.y + rect.h; 1935 verts->color = color; 1936 verts->tex_coord.x = max_U; 1937 verts->tex_coord.y = max_V; 1938 verts++; 1939 /* 0 */ 1940 verts->position.x = rect.x; 1941 verts->position.y = rect.y; 1942 verts->color = color; 1943 verts->tex_coord.x = min_U; 1944 verts->tex_coord.y = min_V; 1945 verts++; 1946 /* 2 */ 1947 verts->position.x = rect.x + rect.w; 1948 verts->position.y = rect.y + rect.h; 1949 verts->color = color; 1950 verts->tex_coord.x = max_U; 1951 verts->tex_coord.y = max_V; 1952 verts++; 1953 /* 3 */ 1954 verts->position.x = rect.x; 1955 verts->position.y = rect.y + rect.h; 1956 verts->color = color; 1957 verts->tex_coord.x = min_U; 1958 verts->tex_coord.y = max_V; 1959 verts++; 1960 1961 /* Blit sprites as triangles onto the screen */ 1962 SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0); 1963 1964 /* See if it's the same */ 1965 referenceSurface = SDLTest_ImageWrappingSprite(); 1966 compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); 1967 1968 /* Make current */ 1969 SDL_RenderPresent(renderer); 1970 1971 /* Clean up. */ 1972 SDL_DestroyTexture(tface); 1973 SDL_DestroySurface(referenceSurface); 1974 referenceSurface = NULL; 1975 1976 return TEST_COMPLETED; 1977} 1978 1979/** 1980 * Tests texture state changes 1981 */ 1982static int SDLCALL render_testTextureState(void *arg) 1983{ 1984 const Uint8 pixels[8] = { 1985 0x00, 0x00, 0x00, 0xFF, 1986 0xFF, 0xFF, 0xFF, 0xFF 1987 }; 1988 const SDL_Color expected[] = { 1989 /* Step 0: plain copy */ 1990 { 0x00, 0x00, 0x00, 0xFF }, 1991 { 0xFF, 0xFF, 0xFF, 0xFF }, 1992 /* Step 1: color mod to red */ 1993 { 0x00, 0x00, 0x00, 0xFF }, 1994 { 0xFF, 0x00, 0x00, 0xFF }, 1995 /* Step 2: alpha mod to 128 (cleared to green) */ 1996 { 0x00, 0x7F, 0x00, 0xFF }, 1997 { 0x80, 0xFF, 0x80, 0xFF }, 1998 /* Step 3: nearest stretch */ 1999 { 0xFF, 0xFF, 0xFF, 0xFF }, 2000 { 0x00, 0xFF, 0x00, 0xFF }, 2001 /* Step 4: linear stretch */ 2002 { 0x80, 0x80, 0x80, 0xFF }, 2003 { 0x00, 0xFF, 0x00, 0xFF }, 2004 }; 2005 SDL_Texture *texture; 2006 SDL_Rect rect; 2007 SDL_FRect dst; 2008 int i; 2009 2010 /* Clear surface to green */ 2011 SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); 2012 SDL_RenderClear(renderer); 2013 2014 /* Create 2-pixel surface. */ 2015 texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 2, 1); 2016 SDLTest_AssertCheck(texture != NULL, "Verify SDL_CreateTexture() result"); 2017 if (texture == NULL) { 2018 return TEST_ABORTED; 2019 } 2020 SDL_UpdateTexture(texture, NULL, pixels, sizeof(pixels)); 2021 2022 dst.x = 0.0f; 2023 dst.y = 0.0f; 2024 dst.w = 2.0f; 2025 dst.h = 1.0f; 2026 2027 /* Step 0: plain copy */ 2028 SDL_RenderTexture(renderer, texture, NULL, &dst); 2029 dst.y += 1; 2030 2031 /* Step 1: color mod to red */ 2032 SDL_SetTextureColorMod(texture, 0xFF, 0x00, 0x00); 2033 SDL_RenderTexture(renderer, texture, NULL, &dst); 2034 SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF); 2035 dst.y += 1; 2036 2037 /* Step 2: alpha mod to 128 */ 2038 SDL_SetTextureAlphaMod(texture, 0x80); 2039 SDL_RenderTexture(renderer, texture, NULL, &dst); 2040 SDL_SetTextureAlphaMod(texture, 0xFF); 2041 dst.y += 1; 2042 2043 /* Step 3: nearest stretch */ 2044 dst.w = 1; 2045 SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST); 2046 SDL_RenderTexture(renderer, texture, NULL, &dst); 2047 dst.y += 1; 2048 2049 /* Step 4: linear stretch */ 2050 dst.w = 1; 2051 SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR); 2052 SDL_RenderTexture(renderer, texture, NULL, &dst); 2053 dst.y += 1; 2054 2055 /* Verify results */ 2056 rect.x = 0; 2057 rect.y = 0; 2058 rect.w = 2; 2059 rect.h = 1; 2060 for (i = 0; i < SDL_arraysize(expected); ) { 2061 const int MAX_DELTA = 1; 2062 SDL_Color actual; 2063 int deltaR, deltaG, deltaB, deltaA; 2064 SDL_Surface *surface = SDL_RenderReadPixels(renderer, &rect); 2065 2066 SDL_ReadSurfacePixel(surface, 0, 0, &actual.r, &actual.g, &actual.b, &actual.a); 2067 deltaR = (actual.r - expected[i].r); 2068 deltaG = (actual.g - expected[i].g); 2069 deltaB = (actual.b - expected[i].b); 2070 deltaA = (actual.a - expected[i].a); 2071 SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA && 2072 SDL_abs(deltaG) <= MAX_DELTA && 2073 SDL_abs(deltaB) <= MAX_DELTA && 2074 SDL_abs(deltaA) <= MAX_DELTA, 2075 "Validate left pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2, 2076 expected[i].r, expected[i].g, expected[i].b, expected[i].a, 2077 actual.r, actual.g, actual.b, actual.a); 2078 ++i; 2079 2080 SDL_ReadSurfacePixel(surface, 1, 0, &actual.r, &actual.g, &actual.b, &actual.a); 2081 deltaR = (actual.r - expected[i].r); 2082 deltaG = (actual.g - expected[i].g); 2083 deltaB = (actual.b - expected[i].b); 2084 deltaA = (actual.a - expected[i].a); 2085 SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA && 2086 SDL_abs(deltaG) <= MAX_DELTA && 2087 SDL_abs(deltaB) <= MAX_DELTA && 2088 SDL_abs(deltaA) <= MAX_DELTA, 2089 "Validate right pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2, 2090 expected[i].r, expected[i].g, expected[i].b, expected[i].a, 2091 actual.r, actual.g, actual.b, actual.a); 2092 ++i; 2093 2094 SDL_DestroySurface(surface); 2095 2096 rect.y += 1; 2097 } 2098 2099 /* Clean up. */ 2100 SDL_DestroyTexture(texture); 2101 2102 return TEST_COMPLETED; 2103} 2104 2105static void CheckUniformColor(float expected) 2106{ 2107 SDL_Surface *surface = SDL_RenderReadPixels(renderer, NULL); 2108 if (surface) { 2109 const float epsilon = 0.001f; 2110 float r, g, b, a; 2111 CHECK_FUNC(SDL_ReadSurfacePixelFloat, (surface, 0, 0, &r, &g, &b, &a)); 2112 SDLTest_AssertCheck( 2113 SDL_fabs(r - expected) <= epsilon && 2114 SDL_fabs(g - expected) <= epsilon && 2115 SDL_fabs(b - expected) <= epsilon && 2116 a == 1.0f, 2117 "Check color, expected %g,%g,%g,%g, got %g,%g,%g,%g", 2118 expected, expected, expected, 1.0f, r, g, b, a); 2119 SDL_DestroySurface(surface); 2120 } else { 2121 SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError()); 2122 } 2123} 2124 2125/** 2126 * Tests colorspace support (sRGB -> linear) 2127 */ 2128static int SDLCALL render_testColorspaceLinear(void *arg) 2129{ 2130 SDL_PropertiesID props; 2131 SDL_Texture *texture; 2132 Uint32 pixel = 0xFF404040; 2133 2134 SDL_DestroyRenderer(renderer); 2135 2136 props = SDL_CreateProperties(); 2137#ifdef SDL_PLATFORM_EMSCRIPTEN 2138 // Something about falling back to the software renderer and failing causes window surface updates to fail in video_getWindowSurface() 2139 // Adding this as a workaround to prevent software fallback until we figure this out. 2140 SDL_SetStringProperty(props, SDL_PROP_RENDERER_CREATE_NAME_STRING, "opengles2"); 2141#endif 2142 SDL_SetPointerProperty(props, SDL_PROP_RENDERER_CREATE_WINDOW_POINTER, window); 2143 SDL_SetNumberProperty(props, SDL_PROP_RENDERER_CREATE_OUTPUT_COLORSPACE_NUMBER, SDL_COLORSPACE_SRGB_LINEAR); 2144 renderer = SDL_CreateRendererWithProperties(props); 2145 SDL_DestroyProperties(props); 2146 if (!renderer) { 2147 SDLTest_Log("Skipping test render_testColorspaceLinear, couldn't create a linear colorspace renderer"); 2148 return TEST_SKIPPED; 2149 } 2150 2151 /* Verify conversion between sRGB and linear colorspaces */ 2152 texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, 1, 1); 2153 SDLTest_AssertPass("Create texture"); 2154 SDLTest_AssertCheck(texture != NULL, "Check SDL_CreateTexture result"); 2155 CHECK_FUNC(SDL_UpdateTexture, (texture, NULL, &pixel, sizeof(pixel))); 2156 2157 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2158 CHECK_FUNC(SDL_RenderClear, (renderer)); 2159 CheckUniformColor(0.0f); 2160 2161 SDLTest_AssertPass("Checking sRGB clear 0x40"); 2162 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2163 CHECK_FUNC(SDL_RenderClear, (renderer)); 2164 CheckUniformColor(0.0512695f); 2165 2166 /* Clear target to 0 */ 2167 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2168 CHECK_FUNC(SDL_RenderClear, (renderer)); 2169 2170 SDLTest_AssertPass("Checking sRGB draw 0x40"); 2171 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2172 CHECK_FUNC(SDL_RenderPoint, (renderer, 0.0f, 0.0f)); 2173 CheckUniformColor(0.0512695f); 2174 2175 /* Clear target to 0 */ 2176 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2177 CHECK_FUNC(SDL_RenderClear, (renderer)); 2178 2179 SDLTest_AssertPass("Checking sRGB texture 0x40"); 2180 CHECK_FUNC(SDL_RenderTexture, (renderer, texture, NULL, NULL)); 2181 CheckUniformColor(0.0512695f); 2182 2183 /* Clear target to 0 */ 2184 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2185 CHECK_FUNC(SDL_RenderClear, (renderer)); 2186 2187 SDL_SetRenderColorScale(renderer, 2.0f); 2188 2189 SDLTest_AssertPass("Checking sRGB clear 0x40 with color scale 2.0"); 2190 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2191 CHECK_FUNC(SDL_RenderClear, (renderer)); 2192 CheckUniformColor(0.102478f); 2193 2194 /* Clear target to 0 */ 2195 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2196 CHECK_FUNC(SDL_RenderClear, (renderer)); 2197 2198 SDLTest_AssertPass("Checking sRGB draw 0x40 with color scale 2.0f"); 2199 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2200 CHECK_FUNC(SDL_RenderPoint, (renderer, 0.0f, 0.0f)); 2201 CheckUniformColor(0.102478f); 2202 2203 /* Clear target to 0 */ 2204 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2205 CHECK_FUNC(SDL_RenderClear, (renderer)); 2206 2207 SDLTest_AssertPass("Checking sRGB texture 0x40 with color scale 2.0f"); 2208 CHECK_FUNC(SDL_RenderTexture, (renderer, texture, NULL, NULL)); 2209 CheckUniformColor(0.102478f); 2210 2211 SDL_DestroyTexture(texture); 2212 2213 return TEST_COMPLETED; 2214} 2215 2216/** 2217 * Tests colorspace support (linear -> sRGB) 2218 */ 2219static int SDLCALL render_testColorspaceSRGB(void *arg) 2220{ 2221 bool supports_float_textures; 2222 const SDL_PixelFormat *texture_formats; 2223 int i; 2224 SDL_Texture *texture; 2225 float pixel[4] = { 0.25f, 0.25f, 0.25f, 1.0f }; 2226 2227 supports_float_textures = false; 2228 texture_formats = (const SDL_PixelFormat *)SDL_GetPointerProperty(SDL_GetRendererProperties(renderer), SDL_PROP_RENDERER_TEXTURE_FORMATS_POINTER, NULL); 2229 if (texture_formats) { 2230 for (i = 0; texture_formats[i] != SDL_PIXELFORMAT_UNKNOWN; ++i) { 2231 if (SDL_ISPIXELFORMAT_FLOAT(texture_formats[i])) { 2232 supports_float_textures = true; 2233 break; 2234 } 2235 } 2236 } 2237 if (!supports_float_textures) { 2238 SDLTest_Log("Skipping test render_testColorspaceSRGB, renderer doesn't support float textures"); 2239 return TEST_SKIPPED; 2240 } 2241 2242 /* Verify conversion between sRGB and linear colorspaces */ 2243 texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA128_FLOAT, SDL_TEXTUREACCESS_STATIC, 1, 1); 2244 SDLTest_AssertPass("Create texture"); 2245 SDLTest_AssertCheck(texture != NULL, "Check SDL_CreateTexture result"); 2246 CHECK_FUNC(SDL_UpdateTexture, (texture, NULL, &pixel, sizeof(pixel))); 2247 2248 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2249 CHECK_FUNC(SDL_RenderClear, (renderer)); 2250 CheckUniformColor(0.0f); 2251 2252 SDLTest_AssertPass("Checking sRGB clear 0x40"); 2253 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2254 CHECK_FUNC(SDL_RenderClear, (renderer)); 2255 CheckUniformColor(0.25098f); 2256 2257 /* Clear target to 0 */ 2258 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2259 CHECK_FUNC(SDL_RenderClear, (renderer)); 2260 2261 SDLTest_AssertPass("Checking sRGB draw 0x40"); 2262 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2263 CHECK_FUNC(SDL_RenderPoint, (renderer, 0.0f, 0.0f)); 2264 CheckUniformColor(0.25098f); 2265 2266 /* Clear target to 0 */ 2267 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2268 CHECK_FUNC(SDL_RenderClear, (renderer)); 2269 2270 SDLTest_AssertPass("Checking linear texture 0.25"); 2271 CHECK_FUNC(SDL_RenderTexture, (renderer, texture, NULL, NULL)); 2272 CheckUniformColor(0.537255f); 2273 2274 /* Clear target to 0 */ 2275 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2276 CHECK_FUNC(SDL_RenderClear, (renderer)); 2277 2278 SDL_SetRenderColorScale(renderer, 2.0f); 2279 2280 SDLTest_AssertPass("Checking sRGB clear 0x40 with color scale 2.0"); 2281 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2282 CHECK_FUNC(SDL_RenderClear, (renderer)); 2283 CheckUniformColor(0.501961f); 2284 2285 /* Clear target to 0 */ 2286 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2287 CHECK_FUNC(SDL_RenderClear, (renderer)); 2288 2289 SDLTest_AssertPass("Checking sRGB draw 0x40 with color scale 2.0f"); 2290 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0x40, 0x40, 0x40, 255)); 2291 CHECK_FUNC(SDL_RenderPoint, (renderer, 0.0f, 0.0f)); 2292 CheckUniformColor(0.501961f); 2293 2294 /* Clear target to 0 */ 2295 CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 0, 0, 255)); 2296 CHECK_FUNC(SDL_RenderClear, (renderer)); 2297 2298 SDLTest_AssertPass("Checking linear texture 0.25 with color scale 2.0f"); 2299 CHECK_FUNC(SDL_RenderTexture, (renderer, texture, NULL, NULL)); 2300 CheckUniformColor(0.737255f); 2301 2302 SDL_DestroyTexture(texture); 2303 2304 return TEST_COMPLETED; 2305} 2306 2307/* ================= Test References ================== */ 2308 2309/* Render test cases */ 2310static const SDLTest_TestCaseReference renderTestGetNumRenderDrivers = { 2311 render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED 2312}; 2313 2314static const SDLTest_TestCaseReference renderTestPrimitives = { 2315 render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED 2316}; 2317 2318static const SDLTest_TestCaseReference renderTestPrimitivesWithViewport = { 2319 render_testPrimitivesWithViewport, "render_testPrimitivesWithViewport", "Tests rendering primitives within a viewport", TEST_ENABLED 2320}; 2321 2322static const SDLTest_TestCaseReference renderTestBlit = { 2323 render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED 2324}; 2325 2326static const SDLTest_TestCaseReference renderTestBlitTiled = { 2327 render_testBlitTiled, "render_testBlitTiled", "Tests tiled blitting", TEST_ENABLED 2328}; 2329 2330static const SDLTest_TestCaseReference renderTestBlit9Grid = { 2331 render_testBlit9Grid, "render_testBlit9Grid", "Tests 9-grid blitting", TEST_ENABLED 2332}; 2333 2334static const SDLTest_TestCaseReference renderTestBlit9GridTiled = { 2335 render_testBlit9GridTiled, "render_testBlit9GridTiled", "Tests tiled 9-grid blitting", TEST_ENABLED 2336}; 2337 2338static const SDLTest_TestCaseReference renderTestBlitColor = { 2339 render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED 2340}; 2341 2342static const SDLTest_TestCaseReference renderTestBlendModes = { 2343 render_testBlendModes, "render_testBlendModes", "Tests rendering blend modes", TEST_ENABLED 2344}; 2345 2346static const SDLTest_TestCaseReference renderTestViewport = { 2347 render_testViewport, "render_testViewport", "Tests viewport", TEST_ENABLED 2348}; 2349 2350static const SDLTest_TestCaseReference renderTestClipRect = { 2351 render_testClipRect, "render_testClipRect", "Tests clip rect", TEST_ENABLED 2352}; 2353 2354static const SDLTest_TestCaseReference renderTestLogicalSize = { 2355 render_testLogicalSize, "render_testLogicalSize", "Tests logical size", TEST_ENABLED 2356}; 2357 2358static const SDLTest_TestCaseReference renderTestUVClamping = { 2359 render_testUVClamping, "render_testUVClamping", "Tests geometry UV clamping", TEST_ENABLED 2360}; 2361 2362static const SDLTest_TestCaseReference renderTestUVWrapping = { 2363 render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED 2364}; 2365 2366static const SDLTest_TestCaseReference renderTestTextureState = { 2367 render_testTextureState, "render_testTextureState", "Tests texture state changes", TEST_ENABLED 2368}; 2369 2370static const SDLTest_TestCaseReference renderTestGetSetTextureScaleMode = { 2371 render_testGetSetTextureScaleMode, "render_testGetSetTextureScaleMode", "Tests setting/getting texture scale mode", TEST_ENABLED 2372}; 2373 2374static const SDLTest_TestCaseReference renderTestRGBSurfaceNoAlpha = { 2375 render_testRGBSurfaceNoAlpha, "render_testRGBSurfaceNoAlpha", "Tests RGB surface with no alpha using software renderer", TEST_ENABLED 2376}; 2377 2378static const SDLTest_TestCaseReference renderTestColorspaceLinear = { 2379 render_testColorspaceLinear, "render_testColorspaceLinear", "Tests colorspace support (sRGB -> linear)", TEST_ENABLED 2380}; 2381 2382static const SDLTest_TestCaseReference renderTestColorspaceSRGB = { 2383 render_testColorspaceSRGB, "render_testColorspaceSRGB", "Tests colorspace support (linear -> sRGB)", TEST_ENABLED 2384}; 2385 2386/* Sequence of Render test cases */ 2387static const SDLTest_TestCaseReference *renderTests[] = { 2388 &renderTestGetNumRenderDrivers, 2389 &renderTestPrimitives, 2390 &renderTestPrimitivesWithViewport, 2391 &renderTestBlit, 2392 &renderTestBlitTiled, 2393 &renderTestBlit9Grid, 2394 &renderTestBlit9GridTiled, 2395 &renderTestBlitColor, 2396 &renderTestBlendModes, 2397 &renderTestViewport, 2398 &renderTestClipRect, 2399 &renderTestLogicalSize, 2400 &renderTestUVClamping, 2401 &renderTestUVWrapping, 2402 &renderTestTextureState, 2403 &renderTestGetSetTextureScaleMode, 2404 &renderTestRGBSurfaceNoAlpha, 2405 &renderTestColorspaceLinear, 2406 &renderTestColorspaceSRGB, 2407 NULL 2408}; 2409 2410/* Render test suite (global) */ 2411SDLTest_TestSuiteReference renderTestSuite = { 2412 "Render", 2413 InitCreateRenderer, 2414 renderTests, 2415 CleanupDestroyRenderer 2416}; 2417[FILE END](C) 2025 0x4248 (C) 2025 4248 Media and 4248 Systems, All part of 0x4248 See LICENCE files for more information. Not all files are by 0x4248 always check Licencing.