From a8e74f0aa2f0a4a2c81ddf6a0de128ae43f802c6 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 2 Aug 2016 02:27:05 +0200 Subject: [PATCH] (GL) Start moving renderchain code over to separate files --- Makefile.common | 1 + gfx/drivers/gl.c | 109 +--------- .../gl_renderchains/render_chain_driver.h | 54 +++++ .../gl_renderchains/render_chain_gl_legacy.c | 188 ++++++++++++++++++ griffin/griffin.c | 1 + 5 files changed, 247 insertions(+), 106 deletions(-) create mode 100644 gfx/drivers/gl_renderchains/render_chain_driver.h create mode 100644 gfx/drivers/gl_renderchains/render_chain_gl_legacy.c diff --git a/Makefile.common b/Makefile.common index 2e888a9474..c33b4bbe2a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -695,6 +695,7 @@ endif ifeq ($(HAVE_GL_CONTEXT), 1) DEFINES += -DHAVE_OPENGL -DHAVE_GLSL OBJ += gfx/drivers/gl.o \ + gfx/drivers/gl_renderchains/render_chain_gl_legacy.o \ gfx/common/gl_common.o \ gfx/drivers_font/gl_raster_font.o \ libretro-common/glsym/rglgen.o diff --git a/gfx/drivers/gl.c b/gfx/drivers/gl.c index 451a59dc32..29b3acec99 100644 --- a/gfx/drivers/gl.c +++ b/gfx/drivers/gl.c @@ -33,6 +33,8 @@ #include #include +#include "gl_renderchains/render_chain_driver.h" + #include "../../driver.h" #include "../../record/record_driver.h" #include "../../performance_counters.h" @@ -784,51 +786,6 @@ static uintptr_t gl_get_current_framebuffer(void *data) * When width/height changes or window sizes change, * we have to recalculate geometry of our FBO. */ - -static void gl_renderchain_convert_geometry(gl_t *gl, - struct video_fbo_rect *fbo_rect, - struct gfx_fbo_scale *fbo_scale, - unsigned last_width, unsigned last_max_width, - unsigned last_height, unsigned last_max_height, - unsigned vp_width, unsigned vp_height) -{ - switch (fbo_scale->type_x) - { - case RARCH_SCALE_INPUT: - fbo_rect->img_width = fbo_scale->scale_x * last_width; - fbo_rect->max_img_width = last_max_width * fbo_scale->scale_x; - break; - - case RARCH_SCALE_ABSOLUTE: - fbo_rect->img_width = fbo_rect->max_img_width = - fbo_scale->abs_x; - break; - - case RARCH_SCALE_VIEWPORT: - fbo_rect->img_width = fbo_rect->max_img_width = - fbo_scale->scale_x * vp_width; - break; - } - - switch (fbo_scale->type_y) - { - case RARCH_SCALE_INPUT: - fbo_rect->img_height = last_height * fbo_scale->scale_y; - fbo_rect->max_img_height = last_max_height * fbo_scale->scale_y; - break; - - case RARCH_SCALE_ABSOLUTE: - fbo_rect->img_height = fbo_scale->abs_y; - fbo_rect->max_img_height = fbo_scale->abs_y; - break; - - case RARCH_SCALE_VIEWPORT: - fbo_rect->img_height = fbo_rect->max_img_height = - fbo_scale->scale_y * vp_height; - break; - } -} - static void gl_recompute_pass_sizes(gl_t *gl, unsigned width, unsigned height, unsigned vp_width, unsigned vp_height) @@ -1926,30 +1883,6 @@ static INLINE void gl_copy_frame(gl_t *gl, const void *frame, performance_counter_stop(©_frame); } -static INLINE void gl_renderchain_bind_prev_texture( - gl_t *gl, - const struct video_tex_info *tex_info) -{ - memmove(gl->prev_info + 1, gl->prev_info, - sizeof(*tex_info) * (gl->textures - 1)); - memcpy(&gl->prev_info[0], tex_info, - sizeof(*tex_info)); - -#ifdef HAVE_FBO - /* Implement feedback by swapping out FBO/textures - * for FBO pass #N and feedbacks. */ - if (gl->fbo_feedback_enable) - { - GLuint tmp_fbo = gl->fbo_feedback; - GLuint tmp_tex = gl->fbo_feedback_texture; - gl->fbo_feedback = gl->fbo[gl->fbo_feedback_pass]; - gl->fbo_feedback_texture = gl->fbo_texture[gl->fbo_feedback_pass]; - gl->fbo[gl->fbo_feedback_pass] = tmp_fbo; - gl->fbo_texture[gl->fbo_feedback_pass] = tmp_tex; - } -#endif -} - static INLINE void gl_set_shader_viewport(gl_t *gl, unsigned idx) { unsigned width, height; @@ -1965,7 +1898,7 @@ static INLINE void gl_set_shader_viewport(gl_t *gl, unsigned idx) gl_set_viewport(gl, width, height, false, true); } -static void gl_load_texture_data( +void gl_load_texture_data( uint32_t id_data, enum gfx_wrap_type wrap_type, enum texture_filter_type filter_type, @@ -3638,42 +3571,6 @@ unsigned *height_p, size_t *pitch_p) } #endif -static bool gl_renderchain_add_lut(const struct video_shader *shader, - unsigned i, GLuint *textures_lut) -{ - struct texture_image img = {0}; - enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR; - - RARCH_LOG("Loading texture image from: \"%s\" ...\n", - shader->lut[i].path); - - if (!image_texture_load(&img, shader->lut[i].path)) - { - RARCH_ERR("Failed to load texture image from: \"%s\"\n", - shader->lut[i].path); - return false; - } - - if (shader->lut[i].filter == RARCH_FILTER_NEAREST) - filter_type = TEXTURE_FILTER_NEAREST; - - if (shader->lut[i].mipmap) - { - if (filter_type == TEXTURE_FILTER_NEAREST) - filter_type = TEXTURE_FILTER_MIPMAP_NEAREST; - else - filter_type = TEXTURE_FILTER_MIPMAP_LINEAR; - } - - gl_load_texture_data(textures_lut[i], - shader->lut[i].wrap, - filter_type, 4, - img.width, img.height, - img.pixels, sizeof(uint32_t)); - image_texture_free(&img); - - return true; -} bool gl_load_luts(const struct video_shader *shader, GLuint *textures_lut) diff --git a/gfx/drivers/gl_renderchains/render_chain_driver.h b/gfx/drivers/gl_renderchains/render_chain_driver.h new file mode 100644 index 0000000000..abfd9e96d1 --- /dev/null +++ b/gfx/drivers/gl_renderchains/render_chain_driver.h @@ -0,0 +1,54 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2016 - 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 __GL_RENDER_CHAIN_H +#define __GL_RENDER_CHAIN_H + +#include +#include + +#include "../../video_driver.h" +#include "../../video_shader_parse.h" +#include "../../common/gl_common.h" + +RETRO_BEGIN_DECLS + +void gl_renderchain_convert_geometry(gl_t *gl, + struct video_fbo_rect *fbo_rect, + struct gfx_fbo_scale *fbo_scale, + unsigned last_width, unsigned last_max_width, + unsigned last_height, unsigned last_max_height, + unsigned vp_width, unsigned vp_height); + +void gl_renderchain_bind_prev_texture( + gl_t *gl, + const struct video_tex_info *tex_info); + +bool gl_renderchain_add_lut(const struct video_shader *shader, + unsigned i, GLuint *textures_lut); + +void gl_load_texture_data( + uint32_t id_data, + enum gfx_wrap_type wrap_type, + enum texture_filter_type filter_type, + unsigned alignment, + unsigned width, unsigned height, + const void *frame, unsigned base_size); + +RETRO_END_DECLS + +#endif + diff --git a/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c b/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c new file mode 100644 index 0000000000..8a7020153d --- /dev/null +++ b/gfx/drivers/gl_renderchains/render_chain_gl_legacy.c @@ -0,0 +1,188 @@ +/* RetroArch - A frontend for libretro. + * Copyright (C) 2010-2014 - Hans-Kristian Arntzen + * Copyright (C) 2011-2016 - Daniel De Matteis + * Copyright (C) 2012-2015 - Michael Lelli + * + * 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 . + */ + +#ifdef _MSC_VER +#pragma comment(lib, "opengl32") +#endif + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../../../driver.h" +#include "../../../record/record_driver.h" +#include "../../../performance_counters.h" + +#include "../../../general.h" +#include "../../../retroarch.h" +#include "../../../verbosity.h" +#include "../../common/gl_common.h" + +#include "render_chain_driver.h" + +#ifdef HAVE_THREADS +#include "../../video_thread_wrapper.h" +#endif + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "../../font_driver.h" +#include "../../video_context_driver.h" +#include "../../video_frame.h" + +#ifdef HAVE_GLSL +#include "../../drivers_shader/shader_glsl.h" +#endif + +#ifdef GL_DEBUG +#include +#endif + +#ifdef HAVE_MENU +#include "../../../menu/menu_driver.h" +#endif + +#if defined(_WIN32) && !defined(_XBOX) +#include "../../common/win32_common.h" +#endif + +#include "../../video_shader_driver.h" + +#ifndef GL_SYNC_GPU_COMMANDS_COMPLETE +#define GL_SYNC_GPU_COMMANDS_COMPLETE 0x9117 +#endif + +#ifndef GL_SYNC_FLUSH_COMMANDS_BIT +#define GL_SYNC_FLUSH_COMMANDS_BIT 0x00000001 +#endif + +void gl_renderchain_convert_geometry(gl_t *gl, + struct video_fbo_rect *fbo_rect, + struct gfx_fbo_scale *fbo_scale, + unsigned last_width, unsigned last_max_width, + unsigned last_height, unsigned last_max_height, + unsigned vp_width, unsigned vp_height) +{ + switch (fbo_scale->type_x) + { + case RARCH_SCALE_INPUT: + fbo_rect->img_width = fbo_scale->scale_x * last_width; + fbo_rect->max_img_width = last_max_width * fbo_scale->scale_x; + break; + + case RARCH_SCALE_ABSOLUTE: + fbo_rect->img_width = fbo_rect->max_img_width = + fbo_scale->abs_x; + break; + + case RARCH_SCALE_VIEWPORT: + fbo_rect->img_width = fbo_rect->max_img_width = + fbo_scale->scale_x * vp_width; + break; + } + + switch (fbo_scale->type_y) + { + case RARCH_SCALE_INPUT: + fbo_rect->img_height = last_height * fbo_scale->scale_y; + fbo_rect->max_img_height = last_max_height * fbo_scale->scale_y; + break; + + case RARCH_SCALE_ABSOLUTE: + fbo_rect->img_height = fbo_scale->abs_y; + fbo_rect->max_img_height = fbo_scale->abs_y; + break; + + case RARCH_SCALE_VIEWPORT: + fbo_rect->img_height = fbo_rect->max_img_height = + fbo_scale->scale_y * vp_height; + break; + } +} + +void gl_renderchain_bind_prev_texture( + gl_t *gl, + const struct video_tex_info *tex_info) +{ + memmove(gl->prev_info + 1, gl->prev_info, + sizeof(*tex_info) * (gl->textures - 1)); + memcpy(&gl->prev_info[0], tex_info, + sizeof(*tex_info)); + +#ifdef HAVE_FBO + /* Implement feedback by swapping out FBO/textures + * for FBO pass #N and feedbacks. */ + if (gl->fbo_feedback_enable) + { + GLuint tmp_fbo = gl->fbo_feedback; + GLuint tmp_tex = gl->fbo_feedback_texture; + gl->fbo_feedback = gl->fbo[gl->fbo_feedback_pass]; + gl->fbo_feedback_texture = gl->fbo_texture[gl->fbo_feedback_pass]; + gl->fbo[gl->fbo_feedback_pass] = tmp_fbo; + gl->fbo_texture[gl->fbo_feedback_pass] = tmp_tex; + } +#endif +} + +bool gl_renderchain_add_lut(const struct video_shader *shader, + unsigned i, GLuint *textures_lut) +{ + struct texture_image img = {0}; + enum texture_filter_type filter_type = TEXTURE_FILTER_LINEAR; + + RARCH_LOG("Loading texture image from: \"%s\" ...\n", + shader->lut[i].path); + + if (!image_texture_load(&img, shader->lut[i].path)) + { + RARCH_ERR("Failed to load texture image from: \"%s\"\n", + shader->lut[i].path); + return false; + } + + if (shader->lut[i].filter == RARCH_FILTER_NEAREST) + filter_type = TEXTURE_FILTER_NEAREST; + + if (shader->lut[i].mipmap) + { + if (filter_type == TEXTURE_FILTER_NEAREST) + filter_type = TEXTURE_FILTER_MIPMAP_NEAREST; + else + filter_type = TEXTURE_FILTER_MIPMAP_LINEAR; + } + + gl_load_texture_data(textures_lut[i], + shader->lut[i].wrap, + filter_type, 4, + img.width, img.height, + img.pixels, sizeof(uint32_t)); + image_texture_free(&img); + + return true; +} diff --git a/griffin/griffin.c b/griffin/griffin.c index 92e3385c11..332e94234f 100644 --- a/griffin/griffin.c +++ b/griffin/griffin.c @@ -288,6 +288,7 @@ VIDEO DRIVER #ifdef HAVE_OPENGL #include "../gfx/common/gl_common.c" #include "../gfx/drivers/gl.c" +#include "../gfx/drivers/gl_renderchains/render_chain_gl_legacy.c" #ifndef HAVE_PSGL #include "../libretro-common/glsym/rglgen.c"