testautomation_render.c 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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. /* ================= Test Case Implementation ================== */
  10. #define TESTRENDER_SCREEN_W 80
  11. #define TESTRENDER_SCREEN_H 60
  12. #define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888
  13. #define RENDER_COLOR_CLEAR 0xFF000000
  14. #define RENDER_COLOR_GREEN 0xFF00FF00
  15. #define ALLOWABLE_ERROR_OPAQUE 0
  16. #define ALLOWABLE_ERROR_BLENDED 0
  17. #define CHECK_FUNC(FUNC, PARAMS) \
  18. { \
  19. int result = FUNC PARAMS; \
  20. if (result != 0) { \
  21. SDLTest_AssertCheck(result == 0, "Validate result from %s, expected: 0, got: %i, %s", #FUNC, result, SDL_GetError()); \
  22. } \
  23. }
  24. /* Test window and renderer */
  25. static SDL_Window *window = NULL;
  26. static SDL_Renderer *renderer = NULL;
  27. /* Prototypes for helper functions */
  28. static int clearScreen(void);
  29. static void compare(SDL_Surface *reference, int allowable_error);
  30. static void compare2x(SDL_Surface *reference, int allowable_error);
  31. static SDL_Texture *loadTestFace(void);
  32. static int hasDrawColor(void);
  33. static int isSupported(int code);
  34. /**
  35. * Create software renderer for tests
  36. */
  37. static void InitCreateRenderer(void *arg)
  38. {
  39. int width = 320, height = 240;
  40. const char *renderer_name = NULL;
  41. renderer = NULL;
  42. window = SDL_CreateWindow("render_testCreateRenderer", width, height, 0);
  43. SDLTest_AssertPass("SDL_CreateWindow()");
  44. SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
  45. if (window == NULL) {
  46. return;
  47. }
  48. renderer = SDL_CreateRenderer(window, renderer_name);
  49. SDLTest_AssertPass("SDL_CreateRenderer()");
  50. SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError());
  51. if (renderer == NULL) {
  52. SDL_DestroyWindow(window);
  53. return;
  54. }
  55. }
  56. /**
  57. * Destroy renderer for tests
  58. */
  59. static void CleanupDestroyRenderer(void *arg)
  60. {
  61. if (renderer) {
  62. SDL_DestroyRenderer(renderer);
  63. renderer = NULL;
  64. SDLTest_AssertPass("SDL_DestroyRenderer()");
  65. }
  66. if (window) {
  67. SDL_DestroyWindow(window);
  68. window = NULL;
  69. SDLTest_AssertPass("SDL_DestroyWindow");
  70. }
  71. }
  72. /**
  73. * Tests call to SDL_GetNumRenderDrivers
  74. *
  75. * \sa SDL_GetNumRenderDrivers
  76. */
  77. static int render_testGetNumRenderDrivers(void *arg)
  78. {
  79. int n;
  80. n = SDL_GetNumRenderDrivers();
  81. SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n);
  82. return TEST_COMPLETED;
  83. }
  84. /**
  85. * Tests the SDL primitives for rendering.
  86. *
  87. * \sa SDL_SetRenderDrawColor
  88. * \sa SDL_RenderFillRect
  89. * \sa SDL_RenderLine
  90. *
  91. */
  92. static int render_testPrimitives(void *arg)
  93. {
  94. int ret;
  95. int x, y;
  96. SDL_FRect rect;
  97. SDL_Surface *referenceSurface = NULL;
  98. int checkFailCount1;
  99. int checkFailCount2;
  100. /* Clear surface. */
  101. clearScreen();
  102. /* Need drawcolor or just skip test. */
  103. SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor");
  104. /* Draw a rectangle. */
  105. rect.x = 40.0f;
  106. rect.y = 0.0f;
  107. rect.w = 40.0f;
  108. rect.h = 80.0f;
  109. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 13, 73, 200, SDL_ALPHA_OPAQUE))
  110. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  111. /* Draw a rectangle. */
  112. rect.x = 10.0f;
  113. rect.y = 10.0f;
  114. rect.w = 60.0f;
  115. rect.h = 40.0f;
  116. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE))
  117. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  118. /* Draw some points like so:
  119. * X.X.X.X..
  120. * .X.X.X.X.
  121. * X.X.X.X.. */
  122. checkFailCount1 = 0;
  123. checkFailCount2 = 0;
  124. for (y = 0; y < 3; y++) {
  125. for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) {
  126. ret = SDL_SetRenderDrawColor(renderer, (Uint8)(x * y), (Uint8)(x * y / 2), (Uint8)(x * y / 3), SDL_ALPHA_OPAQUE);
  127. if (ret != 0) {
  128. checkFailCount1++;
  129. }
  130. ret = SDL_RenderPoint(renderer, (float)x, (float)y);
  131. if (ret != 0) {
  132. checkFailCount2++;
  133. }
  134. }
  135. }
  136. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
  137. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", checkFailCount2);
  138. /* Draw some lines. */
  139. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  140. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, TESTRENDER_SCREEN_W, 30.0f))
  141. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 55, 55, 5, SDL_ALPHA_OPAQUE))
  142. CHECK_FUNC(SDL_RenderLine, (renderer, 40.0f, 30.0f, 40.0f, 60.0f))
  143. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 5, 105, 105, SDL_ALPHA_OPAQUE))
  144. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 29.0f, 29.0f))
  145. CHECK_FUNC(SDL_RenderLine, (renderer, 29.0f, 30.0f, 0.0f, 59.0f))
  146. CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 0.0f, 50.0f, 29.0f))
  147. CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 59.0f, 50.0f, 30.0f))
  148. /* See if it's the same. */
  149. referenceSurface = SDLTest_ImagePrimitives();
  150. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  151. /* Make current */
  152. SDL_RenderPresent(renderer);
  153. /* Clean up. */
  154. SDL_DestroySurface(referenceSurface);
  155. referenceSurface = NULL;
  156. return TEST_COMPLETED;
  157. }
  158. /**
  159. * Tests the SDL primitives for rendering within a viewport.
  160. *
  161. * \sa SDL_SetRenderDrawColor
  162. * \sa SDL_RenderFillRect
  163. * \sa SDL_RenderLine
  164. *
  165. */
  166. static int render_testPrimitivesWithViewport(void *arg)
  167. {
  168. SDL_Rect viewport;
  169. SDL_Surface *surface;
  170. /* Clear surface. */
  171. clearScreen();
  172. viewport.x = 2;
  173. viewport.y = 2;
  174. viewport.w = 2;
  175. viewport.h = 2;
  176. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
  177. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 255, 255, SDL_ALPHA_OPAQUE))
  178. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 1.0f, 1.0f));
  179. viewport.x = 3;
  180. viewport.y = 3;
  181. viewport.w = 1;
  182. viewport.h = 1;
  183. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
  184. surface = SDL_RenderReadPixels(renderer, NULL);
  185. if (surface) {
  186. Uint8 r, g, b, a;
  187. CHECK_FUNC(SDL_ReadSurfacePixel, (surface, 0, 0, &r, &g, &b, &a));
  188. 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);
  189. SDL_DestroySurface(surface);
  190. } else {
  191. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  192. }
  193. return TEST_COMPLETED;
  194. }
  195. /**
  196. * Tests some blitting routines.
  197. *
  198. * \sa SDL_RenderTexture
  199. * \sa SDL_DestroyTexture
  200. */
  201. static int render_testBlit(void *arg)
  202. {
  203. int ret;
  204. SDL_FRect rect;
  205. SDL_Texture *tface;
  206. SDL_Surface *referenceSurface = NULL;
  207. float tw, th;
  208. float i, j, ni, nj;
  209. int checkFailCount1;
  210. /* Clear surface. */
  211. clearScreen();
  212. /* Need drawcolor or just skip test. */
  213. SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor)");
  214. /* Create face surface. */
  215. tface = loadTestFace();
  216. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  217. if (tface == NULL) {
  218. return TEST_ABORTED;
  219. }
  220. /* Constant values. */
  221. CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
  222. rect.w = tw;
  223. rect.h = th;
  224. ni = TESTRENDER_SCREEN_W - tw;
  225. nj = TESTRENDER_SCREEN_H - th;
  226. /* Loop blit. */
  227. checkFailCount1 = 0;
  228. for (j = 0; j <= nj; j += 4) {
  229. for (i = 0; i <= ni; i += 4) {
  230. /* Blitting. */
  231. rect.x = i;
  232. rect.y = j;
  233. ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
  234. if (ret != 0) {
  235. checkFailCount1++;
  236. }
  237. }
  238. }
  239. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount1);
  240. /* See if it's the same */
  241. referenceSurface = SDLTest_ImageBlit();
  242. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  243. /* Make current */
  244. SDL_RenderPresent(renderer);
  245. /* Clean up. */
  246. SDL_DestroyTexture(tface);
  247. SDL_DestroySurface(referenceSurface);
  248. referenceSurface = NULL;
  249. return TEST_COMPLETED;
  250. }
  251. /**
  252. * Tests tiled blitting routines.
  253. */
  254. static int render_testBlitTiled(void *arg)
  255. {
  256. int ret;
  257. SDL_FRect rect;
  258. SDL_Texture *tface;
  259. SDL_Surface *referenceSurface = NULL;
  260. SDL_Surface *referenceSurface2x = NULL;
  261. /* Create face surface. */
  262. tface = loadTestFace();
  263. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  264. if (tface == NULL) {
  265. return TEST_ABORTED;
  266. }
  267. SDL_SetTextureScaleMode(tface, SDL_SCALEMODE_NEAREST); /* So 2x scaling is pixel perfect */
  268. /* Tiled blit - 1.0 scale */
  269. {
  270. /* Clear surface. */
  271. clearScreen();
  272. /* Tiled blit. */
  273. rect.x = 0.0f;
  274. rect.y = 0.0f;
  275. rect.w = (float)TESTRENDER_SCREEN_W;
  276. rect.h = (float)TESTRENDER_SCREEN_H;
  277. ret = SDL_RenderTextureTiled(renderer, tface, NULL, 1.0f, &rect);
  278. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret);
  279. /* See if it's the same */
  280. referenceSurface = SDLTest_ImageBlitTiled();
  281. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  282. /* Make current */
  283. SDL_RenderPresent(renderer);
  284. }
  285. /* Tiled blit - 2.0 scale */
  286. {
  287. /* Clear surface. */
  288. clearScreen();
  289. /* Tiled blit. */
  290. rect.x = 0.0f;
  291. rect.y = 0.0f;
  292. rect.w = (float)TESTRENDER_SCREEN_W * 2;
  293. rect.h = (float)TESTRENDER_SCREEN_H * 2;
  294. ret = SDL_RenderTextureTiled(renderer, tface, NULL, 2.0f, &rect);
  295. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTextureTiled, expected: 0, got: %i", ret);
  296. /* See if it's the same */
  297. referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
  298. SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
  299. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret);
  300. compare2x(referenceSurface2x, ALLOWABLE_ERROR_OPAQUE);
  301. /* Make current */
  302. SDL_RenderPresent(renderer);
  303. }
  304. /* Clean up. */
  305. SDL_DestroyTexture(tface);
  306. SDL_DestroySurface(referenceSurface);
  307. SDL_DestroySurface(referenceSurface2x);
  308. referenceSurface = NULL;
  309. return TEST_COMPLETED;
  310. }
  311. static const Uint8 COLOR_SEPARATION = 85;
  312. static void Fill9GridReferenceSurface(SDL_Surface *surface, int corner_size)
  313. {
  314. SDL_Rect rect;
  315. // Upper left
  316. rect.x = 0;
  317. rect.y = 0;
  318. rect.w = corner_size;
  319. rect.h = corner_size;
  320. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  321. // Top
  322. rect.x = corner_size;
  323. rect.y = 0;
  324. rect.w = surface->w - 2 * corner_size;
  325. rect.h = corner_size;
  326. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  327. // Upper right
  328. rect.x = surface->w - corner_size;
  329. rect.y = 0;
  330. rect.w = corner_size;
  331. rect.h = corner_size;
  332. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  333. // Left
  334. rect.x = 0;
  335. rect.y = corner_size;
  336. rect.w = corner_size;
  337. rect.h = surface->h - 2 * corner_size;
  338. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  339. // Center
  340. rect.x = corner_size;
  341. rect.y = corner_size;
  342. rect.w = surface->w - 2 * corner_size;
  343. rect.h = surface->h - 2 * corner_size;
  344. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  345. // Right
  346. rect.x = surface->w - corner_size;
  347. rect.y = corner_size;
  348. rect.w = corner_size;
  349. rect.h = surface->h - 2 * corner_size;
  350. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  351. // Lower left
  352. rect.x = 0;
  353. rect.y = surface->h - corner_size;
  354. rect.w = corner_size;
  355. rect.h = corner_size;
  356. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  357. // Bottom
  358. rect.x = corner_size;
  359. rect.y = surface->h - corner_size;
  360. rect.w = surface->w - 2 * corner_size;
  361. rect.h = corner_size;
  362. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  363. // Lower right
  364. rect.x = surface->w - corner_size;
  365. rect.y = surface->h - corner_size;
  366. rect.w = corner_size;
  367. rect.h = corner_size;
  368. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  369. }
  370. /**
  371. * Tests 9-grid blitting.
  372. */
  373. static int render_testBlit9Grid(void *arg)
  374. {
  375. SDL_Surface *referenceSurface = NULL;
  376. SDL_Surface *source = NULL;
  377. SDL_Texture *texture;
  378. int x, y;
  379. SDL_FRect rect;
  380. int ret = 0;
  381. /* Create source surface */
  382. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  383. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  384. for (y = 0; y < 3; ++y) {
  385. for (x = 0; x < 3; ++x) {
  386. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  387. }
  388. }
  389. texture = SDL_CreateTextureFromSurface(renderer, source);
  390. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  391. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  392. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_SetTextureScaleMode, expected: 0, got: %i", ret);
  393. /* 9-grid blit - 1.0 scale */
  394. {
  395. /* Create reference surface */
  396. SDL_DestroySurface(referenceSurface);
  397. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  398. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  399. Fill9GridReferenceSurface(referenceSurface, 1);
  400. /* Clear surface. */
  401. clearScreen();
  402. /* Tiled blit. */
  403. rect.x = 0.0f;
  404. rect.y = 0.0f;
  405. rect.w = (float)TESTRENDER_SCREEN_W;
  406. rect.h = (float)TESTRENDER_SCREEN_H;
  407. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, &rect);
  408. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret);
  409. /* See if it's the same */
  410. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  411. /* Make current */
  412. SDL_RenderPresent(renderer);
  413. }
  414. /* 9-grid blit - 2.0 scale */
  415. {
  416. /* Create reference surface */
  417. SDL_DestroySurface(referenceSurface);
  418. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  419. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  420. Fill9GridReferenceSurface(referenceSurface, 2);
  421. /* Clear surface. */
  422. clearScreen();
  423. /* Tiled blit. */
  424. rect.x = 0.0f;
  425. rect.y = 0.0f;
  426. rect.w = (float)TESTRENDER_SCREEN_W;
  427. rect.h = (float)TESTRENDER_SCREEN_H;
  428. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, &rect);
  429. SDLTest_AssertCheck(ret == 0, "Validate results from call to SDL_RenderTexture9Grid, expected: 0, got: %i", ret);
  430. /* See if it's the same */
  431. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  432. /* Make current */
  433. SDL_RenderPresent(renderer);
  434. }
  435. /* Clean up. */
  436. SDL_DestroySurface(referenceSurface);
  437. SDL_DestroySurface(source);
  438. SDL_DestroyTexture(texture);
  439. return TEST_COMPLETED;
  440. }
  441. /**
  442. * Blits doing color tests.
  443. *
  444. * \sa SDL_SetTextureColorMod
  445. * \sa SDL_RenderTexture
  446. * \sa SDL_DestroyTexture
  447. */
  448. static int render_testBlitColor(void *arg)
  449. {
  450. int ret;
  451. SDL_FRect rect;
  452. SDL_Texture *tface;
  453. SDL_Surface *referenceSurface = NULL;
  454. float tw, th;
  455. int i, j, ni, nj;
  456. int checkFailCount1;
  457. int checkFailCount2;
  458. /* Clear surface. */
  459. clearScreen();
  460. /* Create face surface. */
  461. tface = loadTestFace();
  462. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  463. if (tface == NULL) {
  464. return TEST_ABORTED;
  465. }
  466. /* Constant values. */
  467. CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
  468. rect.w = tw;
  469. rect.h = th;
  470. ni = TESTRENDER_SCREEN_W - (int)tw;
  471. nj = TESTRENDER_SCREEN_H - (int)th;
  472. /* Test blitting with color mod. */
  473. checkFailCount1 = 0;
  474. checkFailCount2 = 0;
  475. for (j = 0; j <= nj; j += 4) {
  476. for (i = 0; i <= ni; i += 4) {
  477. /* Set color mod. */
  478. ret = SDL_SetTextureColorMod(tface, (Uint8)((255 / nj) * j), (Uint8)((255 / ni) * i), (Uint8)((255 / nj) * j));
  479. if (ret != 0) {
  480. checkFailCount1++;
  481. }
  482. /* Blitting. */
  483. rect.x = (float)i;
  484. rect.y = (float)j;
  485. ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
  486. if (ret != 0) {
  487. checkFailCount2++;
  488. }
  489. }
  490. }
  491. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
  492. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount2);
  493. /* See if it's the same. */
  494. referenceSurface = SDLTest_ImageBlitColor();
  495. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  496. /* Make current */
  497. SDL_RenderPresent(renderer);
  498. /* Clean up. */
  499. SDL_DestroyTexture(tface);
  500. SDL_DestroySurface(referenceSurface);
  501. referenceSurface = NULL;
  502. return TEST_COMPLETED;
  503. }
  504. typedef enum TestRenderOperation
  505. {
  506. TEST_RENDER_POINT,
  507. TEST_RENDER_LINE,
  508. TEST_RENDER_RECT,
  509. TEST_RENDER_COPY_XRGB,
  510. TEST_RENDER_COPY_ARGB,
  511. } TestRenderOperation;
  512. /**
  513. * Helper that tests a specific operation and blend mode, -1 for color mod, -2 for alpha mod
  514. */
  515. static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFormat dst_format)
  516. {
  517. /* Allow up to 2 delta from theoretical value to account for rounding error.
  518. * We allow 2 rounding errors because the software renderer breaks drawing operations into alpha multiplication and a separate blend operation.
  519. */
  520. const int MAXIMUM_ERROR = 2;
  521. int ret;
  522. SDL_Texture *src = NULL;
  523. SDL_Texture *dst;
  524. SDL_Surface *result;
  525. Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
  526. Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
  527. Uint8 expectedR, expectedG, expectedB, expectedA;
  528. Uint8 actualR, actualG, actualB, actualA;
  529. int deltaR, deltaG, deltaB, deltaA;
  530. const char *operation = "UNKNOWN";
  531. const char *mode_name = "UNKNOWN";
  532. /* Create dst surface */
  533. dst = SDL_CreateTexture(renderer, dst_format, SDL_TEXTUREACCESS_TARGET, 3, 3);
  534. SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
  535. if (dst == NULL) {
  536. return;
  537. }
  538. if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
  539. SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
  540. ret = SDL_GetTextureBlendMode(dst, &blendMode);
  541. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_GetTextureBlendMode(), expected: 0, got: %i", ret);
  542. SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode);
  543. }
  544. /* Set as render target */
  545. SDL_SetRenderTarget(renderer, dst);
  546. /* Clear surface. */
  547. if (!SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
  548. dstA = 255;
  549. }
  550. ret = SDL_SetRenderDrawColor(renderer, dstR, dstG, dstB, dstA);
  551. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawColor(), expected: 0, got: %i", ret);
  552. ret = SDL_RenderClear(renderer);
  553. SDLTest_AssertPass("Call to SDL_RenderClear()");
  554. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_RenderClear, expected: 0, got: %i", ret);
  555. if (op == TEST_RENDER_COPY_XRGB || op == TEST_RENDER_COPY_ARGB) {
  556. Uint8 pixels[4];
  557. /* Create src surface */
  558. src = SDL_CreateTexture(renderer, op == TEST_RENDER_COPY_XRGB ? SDL_PIXELFORMAT_RGBX32 : SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 1, 1);
  559. SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
  560. if (src == NULL) {
  561. return;
  562. }
  563. /* Clear surface. */
  564. if (op == TEST_RENDER_COPY_XRGB) {
  565. srcA = 255;
  566. }
  567. pixels[0] = srcR;
  568. pixels[1] = srcG;
  569. pixels[2] = srcB;
  570. pixels[3] = srcA;
  571. SDL_UpdateTexture(src, NULL, pixels, sizeof(pixels));
  572. /* Set blend mode. */
  573. if (mode >= 0) {
  574. ret = SDL_SetTextureBlendMode(src, (SDL_BlendMode)mode);
  575. SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
  576. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: 0, got: %i", mode, ret);
  577. } else {
  578. ret = SDL_SetTextureBlendMode(src, SDL_BLENDMODE_BLEND);
  579. SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
  580. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: 0, got: %i", mode, ret);
  581. }
  582. } else {
  583. /* Set draw color */
  584. ret = SDL_SetRenderDrawColor(renderer, srcR, srcG, srcB, srcA);
  585. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawColor(), expected: 0, got: %i", ret);
  586. /* Set blend mode. */
  587. if (mode >= 0) {
  588. ret = SDL_SetRenderDrawBlendMode(renderer, (SDL_BlendMode)mode);
  589. SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
  590. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: 0, got: %i", mode, ret);
  591. } else {
  592. ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
  593. SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
  594. SDLTest_AssertCheck(ret == 0, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: 0, got: %i", mode, ret);
  595. }
  596. }
  597. /* Test blend mode. */
  598. #define FLOAT(X) ((float)X / 255.0f)
  599. switch (mode) {
  600. case -1:
  601. mode_name = "color modulation";
  602. ret = SDL_SetTextureColorMod(src, srcR, srcG, srcB);
  603. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", ret);
  604. expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  605. expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  606. expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  607. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  608. break;
  609. case -2:
  610. mode_name = "alpha modulation";
  611. ret = SDL_SetTextureAlphaMod(src, srcA);
  612. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_SetTextureAlphaMod, expected: 0, got: %i", ret);
  613. 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);
  614. 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);
  615. 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);
  616. expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  617. break;
  618. case SDL_BLENDMODE_NONE:
  619. mode_name = "SDL_BLENDMODE_NONE";
  620. expectedR = srcR;
  621. expectedG = srcG;
  622. expectedB = srcB;
  623. expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
  624. break;
  625. case SDL_BLENDMODE_BLEND:
  626. mode_name = "SDL_BLENDMODE_BLEND";
  627. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  628. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  629. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  630. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  631. break;
  632. case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
  633. mode_name = "SDL_BLENDMODE_BLEND_PREMULTIPLIED";
  634. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  635. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  636. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  637. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  638. break;
  639. case SDL_BLENDMODE_ADD:
  640. mode_name = "SDL_BLENDMODE_ADD";
  641. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  642. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  643. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  644. expectedA = dstA;
  645. break;
  646. case SDL_BLENDMODE_ADD_PREMULTIPLIED:
  647. mode_name = "SDL_BLENDMODE_ADD_PREMULTIPLIED";
  648. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  649. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  650. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  651. expectedA = dstA;
  652. break;
  653. case SDL_BLENDMODE_MOD:
  654. mode_name = "SDL_BLENDMODE_MOD";
  655. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  656. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  657. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  658. expectedA = dstA;
  659. break;
  660. case SDL_BLENDMODE_MUL:
  661. mode_name = "SDL_BLENDMODE_MUL";
  662. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  663. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  664. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  665. expectedA = dstA;
  666. break;
  667. default:
  668. SDLTest_LogError("Invalid blending mode: %d", mode);
  669. return;
  670. }
  671. switch (op) {
  672. case TEST_RENDER_POINT:
  673. operation = "render point";
  674. ret = SDL_RenderPoint(renderer, 0.0f, 0.0f);
  675. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret);
  676. break;
  677. case TEST_RENDER_LINE:
  678. operation = "render line";
  679. ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 2.0f, 2.0f);
  680. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderLine, expected: 0, got: %i", ret);
  681. break;
  682. case TEST_RENDER_RECT:
  683. operation = "render rect";
  684. ret = SDL_RenderFillRect(renderer, NULL);
  685. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret);
  686. break;
  687. case TEST_RENDER_COPY_XRGB:
  688. case TEST_RENDER_COPY_ARGB:
  689. operation = (op == TEST_RENDER_COPY_XRGB) ? "render XRGB" : "render ARGB";
  690. ret = SDL_RenderTexture(renderer, src, NULL, NULL);
  691. SDLTest_AssertCheck(ret == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", ret);
  692. break;
  693. default:
  694. SDLTest_LogError("Invalid blending operation: %d", op);
  695. return;
  696. }
  697. result = SDL_RenderReadPixels(renderer, NULL);
  698. SDL_ReadSurfacePixel(result, 0, 0, &actualR, &actualG, &actualB, &actualA);
  699. deltaR = SDL_abs((int)actualR - expectedR);
  700. deltaG = SDL_abs((int)actualG - expectedG);
  701. deltaB = SDL_abs((int)actualB - expectedB);
  702. deltaA = SDL_abs((int)actualA - expectedA);
  703. SDLTest_AssertCheck(
  704. deltaR <= MAXIMUM_ERROR &&
  705. deltaG <= MAXIMUM_ERROR &&
  706. deltaB <= MAXIMUM_ERROR &&
  707. deltaA <= MAXIMUM_ERROR,
  708. "Checking %s %s operation results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
  709. operation, mode_name,
  710. expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
  711. /* Clean up */
  712. SDL_DestroySurface(result);
  713. SDL_DestroyTexture(src);
  714. SDL_DestroyTexture(dst);
  715. }
  716. static void testBlendMode(int mode)
  717. {
  718. const TestRenderOperation operations[] = {
  719. TEST_RENDER_POINT,
  720. TEST_RENDER_LINE,
  721. TEST_RENDER_RECT,
  722. TEST_RENDER_COPY_XRGB,
  723. TEST_RENDER_COPY_ARGB
  724. };
  725. const SDL_PixelFormat dst_formats[] = {
  726. SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  727. };
  728. int i, j;
  729. for (i = 0; i < SDL_arraysize(operations); ++i) {
  730. for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
  731. TestRenderOperation op = operations[i];
  732. if (mode < 0) {
  733. if (op != TEST_RENDER_COPY_XRGB && op != TEST_RENDER_COPY_ARGB) {
  734. /* Unsupported mode for this operation */
  735. continue;
  736. }
  737. }
  738. testBlendModeOperation(op, mode, dst_formats[j]);
  739. }
  740. }
  741. }
  742. /**
  743. * Tests render operations with blend modes
  744. */
  745. static int render_testBlendModes(void *arg)
  746. {
  747. testBlendMode(-1);
  748. testBlendMode(-2);
  749. testBlendMode(SDL_BLENDMODE_NONE);
  750. testBlendMode(SDL_BLENDMODE_BLEND);
  751. testBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
  752. testBlendMode(SDL_BLENDMODE_ADD);
  753. testBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
  754. testBlendMode(SDL_BLENDMODE_MOD);
  755. testBlendMode(SDL_BLENDMODE_MUL);
  756. return TEST_COMPLETED;
  757. }
  758. /**
  759. * Test viewport
  760. */
  761. static int render_testViewport(void *arg)
  762. {
  763. SDL_Surface *referenceSurface;
  764. SDL_Rect viewport;
  765. viewport.x = TESTRENDER_SCREEN_W / 3;
  766. viewport.y = TESTRENDER_SCREEN_H / 3;
  767. viewport.w = TESTRENDER_SCREEN_W / 2;
  768. viewport.h = TESTRENDER_SCREEN_H / 2;
  769. /* Create expected result */
  770. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  771. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  772. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  773. /* Clear surface. */
  774. clearScreen();
  775. /* Set the viewport and do a fill operation */
  776. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  777. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  778. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  779. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  780. /* Check to see if final image matches. */
  781. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  782. /*
  783. * Verify that clear ignores the viewport
  784. */
  785. /* Create expected result */
  786. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
  787. /* Clear surface. */
  788. clearScreen();
  789. /* Set the viewport and do a clear operation */
  790. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  791. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  792. CHECK_FUNC(SDL_RenderClear, (renderer))
  793. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  794. /* Check to see if final image matches. */
  795. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  796. /* Make current */
  797. SDL_RenderPresent(renderer);
  798. SDL_DestroySurface(referenceSurface);
  799. return TEST_COMPLETED;
  800. }
  801. /**
  802. * Test clip rect
  803. */
  804. static int render_testClipRect(void *arg)
  805. {
  806. SDL_Surface *referenceSurface;
  807. SDL_Rect cliprect;
  808. cliprect.x = TESTRENDER_SCREEN_W / 3;
  809. cliprect.y = TESTRENDER_SCREEN_H / 3;
  810. cliprect.w = TESTRENDER_SCREEN_W / 2;
  811. cliprect.h = TESTRENDER_SCREEN_H / 2;
  812. /* Create expected result */
  813. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  814. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  815. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN))
  816. /* Clear surface. */
  817. clearScreen();
  818. /* Set the cliprect and do a fill operation */
  819. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
  820. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  821. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  822. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
  823. /* Check to see if final image matches. */
  824. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  825. /*
  826. * Verify that clear ignores the cliprect
  827. */
  828. /* Create expected result */
  829. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
  830. /* Clear surface. */
  831. clearScreen();
  832. /* Set the cliprect and do a clear operation */
  833. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
  834. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  835. CHECK_FUNC(SDL_RenderClear, (renderer))
  836. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
  837. /* Check to see if final image matches. */
  838. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  839. /* Make current */
  840. SDL_RenderPresent(renderer);
  841. SDL_DestroySurface(referenceSurface);
  842. return TEST_COMPLETED;
  843. }
  844. /**
  845. * Test logical size
  846. */
  847. static int render_testLogicalSize(void *arg)
  848. {
  849. SDL_Surface *referenceSurface;
  850. SDL_Rect viewport;
  851. SDL_FRect rect;
  852. int w, h;
  853. int set_w, set_h;
  854. SDL_RendererLogicalPresentation set_presentation_mode;
  855. SDL_ScaleMode set_scale_mode;
  856. SDL_FRect set_rect;
  857. const int factor = 2;
  858. viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor;
  859. viewport.y = ((TESTRENDER_SCREEN_H / 4) / factor) * factor;
  860. viewport.w = ((TESTRENDER_SCREEN_W / 2) / factor) * factor;
  861. viewport.h = ((TESTRENDER_SCREEN_H / 2) / factor) * factor;
  862. /* Create expected result */
  863. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  864. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  865. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  866. /* Clear surface. */
  867. clearScreen();
  868. /* Set the logical size and do a fill operation */
  869. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  870. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor,
  871. SDL_LOGICAL_PRESENTATION_LETTERBOX,
  872. SDL_SCALEMODE_NEAREST))
  873. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
  874. SDLTest_AssertCheck(
  875. set_w == (w / factor) &&
  876. set_h == (h / factor) &&
  877. set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX &&
  878. set_scale_mode == SDL_SCALEMODE_NEAREST,
  879. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
  880. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  881. SDLTest_AssertCheck(
  882. set_rect.x == 0.0f &&
  883. set_rect.y == 0.0f &&
  884. set_rect.w == 320.0f &&
  885. set_rect.h == 240.0f,
  886. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  887. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  888. rect.x = (float)viewport.x / factor;
  889. rect.y = (float)viewport.y / factor;
  890. rect.w = (float)viewport.w / factor;
  891. rect.h = (float)viewport.h / factor;
  892. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  893. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
  894. SDL_LOGICAL_PRESENTATION_DISABLED,
  895. SDL_SCALEMODE_NEAREST))
  896. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
  897. SDLTest_AssertCheck(
  898. set_w == 0 &&
  899. set_h == 0 &&
  900. set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED &&
  901. set_scale_mode == SDL_SCALEMODE_NEAREST,
  902. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
  903. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  904. SDLTest_AssertCheck(
  905. set_rect.x == 0.0f &&
  906. set_rect.y == 0.0f &&
  907. set_rect.w == 320.0f &&
  908. set_rect.h == 240.0f,
  909. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  910. /* Check to see if final image matches. */
  911. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  912. /* Clear surface. */
  913. clearScreen();
  914. /* Set the logical size and viewport and do a fill operation */
  915. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  916. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor,
  917. SDL_LOGICAL_PRESENTATION_LETTERBOX,
  918. SDL_SCALEMODE_NEAREST))
  919. viewport.x = (TESTRENDER_SCREEN_W / 4) / factor;
  920. viewport.y = (TESTRENDER_SCREEN_H / 4) / factor;
  921. viewport.w = (TESTRENDER_SCREEN_W / 2) / factor;
  922. viewport.h = (TESTRENDER_SCREEN_H / 2) / factor;
  923. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  924. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  925. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  926. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  927. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
  928. SDL_LOGICAL_PRESENTATION_DISABLED,
  929. SDL_SCALEMODE_NEAREST))
  930. /* Check to see if final image matches. */
  931. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  932. /*
  933. * Test a logical size that isn't the same aspect ratio as the window
  934. */
  935. viewport.x = (TESTRENDER_SCREEN_W / 4);
  936. viewport.y = 0;
  937. viewport.w = TESTRENDER_SCREEN_W;
  938. viewport.h = TESTRENDER_SCREEN_H;
  939. /* Create expected result */
  940. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  941. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  942. /* Clear surface. */
  943. clearScreen();
  944. /* Set the logical size and do a fill operation */
  945. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  946. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer,
  947. w - 2 * (TESTRENDER_SCREEN_W / 4),
  948. h,
  949. SDL_LOGICAL_PRESENTATION_LETTERBOX,
  950. SDL_SCALEMODE_LINEAR))
  951. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
  952. SDLTest_AssertCheck(
  953. set_w == w - 2 * (TESTRENDER_SCREEN_W / 4) &&
  954. set_h == h &&
  955. set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX &&
  956. set_scale_mode == SDL_SCALEMODE_LINEAR,
  957. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
  958. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  959. SDLTest_AssertCheck(
  960. set_rect.x == 20.0f &&
  961. set_rect.y == 0.0f &&
  962. set_rect.w == 280.0f &&
  963. set_rect.h == 240.0f,
  964. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  965. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  966. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  967. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0,
  968. SDL_LOGICAL_PRESENTATION_DISABLED,
  969. SDL_SCALEMODE_NEAREST))
  970. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode, &set_scale_mode))
  971. SDLTest_AssertCheck(
  972. set_w == 0 &&
  973. set_h == 0 &&
  974. set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED &&
  975. set_scale_mode == SDL_SCALEMODE_NEAREST,
  976. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d, %d", set_w, set_h, set_presentation_mode, set_scale_mode);
  977. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  978. SDLTest_AssertCheck(
  979. set_rect.x == 0.0f &&
  980. set_rect.y == 0.0f &&
  981. set_rect.w == 320.0f &&
  982. set_rect.h == 240.0f,
  983. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  984. /* Check to see if final image matches. */
  985. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  986. /* Clear surface. */
  987. clearScreen();
  988. /* Make current */
  989. SDL_RenderPresent(renderer);
  990. SDL_DestroySurface(referenceSurface);
  991. return TEST_COMPLETED;
  992. }
  993. /* Helper functions */
  994. /**
  995. * Checks to see if functionality is supported. Helper function.
  996. */
  997. static int
  998. isSupported(int code)
  999. {
  1000. return code == 0;
  1001. }
  1002. /**
  1003. * Test to see if we can vary the draw color. Helper function.
  1004. *
  1005. * \sa SDL_SetRenderDrawColor
  1006. * \sa SDL_GetRenderDrawColor
  1007. */
  1008. static int
  1009. hasDrawColor(void)
  1010. {
  1011. int ret, fail;
  1012. Uint8 r, g, b, a;
  1013. fail = 0;
  1014. /* Set color. */
  1015. ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100);
  1016. if (!isSupported(ret)) {
  1017. fail = 1;
  1018. }
  1019. ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
  1020. if (!isSupported(ret)) {
  1021. fail = 1;
  1022. }
  1023. /* Restore natural. */
  1024. ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  1025. if (!isSupported(ret)) {
  1026. fail = 1;
  1027. }
  1028. /* Something failed, consider not available. */
  1029. if (fail) {
  1030. return 0;
  1031. }
  1032. /* Not set properly, consider failed. */
  1033. else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) {
  1034. return 0;
  1035. }
  1036. return 1;
  1037. }
  1038. /**
  1039. * Loads the test image 'Face' as texture. Helper function.
  1040. *
  1041. * \sa SDL_CreateTextureFromSurface
  1042. */
  1043. static SDL_Texture *
  1044. loadTestFace(void)
  1045. {
  1046. SDL_Surface *face;
  1047. SDL_Texture *tface;
  1048. face = SDLTest_ImageFace();
  1049. if (!face) {
  1050. return NULL;
  1051. }
  1052. tface = SDL_CreateTextureFromSurface(renderer, face);
  1053. if (!tface) {
  1054. SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
  1055. }
  1056. SDL_DestroySurface(face);
  1057. return tface;
  1058. }
  1059. /**
  1060. * Compares screen pixels with image pixels. Helper function.
  1061. *
  1062. * \param referenceSurface Image to compare against.
  1063. * \param allowable_error allowed difference from the reference image
  1064. *
  1065. * \sa SDL_RenderReadPixels
  1066. * \sa SDL_CreateSurfaceFrom
  1067. * \sa SDL_DestroySurface
  1068. */
  1069. static void compare(SDL_Surface *referenceSurface, int allowable_error)
  1070. {
  1071. int ret;
  1072. SDL_Rect rect;
  1073. SDL_Surface *surface, *testSurface;
  1074. /* Explicitly specify the rect in case the window isn't the expected size... */
  1075. rect.x = 0;
  1076. rect.y = 0;
  1077. rect.w = TESTRENDER_SCREEN_W;
  1078. rect.h = TESTRENDER_SCREEN_H;
  1079. surface = SDL_RenderReadPixels(renderer, &rect);
  1080. if (!surface) {
  1081. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  1082. return;
  1083. }
  1084. testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
  1085. SDL_DestroySurface(surface);
  1086. if (!testSurface) {
  1087. SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
  1088. return;
  1089. }
  1090. /* Compare surface. */
  1091. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
  1092. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1093. /* Clean up. */
  1094. SDL_DestroySurface(testSurface);
  1095. }
  1096. static void compare2x(SDL_Surface *referenceSurface, int allowable_error)
  1097. {
  1098. int ret;
  1099. SDL_Rect rect;
  1100. SDL_Surface *surface, *testSurface;
  1101. /* Explicitly specify the rect in case the window isn't the expected size... */
  1102. rect.x = 0;
  1103. rect.y = 0;
  1104. rect.w = TESTRENDER_SCREEN_W * 2;
  1105. rect.h = TESTRENDER_SCREEN_H * 2;
  1106. surface = SDL_RenderReadPixels(renderer, &rect);
  1107. if (!surface) {
  1108. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  1109. return;
  1110. }
  1111. testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
  1112. SDL_DestroySurface(surface);
  1113. if (!testSurface) {
  1114. SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
  1115. return;
  1116. }
  1117. /* Compare surface. */
  1118. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
  1119. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1120. /* Clean up. */
  1121. SDL_DestroySurface(testSurface);
  1122. }
  1123. /**
  1124. * Clears the screen. Helper function.
  1125. *
  1126. * \sa SDL_SetRenderDrawColor
  1127. * \sa SDL_RenderClear
  1128. * \sa SDL_RenderPresent
  1129. * \sa SDL_SetRenderDrawBlendMode
  1130. */
  1131. static int
  1132. clearScreen(void)
  1133. {
  1134. int ret;
  1135. /* Make current */
  1136. SDL_RenderPresent(renderer);
  1137. /* Set color. */
  1138. ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  1139. SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
  1140. /* Clear screen. */
  1141. ret = SDL_RenderClear(renderer);
  1142. SDLTest_AssertCheck(ret == 0, "Validate result from SDL_RenderClear, expected: 0, got: %i", ret);
  1143. /* Set defaults. */
  1144. ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
  1145. SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawBlendMode, expected: 0, got: %i", ret);
  1146. ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
  1147. SDLTest_AssertCheck(ret == 0, "Validate result from SDL_SetRenderDrawColor, expected: 0, got: %i", ret);
  1148. return 0;
  1149. }
  1150. /**
  1151. * Tests geometry UV wrapping
  1152. */
  1153. static int render_testUVWrapping(void *arg)
  1154. {
  1155. SDL_Vertex vertices[6];
  1156. SDL_Vertex *verts = vertices;
  1157. SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
  1158. float tw, th;
  1159. SDL_FRect rect;
  1160. float min_U = -0.5f;
  1161. float max_U = 1.5f;
  1162. float min_V = -0.5f;
  1163. float max_V = 1.5f;
  1164. SDL_Texture *tface;
  1165. SDL_Surface *referenceSurface = NULL;
  1166. /* Clear surface. */
  1167. clearScreen();
  1168. /* Create face surface. */
  1169. tface = loadTestFace();
  1170. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  1171. if (tface == NULL) {
  1172. return TEST_ABORTED;
  1173. }
  1174. CHECK_FUNC(SDL_GetTextureSize, (tface, &tw, &th))
  1175. rect.w = tw * 2;
  1176. rect.h = th * 2;
  1177. rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
  1178. rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
  1179. /*
  1180. * 0--1
  1181. * | /|
  1182. * |/ |
  1183. * 3--2
  1184. *
  1185. * Draw sprite2 as triangles that can be recombined as rect by software renderer
  1186. */
  1187. /* 0 */
  1188. verts->position.x = rect.x;
  1189. verts->position.y = rect.y;
  1190. verts->color = color;
  1191. verts->tex_coord.x = min_U;
  1192. verts->tex_coord.y = min_V;
  1193. verts++;
  1194. /* 1 */
  1195. verts->position.x = rect.x + rect.w;
  1196. verts->position.y = rect.y;
  1197. verts->color = color;
  1198. verts->tex_coord.x = max_U;
  1199. verts->tex_coord.y = min_V;
  1200. verts++;
  1201. /* 2 */
  1202. verts->position.x = rect.x + rect.w;
  1203. verts->position.y = rect.y + rect.h;
  1204. verts->color = color;
  1205. verts->tex_coord.x = max_U;
  1206. verts->tex_coord.y = max_V;
  1207. verts++;
  1208. /* 0 */
  1209. verts->position.x = rect.x;
  1210. verts->position.y = rect.y;
  1211. verts->color = color;
  1212. verts->tex_coord.x = min_U;
  1213. verts->tex_coord.y = min_V;
  1214. verts++;
  1215. /* 2 */
  1216. verts->position.x = rect.x + rect.w;
  1217. verts->position.y = rect.y + rect.h;
  1218. verts->color = color;
  1219. verts->tex_coord.x = max_U;
  1220. verts->tex_coord.y = max_V;
  1221. verts++;
  1222. /* 3 */
  1223. verts->position.x = rect.x;
  1224. verts->position.y = rect.y + rect.h;
  1225. verts->color = color;
  1226. verts->tex_coord.x = min_U;
  1227. verts->tex_coord.y = max_V;
  1228. verts++;
  1229. /* Blit sprites as triangles onto the screen */
  1230. SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0);
  1231. /* See if it's the same */
  1232. referenceSurface = SDLTest_ImageWrappingSprite();
  1233. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1234. /* Make current */
  1235. SDL_RenderPresent(renderer);
  1236. /* Clean up. */
  1237. SDL_DestroyTexture(tface);
  1238. SDL_DestroySurface(referenceSurface);
  1239. referenceSurface = NULL;
  1240. return TEST_COMPLETED;
  1241. }
  1242. /* ================= Test References ================== */
  1243. /* Render test cases */
  1244. static const SDLTest_TestCaseReference renderTestGetNumRenderDrivers = {
  1245. (SDLTest_TestCaseFp)render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED
  1246. };
  1247. static const SDLTest_TestCaseReference renderTestPrimitives = {
  1248. (SDLTest_TestCaseFp)render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED
  1249. };
  1250. static const SDLTest_TestCaseReference renderTestPrimitivesWithViewport = {
  1251. (SDLTest_TestCaseFp)render_testPrimitivesWithViewport, "render_testPrimitivesWithViewport", "Tests rendering primitives within a viewport", TEST_ENABLED
  1252. };
  1253. static const SDLTest_TestCaseReference renderTestBlit = {
  1254. (SDLTest_TestCaseFp)render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED
  1255. };
  1256. static const SDLTest_TestCaseReference renderTestBlitTiled = {
  1257. (SDLTest_TestCaseFp)render_testBlitTiled, "render_testBlitTiled", "Tests tiled blitting", TEST_ENABLED
  1258. };
  1259. static const SDLTest_TestCaseReference renderTestBlit9Grid = {
  1260. (SDLTest_TestCaseFp)render_testBlit9Grid, "render_testBlit9Grid", "Tests 9-grid blitting", TEST_ENABLED
  1261. };
  1262. static const SDLTest_TestCaseReference renderTestBlitColor = {
  1263. (SDLTest_TestCaseFp)render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED
  1264. };
  1265. static const SDLTest_TestCaseReference renderTestBlendModes = {
  1266. (SDLTest_TestCaseFp)render_testBlendModes, "render_testBlendModes", "Tests rendering blend modes", TEST_ENABLED
  1267. };
  1268. static const SDLTest_TestCaseReference renderTestViewport = {
  1269. (SDLTest_TestCaseFp)render_testViewport, "render_testViewport", "Tests viewport", TEST_ENABLED
  1270. };
  1271. static const SDLTest_TestCaseReference renderTestClipRect = {
  1272. (SDLTest_TestCaseFp)render_testClipRect, "render_testClipRect", "Tests clip rect", TEST_ENABLED
  1273. };
  1274. static const SDLTest_TestCaseReference renderTestLogicalSize = {
  1275. (SDLTest_TestCaseFp)render_testLogicalSize, "render_testLogicalSize", "Tests logical size", TEST_ENABLED
  1276. };
  1277. static const SDLTest_TestCaseReference renderTestUVWrapping = {
  1278. (SDLTest_TestCaseFp)render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED
  1279. };
  1280. /* Sequence of Render test cases */
  1281. static const SDLTest_TestCaseReference *renderTests[] = {
  1282. &renderTestGetNumRenderDrivers,
  1283. &renderTestPrimitives,
  1284. &renderTestPrimitivesWithViewport,
  1285. &renderTestBlit,
  1286. &renderTestBlitTiled,
  1287. &renderTestBlit9Grid,
  1288. &renderTestBlitColor,
  1289. &renderTestBlendModes,
  1290. &renderTestViewport,
  1291. &renderTestClipRect,
  1292. &renderTestLogicalSize,
  1293. &renderTestUVWrapping,
  1294. NULL
  1295. };
  1296. /* Render test suite (global) */
  1297. SDLTest_TestSuiteReference renderTestSuite = {
  1298. "Render",
  1299. InitCreateRenderer,
  1300. renderTests,
  1301. CleanupDestroyRenderer
  1302. };