Mercurial > repos > blastem
comparison render_sdl.c @ 1267:3772bb926be5
Initial stab at horizontal border emulation. Only works for H40 and still has a few minor holes to fill
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 06 Mar 2017 00:23:35 -0800 |
parents | 5f65a16c23ff |
children | eca01056a915 |
comparison
equal
deleted
inserted
replaced
1266:a4fa897c99ce | 1267:3772bb926be5 |
---|---|
254 gl_setup(); | 254 gl_setup(); |
255 } else { | 255 } else { |
256 #endif | 256 #endif |
257 | 257 |
258 //TODO: Fixme for invalid display mode | 258 //TODO: Fixme for invalid display mode |
259 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 588); | 259 sdl_textures[0] = sdl_textures[1] = SDL_CreateTexture(main_renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, LINEBUF_SIZE, 588); |
260 #ifndef DISABLE_OPENGL | 260 #ifndef DISABLE_OPENGL |
261 } | 261 } |
262 #endif | 262 #endif |
263 } | 263 } |
264 | 264 |
322 } | 322 } |
323 } | 323 } |
324 | 324 |
325 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; | 325 static uint32_t overscan_top[NUM_VID_STD] = {2, 21}; |
326 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; | 326 static uint32_t overscan_bot[NUM_VID_STD] = {1, 17}; |
327 static uint32_t overscan_left[NUM_VID_STD] = {13, 13}; | |
328 static uint32_t overscan_right[NUM_VID_STD] = {14, 14}; | |
327 static vid_std video_standard = VID_NTSC; | 329 static vid_std video_standard = VID_NTSC; |
328 static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal"}; | 330 static char *vid_std_names[NUM_VID_STD] = {"ntsc", "pal"}; |
329 void render_init(int width, int height, char * title, uint8_t fullscreen) | 331 void render_init(int width, int height, char * title, uint8_t fullscreen) |
330 { | 332 { |
331 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { | 333 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER) < 0) { |
373 } | 375 } |
374 val = tern_find_path_default(std_settings, "overscan\0bottom\0", (tern_val){.ptrval = NULL}).ptrval; | 376 val = tern_find_path_default(std_settings, "overscan\0bottom\0", (tern_val){.ptrval = NULL}).ptrval; |
375 if (val) { | 377 if (val) { |
376 overscan_bot[i] = atoi(val); | 378 overscan_bot[i] = atoi(val); |
377 } | 379 } |
380 val = tern_find_path_default(std_settings, "overscan\0left\0", (tern_val){.ptrval = NULL}).ptrval; | |
381 if (val) { | |
382 overscan_left[i] = atoi(val); | |
383 } | |
384 val = tern_find_path_default(std_settings, "overscan\0right\0", (tern_val){.ptrval = NULL}).ptrval; | |
385 if (val) { | |
386 overscan_right[i] = atoi(val); | |
387 } | |
378 } | 388 } |
379 } | 389 } |
380 } | 390 } |
381 | 391 |
382 #ifndef DISABLE_OPENGL | 392 #ifndef DISABLE_OPENGL |
502 uint32_t locked_pitch; | 512 uint32_t locked_pitch; |
503 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) | 513 uint32_t *render_get_framebuffer(uint8_t which, int *pitch) |
504 { | 514 { |
505 #ifndef DISABLE_OPENGL | 515 #ifndef DISABLE_OPENGL |
506 if (render_gl && which <= FRAMEBUFFER_EVEN) { | 516 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
507 *pitch = 320 * sizeof(uint32_t); //TODO: change this to LINEBUF_SIZE once border rendering is added | 517 *pitch = LINEBUF_SIZE * sizeof(uint32_t); |
508 return texture_buf; | 518 return texture_buf; |
509 } else { | 519 } else { |
510 #endif | 520 #endif |
511 if (which >= num_textures) { | 521 if (which >= num_textures) { |
512 warning("Request for invalid framebuffer number %d\n", which); | 522 warning("Request for invalid framebuffer number %d\n", which); |
546 { | 556 { |
547 static uint8_t last; | 557 static uint8_t last; |
548 uint32_t height = which <= FRAMEBUFFER_EVEN | 558 uint32_t height = which <= FRAMEBUFFER_EVEN |
549 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) | 559 ? (video_standard == VID_NTSC ? 243 : 294) - (overscan_top[video_standard] + overscan_bot[video_standard]) |
550 : 240; | 560 : 240; |
561 width -= overscan_left[video_standard] + overscan_right[video_standard]; | |
551 FILE *screenshot_file = NULL; | 562 FILE *screenshot_file = NULL; |
552 uint32_t shot_height; | 563 uint32_t shot_height; |
553 if (screenshot_path && which == FRAMEBUFFER_ODD) { | 564 if (screenshot_path && which == FRAMEBUFFER_ODD) { |
554 screenshot_file = fopen(screenshot_path, "wb"); | 565 screenshot_file = fopen(screenshot_path, "wb"); |
555 if (screenshot_file) { | 566 if (screenshot_file) { |
562 shot_height = video_standard == VID_NTSC ? 243 : 294; | 573 shot_height = video_standard == VID_NTSC ? 243 : 294; |
563 } | 574 } |
564 #ifndef DISABLE_OPENGL | 575 #ifndef DISABLE_OPENGL |
565 if (render_gl && which <= FRAMEBUFFER_EVEN) { | 576 if (render_gl && which <= FRAMEBUFFER_EVEN) { |
566 glBindTexture(GL_TEXTURE_2D, textures[which]); | 577 glBindTexture(GL_TEXTURE_2D, textures[which]); |
567 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 320, height, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf + 320 * overscan_top[video_standard]); | 578 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, GL_BGRA, GL_UNSIGNED_BYTE, texture_buf + overscan_left[video_standard] + LINEBUF_SIZE * overscan_top[video_standard]); |
568 | 579 |
569 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); | 580 glClearColor(0.0f, 0.0f, 0.0f, 1.0f); |
570 glClear(GL_COLOR_BUFFER_BIT); | 581 glClear(GL_COLOR_BUFFER_BIT); |
571 | 582 |
572 glUseProgram(program); | 583 glUseProgram(program); |
592 | 603 |
593 SDL_GL_SwapWindow(main_window); | 604 SDL_GL_SwapWindow(main_window); |
594 | 605 |
595 if (screenshot_file) { | 606 if (screenshot_file) { |
596 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now | 607 //properly supporting interlaced modes here is non-trivial, so only save the odd field for now |
597 save_ppm(screenshot_file, texture_buf, width, shot_height, 320*sizeof(uint32_t)); | 608 save_ppm(screenshot_file, texture_buf, width, shot_height, LINEBUF_SIZE*sizeof(uint32_t)); |
598 } | 609 } |
599 } else { | 610 } else { |
600 #endif | 611 #endif |
601 if (which <= FRAMEBUFFER_EVEN && last != which) { | 612 if (which <= FRAMEBUFFER_EVEN && last != which) { |
602 uint8_t *cur_dst = (uint8_t *)locked_pixels; | 613 uint8_t *cur_dst = (uint8_t *)locked_pixels; |
623 } | 634 } |
624 save_ppm(screenshot_file, locked_pixels, width, shot_height, shot_pitch); | 635 save_ppm(screenshot_file, locked_pixels, width, shot_height, shot_pitch); |
625 } | 636 } |
626 SDL_UnlockTexture(sdl_textures[which]); | 637 SDL_UnlockTexture(sdl_textures[which]); |
627 SDL_Rect src_clip = { | 638 SDL_Rect src_clip = { |
628 .x = 0, | 639 .x = overscan_left[video_standard], |
629 .y = overscan_top[video_standard], | 640 .y = overscan_top[video_standard], |
630 .w = width, | 641 .w = width, |
631 .h = height | 642 .h = height |
632 }; | 643 }; |
633 SDL_RenderCopy(main_renderer, sdl_textures[which], &src_clip, &main_clip); | 644 SDL_RenderCopy(main_renderer, sdl_textures[which], &src_clip, &main_clip); |