(PS3) Small rewrite of ps3_video_psgl.c

This commit is contained in:
TwinAphex51224 2012-01-28 11:38:24 +01:00
parent f3d9588e37
commit 30d229c30b
3 changed files with 702 additions and 689 deletions

View File

@ -173,14 +173,16 @@ struct settings
struct console_settings
{
bool block_config_read;
bool in_game_menu;
bool return_to_multiman_enable;
uint32_t *supported_resolutions;
uint32_t supported_resolutions_count;
bool screenshots_enable;
bool throttle;
bool triple_buffering_enabled;
uint32_t current_resolution_index;
uint32_t current_resolution_id;
uint32_t initial_resolution_id;
bool screenshots_enable;
bool in_game_menu;
uint32_t *supported_resolutions;
uint32_t supported_resolutions_count;
char rom_path[PATH_MAX];
};
#endif

View File

@ -640,8 +640,28 @@ static void set_setting_label(menu * menu_obj, int currentsetting)
case SETTING_HW_OVERSCAN_AMOUNT:
break;
case SETTING_THROTTLE_MODE:
if(g_console.throttle)
{
snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "ON");
menu_obj->items[currentsetting].text_color = GREEN;
}
else
{
snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "OFF");
menu_obj->items[currentsetting].text_color = ORANGE;
}
break;
case SETTING_TRIPLE_BUFFERING:
if(g_console.triple_buffering_enabled)
{
snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "ON");
menu_obj->items[currentsetting].text_color = GREEN;
}
else
{
snprintf(menu_obj->items[currentsetting].setting_text, sizeof(menu_obj->items[currentsetting].setting_text), "OFF");
menu_obj->items[currentsetting].text_color = ORANGE;
}
break;
case SETTING_ENABLE_SCREENSHOTS:
if(g_console.screenshots_enable)
@ -992,6 +1012,12 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue)
case SETTING_HW_OVERSCAN_AMOUNT:
break;
case SETTING_THROTTLE_MODE:
if(g_console.throttle)
ps3_unblock_swap();
else
ps3_block_swap();
g_console.throttle = !g_console.throttle;
set_text_message("", 7);
break;
case SETTING_TRIPLE_BUFFERING:
break;

View File

@ -86,50 +86,46 @@ bool g_quitting;
unsigned g_frame_count;
void *g_gl;
static CellVideoOutState g_video_state;
typedef struct gl
{
GLuint pbo;
PSGLdevice* gl_device;
PSGLcontext* gl_context;
bool vsync;
bool block_swap;
GLuint texture[TEXTURES];
unsigned tex_index; // For use with PREV.
struct gl_tex_info prev_info[TEXTURES];
GLuint tex_filter;
void *empty_buf;
// Render-to-texture, multipass shaders
GLuint fbo[MAX_SHADERS];
GLuint fbo_texture[MAX_SHADERS];
struct gl_fbo_rect fbo_rect[MAX_SHADERS];
struct gl_fbo_scale fbo_scale[MAX_SHADERS];
bool render_to_tex;
int fbo_pass;
bool fbo_inited;
bool should_resize;
bool keep_aspect;
unsigned win_width;
unsigned win_height;
unsigned vp_width, vp_out_width;
unsigned vp_height, vp_out_height;
bool render_to_tex;
bool should_resize;
bool vsync;
int fbo_pass;
unsigned base_size; /* 2 or 4*/
unsigned last_width[TEXTURES];
unsigned last_height[TEXTURES];
unsigned tex_index; /* For use with PREV. */
unsigned tex_w, tex_h;
unsigned vp_width, vp_out_width;
unsigned vp_height, vp_out_height;
unsigned win_width;
unsigned win_height;
GLfloat tex_coords[8];
GLfloat fbo_tex_coords[8];
GLenum texture_type; // XBGR1555 or ARGB
GLenum texture_type; /* XBGR1555 or ARGB*/
GLenum texture_fmt;
unsigned base_size; // 2 or 4
/* Render-to-texture, multipass shaders */
GLuint fbo[MAX_SHADERS];
GLuint fbo_texture[MAX_SHADERS];
GLuint menu_texture_id;
GLuint pbo;
GLuint texture[TEXTURES];
GLuint tex_filter;
CellVideoOutState g_video_state;
PSGLdevice* gl_device;
PSGLcontext* gl_context;
struct gl_fbo_rect fbo_rect[MAX_SHADERS];
struct gl_fbo_scale fbo_scale[MAX_SHADERS];
struct gl_tex_info prev_info[TEXTURES];
struct texture_image menu_texture;
void *empty_buf;
} gl_t;
static struct texture_image menu_texture;
static GLuint menu_texture_id;
static bool gl_shader_init(void)
{
@ -159,21 +155,6 @@ static bool gl_shader_init(void)
return true;
}
static void gl_shader_use(unsigned index)
{
gl_cg_use(index);
}
static void gl_shader_deinit(void)
{
gl_cg_deinit();
}
static void gl_shader_set_proj_matrix(void)
{
gl_cg_set_proj_matrix();
}
static void gl_shader_set_params(unsigned width, unsigned height,
unsigned tex_width, unsigned tex_height,
unsigned out_width, unsigned out_height,
@ -436,7 +417,7 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gl_shader_set_proj_matrix();
gl_cg_set_proj_matrix();
gl->vp_width = width;
gl->vp_height = height;
@ -447,8 +428,6 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f
gl->vp_out_width = width;
gl->vp_out_height = height;
}
//SSNES_LOG("Setting viewport @ %ux%u\n", width, height);
}
static inline void set_lut_texture_coords(const GLfloat *coords)
@ -478,7 +457,7 @@ void gl_frame_menu (void)
return;
gl_shader_use(SSNES_CG_MENU_SHADER_INDEX);
gl_cg_use(SSNES_CG_MENU_SHADER_INDEX);
gl_cg_set_params(gl->win_width, gl->win_height, gl->win_width,
gl->win_height, gl->win_width, gl->win_height, g_frame_count,
@ -487,7 +466,7 @@ void gl_frame_menu (void)
set_viewport(gl, gl->win_width, gl->win_height, false);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, menu_texture_id);
glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id);
glDrawArrays(GL_QUADS, 0, 4);
@ -498,7 +477,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
{
gl_t *gl = data;
gl_shader_use(1);
gl_cg_use(1);
g_frame_count++;
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
@ -567,8 +546,6 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
{
gl->should_resize = false;
//sdlwrap_set_resize(gl->win_width, gl->win_height);
if (!gl->render_to_tex)
set_viewport(gl, gl->win_width, gl->win_height, false);
else
@ -699,7 +676,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
memcpy(fbo_info->coord, gl->fbo_tex_coords, sizeof(gl->fbo_tex_coords));
glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]);
gl_shader_use(i + 1);
gl_cg_use(i + 1);
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]);
glClear(GL_COLOR_BUFFER_BIT);
@ -725,7 +702,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
// Render our FBO texture to back buffer.
glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0);
gl_shader_use(gl->fbo_pass + 1);
gl_cg_use(gl->fbo_pass + 1);
glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]);
@ -786,7 +763,8 @@ static void gl_free(void *data)
gl_t *gl = data;
gl_shader_deinit();
gl_cg_deinit();
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
@ -814,7 +792,10 @@ static void gl_set_nonblock_state(void *data, bool state)
if (gl->vsync)
{
SSNES_LOG("GL VSync => %s\n", state ? "off" : "on");
state ? glDisable(GL_VSYNC_SCE) : glEnable(GL_VSYNC_SCE);
if(state)
glDisable(GL_VSYNC_SCE);
else
glEnable(GL_VSYNC_SCE);
}
}
@ -909,9 +890,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
gl->keep_aspect = video->force_aspect;
// Apparently need to set viewport for passes when we aren't using FBOs.
gl_shader_use(0);
gl_cg_use(0);
set_viewport(gl, gl->win_width, gl->win_height, false);
gl_shader_use(1);
gl_cg_use(1);
set_viewport(gl, gl->win_width, gl->win_height, false);
bool force_smooth;
@ -1070,15 +1051,16 @@ static void get_all_available_resolutions (void)
}
}
/* In case we didn't specify a resolution - make the last resolution*/
/* that was added to the list (the highest resolution) the default resolution*/
/* 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;
}
void ps3_set_resolution (void)
{
cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &g_video_state);
gl_t *gl = g_gl;
cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &gl->g_video_state);
}
void ps3_next_resolution (void)
@ -1092,7 +1074,7 @@ void ps3_next_resolution (void)
void ps3_previous_resolution (void)
{
if(g_console.current_resolution_index > 0)
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];
@ -1151,38 +1133,41 @@ bool ps3_setup_texture(void)
if (!gl)
return false;
glGenTextures(1, &menu_texture_id);
glGenTextures(1, &gl->menu_texture_id);
SSNES_LOG("Loading texture image for menu...\n");
menu_texture.pixels = memalign(128, 2048 * 2048 * 4);
memset(menu_texture.pixels, 0, (2048 * 2048 * 4));
if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &menu_texture))
gl->menu_texture.pixels = memalign(128, 2048 * 2048 * 4);
memset(gl->menu_texture.pixels, 0, (2048 * 2048 * 4));
if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &gl->menu_texture))
{
SSNES_ERR("Failed to load texture image for menu\n");
return false;
}
glBindTexture(GL_TEXTURE_2D, menu_texture_id);
glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB_SCE, menu_texture.width, menu_texture.height, 0,
GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, menu_texture.pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB_SCE, gl->menu_texture.width, gl->menu_texture.height, 0,
GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, gl->menu_texture.pixels);
glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
free(menu_texture.pixels);
free(gl->menu_texture.pixels);
return true;
}
// PS3 needs a working graphics stack before SSNES even starts.
// To deal with this main.c,
// the top level module owns the instance, and is created beforehand.
// When SSNES gets around to init it, it is already allocated.
// When SSNES wants to free it, it is ignored.
/* PS3 needs a working graphics stack before SSNES even starts.
To deal with this main.c, the top level module owns the instance,
and is created beforehand. When SSNES gets around to init it, it
is already allocated.
When SSNES wants to free it, it is ignored. */
void ps3_video_init(void)
{
video_info_t video_info = {0};