Add an option to 'testsprite2' to render slicing into triangles. [--use-rendergeometry mode1|mode2] mode1: Draw sprite2 as triangles that can be recombined as rect by software renderer mode2: Draw sprite2 as triangles that can *not* be recombined as rect by software renderer Use an 'indices' array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 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 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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273
diff --git a/test/testsprite2.c b/test/testsprite2.c
index 672ff3f..dc48b1e 100644
--- a/test/testsprite2.c
+++ b/test/testsprite2.c
@@ -39,6 +39,7 @@ static int sprite_w, sprite_h;
static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
static Uint32 next_fps_check, frames;
static const Uint32 fps_check_delay = 5000;
+static int use_rendergeometry = 0;
/* Number of iterations to move sprites - used for visual tests. */
/* -1: infinite random moves (default); >=0: enables N deterministic moves */
@@ -175,7 +176,38 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
temp.y = 1;
temp.w = sprite_w;
temp.h = sprite_h;
- SDL_RenderFillRect(renderer, &temp);
+ if (use_rendergeometry == 0) {
+ SDL_RenderFillRect(renderer, &temp);
+ } else {
+ /* Draw two triangles, filled, uniform */
+ SDL_Color color;
+ SDL_Vertex verts[3];
+ SDL_zeroa(verts);
+ color.r = 0xFF;
+ color.g = 0xFF;
+ color.b = 0xFF;
+ color.a = 0xFF;
+
+ verts[0].position.x = temp.x;
+ verts[0].position.y = temp.y;
+ verts[0].color = color;
+
+ verts[1].position.x = temp.x + temp.w;
+ verts[1].position.y = temp.y;
+ verts[1].color = color;
+
+ verts[2].position.x = temp.x + temp.w;
+ verts[2].position.y = temp.y + temp.h;
+ verts[2].color = color;
+
+ SDL_RenderGeometry(renderer, NULL, verts, 3, NULL, 0);
+
+ verts[1].position.x = temp.x;
+ verts[1].position.y = temp.y + temp.h;
+ verts[1].color = color;
+
+ SDL_RenderGeometry(renderer, NULL, verts, 3, NULL, 0);
+ }
SDL_RenderCopy(renderer, sprite, NULL, &temp);
temp.x = viewport.w-sprite_w-1;
temp.y = 1;
@@ -220,7 +252,7 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
}
}
-
+
/* Countdown sprite-move iterations and disable color changes at iteration end - used for visual tests. */
if (iterations > 0) {
iterations--;
@@ -232,11 +264,160 @@ MoveSprites(SDL_Renderer * renderer, SDL_Texture * sprite)
}
/* Draw sprites */
- for (i = 0; i < num_sprites; ++i) {
- position = &positions[i];
+ if (use_rendergeometry == 0) {
+ for (i = 0; i < num_sprites; ++i) {
+ position = &positions[i];
- /* Blit the sprite onto the screen */
- SDL_RenderCopy(renderer, sprite, NULL, position);
+ /* Blit the sprite onto the screen */
+ SDL_RenderCopy(renderer, sprite, NULL, position);
+ }
+ } else if (use_rendergeometry == 1) {
+ /*
+ * 0--1
+ * | /|
+ * |/ |
+ * 3--2
+ *
+ * Draw sprite2 as triangles that can be recombined as rect by software renderer
+ */
+ SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 6);
+ SDL_Vertex *verts2 = verts;
+ if (verts) {
+ SDL_Color color;
+ SDL_GetTextureColorMod(sprite, &color.r, &color.g, &color.b);
+ SDL_GetTextureAlphaMod(sprite, &color.a);
+ for (i = 0; i < num_sprites; ++i) {
+ position = &positions[i];
+ /* 0 */
+ verts->position.x = position->x;
+ verts->position.y = position->y;
+ verts->color = color;
+ verts->tex_coord.x = 0.0f;
+ verts->tex_coord.y = 0.0f;
+ verts++;
+ /* 1 */
+ verts->position.x = position->x + position->w;
+ verts->position.y = position->y;
+ verts->color = color;
+ verts->tex_coord.x = 1.0f;
+ verts->tex_coord.y = 0.0f;
+ verts++;
+ /* 2 */
+ verts->position.x = position->x + position->w;
+ verts->position.y = position->y + position->h;
+ verts->color = color;
+ verts->tex_coord.x = 1.0f;
+ verts->tex_coord.y = 1.0f;
+ verts++;
+ /* 0 */
+ verts->position.x = position->x;
+ verts->position.y = position->y;
+ verts->color = color;
+ verts->tex_coord.x = 0.0f;
+ verts->tex_coord.y = 0.0f;
+ verts++;
+ /* 2 */
+ verts->position.x = position->x + position->w;
+ verts->position.y = position->y + position->h;
+ verts->color = color;
+ verts->tex_coord.x = 1.0f;
+ verts->tex_coord.y = 1.0f;
+ verts++;
+ /* 3 */
+ verts->position.x = position->x;
+ verts->position.y = position->y + position->h;
+ verts->color = color;
+ verts->tex_coord.x = 0.0f;
+ verts->tex_coord.y = 1.0f;
+ verts++;
+ }
+
+ /* Blit sprites as triangles onto the screen */
+ SDL_RenderGeometry(renderer, sprite, verts2, num_sprites * 6, NULL, 0);
+ SDL_free(verts2);
+ }
+ } else if (use_rendergeometry == 2) {
+ /* 0-----1
+ * |\ A /|
+ * | \ / |
+ * |D 2 B|
+ * | / \ |
+ * |/ C \|
+ * 3-----4
+ *
+ * Draw sprite2 as triangles that can *not* be recombined as rect by software renderer
+ * Use an 'indices' array
+ */
+ SDL_Vertex *verts = (SDL_Vertex *) SDL_malloc(num_sprites * sizeof (SDL_Vertex) * 5);
+ SDL_Vertex *verts2 = verts;
+ int *indices = (int *) SDL_malloc(num_sprites * sizeof (int) * 4 * 3);
+ int *indices2 = indices;
+ if (verts && indices) {
+ int pos = 0;
+ SDL_Color color;
+ SDL_GetTextureColorMod(sprite, &color.r, &color.g, &color.b);
+ SDL_GetTextureAlphaMod(sprite, &color.a);
+ for (i = 0; i < num_sprites; ++i) {
+ position = &positions[i];
+ /* 0 */
+ verts->position.x = position->x;
+ verts->position.y = position->y;
+ verts->color = color;
+ verts->tex_coord.x = 0.0f;
+ verts->tex_coord.y = 0.0f;
+ verts++;
+ /* 1 */
+ verts->position.x = position->x + position->w;
+ verts->position.y = position->y;
+ verts->color = color;
+ verts->tex_coord.x = 1.0f;
+ verts->tex_coord.y = 0.0f;
+ verts++;
+ /* 2 */
+ verts->position.x = position->x + position->w / 2.0f;
+ verts->position.y = position->y + position->h / 2.0f;
+ verts->color = color;
+ verts->tex_coord.x = 0.5f;
+ verts->tex_coord.y = 0.5f;
+ verts++;
+ /* 3 */
+ verts->position.x = position->x;
+ verts->position.y = position->y + position->h;
+ verts->color = color;
+ verts->tex_coord.x = 0.0f;
+ verts->tex_coord.y = 1.0f;
+ verts++;
+ /* 4 */
+ verts->position.x = position->x + position->w;
+ verts->position.y = position->y + position->h;
+ verts->color = color;
+ verts->tex_coord.x = 1.0f;
+ verts->tex_coord.y = 1.0f;
+ verts++;
+ /* A */
+ *indices++ = pos + 0;
+ *indices++ = pos + 1;
+ *indices++ = pos + 2;
+ /* B */
+ *indices++ = pos + 1;
+ *indices++ = pos + 2;
+ *indices++ = pos + 4;
+ /* C */
+ *indices++ = pos + 3;
+ *indices++ = pos + 2;
+ *indices++ = pos + 4;
+ /* D */
+ *indices++ = pos + 3;
+ *indices++ = pos + 2;
+ *indices++ = pos + 0;
+ pos += 5;
+ }
+ }
+
+ /* Blit sprites as triangles onto the screen */
+ SDL_RenderGeometry(renderer, sprite, verts2, num_sprites * 5, indices2, num_sprites * 4 * 3);
+ SDL_free(verts2);
+ SDL_free(indices2);
}
/* Update the screen! */
@@ -331,6 +512,20 @@ main(int argc, char *argv[])
} else if (SDL_strcasecmp(argv[i], "--cyclealpha") == 0) {
cycle_alpha = SDL_TRUE;
consumed = 1;
+ } else if (SDL_strcasecmp(argv[i], "--use-rendergeometry") == 0) {
+ if (argv[i + 1]) {
+ if (SDL_strcasecmp(argv[i + 1], "mode1") == 0) {
+ /* Draw sprite2 as triangles that can be recombined as rect by software renderer */
+ use_rendergeometry = 1;
+ } else if (SDL_strcasecmp(argv[i + 1], "mode2") == 0) {
+ /* Draw sprite2 as triangles that can *not* be recombined as rect by software renderer
+ * Use an 'indices' array */
+ use_rendergeometry = 2;
+ } else {
+ return -1;
+ }
+ }
+ consumed = 2;
} else if (SDL_isdigit(*argv[i])) {
num_sprites = SDL_atoi(argv[i]);
consumed = 1;
@@ -340,7 +535,15 @@ main(int argc, char *argv[])
}
}
if (consumed < 0) {
- static const char *options[] = { "[--blend none|blend|add|mod]", "[--cyclecolor]", "[--cyclealpha]", "[--iterations N]", "[num_sprites]", "[icon.bmp]", NULL };
+ static const char *options[] = {
+ "[--blend none|blend|add|mod]",
+ "[--cyclecolor]",
+ "[--cyclealpha]",
+ "[--iterations N]",
+ "[--use-rendergeometry mode1|mode2]",
+ "[num_sprites]",
+ "[icon.bmp]",
+ NULL };
SDLTest_CommonLogUsage(state, argv[0], options);
quit(1);
}
@@ -374,7 +577,7 @@ main(int argc, char *argv[])
quit(2);
}
- /* Position sprites and set their velocities using the fuzzer */
+ /* Position sprites and set their velocities using the fuzzer */
if (iterations >= 0) {
/* Deterministic seed - used for visual tests */
seed = (Uint64)iterations;