2015-06-21 17:33:46 +02:00
/**
* Original code : automated SDL platform test written by Edgar Simo " bobbens "
* Extended and extensively updated by aschiffler at ferzkopp dot net
*/
2022-11-26 20:43:38 -08:00
# include <SDL3/SDL.h>
# include <SDL3/SDL_test.h>
2023-01-26 10:23:57 -08:00
# include "testautomation_images.h"
2023-03-08 16:12:45 +01:00
# include "testautomation_suites.h"
2015-06-21 17:33:46 +02:00
/* ================= Test Case Implementation ================== */
2025-09-21 20:25:10 -07:00
# define TESTRENDER_WINDOW_W 320
# define TESTRENDER_WINDOW_H 240
2022-11-30 12:51:59 -08:00
# define TESTRENDER_SCREEN_W 80
# define TESTRENDER_SCREEN_H 60
2015-06-21 17:33:46 +02:00
2022-12-01 17:04:02 +01:00
2022-11-30 12:51:59 -08:00
# define RENDER_COMPARE_FORMAT SDL_PIXELFORMAT_ARGB8888
2023-01-26 14:49:23 -08:00
# define RENDER_COLOR_CLEAR 0xFF000000
2023-01-26 13:58:38 -08:00
# define RENDER_COLOR_GREEN 0xFF00FF00
2015-06-21 17:33:46 +02:00
# define ALLOWABLE_ERROR_OPAQUE 0
2024-07-03 18:02:52 +01:00
# define ALLOWABLE_ERROR_BLENDED 0
2015-06-21 17:33:46 +02:00
2023-02-05 09:08:33 -08:00
# define CHECK_FUNC(FUNC, PARAMS) \
{ \
2024-09-18 07:52:28 -07:00
bool result = FUNC PARAMS ; \
2024-08-22 17:33:49 -07:00
if ( ! result ) { \
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( result , " Validate result from %s, expected: true, got: false, %s " , # FUNC , SDL_GetError ( ) ) ; \
2023-02-05 09:08:33 -08:00
} \
}
2015-06-21 17:33:46 +02:00
/* Test window and renderer */
2023-03-08 16:12:45 +01:00
static SDL_Window * window = NULL ;
static SDL_Renderer * renderer = NULL ;
2015-06-21 17:33:46 +02:00
/* Prototypes for helper functions */
2022-12-29 22:58:16 +01:00
static int clearScreen ( void ) ;
static void compare ( SDL_Surface * reference , int allowable_error ) ;
2024-07-20 13:47:01 -07:00
static void compare2x ( SDL_Surface * reference , int allowable_error ) ;
2022-12-29 22:58:16 +01:00
static SDL_Texture * loadTestFace ( void ) ;
2024-09-18 07:52:28 -07:00
static bool isSupported ( int code ) ;
static bool hasDrawColor ( void ) ;
2015-06-21 17:33:46 +02:00
/**
* Create software renderer for tests
*/
2024-09-06 03:21:13 +02:00
static void SDLCALL InitCreateRenderer ( void * * arg )
2015-06-21 17:33:46 +02:00
{
2024-04-04 12:39:24 -07:00
const char * renderer_name = NULL ;
2022-11-30 12:51:59 -08:00
renderer = NULL ;
2025-09-21 20:25:10 -07:00
window = SDL_CreateWindow ( " render_testCreateRenderer " , TESTRENDER_WINDOW_W , TESTRENDER_WINDOW_H , 0 ) ;
2022-11-30 12:51:59 -08:00
SDLTest_AssertPass ( " SDL_CreateWindow() " ) ;
SDLTest_AssertCheck ( window ! = NULL , " Check SDL_CreateWindow result " ) ;
if ( window = = NULL ) {
return ;
}
2024-05-13 10:31:55 -07:00
renderer = SDL_CreateRenderer ( window , renderer_name ) ;
2022-11-30 12:51:59 -08:00
SDLTest_AssertPass ( " SDL_CreateRenderer() " ) ;
2024-01-08 18:34:28 +00:00
SDLTest_AssertCheck ( renderer ! = NULL , " Check SDL_CreateRenderer result: %s " , renderer ! = NULL ? " success " : SDL_GetError ( ) ) ;
2022-11-30 12:51:59 -08:00
if ( renderer = = NULL ) {
SDL_DestroyWindow ( window ) ;
return ;
}
2015-06-21 17:33:46 +02:00
}
2023-02-02 00:21:53 +01:00
/**
2015-06-21 17:33:46 +02:00
* Destroy renderer for tests
*/
2024-09-06 03:21:13 +02:00
static void SDLCALL CleanupDestroyRenderer ( void * arg )
2015-06-21 17:33:46 +02:00
{
2023-11-09 22:29:15 +01:00
if ( renderer ) {
2022-11-30 12:51:59 -08:00
SDL_DestroyRenderer ( renderer ) ;
renderer = NULL ;
SDLTest_AssertPass ( " SDL_DestroyRenderer() " ) ;
}
2023-11-09 22:29:15 +01:00
if ( window ) {
2022-11-30 12:51:59 -08:00
SDL_DestroyWindow ( window ) ;
window = NULL ;
SDLTest_AssertPass ( " SDL_DestroyWindow " ) ;
}
2015-06-21 17:33:46 +02:00
}
/**
2023-11-06 10:26:06 -05:00
* Tests call to SDL_GetNumRenderDrivers
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_GetNumRenderDrivers
2015-06-21 17:33:46 +02:00
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testGetNumRenderDrivers ( void * arg )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
int n ;
n = SDL_GetNumRenderDrivers ( ) ;
SDLTest_AssertCheck ( n > = 1 , " Number of renderers >= 1, reported as %i " , n ) ;
return TEST_COMPLETED ;
2015-06-21 17:33:46 +02:00
}
/**
2023-11-06 10:26:06 -05:00
* Tests the SDL primitives for rendering .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_SetRenderDrawColor
* \ sa SDL_RenderFillRect
* \ sa SDL_RenderLine
2015-06-21 17:33:46 +02:00
*
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testPrimitives ( void * arg )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
int ret ;
int x , y ;
2022-12-31 11:19:32 -08:00
SDL_FRect rect ;
2022-11-30 12:51:59 -08:00
SDL_Surface * referenceSurface = NULL ;
int checkFailCount1 ;
int checkFailCount2 ;
/* Clear surface. */
2022-12-29 22:58:16 +01:00
clearScreen ( ) ;
2022-11-30 12:51:59 -08:00
/* Need drawcolor or just skip test. */
2024-07-15 13:42:06 -07:00
SDLTest_AssertCheck ( hasDrawColor ( ) , " hasDrawColor " ) ;
2022-11-30 12:51:59 -08:00
/* Draw a rectangle. */
2022-12-31 11:19:32 -08:00
rect . x = 40.0f ;
rect . y = 0.0f ;
rect . w = 40.0f ;
rect . h = 80.0f ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 13 , 73 , 200 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , & rect ) )
2022-11-30 12:51:59 -08:00
2025-09-07 12:08:38 -07:00
/* Draw a rectangle with negative width and height. */
rect . x = 10.0f + 60.0f ;
rect . y = 10.0f + 40.0f ;
rect . w = - 60.0f ;
rect . h = - 40.0f ;
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 200 , 0 , 100 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , & rect ) )
/* Draw a rectangle with zero width and height. */
2022-12-31 11:19:32 -08:00
rect . x = 10.0f ;
rect . y = 10.0f ;
2025-09-07 12:08:38 -07:00
rect . w = 0.0f ;
rect . h = 0.0f ;
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 255 , 0 , 0 , SDL_ALPHA_OPAQUE ) )
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , & rect ) )
2022-11-30 12:51:59 -08:00
/* Draw some points like so:
* X . X . X . X . .
* . X . X . X . X .
* X . X . X . X . . */
checkFailCount1 = 0 ;
checkFailCount2 = 0 ;
for ( y = 0 ; y < 3 ; y + + ) {
for ( x = y % 2 ; x < TESTRENDER_SCREEN_W ; x + = 2 ) {
2024-02-03 11:23:16 -08:00
ret = SDL_SetRenderDrawColor ( renderer , ( Uint8 ) ( x * y ) , ( Uint8 ) ( x * y / 2 ) , ( Uint8 ) ( x * y / 3 ) , SDL_ALPHA_OPAQUE ) ;
2024-08-22 17:33:49 -07:00
if ( ! ret ) {
2022-11-30 12:51:59 -08:00
checkFailCount1 + + ;
}
2024-06-12 19:08:06 -07:00
ret = SDL_RenderPoint ( renderer , ( float ) x , ( float ) y ) ;
2024-08-22 17:33:49 -07:00
if ( ! ret ) {
2022-11-30 12:51:59 -08:00
checkFailCount2 + + ;
}
}
}
SDLTest_AssertCheck ( checkFailCount1 = = 0 , " Validate results from calls to SDL_SetRenderDrawColor, expected: 0, got: %i " , checkFailCount1 ) ;
2022-12-27 06:21:13 -08:00
SDLTest_AssertCheck ( checkFailCount2 = = 0 , " Validate results from calls to SDL_RenderPoint, expected: 0, got: %i " , checkFailCount2 ) ;
2022-11-30 12:51:59 -08:00
/* Draw some lines. */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
2024-06-12 09:21:02 -07:00
CHECK_FUNC ( SDL_RenderLine , ( renderer , 0.0f , 30.0f , TESTRENDER_SCREEN_W , 30.0f ) )
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 55 , 55 , 5 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderLine , ( renderer , 40.0f , 30.0f , 40.0f , 60.0f ) )
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 5 , 105 , 105 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderLine , ( renderer , 0.0f , 0.0f , 29.0f , 29.0f ) )
CHECK_FUNC ( SDL_RenderLine , ( renderer , 29.0f , 30.0f , 0.0f , 59.0f ) )
CHECK_FUNC ( SDL_RenderLine , ( renderer , 79.0f , 0.0f , 50.0f , 29.0f ) )
CHECK_FUNC ( SDL_RenderLine , ( renderer , 79.0f , 59.0f , 50.0f , 30.0f ) )
2022-11-30 12:51:59 -08:00
/* See if it's the same. */
referenceSurface = SDLTest_ImagePrimitives ( ) ;
2022-12-29 22:58:16 +01:00
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
2022-11-30 12:51:59 -08:00
/* Make current */
SDL_RenderPresent ( renderer ) ;
/* Clean up. */
2022-12-27 06:36:39 -08:00
SDL_DestroySurface ( referenceSurface ) ;
2022-11-30 12:51:59 -08:00
referenceSurface = NULL ;
return TEST_COMPLETED ;
2015-06-21 17:33:46 +02:00
}
2024-01-19 16:28:00 -08:00
/**
* Tests the SDL primitives for rendering within a viewport .
*
* \ sa SDL_SetRenderDrawColor
* \ sa SDL_RenderFillRect
* \ sa SDL_RenderLine
*
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testPrimitivesWithViewport ( void * arg )
2024-01-19 16:28:00 -08:00
{
2024-06-12 19:08:06 -07:00
SDL_Rect viewport ;
2024-02-03 10:18:12 -08:00
SDL_Surface * surface ;
2024-01-19 16:28:00 -08:00
/* Clear surface. */
clearScreen ( ) ;
viewport . x = 2 ;
viewport . y = 2 ;
viewport . w = 2 ;
viewport . h = 2 ;
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , & viewport ) ) ;
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 255 , 255 , 255 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderLine , ( renderer , 0.0f , 0.0f , 1.0f , 1.0f ) ) ;
viewport . x = 3 ;
viewport . y = 3 ;
viewport . w = 1 ;
viewport . h = 1 ;
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , & viewport ) ) ;
2024-02-03 10:18:12 -08:00
surface = SDL_RenderReadPixels ( renderer , NULL ) ;
if ( surface ) {
Uint8 r , g , b , a ;
CHECK_FUNC ( SDL_ReadSurfacePixel , ( surface , 0 , 0 , & r , & g , & b , & a ) ) ;
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 ) ;
SDL_DestroySurface ( surface ) ;
} else {
SDLTest_AssertCheck ( surface ! = NULL , " Validate result from SDL_RenderReadPixels, got NULL, %s " , SDL_GetError ( ) ) ;
}
2024-01-19 16:28:00 -08:00
return TEST_COMPLETED ;
}
2015-06-21 17:33:46 +02:00
/**
2023-11-06 10:26:06 -05:00
* Tests some blitting routines .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_RenderTexture
* \ sa SDL_DestroyTexture
2015-06-21 17:33:46 +02:00
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testBlit ( void * arg )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
int ret ;
2022-12-31 11:19:32 -08:00
SDL_FRect rect ;
2022-11-30 12:51:59 -08:00
SDL_Texture * tface ;
SDL_Surface * referenceSurface = NULL ;
2024-09-30 20:40:54 -07:00
int i , j , ni , nj ;
2022-11-30 12:51:59 -08:00
int checkFailCount1 ;
/* Clear surface. */
2022-12-29 22:58:16 +01:00
clearScreen ( ) ;
2022-11-30 12:51:59 -08:00
/* Need drawcolor or just skip test. */
2024-07-15 13:42:06 -07:00
SDLTest_AssertCheck ( hasDrawColor ( ) , " hasDrawColor) " ) ;
2022-11-30 12:51:59 -08:00
/* Create face surface. */
2022-12-29 22:58:16 +01:00
tface = loadTestFace ( ) ;
SDLTest_AssertCheck ( tface ! = NULL , " Verify loadTestFace() result " ) ;
2022-11-30 12:51:59 -08:00
if ( tface = = NULL ) {
return TEST_ABORTED ;
}
/* Constant values. */
2024-09-30 20:40:54 -07:00
rect . w = ( float ) tface - > w ;
rect . h = ( float ) tface - > h ;
ni = TESTRENDER_SCREEN_W - tface - > w ;
nj = TESTRENDER_SCREEN_H - tface - > h ;
2022-11-30 12:51:59 -08:00
/* Loop blit. */
checkFailCount1 = 0 ;
for ( j = 0 ; j < = nj ; j + = 4 ) {
for ( i = 0 ; i < = ni ; i + = 4 ) {
/* Blitting. */
2024-09-30 20:40:54 -07:00
rect . x = ( float ) i ;
rect . y = ( float ) j ;
2022-12-27 06:21:13 -08:00
ret = SDL_RenderTexture ( renderer , tface , NULL , & rect ) ;
2024-08-22 17:33:49 -07:00
if ( ! ret ) {
2022-11-30 12:51:59 -08:00
checkFailCount1 + + ;
}
}
}
2022-12-27 06:21:13 -08:00
SDLTest_AssertCheck ( checkFailCount1 = = 0 , " Validate results from calls to SDL_RenderTexture, expected: 0, got: %i " , checkFailCount1 ) ;
2022-11-30 12:51:59 -08:00
/* See if it's the same */
referenceSurface = SDLTest_ImageBlit ( ) ;
2022-12-29 22:58:16 +01:00
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
2022-11-30 12:51:59 -08:00
/* Make current */
SDL_RenderPresent ( renderer ) ;
/* Clean up. */
SDL_DestroyTexture ( tface ) ;
2022-12-27 06:36:39 -08:00
SDL_DestroySurface ( referenceSurface ) ;
2022-11-30 12:51:59 -08:00
referenceSurface = NULL ;
return TEST_COMPLETED ;
2015-06-21 17:33:46 +02:00
}
2024-07-20 13:47:01 -07:00
/**
* Tests tiled blitting routines .
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testBlitTiled ( void * arg )
2024-07-20 13:47:01 -07:00
{
int ret ;
SDL_FRect rect ;
SDL_Texture * tface ;
SDL_Surface * referenceSurface = NULL ;
SDL_Surface * referenceSurface2x = NULL ;
/* Create face surface. */
tface = loadTestFace ( ) ;
SDLTest_AssertCheck ( tface ! = NULL , " Verify loadTestFace() result " ) ;
if ( tface = = NULL ) {
return TEST_ABORTED ;
}
SDL_SetTextureScaleMode ( tface , SDL_SCALEMODE_NEAREST ) ; /* So 2x scaling is pixel perfect */
/* Tiled blit - 1.0 scale */
{
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTextureTiled ( renderer , tface , NULL , 1.0f , & rect ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i " , ret ) ;
2024-07-20 13:47:01 -07:00
/* See if it's the same */
referenceSurface = SDLTest_ImageBlitTiled ( ) ;
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Tiled blit - 2.0 scale */
{
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W * 2 ;
rect . h = ( float ) TESTRENDER_SCREEN_H * 2 ;
ret = SDL_RenderTextureTiled ( renderer , tface , NULL , 2.0f , & rect ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTextureTiled, expected: true, got: %i " , ret ) ;
2024-07-20 13:47:01 -07:00
/* See if it's the same */
referenceSurface2x = SDL_CreateSurface ( referenceSurface - > w * 2 , referenceSurface - > h * 2 , referenceSurface - > format ) ;
SDL_BlitSurfaceScaled ( referenceSurface , NULL , referenceSurface2x , NULL , SDL_SCALEMODE_NEAREST ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_BlitSurfaceScaled, expected: 0, got: %i " , ret ) ;
2024-07-20 13:47:01 -07:00
compare2x ( referenceSurface2x , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Clean up. */
SDL_DestroyTexture ( tface ) ;
SDL_DestroySurface ( referenceSurface ) ;
SDL_DestroySurface ( referenceSurface2x ) ;
referenceSurface = NULL ;
return TEST_COMPLETED ;
}
2024-07-20 16:39:09 -07:00
static const Uint8 COLOR_SEPARATION = 85 ;
2024-07-31 22:09:42 -07:00
static void Fill9GridReferenceSurface ( SDL_Surface * surface , int left_width , int right_width , int top_height , int bottom_height )
2024-07-20 16:39:09 -07:00
{
SDL_Rect rect ;
// Upper left
rect . x = 0 ;
rect . y = 0 ;
2024-07-31 22:09:42 -07:00
rect . w = left_width ;
rect . h = top_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 1 * COLOR_SEPARATION , 1 * COLOR_SEPARATION , 0 ) ) ;
// Top
2024-07-31 22:09:42 -07:00
rect . x = left_width ;
2024-07-20 16:39:09 -07:00
rect . y = 0 ;
2024-07-31 22:09:42 -07:00
rect . w = surface - > w - left_width - right_width ;
rect . h = top_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 2 * COLOR_SEPARATION , 1 * COLOR_SEPARATION , 0 ) ) ;
// Upper right
2024-07-31 22:09:42 -07:00
rect . x = surface - > w - right_width ;
2024-07-20 16:39:09 -07:00
rect . y = 0 ;
2024-07-31 22:09:42 -07:00
rect . w = right_width ;
rect . h = top_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 3 * COLOR_SEPARATION , 1 * COLOR_SEPARATION , 0 ) ) ;
// Left
rect . x = 0 ;
2024-07-31 22:09:42 -07:00
rect . y = top_height ;
rect . w = left_width ;
rect . h = surface - > h - top_height - bottom_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 1 * COLOR_SEPARATION , 2 * COLOR_SEPARATION , 0 ) ) ;
// Center
2024-07-31 22:09:42 -07:00
rect . x = left_width ;
rect . y = top_height ;
rect . w = surface - > w - right_width - left_width ;
rect . h = surface - > h - top_height - bottom_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 2 * COLOR_SEPARATION , 2 * COLOR_SEPARATION , 0 ) ) ;
// Right
2024-07-31 22:09:42 -07:00
rect . x = surface - > w - right_width ;
rect . y = top_height ;
rect . w = right_width ;
rect . h = surface - > h - top_height - bottom_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 3 * COLOR_SEPARATION , 2 * COLOR_SEPARATION , 0 ) ) ;
// Lower left
rect . x = 0 ;
2024-07-31 22:09:42 -07:00
rect . y = surface - > h - bottom_height ;
rect . w = left_width ;
rect . h = bottom_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 1 * COLOR_SEPARATION , 3 * COLOR_SEPARATION , 0 ) ) ;
// Bottom
2024-07-31 22:09:42 -07:00
rect . x = left_width ;
rect . y = surface - > h - bottom_height ;
rect . w = surface - > w - left_width - right_width ;
rect . h = bottom_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 2 * COLOR_SEPARATION , 3 * COLOR_SEPARATION , 0 ) ) ;
// Lower right
2024-07-31 22:09:42 -07:00
rect . x = surface - > w - right_width ;
rect . y = surface - > h - bottom_height ;
rect . w = right_width ;
rect . h = bottom_height ;
2024-07-20 16:39:09 -07:00
SDL_FillSurfaceRect ( surface , & rect , SDL_MapSurfaceRGB ( surface , 3 * COLOR_SEPARATION , 3 * COLOR_SEPARATION , 0 ) ) ;
}
/**
* Tests 9 - grid blitting .
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testBlit9Grid ( void * arg )
2024-07-20 16:39:09 -07:00
{
SDL_Surface * referenceSurface = NULL ;
SDL_Surface * source = NULL ;
SDL_Texture * texture ;
int x , y ;
SDL_FRect rect ;
int ret = 0 ;
/* Create source surface */
source = SDL_CreateSurface ( 3 , 3 , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( source ! = NULL , " Verify source surface is not NULL " ) ;
for ( y = 0 ; y < 3 ; + + y ) {
for ( x = 0 ; x < 3 ; + + x ) {
SDL_WriteSurfacePixel ( source , x , y , ( Uint8 ) ( ( 1 + x ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 + y ) * COLOR_SEPARATION ) , 0 , 255 ) ;
}
}
texture = SDL_CreateTextureFromSurface ( renderer , source ) ;
SDLTest_AssertCheck ( texture ! = NULL , " Verify source texture is not NULL " ) ;
ret = SDL_SetTextureScaleMode ( texture , SDL_SCALEMODE_NEAREST ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i " , ret ) ;
2024-07-20 16:39:09 -07:00
/* 9-grid blit - 1.0 scale */
{
2024-07-31 22:09:42 -07:00
SDLTest_Log ( " 9-grid blit - 1.0 scale " ) ;
2024-07-20 16:39:09 -07:00
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
2024-07-31 22:09:42 -07:00
Fill9GridReferenceSurface ( referenceSurface , 1 , 1 , 1 , 1 ) ;
2024-07-20 16:39:09 -07:00
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
2024-07-31 22:09:42 -07:00
ret = SDL_RenderTexture9Grid ( renderer , texture , NULL , 1.0f , 1.0f , 1.0f , 1.0f , 1.0f , & rect ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i " , ret ) ;
2024-07-20 16:39:09 -07:00
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* 9-grid blit - 2.0 scale */
{
2024-07-31 22:09:42 -07:00
SDLTest_Log ( " 9-grid blit - 2.0 scale " ) ;
2024-07-20 16:39:09 -07:00
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
2024-07-31 22:09:42 -07:00
Fill9GridReferenceSurface ( referenceSurface , 2 , 2 , 2 , 2 ) ;
2024-07-20 16:39:09 -07:00
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
2024-07-31 22:09:42 -07:00
ret = SDL_RenderTexture9Grid ( renderer , texture , NULL , 1.0f , 1.0f , 1.0f , 1.0f , 2.0f , & rect ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i " , ret ) ;
2024-07-31 22:09:42 -07:00
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Clean up. */
SDL_DestroySurface ( source ) ;
SDL_DestroyTexture ( texture ) ;
/* Create complex source surface */
source = SDL_CreateSurface ( 5 , 5 , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( source ! = NULL , " Verify source surface is not NULL " ) ;
SDL_WriteSurfacePixel ( source , 0 , 0 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 0 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 0 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 0 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 0 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 1 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 1 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 1 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 1 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 1 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 2 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 2 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 2 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 2 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 2 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 3 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 3 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 3 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 3 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 3 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 4 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 4 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 4 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 4 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 4 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
texture = SDL_CreateTextureFromSurface ( renderer , source ) ;
SDLTest_AssertCheck ( texture ! = NULL , " Verify source texture is not NULL " ) ;
ret = SDL_SetTextureScaleMode ( texture , SDL_SCALEMODE_NEAREST ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i " , ret ) ;
2024-07-31 22:09:42 -07:00
/* complex 9-grid blit - 1.0 scale */
{
SDLTest_Log ( " complex 9-grid blit - 1.0 scale " ) ;
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
Fill9GridReferenceSurface ( referenceSurface , 1 , 2 , 1 , 2 ) ;
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTexture9Grid ( renderer , texture , NULL , 1.0f , 2.0f , 1.0f , 2.0f , 1.0f , & rect ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i " , ret ) ;
2024-07-31 22:09:42 -07:00
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* complex 9-grid blit - 2.0 scale */
{
SDLTest_Log ( " complex 9-grid blit - 2.0 scale " ) ;
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
Fill9GridReferenceSurface ( referenceSurface , 2 , 4 , 2 , 4 ) ;
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTexture9Grid ( renderer , texture , NULL , 1.0f , 2.0f , 1.0f , 2.0f , 2.0f , & rect ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9Grid, expected: true, got: %i " , ret ) ;
2024-07-20 16:39:09 -07:00
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Clean up. */
SDL_DestroySurface ( referenceSurface ) ;
SDL_DestroySurface ( source ) ;
SDL_DestroyTexture ( texture ) ;
return TEST_COMPLETED ;
}
2025-01-24 10:17:44 +01:00
/**
* Tests tiled 9 - grid blitting .
*/
static int SDLCALL render_testBlit9GridTiled ( void * arg )
{
SDL_Surface * referenceSurface = NULL ;
SDL_Surface * source = NULL ;
SDL_Texture * texture ;
int x , y ;
SDL_FRect rect ;
int ret = 0 ;
/* Create source surface */
source = SDL_CreateSurface ( 3 , 3 , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( source ! = NULL , " Verify source surface is not NULL " ) ;
for ( y = 0 ; y < 3 ; + + y ) {
for ( x = 0 ; x < 3 ; + + x ) {
SDL_WriteSurfacePixel ( source , x , y , ( Uint8 ) ( ( 1 + x ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 + y ) * COLOR_SEPARATION ) , 0 , 255 ) ;
}
}
texture = SDL_CreateTextureFromSurface ( renderer , source ) ;
SDLTest_AssertCheck ( texture ! = NULL , " Verify source texture is not NULL " ) ;
ret = SDL_SetTextureScaleMode ( texture , SDL_SCALEMODE_NEAREST ) ;
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i " , ret ) ;
/* Tiled 9-grid blit - 1.0 scale */
{
SDLTest_Log ( " tiled 9-grid blit - 1.0 scale " ) ;
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
Fill9GridReferenceSurface ( referenceSurface , 1 , 1 , 1 , 1 ) ;
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTexture9GridTiled ( renderer , texture , NULL , 1.0f , 1.0f , 1.0f , 1.0f , 1.0f , & rect , 1.0f ) ;
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i " , ret ) ;
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Tiled 9-grid blit - 2.0 scale */
{
SDLTest_Log ( " tiled 9-grid blit - 2.0 scale " ) ;
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
Fill9GridReferenceSurface ( referenceSurface , 2 , 2 , 2 , 2 ) ;
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTexture9GridTiled ( renderer , texture , NULL , 1.0f , 1.0f , 1.0f , 1.0f , 2.0f , & rect , 2.0f ) ;
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i " , ret ) ;
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Clean up. */
SDL_DestroySurface ( source ) ;
SDL_DestroyTexture ( texture ) ;
/* Create complex source surface */
source = SDL_CreateSurface ( 5 , 5 , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( source ! = NULL , " Verify source surface is not NULL " ) ;
SDL_WriteSurfacePixel ( source , 0 , 0 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 0 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 0 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 0 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 0 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 1 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 1 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 1 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 1 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 1 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 2 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 2 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 2 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 2 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 2 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 3 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 3 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 3 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 3 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 3 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 0 , 4 , ( Uint8 ) ( ( 1 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 1 , 4 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 2 , 4 , ( Uint8 ) ( ( 2 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 3 , 4 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
SDL_WriteSurfacePixel ( source , 4 , 4 , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , ( Uint8 ) ( ( 3 ) * COLOR_SEPARATION ) , 0 , 255 ) ;
texture = SDL_CreateTextureFromSurface ( renderer , source ) ;
SDLTest_AssertCheck ( texture ! = NULL , " Verify source texture is not NULL " ) ;
ret = SDL_SetTextureScaleMode ( texture , SDL_SCALEMODE_NEAREST ) ;
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_SetTextureScaleMode, expected: true, got: %i " , ret ) ;
/* complex tiled 9-grid blit - 1.0 scale */
{
SDLTest_Log ( " complex tiled 9-grid blit - 1.0 scale " ) ;
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
Fill9GridReferenceSurface ( referenceSurface , 1 , 2 , 1 , 2 ) ;
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTexture9GridTiled ( renderer , texture , NULL , 1.0f , 2.0f , 1.0f , 2.0f , 1.0f , & rect , 1.0f ) ;
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i " , ret ) ;
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* complex tiled 9-grid blit - 2.0 scale */
{
SDLTest_Log ( " complex tiled 9-grid blit - 2.0 scale " ) ;
/* Create reference surface */
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , SDL_PIXELFORMAT_RGBA32 ) ;
SDLTest_AssertCheck ( referenceSurface ! = NULL , " Verify reference surface is not NULL " ) ;
Fill9GridReferenceSurface ( referenceSurface , 2 , 4 , 2 , 4 ) ;
/* Clear surface. */
clearScreen ( ) ;
/* Tiled blit. */
rect . x = 0.0f ;
rect . y = 0.0f ;
rect . w = ( float ) TESTRENDER_SCREEN_W ;
rect . h = ( float ) TESTRENDER_SCREEN_H ;
ret = SDL_RenderTexture9GridTiled ( renderer , texture , NULL , 1.0f , 2.0f , 1.0f , 2.0f , 2.0f , & rect , 2.0f ) ;
SDLTest_AssertCheck ( ret = = true , " Validate results from call to SDL_RenderTexture9GridTiled, expected: true, got: %i " , ret ) ;
/* See if it's the same */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
}
/* Clean up. */
SDL_DestroySurface ( referenceSurface ) ;
SDL_DestroySurface ( source ) ;
SDL_DestroyTexture ( texture ) ;
return TEST_COMPLETED ;
}
2015-06-21 17:33:46 +02:00
/**
2023-11-06 10:26:06 -05:00
* Blits doing color tests .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_SetTextureColorMod
* \ sa SDL_RenderTexture
* \ sa SDL_DestroyTexture
2015-06-21 17:33:46 +02:00
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testBlitColor ( void * arg )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
int ret ;
2022-12-31 11:19:32 -08:00
SDL_FRect rect ;
2022-11-30 12:51:59 -08:00
SDL_Texture * tface ;
SDL_Surface * referenceSurface = NULL ;
int i , j , ni , nj ;
int checkFailCount1 ;
int checkFailCount2 ;
/* Clear surface. */
2022-12-29 22:58:16 +01:00
clearScreen ( ) ;
2022-11-30 12:51:59 -08:00
/* Create face surface. */
2022-12-29 22:58:16 +01:00
tface = loadTestFace ( ) ;
SDLTest_AssertCheck ( tface ! = NULL , " Verify loadTestFace() result " ) ;
2022-11-30 12:51:59 -08:00
if ( tface = = NULL ) {
return TEST_ABORTED ;
}
/* Constant values. */
2024-09-30 20:40:54 -07:00
rect . w = ( float ) tface - > w ;
rect . h = ( float ) tface - > h ;
ni = TESTRENDER_SCREEN_W - tface - > w ;
nj = TESTRENDER_SCREEN_H - tface - > h ;
2022-11-30 12:51:59 -08:00
/* Test blitting with color mod. */
checkFailCount1 = 0 ;
checkFailCount2 = 0 ;
for ( j = 0 ; j < = nj ; j + = 4 ) {
for ( i = 0 ; i < = ni ; i + = 4 ) {
/* Set color mod. */
2024-02-03 11:23:16 -08:00
ret = SDL_SetTextureColorMod ( tface , ( Uint8 ) ( ( 255 / nj ) * j ) , ( Uint8 ) ( ( 255 / ni ) * i ) , ( Uint8 ) ( ( 255 / nj ) * j ) ) ;
2024-08-22 17:33:49 -07:00
if ( ! ret ) {
2022-11-30 12:51:59 -08:00
checkFailCount1 + + ;
}
/* Blitting. */
2024-06-12 19:08:06 -07:00
rect . x = ( float ) i ;
rect . y = ( float ) j ;
2022-12-27 06:21:13 -08:00
ret = SDL_RenderTexture ( renderer , tface , NULL , & rect ) ;
2024-08-22 17:33:49 -07:00
if ( ! ret ) {
2022-11-30 12:51:59 -08:00
checkFailCount2 + + ;
}
}
}
SDLTest_AssertCheck ( checkFailCount1 = = 0 , " Validate results from calls to SDL_SetTextureColorMod, expected: 0, got: %i " , checkFailCount1 ) ;
2022-12-27 06:21:13 -08:00
SDLTest_AssertCheck ( checkFailCount2 = = 0 , " Validate results from calls to SDL_RenderTexture, expected: 0, got: %i " , checkFailCount2 ) ;
2022-11-30 12:51:59 -08:00
/* See if it's the same. */
referenceSurface = SDLTest_ImageBlitColor ( ) ;
2022-12-29 22:58:16 +01:00
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
2022-11-30 12:51:59 -08:00
/* Make current */
SDL_RenderPresent ( renderer ) ;
/* Clean up. */
SDL_DestroyTexture ( tface ) ;
2022-12-27 06:36:39 -08:00
SDL_DestroySurface ( referenceSurface ) ;
2022-11-30 12:51:59 -08:00
referenceSurface = NULL ;
return TEST_COMPLETED ;
2015-06-21 17:33:46 +02:00
}
2024-07-15 13:42:06 -07:00
typedef enum TestRenderOperation
{
TEST_RENDER_POINT ,
TEST_RENDER_LINE ,
TEST_RENDER_RECT ,
TEST_RENDER_COPY_XRGB ,
TEST_RENDER_COPY_ARGB ,
} TestRenderOperation ;
2015-06-21 17:33:46 +02:00
/**
2024-07-15 13:42:06 -07:00
* Helper that tests a specific operation and blend mode , - 1 for color mod , - 2 for alpha mod
2015-06-21 17:33:46 +02:00
*/
2024-07-15 13:42:06 -07:00
static void testBlendModeOperation ( TestRenderOperation op , int mode , SDL_PixelFormat dst_format )
2015-06-21 17:33:46 +02:00
{
2024-07-15 13:42:06 -07:00
/* Allow up to 2 delta from theoretical value to account for rounding error.
* We allow 2 rounding errors because the software renderer breaks drawing operations into alpha multiplication and a separate blend operation .
*/
const int MAXIMUM_ERROR = 2 ;
2022-11-30 12:51:59 -08:00
int ret ;
2024-07-15 13:42:06 -07:00
SDL_Texture * src = NULL ;
SDL_Texture * dst ;
SDL_Surface * result ;
Uint8 srcR = 10 , srcG = 128 , srcB = 240 , srcA = 100 ;
Uint8 dstR = 128 , dstG = 128 , dstB = 128 , dstA = 128 ;
Uint8 expectedR , expectedG , expectedB , expectedA ;
Uint8 actualR , actualG , actualB , actualA ;
int deltaR , deltaG , deltaB , deltaA ;
const char * operation = " UNKNOWN " ;
const char * mode_name = " UNKNOWN " ;
/* Create dst surface */
dst = SDL_CreateTexture ( renderer , dst_format , SDL_TEXTUREACCESS_TARGET , 3 , 3 ) ;
SDLTest_AssertCheck ( dst ! = NULL , " Verify dst surface is not NULL " ) ;
if ( dst = = NULL ) {
return ;
}
2024-07-16 18:00:20 -07:00
if ( SDL_ISPIXELFORMAT_ALPHA ( dst_format ) ) {
2024-07-17 09:40:25 -07:00
SDL_BlendMode blendMode = SDL_BLENDMODE_NONE ;
ret = SDL_GetTextureBlendMode ( dst , & blendMode ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_GetTextureBlendMode(), expected: true, got: %i " , ret ) ;
2024-07-16 18:00:20 -07:00
SDLTest_AssertCheck ( blendMode = = SDL_BLENDMODE_BLEND , " Verify alpha texture blend mode, expected %d, got % " SDL_PRIu32 , SDL_BLENDMODE_BLEND , blendMode ) ;
}
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
/* Set as render target */
SDL_SetRenderTarget ( renderer , dst ) ;
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
/* Clear surface. */
if ( ! SDL_ISPIXELFORMAT_ALPHA ( dst_format ) ) {
dstA = 255 ;
2022-11-30 12:51:59 -08:00
}
2024-07-15 13:42:06 -07:00
ret = SDL_SetRenderDrawColor ( renderer , dstR , dstG , dstB , dstA ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
ret = SDL_RenderClear ( renderer ) ;
SDLTest_AssertPass ( " Call to SDL_RenderClear() " ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_RenderClear, expected: true, got: %i " , ret ) ;
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
if ( op = = TEST_RENDER_COPY_XRGB | | op = = TEST_RENDER_COPY_ARGB ) {
Uint8 pixels [ 4 ] ;
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
/* Create src surface */
src = SDL_CreateTexture ( renderer , op = = TEST_RENDER_COPY_XRGB ? SDL_PIXELFORMAT_RGBX32 : SDL_PIXELFORMAT_RGBA32 , SDL_TEXTUREACCESS_STATIC , 1 , 1 ) ;
SDLTest_AssertCheck ( src ! = NULL , " Verify src surface is not NULL " ) ;
if ( src = = NULL ) {
return ;
}
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
/* Clear surface. */
if ( op = = TEST_RENDER_COPY_XRGB ) {
srcA = 255 ;
}
pixels [ 0 ] = srcR ;
pixels [ 1 ] = srcG ;
pixels [ 2 ] = srcB ;
pixels [ 3 ] = srcA ;
SDL_UpdateTexture ( src , NULL , pixels , sizeof ( pixels ) ) ;
/* Set blend mode. */
if ( mode > = 0 ) {
ret = SDL_SetTextureBlendMode ( src , ( SDL_BlendMode ) mode ) ;
SDLTest_AssertPass ( " Call to SDL_SetTextureBlendMode() " ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i " , mode , ret ) ;
2024-07-15 13:42:06 -07:00
} else {
ret = SDL_SetTextureBlendMode ( src , SDL_BLENDMODE_BLEND ) ;
SDLTest_AssertPass ( " Call to SDL_SetTextureBlendMode() " ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_SetTextureBlendMode(..., %i), expected: true, got: %i " , mode , ret ) ;
2024-07-15 13:42:06 -07:00
}
} else {
/* Set draw color */
ret = SDL_SetRenderDrawColor ( renderer , srcR , srcG , srcB , srcA ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_SetRenderDrawColor(), expected: true, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
/* Set blend mode. */
if ( mode > = 0 ) {
ret = SDL_SetRenderDrawBlendMode ( renderer , ( SDL_BlendMode ) mode ) ;
SDLTest_AssertPass ( " Call to SDL_SetRenderDrawBlendMode() " ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i " , mode , ret ) ;
2024-07-15 13:42:06 -07:00
} else {
ret = SDL_SetRenderDrawBlendMode ( renderer , SDL_BLENDMODE_BLEND ) ;
SDLTest_AssertPass ( " Call to SDL_SetRenderDrawBlendMode() " ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Verify result from SDL_SetRenderDrawBlendMode(..., %i), expected: true, got: %i " , mode , ret ) ;
2022-11-30 12:51:59 -08:00
}
}
2024-07-15 13:42:06 -07:00
/* Test blend mode. */
# define FLOAT(X) ((float)X / 255.0f)
switch ( mode ) {
case - 1 :
mode_name = " color modulation " ;
ret = SDL_SetTextureColorMod ( src , srcR , srcG , srcB ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from calls to SDL_SetTextureColorMod, expected: true, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( ( FLOAT ( srcR ) * FLOAT ( srcR ) ) * FLOAT ( srcA ) + FLOAT ( dstR ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( ( FLOAT ( srcG ) * FLOAT ( srcG ) ) * FLOAT ( srcA ) + FLOAT ( dstG ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( ( FLOAT ( srcB ) * FLOAT ( srcB ) ) * FLOAT ( srcA ) + FLOAT ( dstB ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcA ) + FLOAT ( dstA ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
break ;
case - 2 :
mode_name = " alpha modulation " ;
ret = SDL_SetTextureAlphaMod ( src , srcA ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from calls to SDL_SetTextureAlphaMod, expected: true, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
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 ) ;
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 ) ;
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 ) ;
expectedA = ( Uint8 ) SDL_roundf ( SDL_clamp ( ( FLOAT ( srcA ) * FLOAT ( srcA ) ) + FLOAT ( dstA ) * ( 1.0f - ( FLOAT ( srcA ) * FLOAT ( srcA ) ) ) , 0.0f , 1.0f ) * 255.0f ) ;
break ;
case SDL_BLENDMODE_NONE :
mode_name = " SDL_BLENDMODE_NONE " ;
expectedR = srcR ;
expectedG = srcG ;
expectedB = srcB ;
expectedA = SDL_ISPIXELFORMAT_ALPHA ( dst_format ) ? srcA : 255 ;
break ;
case SDL_BLENDMODE_BLEND :
mode_name = " SDL_BLENDMODE_BLEND " ;
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcR ) * FLOAT ( srcA ) + FLOAT ( dstR ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcG ) * FLOAT ( srcA ) + FLOAT ( dstG ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcB ) * FLOAT ( srcA ) + FLOAT ( dstB ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcA ) + FLOAT ( dstA ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
break ;
case SDL_BLENDMODE_BLEND_PREMULTIPLIED :
mode_name = " SDL_BLENDMODE_BLEND_PREMULTIPLIED " ;
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcR ) + FLOAT ( dstR ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcG ) + FLOAT ( dstG ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcB ) + FLOAT ( dstB ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcA ) + FLOAT ( dstA ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
break ;
case SDL_BLENDMODE_ADD :
mode_name = " SDL_BLENDMODE_ADD " ;
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcR ) * FLOAT ( srcA ) + FLOAT ( dstR ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcG ) * FLOAT ( srcA ) + FLOAT ( dstG ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcB ) * FLOAT ( srcA ) + FLOAT ( dstB ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = dstA ;
break ;
case SDL_BLENDMODE_ADD_PREMULTIPLIED :
mode_name = " SDL_BLENDMODE_ADD_PREMULTIPLIED " ;
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcR ) + FLOAT ( dstR ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcG ) + FLOAT ( dstG ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcB ) + FLOAT ( dstB ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = dstA ;
break ;
case SDL_BLENDMODE_MOD :
mode_name = " SDL_BLENDMODE_MOD " ;
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcR ) * FLOAT ( dstR ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcG ) * FLOAT ( dstG ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcB ) * FLOAT ( dstB ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = dstA ;
break ;
case SDL_BLENDMODE_MUL :
mode_name = " SDL_BLENDMODE_MUL " ;
expectedR = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcR ) * FLOAT ( dstR ) + FLOAT ( dstR ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedG = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcG ) * FLOAT ( dstG ) + FLOAT ( dstG ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedB = ( Uint8 ) SDL_roundf ( SDL_clamp ( FLOAT ( srcB ) * FLOAT ( dstB ) + FLOAT ( dstB ) * ( 1.0f - FLOAT ( srcA ) ) , 0.0f , 1.0f ) * 255.0f ) ;
expectedA = dstA ;
break ;
default :
SDLTest_LogError ( " Invalid blending mode: %d " , mode ) ;
return ;
}
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
switch ( op ) {
case TEST_RENDER_POINT :
operation = " render point " ;
ret = SDL_RenderPoint ( renderer , 0.0f , 0.0f ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from calls to SDL_RenderPoint, expected: 0, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
break ;
case TEST_RENDER_LINE :
operation = " render line " ;
ret = SDL_RenderLine ( renderer , 0.0f , 0.0f , 2.0f , 2.0f ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from calls to SDL_RenderLine, expected: true, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
break ;
case TEST_RENDER_RECT :
operation = " render rect " ;
ret = SDL_RenderFillRect ( renderer , NULL ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from calls to SDL_RenderFillRect, expected: 0, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
break ;
case TEST_RENDER_COPY_XRGB :
case TEST_RENDER_COPY_ARGB :
operation = ( op = = TEST_RENDER_COPY_XRGB ) ? " render XRGB " : " render ARGB " ;
ret = SDL_RenderTexture ( renderer , src , NULL , NULL ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate results from calls to SDL_RenderTexture, expected: true, got: %i " , ret ) ;
2024-07-15 13:42:06 -07:00
break ;
default :
SDLTest_LogError ( " Invalid blending operation: %d " , op ) ;
return ;
}
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
result = SDL_RenderReadPixels ( renderer , NULL ) ;
SDL_ReadSurfacePixel ( result , 0 , 0 , & actualR , & actualG , & actualB , & actualA ) ;
deltaR = SDL_abs ( ( int ) actualR - expectedR ) ;
deltaG = SDL_abs ( ( int ) actualG - expectedG ) ;
deltaB = SDL_abs ( ( int ) actualB - expectedB ) ;
2025-01-20 11:40:04 -08:00
deltaA = SDL_abs ( ( int ) actualA - expectedA ) ;
2024-07-15 13:42:06 -07:00
SDLTest_AssertCheck (
deltaR < = MAXIMUM_ERROR & &
deltaG < = MAXIMUM_ERROR & &
deltaB < = MAXIMUM_ERROR & &
deltaA < = MAXIMUM_ERROR ,
" Checking %s %s operation results, expected %d,%d,%d,%d, got %d,%d,%d,%d " ,
operation , mode_name ,
expectedR , expectedG , expectedB , expectedA , actualR , actualG , actualB , actualA ) ;
/* Clean up */
SDL_DestroySurface ( result ) ;
SDL_DestroyTexture ( src ) ;
SDL_DestroyTexture ( dst ) ;
2015-06-21 17:33:46 +02:00
}
2024-07-15 13:42:06 -07:00
static void testBlendMode ( int mode )
2015-06-21 17:33:46 +02:00
{
2024-07-15 13:42:06 -07:00
const TestRenderOperation operations [ ] = {
TEST_RENDER_POINT ,
TEST_RENDER_LINE ,
TEST_RENDER_RECT ,
TEST_RENDER_COPY_XRGB ,
TEST_RENDER_COPY_ARGB
} ;
const SDL_PixelFormat dst_formats [ ] = {
SDL_PIXELFORMAT_XRGB8888 , SDL_PIXELFORMAT_ARGB8888
} ;
int i , j ;
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
for ( i = 0 ; i < SDL_arraysize ( operations ) ; + + i ) {
for ( j = 0 ; j < SDL_arraysize ( dst_formats ) ; + + j ) {
TestRenderOperation op = operations [ i ] ;
2022-11-30 12:51:59 -08:00
2024-07-15 13:42:06 -07:00
if ( mode < 0 ) {
if ( op ! = TEST_RENDER_COPY_XRGB & & op ! = TEST_RENDER_COPY_ARGB ) {
/* Unsupported mode for this operation */
continue ;
}
2022-11-30 12:51:59 -08:00
}
2024-07-15 13:42:06 -07:00
testBlendModeOperation ( op , mode , dst_formats [ j ] ) ;
2022-11-30 12:51:59 -08:00
}
}
2015-06-21 17:33:46 +02:00
}
/**
2024-07-15 13:42:06 -07:00
* Tests render operations with blend modes
2015-06-21 17:33:46 +02:00
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testBlendModes ( void * arg )
2015-06-21 17:33:46 +02:00
{
2024-07-15 13:42:06 -07:00
testBlendMode ( - 1 ) ;
testBlendMode ( - 2 ) ;
testBlendMode ( SDL_BLENDMODE_NONE ) ;
testBlendMode ( SDL_BLENDMODE_BLEND ) ;
testBlendMode ( SDL_BLENDMODE_BLEND_PREMULTIPLIED ) ;
testBlendMode ( SDL_BLENDMODE_ADD ) ;
testBlendMode ( SDL_BLENDMODE_ADD_PREMULTIPLIED ) ;
testBlendMode ( SDL_BLENDMODE_MOD ) ;
testBlendMode ( SDL_BLENDMODE_MUL ) ;
2022-11-30 12:51:59 -08:00
return TEST_COMPLETED ;
2015-06-21 17:33:46 +02:00
}
2023-01-26 13:58:38 -08:00
/**
2023-11-06 10:26:06 -05:00
* Test viewport
2023-01-26 13:58:38 -08:00
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testViewport ( void * arg )
2023-01-26 13:58:38 -08:00
{
2023-01-26 16:10:13 -08:00
SDL_Surface * referenceSurface ;
2024-06-12 19:08:06 -07:00
SDL_Rect viewport ;
2023-01-26 13:58:38 -08:00
2023-01-26 16:10:13 -08:00
viewport . x = TESTRENDER_SCREEN_W / 3 ;
viewport . y = TESTRENDER_SCREEN_H / 3 ;
viewport . w = TESTRENDER_SCREEN_W / 2 ;
viewport . h = TESTRENDER_SCREEN_H / 2 ;
2023-01-26 13:58:38 -08:00
2023-01-26 16:10:13 -08:00
/* Create expected result */
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , RENDER_COMPARE_FORMAT ) ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , NULL , RENDER_COLOR_CLEAR ) )
2024-06-12 19:08:06 -07:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , & viewport , RENDER_COLOR_GREEN ) )
2023-02-02 00:21:53 +01:00
2023-01-26 13:58:38 -08:00
/* Clear surface. */
clearScreen ( ) ;
2023-01-26 16:10:13 -08:00
/* Set the viewport and do a fill operation */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , & viewport ) )
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , NULL ) )
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , NULL ) )
2023-01-26 13:58:38 -08:00
/* Check to see if final image matches. */
2023-01-26 14:49:23 -08:00
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
2023-01-26 16:10:13 -08:00
/*
* Verify that clear ignores the viewport
*/
/* Create expected result */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , NULL , RENDER_COLOR_GREEN ) )
2023-02-02 00:21:53 +01:00
2023-01-26 16:10:13 -08:00
/* Clear surface. */
clearScreen ( ) ;
/* Set the viewport and do a clear operation */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , & viewport ) )
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderClear , ( renderer ) )
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , NULL ) )
2023-01-26 16:10:13 -08:00
/* Check to see if final image matches. */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
2023-01-26 14:49:23 -08:00
/* Make current */
SDL_RenderPresent ( renderer ) ;
SDL_DestroySurface ( referenceSurface ) ;
return TEST_COMPLETED ;
}
2025-03-15 20:01:51 +01:00
static int SDLCALL render_testRGBSurfaceNoAlpha ( void * arg )
{
SDL_Surface * surface ;
SDL_Renderer * software_renderer ;
SDL_Surface * surface2 ;
SDL_Texture * texture2 ;
bool result ;
SDL_FRect dest_rect ;
SDL_FPoint point ;
const SDL_PixelFormatDetails * format_details ;
Uint8 r , g , b , a ;
SDLTest_AssertPass ( " About to call SDL_CreateSurface(128, 128, SDL_PIXELFORMAT_RGBX32) " ) ;
surface = SDL_CreateSurface ( 128 , 128 , SDL_PIXELFORMAT_RGBX32 ) ;
SDLTest_AssertCheck ( surface ! = NULL , " Returned surface must be not NULL " ) ;
if ( surface = = NULL ) {
return TEST_ABORTED ;
}
SDLTest_AssertPass ( " About to call SDL_GetPixelFormatDetails(surface->format) " ) ;
format_details = SDL_GetPixelFormatDetails ( surface - > format ) ;
SDLTest_AssertCheck ( format_details ! = NULL , " Result must be non-NULL, is %p " , format_details ) ;
if ( format_details = = NULL ) {
SDL_DestroySurface ( surface ) ;
return TEST_ABORTED ;
}
SDLTest_AssertCheck ( format_details - > bits_per_pixel = = 32 , " format_details->bits_per_pixel is %d, should be %d " , format_details - > bits_per_pixel , 32 ) ;
SDLTest_AssertCheck ( format_details - > bytes_per_pixel = = 4 , " format_details->bytes_per_pixel is %d, should be %d " , format_details - > bytes_per_pixel , 4 ) ;
SDLTest_AssertPass ( " About to call SDL_CreateSoftwareRenderer(surface) " ) ;
software_renderer = SDL_CreateSoftwareRenderer ( surface ) ;
SDLTest_AssertCheck ( software_renderer ! = NULL , " Returned renderer must be not NULL " ) ;
if ( software_renderer = = NULL ) {
SDL_DestroySurface ( surface ) ;
return TEST_ABORTED ;
}
SDLTest_AssertPass ( " About to call SDL_CreateSurface(16, 16, SDL_PIXELFORMAT_RGBX32) " ) ;
surface2 = SDL_CreateSurface ( 16 , 16 , SDL_PIXELFORMAT_RGBX32 ) ;
SDLTest_AssertCheck ( surface2 ! = NULL , " Returned surface must be not NULL " ) ;
if ( surface2 = = NULL ) {
SDL_DestroySurface ( surface ) ;
SDL_DestroyRenderer ( software_renderer ) ;
return TEST_ABORTED ;
}
SDLTest_AssertPass ( " About to call SDL_FillRect(surface2, NULL, 0) " ) ;
result = SDL_FillSurfaceRect ( surface2 , NULL , SDL_MapRGB ( SDL_GetPixelFormatDetails ( surface2 - > format ) , NULL , 0 , 0 , 0 ) ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertPass ( " About to call SDL_CreateTextureFromSurface(software_renderer, surface2) " ) ;
texture2 = SDL_CreateTextureFromSurface ( software_renderer , surface2 ) ;
SDLTest_AssertCheck ( texture2 ! = NULL , " Returned texture is not NULL " ) ;
SDLTest_AssertPass ( " About to call SDL_SetRenderDrawColor(renderer, 0xaa, 0xbb, 0xcc, 0x0) " ) ;
result = SDL_SetRenderDrawColor ( software_renderer , 0xaa , 0xbb , 0xcc , 0x0 ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertPass ( " About to call SDL_RenderClear(renderer) " ) ;
result = SDL_RenderClear ( software_renderer ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertPass ( " About to call SDL_SetRenderDrawColor(renderer, 0x0, 0x0, 0x0, 0x0) " ) ;
result = SDL_SetRenderDrawColor ( software_renderer , 0x0 , 0x0 , 0x0 , 0x0 ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
dest_rect . x = 32 ;
dest_rect . y = 32 ;
dest_rect . w = ( float ) surface2 - > w ;
dest_rect . h = ( float ) surface2 - > h ;
point . x = 0 ;
point . y = 0 ;
SDLTest_AssertPass ( " About to call SDL_RenderCopy(software_renderer, texture, NULL, &{%g, %g, %g, %g}) " ,
dest_rect . x , dest_rect . h , dest_rect . w , dest_rect . h ) ;
result = SDL_RenderTextureRotated ( software_renderer , texture2 , NULL , & dest_rect , 180 , & point , SDL_FLIP_NONE ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertPass ( " About to call SDL_RenderPresent(software_renderer) " ) ;
SDL_RenderPresent ( software_renderer ) ;
SDLTest_AssertPass ( " About to call SDL_ReadSurfacePixel(0, 0) " ) ;
result = SDL_ReadSurfacePixel ( surface , 0 , 0 , & r , & g , & b , & a ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertCheck ( r = = 0xaa & & g = = 0xbb & & b = = 0xcc & & a = = SDL_ALPHA_OPAQUE ,
" Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x} " ,
r , g , b , a , 0xaa , 0xbb , 0xcc , SDL_ALPHA_OPAQUE ) ;
SDLTest_AssertPass ( " About to call SDL_ReadSurfacePixel(15, 15) " ) ;
result = SDL_ReadSurfacePixel ( surface , 15 , 15 , & r , & g , & b , & a ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertCheck ( r = = 0xaa & & g = = 0xbb & & b = = 0xcc & & a = = SDL_ALPHA_OPAQUE ,
" Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x} " ,
r , g , b , a , 0xaa , 0xbb , 0xcc , SDL_ALPHA_OPAQUE ) ;
SDLTest_AssertPass ( " About to call SDL_ReadSurfacePixel(16, 16) " ) ;
result = SDL_ReadSurfacePixel ( surface , 16 , 16 , & r , & g , & b , & a ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertCheck ( r = = 0x00 & & g = = 0x00 & & b = = 0x00 & & a = = SDL_ALPHA_OPAQUE ,
" Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x} " ,
r , g , b , a , 0x00 , 0x00 , 0x00 , SDL_ALPHA_OPAQUE ) ;
SDLTest_AssertPass ( " About to call SDL_ReadSurfacePixel(31, 31) " ) ;
result = SDL_ReadSurfacePixel ( surface , 31 , 31 , & r , & g , & b , & a ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertCheck ( r = = 0x00 & & g = = 0x00 & & b = = 0x00 & & a = = SDL_ALPHA_OPAQUE ,
" Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x} " ,
r , g , b , a , 0x00 , 0x00 , 0x00 , SDL_ALPHA_OPAQUE ) ;
SDLTest_AssertPass ( " About to call SDL_ReadSurfacePixel(32, 32) " ) ;
result = SDL_ReadSurfacePixel ( surface , 32 , 32 , & r , & g , & b , & a ) ;
SDLTest_AssertCheck ( result = = true , " Result is %d, should be %d " , result , true ) ;
SDLTest_AssertCheck ( r = = 0xaa & & g = = 0xbb & & b = = 0xcc & & a = = SDL_ALPHA_OPAQUE ,
" Pixel at (0, 0) is {0x%02x,0x%02x,0x%02x,0x%02x}, should be {0x%02x,0x%02x,0x%02x,0x%02x} " ,
r , g , b , a , 0xaa , 0xbb , 0xcc , SDL_ALPHA_OPAQUE ) ;
SDL_DestroyTexture ( texture2 ) ;
SDL_DestroySurface ( surface2 ) ;
SDL_DestroyRenderer ( software_renderer ) ;
SDL_DestroySurface ( surface ) ;
return TEST_COMPLETED ;
}
2024-02-25 09:44:41 -08:00
/**
* Test clip rect
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testClipRect ( void * arg )
2024-02-25 09:44:41 -08:00
{
SDL_Surface * referenceSurface ;
2024-06-12 19:08:06 -07:00
SDL_Rect cliprect ;
2024-02-25 09:44:41 -08:00
cliprect . x = TESTRENDER_SCREEN_W / 3 ;
cliprect . y = TESTRENDER_SCREEN_H / 3 ;
cliprect . w = TESTRENDER_SCREEN_W / 2 ;
cliprect . h = TESTRENDER_SCREEN_H / 2 ;
/* Create expected result */
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , RENDER_COMPARE_FORMAT ) ;
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , NULL , RENDER_COLOR_CLEAR ) )
2024-06-12 19:08:06 -07:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , & cliprect , RENDER_COLOR_GREEN ) )
2024-02-25 09:44:41 -08:00
/* Clear surface. */
clearScreen ( ) ;
/* Set the cliprect and do a fill operation */
CHECK_FUNC ( SDL_SetRenderClipRect , ( renderer , & cliprect ) )
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , NULL ) )
CHECK_FUNC ( SDL_SetRenderClipRect , ( renderer , NULL ) )
/* Check to see if final image matches. */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/*
* Verify that clear ignores the cliprect
*/
/* Create expected result */
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , NULL , RENDER_COLOR_GREEN ) )
/* Clear surface. */
clearScreen ( ) ;
/* Set the cliprect and do a clear operation */
CHECK_FUNC ( SDL_SetRenderClipRect , ( renderer , & cliprect ) )
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderClear , ( renderer ) )
CHECK_FUNC ( SDL_SetRenderClipRect , ( renderer , NULL ) )
/* Check to see if final image matches. */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
SDL_DestroySurface ( referenceSurface ) ;
return TEST_COMPLETED ;
}
2023-01-26 14:49:23 -08:00
/**
2023-11-06 10:26:06 -05:00
* Test logical size
2023-01-26 14:49:23 -08:00
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testLogicalSize ( void * arg )
2023-01-26 14:49:23 -08:00
{
2023-01-26 16:10:13 -08:00
SDL_Surface * referenceSurface ;
2024-06-12 19:08:06 -07:00
SDL_Rect viewport ;
2023-01-26 14:49:23 -08:00
SDL_FRect rect ;
2025-09-21 20:25:10 -07:00
int w = 0 , h = 0 ;
2024-06-29 14:12:50 -07:00
int set_w , set_h ;
SDL_RendererLogicalPresentation set_presentation_mode ;
SDL_FRect set_rect ;
2023-01-26 14:49:23 -08:00
const int factor = 2 ;
2025-09-21 20:25:10 -07:00
SDL_GetWindowSize ( window , & w , & h ) ;
if ( w ! = TESTRENDER_WINDOW_W | | h ! = TESTRENDER_WINDOW_H ) {
SDLTest_Log ( " Skipping test render_testLogicalSize: expected window %dx%d, got %dx%d " , TESTRENDER_WINDOW_W , TESTRENDER_WINDOW_H , w , h ) ;
return TEST_SKIPPED ;
}
2023-01-26 16:10:13 -08:00
viewport . x = ( ( TESTRENDER_SCREEN_W / 4 ) / factor ) * factor ;
viewport . y = ( ( TESTRENDER_SCREEN_H / 4 ) / factor ) * factor ;
viewport . w = ( ( TESTRENDER_SCREEN_W / 2 ) / factor ) * factor ;
viewport . h = ( ( TESTRENDER_SCREEN_H / 2 ) / factor ) * factor ;
2023-01-26 14:49:23 -08:00
2023-01-26 16:10:13 -08:00
/* Create expected result */
referenceSurface = SDL_CreateSurface ( TESTRENDER_SCREEN_W , TESTRENDER_SCREEN_H , RENDER_COMPARE_FORMAT ) ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , NULL , RENDER_COLOR_CLEAR ) )
2024-06-12 19:08:06 -07:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , & viewport , RENDER_COLOR_GREEN ) )
2023-02-02 00:21:53 +01:00
2023-01-26 14:49:23 -08:00
/* Clear surface. */
clearScreen ( ) ;
2023-01-26 16:10:13 -08:00
/* Set the logical size and do a fill operation */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_GetCurrentRenderOutputSize , ( renderer , & w , & h ) )
2024-09-16 13:33:16 -04:00
CHECK_FUNC ( SDL_SetRenderLogicalPresentation , ( renderer , w / factor , h / factor , SDL_LOGICAL_PRESENTATION_LETTERBOX ) )
CHECK_FUNC ( SDL_GetRenderLogicalPresentation , ( renderer , & set_w , & set_h , & set_presentation_mode ) )
2024-06-29 14:12:50 -07:00
SDLTest_AssertCheck (
set_w = = ( w / factor ) & &
set_h = = ( h / factor ) & &
2024-09-16 13:33:16 -04:00
set_presentation_mode = = SDL_LOGICAL_PRESENTATION_LETTERBOX ,
" Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d " , set_w , set_h , set_presentation_mode ) ;
2024-06-29 14:12:50 -07:00
CHECK_FUNC ( SDL_GetRenderLogicalPresentationRect , ( renderer , & set_rect ) )
SDLTest_AssertCheck (
set_rect . x = = 0.0f & &
set_rect . y = = 0.0f & &
2025-09-21 20:25:10 -07:00
set_rect . w = = ( float ) w & &
set_rect . h = = ( float ) h ,
2024-06-29 14:12:50 -07:00
" Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g} " , set_rect . x , set_rect . y , set_rect . w , set_rect . h ) ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
2024-06-12 19:08:06 -07:00
rect . x = ( float ) viewport . x / factor ;
rect . y = ( float ) viewport . y / factor ;
rect . w = ( float ) viewport . w / factor ;
rect . h = ( float ) viewport . h / factor ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , & rect ) )
2024-09-16 13:33:16 -04:00
CHECK_FUNC ( SDL_SetRenderLogicalPresentation , ( renderer , 0 , 0 , SDL_LOGICAL_PRESENTATION_DISABLED ) )
CHECK_FUNC ( SDL_GetRenderLogicalPresentation , ( renderer , & set_w , & set_h , & set_presentation_mode ) )
2024-06-29 14:12:50 -07:00
SDLTest_AssertCheck (
set_w = = 0 & &
set_h = = 0 & &
2024-09-16 13:33:16 -04:00
set_presentation_mode = = SDL_LOGICAL_PRESENTATION_DISABLED ,
" Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d " , set_w , set_h , set_presentation_mode ) ;
2024-06-29 14:12:50 -07:00
CHECK_FUNC ( SDL_GetRenderLogicalPresentationRect , ( renderer , & set_rect ) )
SDLTest_AssertCheck (
set_rect . x = = 0.0f & &
set_rect . y = = 0.0f & &
2025-09-21 20:25:10 -07:00
set_rect . w = = ( float ) w & &
set_rect . h = = ( float ) h ,
2024-06-29 14:12:50 -07:00
" Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g} " , set_rect . x , set_rect . y , set_rect . w , set_rect . h ) ;
2023-01-26 14:49:23 -08:00
/* Check to see if final image matches. */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Clear surface. */
clearScreen ( ) ;
2023-01-26 16:10:13 -08:00
/* Set the logical size and viewport and do a fill operation */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_GetCurrentRenderOutputSize , ( renderer , & w , & h ) )
2024-09-16 13:33:16 -04:00
CHECK_FUNC ( SDL_SetRenderLogicalPresentation , ( renderer , w / factor , h / factor , SDL_LOGICAL_PRESENTATION_LETTERBOX ) )
2023-01-26 16:10:13 -08:00
viewport . x = ( TESTRENDER_SCREEN_W / 4 ) / factor ;
viewport . y = ( TESTRENDER_SCREEN_H / 4 ) / factor ;
2025-01-08 23:33:39 -05:00
viewport . w = ( TESTRENDER_SCREEN_W / 2 ) / factor ;
viewport . h = ( TESTRENDER_SCREEN_H / 2 ) / factor ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , & viewport ) )
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , NULL ) )
CHECK_FUNC ( SDL_SetRenderViewport , ( renderer , NULL ) )
2024-09-16 13:33:16 -04:00
CHECK_FUNC ( SDL_SetRenderLogicalPresentation , ( renderer , 0 , 0 , SDL_LOGICAL_PRESENTATION_DISABLED ) )
2023-01-26 14:49:23 -08:00
/* Check to see if final image matches. */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
2023-01-26 13:58:38 -08:00
2023-01-26 16:10:13 -08:00
/*
* Test a logical size that isn ' t the same aspect ratio as the window
*/
viewport . x = ( TESTRENDER_SCREEN_W / 4 ) ;
viewport . y = 0 ;
viewport . w = TESTRENDER_SCREEN_W ;
viewport . h = TESTRENDER_SCREEN_H ;
/* Create expected result */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , NULL , RENDER_COLOR_CLEAR ) )
2024-06-12 19:08:06 -07:00
CHECK_FUNC ( SDL_FillSurfaceRect , ( referenceSurface , & viewport , RENDER_COLOR_GREEN ) )
2023-02-02 00:21:53 +01:00
2023-01-26 16:10:13 -08:00
/* Clear surface. */
clearScreen ( ) ;
/* Set the logical size and do a fill operation */
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_GetCurrentRenderOutputSize , ( renderer , & w , & h ) )
CHECK_FUNC ( SDL_SetRenderLogicalPresentation , ( renderer ,
2023-02-03 12:25:46 -08:00
w - 2 * ( TESTRENDER_SCREEN_W / 4 ) ,
h ,
2024-09-16 13:33:16 -04:00
SDL_LOGICAL_PRESENTATION_LETTERBOX ) )
CHECK_FUNC ( SDL_GetRenderLogicalPresentation , ( renderer , & set_w , & set_h , & set_presentation_mode ) )
2024-06-29 14:12:50 -07:00
SDLTest_AssertCheck (
set_w = = w - 2 * ( TESTRENDER_SCREEN_W / 4 ) & &
set_h = = h & &
2024-09-16 13:33:16 -04:00
set_presentation_mode = = SDL_LOGICAL_PRESENTATION_LETTERBOX ,
" Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d " , set_w , set_h , set_presentation_mode ) ;
2024-06-29 14:12:50 -07:00
CHECK_FUNC ( SDL_GetRenderLogicalPresentationRect , ( renderer , & set_rect ) )
SDLTest_AssertCheck (
set_rect . x = = 20.0f & &
set_rect . y = = 0.0f & &
set_rect . w = = 280.0f & &
set_rect . h = = 240.0f ,
" Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g} " , set_rect . x , set_rect . y , set_rect . w , set_rect . h ) ;
2023-02-05 09:08:33 -08:00
CHECK_FUNC ( SDL_SetRenderDrawColor , ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) )
CHECK_FUNC ( SDL_RenderFillRect , ( renderer , NULL ) )
2024-09-16 13:33:16 -04:00
CHECK_FUNC ( SDL_SetRenderLogicalPresentation , ( renderer , 0 , 0 , SDL_LOGICAL_PRESENTATION_DISABLED ) )
CHECK_FUNC ( SDL_GetRenderLogicalPresentation , ( renderer , & set_w , & set_h , & set_presentation_mode ) )
2024-06-29 14:12:50 -07:00
SDLTest_AssertCheck (
set_w = = 0 & &
set_h = = 0 & &
2024-09-16 13:33:16 -04:00
set_presentation_mode = = SDL_LOGICAL_PRESENTATION_DISABLED ,
" Validate result from SDL_GetRenderLogicalPresentation, got %d, %d, %d " , set_w , set_h , set_presentation_mode ) ;
2024-06-29 14:12:50 -07:00
CHECK_FUNC ( SDL_GetRenderLogicalPresentationRect , ( renderer , & set_rect ) )
SDLTest_AssertCheck (
set_rect . x = = 0.0f & &
set_rect . y = = 0.0f & &
set_rect . w = = 320.0f & &
set_rect . h = = 240.0f ,
" Validate result from SDL_GetRenderLogicalPresentationRect, got {%g, %g, %gx%g} " , set_rect . x , set_rect . y , set_rect . w , set_rect . h ) ;
2023-01-26 16:10:13 -08:00
/* Check to see if final image matches. */
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Clear surface. */
clearScreen ( ) ;
2023-01-26 13:58:38 -08:00
/* Make current */
SDL_RenderPresent ( renderer ) ;
SDL_DestroySurface ( referenceSurface ) ;
return TEST_COMPLETED ;
}
2025-03-15 01:18:33 +01:00
/**
* @ brief Tests setting and getting texture scale mode .
*
* \ sa
* http : //wiki.libsdl.org/SDL2/SDL_SetTextureScaleMode
* http : //wiki.libsdl.org/SDL2/SDL_GetTextureScaleMode
*/
static int SDLCALL render_testGetSetTextureScaleMode ( void * arg )
{
const struct {
const char * name ;
SDL_ScaleMode mode ;
} modes [ ] = {
{ " SDL_SCALEMODE_NEAREST " , SDL_SCALEMODE_NEAREST } ,
{ " SDL_SCALEMODE_LINEAR " , SDL_SCALEMODE_LINEAR } ,
{ " SDL_SCALEMODE_PIXELART " , SDL_SCALEMODE_PIXELART } ,
} ;
size_t i ;
for ( i = 0 ; i < SDL_arraysize ( modes ) ; i + + ) {
SDL_Texture * texture ;
bool result ;
SDL_ScaleMode actual_mode = SDL_SCALEMODE_NEAREST ;
SDL_ClearError ( ) ;
SDLTest_AssertPass ( " About to call SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 16, 16) " ) ;
texture = SDL_CreateTexture ( renderer , SDL_PIXELFORMAT_ARGB8888 , SDL_TEXTUREACCESS_STREAMING , 16 , 16 ) ;
SDLTest_AssertCheck ( texture ! = NULL , " SDL_CreateTexture must return a non-NULL texture " ) ;
SDLTest_AssertPass ( " About to call SDL_SetTextureScaleMode(texture, %s) " , modes [ i ] . name ) ;
result = SDL_SetTextureScaleMode ( texture , modes [ i ] . mode ) ;
SDLTest_AssertCheck ( result = = true , " SDL_SetTextureScaleMode returns %d, expected %d " , result , true ) ;
SDLTest_AssertPass ( " About to call SDL_GetTextureScaleMode(texture) " ) ;
result = SDL_GetTextureScaleMode ( texture , & actual_mode ) ;
SDLTest_AssertCheck ( result = = true , " SDL_SetTextureScaleMode returns %d, expected %d " , result , true ) ;
SDLTest_AssertCheck ( actual_mode = = modes [ i ] . mode , " SDL_GetTextureScaleMode must return %s (%d), actual=%d " ,
modes [ i ] . name , modes [ i ] . mode , actual_mode ) ;
}
return TEST_COMPLETED ;
}
2023-01-26 13:58:38 -08:00
/* Helper functions */
2015-06-21 17:33:46 +02:00
/**
2023-11-06 10:26:06 -05:00
* Checks to see if functionality is supported . Helper function .
2015-06-21 17:33:46 +02:00
*/
2024-09-18 07:52:28 -07:00
static bool isSupported ( int code )
2015-06-21 17:33:46 +02:00
{
2024-09-18 07:52:28 -07:00
return ( code ! = false ) ;
2015-06-21 17:33:46 +02:00
}
/**
2023-11-06 10:26:06 -05:00
* Test to see if we can vary the draw color . Helper function .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_SetRenderDrawColor
* \ sa SDL_GetRenderDrawColor
2015-06-21 17:33:46 +02:00
*/
2024-09-18 07:52:28 -07:00
static bool hasDrawColor ( void )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
int ret , fail ;
Uint8 r , g , b , a ;
fail = 0 ;
/* Set color. */
ret = SDL_SetRenderDrawColor ( renderer , 100 , 100 , 100 , 100 ) ;
2022-12-29 22:58:16 +01:00
if ( ! isSupported ( ret ) ) {
2022-11-30 12:51:59 -08:00
fail = 1 ;
}
ret = SDL_GetRenderDrawColor ( renderer , & r , & g , & b , & a ) ;
2022-12-29 22:58:16 +01:00
if ( ! isSupported ( ret ) ) {
2022-11-30 12:51:59 -08:00
fail = 1 ;
}
/* Restore natural. */
ret = SDL_SetRenderDrawColor ( renderer , 0 , 0 , 0 , SDL_ALPHA_OPAQUE ) ;
2022-12-29 22:58:16 +01:00
if ( ! isSupported ( ret ) ) {
2022-11-30 12:51:59 -08:00
fail = 1 ;
}
/* Something failed, consider not available. */
if ( fail ) {
2024-09-18 07:52:28 -07:00
return false ;
2022-11-30 12:51:59 -08:00
}
/* Not set properly, consider failed. */
else if ( ( r ! = 100 ) | | ( g ! = 100 ) | | ( b ! = 100 ) | | ( a ! = 100 ) ) {
2024-09-18 07:52:28 -07:00
return false ;
2022-11-30 12:51:59 -08:00
}
2024-09-18 07:52:28 -07:00
return true ;
2015-06-21 17:33:46 +02:00
}
/**
2023-11-06 10:26:06 -05:00
* Loads the test image ' Face ' as texture . Helper function .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_CreateTextureFromSurface
2015-06-21 17:33:46 +02:00
*/
static SDL_Texture *
2022-12-29 22:58:16 +01:00
loadTestFace ( void )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
SDL_Surface * face ;
SDL_Texture * tface ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
face = SDLTest_ImageFace ( ) ;
2023-11-09 22:29:15 +01:00
if ( ! face ) {
2022-11-30 12:51:59 -08:00
return NULL ;
}
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
tface = SDL_CreateTextureFromSurface ( renderer , face ) ;
2023-11-09 22:29:15 +01:00
if ( ! tface ) {
2022-11-30 12:51:59 -08:00
SDLTest_LogError ( " SDL_CreateTextureFromSurface() failed with error: %s " , SDL_GetError ( ) ) ;
}
2015-06-21 17:33:46 +02:00
2022-12-27 06:36:39 -08:00
SDL_DestroySurface ( face ) ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
return tface ;
2015-06-21 17:33:46 +02:00
}
/**
2023-11-06 10:26:06 -05:00
* Compares screen pixels with image pixels . Helper function .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ param referenceSurface Image to compare against .
* \ param allowable_error allowed difference from the reference image
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_RenderReadPixels
* \ sa SDL_CreateSurfaceFrom
* \ sa SDL_DestroySurface
2015-06-21 17:33:46 +02:00
*/
2024-07-20 13:47:01 -07:00
static void compare ( SDL_Surface * referenceSurface , int allowable_error )
2015-06-21 17:33:46 +02:00
{
2024-02-03 10:18:12 -08:00
int ret ;
SDL_Rect rect ;
SDL_Surface * surface , * testSurface ;
/* Explicitly specify the rect in case the window isn't the expected size... */
rect . x = 0 ;
rect . y = 0 ;
rect . w = TESTRENDER_SCREEN_W ;
rect . h = TESTRENDER_SCREEN_H ;
surface = SDL_RenderReadPixels ( renderer , & rect ) ;
if ( ! surface ) {
SDLTest_AssertCheck ( surface ! = NULL , " Validate result from SDL_RenderReadPixels, got NULL, %s " , SDL_GetError ( ) ) ;
return ;
}
2024-07-08 14:59:18 -07:00
testSurface = SDL_ConvertSurface ( surface , RENDER_COMPARE_FORMAT ) ;
2024-02-03 10:18:12 -08:00
SDL_DestroySurface ( surface ) ;
if ( ! testSurface ) {
2024-07-08 14:59:18 -07:00
SDLTest_AssertCheck ( testSurface ! = NULL , " Validate result from SDL_ConvertSurface, got NULL, %s " , SDL_GetError ( ) ) ;
2024-02-03 10:18:12 -08:00
return ;
}
/* Compare surface. */
ret = SDLTest_CompareSurfaces ( testSurface , referenceSurface , allowable_error ) ;
SDLTest_AssertCheck ( ret = = 0 , " Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i " , ret ) ;
/* Clean up. */
SDL_DestroySurface ( testSurface ) ;
2015-06-21 17:33:46 +02:00
}
2024-07-20 13:47:01 -07:00
static void compare2x ( SDL_Surface * referenceSurface , int allowable_error )
{
int ret ;
SDL_Rect rect ;
SDL_Surface * surface , * testSurface ;
/* Explicitly specify the rect in case the window isn't the expected size... */
rect . x = 0 ;
rect . y = 0 ;
rect . w = TESTRENDER_SCREEN_W * 2 ;
rect . h = TESTRENDER_SCREEN_H * 2 ;
surface = SDL_RenderReadPixels ( renderer , & rect ) ;
if ( ! surface ) {
SDLTest_AssertCheck ( surface ! = NULL , " Validate result from SDL_RenderReadPixels, got NULL, %s " , SDL_GetError ( ) ) ;
return ;
}
testSurface = SDL_ConvertSurface ( surface , RENDER_COMPARE_FORMAT ) ;
SDL_DestroySurface ( surface ) ;
if ( ! testSurface ) {
SDLTest_AssertCheck ( testSurface ! = NULL , " Validate result from SDL_ConvertSurface, got NULL, %s " , SDL_GetError ( ) ) ;
return ;
}
/* Compare surface. */
ret = SDLTest_CompareSurfaces ( testSurface , referenceSurface , allowable_error ) ;
SDLTest_AssertCheck ( ret = = 0 , " Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i " , ret ) ;
/* Clean up. */
SDL_DestroySurface ( testSurface ) ;
}
2015-06-21 17:33:46 +02:00
/**
2023-11-06 10:26:06 -05:00
* Clears the screen . Helper function .
2015-06-21 17:33:46 +02:00
*
2023-02-02 00:21:53 +01:00
* \ sa SDL_SetRenderDrawColor
* \ sa SDL_RenderClear
* \ sa SDL_RenderPresent
* \ sa SDL_SetRenderDrawBlendMode
2015-06-21 17:33:46 +02:00
*/
static int
2022-12-29 22:58:16 +01:00
clearScreen ( void )
2015-06-21 17:33:46 +02:00
{
2022-11-30 12:51:59 -08:00
int ret ;
2015-06-21 17:33:46 +02:00
2023-01-26 16:10:13 -08:00
/* Make current */
SDL_RenderPresent ( renderer ) ;
2023-02-02 00:21:53 +01:00
2022-11-30 12:51:59 -08:00
/* Set color. */
ret = SDL_SetRenderDrawColor ( renderer , 0 , 0 , 0 , SDL_ALPHA_OPAQUE ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate result from SDL_SetRenderDrawColor, expected: true, got: %i " , ret ) ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
/* Clear screen. */
ret = SDL_RenderClear ( renderer ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate result from SDL_RenderClear, expected: true, got: %i " , ret ) ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
/* Set defaults. */
ret = SDL_SetRenderDrawBlendMode ( renderer , SDL_BLENDMODE_NONE ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate result from SDL_SetRenderDrawBlendMode, expected: true, got: %i " , ret ) ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
ret = SDL_SetRenderDrawColor ( renderer , 255 , 255 , 255 , SDL_ALPHA_OPAQUE ) ;
2024-09-18 07:52:28 -07:00
SDLTest_AssertCheck ( ret = = true , " Validate result from SDL_SetRenderDrawColor, expected: true, got: %i " , ret ) ;
2015-06-21 17:33:46 +02:00
2022-11-30 12:51:59 -08:00
return 0 ;
2015-06-21 17:33:46 +02:00
}
2025-07-19 16:33:53 +02:00
/**
* Tests geometry UV clamping
*/
static int SDLCALL render_testUVClamping ( void * arg )
{
SDL_Vertex vertices [ 6 ] ;
SDL_Vertex * verts = vertices ;
SDL_FColor color = { 1.0f , 1.0f , 1.0f , 1.0f } ;
SDL_FRect rect ;
float min_U = - 0.5f ;
float max_U = 1.5f ;
float min_V = - 0.5f ;
float max_V = 1.5f ;
SDL_Texture * tface ;
SDL_Surface * referenceSurface = NULL ;
/* Clear surface. */
clearScreen ( ) ;
/* Create face surface. */
tface = loadTestFace ( ) ;
SDLTest_AssertCheck ( tface ! = NULL , " Verify loadTestFace() result " ) ;
if ( tface = = NULL ) {
return TEST_ABORTED ;
}
rect . w = ( float ) tface - > w * 2 ;
rect . h = ( float ) tface - > h * 2 ;
rect . x = ( TESTRENDER_SCREEN_W - rect . w ) / 2 ;
rect . y = ( TESTRENDER_SCREEN_H - rect . h ) / 2 ;
/*
* 0 - - 1
* | / |
* | / |
* 3 - - 2
*
* Draw sprite2 as triangles that can be recombined as rect by software renderer
*/
/* 0 */
verts - > position . x = rect . x ;
verts - > position . y = rect . y ;
verts - > color = color ;
verts - > tex_coord . x = min_U ;
verts - > tex_coord . y = min_V ;
verts + + ;
/* 1 */
verts - > position . x = rect . x + rect . w ;
verts - > position . y = rect . y ;
verts - > color = color ;
verts - > tex_coord . x = max_U ;
verts - > tex_coord . y = min_V ;
verts + + ;
/* 2 */
verts - > position . x = rect . x + rect . w ;
verts - > position . y = rect . y + rect . h ;
verts - > color = color ;
verts - > tex_coord . x = max_U ;
verts - > tex_coord . y = max_V ;
verts + + ;
/* 0 */
verts - > position . x = rect . x ;
verts - > position . y = rect . y ;
verts - > color = color ;
verts - > tex_coord . x = min_U ;
verts - > tex_coord . y = min_V ;
verts + + ;
/* 2 */
verts - > position . x = rect . x + rect . w ;
verts - > position . y = rect . y + rect . h ;
verts - > color = color ;
verts - > tex_coord . x = max_U ;
verts - > tex_coord . y = max_V ;
verts + + ;
/* 3 */
verts - > position . x = rect . x ;
verts - > position . y = rect . y + rect . h ;
verts - > color = color ;
verts - > tex_coord . x = min_U ;
verts - > tex_coord . y = max_V ;
verts + + ;
/* Set texture address mode to clamp */
SDL_SetRenderTextureAddressMode ( renderer , SDL_TEXTURE_ADDRESS_CLAMP , SDL_TEXTURE_ADDRESS_CLAMP ) ;
/* Blit sprites as triangles onto the screen */
SDL_RenderGeometry ( renderer , tface , vertices , 6 , NULL , 0 ) ;
/* See if it's the same */
referenceSurface = SDLTest_ImageClampedSprite ( ) ;
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
/* Clean up. */
SDL_DestroyTexture ( tface ) ;
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = NULL ;
return TEST_COMPLETED ;
}
2024-07-17 22:49:05 -07:00
/**
* Tests geometry UV wrapping
*/
2024-09-06 03:21:13 +02:00
static int SDLCALL render_testUVWrapping ( void * arg )
2024-07-17 22:49:05 -07:00
{
SDL_Vertex vertices [ 6 ] ;
SDL_Vertex * verts = vertices ;
SDL_FColor color = { 1.0f , 1.0f , 1.0f , 1.0f } ;
SDL_FRect rect ;
float min_U = - 0.5f ;
float max_U = 1.5f ;
float min_V = - 0.5f ;
float max_V = 1.5f ;
SDL_Texture * tface ;
SDL_Surface * referenceSurface = NULL ;
/* Clear surface. */
clearScreen ( ) ;
/* Create face surface. */
tface = loadTestFace ( ) ;
SDLTest_AssertCheck ( tface ! = NULL , " Verify loadTestFace() result " ) ;
if ( tface = = NULL ) {
return TEST_ABORTED ;
}
2024-09-30 20:40:54 -07:00
rect . w = ( float ) tface - > w * 2 ;
rect . h = ( float ) tface - > h * 2 ;
2025-02-21 17:30:24 +01:00
rect . x = ( TESTRENDER_SCREEN_W - rect . w ) / 2 ;
rect . y = ( TESTRENDER_SCREEN_H - rect . h ) / 2 ;
2024-07-17 22:49:05 -07:00
/*
* 0 - - 1
* | / |
* | / |
* 3 - - 2
*
* Draw sprite2 as triangles that can be recombined as rect by software renderer
*/
/* 0 */
verts - > position . x = rect . x ;
verts - > position . y = rect . y ;
verts - > color = color ;
verts - > tex_coord . x = min_U ;
verts - > tex_coord . y = min_V ;
verts + + ;
/* 1 */
verts - > position . x = rect . x + rect . w ;
verts - > position . y = rect . y ;
verts - > color = color ;
verts - > tex_coord . x = max_U ;
verts - > tex_coord . y = min_V ;
verts + + ;
/* 2 */
verts - > position . x = rect . x + rect . w ;
verts - > position . y = rect . y + rect . h ;
verts - > color = color ;
verts - > tex_coord . x = max_U ;
verts - > tex_coord . y = max_V ;
verts + + ;
/* 0 */
verts - > position . x = rect . x ;
verts - > position . y = rect . y ;
verts - > color = color ;
verts - > tex_coord . x = min_U ;
verts - > tex_coord . y = min_V ;
verts + + ;
/* 2 */
verts - > position . x = rect . x + rect . w ;
verts - > position . y = rect . y + rect . h ;
verts - > color = color ;
verts - > tex_coord . x = max_U ;
verts - > tex_coord . y = max_V ;
verts + + ;
/* 3 */
verts - > position . x = rect . x ;
verts - > position . y = rect . y + rect . h ;
verts - > color = color ;
verts - > tex_coord . x = min_U ;
verts - > tex_coord . y = max_V ;
verts + + ;
/* Blit sprites as triangles onto the screen */
SDL_RenderGeometry ( renderer , tface , vertices , 6 , NULL , 0 ) ;
/* See if it's the same */
referenceSurface = SDLTest_ImageWrappingSprite ( ) ;
compare ( referenceSurface , ALLOWABLE_ERROR_OPAQUE ) ;
/* Make current */
SDL_RenderPresent ( renderer ) ;
/* Clean up. */
SDL_DestroyTexture ( tface ) ;
SDL_DestroySurface ( referenceSurface ) ;
referenceSurface = NULL ;
return TEST_COMPLETED ;
}
2025-03-05 18:56:59 -08:00
/**
* Tests texture state changes
*/
static int SDLCALL render_testTextureState ( void * arg )
{
const Uint8 pixels [ 8 ] = {
0x00 , 0x00 , 0x00 , 0xFF ,
0xFF , 0xFF , 0xFF , 0xFF
} ;
const SDL_Color expected [ ] = {
/* Step 0: plain copy */
{ 0x00 , 0x00 , 0x00 , 0xFF } ,
{ 0xFF , 0xFF , 0xFF , 0xFF } ,
/* Step 1: color mod to red */
{ 0x00 , 0x00 , 0x00 , 0xFF } ,
{ 0xFF , 0x00 , 0x00 , 0xFF } ,
/* Step 2: alpha mod to 128 (cleared to green) */
{ 0x00 , 0x7F , 0x00 , 0xFF } ,
{ 0x80 , 0xFF , 0x80 , 0xFF } ,
/* Step 3: nearest stretch */
{ 0xFF , 0xFF , 0xFF , 0xFF } ,
{ 0x00 , 0xFF , 0x00 , 0xFF } ,
/* Step 4: linear stretch */
{ 0x80 , 0x80 , 0x80 , 0xFF } ,
{ 0x00 , 0xFF , 0x00 , 0xFF } ,
} ;
SDL_Texture * texture ;
SDL_Rect rect ;
SDL_FRect dst ;
int i ;
/* Clear surface to green */
SDL_SetRenderDrawColor ( renderer , 0 , 255 , 0 , SDL_ALPHA_OPAQUE ) ;
SDL_RenderClear ( renderer ) ;
/* Create 2-pixel surface. */
texture = SDL_CreateTexture ( renderer , SDL_PIXELFORMAT_RGBA32 , SDL_TEXTUREACCESS_STATIC , 2 , 1 ) ;
SDLTest_AssertCheck ( texture ! = NULL , " Verify SDL_CreateTexture() result " ) ;
if ( texture = = NULL ) {
return TEST_ABORTED ;
}
SDL_UpdateTexture ( texture , NULL , pixels , sizeof ( pixels ) ) ;
dst . x = 0.0f ;
dst . y = 0.0f ;
dst . w = 2.0f ;
dst . h = 1.0f ;
/* Step 0: plain copy */
SDL_RenderTexture ( renderer , texture , NULL , & dst ) ;
dst . y + = 1 ;
/* Step 1: color mod to red */
SDL_SetTextureColorMod ( texture , 0xFF , 0x00 , 0x00 ) ;
SDL_RenderTexture ( renderer , texture , NULL , & dst ) ;
SDL_SetTextureColorMod ( texture , 0xFF , 0xFF , 0xFF ) ;
dst . y + = 1 ;
/* Step 2: alpha mod to 128 */
SDL_SetTextureAlphaMod ( texture , 0x80 ) ;
SDL_RenderTexture ( renderer , texture , NULL , & dst ) ;
SDL_SetTextureAlphaMod ( texture , 0xFF ) ;
dst . y + = 1 ;
/* Step 3: nearest stretch */
dst . w = 1 ;
SDL_SetTextureScaleMode ( texture , SDL_SCALEMODE_NEAREST ) ;
SDL_RenderTexture ( renderer , texture , NULL , & dst ) ;
dst . y + = 1 ;
/* Step 4: linear stretch */
dst . w = 1 ;
SDL_SetTextureScaleMode ( texture , SDL_SCALEMODE_LINEAR ) ;
SDL_RenderTexture ( renderer , texture , NULL , & dst ) ;
dst . y + = 1 ;
/* Verify results */
rect . x = 0 ;
rect . y = 0 ;
rect . w = 2 ;
rect . h = 1 ;
for ( i = 0 ; i < SDL_arraysize ( expected ) ; ) {
const int MAX_DELTA = 1 ;
SDL_Color actual ;
int deltaR , deltaG , deltaB , deltaA ;
SDL_Surface * surface = SDL_RenderReadPixels ( renderer , & rect ) ;
SDL_ReadSurfacePixel ( surface , 0 , 0 , & actual . r , & actual . g , & actual . b , & actual . a ) ;
deltaR = ( actual . r - expected [ i ] . r ) ;
deltaG = ( actual . g - expected [ i ] . g ) ;
deltaB = ( actual . b - expected [ i ] . b ) ;
deltaA = ( actual . a - expected [ i ] . a ) ;
SDLTest_AssertCheck ( SDL_abs ( deltaR ) < = MAX_DELTA & &
SDL_abs ( deltaG ) < = MAX_DELTA & &
SDL_abs ( deltaB ) < = MAX_DELTA & &
SDL_abs ( deltaA ) < = MAX_DELTA ,
" Validate left pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d " , i / 2 ,
expected [ i ] . r , expected [ i ] . g , expected [ i ] . b , expected [ i ] . a ,
actual . r , actual . g , actual . b , actual . a ) ;
+ + i ;
SDL_ReadSurfacePixel ( surface , 1 , 0 , & actual . r , & actual . g , & actual . b , & actual . a ) ;
deltaR = ( actual . r - expected [ i ] . r ) ;
deltaG = ( actual . g - expected [ i ] . g ) ;
deltaB = ( actual . b - expected [ i ] . b ) ;
deltaA = ( actual . a - expected [ i ] . a ) ;
SDLTest_AssertCheck ( SDL_abs ( deltaR ) < = MAX_DELTA & &
SDL_abs ( deltaG ) < = MAX_DELTA & &
SDL_abs ( deltaB ) < = MAX_DELTA & &
SDL_abs ( deltaA ) < = MAX_DELTA ,
" Validate right pixel at step %d, expected %d,%d,%d,%d, got %d,%d,%d,%d " , i / 2 ,
expected [ i ] . r , expected [ i ] . g , expected [ i ] . b , expected [ i ] . a ,
actual . r , actual . g , actual . b , actual . a ) ;
+ + i ;
SDL_DestroySurface ( surface ) ;
rect . y + = 1 ;
}
/* Clean up. */
SDL_DestroyTexture ( texture ) ;
return TEST_COMPLETED ;
}
2015-06-21 17:33:46 +02:00
/* ================= Test References ================== */
/* Render test cases */
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestGetNumRenderDrivers = {
2024-09-04 23:54:56 +02:00
render_testGetNumRenderDrivers , " render_testGetNumRenderDrivers " , " Tests call to SDL_GetNumRenderDrivers " , TEST_ENABLED
2022-11-30 12:51:59 -08:00
} ;
2015-06-21 17:33:46 +02:00
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestPrimitives = {
2024-09-04 23:54:56 +02:00
render_testPrimitives , " render_testPrimitives " , " Tests rendering primitives " , TEST_ENABLED
2022-11-30 12:51:59 -08:00
} ;
2015-06-21 17:33:46 +02:00
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestPrimitivesWithViewport = {
2024-09-04 23:54:56 +02:00
render_testPrimitivesWithViewport , " render_testPrimitivesWithViewport " , " Tests rendering primitives within a viewport " , TEST_ENABLED
2022-11-30 12:51:59 -08:00
} ;
2015-06-21 17:33:46 +02:00
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestBlit = {
2024-09-04 23:54:56 +02:00
render_testBlit , " render_testBlit " , " Tests blitting " , TEST_ENABLED
2022-11-30 12:51:59 -08:00
} ;
2015-06-21 17:33:46 +02:00
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestBlitTiled = {
2024-09-04 23:54:56 +02:00
render_testBlitTiled , " render_testBlitTiled " , " Tests tiled blitting " , TEST_ENABLED
2024-07-20 13:47:01 -07:00
} ;
2024-07-20 16:39:09 -07:00
static const SDLTest_TestCaseReference renderTestBlit9Grid = {
2024-09-04 23:54:56 +02:00
render_testBlit9Grid , " render_testBlit9Grid " , " Tests 9-grid blitting " , TEST_ENABLED
2024-07-20 16:39:09 -07:00
} ;
2025-01-24 10:17:44 +01:00
static const SDLTest_TestCaseReference renderTestBlit9GridTiled = {
render_testBlit9GridTiled , " render_testBlit9GridTiled " , " Tests tiled 9-grid blitting " , TEST_ENABLED
} ;
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestBlitColor = {
2024-09-04 23:54:56 +02:00
render_testBlitColor , " render_testBlitColor " , " Tests blitting with color " , TEST_ENABLED
2024-01-19 16:28:00 -08:00
} ;
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestBlendModes = {
2024-09-04 23:54:56 +02:00
render_testBlendModes , " render_testBlendModes " , " Tests rendering blend modes " , TEST_ENABLED
2022-11-30 12:51:59 -08:00
} ;
2015-06-21 17:33:46 +02:00
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestViewport = {
2024-09-04 23:54:56 +02:00
render_testViewport , " render_testViewport " , " Tests viewport " , TEST_ENABLED
2023-01-26 13:58:38 -08:00
} ;
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestClipRect = {
2024-09-04 23:54:56 +02:00
render_testClipRect , " render_testClipRect " , " Tests clip rect " , TEST_ENABLED
2024-02-25 09:44:41 -08:00
} ;
2024-07-20 13:47:01 -07:00
static const SDLTest_TestCaseReference renderTestLogicalSize = {
2024-09-04 23:54:56 +02:00
render_testLogicalSize , " render_testLogicalSize " , " Tests logical size " , TEST_ENABLED
2023-01-26 14:49:23 -08:00
} ;
2025-07-19 16:33:53 +02:00
static const SDLTest_TestCaseReference renderTestUVClamping = {
render_testUVClamping , " render_testUVClamping " , " Tests geometry UV clamping " , TEST_ENABLED
} ;
2024-07-17 22:49:05 -07:00
static const SDLTest_TestCaseReference renderTestUVWrapping = {
2024-09-04 23:54:56 +02:00
render_testUVWrapping , " render_testUVWrapping " , " Tests geometry UV wrapping " , TEST_ENABLED
2024-07-17 22:49:05 -07:00
} ;
2025-03-05 18:56:59 -08:00
static const SDLTest_TestCaseReference renderTestTextureState = {
render_testTextureState , " render_testTextureState " , " Tests texture state changes " , TEST_ENABLED
} ;
2025-03-15 01:18:33 +01:00
static const SDLTest_TestCaseReference renderTestGetSetTextureScaleMode = {
render_testGetSetTextureScaleMode , " render_testGetSetTextureScaleMode " , " Tests setting/getting texture scale mode " , TEST_ENABLED
} ;
2025-03-15 20:01:51 +01:00
static const SDLTest_TestCaseReference renderTestRGBSurfaceNoAlpha = {
render_testRGBSurfaceNoAlpha , " render_testRGBSurfaceNoAlpha " , " Tests RGB surface with no alpha using software renderer " , TEST_ENABLED
} ;
2015-06-21 17:33:46 +02:00
/* Sequence of Render test cases */
2022-11-30 12:51:59 -08:00
static const SDLTest_TestCaseReference * renderTests [ ] = {
2024-07-20 13:47:01 -07:00
& renderTestGetNumRenderDrivers ,
& renderTestPrimitives ,
& renderTestPrimitivesWithViewport ,
& renderTestBlit ,
& renderTestBlitTiled ,
2024-07-20 16:39:09 -07:00
& renderTestBlit9Grid ,
2025-01-24 10:17:44 +01:00
& renderTestBlit9GridTiled ,
2024-07-20 13:47:01 -07:00
& renderTestBlitColor ,
& renderTestBlendModes ,
& renderTestViewport ,
& renderTestClipRect ,
& renderTestLogicalSize ,
2025-07-19 16:33:53 +02:00
& renderTestUVClamping ,
2024-07-20 13:47:01 -07:00
& renderTestUVWrapping ,
2025-03-05 18:56:59 -08:00
& renderTestTextureState ,
2025-03-15 01:18:33 +01:00
& renderTestGetSetTextureScaleMode ,
2025-03-15 20:01:51 +01:00
& renderTestRGBSurfaceNoAlpha ,
2024-07-20 13:47:01 -07:00
NULL
2015-06-21 17:33:46 +02:00
} ;
/* Render test suite (global) */
SDLTest_TestSuiteReference renderTestSuite = {
" Render " ,
InitCreateRenderer ,
renderTests ,
CleanupDestroyRenderer
} ;