comparison render_sdl.c @ 1642:c6b2c0f8cc61

Implemented support for toggling off a debug view
author Michael Pavone <pavone@retrodev.com>
date Mon, 19 Nov 2018 19:10:16 -0800
parents 022d01b64496
children b500e971da75
comparison
equal deleted inserted replaced
1641:bc9bb4e5856f 1642:c6b2c0f8cc61
1326 screenshot_path = path; 1326 screenshot_path = path;
1327 } 1327 }
1328 1328
1329 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height) 1329 uint8_t render_create_window(char *caption, uint32_t width, uint32_t height)
1330 { 1330 {
1331 num_textures++; 1331 uint8_t win_idx = 0xFF;
1332 sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures)); 1332 for (int i = 0; i < num_textures - FRAMEBUFFER_USER_START; i++)
1333 extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows)); 1333 {
1334 extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers)); 1334 if (!extra_windows[i]) {
1335 uint8_t win_idx = num_textures - FRAMEBUFFER_USER_START - 1; 1335 win_idx = i;
1336 break;
1337 }
1338 }
1339
1340 if (win_idx == 0xFF) {
1341 num_textures++;
1342 sdl_textures = realloc(sdl_textures, num_textures * sizeof(*sdl_textures));
1343 extra_windows = realloc(extra_windows, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_windows));
1344 extra_renderers = realloc(extra_renderers, (num_textures - FRAMEBUFFER_USER_START) * sizeof(*extra_renderers));
1345 win_idx = num_textures - FRAMEBUFFER_USER_START - 1;
1346 }
1336 extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0); 1347 extra_windows[win_idx] = SDL_CreateWindow(caption, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, 0);
1337 if (!extra_windows[win_idx]) { 1348 if (!extra_windows[win_idx]) {
1338 goto fail_window; 1349 goto fail_window;
1339 } 1350 }
1340 extra_renderers[win_idx] = SDL_CreateRenderer(extra_windows[win_idx], -1, SDL_RENDERER_ACCELERATED); 1351 extra_renderers[win_idx] = SDL_CreateRenderer(extra_windows[win_idx], -1, SDL_RENDERER_ACCELERATED);
1341 if (!extra_renderers[win_idx]) { 1352 if (!extra_renderers[win_idx]) {
1342 goto fail_renderer; 1353 goto fail_renderer;
1343 } 1354 }
1344 uint8_t texture_idx = num_textures-1; 1355 uint8_t texture_idx = win_idx + FRAMEBUFFER_USER_START;
1345 sdl_textures[texture_idx] = SDL_CreateTexture(extra_renderers[win_idx], SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height); 1356 sdl_textures[texture_idx] = SDL_CreateTexture(extra_renderers[win_idx], SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, width, height);
1346 if (!sdl_textures[texture_idx]) { 1357 if (!sdl_textures[texture_idx]) {
1347 goto fail_texture; 1358 goto fail_texture;
1348 } 1359 }
1349 return texture_idx; 1360 return texture_idx;
1353 fail_renderer: 1364 fail_renderer:
1354 SDL_DestroyWindow(extra_windows[win_idx]); 1365 SDL_DestroyWindow(extra_windows[win_idx]);
1355 fail_window: 1366 fail_window:
1356 num_textures--; 1367 num_textures--;
1357 return 0; 1368 return 0;
1369 }
1370
1371 void render_destroy_window(uint8_t which)
1372 {
1373 uint8_t win_idx = which - FRAMEBUFFER_USER_START;
1374 //Destroying the renderers also frees the textures
1375 SDL_DestroyRenderer(extra_renderers[win_idx]);
1376 SDL_DestroyWindow(extra_windows[win_idx]);
1377
1378 extra_renderers[win_idx] = NULL;
1379 extra_windows[win_idx] = NULL;
1358 } 1380 }
1359 1381
1360 uint32_t *locked_pixels; 1382 uint32_t *locked_pixels;
1361 uint32_t locked_pitch; 1383 uint32_t locked_pitch;
1362 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) 1384 uint32_t *render_get_framebuffer(uint8_t which, int *pitch)