Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
1088 lines (926 loc) · 27 KB

File metadata and controls

1088 lines (926 loc) · 27 KB
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/**
* Automated SDL_Surface test.
*
* Written by Edgar Simo "bobbens"
*
* Released under Public Domain.
*/
#include "SDL.h"
#include "SDL_at.h"
#include "common/common.h"
/*
* Pull in images for testcases.
*/
#include "common/images.h"
Jul 15, 2009
Jul 15, 2009
22
23
24
#define SCREEN_W 80
#define SCREEN_H 60
Jul 18, 2009
Jul 18, 2009
25
26
27
#define FACE_W img_face.width
#define FACE_H img_face.height
Jul 15, 2009
Jul 15, 2009
28
29
30
31
32
/*
* Prototypes.
*/
static int render_compare( const char *msg, const SurfaceImage_t *s );
Aug 2, 2009
Aug 2, 2009
33
static int render_isSupported( int code );
Jul 20, 2009
Jul 20, 2009
34
35
36
37
static int render_hasDrawColor (void);
static int render_hasBlendModes (void);
static int render_hasTexColor (void);
static int render_hasTexAlpha (void);
38
39
static int render_clearScreen (void);
/* Testcases. */
Jul 18, 2009
Jul 18, 2009
40
41
42
static int render_testPrimitives (void);
static int render_testPrimitivesBlend (void);
static int render_testBlit (void);
Jul 20, 2009
Jul 20, 2009
43
44
static int render_testBlitColour (void);
static int render_testBlitAlpha (void);
Jul 18, 2009
Jul 18, 2009
45
46
static int render_testBlitBlendMode( SDL_TextureID tface, int mode );
static int render_testBlitBlend (void);
Jul 20, 2009
Jul 20, 2009
50
51
52
53
54
* @brief Compares screen pixels with image pixels.
*
* @param msg Message on failure.
* @param s Image to compare against.
* @return 0 on success.
55
56
57
*/
static int render_compare( const char *msg, const SurfaceImage_t *s )
{
Jul 18, 2009
Jul 18, 2009
58
59
(void) msg;
(void) s;
60
61
62
63
64
65
66
67
68
69
int ret;
void *pix;
SDL_Surface *testsur;
/* Allocate pixel space. */
pix = malloc( 4*80*60 );
if (SDL_ATassert( "malloc", pix!=NULL ))
return 1;
/* Read pixels. */
Aug 2, 2009
Aug 2, 2009
70
#if 0
71
72
73
ret = SDL_RenderReadPixels( NULL, pix, 80*4 );
if (SDL_ATassert( "SDL_RenderReadPixels", ret==0) )
return 1;
Aug 2, 2009
Aug 2, 2009
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#else
int i, j;
Uint8 *buf = pix;
const Uint8 *read_pix;
Uint8 *write_pix;
for (j=0; j<s->height; j++) {
for (i=0; i<s->width; i++) {
read_pix = &s->pixel_data[ (j*80 + i) * s->bytes_per_pixel ];
write_pix = &buf[ (j*80 + i) * 4 ];
write_pix[0] = read_pix[0];
write_pix[1] = read_pix[1];
write_pix[2] = read_pix[2];
write_pix[3] = SDL_ALPHA_OPAQUE;
}
}
#endif
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* Create surface. */
testsur = SDL_CreateRGBSurfaceFrom( pix, 80, 60, 32, 80*4,
RMASK, GMASK, BMASK, AMASK );
if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", testsur!=NULL ))
return 1;
/* Compare surface. */
ret = surface_compare( testsur, s );
if (SDL_ATassert( msg, ret==0 ))
return 1;
/* Clean up. */
SDL_FreeSurface( testsur );
free(pix);
return 0;
}
Jul 20, 2009
Jul 20, 2009
109
Aug 2, 2009
Aug 2, 2009
110
111
112
113
114
115
116
117
118
/**
* @brief Checks to see if functionality is supported.
*/
static int render_isSupported( int code )
{
return (code == 0);
}
Jul 20, 2009
Jul 20, 2009
119
120
121
122
123
/**
* @brief Test to see if we can vary the draw colour.
*/
static int render_hasDrawColor (void)
{
Aug 2, 2009
Aug 2, 2009
124
int ret, fail;
Jul 20, 2009
Jul 20, 2009
125
126
Uint8 r, g, b, a;
Aug 2, 2009
Aug 2, 2009
127
128
fail = 0;
Jul 20, 2009
Jul 20, 2009
129
/* Set colour. */
Aug 2, 2009
Aug 2, 2009
130
131
132
133
134
135
ret = SDL_SetRenderDrawColor( 100, 100, 100, 100 );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetRenderDrawColor( &r, &g, &b, &a );
if (!render_isSupported(ret))
fail = 1;
Jul 20, 2009
Jul 20, 2009
136
/* Restore natural. */
Aug 2, 2009
Aug 2, 2009
137
138
139
ret = SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE );
if (!render_isSupported(ret))
fail = 1;
Jul 20, 2009
Jul 20, 2009
140
141
/* Something failed, consider not available. */
Aug 2, 2009
Aug 2, 2009
142
if (fail)
Jul 20, 2009
Jul 20, 2009
143
144
145
146
147
148
149
150
151
152
153
154
155
return 0;
/* Not set properly, consider failed. */
else if ((r != 100) || (g != 100) || (b != 100) || (a != 100))
return 0;
return 1;
}
/**
* @brief Test to see if we can vary the blend mode.
*/
static int render_hasBlendModes (void)
{
Aug 2, 2009
Aug 2, 2009
156
int fail;
Jul 20, 2009
Jul 20, 2009
157
158
159
int ret;
int mode;
Aug 2, 2009
Aug 2, 2009
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
fail = 0;
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetRenderDrawBlendMode( &mode );
if (!render_isSupported(ret))
fail = 1;
ret = (mode != SDL_BLENDMODE_BLEND);
if (!render_isSupported(ret))
fail = 1;
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetRenderDrawBlendMode( &mode );
if (!render_isSupported(ret))
fail = 1;
ret = (mode != SDL_BLENDMODE_ADD);
if (!render_isSupported(ret))
fail = 1;
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetRenderDrawBlendMode( &mode );
if (!render_isSupported(ret))
fail = 1;
ret = (mode != SDL_BLENDMODE_MOD);
if (!render_isSupported(ret))
fail = 1;
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MASK );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetRenderDrawBlendMode( &mode );
if (!render_isSupported(ret))
fail = 1;
ret = (mode != SDL_BLENDMODE_MASK);
if (!render_isSupported(ret))
fail = 1;
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetRenderDrawBlendMode( &mode );
if (!render_isSupported(ret))
fail = 1;
ret = (mode != SDL_BLENDMODE_NONE);
if (!render_isSupported(ret))
fail = 1;
return !fail;
Jul 20, 2009
Jul 20, 2009
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
}
/**
* @brief Loads the test face.
*/
static SDL_TextureID render_loadTestFace (void)
{
SDL_Surface *face;
SDL_TextureID tface;
/* Create face surface. */
face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
img_face.width, img_face.height, 32, img_face.width*4,
RMASK, GMASK, BMASK, AMASK );
if (face == NULL)
return 0;
tface = SDL_CreateTextureFromSurface( 0, face );
SDL_FreeSurface(face);
return tface;
}
/**
* @brief Test to see if can set texture colour mode.
*/
static int render_hasTexColor (void)
{
Aug 2, 2009
Aug 2, 2009
238
int fail;
Jul 20, 2009
Jul 20, 2009
239
240
241
242
243
244
245
246
247
248
int ret;
SDL_TextureID tface;
Uint8 r, g, b;
/* Get test face. */
tface = render_loadTestFace();
if (tface == 0)
return 0;
/* See if supported. */
Aug 2, 2009
Aug 2, 2009
249
250
251
252
253
254
255
fail = 0;
ret = SDL_SetTextureColorMod( tface, 100, 100, 100 );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetTextureColorMod( tface, &r, &g, &b );
if (!render_isSupported(ret))
fail = 1;
Jul 20, 2009
Jul 20, 2009
256
257
258
259
/* Clean up. */
SDL_DestroyTexture( tface );
Aug 2, 2009
Aug 2, 2009
260
if (fail)
Jul 20, 2009
Jul 20, 2009
261
262
263
264
265
266
267
268
269
270
271
272
return 0;
else if ((r != 100) || (g != 100) || (b != 100))
return 0;
return 1;
}
/**
* @brief Test to see if we can vary the alpha of the texture.
*/
static int render_hasTexAlpha (void)
{
Aug 2, 2009
Aug 2, 2009
273
int fail;
Jul 20, 2009
Jul 20, 2009
274
275
276
277
278
279
280
281
282
283
int ret;
SDL_TextureID tface;
Uint8 a;
/* Get test face. */
tface = render_loadTestFace();
if (tface == 0)
return 0;
/* See if supported. */
Aug 2, 2009
Aug 2, 2009
284
285
286
287
288
289
290
fail = 0;
ret = SDL_SetTextureAlphaMod( tface, 100 );
if (!render_isSupported(ret))
fail = 1;
ret = SDL_GetTextureAlphaMod( tface, &a );
if (!render_isSupported(ret))
fail = 1;
Jul 20, 2009
Jul 20, 2009
291
292
293
294
/* Clean up. */
SDL_DestroyTexture( tface );
Aug 2, 2009
Aug 2, 2009
295
if (fail)
Jul 20, 2009
Jul 20, 2009
296
297
298
299
300
301
302
return 0;
else if (a != 100)
return 0;
return 1;
}
303
304
/**
* @brief Clears the screen.
Jul 20, 2009
Jul 20, 2009
305
306
*
* @note We don't test for errors, but they shouldn't happen.
307
308
309
310
311
312
313
*/
static int render_clearScreen (void)
{
int ret;
/* Set colour. */
ret = SDL_SetRenderDrawColor( 0, 0, 0, SDL_ALPHA_OPAQUE );
Jul 20, 2009
Jul 20, 2009
314
/*
315
316
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1;
Jul 20, 2009
Jul 20, 2009
317
*/
318
319
320
/* Clear screen. */
ret = SDL_RenderFill( NULL );
Jul 20, 2009
Jul 20, 2009
321
/*
322
323
if (SDL_ATassert( "SDL_RenderFill", ret == 0))
return -1;
Jul 20, 2009
Jul 20, 2009
324
*/
Jul 15, 2009
Jul 15, 2009
326
327
/* Set defaults. */
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
Jul 20, 2009
Jul 20, 2009
328
/*
Jul 15, 2009
Jul 15, 2009
329
330
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1;
Jul 20, 2009
Jul 20, 2009
331
*/
Jul 15, 2009
Jul 15, 2009
332
ret = SDL_SetRenderDrawColor( 255, 255, 255, SDL_ALPHA_OPAQUE );
Jul 20, 2009
Jul 20, 2009
333
/*
Jul 15, 2009
Jul 15, 2009
334
335
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1;
Jul 20, 2009
Jul 20, 2009
336
*/
Jul 15, 2009
Jul 15, 2009
337
338
339
340
341
342
343
344
return 0;
}
/**
* @brief Tests the SDL primitives for rendering.
*/
Jul 18, 2009
Jul 18, 2009
345
static int render_testPrimitives (void)
346
347
348
349
350
351
352
{
int ret;
int x, y;
SDL_Rect rect;
/* Clear surface. */
if (render_clearScreen())
Jul 18, 2009
Jul 18, 2009
353
return -1;
Jul 20, 2009
Jul 20, 2009
355
356
357
358
/* Need drawcolour or just skip test. */
if (!render_hasDrawColor())
return 0;
359
360
361
362
363
364
365
/* Draw a rectangle. */
rect.x = 40;
rect.y = 0;
rect.w = 40;
rect.h = 80;
ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
366
return -1;
367
368
ret = SDL_RenderFill( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0))
Jul 18, 2009
Jul 18, 2009
369
return -1;
370
371
372
373
374
375
376
377
/* Draw a rectangle. */
rect.x = 10;
rect.y = 10;
rect.w = 60;
rect.h = 40;
ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
378
return -1;
379
380
ret = SDL_RenderFill( &rect );
if (SDL_ATassert( "SDL_RenderRect", ret == 0))
Jul 18, 2009
Jul 18, 2009
381
return -1;
382
383
384
385
386
387
388
389
390
391
/* Draw some points like so:
* X.X.X.X..
* .X.X.X.X.
* X.X.X.X.. */
for (y=0; y<3; y++) {
x = y % 2;
for (; x<80; x+=2) {
ret = SDL_SetRenderDrawColor( x*y, x*y/2, x*y/3, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
392
return -1;
393
394
ret = SDL_RenderPoint( x, y );
if (SDL_ATassert( "SDL_RenderPoint", ret == 0))
Jul 18, 2009
Jul 18, 2009
395
return -1;
396
397
398
399
400
401
}
}
/* Draw some lines. */
ret = SDL_SetRenderDrawColor( 0, 255, 0, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
402
return -1;
403
404
ret = SDL_RenderLine( 0, 30, 80, 30 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0))
Jul 18, 2009
Jul 18, 2009
405
return -1;
406
407
ret = SDL_SetRenderDrawColor( 55, 55, 5, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
408
return -1;
409
410
ret = SDL_RenderLine( 40, 30, 40, 60 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0))
Jul 18, 2009
Jul 18, 2009
411
return -1;
412
413
ret = SDL_SetRenderDrawColor( 5, 105, 105, SDL_ALPHA_OPAQUE );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
414
return -1;
415
416
ret = SDL_RenderLine( 0, 60, 80, 0 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0))
Jul 18, 2009
Jul 18, 2009
417
return -1;
418
419
420
/* See if it's the same. */
if (render_compare( "Primitives output not the same.", &img_primitives ))
Jul 18, 2009
Jul 18, 2009
421
422
423
return -1;
return 0;
424
425
426
427
428
429
}
/**
* @brief Tests the SDL primitives with alpha for rendering.
*/
Jul 18, 2009
Jul 18, 2009
430
static int render_testPrimitivesBlend (void)
431
432
433
434
435
436
{
int ret;
int i, j;
SDL_Rect rect;
/* Clear surface. */
Jul 15, 2009
Jul 15, 2009
437
if (render_clearScreen())
Jul 18, 2009
Jul 18, 2009
438
return -1;
Jul 20, 2009
Jul 20, 2009
440
441
442
/* Need drawcolour and blendmode or just skip test. */
if (!render_hasDrawColor() || !render_hasBlendModes())
return 0;
Jul 15, 2009
Jul 15, 2009
443
444
/* Create some rectangles for each blend mode. */
Jul 15, 2009
Jul 15, 2009
445
446
ret = SDL_SetRenderDrawColor( 255, 255, 255, 0 );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
447
return -1;
Jul 15, 2009
Jul 15, 2009
448
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE );
Jul 15, 2009
Jul 15, 2009
449
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
450
return -1;
Jul 15, 2009
Jul 15, 2009
451
452
ret = SDL_RenderFill( NULL );
if (SDL_ATassert( "SDL_RenderFill", ret == 0))
Jul 18, 2009
Jul 18, 2009
453
return -1;
454
455
456
457
rect.x = 10;
rect.y = 25;
rect.w = 40;
rect.h = 25;
Jul 15, 2009
Jul 15, 2009
458
459
ret = SDL_SetRenderDrawColor( 240, 10, 10, 75 );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
460
return -1;
Jul 15, 2009
Jul 15, 2009
461
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD );
Jul 15, 2009
Jul 15, 2009
462
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
463
return -1;
Jul 15, 2009
Jul 15, 2009
464
465
ret = SDL_RenderFill( &rect );
if (SDL_ATassert( "SDL_RenderFill", ret == 0))
Jul 18, 2009
Jul 18, 2009
466
return -1;
467
468
469
470
rect.x = 30;
rect.y = 40;
rect.w = 45;
rect.h = 15;
Jul 15, 2009
Jul 15, 2009
471
472
ret = SDL_SetRenderDrawColor( 10, 240, 10, 100 );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
473
return -1;
Jul 15, 2009
Jul 15, 2009
474
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND );
Jul 15, 2009
Jul 15, 2009
475
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
476
return -1;
Jul 15, 2009
Jul 15, 2009
477
478
ret = SDL_RenderFill( &rect );
if (SDL_ATassert( "SDL_RenderFill", ret == 0))
Jul 18, 2009
Jul 18, 2009
479
return -1;
480
481
482
483
rect.x = 25;
rect.y = 25;
rect.w = 25;
rect.h = 25;
Jul 15, 2009
Jul 15, 2009
484
485
ret = SDL_SetRenderDrawColor( 10, 10, 240, 125 );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
486
return -1;
Jul 15, 2009
Jul 15, 2009
487
ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD );
Jul 15, 2009
Jul 15, 2009
488
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
489
return -1;
Jul 15, 2009
Jul 15, 2009
490
491
ret = SDL_RenderFill( &rect );
if (SDL_ATassert( "SDL_RenderFill", ret == 0))
Jul 18, 2009
Jul 18, 2009
492
return -1;
493
494
/* Draw blended lines, lines for everyone. */
Jul 15, 2009
Jul 15, 2009
495
496
497
for (i=0; i<SCREEN_W; i+=2) {
ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
498
return -1;
Jul 15, 2009
Jul 15, 2009
499
500
ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
Jul 15, 2009
Jul 15, 2009
501
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
502
return -1;
Jul 15, 2009
Jul 15, 2009
503
504
ret = SDL_RenderLine( 0, 0, i, 59 );
if (SDL_ATassert( "SDL_RenderLine", ret == 0))
Jul 18, 2009
Jul 18, 2009
505
return -1;
Jul 15, 2009
Jul 15, 2009
507
508
509
for (i=0; i<SCREEN_H; i+=2) {
ret = SDL_SetRenderDrawColor( 60+2*i, 240-2*i, 50, 3*i );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
510
return -1;
Jul 15, 2009
Jul 15, 2009
511
512
ret = SDL_SetRenderDrawBlendMode((((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
(((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
Jul 15, 2009
Jul 15, 2009
513
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
514
return -1;
Jul 15, 2009
Jul 15, 2009
515
516
ret = SDL_RenderLine( 0, 0, 79, i );
if (SDL_ATassert( "SDL_RenderLine", ret == 0))
Jul 18, 2009
Jul 18, 2009
517
return -1;
518
519
520
}
/* Draw points. */
Jul 15, 2009
Jul 15, 2009
521
522
523
524
for (j=0; j<SCREEN_H; j+=3) {
for (i=0; i<SCREEN_W; i+=3) {
ret = SDL_SetRenderDrawColor( j*4, i*3, j*4, i*3 );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
Jul 18, 2009
Jul 18, 2009
525
return -1;
Jul 15, 2009
Jul 15, 2009
526
527
ret = SDL_SetRenderDrawBlendMode( ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD );
Jul 15, 2009
Jul 15, 2009
528
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
Jul 18, 2009
Jul 18, 2009
529
return -1;
Jul 15, 2009
Jul 15, 2009
530
531
ret = SDL_RenderPoint( i, j );
if (SDL_ATassert( "SDL_RenderPoint", ret == 0))
Jul 18, 2009
Jul 18, 2009
532
return -1;
533
534
535
536
}
}
/* See if it's the same. */
Jul 15, 2009
Jul 15, 2009
537
if (render_compare( "Blended primitives output not the same.", &img_primitives ))
Jul 18, 2009
Jul 18, 2009
538
539
540
return -1;
return 0;
541
542
543
544
545
546
}
/**
* @brief Tests some blitting routines.
*/
Jul 18, 2009
Jul 18, 2009
547
static int render_testBlit (void)
548
549
550
551
{
int ret;
SDL_Rect rect;
SDL_Surface *face;
Jul 15, 2009
Jul 15, 2009
552
SDL_TextureID tface;
553
554
555
int i, j, ni, nj;
/* Clear surface. */
Jul 15, 2009
Jul 15, 2009
556
if (render_clearScreen())
Jul 18, 2009
Jul 18, 2009
557
return -1;
Jul 20, 2009
Jul 20, 2009
559
560
561
562
/* Need drawcolour or just skip test. */
if (!render_hasDrawColor())
return 0;
563
564
565
566
567
/* Create face surface. */
face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
img_face.width, img_face.height, 32, img_face.width*4,
RMASK, GMASK, BMASK, AMASK );
if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
Jul 18, 2009
Jul 18, 2009
568
return -1;
Jul 15, 2009
Jul 15, 2009
569
570
tface = SDL_CreateTextureFromSurface( 0, face );
if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0))
Jul 18, 2009
Jul 18, 2009
571
return -1;
Jul 15, 2009
Jul 15, 2009
572
573
574
575
/* Constant values. */
rect.w = face->w;
rect.h = face->h;
Jul 15, 2009
Jul 15, 2009
576
577
ni = SCREEN_W - face->w;
nj = SCREEN_H - face->h;
Aug 4, 2009
Aug 4, 2009
579
580
581
/* Clean up. */
SDL_FreeSurface( face );
582
583
584
585
586
587
/* Loop blit. */
for (j=0; j <= nj; j+=4) {
for (i=0; i <= ni; i+=4) {
/* Blitting. */
rect.x = i;
rect.y = j;
Jul 15, 2009
Jul 15, 2009
588
589
ret = SDL_RenderCopy( tface, NULL, &rect );
if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
Jul 18, 2009
Jul 18, 2009
590
return -1;
Jul 20, 2009
Jul 20, 2009
594
595
596
/* Clean up. */
SDL_DestroyTexture( tface );
597
/* See if it's the same. */
Jul 15, 2009
Jul 15, 2009
598
if (render_compare( "Blit output not the same.", &img_blit ))
Jul 18, 2009
Jul 18, 2009
599
return -1;
Jul 20, 2009
Jul 20, 2009
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
return 0;
}
/**
* @brief Blits doing colour tests.
*/
static int render_testBlitColour (void)
{
int ret;
SDL_Rect rect;
SDL_Surface *face;
SDL_TextureID tface;
int i, j, ni, nj;
616
/* Clear surface. */
Jul 15, 2009
Jul 15, 2009
617
if (render_clearScreen())
Jul 18, 2009
Jul 18, 2009
618
return -1;
Jul 20, 2009
Jul 20, 2009
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
/* Need drawcolour or just skip test. */
if (!render_hasTexColor())
return 0;
/* Create face surface. */
face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
img_face.width, img_face.height, 32, img_face.width*4,
RMASK, GMASK, BMASK, AMASK );
if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
return -1;
tface = SDL_CreateTextureFromSurface( 0, face );
if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0))
return -1;
/* Constant values. */
rect.w = face->w;
rect.h = face->h;
ni = SCREEN_W - face->w;
nj = SCREEN_H - face->h;
Aug 4, 2009
Aug 4, 2009
640
641
642
/* Clean up. */
SDL_FreeSurface( face );
643
644
645
646
/* Test blitting with colour mod. */
for (j=0; j <= nj; j+=4) {
for (i=0; i <= ni; i+=4) {
/* Set colour mod. */
Jul 15, 2009
Jul 15, 2009
647
648
ret = SDL_SetTextureColorMod( tface, (255/nj)*j, (255/ni)*i, (255/nj)*j );
if (SDL_ATassert( "SDL_SetTextureColorMod", ret == 0))
Jul 18, 2009
Jul 18, 2009
649
return -1;
650
651
652
653
/* Blitting. */
rect.x = i;
rect.y = j;
Jul 15, 2009
Jul 15, 2009
654
655
ret = SDL_RenderCopy( tface, NULL, &rect );
if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
Jul 18, 2009
Jul 18, 2009
656
return -1;
Jul 20, 2009
Jul 20, 2009
660
661
662
/* Clean up. */
SDL_DestroyTexture( tface );
663
/* See if it's the same. */
Jul 15, 2009
Jul 15, 2009
664
665
if (render_compare( "Blit output not the same (using SDL_SetTextureColorMod).",
&img_blitColour ))
Jul 18, 2009
Jul 18, 2009
666
return -1;
Jul 20, 2009
Jul 20, 2009
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
return 0;
}
/**
* @brief Tests blitting with alpha.
*/
static int render_testBlitAlpha (void)
{
int ret;
SDL_Rect rect;
SDL_Surface *face;
SDL_TextureID tface;
int i, j, ni, nj;
683
/* Clear surface. */
Jul 15, 2009
Jul 15, 2009
684
if (render_clearScreen())
Jul 18, 2009
Jul 18, 2009
685
return -1;
Jul 20, 2009
Jul 20, 2009
687
688
689
690
691
692
693
694
695
696
697
698
/* Need alpha or just skip test. */
if (!render_hasTexAlpha())
return 0;
/* Create face surface. */
face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
img_face.width, img_face.height, 32, img_face.width*4,
RMASK, GMASK, BMASK, AMASK );
if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
return -1;
tface = SDL_CreateTextureFromSurface( 0, face );
if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0))
Jul 18, 2009
Jul 18, 2009
699
return -1;
Jul 20, 2009
Jul 20, 2009
701
702
703
704
705
706
/* Constant values. */
rect.w = face->w;
rect.h = face->h;
ni = SCREEN_W - face->w;
nj = SCREEN_H - face->h;
Aug 4, 2009
Aug 4, 2009
707
708
709
/* Clean up. */
SDL_FreeSurface( face );
Jul 20, 2009
Jul 20, 2009
710
711
712
713
714
/* Clear surface. */
if (render_clearScreen())
return -1;
/* Test blitting with alpha mod. */
715
716
717
for (j=0; j <= nj; j+=4) {
for (i=0; i <= ni; i+=4) {
/* Set alpha mod. */
Jul 15, 2009
Jul 15, 2009
718
719
ret = SDL_SetTextureAlphaMod( tface, (255/ni)*i );
if (SDL_ATassert( "SDL_SetTextureAlphaMod", ret == 0))
Jul 18, 2009
Jul 18, 2009
720
return -1;
721
722
723
724
/* Blitting. */
rect.x = i;
rect.y = j;
Jul 15, 2009
Jul 15, 2009
725
726
ret = SDL_RenderCopy( tface, NULL, &rect );
if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
Jul 18, 2009
Jul 18, 2009
727
return -1;
Jul 20, 2009
Jul 20, 2009
731
732
733
/* Clean up. */
SDL_DestroyTexture( tface );
734
/* See if it's the same. */
Jul 15, 2009
Jul 15, 2009
735
736
if (render_compare( "Blit output not the same (using SDL_SetSurfaceAlphaMod).",
&img_blitAlpha ))
Jul 18, 2009
Jul 18, 2009
737
return -1;
Jul 18, 2009
Jul 18, 2009
739
return 0;
740
741
742
743
744
745
}
/**
* @brief Tests a blend mode.
*/
Jul 18, 2009
Jul 18, 2009
746
static int render_testBlitBlendMode( SDL_TextureID tface, int mode )
747
748
749
750
751
752
{
int ret;
int i, j, ni, nj;
SDL_Rect rect;
/* Clear surface. */
Jul 18, 2009
Jul 18, 2009
753
754
if (render_clearScreen())
return -1;
755
756
/* Steps to take. */
Jul 18, 2009
Jul 18, 2009
757
758
ni = SCREEN_W - FACE_W;
nj = SCREEN_H - FACE_H;
759
760
/* Constant values. */
Jul 18, 2009
Jul 18, 2009
761
762
rect.w = FACE_W;
rect.h = FACE_H;
763
764
765
766
767
/* Test blend mode. */
for (j=0; j <= nj; j+=4) {
for (i=0; i <= ni; i+=4) {
/* Set blend mode. */
Jul 18, 2009
Jul 18, 2009
768
769
770
ret = SDL_SetRenderDrawBlendMode( mode );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1;
771
772
773
774
/* Blitting. */
rect.x = i;
rect.y = j;
Jul 18, 2009
Jul 18, 2009
775
776
777
ret = SDL_RenderCopy( tface, NULL, &rect );
if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
return -1;
778
779
780
781
782
783
784
785
786
787
}
}
return 0;
}
/**
* @brief Tests some more blitting routines.
*/
Jul 18, 2009
Jul 18, 2009
788
static int render_testBlitBlend (void)
789
790
791
792
{
int ret;
SDL_Rect rect;
SDL_Surface *face;
Jul 18, 2009
Jul 18, 2009
793
SDL_TextureID tface;
794
795
796
797
int i, j, ni, nj;
int mode;
/* Clear surface. */
Jul 18, 2009
Jul 18, 2009
798
799
if (render_clearScreen())
return -1;
Jul 20, 2009
Jul 20, 2009
801
802
803
804
/* Need drawcolour and blendmode or just skip test. */
if (!render_hasBlendModes() || !render_hasTexColor() || !render_hasTexAlpha())
return 0;
Jul 18, 2009
Jul 18, 2009
805
/* Create face surface. */
806
807
808
809
face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
img_face.width, img_face.height, 32, img_face.width*4,
RMASK, GMASK, BMASK, AMASK );
if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
Jul 18, 2009
Jul 18, 2009
810
811
812
813
814
return -1;
tface = SDL_CreateTextureFromSurface( 0, face );
if (SDL_ATassert( "SDL_CreateTextureFromSurface", tface != 0))
return -1;
815
/* Steps to take. */
Jul 18, 2009
Jul 18, 2009
816
817
ni = SCREEN_W - FACE_W;
nj = SCREEN_H - FACE_H;
818
819
820
821
822
/* Constant values. */
rect.w = face->w;
rect.h = face->h;
Aug 4, 2009
Aug 4, 2009
823
824
825
826
827
828
829
830
/* Clean up. */
SDL_FreeSurface( face );
/* Set alpha mod. */
ret = SDL_SetRenderDrawColor( 255, 255, 255, 100 );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1;
Jul 18, 2009
Jul 18, 2009
832
833
834
835
836
837
if (render_testBlitBlendMode( tface, SDL_BLENDMODE_NONE ))
return -1;
/* See if it's the same. */
if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_NONE).",
&img_blitAlpha ))
return -1;
Jul 18, 2009
Jul 18, 2009
840
841
842
843
844
if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MASK ))
return -1;
if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MASK).",
&img_blendMask ))
return -1;
845
846
/* Test Blend. */
Jul 18, 2009
Jul 18, 2009
847
848
849
850
851
if (render_testBlitBlendMode( tface, SDL_BLENDMODE_BLEND ))
return -1;
if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_BLEND).",
&img_blendBlend ))
return -1;
Jul 18, 2009
Jul 18, 2009
854
855
856
857
858
if (render_testBlitBlendMode( tface, SDL_BLENDMODE_ADD ))
return -1;
if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_ADD).",
&img_blendAdd ))
return -1;
Jul 18, 2009
Jul 18, 2009
861
862
863
864
865
if (render_testBlitBlendMode( tface, SDL_BLENDMODE_MOD ))
return -1;
if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_MOD).",
&img_blendMod ))
return -1;
866
867
/* Clear surface. */
Jul 18, 2009
Jul 18, 2009
868
869
if (render_clearScreen())
return -1;
870
871
872
873
874
875
/* Loop blit. */
for (j=0; j <= nj; j+=4) {
for (i=0; i <= ni; i+=4) {
/* Set colour mod. */
Jul 18, 2009
Jul 18, 2009
876
877
878
ret = SDL_SetRenderDrawColor( (255/nj)*j, (255/ni)*i, (255/nj)*j, (100/ni)*i );
if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0))
return -1;
879
880
881
882
883
884
885
/* Crazy blending mode magic. */
mode = (i/4*j/4) % 4;
if (mode==0) mode = SDL_BLENDMODE_MASK;
else if (mode==1) mode = SDL_BLENDMODE_BLEND;
else if (mode==2) mode = SDL_BLENDMODE_ADD;
else if (mode==3) mode = SDL_BLENDMODE_MOD;
Jul 18, 2009
Jul 18, 2009
886
887
888
ret = SDL_SetRenderDrawBlendMode( mode );
if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0))
return -1;
889
890
891
892
/* Blitting. */
rect.x = i;
rect.y = j;
Jul 18, 2009
Jul 18, 2009
893
894
895
ret = SDL_RenderCopy( tface, NULL, &rect );
if (SDL_ATassert( "SDL_RenderCopy", ret == 0))
return -1;
Jul 20, 2009
Jul 20, 2009
899
900
901
/* Clean up. */
SDL_DestroyTexture( tface );
902
/* Check to see if matches. */
Jul 18, 2009
Jul 18, 2009
903
904
905
if (render_compare( "Blit blending output not the same (using SDL_BLENDMODE_*).",
&img_blendAll ))
return -1;
Jul 18, 2009
Jul 18, 2009
907
return 0;
908
909
910
911
912
913
}
/**
* @brief Runs all the tests on the surface.
*
Jul 18, 2009
Jul 18, 2009
914
* @return 0 on success.
Jul 18, 2009
Jul 18, 2009
916
int render_runTests (void)
Jul 18, 2009
Jul 18, 2009
918
919
920
921
922
int ret;
/* No error. */
ret = 0;
Aug 3, 2009
Aug 3, 2009
923
924
925
926
927
928
929
930
931
932
/* Test functionality first. */
if (render_hasDrawColor())
SDL_ATprintVerbose( 1, " Draw Color supported\n" );
if (render_hasBlendModes())
SDL_ATprintVerbose( 1, " Blend Modes supported\n" );
if (render_hasTexColor())
SDL_ATprintVerbose( 1, " Texture Color Mod supported\n" );
if (render_hasTexAlpha())
SDL_ATprintVerbose( 1, " Texture Alpha Mod supported\n" );
933
/* Software surface blitting. */
Jul 20, 2009
Jul 20, 2009
934
ret = render_testPrimitives();
Jul 18, 2009
Jul 18, 2009
935
936
if (ret)
return -1;
Jul 20, 2009
Jul 20, 2009
937
ret = render_testPrimitivesBlend();
Jul 18, 2009
Jul 18, 2009
938
939
if (ret)
return -1;
Jul 20, 2009
Jul 20, 2009
940
ret = render_testBlit();
Jul 18, 2009
Jul 18, 2009
941
942
if (ret)
return -1;
Jul 20, 2009
Jul 20, 2009
943
944
945
946
947
948
949
950
ret = render_testBlitColour();
if (ret)
return -1;
ret = render_testBlitAlpha();
if (ret)
return -1;
ret = render_testBlitBlend();
Jul 18, 2009
Jul 18, 2009
951
952
return ret;
953
954
955
956
957
958
959
960
961
962
963
}
/**
* @brief Entry point.
*
* This testsuite is tricky, we're creating a testsuite per driver, the thing
* is we do quite a of stuff outside of the actual testcase which *could*
* give issues. Don't like that very much, but no way around without creating
* superfluous testsuites.
*/
Aug 2, 2009
Aug 2, 2009
964
#ifdef TEST_STANDALONE
965
966
967
968
int main( int argc, const char *argv[] )
{
(void) argc;
(void) argv;
Aug 2, 2009
Aug 2, 2009
969
970
971
972
#else /* TEST_STANDALONE */
int test_render (void)
{
#endif /* TEST_STANDALONE */
Aug 6, 2009
Aug 6, 2009
973
int failed;
974
975
976
977
978
979
980
981
982
983
984
985
986
987
int i, j, nd, nr;
int ret;
const char *driver, *str;
char msg[256];
SDL_WindowID wid;
SDL_RendererInfo renderer;
/* Initializes the SDL subsystems. */
ret = SDL_Init(0);
if (ret != 0)
return -1;
/* Get number of drivers. */
nd = SDL_GetNumVideoDrivers();
Aug 3, 2009
Aug 3, 2009
988
if (nd < 0)
Aug 3, 2009
Aug 3, 2009
990
SDL_ATprintVerbose( 1, "%d Video Drivers found\n", nd );
991
992
993
994
995
996
997
998
999
1000
/* Now run on the video mode. */
ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
if (ret != 0)
goto err;
/*
* Surface on video mode tests.
*/
/* Run for all video modes. */