From 3649376c03f20622ad3a3fe01e12aad6c388cd57 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Fri, 25 May 2012 21:39:59 +0200 Subject: [PATCH 001/103] Revert "(PS3) Added HAVE_LIBDBGFONTS define for PS3 port" This reverts commit 06bb45a856040b6ea63fd8786876be6c05a7b9c3. --- Makefile.ps3 | 2 +- ps3/ps3_video_psgl.c | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Makefile.ps3 b/Makefile.ps3 index 7e7cf3001c..051f86e412 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -68,7 +68,7 @@ endif PPU_LDLIBS = -ldbgfont $(GL_LIBS) -lretro -lcgc -lgcm_cmd -lgcm_sys_stub -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysutil_np_stub -lpngdec_stub -ljpgdec_stub -lsysmodule_stub -laudio_stub -lnet_stub -lnetctl_stub -lpthread -DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_LIBDBGFONTS -DHAVE_CG -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) +DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_CG -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) PPU_OPTIMIZE_LV := -O0 -g diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 50e8c1209c..a911d2fb8a 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -656,7 +656,7 @@ static void ps3graphics_set_orientation(void * data, uint32_t orientation) glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); } -#ifdef HAVE_LIBDBGFONTS +#ifdef HAVE_LIBDBGFONT static void gl_render_msg(gl_t *gl, const char *msg) { cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); @@ -877,9 +877,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei static void psgl_deinit(gl_t *gl) { -#ifdef HAVE_LIBDBGFONTS cellDbgFontExit(); -#endif psglDestroyContext(gl->gl_context); psglDestroyDevice(gl->gl_device); @@ -981,7 +979,6 @@ static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resol return true; } -#ifdef HAVE_LIBDBGFONTS static void psgl_init_dbgfont(gl_t *gl) { CellDbgFontConfig cfg; @@ -991,7 +988,6 @@ static void psgl_init_dbgfont(gl_t *gl) cfg.screenHeight = gl->win_height; cellDbgFontInit(&cfg); } -#endif static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { @@ -1014,10 +1010,8 @@ 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); -#ifdef HAVE_LIBDBGFONTS RARCH_LOG("GL: Initializing debug fonts...\n"); psgl_init_dbgfont(gl); -#endif RARCH_LOG("Initializing menu shader...\n"); gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); From 417cb55a6eb51d9d0f5c6da4d658a19b1bda111a Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Fri, 25 May 2012 21:40:19 +0200 Subject: [PATCH 002/103] Revert "(PS3) ps3_video_psgl.c cleanups #2" This reverts commit 8aafbf63b835f8a5031edab5f87f3d6881197fb4. --- gfx/gl.c | 10 +- ps3/ps3_video_psgl.c | 412 ++++++++++++++----------------------------- ps3/ps3_video_psgl.h | 2 - 3 files changed, 138 insertions(+), 286 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 8a87e22e1c..291da234a9 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -248,7 +248,7 @@ static bool gl_shader_init(void) return true; } -static inline void gl_shader_use(unsigned index) +static void gl_shader_use(unsigned index) { #ifdef HAVE_CG gl_cg_use(index); @@ -281,7 +281,7 @@ static void gl_shader_set_proj_matrix(void) #endif } -static inline void gl_shader_set_params(unsigned width, unsigned height, +static void gl_shader_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, unsigned out_width, unsigned out_height, unsigned frame_count, @@ -1101,7 +1101,7 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi } } -static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) +static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size); glTexSubImage2D(GL_TEXTURE_2D, @@ -1109,7 +1109,7 @@ static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, un gl->texture_fmt, frame); } -static inline void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) +static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) { memmove(gl->prev_info + 1, gl->prev_info, sizeof(*tex_info) * (TEXTURES - 1)); memcpy(&gl->prev_info[0], tex_info, sizeof(*tex_info)); @@ -1130,7 +1130,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (gl->fbo_inited) { // Recompute FBO geometry. - // When width/height changes or window sizes change, we have to recalculate geometry of our FBO. + // When width/height changes or window sizes change, we have to recalcuate geometry of our FBO. gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); gl_start_frame_fbo(gl); } diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index a911d2fb8a..ca6ae0dcfc 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -139,44 +139,18 @@ void *g_gl; GL IMPLEMENTATION ============================================================ */ -////////////////// Shaders static bool gl_shader_init(void) { switch (g_settings.video.shader_type) { case RARCH_SHADER_AUTO: - { - if (*g_settings.video.cg_shader_path && *g_settings.video.bsnes_shader_path) + if (strlen(g_settings.video.cg_shader_path) > 0 && strlen(g_settings.video.bsnes_shader_path) > 0) RARCH_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n"); - -#ifdef HAVE_CG - if (*g_settings.video.cg_shader_path) - return gl_cg_init(g_settings.video.cg_shader_path); -#endif - -#ifdef HAVE_XML - if (*g_settings.video.bsnes_shader_path) - return gl_glsl_init(g_settings.video.bsnes_shader_path); -#endif - break; - } - -#ifdef HAVE_CG + // fall-through case RARCH_SHADER_CG: - { - return gl_cg_init(g_settings.video.cg_shader_path); - break; - } -#endif - -#ifdef HAVE_XML - case RARCH_SHADER_BSNES: - { - return gl_glsl_init(g_settings.video.bsnes_shader_path); - break; - } -#endif - + if (strlen(g_settings.video.cg_shader_path) > 0) + return gl_cg_init(g_settings.video.cg_shader_path); + break; default: break; } @@ -184,81 +158,22 @@ static bool gl_shader_init(void) return true; } -static inline void gl_shader_use(unsigned index) -{ -#ifdef HAVE_CG - gl_cg_use(index); -#endif - -#ifdef HAVE_XML - gl_glsl_use(index); -#endif -} - -static void gl_shader_deinit(void) -{ -#ifdef HAVE_CG - gl_cg_deinit(); -#endif - -#ifdef HAVE_XML - gl_glsl_deinit(); -#endif -} - -static inline void gl_shader_set_params(unsigned width, unsigned height, - unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height, - unsigned frame_count, - const struct gl_tex_info *info, - const struct gl_tex_info *prev_info, - const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt) -{ -#ifdef HAVE_CG - gl_cg_set_params(width, height, - tex_width, tex_height, - out_width, out_height, - frame_count, info, prev_info, fbo_info, fbo_info_cnt); -#endif - -#ifdef HAVE_XML - gl_glsl_set_params(width, height, - tex_width, tex_height, - out_width, out_height, - frame_count, info, prev_info, fbo_info, fbo_info_cnt); -#endif -} - static unsigned gl_shader_num(void) { -#ifdef HAVE_CG + unsigned num = 0; unsigned cg_num = gl_cg_num(); - if (cg_num) - return cg_num; -#endif -#ifdef HAVE_XML - unsigned glsl_num = gl_glsl_num(); - if (glsl_num) - return glsl_num; -#endif + if (cg_num > num) + num = cg_num; - return 0; + return num; } static bool gl_shader_filter_type(unsigned index, bool *smooth) { bool valid = false; - -#ifdef HAVE_CG if (!valid) valid = gl_cg_filter_type(index, smooth); -#endif - -#ifdef HAVE_XML - if (!valid) - valid = gl_glsl_filter_type(index, smooth); -#endif return valid; } @@ -267,26 +182,15 @@ void gl_set_fbo_enable (bool enable) { gl_t *gl = g_gl; - gl->fbo_inited = enable; - gl->render_to_tex = enable; + gl->fbo_enabled = enable; } -#ifdef HAVE_FBO static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) { scale->valid = false; - -#ifdef HAVE_CG if (!scale->valid) gl_cg_shader_scale(index, scale); -#endif - -#ifdef HAVE_XML - if (!scale->valid) - gl_glsl_shader_scale(index, scale); -#endif } -#endif static void gl_create_fbo_textures(gl_t *gl) { @@ -317,16 +221,11 @@ static void gl_create_fbo_textures(gl_t *gl) void gl_deinit_fbo(gl_t *gl) { - if (gl->fbo_inited) - { - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); - memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); - memset(gl->fbo, 0, sizeof(gl->fbo)); - gl->fbo_inited = false; - gl->render_to_tex = false; - gl->fbo_pass = 0; - } + glDeleteTextures(gl->fbo_pass, gl->fbo_texture); + glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); + memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); + memset(gl->fbo, 0, sizeof(gl->fbo)); + gl->fbo_pass = 0; } // Horribly long and complex FBO init :D @@ -448,7 +347,6 @@ void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) } glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); - gl->fbo_inited = true; return; error: @@ -618,9 +516,9 @@ void gl_frame_menu (void) if(!gl) return; - gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); + gl_cg_use(RARCH_CG_MENU_SHADER_INDEX); - gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, + 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, NULL, NULL, NULL, 0); @@ -656,120 +554,28 @@ static void ps3graphics_set_orientation(void * data, uint32_t orientation) glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); } -#ifdef HAVE_LIBDBGFONT -static void gl_render_msg(gl_t *gl, const char *msg) +static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { - cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); - cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); - cellDbgFontDraw(); -} -#else -static void gl_render_msg(gl_t *gl, const char *msg) -{ - (void)gl; - (void)msg; -} -#endif + gl_t *gl = data; + + gl_cg_use(1); + g_frame_count++; -static void gl_start_frame_fbo(gl_t *gl) -{ glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); - gl->render_to_tex = true; - //set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false); - set_viewport_force_full(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height); - // Need to preserve the "flipped" state when in FBO as well to have - // consistent texture coordinates. - // We will "flip" it in place on last pass. - if (gl->render_to_tex) - glVertexPointer(2, GL_FLOAT, 0, vertexes); -} - -static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info) -{ - GLfloat fbo_tex_coords[8] = {0.0f}; - - // Render the rest of our passes. - glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords); - - // It's kinda handy ... :) - const struct gl_fbo_rect *prev_rect; - const struct gl_fbo_rect *rect; - struct gl_tex_info *fbo_info; - - struct gl_tex_info fbo_tex_info[MAX_SHADERS]; - unsigned fbo_tex_info_cnt = 0; - - // Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO. - for (int i = 1; i < gl->fbo_pass; i++) + // Render to texture in first pass. + if (gl->fbo_enabled) { - prev_rect = &gl->fbo_rect[i - 1]; - rect = &gl->fbo_rect[i]; - fbo_info = &fbo_tex_info[i - 1]; - - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - - set_texture_coords(fbo_tex_coords, xamt, yamt); - - fbo_info->tex = gl->fbo_texture[i - 1]; - fbo_info->input_size[0] = prev_rect->img_width; - fbo_info->input_size[1] = prev_rect->img_height; - fbo_info->tex_size[0] = prev_rect->width; - fbo_info->tex_size[1] = prev_rect->height; - memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); - - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); - gl_shader_use(i + 1); - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); - - glClear(GL_COLOR_BUFFER_BIT); - - // Render to FBO with certain size. - set_viewport_force_full(gl, rect->img_width, rect->img_height); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, g_frame_count, - tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glDrawArrays(GL_QUADS, 0, 4); - - fbo_tex_info_cnt++; + gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[0]); + set_viewport_force_full(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height); } - // Render our last FBO texture directly to screen. - prev_rect = &gl->fbo_rect[gl->fbo_pass - 1]; - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - set_texture_coords(fbo_tex_coords, xamt, yamt); - - // Render our FBO texture to back buffer. - glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); - gl_shader_use(gl->fbo_pass + 1); - - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); - - glClear(GL_COLOR_BUFFER_BIT); - gl->render_to_tex = false; - set_viewport(gl, gl->win_width, gl->win_height); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, g_frame_count, - tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); - - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); -} - -static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsigned pitch) -{ - // Res change. Need to clear out texture. if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index])) { + //Resolution change, need to clear out texture. gl->last_width[gl->tex_index] = width; gl->last_height[gl->tex_index] = height; @@ -783,18 +589,19 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi set_texture_coords(gl->tex_coords, xamt, yamt); } - // We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly. - else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || - height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) + else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) { + // We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly. GLfloat xamt = (GLfloat)width / gl->tex_w; GLfloat yamt = (GLfloat)height / gl->tex_h; set_texture_coords(gl->tex_coords, xamt, yamt); } -} -static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) -{ + // Need to preserve the "flipped" state when in FBO as well to have + // consistent texture coordinates. + if (gl->fbo_enabled) + glVertexPointer(2, GL_FLOAT, 0, vertexes); + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; size_t buffer_stride = gl->tex_w * gl->base_size; const uint8_t *frame_copy = frame; @@ -809,65 +616,110 @@ static inline void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, un frame_copy += pitch; buffer_addr += buffer_stride; } -} -static inline void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) -{ - memmove(gl->prev_info + 1, gl->prev_info, sizeof(*tex_info) * (TEXTURES - 1)); - memcpy(&gl->prev_info[0], tex_info, sizeof(*tex_info)); - gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; -} - -static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) -{ - gl_t *gl = data; - - gl_shader_use(1); - g_frame_count++; - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - -#ifdef HAVE_FBO - // Render to texture in first pass. - if (gl->fbo_inited) - { - // Recompute FBO geometry. - // When width/height changes or window sizes change, we have to recalculate geometry of our FBO. - gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); - gl_start_frame_fbo(gl); - } -#endif - - gl_update_input_size(gl, width, height, pitch); - - gl_copy_frame(gl, frame, width, height, pitch); - - struct gl_tex_info tex_info = {0}; - tex_info.tex = gl->texture[gl->tex_index]; - tex_info.input_size[0] = width; - tex_info.input_size[1] = height; - tex_info.tex_size[0] = gl->tex_w; - tex_info.tex_size[1] = gl->tex_h; + struct gl_tex_info tex_info = { + .tex = gl->texture[gl->tex_index], + .input_size = {width, height}, + .tex_size = {gl->tex_w, gl->tex_h} + }; + struct gl_tex_info fbo_tex_info[MAX_SHADERS]; + unsigned fbo_tex_info_cnt = 0; memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); glClear(GL_COLOR_BUFFER_BIT); - gl_shader_set_params(width, height, + gl_cg_set_params(width, height, gl->tex_w, gl->tex_h, gl->vp_width, gl->vp_height, - g_frame_count, &tex_info, gl->prev_info, NULL, 0); + g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); glDrawArrays(GL_QUADS, 0, 4); -#ifdef HAVE_FBO - if (gl->fbo_inited) - gl_frame_fbo(gl, &tex_info); -#endif + if (gl->fbo_enabled) + { + GLfloat fbo_tex_coords[8] = {0.0f}; - gl_next_texture_index(gl, &tex_info); + // Render the rest of our passes. + glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords); + + // It's kinda handy ... :) + const struct gl_fbo_rect *prev_rect; + const struct gl_fbo_rect *rect; + struct gl_tex_info *fbo_info; + + // Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO. + for (int i = 1; i < gl->fbo_pass; i++) + { + prev_rect = &gl->fbo_rect[i - 1]; + rect = &gl->fbo_rect[i]; + fbo_info = &fbo_tex_info[i - 1]; + + GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; + GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; + + set_texture_coords(fbo_tex_coords, xamt, yamt); + + fbo_info->tex = gl->fbo_texture[i - 1]; + fbo_info->input_size[0] = prev_rect->img_width; + fbo_info->input_size[1] = prev_rect->img_height; + fbo_info->tex_size[0] = prev_rect->width; + fbo_info->tex_size[1] = prev_rect->height; + memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); + + glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); + gl_cg_use(i + 1); + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); + + glClear(GL_COLOR_BUFFER_BIT); + + // Render to FBO with certain size. + set_viewport_force_full(gl, rect->img_width, rect->img_height); + gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, + prev_rect->width, prev_rect->height, + gl->vp_width, gl->vp_height, g_frame_count, + &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); + + glDrawArrays(GL_QUADS, 0, 4); + + fbo_tex_info_cnt++; + } + + // Render our last FBO texture directly to screen. + prev_rect = &gl->fbo_rect[gl->fbo_pass - 1]; + GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; + GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; + + set_texture_coords(fbo_tex_coords, xamt, yamt); + + // Render our FBO texture to back buffer. + glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + gl_cg_use(gl->fbo_pass + 1); + + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); + + glClear(GL_COLOR_BUFFER_BIT); + set_viewport(gl, gl->win_width, gl->win_height); + gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, + prev_rect->width, prev_rect->height, + gl->vp_width, gl->vp_height, g_frame_count, + &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); + + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); + glDrawArrays(GL_QUADS, 0, 4); + + glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); + } + + memmove(gl->prev_info + 1, gl->prev_info, sizeof(tex_info) * (TEXTURES - 1)); + memcpy(&gl->prev_info[0], &tex_info, sizeof(tex_info)); + gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; if (msg) - gl_render_msg(gl, msg); + { + cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); + cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); + cellDbgFontDraw(); + } if(!gl->block_swap) psglSwap(); @@ -892,7 +744,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); @@ -1034,9 +887,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); - gl_shader_use(1); + gl_cg_use(1); set_viewport(gl, gl->win_width, gl->win_height); bool force_smooth = false; @@ -1351,7 +1204,7 @@ void ps3_set_filtering(unsigned index, bool set_smooth) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); } } - else if (index >= 2 && gl->fbo_inited) + else if (index >= 2 && gl->fbo_enabled) { glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); @@ -1386,6 +1239,7 @@ void ps3graphics_video_init(bool get_all_resolutions) video_info.smooth = g_settings.video.smooth; video_info.input_scale = 2; g_gl = gl_init(&video_info, NULL, NULL); + gl_set_fbo_enable(g_console.fbo_enabled); gl_t * gl = g_gl; diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 29d87f2b06..8dc65f9d33 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -72,9 +72,7 @@ typedef struct gl 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; #endif GLuint menu_texture_id; GLuint pbo; From b2c7b766aee85a5da26a2ad76a11eb1e59d05a8a Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Fri, 25 May 2012 21:40:28 +0200 Subject: [PATCH 003/103] Revert "(PS3) ps3_video_psgl.c cleanups" This reverts commit 824d2923a537e43ecfea3adac297b544001dc0d3. --- gfx/gl.c | 2 -- ps3/ps3_video_psgl.c | 43 +++++-------------------------------------- ps3/ps3_video_psgl.h | 31 +++++++++++++++---------------- 3 files changed, 20 insertions(+), 56 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 291da234a9..effc59bc74 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -81,9 +81,7 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; -#ifdef _WIN32 #define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) } -#endif #ifdef HAVE_FBO #ifdef _WIN32 diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index ca6ae0dcfc..91f66be0fa 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -17,6 +17,7 @@ #include "../driver.h" +#include "ps3_video_psgl.h" #include #include "../libretro.h" @@ -99,38 +100,6 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; -#ifdef HAVE_FBO -#if defined(HAVE_OPENGLES) -#define pglGenFramebuffers glGenFramebuffersOES -#define pglBindFramebuffer glBindFramebufferOES -#define pglFramebufferTexture2D glFramebufferTexture2DOES -#define pglCheckFramebufferStatus glCheckFramebufferStatusOES -#define pglDeleteFramebuffers glDeleteFramebuffersOES -#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES -#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT -#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES -static bool load_fbo_proc(void) { return true; } -#else -#define pglGenFramebuffers glGenFramebuffers -#define pglBindFramebuffer glBindFramebuffer -#define pglFramebufferTexture2D glFramebufferTexture2D -#define pglCheckFramebufferStatus glCheckFramebufferStatus -#define pglDeleteFramebuffers glDeleteFramebuffers -static bool load_fbo_proc(void) { return true; } -#endif -#endif - -#define MAX_SHADERS 16 - -#if defined(HAVE_XML) || defined(HAVE_CG) -#define TEXTURES 8 -#else -#define TEXTURES 1 -#endif -#define TEXTURES_MASK (TEXTURES - 1) - -#include "ps3_video_psgl.h" - bool g_quitting; unsigned g_frame_count; void *g_gl; @@ -637,10 +606,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (gl->fbo_enabled) { - GLfloat fbo_tex_coords[8] = {0.0f}; - // Render the rest of our passes. - glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords); + glTexCoordPointer(2, GL_FLOAT, 0, gl->fbo_tex_coords); // It's kinda handy ... :) const struct gl_fbo_rect *prev_rect; @@ -657,14 +624,14 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - set_texture_coords(fbo_tex_coords, xamt, yamt); + set_texture_coords(gl->fbo_tex_coords, xamt, yamt); fbo_info->tex = gl->fbo_texture[i - 1]; fbo_info->input_size[0] = prev_rect->img_width; fbo_info->input_size[1] = prev_rect->img_height; fbo_info->tex_size[0] = prev_rect->width; fbo_info->tex_size[1] = prev_rect->height; - memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); + memcpy(fbo_info->coord, gl->fbo_tex_coords, sizeof(gl->fbo_tex_coords)); glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); gl_cg_use(i + 1); @@ -689,7 +656,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - set_texture_coords(fbo_tex_coords, xamt, yamt); + set_texture_coords(gl->fbo_tex_coords, xamt, yamt); // Render our FBO texture to back buffer. glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 8dc65f9d33..c7c24d4883 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -27,6 +27,10 @@ #define FBO_INIT 1 #define FBO_REINIT 2 +#define MAX_SHADERS 16 + +#define TEXTURES 8 +#define TEXTURES_MASK (TEXTURES - 1) #define MIN_SCALING_FACTOR (1.0f) #define MAX_SCALING_FACTOR (4.0f) @@ -40,20 +44,16 @@ typedef struct gl { - bool vsync; - GLuint texture[TEXTURES]; - unsigned tex_index; /* For use with PREV. */ - struct gl_tex_info prev_info[TEXTURES]; - GLuint tex_filter; - - void *empty_buf; - bool block_swap; bool fbo_enabled; bool keep_aspect; + bool vsync; bool overscan_enable; + 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; @@ -61,25 +61,24 @@ typedef struct gl unsigned win_height; GLfloat overscan_amount; GLfloat tex_coords[8]; - + GLfloat fbo_tex_coords[8]; GLenum texture_type; /* XBGR1555 or ARGB*/ GLenum texture_fmt; - unsigned base_size; /* 2 or 4*/ - -#ifdef HAVE_FBO /* 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]; - int fbo_pass; -#endif 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; bool ps3_setup_texture(void); From 1e73ba466141265a55a9c7e46b05c78e65e468ce Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 25 May 2012 22:11:44 +0200 Subject: [PATCH 004/103] Move SDL input driver init to sdlwrap. --- gfx/gl.c | 10 +--------- gfx/sdlwrap.c | 12 ++++++++++++ gfx/sdlwrap.h | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index effc59bc74..f78c50d633 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1381,15 +1381,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); } - // Hook up SDL input driver to get SDL_QUIT events and RESIZE. - sdl_input_t *sdl_input = (sdl_input_t*)input_sdl.init(); - if (sdl_input) - { - *input = &input_sdl; - *input_data = sdl_input; - } - else - *input = NULL; + sdlwrap_input_driver(input, input_data); gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); diff --git a/gfx/sdlwrap.c b/gfx/sdlwrap.c index 7c62c10416..81aed5afe3 100644 --- a/gfx/sdlwrap.c +++ b/gfx/sdlwrap.c @@ -359,3 +359,15 @@ bool sdlwrap_window_has_focus(void) #endif } +void sdlwrap_input_driver(const input_driver_t **input, void **input_data) +{ + void *sdl_input = input_sdl.init(); + if (sdl_input) + { + *input = &input_sdl; + *input_data = sdl_input; + } + else + *input = NULL; +} + diff --git a/gfx/sdlwrap.h b/gfx/sdlwrap.h index f1c3c915e5..a0c9fec116 100644 --- a/gfx/sdlwrap.h +++ b/gfx/sdlwrap.h @@ -23,6 +23,7 @@ #include "../boolean.h" +#include "../driver.h" #include "SDL.h" #include "SDL_version.h" #include "SDL_syswm.h" @@ -64,5 +65,7 @@ bool sdlwrap_get_wm_info(SDL_SysWMinfo *info); bool sdlwrap_window_has_focus(void); +void sdlwrap_input_driver(const input_driver_t **input, void **input_data); + #endif From a2e78055246d9e9111c5a69ef96324c3e883d671 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 25 May 2012 22:28:20 +0200 Subject: [PATCH 005/103] Move more SDL specifics to sdlwrap. --- gfx/gl.c | 19 ++++--------------- gfx/sdlwrap.c | 42 ++++++++++++++++++++++++++++++++---------- gfx/sdlwrap.h | 2 +- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index f78c50d633..2874eef569 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1175,10 +1175,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (msg) gl_render_msg(gl, msg); - char buf[128]; - if (gfx_window_title(buf, sizeof(buf))) - sdlwrap_wm_set_caption(buf); - + sdlwrap_update_window_title(false); sdlwrap_swap_buffers(); return true; @@ -1226,10 +1223,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!sdlwrap_init()) return NULL; - const SDL_VideoInfo *video_info = SDL_GetVideoInfo(); - rarch_assert(video_info); - unsigned full_x = video_info->current_w; - unsigned full_y = video_info->current_h; + unsigned full_x = 0, full_y = 0; + sdlwrap_get_video_size(&full_x, &full_y); RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y); sdlwrap_set_swap_interval(video->vsync ? 1 : 0, false); @@ -1246,13 +1241,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo g_settings.video.force_16bit ? 15 : 0, video->fullscreen)) return NULL; - gfx_window_title_reset(); - char buf[128]; - if (gfx_window_title(buf, sizeof(buf))) - sdlwrap_wm_set_caption(buf); + sdlwrap_update_window_title(true); - // Remove that ugly mouse :D - SDL_ShowCursor(SDL_DISABLE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); #if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) @@ -1382,7 +1372,6 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo } sdlwrap_input_driver(input, input_data); - gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); if (!gl_check_error()) diff --git a/gfx/sdlwrap.c b/gfx/sdlwrap.c index 81aed5afe3..2fd95f6f91 100644 --- a/gfx/sdlwrap.c +++ b/gfx/sdlwrap.c @@ -15,6 +15,7 @@ #include "sdlwrap.h" #include "SDL_syswm.h" +#include "gfx_common.h" #include "../general.h" #ifdef __APPLE__ @@ -67,13 +68,40 @@ void sdlwrap_set_swap_interval(unsigned interval, bool inited) else RARCH_WARN("Could not find GLX VSync call.\n"); #endif - } #endif + if (!success) RARCH_WARN("Failed to set swap interval.\n"); } +static void sdlwrap_wm_set_caption(const char *str) +{ +#if SDL_MODERN + SDL_SetWindowTitle(g_window, str); +#else + SDL_WM_SetCaption(str, NULL); +#endif +} + +void sdlwrap_update_window_title(bool reset) +{ + if (reset) + gfx_window_title_reset(); + + char buf[128]; + if (gfx_window_title(buf, sizeof(buf))) + sdlwrap_wm_set_caption(buf); +} + +void sdlwrap_get_video_size(unsigned *width, unsigned *height) +{ + const SDL_VideoInfo *video_info = SDL_GetVideoInfo(); + rarch_assert(video_info); + *width = video_info->current_w; + *height = video_info->current_h; +} + bool sdlwrap_init(void) { #if SDL_MODERN @@ -178,6 +206,9 @@ bool sdlwrap_set_video_mode( if (attr <= 0) RARCH_WARN("GL double buffer has not been enabled.\n"); + // Remove that ugly mouse :D + SDL_ShowCursor(SDL_DISABLE); + return true; } @@ -198,15 +229,6 @@ void sdlwrap_set_resize(unsigned width, unsigned height) #endif } -void sdlwrap_wm_set_caption(const char *str) -{ -#if SDL_MODERN - SDL_SetWindowTitle(g_window, str); -#else - SDL_WM_SetCaption(str, NULL); -#endif -} - void sdlwrap_swap_buffers(void) { #if SDL_MODERN diff --git a/gfx/sdlwrap.h b/gfx/sdlwrap.h index a0c9fec116..61196c2eb2 100644 --- a/gfx/sdlwrap.h +++ b/gfx/sdlwrap.h @@ -50,7 +50,7 @@ bool sdlwrap_set_video_mode( bool sdlwrap_init(void); void sdlwrap_destroy(void); -void sdlwrap_wm_set_caption(const char *str); +void sdlwrap_update_window_title(bool reset); void sdlwrap_swap_buffers(void); From 4fdfe6a93575c3dd97ea3f695a9aa439bc8eb77e Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 25 May 2012 22:30:40 +0200 Subject: [PATCH 006/103] Fix header. --- gfx/sdlwrap.h | 1 + 1 file changed, 1 insertion(+) diff --git a/gfx/sdlwrap.h b/gfx/sdlwrap.h index 61196c2eb2..591f487561 100644 --- a/gfx/sdlwrap.h +++ b/gfx/sdlwrap.h @@ -50,6 +50,7 @@ bool sdlwrap_set_video_mode( bool sdlwrap_init(void); void sdlwrap_destroy(void); +void sdlwrap_get_video_size(unsigned *width, unsigned *height); void sdlwrap_update_window_title(bool reset); void sdlwrap_swap_buffers(void); From c3cb3ba876dceec19f65eed831c21738f4bcad69 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Fri, 25 May 2012 23:18:38 +0200 Subject: [PATCH 007/103] Add some HAVE_SDL ifdefs to gl.c --- gfx/gl.c | 4 ++++ gfx/sdlwrap.h | 3 +++ 2 files changed, 7 insertions(+) diff --git a/gfx/gl.c b/gfx/gl.c index 2874eef569..004086af01 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -32,10 +32,12 @@ #include "sdlwrap.h" #include "../compat/strl.h" +#ifdef HAVE_SDL #define NO_SDL_GLEXT #include "SDL.h" #include "SDL_opengl.h" #include "../input/rarch_sdl_input.h" +#endif #ifdef HAVE_CG #include "shader_cg.h" @@ -81,7 +83,9 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; +#ifdef HAVE_SDL #define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) } +#endif #ifdef HAVE_FBO #ifdef _WIN32 diff --git a/gfx/sdlwrap.h b/gfx/sdlwrap.h index 591f487561..c23f399c04 100644 --- a/gfx/sdlwrap.h +++ b/gfx/sdlwrap.h @@ -24,6 +24,8 @@ #include "../boolean.h" #include "../driver.h" + +#ifdef HAVE_SDL #include "SDL.h" #include "SDL_version.h" #include "SDL_syswm.h" @@ -40,6 +42,7 @@ void *sym__ = SDL_GL_GetProcAddress(symbol); \ memcpy(&(sym), &sym__, sizeof(void*)); \ } +#endif void sdlwrap_set_swap_interval(unsigned interval, bool inited); From f29338580badd49aee45d164d4566e5b2a73b8d2 Mon Sep 17 00:00:00 2001 From: Themaister Date: Fri, 25 May 2012 23:31:24 +0200 Subject: [PATCH 008/103] Add missing config.h. --- gfx/sdlwrap.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gfx/sdlwrap.h b/gfx/sdlwrap.h index c23f399c04..c0fe3ecfae 100644 --- a/gfx/sdlwrap.h +++ b/gfx/sdlwrap.h @@ -22,9 +22,12 @@ #define __SDLWRAP_H #include "../boolean.h" - #include "../driver.h" +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + #ifdef HAVE_SDL #include "SDL.h" #include "SDL_version.h" From 1386e2ee901c249ed3c9cac32e8e7f9bb7d30893 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 04:47:24 +0200 Subject: [PATCH 009/103] Restructuring of sdlwrap.c for portability reasons - could need a code review --- Makefile | 2 +- Makefile.win | 2 +- gfx/{sdlwrap.c => context/sdl_ctx.c} | 53 +++++++++++-------- gfx/ext_gfx.c | 1 - gfx/gfx_context.h | 62 ++++++++++++++++++++++ gfx/gl.c | 36 ++++++------- gfx/sdlwrap.h | 78 ---------------------------- gfx/shader_glsl.c | 3 +- input/dinput.c | 4 +- input/sdl_input.c | 4 +- 10 files changed, 118 insertions(+), 127 deletions(-) rename gfx/{sdlwrap.c => context/sdl_ctx.c} (89%) create mode 100644 gfx/gfx_context.h delete mode 100644 gfx/sdlwrap.h diff --git a/Makefile b/Makefile index 4ca552f44b..67697bfd83 100644 --- a/Makefile +++ b/Makefile @@ -100,7 +100,7 @@ ifeq ($(HAVE_COREAUDIO), 1) endif ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl_gfx.o gfx/sdlwrap.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o + OBJ += gfx/sdl_gfx.o gfx/context/sdl_ctx.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o DEFINES += $(SDL_CFLAGS) $(BSD_LOCAL_INC) LIBS += $(SDL_LIBS) diff --git a/Makefile.win b/Makefile.win index 100fd79c7e..df7ca46281 100644 --- a/Makefile.win +++ b/Makefile.win @@ -39,7 +39,7 @@ ifeq ($(TDM_GCC),) endif ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/sdlwrap.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o + OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/context/sdl_ctx.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o LIBS += -lSDL DEFINES += -ISDL -DHAVE_SDL endif diff --git a/gfx/sdlwrap.c b/gfx/context/sdl_ctx.c similarity index 89% rename from gfx/sdlwrap.c rename to gfx/context/sdl_ctx.c index 2fd95f6f91..b659fa0590 100644 --- a/gfx/sdlwrap.c +++ b/gfx/context/sdl_ctx.c @@ -13,16 +13,23 @@ * If not, see . */ -#include "sdlwrap.h" -#include "SDL_syswm.h" -#include "gfx_common.h" -#include "../general.h" +// Compatibility wrapper between SDL 1.2/1.3 for OpenGL. +// Wraps functions which differ in 1.2 and 1.3. + +#include "SDL.h" +#include "SDL_version.h" + +#include "../gfx_context.h" +#include "../gfx_common.h" +#include "../../general.h" #ifdef __APPLE__ #include #include #endif +#include "sdl_ctx.h" + // SDL 1.2 is portable, sure, but you still need some platform specific workarounds ;) // Hopefully SDL 1.3 will solve this more cleanly :D // Welcome to #ifdef HELL. :D @@ -36,7 +43,7 @@ static SDL_GLContext g_ctx; static bool g_fullscreen; static unsigned g_interval; -void sdlwrap_set_swap_interval(unsigned interval, bool inited) +void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { g_interval = interval; @@ -75,7 +82,7 @@ void sdlwrap_set_swap_interval(unsigned interval, bool inited) RARCH_WARN("Failed to set swap interval.\n"); } -static void sdlwrap_wm_set_caption(const char *str) +static void gfx_ctx_wm_set_caption(const char *str) { #if SDL_MODERN SDL_SetWindowTitle(g_window, str); @@ -84,17 +91,17 @@ static void sdlwrap_wm_set_caption(const char *str) #endif } -void sdlwrap_update_window_title(bool reset) +void gfx_ctx_update_window_title(bool reset) { if (reset) gfx_window_title_reset(); char buf[128]; if (gfx_window_title(buf, sizeof(buf))) - sdlwrap_wm_set_caption(buf); + gfx_ctx_wm_set_caption(buf); } -void sdlwrap_get_video_size(unsigned *width, unsigned *height) +void gfx_ctx_get_video_size(unsigned *width, unsigned *height) { const SDL_VideoInfo *video_info = SDL_GetVideoInfo(); rarch_assert(video_info); @@ -102,7 +109,7 @@ void sdlwrap_get_video_size(unsigned *width, unsigned *height) *height = video_info->current_h; } -bool sdlwrap_init(void) +bool gfx_ctx_init(void) { #if SDL_MODERN bool ret = SDL_VideoInit(NULL) == 0; @@ -118,7 +125,7 @@ bool sdlwrap_init(void) } #if SDL_MODERN -void sdlwrap_destroy(void) +void gfx_ctx_destroy(void) { if (g_ctx) SDL_GL_DeleteContext(g_ctx); @@ -130,13 +137,13 @@ void sdlwrap_destroy(void) SDL_VideoQuit(); } #else -void sdlwrap_destroy(void) +void gfx_ctx_destroy(void) { SDL_QuitSubSystem(SDL_INIT_VIDEO); } #endif -bool sdlwrap_set_video_mode( +bool gfx_ctx_set_video_mode( unsigned width, unsigned height, unsigned bits, bool fullscreen) { @@ -195,7 +202,7 @@ bool sdlwrap_set_video_mode( if (attr <= 0 && g_interval) { RARCH_WARN("SDL failed to setup VSync, attempting to recover using native calls.\n"); - sdlwrap_set_swap_interval(g_interval, true); + gfx_ctx_set_swap_interval(g_interval, true); } #endif @@ -214,7 +221,7 @@ bool sdlwrap_set_video_mode( // SDL 1.2 has an awkward model where you need to "confirm" window resizing. // SDL 1.3 luckily removes this quirk. -void sdlwrap_set_resize(unsigned width, unsigned height) +void gfx_ctx_set_resize(unsigned width, unsigned height) { #if SDL_MODERN (void)width; @@ -229,7 +236,7 @@ void sdlwrap_set_resize(unsigned width, unsigned height) #endif } -void sdlwrap_swap_buffers(void) +void gfx_ctx_swap_buffers(void) { #if SDL_MODERN SDL_GL_SwapWindow(g_window); @@ -238,7 +245,7 @@ void sdlwrap_swap_buffers(void) #endif } -bool sdlwrap_key_pressed(int key) +bool gfx_ctx_key_pressed(int key) { int num_keys; #if SDL_MODERN @@ -260,7 +267,7 @@ bool sdlwrap_key_pressed(int key) // 1.2 specific workaround for tiling WMs. In 1.3 we call GetSize directly, so we don't need to rely on // proper event handling (I hope). #if !defined(__APPLE__) && !defined(_WIN32) && !SDL_MODERN && !defined(XENON) -static void sdlwrap_get_window_size(unsigned *width, unsigned *height) +static void gfx_ctx_get_window_size(unsigned *width, unsigned *height) { SDL_SysWMinfo info; SDL_VERSION(&info.version); @@ -277,7 +284,7 @@ static void sdlwrap_get_window_size(unsigned *width, unsigned *height) } #endif -void sdlwrap_check_window(bool *quit, +void gfx_ctx_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { *quit = false; @@ -342,7 +349,7 @@ void sdlwrap_check_window(bool *quit, if (!*resize && !g_fullscreen) { unsigned new_width, new_height; - sdlwrap_get_window_size(&new_width, &new_height); + gfx_ctx_get_window_size(&new_width, &new_height); if ((new_width != *width || new_height != *height) || (frame_count == 10)) // Ugly hack :D { *resize = true; @@ -355,7 +362,7 @@ void sdlwrap_check_window(bool *quit, #endif } -bool sdlwrap_get_wm_info(SDL_SysWMinfo *info) +bool gfx_ctx_get_wm_info(SDL_SysWMinfo *info) { #ifdef XENON (void)info; @@ -370,7 +377,7 @@ bool sdlwrap_get_wm_info(SDL_SysWMinfo *info) #endif } -bool sdlwrap_window_has_focus(void) +bool gfx_ctx_window_has_focus(void) { #if SDL_MODERN Uint32 flags = SDL_GetWindowFlags(g_window); @@ -381,7 +388,7 @@ bool sdlwrap_window_has_focus(void) #endif } -void sdlwrap_input_driver(const input_driver_t **input, void **input_data) +void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) { void *sdl_input = input_sdl.init(); if (sdl_input) diff --git a/gfx/ext_gfx.c b/gfx/ext_gfx.c index 92176db596..574e98c29a 100644 --- a/gfx/ext_gfx.c +++ b/gfx/ext_gfx.c @@ -22,7 +22,6 @@ #include #include "../dynamic.h" #include "../general.h" -#include "sdlwrap.h" #include "gfx_common.h" #ifdef HAVE_FREETYPE diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h new file mode 100644 index 0000000000..3593b6ae11 --- /dev/null +++ b/gfx/gfx_context.h @@ -0,0 +1,62 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef __GFX_CONTEXT_H +#define __GFX_CONTEXT_H + +#include "../boolean.h" +#include "../driver.h" + +#ifdef HAVE_CONFIG_H +#include "../config.h" +#endif + +#ifdef HAVE_SDL +#include "SDL_syswm.h" +#endif + +void gfx_ctx_set_swap_interval(unsigned interval, bool inited); + +bool gfx_ctx_set_video_mode( + unsigned width, unsigned height, + unsigned bits, bool fullscreen); + +bool gfx_ctx_init(void); +void gfx_ctx_destroy(void); + +void gfx_ctx_get_video_size(unsigned *width, unsigned *height); +void gfx_ctx_update_window_title(bool reset); + +void gfx_ctx_swap_buffers(void); + +bool gfx_ctx_key_pressed(int key); + +void gfx_ctx_check_window(bool *quit, + bool *resize, unsigned *width, unsigned *height, unsigned frame_count); + +void gfx_ctx_set_resize(unsigned width, unsigned height); + +#ifdef HAVE_SDL +bool gfx_ctx_get_wm_info(SDL_SysWMinfo *info); +#endif + +bool gfx_ctx_window_has_focus(void); + +void gfx_ctx_input_driver(const input_driver_t **input, void **input_data); + +#endif + diff --git a/gfx/gl.c b/gfx/gl.c index 004086af01..7c60d62f15 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -29,7 +29,7 @@ #include "gl_common.h" #include "gfx_common.h" -#include "sdlwrap.h" +#include "gfx_context.h" #include "../compat/strl.h" #ifdef HAVE_SDL @@ -865,7 +865,7 @@ static void check_window(gl_t *gl) { bool quit, resize; - sdlwrap_check_window(&quit, + gfx_ctx_check_window(&quit, &resize, &gl->win_width, &gl->win_height, gl->frame_count); @@ -1141,7 +1141,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (gl->should_resize) { gl->should_resize = false; - sdlwrap_set_resize(gl->win_width, gl->win_height); + gfx_ctx_set_resize(gl->win_width, gl->win_height); // On resize, we might have to recreate our FBOs due to "Viewport" scale, and set a new viewport. gl_update_resize(gl); @@ -1179,8 +1179,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (msg) gl_render_msg(gl, msg); - sdlwrap_update_window_title(false); - sdlwrap_swap_buffers(); + gfx_ctx_update_window_title(false); + gfx_ctx_swap_buffers(); return true; } @@ -1200,7 +1200,7 @@ static void gl_free(void *data) gl_deinit_fbo(gl); #endif - sdlwrap_destroy(); + gfx_ctx_destroy(); if (gl->empty_buf) free(gl->empty_buf); @@ -1214,7 +1214,7 @@ static void gl_set_nonblock_state(void *data, bool state) if (gl->vsync) { RARCH_LOG("GL VSync => %s\n", state ? "off" : "on"); - sdlwrap_set_swap_interval(state ? 0 : 1, true); + gfx_ctx_set_swap_interval(state ? 0 : 1, true); } } @@ -1224,14 +1224,14 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gfx_set_dwm(); #endif - if (!sdlwrap_init()) + if (!gfx_ctx_init()) return NULL; unsigned full_x = 0, full_y = 0; - sdlwrap_get_video_size(&full_x, &full_y); + gfx_ctx_get_video_size(&full_x, &full_y); RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y); - sdlwrap_set_swap_interval(video->vsync ? 1 : 0, false); + gfx_ctx_set_swap_interval(video->vsync ? 1 : 0, false); unsigned win_width = video->width; unsigned win_height = video->height; @@ -1241,11 +1241,11 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo win_height = full_y; } - if (!sdlwrap_set_video_mode(win_width, win_height, + if (!gfx_ctx_set_video_mode(win_width, win_height, g_settings.video.force_16bit ? 15 : 0, video->fullscreen)) return NULL; - sdlwrap_update_window_title(true); + gfx_ctx_update_window_title(true); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -1254,7 +1254,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo // Need to load dynamically :( if (!load_gl_proc()) { - sdlwrap_destroy(); + gfx_ctx_destroy(); return NULL; } #endif @@ -1262,7 +1262,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t)); if (!gl) { - sdlwrap_destroy(); + gfx_ctx_destroy(); return NULL; } @@ -1279,7 +1279,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!gl_shader_init()) { RARCH_ERR("Shader init failed.\n"); - sdlwrap_destroy(); + gfx_ctx_destroy(); free(gl); return NULL; } @@ -1375,12 +1375,12 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); } - sdlwrap_input_driver(input, input_data); + gfx_ctx_input_driver(input, input_data); gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); if (!gl_check_error()) { - sdlwrap_destroy(); + gfx_ctx_destroy(); free(gl); return NULL; } @@ -1398,7 +1398,7 @@ static bool gl_alive(void *data) static bool gl_focus(void *data) { (void)data; - return sdlwrap_window_has_focus(); + return gfx_ctx_window_has_focus(); } #ifdef HAVE_XML diff --git a/gfx/sdlwrap.h b/gfx/sdlwrap.h deleted file mode 100644 index c0fe3ecfae..0000000000 --- a/gfx/sdlwrap.h +++ /dev/null @@ -1,78 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * - - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -// Compatibility wrapper between SDL 1.2/1.3 for OpenGL. -// Wraps functions which differ in 1.2 and 1.3. - -#ifndef __SDLWRAP_H -#define __SDLWRAP_H - -#include "../boolean.h" -#include "../driver.h" - -#ifdef HAVE_CONFIG_H -#include "../config.h" -#endif - -#ifdef HAVE_SDL -#include "SDL.h" -#include "SDL_version.h" -#include "SDL_syswm.h" - -#if SDL_VERSION_ATLEAST(1, 3, 0) -#define SDL_MODERN 1 -#else -#define SDL_MODERN 0 -#endif - -// Not legal to cast (void*) to fn-pointer. Need workaround to be compliant. -#define SDL_SYM_WRAP(sym, symbol) { \ - rarch_assert(sizeof(void*) == sizeof(void (*)(void))); \ - void *sym__ = SDL_GL_GetProcAddress(symbol); \ - memcpy(&(sym), &sym__, sizeof(void*)); \ -} -#endif - -void sdlwrap_set_swap_interval(unsigned interval, bool inited); - -bool sdlwrap_set_video_mode( - unsigned width, unsigned height, - unsigned bits, bool fullscreen); - -bool sdlwrap_init(void); -void sdlwrap_destroy(void); - -void sdlwrap_get_video_size(unsigned *width, unsigned *height); -void sdlwrap_update_window_title(bool reset); - -void sdlwrap_swap_buffers(void); - -bool sdlwrap_key_pressed(int key); - -void sdlwrap_check_window(bool *quit, - bool *resize, unsigned *width, unsigned *height, unsigned frame_count); - -void sdlwrap_set_resize(unsigned width, unsigned height); - -bool sdlwrap_get_wm_info(SDL_SysWMinfo *info); - -bool sdlwrap_window_has_focus(void); - -void sdlwrap_input_driver(const input_driver_t **input, void **input_data); - -#endif - diff --git a/gfx/shader_glsl.c b/gfx/shader_glsl.c index f5eb798516..9956d5d05c 100644 --- a/gfx/shader_glsl.c +++ b/gfx/shader_glsl.c @@ -32,7 +32,8 @@ #define NO_SDL_GLEXT -#include "sdlwrap.h" +#include "gfx_context.h" +#include "context/sdl_ctx.h" #include "SDL_opengl.h" #include diff --git a/input/dinput.c b/input/dinput.c index 5e2ea43c06..2bdb09e7c1 100644 --- a/input/dinput.c +++ b/input/dinput.c @@ -20,7 +20,7 @@ #include #include #include -#include "../gfx/sdlwrap.h" +#include "../gfx/gfx_context.h" void sdl_dinput_free(sdl_dinput_t *di) { @@ -108,7 +108,7 @@ sdl_dinput_t* sdl_dinput_init(void) SDL_SysWMinfo info; SDL_VERSION(&info.version); - if (!sdlwrap_get_wm_info(&info)) + if (!gfx_ctx_get_wm_info(&info)) { RARCH_ERR("Failed to get SysWM info.\n"); goto error; diff --git a/input/sdl_input.c b/input/sdl_input.c index 3e9826cd65..a0bc134269 100644 --- a/input/sdl_input.c +++ b/input/sdl_input.c @@ -15,7 +15,7 @@ #include "../driver.h" -#include "../gfx/sdlwrap.h" +#include "../gfx/gfx_context.h" #include "../boolean.h" #include "../general.h" #include @@ -183,7 +183,7 @@ static void *sdl_input_init(void) static bool sdl_key_pressed(int key) { - return sdlwrap_key_pressed(keysym_lut[key]); + return gfx_ctx_key_pressed(keysym_lut[key]); } #ifndef HAVE_DINPUT From 426daa117cb70a1a0a974e615bc8c463d94a0f0c Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 04:48:55 +0200 Subject: [PATCH 010/103] Add missing sdl_ctx.h --- gfx/context/sdl_ctx.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 gfx/context/sdl_ctx.h diff --git a/gfx/context/sdl_ctx.h b/gfx/context/sdl_ctx.h new file mode 100644 index 0000000000..a3edd55385 --- /dev/null +++ b/gfx/context/sdl_ctx.h @@ -0,0 +1,32 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _SDL_CTX_H +#define _SDL_CTX_H + +#if SDL_VERSION_ATLEAST(1, 3, 0) +#define SDL_MODERN 1 +#else +#define SDL_MODERN 0 +#endif + +// Not legal to cast (void*) to fn-pointer. Need workaround to be compliant. +#define SDL_SYM_WRAP(sym, symbol) { \ + rarch_assert(sizeof(void*) == sizeof(void (*)(void))); \ + void *sym__ = SDL_GL_GetProcAddress(symbol); \ + memcpy(&(sym), &sym__, sizeof(void*)); \ +} + +#endif From 69ffd1c7a726eada620f04e9a5eb834fe9f56b3a Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 05:59:55 +0200 Subject: [PATCH 011/103] (RGL PS3) Implemented glRotatef --- console/rgl/ps3/gl.h | 1 + console/rgl/ps3/rgl.cpp | 80 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 77 insertions(+), 4 deletions(-) diff --git a/console/rgl/ps3/gl.h b/console/rgl/ps3/gl.h index 17f4eb9abc..dea55764a1 100644 --- a/console/rgl/ps3/gl.h +++ b/console/rgl/ps3/gl.h @@ -313,6 +313,7 @@ extern "C" GLAPI void APIENTRY glLoadIdentity( void ); GLAPI void APIENTRY glMatrixMode( GLenum mode ); GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat zNear, GLfloat zFar ); + GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ); GLAPI void APIENTRY glPixelStorei( GLenum pname, GLint param ); GLAPI void APIENTRY glTexCoordPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *pointer ); GLAPI void APIENTRY glTexImage2D( GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height, GLint border, GLenum format, GLenum type, const GLvoid *pixels ); diff --git a/console/rgl/ps3/rgl.cpp b/console/rgl/ps3/rgl.cpp index 767245525b..c25667544e 100644 --- a/console/rgl/ps3/rgl.cpp +++ b/console/rgl/ps3/rgl.cpp @@ -919,8 +919,6 @@ static GLboolean _RGLTextureIsValid( const jsTexture* texture ) static GLenum _RGLPlatformFramebufferCheckStatus( jsFramebuffer* framebuffer ) { GLuint nBuffers = 0; - int width = 0; - int height = 0; jsImage* image[_RGL_MAX_COLOR_ATTACHMENTS + 2] = {0}; @@ -940,8 +938,6 @@ static GLenum _RGLPlatformFramebufferCheckStatus( jsFramebuffer* framebuffer ) } image[nBuffers] = colorTexture->image; - width = image[nBuffers]->width; - height = image[nBuffers]->height; if ( colorFormat && colorFormat != image[nBuffers]->internalFormat ) { @@ -6083,6 +6079,82 @@ GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLflo LContext->InverseModelViewValid = GL_FALSE; } +#define DEGREES_TO_RADIANS 0.017453292519943295769 +#define ELEMENTS_IN_MATRIX 16 + +GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) +{ + PSGLcontext* LContext = _CurrentContext; + jsMatrixStack* LMatrixStack = NULL; + GLfloat * LMatrix = NULL; + + jsContextGetMatrixStack(LContext, LContext->MatrixMode, LMatrixStack); + + if (LMatrixStack) + LMatrix = LMatrixStack->MatrixStackf+ LMatrixStack->MatrixStackPtr*ELEMENTS_IN_MATRIX; + + GLfloat a = angle * DEGREES_TO_RADIANS; + GLfloat c = cosf( a ); + GLfloat one_minus_c = 1.f - c; + GLfloat s = sinf( a ); + GLfloat n = x * x + y * y + z * z; + GLfloat m00, m01, m02, m10, m11, m12, m20, m21, m22; + GLfloat L00, L01, L02, L10, L11, L12, L20, L21, L22, L30, L31, L32; + + + if ( n != 1.f ) + { + n = 1.f / sqrtf( n ); + x *= n; + y *= n; + z *= n; + } + + m00 = x * x * one_minus_c + c; + m01 = x * y * one_minus_c - z * s; + m02 = x * z * one_minus_c + y * s; + m10 = y * x * one_minus_c + z * s; + m11 = y * y * one_minus_c + c; + m12 = y * z * one_minus_c - x * s; + m20 = z * x * one_minus_c - y * s; + m21 = z * y * one_minus_c + x * s; + m22 = z * z * one_minus_c + c; + + L00 = LMatrix[0]; + L01 = LMatrix[M01]; + L02 = LMatrix[M02]; + L10 = LMatrix[M10]; + L11 = LMatrix[M11]; + L12 = LMatrix[M12]; + L20 = LMatrix[M20]; + L21 = LMatrix[M21]; + L22 = LMatrix[M22]; + L30 = LMatrix[M30]; + L31 = LMatrix[M31]; + L32 = LMatrix[M32]; + + LMatrix[0] = L00 * m00 + L01 * m10 + L02 * m20; + LMatrix[M01] = L00 * m01 + L01 * m11 + L02 * m21; + LMatrix[M02] = L00 * m02 + L01 * m12 + L02 * m22; + + LMatrix[M10] = L10 * m00 + L11 * m10 + L12 * m20; + LMatrix[M11] = L10 * m01 + L11 * m11 + L12 * m21; + LMatrix[M12] = L10 * m02 + L11 * m12 + L12 * m22; + + LMatrix[M20] = L20 * m00 + L21 * m10 + L22 * m20; + LMatrix[M21] = L20 * m01 + L21 * m11 + L22 * m21; + LMatrix[M22] = L20 * m02 + L21 * m12 + L22 * m22; + + LMatrix[M30] = L30 * m00 + L31 * m10 + L32 * m20; + LMatrix[M31] = L30 * m01 + L31 * m11 + L32 * m21; + LMatrix[M32] = L30 * m02 + L31 * m12 + L32 * m22; + + LContext->needValidate |= PSGL_VALIDATE_FFX_VERTEX_PROGRAM; + LMatrixStack->dirty = GL_TRUE; + if ( LContext->MatrixMode == GL_MODELVIEW ) + LContext->InverseModelViewValid = GL_FALSE; +} + const uint32_t c_rounded_size_of_RGLDrawParams = (sizeof(jsDrawParams)+0x7f)&~0x7f; static uint8_t s_dparams_buff[ c_rounded_size_of_RGLDrawParams ] __attribute__((aligned(128))); From 95a236ac615f984de7db103f4e742dd36ab8d0f9 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 06:20:14 +0200 Subject: [PATCH 012/103] (PS3) Some cleanups to RGL --- console/rgl/ps3/cgbio.hpp | 131 +++++++++++++++++------------------- console/rgl/ps3/cgnv2rt.cpp | 21 +++--- console/rgl/ps3/elf.h | 86 +++++++++++------------ console/rgl/ps3/rgl.cpp | 5 -- console/rgl/ps3/rgl.h | 10 --- 5 files changed, 113 insertions(+), 140 deletions(-) diff --git a/console/rgl/ps3/cgbio.hpp b/console/rgl/ps3/cgbio.hpp index 07c6b349d1..69a8525710 100644 --- a/console/rgl/ps3/cgbio.hpp +++ b/console/rgl/ps3/cgbio.hpp @@ -11,25 +11,18 @@ #define CGF_DEPTHREPLACE 0x02 #define CGF_PIXELKILL 0x04 -typedef unsigned int Elf32_Addr; -typedef unsigned short Elf32_Half; -typedef short Elf32_Shalf; -typedef unsigned int Elf32_Off; -typedef signed int Elf32_Sword; -typedef unsigned int Elf32_Word; - typedef size_t ptrdiff_t; typedef size_t ptrdiff_t; typedef struct _Elf32_cgParameter { - Elf32_Word cgp_name; - Elf32_Word cgp_semantic; - Elf32_Half cgp_default; - Elf32_Half cgp_reloc; - Elf32_Half cgp_resource; - Elf32_Half cgp_resource_index; + unsigned int cgp_name; + unsigned int cgp_semantic; + unsigned short cgp_default; + unsigned short cgp_reloc; + unsigned short cgp_resource; + unsigned short cgp_resource_index; unsigned char cgp_type; - Elf32_Half cgp_info; + unsigned short cgp_info; unsigned char unused; } Elf32_cgParameter; @@ -182,77 +175,77 @@ typedef struct _Elf32_cgParameter { struct Elf32_Ehdr { unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; + unsigned short e_type; + unsigned short e_machine; + unsigned int e_version; + unsigned int e_entry; + unsigned int e_phoff; + unsigned int e_shoff; + unsigned int e_flags; + unsigned short e_ehsize; + unsigned short e_phentsize; + unsigned short e_phnum; + unsigned short e_shentsize; + unsigned short e_shnum; + unsigned short e_shstrndx; }; struct Elf32_Shdr { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; + unsigned int sh_name; + unsigned int sh_type; + unsigned int sh_flags; + unsigned int sh_addr; + unsigned int sh_offset; + unsigned int sh_size; + unsigned int sh_link; + unsigned int sh_info; + unsigned int sh_addralign; + unsigned int sh_entsize; }; struct Elf32_Phdr { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; + unsigned int p_type; + unsigned int p_offset; + unsigned int p_vaddr; + unsigned int p_paddr; + unsigned int p_filesz; + unsigned int p_memsz; + unsigned int p_flags; + unsigned int p_align; }; struct Elf32_Sym { - Elf32_Word st_name; - Elf32_Addr st_value; - Elf32_Word st_size; + unsigned int st_name; + unsigned int st_value; + unsigned int st_size; unsigned char st_info; unsigned char st_other; - Elf32_Half st_shndx; + unsigned short st_shndx; }; struct Elf32_Note { - Elf32_Word n_namesz; /* Name size */ - Elf32_Word n_descsz; /* Content size */ - Elf32_Word n_type; /* Content type */ + unsigned int n_namesz; /* Name size */ + unsigned int n_descsz; /* Content size */ + unsigned int n_type; /* Content type */ }; struct Elf32_Rel { - Elf32_Addr r_offset; - Elf32_Word r_info; + unsigned int r_offset; + unsigned int r_info; }; struct Elf32_Rela { - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; + unsigned int r_offset; + unsigned int r_info; + signed int r_addend; }; struct Elf32_Dyn { - Elf32_Sword d_tag; + signed int d_tag; union { - Elf32_Word d_val; - Elf32_Addr d_ptr; + unsigned int d_val; + unsigned int d_ptr; } d_un; }; @@ -381,16 +374,16 @@ class isection virtual int reference() const = 0; virtual int release() const = 0; - virtual Elf32_Half index() const = 0; + virtual unsigned short index() const = 0; virtual char *name() const = 0; - virtual Elf32_Word type() const = 0; - virtual Elf32_Word flags() const = 0; - virtual Elf32_Addr addr() const = 0; - virtual Elf32_Word size() const = 0; - virtual Elf32_Word link() const = 0; - virtual Elf32_Word info() const = 0; - virtual Elf32_Word addralign() const = 0; - virtual Elf32_Word entsize() const = 0; + virtual unsigned int type() const = 0; + virtual unsigned int flags() const = 0; + virtual unsigned int addr() const = 0; + virtual unsigned int size() const = 0; + virtual unsigned int link() const = 0; + virtual unsigned int info() const = 0; + virtual unsigned int addralign() const = 0; + virtual unsigned int entsize() const = 0; virtual const char* data() const = 0; }; diff --git a/console/rgl/ps3/cgnv2rt.cpp b/console/rgl/ps3/cgnv2rt.cpp index 8639700b2c..feeae93727 100644 --- a/console/rgl/ps3/cgnv2rt.cpp +++ b/console/rgl/ps3/cgnv2rt.cpp @@ -109,7 +109,7 @@ static unsigned int stringTableAdd( STL_NAMESPACE vector &stringTable, con static unsigned int stringTableAddUnique( STL_NAMESPACE vector &stringTable, const char* str ); template static size_t array_size(STL_NAMESPACE vector &array); template static void array_push(char* ¶meterOffset, STL_NAMESPACE vector &array); -inline static Elf32_Word swap16(const Elf32_Word v); +inline static unsigned int swap16(const unsigned int v); static unsigned short getFlags(CGenum var, CGenum dir, int no, bool is_referenced, bool is_shared, int paramIndex); static void fillStructureItems(_CGNVCONTAINERS &containers, CgStructureType *structure, @@ -211,16 +211,16 @@ int convertNvToElfFromMemory(const void *sourceData, size_t size, int endianness cgShader.fragmentProgram.flags = CNV2END(flags); } - Elf32_Word *tmp = (Elf32_Word *)nvbr->ucode(); + unsigned int *tmp = (unsigned int *)nvbr->ucode(); const char *ucode; - Elf32_Word *buffer = NULL; + unsigned int *buffer = NULL; if (doSwap) { - int size = (int)nvbr->ucode_size()/sizeof(Elf32_Word); - buffer = new Elf32_Word[size]; + int size = (int)nvbr->ucode_size()/sizeof(unsigned int); + buffer = new unsigned int[size]; for (int i=0;iucode_size()/sizeof(Elf32_Word); - buffer = new Elf32_Word[size]; + int size = (int)nvbr->ucode_size()/sizeof(unsigned int); + buffer = new unsigned int[size]; for (int i=0;i static void array_push(char* ¶meterOffset, STL_NAMESPAC parameterOffset += dataSize; } -Elf32_Word inline static swap16(const Elf32_Word v) +unsigned int inline static swap16(const unsigned int v) { return (v>>16) | (v<<16); } @@ -1041,7 +1041,8 @@ Elf32_Word inline static swap16(const Elf32_Word v) unsigned short getFlags(CGenum var, CGenum dir, int no, bool is_referenced, bool is_shared, int paramIndex) { (void)paramIndex; - Elf32_Half flags = 0; + unsigned short flags = 0; + if (var == CG_VARYING) flags |= CGPV_VARYING; else if (var == CG_UNIFORM) diff --git a/console/rgl/ps3/elf.h b/console/rgl/ps3/elf.h index fc3ff6e1ff..996d1c0976 100644 --- a/console/rgl/ps3/elf.h +++ b/console/rgl/ps3/elf.h @@ -3,12 +3,6 @@ #define RGL_ALIGN_FAST_TRANSFER 128 -typedef unsigned int Elf32_Addr; -typedef unsigned int Elf32_Off; -typedef unsigned short Elf32_Half; -typedef unsigned int Elf32_Word; -typedef int Elf32_Sword; - #define EI_MAG0 0 #define EI_MAG1 1 #define EI_MAG2 2 @@ -48,19 +42,19 @@ typedef int Elf32_Sword; typedef struct { unsigned char e_ident[EI_NIDENT]; - Elf32_Half e_type; - Elf32_Half e_machine; - Elf32_Word e_version; - Elf32_Addr e_entry; - Elf32_Off e_phoff; - Elf32_Off e_shoff; - Elf32_Word e_flags; - Elf32_Half e_ehsize; - Elf32_Half e_phentsize; - Elf32_Half e_phnum; - Elf32_Half e_shentsize; - Elf32_Half e_shnum; - Elf32_Half e_shstrndx; + unsigned short e_type; + unsigned short e_machine; + unsigned int e_version; + unsigned int e_entry; + unsigned int e_phoff; + unsigned int e_shoff; + unsigned int e_flags; + unsigned short e_ehsize; + unsigned short e_phentsize; + unsigned short e_phnum; + unsigned short e_shentsize; + unsigned short e_shnum; + unsigned short e_shstrndx; } Elf32_Ehdr; #define PT_NULL 0 @@ -76,14 +70,14 @@ typedef struct { #define PT_HIPROC 0x7fffffff typedef struct { - Elf32_Word p_type; - Elf32_Off p_offset; - Elf32_Addr p_vaddr; - Elf32_Addr p_paddr; - Elf32_Word p_filesz; - Elf32_Word p_memsz; - Elf32_Word p_flags; - Elf32_Word p_align; + unsigned int p_type; + unsigned int p_offset; + unsigned int p_vaddr; + unsigned int p_paddr; + unsigned int p_filesz; + unsigned int p_memsz; + unsigned int p_flags; + unsigned int p_align; } Elf32_Phdr; #define SHT_NULL 0 @@ -112,16 +106,16 @@ typedef struct { typedef struct { - Elf32_Word sh_name; - Elf32_Word sh_type; - Elf32_Word sh_flags; - Elf32_Addr sh_addr; - Elf32_Off sh_offset; - Elf32_Word sh_size; - Elf32_Word sh_link; - Elf32_Word sh_info; - Elf32_Word sh_addralign; - Elf32_Word sh_entsize; + unsigned int sh_name; + unsigned int sh_type; + unsigned int sh_flags; + unsigned int sh_addr; + unsigned int sh_offset; + unsigned int sh_size; + unsigned int sh_link; + unsigned int sh_info; + unsigned int sh_addralign; + unsigned int sh_entsize; } Elf32_Shdr; #define SHN_UNDEF 0 @@ -136,26 +130,26 @@ typedef struct { #define SHN_HIRESERVE 0xffff typedef struct { - Elf32_Word st_name; - Elf32_Word st_value; - Elf32_Word st_size; + unsigned int st_name; + unsigned int st_value; + unsigned int st_size; unsigned char st_info; unsigned char st_other; - Elf32_Half st_shndx; + unsigned short st_shndx; } Elf32_Sym; typedef struct { - Elf32_Addr r_offset; - Elf32_Word r_info; + unsigned int r_offset; + unsigned int r_info; } Elf32_Rel; typedef struct { - Elf32_Addr r_offset; - Elf32_Word r_info; - Elf32_Sword r_addend; + unsigned int r_offset; + unsigned int r_info; + int r_addend; } Elf32_Rela; #endif /* ELF_H */ diff --git a/console/rgl/ps3/rgl.cpp b/console/rgl/ps3/rgl.cpp index c25667544e..09733da853 100644 --- a/console/rgl/ps3/rgl.cpp +++ b/console/rgl/ps3/rgl.cpp @@ -5939,11 +5939,6 @@ GLAPI void APIENTRY glFinish (void) _RGLFifoFinish( &_RGLState.fifo ); } -PSGLuint64 psglGetSystemTime() -{ - return sys_time_get_system_time(); -} - GLAPI const GLubyte* APIENTRY glGetString( GLenum name ) { switch ( name ) diff --git a/console/rgl/ps3/rgl.h b/console/rgl/ps3/rgl.h index 4bb325bd09..e64ebf2134 100644 --- a/console/rgl/ps3/rgl.h +++ b/console/rgl/ps3/rgl.h @@ -1092,12 +1092,6 @@ void _RGLSetNativeCgFragmentProgram( const void *header ); clipY1 - clipY0, zNear, zFar, scale, offset ); } - - - - - - #define PSGL_DEVICE_PARAMETERS_COLOR_FORMAT 0x0001 #define PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT 0x0002 #define PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE 0x0004 @@ -1147,8 +1141,6 @@ void _RGLSetNativeCgFragmentProgram( const void *header ); #define PSGL_INIT_USE_PMQUERIES 0x0080 -typedef unsigned long long int PSGLuint64; - extern void psglInit( PSGLinitOptions* options ); extern void psglExit(); @@ -1167,8 +1159,6 @@ PSGLcontext* psglGetCurrentContext(); PSGLdevice* psglGetCurrentDevice(); void psglSwap( void ); -PSGLuint64 psglGetSystemTime(); - static inline void psglRescAdjustAspectRatio( const float horizontalScale, const float verticalScale ) { cellRescAdjustAspectRatio( horizontalScale, verticalScale ); } From 6583d8262bb828c6c0c387fc121f3e28af8c0cb1 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 06:45:55 +0200 Subject: [PATCH 013/103] Add gl_common.c and move commonly used helper GL functions there --- console/griffin/griffin.c | 4 ++++ gfx/gl_common.c | 38 ++++++++++++++++++++++++++++++++++++++ gfx/gl_common.h | 2 ++ ps3/menu.c | 5 +++-- ps3/ps3_video_psgl.c | 9 --------- 5 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 gfx/gl_common.c diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 8facc62e39..039a626ed4 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -43,6 +43,10 @@ CONFIG FILE /*============================================================ VIDEO ============================================================ */ +#ifdef HAVE_OPENGL +#include "../../gfx/gl_common.c" +#endif + #if defined(__CELLOS_LV2__) #include "../../gfx/shader_cg.c" #include "../../ps3/ps3_video_psgl.c" diff --git a/gfx/gl_common.c b/gfx/gl_common.c new file mode 100644 index 0000000000..aa749c545c --- /dev/null +++ b/gfx/gl_common.c @@ -0,0 +1,38 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "../driver.h" + +#include + +#include "gl_common.h" +#include "gfx_common.h" + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +/*============================================================ + VIDEO +============================================================ */ + +void rarch_gl_set_vsync(unsigned enabled) +{ + if(enabled) + glEnable(GL_VSYNC_SCE); + else + glDisable(GL_VSYNC_SCE); +} diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 5dcd8ce808..369fcea228 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -112,4 +112,6 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #define pglActiveTexture glActiveTexture #endif +void rarch_gl_set_vsync(unsigned enabled); + #endif diff --git a/ps3/menu.c b/ps3/menu.c index eee47e29d6..d820c564ac 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -29,6 +29,7 @@ #include "../console/console_ext.h" #include "ps3_video_psgl.h" +#include "../gfx/gl_common.h" #include "shared.h" #include "../file.h" @@ -1427,13 +1428,13 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state)) { g_console.throttle_enable = !g_console.throttle_enable; - ps3graphics_set_vsync(g_console.throttle_enable); + rarch_gl_set_vsync(g_console.throttle_enable); set_delay = DELAY_MEDIUM; } if(CTRL_START(state)) { g_console.throttle_enable = true; - ps3graphics_set_vsync(g_console.throttle_enable); + rarch_gl_set_vsync(g_console.throttle_enable); set_delay = DELAY_MEDIUM; } break; diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 91f66be0fa..3f4c552e6a 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1113,15 +1113,6 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } - -void ps3graphics_set_vsync(uint32_t vsync) -{ - if(vsync) - glEnable(GL_VSYNC_SCE); - else - glDisable(GL_VSYNC_SCE); -} - bool ps3_setup_texture(void) { gl_t *gl = g_gl; From 7cfd0a366085f8d53137b10a480755e1bea49585 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 10:17:06 +0200 Subject: [PATCH 014/103] Fix build. --- Makefile.win | 2 +- gfx/context/sdl_ctx.c | 3 --- gfx/context/sdl_ctx.h | 3 +++ 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile.win b/Makefile.win index df7ca46281..ddb5eebae5 100644 --- a/Makefile.win +++ b/Makefile.win @@ -30,7 +30,7 @@ endif libretro ?= -lretro LIBS = -lm -DEFINES = -I. -DHAVE_CONFIGFILE -DHAVE_SCREENSHOTS -DHAVE_BSV_MOVIE -DPACKAGE_VERSION=\"0.9.6-rc1\" +DEFINES = -I. -DHAVE_CONFIGFILE -DHAVE_SDL -DHAVE_SCREENSHOTS -DHAVE_BSV_MOVIE -DPACKAGE_VERSION=\"0.9.6-rc1\" LDFLAGS = -L. -static-libgcc LDCXXFLAGS = -s diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index b659fa0590..707b915bcc 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -16,9 +16,6 @@ // Compatibility wrapper between SDL 1.2/1.3 for OpenGL. // Wraps functions which differ in 1.2 and 1.3. -#include "SDL.h" -#include "SDL_version.h" - #include "../gfx_context.h" #include "../gfx_common.h" #include "../../general.h" diff --git a/gfx/context/sdl_ctx.h b/gfx/context/sdl_ctx.h index a3edd55385..7f3167bc52 100644 --- a/gfx/context/sdl_ctx.h +++ b/gfx/context/sdl_ctx.h @@ -16,6 +16,9 @@ #ifndef _SDL_CTX_H #define _SDL_CTX_H +#include "SDL.h" +#include "SDL_version.h" + #if SDL_VERSION_ATLEAST(1, 3, 0) #define SDL_MODERN 1 #else From 8f74b1a555da95136c2321e252e58d19344ddd43 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 10:20:06 +0200 Subject: [PATCH 015/103] Build fixes for Win32. --- gfx/context/sdl_ctx.h | 1 + gfx/gl.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gfx/context/sdl_ctx.h b/gfx/context/sdl_ctx.h index 7f3167bc52..ce1b5f4b21 100644 --- a/gfx/context/sdl_ctx.h +++ b/gfx/context/sdl_ctx.h @@ -17,6 +17,7 @@ #define _SDL_CTX_H #include "SDL.h" +#include "SDL_opengl.h" #include "SDL_version.h" #if SDL_VERSION_ATLEAST(1, 3, 0) diff --git a/gfx/gl.c b/gfx/gl.c index 7c60d62f15..0d0e38c789 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -34,8 +34,7 @@ #ifdef HAVE_SDL #define NO_SDL_GLEXT -#include "SDL.h" -#include "SDL_opengl.h" +#include "context/sdl_ctx.h" #include "../input/rarch_sdl_input.h" #endif From 97b966ab59ba4de7f3ee5d5036ff692efc00f6cd Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 14:59:42 +0200 Subject: [PATCH 016/103] (PS3)_Made ps3_ctx file - implemented set_swap_interval function - removed gl_common.c --- 360/xdk360_video.cpp | 8 ------- console/griffin/griffin.c | 5 +---- gfx/{gl_common.c => context/ps3_ctx.c} | 31 ++++++++++++++++---------- gfx/context/ps3_ctx.h | 20 +++++++++++++++++ ps3/menu.c | 4 ++-- 5 files changed, 42 insertions(+), 26 deletions(-) rename gfx/{gl_common.c => context/ps3_ctx.c} (69%) create mode 100644 gfx/context/ps3_ctx.h diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 60490793c9..e84397a417 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -108,7 +108,6 @@ const DWORD g_MapLinearToSrgbGpuFormat[] = struct XPR_HEADER { - unsigned long dwMagic; unsigned long dwHeaderSize; unsigned long dwDataSize; }; @@ -165,13 +164,6 @@ HRESULT PackedResource::Create( const char * strFilename ) return E_FAIL; } - if( xprh.dwMagic != XPR2_MAGIC_VALUE ) - { - RARCH_ERR( "Invalid Xbox Packed Resource (.xpr) file: Magic = 0x%08lx.\n", xprh.dwMagic ); - CloseHandle( hFile ); - return E_FAIL; - } - // Compute memory requirements m_dwSysMemDataSize = xprh.dwHeaderSize; m_dwVidMemDataSize = xprh.dwDataSize; diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 039a626ed4..fd07a557c5 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -43,11 +43,8 @@ CONFIG FILE /*============================================================ VIDEO ============================================================ */ -#ifdef HAVE_OPENGL -#include "../../gfx/gl_common.c" -#endif - #if defined(__CELLOS_LV2__) +#include "../../gfx/context/ps3_ctx.c" #include "../../gfx/shader_cg.c" #include "../../ps3/ps3_video_psgl.c" #include "../../ps3/image.c" diff --git a/gfx/gl_common.c b/gfx/context/ps3_ctx.c similarity index 69% rename from gfx/gl_common.c rename to gfx/context/ps3_ctx.c index aa749c545c..5b0831b390 100644 --- a/gfx/gl_common.c +++ b/gfx/context/ps3_ctx.c @@ -14,25 +14,32 @@ * If not, see . */ -#include "../driver.h" +#include "../../driver.h" #include -#include "gl_common.h" -#include "gfx_common.h" - #ifdef HAVE_CONFIG_H #include "config.h" #endif -/*============================================================ - VIDEO -============================================================ */ +#include "../gl_common.h" -void rarch_gl_set_vsync(unsigned enabled) +#include "ps3_ctx.h" + +void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { - if(enabled) - glEnable(GL_VSYNC_SCE); - else - glDisable(GL_VSYNC_SCE); + bool success = false; + + if(inited) + { + success = true; + + if (interval) + glEnable(GL_VSYNC_SCE); + else + glDisable(GL_VSYNC_SCE); + } + + if (!success) + RARCH_WARN("Failed to set swap interval.\n"); } diff --git a/gfx/context/ps3_ctx.h b/gfx/context/ps3_ctx.h new file mode 100644 index 0000000000..6092f321bc --- /dev/null +++ b/gfx/context/ps3_ctx.h @@ -0,0 +1,20 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _PS3_CTX_H +#define _PS3_CTX_H + +#endif diff --git a/ps3/menu.c b/ps3/menu.c index d820c564ac..4a57df5a0f 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1428,13 +1428,13 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state)) { g_console.throttle_enable = !g_console.throttle_enable; - rarch_gl_set_vsync(g_console.throttle_enable); + gfx_ctx_set_swap_interval(g_console.throttle_enable, true); set_delay = DELAY_MEDIUM; } if(CTRL_START(state)) { g_console.throttle_enable = true; - rarch_gl_set_vsync(g_console.throttle_enable); + gfx_ctx_set_swap_interval(g_console.throttle_enable, true); set_delay = DELAY_MEDIUM; } break; From 15760c6a8b67f9a091e412536a712506ecfc341b Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 15:04:10 +0200 Subject: [PATCH 017/103] (PS3) Use gfx_ctx_set_swap_interval in gl_set_nonblock_state too --- ps3/ps3_video_psgl.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 3f4c552e6a..7ca92605e6 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -731,14 +731,11 @@ static void gl_free(void *data) static void gl_set_nonblock_state(void *data, bool state) { - gl_t *gl = data; + gl_t *gl = (gl_t*)data; if (gl->vsync) { RARCH_LOG("GL VSync => %s\n", state ? "off" : "on"); - if(state) - glDisable(GL_VSYNC_SCE); - else - glEnable(GL_VSYNC_SCE); + gfx_ctx_set_swap_interval(state ? 0 : 1, true); } } From a10a5badcc8e08a9ef8ff77de8a966fe5f8259c0 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 15:21:51 +0200 Subject: [PATCH 018/103] Move font code to gl_font. --- Makefile | 2 +- Makefile.win | 2 +- gfx/gl.c | 376 ++++-------------------------------------------- gfx/gl_common.h | 77 ++++++++++ gfx/gl_font.c | 269 ++++++++++++++++++++++++++++++++++ gfx/gl_font.h | 27 ++++ 6 files changed, 404 insertions(+), 349 deletions(-) create mode 100644 gfx/gl_font.c create mode 100644 gfx/gl_font.h diff --git a/Makefile b/Makefile index 67697bfd83..033fcbd993 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ ifeq ($(HAVE_SDL), 1) LIBS += $(SDL_LIBS) ifeq ($(HAVE_OPENGL), 1) - OBJ += gfx/gl.o + OBJ += gfx/gl.o gfx/gl_font.o ifeq ($(OSX),1) LIBS += -framework OpenGL else diff --git a/Makefile.win b/Makefile.win index ddb5eebae5..9782ef8a81 100644 --- a/Makefile.win +++ b/Makefile.win @@ -39,7 +39,7 @@ ifeq ($(TDM_GCC),) endif ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/context/sdl_ctx.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o + OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/gl_font.o gfx/context/sdl_ctx.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o LIBS += -lSDL DEFINES += -ISDL -DHAVE_SDL endif diff --git a/gfx/gl.c b/gfx/gl.c index 0d0e38c789..25fa0a660c 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -13,7 +13,6 @@ * If not, see . */ - #include "../driver.h" #include @@ -28,6 +27,7 @@ #endif #include "gl_common.h" +#include "gl_font.h" #include "gfx_common.h" #include "gfx_context.h" #include "../compat/strl.h" @@ -138,72 +138,6 @@ static inline bool load_gl_proc(void) static inline bool load_gl_proc(void) { return true; } #endif -#define MAX_SHADERS 16 - -#if defined(HAVE_XML) || defined(HAVE_CG) -#define TEXTURES 8 -#else -#define TEXTURES 1 -#endif -#define TEXTURES_MASK (TEXTURES - 1) - -typedef struct gl -{ - bool vsync; - GLuint texture[TEXTURES]; - unsigned tex_index; // For use with PREV. - struct gl_tex_info prev_info[TEXTURES]; - GLuint tex_filter; - - void *empty_buf; - - unsigned frame_count; - -#ifdef HAVE_FBO - // 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; -#endif - - bool should_resize; - bool quitting; - bool fullscreen; - bool keep_aspect; - unsigned rotation; - - unsigned full_x, full_y; - - unsigned win_width; - unsigned win_height; - unsigned vp_width, vp_out_width; - unsigned vp_height, vp_out_height; - unsigned last_width[TEXTURES]; - unsigned last_height[TEXTURES]; - unsigned tex_w, tex_h; - GLfloat tex_coords[8]; - - GLenum texture_type; // XBGR1555 or ARGB - GLenum texture_fmt; - unsigned base_size; // 2 or 4 - -#ifdef HAVE_FREETYPE - font_renderer_t *font; - GLuint font_tex; - int font_tex_w, font_tex_h; - void *font_tex_empty_buf; - char font_last_msg[256]; - int font_last_width, font_last_height; - GLfloat font_color[16]; - GLfloat font_color_dark[16]; -#endif - -} gl_t; - ////////////////// Shaders static bool gl_shader_init(void) { @@ -357,57 +291,6 @@ static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) #endif /////////////////// -//////////////// Message rendering -static inline void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) -{ -#ifdef HAVE_FREETYPE - if (!g_settings.video.font_enable) - return; - - const char *path = font_path; - if (!*path) - path = font_renderer_get_default_font(); - - if (path) - { - gl->font = font_renderer_new(path, font_size); - if (gl->font) - { - glGenTextures(1, &gl->font_tex); - glBindTexture(GL_TEXTURE_2D, gl->font_tex); - 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); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - } - else - RARCH_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path); - } - else - RARCH_LOG("Did not find default font.\n"); - - for (unsigned i = 0; i < 4; i++) - { - gl->font_color[4 * i + 0] = g_settings.video.msg_color_r; - gl->font_color[4 * i + 1] = g_settings.video.msg_color_g; - gl->font_color[4 * i + 2] = g_settings.video.msg_color_b; - gl->font_color[4 * i + 3] = 1.0; - } - - for (unsigned i = 0; i < 4; i++) - { - for (unsigned j = 0; j < 3; j++) - gl->font_color_dark[4 * i + j] = 0.3 * gl->font_color[4 * i + j]; - gl->font_color_dark[4 * i + 3] = 1.0; - } - -#else - (void)gl; - (void)font_path; - (void)font_size; -#endif -} #ifdef HAVE_FBO static void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, @@ -544,34 +427,8 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) } #endif -static inline void gl_deinit_font(gl_t *gl) -{ -#ifdef HAVE_FREETYPE - if (gl->font) - { - font_renderer_free(gl->font); - glDeleteTextures(1, &gl->font_tex); - - if (gl->font_tex_empty_buf) - free(gl->font_tex_empty_buf); - } -#else - (void)gl; -#endif -} //////////// -static inline unsigned get_alignment(unsigned pitch) -{ - if (pitch & 1) - return 1; - if (pitch & 2) - return 2; - if (pitch & 4) - return 4; - return 8; -} - static void set_projection(gl_t *gl, bool allow_rotate) { glMatrixMode(GL_PROJECTION); @@ -636,209 +493,6 @@ static void gl_set_rotation(void *data, unsigned rotation) set_projection(gl, true); } -#ifdef HAVE_FREETYPE - -// Somewhat overwhelming code just to render some damn fonts. -// We aim to use NPOT textures for compatibility with old and shitty cards. -// Also, we want to avoid reallocating a texture for each glyph (performance dips), so we -// contruct the whole texture using one call, and copy straight to it with -// glTexSubImage. - -struct font_rect -{ - int x, y; - int width, height; - int pot_width, pot_height; -}; - -static void calculate_msg_geometry(const struct font_output *head, struct font_rect *rect) -{ - int x_min = head->off_x; - int x_max = head->off_x + head->width; - int y_min = head->off_y; - int y_max = head->off_y + head->height; - - while ((head = head->next)) - { - int left = head->off_x; - int right = head->off_x + head->width; - int bottom = head->off_y; - int top = head->off_y + head->height; - - if (left < x_min) - x_min = left; - if (right > x_max) - x_max = right; - - if (bottom < y_min) - y_min = bottom; - if (top > y_max) - y_max = top; - } - - rect->x = x_min; - rect->y = y_min; - rect->width = x_max - x_min; - rect->height = y_max - y_min; -} - -static void adjust_power_of_two(gl_t *gl, struct font_rect *geom) -{ - // Some systems really hate NPOT textures. - geom->pot_width = next_pow2(geom->width); - geom->pot_height = next_pow2(geom->height); - - if ((geom->pot_width > gl->font_tex_w) || (geom->pot_height > gl->font_tex_h)) - { - gl->font_tex_empty_buf = realloc(gl->font_tex_empty_buf, geom->pot_width * geom->pot_height); - memset(gl->font_tex_empty_buf, 0, geom->pot_width * geom->pot_height); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - glPixelStorei(GL_UNPACK_ROW_LENGTH, geom->pot_width); - glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, geom->pot_width, geom->pot_height, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); - - gl->font_tex_w = geom->pot_width; - gl->font_tex_h = geom->pot_height; - } -} - -// Old style "blitting", so we can render all the fonts in one go. -// TODO: Is it possible that fonts could overlap if we blit without alpha blending? -static void blit_fonts(gl_t *gl, const struct font_output *head, const struct font_rect *geom) -{ - // Clear out earlier fonts. - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->font_tex_w); - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, gl->font_tex_w, gl->font_tex_h, - GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); - - while (head) - { - // head has top-left oriented coords. - int x = head->off_x - geom->x; - int y = head->off_y - geom->y; - y = gl->font_tex_h - head->height - y - 1; - - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(head->pitch)); - glPixelStorei(GL_UNPACK_ROW_LENGTH, head->pitch); - glTexSubImage2D(GL_TEXTURE_2D, - 0, x, y, head->width, head->height, - GL_LUMINANCE, GL_UNSIGNED_BYTE, head->output); - - head = head->next; - } -} - -static void calculate_font_coords(gl_t *gl, - GLfloat font_vertex[8], GLfloat font_vertex_dark[8], GLfloat font_tex_coords[8]) -{ - GLfloat scale_factor = g_settings.video.font_scale ? - (GLfloat)gl->full_x / (GLfloat)gl->vp_width : - 1.0f; - - GLfloat lx = g_settings.video.msg_pos_x; - GLfloat hx = (GLfloat)gl->font_last_width / (gl->vp_width * scale_factor) + lx; - GLfloat ly = g_settings.video.msg_pos_y; - GLfloat hy = (GLfloat)gl->font_last_height / (gl->vp_height * scale_factor) + ly; - - font_vertex[0] = lx; - font_vertex[1] = ly; - font_vertex[2] = lx; - font_vertex[3] = hy; - font_vertex[4] = hx; - font_vertex[5] = hy; - font_vertex[6] = hx; - font_vertex[7] = ly; - - GLfloat shift_x = 2.0f / gl->vp_width; - GLfloat shift_y = 2.0f / gl->vp_height; - for (unsigned i = 0; i < 4; i++) - { - font_vertex_dark[2 * i + 0] = font_vertex[2 * i + 0] - shift_x; - font_vertex_dark[2 * i + 1] = font_vertex[2 * i + 1] - shift_y; - } - - lx = 0.0f; - hx = (GLfloat)gl->font_last_width / gl->font_tex_w; - ly = 1.0f - (GLfloat)gl->font_last_height / gl->font_tex_h; - hy = 1.0f; - - font_tex_coords[0] = lx; - font_tex_coords[1] = hy; - font_tex_coords[2] = lx; - font_tex_coords[3] = ly; - font_tex_coords[4] = hx; - font_tex_coords[5] = ly; - font_tex_coords[6] = hx; - font_tex_coords[7] = hy; -} - -static void gl_render_msg(gl_t *gl, const char *msg) -{ - if (!gl->font) - return; - - GLfloat font_vertex[8]; - GLfloat font_vertex_dark[8]; - GLfloat font_tex_coords[8]; - - // Deactivate custom shaders. Enable the font texture. - gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false, false); - glBindTexture(GL_TEXTURE_2D, gl->font_tex); - glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords); - - // Need blending. - // Using fixed function pipeline here since we cannot guarantee presence of shaders (would be kinda overkill anyways). - glEnable(GL_BLEND); - - struct font_output_list out; - - // If we get the same message, there's obviously no need to render fonts again ... - if (strcmp(gl->font_last_msg, msg) != 0) - { - font_renderer_msg(gl->font, msg, &out); - struct font_output *head = out.head; - - struct font_rect geom; - calculate_msg_geometry(head, &geom); - adjust_power_of_two(gl, &geom); - blit_fonts(gl, head, &geom); - - font_renderer_free_output(&out); - strlcpy(gl->font_last_msg, msg, sizeof(gl->font_last_msg)); - - gl->font_last_width = geom.width; - gl->font_last_height = geom.height; - } - calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords); - - glVertexPointer(2, GL_FLOAT, 0, font_vertex_dark); - glColorPointer(4, GL_FLOAT, 0, gl->font_color_dark); - glDrawArrays(GL_QUADS, 0, 4); - glVertexPointer(2, GL_FLOAT, 0, font_vertex); - glColorPointer(4, GL_FLOAT, 0, gl->font_color); - glDrawArrays(GL_QUADS, 0, 4); - - // Go back to old rendering path. - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); - glColorPointer(4, GL_FLOAT, 0, white_color); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - - glDisable(GL_BLEND); - set_projection(gl, true); -} -#else -static void gl_render_msg(gl_t *gl, const char *msg) -{ - (void)gl; - (void)msg; -} -#endif - static inline void set_lut_texture_coords(const GLfloat *coords) { #if defined(HAVE_XML) || defined(HAVE_CG) @@ -1117,6 +771,30 @@ static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; } +#ifdef HAVE_FREETYPE +static inline void gl_render_msg_pre(gl_t *gl) +{ + gl_shader_use(0); + set_viewport(gl, gl->win_width, gl->win_height, false, false); + glEnable(GL_BLEND); +} + +static inline void gl_render_msg_post(gl_t *gl) +{ + // Go back to old rendering path. + glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); + glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); + glColorPointer(4, GL_FLOAT, 0, white_color); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + + glDisable(GL_BLEND); + set_projection(gl, true); +} +#else +#define gl_render_msg_pre(...) +#define gl_render_msg_post(...) +#endif + static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = (gl_t*)data; @@ -1176,7 +854,11 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_next_texture_index(gl, &tex_info); if (msg) + { + gl_render_msg_pre(gl); gl_render_msg(gl, msg); + gl_render_msg_post(gl); + } gfx_ctx_update_window_title(false); gfx_ctx_swap_buffers(); diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 369fcea228..c0b9512535 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -17,6 +17,7 @@ #define __GL_COMMON_H #include "../general.h" +#include "fonts.h" #ifdef HAVE_CONFIG_H #include "../config.h" @@ -67,6 +68,17 @@ static inline bool gl_check_error(void) return false; } +static inline unsigned get_alignment(unsigned pitch) +{ + if (pitch & 1) + return 1; + if (pitch & 2) + return 2; + if (pitch & 4) + return 4; + return 8; +} + struct gl_fbo_rect { unsigned img_width; @@ -103,6 +115,71 @@ struct gl_tex_info GLfloat coord[8]; }; +#define MAX_SHADERS 16 + +#if defined(HAVE_XML) || defined(HAVE_CG) +#define TEXTURES 8 +#else +#define TEXTURES 1 +#endif +#define TEXTURES_MASK (TEXTURES - 1) + +typedef struct gl +{ + bool vsync; + GLuint texture[TEXTURES]; + unsigned tex_index; // For use with PREV. + struct gl_tex_info prev_info[TEXTURES]; + GLuint tex_filter; + + void *empty_buf; + + unsigned frame_count; + +#ifdef HAVE_FBO + // 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; +#endif + + bool should_resize; + bool quitting; + bool fullscreen; + bool keep_aspect; + unsigned rotation; + + unsigned full_x, full_y; + + unsigned win_width; + unsigned win_height; + unsigned vp_width, vp_out_width; + unsigned vp_height, vp_out_height; + unsigned last_width[TEXTURES]; + unsigned last_height[TEXTURES]; + unsigned tex_w, tex_h; + GLfloat tex_coords[8]; + + GLenum texture_type; // XBGR1555 or ARGB + GLenum texture_fmt; + unsigned base_size; // 2 or 4 + +#ifdef HAVE_FREETYPE + font_renderer_t *font; + GLuint font_tex; + int font_tex_w, font_tex_h; + void *font_tex_empty_buf; + char font_last_msg[256]; + int font_last_width, font_last_height; + GLfloat font_color[16]; + GLfloat font_color_dark[16]; +#endif +} gl_t; + // Windows ... <_< #if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) extern PFNGLCLIENTACTIVETEXTUREPROC pglClientActiveTexture; diff --git a/gfx/gl_font.c b/gfx/gl_font.c new file mode 100644 index 0000000000..1ce34d164d --- /dev/null +++ b/gfx/gl_font.c @@ -0,0 +1,269 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "gl_font.h" + +void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) +{ +#ifdef HAVE_FREETYPE + if (!g_settings.video.font_enable) + return; + + const char *path = font_path; + if (!*path) + path = font_renderer_get_default_font(); + + if (path) + { + gl->font = font_renderer_new(path, font_size); + if (gl->font) + { + glGenTextures(1, &gl->font_tex); + glBindTexture(GL_TEXTURE_2D, gl->font_tex); + 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); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + } + else + RARCH_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path); + } + else + RARCH_LOG("Did not find default font.\n"); + + for (unsigned i = 0; i < 4; i++) + { + gl->font_color[4 * i + 0] = g_settings.video.msg_color_r; + gl->font_color[4 * i + 1] = g_settings.video.msg_color_g; + gl->font_color[4 * i + 2] = g_settings.video.msg_color_b; + gl->font_color[4 * i + 3] = 1.0; + } + + for (unsigned i = 0; i < 4; i++) + { + for (unsigned j = 0; j < 3; j++) + gl->font_color_dark[4 * i + j] = 0.3 * gl->font_color[4 * i + j]; + gl->font_color_dark[4 * i + 3] = 1.0; + } + +#else + (void)gl; + (void)font_path; + (void)font_size; +#endif +} + +void gl_deinit_font(gl_t *gl) +{ +#ifdef HAVE_FREETYPE + if (gl->font) + { + font_renderer_free(gl->font); + glDeleteTextures(1, &gl->font_tex); + + if (gl->font_tex_empty_buf) + free(gl->font_tex_empty_buf); + } +#else + (void)gl; +#endif +} + +#ifdef HAVE_FREETYPE +// Somewhat overwhelming code just to render some damn fonts. +// We aim to use NPOT textures for compatibility with old and shitty cards. +// Also, we want to avoid reallocating a texture for each glyph (performance dips), so we +// contruct the whole texture using one call, and copy straight to it with +// glTexSubImage. + +struct font_rect +{ + int x, y; + int width, height; + int pot_width, pot_height; +}; + +static void calculate_msg_geometry(const struct font_output *head, struct font_rect *rect) +{ + int x_min = head->off_x; + int x_max = head->off_x + head->width; + int y_min = head->off_y; + int y_max = head->off_y + head->height; + + while ((head = head->next)) + { + int left = head->off_x; + int right = head->off_x + head->width; + int bottom = head->off_y; + int top = head->off_y + head->height; + + if (left < x_min) + x_min = left; + if (right > x_max) + x_max = right; + + if (bottom < y_min) + y_min = bottom; + if (top > y_max) + y_max = top; + } + + rect->x = x_min; + rect->y = y_min; + rect->width = x_max - x_min; + rect->height = y_max - y_min; +} + +static void adjust_power_of_two(gl_t *gl, struct font_rect *geom) +{ + // Some systems really hate NPOT textures. + geom->pot_width = next_pow2(geom->width); + geom->pot_height = next_pow2(geom->height); + + if ((geom->pot_width > gl->font_tex_w) || (geom->pot_height > gl->font_tex_h)) + { + gl->font_tex_empty_buf = realloc(gl->font_tex_empty_buf, geom->pot_width * geom->pot_height); + memset(gl->font_tex_empty_buf, 0, geom->pot_width * geom->pot_height); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + glPixelStorei(GL_UNPACK_ROW_LENGTH, geom->pot_width); + glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, geom->pot_width, geom->pot_height, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); + + gl->font_tex_w = geom->pot_width; + gl->font_tex_h = geom->pot_height; + } +} + +// Old style "blitting", so we can render all the fonts in one go. +// TODO: Is it possible that fonts could overlap if we blit without alpha blending? +static void blit_fonts(gl_t *gl, const struct font_output *head, const struct font_rect *geom) +{ + // Clear out earlier fonts. + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->font_tex_w); + glTexSubImage2D(GL_TEXTURE_2D, + 0, 0, 0, gl->font_tex_w, gl->font_tex_h, + GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); + + while (head) + { + // head has top-left oriented coords. + int x = head->off_x - geom->x; + int y = head->off_y - geom->y; + y = gl->font_tex_h - head->height - y - 1; + + glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(head->pitch)); + glPixelStorei(GL_UNPACK_ROW_LENGTH, head->pitch); + glTexSubImage2D(GL_TEXTURE_2D, + 0, x, y, head->width, head->height, + GL_LUMINANCE, GL_UNSIGNED_BYTE, head->output); + + head = head->next; + } +} + +static void calculate_font_coords(gl_t *gl, + GLfloat font_vertex[8], GLfloat font_vertex_dark[8], GLfloat font_tex_coords[8]) +{ + GLfloat scale_factor = g_settings.video.font_scale ? + (GLfloat)gl->full_x / (GLfloat)gl->vp_width : + 1.0f; + + GLfloat lx = g_settings.video.msg_pos_x; + GLfloat hx = (GLfloat)gl->font_last_width / (gl->vp_width * scale_factor) + lx; + GLfloat ly = g_settings.video.msg_pos_y; + GLfloat hy = (GLfloat)gl->font_last_height / (gl->vp_height * scale_factor) + ly; + + font_vertex[0] = lx; + font_vertex[1] = ly; + font_vertex[2] = lx; + font_vertex[3] = hy; + font_vertex[4] = hx; + font_vertex[5] = hy; + font_vertex[6] = hx; + font_vertex[7] = ly; + + GLfloat shift_x = 2.0f / gl->vp_width; + GLfloat shift_y = 2.0f / gl->vp_height; + for (unsigned i = 0; i < 4; i++) + { + font_vertex_dark[2 * i + 0] = font_vertex[2 * i + 0] - shift_x; + font_vertex_dark[2 * i + 1] = font_vertex[2 * i + 1] - shift_y; + } + + lx = 0.0f; + hx = (GLfloat)gl->font_last_width / gl->font_tex_w; + ly = 1.0f - (GLfloat)gl->font_last_height / gl->font_tex_h; + hy = 1.0f; + + font_tex_coords[0] = lx; + font_tex_coords[1] = hy; + font_tex_coords[2] = lx; + font_tex_coords[3] = ly; + font_tex_coords[4] = hx; + font_tex_coords[5] = ly; + font_tex_coords[6] = hx; + font_tex_coords[7] = hy; +} +#endif + +void gl_render_msg(gl_t *gl, const char *msg) +{ +#ifdef HAVE_FREETYPE + if (!gl->font) + return; + + GLfloat font_vertex[8]; + GLfloat font_vertex_dark[8]; + GLfloat font_tex_coords[8]; + + glBindTexture(GL_TEXTURE_2D, gl->font_tex); + glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords); + + struct font_output_list out; + + // If we get the same message, there's obviously no need to render fonts again ... + if (strcmp(gl->font_last_msg, msg) != 0) + { + font_renderer_msg(gl->font, msg, &out); + struct font_output *head = out.head; + + struct font_rect geom; + calculate_msg_geometry(head, &geom); + adjust_power_of_two(gl, &geom); + blit_fonts(gl, head, &geom); + + font_renderer_free_output(&out); + strlcpy(gl->font_last_msg, msg, sizeof(gl->font_last_msg)); + + gl->font_last_width = geom.width; + gl->font_last_height = geom.height; + } + calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords); + + glVertexPointer(2, GL_FLOAT, 0, font_vertex_dark); + glColorPointer(4, GL_FLOAT, 0, gl->font_color_dark); + glDrawArrays(GL_QUADS, 0, 4); + glVertexPointer(2, GL_FLOAT, 0, font_vertex); + glColorPointer(4, GL_FLOAT, 0, gl->font_color); + glDrawArrays(GL_QUADS, 0, 4); +#else + (void)gl; + (void)msg; +#endif +} + diff --git a/gfx/gl_font.h b/gfx/gl_font.h new file mode 100644 index 0000000000..9c512ecd35 --- /dev/null +++ b/gfx/gl_font.h @@ -0,0 +1,27 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef GL_FONT_H__ +#define GL_FONT_H__ + +#include "gl_common.h" + +void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size); +void gl_deinit_font(gl_t *gl); + +void gl_render_msg(gl_t *gl, const char *msg); + +#endif + From 9040e3348f0defb823c4305fb714fc35126c9612 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 15:36:26 +0200 Subject: [PATCH 019/103] Delete unneeded prototype. --- gfx/gl_common.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/gfx/gl_common.h b/gfx/gl_common.h index c0b9512535..bf6f05ae6d 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -189,6 +189,4 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #define pglActiveTexture glActiveTexture #endif -void rarch_gl_set_vsync(unsigned enabled); - #endif From 04f325dcc97a5936dd7461324c47ec22512df17a Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 15:46:37 +0200 Subject: [PATCH 020/103] Refactor texture init. --- gfx/gl.c | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 25fa0a660c..851e631f9d 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -764,6 +764,26 @@ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned gl->texture_fmt, frame); } +static void gl_init_textures(gl_t *gl) +{ + glGenTextures(TEXTURES, gl->texture); + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + + 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->tex_filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); + glTexImage2D(GL_TEXTURE_2D, + 0, GL_RGBA, gl->tex_w, gl->tex_h, 0, gl->texture_type, + gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); + } + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} + static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) { memmove(gl->prev_info + 1, gl->prev_info, sizeof(*tex_info) * (TEXTURES - 1)); @@ -999,19 +1019,6 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - glGenTextures(TEXTURES, gl->texture); - - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - - 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->tex_filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); - } - glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); @@ -1019,7 +1026,6 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glColorPointer(4, GL_FLOAT, 0, white_color); set_lut_texture_coords(tex_coords); @@ -1029,16 +1035,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo // Empty buffer that we use to clear out the texture with on res change. gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); - - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); - glTexImage2D(GL_TEXTURE_2D, - 0, GL_RGBA, gl->tex_w, gl->tex_h, 0, gl->texture_type, - gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); - } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + gl_init_textures(gl); for (unsigned i = 0; i < TEXTURES; i++) { From 6000bd33e91c4bc3cf52b92117b7b5de77c1f396 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 15:45:00 +0200 Subject: [PATCH 021/103] (PS3) Cleaned up ps3_video_psgl.c code - added some PS3-specific ifdefs to gl.c --- gfx/gl.c | 34 +++++- gfx/gl_common.h | 3 + ps3/ps3_video_psgl.c | 261 ++++++++++++++++++++++++++++++------------- ps3/ps3_video_psgl.h | 39 ------- 4 files changed, 217 insertions(+), 120 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 851e631f9d..64293b616e 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -87,7 +87,7 @@ static const GLfloat white_color[] = { #endif #ifdef HAVE_FBO -#ifdef _WIN32 +#if defined(_WIN32) && !defined(RARCH_CONSOLE) static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer = NULL; static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL; @@ -114,6 +114,7 @@ static bool load_fbo_proc(void) #define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES #define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT #define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES +#define glOrtho glOrthof static bool load_fbo_proc(void) { return true; } #else #define pglGenFramebuffers glGenFramebuffers @@ -756,6 +757,25 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi } } +#ifdef __CELLOS_LV2__ +static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) +{ + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; + size_t buffer_stride = gl->tex_w * gl->base_size; + const uint8_t *frame_copy = frame; + size_t frame_copy_size = width * gl->base_size; + for (unsigned h = 0; h < height; h++) + { + glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, + buffer_addr, + frame_copy_size, + frame_copy); + + frame_copy += pitch; + buffer_addr += buffer_stride; + } +} +#else static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size); @@ -763,6 +783,7 @@ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned 0, 0, 0, width, height, gl->texture_type, gl->texture_fmt, frame); } +#endif static void gl_init_textures(gl_t *gl) { @@ -897,6 +918,11 @@ static void gl_free(void *data) glDisableClientState(GL_COLOR_ARRAY); glDeleteTextures(TEXTURES, gl->texture); +#ifdef __CELLOS_LV2__ + glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0); + glDeleteBuffers(1, &gl->pbo); +#endif + #ifdef HAVE_FBO gl_deinit_fbo(gl); #endif @@ -1033,6 +1059,12 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl->tex_w = RARCH_SCALE_BASE * video->input_scale; gl->tex_h = RARCH_SCALE_BASE * video->input_scale; +#ifdef __CELLOS_LV2__ + glGenBuffers(1, &gl->pbo); + glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); + glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); +#endif + // Empty buffer that we use to clear out the texture with on res change. gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); gl_init_textures(gl); diff --git a/gfx/gl_common.h b/gfx/gl_common.h index bf6f05ae6d..5f26255e12 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -164,6 +164,9 @@ typedef struct gl unsigned tex_w, tex_h; GLfloat tex_coords[8]; +#ifdef __CELLOS_LV2__ + GLuint pbo; +#endif GLenum texture_type; // XBGR1555 or ARGB GLenum texture_fmt; unsigned base_size; // 2 or 4 diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 7ca92605e6..4ffe3cda40 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -43,8 +43,6 @@ #define BLUE 0xffff0000u #define WHITE 0xffffffffu -#define FORCE_16BIT_COLOR 1 - // Used for the last pass when rendering to the back buffer. static const GLfloat vertexes_flipped[] = { 0, 0, @@ -100,10 +98,62 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; +struct { + bool block_swap; + bool fbo_enabled; + bool overscan_enable; + GLfloat overscan_amount; + GLuint menu_texture_id; + struct texture_image menu_texture; + PSGLdevice* gl_device; + PSGLcontext* gl_context; + CellVideoOutState g_video_state; +} ps3_gl; + bool g_quitting; unsigned g_frame_count; void *g_gl; +#ifdef HAVE_FBO +#if defined(_WIN32) && !defined(RARCH_CONSOLE) +static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; +static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer = NULL; +static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL; +static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL; +static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL; + +static bool load_fbo_proc(void) +{ + LOAD_SYM(glGenFramebuffers); + LOAD_SYM(glBindFramebuffer); + LOAD_SYM(glFramebufferTexture2D); + LOAD_SYM(glCheckFramebufferStatus); + LOAD_SYM(glDeleteFramebuffers); + + return pglGenFramebuffers && pglBindFramebuffer && pglFramebufferTexture2D && + pglCheckFramebufferStatus && pglDeleteFramebuffers; +} +#elif defined(HAVE_OPENGLES) +#define pglGenFramebuffers glGenFramebuffersOES +#define pglBindFramebuffer glBindFramebufferOES +#define pglFramebufferTexture2D glFramebufferTexture2DOES +#define pglCheckFramebufferStatus glCheckFramebufferStatusOES +#define pglDeleteFramebuffers glDeleteFramebuffersOES +#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES +#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT +#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES +#define glOrtho glOrthof +static bool load_fbo_proc(void) { return true; } +#else +#define pglGenFramebuffers glGenFramebuffers +#define pglBindFramebuffer glBindFramebuffer +#define pglFramebufferTexture2D glFramebufferTexture2D +#define pglCheckFramebufferStatus glCheckFramebufferStatus +#define pglDeleteFramebuffers glDeleteFramebuffers +static bool load_fbo_proc(void) { return true; } +#endif +#endif + /*============================================================ GL IMPLEMENTATION ============================================================ */ @@ -113,13 +163,38 @@ static bool gl_shader_init(void) switch (g_settings.video.shader_type) { case RARCH_SHADER_AUTO: - if (strlen(g_settings.video.cg_shader_path) > 0 && strlen(g_settings.video.bsnes_shader_path) > 0) + { + if (*g_settings.video.cg_shader_path && *g_settings.video.bsnes_shader_path) RARCH_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n"); - // fall-through - case RARCH_SHADER_CG: - if (strlen(g_settings.video.cg_shader_path) > 0) + +#ifdef HAVE_CG + if (*g_settings.video.cg_shader_path) return gl_cg_init(g_settings.video.cg_shader_path); - break; +#endif + +#ifdef HAVE_XML + if (*g_settings.video.bsnes_shader_path) + return gl_glsl_init(g_settings.video.bsnes_shader_path); +#endif + break; + } + +#ifdef HAVE_CG + case RARCH_SHADER_CG: + { + return gl_cg_init(g_settings.video.cg_shader_path); + break; + } +#endif + +#ifdef HAVE_XML + case RARCH_SHADER_BSNES: + { + return gl_glsl_init(g_settings.video.bsnes_shader_path); + break; + } +#endif + default: break; } @@ -129,37 +204,59 @@ static bool gl_shader_init(void) static unsigned gl_shader_num(void) { - unsigned num = 0; +#ifdef HAVE_CG unsigned cg_num = gl_cg_num(); + if (cg_num) + return cg_num; +#endif - if (cg_num > num) - num = cg_num; +#ifdef HAVE_XML + unsigned glsl_num = gl_glsl_num(); + if (glsl_num) + return glsl_num; +#endif - return num; + return 0; } static bool gl_shader_filter_type(unsigned index, bool *smooth) { bool valid = false; + +#ifdef HAVE_CG if (!valid) valid = gl_cg_filter_type(index, smooth); +#endif + +#ifdef HAVE_XML + if (!valid) + valid = gl_glsl_filter_type(index, smooth); +#endif return valid; } void gl_set_fbo_enable (bool enable) { - gl_t *gl = g_gl; - - gl->fbo_enabled = enable; + ps3_gl.fbo_enabled = enable; } +#ifdef HAVE_FBO static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) { scale->valid = false; + +#ifdef HAVE_CG if (!scale->valid) gl_cg_shader_scale(index, scale); +#endif + +#ifdef HAVE_XML + if (!scale->valid) + gl_glsl_shader_scale(index, scale); +#endif } +#endif static void gl_create_fbo_textures(gl_t *gl) { @@ -191,7 +288,7 @@ static void gl_create_fbo_textures(gl_t *gl) void gl_deinit_fbo(gl_t *gl) { glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); + pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); memset(gl->fbo, 0, sizeof(gl->fbo)); gl->fbo_pass = 0; @@ -304,23 +401,23 @@ void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) gl_create_fbo_textures(gl); - glGenFramebuffersOES(gl->fbo_pass, gl->fbo); + pglGenFramebuffers(gl->fbo_pass, gl->fbo); for (int i = 0; i < gl->fbo_pass; i++) { - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); - glFramebufferTexture2DOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, gl->fbo_texture[i], 0); + pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); + pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0); - GLenum status = glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES); - if (status != GL_FRAMEBUFFER_COMPLETE_OES) + GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER); + if (status != GL_FRAMEBUFFER_COMPLETE) goto error; } - glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + pglBindFramebuffer(GL_FRAMEBUFFER, 0); return; error: glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - glDeleteFramebuffersOES(gl->fbo_pass, gl->fbo); + pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); RARCH_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n"); } @@ -379,8 +476,6 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height) uint32_t m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; GLfloat m_left, m_right, m_bottom, m_top, m_zNear, m_zFar; - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); m_viewport_x_temp = 0; m_viewport_y_temp = 0; @@ -427,14 +522,17 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height) glViewport(m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp); - if(gl->overscan_enable) + if(ps3_gl.overscan_enable) { - m_left = -gl->overscan_amount/2; - m_right = 1 + gl->overscan_amount/2; - m_bottom = -gl->overscan_amount/2; + m_left = -ps3_gl.overscan_amount/2; + m_right = 1 + ps3_gl.overscan_amount/2; + m_bottom = -ps3_gl.overscan_amount/2; } - glOrthof(m_left, m_right, m_bottom, m_top, m_zNear, m_zFar); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + glOrtho(m_left, m_right, m_bottom, m_top, m_zNear, m_zFar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -453,7 +551,7 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height) glMatrixMode(GL_PROJECTION); \ glLoadIdentity(); \ glViewport(0, 0, width, height); \ - glOrthof(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); \ + glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); \ glMatrixMode(GL_MODELVIEW); \ glLoadIdentity(); \ if (prg[active_index].mvp) \ @@ -494,7 +592,7 @@ void gl_frame_menu (void) set_viewport_force_full(gl, gl->win_width, gl->win_height); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + glBindTexture(GL_TEXTURE_2D, ps3_gl.menu_texture_id); glDrawArrays(GL_QUADS, 0, 4); @@ -523,6 +621,24 @@ static void ps3graphics_set_orientation(void * data, uint32_t orientation) glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); } +static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) +{ + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; + size_t buffer_stride = gl->tex_w * gl->base_size; + const uint8_t *frame_copy = frame; + size_t frame_copy_size = width * gl->base_size; + for (unsigned h = 0; h < height; h++) + { + glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, + buffer_addr, + frame_copy_size, + frame_copy); + + frame_copy += pitch; + buffer_addr += buffer_stride; + } +} + static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = data; @@ -533,11 +649,11 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); // Render to texture in first pass. - if (gl->fbo_enabled) + if (ps3_gl.fbo_enabled) { gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[0]); + pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); set_viewport_force_full(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height); } @@ -568,23 +684,10 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei // Need to preserve the "flipped" state when in FBO as well to have // consistent texture coordinates. - if (gl->fbo_enabled) + if (ps3_gl.fbo_enabled) glVertexPointer(2, GL_FLOAT, 0, vertexes); - size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; - size_t buffer_stride = gl->tex_w * gl->base_size; - const uint8_t *frame_copy = frame; - size_t frame_copy_size = width * gl->base_size; - for (unsigned h = 0; h < height; h++) - { - glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - buffer_addr, - frame_copy_size, - frame_copy); - - frame_copy += pitch; - buffer_addr += buffer_stride; - } + gl_copy_frame(gl, frame, width, height, pitch); struct gl_tex_info tex_info = { .tex = gl->texture[gl->tex_index], @@ -604,10 +707,12 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glDrawArrays(GL_QUADS, 0, 4); - if (gl->fbo_enabled) + if (ps3_gl.fbo_enabled) { + GLfloat fbo_tex_coords[8] = {0.0f}; + // Render the rest of our passes. - glTexCoordPointer(2, GL_FLOAT, 0, gl->fbo_tex_coords); + glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords); // It's kinda handy ... :) const struct gl_fbo_rect *prev_rect; @@ -624,16 +729,16 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - set_texture_coords(gl->fbo_tex_coords, xamt, yamt); + set_texture_coords(fbo_tex_coords, xamt, yamt); fbo_info->tex = gl->fbo_texture[i - 1]; fbo_info->input_size[0] = prev_rect->img_width; fbo_info->input_size[1] = prev_rect->img_height; fbo_info->tex_size[0] = prev_rect->width; fbo_info->tex_size[1] = prev_rect->height; - memcpy(fbo_info->coord, gl->fbo_tex_coords, sizeof(gl->fbo_tex_coords)); + memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); - glBindFramebufferOES(GL_FRAMEBUFFER_OES, gl->fbo[i]); + pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); gl_cg_use(i + 1); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); @@ -656,10 +761,10 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - set_texture_coords(gl->fbo_tex_coords, xamt, yamt); + set_texture_coords(fbo_tex_coords, xamt, yamt); // Render our FBO texture to back buffer. - glBindFramebufferOES(GL_FRAMEBUFFER_OES, 0); + pglBindFramebuffer(GL_FRAMEBUFFER, 0); gl_cg_use(gl->fbo_pass + 1); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); @@ -688,7 +793,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei cellDbgFontDraw(); } - if(!gl->block_swap) + if(!ps3_gl.block_swap) psglSwap(); return true; @@ -698,8 +803,8 @@ static void psgl_deinit(gl_t *gl) { cellDbgFontExit(); - psglDestroyContext(gl->gl_context); - psglDestroyDevice(gl->gl_device); + psglDestroyContext(ps3_gl.gl_context); + psglDestroyDevice(ps3_gl.gl_device); psglExit(); } @@ -780,8 +885,8 @@ static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resol params.height = resolution.height; } - gl->gl_device = psglCreateDeviceExtended(¶ms); - psglGetDeviceDimensions(gl->gl_device, &gl->win_width, &gl->win_height); + ps3_gl.gl_device = psglCreateDeviceExtended(¶ms); + psglGetDeviceDimensions(ps3_gl.gl_device, &gl->win_width, &gl->win_height); if(g_console.viewports.custom_vp.width == 0) g_console.viewports.custom_vp.width = gl->win_width; @@ -789,8 +894,8 @@ static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resol if(g_console.viewports.custom_vp.height == 0) g_console.viewports.custom_vp.height = gl->win_height; - gl->gl_context = psglCreateContext(); - psglMakeCurrent(gl->gl_context, gl->gl_device); + ps3_gl.gl_context = psglCreateContext(); + psglMakeCurrent(ps3_gl.gl_context, ps3_gl.gl_device); psglResetCurrentContext(); return true; @@ -966,8 +1071,7 @@ static bool gl_focus(void *data) static void ps3graphics_set_swap_block_swap(void * data, bool toggle) { (void)data; - gl_t *gl = g_gl; - gl->block_swap = toggle; + ps3_gl.block_swap = toggle; } static void ps3graphics_swap(void * data) @@ -1058,8 +1162,7 @@ static void get_all_available_resolutions (void) void ps3_set_resolution (void) { - gl_t *gl = g_gl; - cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &gl->g_video_state); + cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &ps3_gl.g_video_state); } void ps3_next_resolution (void) @@ -1117,27 +1220,27 @@ bool ps3_setup_texture(void) if (!gl) return false; - glGenTextures(1, &gl->menu_texture_id); + glGenTextures(1, &ps3_gl.menu_texture_id); RARCH_LOG("Loading texture image for menu...\n"); - if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &gl->menu_texture)) + if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &ps3_gl.menu_texture)) { RARCH_ERR("Failed to load texture image for menu.\n"); return false; } - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + glBindTexture(GL_TEXTURE_2D, ps3_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, gl->menu_texture.width, gl->menu_texture.height, 0, - GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, gl->menu_texture.pixels); + glTexImage2D(GL_TEXTURE_2D, 0, GL_ARGB_SCE, ps3_gl.menu_texture.width, ps3_gl.menu_texture.height, 0, + GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, ps3_gl.menu_texture.pixels); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - free(gl->menu_texture.pixels); + free(ps3_gl.menu_texture.pixels); return true; } @@ -1159,7 +1262,7 @@ void ps3_set_filtering(unsigned index, bool set_smooth) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); } } - else if (index >= 2 && gl->fbo_enabled) + else if (index >= 2 && ps3_gl.fbo_enabled) { glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); @@ -1175,8 +1278,8 @@ void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalcula if(!gl) return; - gl->overscan_enable = overscan_enable; - gl->overscan_amount = amount; + ps3_gl.overscan_enable = overscan_enable; + ps3_gl.overscan_amount = amount; if(recalculate_viewport) { @@ -1196,17 +1299,15 @@ void ps3graphics_video_init(bool get_all_resolutions) g_gl = gl_init(&video_info, NULL, NULL); gl_set_fbo_enable(g_console.fbo_enabled); - gl_t * gl = g_gl; - - gl->overscan_enable = g_console.overscan_enable; - gl->overscan_amount = g_console.overscan_amount; + ps3_gl.overscan_enable = g_console.overscan_enable; + ps3_gl.overscan_amount = g_console.overscan_amount; if(get_all_resolutions) get_all_available_resolutions(); ps3_set_resolution(); ps3_setup_texture(); - ps3graphics_set_overscan(gl->overscan_enable, gl->overscan_amount, 0); + ps3graphics_set_overscan(ps3_gl.overscan_enable, ps3_gl.overscan_amount, 0); } void ps3graphics_video_reinit(void) diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index c7c24d4883..190682d471 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -42,45 +42,6 @@ #define RARCH_CG_MAX_SHADERS 16 #define RARCH_CG_MENU_SHADER_INDEX (RARCH_CG_MAX_SHADERS - 1) -typedef struct gl -{ - bool block_swap; - bool fbo_enabled; - bool keep_aspect; - bool vsync; - bool overscan_enable; - 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 overscan_amount; - GLfloat tex_coords[8]; - GLfloat fbo_tex_coords[8]; - GLenum texture_type; /* XBGR1555 or ARGB*/ - GLenum texture_fmt; - /* 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; - bool ps3_setup_texture(void); const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); From f121f8d2bc1d81b9ce54318936802bba351414ec Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 15:59:22 +0200 Subject: [PATCH 022/103] Style nits. --- gfx/gl.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 64293b616e..f533320928 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -760,16 +760,17 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi #ifdef __CELLOS_LV2__ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { - size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; - size_t buffer_stride = gl->tex_w * gl->base_size; + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; + size_t buffer_stride = gl->tex_w * gl->base_size; const uint8_t *frame_copy = frame; - size_t frame_copy_size = width * gl->base_size; + size_t frame_copy_size = width * gl->base_size; + for (unsigned h = 0; h < height; h++) { glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - buffer_addr, - frame_copy_size, - frame_copy); + buffer_addr, + frame_copy_size, + frame_copy); frame_copy += pitch; buffer_addr += buffer_stride; From f873960224c02354173565acf721eb8a6d978ab1 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 16:01:59 +0200 Subject: [PATCH 023/103] init_textures for ps3. --- gfx/gl.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/gfx/gl.c b/gfx/gl.c index f533320928..8a3ecac804 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -776,6 +776,28 @@ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned buffer_addr += buffer_stride; } } + +static void gl_init_textures(gl_t *gl) +{ + glGenTextures(TEXTURES, gl->texture); + + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + + 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->tex_filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); + + glTextureReferenceSCE(GL_TEXTURE_2D, 1, + gl->tex_w, gl->tex_h, 0, + gl->texture_fmt, + gl->tex_w * gl->base_size, + gl->tex_w * gl->tex_h * i * gl->base_size); + } + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} #else static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { @@ -784,7 +806,6 @@ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned 0, 0, 0, width, height, gl->texture_type, gl->texture_fmt, frame); } -#endif static void gl_init_textures(gl_t *gl) { @@ -805,6 +826,7 @@ static void gl_init_textures(gl_t *gl) } glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } +#endif static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) { From 7ec17f14376a29f0c9ebf7bdfb069b2fba5755a1 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 15:57:59 +0200 Subject: [PATCH 024/103] (PS3) Cleanup ps3_video_psgl.h header --- ps3/ps3_video_psgl.h | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 190682d471..f8fff60d18 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -23,14 +23,12 @@ #include "../console/console_ext.h" #include -#define FBO_DEINIT 0 -#define FBO_INIT 1 -#define FBO_REINIT 2 - -#define MAX_SHADERS 16 - -#define TEXTURES 8 -#define TEXTURES_MASK (TEXTURES - 1) +enum +{ + FBO_DEINIT = 0, + FBO_INIT, + FBO_REINIT +}; #define MIN_SCALING_FACTOR (1.0f) #define MAX_SCALING_FACTOR (4.0f) @@ -39,9 +37,6 @@ #define IS_TIMER_EXPIRED(getter) (!(IS_TIMER_NOT_EXPIRED(getter))) #define SET_TIMER_EXPIRATION(setter, value) setter = g_frame_count + value; -#define RARCH_CG_MAX_SHADERS 16 -#define RARCH_CG_MENU_SHADER_INDEX (RARCH_CG_MAX_SHADERS - 1) - bool ps3_setup_texture(void); const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); From 7ddad8ade94bb875591214fb1556f7babe2de9de Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 16:09:43 +0200 Subject: [PATCH 025/103] (PS3) Streamline ps3_video_psgl.c with gl.c --- ps3/ps3_video_psgl.c | 77 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 62 insertions(+), 15 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 4ffe3cda40..e34d1ade2b 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -202,6 +202,51 @@ static bool gl_shader_init(void) return true; } +static void gl_shader_use(unsigned index) +{ +#ifdef HAVE_CG + gl_cg_use(index); +#endif + +#ifdef HAVE_XML + gl_glsl_use(index); +#endif +} + +static void gl_shader_deinit(void) +{ +#ifdef HAVE_CG + gl_cg_deinit(); +#endif + +#ifdef HAVE_XML + gl_glsl_deinit(); +#endif +} + +static void gl_shader_set_params(unsigned width, unsigned height, + unsigned tex_width, unsigned tex_height, + unsigned out_width, unsigned out_height, + unsigned frame_count, + const struct gl_tex_info *info, + const struct gl_tex_info *prev_info, + const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt) +{ +#ifdef HAVE_CG + gl_cg_set_params(width, height, + tex_width, tex_height, + out_width, out_height, + frame_count, info, prev_info, fbo_info, fbo_info_cnt); +#endif + +#ifdef HAVE_XML + gl_glsl_set_params(width, height, + tex_width, tex_height, + out_width, out_height, + frame_count, info, prev_info, fbo_info, fbo_info_cnt); +#endif +} + static unsigned gl_shader_num(void) { #ifdef HAVE_CG @@ -568,11 +613,13 @@ static void set_lut_texture_coords(const GLfloat *coords) pglClientActiveTexture(GL_TEXTURE0); } -#define set_texture_coords(coords, xamt, yamt) \ - coords[1] = yamt; \ - coords[4] = xamt; \ - coords[6] = xamt; \ +static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt) +{ + coords[1] = yamt; + coords[4] = xamt; + coords[6] = xamt; coords[7] = yamt; +} void gl_frame_menu (void) { @@ -583,9 +630,9 @@ void gl_frame_menu (void) if(!gl) return; - gl_cg_use(RARCH_CG_MENU_SHADER_INDEX); + gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); - gl_cg_set_params(gl->win_width, gl->win_height, gl->win_width, + gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, gl->win_height, gl->win_width, gl->win_height, g_frame_count, NULL, NULL, NULL, 0); @@ -643,7 +690,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei { gl_t *gl = data; - gl_cg_use(1); + gl_shader_use(1); g_frame_count++; glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); @@ -700,7 +747,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); glClear(GL_COLOR_BUFFER_BIT); - gl_cg_set_params(width, height, + gl_shader_set_params(width, height, gl->tex_w, gl->tex_h, gl->vp_width, gl->vp_height, g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); @@ -739,14 +786,14 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); - gl_cg_use(i + 1); + gl_shader_use(i + 1); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); glClear(GL_COLOR_BUFFER_BIT); // Render to FBO with certain size. set_viewport_force_full(gl, rect->img_width, rect->img_height); - gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, + gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); @@ -765,13 +812,13 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei // Render our FBO texture to back buffer. pglBindFramebuffer(GL_FRAMEBUFFER, 0); - gl_cg_use(gl->fbo_pass + 1); + gl_shader_use(gl->fbo_pass + 1); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); glClear(GL_COLOR_BUFFER_BIT); set_viewport(gl, gl->win_width, gl->win_height); - gl_cg_set_params(prev_rect->img_width, prev_rect->img_height, + gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); @@ -816,7 +863,7 @@ static void gl_free(void *data) gl_t *gl = data; - gl_cg_deinit(); + gl_shader_deinit(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); @@ -956,9 +1003,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_cg_use(0); + gl_shader_use(0); set_viewport(gl, gl->win_width, gl->win_height); - gl_cg_use(1); + gl_shader_use(1); set_viewport(gl, gl->win_width, gl->win_height); bool force_smooth = false; From 9e50b0a8bb0b4c3971b79df12ea6dc9fe2347aac Mon Sep 17 00:00:00 2001 From: Themaister Date: Sat, 26 May 2012 16:29:02 +0200 Subject: [PATCH 026/103] Make GL texture types more generic. --- gfx/gl.c | 16 +++++++++------- gfx/gl_common.h | 5 +++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 8a3ecac804..d7f907fa3e 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -317,8 +317,9 @@ static void gl_create_fbo_textures(gl_t *gl) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); glTexImage2D(GL_TEXTURE_2D, - 0, GL_RGBA, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_BGRA, - GL_UNSIGNED_INT_8_8_8_8, NULL); + 0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height, + 0, RARCH_GL_TEXTURE_TYPE, + RARCH_GL_FORMAT32, NULL); } glBindTexture(GL_TEXTURE_2D, 0); @@ -617,8 +618,9 @@ static void gl_check_fbo_dimensions(gl_t *gl) pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]); glTexImage2D(GL_TEXTURE_2D, - 0, GL_RGBA, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_BGRA, - GL_UNSIGNED_INT_8_8_8_8, NULL); + 0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height, + 0, RARCH_GL_TEXTURE_TYPE, + RARCH_GL_FORMAT32, NULL); pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0); @@ -821,7 +823,7 @@ static void gl_init_textures(gl_t *gl) glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); glTexImage2D(GL_TEXTURE_2D, - 0, GL_RGBA, gl->tex_w, gl->tex_h, 0, gl->texture_type, + 0, RARCH_GL_INTERNAL_FORMAT, gl->tex_w, gl->tex_h, 0, gl->texture_type, gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); } glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); @@ -1056,8 +1058,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo else gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST; - gl->texture_type = GL_BGRA; - gl->texture_fmt = video->rgb32 ? GL_UNSIGNED_INT_8_8_8_8_REV : GL_UNSIGNED_SHORT_1_5_5_5_REV; + gl->texture_type = RARCH_GL_TEXTURE_TYPE; + gl->texture_fmt = video->rgb32 ? RARCH_GL_FORMAT32 : RARCH_GL_FORMAT16; gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); glEnable(GL_TEXTURE_2D); diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 5f26255e12..9fff4ad516 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -192,4 +192,9 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #define pglActiveTexture glActiveTexture #endif +#define RARCH_GL_INTERNAL_FORMAT GL_RGBA +#define RARCH_GL_TEXTURE_TYPE GL_BGRA +#define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV +#define RARCH_GL_FORMAT16 GL_UNSIGNED_SHORT_1_5_5_5_REV + #endif From 87e850ea085f270591b3d4b5b6e62896ee16fc7d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 16:44:02 +0200 Subject: [PATCH 027/103] (PS3) Don't use global g_quitting anymore --- gfx/context/ps3_ctx.c | 18 ++++++++++++++++++ ps3/main.c | 3 ++- ps3/ps3_video_psgl.c | 23 +++++++++++++++++------ ps3/shared.h | 1 - 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 5b0831b390..b976108f9b 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -43,3 +43,21 @@ void gfx_ctx_set_swap_interval(unsigned interval, bool inited) if (!success) RARCH_WARN("Failed to set swap interval.\n"); } + +void gfx_ctx_check_window(bool *quit, + bool *resize, unsigned *width, unsigned *height, unsigned frame_count) +{ + *quit = false; + *resize = false; + gl_t *gl = driver.video_data; + +#ifdef HAVE_SYSUTILS + cellSysutilCheckCallback(); +#endif + + if(gl->quitting) + *quit = true; + + if(gl->should_resize) + *resize = true; +} diff --git a/ps3/main.c b/ps3/main.c index 2df04cd950..8c7c4cf96f 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -320,12 +320,13 @@ static void callback_sysutil_exit(uint64_t status, uint64_t param, void *userdat { (void) param; (void) userdata; + gl_t *gl = driver.video_data; switch (status) { case CELL_SYSUTIL_REQUEST_EXITGAME: g_console.menu_enable = false; - g_quitting = true; + gl->quitting = true; g_console.ingame_menu_enable = false; g_console.mode_switch = MODE_EXIT; break; diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index e34d1ade2b..d206ffbf34 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -110,7 +110,6 @@ struct { CellVideoOutState g_video_state; } ps3_gl; -bool g_quitting; unsigned g_frame_count; void *g_gl; @@ -621,6 +620,20 @@ static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yam coords[7] = yamt; } +static void check_window(gl_t *gl) +{ + bool quit, resize; + + gfx_ctx_check_window(&quit, + &resize, &gl->win_width, &gl->win_height, + gl->frame_count); + + if (quit) + gl->quitting = true; + else if (resize) + gl->should_resize = true; +} + void gl_frame_menu (void) { gl_t *gl = g_gl; @@ -1102,11 +1115,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo static bool gl_alive(void *data) { - (void)data; -#ifdef HAVE_SYSUTILS - cellSysutilCheckCallback(); -#endif - return !g_quitting; + gl_t *gl = (gl_t*)data; + check_window(gl); + return !gl->quitting; } static bool gl_focus(void *data) diff --git a/ps3/shared.h b/ps3/shared.h index 675329478b..d458a701e3 100644 --- a/ps3/shared.h +++ b/ps3/shared.h @@ -74,7 +74,6 @@ enum { #define MENU_ITEM_LAST MENU_ITEM_RETURN_TO_XMB+1 extern unsigned g_frame_count; -extern bool g_quitting; extern char contentInfoPath[MAX_PATH_LENGTH]; extern char usrDirPath[MAX_PATH_LENGTH]; From e34f6aa77440159978d0668d839e49b82a439edd Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 17:35:40 +0200 Subject: [PATCH 028/103] (PS3) Removed g_gl - will use pointer to driver.video_data from now on --- ps3/menu.c | 12 +++++++----- ps3/ps3_video_psgl.c | 25 ++++++++++++------------- ps3/ps3_video_psgl.h | 1 - 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ps3/menu.c b/ps3/menu.c index 4a57df5a0f..2f59a120ab 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -806,18 +806,20 @@ static void menu_reinit_settings (void) static void apply_scaling (unsigned init_mode) { + gl_t *gl = driver.video_data; + switch(init_mode) { case FBO_DEINIT: - gl_deinit_fbo(g_gl); + gl_deinit_fbo(gl); break; case FBO_INIT: - gl_init_fbo(g_gl, RARCH_SCALE_BASE * INPUT_SCALE, + gl_init_fbo(gl, RARCH_SCALE_BASE * INPUT_SCALE, RARCH_SCALE_BASE * INPUT_SCALE); break; case FBO_REINIT: - gl_deinit_fbo(g_gl); - gl_init_fbo(g_gl, RARCH_SCALE_BASE * INPUT_SCALE, + gl_deinit_fbo(gl); + gl_init_fbo(gl, RARCH_SCALE_BASE * INPUT_SCALE, RARCH_SCALE_BASE * INPUT_SCALE); break; } @@ -2024,6 +2026,7 @@ static void ingame_menu(uint32_t menu_id) static uint32_t menuitem_colors[MENU_ITEM_LAST]; uint64_t state, stuck_in_loop; static uint64_t blocking; + gl_t * gl = driver.video_data; float x_position = 0.3f; float font_size = 1.1f; @@ -2035,7 +2038,6 @@ static void ingame_menu(uint32_t menu_id) menuitem_colors[g_console.ingame_menu_item] = RED; - gl_t * gl = g_gl; state = cell_pad_input_poll_device(0); stuck_in_loop = 1; diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index d206ffbf34..78079f945d 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -111,7 +111,6 @@ struct { } ps3_gl; unsigned g_frame_count; -void *g_gl; #ifdef HAVE_FBO #if defined(_WIN32) && !defined(RARCH_CONSOLE) @@ -636,7 +635,7 @@ static void check_window(gl_t *gl) void gl_frame_menu (void) { - gl_t *gl = g_gl; + gl_t *gl = driver.video_data; g_frame_count++; @@ -871,7 +870,7 @@ static void psgl_deinit(gl_t *gl) static void gl_free(void *data) { - if (g_gl) + if (driver.video_data) return; gl_t *gl = data; @@ -973,8 +972,8 @@ static void psgl_init_dbgfont(gl_t *gl) static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - if (g_gl) - return g_gl; + if (driver.video_data) + return driver.video_data; gl_t *gl = calloc(1, sizeof(gl_t)); if (!gl) @@ -1144,7 +1143,7 @@ static void ps3graphics_swap(void * data) static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index) { (void)data; - gl_t * gl = g_gl; + gl_t * gl = driver.video_data; if(g_console.aspect_ratio_index == ASPECT_RATIO_AUTO) rarch_set_auto_viewport(g_extern.frame_cache.width, g_extern.frame_cache.height); @@ -1273,7 +1272,7 @@ const char * ps3_get_resolution_label(uint32_t resolution) bool ps3_setup_texture(void) { - gl_t *gl = g_gl; + gl_t *gl = driver.video_data; if (!gl) return false; @@ -1305,7 +1304,7 @@ bool ps3_setup_texture(void) void ps3_set_filtering(unsigned index, bool set_smooth) { - gl_t *gl = g_gl; + gl_t *gl = driver.video_data; if (!gl) return; @@ -1332,7 +1331,7 @@ void ps3_set_filtering(unsigned index, bool set_smooth) void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalculate_viewport) { - gl_t * gl = g_gl; + gl_t * gl = driver.video_data; if(!gl) return; @@ -1354,7 +1353,7 @@ void ps3graphics_video_init(bool get_all_resolutions) video_info.force_aspect = false; video_info.smooth = g_settings.video.smooth; video_info.input_scale = 2; - g_gl = gl_init(&video_info, NULL, NULL); + driver.video_data = gl_init(&video_info, NULL, NULL); gl_set_fbo_enable(g_console.fbo_enabled); ps3_gl.overscan_enable = g_console.overscan_enable; @@ -1370,7 +1369,7 @@ void ps3graphics_video_init(bool get_all_resolutions) void ps3graphics_video_reinit(void) { - gl_t * gl = g_gl; + gl_t * gl = driver.video_data; if(!gl) return; @@ -1382,8 +1381,8 @@ void ps3graphics_video_reinit(void) void ps3_video_deinit(void) { - void *data = g_gl; - g_gl = NULL; + void *data = driver.video_data; + driver.video_data = NULL; gl_free(data); } diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index f8fff60d18..0f7e0eb8c1 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -61,7 +61,6 @@ bool gl_cg_load_shader(unsigned index, const char *path); unsigned gl_cg_get_lut_info(struct gl_cg_lut_info *info, unsigned elems); -extern void *g_gl; extern unsigned g_frame_count; #endif From c40edf878c224492de3cdefa4e78926c59841bf9 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 18:18:09 +0200 Subject: [PATCH 029/103] (PS3) Removed g_frame_count - will use pointer to gl->frame_count --- gfx/context/ps3_ctx.c | 5 +++++ ps3/menu.c | 8 ++++++++ ps3/ps3_input.c | 2 ++ ps3/ps3_video_psgl.c | 16 +++++++--------- ps3/ps3_video_psgl.h | 6 ++---- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index b976108f9b..98ff177ec0 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -61,3 +61,8 @@ void gfx_ctx_check_window(bool *quit, if(gl->should_resize) *resize = true; } + +bool gfx_ctx_window_has_focus(void) +{ + return true; +} diff --git a/ps3/menu.c b/ps3/menu.c index 2f59a120ab..2bd01f3216 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -175,6 +175,7 @@ static uint64_t old_state = 0; static void set_delay_speed(unsigned delaymode) { unsigned speed; + gl_t * gl = driver.video_data; speed = 0; @@ -203,6 +204,7 @@ static void set_delay_speed(unsigned delaymode) static void browser_update(filebrowser_t * b) { uint64_t state, diff_state, button_was_pressed; + gl_t * gl = driver.video_data; state = cell_pad_input_poll_device(0); diff_state = old_state ^ state; @@ -830,6 +832,7 @@ static void select_file(uint32_t menu_id) char extensions[256], title[256], object[256], comment[256], dir_path[MAX_PATH_LENGTH], path[MAX_PATH_LENGTH], *separatorslash; uint64_t state, diff_state, button_was_pressed; + gl_t * gl = driver.video_data; state = cell_pad_input_poll_device(0); diff_state = old_state ^ state; @@ -972,6 +975,7 @@ static void select_directory(uint32_t menu_id) { char path[1024], newpath[1024], *separatorslash; uint64_t state, diff_state, button_was_pressed; + gl_t * gl = driver.video_data; state = cell_pad_input_poll_device(0); diff_state = old_state ^ state; @@ -1821,6 +1825,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) static void select_setting(menu * menu_obj) { uint64_t state, diff_state, button_was_pressed, i; + gl_t * gl = driver.video_data; state = cell_pad_input_poll_device(0); diff_state = old_state ^ state; @@ -1924,6 +1929,7 @@ static void select_rom(void) { char newpath[1024], *separatorslash; uint64_t state, diff_state, button_was_pressed; + gl_t * gl = driver.video_data; state = cell_pad_input_poll_device(0); diff_state = old_state ^ state; @@ -2539,6 +2545,8 @@ void menu_init (void) void menu_loop(void) { + gl_t * gl = driver.video_data; + menuStack[0] = menu_filebrowser; menuStack[0].enum_id = FILE_BROWSER_MENU; diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index f9fdc83cb3..e556d6176a 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -291,6 +291,8 @@ void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) static bool ps3_key_pressed(void *data, int key) { (void)data; + gl_t *gl = driver.video_data; + switch (key) { case RARCH_FAST_FORWARD_HOLD_KEY: diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 78079f945d..cadc2c0dce 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -110,8 +110,6 @@ struct { CellVideoOutState g_video_state; } ps3_gl; -unsigned g_frame_count; - #ifdef HAVE_FBO #if defined(_WIN32) && !defined(RARCH_CONSOLE) static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; @@ -637,7 +635,7 @@ void gl_frame_menu (void) { gl_t *gl = driver.video_data; - g_frame_count++; + gl->frame_count++; if(!gl) return; @@ -645,7 +643,7 @@ void gl_frame_menu (void) gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, - gl->win_height, gl->win_width, gl->win_height, g_frame_count, + gl->win_height, gl->win_width, gl->win_height, gl->frame_count, NULL, NULL, NULL, 0); set_viewport_force_full(gl, gl->win_width, gl->win_height); @@ -703,7 +701,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_t *gl = data; gl_shader_use(1); - g_frame_count++; + gl->frame_count++; glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); @@ -762,7 +760,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_shader_set_params(width, height, gl->tex_w, gl->tex_h, gl->vp_width, gl->vp_height, - g_frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); + gl->frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); glDrawArrays(GL_QUADS, 0, 4); @@ -807,7 +805,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei set_viewport_force_full(gl, rect->img_width, rect->img_height); gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, g_frame_count, + gl->vp_width, gl->vp_height, gl->frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); glDrawArrays(GL_QUADS, 0, 4); @@ -832,7 +830,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei set_viewport(gl, gl->win_width, gl->win_height); gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, g_frame_count, + gl->vp_width, gl->vp_height, gl->frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); @@ -1122,7 +1120,7 @@ static bool gl_alive(void *data) static bool gl_focus(void *data) { (void)data; - return true; + return gfx_ctx_window_has_focus(); } static void ps3graphics_set_swap_block_swap(void * data, bool toggle) diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 0f7e0eb8c1..bb13ccecec 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -33,9 +33,9 @@ enum #define MIN_SCALING_FACTOR (1.0f) #define MAX_SCALING_FACTOR (4.0f) -#define IS_TIMER_NOT_EXPIRED(getter) (g_frame_count < getter) +#define IS_TIMER_NOT_EXPIRED(getter) (gl->frame_count < getter) #define IS_TIMER_EXPIRED(getter) (!(IS_TIMER_NOT_EXPIRED(getter))) -#define SET_TIMER_EXPIRATION(setter, value) setter = g_frame_count + value; +#define SET_TIMER_EXPIRATION(setter, value) setter = gl->frame_count + value; bool ps3_setup_texture(void); const char * ps3_get_resolution_label(uint32_t resolution); @@ -61,6 +61,4 @@ bool gl_cg_load_shader(unsigned index, const char *path); unsigned gl_cg_get_lut_info(struct gl_cg_lut_info *info, unsigned elems); -extern unsigned g_frame_count; - #endif From 987d9c0b24e95aee2e7219b8d2baa6d6d043dbcc Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 20:25:37 +0200 Subject: [PATCH 030/103] (PS3) Use fbo_inited --- ps3/ps3_video_psgl.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index cadc2c0dce..c64f8b6386 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -100,7 +100,6 @@ static const GLfloat white_color[] = { struct { bool block_swap; - bool fbo_enabled; bool overscan_enable; GLfloat overscan_amount; GLuint menu_texture_id; @@ -279,7 +278,9 @@ static bool gl_shader_filter_type(unsigned index, bool *smooth) void gl_set_fbo_enable (bool enable) { - ps3_gl.fbo_enabled = enable; + gl_t *gl = driver.video_data; + gl->fbo_inited = enable; + gl->render_to_tex = false; } #ifdef HAVE_FBO @@ -328,11 +329,16 @@ static void gl_create_fbo_textures(gl_t *gl) void gl_deinit_fbo(gl_t *gl) { - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); - memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); - memset(gl->fbo, 0, sizeof(gl->fbo)); - gl->fbo_pass = 0; + if (gl->fbo_inited) + { + glDeleteTextures(gl->fbo_pass, gl->fbo_texture); + pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); + memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); + memset(gl->fbo, 0, sizeof(gl->fbo)); + gl->fbo_inited = false; + gl->render_to_tex = false; + gl->fbo_pass = 0; + } } // Horribly long and complex FBO init :D @@ -454,6 +460,8 @@ void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) } pglBindFramebuffer(GL_FRAMEBUFFER, 0); + + gl->fbo_inited = true; return; error: @@ -706,7 +714,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); // Render to texture in first pass. - if (ps3_gl.fbo_enabled) + if (gl->fbo_inited) { gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); @@ -741,7 +749,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei // Need to preserve the "flipped" state when in FBO as well to have // consistent texture coordinates. - if (ps3_gl.fbo_enabled) + if (gl->fbo_inited) glVertexPointer(2, GL_FLOAT, 0, vertexes); gl_copy_frame(gl, frame, width, height, pitch); @@ -764,7 +772,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glDrawArrays(GL_QUADS, 0, 4); - if (ps3_gl.fbo_enabled) + if (gl->fbo_inited) { GLfloat fbo_tex_coords[8] = {0.0f}; @@ -1317,7 +1325,7 @@ void ps3_set_filtering(unsigned index, bool set_smooth) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); } } - else if (index >= 2 && ps3_gl.fbo_enabled) + else if (index >= 2 && gl->fbo_inited) { glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); From dd101ff04aa0ba93a88e2143619679d422bc312b Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sat, 26 May 2012 20:51:36 +0200 Subject: [PATCH 031/103] (PS3) Updated set_viewport in ps3_video_psgl.c --- ps3/ps3_video_psgl.c | 49 ++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index c64f8b6386..bc4231c5fb 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -520,12 +520,11 @@ unsigned vp_width, unsigned vp_height) } } -static void set_viewport(gl_t *gl, unsigned width, unsigned height) +static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) { - uint32_t m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; + unsigned m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; GLfloat m_left, m_right, m_bottom, m_top, m_zNear, m_zFar; - m_viewport_x_temp = 0; m_viewport_y_temp = 0; m_viewport_width_temp = width; @@ -538,13 +537,12 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height) m_zNear = -1.0f; m_zFar = 1.0f; - if (gl->keep_aspect) + if (gl->keep_aspect && !force_full) { float desired_aspect = g_settings.video.aspect_ratio; float device_aspect = (float)width / height; float delta; - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) { delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; @@ -553,6 +551,11 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height) m_viewport_width_temp = g_console.viewports.custom_vp.width; m_viewport_height_temp = g_console.viewports.custom_vp.height; } + // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), + // assume they are actually equal. + else if (fabs(device_aspect - desired_aspect) < 0.0001) + { + } else if (device_aspect > desired_aspect) { delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; @@ -596,18 +599,6 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height) gl->vp_out_height = height; } -#define set_viewport_force_full(gl, width, height) \ - glMatrixMode(GL_PROJECTION); \ - glLoadIdentity(); \ - glViewport(0, 0, width, height); \ - glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f); \ - glMatrixMode(GL_MODELVIEW); \ - glLoadIdentity(); \ - if (prg[active_index].mvp) \ - cgGLSetStateMatrixParameter(prg[active_index].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); \ - gl->vp_width = width; \ - gl->vp_height = height; - static void set_lut_texture_coords(const GLfloat *coords) { // For texture images. @@ -654,7 +645,7 @@ void gl_frame_menu (void) gl->win_height, gl->win_width, gl->win_height, gl->frame_count, NULL, NULL, NULL, 0); - set_viewport_force_full(gl, gl->win_width, gl->win_height); + set_viewport(gl, gl->win_width, gl->win_height, true, false); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, ps3_gl.menu_texture_id); @@ -719,7 +710,14 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); - set_viewport_force_full(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height); + gl->render_to_tex = true; + set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false); + + // Need to preserve the "flipped" state when in FBO as well to have + // consistent texture coordinates. + // We will "flip" it in place on last pass. + if (gl->render_to_tex) + glVertexPointer(2, GL_FLOAT, 0, vertexes); } @@ -810,7 +808,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glClear(GL_COLOR_BUFFER_BIT); // Render to FBO with certain size. - set_viewport_force_full(gl, rect->img_width, rect->img_height); + set_viewport(gl, rect->img_width, rect->img_height, true, false); gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, gl->frame_count, @@ -835,7 +833,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); glClear(GL_COLOR_BUFFER_BIT); - set_viewport(gl, gl->win_width, gl->win_height); + gl->render_to_tex = false; + set_viewport(gl, gl->win_width, gl->win_height, false, true); gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, gl->frame_count, @@ -1022,9 +1021,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo // Apparently need to set viewport for passes when we aren't using FBOs. gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height); + set_viewport(gl, gl->win_width, gl->win_height, false, true); gl_shader_use(1); - set_viewport(gl, gl->win_width, gl->win_height); + set_viewport(gl, gl->win_width, gl->win_height, false, true); bool force_smooth = false; if (gl_shader_filter_type(1, &force_smooth)) @@ -1159,7 +1158,7 @@ static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index gl->keep_aspect = true; - set_viewport(gl, gl->win_width, gl->win_height); + set_viewport(gl, gl->win_width, gl->win_height, false, true); } const video_driver_t video_gl = @@ -1346,7 +1345,7 @@ void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalcula if(recalculate_viewport) { - set_viewport(gl, gl->win_width, gl->win_height); + set_viewport(gl, gl->win_width, gl->win_height, false, true); } } From 42bcc8ea5933e1fba4fa4d6bf854204d49363103 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 00:51:02 +0200 Subject: [PATCH 032/103] (PS3) Add HAVE_OPENGL_PBO and HAVE_CG_MENU defines --- Makefile.ps3 | 2 +- gfx/gl.c | 7 ++- ps3/ps3_video_psgl.c | 125 +++++++++++++++++++++++++++++-------------- ps3/ps3_video_psgl.h | 1 - 4 files changed, 92 insertions(+), 43 deletions(-) diff --git a/Makefile.ps3 b/Makefile.ps3 index 051f86e412..2e3031dc42 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -68,7 +68,7 @@ endif PPU_LDLIBS = -ldbgfont $(GL_LIBS) -lretro -lcgc -lgcm_cmd -lgcm_sys_stub -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysutil_np_stub -lpngdec_stub -ljpgdec_stub -lsysmodule_stub -laudio_stub -lnet_stub -lnetctl_stub -lpthread -DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGLES -DHAVE_CG -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) +DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_PBO -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) PPU_OPTIMIZE_LV := -O0 -g diff --git a/gfx/gl.c b/gfx/gl.c index d7f907fa3e..3837c01233 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1028,6 +1028,11 @@ 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); +#ifdef HAVE_CG_MENU + RARCH_LOG("Initializing menu shader...\n"); + gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); +#endif + if (!gl_shader_init()) { RARCH_ERR("Shader init failed.\n"); @@ -1084,7 +1089,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl->tex_w = RARCH_SCALE_BASE * video->input_scale; gl->tex_h = RARCH_SCALE_BASE * video->input_scale; -#ifdef __CELLOS_LV2__ +#ifdef HAVE_OPENGL_PBO glGenBuffers(1, &gl->pbo); glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index bc4231c5fb..758cc61b91 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -102,8 +102,10 @@ struct { bool block_swap; bool overscan_enable; GLfloat overscan_amount; +#ifdef HAVE_CG_MENU GLuint menu_texture_id; struct texture_image menu_texture; +#endif PSGLdevice* gl_device; PSGLcontext* gl_context; CellVideoOutState g_video_state; @@ -639,6 +641,7 @@ void gl_frame_menu (void) if(!gl) return; +#ifdef HAVE_CG_MENU gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, @@ -653,6 +656,7 @@ void gl_frame_menu (void) glDrawArrays(GL_QUADS, 0, 4); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +#endif } static void ps3graphics_set_orientation(void * data, uint32_t orientation) @@ -677,24 +681,77 @@ static void ps3graphics_set_orientation(void * data, uint32_t orientation) glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); } +#ifdef __CELLOS_LV2__ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { - size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; - size_t buffer_stride = gl->tex_w * gl->base_size; + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; + size_t buffer_stride = gl->tex_w * gl->base_size; const uint8_t *frame_copy = frame; - size_t frame_copy_size = width * gl->base_size; + size_t frame_copy_size = width * gl->base_size; + for (unsigned h = 0; h < height; h++) { glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - buffer_addr, - frame_copy_size, - frame_copy); + buffer_addr, + frame_copy_size, + frame_copy); frame_copy += pitch; buffer_addr += buffer_stride; } } +static void gl_init_textures(gl_t *gl) +{ + glGenTextures(TEXTURES, gl->texture); + + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + + 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->tex_filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); + + glTextureReferenceSCE(GL_TEXTURE_2D, 1, + gl->tex_w, gl->tex_h, 0, + gl->texture_fmt, + gl->tex_w * gl->base_size, + gl->tex_w * gl->tex_h * i * gl->base_size); + } + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} +#else +static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) +{ + glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size); + glTexSubImage2D(GL_TEXTURE_2D, + 0, 0, 0, width, height, gl->texture_type, + gl->texture_fmt, frame); +} + +static void gl_init_textures(gl_t *gl) +{ + glGenTextures(TEXTURES, gl->texture); + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + + 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->tex_filter); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); + + glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); + glTexImage2D(GL_TEXTURE_2D, + 0, RARCH_GL_INTERNAL_FORMAT, gl->tex_w, gl->tex_h, 0, gl->texture_type, + gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); + } + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} +#endif + static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = data; @@ -996,15 +1053,15 @@ 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); - RARCH_LOG("GL: Initializing debug fonts...\n"); - psgl_init_dbgfont(gl); +#ifdef HAVE_CG_MENU RARCH_LOG("Initializing menu shader...\n"); gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); +#endif if (!gl_shader_init()) { - RARCH_ERR("Menu shader initialization failed.\n"); + RARCH_ERR("Shader init failed.\n"); psgl_deinit(gl); free(gl); return NULL; @@ -1012,9 +1069,11 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo RARCH_LOG("GL: Loaded %u program(s).\n", gl_shader_num()); +#ifdef HAVE_FBO // Set up render to texture. gl_init_fbo(gl, RARCH_SCALE_BASE * video->input_scale, RARCH_SCALE_BASE * video->input_scale); +#endif gl->keep_aspect = video->force_aspect; @@ -1036,30 +1095,13 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); glEnable(GL_TEXTURE_2D); + glDisable(GL_DEPTH_TEST); + glDisable(GL_DITHER); glClearColor(0, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - gl->tex_w = RARCH_SCALE_BASE * video->input_scale; - gl->tex_h = RARCH_SCALE_BASE * video->input_scale; - glGenBuffers(1, &gl->pbo); - glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); - glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); - - glGenTextures(TEXTURES, gl->texture); - - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - - 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->tex_filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); - } - glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); @@ -1072,19 +1114,18 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo set_lut_texture_coords(tex_coords); + gl->tex_w = RARCH_SCALE_BASE * video->input_scale; + gl->tex_h = RARCH_SCALE_BASE * video->input_scale; + +#ifdef HAVE_OPENGL_PBO + glGenBuffers(1, &gl->pbo); + glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); + glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); +#endif + // Empty buffer that we use to clear out the texture with on res change. gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); - - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glTextureReferenceSCE(GL_TEXTURE_2D, 1, - gl->tex_w, gl->tex_h, 0, - gl->texture_fmt, - gl->tex_w * gl->base_size, - gl->tex_w * gl->tex_h * i * gl->base_size); - } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + gl_init_textures(gl); for (unsigned i = 0; i < TEXTURES; i++) { @@ -1102,6 +1143,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); } + psgl_init_dbgfont(gl); + if (!gl_check_error()) { psgl_deinit(gl); @@ -1275,13 +1318,14 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -bool ps3_setup_texture(void) +static bool ps3_setup_texture(void) { gl_t *gl = driver.video_data; if (!gl) return false; +#ifdef HAVE_CG_MENU glGenTextures(1, &ps3_gl.menu_texture_id); RARCH_LOG("Loading texture image for menu...\n"); @@ -1303,6 +1347,7 @@ bool ps3_setup_texture(void) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); free(ps3_gl.menu_texture.pixels); +#endif return true; } diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index bb13ccecec..1540cc720a 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -37,7 +37,6 @@ enum #define IS_TIMER_EXPIRED(getter) (!(IS_TIMER_NOT_EXPIRED(getter))) #define SET_TIMER_EXPIRATION(setter, value) setter = gl->frame_count + value; -bool ps3_setup_texture(void); const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); void gl_frame_menu(void); From 5d7056800355c90be52fb8425c9f29e2b7c04518 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 01:03:58 +0200 Subject: [PATCH 033/103] Micronit. --- gfx/gl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/gl.c b/gfx/gl.c index 3837c01233..d40920c321 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1029,7 +1029,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); #ifdef HAVE_CG_MENU - RARCH_LOG("Initializing menu shader...\n"); + RARCH_LOG("Initializing menu shader ...\n"); gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); #endif From e53db2303140470995e3a20ee81975386a32c37b Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 00:59:35 +0200 Subject: [PATCH 034/103] (PS3) Change HAVE_OPENGL_PBO to HAVE_OPENGL_TEXREF --- Makefile.ps3 | 2 +- gfx/gl.c | 2 +- ps3/ps3_video_psgl.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile.ps3 b/Makefile.ps3 index 2e3031dc42..d5468acb20 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -68,7 +68,7 @@ endif PPU_LDLIBS = -ldbgfont $(GL_LIBS) -lretro -lcgc -lgcm_cmd -lgcm_sys_stub -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysutil_np_stub -lpngdec_stub -ljpgdec_stub -lsysmodule_stub -laudio_stub -lnet_stub -lnetctl_stub -lpthread -DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_PBO -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) +DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_TEXREF -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) PPU_OPTIMIZE_LV := -O0 -g diff --git a/gfx/gl.c b/gfx/gl.c index d40920c321..e97069cf70 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1089,7 +1089,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl->tex_w = RARCH_SCALE_BASE * video->input_scale; gl->tex_h = RARCH_SCALE_BASE * video->input_scale; -#ifdef HAVE_OPENGL_PBO +#ifdef HAVE_OPENGL_TEXREF glGenBuffers(1, &gl->pbo); glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 758cc61b91..789c4b99b7 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1117,7 +1117,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl->tex_w = RARCH_SCALE_BASE * video->input_scale; gl->tex_h = RARCH_SCALE_BASE * video->input_scale; -#ifdef HAVE_OPENGL_PBO +#ifdef HAVE_OPENGL_TEXREF glGenBuffers(1, &gl->pbo); glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); From 4176ddecccea3818d309ab1908b1ff76ea256e40 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 01:16:55 +0200 Subject: [PATCH 035/103] Split up font code so that it's more portable --- Makefile | 2 +- gfx/context/font_freetype_ctx.c | 268 ++++++++++++++++++++++++++ gfx/context/font_ps3_libdgbfont_ctx.c | 35 ++++ gfx/gl_font.c | 243 +---------------------- gfx/gl_font.h | 4 + 5 files changed, 311 insertions(+), 241 deletions(-) create mode 100644 gfx/context/font_freetype_ctx.c create mode 100644 gfx/context/font_ps3_libdgbfont_ctx.c diff --git a/Makefile b/Makefile index 033fcbd993..b2ea0a09a9 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ ifeq ($(HAVE_SDL), 1) LIBS += $(SDL_LIBS) ifeq ($(HAVE_OPENGL), 1) - OBJ += gfx/gl.o gfx/gl_font.o + OBJ += gfx/gl.o gfx/gl_font.o gfx/context/font_freetype_ctx.o ifeq ($(OSX),1) LIBS += -framework OpenGL else diff --git a/gfx/context/font_freetype_ctx.c b/gfx/context/font_freetype_ctx.c new file mode 100644 index 0000000000..e47a730d7c --- /dev/null +++ b/gfx/context/font_freetype_ctx.c @@ -0,0 +1,268 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "../gl_common.h" + +void gl_init_font_ctx(gl_t *gl, const char *font_path, unsigned font_size) +{ +#ifdef HAVE_FREETYPE + if (!g_settings.video.font_enable) + return; + + const char *path = font_path; + if (!*path) + path = font_renderer_get_default_font(); + + if (path) + { + gl->font = font_renderer_new(path, font_size); + if (gl->font) + { + glGenTextures(1, &gl->font_tex); + glBindTexture(GL_TEXTURE_2D, gl->font_tex); + 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); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + } + else + RARCH_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path); + } + else + RARCH_LOG("Did not find default font.\n"); + + for (unsigned i = 0; i < 4; i++) + { + gl->font_color[4 * i + 0] = g_settings.video.msg_color_r; + gl->font_color[4 * i + 1] = g_settings.video.msg_color_g; + gl->font_color[4 * i + 2] = g_settings.video.msg_color_b; + gl->font_color[4 * i + 3] = 1.0; + } + + for (unsigned i = 0; i < 4; i++) + { + for (unsigned j = 0; j < 3; j++) + gl->font_color_dark[4 * i + j] = 0.3 * gl->font_color[4 * i + j]; + gl->font_color_dark[4 * i + 3] = 1.0; + } +#else + (void)gl; + (void)font_path; + (void)font_size; +#endif +} + +void gl_deinit_font_ctx(gl_t *gl) +{ +#ifdef HAVE_FREETYPE + if (gl->font) + { + font_renderer_free(gl->font); + glDeleteTextures(1, &gl->font_tex); + + if (gl->font_tex_empty_buf) + free(gl->font_tex_empty_buf); + } +#else + (void)gl; +#endif +} + +#ifdef HAVE_FREETYPE +// Somewhat overwhelming code just to render some damn fonts. +// We aim to use NPOT textures for compatibility with old and shitty cards. +// Also, we want to avoid reallocating a texture for each glyph (performance dips), so we +// contruct the whole texture using one call, and copy straight to it with +// glTexSubImage. + +struct font_rect +{ + int x, y; + int width, height; + int pot_width, pot_height; +}; + +static void calculate_msg_geometry(const struct font_output *head, struct font_rect *rect) +{ + int x_min = head->off_x; + int x_max = head->off_x + head->width; + int y_min = head->off_y; + int y_max = head->off_y + head->height; + + while ((head = head->next)) + { + int left = head->off_x; + int right = head->off_x + head->width; + int bottom = head->off_y; + int top = head->off_y + head->height; + + if (left < x_min) + x_min = left; + if (right > x_max) + x_max = right; + + if (bottom < y_min) + y_min = bottom; + if (top > y_max) + y_max = top; + } + + rect->x = x_min; + rect->y = y_min; + rect->width = x_max - x_min; + rect->height = y_max - y_min; +} + +static void adjust_power_of_two(gl_t *gl, struct font_rect *geom) +{ + // Some systems really hate NPOT textures. + geom->pot_width = next_pow2(geom->width); + geom->pot_height = next_pow2(geom->height); + + if ((geom->pot_width > gl->font_tex_w) || (geom->pot_height > gl->font_tex_h)) + { + gl->font_tex_empty_buf = realloc(gl->font_tex_empty_buf, geom->pot_width * geom->pot_height); + memset(gl->font_tex_empty_buf, 0, geom->pot_width * geom->pot_height); + + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + glPixelStorei(GL_UNPACK_ROW_LENGTH, geom->pot_width); + glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, geom->pot_width, geom->pot_height, + 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); + + gl->font_tex_w = geom->pot_width; + gl->font_tex_h = geom->pot_height; + } +} + +// Old style "blitting", so we can render all the fonts in one go. +// TODO: Is it possible that fonts could overlap if we blit without alpha blending? +static void blit_fonts(gl_t *gl, const struct font_output *head, const struct font_rect *geom) +{ + // Clear out earlier fonts. + glPixelStorei(GL_UNPACK_ALIGNMENT, 8); + glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->font_tex_w); + glTexSubImage2D(GL_TEXTURE_2D, + 0, 0, 0, gl->font_tex_w, gl->font_tex_h, + GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); + + while (head) + { + // head has top-left oriented coords. + int x = head->off_x - geom->x; + int y = head->off_y - geom->y; + y = gl->font_tex_h - head->height - y - 1; + + glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(head->pitch)); + glPixelStorei(GL_UNPACK_ROW_LENGTH, head->pitch); + glTexSubImage2D(GL_TEXTURE_2D, + 0, x, y, head->width, head->height, + GL_LUMINANCE, GL_UNSIGNED_BYTE, head->output); + + head = head->next; + } +} + +static void calculate_font_coords(gl_t *gl, + GLfloat font_vertex[8], GLfloat font_vertex_dark[8], GLfloat font_tex_coords[8]) +{ + GLfloat scale_factor = g_settings.video.font_scale ? + (GLfloat)gl->full_x / (GLfloat)gl->vp_width : + 1.0f; + + GLfloat lx = g_settings.video.msg_pos_x; + GLfloat hx = (GLfloat)gl->font_last_width / (gl->vp_width * scale_factor) + lx; + GLfloat ly = g_settings.video.msg_pos_y; + GLfloat hy = (GLfloat)gl->font_last_height / (gl->vp_height * scale_factor) + ly; + + font_vertex[0] = lx; + font_vertex[1] = ly; + font_vertex[2] = lx; + font_vertex[3] = hy; + font_vertex[4] = hx; + font_vertex[5] = hy; + font_vertex[6] = hx; + font_vertex[7] = ly; + + GLfloat shift_x = 2.0f / gl->vp_width; + GLfloat shift_y = 2.0f / gl->vp_height; + for (unsigned i = 0; i < 4; i++) + { + font_vertex_dark[2 * i + 0] = font_vertex[2 * i + 0] - shift_x; + font_vertex_dark[2 * i + 1] = font_vertex[2 * i + 1] - shift_y; + } + + lx = 0.0f; + hx = (GLfloat)gl->font_last_width / gl->font_tex_w; + ly = 1.0f - (GLfloat)gl->font_last_height / gl->font_tex_h; + hy = 1.0f; + + font_tex_coords[0] = lx; + font_tex_coords[1] = hy; + font_tex_coords[2] = lx; + font_tex_coords[3] = ly; + font_tex_coords[4] = hx; + font_tex_coords[5] = ly; + font_tex_coords[6] = hx; + font_tex_coords[7] = hy; +} +#endif + +void gl_render_msg_ctx(gl_t *gl, const char *msg) +{ +#ifdef HAVE_FREETYPE + if (!gl->font) + return; + + GLfloat font_vertex[8]; + GLfloat font_vertex_dark[8]; + GLfloat font_tex_coords[8]; + + glBindTexture(GL_TEXTURE_2D, gl->font_tex); + glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords); + + struct font_output_list out; + + // If we get the same message, there's obviously no need to render fonts again ... + if (strcmp(gl->font_last_msg, msg) != 0) + { + font_renderer_msg(gl->font, msg, &out); + struct font_output *head = out.head; + + struct font_rect geom; + calculate_msg_geometry(head, &geom); + adjust_power_of_two(gl, &geom); + blit_fonts(gl, head, &geom); + + font_renderer_free_output(&out); + strlcpy(gl->font_last_msg, msg, sizeof(gl->font_last_msg)); + + gl->font_last_width = geom.width; + gl->font_last_height = geom.height; + } + calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords); + + glVertexPointer(2, GL_FLOAT, 0, font_vertex_dark); + glColorPointer(4, GL_FLOAT, 0, gl->font_color_dark); + glDrawArrays(GL_QUADS, 0, 4); + glVertexPointer(2, GL_FLOAT, 0, font_vertex); + glColorPointer(4, GL_FLOAT, 0, gl->font_color); + glDrawArrays(GL_QUADS, 0, 4); +#else + (void)gl; + (void)msg; +#endif +} diff --git a/gfx/context/font_ps3_libdgbfont_ctx.c b/gfx/context/font_ps3_libdgbfont_ctx.c new file mode 100644 index 0000000000..0a791a6272 --- /dev/null +++ b/gfx/context/font_ps3_libdgbfont_ctx.c @@ -0,0 +1,35 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "../gl_common.h" + +void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) +{ + (void)gl; + (void)font_path; + (void)font_size; +} + +void gl_deinit_font_ctx(gl_t *gl) +{ + (void)gl; +} + +void gl_render_msg_ctx(gl_t *gl, const char *msg) +{ + (void)gl; + (void)msg; +} diff --git a/gfx/gl_font.c b/gfx/gl_font.c index 1ce34d164d..d6ce066d70 100644 --- a/gfx/gl_font.c +++ b/gfx/gl_font.c @@ -17,253 +17,16 @@ void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) { -#ifdef HAVE_FREETYPE - if (!g_settings.video.font_enable) - return; - - const char *path = font_path; - if (!*path) - path = font_renderer_get_default_font(); - - if (path) - { - gl->font = font_renderer_new(path, font_size); - if (gl->font) - { - glGenTextures(1, &gl->font_tex); - glBindTexture(GL_TEXTURE_2D, gl->font_tex); - 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); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - } - else - RARCH_WARN("Couldn't init font renderer with font \"%s\"...\n", font_path); - } - else - RARCH_LOG("Did not find default font.\n"); - - for (unsigned i = 0; i < 4; i++) - { - gl->font_color[4 * i + 0] = g_settings.video.msg_color_r; - gl->font_color[4 * i + 1] = g_settings.video.msg_color_g; - gl->font_color[4 * i + 2] = g_settings.video.msg_color_b; - gl->font_color[4 * i + 3] = 1.0; - } - - for (unsigned i = 0; i < 4; i++) - { - for (unsigned j = 0; j < 3; j++) - gl->font_color_dark[4 * i + j] = 0.3 * gl->font_color[4 * i + j]; - gl->font_color_dark[4 * i + 3] = 1.0; - } - -#else - (void)gl; - (void)font_path; - (void)font_size; -#endif + gl_init_font_ctx(gl, font_path, font_size); } void gl_deinit_font(gl_t *gl) { -#ifdef HAVE_FREETYPE - if (gl->font) - { - font_renderer_free(gl->font); - glDeleteTextures(1, &gl->font_tex); - - if (gl->font_tex_empty_buf) - free(gl->font_tex_empty_buf); - } -#else - (void)gl; -#endif + gl_deinit_font_ctx(gl); } -#ifdef HAVE_FREETYPE -// Somewhat overwhelming code just to render some damn fonts. -// We aim to use NPOT textures for compatibility with old and shitty cards. -// Also, we want to avoid reallocating a texture for each glyph (performance dips), so we -// contruct the whole texture using one call, and copy straight to it with -// glTexSubImage. - -struct font_rect -{ - int x, y; - int width, height; - int pot_width, pot_height; -}; - -static void calculate_msg_geometry(const struct font_output *head, struct font_rect *rect) -{ - int x_min = head->off_x; - int x_max = head->off_x + head->width; - int y_min = head->off_y; - int y_max = head->off_y + head->height; - - while ((head = head->next)) - { - int left = head->off_x; - int right = head->off_x + head->width; - int bottom = head->off_y; - int top = head->off_y + head->height; - - if (left < x_min) - x_min = left; - if (right > x_max) - x_max = right; - - if (bottom < y_min) - y_min = bottom; - if (top > y_max) - y_max = top; - } - - rect->x = x_min; - rect->y = y_min; - rect->width = x_max - x_min; - rect->height = y_max - y_min; -} - -static void adjust_power_of_two(gl_t *gl, struct font_rect *geom) -{ - // Some systems really hate NPOT textures. - geom->pot_width = next_pow2(geom->width); - geom->pot_height = next_pow2(geom->height); - - if ((geom->pot_width > gl->font_tex_w) || (geom->pot_height > gl->font_tex_h)) - { - gl->font_tex_empty_buf = realloc(gl->font_tex_empty_buf, geom->pot_width * geom->pot_height); - memset(gl->font_tex_empty_buf, 0, geom->pot_width * geom->pot_height); - - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - glPixelStorei(GL_UNPACK_ROW_LENGTH, geom->pot_width); - glTexImage2D(GL_TEXTURE_2D, 0, GL_INTENSITY8, geom->pot_width, geom->pot_height, - 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); - - gl->font_tex_w = geom->pot_width; - gl->font_tex_h = geom->pot_height; - } -} - -// Old style "blitting", so we can render all the fonts in one go. -// TODO: Is it possible that fonts could overlap if we blit without alpha blending? -static void blit_fonts(gl_t *gl, const struct font_output *head, const struct font_rect *geom) -{ - // Clear out earlier fonts. - glPixelStorei(GL_UNPACK_ALIGNMENT, 8); - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->font_tex_w); - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, gl->font_tex_w, gl->font_tex_h, - GL_LUMINANCE, GL_UNSIGNED_BYTE, gl->font_tex_empty_buf); - - while (head) - { - // head has top-left oriented coords. - int x = head->off_x - geom->x; - int y = head->off_y - geom->y; - y = gl->font_tex_h - head->height - y - 1; - - glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(head->pitch)); - glPixelStorei(GL_UNPACK_ROW_LENGTH, head->pitch); - glTexSubImage2D(GL_TEXTURE_2D, - 0, x, y, head->width, head->height, - GL_LUMINANCE, GL_UNSIGNED_BYTE, head->output); - - head = head->next; - } -} - -static void calculate_font_coords(gl_t *gl, - GLfloat font_vertex[8], GLfloat font_vertex_dark[8], GLfloat font_tex_coords[8]) -{ - GLfloat scale_factor = g_settings.video.font_scale ? - (GLfloat)gl->full_x / (GLfloat)gl->vp_width : - 1.0f; - - GLfloat lx = g_settings.video.msg_pos_x; - GLfloat hx = (GLfloat)gl->font_last_width / (gl->vp_width * scale_factor) + lx; - GLfloat ly = g_settings.video.msg_pos_y; - GLfloat hy = (GLfloat)gl->font_last_height / (gl->vp_height * scale_factor) + ly; - - font_vertex[0] = lx; - font_vertex[1] = ly; - font_vertex[2] = lx; - font_vertex[3] = hy; - font_vertex[4] = hx; - font_vertex[5] = hy; - font_vertex[6] = hx; - font_vertex[7] = ly; - - GLfloat shift_x = 2.0f / gl->vp_width; - GLfloat shift_y = 2.0f / gl->vp_height; - for (unsigned i = 0; i < 4; i++) - { - font_vertex_dark[2 * i + 0] = font_vertex[2 * i + 0] - shift_x; - font_vertex_dark[2 * i + 1] = font_vertex[2 * i + 1] - shift_y; - } - - lx = 0.0f; - hx = (GLfloat)gl->font_last_width / gl->font_tex_w; - ly = 1.0f - (GLfloat)gl->font_last_height / gl->font_tex_h; - hy = 1.0f; - - font_tex_coords[0] = lx; - font_tex_coords[1] = hy; - font_tex_coords[2] = lx; - font_tex_coords[3] = ly; - font_tex_coords[4] = hx; - font_tex_coords[5] = ly; - font_tex_coords[6] = hx; - font_tex_coords[7] = hy; -} -#endif void gl_render_msg(gl_t *gl, const char *msg) { -#ifdef HAVE_FREETYPE - if (!gl->font) - return; - - GLfloat font_vertex[8]; - GLfloat font_vertex_dark[8]; - GLfloat font_tex_coords[8]; - - glBindTexture(GL_TEXTURE_2D, gl->font_tex); - glTexCoordPointer(2, GL_FLOAT, 0, font_tex_coords); - - struct font_output_list out; - - // If we get the same message, there's obviously no need to render fonts again ... - if (strcmp(gl->font_last_msg, msg) != 0) - { - font_renderer_msg(gl->font, msg, &out); - struct font_output *head = out.head; - - struct font_rect geom; - calculate_msg_geometry(head, &geom); - adjust_power_of_two(gl, &geom); - blit_fonts(gl, head, &geom); - - font_renderer_free_output(&out); - strlcpy(gl->font_last_msg, msg, sizeof(gl->font_last_msg)); - - gl->font_last_width = geom.width; - gl->font_last_height = geom.height; - } - calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords); - - glVertexPointer(2, GL_FLOAT, 0, font_vertex_dark); - glColorPointer(4, GL_FLOAT, 0, gl->font_color_dark); - glDrawArrays(GL_QUADS, 0, 4); - glVertexPointer(2, GL_FLOAT, 0, font_vertex); - glColorPointer(4, GL_FLOAT, 0, gl->font_color); - glDrawArrays(GL_QUADS, 0, 4); -#else - (void)gl; - (void)msg; -#endif + gl_render_msg_ctx(gl, msg); } - diff --git a/gfx/gl_font.h b/gfx/gl_font.h index 9c512ecd35..5ee5c3ad8b 100644 --- a/gfx/gl_font.h +++ b/gfx/gl_font.h @@ -23,5 +23,9 @@ void gl_deinit_font(gl_t *gl); void gl_render_msg(gl_t *gl, const char *msg); +extern void gl_init_font_ctx(gl_t *gl, const char *font_path, unsigned font_size); +extern void gl_deinit_font_ctx(gl_t *gl); +extern void gl_render_msg_ctx(gl_t *gl, const char *msg); + #endif From ca0a5b9f76bb19be8423e984b6d65920950bcaf5 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 02:04:50 +0200 Subject: [PATCH 036/103] Move font stuff to gfx/fonts. --- Makefile | 4 +-- Makefile.win | 4 +-- gfx/context/ps3_ctx.c | 16 +++------- gfx/ext_gfx.c | 2 +- gfx/{ => fonts}/fonts.c | 2 +- gfx/{ => fonts}/fonts.h | 0 .../font_freetype_ctx.c => fonts/freetype.c} | 6 ++-- .../ps3_libdbgfont.c} | 5 +-- gfx/gl.c | 3 +- gfx/gl_common.h | 2 +- gfx/gl_font.c | 32 ------------------- gfx/sdl_gfx.c | 2 +- gfx/xvideo.c | 2 +- 13 files changed, 21 insertions(+), 59 deletions(-) rename gfx/{ => fonts}/fonts.c (99%) rename gfx/{ => fonts}/fonts.h (100%) rename gfx/{context/font_freetype_ctx.c => fonts/freetype.c} (98%) rename gfx/{context/font_ps3_libdgbfont_ctx.c => fonts/ps3_libdbgfont.c} (92%) delete mode 100644 gfx/gl_font.c diff --git a/Makefile b/Makefile index b2ea0a09a9..60f3f787d3 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ ifeq ($(HAVE_SDL), 1) LIBS += $(SDL_LIBS) ifeq ($(HAVE_OPENGL), 1) - OBJ += gfx/gl.o gfx/gl_font.o gfx/context/font_freetype_ctx.o + OBJ += gfx/gl.o gfx/fonts/freetype.o ifeq ($(OSX),1) LIBS += -framework OpenGL else @@ -147,7 +147,7 @@ ifeq ($(HAVE_DYLIB), 1) endif ifeq ($(HAVE_FREETYPE), 1) - OBJ += gfx/fonts.o + OBJ += gfx/fonts/fonts.o LIBS += $(FREETYPE_LIBS) DEFINES += $(FREETYPE_CFLAGS) endif diff --git a/Makefile.win b/Makefile.win index 9782ef8a81..3273443b52 100644 --- a/Makefile.win +++ b/Makefile.win @@ -39,7 +39,7 @@ ifeq ($(TDM_GCC),) endif ifeq ($(HAVE_SDL), 1) - OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/gl_font.o gfx/context/sdl_ctx.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o + OBJ += gfx/sdl_gfx.o gfx/gl.o gfx/fonts/freetype.o gfx/context/sdl_ctx.o input/sdl_input.o audio/sdl_audio.o fifo_buffer.o LIBS += -lSDL DEFINES += -ISDL -DHAVE_SDL endif @@ -100,7 +100,7 @@ ifeq ($(HAVE_NETPLAY), 1) endif ifeq ($(HAVE_FREETYPE), 1) - OBJ += gfx/fonts.o + OBJ += gfx/fonts/fonts.o DEFINES += -DHAVE_FREETYPE -Ifreetype2 LIBS += -lfreetype -lz endif diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 98ff177ec0..919b9e159e 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -28,37 +28,30 @@ void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { - bool success = false; - - if(inited) + if (inited) { - success = true; - if (interval) glEnable(GL_VSYNC_SCE); else glDisable(GL_VSYNC_SCE); } - - if (!success) - RARCH_WARN("Failed to set swap interval.\n"); } void gfx_ctx_check_window(bool *quit, bool *resize, unsigned *width, unsigned *height, unsigned frame_count) { + gl_t *gl = driver.video_data; *quit = false; *resize = false; - gl_t *gl = driver.video_data; #ifdef HAVE_SYSUTILS cellSysutilCheckCallback(); #endif - if(gl->quitting) + if (gl->quitting) *quit = true; - if(gl->should_resize) + if (gl->should_resize) *resize = true; } @@ -66,3 +59,4 @@ bool gfx_ctx_window_has_focus(void) { return true; } + diff --git a/gfx/ext_gfx.c b/gfx/ext_gfx.c index 574e98c29a..6f917bf0a3 100644 --- a/gfx/ext_gfx.c +++ b/gfx/ext_gfx.c @@ -25,7 +25,7 @@ #include "gfx_common.h" #ifdef HAVE_FREETYPE -#include "fonts.h" +#include "fonts/fonts.h" #endif #ifdef HAVE_PYTHON diff --git a/gfx/fonts.c b/gfx/fonts/fonts.c similarity index 99% rename from gfx/fonts.c rename to gfx/fonts/fonts.c index 98554056b6..c027a7133f 100644 --- a/gfx/fonts.c +++ b/gfx/fonts/fonts.c @@ -14,7 +14,7 @@ */ #include "fonts.h" -#include "../file.h" +#include "../../file.h" #include #include #include diff --git a/gfx/fonts.h b/gfx/fonts/fonts.h similarity index 100% rename from gfx/fonts.h rename to gfx/fonts/fonts.h diff --git a/gfx/context/font_freetype_ctx.c b/gfx/fonts/freetype.c similarity index 98% rename from gfx/context/font_freetype_ctx.c rename to gfx/fonts/freetype.c index e47a730d7c..53e5557414 100644 --- a/gfx/context/font_freetype_ctx.c +++ b/gfx/fonts/freetype.c @@ -16,7 +16,7 @@ #include "../gl_common.h" -void gl_init_font_ctx(gl_t *gl, const char *font_path, unsigned font_size) +void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) { #ifdef HAVE_FREETYPE if (!g_settings.video.font_enable) @@ -66,7 +66,7 @@ void gl_init_font_ctx(gl_t *gl, const char *font_path, unsigned font_size) #endif } -void gl_deinit_font_ctx(gl_t *gl) +void gl_deinit_font(gl_t *gl) { #ifdef HAVE_FREETYPE if (gl->font) @@ -221,7 +221,7 @@ static void calculate_font_coords(gl_t *gl, } #endif -void gl_render_msg_ctx(gl_t *gl, const char *msg) +void gl_render_msg(gl_t *gl, const char *msg) { #ifdef HAVE_FREETYPE if (!gl->font) diff --git a/gfx/context/font_ps3_libdgbfont_ctx.c b/gfx/fonts/ps3_libdbgfont.c similarity index 92% rename from gfx/context/font_ps3_libdgbfont_ctx.c rename to gfx/fonts/ps3_libdbgfont.c index 0a791a6272..9677153221 100644 --- a/gfx/context/font_ps3_libdgbfont_ctx.c +++ b/gfx/fonts/ps3_libdbgfont.c @@ -23,13 +23,14 @@ void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) (void)font_size; } -void gl_deinit_font_ctx(gl_t *gl) +void gl_deinit_font(gl_t *gl) { (void)gl; } -void gl_render_msg_ctx(gl_t *gl, const char *msg) +void gl_render_msg(gl_t *gl, const char *msg) { (void)gl; (void)msg; } + diff --git a/gfx/gl.c b/gfx/gl.c index e97069cf70..d76a2f1d88 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -46,9 +46,8 @@ #include "shader_glsl.h" #endif - #ifdef HAVE_FREETYPE -#include "fonts.h" +#include "fonts/fonts.h" #endif // Used for the last pass when rendering to the back buffer. diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 9fff4ad516..faed0c34c7 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -17,7 +17,7 @@ #define __GL_COMMON_H #include "../general.h" -#include "fonts.h" +#include "fonts/fonts.h" #ifdef HAVE_CONFIG_H #include "../config.h" diff --git a/gfx/gl_font.c b/gfx/gl_font.c deleted file mode 100644 index d6ce066d70..0000000000 --- a/gfx/gl_font.c +++ /dev/null @@ -1,32 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#include "gl_font.h" - -void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) -{ - gl_init_font_ctx(gl, font_path, font_size); -} - -void gl_deinit_font(gl_t *gl) -{ - gl_deinit_font_ctx(gl); -} - - -void gl_render_msg(gl_t *gl, const char *msg) -{ - gl_render_msg_ctx(gl, msg); -} diff --git a/gfx/sdl_gfx.c b/gfx/sdl_gfx.c index 93cbd3ce24..64dddcc882 100644 --- a/gfx/sdl_gfx.c +++ b/gfx/sdl_gfx.c @@ -26,7 +26,7 @@ #endif #ifdef HAVE_FREETYPE -#include "fonts.h" +#include "fonts/fonts.h" #endif static void convert_15bit_15bit_direct(uint16_t *out, unsigned outpitch, const uint16_t *input, unsigned width, unsigned height, unsigned pitch, const SDL_PixelFormat *fmt); diff --git a/gfx/xvideo.c b/gfx/xvideo.c index f86e316cf9..362a6df4a9 100644 --- a/gfx/xvideo.c +++ b/gfx/xvideo.c @@ -20,7 +20,7 @@ #include #include #ifdef HAVE_FREETYPE -#include "fonts.h" +#include "fonts/fonts.h" #endif #include "gfx_common.h" From 503f01867aa20acf5d0b2a32740a293770ce825f Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 04:02:07 +0200 Subject: [PATCH 037/103] (PS3) Use new font abstraction code --- console/griffin/griffin.c | 13 ++++++++-- gfx/fonts/ps3_libdbgfont.c | 14 +++++++--- gfx/gl.c | 7 +++++ ps3/ps3_video_psgl.c | 53 ++++++++++++++++++++++++++------------ 4 files changed, 65 insertions(+), 22 deletions(-) diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index fd07a557c5..36db2caa78 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -40,9 +40,12 @@ CONFIG FILE #include "func_hooks.h" + + /*============================================================ VIDEO ============================================================ */ + #if defined(__CELLOS_LV2__) #include "../../gfx/context/ps3_ctx.c" #include "../../gfx/shader_cg.c" @@ -55,10 +58,16 @@ VIDEO #include "../../wii/video.c" #endif -#if defined(_XBOX) +/*============================================================ +FONTS +============================================================ */ + +#if defined(__CELLOS_LV2__) +#include "../../gfx/fonts/ps3_libdbgfont.c" +#elif defined(_XBOX) #include "../../360/fonts.cpp" #elif defined(GEKKO) -#include "../../gfx/fonts.c" +#include "../../gfx/fonts/fonts.c" #endif /*============================================================ diff --git a/gfx/fonts/ps3_libdbgfont.c b/gfx/fonts/ps3_libdbgfont.c index 9677153221..51f4951987 100644 --- a/gfx/fonts/ps3_libdbgfont.c +++ b/gfx/fonts/ps3_libdbgfont.c @@ -18,19 +18,25 @@ void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) { - (void)gl; (void)font_path; (void)font_size; + CellDbgFontConfig cfg; + + memset(&cfg, 0, sizeof(cfg)); + cfg.bufSize = 512; + cfg.screenWidth = gl->win_width; + cfg.screenHeight = gl->win_height; + cellDbgFontInit(&cfg); } void gl_deinit_font(gl_t *gl) { - (void)gl; + cellDbgFontExit(); } void gl_render_msg(gl_t *gl, const char *msg) { - (void)gl; - (void)msg; + cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); + cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); } diff --git a/gfx/gl.c b/gfx/gl.c index d76a2f1d88..21fd6e90ed 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -855,6 +855,13 @@ static inline void gl_render_msg_post(gl_t *gl) glDisable(GL_BLEND); set_projection(gl, true); } +#elif defined(__CELLOS_LV2__) +static inline void gl_render_msg_pre(gl_t *gl) { } + +static inline void gl_render_msg_post(gl_t *gl) +{ + cellDbgFontDraw(); +} #else #define gl_render_msg_pre(...) #define gl_render_msg_post(...) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 789c4b99b7..1c976fa774 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -38,6 +38,7 @@ #include "config.h" #endif +#include "../gfx/gl_font.h" #include "../compat/strl.h" #define BLUE 0xffff0000u @@ -752,6 +753,37 @@ static void gl_init_textures(gl_t *gl) } #endif +#ifdef HAVE_FREETYPE +static inline void gl_render_msg_pre(gl_t *gl) +{ + gl_shader_use(0); + set_viewport(gl, gl->win_width, gl->win_height, false, false); + glEnable(GL_BLEND); +} + +static inline void gl_render_msg_post(gl_t *gl) +{ + // Go back to old rendering path. + glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); + glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); + glColorPointer(4, GL_FLOAT, 0, white_color); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + + glDisable(GL_BLEND); + set_projection(gl, true); +} +#elif defined(__CELLOS_LV2__) +static inline void gl_render_msg_pre(gl_t *gl) { } + +static inline void gl_render_msg_post(gl_t *gl) +{ + cellDbgFontDraw(); +} +#else +#define gl_render_msg_pre(...) +#define gl_render_msg_post(...) +#endif + static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = data; @@ -909,9 +941,9 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (msg) { - cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); - cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); - cellDbgFontDraw(); + gl_render_msg_pre(gl); + gl_render_msg(gl, msg); + gl_render_msg_post(gl); } if(!ps3_gl.block_swap) @@ -922,8 +954,6 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei static void psgl_deinit(gl_t *gl) { - cellDbgFontExit(); - psglDestroyContext(ps3_gl.gl_context); psglDestroyDevice(ps3_gl.gl_device); @@ -937,6 +967,7 @@ static void gl_free(void *data) gl_t *gl = data; + gl_deinit_font(gl); gl_shader_deinit(); glDisableClientState(GL_VERTEX_ARRAY); @@ -1022,16 +1053,6 @@ static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resol return true; } -static void psgl_init_dbgfont(gl_t *gl) -{ - CellDbgFontConfig cfg; - memset(&cfg, 0, sizeof(cfg)); - cfg.bufSize = 512; - cfg.screenWidth = gl->win_width; - cfg.screenHeight = gl->win_height; - cellDbgFontInit(&cfg); -} - static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { if (driver.video_data) @@ -1143,7 +1164,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); } - psgl_init_dbgfont(gl); + gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); if (!gl_check_error()) { From 7f13257d1ba9ec1ed528debb9ff37dd21d52a101 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 04:21:54 +0200 Subject: [PATCH 038/103] Move remaining FREETYPE/font code from gl.c to font files --- gfx/fonts/freetype.c | 18 ++++++++++++++ gfx/fonts/ps3_libdbgfont.c | 6 +++++ gfx/gl.c | 23 ++---------------- gfx/gl_font.h | 5 ++-- ps3/ps3_video_psgl.c | 49 ++++++++++++++++++++++---------------- 5 files changed, 57 insertions(+), 44 deletions(-) diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index 53e5557414..7014c8c28c 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -266,3 +266,21 @@ void gl_render_msg(gl_t *gl, const char *msg) (void)msg; #endif } + +void gl_render_msg_pre(gl_t *gl) +{ +#ifdef HAVE_FREETYPE +#ifdef HAVE_CG + gl_shader_use(0); +#endif + set_viewport(gl, gl->win_width, gl->win_height, false, false); + glEnable(GL_BLEND); +#endif +} + +void gl_render_msg_post(gl_t *gl) +{ +#ifdef HAVE_FREETYPE + gl_old_render_path(gl); +#endif +} diff --git a/gfx/fonts/ps3_libdbgfont.c b/gfx/fonts/ps3_libdbgfont.c index 51f4951987..ffee675870 100644 --- a/gfx/fonts/ps3_libdbgfont.c +++ b/gfx/fonts/ps3_libdbgfont.c @@ -40,3 +40,9 @@ void gl_render_msg(gl_t *gl, const char *msg) cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); } +void gl_render_msg_pre(gl_t *gl) { } + +void gl_render_msg_post(gl_t *gl) +{ + cellDbgFontDraw(); +} diff --git a/gfx/gl.c b/gfx/gl.c index 21fd6e90ed..2da9d6909a 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -445,7 +445,7 @@ static void set_projection(gl_t *gl, bool allow_rotate) gl_shader_set_proj_matrix(); } -static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) +void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) { if (gl->keep_aspect && !force_full) { @@ -836,15 +836,7 @@ static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; } -#ifdef HAVE_FREETYPE -static inline void gl_render_msg_pre(gl_t *gl) -{ - gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false, false); - glEnable(GL_BLEND); -} - -static inline void gl_render_msg_post(gl_t *gl) +void gl_old_render_path (gl_t *gl) { // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); @@ -855,17 +847,6 @@ static inline void gl_render_msg_post(gl_t *gl) glDisable(GL_BLEND); set_projection(gl, true); } -#elif defined(__CELLOS_LV2__) -static inline void gl_render_msg_pre(gl_t *gl) { } - -static inline void gl_render_msg_post(gl_t *gl) -{ - cellDbgFontDraw(); -} -#else -#define gl_render_msg_pre(...) -#define gl_render_msg_post(...) -#endif static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { diff --git a/gfx/gl_font.h b/gfx/gl_font.h index 5ee5c3ad8b..6fd286bafa 100644 --- a/gfx/gl_font.h +++ b/gfx/gl_font.h @@ -23,9 +23,8 @@ void gl_deinit_font(gl_t *gl); void gl_render_msg(gl_t *gl, const char *msg); -extern void gl_init_font_ctx(gl_t *gl, const char *font_path, unsigned font_size); -extern void gl_deinit_font_ctx(gl_t *gl); -extern void gl_render_msg_ctx(gl_t *gl, const char *msg); +void gl_render_msg_post(gl_t *gl); +void gl_render_msg_pre(gl_t *gl); #endif diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 1c976fa774..e17bd07fc1 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -222,6 +222,17 @@ static void gl_shader_deinit(void) #endif } +static void gl_shader_set_proj_matrix(void) +{ +#ifdef HAVE_CG + gl_cg_set_proj_matrix(); +#endif + +#ifdef HAVE_XML + gl_glsl_set_proj_matrix(); +#endif +} + static void gl_shader_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, unsigned out_width, unsigned out_height, @@ -473,6 +484,23 @@ error: RARCH_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n"); } +//////////// + +static void set_projection(gl_t *gl, bool allow_rotate) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + if (allow_rotate) + glRotatef(gl->rotation, 0, 0, 1); + + glOrtho(0, 1, 0, 1, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + gl_shader_set_proj_matrix(); +} + static inline void gl_compute_fbo_geometry(gl_t *gl, unsigned width, unsigned height, unsigned vp_width, unsigned vp_height) { @@ -753,15 +781,7 @@ static void gl_init_textures(gl_t *gl) } #endif -#ifdef HAVE_FREETYPE -static inline void gl_render_msg_pre(gl_t *gl) -{ - gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false, false); - glEnable(GL_BLEND); -} - -static inline void gl_render_msg_post(gl_t *gl) +void gl_old_render_path (gl_t *gl) { // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); @@ -772,17 +792,6 @@ static inline void gl_render_msg_post(gl_t *gl) glDisable(GL_BLEND); set_projection(gl, true); } -#elif defined(__CELLOS_LV2__) -static inline void gl_render_msg_pre(gl_t *gl) { } - -static inline void gl_render_msg_post(gl_t *gl) -{ - cellDbgFontDraw(); -} -#else -#define gl_render_msg_pre(...) -#define gl_render_msg_post(...) -#endif static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { From efa3bef5285ab1051d8a4be76e64fa4170667388 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 04:34:21 +0200 Subject: [PATCH 039/103] (PS3) Move header file include for libdbgfont --- gfx/fonts/ps3_libdbgfont.c | 1 + ps3/ps3_video_psgl.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/fonts/ps3_libdbgfont.c b/gfx/fonts/ps3_libdbgfont.c index ffee675870..51f22bd5d1 100644 --- a/gfx/fonts/ps3_libdbgfont.c +++ b/gfx/fonts/ps3_libdbgfont.c @@ -14,6 +14,7 @@ * If not, see . */ +#include #include "../gl_common.h" void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 1540cc720a..66271201d1 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -21,7 +21,6 @@ #include "../gfx/gfx_common.h" #include "../gfx/image.h" #include "../console/console_ext.h" -#include enum { From 8e17f8695e837e392c3e7ab64570932135362f35 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 12:26:43 +0200 Subject: [PATCH 040/103] Remove unneeded pre/post calls. --- gfx/fonts/freetype.c | 50 ++++++++++++++++++++++++------------ gfx/fonts/ps3_libdbgfont.c | 18 +++++-------- gfx/gl.c | 52 ++++++++++++-------------------------- gfx/gl_common.h | 4 +++ gfx/gl_font.h | 3 --- 5 files changed, 61 insertions(+), 66 deletions(-) diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index 7014c8c28c..6377948fa2 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -221,12 +221,44 @@ static void calculate_font_coords(gl_t *gl, } #endif +static void gl_render_msg_pre(gl_t *gl) +{ +#ifdef HAVE_FREETYPE + gl_shader_use(0); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); + glEnable(GL_BLEND); +#else + (void)gl; +#endif +} + +extern const GLfloat vertexes_flipped[]; +extern const GLfloat white_color[]; + +static void gl_render_msg_post(gl_t *gl) +{ +#ifdef HAVE_FREETYPE + // Go back to old rendering path. + glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); + glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); + glColorPointer(4, GL_FLOAT, 0, white_color); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + + glDisable(GL_BLEND); + gl_set_projection(gl, true); +#else + (void)gl; +#endif +} + void gl_render_msg(gl_t *gl, const char *msg) { #ifdef HAVE_FREETYPE if (!gl->font) return; + gl_render_msg_pre(gl); + GLfloat font_vertex[8]; GLfloat font_vertex_dark[8]; GLfloat font_tex_coords[8]; @@ -261,26 +293,12 @@ void gl_render_msg(gl_t *gl, const char *msg) glVertexPointer(2, GL_FLOAT, 0, font_vertex); glColorPointer(4, GL_FLOAT, 0, gl->font_color); glDrawArrays(GL_QUADS, 0, 4); + + gl_render_msg_post(gl); #else (void)gl; (void)msg; #endif } -void gl_render_msg_pre(gl_t *gl) -{ -#ifdef HAVE_FREETYPE -#ifdef HAVE_CG - gl_shader_use(0); -#endif - set_viewport(gl, gl->win_width, gl->win_height, false, false); - glEnable(GL_BLEND); -#endif -} -void gl_render_msg_post(gl_t *gl) -{ -#ifdef HAVE_FREETYPE - gl_old_render_path(gl); -#endif -} diff --git a/gfx/fonts/ps3_libdbgfont.c b/gfx/fonts/ps3_libdbgfont.c index 51f22bd5d1..445af60a56 100644 --- a/gfx/fonts/ps3_libdbgfont.c +++ b/gfx/fonts/ps3_libdbgfont.c @@ -21,12 +21,13 @@ void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size) { (void)font_path; (void)font_size; - CellDbgFontConfig cfg; - memset(&cfg, 0, sizeof(cfg)); - cfg.bufSize = 512; - cfg.screenWidth = gl->win_width; - cfg.screenHeight = gl->win_height; + CellDbgFontConfig cfg = { + .bufSize = 512, + .screenWidth = gl->win_width, + .screenHeight = gl->win_height, + }; + cellDbgFontInit(&cfg); } @@ -39,11 +40,6 @@ void gl_render_msg(gl_t *gl, const char *msg) { cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); -} - -void gl_render_msg_pre(gl_t *gl) { } - -void gl_render_msg_post(gl_t *gl) -{ cellDbgFontDraw(); } + diff --git a/gfx/gl.c b/gfx/gl.c index 2da9d6909a..d052f5c59f 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -46,12 +46,8 @@ #include "shader_glsl.h" #endif -#ifdef HAVE_FREETYPE -#include "fonts/fonts.h" -#endif - // Used for the last pass when rendering to the back buffer. -static const GLfloat vertexes_flipped[] = { +const GLfloat vertexes_flipped[] = { 0, 0, 0, 1, 1, 1, @@ -74,7 +70,7 @@ static const GLfloat tex_coords[] = { 1, 1 }; -static const GLfloat white_color[] = { +const GLfloat white_color[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -183,7 +179,7 @@ static bool gl_shader_init(void) return true; } -static void gl_shader_use(unsigned index) +void gl_shader_use(unsigned index) { #ifdef HAVE_CG gl_cg_use(index); @@ -430,7 +426,7 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) //////////// -static void set_projection(gl_t *gl, bool allow_rotate) +void gl_set_projection(gl_t *gl, bool allow_rotate) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); @@ -445,7 +441,7 @@ static void set_projection(gl_t *gl, bool allow_rotate) gl_shader_set_proj_matrix(); } -void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) +void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) { if (gl->keep_aspect && !force_full) { @@ -472,7 +468,7 @@ void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bo else glViewport(0, 0, width, height); - set_projection(gl, allow_rotate); + gl_set_projection(gl, allow_rotate); gl->vp_width = width; gl->vp_height = height; @@ -491,7 +487,7 @@ static void gl_set_rotation(void *data, unsigned rotation) { gl_t *gl = (gl_t*)data; gl->rotation = 90 * rotation; - set_projection(gl, true); + gl_set_projection(gl, true); } static inline void set_lut_texture_coords(const GLfloat *coords) @@ -590,7 +586,7 @@ static void gl_start_frame_fbo(gl_t *gl) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); gl->render_to_tex = true; - set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false); + gl_set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false); // Need to preserve the "flipped" state when in FBO as well to have // consistent texture coordinates. @@ -673,7 +669,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info) glClear(GL_COLOR_BUFFER_BIT); // Render to FBO with certain size. - set_viewport(gl, rect->img_width, rect->img_height, true, false); + gl_set_viewport(gl, rect->img_width, rect->img_height, true, false); gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, gl->frame_count, @@ -699,7 +695,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info) glClear(GL_COLOR_BUFFER_BIT); gl->render_to_tex = false; - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, prev_rect->width, prev_rect->height, gl->vp_width, gl->vp_height, gl->frame_count, @@ -716,7 +712,7 @@ static void gl_update_resize(gl_t *gl) { #ifdef HAVE_FBO if (!gl->render_to_tex) - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); else { gl_check_fbo_dimensions(gl); @@ -725,7 +721,7 @@ static void gl_update_resize(gl_t *gl) gl_start_frame_fbo(gl); } #else - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); #endif } @@ -836,18 +832,6 @@ static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; } -void gl_old_render_path (gl_t *gl) -{ - // Go back to old rendering path. - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); - glColorPointer(4, GL_FLOAT, 0, white_color); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - - glDisable(GL_BLEND); - set_projection(gl, true); -} - static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = (gl_t*)data; @@ -907,11 +891,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_next_texture_index(gl, &tex_info); if (msg) - { - gl_render_msg_pre(gl); gl_render_msg(gl, msg); - gl_render_msg_post(gl); - } gfx_ctx_update_window_title(false); gfx_ctx_swap_buffers(); @@ -1040,9 +1020,9 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo // Apparently need to set viewport for passes when we aren't using FBOs. gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); gl_shader_use(1); - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); bool force_smooth; if (gl_shader_filter_type(1, &force_smooth)) @@ -1150,9 +1130,9 @@ static bool gl_xml_shader(void *data, const char *path) // Apparently need to set viewport for passes when we aren't using FBOs. gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); gl_shader_use(1); - set_viewport(gl, gl->win_width, gl->win_height, false, true); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); return true; } diff --git a/gfx/gl_common.h b/gfx/gl_common.h index faed0c34c7..800e8b946c 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -197,4 +197,8 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV #define RARCH_GL_FORMAT16 GL_UNSIGNED_SHORT_1_5_5_5_REV +void gl_shader_use(unsigned); +void gl_set_projection(gl_t *gl, bool allow_rotate); +void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate); + #endif diff --git a/gfx/gl_font.h b/gfx/gl_font.h index 6fd286bafa..9c512ecd35 100644 --- a/gfx/gl_font.h +++ b/gfx/gl_font.h @@ -23,8 +23,5 @@ void gl_deinit_font(gl_t *gl); void gl_render_msg(gl_t *gl, const char *msg); -void gl_render_msg_post(gl_t *gl); -void gl_render_msg_pre(gl_t *gl); - #endif From 8e45e6bc4a299cf98be6922b4b06177b35df3fa0 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 12:28:16 +0200 Subject: [PATCH 041/103] Fix warnings on non-freetype builds. --- gfx/fonts/freetype.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index 6377948fa2..1125d9acc9 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -219,17 +219,13 @@ static void calculate_font_coords(gl_t *gl, font_tex_coords[6] = hx; font_tex_coords[7] = hy; } -#endif static void gl_render_msg_pre(gl_t *gl) { -#ifdef HAVE_FREETYPE gl_shader_use(0); gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); glEnable(GL_BLEND); -#else (void)gl; -#endif } extern const GLfloat vertexes_flipped[]; @@ -237,7 +233,6 @@ extern const GLfloat white_color[]; static void gl_render_msg_post(gl_t *gl) { -#ifdef HAVE_FREETYPE // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); @@ -246,10 +241,8 @@ static void gl_render_msg_post(gl_t *gl) glDisable(GL_BLEND); gl_set_projection(gl, true); -#else - (void)gl; -#endif } +#endif void gl_render_msg(gl_t *gl, const char *msg) { From e1a3bf48fd89993106725b9101eaee84f157e6d5 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 12:38:07 +0200 Subject: [PATCH 042/103] Use correlating ifdef. --- gfx/gl.c | 5 +++-- gfx/gl_common.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index d052f5c59f..48d1bdf071 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -910,7 +910,7 @@ static void gl_free(void *data) glDisableClientState(GL_COLOR_ARRAY); glDeleteTextures(TEXTURES, gl->texture); -#ifdef __CELLOS_LV2__ +#ifdef HAVE_OPENGL_TEXREF glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0); glDeleteBuffers(1, &gl->pbo); #endif @@ -1059,7 +1059,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo #ifdef HAVE_OPENGL_TEXREF glGenBuffers(1, &gl->pbo); glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); - glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); + glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, + gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); #endif // Empty buffer that we use to clear out the texture with on res change. diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 800e8b946c..2c48ac9227 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -197,7 +197,7 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV #define RARCH_GL_FORMAT16 GL_UNSIGNED_SHORT_1_5_5_5_REV -void gl_shader_use(unsigned); +void gl_shader_use(unsigned index); void gl_set_projection(gl_t *gl, bool allow_rotate); void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate); From 0375de48a2007f73556341e5d84632c208765d01 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:12:29 +0200 Subject: [PATCH 043/103] Add preliminary network command interface. --- Makefile | 2 +- Makefile.win | 2 +- config.def.h | 4 ++ driver.h | 23 +++++- general.h | 4 ++ netplay.c | 32 +-------- netplay.h | 1 + netplay_compat.h | 32 +++++++-- network_cmd.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++ network_cmd.h | 32 +++++++++ retroarch.c | 26 +++++++ retroarch.cfg | 4 ++ settings.c | 5 ++ 13 files changed, 308 insertions(+), 38 deletions(-) create mode 100644 network_cmd.c create mode 100644 network_cmd.h diff --git a/Makefile b/Makefile index 60f3f787d3..ef6b41255d 100644 --- a/Makefile +++ b/Makefile @@ -46,7 +46,7 @@ ifeq ($(HAVE_BSV_MOVIE), 1) endif ifeq ($(HAVE_NETPLAY), 1) - OBJ += netplay.o + OBJ += netplay.o network_cmd.o endif ifeq ($(HAVE_RSOUND), 1) diff --git a/Makefile.win b/Makefile.win index 3273443b52..4ce79a2b52 100644 --- a/Makefile.win +++ b/Makefile.win @@ -95,7 +95,7 @@ endif ifeq ($(HAVE_NETPLAY), 1) DEFINES += -DHAVE_NETPLAY - OBJ += netplay.o + OBJ += netplay.o network_cmd.o LIBS += -lws2_32 endif diff --git a/config.def.h b/config.def.h index b2178a6172..f1f22da4df 100644 --- a/config.def.h +++ b/config.def.h @@ -280,6 +280,10 @@ static const bool savestate_auto_index = false; // Slowmotion ratio. static const float slowmotion_ratio = 3.0; +// Enable network command interface +static const bool network_cmd_enable = false; +static const uint16_t network_cmd_port = 55355; + //////////////////// // Keybinds, Joypad diff --git a/driver.h b/driver.h index 0666597ba0..f52a6f7231 100644 --- a/driver.h +++ b/driver.h @@ -24,6 +24,14 @@ #include "msvc/msvc_compat.h" #include "input/keysym.h" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#ifdef HAVE_NETPLAY +#include "network_cmd.h" +#endif + #define AUDIO_CHUNK_SIZE_BLOCKING 64 #define AUDIO_CHUNK_SIZE_NONBLOCKING 2048 // So we don't get complete line-noise when fast-forwarding audio. #define AUDIO_MAX_RATIO 16 @@ -167,6 +175,10 @@ typedef struct driver void *audio_data; void *video_data; void *input_data; + +#ifdef HAVE_NETPLAY + network_cmd_t *network_cmd; +#endif } driver_t; void init_drivers(void); @@ -243,8 +255,17 @@ extern const input_driver_t input_xdk360; #define input_poll_func() driver.input->poll(driver.input_data) #define input_input_state_func(snes_keybinds, port, device, index, id) \ driver.input->input_state(driver.input_data, snes_keybinds, port, device, index, id) -#define input_key_pressed_func(key) driver.input->key_pressed(driver.input_data, key) #define input_free_func() driver.input->free(driver.input_data) + +static inline bool input_key_pressed_func(int key) +{ + bool ret = driver.input->key_pressed(driver.input_data, key); +#ifdef HAVE_NETPLAY + if (!ret && driver.network_cmd) + ret = network_cmd_get(driver.network_cmd, key); +#endif + return ret; +} #endif #endif diff --git a/general.h b/general.h index 154e69efd7..a0a20e80b4 100644 --- a/general.h +++ b/general.h @@ -53,6 +53,7 @@ #ifdef HAVE_NETPLAY #include "netplay.h" +#include "network_cmd.h" #endif #include "audio/resampler.h" @@ -177,6 +178,9 @@ struct settings bool block_sram_overwrite; bool savestate_auto_index; + + bool network_cmd_enable; + uint16_t network_cmd_port; }; // Settings and/or global state that is specific to a console-style implementation. diff --git a/netplay.c b/netplay.c index f94bf0beb1..9c977b9097 100644 --- a/netplay.c +++ b/netplay.c @@ -13,35 +13,7 @@ * If not, see . */ -#if defined(_WIN32) && !defined(_XBOX) -#ifndef _WIN32_WINNT -#define _WIN32_WINNT 0x0501 -#endif -#define WIN32_LEAN_AND_MEAN -#include -#include -#include -#elif defined(_XBOX) -#define NOD3D -#include -#else -#include -#include -#include -#include -#include -#include -#include - -#ifdef __CELLOS_LV2__ -#include -#include -#else -#include -#endif - -#endif - +#include "netplay_compat.h" #include "netplay.h" #include "general.h" #include "autosave.h" @@ -50,8 +22,6 @@ #include #include -#include "netplay_compat.h" - // Checks if input port/index is controlled by netplay or not. static bool netplay_is_alive(netplay_t *handle); diff --git a/netplay.h b/netplay.h index 9b2c110fd9..5da2df58aa 100644 --- a/netplay.h +++ b/netplay.h @@ -57,3 +57,4 @@ void netplay_pre_frame(netplay_t *handle); void netplay_post_frame(netplay_t *handle); #endif + diff --git a/netplay_compat.h b/netplay_compat.h index ad0cc901e4..2b114c88e1 100644 --- a/netplay_compat.h +++ b/netplay_compat.h @@ -20,6 +20,34 @@ #include "config.h" #endif +#if defined(_WIN32) && !defined(_XBOX) +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0501 +#endif +#define WIN32_LEAN_AND_MEAN +#include +#include +#include +#elif defined(_XBOX) +#define NOD3D +#include +#else +#include +#include +#include +#include +#include +#include +#include + +#ifdef __CELLOS_LV2__ +#include +#include +#else +#include +#endif +#endif + #ifdef _XBOX #define socklen_t int #endif @@ -29,9 +57,7 @@ #define close(x) closesocket(x) #define CONST_CAST (const char*) #define NONCONST_CAST (char*) - #else - #define CONST_CAST #define NONCONST_CAST #include @@ -41,7 +67,6 @@ #define close(x) socketclose(x) #define select(nfds, readfds, writefds, errorfds, timeout) socketselect(nfds, readfds, writefds, errorfds, timeout) #endif - #endif // Compatibility layer for legacy or incomplete BSD socket implementations. @@ -80,6 +105,5 @@ void freeaddrinfo(struct addrinfo *res); // gai_strerror() not used, so we skip that. #endif - #endif diff --git a/network_cmd.c b/network_cmd.c new file mode 100644 index 0000000000..51b67c1d78 --- /dev/null +++ b/network_cmd.c @@ -0,0 +1,179 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "netplay_compat.h" +#include "network_cmd.h" +#include "driver.h" +#include "general.h" +#include +#include + +struct network_cmd +{ + int fd; + bool state[RARCH_BIND_LIST_END]; +}; + +network_cmd_t *network_cmd_new(uint16_t port) +{ + network_cmd_t *handle = (network_cmd_t*)calloc(1, sizeof(*handle)); + if (!handle) + return NULL; + + handle->fd = -1; + + struct addrinfo hints, *res = NULL; + memset(&hints, 0, sizeof(hints)); +#if defined(_WIN32) || defined(HAVE_SOCKET_LEGACY) + hints.ai_family = AF_INET; +#else + hints.ai_family = AF_UNSPEC; +#endif + hints.ai_socktype = SOCK_DGRAM; + hints.ai_flags = AI_PASSIVE; + + char port_buf[16]; + int yes = 1; + + snprintf(port_buf, sizeof(port_buf), "%hu", (unsigned short)port); + if (getaddrinfo(NULL, port_buf, &hints, &res) < 0) + goto error; + + handle->fd = socket(res->ai_family, res->ai_socktype | SOCK_NONBLOCK, res->ai_protocol); + if (handle->fd < 0) + goto error; + + setsockopt(handle->fd, SOL_SOCKET, SO_REUSEADDR, CONST_CAST &yes, sizeof(int)); + if (bind(handle->fd, res->ai_addr, res->ai_addrlen) < 0) + { + RARCH_ERR("Failed to bind socket.\n"); + goto error; + } + + freeaddrinfo(res); + + return handle; + +error: + if (res) + freeaddrinfo(res); + network_cmd_free(handle); + return NULL; +} + +void network_cmd_free(network_cmd_t *handle) +{ + if (handle->fd >= 0) + close(handle->fd); + + free(handle); +} + +struct cmd_map +{ + const char *str; + unsigned id; +}; + +static const struct cmd_map map[] = { + { "FAST_FORWARD", RARCH_FAST_FORWARD_KEY }, + { "FAST_FORWARD_HOLD", RARCH_FAST_FORWARD_HOLD_KEY }, + { "LOAD_STATE", RARCH_LOAD_STATE_KEY }, + { "SAVE_STATE", RARCH_SAVE_STATE_KEY }, + { "FULLSCREEN_TOGGLE", RARCH_FULLSCREEN_TOGGLE_KEY }, + { "QUIT", RARCH_QUIT_KEY }, + { "STATE_SLOT_PLUS", RARCH_STATE_SLOT_PLUS }, + { "STATE_SLOT_MINUS", RARCH_STATE_SLOT_MINUS }, + { "AUDIO_INPUT_RATE_PLUS", RARCH_AUDIO_INPUT_RATE_PLUS }, + { "AUDIO_INPUT_RATE_MINUS", RARCH_AUDIO_INPUT_RATE_MINUS }, + { "REWIND", RARCH_REWIND }, + { "MOVIE_RECORD_TOGGLE", RARCH_MOVIE_RECORD_TOGGLE }, + { "PAUSE_TOGGLE", RARCH_PAUSE_TOGGLE }, + { "FRAMEADVANCE", RARCH_FRAMEADVANCE }, + { "RESET", RARCH_RESET }, + { "SHADER_NEXT", RARCH_SHADER_NEXT }, + { "SHADER_PREV", RARCH_SHADER_PREV }, + { "CHEAT_INDEX_PLUS", RARCH_CHEAT_INDEX_PLUS }, + { "CHEAT_INDEX_MINUS", RARCH_CHEAT_INDEX_MINUS }, + { "CHEAT_TOGGLE", RARCH_CHEAT_TOGGLE }, + { "SCREENSHOT", RARCH_SCREENSHOT }, + { "DSP_CONFIG", RARCH_DSP_CONFIG }, + { "MUTE", RARCH_MUTE }, + { "NETPLAY_FLIP", RARCH_NETPLAY_FLIP }, + { "SLOWMOTION", RARCH_SLOWMOTION }, +}; + +static void parse_sub_msg(network_cmd_t *handle, const char *tok) +{ + for (unsigned i = 0; i < sizeof(map) / sizeof(map[0]); i++) + { + if (strcmp(tok, map[i].str) == 0) + { + handle->state[map[i].id] = true; + return; + } + } + + RARCH_WARN("Unrecognized command \"%s\" received.\n", tok); +} + +static void parse_msg(network_cmd_t *handle, char *buf) +{ + const char *tok = strtok(buf, "\n"); + while (tok) + { + parse_sub_msg(handle, tok); + tok = strtok(NULL, "\n"); + } +} + +void network_cmd_set(network_cmd_t *handle, unsigned id) +{ + if (id < RARCH_BIND_LIST_END) + handle->state[id] = true; +} + +bool network_cmd_get(network_cmd_t *handle, unsigned id) +{ + return id < RARCH_BIND_LIST_END && handle->state[id]; +} + +void network_cmd_pre_frame(network_cmd_t *handle) +{ + memset(handle->state, 0, sizeof(handle->state)); + + fd_set fds; + FD_ZERO(&fds); + FD_SET(handle->fd, &fds); + + struct timeval tmp_tv = {0}; + if (select(handle->fd + 1, &fds, NULL, NULL, &tmp_tv) <= 0) + return; + + if (!FD_ISSET(handle->fd, &fds)) + return; + + for (;;) + { + char buf[1024]; + ssize_t ret = recvfrom(handle->fd, buf, sizeof(buf) - 1, 0, NULL, NULL); + if (ret <= 0) + break; + + buf[ret] = '\0'; + parse_msg(handle, buf); + } +} + diff --git a/network_cmd.h b/network_cmd.h new file mode 100644 index 0000000000..fd19f6a305 --- /dev/null +++ b/network_cmd.h @@ -0,0 +1,32 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef NETWORK_CMD_H__ +#define NETWORK_CMD_H__ + +#include +#include + +typedef struct network_cmd network_cmd_t; + +network_cmd_t *network_cmd_new(uint16_t port); +void network_cmd_free(network_cmd_t *handle); + +void network_cmd_pre_frame(network_cmd_t *handle); +void network_cmd_set(network_cmd_t *handle, unsigned id); +bool network_cmd_get(network_cmd_t *handle, unsigned id); + +#endif + diff --git a/retroarch.c b/retroarch.c index 17a04db351..176b33da0a 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1337,6 +1337,25 @@ static void deinit_netplay(void) if (g_extern.netplay) netplay_free(g_extern.netplay); } + +static void init_network_cmd(void) +{ + if (!g_settings.network_cmd_enable) + return; + + driver.network_cmd = network_cmd_new(g_settings.network_cmd_port); + if (!driver.network_cmd) + RARCH_ERR("Failed to initialize network command interface.\n"); +} + +static void deinit_network_cmd(void) +{ + if (driver.network_cmd) + { + network_cmd_free(driver.network_cmd); + driver.network_cmd = NULL; + } +} #endif static void init_libretro_cbs_plain(void) @@ -2353,6 +2372,7 @@ int rarch_main_init(int argc, char *argv[]) #ifdef HAVE_NETPLAY init_netplay(); + init_network_cmd(); #endif init_drivers(); @@ -2427,6 +2447,11 @@ bool rarch_main_iterate(void) !video_alive_func()) return false; +#ifdef HAVE_NETPLAY + if (driver.network_cmd) + network_cmd_pre_frame(driver.network_cmd); +#endif + // Checks for stuff like fullscreen, save states, etc. do_state_checks(); @@ -2480,6 +2505,7 @@ void rarch_main_deinit(void) { #ifdef HAVE_NETPLAY deinit_netplay(); + deinit_network_cmd(); #endif #ifdef HAVE_THREADS diff --git a/retroarch.cfg b/retroarch.cfg index 80e6950e0f..9246d93788 100644 --- a/retroarch.cfg +++ b/retroarch.cfg @@ -358,3 +358,7 @@ # Slowmotion ratio. When slowmotion, game will slow down by factor. # slowmotion_ratio = 3.0 +# Enable network command interface. +# network_cmd_enable = false +# network_cmd_port = 55355 + diff --git a/settings.c b/settings.c index 84d352e028..a5109d2b1c 100644 --- a/settings.c +++ b/settings.c @@ -189,6 +189,8 @@ void config_set_defaults(void) g_settings.block_sram_overwrite = block_sram_overwrite; g_settings.savestate_auto_index = savestate_auto_index; + g_settings.network_cmd_enable = network_cmd_enable; + g_settings.network_cmd_port = network_cmd_port; rarch_assert(sizeof(g_settings.input.binds[0]) >= sizeof(snes_keybinds_1)); rarch_assert(sizeof(g_settings.input.binds[1]) >= sizeof(snes_keybinds_rest)); @@ -455,6 +457,9 @@ bool config_load_file(const char *path) CONFIG_GET_BOOL(block_sram_overwrite, "block_sram_overwrite"); CONFIG_GET_BOOL(savestate_auto_index, "savestate_auto_index"); + CONFIG_GET_BOOL(network_cmd_enable, "network_cmd_enable"); + CONFIG_GET_INT(network_cmd_port, "network_cmd_port"); + if (config_get_string(conf, "environment_variables", &g_extern.system.environment)) { From 0b729e170786a595ddcfe11e5e8287b3f44e28a5 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:16:24 +0200 Subject: [PATCH 044/103] SOCK_NONBLOCK doesn't exist on Win32. --- network_cmd.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/network_cmd.c b/network_cmd.c index 51b67c1d78..2acb48f521 100644 --- a/network_cmd.c +++ b/network_cmd.c @@ -19,6 +19,7 @@ #include "general.h" #include #include +#include struct network_cmd { @@ -26,6 +27,16 @@ struct network_cmd bool state[RARCH_BIND_LIST_END]; }; +static bool socket_nonblock(int fd) +{ +#ifdef _WIN32 + u_long mode = 1; + ioctlsocket(fd, FIONBIO, &mode); +#else + return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0; +#endif +} + network_cmd_t *network_cmd_new(uint16_t port) { network_cmd_t *handle = (network_cmd_t*)calloc(1, sizeof(*handle)); @@ -51,10 +62,13 @@ network_cmd_t *network_cmd_new(uint16_t port) if (getaddrinfo(NULL, port_buf, &hints, &res) < 0) goto error; - handle->fd = socket(res->ai_family, res->ai_socktype | SOCK_NONBLOCK, res->ai_protocol); + handle->fd = socket(res->ai_family, res->ai_socktype, res->ai_protocol); if (handle->fd < 0) goto error; + if (!socket_nonblock(handle->fd)) + goto error; + setsockopt(handle->fd, SOL_SOCKET, SO_REUSEADDR, CONST_CAST &yes, sizeof(int)); if (bind(handle->fd, res->ai_addr, res->ai_addrlen) < 0) { From b01fc8b4f7857738f40ee2184a996c897ed39a1e Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:17:32 +0200 Subject: [PATCH 045/103] Handle errors. --- network_cmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/network_cmd.c b/network_cmd.c index 2acb48f521..407486055e 100644 --- a/network_cmd.c +++ b/network_cmd.c @@ -31,7 +31,7 @@ static bool socket_nonblock(int fd) { #ifdef _WIN32 u_long mode = 1; - ioctlsocket(fd, FIONBIO, &mode); + return ioctlsocket(fd, FIONBIO, &mode) == 0; #else return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK) == 0; #endif From 20472ae36da4d421966eb5d4c7049ececb92cc1d Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:18:37 +0200 Subject: [PATCH 046/103] Don't include in Win32. --- netplay_compat.h | 1 + network_cmd.c | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/netplay_compat.h b/netplay_compat.h index 2b114c88e1..669e66bccb 100644 --- a/netplay_compat.h +++ b/netplay_compat.h @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef __CELLOS_LV2__ #include diff --git a/network_cmd.c b/network_cmd.c index 407486055e..258cd31a41 100644 --- a/network_cmd.c +++ b/network_cmd.c @@ -19,7 +19,6 @@ #include "general.h" #include #include -#include struct network_cmd { From 65b78348f09281fee05d24b95b802637d98744dd Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:23:30 +0200 Subject: [PATCH 047/103] Use HAVE_NETWORK_CMD --- driver.h | 6 +++--- qb/config.libs.sh | 6 +++++- retroarch.c | 9 ++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/driver.h b/driver.h index f52a6f7231..7e14f009ba 100644 --- a/driver.h +++ b/driver.h @@ -28,7 +28,7 @@ #include "config.h" #endif -#ifdef HAVE_NETPLAY +#ifdef HAVE_NETWORK_CMD #include "network_cmd.h" #endif @@ -176,7 +176,7 @@ typedef struct driver void *video_data; void *input_data; -#ifdef HAVE_NETPLAY +#ifdef HAVE_NETWORK_CMD network_cmd_t *network_cmd; #endif } driver_t; @@ -260,7 +260,7 @@ extern const input_driver_t input_xdk360; static inline bool input_key_pressed_func(int key) { bool ret = driver.input->key_pressed(driver.input_data, key); -#ifdef HAVE_NETPLAY +#ifdef HAVE_NETWORK_CMD if (!ret && driver.network_cmd) ret = network_cmd_get(driver.network_cmd, key); #endif diff --git a/qb/config.libs.sh b/qb/config.libs.sh index 5382eeb8e9..abf40ebc0f 100644 --- a/qb/config.libs.sh +++ b/qb/config.libs.sh @@ -46,8 +46,12 @@ if [ $HAVE_NETPLAY = yes ]; then else HAVE_SOCKET_LEGACY=yes fi + HAVE_NETWORK_CMD=yes +else + HAVE_NETWORK_CMD=no fi + check_lib GETOPT_LONG -lc getopt_long if [ $HAVE_DYLIB = no ] && [ $HAVE_DYNAMIC = yes ]; then @@ -140,7 +144,7 @@ check_pkgconf PYTHON python3 add_define_make OS $OS # Creates config.mk and config.h. -VARS="ALSA OSS OSS_BSD OSS_LIB AL RSOUND ROAR JACK COREAUDIO PULSE SDL OPENGL DYLIB GETOPT_LONG THREADS CG XML SDL_IMAGE DYNAMIC FFMPEG AVCODEC AVFORMAT AVUTIL SWSCALE CONFIGFILE FREETYPE XVIDEO X11 XEXT NETPLAY SOCKET_LEGACY FBO STRL PYTHON FFMPEG_ALLOC_CONTEXT3 FFMPEG_AVCODEC_OPEN2 FFMPEG_AVIO_OPEN FFMPEG_AVFORMAT_WRITE_HEADER FFMPEG_AVFORMAT_NEW_STREAM FFMPEG_AVCODEC_ENCODE_AUDIO2 FFMPEG_AVCODEC_ENCODE_VIDEO2 X264RGB SINC BSV_MOVIE" +VARS="ALSA OSS OSS_BSD OSS_LIB AL RSOUND ROAR JACK COREAUDIO PULSE SDL OPENGL DYLIB GETOPT_LONG THREADS CG XML SDL_IMAGE DYNAMIC FFMPEG AVCODEC AVFORMAT AVUTIL SWSCALE CONFIGFILE FREETYPE XVIDEO X11 XEXT NETPLAY NETWORK_CMD SOCKET_LEGACY FBO STRL PYTHON FFMPEG_ALLOC_CONTEXT3 FFMPEG_AVCODEC_OPEN2 FFMPEG_AVIO_OPEN FFMPEG_AVFORMAT_WRITE_HEADER FFMPEG_AVFORMAT_NEW_STREAM FFMPEG_AVCODEC_ENCODE_AUDIO2 FFMPEG_AVCODEC_ENCODE_VIDEO2 X264RGB SINC BSV_MOVIE" create_config_make config.mk $VARS create_config_header config.h $VARS diff --git a/retroarch.c b/retroarch.c index 176b33da0a..4184d660e2 100644 --- a/retroarch.c +++ b/retroarch.c @@ -1337,7 +1337,9 @@ static void deinit_netplay(void) if (g_extern.netplay) netplay_free(g_extern.netplay); } +#endif +#ifdef HAVE_NETWORK_CMD static void init_network_cmd(void) { if (!g_settings.network_cmd_enable) @@ -2372,8 +2374,11 @@ int rarch_main_init(int argc, char *argv[]) #ifdef HAVE_NETPLAY init_netplay(); +#endif +#ifdef HAVE_NETWORK_CMD init_network_cmd(); #endif + init_drivers(); #ifdef HAVE_NETPLAY @@ -2447,7 +2452,7 @@ bool rarch_main_iterate(void) !video_alive_func()) return false; -#ifdef HAVE_NETPLAY +#ifdef HAVE_NETWORK_CMD if (driver.network_cmd) network_cmd_pre_frame(driver.network_cmd); #endif @@ -2505,6 +2510,8 @@ void rarch_main_deinit(void) { #ifdef HAVE_NETPLAY deinit_netplay(); +#endif +#ifdef HAVE_NETWORK_CMD deinit_network_cmd(); #endif From 86295bf0571ec5e45abae2dedb0e2ea436591832 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:27:17 +0200 Subject: [PATCH 048/103] Re-add gl_render_msg_post(). --- gfx/fonts/freetype.c | 17 ++++------------- gfx/fonts/ps3_libdbgfont.c | 4 ++++ gfx/gl.c | 3 +++ gfx/gl_font.h | 1 + 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index 1125d9acc9..fa3e3cb81a 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -220,18 +220,10 @@ static void calculate_font_coords(gl_t *gl, font_tex_coords[7] = hy; } -static void gl_render_msg_pre(gl_t *gl) -{ - gl_shader_use(0); - gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); - glEnable(GL_BLEND); - (void)gl; -} - extern const GLfloat vertexes_flipped[]; extern const GLfloat white_color[]; -static void gl_render_msg_post(gl_t *gl) +void gl_render_msg_post(gl_t *gl) { // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); @@ -250,7 +242,9 @@ void gl_render_msg(gl_t *gl, const char *msg) if (!gl->font) return; - gl_render_msg_pre(gl); + gl_shader_use(0); + gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); + glEnable(GL_BLEND); GLfloat font_vertex[8]; GLfloat font_vertex_dark[8]; @@ -286,12 +280,9 @@ void gl_render_msg(gl_t *gl, const char *msg) glVertexPointer(2, GL_FLOAT, 0, font_vertex); glColorPointer(4, GL_FLOAT, 0, gl->font_color); glDrawArrays(GL_QUADS, 0, 4); - - gl_render_msg_post(gl); #else (void)gl; (void)msg; #endif } - diff --git a/gfx/fonts/ps3_libdbgfont.c b/gfx/fonts/ps3_libdbgfont.c index 445af60a56..3279d9fc0b 100644 --- a/gfx/fonts/ps3_libdbgfont.c +++ b/gfx/fonts/ps3_libdbgfont.c @@ -40,6 +40,10 @@ void gl_render_msg(gl_t *gl, const char *msg) { cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.11f, BLUE, msg); cellDbgFontPrintf(g_settings.video.msg_pos_x, g_settings.video.msg_pos_y, 1.10f, WHITE, msg); +} + +void gl_render_msg_post(gl_t *gl) +{ cellDbgFontDraw(); } diff --git a/gfx/gl.c b/gfx/gl.c index 48d1bdf071..16e2f4b86f 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -891,7 +891,10 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_next_texture_index(gl, &tex_info); if (msg) + { gl_render_msg(gl, msg); + gl_render_msg_post(gl); + } gfx_ctx_update_window_title(false); gfx_ctx_swap_buffers(); diff --git a/gfx/gl_font.h b/gfx/gl_font.h index 9c512ecd35..cc74950e93 100644 --- a/gfx/gl_font.h +++ b/gfx/gl_font.h @@ -22,6 +22,7 @@ void gl_init_font(gl_t *gl, const char *font_path, unsigned font_size); void gl_deinit_font(gl_t *gl); void gl_render_msg(gl_t *gl, const char *msg); +void gl_render_msg_post(gl_t *gl); #endif From a61e52b41957237d3e31eaa3ed0fab11744e8c63 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 14:43:30 +0200 Subject: [PATCH 049/103] Do not call gl_render_msg_pre(). --- ps3/ps3_video_psgl.c | 1 - 1 file changed, 1 deletion(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index e17bd07fc1..74da84f449 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -950,7 +950,6 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if (msg) { - gl_render_msg_pre(gl); gl_render_msg(gl, msg); gl_render_msg_post(gl); } From 9aaf878908c919b1e885cc8097d412c8fb29fe57 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 15:04:43 +0200 Subject: [PATCH 050/103] Init gl handle early. --- gfx/gl.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 16e2f4b86f..fb3708bf75 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -946,9 +946,16 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gfx_set_dwm(); #endif - if (!gfx_ctx_init()) + gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t)); + if (!gl) return NULL; + if (!gfx_ctx_init()) + { + free(gl); + return NULL; + } + unsigned full_x = 0, full_y = 0; gfx_ctx_get_video_size(&full_x, &full_y); RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y); @@ -965,7 +972,10 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!gfx_ctx_set_video_mode(win_width, win_height, g_settings.video.force_16bit ? 15 : 0, video->fullscreen)) + { + free(gl); return NULL; + } gfx_ctx_update_window_title(true); @@ -977,17 +987,11 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!load_gl_proc()) { gfx_ctx_destroy(); + free(gl); return NULL; } #endif - gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t)); - if (!gl) - { - gfx_ctx_destroy(); - return NULL; - } - gl->vsync = video->vsync; gl->fullscreen = video->fullscreen; From 3dbc1a3e7f58ab2a6df9723b91b4267889e5b256 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 15:03:13 +0200 Subject: [PATCH 051/103] (PS3) Clean up set_overscan --- ps3/menu.c | 12 ++++++------ ps3/ps3_video_psgl.c | 22 ++++++---------------- ps3/ps3_video_psgl.h | 4 ++-- 3 files changed, 14 insertions(+), 24 deletions(-) diff --git a/ps3/menu.c b/ps3/menu.c index 2bd01f3216..e83df45c15 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1409,7 +1409,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(g_console.overscan_amount == 0.0f) g_console.overscan_enable = false; - ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + ps3graphics_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) @@ -1420,14 +1420,14 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(g_console.overscan_amount == 0.0f) g_console.overscan_enable = 0; - ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + ps3graphics_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_START(state)) { g_console.overscan_amount = 0.0f; g_console.overscan_enable = false; - ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + ps3graphics_set_overscan(); } break; case SETTING_THROTTLE_MODE: @@ -2137,7 +2137,7 @@ static void ingame_menu(uint32_t menu_id) if(g_console.overscan_amount == 0.00f) g_console.overscan_enable = false; - ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + ps3graphics_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state) || CTRL_LSTICK_RIGHT(state)) @@ -2147,14 +2147,14 @@ static void ingame_menu(uint32_t menu_id) if(g_console.overscan_amount == 0.0f) g_console.overscan_amount = false; - ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + ps3graphics_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_START(state)) { g_console.overscan_amount = 0.0f; g_console.overscan_enable = false; - ps3graphics_set_overscan(g_console.overscan_enable, g_console.overscan_amount, 1); + ps3graphics_set_overscan(); } strlcpy(comment, "Press LEFT or RIGHT to change the [Overscan] settings.\nPress START to reset back to default values.", sizeof(comment)); break; diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 74da84f449..b67dabc5f5 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -605,11 +605,11 @@ static void set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_f glViewport(m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp); - if(ps3_gl.overscan_enable) + if(g_console.overscan_enable) { - m_left = -ps3_gl.overscan_amount/2; - m_right = 1 + ps3_gl.overscan_amount/2; - m_bottom = -ps3_gl.overscan_amount/2; + m_left = -g_console.overscan_amount/2; + m_right = 1 + g_console.overscan_amount/2; + m_bottom = -g_console.overscan_amount/2; } glMatrixMode(GL_PROJECTION); @@ -1408,19 +1408,13 @@ void ps3_set_filtering(unsigned index, bool set_smooth) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } -void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalculate_viewport) +void ps3graphics_set_overscan(void) { gl_t * gl = driver.video_data; if(!gl) return; - ps3_gl.overscan_enable = overscan_enable; - ps3_gl.overscan_amount = amount; - - if(recalculate_viewport) - { - set_viewport(gl, gl->win_width, gl->win_height, false, true); - } + set_viewport(gl, gl->win_width, gl->win_height, false, true); } void ps3graphics_video_init(bool get_all_resolutions) @@ -1435,15 +1429,11 @@ void ps3graphics_video_init(bool get_all_resolutions) driver.video_data = gl_init(&video_info, NULL, NULL); gl_set_fbo_enable(g_console.fbo_enabled); - ps3_gl.overscan_enable = g_console.overscan_enable; - ps3_gl.overscan_amount = g_console.overscan_amount; - if(get_all_resolutions) get_all_available_resolutions(); ps3_set_resolution(); ps3_setup_texture(); - ps3graphics_set_overscan(ps3_gl.overscan_enable, ps3_gl.overscan_amount, 0); } void ps3graphics_video_reinit(void) diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 66271201d1..53f077e5d6 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -46,8 +46,8 @@ void ps3_previous_resolution (void); void ps3_next_resolution (void); void ps3_set_filtering(unsigned index, bool set_smooth); void ps3_video_deinit(void); -void ps3graphics_reinit_fbos (void); -void ps3graphics_set_overscan(bool overscan_enable, float amount, bool recalculate_viewport); +void ps3graphics_reinit_fbos(void); +void ps3graphics_set_overscan(void); void ps3graphics_set_vsync(uint32_t vsync); void ps3graphics_video_init(bool get_all_resolutions); void ps3graphics_video_reinit(void); From d72751956ec761b173b9e2a8f555eb92af8c32f5 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 16:23:01 +0200 Subject: [PATCH 052/103] (PS3) Implement gfx_ctx_swap_buffers --- gfx/context/ps3_ctx.c | 4 ++++ gfx/gl_common.h | 3 +++ ps3/menu.c | 31 +++++++++++++++++++++++-------- ps3/ps3_video_psgl.c | 20 +++++--------------- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 919b9e159e..ac630886c0 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -60,3 +60,7 @@ bool gfx_ctx_window_has_focus(void) return true; } +void gfx_ctx_swap_buffers(void) +{ + psglSwap(); +} diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 2c48ac9227..2601bd79ab 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -126,6 +126,9 @@ struct gl_tex_info typedef struct gl { +#ifdef RARCH_CONSOLE + bool block_swap; +#endif bool vsync; GLuint texture[TEXTURES]; unsigned tex_index; // For use with PREV. diff --git a/ps3/menu.c b/ps3/menu.c index e83df45c15..87a7a5b8a2 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1105,8 +1105,10 @@ static void rarch_filename_input_and_save (unsigned filename_type) { glClear(GL_COLOR_BUFFER_BIT); gl_frame_menu(); - video_gl.swap(NULL); + gfx_ctx_swap_buffers(); +#ifdef HAVE_SYSUTILS cellSysutilCheckCallback(); +#endif } if(g_console.oskutil_handle.text_can_be_fetched) @@ -1138,8 +1140,10 @@ static void rarch_filename_input_and_save (unsigned filename_type) { /* OSK Util gets updated */ glClear(GL_COLOR_BUFFER_BIT); - video_gl.swap(NULL); - cellSysutilCheckCallback(); + gfx_ctx_swap_buffers(); +#ifdef HAVE_SYSUTILS + cellSysutilCheckCallback(); +#endif } if(g_console.oskutil_handle.text_can_be_fetched) @@ -1545,8 +1549,10 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) while(OSK_IS_RUNNING(g_console.oskutil_handle)) { glClear(GL_COLOR_BUFFER_BIT); - video_gl.swap(NULL); - cellSysutilCheckCallback(); + gfx_ctx_swap_buffers(); +#ifdef HAVE_SYSUTILS + cellSysutilCheckCallback(); +#endif } if(g_console.oskutil_handle.text_can_be_fetched) @@ -2353,7 +2359,10 @@ static void ingame_menu(uint32_t menu_id) cellDbgFontPrintf (0.09f, 0.83f, 0.91f, LIGHTBLUE, "Allows you to resize the screen by moving around the two analog sticks.\nPress TRIANGLE to reset to default values, and CIRCLE to go back to the menu."); cellDbgFontDraw(); } - video_gl.swap(NULL); + gfx_ctx_swap_buffers(); +#ifdef HAVE_SYSUTILS + cellSysutilCheckCallback(); +#endif if(CTRL_SQUARE(~state)) { glDisable(GL_BLEND); @@ -2376,7 +2385,10 @@ static void ingame_menu(uint32_t menu_id) rarch_render_cached_frame(); - video_gl.swap(NULL); + gfx_ctx_swap_buffers(); +#ifdef HAVE_SYSUTILS + cellSysutilCheckCallback(); +#endif } } @@ -2642,7 +2654,10 @@ void menu_loop(void) SET_TIMER_EXPIRATION(g_console.timer_expiration_frame_count, 30); } - video_gl.swap(NULL); + gfx_ctx_swap_buffers(); +#ifdef HAVE_SYSUTILS + cellSysutilCheckCallback(); +#endif glDisable(GL_BLEND); }while (g_console.menu_enable); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index b67dabc5f5..725d5a479d 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -100,7 +100,6 @@ static const GLfloat white_color[] = { }; struct { - bool block_swap; bool overscan_enable; GLfloat overscan_amount; #ifdef HAVE_CG_MENU @@ -954,8 +953,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gl_render_msg_post(gl); } - if(!ps3_gl.block_swap) - psglSwap(); + if(!gl->block_swap) + gfx_ctx_swap_buffers(); return true; } @@ -1202,19 +1201,11 @@ static bool gl_focus(void *data) return gfx_ctx_window_has_focus(); } -static void ps3graphics_set_swap_block_swap(void * data, bool toggle) +static void ps3graphics_set_swap_block_swap(void * data, bool enable) { - (void)data; - ps3_gl.block_swap = toggle; -} + gl_t *gl = driver.video_data; -static void ps3graphics_swap(void * data) -{ - (void)data; - psglSwap(); -#ifdef HAVE_SYSUTILS - cellSysutilCheckCallback(); -#endif + gl->block_swap = enable; } static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index) @@ -1245,7 +1236,6 @@ const video_driver_t video_gl = .set_swap_block_state = ps3graphics_set_swap_block_swap, .set_rotation = ps3graphics_set_orientation, .set_aspect_ratio = ps3graphics_set_aspect_ratio, - .swap = ps3graphics_swap }; static void get_all_available_resolutions (void) From d1db5abb99ff67b0162e994663fadfaec34e397f Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 16:30:38 +0200 Subject: [PATCH 053/103] (PS3) ps3_video_psgl.c - cleanups --- ps3/ps3_video_psgl.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 725d5a479d..9b0bafda41 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -100,15 +100,12 @@ static const GLfloat white_color[] = { }; struct { - bool overscan_enable; - GLfloat overscan_amount; #ifdef HAVE_CG_MENU GLuint menu_texture_id; struct texture_image menu_texture; #endif PSGLdevice* gl_device; PSGLcontext* gl_context; - CellVideoOutState g_video_state; } ps3_gl; #ifdef HAVE_FBO @@ -1284,11 +1281,6 @@ static void get_all_available_resolutions (void) g_console.current_resolution_index = g_console.supported_resolutions_count-1; } -void ps3_set_resolution (void) -{ - cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &ps3_gl.g_video_state); -} - void ps3_next_resolution (void) { if(g_console.current_resolution_index+1 < g_console.supported_resolutions_count) @@ -1422,7 +1414,8 @@ void ps3graphics_video_init(bool get_all_resolutions) if(get_all_resolutions) get_all_available_resolutions(); - ps3_set_resolution(); + CellVideoOutState g_video_state; + cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &g_video_state); ps3_setup_texture(); } From ac96bee03de4c51f6995eda52fe5237e0761a642 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 16:52:30 +0200 Subject: [PATCH 054/103] Fix build for Win32. --- gfx/fonts/freetype.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index fa3e3cb81a..545e9126bf 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -223,8 +223,11 @@ static void calculate_font_coords(gl_t *gl, extern const GLfloat vertexes_flipped[]; extern const GLfloat white_color[]; +#endif + void gl_render_msg_post(gl_t *gl) { +#ifdef HAVE_FREETYPE // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); @@ -233,8 +236,10 @@ void gl_render_msg_post(gl_t *gl) glDisable(GL_BLEND); gl_set_projection(gl, true); -} +#else + (void)gl; #endif +} void gl_render_msg(gl_t *gl, const char *msg) { From dfb5678ce1c0f968ae4e24e7985100afda2dc28d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 17:02:19 +0200 Subject: [PATCH 055/103] (PS3) Put menu rendering code in gl_frame --- gfx/gl_common.h | 4 +++ ps3/menu.c | 22 ++++++----------- ps3/ps3_video_psgl.c | 58 +++++++++++++++++++------------------------- ps3/ps3_video_psgl.h | 1 - 4 files changed, 37 insertions(+), 48 deletions(-) diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 2601bd79ab..a3dd4bcffa 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -128,6 +128,10 @@ typedef struct gl { #ifdef RARCH_CONSOLE bool block_swap; +#endif +#ifdef HAVE_CG_MENU + bool menu_render; + GLuint menu_texture_id; #endif bool vsync; GLuint texture[TEXTURES]; diff --git a/ps3/menu.c b/ps3/menu.c index 87a7a5b8a2..b81e30d099 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1104,7 +1104,6 @@ static void rarch_filename_input_and_save (unsigned filename_type) while(OSK_IS_RUNNING(g_console.oskutil_handle)) { glClear(GL_COLOR_BUFFER_BIT); - gl_frame_menu(); gfx_ctx_swap_buffers(); #ifdef HAVE_SYSUTILS cellSysutilCheckCallback(); @@ -2256,9 +2255,7 @@ static void ingame_menu(uint32_t menu_id) rarch_render_cached_frame(); if(CTRL_SQUARE(~state)) - { - gl_frame_menu(); - } + gl->menu_render = false; if(CTRL_LSTICK_LEFT(state) || CTRL_LEFT(state)) g_console.viewports.custom_vp.x -= 1; @@ -2566,8 +2563,7 @@ void menu_loop(void) menu_reinit_settings(); - if(g_console.emulator_initialized) - video_gl.set_swap_block_state(NULL, true); + video_gl.set_swap_block_state(NULL, true); if(g_console.ingame_menu_enable) { @@ -2576,17 +2572,14 @@ void menu_loop(void) menuStack[menuStackindex].enum_id = INGAME_MENU; } + gl->menu_render = true; + do { glClear(GL_COLOR_BUFFER_BIT); glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); - if(g_console.emulator_initialized) - { - rarch_render_cached_frame(); - } - - gl_frame_menu(); + rarch_render_cached_frame(); switch(menuStack[menuStackindex].enum_id) { @@ -2661,11 +2654,12 @@ void menu_loop(void) glDisable(GL_BLEND); }while (g_console.menu_enable); + gl->menu_render = false; + if(g_console.ingame_menu_enable) menuStackindex--; // pop ingame menu from stack - if(g_console.emulator_initialized) - video_gl.set_swap_block_state(NULL, false); + video_gl.set_swap_block_state(NULL, false); g_console.ingame_menu_enable = false; } diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 9b0bafda41..4da9146e93 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -101,7 +101,6 @@ static const GLfloat white_color[] = { struct { #ifdef HAVE_CG_MENU - GLuint menu_texture_id; struct texture_image menu_texture; #endif PSGLdevice* gl_device; @@ -657,33 +656,6 @@ static void check_window(gl_t *gl) gl->should_resize = true; } -void gl_frame_menu (void) -{ - gl_t *gl = driver.video_data; - - gl->frame_count++; - - if(!gl) - return; - -#ifdef HAVE_CG_MENU - gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); - - gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, - gl->win_height, gl->win_width, gl->win_height, gl->frame_count, - NULL, NULL, NULL, 0); - - set_viewport(gl, gl->win_width, gl->win_height, true, false); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, ps3_gl.menu_texture_id); - - glDrawArrays(GL_QUADS, 0, 4); - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -#endif -} - static void ps3graphics_set_orientation(void * data, uint32_t orientation) { (void)data; @@ -953,6 +925,25 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei if(!gl->block_swap) gfx_ctx_swap_buffers(); +#ifdef HAVE_CG_MENU + if(gl->menu_render) + { + gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); + + gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, + gl->win_height, gl->win_width, gl->win_height, gl->frame_count, + NULL, NULL, NULL, 0); + + set_viewport(gl, gl->win_width, gl->win_height, true, false); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + + glDrawArrays(GL_QUADS, 0, 4); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + } +#endif + return true; } @@ -1329,7 +1320,7 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -static bool ps3_setup_texture(void) +static bool gfx_ctx_menu_init(void) { gl_t *gl = driver.video_data; @@ -1337,7 +1328,7 @@ static bool ps3_setup_texture(void) return false; #ifdef HAVE_CG_MENU - glGenTextures(1, &ps3_gl.menu_texture_id); + glGenTextures(1, &gl->menu_texture_id); RARCH_LOG("Loading texture image for menu...\n"); if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &ps3_gl.menu_texture)) @@ -1346,7 +1337,7 @@ static bool ps3_setup_texture(void) return false; } - glBindTexture(GL_TEXTURE_2D, ps3_gl.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); @@ -1416,7 +1407,9 @@ void ps3graphics_video_init(bool get_all_resolutions) CellVideoOutState g_video_state; cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &g_video_state); - ps3_setup_texture(); +#ifdef HAVE_CG_MENU + gfx_ctx_menu_init(); +#endif } void ps3graphics_video_reinit(void) @@ -1437,4 +1430,3 @@ void ps3_video_deinit(void) driver.video_data = NULL; gl_free(data); } - diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 53f077e5d6..497deb9266 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -38,7 +38,6 @@ enum const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); -void gl_frame_menu(void); void gl_deinit_fbo(gl_t * gl); void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); void gl_set_fbo_enable(bool enable); From f3ea8aa0518345898a7e039d21a49356302b8f9a Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 17:11:30 +0200 Subject: [PATCH 056/103] (PS3) Fixed Resize Mode menu rendering --- ps3/menu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ps3/menu.c b/ps3/menu.c index b81e30d099..7c10d6f0d7 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -2254,8 +2254,14 @@ static void ingame_menu(uint32_t menu_id) rarch_render_cached_frame(); - if(CTRL_SQUARE(~state)) + if(CTRL_SQUARE(state)) + { gl->menu_render = false; + } + else + { + gl->menu_render = true; + } if(CTRL_LSTICK_LEFT(state) || CTRL_LEFT(state)) g_console.viewports.custom_vp.x -= 1; From 754e36ea33948fbef4a4bbea26c4a9f721d015d9 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 17:20:02 +0200 Subject: [PATCH 057/103] (PS3) Moved gfx_ctx_menu_init to ps3_ctx.c --- gfx/context/ps3_ctx.c | 38 ++++++++++++++++++++++++++++++++++++ gfx/gfx_context.h | 4 ++++ ps3/ps3_video_psgl.c | 45 ++++--------------------------------------- 3 files changed, 46 insertions(+), 41 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index ac630886c0..1e6b960558 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -23,9 +23,13 @@ #endif #include "../gl_common.h" +#include "../image.h" +#include "../../ps3/shared.h" #include "ps3_ctx.h" +static struct texture_image menu_texture; + void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { if (inited) @@ -64,3 +68,37 @@ void gfx_ctx_swap_buffers(void) { psglSwap(); } + +bool gfx_ctx_menu_init(void) +{ + gl_t *gl = driver.video_data; + + if (!gl) + return false; + +#ifdef HAVE_CG_MENU + glGenTextures(1, &gl->menu_texture_id); + + RARCH_LOG("Loading texture image for menu...\n"); + if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &menu_texture)) + { + RARCH_ERR("Failed to load texture image for menu.\n"); + return false; + } + + 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); + + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + + free(menu_texture.pixels); +#endif + + return true; +} diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index 3593b6ae11..f3ff2f54c6 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -58,5 +58,9 @@ bool gfx_ctx_window_has_focus(void); void gfx_ctx_input_driver(const input_driver_t **input, void **input_data); +#ifdef HAVE_CG_MENU +bool gfx_ctx_menu_init(void) +#endif + #endif diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 4da9146e93..72990c3942 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -100,9 +100,6 @@ static const GLfloat white_color[] = { }; struct { -#ifdef HAVE_CG_MENU - struct texture_image menu_texture; -#endif PSGLdevice* gl_device; PSGLcontext* gl_context; } ps3_gl; @@ -991,7 +988,7 @@ static void gl_set_nonblock_state(void *data, bool state) } } -static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resolution_id) +static bool psgl_init_device(gl_t *gl) { PSGLinitOptions options = { @@ -1022,10 +1019,10 @@ static bool psgl_init_device(gl_t *gl, const video_info_t *video, uint32_t resol params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; } - if(resolution_id) + if(g_console.current_resolution_id) { CellVideoOutResolution resolution; - cellVideoOutGetResolution(resolution_id, &resolution); + cellVideoOutGetResolution(g_console.current_resolution_id, &resolution); params.enable |= PSGL_DEVICE_PARAMETERS_WIDTH_HEIGHT; params.width = resolution.width; @@ -1057,7 +1054,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!gl) return NULL; - if (!psgl_init_device(gl, video, g_console.current_resolution_id)) + if (!psgl_init_device(gl)) return NULL; @@ -1320,40 +1317,6 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -static bool gfx_ctx_menu_init(void) -{ - gl_t *gl = driver.video_data; - - if (!gl) - return false; - -#ifdef HAVE_CG_MENU - glGenTextures(1, &gl->menu_texture_id); - - RARCH_LOG("Loading texture image for menu...\n"); - if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &ps3_gl.menu_texture)) - { - RARCH_ERR("Failed to load texture image for menu.\n"); - return false; - } - - 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, ps3_gl.menu_texture.width, ps3_gl.menu_texture.height, 0, - GL_ARGB_SCE, GL_UNSIGNED_INT_8_8_8_8, ps3_gl.menu_texture.pixels); - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - - free(ps3_gl.menu_texture.pixels); -#endif - - return true; -} - void ps3_set_filtering(unsigned index, bool set_smooth) { gl_t *gl = driver.video_data; From f32bc9e017ca8a537a1a2ca725017fae0cdfb9f7 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 17:46:47 +0200 Subject: [PATCH 058/103] (PS3) Implemented gfx_ctx_init, gfx_ctx_destroy and other functions --- gfx/context/ps3_ctx.c | 76 +++++++++++++++++++++++ gfx/gl.c | 4 +- ps3/ps3_video_psgl.c | 140 +++++++++++++++++------------------------- 3 files changed, 133 insertions(+), 87 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 1e6b960558..ffac36ee38 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -18,6 +18,8 @@ #include +#include + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -29,6 +31,8 @@ #include "ps3_ctx.h" static struct texture_image menu_texture; +static PSGLdevice* gl_device; +static PSGLcontext* gl_context; void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { @@ -102,3 +106,75 @@ bool gfx_ctx_menu_init(void) return true; } + +void gfx_ctx_get_video_size(unsigned *width, unsigned *height) +{ + psglGetDeviceDimensions(gl_device, width, height); +} + +bool gfx_ctx_init(void) +{ + PSGLinitOptions options = + { + .enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS, + .maxSPUs = 1, + .initializeSPUs = GL_FALSE, + }; +#if CELL_SDK_VERSION < 0x340000 + options.enable |= PSGL_INIT_HOST_MEMORY_SIZE; +#endif + + // Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL + sys_spu_initialize(6, 1); + psglInit(&options); + + PSGLdeviceParameters params; + + params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \ + PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \ + PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; + params.colorFormat = GL_ARGB_SCE; + params.depthFormat = GL_NONE; + params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; + + if(g_console.triple_buffering_enable) + { + params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE; + params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; + } + + 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; + } + + gl_device = psglCreateDeviceExtended(¶ms); + gl_context = psglCreateContext(); + + psglMakeCurrent(gl_context, gl_device); + psglResetCurrentContext(); + + return true; +} + +bool gfx_ctx_set_video_mode( + unsigned width, unsigned height, + unsigned bits, bool fullscreen) +{ + return true; +} + +void gfx_ctx_destroy(void) +{ + psglDestroyContext(gl_context); + psglDestroyDevice(gl_device); + + psglExit(); +} + +void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) { } diff --git a/gfx/gl.c b/gfx/gl.c index fb3708bf75..862be70d44 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -958,7 +958,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo unsigned full_x = 0, full_y = 0; gfx_ctx_get_video_size(&full_x, &full_y); - RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y); + RARCH_LOG("Detecting resolution %ux%u.\n", full_x, full_y); gfx_ctx_set_swap_interval(video->vsync ? 1 : 0, false); @@ -1031,7 +1031,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gl_shader_use(1); gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); - bool force_smooth; + bool force_smooth = false; if (gl_shader_filter_type(1, &force_smooth)) gl->tex_filter = force_smooth ? GL_LINEAR : GL_NEAREST; else diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 72990c3942..220ca10532 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -26,8 +26,6 @@ #include #include -#include - #include "../gfx/state_tracker.h" #include "../gfx/shader_cg.h" #include "../general.h" @@ -99,11 +97,6 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; -struct { - PSGLdevice* gl_device; - PSGLcontext* gl_context; -} ps3_gl; - #ifdef HAVE_FBO #if defined(_WIN32) && !defined(RARCH_CONSOLE) static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; @@ -944,14 +937,6 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei return true; } -static void psgl_deinit(gl_t *gl) -{ - psglDestroyContext(ps3_gl.gl_context); - psglDestroyDevice(ps3_gl.gl_device); - - psglExit(); -} - static void gl_free(void *data) { if (driver.video_data) @@ -966,11 +951,17 @@ static void gl_free(void *data) glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_COLOR_ARRAY); glDeleteTextures(TEXTURES, gl->texture); + +#ifdef HAVE_OPENGL_TEXREF glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0); glDeleteBuffers(1, &gl->pbo); +#endif +#ifdef HAVE_FBO gl_deinit_fbo(gl); - psgl_deinit(gl); +#endif + + gfx_ctx_destroy(); if (gl->empty_buf) free(gl->empty_buf); @@ -988,63 +979,6 @@ static void gl_set_nonblock_state(void *data, bool state) } } -static bool psgl_init_device(gl_t *gl) -{ - PSGLinitOptions options = - { - .enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS, - .maxSPUs = 1, - .initializeSPUs = GL_FALSE, - }; -#if CELL_SDK_VERSION < 0x340000 - options.enable |= PSGL_INIT_HOST_MEMORY_SIZE; -#endif - - // Initialize 6 SPUs but reserve 1 SPU as a raw SPU for PSGL - sys_spu_initialize(6, 1); - psglInit(&options); - - PSGLdeviceParameters params; - - params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \ - PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \ - PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; - params.colorFormat = GL_ARGB_SCE; - params.depthFormat = GL_NONE; - params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; - - if(g_console.triple_buffering_enable) - { - params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE; - params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; - } - - 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; - } - - ps3_gl.gl_device = psglCreateDeviceExtended(¶ms); - psglGetDeviceDimensions(ps3_gl.gl_device, &gl->win_width, &gl->win_height); - - if(g_console.viewports.custom_vp.width == 0) - g_console.viewports.custom_vp.width = gl->win_width; - - if(g_console.viewports.custom_vp.height == 0) - g_console.viewports.custom_vp.height = gl->win_height; - - ps3_gl.gl_context = psglCreateContext(); - psglMakeCurrent(ps3_gl.gl_context, ps3_gl.gl_device); - psglResetCurrentContext(); - - return true; -} - static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) { if (driver.video_data) @@ -1054,19 +988,54 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!gl) return NULL; - if (!psgl_init_device(gl)) + if (!gfx_ctx_init()) + { + free(gl); return NULL; + } + unsigned full_x = 0, full_y = 0; + gfx_ctx_get_video_size(&full_x, &full_y); + RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y); - RARCH_LOG("Detecting resolution %ux%u.\n", gl->win_width, gl->win_height); + gfx_ctx_set_swap_interval(video->vsync ? 1 : 0, false); - 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 (!gfx_ctx_set_video_mode(win_width, win_height, + g_settings.video.force_16bit ? 15 : 0, video->fullscreen)) + { + free(gl); + return NULL; + } + +#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) + // Win32 GL lib doesn't have some functions needed for XML shaders. + // Need to load dynamically :( + if (!load_gl_proc()) + { + gfx_ctx_destroy(); + free(gl); + return NULL; + } +#endif 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; RARCH_LOG("GL: Using resolution %ux%u.\n", gl->win_width, gl->win_height); - #ifdef HAVE_CG_MENU RARCH_LOG("Initializing menu shader...\n"); gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); @@ -1075,7 +1044,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo if (!gl_shader_init()) { RARCH_ERR("Shader init failed.\n"); - psgl_deinit(gl); + gfx_ctx_destroy(); free(gl); return NULL; } @@ -1122,7 +1091,6 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glColorPointer(4, GL_FLOAT, 0, white_color); set_lut_texture_coords(tex_coords); @@ -1156,20 +1124,16 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); } + gfx_ctx_input_driver(input, input_data); gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); if (!gl_check_error()) { - psgl_deinit(gl); + gfx_ctx_destroy(); free(gl); return NULL; } - if (input) - *input = NULL; - if (input_data) - *input_data = NULL; - return gl; } @@ -1362,6 +1326,12 @@ void ps3graphics_video_init(bool get_all_resolutions) video_info.force_aspect = false; 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) + { + video_info.width = g_console.viewports.custom_vp.width; + video_info.height = g_console.viewports.custom_vp.height; + } driver.video_data = gl_init(&video_info, NULL, NULL); gl_set_fbo_enable(g_console.fbo_enabled); From 90d6aca1e12de2397b0b77659aaf01526e663247 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 18:04:25 +0200 Subject: [PATCH 059/103] (PS3) Move set_filtering and set_fbo to ps3_ctx.c --- gfx/context/ps3_ctx.c | 34 ++++++++++++++++++++++++++++++++++ gfx/gfx_context.h | 4 ++++ ps3/menu.c | 10 +++++----- ps3/ps3_video_psgl.c | 39 ++++----------------------------------- ps3/ps3_video_psgl.h | 2 -- 5 files changed, 47 insertions(+), 42 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index ffac36ee38..60edacd8c5 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -178,3 +178,37 @@ void gfx_ctx_destroy(void) } void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) { } + +void gfx_ctx_set_filtering(unsigned index, bool set_smooth) +{ + gl_t *gl = driver.video_data; + + if (!gl) + return; + + if (index == 1) + { + // Apply to all PREV textures. + for (unsigned i = 0; i < TEXTURES; i++) + { + glBindTexture(GL_TEXTURE_2D, gl->texture[i]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + } + } + else if (index >= 2 && gl->fbo_inited) + { + glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + } + + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} + +void gfx_ctx_set_fbo(bool enable) +{ + gl_t *gl = driver.video_data; + gl->fbo_inited = enable; + gl->render_to_tex = enable; +} diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index f3ff2f54c6..cf1dc44973 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -62,5 +62,9 @@ void gfx_ctx_input_driver(const input_driver_t **input, void **input_data); bool gfx_ctx_menu_init(void) #endif +#ifdef RARCH_CONSOLE +void gfx_ctx_set_filtering(unsigned index, bool set_smooth); +#endif + #endif diff --git a/ps3/menu.c b/ps3/menu.c index 7c10d6f0d7..642c8973c4 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1328,33 +1328,33 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) { g_settings.video.smooth = !g_settings.video.smooth; - ps3_set_filtering(1, g_settings.video.smooth); + gfx_ctx_set_filtering(1, g_settings.video.smooth); set_delay = DELAY_LONG; } if(CTRL_START(state)) { g_settings.video.smooth = 1; - ps3_set_filtering(1, g_settings.video.smooth); + gfx_ctx_set_filtering(1, g_settings.video.smooth); } break; case SETTING_HW_TEXTURE_FILTER_2: if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) { g_settings.video.second_pass_smooth = !g_settings.video.second_pass_smooth; - ps3_set_filtering(2, g_settings.video.second_pass_smooth); + gfx_ctx_set_filtering(2, g_settings.video.second_pass_smooth); set_delay = DELAY_LONG; } if(CTRL_START(state)) { g_settings.video.second_pass_smooth = 1; - ps3_set_filtering(2, g_settings.video.second_pass_smooth); + gfx_ctx_set_filtering(2, g_settings.video.second_pass_smooth); } break; case SETTING_SCALE_ENABLED: if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) { g_console.fbo_enabled = !g_console.fbo_enabled; - gl_set_fbo_enable(g_console.fbo_enabled); + gfx_ctx_set_fbo(g_console.fbo_enabled); set_delay = DELAY_MEDIUM; diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 220ca10532..2fb619e694 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -275,13 +275,6 @@ static bool gl_shader_filter_type(unsigned index, bool *smooth) return valid; } -void gl_set_fbo_enable (bool enable) -{ - gl_t *gl = driver.video_data; - gl->fbo_inited = enable; - gl->render_to_tex = false; -} - #ifdef HAVE_FBO static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) { @@ -1281,33 +1274,6 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -void ps3_set_filtering(unsigned index, bool set_smooth) -{ - gl_t *gl = driver.video_data; - - if (!gl) - return; - - if (index == 1) - { - // Apply to all PREV textures. - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - } - } - else if (index >= 2 && gl->fbo_inited) - { - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[index - 2]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - } - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -} - void ps3graphics_set_overscan(void) { gl_t * gl = driver.video_data; @@ -1333,7 +1299,10 @@ void ps3graphics_video_init(bool get_all_resolutions) video_info.height = g_console.viewports.custom_vp.height; } driver.video_data = gl_init(&video_info, NULL, NULL); - gl_set_fbo_enable(g_console.fbo_enabled); + +#ifdef HAVE_FBO + gfx_ctx_set_fbo(g_console.fbo_enabled); +#endif if(get_all_resolutions) get_all_available_resolutions(); diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 497deb9266..96bc8cf4c5 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -40,10 +40,8 @@ const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); void gl_deinit_fbo(gl_t * gl); void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); -void gl_set_fbo_enable(bool enable); void ps3_previous_resolution (void); void ps3_next_resolution (void); -void ps3_set_filtering(unsigned index, bool set_smooth); void ps3_video_deinit(void); void ps3graphics_reinit_fbos(void); void ps3graphics_set_overscan(void); From 9ef37ca9d9f390a7803e3229f6fe7897f6e53503 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 18:08:46 +0200 Subject: [PATCH 060/103] (PS3) Works just fine using standard texture formats --- ps3/ps3_video_psgl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 2fb619e694..a5fad43c71 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1065,8 +1065,8 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo else gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST; - gl->texture_type = GL_BGRA; - gl->texture_fmt = video->rgb32 ? GL_ARGB_SCE : GL_RGB5_A1; + gl->texture_type = RARCH_GL_TEXTURE_TYPE; + gl->texture_fmt = video->rgb32 ? RARCH_GL_FORMAT32 : RARCH_GL_FORMAT16; gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); glEnable(GL_TEXTURE_2D); From 9cd51921cbba64856db7478d7b9278ada7c40aaf Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 18:22:36 +0200 Subject: [PATCH 061/103] Apply vsync on init. --- gfx/context/ps3_ctx.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 60edacd8c5..8828134f2e 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -33,9 +33,12 @@ static struct texture_image menu_texture; static PSGLdevice* gl_device; static PSGLcontext* gl_context; +static unsigned swap_interval; void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { + swap_interval = interval; + if (inited) { if (interval) @@ -84,7 +87,7 @@ bool gfx_ctx_menu_init(void) glGenTextures(1, &gl->menu_texture_id); RARCH_LOG("Loading texture image for menu...\n"); - if(!texture_image_load(DEFAULT_MENU_BORDER_FILE, &menu_texture)) + if (!texture_image_load(DEFAULT_MENU_BORDER_FILE, &menu_texture)) { RARCH_ERR("Failed to load texture image for menu.\n"); return false; @@ -114,8 +117,7 @@ void gfx_ctx_get_video_size(unsigned *width, unsigned *height) bool gfx_ctx_init(void) { - PSGLinitOptions options = - { + PSGLinitOptions options = { .enable = PSGL_INIT_MAX_SPUS | PSGL_INIT_INITIALIZE_SPUS, .maxSPUs = 1, .initializeSPUs = GL_FALSE, @@ -130,20 +132,20 @@ bool gfx_ctx_init(void) PSGLdeviceParameters params; - params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | \ - PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | \ + params.enable = PSGL_DEVICE_PARAMETERS_COLOR_FORMAT | + PSGL_DEVICE_PARAMETERS_DEPTH_FORMAT | PSGL_DEVICE_PARAMETERS_MULTISAMPLING_MODE; params.colorFormat = GL_ARGB_SCE; params.depthFormat = GL_NONE; params.multisamplingMode = GL_MULTISAMPLING_NONE_SCE; - if(g_console.triple_buffering_enable) + if (g_console.triple_buffering_enable) { params.enable |= PSGL_DEVICE_PARAMETERS_BUFFERING_MODE; params.bufferingMode = PSGL_BUFFERING_MODE_TRIPLE; } - if(g_console.current_resolution_id) + if (g_console.current_resolution_id) { CellVideoOutResolution resolution; cellVideoOutGetResolution(g_console.current_resolution_id, &resolution); @@ -159,6 +161,7 @@ bool gfx_ctx_init(void) psglMakeCurrent(gl_context, gl_device); psglResetCurrentContext(); + gfx_ctx_set_swap_interval(swap_interval, true); return true; } @@ -192,8 +195,8 @@ void gfx_ctx_set_filtering(unsigned index, bool set_smooth) for (unsigned i = 0; i < TEXTURES; i++) { glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, set_smooth ? GL_LINEAR : GL_NEAREST); } } else if (index >= 2 && gl->fbo_inited) @@ -212,3 +215,4 @@ void gfx_ctx_set_fbo(bool enable) gl->fbo_inited = enable; gl->render_to_tex = enable; } + From 1b01a00e3e8d47943563052e50a2a023180d7213 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 18:40:07 +0200 Subject: [PATCH 062/103] Fix trigger happy warnings. --- gfx/gl.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 862be70d44..ad8ac7dc3e 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -158,18 +158,12 @@ static bool gl_shader_init(void) #ifdef HAVE_CG case RARCH_SHADER_CG: - { return gl_cg_init(g_settings.video.cg_shader_path); - break; - } #endif #ifdef HAVE_XML case RARCH_SHADER_BSNES: - { return gl_glsl_init(g_settings.video.bsnes_shader_path); - break; - } #endif default: @@ -304,7 +298,7 @@ static void gl_create_fbo_textures(gl_t *gl) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); GLuint filter_type = base_filt; - bool smooth; + bool smooth = false; if (gl_shader_filter_type(i + 2, &smooth)) filter_type = smooth ? GL_LINEAR : GL_NEAREST; From 336a805a5af797fe08862f1081472a8e455df8c4 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 18:33:35 +0200 Subject: [PATCH 063/103] (PS3) Got rid of warning ps3_video_psgl.c --- ps3/ps3_video_psgl.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index a5fad43c71..338b884d62 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -164,18 +164,12 @@ static bool gl_shader_init(void) #ifdef HAVE_CG case RARCH_SHADER_CG: - { return gl_cg_init(g_settings.video.cg_shader_path); - break; - } #endif #ifdef HAVE_XML case RARCH_SHADER_BSNES: - { return gl_glsl_init(g_settings.video.bsnes_shader_path); - break; - } #endif default: From 1a4c122310803512f8a5eb53f9a6f5f5433789fa Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 18:46:20 +0200 Subject: [PATCH 064/103] (PS3) Don't use custom type macros in ps3_video_psgl.c anymore --- gfx/gl_common.h | 7 +++++++ ps3/ps3_video_psgl.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/gfx/gl_common.h b/gfx/gl_common.h index a3dd4bcffa..df2115566f 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -199,10 +199,17 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #define pglActiveTexture glActiveTexture #endif +#ifdef __CELLOS_LV2__ +#define RARCH_GL_INTERNAL_FORMAT GL_ARGB_SCE +#define RARCH_GL_TEXTURE_TYPE GL_ARGB_SCE +#define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8 +#define RARCH_GL_FORMAT16 GL_RGB5_A1 +#else #define RARCH_GL_INTERNAL_FORMAT GL_RGBA #define RARCH_GL_TEXTURE_TYPE GL_BGRA #define RARCH_GL_FORMAT32 GL_UNSIGNED_INT_8_8_8_8_REV #define RARCH_GL_FORMAT16 GL_UNSIGNED_SHORT_1_5_5_5_REV +#endif void gl_shader_use(unsigned index); void gl_set_projection(gl_t *gl, bool allow_rotate); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 338b884d62..e13f786acf 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -306,8 +306,9 @@ static void gl_create_fbo_textures(gl_t *gl) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); glTexImage2D(GL_TEXTURE_2D, - 0, GL_ARGB_SCE, gl->fbo_rect[i].width, gl->fbo_rect[i].height, 0, GL_ARGB_SCE, - GL_UNSIGNED_INT_8_8_8_8, NULL); + 0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height, + 0, RARCH_GL_TEXTURE_TYPE, + RARCH_GL_FORMAT32, NULL); } glBindTexture(GL_TEXTURE_2D, 0); From 4c1c9cfff599f574ea405fcdd0018777b757dbe8 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 19:03:14 +0200 Subject: [PATCH 065/103] (PS3) Sets vsync correctly now on startup --- gfx/context/ps3_ctx.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 8828134f2e..7a18c88cc9 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -33,13 +33,12 @@ static struct texture_image menu_texture; static PSGLdevice* gl_device; static PSGLcontext* gl_context; -static unsigned swap_interval; void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { - swap_interval = interval; + (void)inited; - if (inited) + if (gl_context) { if (interval) glEnable(GL_VSYNC_SCE); @@ -161,7 +160,6 @@ bool gfx_ctx_init(void) psglMakeCurrent(gl_context, gl_device); psglResetCurrentContext(); - gfx_ctx_set_swap_interval(swap_interval, true); return true; } From e4367646c476cbac528ce8789b6bc4db1a320426 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 19:11:52 +0200 Subject: [PATCH 066/103] (PS3) Move resolution code to ps3_ctx.c --- gfx/context/ps3_ctx.c | 98 +++++++++++++++++++++++++++++++++++++++++++ ps3/ps3_video_psgl.c | 94 ----------------------------------------- 2 files changed, 98 insertions(+), 94 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 7a18c88cc9..dcf109d3a1 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -214,3 +214,101 @@ void gfx_ctx_set_fbo(bool enable) gl->render_to_tex = enable; } +/*============================================================ + MISC + TODO: Refactor +============================================================ */ + +static void get_all_available_resolutions (void) +{ + bool defaultresolution; + uint32_t i, resolution_count; + uint16_t num_videomodes; + + 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 (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_count = 0; + + for (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; +} + +void ps3_next_resolution (void) +{ + 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]; + } +} + +void ps3_previous_resolution (void) +{ + 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]; + } +} + +int ps3_check_resolution(uint32_t resolution_id) +{ + return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO,0); +} + +const char * ps3_get_resolution_label(uint32_t resolution) +{ + switch(resolution) + { + case CELL_VIDEO_OUT_RESOLUTION_480: + return "720x480 (480p)"; + case CELL_VIDEO_OUT_RESOLUTION_576: + return "720x576 (576p)"; + case CELL_VIDEO_OUT_RESOLUTION_720: + return "1280x720 (720p)"; + case CELL_VIDEO_OUT_RESOLUTION_960x1080: + return "960x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1280x1080: + return "1280x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1440x1080: + return "1440x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1600x1080: + return "1600x1080"; + case CELL_VIDEO_OUT_RESOLUTION_1080: + return "1920x1080 (1080p)"; + default: + return "Unknown"; + } +} diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index e13f786acf..bbbd5067a3 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1175,100 +1175,6 @@ const video_driver_t video_gl = .set_aspect_ratio = ps3graphics_set_aspect_ratio, }; -static void get_all_available_resolutions (void) -{ - bool defaultresolution; - uint32_t i, resolution_count; - uint16_t num_videomodes; - - 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 (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_count = 0; - - for (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; -} - -void ps3_next_resolution (void) -{ - 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]; - } -} - -void ps3_previous_resolution (void) -{ - 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]; - } -} - -int ps3_check_resolution(uint32_t resolution_id) -{ - return cellVideoOutGetResolutionAvailability(CELL_VIDEO_OUT_PRIMARY, resolution_id, CELL_VIDEO_OUT_ASPECT_AUTO,0); -} - -const char * ps3_get_resolution_label(uint32_t resolution) -{ - switch(resolution) - { - case CELL_VIDEO_OUT_RESOLUTION_480: - return "720x480 (480p)"; - case CELL_VIDEO_OUT_RESOLUTION_576: - return "720x576 (576p)"; - case CELL_VIDEO_OUT_RESOLUTION_720: - return "1280x720 (720p)"; - case CELL_VIDEO_OUT_RESOLUTION_960x1080: - return "960x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1280x1080: - return "1280x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1440x1080: - return "1440x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1600x1080: - return "1600x1080"; - case CELL_VIDEO_OUT_RESOLUTION_1080: - return "1920x1080 (1080p)"; - default: - return "Unknown"; - } -} - void ps3graphics_set_overscan(void) { gl_t * gl = driver.video_data; From 448bf2cdc851c8e0e30865b75bccf6cd29e98eb5 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 19:25:29 +0200 Subject: [PATCH 067/103] Add static start/stop/restart to console video drivers. --- driver.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/driver.h b/driver.h index 7e14f009ba..686e4fd3a6 100644 --- a/driver.h +++ b/driver.h @@ -163,7 +163,11 @@ typedef struct video_driver void (*set_swap_block_state)(void *data, bool toggle); // Block swapping from being called in ::frame(). void (*swap)(void *data); // Explicitly swap buffers. Only useful when set_swap_block_state() is set to true. void (*set_aspect_ratio)(void *data, unsigned aspectratio_idx); // TODO: refactor this properly to float. + void (*start)(void); + void (*stop)(void); + void (*restart)(void); #endif + void (*set_rotation)(void *data, unsigned rotation); } video_driver_t; From 29ba19bc737c8a67621bec5dd32046fc7412a324 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 19:29:10 +0200 Subject: [PATCH 068/103] (PS3) Implement start/stop/restart --- general.h | 1 + gfx/context/ps3_ctx.c | 7 +++- gfx/gfx_context.h | 1 + ps3/main.c | 7 ++-- ps3/menu.c | 8 ++--- ps3/ps3_video_psgl.c | 74 +++++++++++++++++++++++-------------------- ps3/ps3_video_psgl.h | 8 ++--- 7 files changed, 59 insertions(+), 47 deletions(-) diff --git a/general.h b/general.h index a0a20e80b4..15d7ee5707 100644 --- a/general.h +++ b/general.h @@ -198,6 +198,7 @@ struct console_settings #ifdef __CELLOS_LV2__ bool custom_bgm_enable; #endif + bool check_available_resolutions; bool block_config_read; bool default_sram_dir_enable; bool default_savestate_dir_enable; diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index dcf109d3a1..d1e34788fe 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -219,12 +219,15 @@ void gfx_ctx_set_fbo(bool enable) TODO: Refactor ============================================================ */ -static void get_all_available_resolutions (void) +void gfx_ctx_get_available_resolutions (void) { bool defaultresolution; uint32_t i, resolution_count; uint16_t num_videomodes; + if(g_console.check_available_resolutions) + return; + defaultresolution = true; uint32_t videomode[] = { @@ -263,6 +266,8 @@ static void get_all_available_resolutions (void) 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 ps3_next_resolution (void) diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index cf1dc44973..b7c141b4b0 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -64,6 +64,7 @@ bool gfx_ctx_menu_init(void) #ifdef RARCH_CONSOLE void gfx_ctx_set_filtering(unsigned index, bool set_smooth); +void gfx_ctx_get_available_resolutions (void); #endif #endif diff --git a/ps3/main.c b/ps3/main.c index 8c7c4cf96f..a08ccf80c1 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -508,7 +508,8 @@ int main(int argc, char *argv[]) #endif #endif - ps3graphics_video_init(true); + video_gl.start(); + ps3_input_init(); oskutil_init(&g_console.oskutil_handle, 0); @@ -559,7 +560,9 @@ begin_shutdown: if(g_console.emulator_initialized) rarch_main_deinit(); cell_pad_input_deinit(); - ps3_video_deinit(); + + video_gl.stop(); + if(g_console.oskutil_handle.is_running) oskutil_unload(&g_console.oskutil_handle); #ifdef HAVE_LOGGER diff --git a/ps3/menu.c b/ps3/menu.c index 642c8973c4..da625af80f 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1199,13 +1199,13 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(ps3_check_resolution(CELL_VIDEO_OUT_RESOLUTION_576)) { //ps3graphics_set_pal60hz(Settings.PS3PALTemporalMode60Hz); - ps3graphics_video_reinit(); + video_gl.restart(); } } else { //ps3graphics_set_pal60hz(0); - ps3graphics_video_reinit(); + video_gl.restart(); } } break; @@ -1451,7 +1451,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(CTRL_LEFT(state) || CTRL_LSTICK_LEFT(state) || CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state)) { g_console.triple_buffering_enable = !g_console.triple_buffering_enable; - ps3graphics_video_reinit(); + video_gl.restart(); set_delay = DELAY_MEDIUM; } if(CTRL_START(state)) @@ -1459,7 +1459,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(!g_console.triple_buffering_enable) { g_console.triple_buffering_enable = true; - ps3graphics_video_reinit(); + video_gl.restart(); } } break; diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index bbbd5067a3..c88335f201 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1161,30 +1161,8 @@ static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index set_viewport(gl, gl->win_width, gl->win_height, false, true); } -const video_driver_t video_gl = -{ - .init = gl_init, - .frame = gl_frame, - .alive = gl_alive, - .set_nonblock_state = gl_set_nonblock_state, - .focus = gl_focus, - .free = gl_free, - .ident = "gl", - .set_swap_block_state = ps3graphics_set_swap_block_swap, - .set_rotation = ps3graphics_set_orientation, - .set_aspect_ratio = ps3graphics_set_aspect_ratio, -}; - -void ps3graphics_set_overscan(void) -{ - gl_t * gl = driver.video_data; - if(!gl) - return; - - set_viewport(gl, gl->win_width, gl->win_height, false, true); -} - -void ps3graphics_video_init(bool get_all_resolutions) +#ifdef RARCH_CONSOLE +static void gl_start(void) { video_info_t video_info = {0}; @@ -1205,31 +1183,57 @@ void ps3graphics_video_init(bool get_all_resolutions) gfx_ctx_set_fbo(g_console.fbo_enabled); #endif - if(get_all_resolutions) - get_all_available_resolutions(); + gfx_ctx_get_available_resolutions(); - CellVideoOutState g_video_state; - cellVideoOutGetState(CELL_VIDEO_OUT_PRIMARY, 0, &g_video_state); #ifdef HAVE_CG_MENU gfx_ctx_menu_init(); #endif } -void ps3graphics_video_reinit(void) +static void gl_stop(void) +{ + void *data = driver.video_data; + driver.video_data = NULL; + gl_free(data); +} + +static void gl_restart(void) { gl_t * gl = driver.video_data; if(!gl) return; - ps3_video_deinit(); + gl_stop(); gl_cg_invalidate_context(); - ps3graphics_video_init(false); + gl_start(); } -void ps3_video_deinit(void) +#endif + +const video_driver_t video_gl = { - void *data = driver.video_data; - driver.video_data = NULL; - gl_free(data); + .init = gl_init, + .frame = gl_frame, + .alive = gl_alive, + .set_nonblock_state = gl_set_nonblock_state, + .focus = gl_focus, + .free = gl_free, + .ident = "gl", + .set_swap_block_state = ps3graphics_set_swap_block_swap, + .set_rotation = ps3graphics_set_orientation, + .set_aspect_ratio = ps3graphics_set_aspect_ratio, + .start = gl_start, + .restart = gl_restart, + .stop = gl_stop, +}; + +void ps3graphics_set_overscan(void) +{ + gl_t * gl = driver.video_data; + if(!gl) + return; + + set_viewport(gl, gl->win_width, gl->win_height, false, true); } + diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 96bc8cf4c5..4ac47a6441 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -38,16 +38,14 @@ enum const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); -void gl_deinit_fbo(gl_t * gl); -void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); void ps3_previous_resolution (void); void ps3_next_resolution (void); -void ps3_video_deinit(void); + +void gl_deinit_fbo(gl_t * gl); +void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); void ps3graphics_reinit_fbos(void); void ps3graphics_set_overscan(void); void ps3graphics_set_vsync(uint32_t vsync); -void ps3graphics_video_init(bool get_all_resolutions); -void ps3graphics_video_reinit(void); bool gl_cg_reinit(const char *path); bool gl_cg_save_cgp(const char *path, const struct gl_cg_cgp_info *info); From 1f6efc65cade74fd63fd78b13b44ee59d4883655 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 19:36:31 +0200 Subject: [PATCH 069/103] (PS3) Don't use set_swap_block callback anymore --- ps3/menu.c | 4 ++-- ps3/ps3_video_psgl.c | 11 ++--------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/ps3/menu.c b/ps3/menu.c index da625af80f..32d7f95cd3 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -2569,7 +2569,7 @@ void menu_loop(void) menu_reinit_settings(); - video_gl.set_swap_block_state(NULL, true); + gl->block_swap = true; if(g_console.ingame_menu_enable) { @@ -2665,7 +2665,7 @@ void menu_loop(void) if(g_console.ingame_menu_enable) menuStackindex--; // pop ingame menu from stack - video_gl.set_swap_block_state(NULL, false); + gl->block_swap = false; g_console.ingame_menu_enable = false; } diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index c88335f201..a93a980bb1 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1138,13 +1138,6 @@ static bool gl_focus(void *data) return gfx_ctx_window_has_focus(); } -static void ps3graphics_set_swap_block_swap(void * data, bool enable) -{ - gl_t *gl = driver.video_data; - - gl->block_swap = enable; -} - static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index) { (void)data; @@ -1208,7 +1201,6 @@ static void gl_restart(void) gl_cg_invalidate_context(); gl_start(); } - #endif const video_driver_t video_gl = @@ -1220,12 +1212,13 @@ const video_driver_t video_gl = .focus = gl_focus, .free = gl_free, .ident = "gl", - .set_swap_block_state = ps3graphics_set_swap_block_swap, .set_rotation = ps3graphics_set_orientation, .set_aspect_ratio = ps3graphics_set_aspect_ratio, +#ifdef RARCH_CONSOLE .start = gl_start, .restart = gl_restart, .stop = gl_stop, +#endif }; void ps3graphics_set_overscan(void) From 6ff8154d19059a72133b3b9af26ce4e810e74a12 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 20:50:06 +0200 Subject: [PATCH 070/103] (PS3) Abstracted rotation code to allow for different implementations --- console/griffin/hook.h | 2 +- gfx/context/ps3_ctx.c | 51 ++++++++++++++++++++++++++++++++++++++ gfx/context/sdl_ctx.c | 12 +++++++++ gfx/gl.c | 20 ++++++--------- ps3/ps3_video_psgl.c | 56 ++++++++++-------------------------------- 5 files changed, 84 insertions(+), 57 deletions(-) diff --git a/console/griffin/hook.h b/console/griffin/hook.h index 45e556cfe2..561a03b959 100644 --- a/console/griffin/hook.h +++ b/console/griffin/hook.h @@ -37,7 +37,7 @@ #define video_focus_func() gl_focus(driver.video_data) #define video_xml_shader_func(path) driver.video->xml_shader(driver.video_data, path) #define video_free_func() gl_free(driver.video_data) -#define video_set_rotation_func(orientation) ps3graphics_set_orientation(driver.video_data, orientation) +#define video_set_rotation_func(rotation) gl_set_rotation(driver.video_data, rotation) #define video_set_aspect_ratio_func(aspectratio_idx) ps3graphics_set_aspect_ratio(driver.video_data, aspectratio_idx) #define input_init_func() ps3_input_initialize() diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index d1e34788fe..e4aaabb2f1 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -34,6 +34,32 @@ static struct texture_image menu_texture; static PSGLdevice* gl_device; static PSGLcontext* gl_context; +// Other vertex orientations +static const GLfloat vertexes_90[] = { + 0, 1, + 1, 1, + 1, 0, + 0, 0 +}; + +static const GLfloat vertexes_180[] = { + 1, 1, + 1, 0, + 0, 0, + 0, 1 +}; + +static const GLfloat vertexes_270[] = { + 1, 0, + 0, 0, + 0, 1, + 1, 1 +}; + +//forward decls +extern const GLfloat *vertex_ptr; +extern const GLfloat *default_vertex_ptr; + void gfx_ctx_set_swap_interval(unsigned interval, bool inited) { (void)inited; @@ -317,3 +343,28 @@ const char * ps3_get_resolution_label(uint32_t resolution) return "Unknown"; } } + +void gfx_ctx_set_rotation(gl_t *gl, bool allow_rotate) +{ + if(allow_rotate) + { + switch (gl->rotation) + { + case 90: + vertex_ptr = vertexes_90; + break; + case 180: + vertex_ptr = vertexes_180; + break; + case 270: + vertex_ptr = vertexes_270; + break; + case 0: + default: + vertex_ptr = default_vertex_ptr; + break; + } + } + + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); +} diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index 707b915bcc..1d18502026 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -397,3 +397,15 @@ void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) *input = NULL; } +void gfx_ctx_set_rotation(gl_t *gl, bool allow_rotate) +{ + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + if (allow_rotate) + glRotatef(gl->rotation, 0, 0, 1); + + glOrtho(0, 1, 0, 1, -1, 1); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} diff --git a/gfx/gl.c b/gfx/gl.c index ad8ac7dc3e..0ab27d2591 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -77,6 +77,9 @@ const GLfloat white_color[] = { 1, 1, 1, 1, }; +const GLfloat *vertex_ptr = vertexes_flipped; +const GLfloat *default_vertex_ptr = vertexes_flipped; + #ifdef HAVE_SDL #define LOAD_SYM(sym) if (!p##sym) { SDL_SYM_WRAP(p##sym, #sym) } #endif @@ -422,16 +425,7 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) void gl_set_projection(gl_t *gl, bool allow_rotate) { - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - if (allow_rotate) - glRotatef(gl->rotation, 0, 0, 1); - - glOrtho(0, 1, 0, 1, -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - + gfx_ctx_set_rotation(gl, allow_rotate); gl_shader_set_proj_matrix(); } @@ -479,7 +473,7 @@ void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, static void gl_set_rotation(void *data, unsigned rotation) { - gl_t *gl = (gl_t*)data; + gl_t * gl = driver.video_data; gl->rotation = 90 * rotation; gl_set_projection(gl, true); } @@ -695,7 +689,7 @@ static void gl_frame_fbo(gl_t *gl, const struct gl_tex_info *tex_info) gl->vp_width, gl->vp_height, gl->frame_count, tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); glDrawArrays(GL_QUADS, 0, 4); glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); @@ -1046,7 +1040,7 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); + glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index a93a980bb1..5fee06c4fa 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -50,30 +50,6 @@ static const GLfloat vertexes_flipped[] = { 1, 0 }; -// Other vertex orientations -static const GLfloat vertexes_90[] = { - 0, 1, - 1, 1, - 1, 0, - 0, 0 -}; - -static const GLfloat vertexes_180[] = { - 1, 1, - 1, 0, - 0, 0, - 0, 1 -}; - -static const GLfloat vertexes_270[] = { - 1, 0, - 0, 0, - 0, 1, - 1, 1 -}; - -static const GLfloat *vertex_ptr = vertexes_flipped; - // Used when rendering to an FBO. // Texture coords have to be aligned with vertex coordinates. static const GLfloat vertexes[] = { @@ -97,6 +73,9 @@ static const GLfloat white_color[] = { 1, 1, 1, 1, }; +const GLfloat *vertex_ptr = vertexes_flipped; +const GLfloat *default_vertex_ptr = vertexes_flipped; + #ifdef HAVE_FBO #if defined(_WIN32) && !defined(RARCH_CONSOLE) static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; @@ -634,26 +613,17 @@ static void check_window(gl_t *gl) gl->should_resize = true; } -static void ps3graphics_set_orientation(void * data, uint32_t orientation) +void gl_set_projection(gl_t *gl, bool allow_rotate) { - (void)data; - switch (orientation) - { - case ORIENTATION_NORMAL: - vertex_ptr = vertexes_flipped; - break; - case ORIENTATION_VERTICAL: - vertex_ptr = vertexes_90; - break; - case ORIENTATION_FLIPPED: - vertex_ptr = vertexes_180; - break; - case ORIENTATION_FLIPPED_ROTATED: - vertex_ptr = vertexes_270; - break; - } + gfx_ctx_set_rotation(gl, allow_rotate); + gl_shader_set_proj_matrix(); +} - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); +static void gl_set_rotation(void *data, unsigned rotation) +{ + gl_t * gl = driver.video_data; + gl->rotation = 90 * rotation; + gl_set_projection(gl, true); } #ifdef __CELLOS_LV2__ @@ -1212,7 +1182,7 @@ const video_driver_t video_gl = .focus = gl_focus, .free = gl_free, .ident = "gl", - .set_rotation = ps3graphics_set_orientation, + .set_rotation = gl_set_rotation, .set_aspect_ratio = ps3graphics_set_aspect_ratio, #ifdef RARCH_CONSOLE .start = gl_start, From 1c2c2e1a37955e359f50ed77468112b72138ce39 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 20:55:11 +0200 Subject: [PATCH 071/103] Rename to gfx_ctx_set_projection --- gfx/context/ps3_ctx.c | 2 +- gfx/context/sdl_ctx.c | 2 +- gfx/gfx_context.h | 2 ++ gfx/gl.c | 2 +- ps3/ps3_video_psgl.c | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index e4aaabb2f1..01522551e6 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -344,7 +344,7 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -void gfx_ctx_set_rotation(gl_t *gl, bool allow_rotate) +void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) { if(allow_rotate) { diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index 1d18502026..0742c12dfb 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -397,7 +397,7 @@ void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) *input = NULL; } -void gfx_ctx_set_rotation(gl_t *gl, bool allow_rotate) +void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index b7c141b4b0..9cb0c55e03 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -67,5 +67,7 @@ void gfx_ctx_set_filtering(unsigned index, bool set_smooth); void gfx_ctx_get_available_resolutions (void); #endif +void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate); + #endif diff --git a/gfx/gl.c b/gfx/gl.c index 0ab27d2591..c51d2501fc 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -425,7 +425,7 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) void gl_set_projection(gl_t *gl, bool allow_rotate) { - gfx_ctx_set_rotation(gl, allow_rotate); + gfx_ctx_set_projection(gl, allow_rotate); gl_shader_set_proj_matrix(); } diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index 5fee06c4fa..b6a0f4703a 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -615,7 +615,7 @@ static void check_window(gl_t *gl) void gl_set_projection(gl_t *gl, bool allow_rotate) { - gfx_ctx_set_rotation(gl, allow_rotate); + gfx_ctx_set_projection(gl, allow_rotate); gl_shader_set_proj_matrix(); } From 0171023edc80901c6028f144b8155d74d9828aa8 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 21:24:55 +0200 Subject: [PATCH 072/103] Fix build. --- gfx/context/sdl_ctx.c | 3 +++ gfx/context/sdl_ctx.h | 1 - gfx/gfx_context.h | 9 ++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index 0742c12dfb..12f8b576d5 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -397,6 +397,7 @@ void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) *input = NULL; } +#ifdef HAVE_OPENGL void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) { glMatrixMode(GL_PROJECTION); @@ -409,3 +410,5 @@ void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } +#endif + diff --git a/gfx/context/sdl_ctx.h b/gfx/context/sdl_ctx.h index ce1b5f4b21..7f3167bc52 100644 --- a/gfx/context/sdl_ctx.h +++ b/gfx/context/sdl_ctx.h @@ -17,7 +17,6 @@ #define _SDL_CTX_H #include "SDL.h" -#include "SDL_opengl.h" #include "SDL_version.h" #if SDL_VERSION_ATLEAST(1, 3, 0) diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index 9cb0c55e03..026d2c4e51 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -21,10 +21,15 @@ #include "../boolean.h" #include "../driver.h" + #ifdef HAVE_CONFIG_H #include "../config.h" #endif +#ifdef HAVE_OPENGL +#include "gl_common.h" +#endif + #ifdef HAVE_SDL #include "SDL_syswm.h" #endif @@ -64,10 +69,12 @@ bool gfx_ctx_menu_init(void) #ifdef RARCH_CONSOLE void gfx_ctx_set_filtering(unsigned index, bool set_smooth); -void gfx_ctx_get_available_resolutions (void); +void gfx_ctx_get_available_resolutions(void); #endif +#ifdef HAVE_OPENGL void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate); +#endif #endif From 232a3850d1fac9a86e1b208645b5ac3dd0390e42 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 21:42:30 +0200 Subject: [PATCH 073/103] (PS3) Menu texture is no longer rotated --- ps3/ps3_video_psgl.c | 1 + 1 file changed, 1 insertion(+) diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index b6a0f4703a..c175921fcd 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -887,6 +887,7 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr); glDrawArrays(GL_QUADS, 0, 4); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); } From 4f9b284c6d2db5c764e380f51908d4098975835b Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 21:52:52 +0200 Subject: [PATCH 074/103] (PS3) Restructure / move set functions to ps3_ctx.c --- console/griffin/hook.h | 2 +- gfx/context/ps3_ctx.c | 23 +++++++++++++++++++++++ ps3/menu.c | 26 +++++++++++++------------- ps3/ps3_video_psgl.c | 25 ------------------------- ps3/ps3_video_psgl.h | 2 -- 5 files changed, 37 insertions(+), 41 deletions(-) diff --git a/console/griffin/hook.h b/console/griffin/hook.h index 561a03b959..8f6a31ef14 100644 --- a/console/griffin/hook.h +++ b/console/griffin/hook.h @@ -38,7 +38,7 @@ #define video_xml_shader_func(path) driver.video->xml_shader(driver.video_data, path) #define video_free_func() gl_free(driver.video_data) #define video_set_rotation_func(rotation) gl_set_rotation(driver.video_data, rotation) -#define video_set_aspect_ratio_func(aspectratio_idx) ps3graphics_set_aspect_ratio(driver.video_data, aspectratio_idx) +#define video_set_aspect_ratio_func(aspectratio_idx) gfx_ctx_set_aspect_ratio(driver.video_data, aspectratio_idx) #define input_init_func() ps3_input_initialize() #define input_poll_func() ps3_input_poll(driver.input_data) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 01522551e6..87b833e35f 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -368,3 +368,26 @@ void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); } + +void gfx_ctx_set_aspect_ratio(void * data, unsigned aspectratio_index) +{ + (void)data; + gl_t * gl = driver.video_data; + + 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; + g_settings.video.force_aspect = false; + gl->keep_aspect = true; + gl->should_resize = true; +} + +void gfx_ctx_set_overscan(void) +{ + gl_t * gl = driver.video_data; + if(!gl) + return; + + gl->should_resize = true; +} diff --git a/ps3/menu.c b/ps3/menu.c index 32d7f95cd3..072131f05f 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -1303,7 +1303,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(g_console.aspect_ratio_index > 0) { g_console.aspect_ratio_index--; - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); set_delay = DELAY_SMALL; } } @@ -1312,7 +1312,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) g_console.aspect_ratio_index++; if(g_console.aspect_ratio_index < ASPECT_RATIO_END) { - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); set_delay = DELAY_SMALL; } else @@ -1321,7 +1321,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(CTRL_START(state)) { g_console.aspect_ratio_index = ASPECT_RATIO_4_3; - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); } break; case SETTING_HW_TEXTURE_FILTER: @@ -1412,7 +1412,7 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(g_console.overscan_amount == 0.0f) g_console.overscan_enable = false; - ps3graphics_set_overscan(); + gfx_ctx_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state)) @@ -1423,14 +1423,14 @@ static void producesettingentry(menu * menu_obj, uint64_t switchvalue) if(g_console.overscan_amount == 0.0f) g_console.overscan_enable = 0; - ps3graphics_set_overscan(); + gfx_ctx_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_START(state)) { g_console.overscan_amount = 0.0f; g_console.overscan_enable = false; - ps3graphics_set_overscan(); + gfx_ctx_set_overscan(); } break; case SETTING_THROTTLE_MODE: @@ -2111,7 +2111,7 @@ static void ingame_menu(uint32_t menu_id) if(g_console.aspect_ratio_index > 0) { g_console.aspect_ratio_index--; - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); set_delay = DELAY_LONG; } } @@ -2120,7 +2120,7 @@ static void ingame_menu(uint32_t menu_id) g_console.aspect_ratio_index++; if(g_console.aspect_ratio_index < ASPECT_RATIO_END) { - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); set_delay = DELAY_LONG; } else @@ -2129,7 +2129,7 @@ static void ingame_menu(uint32_t menu_id) if(CTRL_START(state)) { g_console.aspect_ratio_index = ASPECT_RATIO_4_3; - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); } strlcpy(comment, "Press LEFT or RIGHT to change the [Aspect Ratio].\nPress START to reset back to default values.", sizeof(comment)); break; @@ -2142,7 +2142,7 @@ static void ingame_menu(uint32_t menu_id) if(g_console.overscan_amount == 0.00f) g_console.overscan_enable = false; - ps3graphics_set_overscan(); + gfx_ctx_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_RIGHT(state) || CTRL_LSTICK_RIGHT(state) || CTRL_CROSS(state) || CTRL_LSTICK_RIGHT(state)) @@ -2152,14 +2152,14 @@ static void ingame_menu(uint32_t menu_id) if(g_console.overscan_amount == 0.0f) g_console.overscan_amount = false; - ps3graphics_set_overscan(); + gfx_ctx_set_overscan(); set_delay = DELAY_SMALLEST; } if(CTRL_START(state)) { g_console.overscan_amount = 0.0f; g_console.overscan_enable = false; - ps3graphics_set_overscan(); + gfx_ctx_set_overscan(); } strlcpy(comment, "Press LEFT or RIGHT to change the [Overscan] settings.\nPress START to reset back to default values.", sizeof(comment)); break; @@ -2240,7 +2240,7 @@ static void ingame_menu(uint32_t menu_id) if(CTRL_CROSS(state)) { g_console.aspect_ratio_index = ASPECT_RATIO_CUSTOM; - video_gl.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(NULL, g_console.aspect_ratio_index); while(stuck_in_loop && g_console.ingame_menu_enable) { state = cell_pad_input_poll_device(0); diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c index c175921fcd..d4686a873d 100644 --- a/ps3/ps3_video_psgl.c +++ b/ps3/ps3_video_psgl.c @@ -1109,22 +1109,6 @@ static bool gl_focus(void *data) return gfx_ctx_window_has_focus(); } -static void ps3graphics_set_aspect_ratio(void * data, uint32_t aspectratio_index) -{ - (void)data; - gl_t * gl = driver.video_data; - - 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; - g_settings.video.force_aspect = false; - gl->keep_aspect = true; - - - set_viewport(gl, gl->win_width, gl->win_height, false, true); -} - #ifdef RARCH_CONSOLE static void gl_start(void) { @@ -1184,7 +1168,6 @@ const video_driver_t video_gl = .free = gl_free, .ident = "gl", .set_rotation = gl_set_rotation, - .set_aspect_ratio = ps3graphics_set_aspect_ratio, #ifdef RARCH_CONSOLE .start = gl_start, .restart = gl_restart, @@ -1192,12 +1175,4 @@ const video_driver_t video_gl = #endif }; -void ps3graphics_set_overscan(void) -{ - gl_t * gl = driver.video_data; - if(!gl) - return; - - set_viewport(gl, gl->win_width, gl->win_height, false, true); -} diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index 4ac47a6441..b1f8039b5d 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -44,8 +44,6 @@ void ps3_next_resolution (void); void gl_deinit_fbo(gl_t * gl); void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); void ps3graphics_reinit_fbos(void); -void ps3graphics_set_overscan(void); -void ps3graphics_set_vsync(uint32_t vsync); bool gl_cg_reinit(const char *path); bool gl_cg_save_cgp(const char *path, const struct gl_cg_cgp_info *info); From b6131dfcd78ebaa21f009f78245a19a7e230cd48 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 22:39:29 +0200 Subject: [PATCH 075/103] (PS3) PS3 now uses gl.c - ps3_video_psgl.c removed --- console/griffin/griffin.c | 8 +- gfx/context/ps3_ctx.c | 17 +- gfx/gfx_context.h | 4 +- gfx/gl.c | 206 ++++++- gfx/gl_common.h | 12 +- ps3/ps3_video_psgl.c | 1178 ------------------------------------- ps3/ps3_video_psgl.h | 2 - 7 files changed, 211 insertions(+), 1216 deletions(-) delete mode 100644 ps3/ps3_video_psgl.c diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 36db2caa78..9335f7f4b4 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -49,7 +49,13 @@ VIDEO #if defined(__CELLOS_LV2__) #include "../../gfx/context/ps3_ctx.c" #include "../../gfx/shader_cg.c" -#include "../../ps3/ps3_video_psgl.c" +#endif + +#ifdef HAVE_OPENGL +#include "../../gfx/gl.c" +#endif + +#if defined(__CELLOS_LV2__) #include "../../ps3/image.c" #elif defined(_XBOX) #include "../../gfx/shader_hlsl.c" diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 87b833e35f..6f3b489994 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -30,6 +30,10 @@ #include "ps3_ctx.h" +#ifdef HAVE_OPENGLES +#define glOrtho glOrthof +#endif + static struct texture_image menu_texture; static PSGLdevice* gl_device; static PSGLcontext* gl_context; @@ -96,6 +100,8 @@ bool gfx_ctx_window_has_focus(void) return true; } +void gfx_ctx_set_resize(unsigned width, unsigned height) { } + void gfx_ctx_swap_buffers(void) { psglSwap(); @@ -135,6 +141,8 @@ bool gfx_ctx_menu_init(void) return true; } +void gfx_ctx_update_window_title(bool reset) { } + void gfx_ctx_get_video_size(unsigned *width, unsigned *height) { psglGetDeviceDimensions(gl_device, width, height); @@ -344,8 +352,11 @@ const char * ps3_get_resolution_label(uint32_t resolution) } } -void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) +void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) { + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + if(allow_rotate) { switch (gl->rotation) @@ -367,6 +378,10 @@ void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate) } glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); + + glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->near, ortho->far); + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); } void gfx_ctx_set_aspect_ratio(void * data, unsigned aspectratio_index) diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index 026d2c4e51..996033e90d 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -64,7 +64,7 @@ bool gfx_ctx_window_has_focus(void); void gfx_ctx_input_driver(const input_driver_t **input, void **input_data); #ifdef HAVE_CG_MENU -bool gfx_ctx_menu_init(void) +bool gfx_ctx_menu_init(void); #endif #ifdef RARCH_CONSOLE @@ -73,7 +73,7 @@ void gfx_ctx_get_available_resolutions(void); #endif #ifdef HAVE_OPENGL -void gfx_ctx_set_projection(gl_t *gl, bool allow_rotate); +void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate); #endif #endif diff --git a/gfx/gl.c b/gfx/gl.c index c51d2501fc..01a7dfb4fe 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -423,40 +423,79 @@ static void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) //////////// -void gl_set_projection(gl_t *gl, bool allow_rotate) +void gl_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) { - gfx_ctx_set_projection(gl, allow_rotate); +#ifdef RARCH_CONSOLE + 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; + } +#endif + + gfx_ctx_set_projection(gl, ortho, allow_rotate); gl_shader_set_proj_matrix(); } -void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) +static 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; + + vp_x_temp = 0; + vp_y_temp = 0; + vp_width_temp = width; + vp_height_temp = height; + + ortho.left = 0.0f; + ortho.right = 1.0f; + ortho.bottom = 0.0f; + ortho.top = 1.0f; + ortho.near = -1.0f; + ortho.far = 1.0f; + if (gl->keep_aspect && !force_full) { float desired_aspect = g_settings.video.aspect_ratio; float device_aspect = (float)width / height; + float delta; - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - // assume they are actually equal. +#ifdef RARCH_CONSOLE + 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; + } + else +#endif if (fabs(device_aspect - desired_aspect) < 0.0001) - glViewport(0, 0, width, height); + { + // 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) { - float delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - glViewport(width * (0.5 - delta), 0, 2.0 * width * delta, height); - width = 2.0 * width * delta; + 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 { - float delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; - glViewport(0, height * (0.5 - delta), width, 2.0 * height * delta); - height = 2.0 * height * delta; + 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); } } - else - glViewport(0, 0, width, height); - gl_set_projection(gl, allow_rotate); + glViewport(vp_x_temp, vp_y_temp, vp_width_temp, vp_height_temp); + + gl_set_projection(gl, &ortho, allow_rotate); gl->vp_width = width; gl->vp_height = height; @@ -473,9 +512,18 @@ 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; + + ortho.left = 0; + ortho.right = 1; + ortho.bottom = 0; + ortho.top = 1; + ortho.near = -1; + ortho.far = 1; + gl_t * gl = driver.video_data; gl->rotation = 90 * rotation; - gl_set_projection(gl, true); + gl_set_projection(gl, &ortho, true); } static inline void set_lut_texture_coords(const GLfloat *coords) @@ -720,12 +768,20 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi { gl->last_width[gl->tex_index] = width; gl->last_height[gl->tex_index] = height; + +#ifdef HAVE_OPENGL_TEXREF + glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, + gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size, + gl->tex_w * gl->tex_h * gl->base_size, + gl->empty_buf); +#else glPixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(pitch)); glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, gl->tex_w, gl->tex_h, gl->texture_type, gl->texture_fmt, gl->empty_buf); +#endif GLfloat xamt = (GLfloat)width / gl->tex_w; GLfloat yamt = (GLfloat)height / gl->tex_h; @@ -885,13 +941,42 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei } gfx_ctx_update_window_title(false); - gfx_ctx_swap_buffers(); + +#ifdef RARCH_CONSOLE + if(!gl->block_swap) +#endif + gfx_ctx_swap_buffers(); + +#ifdef HAVE_CG_MENU + if(gl->menu_render) + { + gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); + + gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, + gl->win_height, gl->win_width, gl->win_height, gl->frame_count, + NULL, NULL, NULL, 0); + + gl_set_viewport(gl, gl->win_width, gl->win_height, true, false); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + + glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr); + glDrawArrays(GL_QUADS, 0, 4); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + } +#endif return true; } static void gl_free(void *data) { +#ifdef RARCH_CONSOLE + if (driver.video_data) + return; +#endif + gl_t *gl = (gl_t*)data; gl_deinit_font(gl); @@ -934,6 +1019,11 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo gfx_set_dwm(); #endif +#ifdef RARCH_CONSOLE + if (driver.video_data) + return driver.video_data; +#endif + gl_t *gl = (gl_t*)calloc(1, sizeof(gl_t)); if (!gl) return NULL; @@ -965,9 +1055,11 @@ static void *gl_init(const video_info_t *video, const input_driver_t **input, vo return NULL; } +#ifndef RARCH_CONSOLE gfx_ctx_update_window_title(true); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); +#endif #if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) // Win32 GL lib doesn't have some functions needed for XML shaders. @@ -1134,20 +1226,72 @@ static bool gl_xml_shader(void *data, const char *path) } #endif -const video_driver_t video_gl = { - gl_init, - gl_frame, - gl_set_nonblock_state, - gl_alive, - gl_focus, -#ifdef HAVE_XML - gl_xml_shader, -#else - NULL, +#ifdef RARCH_CONSOLE +static void gl_start(void) +{ + video_info_t video_info = {0}; + + // Might have to supply correct values here. + video_info.vsync = g_settings.video.vsync; + video_info.force_aspect = false; + 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) + { + video_info.width = g_console.viewports.custom_vp.width; + video_info.height = g_console.viewports.custom_vp.height; + } + driver.video_data = gl_init(&video_info, NULL, NULL); + +#ifdef HAVE_FBO + gfx_ctx_set_fbo(g_console.fbo_enabled); #endif - gl_free, - "gl", - gl_set_rotation, + gfx_ctx_get_available_resolutions(); + +#ifdef HAVE_CG_MENU + gfx_ctx_menu_init(); +#endif +} + +static void gl_stop(void) +{ + void *data = driver.video_data; + driver.video_data = NULL; + gl_free(data); +} + +static void gl_restart(void) +{ + gl_t * gl = driver.video_data; + + if(!gl) + return; + + gl_stop(); + gl_cg_invalidate_context(); + gl_start(); +} +#endif + +const video_driver_t video_gl = { + .init = gl_init, + .frame = gl_frame, + .set_nonblock_state = gl_set_nonblock_state, + .alive = gl_alive, + .focus = gl_focus, +#ifdef HAVE_XML + .xml_shader = gl_xml_shader, +#else + .xml_shader = NULL, +#endif + .free = gl_free, + .ident = "gl", + .set_rotation = gl_set_rotation, +#ifdef RARCH_CONSOLE + .start = gl_start, + .restart = gl_restart, + .stop = gl_stop, +#endif }; - diff --git a/gfx/gl_common.h b/gfx/gl_common.h index df2115566f..47ae3cc630 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -107,6 +107,16 @@ struct gl_fbo_scale bool valid; }; +typedef struct +{ + float left; + float right; + float bottom; + float top; + float near; + float far; +} ortho_t; + struct gl_tex_info { GLuint tex; @@ -212,7 +222,7 @@ extern PFNGLACTIVETEXTUREPROC pglActiveTexture; #endif void gl_shader_use(unsigned index); -void gl_set_projection(gl_t *gl, bool allow_rotate); +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); #endif diff --git a/ps3/ps3_video_psgl.c b/ps3/ps3_video_psgl.c deleted file mode 100644 index d4686a873d..0000000000 --- a/ps3/ps3_video_psgl.c +++ /dev/null @@ -1,1178 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - - -#include "../driver.h" - -#include "ps3_video_psgl.h" - -#include -#include "../libretro.h" -#include -#include -#include -#include - -#include "../gfx/state_tracker.h" -#include "../gfx/shader_cg.h" -#include "../general.h" -#include "../compat/strl.h" -#include "shared.h" - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "../gfx/gl_font.h" -#include "../compat/strl.h" - -#define BLUE 0xffff0000u -#define WHITE 0xffffffffu - -// Used for the last pass when rendering to the back buffer. -static const GLfloat vertexes_flipped[] = { - 0, 0, - 0, 1, - 1, 1, - 1, 0 -}; - -// Used when rendering to an FBO. -// Texture coords have to be aligned with vertex coordinates. -static const GLfloat vertexes[] = { - 0, 1, - 0, 0, - 1, 0, - 1, 1 -}; - -static const GLfloat tex_coords[] = { - 0, 1, - 0, 0, - 1, 0, - 1, 1 -}; - -static const GLfloat white_color[] = { - 1, 1, 1, 1, - 1, 1, 1, 1, - 1, 1, 1, 1, - 1, 1, 1, 1, -}; - -const GLfloat *vertex_ptr = vertexes_flipped; -const GLfloat *default_vertex_ptr = vertexes_flipped; - -#ifdef HAVE_FBO -#if defined(_WIN32) && !defined(RARCH_CONSOLE) -static PFNGLGENFRAMEBUFFERSPROC pglGenFramebuffers = NULL; -static PFNGLBINDFRAMEBUFFERPROC pglBindFramebuffer = NULL; -static PFNGLFRAMEBUFFERTEXTURE2DPROC pglFramebufferTexture2D = NULL; -static PFNGLCHECKFRAMEBUFFERSTATUSPROC pglCheckFramebufferStatus = NULL; -static PFNGLDELETEFRAMEBUFFERSPROC pglDeleteFramebuffers = NULL; - -static bool load_fbo_proc(void) -{ - LOAD_SYM(glGenFramebuffers); - LOAD_SYM(glBindFramebuffer); - LOAD_SYM(glFramebufferTexture2D); - LOAD_SYM(glCheckFramebufferStatus); - LOAD_SYM(glDeleteFramebuffers); - - return pglGenFramebuffers && pglBindFramebuffer && pglFramebufferTexture2D && - pglCheckFramebufferStatus && pglDeleteFramebuffers; -} -#elif defined(HAVE_OPENGLES) -#define pglGenFramebuffers glGenFramebuffersOES -#define pglBindFramebuffer glBindFramebufferOES -#define pglFramebufferTexture2D glFramebufferTexture2DOES -#define pglCheckFramebufferStatus glCheckFramebufferStatusOES -#define pglDeleteFramebuffers glDeleteFramebuffersOES -#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES -#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_EXT -#define GL_FRAMEBUFFER_COMPLETE GL_FRAMEBUFFER_COMPLETE_OES -#define glOrtho glOrthof -static bool load_fbo_proc(void) { return true; } -#else -#define pglGenFramebuffers glGenFramebuffers -#define pglBindFramebuffer glBindFramebuffer -#define pglFramebufferTexture2D glFramebufferTexture2D -#define pglCheckFramebufferStatus glCheckFramebufferStatus -#define pglDeleteFramebuffers glDeleteFramebuffers -static bool load_fbo_proc(void) { return true; } -#endif -#endif - -/*============================================================ - GL IMPLEMENTATION -============================================================ */ - -static bool gl_shader_init(void) -{ - switch (g_settings.video.shader_type) - { - case RARCH_SHADER_AUTO: - { - if (*g_settings.video.cg_shader_path && *g_settings.video.bsnes_shader_path) - RARCH_WARN("Both Cg and bSNES XML shader are defined in config file. Cg shader will be selected by default.\n"); - -#ifdef HAVE_CG - if (*g_settings.video.cg_shader_path) - return gl_cg_init(g_settings.video.cg_shader_path); -#endif - -#ifdef HAVE_XML - if (*g_settings.video.bsnes_shader_path) - return gl_glsl_init(g_settings.video.bsnes_shader_path); -#endif - break; - } - -#ifdef HAVE_CG - case RARCH_SHADER_CG: - return gl_cg_init(g_settings.video.cg_shader_path); -#endif - -#ifdef HAVE_XML - case RARCH_SHADER_BSNES: - return gl_glsl_init(g_settings.video.bsnes_shader_path); -#endif - - default: - break; - } - - return true; -} - -static void gl_shader_use(unsigned index) -{ -#ifdef HAVE_CG - gl_cg_use(index); -#endif - -#ifdef HAVE_XML - gl_glsl_use(index); -#endif -} - -static void gl_shader_deinit(void) -{ -#ifdef HAVE_CG - gl_cg_deinit(); -#endif - -#ifdef HAVE_XML - gl_glsl_deinit(); -#endif -} - -static void gl_shader_set_proj_matrix(void) -{ -#ifdef HAVE_CG - gl_cg_set_proj_matrix(); -#endif - -#ifdef HAVE_XML - gl_glsl_set_proj_matrix(); -#endif -} - -static void gl_shader_set_params(unsigned width, unsigned height, - unsigned tex_width, unsigned tex_height, - unsigned out_width, unsigned out_height, - unsigned frame_count, - const struct gl_tex_info *info, - const struct gl_tex_info *prev_info, - const struct gl_tex_info *fbo_info, unsigned fbo_info_cnt) -{ -#ifdef HAVE_CG - gl_cg_set_params(width, height, - tex_width, tex_height, - out_width, out_height, - frame_count, info, prev_info, fbo_info, fbo_info_cnt); -#endif - -#ifdef HAVE_XML - gl_glsl_set_params(width, height, - tex_width, tex_height, - out_width, out_height, - frame_count, info, prev_info, fbo_info, fbo_info_cnt); -#endif -} - -static unsigned gl_shader_num(void) -{ -#ifdef HAVE_CG - unsigned cg_num = gl_cg_num(); - if (cg_num) - return cg_num; -#endif - -#ifdef HAVE_XML - unsigned glsl_num = gl_glsl_num(); - if (glsl_num) - return glsl_num; -#endif - - return 0; -} - -static bool gl_shader_filter_type(unsigned index, bool *smooth) -{ - bool valid = false; - -#ifdef HAVE_CG - if (!valid) - valid = gl_cg_filter_type(index, smooth); -#endif - -#ifdef HAVE_XML - if (!valid) - valid = gl_glsl_filter_type(index, smooth); -#endif - - return valid; -} - -#ifdef HAVE_FBO -static void gl_shader_scale(unsigned index, struct gl_fbo_scale *scale) -{ - scale->valid = false; - -#ifdef HAVE_CG - if (!scale->valid) - gl_cg_shader_scale(index, scale); -#endif - -#ifdef HAVE_XML - if (!scale->valid) - gl_glsl_shader_scale(index, scale); -#endif -} -#endif - -static void gl_create_fbo_textures(gl_t *gl) -{ - glGenTextures(gl->fbo_pass, gl->fbo_texture); - - GLuint base_filt = g_settings.video.second_pass_smooth ? GL_LINEAR : GL_NEAREST; - for (int i = 0; i < gl->fbo_pass; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i]); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); - - GLuint filter_type = base_filt; - bool smooth = false; - if (gl_shader_filter_type(i + 2, &smooth)) - filter_type = smooth ? GL_LINEAR : GL_NEAREST; - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter_type); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter_type); - - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT, gl->fbo_rect[i].width, gl->fbo_rect[i].height, - 0, RARCH_GL_TEXTURE_TYPE, - RARCH_GL_FORMAT32, NULL); - } - - glBindTexture(GL_TEXTURE_2D, 0); -} - -void gl_deinit_fbo(gl_t *gl) -{ - if (gl->fbo_inited) - { - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); - memset(gl->fbo_texture, 0, sizeof(gl->fbo_texture)); - memset(gl->fbo, 0, sizeof(gl->fbo)); - gl->fbo_inited = false; - gl->render_to_tex = false; - gl->fbo_pass = 0; - } -} - -// Horribly long and complex FBO init :D -void gl_init_fbo(gl_t *gl, unsigned width, unsigned height) -{ - struct gl_fbo_scale scale, scale_last; - gl_shader_scale(1, &scale); - gl_shader_scale(gl_shader_num(), &scale_last); - - gl->fbo_pass = gl_shader_num() - 1; - if (scale_last.valid) - gl->fbo_pass++; - - if (gl->fbo_pass <= 0) - gl->fbo_pass = 1; - - if (!scale.valid) - { - scale.scale_x = g_settings.video.fbo_scale_x; - scale.scale_y = g_settings.video.fbo_scale_y; - scale.type_x = scale.type_y = RARCH_SCALE_INPUT; - } - - switch (scale.type_x) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[0].width = width * next_pow2(ceil(scale.scale_x)); - break; - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[0].width = next_pow2(scale.abs_x); - break; - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[0].width = next_pow2(gl->win_width); - break; - default: - break; - } - - switch (scale.type_y) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[0].height = height * next_pow2(ceil(scale.scale_y)); - break; - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[0].height = next_pow2(scale.abs_y); - break; - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[0].height = next_pow2(gl->win_height); - break; - default: - break; - } - - unsigned last_width = gl->fbo_rect[0].width, last_height = gl->fbo_rect[0].height; - gl->fbo_scale[0] = scale; - - RARCH_LOG("Creating FBO 0 @ %ux%u\n", gl->fbo_rect[0].width, gl->fbo_rect[0].height); - - for (int i = 1; i < gl->fbo_pass; i++) - { - gl_shader_scale(i + 1, &gl->fbo_scale[i]); - if (gl->fbo_scale[i].valid) - { - switch (gl->fbo_scale[i].type_x) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[i].width = last_width * next_pow2(ceil(gl->fbo_scale[i].scale_x)); - break; - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[i].width = next_pow2(gl->fbo_scale[i].abs_x); - break; - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[i].width = next_pow2(gl->win_width); - break; - default: - break; - } - - switch (gl->fbo_scale[i].type_y) - { - case RARCH_SCALE_INPUT: - gl->fbo_rect[i].height = last_height * next_pow2(ceil(gl->fbo_scale[i].scale_y)); - break; - case RARCH_SCALE_ABSOLUTE: - gl->fbo_rect[i].height = next_pow2(gl->fbo_scale[i].abs_y); - break; - case RARCH_SCALE_VIEWPORT: - gl->fbo_rect[i].height = next_pow2(gl->win_height); - break; - default: - break; - } - - last_width = gl->fbo_rect[i].width; - last_height = gl->fbo_rect[i].height; - } - else - { - // Use previous values, essentially a 1x scale compared to last shader in chain. - gl->fbo_rect[i] = gl->fbo_rect[i - 1]; - gl->fbo_scale[i].scale_x = gl->fbo_scale[i].scale_y = 1.0; - gl->fbo_scale[i].type_x = gl->fbo_scale[i].type_y = RARCH_SCALE_INPUT; - } - - RARCH_LOG("Creating FBO %d @ %ux%u\n", i, gl->fbo_rect[i].width, gl->fbo_rect[i].height); - } - - gl_create_fbo_textures(gl); - - pglGenFramebuffers(gl->fbo_pass, gl->fbo); - for (int i = 0; i < gl->fbo_pass; i++) - { - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); - pglFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, gl->fbo_texture[i], 0); - - GLenum status = pglCheckFramebufferStatus(GL_FRAMEBUFFER); - if (status != GL_FRAMEBUFFER_COMPLETE) - goto error; - } - - pglBindFramebuffer(GL_FRAMEBUFFER, 0); - - gl->fbo_inited = true; - return; - -error: - glDeleteTextures(gl->fbo_pass, gl->fbo_texture); - pglDeleteFramebuffers(gl->fbo_pass, gl->fbo); - RARCH_ERR("Failed to set up frame buffer objects. Multi-pass shading will not work.\n"); -} - -//////////// - -static void set_projection(gl_t *gl, bool allow_rotate) -{ - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - if (allow_rotate) - glRotatef(gl->rotation, 0, 0, 1); - - glOrtho(0, 1, 0, 1, -1, 1); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - gl_shader_set_proj_matrix(); -} - -static inline 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 * gl->vp_out_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 * gl->vp_out_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 set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) -{ - unsigned m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; - GLfloat m_left, m_right, m_bottom, m_top, m_zNear, m_zFar; - - m_viewport_x_temp = 0; - m_viewport_y_temp = 0; - m_viewport_width_temp = width; - m_viewport_height_temp = height; - - m_left = 0.0f; - m_right = 1.0f; - m_bottom = 0.0f; - m_top = 1.0f; - m_zNear = -1.0f; - m_zFar = 1.0f; - - if (gl->keep_aspect && !force_full) - { - float desired_aspect = g_settings.video.aspect_ratio; - float device_aspect = (float)width / height; - float delta; - - if(g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - m_viewport_x_temp = g_console.viewports.custom_vp.x; - m_viewport_y_temp = g_console.viewports.custom_vp.y; - m_viewport_width_temp = g_console.viewports.custom_vp.width; - m_viewport_height_temp = g_console.viewports.custom_vp.height; - } - // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), - // assume they are actually equal. - else if (fabs(device_aspect - desired_aspect) < 0.0001) - { - } - else if (device_aspect > desired_aspect) - { - delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; - m_viewport_x_temp = (GLint)(width * (0.5 - delta)); - m_viewport_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; - m_viewport_y_temp = (GLint)(height * (0.5 - delta)); - m_viewport_height_temp = (GLint)(2.0 * height * delta); - height = (unsigned)(2.0 * height * delta); - } - } - - glViewport(m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp); - - if(g_console.overscan_enable) - { - m_left = -g_console.overscan_amount/2; - m_right = 1 + g_console.overscan_amount/2; - m_bottom = -g_console.overscan_amount/2; - } - - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - glOrtho(m_left, m_right, m_bottom, m_top, m_zNear, m_zFar); - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - if (prg[active_index].mvp) - cgGLSetStateMatrixParameter(prg[active_index].mvp, CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY); - - gl->vp_width = width; - gl->vp_height = height; - - // Set last backbuffer viewport. - gl->vp_out_width = width; - gl->vp_out_height = height; -} - -static void set_lut_texture_coords(const GLfloat *coords) -{ - // For texture images. - pglClientActiveTexture(GL_TEXTURE1); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glTexCoordPointer(2, GL_FLOAT, 0, coords); - pglClientActiveTexture(GL_TEXTURE0); -} - -static inline void set_texture_coords(GLfloat *coords, GLfloat xamt, GLfloat yamt) -{ - coords[1] = yamt; - coords[4] = xamt; - coords[6] = xamt; - coords[7] = yamt; -} - -static void check_window(gl_t *gl) -{ - bool quit, resize; - - gfx_ctx_check_window(&quit, - &resize, &gl->win_width, &gl->win_height, - gl->frame_count); - - if (quit) - gl->quitting = true; - else if (resize) - gl->should_resize = true; -} - -void gl_set_projection(gl_t *gl, bool allow_rotate) -{ - gfx_ctx_set_projection(gl, allow_rotate); - gl_shader_set_proj_matrix(); -} - -static void gl_set_rotation(void *data, unsigned rotation) -{ - gl_t * gl = driver.video_data; - gl->rotation = 90 * rotation; - gl_set_projection(gl, true); -} - -#ifdef __CELLOS_LV2__ -static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) -{ - size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; - size_t buffer_stride = gl->tex_w * gl->base_size; - const uint8_t *frame_copy = frame; - size_t frame_copy_size = width * gl->base_size; - - for (unsigned h = 0; h < height; h++) - { - glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - buffer_addr, - frame_copy_size, - frame_copy); - - frame_copy += pitch; - buffer_addr += buffer_stride; - } -} - -static void gl_init_textures(gl_t *gl) -{ - glGenTextures(TEXTURES, gl->texture); - - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - - 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->tex_filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); - - glTextureReferenceSCE(GL_TEXTURE_2D, 1, - gl->tex_w, gl->tex_h, 0, - gl->texture_fmt, - gl->tex_w * gl->base_size, - gl->tex_w * gl->tex_h * i * gl->base_size); - } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -} -#else -static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) -{ - glPixelStorei(GL_UNPACK_ROW_LENGTH, pitch / gl->base_size); - glTexSubImage2D(GL_TEXTURE_2D, - 0, 0, 0, width, height, gl->texture_type, - gl->texture_fmt, frame); -} - -static void gl_init_textures(gl_t *gl) -{ - glGenTextures(TEXTURES, gl->texture); - for (unsigned i = 0; i < TEXTURES; i++) - { - glBindTexture(GL_TEXTURE_2D, gl->texture[i]); - - 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->tex_filter); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl->tex_filter); - - glPixelStorei(GL_UNPACK_ROW_LENGTH, gl->tex_w); - glTexImage2D(GL_TEXTURE_2D, - 0, RARCH_GL_INTERNAL_FORMAT, gl->tex_w, gl->tex_h, 0, gl->texture_type, - gl->texture_fmt, gl->empty_buf ? gl->empty_buf : NULL); - } - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); -} -#endif - -void gl_old_render_path (gl_t *gl) -{ - // Go back to old rendering path. - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glVertexPointer(2, GL_FLOAT, 0, vertexes_flipped); - glColorPointer(4, GL_FLOAT, 0, white_color); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - - glDisable(GL_BLEND); - set_projection(gl, true); -} - -static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) -{ - gl_t *gl = data; - - gl_shader_use(1); - gl->frame_count++; - - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - - // Render to texture in first pass. - if (gl->fbo_inited) - { - gl_compute_fbo_geometry(gl, width, height, gl->vp_out_width, gl->vp_out_height); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[0]); - gl->render_to_tex = true; - set_viewport(gl, gl->fbo_rect[0].img_width, gl->fbo_rect[0].img_height, true, false); - - // Need to preserve the "flipped" state when in FBO as well to have - // consistent texture coordinates. - // We will "flip" it in place on last pass. - if (gl->render_to_tex) - glVertexPointer(2, GL_FLOAT, 0, vertexes); - } - - - if ((width != gl->last_width[gl->tex_index] || height != gl->last_height[gl->tex_index])) - { - //Resolution change, need to clear out texture. - gl->last_width[gl->tex_index] = width; - gl->last_height[gl->tex_index] = height; - - glBufferSubData(GL_TEXTURE_REFERENCE_BUFFER_SCE, - gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size, - gl->tex_w * gl->tex_h * gl->base_size, - gl->empty_buf); - - GLfloat xamt = (GLfloat)width / gl->tex_w; - GLfloat yamt = (GLfloat)height / gl->tex_h; - - set_texture_coords(gl->tex_coords, xamt, yamt); - } - else if (width != gl->last_width[(gl->tex_index - 1) & TEXTURES_MASK] || height != gl->last_height[(gl->tex_index - 1) & TEXTURES_MASK]) - { - // We might have used different texture coordinates last frame. Edge case if resolution changes very rapidly. - GLfloat xamt = (GLfloat)width / gl->tex_w; - GLfloat yamt = (GLfloat)height / gl->tex_h; - set_texture_coords(gl->tex_coords, xamt, yamt); - } - - // Need to preserve the "flipped" state when in FBO as well to have - // consistent texture coordinates. - if (gl->fbo_inited) - glVertexPointer(2, GL_FLOAT, 0, vertexes); - - gl_copy_frame(gl, frame, width, height, pitch); - - struct gl_tex_info tex_info = { - .tex = gl->texture[gl->tex_index], - .input_size = {width, height}, - .tex_size = {gl->tex_w, gl->tex_h} - }; - - struct gl_tex_info fbo_tex_info[MAX_SHADERS]; - unsigned fbo_tex_info_cnt = 0; - memcpy(tex_info.coord, gl->tex_coords, sizeof(gl->tex_coords)); - - glClear(GL_COLOR_BUFFER_BIT); - gl_shader_set_params(width, height, - gl->tex_w, gl->tex_h, - gl->vp_width, gl->vp_height, - gl->frame_count, &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glDrawArrays(GL_QUADS, 0, 4); - - if (gl->fbo_inited) - { - GLfloat fbo_tex_coords[8] = {0.0f}; - - // Render the rest of our passes. - glTexCoordPointer(2, GL_FLOAT, 0, fbo_tex_coords); - - // It's kinda handy ... :) - const struct gl_fbo_rect *prev_rect; - const struct gl_fbo_rect *rect; - struct gl_tex_info *fbo_info; - - // Calculate viewports, texture coordinates etc, and render all passes from FBOs, to another FBO. - for (int i = 1; i < gl->fbo_pass; i++) - { - prev_rect = &gl->fbo_rect[i - 1]; - rect = &gl->fbo_rect[i]; - fbo_info = &fbo_tex_info[i - 1]; - - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - - set_texture_coords(fbo_tex_coords, xamt, yamt); - - fbo_info->tex = gl->fbo_texture[i - 1]; - fbo_info->input_size[0] = prev_rect->img_width; - fbo_info->input_size[1] = prev_rect->img_height; - fbo_info->tex_size[0] = prev_rect->width; - fbo_info->tex_size[1] = prev_rect->height; - memcpy(fbo_info->coord, fbo_tex_coords, sizeof(fbo_tex_coords)); - - pglBindFramebuffer(GL_FRAMEBUFFER, gl->fbo[i]); - gl_shader_use(i + 1); - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[i - 1]); - - glClear(GL_COLOR_BUFFER_BIT); - - // Render to FBO with certain size. - set_viewport(gl, rect->img_width, rect->img_height, true, false); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, gl->frame_count, - &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glDrawArrays(GL_QUADS, 0, 4); - - fbo_tex_info_cnt++; - } - - // Render our last FBO texture directly to screen. - prev_rect = &gl->fbo_rect[gl->fbo_pass - 1]; - GLfloat xamt = (GLfloat)prev_rect->img_width / prev_rect->width; - GLfloat yamt = (GLfloat)prev_rect->img_height / prev_rect->height; - - set_texture_coords(fbo_tex_coords, xamt, yamt); - - // Render our FBO texture to back buffer. - pglBindFramebuffer(GL_FRAMEBUFFER, 0); - gl_shader_use(gl->fbo_pass + 1); - - glBindTexture(GL_TEXTURE_2D, gl->fbo_texture[gl->fbo_pass - 1]); - - glClear(GL_COLOR_BUFFER_BIT); - gl->render_to_tex = false; - set_viewport(gl, gl->win_width, gl->win_height, false, true); - gl_shader_set_params(prev_rect->img_width, prev_rect->img_height, - prev_rect->width, prev_rect->height, - gl->vp_width, gl->vp_height, gl->frame_count, - &tex_info, gl->prev_info, fbo_tex_info, fbo_tex_info_cnt); - - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); - - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - } - - memmove(gl->prev_info + 1, gl->prev_info, sizeof(tex_info) * (TEXTURES - 1)); - memcpy(&gl->prev_info[0], &tex_info, sizeof(tex_info)); - gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; - - if (msg) - { - gl_render_msg(gl, msg); - gl_render_msg_post(gl); - } - - if(!gl->block_swap) - gfx_ctx_swap_buffers(); - -#ifdef HAVE_CG_MENU - if(gl->menu_render) - { - gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); - - gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, - gl->win_height, gl->win_width, gl->win_height, gl->frame_count, - NULL, NULL, NULL, 0); - - set_viewport(gl, gl->win_width, gl->win_height, true, false); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); - - glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - } -#endif - - return true; -} - -static void gl_free(void *data) -{ - if (driver.video_data) - return; - - gl_t *gl = data; - - gl_deinit_font(gl); - gl_shader_deinit(); - - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_TEXTURE_COORD_ARRAY); - glDisableClientState(GL_COLOR_ARRAY); - glDeleteTextures(TEXTURES, gl->texture); - -#ifdef HAVE_OPENGL_TEXREF - glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, 0); - glDeleteBuffers(1, &gl->pbo); -#endif - -#ifdef HAVE_FBO - gl_deinit_fbo(gl); -#endif - - gfx_ctx_destroy(); - - if (gl->empty_buf) - free(gl->empty_buf); - - free(gl); -} - -static void gl_set_nonblock_state(void *data, bool state) -{ - gl_t *gl = (gl_t*)data; - if (gl->vsync) - { - RARCH_LOG("GL VSync => %s\n", state ? "off" : "on"); - gfx_ctx_set_swap_interval(state ? 0 : 1, true); - } -} - -static void *gl_init(const video_info_t *video, const input_driver_t **input, void **input_data) -{ - if (driver.video_data) - return driver.video_data; - - gl_t *gl = calloc(1, sizeof(gl_t)); - if (!gl) - return NULL; - - if (!gfx_ctx_init()) - { - free(gl); - return NULL; - } - - unsigned full_x = 0, full_y = 0; - gfx_ctx_get_video_size(&full_x, &full_y); - RARCH_LOG("Detecting desktop resolution %ux%u.\n", full_x, full_y); - - gfx_ctx_set_swap_interval(video->vsync ? 1 : 0, false); - - 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 (!gfx_ctx_set_video_mode(win_width, win_height, - g_settings.video.force_16bit ? 15 : 0, video->fullscreen)) - { - free(gl); - return NULL; - } - -#if (defined(HAVE_XML) || defined(HAVE_CG)) && defined(_WIN32) - // Win32 GL lib doesn't have some functions needed for XML shaders. - // Need to load dynamically :( - if (!load_gl_proc()) - { - gfx_ctx_destroy(); - free(gl); - return NULL; - } -#endif - - 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; - - RARCH_LOG("GL: Using resolution %ux%u.\n", gl->win_width, gl->win_height); - -#ifdef HAVE_CG_MENU - RARCH_LOG("Initializing menu shader...\n"); - gl_cg_set_menu_shader(DEFAULT_MENU_SHADER_FILE); -#endif - - if (!gl_shader_init()) - { - RARCH_ERR("Shader init failed.\n"); - gfx_ctx_destroy(); - free(gl); - return NULL; - } - - RARCH_LOG("GL: Loaded %u program(s).\n", gl_shader_num()); - -#ifdef HAVE_FBO - // Set up render to texture. - gl_init_fbo(gl, RARCH_SCALE_BASE * video->input_scale, - RARCH_SCALE_BASE * video->input_scale); -#endif - - - gl->keep_aspect = video->force_aspect; - - // Apparently need to set viewport for passes when we aren't using FBOs. - gl_shader_use(0); - set_viewport(gl, gl->win_width, gl->win_height, false, true); - gl_shader_use(1); - set_viewport(gl, gl->win_width, gl->win_height, false, true); - - bool force_smooth = false; - if (gl_shader_filter_type(1, &force_smooth)) - gl->tex_filter = force_smooth ? GL_LINEAR : GL_NEAREST; - else - gl->tex_filter = video->smooth ? GL_LINEAR : GL_NEAREST; - - gl->texture_type = RARCH_GL_TEXTURE_TYPE; - gl->texture_fmt = video->rgb32 ? RARCH_GL_FORMAT32 : RARCH_GL_FORMAT16; - gl->base_size = video->rgb32 ? sizeof(uint32_t) : sizeof(uint16_t); - - glEnable(GL_TEXTURE_2D); - glDisable(GL_DEPTH_TEST); - glDisable(GL_DITHER); - glClearColor(0, 0, 0, 1); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - - glEnableClientState(GL_VERTEX_ARRAY); - glEnableClientState(GL_TEXTURE_COORD_ARRAY); - glEnableClientState(GL_COLOR_ARRAY); - glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - - memcpy(gl->tex_coords, tex_coords, sizeof(tex_coords)); - glTexCoordPointer(2, GL_FLOAT, 0, gl->tex_coords); - glColorPointer(4, GL_FLOAT, 0, white_color); - - set_lut_texture_coords(tex_coords); - - gl->tex_w = RARCH_SCALE_BASE * video->input_scale; - gl->tex_h = RARCH_SCALE_BASE * video->input_scale; - -#ifdef HAVE_OPENGL_TEXREF - glGenBuffers(1, &gl->pbo); - glBindBuffer(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->pbo); - glBufferData(GL_TEXTURE_REFERENCE_BUFFER_SCE, gl->tex_w * gl->tex_h * gl->base_size * TEXTURES, NULL, GL_STREAM_DRAW); -#endif - - // Empty buffer that we use to clear out the texture with on res change. - gl->empty_buf = calloc(gl->tex_w * gl->tex_h, gl->base_size); - gl_init_textures(gl); - - for (unsigned i = 0; i < TEXTURES; i++) - { - gl->last_width[i] = gl->tex_w; - gl->last_height[i] = gl->tex_h; - } - - for (unsigned i = 0; i < TEXTURES; i++) - { - gl->prev_info[i].tex = gl->texture[(gl->tex_index - (i + 1)) & TEXTURES_MASK]; - gl->prev_info[i].input_size[0] = gl->tex_w; - gl->prev_info[i].tex_size[0] = gl->tex_w; - gl->prev_info[i].input_size[1] = gl->tex_h; - gl->prev_info[i].tex_size[1] = gl->tex_h; - memcpy(gl->prev_info[i].coord, tex_coords, sizeof(tex_coords)); - } - - gfx_ctx_input_driver(input, input_data); - gl_init_font(gl, g_settings.video.font_path, g_settings.video.font_size); - - if (!gl_check_error()) - { - gfx_ctx_destroy(); - free(gl); - return NULL; - } - - return gl; -} - -static bool gl_alive(void *data) -{ - gl_t *gl = (gl_t*)data; - check_window(gl); - return !gl->quitting; -} - -static bool gl_focus(void *data) -{ - (void)data; - return gfx_ctx_window_has_focus(); -} - -#ifdef RARCH_CONSOLE -static void gl_start(void) -{ - video_info_t video_info = {0}; - - // Might have to supply correct values here. - video_info.vsync = g_settings.video.vsync; - video_info.force_aspect = false; - 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) - { - video_info.width = g_console.viewports.custom_vp.width; - video_info.height = g_console.viewports.custom_vp.height; - } - driver.video_data = gl_init(&video_info, NULL, NULL); - -#ifdef HAVE_FBO - gfx_ctx_set_fbo(g_console.fbo_enabled); -#endif - - gfx_ctx_get_available_resolutions(); - -#ifdef HAVE_CG_MENU - gfx_ctx_menu_init(); -#endif -} - -static void gl_stop(void) -{ - void *data = driver.video_data; - driver.video_data = NULL; - gl_free(data); -} - -static void gl_restart(void) -{ - gl_t * gl = driver.video_data; - - if(!gl) - return; - - gl_stop(); - gl_cg_invalidate_context(); - gl_start(); -} -#endif - -const video_driver_t video_gl = -{ - .init = gl_init, - .frame = gl_frame, - .alive = gl_alive, - .set_nonblock_state = gl_set_nonblock_state, - .focus = gl_focus, - .free = gl_free, - .ident = "gl", - .set_rotation = gl_set_rotation, -#ifdef RARCH_CONSOLE - .start = gl_start, - .restart = gl_restart, - .stop = gl_stop, -#endif -}; - - diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index b1f8039b5d..e9166e8824 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -43,13 +43,11 @@ void ps3_next_resolution (void); void gl_deinit_fbo(gl_t * gl); void gl_init_fbo(gl_t * gl, unsigned width, unsigned height); -void ps3graphics_reinit_fbos(void); bool gl_cg_reinit(const char *path); bool gl_cg_save_cgp(const char *path, const struct gl_cg_cgp_info *info); bool gl_cg_load_shader(unsigned index, const char *path); - unsigned gl_cg_get_lut_info(struct gl_cg_lut_info *info, unsigned elems); #endif From 15e16728f2e519be782a0a8cf487174c3b0b3c79 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 22:45:00 +0200 Subject: [PATCH 076/103] PC fix build --- gfx/context/sdl_ctx.c | 2 +- gfx/fonts/freetype.c | 3 ++- gfx/gl.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index 12f8b576d5..4666397a61 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, bool allow_rotate) +void gfx_ctx_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/gfx/fonts/freetype.c b/gfx/fonts/freetype.c index 545e9126bf..e4ca7c6a85 100644 --- a/gfx/fonts/freetype.c +++ b/gfx/fonts/freetype.c @@ -227,6 +227,7 @@ 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); @@ -235,7 +236,7 @@ void gl_render_msg_post(gl_t *gl) glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glDisable(GL_BLEND); - gl_set_projection(gl, true); + gl_set_projection(gl, &ortho, true); #else (void)gl; #endif diff --git a/gfx/gl.c b/gfx/gl.c index 01a7dfb4fe..5507156695 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -438,7 +438,7 @@ void gl_set_projection(gl_t *gl, ortho_t *ortho, bool allow_rotate) gl_shader_set_proj_matrix(); } -static void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, 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; From e88318e886d055243380b306934ab2b3c8a8b86d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 22:50:03 +0200 Subject: [PATCH 077/103] Fixed up initializer for gl driver --- gfx/gl.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 5507156695..3dc440f2d9 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1276,22 +1276,25 @@ static void gl_restart(void) #endif const video_driver_t video_gl = { - .init = gl_init, - .frame = gl_frame, - .set_nonblock_state = gl_set_nonblock_state, - .alive = gl_alive, - .focus = gl_focus, + gl_init, + gl_frame, + gl_set_nonblock_state, + gl_alive, + gl_focus, #ifdef HAVE_XML - .xml_shader = gl_xml_shader, + gl_xml_shader, #else - .xml_shader = NULL, + NULL, #endif - .free = gl_free, - .ident = "gl", - .set_rotation = gl_set_rotation, + gl_free, + "gl", #ifdef RARCH_CONSOLE - .start = gl_start, - .restart = gl_restart, - .stop = gl_stop, + NULL, //FIXME: set_swap_block_state - to be removed + NULL, //FIXME: swap - to be removed + NULL, //FIXME: set_aspect_ratio - to be removed + gl_start, + gl_stop, + gl_restart, #endif + .set_rotation = gl_set_rotation, }; From 1d051617236524b03b3ded4af695f02ef040d7d7 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 22:58:14 +0200 Subject: [PATCH 078/103] (Griffin) Small nit --- console/griffin/griffin.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 9335f7f4b4..25d89de927 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -48,6 +48,9 @@ VIDEO #if defined(__CELLOS_LV2__) #include "../../gfx/context/ps3_ctx.c" +#endif + +#ifdef HAVE_CG #include "../../gfx/shader_cg.c" #endif From 72310b6661fa68bcdc6ee7637d5ef7be531e8d65 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 23:14:46 +0200 Subject: [PATCH 079/103] Style nit party. --- gfx/context/ps3_ctx.c | 85 ++++++++++++++++++++++--------------------- gfx/context/sdl_ctx.c | 4 +- gfx/fonts/freetype.c | 3 +- gfx/gfx_context.h | 2 +- gfx/gl.c | 70 ++++++++++++++++++----------------- gfx/gl_common.h | 18 ++++----- 6 files changed, 94 insertions(+), 88 deletions(-) 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 From 4ffecbb058d3890e6d8c67d92e2331aeba11f9ed Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 23:16:22 +0200 Subject: [PATCH 080/103] Minor initializer fixup. --- gfx/gl.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index 9465741731..df987aa804 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1283,20 +1283,24 @@ const video_driver_t video_gl = { gl_set_nonblock_state, gl_alive, gl_focus, + #ifdef HAVE_XML gl_xml_shader, #else NULL, #endif + gl_free, "gl", + #ifdef RARCH_CONSOLE - NULL, //FIXME: set_swap_block_state - to be removed - NULL, //FIXME: swap - to be removed - NULL, //FIXME: set_aspect_ratio - to be removed + NULL, // FIXME: set_swap_block_state - to be removed + NULL, // FIXME: swap - to be removed + NULL, // FIXME: set_aspect_ratio - to be removed gl_start, gl_stop, gl_restart, #endif - .set_rotation = gl_set_rotation, + + gl_set_rotation, }; From 6aa621a8f80a3c05434e468f16b1b10746061906 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 23:21:30 +0200 Subject: [PATCH 081/103] Minor refactor. --- gfx/gl.c | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index df987aa804..43331205d1 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -878,6 +878,26 @@ static void gl_next_texture_index(gl_t *gl, const struct gl_tex_info *tex_info) gl->tex_index = (gl->tex_index + 1) & TEXTURES_MASK; } +#ifdef HAVE_CG_MENU +static void gl_render_menu(gl_t *gl) +{ + gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); + + gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, + gl->win_height, gl->win_width, gl->win_height, gl->frame_count, + NULL, NULL, NULL, 0); + + gl_set_viewport(gl, gl->win_width, gl->win_height, true, false); + + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); + + glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr); + glDrawArrays(GL_QUADS, 0, 4); + glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); +} +#endif + static bool gl_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { gl_t *gl = (gl_t*)data; @@ -950,23 +970,8 @@ static bool gl_frame(void *data, const void *frame, unsigned width, unsigned hei gfx_ctx_swap_buffers(); #ifdef HAVE_CG_MENU - if(gl->menu_render) - { - gl_shader_use(RARCH_CG_MENU_SHADER_INDEX); - - gl_shader_set_params(gl->win_width, gl->win_height, gl->win_width, - gl->win_height, gl->win_width, gl->win_height, gl->frame_count, - NULL, NULL, NULL, 0); - - gl_set_viewport(gl, gl->win_width, gl->win_height, true, false); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, gl->menu_texture_id); - - glVertexPointer(2, GL_FLOAT, 0, default_vertex_ptr); - glDrawArrays(GL_QUADS, 0, 4); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); - } + if (gl->menu_render) + gl_render_menu(gl); #endif return true; From 4e9a5a5360cef59008b25efe71a2cbb98b54a8be Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 23:30:00 +0200 Subject: [PATCH 082/103] DOS retardations creep in. --- gfx/gl.c | 1 + gfx/gl_common.h | 3 +++ 2 files changed, 4 insertions(+) diff --git a/gfx/gl.c b/gfx/gl.c index 43331205d1..348eed8538 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1309,3 +1309,4 @@ const video_driver_t video_gl = { gl_set_rotation, }; + diff --git a/gfx/gl_common.h b/gfx/gl_common.h index ad052cd28c..616cea7c32 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -107,6 +107,9 @@ struct gl_fbo_scale bool valid; }; +// DOS creeps into Win32, yay. +#undef near +#undef far struct gl_ortho { GLfloat left; From fea9aa9e9c85606854737f835d144b6c7203d5e9 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 23:22:55 +0200 Subject: [PATCH 083/103] Removed glRotatef from RGL - didn't work anyway --- console/rgl/ps3/rgl.cpp | 76 ----------------------------------------- 1 file changed, 76 deletions(-) diff --git a/console/rgl/ps3/rgl.cpp b/console/rgl/ps3/rgl.cpp index 09733da853..277f019860 100644 --- a/console/rgl/ps3/rgl.cpp +++ b/console/rgl/ps3/rgl.cpp @@ -6074,82 +6074,6 @@ GLAPI void APIENTRY glOrthof( GLfloat left, GLfloat right, GLfloat bottom, GLflo LContext->InverseModelViewValid = GL_FALSE; } -#define DEGREES_TO_RADIANS 0.017453292519943295769 -#define ELEMENTS_IN_MATRIX 16 - -GLAPI void APIENTRY glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) -{ - PSGLcontext* LContext = _CurrentContext; - jsMatrixStack* LMatrixStack = NULL; - GLfloat * LMatrix = NULL; - - jsContextGetMatrixStack(LContext, LContext->MatrixMode, LMatrixStack); - - if (LMatrixStack) - LMatrix = LMatrixStack->MatrixStackf+ LMatrixStack->MatrixStackPtr*ELEMENTS_IN_MATRIX; - - GLfloat a = angle * DEGREES_TO_RADIANS; - GLfloat c = cosf( a ); - GLfloat one_minus_c = 1.f - c; - GLfloat s = sinf( a ); - GLfloat n = x * x + y * y + z * z; - GLfloat m00, m01, m02, m10, m11, m12, m20, m21, m22; - GLfloat L00, L01, L02, L10, L11, L12, L20, L21, L22, L30, L31, L32; - - - if ( n != 1.f ) - { - n = 1.f / sqrtf( n ); - x *= n; - y *= n; - z *= n; - } - - m00 = x * x * one_minus_c + c; - m01 = x * y * one_minus_c - z * s; - m02 = x * z * one_minus_c + y * s; - m10 = y * x * one_minus_c + z * s; - m11 = y * y * one_minus_c + c; - m12 = y * z * one_minus_c - x * s; - m20 = z * x * one_minus_c - y * s; - m21 = z * y * one_minus_c + x * s; - m22 = z * z * one_minus_c + c; - - L00 = LMatrix[0]; - L01 = LMatrix[M01]; - L02 = LMatrix[M02]; - L10 = LMatrix[M10]; - L11 = LMatrix[M11]; - L12 = LMatrix[M12]; - L20 = LMatrix[M20]; - L21 = LMatrix[M21]; - L22 = LMatrix[M22]; - L30 = LMatrix[M30]; - L31 = LMatrix[M31]; - L32 = LMatrix[M32]; - - LMatrix[0] = L00 * m00 + L01 * m10 + L02 * m20; - LMatrix[M01] = L00 * m01 + L01 * m11 + L02 * m21; - LMatrix[M02] = L00 * m02 + L01 * m12 + L02 * m22; - - LMatrix[M10] = L10 * m00 + L11 * m10 + L12 * m20; - LMatrix[M11] = L10 * m01 + L11 * m11 + L12 * m21; - LMatrix[M12] = L10 * m02 + L11 * m12 + L12 * m22; - - LMatrix[M20] = L20 * m00 + L21 * m10 + L22 * m20; - LMatrix[M21] = L20 * m01 + L21 * m11 + L22 * m21; - LMatrix[M22] = L20 * m02 + L21 * m12 + L22 * m22; - - LMatrix[M30] = L30 * m00 + L31 * m10 + L32 * m20; - LMatrix[M31] = L30 * m01 + L31 * m11 + L32 * m21; - LMatrix[M32] = L30 * m02 + L31 * m12 + L32 * m22; - - LContext->needValidate |= PSGL_VALIDATE_FFX_VERTEX_PROGRAM; - LMatrixStack->dirty = GL_TRUE; - if ( LContext->MatrixMode == GL_MODELVIEW ) - LContext->InverseModelViewValid = GL_FALSE; -} - const uint32_t c_rounded_size_of_RGLDrawParams = (sizeof(jsDrawParams)+0x7f)&~0x7f; static uint8_t s_dparams_buff[ c_rounded_size_of_RGLDrawParams ] __attribute__((aligned(128))); From 2d3fed35e79c8e05d563fc482251fc33a7790637 Mon Sep 17 00:00:00 2001 From: Themaister Date: Sun, 27 May 2012 23:33:31 +0200 Subject: [PATCH 084/103] Avoid ugly #undefs. --- gfx/context/ps3_ctx.c | 2 +- gfx/context/sdl_ctx.c | 2 +- gfx/gl.c | 13 +++---------- gfx/gl_common.h | 7 ++----- 4 files changed, 7 insertions(+), 17 deletions(-) diff --git a/gfx/context/ps3_ctx.c b/gfx/context/ps3_ctx.c index 67605a8199..0822cbc4ee 100644 --- a/gfx/context/ps3_ctx.c +++ b/gfx/context/ps3_ctx.c @@ -381,7 +381,7 @@ void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_r glVertexPointer(2, GL_FLOAT, 0, vertex_ptr); - glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->near, ortho->far); + glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->znear, ortho->zfar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } diff --git a/gfx/context/sdl_ctx.c b/gfx/context/sdl_ctx.c index ef12ee9eeb..9ebd8bf7e1 100644 --- a/gfx/context/sdl_ctx.c +++ b/gfx/context/sdl_ctx.c @@ -406,7 +406,7 @@ void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_r if (allow_rotate) glRotatef(gl->rotation, 0, 0, 1); - glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->near, ortho->far); + glOrtho(ortho->left, ortho->right, ortho->bottom, ortho->top, ortho->znear, ortho->zfar); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } diff --git a/gfx/gl.c b/gfx/gl.c index 348eed8538..7a2a58643b 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -452,8 +452,8 @@ void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, ortho.right = 1.0f; ortho.bottom = 0.0f; ortho.top = 1.0f; - ortho.near = -1.0f; - ortho.far = 1.0f; + ortho.znear = -1.0f; + ortho.zfar = 1.0f; if (gl->keep_aspect && !force_full) { @@ -514,14 +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) { - struct gl_ortho ortho = {0}; - - ortho.left = 0; - ortho.right = 1; - ortho.bottom = 0; - ortho.top = 1; - ortho.near = -1; - ortho.far = 1; + struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; gl_t *gl = (gl_t*)driver.video_data; gl->rotation = 90 * rotation; diff --git a/gfx/gl_common.h b/gfx/gl_common.h index 616cea7c32..0cb15c479c 100644 --- a/gfx/gl_common.h +++ b/gfx/gl_common.h @@ -107,17 +107,14 @@ struct gl_fbo_scale bool valid; }; -// DOS creeps into Win32, yay. -#undef near -#undef far struct gl_ortho { GLfloat left; GLfloat right; GLfloat bottom; GLfloat top; - GLfloat near; - GLfloat far; + GLfloat znear; + GLfloat zfar; }; struct gl_tex_info From 49e69a530d60b0ca08af0b030673fcf2e5d8cbf8 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Sun, 27 May 2012 23:57:16 +0200 Subject: [PATCH 085/103] (RGL) Stripped some unused stuff --- console/rgl/ps3/rgl.cpp | 129 +--------------------------------------- 1 file changed, 3 insertions(+), 126 deletions(-) diff --git a/console/rgl/ps3/rgl.cpp b/console/rgl/ps3/rgl.cpp index 277f019860..9967431270 100644 --- a/console/rgl/ps3/rgl.cpp +++ b/console/rgl/ps3/rgl.cpp @@ -2482,9 +2482,7 @@ static GmmBlock *gmmAllocBlock(GmmAllocator *pAllocator, uint32_t size) { pNewBlock = (GmmBlock *)gmmAllocFixed(0); if (pNewBlock == NULL) - { return NULL; - } memset(pNewBlock, 0, sizeof(GmmBlock)); @@ -2541,9 +2539,7 @@ static GmmTileBlock *gmmFindFreeTileBlock( pNewBlock = (GmmTileBlock *)gmmAllocFixed(1); if (pNewBlock == NULL) - { return NULL; - } memset(pNewBlock, 0, sizeof(GmmTileBlock)); @@ -2576,9 +2572,7 @@ static GmmTileBlock *gmmCreateTileBlock( address = pAllocator->tileStartAddress - size; if (address > pAllocator->startAddress + pAllocator->size) - { return NULL; - } if (pAllocator->pTail && pAllocator->pTail->base.address + pAllocator->pTail->base.size > address) @@ -2625,23 +2619,15 @@ static void gmmFreeTileBlock( GmmAllocator *pAllocator; if (pTileBlock->pPrev) - { pTileBlock->pPrev->pNext = pTileBlock->pNext; - } if (pTileBlock->pNext) - { pTileBlock->pNext->pPrev = pTileBlock->pPrev; - } if (pTileBlock->base.isMain) - { pAllocator = pGmmMainAllocator; - } else - { pAllocator = pGmmLocalAllocator; - } if (pAllocator->pTileHead == pTileBlock) { @@ -2753,9 +2739,7 @@ uint32_t gmmAllocExtendedTileBlock(const uint32_t size, const uint32_t tag) } if (retId == 0) - { return GMM_ERROR; - } if (!resizeSucceed) { @@ -2774,9 +2758,7 @@ static GmmTileBlock *gmmAllocTileBlock( GmmTileBlock *pBlock = gmmFindFreeTileBlock(pAllocator, size); if (pBlock == NULL) - { pBlock = gmmCreateTileBlock(pAllocator, size); - } return pBlock; } @@ -2788,32 +2770,22 @@ static void gmmFreeBlock( GmmAllocator *pAllocator; if (pBlock->pPrev) - { pBlock->pPrev->pNext = pBlock->pNext; - } if (pBlock->pNext) - { pBlock->pNext->pPrev = pBlock->pPrev; - } if (pBlock->base.isMain) - { pAllocator = pGmmMainAllocator; - } else - { pAllocator = pGmmLocalAllocator; - } if (pAllocator->pHead == pBlock) { pAllocator->pHead = pBlock->pNext; if (pAllocator->pHead) - { pAllocator->pHead->pPrev = NULL; - } } if (pAllocator->pTail == pBlock) @@ -2821,15 +2793,11 @@ static void gmmFreeBlock( pAllocator->pTail = pBlock->pPrev; if (pAllocator->pTail) - { pAllocator->pTail->pNext = NULL; - } } if (pBlock->pPrev == NULL) - { pAllocator->pSweepHead = pAllocator->pHead; - } else if (pBlock->pPrev && (pAllocator->pSweepHead == NULL || (pAllocator->pSweepHead && @@ -2850,13 +2818,9 @@ static void gmmAddPendingFree( GmmAllocator *pAllocator; if (pBlock->base.isMain) - { pAllocator = pGmmMainAllocator; - } else - { pAllocator = pGmmLocalAllocator; - } if (pAllocator->pPendingFreeTail) { @@ -3011,9 +2975,7 @@ static inline void gmmMemcpy(const uint32_t dstOffset, const uint32_t srcOffset, uint32_t iterations = (moveSize+moveBlockSize-1)/moveBlockSize; for (uint32_t i=0; iViewPort.XSize, LContext->ViewPort.YSize, 0.0f, 1.0f); } - - - - - jsTexture *_RGLGetCurrentTexture( const jsTextureImageUnit *unit, GLenum target ) { PSGLcontext* LContext = _CurrentContext; @@ -6704,21 +6661,6 @@ jsTexture *_RGLGetCurrentTexture( const jsTextureImageUnit *unit, GLenum target return defaultTexture; } - - - - - - - - - - - - - - - CgprogramHookFunction _cgProgramCreateHook = NULL; CgprogramHookFunction _cgProgramDestroyHook = NULL; CgprogramCopyHookFunction _cgProgramCopyHook = NULL; @@ -7479,31 +7421,6 @@ CG_API void cgDestroyProgram( CGprogram program ) return; } -CG_API CGprofile cgGetProgramProfile( CGprogram prog ) -{ - if ( !CG_IS_PROGRAM( prog ) ) - { - _RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return CG_PROFILE_UNKNOWN; - } - - return ( CGprofile )_cgGetProgPtr( prog )->header.profile; -} - -CG_API CGprofile cgGetProgramDomainProfile( CGprogram program, int index ) -{ - if ( !CG_IS_PROGRAM( program ) ) - { - _RGLCgRaiseError( CG_INVALID_PROGRAM_HANDLE_ERROR ); - return CG_PROFILE_UNKNOWN; - } - - if ( index >= 1 ) - return CG_PROFILE_UNKNOWN; - - return ( CGprofile )_cgGetProgPtr( program )->header.profile; -} - static CGprogram _RGLCgUpdateProgramAtIndex( CGprogramGroup group, int index, int refcount ) { if ( index < ( int )group->programCount ) @@ -8365,41 +8282,20 @@ CGGL_API void cgGLSetTextureParameter( CGparameter param, GLuint texobj ) ptr->samplerSetter( ptr, &texobj, 0 ); } -CGGL_API GLuint cgGLGetTextureParameter( CGparameter param ) -{ - CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param ); - if ( ptr == NULL ) return 0; -if ( !( ptr->parameterEntry->flags & CGPF_REFERENCED ) ) { _RGLCgRaiseError( CG_INVALID_PARAMETER_ERROR ); return 0; } - return *( GLuint* )ptr->pushBufferPointer; - return 0; -} - CGGL_API void cgGLEnableTextureParameter( CGparameter param ) { CgRuntimeParameter* ptr = _cgGLTestTextureParameter( param ); ptr->samplerSetter( ptr, NULL, 0 ); } -CGGL_API void cgGLDisableTextureParameter( CGparameter param ) -{ - if ( _cgGLTestTextureParameter( param ) ) - { - } -} - -CGGL_API void cgGLSetDebugMode( CGbool debug ) -{ - return; -} - -void _RGLCgContextZero( _CGcontext* p ) +static void _RGLCgContextZero( _CGcontext* p ) { memset( p, 0, sizeof( *p ) ); p->compileType = CG_UNKNOWN; } -void _RGLCgContextPushFront( _CGcontext* ctx ) +static void _RGLCgContextPushFront( _CGcontext* ctx ) { if ( _CurrentContext->RGLcgContextHead ) { @@ -8417,25 +8313,6 @@ static void destroy_context( _CGcontext*ctx ) free( ctx ); } -void _RGLCgContextPopFront() -{ - if ( _CurrentContext->RGLcgContextHead ) - { - _CGcontext* head = _cgGetContextPtr( _CurrentContext->RGLcgContextHead ); - _CGcontext* temp = head->next; - destroy_context( head ); - - if ( temp ) - { - _CurrentContext->RGLcgContextHead = temp->id; - } - else - { - _CurrentContext->RGLcgContextHead = 0; - } - } -} - CG_API CGcontext cgCreateContext( void ) { _CGcontext* ptr = NULL; From ef0ab68c4b04824a4e24e2726e7d7c6474033b14 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 00:06:18 +0200 Subject: [PATCH 086/103] (PS3) Applies overscan / aspect ratio / rotation in non-FBO mode now --- gfx/gl.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gfx/gl.c b/gfx/gl.c index 7a2a58643b..89a95246a2 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -796,6 +796,9 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi #ifdef __CELLOS_LV2__ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { + if(!gl->fbo_inited) + gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); + size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; size_t buffer_stride = gl->tex_w * gl->base_size; const uint8_t *frame_copy = frame; From 5989fa0405dd1fe759f94dd3ac2f7515943b42be Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 28 May 2012 00:21:51 +0200 Subject: [PATCH 087/103] Nit. --- gfx/gl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gfx/gl.c b/gfx/gl.c index 89a95246a2..4c215ed8c4 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -796,7 +796,7 @@ static void gl_update_input_size(gl_t *gl, unsigned width, unsigned height, unsi #ifdef __CELLOS_LV2__ static void gl_copy_frame(gl_t *gl, const void *frame, unsigned width, unsigned height, unsigned pitch) { - if(!gl->fbo_inited) + if (!gl->fbo_inited) gl_set_viewport(gl, gl->win_width, gl->win_height, false, true); size_t buffer_addr = gl->tex_w * gl->tex_h * gl->tex_index * gl->base_size; From 28f3e473e3496d766af1675a798e4c173e279d1a Mon Sep 17 00:00:00 2001 From: Themaister Date: Mon, 28 May 2012 00:27:53 +0200 Subject: [PATCH 088/103] Build fixes. --- general.h | 3 +++ network_cmd.h | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/general.h b/general.h index 15d7ee5707..ae37043b7a 100644 --- a/general.h +++ b/general.h @@ -53,6 +53,9 @@ #ifdef HAVE_NETPLAY #include "netplay.h" +#endif + +#ifdef HAVE_NETWORK_CMD #include "network_cmd.h" #endif diff --git a/network_cmd.h b/network_cmd.h index fd19f6a305..696f5c5a2d 100644 --- a/network_cmd.h +++ b/network_cmd.h @@ -17,7 +17,7 @@ #define NETWORK_CMD_H__ #include -#include +#include "boolean.h" typedef struct network_cmd network_cmd_t; From e871f9523f25edd09e6009907697e595d008912a Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 00:37:54 +0200 Subject: [PATCH 089/103] (360) Fix 360 build --- 360/main.c | 4 ++-- 360/xdk360_video.cpp | 11 +++++++++-- 360/xdk360_video.h | 2 -- console/griffin/griffin.c | 5 ++++- msvc-360/RetroArch-360/RetroArch-360.vcxproj | 14 +++++++------- 5 files changed, 22 insertions(+), 14 deletions(-) diff --git a/360/main.c b/360/main.c index 4f09a7217f..582471293f 100644 --- a/360/main.c +++ b/360/main.c @@ -418,7 +418,7 @@ int main(int argc, char *argv[]) init_settings(load_libretro_path); init_libretro_sym(); - xdk360_video_init(); + video_xdk360.start(); xdk360_input_init(); rarch_input_set_default_keybind_names_for_emulator(); @@ -453,7 +453,7 @@ begin_shutdown: save_settings(); menu_deinit(); - xdk360_video_deinit(); + video_xdk360.stop(); rarch_exec(); return 0; diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index e84397a417..9bfaf7183c 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -719,7 +719,7 @@ void xdk360_video_set_vsync(bool vsync) // the top level module owns the instance, and is created beforehand. // When RetroArch gets around to init it, it is already allocated. // When RetroArch wants to free it, it is ignored. -void xdk360_video_init(void) +static void xdk360_start(void) { video_info_t video_info = {0}; @@ -742,7 +742,11 @@ void xdk360_video_init(void) } } -void xdk360_video_deinit(void) +static void xdk360_restart(void) +{ +} + +static void xdk360_stop(void) { void *data = g_d3d; g_d3d = NULL; @@ -762,5 +766,8 @@ const video_driver_t video_xdk360 = { xdk360_set_swap_block_swap, xdk360_swap, xdk360_set_aspect_ratio, + xdk360_start, + xdk360_stop, + xdk360_restart, xdk360_set_orientation, }; diff --git a/360/xdk360_video.h b/360/xdk360_video.h index c94e62fe61..0165fd4723 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -62,8 +62,6 @@ typedef struct xdk360_video LPDIRECT3DSURFACE9 lpSurface; } xdk360_video_t; -void xdk360_video_init (void); -void xdk360_video_deinit (void); void xdk360_video_set_vsync (bool vsync); void xdk360_set_fbo_enable (bool enable); void xdk360_gfx_init_fbo(xdk360_video_t *vid); diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 25d89de927..d92a63fee6 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -58,10 +58,13 @@ VIDEO #include "../../gfx/gl.c" #endif +#ifdef HAVE_HLSL +#include "../../gfx/shader_hlsl.c" +#endif + #if defined(__CELLOS_LV2__) #include "../../ps3/image.c" #elif defined(_XBOX) -#include "../../gfx/shader_hlsl.c" #include "../../360/xdk360_video.cpp" #elif defined(GEKKO) #include "../../wii/video.c" diff --git a/msvc-360/RetroArch-360/RetroArch-360.vcxproj b/msvc-360/RetroArch-360/RetroArch-360.vcxproj index c0d22cbeed..88b10da7e3 100644 --- a/msvc-360/RetroArch-360/RetroArch-360.vcxproj +++ b/msvc-360/RetroArch-360/RetroArch-360.vcxproj @@ -113,7 +113,7 @@ true false MultiThreadedDebug - _DEBUG;_XBOX;PACKAGE_VERSION="0.9.6-rc1";%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN + _DEBUG;_XBOX;PACKAGE_VERSION="0.9.6-rc1";%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL Callcap @@ -151,7 +151,7 @@ AnalyzeOnly false MultiThreadedDebug - _DEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;RARCH_CONSOLE;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN + _DEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;RARCH_CONSOLE;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL Callcap @@ -190,7 +190,7 @@ Size false MultiThreaded - NDEBUG;_XBOX;PROFILE;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN + NDEBUG;_XBOX;PROFILE;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL Callcap @@ -234,7 +234,7 @@ Size false MultiThreaded - NDEBUG;_XBOX;PROFILE;FASTCAP;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN + NDEBUG;_XBOX;PROFILE;FASTCAP;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL true @@ -275,7 +275,7 @@ false false MultiThreaded - NDEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE=1;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN + NDEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE=1;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL true @@ -316,7 +316,7 @@ false false MultiThreaded - NDEBUG;_XBOX;LTCG;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN + NDEBUG;_XBOX;LTCG;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL true @@ -714,4 +714,4 @@ - + \ No newline at end of file From f8ad3dcc9144633866cb6ce412f6f9d12d95356f Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 00:45:30 +0200 Subject: [PATCH 090/103] (360) Font subsystem works again - font crap needs to be badly refactored --- 360/xdk360_video.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 9bfaf7183c..94c5b7074b 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -108,6 +108,7 @@ const DWORD g_MapLinearToSrgbGpuFormat[] = struct XPR_HEADER { + unsigned long dwMagic; unsigned long dwHeaderSize; unsigned long dwDataSize; }; @@ -164,6 +165,13 @@ HRESULT PackedResource::Create( const char * strFilename ) return E_FAIL; } + if( xprh.dwMagic != XPR2_MAGIC_VALUE ) + { + RARCH_ERR( "Invalid Xbox Packed Resource (.xpr) file: Magic = 0x%08lx.\n", xprh.dwMagic ); + CloseHandle( hFile ); + return E_FAIL; + } + // Compute memory requirements m_dwSysMemDataSize = xprh.dwHeaderSize; m_dwVidMemDataSize = xprh.dwDataSize; From b7fce9a98e4bae93d6b3f5ed7c0e4e72cf493154 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 00:56:58 +0200 Subject: [PATCH 091/103] (360) Removed g_d3d global pointer --- 360/fonts.cpp | 14 +++++++------- 360/menu.cpp | 8 ++++---- 360/xdk360_video.cpp | 29 ++++++++++++++++------------- 360/xdk360_video.h | 2 -- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/360/fonts.cpp b/360/fonts.cpp index 34930d1a54..cd3f3a809d 100644 --- a/360/fonts.cpp +++ b/360/fonts.cpp @@ -26,7 +26,7 @@ static xdk360_video_font_t m_Font; void xdk360_console_draw(void) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *m_pd3dDevice = vid->d3d_render_device; // The top line @@ -54,7 +54,7 @@ void xdk360_console_draw(void) HRESULT xdk360_console_init( LPCSTR strFontFileName, unsigned long colBackColor, unsigned long colTextColor) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *m_pd3dDevice = vid->d3d_render_device; video_console.first_message = true; @@ -353,7 +353,7 @@ static HRESULT xdk360_video_font_create_shaders (xdk360_video_font_t * font) }; // Cache this global into a register - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *pd3dDevice = vid->d3d_render_device; hr = pd3dDevice->CreateVertexDeclaration( decl, &s_FontLocals.m_pFontVertexDecl ); @@ -481,7 +481,7 @@ HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontF return E_FAIL; } - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *pd3dDevice = vid->d3d_render_device; // Initialize the window @@ -603,7 +603,7 @@ void xdk360_video_font_begin (xdk360_video_font_t * font) if( font->m_dwNestedBeginCount == 0 ) { // Cache the global pointer into a register - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *pD3dDevice = vid->d3d_render_device; // Save state @@ -680,7 +680,7 @@ void xdk360_video_font_end(xdk360_video_font_t * font) if( font->m_bSaveState ) { // Cache the global pointer into a register - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *pD3dDevice = vid->d3d_render_device; D3DDevice_SetTexture_Inline(pD3dDevice, 0, NULL); @@ -710,7 +710,7 @@ void xdk360_video_font_draw_text(xdk360_video_font_t * font, float fOriginX, flo if( strText == NULL || strText[0] == L'\0') return; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; D3DDevice *pd3dDevice = vid->d3d_render_device; // Set the color as a vertex shader constant diff --git a/360/menu.cpp b/360/menu.cpp index 9d939438db..e053e76c52 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -255,7 +255,7 @@ HRESULT CRetroArchSettings::OnControlNavigate(XUIMessageControlNavigate *pContro { char scalefactor[128]; int current_index; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; current_index = m_settingslist.GetCurSel(); @@ -668,7 +668,7 @@ HRESULT CRetroArchSettings::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled HRESULT CRetroArchMain::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled ) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; hdmenus_allowed = vid->video_mode.fIsHiDef && (g_console.aspect_ratio_index >= ASPECT_RATIO_16_9); @@ -738,7 +738,7 @@ int menu_init (void) { HRESULT hr; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; hr = app.InitShared(vid->d3d_render_device, &vid->d3dpp, XuiPNGTextureLoader); @@ -788,7 +788,7 @@ void menu_loop(void) g_console.menu_enable = true; HRESULT hr; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; if(g_console.emulator_initialized) video_xdk360.set_swap_block_state(NULL, true); diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 94c5b7074b..90180ab7a5 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -34,7 +34,6 @@ static bool g_quitting; static bool g_first_msg; unsigned g_frame_count; -void *g_d3d; /* Xbox 360 specific code */ @@ -255,8 +254,10 @@ void PackedResource::Destroy() static void xdk360_gfx_free(void * data) { - if (g_d3d) +#ifdef RARCH_CONSOLE + if (driver.video_data) return; +#endif xdk360_video_t *vid = (xdk360_video_t*)data; @@ -272,7 +273,8 @@ static void xdk360_gfx_free(void * data) void set_viewport(bool force_full) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; + vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); @@ -340,7 +342,7 @@ void set_viewport(bool force_full) static void xdk360_set_orientation(void * data, uint32_t orientation) { (void)data; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; FLOAT angle; switch(orientation) @@ -390,7 +392,7 @@ static void xdk360_convert_texture_to_as16_srgb( D3DTexture *pTexture ) void xdk360_set_fbo_enable (bool enable) { - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; vid->fbo_enabled = enable; } @@ -424,8 +426,8 @@ void xdk360_gfx_init_fbo(xdk360_video_t *vid) static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) { - if (g_d3d) - return g_d3d; + if (driver.video_data) + return driver.video_data; xdk360_video_t *vid = (xdk360_video_t*)calloc(1, sizeof(xdk360_video_t)); if (!vid) @@ -678,7 +680,7 @@ static bool xdk360_gfx_frame(void *data, const void *frame, static void xdk360_set_swap_block_swap (void * data, bool toggle) { (void)data; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; vid->block_swap = toggle; if(toggle) @@ -690,7 +692,7 @@ static void xdk360_set_swap_block_swap (void * data, bool toggle) static void xdk360_swap (void * data) { (void)data; - xdk360_video_t *vid = (xdk360_video_t*)g_d3d; + xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; vid->d3d_render_device->Present(NULL, NULL, NULL, NULL); } @@ -719,7 +721,7 @@ static bool xdk360_gfx_focus(void *data) void xdk360_video_set_vsync(bool vsync) { - xdk360_gfx_set_nonblock_state(g_d3d, vsync); + xdk360_gfx_set_nonblock_state(driver.video_data, vsync); } // 360 needs a working graphics stack before RetroArch even starts. @@ -733,10 +735,11 @@ static void xdk360_start(void) video_info.vsync = g_settings.video.vsync; video_info.force_aspect = false; + video_info.fullscreen = true; video_info.smooth = g_settings.video.smooth; video_info.input_scale = 2; - g_d3d = xdk360_gfx_init(&video_info, NULL, NULL); + driver.video_data = xdk360_gfx_init(&video_info, NULL, NULL); g_first_msg = true; @@ -756,8 +759,8 @@ static void xdk360_restart(void) static void xdk360_stop(void) { - void *data = g_d3d; - g_d3d = NULL; + void *data = driver.video_data; + driver.video_data = NULL; xdk360_console_deinit(); xdk360_gfx_free(data); } diff --git a/360/xdk360_video.h b/360/xdk360_video.h index 0165fd4723..3e252ad700 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -67,6 +67,4 @@ void xdk360_set_fbo_enable (bool enable); void xdk360_gfx_init_fbo(xdk360_video_t *vid); void set_viewport(bool force_full); -extern void *g_d3d; - #endif From 85850ffba1a752d8c788f8ef46560cb09816657d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 01:15:00 +0200 Subject: [PATCH 092/103] (PS3) Add HAVE_VID_CONTEXT define --- Makefile.ps3 | 2 +- console/griffin/griffin.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile.ps3 b/Makefile.ps3 index d5468acb20..7ea9033349 100644 --- a/Makefile.ps3 +++ b/Makefile.ps3 @@ -68,7 +68,7 @@ endif PPU_LDLIBS = -ldbgfont $(GL_LIBS) -lretro -lcgc -lgcm_cmd -lgcm_sys_stub -lresc_stub -lm -lio_stub -lfs_stub -lsysutil_stub -lsysutil_game_stub -lsysutil_screenshot_stub -lsysutil_np_stub -lpngdec_stub -ljpgdec_stub -lsysmodule_stub -laudio_stub -lnet_stub -lnetctl_stub -lpthread -DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_TEXREF -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) +DEFINES += -DRARCH_CONSOLE -DHAVE_OPENGL -DHAVE_OPENGL_TEXREF -DHAVE_VID_CONTEXT -DHAVE_OPENGLES -DHAVE_CG -DHAVE_CG_MENU -DHAVE_FILEBROWSER -DHAVE_FBO -DHAVE_RARCH_MAIN_WRAP -DHAVE_SYSMODULES -DHAVE_SYSUTILS -DHAVE_RARCH_EXEC -DHAVE_RGL -DHAVE_LIBRETRO_MANAGEMENT -DHAVE_RSOUND -DHAVE_ZLIB -D__CELLOS_LV2__ -DHAVE_CONFIGFILE=1 -DHAVE_NETPLAY=1 -DHAVE_SOCKET_LEGACY=1 -DHAVE_GRIFFIN=1 -DPACKAGE_VERSION=\"$(RARCH_VERSION)\" -Dmain=rarch_main -DPC_DEVELOPMENT_IP_ADDRESS=\"$(PC_DEVELOPMENT_IP_ADDRESS)\" -DPC_DEVELOPMENT_UDP_PORT=$(PC_DEVELOPMENT_UDP_PORT) ifeq ($(DEBUG), 1) PPU_OPTIMIZE_LV := -O0 -g diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index d92a63fee6..e05cad05e2 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -46,8 +46,13 @@ CONFIG FILE VIDEO ============================================================ */ +#ifdef HAVE_VID_CONTEXT + #if defined(__CELLOS_LV2__) #include "../../gfx/context/ps3_ctx.c" +#elif defined(_XBOX) +#endif + #endif #ifdef HAVE_CG From 463fdd9bdf83d6bae959f3fd02507470bc898c86 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 02:29:51 +0200 Subject: [PATCH 093/103] (360) Add 360 context file and use it --- 360/menu.cpp | 30 +- 360/xdk360_input.c | 1 + 360/xdk360_video.cpp | 356 +++++++++---------- 360/xdk360_video.h | 8 +- 360/xdk360_video_general.h | 6 +- console/griffin/griffin.c | 1 + console/griffin/hook.h | 14 +- driver.h | 3 - gfx/context/xdk360_ctx.c | 135 +++++++ gfx/context/xdk360_ctx.h | 20 ++ gfx/gfx_context.h | 9 +- gfx/gl.c | 3 - msvc-360/RetroArch-360/RetroArch-360.vcxproj | 12 +- 13 files changed, 372 insertions(+), 226 deletions(-) create mode 100644 gfx/context/xdk360_ctx.c create mode 100644 gfx/context/xdk360_ctx.h diff --git a/360/menu.cpp b/360/menu.cpp index e053e76c52..b48d307b19 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -337,6 +337,7 @@ HRESULT CRetroArchQuickMenu::OnInit(XUIMessageInit * pInitData, BOOL& bHandled) HRESULT CRetroArchQuickMenu::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled ) { + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; int current_index; if ( hObjPressed == m_quickmenulist) @@ -365,7 +366,7 @@ HRESULT CRetroArchQuickMenu::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled if(g_console.aspect_ratio_index >= ASPECT_RATIO_END) g_console.aspect_ratio_index = 0; - video_xdk360.set_aspect_ratio(NULL, g_console.aspect_ratio_index); + gfx_ctx_set_aspect_ratio(d3d9, g_console.aspect_ratio_index); char aspectratio_label[32]; snprintf(aspectratio_label, sizeof(aspectratio_label), "Aspect Ratio: %s", aspectratio_lut[g_console.aspect_ratio_index].name); wchar_t * aspectratio_label_w = rarch_convert_char_to_wchar(aspectratio_label); @@ -397,7 +398,7 @@ HRESULT CRetroArchQuickMenu::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled m_quickmenulist.SetText(MENU_ITEM_ORIENTATION, L"Orientation: Normal"); break; } - video_xdk360.set_rotation(NULL, g_console.screen_orientation); + video_xdk360.set_rotation(driver.video_data, g_console.screen_orientation); break; case MENU_ITEM_RESIZE_MODE: g_console.input_loop = INPUT_LOOP_RESIZE_MODE; @@ -657,7 +658,7 @@ HRESULT CRetroArchSettings::OnNotifyPress( HXUIOBJ hObjPressed, int & bHandled case SETTING_SCALE_ENABLED: g_console.fbo_enabled = !g_console.fbo_enabled; m_settingslist.SetText(SETTING_SCALE_ENABLED, g_console.fbo_enabled ? L"Custom Scaling/Dual Shaders: ON" : L"Custom Scaling/Dual Shaders: OFF"); - xdk360_set_fbo_enable(g_console.fbo_enabled); + gfx_ctx_set_fbo(g_console.fbo_enabled); break; } } @@ -785,26 +786,18 @@ void menu_deinit (void) void menu_loop(void) { + HRESULT hr; + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + g_console.menu_enable = true; - HRESULT hr; - xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; - - if(g_console.emulator_initialized) - video_xdk360.set_swap_block_state(NULL, true); + d3d9->block_swap = true; g_console.input_loop = INPUT_LOOP_MENU; do { - g_frame_count++; - if(g_console.emulator_initialized) - { - rarch_render_cached_frame(); - } - else - vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, - D3DCOLOR_ARGB(255, 32, 32, 64), 1.0f, 0); + rarch_render_cached_frame(); XINPUT_STATE state; XInputGetState(0, &state); @@ -853,11 +846,10 @@ void menu_loop(void) } } - video_xdk360.swap(NULL); + gfx_ctx_swap_buffers(); }while(g_console.menu_enable); - if(g_console.emulator_initialized) - video_xdk360.set_swap_block_state(NULL, false); + d3d9->block_swap = false; g_console.ingame_menu_enable = false; } diff --git a/360/xdk360_input.c b/360/xdk360_input.c index ea23dfc17d..5a2ad699f4 100644 --- a/360/xdk360_input.c +++ b/360/xdk360_input.c @@ -150,6 +150,7 @@ static bool xdk360_key_pressed(void *data, int key) (void)data; XINPUT_STATE state; bool retval; + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; XInputGetState(0, &state); retval = false; diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 90180ab7a5..0aecac5f81 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -15,13 +15,20 @@ */ // Xbox 360-specific headers +#ifdef _XBOX #include #include +#endif #include "../driver.h" #include "xdk360_video.h" #include "xdk360_video_resources.h" + +#ifdef HAVE_HLSL #include "../gfx/shader_hlsl.h" +#endif + +#include "./../gfx/gfx_context.h" #include "../console/console_ext.h" #include "../general.h" #include "../message.h" @@ -31,9 +38,7 @@ #include "config.h" #endif -static bool g_quitting; static bool g_first_msg; -unsigned g_frame_count; /* Xbox 360 specific code */ @@ -252,34 +257,50 @@ void PackedResource::Destroy() /* end of Xbox 360 specific code */ -static void xdk360_gfx_free(void * data) +static void check_window(xdk360_video_t *d3d9) +{ + bool quit, resize; + + gfx_ctx_check_window(&quit, + &resize, NULL, NULL, + d3d9->frame_count); + + if (quit) + d3d9->quitting = true; + else if (resize) + d3d9->should_resize = true; +} + +static void xdk360_free(void * data) { #ifdef RARCH_CONSOLE if (driver.video_data) return; #endif - xdk360_video_t *vid = (xdk360_video_t*)data; + xdk360_video_t *d3d9 = (xdk360_video_t*)data; - if (!vid) + if (!d3d9) return; +#ifdef HAVE_HLSL hlsl_deinit(); - vid->d3d_render_device->Release(); - vid->d3d_device->Release(); +#endif + d3d9->d3d_render_device->Release(); + d3d9->d3d_device->Release(); - free(vid); + free(d3d9); } -void set_viewport(bool force_full) +static void xdk360_set_viewport(bool force_full) { - xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; - vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + d3d9->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); - int width = vid->video_mode.fIsHiDef ? 1280 : 640; - int height = vid->video_mode.fIsHiDef ? 720 : 480; + int width = d3d9->video_mode.fIsHiDef ? 1280 : 640; + int height = d3d9->video_mode.fIsHiDef ? 720 : 480; int m_viewport_x_temp, m_viewport_y_temp, m_viewport_width_temp, m_viewport_height_temp; float m_zNear, m_zFar; @@ -329,7 +350,7 @@ void set_viewport(bool force_full) vp.Y = m_viewport_y_temp; vp.MinZ = m_zNear; vp.MaxZ = m_zFar; - vid->d3d_render_device->SetViewport(&vp); + d3d9->d3d_render_device->SetViewport(&vp); //if(gl->overscan_enable && !force_full) //{ @@ -339,10 +360,10 @@ void set_viewport(bool force_full) //} } -static void xdk360_set_orientation(void * data, uint32_t orientation) +static void xdk360_set_rotation(void * data, unsigned orientation) { (void)data; - xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; + xdk360_video_t *d3d9 = (xdk360_video_t*)data; FLOAT angle; switch(orientation) @@ -363,18 +384,8 @@ static void xdk360_set_orientation(void * data, uint32_t orientation) /* TODO: Move to D3DXMATRIX here */ hlsl_set_proj_matrix(XMMatrixRotationZ(angle)); -} -static void xdk360_set_aspect_ratio(void * data, uint32_t aspectratio_index) -{ - (void)data; - - 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; - g_settings.video.force_aspect = false; - set_viewport(false); + d3d9->should_resize = TRUE; } static void xdk360_convert_texture_to_as16_srgb( D3DTexture *pTexture ) @@ -390,110 +401,103 @@ static void xdk360_convert_texture_to_as16_srgb( D3DTexture *pTexture ) pTexture->Format.DataFormat = g_MapLinearToSrgbGpuFormat[ (desc.Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT ]; } -void xdk360_set_fbo_enable (bool enable) +void xdk360_init_fbo(xdk360_video_t *d3d9) { - xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; - - vid->fbo_enabled = enable; -} - -void xdk360_gfx_init_fbo(xdk360_video_t *vid) -{ - if (vid->lpTexture_ot) + if (d3d9->lpTexture_ot) { - vid->lpTexture_ot->Release(); - vid->lpTexture_ot = NULL; + d3d9->lpTexture_ot->Release(); + d3d9->lpTexture_ot = NULL; } - if (vid->lpSurface) + if (d3d9->lpSurface) { - vid->lpSurface->Release(); - vid->lpSurface = NULL; + d3d9->lpSurface->Release(); + d3d9->lpSurface = NULL; } - vid->d3d_render_device->CreateTexture(512 * g_settings.video.fbo_scale_x, 512 * g_settings.video.fbo_scale_y, + d3d9->d3d_render_device->CreateTexture(512 * g_settings.video.fbo_scale_x, 512 * g_settings.video.fbo_scale_y, 1, 0, g_console.gamma_correction_enable ? ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 ) : D3DFMT_A8R8G8B8, - 0, &vid->lpTexture_ot, NULL); + 0, &d3d9->lpTexture_ot, NULL); - vid->d3d_render_device->CreateRenderTarget(512 * g_settings.video.fbo_scale_x, 512 * g_settings.video.fbo_scale_y, + d3d9->d3d_render_device->CreateRenderTarget(512 * g_settings.video.fbo_scale_x, 512 * g_settings.video.fbo_scale_y, g_console.gamma_correction_enable ? ( D3DFORMAT )MAKESRGBFMT( D3DFMT_A8R8G8B8 ) : D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, - 0, 0, &vid->lpSurface, NULL); + 0, 0, &d3d9->lpSurface, NULL); - vid->lpTexture_ot_as16srgb = *vid->lpTexture_ot; - xdk360_convert_texture_to_as16_srgb(vid->lpTexture); - xdk360_convert_texture_to_as16_srgb(&vid->lpTexture_ot_as16srgb); + d3d9->lpTexture_ot_as16srgb = *d3d9->lpTexture_ot; + xdk360_convert_texture_to_as16_srgb(d3d9->lpTexture); + xdk360_convert_texture_to_as16_srgb(&d3d9->lpTexture_ot_as16srgb); } -static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **input, void **input_data) +static void *xdk360_init(const video_info_t *video, const input_driver_t **input, void **input_data) { if (driver.video_data) return driver.video_data; - xdk360_video_t *vid = (xdk360_video_t*)calloc(1, sizeof(xdk360_video_t)); - if (!vid) + xdk360_video_t *d3d9 = (xdk360_video_t*)calloc(1, sizeof(xdk360_video_t)); + if (!d3d9) return NULL; - vid->d3d_device = Direct3DCreate9(D3D_SDK_VERSION); - if (!vid->d3d_device) + d3d9->d3d_device = Direct3DCreate9(D3D_SDK_VERSION); + if (!d3d9->d3d_device) { - free(vid); + free(d3d9); return NULL; } // Get video settings - memset(&vid->video_mode, 0, sizeof(vid->video_mode)); + memset(&d3d9->video_mode, 0, sizeof(d3d9->video_mode)); - XGetVideoMode(&vid->video_mode); + XGetVideoMode(&d3d9->video_mode); - memset(&vid->d3dpp, 0, sizeof(vid->d3dpp)); + memset(&d3d9->d3dpp, 0, sizeof(d3d9->d3dpp)); // no letterboxing in 4:3 mode (if widescreen is // unsupported - if(!vid->video_mode.fIsWideScreen) - vid->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX; + if(!d3d9->video_mode.fIsWideScreen) + d3d9->d3dpp.Flags |= D3DPRESENTFLAG_NO_LETTERBOX; - vid->d3dpp.BackBufferWidth = vid->video_mode.fIsHiDef ? 1280 : 640; - vid->d3dpp.BackBufferHeight = vid->video_mode.fIsHiDef ? 720 : 480; + d3d9->d3dpp.BackBufferWidth = d3d9->video_mode.fIsHiDef ? 1280 : 640; + d3d9->d3dpp.BackBufferHeight = d3d9->video_mode.fIsHiDef ? 720 : 480; if(g_console.gamma_correction_enable) { - vid->d3dpp.BackBufferFormat = g_console.color_format ? (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8) : (D3DFORMAT)MAKESRGBFMT(D3DFMT_LIN_A1R5G5B5); - vid->d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8); + d3d9->d3dpp.BackBufferFormat = g_console.color_format ? (D3DFORMAT)MAKESRGBFMT(D3DFMT_A8R8G8B8) : (D3DFORMAT)MAKESRGBFMT(D3DFMT_LIN_A1R5G5B5); + d3d9->d3dpp.FrontBufferFormat = (D3DFORMAT)MAKESRGBFMT(D3DFMT_LE_X8R8G8B8); } else { - vid->d3dpp.BackBufferFormat = g_console.color_format ? D3DFMT_A8R8G8B8 : D3DFMT_LIN_A1R5G5B5; - vid->d3dpp.FrontBufferFormat = D3DFMT_LE_X8R8G8B8; + d3d9->d3dpp.BackBufferFormat = g_console.color_format ? D3DFMT_A8R8G8B8 : D3DFMT_LIN_A1R5G5B5; + d3d9->d3dpp.FrontBufferFormat = D3DFMT_LE_X8R8G8B8; } - vid->d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; - vid->d3dpp.MultiSampleQuality = 0; - vid->d3dpp.BackBufferCount = 2; - vid->d3dpp.EnableAutoDepthStencil = FALSE; - vid->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; - vid->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; + d3d9->d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; + d3d9->d3dpp.MultiSampleQuality = 0; + d3d9->d3dpp.BackBufferCount = 2; + d3d9->d3dpp.EnableAutoDepthStencil = FALSE; + d3d9->d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; + d3d9->d3dpp.PresentationInterval = video->vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; // D3DCREATE_HARDWARE_VERTEXPROCESSING is ignored on 360 - vid->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, - &vid->d3dpp, &vid->d3d_render_device); + d3d9->d3d_device->CreateDevice(0, D3DDEVTYPE_HAL, NULL, D3DCREATE_HARDWARE_VERTEXPROCESSING, + &d3d9->d3dpp, &d3d9->d3d_render_device); - hlsl_init(g_settings.video.cg_shader_path, vid->d3d_render_device); + hlsl_init(g_settings.video.cg_shader_path, d3d9->d3d_render_device); - vid->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, - 0, &vid->lpTexture, NULL); + d3d9->d3d_render_device->CreateTexture(512, 512, 1, 0, D3DFMT_LIN_X1R5G5B5, + 0, &d3d9->lpTexture, NULL); - xdk360_gfx_init_fbo(vid); + xdk360_init_fbo(d3d9); D3DLOCKED_RECT d3dlr; - vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + d3d9->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - vid->lpTexture->UnlockRect(0); + d3d9->lpTexture->UnlockRect(0); - vid->last_width = 512; - vid->last_height = 512; + d3d9->last_width = 512; + d3d9->last_height = 512; - vid->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), - 0, 0, 0, &vid->vertex_buf, NULL); + d3d9->d3d_render_device->CreateVertexBuffer(4 * sizeof(DrawVerticeFormats), + 0, 0, 0, &d3d9->vertex_buf, NULL); static const DrawVerticeFormats init_verts[] = { { -1.0f, -1.0f, 0.0f, 1.0f }, @@ -503,9 +507,9 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i }; void *verts_ptr; - vid->vertex_buf->Lock(0, 0, &verts_ptr, 0); + d3d9->vertex_buf->Lock(0, 0, &verts_ptr, 0); memcpy(verts_ptr, init_verts, sizeof(init_verts)); - vid->vertex_buf->Unlock(); + d3d9->vertex_buf->Unlock(); static const D3DVERTEXELEMENT9 VertexElements[] = { @@ -514,20 +518,20 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i D3DDECL_END() }; - vid->d3d_render_device->CreateVertexDeclaration(VertexElements, &vid->v_decl); + d3d9->d3d_render_device->CreateVertexDeclaration(VertexElements, &d3d9->v_decl); - vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + d3d9->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0); - vid->d3d_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); - vid->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); + d3d9->d3d_render_device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); + d3d9->d3d_render_device->SetRenderState(D3DRS_ZENABLE, FALSE); D3DVIEWPORT9 vp = {0}; - vp.Width = vid->video_mode.fIsHiDef ? 1280 : 640; - vp.Height = vid->video_mode.fIsHiDef ? 720 : 480; + vp.Width = d3d9->video_mode.fIsHiDef ? 1280 : 640; + vp.Height = d3d9->video_mode.fIsHiDef ? 720 : 480; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; - vid->d3d_render_device->SetViewport(&vp); + d3d9->d3d_render_device->SetViewport(&vp); if(g_console.viewports.custom_vp.width == 0) g_console.viewports.custom_vp.width = vp.Width; @@ -535,27 +539,27 @@ static void *xdk360_gfx_init(const video_info_t *video, const input_driver_t **i if(g_console.viewports.custom_vp.height == 0) g_console.viewports.custom_vp.height = vp.Height; - xdk360_set_orientation(NULL, g_console.screen_orientation); + xdk360_set_rotation(d3d9, g_console.screen_orientation); - vid->fbo_enabled = 1; + d3d9->fbo_enabled = 1; - return vid; + return d3d9; } -static bool xdk360_gfx_frame(void *data, const void *frame, +static bool xdk360_frame(void *data, const void *frame, unsigned width, unsigned height, unsigned pitch, const char *msg) { - xdk360_video_t *vid = (xdk360_video_t*)data; + xdk360_video_t *d3d9 = (xdk360_video_t*)data; D3DSurface* pRenderTarget0; bool menu_enabled = g_console.menu_enable; - if (vid->last_width != width || vid->last_height != height) + if (d3d9->last_width != width || d3d9->last_height != height) { D3DLOCKED_RECT d3dlr; - vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + d3d9->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); memset(d3dlr.pBits, 0, 512 * d3dlr.Pitch); - vid->lpTexture->UnlockRect(0); + d3d9->lpTexture->UnlockRect(0); float tex_w = width / 512.0f; float tex_h = height / 512.0f; @@ -575,31 +579,34 @@ static bool xdk360_gfx_frame(void *data, const void *frame, } void *verts_ptr; - vid->vertex_buf->Lock(0, 0, &verts_ptr, 0); + d3d9->vertex_buf->Lock(0, 0, &verts_ptr, 0); memcpy(verts_ptr, verts, sizeof(verts)); - vid->vertex_buf->Unlock(); + d3d9->vertex_buf->Unlock(); - vid->last_width = width; - vid->last_height = height; + d3d9->last_width = width; + d3d9->last_height = height; } - if(vid->fbo_enabled) + if (d3d9->fbo_enabled) { - vid->d3d_render_device->GetRenderTarget(0, &pRenderTarget0); - vid->d3d_render_device->SetRenderTarget(0, vid->lpSurface); + d3d9->d3d_render_device->GetRenderTarget(0, &pRenderTarget0); + d3d9->d3d_render_device->SetRenderTarget(0, d3d9->lpSurface); } - vid->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, - 0xff000000, 1.0f, 0); - g_frame_count++; + if (d3d9->should_resize) + xdk360_set_viewport(false); - vid->d3d_render_device->SetTexture(0, vid->lpTexture); + d3d9->d3d_render_device->Clear(0, NULL, D3DCLEAR_TARGET, + 0xff000000, 1.0f, 0); + d3d9->frame_count++; + + d3d9->d3d_render_device->SetTexture(0, d3d9->lpTexture); hlsl_use(1); - if(vid->fbo_enabled) + if(d3d9->fbo_enabled) { hlsl_set_params(width, height, 512, 512, g_settings.video.fbo_scale_x * width, - g_settings.video.fbo_scale_y * height, g_frame_count); + g_settings.video.fbo_scale_y * height, d3d9->frame_count); D3DVIEWPORT9 vp = {0}; vp.Width = g_settings.video.fbo_scale_x * width; vp.Height = g_settings.video.fbo_scale_y * height; @@ -607,55 +614,55 @@ static bool xdk360_gfx_frame(void *data, const void *frame, vp.Y = 0; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; - vid->d3d_render_device->SetViewport(&vp); + d3d9->d3d_render_device->SetViewport(&vp); } else { - hlsl_set_params(width, height, 512, 512, vid->d3dpp.BackBufferWidth, - vid->d3dpp.BackBufferHeight, g_frame_count); + hlsl_set_params(width, height, 512, 512, d3d9->d3dpp.BackBufferWidth, + d3d9->d3dpp.BackBufferHeight, d3d9->frame_count); } D3DLOCKED_RECT d3dlr; - vid->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); + d3d9->lpTexture->LockRect(0, &d3dlr, NULL, D3DLOCK_NOSYSLOCK); for (unsigned y = 0; y < height; y++) { const uint8_t *in = (const uint8_t*)frame + y * pitch; uint8_t *out = (uint8_t*)d3dlr.pBits + y * d3dlr.Pitch; memcpy(out, in, width * sizeof(uint16_t)); } - vid->lpTexture->UnlockRect(0); + d3d9->lpTexture->UnlockRect(0); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - vid->d3d_render_device->SetVertexDeclaration(vid->v_decl); - vid->d3d_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats)); + d3d9->d3d_render_device->SetVertexDeclaration(d3d9->v_decl); + d3d9->d3d_render_device->SetStreamSource(0, d3d9->vertex_buf, 0, sizeof(DrawVerticeFormats)); - vid->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); + d3d9->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); - if(vid->fbo_enabled) + if(d3d9->fbo_enabled) { - vid->d3d_render_device->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, vid->lpTexture_ot, + d3d9->d3d_render_device->Resolve(D3DRESOLVE_RENDERTARGET0, NULL, d3d9->lpTexture_ot, NULL, 0, 0, NULL, 0, 0, NULL); - vid->d3d_render_device->SetRenderTarget(0, pRenderTarget0); + d3d9->d3d_render_device->SetRenderTarget(0, pRenderTarget0); pRenderTarget0->Release(); - vid->d3d_render_device->SetTexture(0, &vid->lpTexture_ot_as16srgb); + d3d9->d3d_render_device->SetTexture(0, &d3d9->lpTexture_ot_as16srgb); hlsl_use(2); - hlsl_set_params(g_settings.video.fbo_scale_x * width, g_settings.video.fbo_scale_y * height, g_settings.video.fbo_scale_x * 512, g_settings.video.fbo_scale_y * 512, vid->d3dpp.BackBufferWidth, - vid->d3dpp.BackBufferHeight, g_frame_count); - set_viewport(false); + hlsl_set_params(g_settings.video.fbo_scale_x * width, g_settings.video.fbo_scale_y * height, g_settings.video.fbo_scale_x * 512, g_settings.video.fbo_scale_y * 512, d3d9->d3dpp.BackBufferWidth, + d3d9->d3dpp.BackBufferHeight, d3d9->frame_count); + xdk360_set_viewport(false); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); - vid->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); - vid->d3d_render_device->SetVertexDeclaration(vid->v_decl); - vid->d3d_render_device->SetStreamSource(0, vid->vertex_buf, 0, sizeof(DrawVerticeFormats)); - vid->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MINFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_MAGFILTER, g_settings.video.second_pass_smooth ? D3DTEXF_LINEAR : D3DTEXF_POINT); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER); + d3d9->d3d_render_device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER); + d3d9->d3d_render_device->SetVertexDeclaration(d3d9->v_decl); + d3d9->d3d_render_device->SetStreamSource(0, d3d9->vertex_buf, 0, sizeof(DrawVerticeFormats)); + d3d9->d3d_render_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); } /* XBox 360 specific font code */ @@ -671,8 +678,8 @@ static bool xdk360_gfx_frame(void *data, const void *frame, xdk360_console_draw(); } - if(!vid->block_swap) - vid->d3d_render_device->Present(NULL, NULL, NULL, NULL); + if(!d3d9->block_swap) + d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL); return true; } @@ -680,8 +687,8 @@ static bool xdk360_gfx_frame(void *data, const void *frame, static void xdk360_set_swap_block_swap (void * data, bool toggle) { (void)data; - xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; - vid->block_swap = toggle; + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + d3d9->block_swap = toggle; if(toggle) RARCH_LOG("Swap is set to blocked.\n"); @@ -692,36 +699,32 @@ static void xdk360_set_swap_block_swap (void * data, bool toggle) static void xdk360_swap (void * data) { (void)data; - xdk360_video_t *vid = (xdk360_video_t*)driver.video_data; - vid->d3d_render_device->Present(NULL, NULL, NULL, NULL); + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL); } -static void xdk360_gfx_set_nonblock_state(void *data, bool state) +static void xdk360_set_nonblock_state(void *data, bool state) { - xdk360_video_t *vid = (xdk360_video_t*)data; - RARCH_LOG("D3D Vsync => %s\n", state ? "off" : "on"); - /* XBox 360 specific code */ - if(state) - vid->d3d_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE); - else - vid->d3d_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_ONE); + xdk360_video_t *d3d9 = (xdk360_video_t*)data; + + if(d3d9->vsync) + { + RARCH_LOG("D3D Vsync => %s\n", state ? "off" : "on"); + gfx_ctx_set_swap_interval(state ? 0 : 1, TRUE); + } } -static bool xdk360_gfx_alive(void *data) +static bool xdk360_alive(void *data) +{ + xdk360_video_t *d3d9 = (xdk360_video_t*)data; + check_window(d3d9); + return !d3d9->quitting; +} + +static bool xdk360_focus(void *data) { (void)data; - return !g_quitting; -} - -static bool xdk360_gfx_focus(void *data) -{ - (void)data; - return true; -} - -void xdk360_video_set_vsync(bool vsync) -{ - xdk360_gfx_set_nonblock_state(driver.video_data, vsync); + return gfx_ctx_window_has_focus(); } // 360 needs a working graphics stack before RetroArch even starts. @@ -739,7 +742,7 @@ static void xdk360_start(void) video_info.smooth = g_settings.video.smooth; video_info.input_scale = 2; - driver.video_data = xdk360_gfx_init(&video_info, NULL, NULL); + driver.video_data = xdk360_init(&video_info, NULL, NULL); g_first_msg = true; @@ -762,23 +765,20 @@ static void xdk360_stop(void) void *data = driver.video_data; driver.video_data = NULL; xdk360_console_deinit(); - xdk360_gfx_free(data); + xdk360_free(data); } const video_driver_t video_xdk360 = { - xdk360_gfx_init, - xdk360_gfx_frame, - xdk360_gfx_set_nonblock_state, - xdk360_gfx_alive, - xdk360_gfx_focus, + xdk360_init, + xdk360_frame, + xdk360_set_nonblock_state, + xdk360_alive, + xdk360_focus, NULL, - xdk360_gfx_free, + xdk360_free, "xdk360", - xdk360_set_swap_block_swap, - xdk360_swap, - xdk360_set_aspect_ratio, xdk360_start, xdk360_stop, xdk360_restart, - xdk360_set_orientation, + xdk360_set_rotation, }; diff --git a/360/xdk360_video.h b/360/xdk360_video.h index 3e252ad700..4ed295fb9f 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -47,7 +47,10 @@ typedef struct xdk360_video { bool block_swap; bool fbo_enabled; - bool vsync; + bool should_resize; + bool quitting; + bool vsync; + unsigned frame_count; unsigned last_width; unsigned last_height; IDirect3D9* d3d_device; @@ -62,9 +65,6 @@ typedef struct xdk360_video LPDIRECT3DSURFACE9 lpSurface; } xdk360_video_t; -void xdk360_video_set_vsync (bool vsync); -void xdk360_set_fbo_enable (bool enable); void xdk360_gfx_init_fbo(xdk360_video_t *vid); -void set_viewport(bool force_full); #endif diff --git a/360/xdk360_video_general.h b/360/xdk360_video_general.h index 474b1ce923..d5c29f161e 100644 --- a/360/xdk360_video_general.h +++ b/360/xdk360_video_general.h @@ -19,10 +19,8 @@ #define LAST_ASPECT_RATIO ASPECT_RATIO_CUSTOM -#define IS_TIMER_NOT_EXPIRED() (g_frame_count < g_console.timer_expiration_frame_count) +#define IS_TIMER_NOT_EXPIRED() (d3d9->frame_count < g_console.timer_expiration_frame_count) #define IS_TIMER_EXPIRED() (!(IS_TIMER_NOT_EXPIRED())) -#define SET_TIMER_EXPIRATION(value) g_console.timer_expiration_frame_count = g_frame_count + value; - -extern unsigned g_frame_count; +#define SET_TIMER_EXPIRATION(value) g_console.timer_expiration_frame_count = d3d9->frame_count + value; #endif diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index e05cad05e2..4194037b40 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -51,6 +51,7 @@ VIDEO #if defined(__CELLOS_LV2__) #include "../../gfx/context/ps3_ctx.c" #elif defined(_XBOX) +#include "../../gfx/context/xdk360_ctx.c" #endif #endif diff --git a/console/griffin/hook.h b/console/griffin/hook.h index 8f6a31ef14..00748010a0 100644 --- a/console/griffin/hook.h +++ b/console/griffin/hook.h @@ -54,16 +54,16 @@ #elif defined(_XBOX) #define video_init_func(video_info, input, input_data) \ - xdk360_gfx_init(video_info, input, input_data) + xdk360_init(video_info, input, input_data) #define video_frame_func(data, width, height, pitch, msg) \ - xdk360_gfx_frame(driver.video_data, data, width, height, pitch, msg) + xdk360_frame(driver.video_data, data, width, height, pitch, msg) #define video_set_nonblock_state_func(state) driver.video->set_nonblock_state(driver.video_data, state) -#define video_alive_func() xdk360_gfx_alive(driver.video_data) -#define video_focus_func() xdk360_gfx_focus(driver.video_data) +#define video_alive_func() xdk360_alive(driver.video_data) +#define video_focus_func() xdk360_focus(driver.video_data) #define video_xml_shader_func(path) driver.video->xml_shader(driver.video_data, path) -#define video_free_func() xdk360_gfx_free(driver.video_data) -#define video_set_rotation_func(orientation) xdk360_set_orientation(driver.video_data, orientation) -#define video_set_aspect_ratio_func(aspectratio_idx) xdk360_set_aspect_ratio(driver.video_data, aspectratio_idx) +#define video_free_func() xdk360_free(driver.video_data) +#define video_set_rotation_func(rotation) xdk360_set_rotation(driver.video_data, rotation) +#define video_set_aspect_ratio_func(aspectratio_idx) gfx_ctx_set_aspect_ratio(driver.video_data, aspectratio_idx) #define input_init_func() xdk360_input_initialize() #define input_poll_func() xdk360_input_poll(driver.input_data) diff --git a/driver.h b/driver.h index 686e4fd3a6..260e57109e 100644 --- a/driver.h +++ b/driver.h @@ -160,9 +160,6 @@ typedef struct video_driver // Callbacks essentially useless on PC, but useful on consoles where the drivers are used for more stuff. #ifdef RARCH_CONSOLE - void (*set_swap_block_state)(void *data, bool toggle); // Block swapping from being called in ::frame(). - void (*swap)(void *data); // Explicitly swap buffers. Only useful when set_swap_block_state() is set to true. - void (*set_aspect_ratio)(void *data, unsigned aspectratio_idx); // TODO: refactor this properly to float. void (*start)(void); void (*stop)(void); void (*restart)(void); diff --git a/gfx/context/xdk360_ctx.c b/gfx/context/xdk360_ctx.c new file mode 100644 index 0000000000..31d7453d40 --- /dev/null +++ b/gfx/context/xdk360_ctx.c @@ -0,0 +1,135 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#include "../../driver.h" + +#include + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "xdk360_ctx.h" + +#include "../../360/xdk360_video.h" + +void gfx_ctx_set_swap_interval(unsigned interval, bool inited) +{ + (void)inited; + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + + if (interval) + d3d9->d3d_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_ONE); + else + d3d9->d3d_render_device->SetRenderState(D3DRS_PRESENTINTERVAL, D3DPRESENT_INTERVAL_IMMEDIATE); +} + +void gfx_ctx_check_window(bool *quit, + bool *resize, unsigned *width, unsigned *height, unsigned frame_count) +{ + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + *quit = false; + *resize = false; + + if (d3d9->quitting) + *quit = true; + + if (d3d9->should_resize) + *resize = true; +} + +bool gfx_ctx_window_has_focus(void) +{ + return true; +} + +void gfx_ctx_set_resize(unsigned width, unsigned height) { } + +void gfx_ctx_swap_buffers(void) +{ + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL); +} + +bool gfx_ctx_menu_init(void) +{ + return true; +} + +void gfx_ctx_update_window_title(bool reset) { } + +void gfx_ctx_get_video_size(unsigned *width, unsigned *height) +{ + (void)width; + (void)height; +} + +bool gfx_ctx_init(void) +{ + return true; +} + +bool gfx_ctx_set_video_mode( + unsigned width, unsigned height, + unsigned bits, bool fullscreen) +{ + return true; +} + +void gfx_ctx_destroy(void) +{ +} + +void gfx_ctx_input_driver(const input_driver_t **input, void **input_data) { } + +void gfx_ctx_set_filtering(unsigned index, bool set_smooth) { } + +void gfx_ctx_set_fbo(bool enable) +{ + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + + d3d9->fbo_enabled = enable; +} + +/*============================================================ + MISC + TODO: Refactor +============================================================ */ + +void gfx_ctx_set_projection(xdk360_video_t *d3d9, const struct gl_ortho *ortho, bool allow_rotate) { } + +void gfx_ctx_set_aspect_ratio(void *data, unsigned aspectratio_index) +{ + (void)data; + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + + 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; + g_settings.video.force_aspect = false; + d3d9->should_resize = true; +} + +void gfx_ctx_set_overscan(void) +{ + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + if (!d3d9) + return; + + d3d9->should_resize = true; +} + diff --git a/gfx/context/xdk360_ctx.h b/gfx/context/xdk360_ctx.h new file mode 100644 index 0000000000..9e262d1bf7 --- /dev/null +++ b/gfx/context/xdk360_ctx.h @@ -0,0 +1,20 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2012 - Hans-Kristian Arntzen + * Copyright (C) 2011-2012 - Daniel De Matteis + * + * RetroArch is free software: you can redistribute it and/or modify it under the terms + * of the GNU General Public License as published by the Free Software Found- + * ation, either version 3 of the License, or (at your option) any later version. + * + * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with RetroArch. + * If not, see . + */ + +#ifndef _XDK360_CTX_H +#define _XDK360_CTX_H + +#endif diff --git a/gfx/gfx_context.h b/gfx/gfx_context.h index 02bed5a389..cd1ba4cb52 100644 --- a/gfx/gfx_context.h +++ b/gfx/gfx_context.h @@ -28,6 +28,11 @@ #ifdef HAVE_OPENGL #include "gl_common.h" +#define VID_HANDLE gl_t +#endif + +#ifdef HAVE_D3D9 +#define VID_HANDLE xdk360_video_t #endif #ifdef HAVE_SDL @@ -72,8 +77,8 @@ void gfx_ctx_set_filtering(unsigned index, bool set_smooth); void gfx_ctx_get_available_resolutions(void); #endif -#ifdef HAVE_OPENGL -void gfx_ctx_set_projection(gl_t *gl, const struct gl_ortho *ortho, bool allow_rotate); +#if defined(HAVE_OPENGL) || defined(HAVE_D3D9) +void gfx_ctx_set_projection(VID_HANDLE *gl, const struct gl_ortho *ortho, bool allow_rotate); #endif #endif diff --git a/gfx/gl.c b/gfx/gl.c index 4c215ed8c4..a2ed3ccb01 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -1295,9 +1295,6 @@ const video_driver_t video_gl = { "gl", #ifdef RARCH_CONSOLE - NULL, // FIXME: set_swap_block_state - to be removed - NULL, // FIXME: swap - to be removed - NULL, // FIXME: set_aspect_ratio - to be removed gl_start, gl_stop, gl_restart, diff --git a/msvc-360/RetroArch-360/RetroArch-360.vcxproj b/msvc-360/RetroArch-360/RetroArch-360.vcxproj index 88b10da7e3..bd321a251c 100644 --- a/msvc-360/RetroArch-360/RetroArch-360.vcxproj +++ b/msvc-360/RetroArch-360/RetroArch-360.vcxproj @@ -113,7 +113,7 @@ true false MultiThreadedDebug - _DEBUG;_XBOX;PACKAGE_VERSION="0.9.6-rc1";%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL + _DEBUG;_XBOX;PACKAGE_VERSION="0.9.6-rc1";%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL;HAVE_VID_CONTEXT;HAVE_D3D9 Callcap @@ -151,7 +151,7 @@ AnalyzeOnly false MultiThreadedDebug - _DEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;RARCH_CONSOLE;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL + _DEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;RARCH_CONSOLE;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL;HAVE_VID_CONTEXT;HAVE_D3D9 Callcap @@ -190,7 +190,7 @@ Size false MultiThreaded - NDEBUG;_XBOX;PROFILE;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL + NDEBUG;_XBOX;PROFILE;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL;HAVE_VID_CONTEXT;HAVE_D3D9 Callcap @@ -234,7 +234,7 @@ Size false MultiThreaded - NDEBUG;_XBOX;PROFILE;FASTCAP;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL + NDEBUG;_XBOX;PROFILE;FASTCAP;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL;HAVE_VID_CONTEXT;HAVE_D3D9 true @@ -275,7 +275,7 @@ false false MultiThreaded - NDEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE=1;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL + NDEBUG;_XBOX;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;main=rarch_main;RARCH_CONSOLE=1;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL;HAVE_VID_CONTEXT;HAVE_D3D9 true @@ -316,7 +316,7 @@ false false MultiThreaded - NDEBUG;_XBOX;LTCG;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL + NDEBUG;_XBOX;LTCG;%(PreprocessorDefinitions);PACKAGE_VERSION="0.9.6-rc1";_CRT_SECURE_NO_WARNINGS;RARCH_CONSOLE;main=rarch_main;HAVE_CONFIGFILE;HAVE_FILEBROWSER;HAVE_NETPLAY;HAVE_SOCKET_LEGACY;HAVE_ZLIB;HAVE_RARCH_MAIN_WRAP;HAVE_RARCH_EXEC;HAVE_LIBRETRO_MANAGEMENT;D3DCOMPILE_USEVOIDS;HAVE_GRIFFIN;HAVE_HLSL;HAVE_VID_CONTEXT;HAVE_D3D9 true From c1d8bf8beaa6e618ff62d885a1fc6f556d203b6b Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 02:51:34 +0200 Subject: [PATCH 094/103] (360) Fast forwarding mode works again --- 360/xdk360_video.cpp | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 0aecac5f81..3267c2b134 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -542,6 +542,7 @@ static void *xdk360_init(const video_info_t *video, const input_driver_t **input xdk360_set_rotation(d3d9, g_console.screen_orientation); d3d9->fbo_enabled = 1; + d3d9->vsync = video->vsync; return d3d9; } @@ -679,30 +680,11 @@ static bool xdk360_frame(void *data, const void *frame, } if(!d3d9->block_swap) - d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL); + gfx_ctx_swap_buffers(); return true; } -static void xdk360_set_swap_block_swap (void * data, bool toggle) -{ - (void)data; - xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; - d3d9->block_swap = toggle; - - if(toggle) - RARCH_LOG("Swap is set to blocked.\n"); - else - RARCH_LOG("Swap is set to non-blocked.\n"); -} - -static void xdk360_swap (void * data) -{ - (void)data; - xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; - d3d9->d3d_render_device->Present(NULL, NULL, NULL, NULL); -} - static void xdk360_set_nonblock_state(void *data, bool state) { xdk360_video_t *d3d9 = (xdk360_video_t*)data; @@ -744,6 +726,10 @@ static void xdk360_start(void) driver.video_data = xdk360_init(&video_info, NULL, NULL); + xdk360_video_t *d3d9 = (xdk360_video_t*)driver.video_data; + + gfx_ctx_set_swap_interval(d3d9->vsync ? 1 : 0, false); + g_first_msg = true; /* XBox 360 specific font code */ From ca9b6ac0e29739fc8ee2d3d2b499e29bf6256675 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 03:29:07 +0200 Subject: [PATCH 095/103] (360) Turned xdk360_init_fbo static --- 360/xdk360_video.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 3267c2b134..8ce5e0b617 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -401,7 +401,7 @@ static void xdk360_convert_texture_to_as16_srgb( D3DTexture *pTexture ) pTexture->Format.DataFormat = g_MapLinearToSrgbGpuFormat[ (desc.Format & D3DFORMAT_TEXTUREFORMAT_MASK) >> D3DFORMAT_TEXTUREFORMAT_SHIFT ]; } -void xdk360_init_fbo(xdk360_video_t *d3d9) +static void xdk360_init_fbo(xdk360_video_t *d3d9) { if (d3d9->lpTexture_ot) { From 6e8e5ec89be8602d96b104d47750291fc7ac9f11 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 03:45:22 +0200 Subject: [PATCH 096/103] (360) Remove xdk360_video_general.h header file - use uniform IS_TIMER/SET_TIMER macros --- 360/menu.cpp | 8 ++++---- 360/xdk360_input.c | 9 ++++----- 360/xdk360_video.cpp | 4 ++-- 360/xdk360_video.h | 1 - 360/xdk360_video_general.h | 26 -------------------------- console/console_ext.h | 6 ++++++ 6 files changed, 16 insertions(+), 38 deletions(-) delete mode 100644 360/xdk360_video_general.h diff --git a/360/menu.cpp b/360/menu.cpp index b48d307b19..563bdd4f94 100644 --- a/360/menu.cpp +++ b/360/menu.cpp @@ -804,7 +804,7 @@ void menu_loop(void) g_console.menu_enable = !((state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB) && (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB) && (g_console.emulator_initialized) - && IS_TIMER_EXPIRED()); + && IS_TIMER_EXPIRED(d3d9)); g_console.mode_switch = g_console.menu_enable ? MODE_MENU : MODE_EMULATION; switch(g_console.input_loop) @@ -826,7 +826,7 @@ void menu_loop(void) if(g_console.mode_switch == MODE_EMULATION && !g_console.frame_advance_enable) { - SET_TIMER_EXPIRATION(30); + SET_TIMER_EXPIRATION(d3d9, 30); } /* XBox 360 specific font code */ @@ -835,11 +835,11 @@ void menu_loop(void) if (msg) { - if(IS_TIMER_EXPIRED() || g_first_msg) + if(IS_TIMER_EXPIRED(d3d9) || g_first_msg) { xdk360_console_format(msg); g_first_msg = 0; - SET_TIMER_EXPIRATION(30); + SET_TIMER_EXPIRATION(d3d9, 30); } xdk360_console_draw(); diff --git a/360/xdk360_input.c b/360/xdk360_input.c index 5a2ad699f4..705a961d1e 100644 --- a/360/xdk360_input.c +++ b/360/xdk360_input.c @@ -20,9 +20,8 @@ #include "../driver.h" #include "../general.h" #include "../libretro.h" -#include "../console/console_ext_input.h" +#include "../console/console_ext.h" #include "xdk360_input.h" -#include "xdk360_video_general.h" #include "shared.h" #include "menu.h" @@ -178,18 +177,18 @@ static bool xdk360_key_pressed(void *data, int key) case RARCH_REWIND: return ((state.Gamepad.sThumbRY > DEADZONE) && !(state.Gamepad.bRightTrigger > 128)); case RARCH_QUIT_KEY: - if(IS_TIMER_EXPIRED()) + if(IS_TIMER_EXPIRED(d3d9)) { uint32_t left_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_LEFT_THUMB); uint32_t right_thumb_pressed = (state.Gamepad.wButtons & XINPUT_GAMEPAD_RIGHT_THUMB); - g_console.menu_enable = right_thumb_pressed && left_thumb_pressed && IS_TIMER_EXPIRED(); + g_console.menu_enable = right_thumb_pressed && left_thumb_pressed && IS_TIMER_EXPIRED(d3d9); g_console.ingame_menu_enable = right_thumb_pressed && !left_thumb_pressed; if(g_console.menu_enable || (g_console.ingame_menu_enable && !g_console.menu_enable)) { g_console.mode_switch = MODE_MENU; - SET_TIMER_EXPIRATION(30); + SET_TIMER_EXPIRATION(d3d9, 30); retval = g_console.menu_enable; } diff --git a/360/xdk360_video.cpp b/360/xdk360_video.cpp index 8ce5e0b617..c60539b3be 100644 --- a/360/xdk360_video.cpp +++ b/360/xdk360_video.cpp @@ -669,11 +669,11 @@ static bool xdk360_frame(void *data, const void *frame, /* XBox 360 specific font code */ if (msg && !menu_enabled) { - if(IS_TIMER_EXPIRED() || g_first_msg) + if(IS_TIMER_EXPIRED(d3d9) || g_first_msg) { xdk360_console_format(msg); g_first_msg = 0; - SET_TIMER_EXPIRATION(30); + SET_TIMER_EXPIRATION(d3d9, 30); } xdk360_console_draw(); diff --git a/360/xdk360_video.h b/360/xdk360_video.h index 4ed295fb9f..8cca3cc9d1 100644 --- a/360/xdk360_video.h +++ b/360/xdk360_video.h @@ -19,7 +19,6 @@ #include #include "fonts.h" -#include "xdk360_video_general.h" #define DFONT_MAX 4096 #define PRIM_FVF (D3DFVF_XYZRHW | D3DFVF_TEX1) diff --git a/360/xdk360_video_general.h b/360/xdk360_video_general.h deleted file mode 100644 index d5c29f161e..0000000000 --- a/360/xdk360_video_general.h +++ /dev/null @@ -1,26 +0,0 @@ -/* RetroArch - A frontend for libretro. - * Copyright (C) 2010-2012 - Hans-Kristian Arntzen - * Copyright (C) 2011-2012 - Daniel De Matteis - * - * RetroArch is free software: you can redistribute it and/or modify it under the terms - * of the GNU General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with RetroArch. - * If not, see . - */ - -#ifndef _XDK360_VIDEO_GENERAL_H -#define _XDK360_VIDEO_GENERAL_H - -#define LAST_ASPECT_RATIO ASPECT_RATIO_CUSTOM - -#define IS_TIMER_NOT_EXPIRED() (d3d9->frame_count < g_console.timer_expiration_frame_count) -#define IS_TIMER_EXPIRED() (!(IS_TIMER_NOT_EXPIRED())) -#define SET_TIMER_EXPIRATION(value) g_console.timer_expiration_frame_count = d3d9->frame_count + value; - -#endif diff --git a/console/console_ext.h b/console/console_ext.h index d3f3da52d9..3fabce5a31 100644 --- a/console/console_ext.h +++ b/console/console_ext.h @@ -17,6 +17,10 @@ #ifndef CONSOLE_EXT_H__ #define CONSOLE_EXT_H__ +#define IS_TIMER_NOT_EXPIRED(handle) (handle->frame_count < g_console.timer_expiration_frame_count) +#define IS_TIMER_EXPIRED(handle) (!(IS_TIMER_NOT_EXPIRED(handle))) +#define SET_TIMER_EXPIRATION(handle, value) (g_console.timer_expiration_frame_count = handle->frame_count + value) + enum aspect_ratio { ASPECT_RATIO_1_1 = 0, @@ -44,6 +48,8 @@ enum aspect_ratio ASPECT_RATIO_END, }; +#define LAST_ASPECT_RATIO ASPECT_RATIO_CUSTOM + enum rotation { ORIENTATION_NORMAL = 0, From ae4b8563c8ac918e19ecd8346bf972cc485b0690 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 03:46:44 +0200 Subject: [PATCH 097/103] (PS3) Use identical TIMER macros as 360 --- ps3/menu.c | 18 +++++++++--------- ps3/ps3_input.c | 6 +++--- ps3/ps3_video_psgl.h | 4 ---- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/ps3/menu.c b/ps3/menu.c index 072131f05f..faa84d2e9e 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -198,7 +198,7 @@ static void set_delay_speed(unsigned delaymode) } strlcpy(special_action_msg, "", sizeof(special_action_msg)); - SET_TIMER_EXPIRATION(g_console.control_timer_expiration_frame_count, speed); + SET_TIMER_EXPIRATION(gl, speed); } static void browser_update(filebrowser_t * b) @@ -210,7 +210,7 @@ static void browser_update(filebrowser_t * b) diff_state = old_state ^ state; button_was_pressed = old_state & diff_state; - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { set_delay = DELAY_NONE; @@ -889,7 +889,7 @@ static void select_file(uint32_t menu_id) browser_update(&tmpBrowser); - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { if (CTRL_START(button_was_pressed)) filebrowser_reset_start_directory(&tmpBrowser, "/", extensions); @@ -989,7 +989,7 @@ static void select_directory(uint32_t menu_id) browser_update(&tmpBrowser); - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { if (CTRL_START(button_was_pressed)) filebrowser_reset_start_directory(&tmpBrowser, "/","empty"); @@ -1836,7 +1836,7 @@ static void select_setting(menu * menu_obj) diff_state = old_state ^ state; button_was_pressed = old_state & diff_state; - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { set_delay = DELAY_NONE; /* back to ROM menu if CIRCLE is pressed */ @@ -1942,7 +1942,7 @@ static void select_rom(void) browser_update(&browser); - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { if (CTRL_SELECT(button_was_pressed)) { @@ -2054,7 +2054,7 @@ static void ingame_menu(uint32_t menu_id) stuck_in_loop = 1; blocking = 0; - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count) && blocking == false) + if(IS_TIMER_EXPIRED(gl) && blocking == false) { set_delay = DELAY_NONE; @@ -2621,7 +2621,7 @@ void menu_loop(void) } - if(IS_TIMER_EXPIRED(g_console.control_timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { // if we want to force goto the emulation loop, skip this if(g_console.mode_switch != MODE_EMULATION) @@ -2650,7 +2650,7 @@ void menu_loop(void) // press and holding L3 + R3 in the emulation loop (lasts for 30 frame ticks) if(g_console.mode_switch == MODE_EMULATION && !g_console.frame_advance_enable) { - SET_TIMER_EXPIRATION(g_console.timer_expiration_frame_count, 30); + SET_TIMER_EXPIRATION(gl, 30); } gfx_ctx_swap_buffers(); diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index e556d6176a..c75e8b77f0 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -316,18 +316,18 @@ static bool ps3_key_pressed(void *data, int key) case RARCH_REWIND: return CTRL_RSTICK_UP(state[0]) && CTRL_R2(~state[0]); case RARCH_QUIT_KEY: - if(IS_TIMER_EXPIRED(g_console.timer_expiration_frame_count)) + if(IS_TIMER_EXPIRED(gl)) { uint32_t r3_pressed = CTRL_R3(state[0]); uint32_t l3_pressed = CTRL_L3(state[0]); bool retval = false; - g_console.menu_enable = (r3_pressed && l3_pressed && IS_TIMER_EXPIRED(g_console.timer_expiration_frame_count)); + g_console.menu_enable = (r3_pressed && l3_pressed && IS_TIMER_EXPIRED(gl)); g_console.ingame_menu_enable = r3_pressed && !l3_pressed; if(g_console.menu_enable || (g_console.ingame_menu_enable && !g_console.menu_enable)) { g_console.mode_switch = MODE_MENU; - SET_TIMER_EXPIRATION(g_console.control_timer_expiration_frame_count, 30); + SET_TIMER_EXPIRATION(gl, 30); retval = g_console.menu_enable; } diff --git a/ps3/ps3_video_psgl.h b/ps3/ps3_video_psgl.h index e9166e8824..eb4a935ee6 100644 --- a/ps3/ps3_video_psgl.h +++ b/ps3/ps3_video_psgl.h @@ -32,10 +32,6 @@ enum #define MIN_SCALING_FACTOR (1.0f) #define MAX_SCALING_FACTOR (4.0f) -#define IS_TIMER_NOT_EXPIRED(getter) (gl->frame_count < getter) -#define IS_TIMER_EXPIRED(getter) (!(IS_TIMER_NOT_EXPIRED(getter))) -#define SET_TIMER_EXPIRATION(setter, value) setter = gl->frame_count + value; - const char * ps3_get_resolution_label(uint32_t resolution); int ps3_check_resolution(uint32_t resolution_id); void ps3_previous_resolution (void); From 7dccb123f3d15bf1964af56ae8c325d760023337 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 03:53:25 +0200 Subject: [PATCH 098/103] (PS3) Menu speed duration changed to one speed mode --- ps3/menu.c | 42 ++++++++---------------------------------- ps3/shared.h | 2 -- 2 files changed, 8 insertions(+), 36 deletions(-) diff --git a/ps3/menu.c b/ps3/menu.c index faa84d2e9e..4462100eeb 100644 --- a/ps3/menu.c +++ b/ps3/menu.c @@ -219,11 +219,7 @@ static void browser_update(filebrowser_t * b) if(b->currently_selected < b->file_count-1) { FILEBROWSER_INCREMENT_ENTRY_POINTER(b); - - if(g_console.emulator_initialized) - set_delay = DELAY_SMALL; - else - set_delay = DELAY_SMALLEST; + set_delay = DELAY_SMALLEST; } } @@ -232,10 +228,7 @@ static void browser_update(filebrowser_t * b) if(b->currently_selected < b->file_count-1) { FILEBROWSER_INCREMENT_ENTRY_POINTER(b); - if(g_console.emulator_initialized) - set_delay = DELAY_SMALL; - else - set_delay = DELAY_SMALLEST; + set_delay = DELAY_SMALLEST; } } @@ -244,10 +237,7 @@ static void browser_update(filebrowser_t * b) if(b->currently_selected > 0) { FILEBROWSER_DECREMENT_ENTRY_POINTER(b); - if(g_console.emulator_initialized) - set_delay = DELAY_SMALL; - else - set_delay = DELAY_SMALLEST; + set_delay = DELAY_SMALLEST; } } @@ -256,30 +246,20 @@ static void browser_update(filebrowser_t * b) if(b->currently_selected > 0) { FILEBROWSER_DECREMENT_ENTRY_POINTER(b); - if(g_console.emulator_initialized) - set_delay = DELAY_SMALL; - else - set_delay = DELAY_SMALLEST; + set_delay = DELAY_SMALLEST; } } if (CTRL_RIGHT(state)) { b->currently_selected = (MIN(b->currently_selected + 5, b->file_count-1)); - - if(g_console.emulator_initialized) - set_delay = DELAY_MEDIUM; - else - set_delay = DELAY_SMALL; + set_delay = DELAY_SMALL; } if (CTRL_LSTICK_RIGHT(state)) { b->currently_selected = (MIN(b->currently_selected + 5, b->file_count-1)); - if(g_console.emulator_initialized) - set_delay = DELAY_SMALL; - else - set_delay = DELAY_SMALLEST; + set_delay = DELAY_SMALLEST; } if (CTRL_LEFT(state)) @@ -289,10 +269,7 @@ static void browser_update(filebrowser_t * b) else b->currently_selected -= 5; - if(g_console.emulator_initialized) - set_delay = DELAY_MEDIUM; - else - set_delay = DELAY_SMALL; + set_delay = DELAY_SMALL; } if (CTRL_LSTICK_LEFT(state)) @@ -302,10 +279,7 @@ static void browser_update(filebrowser_t * b) else b->currently_selected -= 5; - if(g_console.emulator_initialized) - set_delay = DELAY_SMALL; - else - set_delay = DELAY_SMALLEST; + set_delay = DELAY_SMALLEST; } if (CTRL_R1(state)) diff --git a/ps3/shared.h b/ps3/shared.h index d458a701e3..09b656d3ff 100644 --- a/ps3/shared.h +++ b/ps3/shared.h @@ -73,8 +73,6 @@ enum { #define MENU_ITEM_LAST MENU_ITEM_RETURN_TO_XMB+1 -extern unsigned g_frame_count; - extern char contentInfoPath[MAX_PATH_LENGTH]; extern char usrDirPath[MAX_PATH_LENGTH]; extern char DEFAULT_PRESET_FILE[MAX_PATH_LENGTH]; From 663268be2494e3cd49a5b67f3f594e8f8a26a387 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 04:47:29 +0200 Subject: [PATCH 099/103] (Wii) Remove some obsolete functions --- gfx/gl.c | 6 +++--- wii/video.c | 25 ------------------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/gfx/gl.c b/gfx/gl.c index a2ed3ccb01..37749d4669 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -187,7 +187,7 @@ void gl_shader_use(unsigned index) #endif } -static void gl_shader_deinit(void) +static inline void gl_shader_deinit(void) { #ifdef HAVE_CG gl_cg_deinit(); @@ -198,7 +198,7 @@ static void gl_shader_deinit(void) #endif } -static void gl_shader_set_proj_matrix(void) +static inline void gl_shader_set_proj_matrix(void) { #ifdef HAVE_CG gl_cg_set_proj_matrix(); @@ -209,7 +209,7 @@ static void gl_shader_set_proj_matrix(void) #endif } -static void gl_shader_set_params(unsigned width, unsigned height, +static inline void gl_shader_set_params(unsigned width, unsigned height, unsigned tex_width, unsigned tex_height, unsigned out_width, unsigned out_height, unsigned frame_count, diff --git a/wii/video.c b/wii/video.c index e01f1c7499..338f8b00ff 100644 --- a/wii/video.c +++ b/wii/video.c @@ -275,22 +275,6 @@ static void wii_free(void *data) (void)data; } -static void wii_swap(void * data) -{ - (void)data; - /* TODO */ -} - -static void wii_set_aspect_ratio(void * data, uint32_t aspectratio_index) -{ - (void)data; - - g_settings.video.aspect_ratio = aspectratio_lut[g_console.aspect_ratio_index].value; - g_settings.video.force_aspect = false; - - /* TODO */ -} - static void wii_set_rotation(void * data, uint32_t orientation) { (void)data; @@ -299,12 +283,6 @@ static void wii_set_rotation(void * data, uint32_t orientation) /* TODO */ } -static void wii_set_swap_block_state(void * data, bool toggle) -{ - (void)data; - (void)toggle; -} - const video_driver_t video_wii = { .init = wii_init, .frame = wii_frame, @@ -313,8 +291,5 @@ const video_driver_t video_wii = { .focus = wii_focus, .free = wii_free, .ident = "wii", - .set_swap_block_state = wii_set_swap_block_state, .set_rotation = wii_set_rotation, - .set_aspect_ratio = wii_set_aspect_ratio, - .swap = wii_swap }; From c5735e0aec7f338bc0e4f8b37a82353e6c57548e Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 05:06:25 +0200 Subject: [PATCH 100/103] (360/Wii/PS3) Abstracted input code --- 360/main.c | 3 ++- 360/xdk360_input.c | 6 +----- 360/xdk360_input.h | 5 ++--- ps3/main.c | 5 +++-- ps3/ps3_input.c | 12 ++---------- ps3/ps3_input.h | 4 ---- wii/input.c | 9 +-------- wii/main.c | 4 ++-- 8 files changed, 13 insertions(+), 35 deletions(-) diff --git a/360/main.c b/360/main.c index 582471293f..c010ed7ad3 100644 --- a/360/main.c +++ b/360/main.c @@ -419,7 +419,7 @@ int main(int argc, char *argv[]) init_libretro_sym(); video_xdk360.start(); - xdk360_input_init(); + input_xdk360.init(); rarch_input_set_default_keybind_names_for_emulator(); @@ -454,6 +454,7 @@ begin_shutdown: menu_deinit(); video_xdk360.stop(); + input_xdk360.free(NULL); rarch_exec(); return 0; diff --git a/360/xdk360_input.c b/360/xdk360_input.c index 705a961d1e..ea9a249d6c 100644 --- a/360/xdk360_input.c +++ b/360/xdk360_input.c @@ -70,14 +70,10 @@ static void xdk360_free_input(void *data) } static void* xdk360_input_initialize(void) -{ - return (void*)-1; -} - -void xdk360_input_init(void) { for(unsigned i = 0; i < 4; i++) xdk360_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i); + return (void*)-1; } void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) diff --git a/360/xdk360_input.h b/360/xdk360_input.h index f2756da64e..ae25f017b6 100644 --- a/360/xdk360_input.h +++ b/360/xdk360_input.h @@ -25,11 +25,10 @@ #define XINPUT_GAMEPAD_RSTICK_RIGHT_MASK (2097152) #define XINPUT_GAMEPAD_RSTICK_UP_MASK (4194304) #define XINPUT_GAMEPAD_RSTICK_DOWN_MASK (8388608) -#define XINPUT_GAMEPAD_LEFT_TRIGGER (16777216) +#define XINPUT_GAMEPAD_LEFT_TRIGGER (16777216) #define XINPUT_GAMEPAD_RIGHT_TRIGGER (33554432) -#define DEADZONE (16000) +#define DEADZONE (16000) -extern void xdk360_input_init(void); extern void xdk360_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id); extern void xdk360_input_loop(void); diff --git a/ps3/main.c b/ps3/main.c index a08ccf80c1..c674c262f8 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -510,7 +510,8 @@ int main(int argc, char *argv[]) video_gl.start(); - ps3_input_init(); + input_ps3.init(); + oskutil_init(&g_console.oskutil_handle, 0); rarch_input_set_default_keybind_names_for_emulator(); @@ -559,7 +560,7 @@ begin_shutdown: save_settings(); if(g_console.emulator_initialized) rarch_main_deinit(); - cell_pad_input_deinit(); + input_ps3.free(NULL); video_gl.stop(); diff --git a/ps3/ps3_input.c b/ps3/ps3_input.c index c75e8b77f0..f92dd7fd8d 100644 --- a/ps3/ps3_input.c +++ b/ps3/ps3_input.c @@ -40,11 +40,6 @@ static uint64_t state[MAX_PADS]; static unsigned pads_connected; -void cell_pad_input_deinit(void) -{ - cellPadEnd(); -} - uint32_t cell_pad_input_pads_connected(void) { #if(CELL_SDK_VERSION > 0x340000) @@ -249,18 +244,15 @@ void oskutil_unload(oskutil_params *params) static void ps3_free_input(void *data) { (void)data; + cellPadEnd(); } static void* ps3_input_initialize(void) -{ - return (void*)-1; -} - -void ps3_input_init(void) { cellPadInit(MAX_PADS); for(unsigned i = 0; i < MAX_PADS; i++) ps3_input_map_dpad_to_stick(g_settings.input.dpad_emulation[i], i); + return (void*)-1; } void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id) diff --git a/ps3/ps3_input.h b/ps3/ps3_input.h index 3321b450c8..0935a70cf2 100644 --- a/ps3/ps3_input.h +++ b/ps3/ps3_input.h @@ -121,14 +121,10 @@ typedef uint64_t cell_input_state_t; -int cell_pad_input_init(void); -void cell_pad_input_deinit(void); - uint32_t cell_pad_input_pads_connected(void); cell_input_state_t cell_pad_input_poll_device(uint32_t id); -void ps3_input_init(void); void ps3_input_map_dpad_to_stick(uint32_t map_dpad_enum, uint32_t controller_id); typedef struct diff --git a/wii/input.c b/wii/input.c index 9255ef518c..4ba47f8263 100644 --- a/wii/input.c +++ b/wii/input.c @@ -55,7 +55,7 @@ static void reset_callback(void) g_quit = true; } -void wii_input_init(void) +static void *wii_input_initialize(void) { PAD_Init(); #ifdef HW_RVL @@ -63,13 +63,6 @@ void wii_input_init(void) #endif SYS_SetResetCallback(reset_callback); SYS_SetPowerCallback(reset_callback); -} - -void wii_input_deinit(void) -{} - -static void *wii_input_initialize(void) -{ return (void*)-1; } diff --git a/wii/main.c b/wii/main.c index ca344624c5..9a4fb96bbc 100644 --- a/wii/main.c +++ b/wii/main.c @@ -138,7 +138,7 @@ int main(void) rarch_assert(g_extern.msg_queue = msg_queue_new(8)); wii_video_init(); - wii_input_init(); + input_wii.init(); rgui_handle_t *rgui = rgui_init("sd:/", menu_framebuf, RGUI_WIDTH * sizeof(uint16_t), @@ -163,8 +163,8 @@ int main(void) if(g_console.emulator_initialized) rarch_main_deinit(); - wii_input_deinit(); wii_video_deinit(); + input_wii.free(NULL); #ifdef HAVE_FILE_LOGGER fclose(log_fp); From dac3713454d5849185d1c8ee86e325e1d3846c3d Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 05:19:04 +0200 Subject: [PATCH 101/103] (Griffin) Ifdef changes / annotations --- console/griffin/griffin.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 4194037b40..4f63d5f5c7 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -43,7 +43,7 @@ CONFIG FILE /*============================================================ -VIDEO +VIDEO CONTEXT ============================================================ */ #ifdef HAVE_VID_CONTEXT @@ -56,21 +56,35 @@ VIDEO #endif +/*============================================================ +VIDEO SHADERS +============================================================ */ + #ifdef HAVE_CG #include "../../gfx/shader_cg.c" #endif -#ifdef HAVE_OPENGL -#include "../../gfx/gl.c" -#endif - #ifdef HAVE_HLSL #include "../../gfx/shader_hlsl.c" #endif +/*============================================================ +VIDEO IMAGE +============================================================ */ + #if defined(__CELLOS_LV2__) #include "../../ps3/image.c" -#elif defined(_XBOX) +#endif + +/*============================================================ +VIDEO DRIVER +============================================================ */ + +#ifdef HAVE_OPENGL +#include "../../gfx/gl.c" +#endif + +#if defined(_XBOX) #include "../../360/xdk360_video.cpp" #elif defined(GEKKO) #include "../../wii/video.c" @@ -100,7 +114,7 @@ INPUT #endif /*============================================================ -SNES STATE +STATE TRACKER ============================================================ */ #include "../../gfx/state_tracker.c" @@ -203,7 +217,7 @@ THREAD /*============================================================ NETPLAY ============================================================ */ -#ifndef GEKKO +#ifdef HAVE_NETPLAY #include "../../netplay.c" #endif From 663bab2c14dfe718121851a392bfce70b2c2bae3 Mon Sep 17 00:00:00 2001 From: Twinaphex Date: Mon, 28 May 2012 05:21:19 +0200 Subject: [PATCH 102/103] (Griffin) ifdef include config_file.c with ifdef HAVE_CONFIGFILE --- console/griffin/griffin.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/console/griffin/griffin.c b/console/griffin/griffin.c index 4f63d5f5c7..f2f8e4d0ce 100644 --- a/console/griffin/griffin.c +++ b/console/griffin/griffin.c @@ -36,12 +36,13 @@ CONFIG FILE #undef __RARCH_MSVC_COMPAT_H #undef strcasecmp #endif + +#ifdef HAVE_CONFIGFILE #include "../../conf/config_file.c" +#endif #include "func_hooks.h" - - /*============================================================ VIDEO CONTEXT ============================================================ */ From 232cf0d1224d219cb496316ee95c55bdde92ab25 Mon Sep 17 00:00:00 2001 From: TwinAphex51224 Date: Mon, 28 May 2012 05:42:00 +0200 Subject: [PATCH 103/103] (360) Only print char * messages, not wchar --- 360/fonts.cpp | 25 ------------------------- 360/fonts.h | 1 - 2 files changed, 26 deletions(-) diff --git a/360/fonts.cpp b/360/fonts.cpp index cd3f3a809d..2cd55da47c 100644 --- a/360/fonts.cpp +++ b/360/fonts.cpp @@ -217,31 +217,6 @@ void xdk360_console_format(_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ) va_end( pArgList ); } -void xdk360_console_format_w(_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ) -{ - video_console.m_nCurLine = 0; - video_console.m_cCurLineLength = 0; - memset( video_console.m_Buffer, 0, video_console.m_cScreenHeightVirtual - * ( video_console.m_cScreenWidth + 1 ) * sizeof( wchar_t ) ); - - va_list pArgList; - va_start( pArgList, wstrFormat ); - - // Count the required length of the string - unsigned long dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1; // +1 = null terminator - wchar_t * strMessage = ( wchar_t * )_malloca( dwStrLen * sizeof( wchar_t ) ); - vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList ); - - // Output the string to the console - unsigned long uStringLength = wcslen( strMessage ); - for( unsigned long i = 0; i < uStringLength; i++ ) - xdk360_console_add( strMessage[i] ); - - _freea( strMessage ); - - va_end( pArgList ); -} - #define CALCFONTFILEHEADERSIZE(x) ( sizeof(unsigned long) + (sizeof(float)* 4) + sizeof(unsigned short) + (sizeof(wchar_t)*(x)) ) #define FONTFILEVERSION 5 diff --git a/360/fonts.h b/360/fonts.h index 400af06ba6..033a464cf4 100644 --- a/360/fonts.h +++ b/360/fonts.h @@ -103,7 +103,6 @@ typedef struct HRESULT xdk360_console_init ( LPCSTR strFontFileName, D3DCOLOR colBackColor, D3DCOLOR colTextColor); void xdk360_console_deinit (void); void xdk360_console_format (_In_z_ _Printf_format_string_ LPCSTR strFormat, ... ); -void xdk360_console_format_w (_In_z_ _Printf_format_string_ LPCWSTR wstrFormat, ... ); void xdk360_console_draw (void); HRESULT xdk360_video_font_init(xdk360_video_font_t * font, const char * strFontFileName);