diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 6f3b489994..67605a8199 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -256,57 +256,59 @@ void gfx_ctx_set_fbo(bool enable) void gfx_ctx_get_available_resolutions (void) { bool defaultresolution; - uint32_t i, resolution_count; + uint32_t resolution_count; uint16_t num_videomodes; - if(g_console.check_available_resolutions) + 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}; + 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); + num_videomodes = sizeof(videomode) / sizeof(uint32_t); resolution_count = 0; - for (i = 0; i < num_videomodes; i++) - if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO,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 = (uint32_t*)malloc(resolution_count * sizeof(uint32_t)); + } + g_console.supported_resolutions = malloc(resolution_count * sizeof(uint32_t)); g_console.supported_resolutions_count = 0; - for (i = 0; i < num_videomodes; i++) + for (unsigned i = 0; i < num_videomodes; i++) { - if (cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, videomode[i], CELL_VIDEO_OUT_ASPECT_AUTO,0)) + 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]; + 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; - } + 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*/ + 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.current_resolution_index = g_console.supported_resolutions_count - 1; g_console.check_available_resolutions = true; } void ps3_next_resolution (void) { - if(g_console.current_resolution_index+1 < g_console.supported_resolutions_count) + if (g_console.current_resolution_index + 1 < g_console.supported_resolutions_count) { g_console.current_resolution_index++; g_console.current_resolution_id = g_console.supported_resolutions[g_console.current_resolution_index]; @@ -315,7 +317,7 @@ void ps3_next_resolution (void) void ps3_previous_resolution (void) { - if(g_console.current_resolution_index) + if (g_console.current_resolution_index) { g_console.current_resolution_index--; g_console.current_resolution_id = g_console.supported_resolutions[g_console.current_resolution_index]; @@ -324,12 +326,12 @@ void ps3_previous_resolution (void) int ps3_check_resolution(uint32_t resolution_id) { - return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO,0); + return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO, 0); } -const char * ps3_get_resolution_label(uint32_t resolution) +const char *ps3_get_resolution_label(uint32_t resolution) { - switch(resolution) + switch (resolution) { case CELL_VIDEO_OUT_RESOLUTION_480: return "720x480 (480p)"; @@ -352,30 +354,30 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) +void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); - if(allow_rotate) + if (allow_rotate) { switch (gl->rotation) { case 90: - vertex_ptr = vertexes_90; - break; + vertex_ptr = vertexes_90; + break; case 180: - vertex_ptr = vertexes_180; - break; + vertex_ptr = vertexes_180; + break; case 270: - vertex_ptr = vertexes_270; - break; + vertex_ptr = vertexes_270; + break; case 0: default: vertex_ptr = default_vertex_ptr; - break; + break; } - } + } glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); @@ -384,12 +386,12 @@ void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) glLoadIdentity(); } -void gfx_ctx_set_aspect_ratio(void * data, unsigned aspectratio_index) +void gfx_ctx_set_aspect_ratio(void *data, unsigned aspectratio_index) { (void)data; - gl_t * gl = driver.video_data; + gl_t *gl = driver.video_data; - if(g_console.aspect_ratio_index == ASPECT_RATIO_AUTO) + if (g_console.aspect_ratio_index == ASPECT_RATIO_AUTO) rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); g_settings.video.aspect_ratio = aspectratio_lut[g_console.aspect_ratio_index].value; @@ -400,9 +402,10 @@ void gfx_ctx_set_aspect_ratio(void * data, unsigned aspectratio_index) void gfx_ctx_set_overscan(void) { - gl_t * gl = driver.video_data; - if(!gl) + gl_t *gl = driver.video_data; + if (!gl) return; gl->should_resize = true; } + diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index 4666397a61..ef12ee9eeb 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -398,7 +398,7 @@ void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) } #ifdef HAVE_OPENGL -void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) +void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -406,7 +406,7 @@ void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) if (allow_rotate) glRotatef(gl->rotation, 0, 0, 1); - glOrtho(0, 1, 0, 1, -1, 1); + glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->near, ortho->far); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index e4ca7c6a85..ac649782aa 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -227,7 +227,6 @@ extern const GLfloat white_color[]; void gl_render_msg_post(gl_t *gl) { - ortho_t ortho = {0}; //dummy - no overscan on PC #ifdef HAVE_FREETYPE // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); @@ -236,6 +235,8 @@ void gl_render_msg_post(gl_t *gl) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glDisable(GL_BLEND); + + struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; gl_set_projection(gl, &ortho, true); #else (void)gl; diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index 996033e90d..02bed5a389 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -73,7 +73,7 @@ void gfx_ctx_get_available_resolutions(void); #endif #ifdef HAVE_OPENGL -void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate); +void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate); #endif #endif diff --git a/gfx/gl.c b/gfx/gl.c index 3dc440f2d9..9465741731 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -423,14 +423,14 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) //////////// -void gl_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) +void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate) { #ifdef RARCH_CONSOLE - if(g_console.overscan_enable) + if (g_console.overscan_enable) { - ortho->left = -g_console.overscan_amount/2; - ortho->right = 1 + g_console.overscan_amount/2; - ortho->bottom = -g_console.overscan_amount/2; + ortho->left = -g_console.overscan_amount / 2; + ortho->right = 1 + g_console.overscan_amount / 2; + ortho->bottom = -g_console.overscan_amount / 2; } #endif @@ -441,7 +441,7 @@ void gl_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) { unsigned vp_x_temp, vp_y_temp, vp_width_temp, vp_height_temp; - ortho_t ortho; + struct gl_ortho ortho = {0}; vp_x_temp = 0; vp_y_temp = 0; @@ -462,34 +462,36 @@ void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, float delta; #ifdef RARCH_CONSOLE - if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) + if (g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) { delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - vp_x_temp = g_console.viewports.custom_vp.x; - vp_y_temp = g_console.viewports.custom_vp.y; - vp_width_temp = g_console.viewports.custom_vp.width; - vp_height_temp = g_console.viewports.custom_vp.height; + vp_x_temp = g_console.viewports.custom_vp.x; + vp_y_temp = g_console.viewports.custom_vp.y; + vp_width_temp = g_console.viewports.custom_vp.width; + vp_height_temp = g_console.viewports.custom_vp.height; } else #endif - if (fabs(device_aspect - desired_aspect) < 0.0001) { - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - // assume they are actually equal. - } - else if (device_aspect > desired_aspect) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - vp_x_temp = (GLint)(width * (0.5 - delta)); - vp_width_temp = (GLint)(2.0 * width * delta); - width = (unsigned)(2.0 * width * delta); - } - else - { - delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; - vp_y_temp = (GLint)(height * (0.5 - delta)); - vp_height_temp = (GLint)(2.0 * height * delta); - height = (unsigned)(2.0 * height * delta); + if (fabs(device_aspect - desired_aspect) < 0.0001) + { + // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), + // assume they are actually equal. + } + else if (device_aspect > desired_aspect) + { + delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; + vp_x_temp = (GLint)(width * (0.5 - delta)); + vp_width_temp = (GLint)(2.0 * width * delta); + width = (unsigned)(2.0 * width * delta); + } + else + { + delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; + vp_y_temp = (GLint)(height * (0.5 - delta)); + vp_height_temp = (GLint)(2.0 * height * delta); + height = (unsigned)(2.0 * height * delta); + } } } @@ -512,7 +514,7 @@ void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, static void gl_set_rotation(void *data, unsigned rotation) { - ortho_t ortho; + struct gl_ortho ortho = {0}; ortho.left = 0; ortho.right = 1; @@ -521,7 +523,7 @@ static void gl_set_rotation(void *data, unsigned rotation) ortho.near = -1; ortho.far = 1; - gl_t * gl = driver.video_data; + gl_t *gl = (gl_t*)driver.video_data; gl->rotation = 90 * rotation; gl_set_projection(gl, &ortho, true); } @@ -943,7 +945,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gfx_ctx_update_window_title(false); #ifdef RARCH_CONSOLE - if(!gl->block_swap) + if (!gl->block_swap) #endif gfx_ctx_swap_buffers(); @@ -1237,7 +1239,7 @@ static void gl_start(void) video_info.smooth = g_settings.video.smooth; video_info.input_scale = 2; video_info.fullscreen = true; - if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) + if (g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) { video_info.width = g_console.viewports.custom_vp.width; video_info.height = g_console.viewports.custom_vp.height; @@ -1264,9 +1266,9 @@ static void gl_stop(void) static void gl_restart(void) { - gl_t * gl = driver.video_data; + gl_t *gl = driver.video_data; - if(!gl) + if (!gl) return; gl_stop(); diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 47ae3cc630..ad052cd28c 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -107,15 +107,15 @@ struct gl_fbo_scale bool valid; }; -typedef struct +struct gl_ortho { - float left; - float right; - float bottom; - float top; - float near; - float far; -} ortho_t; + GLfloat left; + GLfloat right; + GLfloat bottom; + GLfloat top; + GLfloat near; + GLfloat far; +}; struct gl_tex_info { @@ -222,7 +222,7 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #endif void gl_shader_use(unsigned index); -void gl_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate); +void gl_set_projection(gl_t *gl, struct gl_ortho *ortho, bool allow_rotate); void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate); #endif