test/automated/render/render.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 16 Jan 2011 17:48:04 -0800
changeset 5008 35afe807b51c
parent 3685 64ce267332c6
child 5140 e743b9c3f6d6
permissions -rw-r--r--
Fixed compiler warning
slouken@3259
     1
/**
slouken@3259
     2
 * Automated SDL_Surface test.
slouken@3259
     3
 *
slouken@3259
     4
 * Written by Edgar Simo "bobbens"
slouken@3259
     5
 *
slouken@3259
     6
 * Released under Public Domain.
slouken@3259
     7
 */
slouken@3259
     8
slouken@3259
     9
slouken@3259
    10
#include "SDL.h"
slouken@3481
    11
#include "../SDL_at.h"
slouken@3259
    12
slouken@3481
    13
#include "../common/common.h"
slouken@3259
    14
slouken@3259
    15
slouken@3259
    16
/*
slouken@3259
    17
 * Pull in images for testcases.
slouken@3259
    18
 */
slouken@3481
    19
#include "../common/images.h"
slouken@3259
    20
slouken@3259
    21
slouken@3259
    22
#define SCREEN_W     80
slouken@3259
    23
#define SCREEN_H     60
slouken@3259
    24
slouken@3259
    25
#define FACE_W       img_face.width
slouken@3259
    26
#define FACE_H       img_face.height
slouken@3259
    27
slouken@3259
    28
slouken@3259
    29
/*
slouken@3259
    30
 * Prototypes.
slouken@3259
    31
 */
slouken@3477
    32
static int render_compare( const char *msg, const SurfaceImage_t *s, int allowable_error );
slouken@3259
    33
static int render_isSupported( int code );
slouken@3259
    34
static int render_hasDrawColor (void);
slouken@3259
    35
static int render_hasBlendModes (void);
slouken@3259
    36
static int render_hasTexColor (void);
slouken@3259
    37
static int render_hasTexAlpha (void);
slouken@3259
    38
static int render_clearScreen (void);
slouken@3259
    39
/* Testcases. */
slouken@3558
    40
static int render_testReadWrite (void);
slouken@3259
    41
static int render_testPrimitives (void);
slouken@3259
    42
static int render_testPrimitivesBlend (void);
slouken@3259
    43
static int render_testBlit (void);
slouken@3259
    44
static int render_testBlitColour (void);
slouken@3259
    45
static int render_testBlitAlpha (void);
slouken@3685
    46
static int render_testBlitBlendMode( SDL_Texture * tface, int mode );
slouken@3259
    47
static int render_testBlitBlend (void);
slouken@3259
    48
slouken@3259
    49
slouken@3259
    50
/**
slouken@3259
    51
 * @brief Compares screen pixels with image pixels.
slouken@3259
    52
 *
slouken@3259
    53
 *    @param msg Message on failure.
slouken@3259
    54
 *    @param s Image to compare against.
slouken@3259
    55
 *    @return 0 on success.
slouken@3259
    56
 */
slouken@3477
    57
static int render_compare( const char *msg, const SurfaceImage_t *s, int allowable_error )
slouken@3259
    58
{
slouken@3259
    59
   int ret;
slouken@3531
    60
   SDL_Rect rect;
slouken@3467
    61
   Uint8 pix[4*80*60];
slouken@3259
    62
   SDL_Surface *testsur;
slouken@3259
    63
slouken@3259
    64
   /* Read pixels. */
slouken@3531
    65
   /* Explicitly specify the rect in case the window isn't expected size... */
slouken@3531
    66
   rect.x = 0;
slouken@3531
    67
   rect.y = 0;
slouken@3531
    68
   rect.w = 80;
slouken@3531
    69
   rect.h = 60;
slouken@3531
    70
   ret = SDL_RenderReadPixels( &rect, FORMAT, pix, 80*4 );
slouken@3259
    71
   if (SDL_ATassert( "SDL_RenderReadPixels", ret==0) )
slouken@3259
    72
      return 1;
slouken@3259
    73
slouken@3259
    74
   /* Create surface. */
slouken@3259
    75
   testsur = SDL_CreateRGBSurfaceFrom( pix, 80, 60, 32, 80*4,
slouken@3444
    76
                                       RMASK, GMASK, BMASK, AMASK);
slouken@3259
    77
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", testsur!=NULL ))
slouken@3259
    78
      return 1;
slouken@3259
    79
slouken@3259
    80
   /* Compare surface. */
slouken@3477
    81
   ret = surface_compare( testsur, s, allowable_error );
slouken@3259
    82
   if (SDL_ATassert( msg, ret==0 ))
slouken@3259
    83
      return 1;
slouken@3259
    84
slouken@3259
    85
   /* Clean up. */
slouken@3259
    86
   SDL_FreeSurface( testsur );
slouken@3259
    87
slouken@3259
    88
   return 0;
slouken@3259
    89
}
slouken@3259
    90
slouken@3467
    91
#if 0
slouken@3467
    92
static int dump_screen( int index )
slouken@3467
    93
{
slouken@3467
    94
   int ret;
slouken@3467
    95
   char name[1024];
slouken@3467
    96
   Uint8 pix[4*80*60];
slouken@3467
    97
   SDL_Surface *testsur;
slouken@3467
    98
   SDL_RendererInfo info;
slouken@3467
    99
slouken@3467
   100
   /* Read pixels. */
slouken@3467
   101
   ret = SDL_RenderReadPixels( NULL, FORMAT, pix, 80*4 );
slouken@3467
   102
   if (SDL_ATassert( "SDL_RenderReadPixels", ret==0) )
slouken@3467
   103
      return 1;
slouken@3467
   104
slouken@3467
   105
   /* Create surface. */
slouken@3467
   106
   testsur = SDL_CreateRGBSurfaceFrom( pix, 80, 60, 32, 80*4,
slouken@3467
   107
                                       RMASK, GMASK, BMASK, AMASK);
slouken@3467
   108
   if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", testsur!=NULL ))
slouken@3467
   109
      return 1;
slouken@3467
   110
slouken@3467
   111
   /* Dump surface. */
slouken@3467
   112
   SDL_GetRendererInfo(&info);
slouken@3467
   113
   sprintf(name, "%s-%s-%d.bmp", SDL_GetCurrentVideoDriver(), info.name, index);
slouken@3467
   114
   SDL_SaveBMP(testsur, name);
slouken@3467
   115
slouken@3467
   116
   /* Clean up. */
slouken@3467
   117
   SDL_FreeSurface( testsur );
slouken@3467
   118
slouken@3467
   119
   return 0;
slouken@3467
   120
}
slouken@3467
   121
#endif
slouken@3259
   122
slouken@3259
   123
/**
slouken@3259
   124
 * @brief Checks to see if functionality is supported.
slouken@3259
   125
 */
slouken@3259
   126
static int render_isSupported( int code )
slouken@3259
   127
{
slouken@3259
   128
   return (code == 0);
slouken@3259
   129
}
slouken@3259
   130
slouken@3259
   131
slouken@3259
   132
/**
slouken@3259
   133
 * @brief Test to see if we can vary the draw colour.
slouken@3259
   134
 */
slouken@3259
   135
static int render_hasDrawColor (void)
slouken@3259
   136
{
slouken@3259
   137
   int ret, fail;
slouken@3259
   138
   Uint8 r, g, b, a;
slouken@3259
   139
slouken@3259
   140
   fail = 0;
slouken@3259
   141
slouken@3259
   142
   /* Set colour. */
slouken@3259
   143
   ret = SDL_SetRenderDrawColor( 100, 100, 100, 100 );
slouken@3259
   144
   if (!render_isSupported(ret))
slouken@3259
   145
      fail = 1;
slouken@3259
   146
   ret = SDL_GetRenderDrawColor( &r, &g, &b, &a );
slouken@3259
   147
   if (!render_isSupported(ret))
slouken@3259
   148
      fail = 1;
slouken@3259
   149
   /* Restore natural. */
slouken@3259
   150
   ret = SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE );
slouken@3259
   151
   if (!render_isSupported(ret))
slouken@3259
   152
      fail = 1;
slouken@3259
   153
slouken@3259
   154
   /* Something failed, consider not available. */
slouken@3259
   155
   if (fail)
slouken@3259
   156
      return 0;
slouken@3259
   157
   /* Not set properly, consider failed. */
slouken@3259
   158
   else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
slouken@3259
   159
      return 0;
slouken@3259
   160
   return 1;
slouken@3259
   161
}
slouken@3259
   162
slouken@3259
   163
slouken@3259
   164
/**
slouken@3259
   165
 * @brief Test to see if we can vary the blend mode.
slouken@3259
   166
 */
slouken@3259
   167
static int render_hasBlendModes (void)
slouken@3259
   168
{
slouken@3259
   169
   int fail;
slouken@3259
   170
   int ret;
slouken@5008
   171
   SDL_BlendMode mode;
slouken@3259
   172
slouken@3259
   173
   fail = 0;
slouken@3259
   174
slouken@3259
   175
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
slouken@3259
   176
   if (!render_isSupported(ret))
slouken@3259
   177
      fail = 1;
slouken@3259
   178
   ret = SDL_GetRenderDrawBlendMode( &mode );
slouken@3259
   179
   if (!render_isSupported(ret))
slouken@3259
   180
      fail = 1;
slouken@3259
   181
   ret = (mode != SDL_BLENDMODE_BLEND);
slouken@3259
   182
   if (!render_isSupported(ret))
slouken@3259
   183
      fail = 1;
slouken@3259
   184
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
slouken@3259
   185
   if (!render_isSupported(ret))
slouken@3259
   186
      fail = 1;
slouken@3259
   187
   ret = SDL_GetRenderDrawBlendMode( &mode );
slouken@3259
   188
   if (!render_isSupported(ret))
slouken@3259
   189
      fail = 1;
slouken@3259
   190
   ret = (mode != SDL_BLENDMODE_ADD);
slouken@3259
   191
   if (!render_isSupported(ret))
slouken@3259
   192
      fail = 1;
slouken@3259
   193
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
slouken@3259
   194
   if (!render_isSupported(ret))
slouken@3259
   195
      fail = 1;
slouken@3259
   196
   ret = SDL_GetRenderDrawBlendMode( &mode );
slouken@3259
   197
   if (!render_isSupported(ret))
slouken@3259
   198
      fail = 1;
slouken@3259
   199
   ret = (mode != SDL_BLENDMODE_MOD);
slouken@3259
   200
   if (!render_isSupported(ret))
slouken@3259
   201
      fail = 1;
slouken@3259
   202
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MASK );
slouken@3259
   203
   if (!render_isSupported(ret))
slouken@3259
   204
      fail = 1;
slouken@3259
   205
   ret = SDL_GetRenderDrawBlendMode( &mode );
slouken@3259
   206
   if (!render_isSupported(ret))
slouken@3259
   207
      fail = 1;
slouken@3259
   208
   ret = (mode != SDL_BLENDMODE_MASK);
slouken@3259
   209
   if (!render_isSupported(ret))
slouken@3259
   210
      fail = 1;
slouken@3259
   211
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
slouken@3259
   212
   if (!render_isSupported(ret))
slouken@3259
   213
      fail = 1;
slouken@3259
   214
   ret = SDL_GetRenderDrawBlendMode( &mode );
slouken@3259
   215
   if (!render_isSupported(ret))
slouken@3259
   216
      fail = 1;
slouken@3259
   217
   ret = (mode != SDL_BLENDMODE_NONE);
slouken@3259
   218
   if (!render_isSupported(ret))
slouken@3259
   219
      fail = 1;
slouken@3259
   220
slouken@3259
   221
   return !fail;
slouken@3259
   222
}
slouken@3259
   223
slouken@3259
   224
slouken@3259
   225
/**
slouken@3259
   226
 * @brief Loads the test face.
slouken@3259
   227
 */
slouken@3685
   228
static SDL_Texture * render_loadTestFace (void)
slouken@3259
   229
{
slouken@3259
   230
   SDL_Surface *face;
slouken@3685
   231
   SDL_Texture *tface;
slouken@3259
   232
slouken@3259
   233
   /* Create face surface. */
slouken@3259
   234
   face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
slouken@3259
   235
         img_face.width, img_face.height, 32, img_face.width*4,
slouken@3444
   236
#if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
slouken@3444
   237
         0xff000000, /* Red bit mask. */
slouken@3444
   238
         0x00ff0000, /* Green bit mask. */
slouken@3444
   239
         0x0000ff00, /* Blue bit mask. */
slouken@3444
   240
         0x000000ff /* Alpha bit mask. */
slouken@3444
   241
#else
slouken@3444
   242
         0x000000ff, /* Red bit mask. */
slouken@3444
   243
         0x0000ff00, /* Green bit mask. */
slouken@3444
   244
         0x00ff0000, /* Blue bit mask. */
slouken@3444
   245
         0xff000000 /* Alpha bit mask. */
slouken@3444
   246
#endif
slouken@3444
   247
         );
slouken@3259
   248
   if (face == NULL)
slouken@3259
   249
      return 0;
slouken@3259
   250
   tface = SDL_CreateTextureFromSurface( 0, face );
slouken@3259
   251
   SDL_FreeSurface(face);
slouken@3259
   252
slouken@3259
   253
   return tface;
slouken@3259
   254
}
slouken@3259
   255
slouken@3259
   256
slouken@3259
   257
/**
slouken@3259
   258
 * @brief Test to see if can set texture colour mode.
slouken@3259
   259
 */
slouken@3259
   260
static int render_hasTexColor (void)
slouken@3259
   261
{
slouken@3259
   262
   int fail;
slouken@3259
   263
   int ret;
slouken@3685
   264
   SDL_Texture *tface;
slouken@3259
   265
   Uint8 r, g, b;
slouken@3259
   266
slouken@3259
   267
   /* Get test face. */
slouken@3259
   268
   tface = render_loadTestFace();
slouken@3259
   269
   if (tface == 0)
slouken@3259
   270
      return 0;
slouken@3259
   271
slouken@3259
   272
   /* See if supported. */
slouken@3259
   273
   fail = 0;
slouken@3259
   274
   ret = SDL_SetTextureColorMod( tface, 100, 100, 100 );
slouken@3259
   275
   if (!render_isSupported(ret))
slouken@3259
   276
      fail = 1;
slouken@3259
   277
   ret = SDL_GetTextureColorMod( tface, &r, &g, &b );
slouken@3259
   278
   if (!render_isSupported(ret))
slouken@3259
   279
      fail = 1;
slouken@3259
   280
slouken@3259
   281
   /* Clean up. */
slouken@3259
   282
   SDL_DestroyTexture( tface );
slouken@3259
   283
slouken@3259
   284
   if (fail)
slouken@3259
   285
      return 0;
slouken@3259
   286
   else if ((r != 100) || (g != 100) || (b != 100))
slouken@3259
   287
      return 0;
slouken@3259
   288
   return 1;
slouken@3259
   289
}
slouken@3259
   290
slouken@3259
   291
slouken@3259
   292
/**
slouken@3259
   293
 * @brief Test to see if we can vary the alpha of the texture.
slouken@3259
   294
 */
slouken@3259
   295
static int render_hasTexAlpha (void)
slouken@3259
   296
{
slouken@3259
   297
   int fail;
slouken@3259
   298
   int ret;
slouken@3685
   299
   SDL_Texture *tface;
slouken@3259
   300
   Uint8 a;
slouken@3259
   301
slouken@3259
   302
   /* Get test face. */
slouken@3259
   303
   tface = render_loadTestFace();
slouken@3259
   304
   if (tface == 0)
slouken@3259
   305
      return 0;
slouken@3259
   306
slouken@3259
   307
   /* See if supported. */
slouken@3259
   308
   fail = 0;
slouken@3259
   309
   ret = SDL_SetTextureAlphaMod( tface, 100 );
slouken@3259
   310
   if (!render_isSupported(ret))
slouken@3259
   311
      fail = 1;
slouken@3259
   312
   ret = SDL_GetTextureAlphaMod( tface, &a );
slouken@3259
   313
   if (!render_isSupported(ret))
slouken@3259
   314
      fail = 1;
slouken@3259
   315
slouken@3259
   316
   /* Clean up. */
slouken@3259
   317
   SDL_DestroyTexture( tface );
slouken@3259
   318
slouken@3259
   319
   if (fail)
slouken@3259
   320
      return 0;
slouken@3259
   321
   else if (a != 100)
slouken@3259
   322
      return 0;
slouken@3259
   323
   return 1;
slouken@3259
   324
}
slouken@3259
   325
slouken@3259
   326
slouken@3259
   327
/**
slouken@3259
   328
 * @brief Clears the screen.
slouken@3259
   329
 *
slouken@3259
   330
 * @note We don't test for errors, but they shouldn't happen.
slouken@3259
   331
 */
slouken@3259
   332
static int render_clearScreen (void)
slouken@3259
   333
{
slouken@3259
   334
   int ret;
slouken@3259
   335
slouken@3259
   336
   /* Set colour. */
slouken@3259
   337
   ret = SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE );
slouken@3259
   338
   /*
slouken@3259
   339
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   340
      return -1;
slouken@3259
   341
   */
slouken@3259
   342
slouken@3259
   343
   /* Clear screen. */
slouken@3596
   344
   ret = SDL_RenderFillRect( NULL );
slouken@3259
   345
   /*
slouken@3596
   346
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   347
      return -1;
slouken@3259
   348
   */
slouken@3259
   349
slouken@3259
   350
   /* Set defaults. */
slouken@3259
   351
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
slouken@3259
   352
   /*
slouken@3259
   353
   if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   354
      return -1;
slouken@3259
   355
   */
slouken@3259
   356
   ret = SDL_SetRenderDrawColor( 255, 255, 255, SDL_ALPHA_OPAQUE );
slouken@3259
   357
   /*
slouken@3259
   358
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   359
      return -1;
slouken@3259
   360
   */
slouken@3259
   361
slouken@3259
   362
   return 0;
slouken@3259
   363
}
slouken@3259
   364
slouken@3259
   365
slouken@3259
   366
/**
slouken@3558
   367
 * @brief Test reading and writing framebuffer
slouken@3558
   368
 */
slouken@3558
   369
static int render_testReadWrite (void)
slouken@3558
   370
{
slouken@3558
   371
   int ret;
slouken@3558
   372
   SDL_Rect rect;
slouken@3558
   373
slouken@3558
   374
   /* Write pixels. */
slouken@3558
   375
   rect.x = 0;
slouken@3558
   376
   rect.y = 0;
slouken@3558
   377
   rect.w = 80;
slouken@3558
   378
   rect.h = 60;
slouken@3558
   379
   ret = SDL_RenderWritePixels( &rect, SDL_PIXELFORMAT_RGB24, img_primitives.pixel_data, img_primitives.width*img_primitives.bytes_per_pixel );
slouken@3558
   380
   if (SDL_ATassert( "SDL_RenderWritePixels", ret==0) )
slouken@3558
   381
      return 1;
slouken@3558
   382
slouken@3558
   383
   /* See if it's the same. */
slouken@3558
   384
   if (render_compare( "Read/write output not the same.", &img_primitives, ALLOWABLE_ERROR_OPAQUE ))
slouken@3558
   385
      return -1;
slouken@3558
   386
slouken@3558
   387
   return 0;
slouken@3558
   388
}
slouken@3558
   389
slouken@3558
   390
slouken@3558
   391
/**
slouken@3259
   392
 * @brief Tests the SDL primitives for rendering.
slouken@3259
   393
 */
slouken@3259
   394
static int render_testPrimitives (void)
slouken@3259
   395
{
slouken@3259
   396
   int ret;
slouken@3259
   397
   int x, y;
slouken@3259
   398
   SDL_Rect rect;
slouken@3259
   399
slouken@3259
   400
   /* Clear surface. */
slouken@3259
   401
   if (render_clearScreen())
slouken@3259
   402
      return -1;
slouken@3259
   403
slouken@3259
   404
   /* Need drawcolour or just skip test. */
slouken@3259
   405
   if (!render_hasDrawColor())
slouken@3259
   406
      return 0;
slouken@3259
   407
slouken@3259
   408
   /* Draw a rectangle. */
slouken@3259
   409
   rect.x = 40;
slouken@3259
   410
   rect.y = 0;
slouken@3259
   411
   rect.w = 40;
slouken@3259
   412
   rect.h = 80;
slouken@3259
   413
   ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE );
slouken@3259
   414
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   415
      return -1;
slouken@3596
   416
   ret = SDL_RenderFillRect( &rect );
slouken@3596
   417
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   418
      return -1;
slouken@3259
   419
slouken@3259
   420
   /* Draw a rectangle. */
slouken@3259
   421
   rect.x = 10;
slouken@3259
   422
   rect.y = 10;
slouken@3259
   423
   rect.w = 60;
slouken@3259
   424
   rect.h = 40;
slouken@3259
   425
   ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE );
slouken@3259
   426
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   427
      return -1;
slouken@3596
   428
   ret = SDL_RenderFillRect( &rect );
slouken@3596
   429
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   430
      return -1;
slouken@3259
   431
slouken@3259
   432
   /* Draw some points like so:
slouken@3259
   433
    * X.X.X.X..
slouken@3259
   434
    * .X.X.X.X.
slouken@3259
   435
    * X.X.X.X.. */
slouken@3259
   436
   for (y=0; y<3; y++) {
slouken@3259
   437
      x = y % 2;
slouken@3259
   438
      for (; x<80; x+=2) {
slouken@3259
   439
         ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE );
slouken@3259
   440
         if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   441
            return -1;
slouken@3596
   442
         ret = SDL_RenderDrawPoint( x, y );
slouken@3596
   443
         if (SDL_ATassert( "SDL_RenderDrawPoint", ret == 0))
slouken@3259
   444
            return -1;
slouken@3259
   445
      }
slouken@3259
   446
   }
slouken@3259
   447
slouken@3259
   448
   /* Draw some lines. */
slouken@3259
   449
   ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE );
slouken@3259
   450
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   451
      return -1;
slouken@3596
   452
   ret = SDL_RenderDrawLine( 0, 30, 80, 30 );
slouken@3596
   453
   if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3259
   454
      return -1;
slouken@3259
   455
   ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE );
slouken@3259
   456
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   457
      return -1;
slouken@3596
   458
   ret = SDL_RenderDrawLine( 40, 30, 40, 60 );
slouken@3596
   459
   if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3259
   460
      return -1;
slouken@3259
   461
   ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE );
slouken@3259
   462
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   463
      return -1;
slouken@3596
   464
   ret = SDL_RenderDrawLine( 0, 0, 29, 29 );
slouken@3596
   465
   if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3471
   466
      return -1;
slouken@3596
   467
   ret = SDL_RenderDrawLine( 29, 30, 0, 59 );
slouken@3596
   468
   if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3471
   469
      return -1;
slouken@3596
   470
   ret = SDL_RenderDrawLine( 79, 0, 50, 29 );
slouken@3596
   471
   if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3471
   472
      return -1;
slouken@3596
   473
   ret = SDL_RenderDrawLine( 79, 59, 50, 30 );
slouken@3596
   474
   if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3259
   475
      return -1;
slouken@3259
   476
slouken@3259
   477
   /* See if it's the same. */
slouken@3477
   478
   if (render_compare( "Primitives output not the same.", &img_primitives, ALLOWABLE_ERROR_OPAQUE ))
slouken@3259
   479
      return -1;
slouken@3259
   480
slouken@3259
   481
   return 0;
slouken@3259
   482
}
slouken@3259
   483
slouken@3259
   484
slouken@3259
   485
/**
slouken@3259
   486
 * @brief Tests the SDL primitives with alpha for rendering.
slouken@3259
   487
 */
slouken@3259
   488
static int render_testPrimitivesBlend (void)
slouken@3259
   489
{
slouken@3259
   490
   int ret;
slouken@3259
   491
   int i, j;
slouken@3259
   492
   SDL_Rect rect;
slouken@3259
   493
slouken@3259
   494
   /* Clear surface. */
slouken@3259
   495
   if (render_clearScreen())
slouken@3259
   496
      return -1;
slouken@3259
   497
slouken@3259
   498
   /* Need drawcolour and blendmode or just skip test. */
slouken@3259
   499
   if (!render_hasDrawColor() || !render_hasBlendModes())
slouken@3259
   500
      return 0;
slouken@3259
   501
slouken@3259
   502
   /* Create some rectangles for each blend mode. */
slouken@3259
   503
   ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 );
slouken@3259
   504
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   505
      return -1;
slouken@3259
   506
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
slouken@3259
   507
   if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   508
      return -1;
slouken@3596
   509
   ret = SDL_RenderFillRect( NULL );
slouken@3596
   510
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   511
      return -1;
slouken@3259
   512
   rect.x = 10;
slouken@3259
   513
   rect.y = 25;
slouken@3259
   514
   rect.w = 40;
slouken@3259
   515
   rect.h = 25;
slouken@3259
   516
   ret = SDL_SetRenderDrawColor( 240, 10, 10, 75 );
slouken@3259
   517
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   518
      return -1;
slouken@3259
   519
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
slouken@3259
   520
   if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   521
      return -1;
slouken@3596
   522
   ret = SDL_RenderFillRect( &rect );
slouken@3596
   523
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   524
      return -1;
slouken@3259
   525
   rect.x = 30;
slouken@3259
   526
   rect.y = 40;
slouken@3259
   527
   rect.w = 45;
slouken@3259
   528
   rect.h = 15;
slouken@3259
   529
   ret = SDL_SetRenderDrawColor( 10, 240, 10, 100 );
slouken@3259
   530
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   531
      return -1;
slouken@3259
   532
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
slouken@3259
   533
   if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   534
      return -1;
slouken@3596
   535
   ret = SDL_RenderFillRect( &rect );
slouken@3596
   536
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   537
      return -1;
slouken@3259
   538
   rect.x = 25;
slouken@3259
   539
   rect.y = 25;
slouken@3259
   540
   rect.w = 25;
slouken@3259
   541
   rect.h = 25;
slouken@3259
   542
   ret = SDL_SetRenderDrawColor( 10, 10, 240, 125 );
slouken@3259
   543
   if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   544
      return -1;
slouken@3259
   545
   ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
slouken@3259
   546
   if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   547
      return -1;
slouken@3596
   548
   ret = SDL_RenderFillRect( &rect );
slouken@3596
   549
   if (SDL_ATassert( "SDL_RenderFillRect", ret == 0))
slouken@3259
   550
      return -1;
slouken@3259
   551
slouken@3259
   552
   /* Draw blended lines, lines for everyone. */
slouken@3259
   553
   for (i=0; i<SCREEN_W; i+=2)  {
slouken@3259
   554
      ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i );
slouken@3259
   555
      if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   556
         return -1;
slouken@3259
   557
      ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
slouken@3259
   558
            (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
slouken@3259
   559
      if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   560
         return -1;
slouken@3596
   561
      ret = SDL_RenderDrawLine( 0, 0, i, 59 );
slouken@3596
   562
      if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3259
   563
         return -1;
slouken@3259
   564
   }
slouken@3259
   565
   for (i=0; i<SCREEN_H; i+=2)  {
slouken@3259
   566
      ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i );
slouken@3259
   567
      if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   568
         return -1;
slouken@3259
   569
      ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
slouken@3259
   570
            (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
slouken@3259
   571
      if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   572
         return -1;
slouken@3596
   573
      ret = SDL_RenderDrawLine( 0, 0, 79, i );
slouken@3596
   574
      if (SDL_ATassert( "SDL_RenderDrawLine", ret == 0))
slouken@3259
   575
         return -1;
slouken@3259
   576
   }
slouken@3259
   577
slouken@3259
   578
   /* Draw points. */
slouken@3259
   579
   for (j=0; j<SCREEN_H; j+=3) {
slouken@3259
   580
      for (i=0; i<SCREEN_W; i+=3) {
slouken@3259
   581
         ret = SDL_SetRenderDrawColor( j*4, i*3, j*4, i*3 );
slouken@3259
   582
         if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
slouken@3259
   583
            return -1;
slouken@3259
   584
         ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
slouken@3259
   585
               ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
slouken@3259
   586
         if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
slouken@3259
   587
            return -1;
slouken@3596
   588
         ret = SDL_RenderDrawPoint( i, j );
slouken@3596
   589
         if (SDL_ATassert( "SDL_RenderDrawPoint", ret == 0))
slouken@3259
   590
            return -1;
slouken@3259
   591
      }
slouken@3259
   592
   }
slouken@3259
   593
slouken@3259
   594
   /* See if it's the same. */
slouken@3477
   595
   if (render_compare( "Blended primitives output not the same.", &img_blend, ALLOWABLE_ERROR_BLENDED ))
slouken@3259
   596
      return -1;
slouken@3259
   597
slouken@3259
   598
   return 0;
slouken@3259
   599
}
slouken@3259
   600
slouken@3259
   601
slouken@3259
   602
/**
slouken@3259
   603
 * @brief Tests some blitting routines.
slouken@3259
   604
 */
slouken@3259
   605
static int render_testBlit (void)
slouken@3259
   606
{
slouken@3259
   607
   int ret;
slouken@3259
   608
   SDL_Rect rect;
slouken@3685
   609
   SDL_Texture *tface;
slouken@3259
   610
   int i, j, ni, nj;
slouken@3259
   611
slouken@3259
   612
   /* Clear surface. */
slouken@3259
   613
   if (render_clearScreen())
slouken@3259
   614
      return -1;
slouken@3259
   615
slouken@3259
   616
   /* Need drawcolour or just skip test. */
slouken@3259
   617
   if (!render_hasDrawColor())
slouken@3259
   618
      return 0;
slouken@3259
   619
slouken@3259
   620
   /* Create face surface. */
slouken@3445
   621
   tface = render_loadTestFace();
slouken@3445
   622
   if (SDL_ATassert( "render_loadTestFace()", tface != 0))
slouken@3259
   623
      return -1;
slouken@3259
   624
slouken@3259
   625
   /* Constant values. */
slouken@3445
   626
   rect.w = img_face.width;
slouken@3445
   627
   rect.h = img_face.height;
slouken@3445
   628
   ni     = SCREEN_W - img_face.width;
slouken@3445
   629
   nj     = SCREEN_H - img_face.height;
slouken@3259
   630
slouken@3259
   631
   /* Loop blit. */
slouken@3259
   632
   for (j=0; j <= nj; j+=4) {
slouken@3259
   633
      for (i=0; i <= ni; i+=4) {
slouken@3259
   634
         /* Blitting. */
slouken@3259
   635
         rect.x = i;
slouken@3259
   636
         rect.y = j;
slouken@3259
   637
         ret = SDL_RenderCopy( tface, NULL, &rect );
slouken@3259
   638
         if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
slouken@3259
   639
            return -1;
slouken@3259
   640
      }
slouken@3259
   641
   }
slouken@3259
   642
slouken@3259
   643
   /* Clean up. */
slouken@3259
   644
   SDL_DestroyTexture( tface );
slouken@3259
   645
slouken@3259
   646
   /* See if it's the same. */
slouken@3477
   647
   if (render_compare( "Blit output not the same.", &img_blit, ALLOWABLE_ERROR_OPAQUE ))
slouken@3259
   648
      return -1;
slouken@3259
   649
slouken@3259
   650
   return 0;
slouken@3259
   651
}
slouken@3259
   652
slouken@3259
   653
slouken@3259
   654
/**
slouken@3259
   655
 * @brief Blits doing colour tests.
slouken@3259
   656
 */
slouken@3259
   657
static int render_testBlitColour (void)
slouken@3259
   658
{
slouken@3259
   659
   int ret;
slouken@3259
   660
   SDL_Rect rect;
slouken@3685
   661
   SDL_Texture *tface;
slouken@3259
   662
   int i, j, ni, nj;
slouken@3259
   663
slouken@3259
   664
   /* Clear surface. */
slouken@3259
   665
   if (render_clearScreen())
slouken@3259
   666
      return -1;
slouken@3259
   667
slouken@3259
   668
   /* Need drawcolour or just skip test. */
slouken@3259
   669
   if (!render_hasTexColor())
slouken@3259
   670
      return 0;
slouken@3259
   671
slouken@3259
   672
   /* Create face surface. */
slouken@3445
   673
   tface = render_loadTestFace();
slouken@3445
   674
   if (SDL_ATassert( "render_loadTestFace()", tface != 0))
slouken@3259
   675
      return -1;
slouken@3259
   676
slouken@3259
   677
   /* Constant values. */
slouken@3445
   678
   rect.w = img_face.width;
slouken@3445
   679
   rect.h = img_face.height;
slouken@3445
   680
   ni     = SCREEN_W - img_face.width;
slouken@3445
   681
   nj     = SCREEN_H - img_face.height;
slouken@3259
   682
slouken@3259
   683
   /* Test blitting with colour mod. */
slouken@3259
   684
   for (j=0; j <= nj; j+=4) {
slouken@3259
   685
      for (i=0; i <= ni; i+=4) {
slouken@3259
   686
         /* Set colour mod. */
slouken@3259
   687
         ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
slouken@3259
   688
         if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0))
slouken@3259
   689
            return -1;
slouken@3259
   690
slouken@3259
   691
         /* Blitting. */
slouken@3259
   692
         rect.x = i;
slouken@3259
   693
         rect.y = j;
slouken@3259
   694
         ret = SDL_RenderCopy( tface, NULL, &rect );
slouken@3259
   695
         if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
slouken@3259
   696
            return -1;
slouken@3259
   697
      }
slouken@3259
   698
   }
slouken@3259
   699
slouken@3259
   700
   /* Clean up. */
slouken@3259
   701
   SDL_DestroyTexture( tface );
slouken@3259
   702
slouken@3259
   703
   /* See if it's the same. */
slouken@3259
   704
   if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).",
slouken@3477
   705
            &img_blitColour, ALLOWABLE_ERROR_OPAQUE ))
slouken@3259
   706
      return -1;
slouken@3259
   707
slouken@3259
   708
   return 0;
slouken@3259
   709
}
slouken@3259
   710
slouken@3259
   711
slouken@3259
   712
/**
slouken@3259
   713
 * @brief Tests blitting with alpha.
slouken@3259
   714
 */
slouken@3259
   715
static int render_testBlitAlpha (void)
slouken@3259
   716
{
slouken@3259
   717
   int ret;
slouken@3259
   718
   SDL_Rect rect;
slouken@3685
   719
   SDL_Texture *tface;
slouken@3259
   720
   int i, j, ni, nj;
slouken@3259
   721
slouken@3259
   722
   /* Clear surface. */
slouken@3259
   723
   if (render_clearScreen())
slouken@3259
   724
      return -1;
slouken@3259
   725
slouken@3259
   726
   /* Need alpha or just skip test. */
slouken@3259
   727
   if (!render_hasTexAlpha())
slouken@3259
   728
      return 0;
slouken@3259
   729
slouken@3259
   730
   /* Create face surface. */
slouken@3445
   731
   tface = render_loadTestFace();
slouken@3445
   732
   if (SDL_ATassert( "render_loadTestFace()", tface != 0))
slouken@3259
   733
      return -1;
slouken@3259
   734
slouken@3259
   735
   /* Constant values. */
slouken@3445
   736
   rect.w = img_face.width;
slouken@3445
   737
   rect.h = img_face.height;
slouken@3445
   738
   ni     = SCREEN_W - img_face.width;
slouken@3445
   739
   nj     = SCREEN_H - img_face.height;
slouken@3259
   740
slouken@3259
   741
   /* Clear surface. */
slouken@3259
   742
   if (render_clearScreen())
slouken@3259
   743
      return -1;
slouken@3259
   744
slouken@3259
   745
   /* Test blitting with alpha mod. */
slouken@3259
   746
   for (j=0; j <= nj; j+=4) {
slouken@3259
   747
      for (i=0; i <= ni; i+=4) {
slouken@3259
   748
         /* Set alpha mod. */
slouken@3259
   749
         ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i );
slouken@3259
   750
         if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0))
slouken@3259
   751
            return -1;
slouken@3259
   752
slouken@3259
   753
         /* Blitting. */
slouken@3259
   754
         rect.x = i;
slouken@3259
   755
         rect.y = j;
slouken@3259
   756
         ret = SDL_RenderCopy( tface, NULL, &rect );
slouken@3259
   757
         if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
slouken@3259
   758
            return -1;
slouken@3259
   759
      }
slouken@3259
   760
   }
slouken@3259
   761
slouken@3259
   762
   /* Clean up. */
slouken@3259
   763
   SDL_DestroyTexture( tface );
slouken@3259
   764
slouken@3259
   765
   /* See if it's the same. */
slouken@3259
   766
   if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
slouken@3477
   767
            &img_blitAlpha, ALLOWABLE_ERROR_BLENDED ))
slouken@3259
   768
      return -1;
slouken@3259
   769
slouken@3259
   770
   return 0;
slouken@3259
   771
}
slouken@3259
   772
slouken@3259
   773
slouken@3259
   774
/**
slouken@3259
   775
 * @brief Tests a blend mode.
slouken@3259
   776
 */
slouken@3685
   777
static int render_testBlitBlendMode( SDL_Texture * tface, int mode )
slouken@3259
   778
{
slouken@3259
   779
   int ret;
slouken@3259
   780
   int i, j, ni, nj;
slouken@3259
   781
   SDL_Rect rect;
slouken@3259
   782
slouken@3259
   783
   /* Clear surface. */
slouken@3259
   784
   if (render_clearScreen())
slouken@3259
   785
      return -1;
slouken@3259
   786
slouken@3259
   787
   /* Steps to take. */
slouken@3259
   788
   ni     = SCREEN_W - FACE_W;
slouken@3259
   789
   nj     = SCREEN_H - FACE_H;
slouken@3259
   790
slouken@3259
   791
   /* Constant values. */
slouken@3259
   792
   rect.w = FACE_W;
slouken@3259
   793
   rect.h = FACE_H;
slouken@3259
   794
slouken@3259
   795
   /* Test blend mode. */
slouken@3259
   796
   for (j=0; j <= nj; j+=4) {
slouken@3259
   797
      for (i=0; i <= ni; i+=4) {
slouken@3259
   798
         /* Set blend mode. */
slouken@3453
   799
         ret = SDL_SetTextureBlendMode( tface, mode );
slouken@3453
   800
         if (SDL_ATassert( "SDL_SetTextureBlendMode", ret == 0))
slouken@3259
   801
            return -1;
slouken@3259
   802
slouken@3259
   803
         /* Blitting. */
slouken@3259
   804
         rect.x = i;
slouken@3259
   805
         rect.y = j;
slouken@3259
   806
         ret = SDL_RenderCopy( tface, NULL, &rect );
slouken@3259
   807
         if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
slouken@3259
   808
            return -1;
slouken@3259
   809
      }
slouken@3259
   810
   }
slouken@3259
   811
slouken@3259
   812
   return 0;
slouken@3259
   813
}
slouken@3259
   814
slouken@3259
   815
slouken@3259
   816
/**
slouken@3259
   817
 * @brief Tests some more blitting routines.
slouken@3259
   818
 */
slouken@3259
   819
static int render_testBlitBlend (void)
slouken@3259
   820
{
slouken@3259
   821
   int ret;
slouken@3259
   822
   SDL_Rect rect;
slouken@3685
   823
   SDL_Texture *tface;
slouken@3259
   824
   int i, j, ni, nj;
slouken@3259
   825
   int mode;
slouken@3259
   826
slouken@3259
   827
   /* Clear surface. */
slouken@3259
   828
   if (render_clearScreen())
slouken@3259
   829
      return -1;
slouken@3259
   830
slouken@3259
   831
   /* Need drawcolour and blendmode or just skip test. */
slouken@3259
   832
   if (!render_hasBlendModes() || !render_hasTexColor() || !render_hasTexAlpha())
slouken@3259
   833
      return 0;
slouken@3259
   834
slouken@3259
   835
   /* Create face surface. */
slouken@3445
   836
   tface = render_loadTestFace();
slouken@3445
   837
   if (SDL_ATassert( "render_loadTestFace()", tface != 0))
slouken@3259
   838
      return -1;
slouken@3259
   839
slouken@3259
   840
   /* Steps to take. */
slouken@3259
   841
   ni     = SCREEN_W - FACE_W;
slouken@3259
   842
   nj     = SCREEN_H - FACE_H;
slouken@3259
   843
slouken@3259
   844
   /* Constant values. */
slouken@3445
   845
   rect.w = img_face.width;
slouken@3445
   846
   rect.h = img_face.height;
slouken@3259
   847
slouken@3259
   848
   /* Set alpha mod. */
slouken@3453
   849
   ret = SDL_SetTextureAlphaMod( tface, 100 );
slouken@3453
   850
   if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0))
slouken@3259
   851
      return -1;
slouken@3259
   852
slouken@3259
   853
   /* Test None. */
slouken@3259
   854
   if (render_testBlitBlendMode( tface, SDL_BLENDMODE_NONE ))
slouken@3259
   855
      return -1;
slouken@3259
   856
   /* See if it's the same. */
slouken@3259
   857
   if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).",
slouken@3477
   858
            &img_blendNone, ALLOWABLE_ERROR_OPAQUE ))
slouken@3259
   859
      return -1;
slouken@3259
   860
slouken@3259
   861
   /* Test Mask. */
slouken@3259
   862
   if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MASK ))
slouken@3259
   863
      return -1;
slouken@3259
   864
   if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MASK).",
slouken@3477
   865
            &img_blendMask, ALLOWABLE_ERROR_OPAQUE ))
slouken@3259
   866
      return -1;
slouken@3259
   867
slouken@3259
   868
   /* Test Blend. */
slouken@3259
   869
   if (render_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND ))
slouken@3259
   870
      return -1;
slouken@3259
   871
   if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).",
slouken@3477
   872
            &img_blendBlend, ALLOWABLE_ERROR_BLENDED ))
slouken@3259
   873
      return -1;
slouken@3259
   874
slouken@3259
   875
   /* Test Add. */
slouken@3259
   876
   if (render_testBlitBlendMode( tface, SDL_BLENDMODE_ADD ))
slouken@3259
   877
      return -1;
slouken@3259
   878
   if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).",
slouken@3477
   879
            &img_blendAdd, ALLOWABLE_ERROR_BLENDED ))
slouken@3259
   880
      return -1;
slouken@3259
   881
slouken@3259
   882
   /* Test Mod. */
slouken@3259
   883
   if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MOD ))
slouken@3259
   884
      return -1;
slouken@3259
   885
   if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).",
slouken@3477
   886
            &img_blendMod, ALLOWABLE_ERROR_BLENDED ))
slouken@3259
   887
      return -1;
slouken@3259
   888
slouken@3259
   889
   /* Clear surface. */
slouken@3259
   890
   if (render_clearScreen())
slouken@3259
   891
      return -1;
slouken@3259
   892
slouken@3259
   893
   /* Loop blit. */
slouken@3259
   894
   for (j=0; j <= nj; j+=4) {
slouken@3259
   895
      for (i=0; i <= ni; i+=4) {
slouken@3259
   896
slouken@3259
   897
         /* Set colour mod. */
slouken@3453
   898
         ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
slouken@3453
   899
         if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0))
slouken@3453
   900
            return -1;
slouken@3453
   901
slouken@3453
   902
         /* Set alpha mod. */
slouken@3453
   903
         ret = SDL_SetTextureAlphaMod( tface, (100/ni)*i );
slouken@3453
   904
         if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0))
slouken@3259
   905
            return -1;
slouken@3259
   906
slouken@3259
   907
         /* Crazy blending mode magic. */
slouken@3259
   908
         mode = (i/4*j/4) % 4;
slouken@3259
   909
         if (mode==0) mode = SDL_BLENDMODE_MASK;
slouken@3259
   910
         else if (mode==1) mode = SDL_BLENDMODE_BLEND;
slouken@3259
   911
         else if (mode==2) mode = SDL_BLENDMODE_ADD;
slouken@3259
   912
         else if (mode==3) mode = SDL_BLENDMODE_MOD;
slouken@3453
   913
         ret = SDL_SetTextureBlendMode( tface, mode );
slouken@3453
   914
         if (SDL_ATassert( "SDL_SetTextureBlendMode", ret == 0))
slouken@3259
   915
            return -1;
slouken@3259
   916
slouken@3259
   917
         /* Blitting. */
slouken@3259
   918
         rect.x = i;
slouken@3259
   919
         rect.y = j;
slouken@3259
   920
         ret = SDL_RenderCopy( tface, NULL, &rect );
slouken@3259
   921
         if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
slouken@3259
   922
            return -1;
slouken@3259
   923
      }
slouken@3259
   924
   }
slouken@3259
   925
slouken@3259
   926
   /* Clean up. */
slouken@3259
   927
   SDL_DestroyTexture( tface );
slouken@3259
   928
slouken@3259
   929
   /* Check to see if matches. */
slouken@3259
   930
   if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_*).",
slouken@3477
   931
            &img_blendAll, ALLOWABLE_ERROR_BLENDED ))
slouken@3259
   932
      return -1;
slouken@3259
   933
slouken@3259
   934
   return 0;
slouken@3259
   935
}
slouken@3259
   936
slouken@3259
   937
slouken@3259
   938
/**
slouken@3259
   939
 * @brief Runs all the tests on the surface.
slouken@3259
   940
 *
slouken@3259
   941
 *    @return 0 on success.
slouken@3259
   942
 */
slouken@3259
   943
int render_runTests (void)
slouken@3259
   944
{
slouken@3259
   945
   int ret;
lestat@3464
   946
slouken@3259
   947
   /* No error. */
slouken@3259
   948
   ret = 0;
slouken@3259
   949
slouken@3259
   950
   /* Test functionality first. */
slouken@3259
   951
   if (render_hasDrawColor())
slouken@3259
   952
      SDL_ATprintVerbose( 1, "      Draw Color supported\n" );
slouken@3259
   953
   if (render_hasBlendModes())
slouken@3259
   954
      SDL_ATprintVerbose( 1, "      Blend Modes supported\n" );
slouken@3259
   955
   if (render_hasTexColor())
slouken@3259
   956
      SDL_ATprintVerbose( 1, "      Texture Color Mod supported\n" );
slouken@3259
   957
   if (render_hasTexAlpha())
slouken@3259
   958
      SDL_ATprintVerbose( 1, "      Texture Alpha Mod supported\n" );
slouken@3259
   959
slouken@3259
   960
   /* Software surface blitting. */
slouken@3558
   961
   ret = render_testReadWrite();
slouken@3558
   962
   if (ret)
slouken@3558
   963
      return -1;
slouken@3259
   964
   ret = render_testPrimitives();
slouken@3259
   965
   if (ret)
slouken@3259
   966
      return -1;
slouken@3259
   967
   ret = render_testPrimitivesBlend();
slouken@3259
   968
   if (ret)
slouken@3259
   969
      return -1;
slouken@3259
   970
   ret = render_testBlit();
slouken@3259
   971
   if (ret)
slouken@3259
   972
      return -1;
slouken@3259
   973
   ret = render_testBlitColour();
slouken@3259
   974
   if (ret)
slouken@3259
   975
      return -1;
slouken@3259
   976
   ret = render_testBlitAlpha();
slouken@3259
   977
   if (ret)
slouken@3259
   978
      return -1;
slouken@3259
   979
   ret = render_testBlitBlend();
slouken@3259
   980
slouken@3259
   981
   return ret;
slouken@3259
   982
}
slouken@3259
   983
slouken@3259
   984
slouken@3259
   985
/**
slouken@3259
   986
 * @brief Entry point.
slouken@3259
   987
 *
slouken@3259
   988
 * This testsuite is tricky, we're creating a testsuite per driver, the thing
slouken@3259
   989
 *  is we do quite a of stuff outside of the actual testcase which *could*
slouken@3259
   990
 *  give issues. Don't like that very much, but no way around without creating
slouken@3259
   991
 *  superfluous testsuites.
slouken@3259
   992
 */
slouken@3259
   993
#ifdef TEST_STANDALONE
slouken@3259
   994
int main( int argc, const char *argv[] )
slouken@3259
   995
{
slouken@3259
   996
   (void) argc;
slouken@3259
   997
   (void) argv;
slouken@3259
   998
#else /* TEST_STANDALONE */
slouken@3259
   999
int test_render (void)
slouken@3259
  1000
{
slouken@3259
  1001
#endif /* TEST_STANDALONE */
slouken@3259
  1002
   int failed;
slouken@3259
  1003
   int i, j, nd, nr;
slouken@3259
  1004
   int ret;
slouken@3259
  1005
   const char *driver, *str;
slouken@3259
  1006
   char msg[256];
slouken@3685
  1007
   SDL_Window *w;
slouken@3259
  1008
   SDL_RendererInfo renderer;
slouken@3259
  1009
slouken@3259
  1010
   /* Initializes the SDL subsystems. */
slouken@3259
  1011
   ret = SDL_Init(0);
slouken@3259
  1012
   if (ret != 0)
slouken@3259
  1013
      return -1;
slouken@3259
  1014
slouken@3259
  1015
   /* Get number of drivers. */
slouken@3259
  1016
   nd = SDL_GetNumVideoDrivers();
slouken@3259
  1017
   if (nd < 0)
slouken@3259
  1018
      goto err;
slouken@3259
  1019
   SDL_ATprintVerbose( 1, "%d Video Drivers found\n", nd );
slouken@3259
  1020
slouken@3259
  1021
   /* Now run on the video mode. */
slouken@3259
  1022
   ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
slouken@3259
  1023
   if (ret != 0)
slouken@3259
  1024
      goto err;
slouken@3259
  1025
slouken@3259
  1026
   /*
slouken@3259
  1027
    * Surface on video mode tests.
slouken@3259
  1028
    */
slouken@3259
  1029
   /* Run for all video modes. */
slouken@3259
  1030
   failed = 0;
slouken@3259
  1031
   for (i=0; i<nd; i++) {
slouken@3259
  1032
      /* Get video mode. */
slouken@3259
  1033
      driver = SDL_GetVideoDriver(i);
slouken@3259
  1034
      if (driver == NULL)
slouken@3259
  1035
         goto err;
slouken@3259
  1036
      SDL_ATprintVerbose( 1, " %d) %s\n", i+1, driver );
slouken@3259
  1037
slouken@3259
  1038
      /*
slouken@3259
  1039
       * Initialize testsuite.
slouken@3259
  1040
       */
slouken@3482
  1041
      SDL_snprintf( msg, sizeof(msg) , "Rendering with %s driver", driver );
slouken@3259
  1042
      SDL_ATinit( msg );
slouken@3259
  1043
slouken@3259
  1044
      /*
slouken@3259
  1045
       * Initialize.
slouken@3259
  1046
       */
slouken@3259
  1047
      SDL_ATbegin( "Initializing video mode" );
slouken@3259
  1048
      /* Initialize video mode. */
slouken@3259
  1049
      ret = SDL_VideoInit( driver, 0 );
slouken@3259
  1050
      if (SDL_ATvassert( ret==0, "SDL_VideoInit( %s, 0 )", driver ))
slouken@3449
  1051
         goto err_cleanup;
slouken@3259
  1052
      /* Check to see if it's the one we want. */
slouken@3259
  1053
      str = SDL_GetCurrentVideoDriver();
slouken@3482
  1054
      if (SDL_ATassert( "SDL_GetCurrentVideoDriver", SDL_strcmp(driver,str)==0))
slouken@3449
  1055
         goto err_cleanup;
slouken@3259
  1056
      /* Create window. */
slouken@3685
  1057
      w = SDL_CreateWindow( msg, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
slouken@3471
  1058
            80, 60, SDL_WINDOW_SHOWN );
slouken@3685
  1059
      if (SDL_ATassert( "SDL_CreateWindow", w!=NULL ))
slouken@3449
  1060
         goto err_cleanup;
slouken@3259
  1061
      /* Check title. */
slouken@3685
  1062
      str = SDL_GetWindowTitle( w );
slouken@3482
  1063
      if (SDL_ATassert( "SDL_GetWindowTitle", SDL_strcmp(msg,str)==0))
slouken@3449
  1064
         goto err_cleanup;
slouken@3259
  1065
      /* Get renderers. */
slouken@3259
  1066
      nr = SDL_GetNumRenderDrivers();
slouken@3259
  1067
      if (SDL_ATassert("SDL_GetNumRenderDrivers", nr>=0))
slouken@3449
  1068
         goto err_cleanup;
slouken@3259
  1069
      SDL_ATprintVerbose( 1, "   %d Render Drivers\n", nr );
slouken@3259
  1070
      SDL_ATend();
slouken@3259
  1071
      for (j=0; j<nr; j++) {
slouken@3259
  1072
lestat@3464
  1073
         /* We have to recreate window each time, because opengl and opengles renderers */
lestat@3464
  1074
         /* both add SDL_WINDOW_OPENGL flag for window, that was last used              */
slouken@3685
  1075
         SDL_DestroyWindow(w);
slouken@3685
  1076
         w = SDL_CreateWindow( msg, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
slouken@3471
  1077
               80, 60, SDL_WINDOW_SHOWN );
slouken@3685
  1078
         if (SDL_ATassert( "SDL_CreateWindow", w!=NULL ))
lestat@3464
  1079
            goto err_cleanup;
lestat@3464
  1080
slouken@3259
  1081
         /* Get renderer info. */
slouken@3259
  1082
         ret = SDL_GetRenderDriverInfo( j, &renderer );
slouken@3259
  1083
         if (ret != 0)
slouken@3449
  1084
            goto err_cleanup;
slouken@3471
  1085
slouken@3259
  1086
         /* Set testcase name. */
slouken@3482
  1087
         SDL_snprintf( msg, sizeof(msg), "Renderer %s", renderer.name );
slouken@3259
  1088
         SDL_ATprintVerbose( 1, "    %d) %s\n", j+1, renderer.name );
slouken@3259
  1089
         SDL_ATbegin( msg );
slouken@3471
  1090
slouken@3259
  1091
         /* Set renderer. */
slouken@3685
  1092
         ret = SDL_CreateRenderer( w, j, 0 );
slouken@3259
  1093
         if (SDL_ATassert( "SDL_CreateRenderer", ret==0 ))
slouken@3449
  1094
            goto err_cleanup;
slouken@3259
  1095
slouken@3259
  1096
         /*
slouken@3259
  1097
          * Run tests.
slouken@3259
  1098
          */
slouken@3259
  1099
         ret = render_runTests();
lestat@3464
  1100
slouken@3259
  1101
         if (ret)
slouken@3259
  1102
            continue;
slouken@3259
  1103
         SDL_ATend();
slouken@3259
  1104
      }
slouken@3259
  1105
slouken@3259
  1106
      /* Exit the current renderer. */
slouken@3259
  1107
      SDL_VideoQuit();
slouken@3259
  1108
slouken@3259
  1109
      /*
slouken@3259
  1110
       * Finish testsuite.
slouken@3259
  1111
       */
slouken@3259
  1112
      failed += SDL_ATfinish();
slouken@3259
  1113
   }
slouken@3259
  1114
slouken@3259
  1115
   /* Exit SDL. */
slouken@3259
  1116
   SDL_Quit();
slouken@3259
  1117
slouken@3259
  1118
   return failed;
slouken@3259
  1119
slouken@3449
  1120
err_cleanup:
slouken@3449
  1121
   SDL_ATfinish();
slouken@3449
  1122
slouken@3259
  1123
err:
slouken@3259
  1124
   return 1;
slouken@3259
  1125
}
slouken@3259
  1126