From 28eb3604f9fa0db1a0b638cbb0025402544c5306 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Fri, 10 Aug 2012 06:50:41 +0200 Subject: [PATCH] (PS3/Gl) refactored stuff --- gfx/context/ps3_ctx.c | 168 ++++++++++++++++++++---------------------- gfx/context/xdk_ctx.c | 2 + gfx/gl.c | 110 ++++++++++++++------------- 3 files changed, 136 insertions(+), 144 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 59eb60dca7..6b38196807 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -37,6 +37,84 @@ static struct texture_image menu_texture; static PSGLdevice* gl_device; static PSGLcontext* gl_context; +int gfx_ctx_check_resolution(unsigned resolution_id) +{ + return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO, 0); +} + +unsigned gfx_ctx_get_resolution_width(unsigned resolution_id) +{ + CellVideoOutResolution resolution; + cellVideoOutGetResolution(resolution_id, &resolution); + + return resolution.width; +} + +unsigned gfx_ctx_get_resolution_height(unsigned resolution_id) +{ + CellVideoOutResolution resolution; + cellVideoOutGetResolution(resolution_id, &resolution); + + return resolution.height; +} + +void gfx_ctx_get_available_resolutions (void) +{ + bool defaultresolution; + uint32_t resolution_count; + uint16_t num_videomodes; + + if (g_console.check_available_resolutions) + return; + + defaultresolution = true; + + uint32_t videomode[] = { + CELL_VIDEO_OUT_RESOLUTION_480, + CELL_VIDEO_OUT_RESOLUTION_576, + CELL_VIDEO_OUT_RESOLUTION_960x1080, + CELL_VIDEO_OUT_RESOLUTION_720, + CELL_VIDEO_OUT_RESOLUTION_1280x1080, + CELL_VIDEO_OUT_RESOLUTION_1440x1080, + CELL_VIDEO_OUT_RESOLUTION_1600x1080, + CELL_VIDEO_OUT_RESOLUTION_1080 + }; + + num_videomodes = sizeof(videomode) / sizeof(uint32_t); + + resolution_count = 0; + for (unsigned i = 0; i < num_videomodes; i++) + { + if(gfx_ctx_check_resolution(videomode[i])) + resolution_count++; + } + + g_console.supported_resolutions = malloc(resolution_count * sizeof(uint32_t)); + g_console.supported_resolutions_count = 0; + + for (unsigned i = 0; i < num_videomodes; i++) + { + if(gfx_ctx_check_resolution(videomode[i])) + { + g_console.supported_resolutions[g_console.supported_resolutions_count++] = videomode[i]; + g_console.initial_resolution_id = videomode[i]; + + if (g_console.current_resolution_id == videomode[i]) + { + defaultresolution = false; + g_console.current_resolution_index = g_console.supported_resolutions_count-1; + } + } + } + + /* In case we didn't specify a resolution - make the last resolution + that was added to the list (the highest resolution) the default resolution */ + if (g_console.current_resolution_id > num_videomodes || defaultresolution) + g_console.current_resolution_index = g_console.supported_resolutions_count - 1; + + g_console.check_available_resolutions = true; +} + void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { (void)inited; @@ -172,12 +250,9 @@ bool gfx_ctx_init(void) if (g_console.current_resolution_id) { - CellVideoOutResolution resolution; - cellVideoOutGetResolution(g_console.current_resolution_id, &resolution); - params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT; - params.width = resolution.width; - params.height = resolution.height; + params.width = gfx_ctx_get_resolution_width(g_console.current_resolution_id); + params.height = gfx_ctx_get_resolution_height(g_console.current_resolution_id); } gl_device = psglCreateDeviceExtended(¶ms); @@ -240,89 +315,6 @@ void gfx_ctx_set_fbo(bool enable) gl->render_to_tex = enable; } -/*============================================================ - MISC - TODO: Refactor -============================================================ */ - -void gfx_ctx_get_available_resolutions (void) -{ - bool defaultresolution; - uint32_t resolution_count; - uint16_t num_videomodes; - - if (g_console.check_available_resolutions) - return; - - defaultresolution = true; - - uint32_t videomode[] = { - CELL_VIDEO_OUT_RESOLUTION_480, - CELL_VIDEO_OUT_RESOLUTION_576, - CELL_VIDEO_OUT_RESOLUTION_960x1080, - CELL_VIDEO_OUT_RESOLUTION_720, - CELL_VIDEO_OUT_RESOLUTION_1280x1080, - CELL_VIDEO_OUT_RESOLUTION_1440x1080, - CELL_VIDEO_OUT_RESOLUTION_1600x1080, - CELL_VIDEO_OUT_RESOLUTION_1080 - }; - - num_videomodes = sizeof(videomode) / sizeof(uint32_t); - - resolution_count = 0; - for (unsigned i = 0; i < num_videomodes; i++) - { - if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO, 0)) - resolution_count++; - } - - g_console.supported_resolutions = malloc(resolution_count * sizeof(uint32_t)); - g_console.supported_resolutions_count = 0; - - for (unsigned i = 0; i < num_videomodes; i++) - { - if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO, 0)) - { - g_console.supported_resolutions[g_console.supported_resolutions_count++] = videomode[i]; - g_console.initial_resolution_id = videomode[i]; - - if (g_console.current_resolution_id == videomode[i]) - { - defaultresolution = false; - g_console.current_resolution_index = g_console.supported_resolutions_count-1; - } - } - } - - /* In case we didn't specify a resolution - make the last resolution - that was added to the list (the highest resolution) the default resolution */ - if (g_console.current_resolution_id > num_videomodes || defaultresolution) - g_console.current_resolution_index = g_console.supported_resolutions_count - 1; - - g_console.check_available_resolutions = true; -} - -int gfx_ctx_check_resolution(unsigned resolution_id) -{ - return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO, 0); -} - -unsigned gfx_ctx_get_resolution_width(unsigned resolution_id) -{ - CellVideoOutResolution resolution; - cellVideoOutGetResolution(resolution_id, &resolution); - - return resolution.width; -} - -unsigned gfx_ctx_get_resolution_height(unsigned resolution_id) -{ - CellVideoOutResolution resolution; - cellVideoOutGetResolution(resolution_id, &resolution); - - return resolution.height; -} - void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate) { // Calculate projection. diff --git a/gfx/context/xdk_ctx.c b/gfx/context/xdk_ctx.c index fc28810283..31c9a1154b 100644 --- a/gfx/context/xdk_ctx.c +++ b/gfx/context/xdk_ctx.c @@ -83,8 +83,10 @@ void gfx_ctx_swap_buffers(void) void gfx_ctx_clear(void) { xdk_d3d_video_t *device_ptr = (xdk_d3d_video_t*)driver.video_data; +#ifdef _XBOX1 unsigned flicker_filter = g_console.flicker_filter; bool soft_filter_enable = g_console.soft_display_filter_enable; +#endif device_ptr->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0); diff --git a/gfx/gl.c b/gfx/gl.c index 50467d3664..249966e7a6 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -292,7 +292,59 @@ static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) #ifdef HAVE_FBO static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, - unsigned vp_width, unsigned vp_height); + unsigned vp_width, unsigned vp_height) +{ + unsigned last_width = width; + unsigned last_height = height; + unsigned last_max_width = gl->tex_w; + unsigned last_max_height = gl->tex_h; + // Calculate viewports for FBOs. + for (int i = 0; i < gl->fbo_pass; i++) + { + switch (gl->fbo_scale[i].type_x) + { + case RARCH_SCALE_INPUT: + gl->fbo_rect[i].img_width = last_width * gl->fbo_scale[i].scale_x; + gl->fbo_rect[i].max_img_width = last_max_width * gl->fbo_scale[i].scale_x; + break; + + case RARCH_SCALE_ABSOLUTE: + gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x; + break; + + case RARCH_SCALE_VIEWPORT: + gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].scale_x * vp_width; + break; + + default: + break; + } + + switch (gl->fbo_scale[i].type_y) + { + case RARCH_SCALE_INPUT: + gl->fbo_rect[i].img_height = last_height * gl->fbo_scale[i].scale_y; + gl->fbo_rect[i].max_img_height = last_max_height * gl->fbo_scale[i].scale_y; + break; + + case RARCH_SCALE_ABSOLUTE: + gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y; + break; + + case RARCH_SCALE_VIEWPORT: + gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * vp_height; + break; + + default: + break; + } + + last_width = gl->fbo_rect[i].img_width; + last_height = gl->fbo_rect[i].img_height; + last_max_width = gl->fbo_rect[i].max_img_width; + last_max_height = gl->fbo_rect[i].max_img_height; + } +} static void gl_create_fbo_textures(gl_t *gl) { @@ -533,60 +585,6 @@ static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yam } #ifdef HAVE_FBO -static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, - unsigned vp_width, unsigned vp_height) -{ - unsigned last_width = width; - unsigned last_height = height; - unsigned last_max_width = gl->tex_w; - unsigned last_max_height = gl->tex_h; - // Calculate viewports for FBOs. - for (int i = 0; i < gl->fbo_pass; i++) - { - switch (gl->fbo_scale[i].type_x) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[i].img_width = last_width * gl->fbo_scale[i].scale_x; - gl->fbo_rect[i].max_img_width = last_max_width * gl->fbo_scale[i].scale_x; - break; - - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].abs_x; - break; - - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[i].img_width = gl->fbo_rect[i].max_img_width = gl->fbo_scale[i].scale_x * vp_width; - break; - - default: - break; - } - - switch (gl->fbo_scale[i].type_y) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[i].img_height = last_height * gl->fbo_scale[i].scale_y; - gl->fbo_rect[i].max_img_height = last_max_height * gl->fbo_scale[i].scale_y; - break; - - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].abs_y; - break; - - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[i].img_height = gl->fbo_rect[i].max_img_height = gl->fbo_scale[i].scale_y * vp_height; - break; - - default: - break; - } - - last_width = gl->fbo_rect[i].img_width; - last_height = gl->fbo_rect[i].img_height; - last_max_width = gl->fbo_rect[i].max_img_width; - last_max_height = gl->fbo_rect[i].max_img_height; - } -} static inline void gl_start_frame_fbo(gl_t *gl) { @@ -1062,7 +1060,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo RARCH_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height); -#if defined(HAVE_CG_MENU) && defined(RARCH_CONSOLE) +#if defined(HAVE_CG_MENU) RARCH_LOG("Initializing menu shader ...\n"); gl_cg_set_menu_shader(default_paths.menu_shader_file); #endif