testautomation_render.c 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204
  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_WINDOW_W 320
  11. #define TESTRENDER_WINDOW_H 240
  12. #define TESTRENDER_SCREEN_W 80
  13. #define TESTRENDER_SCREEN_H 60
  14. #define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888
  15. #define RENDER_COLOR_CLEAR 0xFF000000
  16. #define RENDER_COLOR_GREEN 0xFF00FF00
  17. #define ALLOWABLE_ERROR_OPAQUE 0
  18. #define ALLOWABLE_ERROR_BLENDED 0
  19. #define CHECK_FUNC(FUNC, PARAMS) \
  20. { \
  21. bool result = FUNC PARAMS; \
  22. if (!result) { \
  23. SDLTest_AssertCheck(result, "Validate result from %s, expected: true, got: false, %s", #FUNC, SDL_GetError()); \
  24. } \
  25. }
  26. /* Test window and renderer */
  27. static SDL_Window *window = NULL;
  28. static SDL_Renderer *renderer = NULL;
  29. /* Prototypes for helper functions */
  30. static int clearScreen(void);
  31. static void compare(SDL_Surface *reference, int allowable_error);
  32. static void compare2x(SDL_Surface *reference, int allowable_error);
  33. static SDL_Texture *loadTestFace(void);
  34. static bool isSupported(int code);
  35. static bool hasDrawColor(void);
  36. /**
  37. * Create software renderer for tests
  38. */
  39. static void SDLCALL InitCreateRenderer(void **arg)
  40. {
  41. const char *renderer_name = NULL;
  42. renderer = NULL;
  43. window = SDL_CreateWindow("render_testCreateRenderer", TESTRENDER_WINDOW_W, TESTRENDER_WINDOW_H, 0);
  44. SDLTest_AssertPass("SDL_CreateWindow()");
  45. SDLTest_AssertCheck(window != NULL, "Check SDL_CreateWindow result");
  46. if (window == NULL) {
  47. return;
  48. }
  49. renderer = SDL_CreateRenderer(window, renderer_name);
  50. SDLTest_AssertPass("SDL_CreateRenderer()");
  51. SDLTest_AssertCheck(renderer != NULL, "Check SDL_CreateRenderer result: %s", renderer != NULL ? "success" : SDL_GetError());
  52. if (renderer == NULL) {
  53. SDL_DestroyWindow(window);
  54. return;
  55. }
  56. }
  57. /**
  58. * Destroy renderer for tests
  59. */
  60. static void SDLCALL CleanupDestroyRenderer(void *arg)
  61. {
  62. if (renderer) {
  63. SDL_DestroyRenderer(renderer);
  64. renderer = NULL;
  65. SDLTest_AssertPass("SDL_DestroyRenderer()");
  66. }
  67. if (window) {
  68. SDL_DestroyWindow(window);
  69. window = NULL;
  70. SDLTest_AssertPass("SDL_DestroyWindow");
  71. }
  72. }
  73. /**
  74. * Tests call to SDL_GetNumRenderDrivers
  75. *
  76. * \sa SDL_GetNumRenderDrivers
  77. */
  78. static int SDLCALL render_testGetNumRenderDrivers(void *arg)
  79. {
  80. int n;
  81. n = SDL_GetNumRenderDrivers();
  82. SDLTest_AssertCheck(n >= 1, "Number of renderers >= 1, reported as %i", n);
  83. return TEST_COMPLETED;
  84. }
  85. /**
  86. * Tests the SDL primitives for rendering.
  87. *
  88. * \sa SDL_SetRenderDrawColor
  89. * \sa SDL_RenderFillRect
  90. * \sa SDL_RenderLine
  91. *
  92. */
  93. static int SDLCALL render_testPrimitives(void *arg)
  94. {
  95. int ret;
  96. int x, y;
  97. SDL_FRect rect;
  98. SDL_Surface *referenceSurface = NULL;
  99. int checkFailCount1;
  100. int checkFailCount2;
  101. /* Clear surface. */
  102. clearScreen();
  103. /* Need drawcolor or just skip test. */
  104. SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor");
  105. /* Draw a rectangle. */
  106. rect.x = 40.0f;
  107. rect.y = 0.0f;
  108. rect.w = 40.0f;
  109. rect.h = 80.0f;
  110. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 13, 73, 200, SDL_ALPHA_OPAQUE))
  111. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  112. /* Draw a rectangle with negative width and height. */
  113. rect.x = 10.0f + 60.0f;
  114. rect.y = 10.0f + 40.0f;
  115. rect.w = -60.0f;
  116. rect.h = -40.0f;
  117. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 200, 0, 100, SDL_ALPHA_OPAQUE))
  118. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  119. /* Draw a rectangle with zero width and height. */
  120. rect.x = 10.0f;
  121. rect.y = 10.0f;
  122. rect.w = 0.0f;
  123. rect.h = 0.0f;
  124. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 0, 0, SDL_ALPHA_OPAQUE))
  125. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  126. /* Draw some points like so:
  127. * X.X.X.X..
  128. * .X.X.X.X.
  129. * X.X.X.X.. */
  130. checkFailCount1 = 0;
  131. checkFailCount2 = 0;
  132. for (y = 0; y < 3; y++) {
  133. for (x = y % 2; x < TESTRENDER_SCREEN_W; x += 2) {
  134. ret = SDL_SetRenderDrawColor(renderer, (Uint8)(x * y), (Uint8)(x * y / 2), (Uint8)(x * y / 3), SDL_ALPHA_OPAQUE);
  135. if (!ret) {
  136. checkFailCount1++;
  137. }
  138. ret = SDL_RenderPoint(renderer, (float)x, (float)y);
  139. if (!ret) {
  140. checkFailCount2++;
  141. }
  142. }
  143. }
  144. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i", checkFailCount1);
  145. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", checkFailCount2);
  146. /* Draw some lines. */
  147. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  148. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 30.0f, TESTRENDER_SCREEN_W, 30.0f))
  149. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 55, 55, 5, SDL_ALPHA_OPAQUE))
  150. CHECK_FUNC(SDL_RenderLine, (renderer, 40.0f, 30.0f, 40.0f, 60.0f))
  151. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 5, 105, 105, SDL_ALPHA_OPAQUE))
  152. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 29.0f, 29.0f))
  153. CHECK_FUNC(SDL_RenderLine, (renderer, 29.0f, 30.0f, 0.0f, 59.0f))
  154. CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 0.0f, 50.0f, 29.0f))
  155. CHECK_FUNC(SDL_RenderLine, (renderer, 79.0f, 59.0f, 50.0f, 30.0f))
  156. /* See if it's the same. */
  157. referenceSurface = SDLTest_ImagePrimitives();
  158. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  159. /* Make current */
  160. SDL_RenderPresent(renderer);
  161. /* Clean up. */
  162. SDL_DestroySurface(referenceSurface);
  163. referenceSurface = NULL;
  164. return TEST_COMPLETED;
  165. }
  166. /**
  167. * Tests the SDL primitives for rendering within a viewport.
  168. *
  169. * \sa SDL_SetRenderDrawColor
  170. * \sa SDL_RenderFillRect
  171. * \sa SDL_RenderLine
  172. *
  173. */
  174. static int SDLCALL render_testPrimitivesWithViewport(void *arg)
  175. {
  176. SDL_Rect viewport;
  177. SDL_Surface *surface;
  178. /* Clear surface. */
  179. clearScreen();
  180. viewport.x = 2;
  181. viewport.y = 2;
  182. viewport.w = 2;
  183. viewport.h = 2;
  184. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
  185. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 255, 255, SDL_ALPHA_OPAQUE))
  186. CHECK_FUNC(SDL_RenderLine, (renderer, 0.0f, 0.0f, 1.0f, 1.0f));
  187. viewport.x = 3;
  188. viewport.y = 3;
  189. viewport.w = 1;
  190. viewport.h = 1;
  191. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport));
  192. surface = SDL_RenderReadPixels(renderer, NULL);
  193. if (surface) {
  194. Uint8 r, g, b, a;
  195. CHECK_FUNC(SDL_ReadSurfacePixel, (surface, 0, 0, &r, &g, &b, &a));
  196. 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);
  197. SDL_DestroySurface(surface);
  198. } else {
  199. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  200. }
  201. return TEST_COMPLETED;
  202. }
  203. /**
  204. * Tests some blitting routines.
  205. *
  206. * \sa SDL_RenderTexture
  207. * \sa SDL_DestroyTexture
  208. */
  209. static int SDLCALL render_testBlit(void *arg)
  210. {
  211. int ret;
  212. SDL_FRect rect;
  213. SDL_Texture *tface;
  214. SDL_Surface *referenceSurface = NULL;
  215. int i, j, ni, nj;
  216. int checkFailCount1;
  217. /* Clear surface. */
  218. clearScreen();
  219. /* Need drawcolor or just skip test. */
  220. SDLTest_AssertCheck(hasDrawColor(), "hasDrawColor)");
  221. /* Create face surface. */
  222. tface = loadTestFace();
  223. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  224. if (tface == NULL) {
  225. return TEST_ABORTED;
  226. }
  227. /* Constant values. */
  228. rect.w = (float)tface->w;
  229. rect.h = (float)tface->h;
  230. ni = TESTRENDER_SCREEN_W - tface->w;
  231. nj = TESTRENDER_SCREEN_H - tface->h;
  232. /* Loop blit. */
  233. checkFailCount1 = 0;
  234. for (j = 0; j <= nj; j += 4) {
  235. for (i = 0; i <= ni; i += 4) {
  236. /* Blitting. */
  237. rect.x = (float)i;
  238. rect.y = (float)j;
  239. ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
  240. if (!ret) {
  241. checkFailCount1++;
  242. }
  243. }
  244. }
  245. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount1);
  246. /* See if it's the same */
  247. referenceSurface = SDLTest_ImageBlit();
  248. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  249. /* Make current */
  250. SDL_RenderPresent(renderer);
  251. /* Clean up. */
  252. SDL_DestroyTexture(tface);
  253. SDL_DestroySurface(referenceSurface);
  254. referenceSurface = NULL;
  255. return TEST_COMPLETED;
  256. }
  257. /**
  258. * Tests tiled blitting routines.
  259. */
  260. static int SDLCALL render_testBlitTiled(void *arg)
  261. {
  262. int ret;
  263. SDL_FRect rect;
  264. SDL_Texture *tface;
  265. SDL_Surface *referenceSurface = NULL;
  266. SDL_Surface *referenceSurface2x = NULL;
  267. /* Create face surface. */
  268. tface = loadTestFace();
  269. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  270. if (tface == NULL) {
  271. return TEST_ABORTED;
  272. }
  273. SDL_SetTextureScaleMode(tface, SDL_SCALEMODE_NEAREST); /* So 2x scaling is pixel perfect */
  274. /* Tiled blit - 1.0 scale */
  275. {
  276. /* Clear surface. */
  277. clearScreen();
  278. /* Tiled blit. */
  279. rect.x = 0.0f;
  280. rect.y = 0.0f;
  281. rect.w = (float)TESTRENDER_SCREEN_W;
  282. rect.h = (float)TESTRENDER_SCREEN_H;
  283. ret = SDL_RenderTextureTiled(renderer, tface, NULL, 1.0f, &rect);
  284. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i", ret);
  285. /* See if it's the same */
  286. referenceSurface = SDLTest_ImageBlitTiled();
  287. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  288. /* Make current */
  289. SDL_RenderPresent(renderer);
  290. }
  291. /* Tiled blit - 2.0 scale */
  292. {
  293. /* Clear surface. */
  294. clearScreen();
  295. /* Tiled blit. */
  296. rect.x = 0.0f;
  297. rect.y = 0.0f;
  298. rect.w = (float)TESTRENDER_SCREEN_W * 2;
  299. rect.h = (float)TESTRENDER_SCREEN_H * 2;
  300. ret = SDL_RenderTextureTiled(renderer, tface, NULL, 2.0f, &rect);
  301. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i", ret);
  302. /* See if it's the same */
  303. referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
  304. SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
  305. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i", ret);
  306. compare2x(referenceSurface2x, ALLOWABLE_ERROR_OPAQUE);
  307. /* Make current */
  308. SDL_RenderPresent(renderer);
  309. }
  310. /* Clean up. */
  311. SDL_DestroyTexture(tface);
  312. SDL_DestroySurface(referenceSurface);
  313. SDL_DestroySurface(referenceSurface2x);
  314. referenceSurface = NULL;
  315. return TEST_COMPLETED;
  316. }
  317. static const Uint8 COLOR_SEPARATION = 85;
  318. static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height)
  319. {
  320. SDL_Rect rect;
  321. // Upper left
  322. rect.x = 0;
  323. rect.y = 0;
  324. rect.w = left_width;
  325. rect.h = top_height;
  326. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  327. // Top
  328. rect.x = left_width;
  329. rect.y = 0;
  330. rect.w = surface->w - left_width - right_width;
  331. rect.h = top_height;
  332. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  333. // Upper right
  334. rect.x = surface->w - right_width;
  335. rect.y = 0;
  336. rect.w = right_width;
  337. rect.h = top_height;
  338. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  339. // Left
  340. rect.x = 0;
  341. rect.y = top_height;
  342. rect.w = left_width;
  343. rect.h = surface->h - top_height - bottom_height;
  344. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  345. // Center
  346. rect.x = left_width;
  347. rect.y = top_height;
  348. rect.w = surface->w - right_width - left_width;
  349. rect.h = surface->h - top_height - bottom_height;
  350. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  351. // Right
  352. rect.x = surface->w - right_width;
  353. rect.y = top_height;
  354. rect.w = right_width;
  355. rect.h = surface->h - top_height - bottom_height;
  356. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  357. // Lower left
  358. rect.x = 0;
  359. rect.y = surface->h - bottom_height;
  360. rect.w = left_width;
  361. rect.h = bottom_height;
  362. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  363. // Bottom
  364. rect.x = left_width;
  365. rect.y = surface->h - bottom_height;
  366. rect.w = surface->w - left_width - right_width;
  367. rect.h = bottom_height;
  368. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  369. // Lower right
  370. rect.x = surface->w - right_width;
  371. rect.y = surface->h - bottom_height;
  372. rect.w = right_width;
  373. rect.h = bottom_height;
  374. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  375. }
  376. /**
  377. * Tests 9-grid blitting.
  378. */
  379. static int SDLCALL render_testBlit9Grid(void *arg)
  380. {
  381. SDL_Surface *referenceSurface = NULL;
  382. SDL_Surface *source = NULL;
  383. SDL_Texture *texture;
  384. int x, y;
  385. SDL_FRect rect;
  386. int ret = 0;
  387. /* Create source surface */
  388. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  389. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  390. for (y = 0; y < 3; ++y) {
  391. for (x = 0; x < 3; ++x) {
  392. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  393. }
  394. }
  395. texture = SDL_CreateTextureFromSurface(renderer, source);
  396. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  397. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  398. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  399. /* 9-grid blit - 1.0 scale */
  400. {
  401. SDLTest_Log("9-grid blit - 1.0 scale");
  402. /* Create reference surface */
  403. SDL_DestroySurface(referenceSurface);
  404. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  405. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  406. Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
  407. /* Clear surface. */
  408. clearScreen();
  409. /* Tiled blit. */
  410. rect.x = 0.0f;
  411. rect.y = 0.0f;
  412. rect.w = (float)TESTRENDER_SCREEN_W;
  413. rect.h = (float)TESTRENDER_SCREEN_H;
  414. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect);
  415. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  416. /* See if it's the same */
  417. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  418. /* Make current */
  419. SDL_RenderPresent(renderer);
  420. }
  421. /* 9-grid blit - 2.0 scale */
  422. {
  423. SDLTest_Log("9-grid blit - 2.0 scale");
  424. /* Create reference surface */
  425. SDL_DestroySurface(referenceSurface);
  426. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  427. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  428. Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
  429. /* Clear surface. */
  430. clearScreen();
  431. /* Tiled blit. */
  432. rect.x = 0.0f;
  433. rect.y = 0.0f;
  434. rect.w = (float)TESTRENDER_SCREEN_W;
  435. rect.h = (float)TESTRENDER_SCREEN_H;
  436. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect);
  437. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  438. /* See if it's the same */
  439. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  440. /* Make current */
  441. SDL_RenderPresent(renderer);
  442. }
  443. /* Clean up. */
  444. SDL_DestroySurface(source);
  445. SDL_DestroyTexture(texture);
  446. /* Create complex source surface */
  447. source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
  448. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  449. SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  450. SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  451. SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  452. SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  453. SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  454. SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  455. SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  456. SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  457. SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  458. SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  459. SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  460. SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  461. SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  462. SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  463. SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  464. SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  465. SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  466. SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  467. SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  468. SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  469. SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  470. SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  471. SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  472. SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  473. SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  474. texture = SDL_CreateTextureFromSurface(renderer, source);
  475. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  476. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  477. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  478. /* complex 9-grid blit - 1.0 scale */
  479. {
  480. SDLTest_Log("complex 9-grid blit - 1.0 scale");
  481. /* Create reference surface */
  482. SDL_DestroySurface(referenceSurface);
  483. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  484. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  485. Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
  486. /* Clear surface. */
  487. clearScreen();
  488. /* Tiled blit. */
  489. rect.x = 0.0f;
  490. rect.y = 0.0f;
  491. rect.w = (float)TESTRENDER_SCREEN_W;
  492. rect.h = (float)TESTRENDER_SCREEN_H;
  493. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect);
  494. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  495. /* See if it's the same */
  496. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  497. /* Make current */
  498. SDL_RenderPresent(renderer);
  499. }
  500. /* complex 9-grid blit - 2.0 scale */
  501. {
  502. SDLTest_Log("complex 9-grid blit - 2.0 scale");
  503. /* Create reference surface */
  504. SDL_DestroySurface(referenceSurface);
  505. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  506. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  507. Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
  508. /* Clear surface. */
  509. clearScreen();
  510. /* Tiled blit. */
  511. rect.x = 0.0f;
  512. rect.y = 0.0f;
  513. rect.w = (float)TESTRENDER_SCREEN_W;
  514. rect.h = (float)TESTRENDER_SCREEN_H;
  515. ret = SDL_RenderTexture9Grid(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect);
  516. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i", ret);
  517. /* See if it's the same */
  518. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  519. /* Make current */
  520. SDL_RenderPresent(renderer);
  521. }
  522. /* Clean up. */
  523. SDL_DestroySurface(referenceSurface);
  524. SDL_DestroySurface(source);
  525. SDL_DestroyTexture(texture);
  526. return TEST_COMPLETED;
  527. }
  528. /**
  529. * Tests tiled 9-grid blitting.
  530. */
  531. static int SDLCALL render_testBlit9GridTiled(void *arg)
  532. {
  533. SDL_Surface *referenceSurface = NULL;
  534. SDL_Surface *source = NULL;
  535. SDL_Texture *texture;
  536. int x, y;
  537. SDL_FRect rect;
  538. int ret = 0;
  539. /* Create source surface */
  540. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  541. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  542. for (y = 0; y < 3; ++y) {
  543. for (x = 0; x < 3; ++x) {
  544. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  545. }
  546. }
  547. texture = SDL_CreateTextureFromSurface(renderer, source);
  548. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  549. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  550. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  551. /* Tiled 9-grid blit - 1.0 scale */
  552. {
  553. SDLTest_Log("tiled 9-grid blit - 1.0 scale");
  554. /* Create reference surface */
  555. SDL_DestroySurface(referenceSurface);
  556. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  557. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  558. Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
  559. /* Clear surface. */
  560. clearScreen();
  561. /* Tiled blit. */
  562. rect.x = 0.0f;
  563. rect.y = 0.0f;
  564. rect.w = (float)TESTRENDER_SCREEN_W;
  565. rect.h = (float)TESTRENDER_SCREEN_H;
  566. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, &rect, 1.0f);
  567. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  568. /* See if it's the same */
  569. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  570. /* Make current */
  571. SDL_RenderPresent(renderer);
  572. }
  573. /* Tiled 9-grid blit - 2.0 scale */
  574. {
  575. SDLTest_Log("tiled 9-grid blit - 2.0 scale");
  576. /* Create reference surface */
  577. SDL_DestroySurface(referenceSurface);
  578. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  579. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  580. Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
  581. /* Clear surface. */
  582. clearScreen();
  583. /* Tiled blit. */
  584. rect.x = 0.0f;
  585. rect.y = 0.0f;
  586. rect.w = (float)TESTRENDER_SCREEN_W;
  587. rect.h = (float)TESTRENDER_SCREEN_H;
  588. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, &rect, 2.0f);
  589. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  590. /* See if it's the same */
  591. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  592. /* Make current */
  593. SDL_RenderPresent(renderer);
  594. }
  595. /* Clean up. */
  596. SDL_DestroySurface(source);
  597. SDL_DestroyTexture(texture);
  598. /* Create complex source surface */
  599. source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
  600. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  601. SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  602. SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  603. SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  604. SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  605. SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  606. SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  607. SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  608. SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  609. SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  610. SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  611. SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  612. SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  613. SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  614. SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  615. SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  616. SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  617. SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  618. SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  619. SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  620. SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  621. SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  622. SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  623. SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  624. SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  625. SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  626. texture = SDL_CreateTextureFromSurface(renderer, source);
  627. SDLTest_AssertCheck(texture != NULL, "Verify source texture is not NULL");
  628. ret = SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  629. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i", ret);
  630. /* complex tiled 9-grid blit - 1.0 scale */
  631. {
  632. SDLTest_Log("complex tiled 9-grid blit - 1.0 scale");
  633. /* Create reference surface */
  634. SDL_DestroySurface(referenceSurface);
  635. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, SDL_PIXELFORMAT_RGBA32);
  636. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  637. Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
  638. /* Clear surface. */
  639. clearScreen();
  640. /* Tiled blit. */
  641. rect.x = 0.0f;
  642. rect.y = 0.0f;
  643. rect.w = (float)TESTRENDER_SCREEN_W;
  644. rect.h = (float)TESTRENDER_SCREEN_H;
  645. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 1.0f, &rect, 1.0f);
  646. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  647. /* See if it's the same */
  648. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  649. /* Make current */
  650. SDL_RenderPresent(renderer);
  651. }
  652. /* complex tiled 9-grid blit - 2.0 scale */
  653. {
  654. SDLTest_Log("complex tiled 9-grid blit - 2.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, 2, 4, 2, 4);
  660. /* Clear surface. */
  661. clearScreen();
  662. /* Tiled blit. */
  663. rect.x = 0.0f;
  664. rect.y = 0.0f;
  665. rect.w = (float)TESTRENDER_SCREEN_W;
  666. rect.h = (float)TESTRENDER_SCREEN_H;
  667. ret = SDL_RenderTexture9GridTiled(renderer, texture, NULL, 1.0f, 2.0f, 1.0f, 2.0f, 2.0f, &rect, 2.0f);
  668. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i", ret);
  669. /* See if it's the same */
  670. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  671. /* Make current */
  672. SDL_RenderPresent(renderer);
  673. }
  674. /* Clean up. */
  675. SDL_DestroySurface(referenceSurface);
  676. SDL_DestroySurface(source);
  677. SDL_DestroyTexture(texture);
  678. return TEST_COMPLETED;
  679. }
  680. /**
  681. * Blits doing color tests.
  682. *
  683. * \sa SDL_SetTextureColorMod
  684. * \sa SDL_RenderTexture
  685. * \sa SDL_DestroyTexture
  686. */
  687. static int SDLCALL render_testBlitColor(void *arg)
  688. {
  689. int ret;
  690. SDL_FRect rect;
  691. SDL_Texture *tface;
  692. SDL_Surface *referenceSurface = NULL;
  693. int i, j, ni, nj;
  694. int checkFailCount1;
  695. int checkFailCount2;
  696. /* Clear surface. */
  697. clearScreen();
  698. /* Create face surface. */
  699. tface = loadTestFace();
  700. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  701. if (tface == NULL) {
  702. return TEST_ABORTED;
  703. }
  704. /* Constant values. */
  705. rect.w = (float)tface->w;
  706. rect.h = (float)tface->h;
  707. ni = TESTRENDER_SCREEN_W - tface->w;
  708. nj = TESTRENDER_SCREEN_H - tface->h;
  709. /* Test blitting with color mod. */
  710. checkFailCount1 = 0;
  711. checkFailCount2 = 0;
  712. for (j = 0; j <= nj; j += 4) {
  713. for (i = 0; i <= ni; i += 4) {
  714. /* Set color mod. */
  715. ret = SDL_SetTextureColorMod(tface, (Uint8)((255 / nj) * j), (Uint8)((255 / ni) * i), (Uint8)((255 / nj) * j));
  716. if (!ret) {
  717. checkFailCount1++;
  718. }
  719. /* Blitting. */
  720. rect.x = (float)i;
  721. rect.y = (float)j;
  722. ret = SDL_RenderTexture(renderer, tface, NULL, &rect);
  723. if (!ret) {
  724. checkFailCount2++;
  725. }
  726. }
  727. }
  728. SDLTest_AssertCheck(checkFailCount1 == 0, "Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i", checkFailCount1);
  729. SDLTest_AssertCheck(checkFailCount2 == 0, "Validate results from calls to SDL_RenderTexture, expected: 0, got: %i", checkFailCount2);
  730. /* See if it's the same. */
  731. referenceSurface = SDLTest_ImageBlitColor();
  732. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  733. /* Make current */
  734. SDL_RenderPresent(renderer);
  735. /* Clean up. */
  736. SDL_DestroyTexture(tface);
  737. SDL_DestroySurface(referenceSurface);
  738. referenceSurface = NULL;
  739. return TEST_COMPLETED;
  740. }
  741. typedef enum TestRenderOperation
  742. {
  743. TEST_RENDER_POINT,
  744. TEST_RENDER_LINE,
  745. TEST_RENDER_RECT,
  746. TEST_RENDER_COPY_XRGB,
  747. TEST_RENDER_COPY_ARGB,
  748. } TestRenderOperation;
  749. /**
  750. * Helper that tests a specific operation and blend mode, -1 for color mod, -2 for alpha mod
  751. */
  752. static void testBlendModeOperation(TestRenderOperation op, int mode, SDL_PixelFormat dst_format)
  753. {
  754. /* Allow up to 2 delta from theoretical value to account for rounding error.
  755. * We allow 2 rounding errors because the software renderer breaks drawing operations into alpha multiplication and a separate blend operation.
  756. */
  757. const int MAXIMUM_ERROR = 2;
  758. int ret;
  759. SDL_Texture *src = NULL;
  760. SDL_Texture *dst;
  761. SDL_Surface *result;
  762. Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
  763. Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
  764. Uint8 expectedR, expectedG, expectedB, expectedA;
  765. Uint8 actualR, actualG, actualB, actualA;
  766. int deltaR, deltaG, deltaB, deltaA;
  767. const char *operation = "UNKNOWN";
  768. const char *mode_name = "UNKNOWN";
  769. /* Create dst surface */
  770. dst = SDL_CreateTexture(renderer, dst_format, SDL_TEXTUREACCESS_TARGET, 3, 3);
  771. SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
  772. if (dst == NULL) {
  773. return;
  774. }
  775. if (SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
  776. SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
  777. ret = SDL_GetTextureBlendMode(dst, &blendMode);
  778. SDLTest_AssertCheck(ret == true, "Verify result from SDL_GetTextureBlendMode(), expected: true, got: %i", ret);
  779. SDLTest_AssertCheck(blendMode == SDL_BLENDMODE_BLEND, "Verify alpha texture blend mode, expected %d, got %" SDL_PRIu32, SDL_BLENDMODE_BLEND, blendMode);
  780. }
  781. /* Set as render target */
  782. SDL_SetRenderTarget(renderer, dst);
  783. /* Clear surface. */
  784. if (!SDL_ISPIXELFORMAT_ALPHA(dst_format)) {
  785. dstA = 255;
  786. }
  787. ret = SDL_SetRenderDrawColor(renderer, dstR, dstG, dstB, dstA);
  788. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i", ret);
  789. ret = SDL_RenderClear(renderer);
  790. SDLTest_AssertPass("Call to SDL_RenderClear()");
  791. SDLTest_AssertCheck(ret == true, "Verify result from SDL_RenderClear, expected: true, got: %i", ret);
  792. if (op == TEST_RENDER_COPY_XRGB || op == TEST_RENDER_COPY_ARGB) {
  793. Uint8 pixels[4];
  794. /* Create src surface */
  795. src = SDL_CreateTexture(renderer, op == TEST_RENDER_COPY_XRGB ? SDL_PIXELFORMAT_RGBX32 : SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 1, 1);
  796. SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
  797. if (src == NULL) {
  798. return;
  799. }
  800. /* Clear surface. */
  801. if (op == TEST_RENDER_COPY_XRGB) {
  802. srcA = 255;
  803. }
  804. pixels[0] = srcR;
  805. pixels[1] = srcG;
  806. pixels[2] = srcB;
  807. pixels[3] = srcA;
  808. SDL_UpdateTexture(src, NULL, pixels, sizeof(pixels));
  809. /* Set blend mode. */
  810. if (mode >= 0) {
  811. ret = SDL_SetTextureBlendMode(src, (SDL_BlendMode)mode);
  812. SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
  813. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i", mode, ret);
  814. } else {
  815. ret = SDL_SetTextureBlendMode(src, SDL_BLENDMODE_BLEND);
  816. SDLTest_AssertPass("Call to SDL_SetTextureBlendMode()");
  817. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i", mode, ret);
  818. }
  819. } else {
  820. /* Set draw color */
  821. ret = SDL_SetRenderDrawColor(renderer, srcR, srcG, srcB, srcA);
  822. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i", ret);
  823. /* Set blend mode. */
  824. if (mode >= 0) {
  825. ret = SDL_SetRenderDrawBlendMode(renderer, (SDL_BlendMode)mode);
  826. SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
  827. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i", mode, ret);
  828. } else {
  829. ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
  830. SDLTest_AssertPass("Call to SDL_SetRenderDrawBlendMode()");
  831. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i", mode, ret);
  832. }
  833. }
  834. /* Test blend mode. */
  835. #define FLOAT(X) ((float)X / 255.0f)
  836. switch (mode) {
  837. case -1:
  838. mode_name = "color modulation";
  839. ret = SDL_SetTextureColorMod(src, srcR, srcG, srcB);
  840. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetTextureColorMod, expected: true, got: %i", ret);
  841. expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  842. expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  843. expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  844. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  845. break;
  846. case -2:
  847. mode_name = "alpha modulation";
  848. ret = SDL_SetTextureAlphaMod(src, srcA);
  849. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_SetTextureAlphaMod, expected: true, got: %i", ret);
  850. 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);
  851. 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);
  852. 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);
  853. expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  854. break;
  855. case SDL_BLENDMODE_NONE:
  856. mode_name = "SDL_BLENDMODE_NONE";
  857. expectedR = srcR;
  858. expectedG = srcG;
  859. expectedB = srcB;
  860. expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
  861. break;
  862. case SDL_BLENDMODE_BLEND:
  863. mode_name = "SDL_BLENDMODE_BLEND";
  864. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  865. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  866. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  867. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  868. break;
  869. case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
  870. mode_name = "SDL_BLENDMODE_BLEND_PREMULTIPLIED";
  871. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  872. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  873. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  874. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  875. break;
  876. case SDL_BLENDMODE_ADD:
  877. mode_name = "SDL_BLENDMODE_ADD";
  878. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  879. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  880. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  881. expectedA = dstA;
  882. break;
  883. case SDL_BLENDMODE_ADD_PREMULTIPLIED:
  884. mode_name = "SDL_BLENDMODE_ADD_PREMULTIPLIED";
  885. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  886. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  887. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  888. expectedA = dstA;
  889. break;
  890. case SDL_BLENDMODE_MOD:
  891. mode_name = "SDL_BLENDMODE_MOD";
  892. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  893. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  894. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  895. expectedA = dstA;
  896. break;
  897. case SDL_BLENDMODE_MUL:
  898. mode_name = "SDL_BLENDMODE_MUL";
  899. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  900. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  901. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  902. expectedA = dstA;
  903. break;
  904. default:
  905. SDLTest_LogError("Invalid blending mode: %d", mode);
  906. return;
  907. }
  908. switch (op) {
  909. case TEST_RENDER_POINT:
  910. operation = "render point";
  911. ret = SDL_RenderPoint(renderer, 0.0f, 0.0f);
  912. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderPoint, expected: 0, got: %i", ret);
  913. break;
  914. case TEST_RENDER_LINE:
  915. operation = "render line";
  916. ret = SDL_RenderLine(renderer, 0.0f, 0.0f, 2.0f, 2.0f);
  917. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderLine, expected: true, got: %i", ret);
  918. break;
  919. case TEST_RENDER_RECT:
  920. operation = "render rect";
  921. ret = SDL_RenderFillRect(renderer, NULL);
  922. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i", ret);
  923. break;
  924. case TEST_RENDER_COPY_XRGB:
  925. case TEST_RENDER_COPY_ARGB:
  926. operation = (op == TEST_RENDER_COPY_XRGB) ? "render XRGB" : "render ARGB";
  927. ret = SDL_RenderTexture(renderer, src, NULL, NULL);
  928. SDLTest_AssertCheck(ret == true, "Validate results from calls to SDL_RenderTexture, expected: true, got: %i", ret);
  929. break;
  930. default:
  931. SDLTest_LogError("Invalid blending operation: %d", op);
  932. return;
  933. }
  934. result = SDL_RenderReadPixels(renderer, NULL);
  935. SDL_ReadSurfacePixel(result, 0, 0, &actualR, &actualG, &actualB, &actualA);
  936. deltaR = SDL_abs((int)actualR - expectedR);
  937. deltaG = SDL_abs((int)actualG - expectedG);
  938. deltaB = SDL_abs((int)actualB - expectedB);
  939. deltaA = SDL_abs((int)actualA - expectedA);
  940. SDLTest_AssertCheck(
  941. deltaR <= MAXIMUM_ERROR &&
  942. deltaG <= MAXIMUM_ERROR &&
  943. deltaB <= MAXIMUM_ERROR &&
  944. deltaA <= MAXIMUM_ERROR,
  945. "Checking %s %s operation results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
  946. operation, mode_name,
  947. expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
  948. /* Clean up */
  949. SDL_DestroySurface(result);
  950. SDL_DestroyTexture(src);
  951. SDL_DestroyTexture(dst);
  952. }
  953. static void testBlendMode(int mode)
  954. {
  955. const TestRenderOperation operations[] = {
  956. TEST_RENDER_POINT,
  957. TEST_RENDER_LINE,
  958. TEST_RENDER_RECT,
  959. TEST_RENDER_COPY_XRGB,
  960. TEST_RENDER_COPY_ARGB
  961. };
  962. const SDL_PixelFormat dst_formats[] = {
  963. SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  964. };
  965. int i, j;
  966. for (i = 0; i < SDL_arraysize(operations); ++i) {
  967. for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
  968. TestRenderOperation op = operations[i];
  969. if (mode < 0) {
  970. if (op != TEST_RENDER_COPY_XRGB && op != TEST_RENDER_COPY_ARGB) {
  971. /* Unsupported mode for this operation */
  972. continue;
  973. }
  974. }
  975. testBlendModeOperation(op, mode, dst_formats[j]);
  976. }
  977. }
  978. }
  979. /**
  980. * Tests render operations with blend modes
  981. */
  982. static int SDLCALL render_testBlendModes(void *arg)
  983. {
  984. testBlendMode(-1);
  985. testBlendMode(-2);
  986. testBlendMode(SDL_BLENDMODE_NONE);
  987. testBlendMode(SDL_BLENDMODE_BLEND);
  988. testBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
  989. testBlendMode(SDL_BLENDMODE_ADD);
  990. testBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
  991. testBlendMode(SDL_BLENDMODE_MOD);
  992. testBlendMode(SDL_BLENDMODE_MUL);
  993. return TEST_COMPLETED;
  994. }
  995. /**
  996. * Test viewport
  997. */
  998. static int SDLCALL render_testViewport(void *arg)
  999. {
  1000. SDL_Surface *referenceSurface;
  1001. SDL_Rect viewport;
  1002. viewport.x = TESTRENDER_SCREEN_W / 3;
  1003. viewport.y = TESTRENDER_SCREEN_H / 3;
  1004. viewport.w = TESTRENDER_SCREEN_W / 2;
  1005. viewport.h = TESTRENDER_SCREEN_H / 2;
  1006. /* Create expected result */
  1007. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  1008. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1009. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  1010. /* Clear surface. */
  1011. clearScreen();
  1012. /* Set the viewport and do a fill operation */
  1013. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  1014. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1015. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1016. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  1017. /* Check to see if final image matches. */
  1018. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1019. /*
  1020. * Verify that clear ignores the viewport
  1021. */
  1022. /* Create expected result */
  1023. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
  1024. /* Clear surface. */
  1025. clearScreen();
  1026. /* Set the viewport and do a clear operation */
  1027. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  1028. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1029. CHECK_FUNC(SDL_RenderClear, (renderer))
  1030. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  1031. /* Check to see if final image matches. */
  1032. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1033. /* Make current */
  1034. SDL_RenderPresent(renderer);
  1035. SDL_DestroySurface(referenceSurface);
  1036. return TEST_COMPLETED;
  1037. }
  1038. static int SDLCALL render_testRGBSurfaceNoAlpha(void* arg)
  1039. {
  1040. SDL_Surface *surface;
  1041. SDL_Renderer *software_renderer;
  1042. SDL_Surface *surface2;
  1043. SDL_Texture *texture2;
  1044. bool result;
  1045. SDL_FRect dest_rect;
  1046. SDL_FPoint point;
  1047. const SDL_PixelFormatDetails *format_details;
  1048. Uint8 r, g, b, a;
  1049. SDLTest_AssertPass("About to call SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32)");
  1050. surface = SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32);
  1051. SDLTest_AssertCheck(surface != NULL, "Returned surface must be not NULL");
  1052. if (surface == NULL) {
  1053. return TEST_ABORTED;
  1054. }
  1055. SDLTest_AssertPass("About to call SDL_GetPixelFormatDetails(surface->format)");
  1056. format_details = SDL_GetPixelFormatDetails(surface->format);
  1057. SDLTest_AssertCheck(format_details != NULL, "Result must be non-NULL, is %p", format_details);
  1058. if (format_details == NULL) {
  1059. SDL_DestroySurface(surface);
  1060. return TEST_ABORTED;
  1061. }
  1062. SDLTest_AssertCheck(format_details->bits_per_pixel == 32, "format_details->bits_per_pixel is %d, should be %d", format_details->bits_per_pixel, 32);
  1063. SDLTest_AssertCheck(format_details->bytes_per_pixel == 4, "format_details->bytes_per_pixel is %d, should be %d", format_details->bytes_per_pixel, 4);
  1064. SDLTest_AssertPass("About to call SDL_CreateSoftwareRenderer(surface)");
  1065. software_renderer = SDL_CreateSoftwareRenderer(surface);
  1066. SDLTest_AssertCheck(software_renderer != NULL, "Returned renderer must be not NULL");
  1067. if (software_renderer == NULL) {
  1068. SDL_DestroySurface(surface);
  1069. return TEST_ABORTED;
  1070. }
  1071. SDLTest_AssertPass("About to call SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32)");
  1072. surface2 = SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32);
  1073. SDLTest_AssertCheck(surface2 != NULL, "Returned surface must be not NULL");
  1074. if (surface2 == NULL) {
  1075. SDL_DestroySurface(surface);
  1076. SDL_DestroyRenderer(software_renderer);
  1077. return TEST_ABORTED;
  1078. }
  1079. SDLTest_AssertPass("About to call SDL_FillRect(surface2, NULL, 0)");
  1080. result = SDL_FillSurfaceRect(surface2, NULL, SDL_MapRGB(SDL_GetPixelFormatDetails(surface2->format), NULL, 0, 0, 0));
  1081. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1082. SDLTest_AssertPass("About to call SDL_CreateTextureFromSurface(software_renderer, surface2)");
  1083. texture2 = SDL_CreateTextureFromSurface(software_renderer, surface2);
  1084. SDLTest_AssertCheck(texture2 != NULL, "Returned texture is not NULL");
  1085. SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0xaa, 0xbb, 0xcc, 0x0)");
  1086. result = SDL_SetRenderDrawColor(software_renderer, 0xaa, 0xbb, 0xcc, 0x0);
  1087. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1088. SDLTest_AssertPass("About to call SDL_RenderClear(renderer)");
  1089. result = SDL_RenderClear(software_renderer);
  1090. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1091. SDLTest_AssertPass("About to call SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0x0)");
  1092. result = SDL_SetRenderDrawColor(software_renderer, 0x0, 0x0, 0x0, 0x0);
  1093. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1094. dest_rect.x = 32;
  1095. dest_rect.y = 32;
  1096. dest_rect.w = (float)surface2->w;
  1097. dest_rect.h = (float)surface2->h;
  1098. point.x = 0;
  1099. point.y = 0;
  1100. SDLTest_AssertPass("About to call SDL_RenderCopy(software_renderer, texture, NULL, &{%g, %g, %g, %g})",
  1101. dest_rect.x, dest_rect.h, dest_rect.w, dest_rect.h);
  1102. result = SDL_RenderTextureRotated(software_renderer, texture2, NULL, &dest_rect, 180, &point, SDL_FLIP_NONE);
  1103. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1104. SDLTest_AssertPass("About to call SDL_RenderPresent(software_renderer)");
  1105. SDL_RenderPresent(software_renderer);
  1106. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(0, 0)");
  1107. result = SDL_ReadSurfacePixel(surface, 0, 0, &r, &g, &b, &a);
  1108. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1109. SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE,
  1110. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1111. r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE);
  1112. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(15, 15)");
  1113. result = SDL_ReadSurfacePixel(surface, 15, 15, &r, &g, &b, &a);
  1114. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1115. SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE,
  1116. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1117. r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE);
  1118. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(16, 16)");
  1119. result = SDL_ReadSurfacePixel(surface, 16, 16, &r, &g, &b, &a);
  1120. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1121. SDLTest_AssertCheck(r == 0x00 && g == 0x00 && b == 0x00 && a == SDL_ALPHA_OPAQUE,
  1122. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1123. r, g, b, a, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
  1124. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(31, 31)");
  1125. result = SDL_ReadSurfacePixel(surface, 31, 31, &r, &g, &b, &a);
  1126. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1127. SDLTest_AssertCheck(r == 0x00 && g == 0x00 && b == 0x00 && a == SDL_ALPHA_OPAQUE,
  1128. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1129. r, g, b, a, 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE);
  1130. SDLTest_AssertPass("About to call SDL_ReadSurfacePixel(32, 32)");
  1131. result = SDL_ReadSurfacePixel(surface, 32, 32, &r, &g, &b, &a);
  1132. SDLTest_AssertCheck(result == true, "Result is %d, should be %d", result, true);
  1133. SDLTest_AssertCheck(r == 0xaa && g == 0xbb && b == 0xcc && a == SDL_ALPHA_OPAQUE,
  1134. "Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x}",
  1135. r, g, b, a, 0xaa, 0xbb, 0xcc, SDL_ALPHA_OPAQUE);
  1136. SDL_DestroyTexture(texture2);
  1137. SDL_DestroySurface(surface2);
  1138. SDL_DestroyRenderer(software_renderer);
  1139. SDL_DestroySurface(surface);
  1140. return TEST_COMPLETED;
  1141. }
  1142. /**
  1143. * Test clip rect
  1144. */
  1145. static int SDLCALL render_testClipRect(void *arg)
  1146. {
  1147. SDL_Surface *referenceSurface;
  1148. SDL_Rect cliprect;
  1149. cliprect.x = TESTRENDER_SCREEN_W / 3;
  1150. cliprect.y = TESTRENDER_SCREEN_H / 3;
  1151. cliprect.w = TESTRENDER_SCREEN_W / 2;
  1152. cliprect.h = TESTRENDER_SCREEN_H / 2;
  1153. /* Create expected result */
  1154. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  1155. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1156. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &cliprect, RENDER_COLOR_GREEN))
  1157. /* Clear surface. */
  1158. clearScreen();
  1159. /* Set the cliprect and do a fill operation */
  1160. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
  1161. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1162. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1163. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
  1164. /* Check to see if final image matches. */
  1165. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1166. /*
  1167. * Verify that clear ignores the cliprect
  1168. */
  1169. /* Create expected result */
  1170. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_GREEN))
  1171. /* Clear surface. */
  1172. clearScreen();
  1173. /* Set the cliprect and do a clear operation */
  1174. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
  1175. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1176. CHECK_FUNC(SDL_RenderClear, (renderer))
  1177. CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
  1178. /* Check to see if final image matches. */
  1179. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1180. /* Make current */
  1181. SDL_RenderPresent(renderer);
  1182. SDL_DestroySurface(referenceSurface);
  1183. return TEST_COMPLETED;
  1184. }
  1185. /**
  1186. * Test logical size
  1187. */
  1188. static int SDLCALL render_testLogicalSize(void *arg)
  1189. {
  1190. SDL_Surface *referenceSurface;
  1191. SDL_Rect viewport;
  1192. SDL_FRect rect;
  1193. int w = 0, h = 0;
  1194. int set_w, set_h;
  1195. SDL_RendererLogicalPresentation set_presentation_mode;
  1196. SDL_FRect set_rect;
  1197. const int factor = 2;
  1198. SDL_GetWindowSize(window, &w, &h);
  1199. if (w != TESTRENDER_WINDOW_W || h != TESTRENDER_WINDOW_H) {
  1200. SDLTest_Log("Skipping test render_testLogicalSize: expected window %dx%d, got %dx%d", TESTRENDER_WINDOW_W, TESTRENDER_WINDOW_H, w, h);
  1201. return TEST_SKIPPED;
  1202. }
  1203. viewport.x = ((TESTRENDER_SCREEN_W / 4) / factor) * factor;
  1204. viewport.y = ((TESTRENDER_SCREEN_H / 4) / factor) * factor;
  1205. viewport.w = ((TESTRENDER_SCREEN_W / 2) / factor) * factor;
  1206. viewport.h = ((TESTRENDER_SCREEN_H / 2) / factor) * factor;
  1207. /* Create expected result */
  1208. referenceSurface = SDL_CreateSurface(TESTRENDER_SCREEN_W, TESTRENDER_SCREEN_H, RENDER_COMPARE_FORMAT);
  1209. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1210. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  1211. /* Clear surface. */
  1212. clearScreen();
  1213. /* Set the logical size and do a fill operation */
  1214. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  1215. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX))
  1216. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1217. SDLTest_AssertCheck(
  1218. set_w == (w / factor) &&
  1219. set_h == (h / factor) &&
  1220. set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX,
  1221. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1222. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1223. SDLTest_AssertCheck(
  1224. set_rect.x == 0.0f &&
  1225. set_rect.y == 0.0f &&
  1226. set_rect.w == (float)w &&
  1227. set_rect.h == (float)h,
  1228. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1229. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1230. rect.x = (float)viewport.x / factor;
  1231. rect.y = (float)viewport.y / factor;
  1232. rect.w = (float)viewport.w / factor;
  1233. rect.h = (float)viewport.h / factor;
  1234. CHECK_FUNC(SDL_RenderFillRect, (renderer, &rect))
  1235. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
  1236. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1237. SDLTest_AssertCheck(
  1238. set_w == 0 &&
  1239. set_h == 0 &&
  1240. set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED,
  1241. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1242. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1243. SDLTest_AssertCheck(
  1244. set_rect.x == 0.0f &&
  1245. set_rect.y == 0.0f &&
  1246. set_rect.w == (float)w &&
  1247. set_rect.h == (float)h,
  1248. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1249. /* Check to see if final image matches. */
  1250. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1251. /* Clear surface. */
  1252. clearScreen();
  1253. /* Set the logical size and viewport and do a fill operation */
  1254. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  1255. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, w / factor, h / factor, SDL_LOGICAL_PRESENTATION_LETTERBOX))
  1256. viewport.x = (TESTRENDER_SCREEN_W / 4) / factor;
  1257. viewport.y = (TESTRENDER_SCREEN_H / 4) / factor;
  1258. viewport.w = (TESTRENDER_SCREEN_W / 2) / factor;
  1259. viewport.h = (TESTRENDER_SCREEN_H / 2) / factor;
  1260. CHECK_FUNC(SDL_SetRenderViewport, (renderer, &viewport))
  1261. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1262. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1263. CHECK_FUNC(SDL_SetRenderViewport, (renderer, NULL))
  1264. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
  1265. /* Check to see if final image matches. */
  1266. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1267. /*
  1268. * Test a logical size that isn't the same aspect ratio as the window
  1269. */
  1270. viewport.x = (TESTRENDER_SCREEN_W / 4);
  1271. viewport.y = 0;
  1272. viewport.w = TESTRENDER_SCREEN_W;
  1273. viewport.h = TESTRENDER_SCREEN_H;
  1274. /* Create expected result */
  1275. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, NULL, RENDER_COLOR_CLEAR))
  1276. CHECK_FUNC(SDL_FillSurfaceRect, (referenceSurface, &viewport, RENDER_COLOR_GREEN))
  1277. /* Clear surface. */
  1278. clearScreen();
  1279. /* Set the logical size and do a fill operation */
  1280. CHECK_FUNC(SDL_GetCurrentRenderOutputSize, (renderer, &w, &h))
  1281. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer,
  1282. w - 2 * (TESTRENDER_SCREEN_W / 4),
  1283. h,
  1284. SDL_LOGICAL_PRESENTATION_LETTERBOX))
  1285. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1286. SDLTest_AssertCheck(
  1287. set_w == w - 2 * (TESTRENDER_SCREEN_W / 4) &&
  1288. set_h == h &&
  1289. set_presentation_mode == SDL_LOGICAL_PRESENTATION_LETTERBOX,
  1290. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1291. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1292. SDLTest_AssertCheck(
  1293. set_rect.x == 20.0f &&
  1294. set_rect.y == 0.0f &&
  1295. set_rect.w == 280.0f &&
  1296. set_rect.h == 240.0f,
  1297. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1298. CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 0, 255, 0, SDL_ALPHA_OPAQUE))
  1299. CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
  1300. CHECK_FUNC(SDL_SetRenderLogicalPresentation, (renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED))
  1301. CHECK_FUNC(SDL_GetRenderLogicalPresentation, (renderer, &set_w, &set_h, &set_presentation_mode))
  1302. SDLTest_AssertCheck(
  1303. set_w == 0 &&
  1304. set_h == 0 &&
  1305. set_presentation_mode == SDL_LOGICAL_PRESENTATION_DISABLED,
  1306. "Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d", set_w, set_h, set_presentation_mode);
  1307. CHECK_FUNC(SDL_GetRenderLogicalPresentationRect, (renderer, &set_rect))
  1308. SDLTest_AssertCheck(
  1309. set_rect.x == 0.0f &&
  1310. set_rect.y == 0.0f &&
  1311. set_rect.w == 320.0f &&
  1312. set_rect.h == 240.0f,
  1313. "Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g}", set_rect.x, set_rect.y, set_rect.w, set_rect.h);
  1314. /* Check to see if final image matches. */
  1315. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1316. /* Clear surface. */
  1317. clearScreen();
  1318. /* Make current */
  1319. SDL_RenderPresent(renderer);
  1320. SDL_DestroySurface(referenceSurface);
  1321. return TEST_COMPLETED;
  1322. }
  1323. /**
  1324. * @brief Tests setting and getting texture scale mode.
  1325. *
  1326. * \sa
  1327. * http://wiki.libsdl.org/SDL2/SDL_SetTextureScaleMode
  1328. * http://wiki.libsdl.org/SDL2/SDL_GetTextureScaleMode
  1329. */
  1330. static int SDLCALL render_testGetSetTextureScaleMode(void *arg)
  1331. {
  1332. const struct {
  1333. const char *name;
  1334. SDL_ScaleMode mode;
  1335. } modes[] = {
  1336. { "SDL_SCALEMODE_NEAREST", SDL_SCALEMODE_NEAREST },
  1337. { "SDL_SCALEMODE_LINEAR", SDL_SCALEMODE_LINEAR },
  1338. { "SDL_SCALEMODE_PIXELART", SDL_SCALEMODE_PIXELART },
  1339. };
  1340. size_t i;
  1341. for (i = 0; i < SDL_arraysize(modes); i++) {
  1342. SDL_Texture *texture;
  1343. bool result;
  1344. SDL_ScaleMode actual_mode = SDL_SCALEMODE_NEAREST;
  1345. SDL_ClearError();
  1346. SDLTest_AssertPass("About to call SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16)");
  1347. texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16);
  1348. SDLTest_AssertCheck(texture != NULL, "SDL_CreateTexture must return a non-NULL texture");
  1349. SDLTest_AssertPass("About to call SDL_SetTextureScaleMode(texture, %s)", modes[i].name);
  1350. result = SDL_SetTextureScaleMode(texture, modes[i].mode);
  1351. SDLTest_AssertCheck(result == true, "SDL_SetTextureScaleMode returns %d, expected %d", result, true);
  1352. SDLTest_AssertPass("About to call SDL_GetTextureScaleMode(texture)");
  1353. result = SDL_GetTextureScaleMode(texture, &actual_mode);
  1354. SDLTest_AssertCheck(result == true, "SDL_SetTextureScaleMode returns %d, expected %d", result, true);
  1355. SDLTest_AssertCheck(actual_mode == modes[i].mode, "SDL_GetTextureScaleMode must return %s (%d), actual=%d",
  1356. modes[i].name, modes[i].mode, actual_mode);
  1357. }
  1358. return TEST_COMPLETED;
  1359. }
  1360. /* Helper functions */
  1361. /**
  1362. * Checks to see if functionality is supported. Helper function.
  1363. */
  1364. static bool isSupported(int code)
  1365. {
  1366. return (code != false);
  1367. }
  1368. /**
  1369. * Test to see if we can vary the draw color. Helper function.
  1370. *
  1371. * \sa SDL_SetRenderDrawColor
  1372. * \sa SDL_GetRenderDrawColor
  1373. */
  1374. static bool hasDrawColor(void)
  1375. {
  1376. int ret, fail;
  1377. Uint8 r, g, b, a;
  1378. fail = 0;
  1379. /* Set color. */
  1380. ret = SDL_SetRenderDrawColor(renderer, 100, 100, 100, 100);
  1381. if (!isSupported(ret)) {
  1382. fail = 1;
  1383. }
  1384. ret = SDL_GetRenderDrawColor(renderer, &r, &g, &b, &a);
  1385. if (!isSupported(ret)) {
  1386. fail = 1;
  1387. }
  1388. /* Restore natural. */
  1389. ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  1390. if (!isSupported(ret)) {
  1391. fail = 1;
  1392. }
  1393. /* Something failed, consider not available. */
  1394. if (fail) {
  1395. return false;
  1396. }
  1397. /* Not set properly, consider failed. */
  1398. else if ((r != 100) || (g != 100) || (b != 100) || (a != 100)) {
  1399. return false;
  1400. }
  1401. return true;
  1402. }
  1403. /**
  1404. * Loads the test image 'Face' as texture. Helper function.
  1405. *
  1406. * \sa SDL_CreateTextureFromSurface
  1407. */
  1408. static SDL_Texture *
  1409. loadTestFace(void)
  1410. {
  1411. SDL_Surface *face;
  1412. SDL_Texture *tface;
  1413. face = SDLTest_ImageFace();
  1414. if (!face) {
  1415. return NULL;
  1416. }
  1417. tface = SDL_CreateTextureFromSurface(renderer, face);
  1418. if (!tface) {
  1419. SDLTest_LogError("SDL_CreateTextureFromSurface() failed with error: %s", SDL_GetError());
  1420. }
  1421. SDL_DestroySurface(face);
  1422. return tface;
  1423. }
  1424. /**
  1425. * Compares screen pixels with image pixels. Helper function.
  1426. *
  1427. * \param referenceSurface Image to compare against.
  1428. * \param allowable_error allowed difference from the reference image
  1429. *
  1430. * \sa SDL_RenderReadPixels
  1431. * \sa SDL_CreateSurfaceFrom
  1432. * \sa SDL_DestroySurface
  1433. */
  1434. static void compare(SDL_Surface *referenceSurface, int allowable_error)
  1435. {
  1436. int ret;
  1437. SDL_Rect rect;
  1438. SDL_Surface *surface, *testSurface;
  1439. /* Explicitly specify the rect in case the window isn't the expected size... */
  1440. rect.x = 0;
  1441. rect.y = 0;
  1442. rect.w = TESTRENDER_SCREEN_W;
  1443. rect.h = TESTRENDER_SCREEN_H;
  1444. surface = SDL_RenderReadPixels(renderer, &rect);
  1445. if (!surface) {
  1446. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  1447. return;
  1448. }
  1449. testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
  1450. SDL_DestroySurface(surface);
  1451. if (!testSurface) {
  1452. SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
  1453. return;
  1454. }
  1455. /* Compare surface. */
  1456. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
  1457. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1458. /* Clean up. */
  1459. SDL_DestroySurface(testSurface);
  1460. }
  1461. static void compare2x(SDL_Surface *referenceSurface, int allowable_error)
  1462. {
  1463. int ret;
  1464. SDL_Rect rect;
  1465. SDL_Surface *surface, *testSurface;
  1466. /* Explicitly specify the rect in case the window isn't the expected size... */
  1467. rect.x = 0;
  1468. rect.y = 0;
  1469. rect.w = TESTRENDER_SCREEN_W * 2;
  1470. rect.h = TESTRENDER_SCREEN_H * 2;
  1471. surface = SDL_RenderReadPixels(renderer, &rect);
  1472. if (!surface) {
  1473. SDLTest_AssertCheck(surface != NULL, "Validate result from SDL_RenderReadPixels, got NULL, %s", SDL_GetError());
  1474. return;
  1475. }
  1476. testSurface = SDL_ConvertSurface(surface, RENDER_COMPARE_FORMAT);
  1477. SDL_DestroySurface(surface);
  1478. if (!testSurface) {
  1479. SDLTest_AssertCheck(testSurface != NULL, "Validate result from SDL_ConvertSurface, got NULL, %s", SDL_GetError());
  1480. return;
  1481. }
  1482. /* Compare surface. */
  1483. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, allowable_error);
  1484. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1485. /* Clean up. */
  1486. SDL_DestroySurface(testSurface);
  1487. }
  1488. /**
  1489. * Clears the screen. Helper function.
  1490. *
  1491. * \sa SDL_SetRenderDrawColor
  1492. * \sa SDL_RenderClear
  1493. * \sa SDL_RenderPresent
  1494. * \sa SDL_SetRenderDrawBlendMode
  1495. */
  1496. static int
  1497. clearScreen(void)
  1498. {
  1499. int ret;
  1500. /* Make current */
  1501. SDL_RenderPresent(renderer);
  1502. /* Set color. */
  1503. ret = SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
  1504. SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawColor, expected: true, got: %i", ret);
  1505. /* Clear screen. */
  1506. ret = SDL_RenderClear(renderer);
  1507. SDLTest_AssertCheck(ret == true, "Validate result from SDL_RenderClear, expected: true, got: %i", ret);
  1508. /* Set defaults. */
  1509. ret = SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE);
  1510. SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawBlendMode, expected: true, got: %i", ret);
  1511. ret = SDL_SetRenderDrawColor(renderer, 255, 255, 255, SDL_ALPHA_OPAQUE);
  1512. SDLTest_AssertCheck(ret == true, "Validate result from SDL_SetRenderDrawColor, expected: true, got: %i", ret);
  1513. return 0;
  1514. }
  1515. /**
  1516. * Tests geometry UV clamping
  1517. */
  1518. static int SDLCALL render_testUVClamping(void *arg)
  1519. {
  1520. SDL_Vertex vertices[6];
  1521. SDL_Vertex *verts = vertices;
  1522. SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
  1523. SDL_FRect rect;
  1524. float min_U = -0.5f;
  1525. float max_U = 1.5f;
  1526. float min_V = -0.5f;
  1527. float max_V = 1.5f;
  1528. SDL_Texture *tface;
  1529. SDL_Surface *referenceSurface = NULL;
  1530. /* Clear surface. */
  1531. clearScreen();
  1532. /* Create face surface. */
  1533. tface = loadTestFace();
  1534. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  1535. if (tface == NULL) {
  1536. return TEST_ABORTED;
  1537. }
  1538. rect.w = (float)tface->w * 2;
  1539. rect.h = (float)tface->h * 2;
  1540. rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
  1541. rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
  1542. /*
  1543. * 0--1
  1544. * | /|
  1545. * |/ |
  1546. * 3--2
  1547. *
  1548. * Draw sprite2 as triangles that can be recombined as rect by software renderer
  1549. */
  1550. /* 0 */
  1551. verts->position.x = rect.x;
  1552. verts->position.y = rect.y;
  1553. verts->color = color;
  1554. verts->tex_coord.x = min_U;
  1555. verts->tex_coord.y = min_V;
  1556. verts++;
  1557. /* 1 */
  1558. verts->position.x = rect.x + rect.w;
  1559. verts->position.y = rect.y;
  1560. verts->color = color;
  1561. verts->tex_coord.x = max_U;
  1562. verts->tex_coord.y = min_V;
  1563. verts++;
  1564. /* 2 */
  1565. verts->position.x = rect.x + rect.w;
  1566. verts->position.y = rect.y + rect.h;
  1567. verts->color = color;
  1568. verts->tex_coord.x = max_U;
  1569. verts->tex_coord.y = max_V;
  1570. verts++;
  1571. /* 0 */
  1572. verts->position.x = rect.x;
  1573. verts->position.y = rect.y;
  1574. verts->color = color;
  1575. verts->tex_coord.x = min_U;
  1576. verts->tex_coord.y = min_V;
  1577. verts++;
  1578. /* 2 */
  1579. verts->position.x = rect.x + rect.w;
  1580. verts->position.y = rect.y + rect.h;
  1581. verts->color = color;
  1582. verts->tex_coord.x = max_U;
  1583. verts->tex_coord.y = max_V;
  1584. verts++;
  1585. /* 3 */
  1586. verts->position.x = rect.x;
  1587. verts->position.y = rect.y + rect.h;
  1588. verts->color = color;
  1589. verts->tex_coord.x = min_U;
  1590. verts->tex_coord.y = max_V;
  1591. verts++;
  1592. /* Set texture address mode to clamp */
  1593. SDL_SetRenderTextureAddressMode(renderer, SDL_TEXTURE_ADDRESS_CLAMP, SDL_TEXTURE_ADDRESS_CLAMP);
  1594. /* Blit sprites as triangles onto the screen */
  1595. SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0);
  1596. /* See if it's the same */
  1597. referenceSurface = SDLTest_ImageClampedSprite();
  1598. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1599. /* Make current */
  1600. SDL_RenderPresent(renderer);
  1601. /* Clean up. */
  1602. SDL_DestroyTexture(tface);
  1603. SDL_DestroySurface(referenceSurface);
  1604. referenceSurface = NULL;
  1605. return TEST_COMPLETED;
  1606. }
  1607. /**
  1608. * Tests geometry UV wrapping
  1609. */
  1610. static int SDLCALL render_testUVWrapping(void *arg)
  1611. {
  1612. SDL_Vertex vertices[6];
  1613. SDL_Vertex *verts = vertices;
  1614. SDL_FColor color = { 1.0f, 1.0f, 1.0f, 1.0f };
  1615. SDL_FRect rect;
  1616. float min_U = -0.5f;
  1617. float max_U = 1.5f;
  1618. float min_V = -0.5f;
  1619. float max_V = 1.5f;
  1620. SDL_Texture *tface;
  1621. SDL_Surface *referenceSurface = NULL;
  1622. /* Clear surface. */
  1623. clearScreen();
  1624. /* Create face surface. */
  1625. tface = loadTestFace();
  1626. SDLTest_AssertCheck(tface != NULL, "Verify loadTestFace() result");
  1627. if (tface == NULL) {
  1628. return TEST_ABORTED;
  1629. }
  1630. rect.w = (float)tface->w * 2;
  1631. rect.h = (float)tface->h * 2;
  1632. rect.x = (TESTRENDER_SCREEN_W - rect.w) / 2;
  1633. rect.y = (TESTRENDER_SCREEN_H - rect.h) / 2;
  1634. /*
  1635. * 0--1
  1636. * | /|
  1637. * |/ |
  1638. * 3--2
  1639. *
  1640. * Draw sprite2 as triangles that can be recombined as rect by software renderer
  1641. */
  1642. /* 0 */
  1643. verts->position.x = rect.x;
  1644. verts->position.y = rect.y;
  1645. verts->color = color;
  1646. verts->tex_coord.x = min_U;
  1647. verts->tex_coord.y = min_V;
  1648. verts++;
  1649. /* 1 */
  1650. verts->position.x = rect.x + rect.w;
  1651. verts->position.y = rect.y;
  1652. verts->color = color;
  1653. verts->tex_coord.x = max_U;
  1654. verts->tex_coord.y = min_V;
  1655. verts++;
  1656. /* 2 */
  1657. verts->position.x = rect.x + rect.w;
  1658. verts->position.y = rect.y + rect.h;
  1659. verts->color = color;
  1660. verts->tex_coord.x = max_U;
  1661. verts->tex_coord.y = max_V;
  1662. verts++;
  1663. /* 0 */
  1664. verts->position.x = rect.x;
  1665. verts->position.y = rect.y;
  1666. verts->color = color;
  1667. verts->tex_coord.x = min_U;
  1668. verts->tex_coord.y = min_V;
  1669. verts++;
  1670. /* 2 */
  1671. verts->position.x = rect.x + rect.w;
  1672. verts->position.y = rect.y + rect.h;
  1673. verts->color = color;
  1674. verts->tex_coord.x = max_U;
  1675. verts->tex_coord.y = max_V;
  1676. verts++;
  1677. /* 3 */
  1678. verts->position.x = rect.x;
  1679. verts->position.y = rect.y + rect.h;
  1680. verts->color = color;
  1681. verts->tex_coord.x = min_U;
  1682. verts->tex_coord.y = max_V;
  1683. verts++;
  1684. /* Blit sprites as triangles onto the screen */
  1685. SDL_RenderGeometry(renderer, tface, vertices, 6, NULL, 0);
  1686. /* See if it's the same */
  1687. referenceSurface = SDLTest_ImageWrappingSprite();
  1688. compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
  1689. /* Make current */
  1690. SDL_RenderPresent(renderer);
  1691. /* Clean up. */
  1692. SDL_DestroyTexture(tface);
  1693. SDL_DestroySurface(referenceSurface);
  1694. referenceSurface = NULL;
  1695. return TEST_COMPLETED;
  1696. }
  1697. /**
  1698. * Tests texture state changes
  1699. */
  1700. static int SDLCALL render_testTextureState(void *arg)
  1701. {
  1702. const Uint8 pixels[8] = {
  1703. 0x00, 0x00, 0x00, 0xFF,
  1704. 0xFF, 0xFF, 0xFF, 0xFF
  1705. };
  1706. const SDL_Color expected[] = {
  1707. /* Step 0: plain copy */
  1708. { 0x00, 0x00, 0x00, 0xFF },
  1709. { 0xFF, 0xFF, 0xFF, 0xFF },
  1710. /* Step 1: color mod to red */
  1711. { 0x00, 0x00, 0x00, 0xFF },
  1712. { 0xFF, 0x00, 0x00, 0xFF },
  1713. /* Step 2: alpha mod to 128 (cleared to green) */
  1714. { 0x00, 0x7F, 0x00, 0xFF },
  1715. { 0x80, 0xFF, 0x80, 0xFF },
  1716. /* Step 3: nearest stretch */
  1717. { 0xFF, 0xFF, 0xFF, 0xFF },
  1718. { 0x00, 0xFF, 0x00, 0xFF },
  1719. /* Step 4: linear stretch */
  1720. { 0x80, 0x80, 0x80, 0xFF },
  1721. { 0x00, 0xFF, 0x00, 0xFF },
  1722. };
  1723. SDL_Texture *texture;
  1724. SDL_Rect rect;
  1725. SDL_FRect dst;
  1726. int i;
  1727. /* Clear surface to green */
  1728. SDL_SetRenderDrawColor(renderer, 0, 255, 0, SDL_ALPHA_OPAQUE);
  1729. SDL_RenderClear(renderer);
  1730. /* Create 2-pixel surface. */
  1731. texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA32, SDL_TEXTUREACCESS_STATIC, 2, 1);
  1732. SDLTest_AssertCheck(texture != NULL, "Verify SDL_CreateTexture() result");
  1733. if (texture == NULL) {
  1734. return TEST_ABORTED;
  1735. }
  1736. SDL_UpdateTexture(texture, NULL, pixels, sizeof(pixels));
  1737. dst.x = 0.0f;
  1738. dst.y = 0.0f;
  1739. dst.w = 2.0f;
  1740. dst.h = 1.0f;
  1741. /* Step 0: plain copy */
  1742. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1743. dst.y += 1;
  1744. /* Step 1: color mod to red */
  1745. SDL_SetTextureColorMod(texture, 0xFF, 0x00, 0x00);
  1746. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1747. SDL_SetTextureColorMod(texture, 0xFF, 0xFF, 0xFF);
  1748. dst.y += 1;
  1749. /* Step 2: alpha mod to 128 */
  1750. SDL_SetTextureAlphaMod(texture, 0x80);
  1751. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1752. SDL_SetTextureAlphaMod(texture, 0xFF);
  1753. dst.y += 1;
  1754. /* Step 3: nearest stretch */
  1755. dst.w = 1;
  1756. SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_NEAREST);
  1757. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1758. dst.y += 1;
  1759. /* Step 4: linear stretch */
  1760. dst.w = 1;
  1761. SDL_SetTextureScaleMode(texture, SDL_SCALEMODE_LINEAR);
  1762. SDL_RenderTexture(renderer, texture, NULL, &dst);
  1763. dst.y += 1;
  1764. /* Verify results */
  1765. rect.x = 0;
  1766. rect.y = 0;
  1767. rect.w = 2;
  1768. rect.h = 1;
  1769. for (i = 0; i < SDL_arraysize(expected); ) {
  1770. const int MAX_DELTA = 1;
  1771. SDL_Color actual;
  1772. int deltaR, deltaG, deltaB, deltaA;
  1773. SDL_Surface *surface = SDL_RenderReadPixels(renderer, &rect);
  1774. SDL_ReadSurfacePixel(surface, 0, 0, &actual.r, &actual.g, &actual.b, &actual.a);
  1775. deltaR = (actual.r - expected[i].r);
  1776. deltaG = (actual.g - expected[i].g);
  1777. deltaB = (actual.b - expected[i].b);
  1778. deltaA = (actual.a - expected[i].a);
  1779. SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
  1780. SDL_abs(deltaG) <= MAX_DELTA &&
  1781. SDL_abs(deltaB) <= MAX_DELTA &&
  1782. SDL_abs(deltaA) <= MAX_DELTA,
  1783. "Validate left pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
  1784. expected[i].r, expected[i].g, expected[i].b, expected[i].a,
  1785. actual.r, actual.g, actual.b, actual.a);
  1786. ++i;
  1787. SDL_ReadSurfacePixel(surface, 1, 0, &actual.r, &actual.g, &actual.b, &actual.a);
  1788. deltaR = (actual.r - expected[i].r);
  1789. deltaG = (actual.g - expected[i].g);
  1790. deltaB = (actual.b - expected[i].b);
  1791. deltaA = (actual.a - expected[i].a);
  1792. SDLTest_AssertCheck(SDL_abs(deltaR) <= MAX_DELTA &&
  1793. SDL_abs(deltaG) <= MAX_DELTA &&
  1794. SDL_abs(deltaB) <= MAX_DELTA &&
  1795. SDL_abs(deltaA) <= MAX_DELTA,
  1796. "Validate right pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d", i/2,
  1797. expected[i].r, expected[i].g, expected[i].b, expected[i].a,
  1798. actual.r, actual.g, actual.b, actual.a);
  1799. ++i;
  1800. SDL_DestroySurface(surface);
  1801. rect.y += 1;
  1802. }
  1803. /* Clean up. */
  1804. SDL_DestroyTexture(texture);
  1805. return TEST_COMPLETED;
  1806. }
  1807. /* ================= Test References ================== */
  1808. /* Render test cases */
  1809. static const SDLTest_TestCaseReference renderTestGetNumRenderDrivers = {
  1810. render_testGetNumRenderDrivers, "render_testGetNumRenderDrivers", "Tests call to SDL_GetNumRenderDrivers", TEST_ENABLED
  1811. };
  1812. static const SDLTest_TestCaseReference renderTestPrimitives = {
  1813. render_testPrimitives, "render_testPrimitives", "Tests rendering primitives", TEST_ENABLED
  1814. };
  1815. static const SDLTest_TestCaseReference renderTestPrimitivesWithViewport = {
  1816. render_testPrimitivesWithViewport, "render_testPrimitivesWithViewport", "Tests rendering primitives within a viewport", TEST_ENABLED
  1817. };
  1818. static const SDLTest_TestCaseReference renderTestBlit = {
  1819. render_testBlit, "render_testBlit", "Tests blitting", TEST_ENABLED
  1820. };
  1821. static const SDLTest_TestCaseReference renderTestBlitTiled = {
  1822. render_testBlitTiled, "render_testBlitTiled", "Tests tiled blitting", TEST_ENABLED
  1823. };
  1824. static const SDLTest_TestCaseReference renderTestBlit9Grid = {
  1825. render_testBlit9Grid, "render_testBlit9Grid", "Tests 9-grid blitting", TEST_ENABLED
  1826. };
  1827. static const SDLTest_TestCaseReference renderTestBlit9GridTiled = {
  1828. render_testBlit9GridTiled, "render_testBlit9GridTiled", "Tests tiled 9-grid blitting", TEST_ENABLED
  1829. };
  1830. static const SDLTest_TestCaseReference renderTestBlitColor = {
  1831. render_testBlitColor, "render_testBlitColor", "Tests blitting with color", TEST_ENABLED
  1832. };
  1833. static const SDLTest_TestCaseReference renderTestBlendModes = {
  1834. render_testBlendModes, "render_testBlendModes", "Tests rendering blend modes", TEST_ENABLED
  1835. };
  1836. static const SDLTest_TestCaseReference renderTestViewport = {
  1837. render_testViewport, "render_testViewport", "Tests viewport", TEST_ENABLED
  1838. };
  1839. static const SDLTest_TestCaseReference renderTestClipRect = {
  1840. render_testClipRect, "render_testClipRect", "Tests clip rect", TEST_ENABLED
  1841. };
  1842. static const SDLTest_TestCaseReference renderTestLogicalSize = {
  1843. render_testLogicalSize, "render_testLogicalSize", "Tests logical size", TEST_ENABLED
  1844. };
  1845. static const SDLTest_TestCaseReference renderTestUVClamping = {
  1846. render_testUVClamping, "render_testUVClamping", "Tests geometry UV clamping", TEST_ENABLED
  1847. };
  1848. static const SDLTest_TestCaseReference renderTestUVWrapping = {
  1849. render_testUVWrapping, "render_testUVWrapping", "Tests geometry UV wrapping", TEST_ENABLED
  1850. };
  1851. static const SDLTest_TestCaseReference renderTestTextureState = {
  1852. render_testTextureState, "render_testTextureState", "Tests texture state changes", TEST_ENABLED
  1853. };
  1854. static const SDLTest_TestCaseReference renderTestGetSetTextureScaleMode = {
  1855. render_testGetSetTextureScaleMode, "render_testGetSetTextureScaleMode", "Tests setting/getting texture scale mode", TEST_ENABLED
  1856. };
  1857. static const SDLTest_TestCaseReference renderTestRGBSurfaceNoAlpha = {
  1858. render_testRGBSurfaceNoAlpha, "render_testRGBSurfaceNoAlpha", "Tests RGB surface with no alpha using software renderer", TEST_ENABLED
  1859. };
  1860. /* Sequence of Render test cases */
  1861. static const SDLTest_TestCaseReference *renderTests[] = {
  1862. &renderTestGetNumRenderDrivers,
  1863. &renderTestPrimitives,
  1864. &renderTestPrimitivesWithViewport,
  1865. &renderTestBlit,
  1866. &renderTestBlitTiled,
  1867. &renderTestBlit9Grid,
  1868. &renderTestBlit9GridTiled,
  1869. &renderTestBlitColor,
  1870. &renderTestBlendModes,
  1871. &renderTestViewport,
  1872. &renderTestClipRect,
  1873. &renderTestLogicalSize,
  1874. &renderTestUVClamping,
  1875. &renderTestUVWrapping,
  1876. &renderTestTextureState,
  1877. &renderTestGetSetTextureScaleMode,
  1878. &renderTestRGBSurfaceNoAlpha,
  1879. NULL
  1880. };
  1881. /* Render test suite (global) */
  1882. SDLTest_TestSuiteReference renderTestSuite = {
  1883. "Render",
  1884. InitCreateRenderer,
  1885. renderTests,
  1886. CleanupDestroyRenderer
  1887. };