Skip to content

Commit

Permalink
(OpenGL) Supporto shaders Retroarch
Browse files Browse the repository at this point in the history
Riscritto da zero l'engine OpenGL per supportare pienamente shader
multi-pass e il formato meta-shader utilizzato da Retroarch.
  • Loading branch information
punesemu committed Feb 27, 2016
1 parent 5f84fa5 commit 3a18faf
Show file tree
Hide file tree
Showing 109 changed files with 19,139 additions and 2,185 deletions.
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bin_PROGRAMS = punes

punes_SOURCES = \
core/main.c \
core/matrix.c \
gui/application.cpp \
core/palette.c \
$(ico_stuff)
Expand Down
1 change: 1 addition & 0 deletions src/core/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ libcore_a_SOURCES = \
main.h \
mappers.c \
mappers.h \
matrix.h \
mem_map.h \
miniz.h \
overscan.c \
Expand Down
2 changes: 1 addition & 1 deletion src/core/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ typedef struct {
BYTE render;
BYTE scale;
BYTE fullscreen;
BYTE filter;
DBWORD filter;
BYTE ntsc_format;
BYTE palette;
BYTE disable_swap_emphasis_pal;
Expand Down
79 changes: 64 additions & 15 deletions src/core/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,67 @@ enum filters_type {
HQ3X,
HQ4X,
NTSC_FILTER,
/* shaders */
PHOSPHOR,
SCANLINE,
DBL,
CRT_CURVE,
CRT_NO_CURVE,
PHOSPHOR2,
DARK_ROOM,
/* shaders end */
XBRZ2X,
XBRZ3X,
XBRZ4X
XBRZ4X,
FUTURE_USE0,
FUTURE_USE1,
FUTURE_USE2,
FUTURE_USE3,
FUTURE_USE4,
FUTURE_USE5,
FUTURE_USE6,
FUTURE_USE7,
FUTURE_USE8,
FUTURE_USE9,
FUTURE_USE10,
FUTURE_USE11,
FUTURE_USE12,
FUTURE_USE13,
FUTURE_USE14,
/* shaders */
FLTSHDSTART,
sh_anti_aliasing_advanced_aa = FLTSHDSTART,
sh_anti_aliasing_fx_aa,
sh_anti_aliasing_fxaa_edge_detect,
sh_cgp_tvout_tvout_ntsc_2phase_composite,
sh_cgp_tvout_tvout_ntsc_256px_svideo,
sh_cgp_2xbr_crt_hyllian,
sh_cgp_2xbr_jinc2_sharper_hybrid,
sh_crt_gtuv50,
sh_crt_4xbr_hybrid_crt,
sh_crt_crt_caligari,
sh_crt_crt_cgwg_fast,
sh_crt_crt_easymode,
sh_crt_crt_easymode_halation,
sh_crt_crt_geom,
sh_crt_crtglow_gauss,
sh_crt_crtglow_gauss_ntsc_3phase,
sh_crt_crt_hyllian,
sh_crt_crt_lottes,
sh_crt_crt_reverse_aa,
sh_crt_dotmask,
sh_eagle_super_eagle,
sh_hunterk_borders_1080p_bigblur,
sh_hunterk_borders_1080p_color_grid,
sh_hunterk_borders_1080p_mudlord,
sh_hunterk_borders_1080p_shiny_iterations,
sh_hunterk_borders_1080p_snow,
sh_hunterk_borders_1080p_voronoi,
sh_hunterk_borders_1080p_water,
sh_hunterk_handheld_nds,
sh_hunterk_hqx_hq3x,
sh_hunterk_motionblur_motionblur_simple,
sh_motionblur_feedback,
sh_mudlord_emboss,
sh_mudlord_mud_mudlord,
sh_mudlord_noise_mudlord,
sh_mudlord_oldtv,
sh_waterpaint_water,

sh_test,
FLTSHDSTOP = sh_waterpaint_water
/* shaders end */
};
enum overcan_type { OSCAN_OFF, OSCAN_ON, OSCAN_DEFAULT, OSCAN_DEFAULT_OFF, OSCAN_DEFAULT_ON };
enum gfx_info_type { CURRENT, NO_OVERSCAN, MONITOR, VIDEO_MODE };
Expand All @@ -72,7 +121,7 @@ enum no_change { NO_CHANGE = 255 };
#if defined (SDL)
#include <SDL.h>

enum render_type { RENDER_SOFTWARE, RENDER_OPENGL, RENDER_GLSL };
enum render_type { RENDER_SOFTWARE, RENDER_GLSL };
#if defined (__WIN32__)
enum sdl_win_event_type {
SDLWIN_NONE,
Expand All @@ -86,7 +135,7 @@ enum sdl_win_event_type {
SDLWIN_VSYNC
};

EXTERNC struct {
EXTERNC struct _sdlwe {
int event;
int arg;
} sdlwe;
Expand All @@ -102,7 +151,7 @@ EXTERNC int (*flip)(SDL_Surface *surface);
#elif defined (D3D9)
enum render_type { RENDER_SOFTWARE, RENDER_HLSL };

typedef struct {
typedef struct _texcoords {
float l, r;
float t, b;
} _texcoords;
Expand Down Expand Up @@ -136,8 +185,8 @@ EXTERNC struct _gfx {

EXTERNC BYTE gfx_init(void);
EXTERNC void gfx_set_render(BYTE render);
EXTERNC void gfx_set_screen(BYTE scale, BYTE filter, BYTE fullscreen, BYTE palette, BYTE force_scale,
BYTE force_palette);
EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, BYTE fullscreen, BYTE palette,
BYTE force_scale, BYTE force_palette);

EXTERNC void gfx_draw_screen(BYTE forced);
EXTERNC void gfx_quit(void);
Expand Down
36 changes: 9 additions & 27 deletions src/core/gfx_functions_inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ static void INLINE gfx_VSYNC(void);
static void INLINE gfx_SWITCH_RENDERING(void) {
#if defined (SDL)
sdl_wid();
opengl_effect_change(opengl.rotation);
gfx_reset_video();
#endif
gfx_set_screen(NO_CHANGE, NO_CHANGE, NO_CHANGE, NO_CHANGE, TRUE, FALSE);
Expand Down Expand Up @@ -68,27 +67,6 @@ static void INLINE gfx_FILTER(int filter) {
case NO_FILTER:
gfx_set_screen(NO_CHANGE, NO_FILTER, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case PHOSPHOR:
gfx_set_screen(NO_CHANGE, PHOSPHOR, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case PHOSPHOR2:
gfx_set_screen(NO_CHANGE, PHOSPHOR2, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case SCANLINE:
gfx_set_screen(NO_CHANGE, SCANLINE, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case DBL:
gfx_set_screen(NO_CHANGE, DBL, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case DARK_ROOM:
gfx_set_screen(NO_CHANGE, DARK_ROOM, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case CRT_CURVE:
gfx_set_screen(NO_CHANGE, CRT_CURVE, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case CRT_NO_CURVE:
gfx_set_screen(NO_CHANGE, CRT_NO_CURVE, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case SCALE2X:
gfx_set_screen(X2, SCALE2X, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
Expand All @@ -107,6 +85,12 @@ static void INLINE gfx_FILTER(int filter) {
case HQ4X:
gfx_set_screen(X4, HQ4X, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case NTSC_FILTER:
gfx_set_screen(NO_CHANGE, NTSC_FILTER, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
if (cfg->filter == NTSC_FILTER) {
ntsc_set(cfg->ntsc_format, 0, 0, (BYTE *) palette_RGB, 0);
}
break;
case XBRZ2X:
gfx_set_screen(X2, XBRZ2X, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
Expand All @@ -116,11 +100,9 @@ static void INLINE gfx_FILTER(int filter) {
case XBRZ4X:
gfx_set_screen(X4, XBRZ4X, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
case NTSC_FILTER:
gfx_set_screen(NO_CHANGE, NTSC_FILTER, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
if (cfg->filter == NTSC_FILTER) {
ntsc_set(cfg->ntsc_format, 0, 0, (BYTE *) palette_RGB, 0);
}
default:
// shaders
gfx_set_screen(NO_CHANGE, filter, NO_CHANGE, NO_CHANGE, FALSE, FALSE);
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ BYTE input_rd_reg_zapper(BYTE openbus, WORD **screen_index, BYTE nport) {
if (!mouse.right) {
#if defined (SDL)
if (gfx.opengl) {
int l = (int) opengl.quadcoords.l;
int b = (int) opengl.quadcoords.b;
int l = (int) opengl.vp->x;
int b = (int) opengl.vp->y;

gx -= l;
gy -= b;
Expand Down
72 changes: 72 additions & 0 deletions src/core/matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (matrix.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Copyright (C) 2010-2016 Fabio Cavallo (aka FHorse)
*
* This program 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 Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <string.h>
#include "matrix.h"

// Sets mat to an identity matrix
void matrix_4x4_identity(_math_matrix_4x4 *mat) {
int i;

memset(mat, 0, sizeof(*mat));

for (i = 0; i < 4; i++) {
MAT_ELEM_4X4(*mat, i, i) = 1.0f;
}
}
// Creates an orthographic projection matrix.
void matrix_4x4_ortho(_math_matrix_4x4 *mat, float left, float right, float bottom, float top,
float znear, float zfar) {
float tx, ty, tz;

matrix_4x4_identity(mat);

tx = -(right + left) / (right - left);
ty = -(top + bottom) / (top - bottom);
tz = -(zfar + znear) / (zfar - znear);

MAT_ELEM_4X4(*mat, 0, 0) = 2.0f / (right - left);
MAT_ELEM_4X4(*mat, 1, 1) = 2.0f / (top - bottom);
MAT_ELEM_4X4(*mat, 2, 2) = -2.0f / (zfar - znear);
MAT_ELEM_4X4(*mat, 0, 3) = tx;
MAT_ELEM_4X4(*mat, 1, 3) = ty;
MAT_ELEM_4X4(*mat, 2, 3) = tz;
}


53 changes: 53 additions & 0 deletions src/core/matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* Copyright (C) 2010-2015 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (matrix.c).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* Copyright (C) 2010-2016 Fabio Cavallo (aka FHorse)
*
* This program 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 Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#ifndef MATRIX_H_
#define MATRIX_H_

#define MAT_ELEM_4X4(mat, r, c) ((mat).data[4 * (c) + (r)])

typedef struct {
float data[16];
} _math_matrix_4x4;

void matrix_4x4_identity(_math_matrix_4x4 *mat);
void matrix_4x4_ortho(_math_matrix_4x4 *mat, float left, float right, float bottom, float top,
float znear, float zfar);

#endif /* MATRIX_H_ */
2 changes: 2 additions & 0 deletions src/gui/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ BUILT_SOURCES += \
noinst_LIBRARIES = libgui.a
libgui_a_SOURCES = \
application.hh \
cgp.cpp \
cgp.h \
cheatObject.cpp \
cheatObject.hpp \
dlgApuChannels.cpp \
Expand Down
Loading

0 comments on commit 3a18faf

Please sign in to comment.