Update to PSGL driver

This commit is contained in:
TwinAphex51224 2011-12-01 11:25:08 +01:00
parent 50babe8432
commit eac8d9f191

View File

@ -85,7 +85,6 @@ static const GLfloat white_color[] = {
#ifdef HAVE_FBO #ifdef HAVE_FBO
#define pglGenFramebuffers glGenFramebuffers
static bool load_fbo_proc(void) { return true; } static bool load_fbo_proc(void) { return true; }
#endif #endif
@ -113,12 +112,13 @@ static inline bool load_gl_proc(void) { return true; }
typedef struct gl typedef struct gl
{ {
PSGLdevice* gl_device;
PSGLcontext* gl_context;
bool vsync; bool vsync;
GLuint texture[TEXTURES]; GLuint texture[TEXTURES];
unsigned tex_index; // For use with PREV. unsigned tex_index; // For use with PREV.
struct gl_tex_info prev_info[TEXTURES]; struct gl_tex_info prev_info[TEXTURES];
GLuint tex_filter; GLuint tex_filter;
void *empty_buf; void *empty_buf;
unsigned frame_count; unsigned frame_count;
@ -136,11 +136,8 @@ typedef struct gl
bool should_resize; bool should_resize;
bool quitting; bool quitting;
bool fullscreen;
bool keep_aspect; bool keep_aspect;
unsigned full_x, full_y;
unsigned win_width; unsigned win_width;
unsigned win_height; unsigned win_height;
unsigned vp_width, vp_out_width; unsigned vp_width, vp_out_width;
@ -593,14 +590,14 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f
else if (device_aspect > desired_aspect) else if (device_aspect > desired_aspect)
{ {
float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5;
glViewport(width * (0.5 - delta), 0, 2.0 * width * delta, height); glViewport((GLint)(width * (0.5 - delta)), 0,(GLint)(2.0 * width * delta), height);
width = 2.0 * width * delta; width = (unsigned)(2.0 * width * delta);
} }
else else
{ {
float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5;
glViewport(0, height * (0.5 - delta), width, 2.0 * height * delta); glViewport(0, (GLint)(height * (0.5 - delta)), width,(GLint)(2.0 * height * delta));
height = 2.0 * height * delta; height = (unsigned)(2.0 * height * delta);
} }
} }
else else
@ -909,7 +906,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei
{ {
gl->should_resize = false; gl->should_resize = false;
sdlwrap_set_resize(gl->win_width, gl->win_height); //sdlwrap_set_resize(gl->win_width, gl->win_height);
#ifdef HAVE_FBO #ifdef HAVE_FBO
if (!gl->render_to_tex) if (!gl->render_to_tex)
@ -1116,7 +1113,7 @@ static void gl_free(void *data)
glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo);
} }
#endif #endif
sdlwrap_destroy(); psgl_deinit();
if (gl->empty_buf) if (gl->empty_buf)
free(gl->empty_buf); free(gl->empty_buf);
@ -1212,7 +1209,7 @@ static void psgl_init()
return CELL_OK; return CELL_OK;
} }
static bool psglinit_init_context() static bool psgl_init_device(uint32_t resolution_id)
{ {
PSGLdeviceParameters params; PSGLdeviceParameters params;
PSGLinitOptions options; PSGLinitOptions options;
@ -1235,6 +1232,7 @@ static bool psglinit_init_context()
params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \ params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \
PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \ PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \
PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE;
params.colorFormat = GL_ARGB_SCE; params.colorFormat = GL_ARGB_SCE;
params.depthFormat = GL_NONE; params.depthFormat = GL_NONE;
params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE;
@ -1242,7 +1240,7 @@ static bool psglinit_init_context()
params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE; params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE;
params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE;
#if 0 #if 0
if (pal60Hz) if (pal60Hz)
{ {
params.enable |= PSGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE; params.enable |= PSGL_DEVICE_PARAMETERS_RESC_PAL_TEMPORAL_MODE;
@ -1250,77 +1248,80 @@ static bool psglinit_init_context()
params.enable |= PSGL_DEVICE_PARAMETERS_RESC_RATIO_MODE; params.enable |= PSGL_DEVICE_PARAMETERS_RESC_RATIO_MODE;
params.rescRatioMode = RESC_RATIO_MODE_FULLSCREEN; params.rescRatioMode = RESC_RATIO_MODE_FULLSCREEN;
} }
#endif #endif
#if 0 #if 0
if (resolutionId) if (resolution_id)
{ {
//Resolution setting //Resolution setting
CellVideoOutResolution resolution; CellVideoOutResolution resolution;
cellVideoOutGetResolution(resolutionId, &resolution); cellVideoOutGetResolution(resolution_id, &resolution);
params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT; params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT;
params.width = resolution.width; params.width = resolution.width;
params.height = resolution.height; params.height = resolution.height;
m_currentResolutionId = resolutionId; gl->resolution_id = resolutionId;
} }
#endif #endif
psgl_device = psglCreateDeviceExtended(&params); gl->psgl_device = psglCreateDeviceExtended(&params);
// Get the dimensions of the screen in question, and do stuff with it :) // Get the dimensions of the screen in question, and do stuff with it :)
psglGetDeviceDimensions(psgl_device, &gl_width, &gl_height); psglGetDeviceDimensions(gl->psgl_device, &gl->win_width, &gl->win_height);
// Create a context and bind it to the current display. // Create a context and bind it to the current display.
psgl_context = psglCreateContext(); gl->psgl_context = psglCreateContext();
#if 0 #if 0
if(m_viewport_width == 0) if(m_viewport_width == 0)
m_viewport_width = gl_width; m_viewport_width = gl_width;
if(m_viewport_height == 0) if(m_viewport_height == 0)
m_viewport_height = gl_height; m_viewport_height = gl_height;
#endif #endif
psglMakeCurrent(psgl_context, psgl_device); psglMakeCurrent(gl->psgl_context, gl->psgl_device);
psglResetCurrentContext(); psglResetCurrentContext();
return true; return true;
} }
static void psgl_deinit()
{
glDeleteTextures(1, &tex);
glFinish();
cellDbgFontExit();
psglDestroyContext(psgl_context);
psglDestroyDevice(psgl_device);
#if(CELL_SDK_VERSION > 0x340000)
//FIXME: It will crash here for 1.92 - termination of the PSGL library - works fine for 3.41
psglExit();
#else
//for 1.92
gl_width = 0;
gl_height = 0;
psgl_context = NULL;
psgl_device = NULL;
#endif
}
static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data)
{ {
if (!psgl_init()) if (!psgl_init_device(0))
return NULL; return NULL;
const SDL_VideoInfo *video_info = SDL_GetVideoInfo(); SSNES_LOG("Detecting resolution %ux%u.\n", gl->win_width, gl->win_height);
assert(video_info);
unsigned full_x = video_info->current_w;
unsigned full_y = video_info->current_h;
SSNES_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y);
video->vsync ? glEnable(GL_VSYNC_SCE) : glDisable(GL_VSYNC_SCE); video->vsync ? glEnable(GL_VSYNC_SCE) : glDisable(GL_VSYNC_SCE);
unsigned win_width = video->width;
unsigned win_height = video->height;
if (video->fullscreen && (win_width == 0) && (win_height == 0))
{
win_width = full_x;
win_height = full_y;
}
if (!sdlwrap_set_video_mode(win_width, win_height,
g_settings.video.force_16bit ? 15 : 0, video->fullscreen))
return NULL;
gfx_window_title_reset();
#if defined(HAVE_XML) #if defined(HAVE_XML)
// Win32 GL lib doesn't have some functions needed for XML shaders. // Win32 GL lib doesn't have some functions needed for XML shaders.
// Need to load dynamically :( // Need to load dynamically :(
if (!load_gl_proc()) if (!load_gl_proc())
{ {
sdlwrap_destroy(); psgl_deinit();
return NULL; return NULL;
} }
#endif #endif
@ -1328,24 +1329,18 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
gl_t *gl = calloc(1, sizeof(gl_t)); gl_t *gl = calloc(1, sizeof(gl_t));
if (!gl) if (!gl)
{ {
sdlwrap_destroy(); psgl_deinit();
return NULL; return NULL;
} }
gl->vsync = video->vsync; gl->vsync = video->vsync;
gl->fullscreen = video->fullscreen;
gl->full_x = full_x;
gl->full_y = full_y;
gl->win_width = win_width;
gl->win_height = win_height;
SSNES_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height); SSNES_LOG("GL: Using resolution %ux%u\n", gl->win_width, gl->win_height);
if (!gl_shader_init()) if (!gl_shader_init())
{ {
SSNES_ERR("Shader init failed.\n"); SSNES_ERR("Shader init failed.\n");
sdlwrap_destroy(); psgl_deinit();
free(gl); free(gl);
return NULL; return NULL;
} }
@ -1443,7 +1438,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo
if (!gl_check_error()) if (!gl_check_error())
{ {
sdlwrap_destroy(); psgl_deinit();
free(gl); free(gl);
return NULL; return NULL;
} }
@ -1524,6 +1519,3 @@ const video_driver_t video_gl = {
#endif #endif
.ident = "gl" .ident = "gl"
}; };