2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2012-01-08 00:08:18 +00:00
|
|
|
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
|
2011-01-05 16:22:12 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2011-01-05 16:22:12 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2011-01-05 16:22:12 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2011-01-05 16:22:12 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-11-14 20:01:40 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma comment( lib, "cg" )
|
|
|
|
#pragma comment( lib, "cggl" )
|
|
|
|
#endif
|
|
|
|
|
2011-01-05 16:22:12 +00:00
|
|
|
#include "shader_cg.h"
|
|
|
|
#include <Cg/cg.h>
|
|
|
|
#include <Cg/cgGL.h>
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../general.h"
|
2011-03-06 18:56:35 +00:00
|
|
|
#include <string.h>
|
2012-03-16 22:31:26 +00:00
|
|
|
#include "../compat/strl.h"
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../conf/config_file.h"
|
2011-05-22 16:48:43 +00:00
|
|
|
#include "image.h"
|
2011-11-30 17:31:09 +00:00
|
|
|
#include "../dynamic.h"
|
2012-03-16 22:31:26 +00:00
|
|
|
#include "../compat/posix_string.h"
|
2011-05-27 00:25:26 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIGFILE
|
2012-04-07 10:17:40 +00:00
|
|
|
#include "state_tracker.h"
|
2011-05-27 00:25:26 +00:00
|
|
|
#endif
|
2011-01-05 16:22:12 +00:00
|
|
|
|
2012-09-27 15:30:28 +00:00
|
|
|
//#define RARCH_CG_DEBUG
|
2011-05-25 22:23:36 +00:00
|
|
|
|
2011-01-22 23:48:47 +00:00
|
|
|
// Used when we call deactivate() since just unbinding the program didn't seem to work... :(
|
2011-11-02 18:31:36 +00:00
|
|
|
static const char *stock_cg_program =
|
2011-01-22 23:48:47 +00:00
|
|
|
"void main_vertex"
|
|
|
|
"("
|
2012-01-25 20:56:21 +00:00
|
|
|
" float4 position : POSITION,"
|
2011-01-22 23:48:47 +00:00
|
|
|
" float2 texCoord : TEXCOORD0,"
|
2011-09-05 15:00:28 +00:00
|
|
|
" float4 color : COLOR,"
|
2011-01-22 23:48:47 +00:00
|
|
|
""
|
|
|
|
" uniform float4x4 modelViewProj,"
|
|
|
|
""
|
|
|
|
" out float4 oPosition : POSITION,"
|
2011-09-05 15:00:28 +00:00
|
|
|
" out float2 otexCoord : TEXCOORD0,"
|
|
|
|
" out float4 oColor : COLOR"
|
2011-01-22 23:48:47 +00:00
|
|
|
")"
|
|
|
|
"{"
|
|
|
|
" oPosition = mul(modelViewProj, position);"
|
|
|
|
" otexCoord = texCoord;"
|
2011-09-05 15:00:28 +00:00
|
|
|
" oColor = color;"
|
2011-01-22 23:48:47 +00:00
|
|
|
"}"
|
|
|
|
""
|
2011-09-05 15:00:28 +00:00
|
|
|
"float4 main_fragment(in float4 color : COLOR, float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR"
|
2011-01-22 23:48:47 +00:00
|
|
|
"{"
|
2011-09-05 15:00:28 +00:00
|
|
|
" return color * tex2D(s0, tex);"
|
2011-01-22 23:48:47 +00:00
|
|
|
"}";
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
static char *menu_cg_program;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
#ifdef RARCH_CG_DEBUG
|
2011-05-23 19:43:08 +00:00
|
|
|
static void cg_error_handler(CGcontext ctx, CGerror error, void *data)
|
|
|
|
{
|
|
|
|
(void)ctx;
|
|
|
|
(void)data;
|
|
|
|
|
2011-05-26 00:03:38 +00:00
|
|
|
switch (error)
|
|
|
|
{
|
|
|
|
case CG_INVALID_PARAM_HANDLE_ERROR:
|
2012-09-15 09:22:07 +00:00
|
|
|
RARCH_ERR("CG: Invalid param handle.\n");
|
2011-05-26 00:03:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CG_INVALID_PARAMETER_ERROR:
|
2012-09-15 09:22:07 +00:00
|
|
|
RARCH_ERR("CG: Invalid parameter.\n");
|
2011-05-26 00:03:38 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
RARCH_ERR("CG error: \"%s\"\n", cgGetErrorString(error));
|
2011-05-23 19:43:08 +00:00
|
|
|
}
|
|
|
|
#endif
|
2011-01-22 23:48:47 +00:00
|
|
|
|
2011-01-05 16:22:12 +00:00
|
|
|
static CGcontext cgCtx;
|
2011-05-23 19:04:25 +00:00
|
|
|
|
|
|
|
struct cg_fbo_params
|
|
|
|
{
|
|
|
|
CGparameter vid_size_f;
|
|
|
|
CGparameter tex_size_f;
|
|
|
|
CGparameter vid_size_v;
|
|
|
|
CGparameter tex_size_v;
|
|
|
|
CGparameter tex;
|
|
|
|
CGparameter coord;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define MAX_TEXTURES 8
|
2011-05-27 00:25:26 +00:00
|
|
|
#define MAX_VARIABLES 64
|
2011-11-12 13:18:10 +00:00
|
|
|
#define PREV_TEXTURES 7
|
2011-05-23 19:04:25 +00:00
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
struct cg_program
|
|
|
|
{
|
|
|
|
CGprogram vprg;
|
|
|
|
CGprogram fprg;
|
2012-09-15 09:22:07 +00:00
|
|
|
|
|
|
|
CGparameter tex;
|
|
|
|
CGparameter lut_tex;
|
|
|
|
CGparameter color;
|
|
|
|
CGparameter vertex;
|
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
CGparameter vid_size_f;
|
|
|
|
CGparameter tex_size_f;
|
|
|
|
CGparameter out_size_f;
|
2011-05-11 11:24:59 +00:00
|
|
|
CGparameter frame_cnt_f;
|
2011-11-09 22:45:34 +00:00
|
|
|
CGparameter frame_dir_f;
|
2011-03-06 18:56:35 +00:00
|
|
|
CGparameter vid_size_v;
|
|
|
|
CGparameter tex_size_v;
|
|
|
|
CGparameter out_size_v;
|
2011-05-11 11:24:59 +00:00
|
|
|
CGparameter frame_cnt_v;
|
2011-11-09 22:45:34 +00:00
|
|
|
CGparameter frame_dir_v;
|
2011-03-06 18:56:35 +00:00
|
|
|
CGparameter mvp;
|
2011-05-23 19:04:25 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
struct cg_fbo_params fbo[RARCH_CG_MAX_SHADERS];
|
2011-05-23 19:04:25 +00:00
|
|
|
struct cg_fbo_params orig;
|
2011-11-12 11:55:03 +00:00
|
|
|
struct cg_fbo_params prev[PREV_TEXTURES];
|
2011-03-06 18:56:35 +00:00
|
|
|
};
|
|
|
|
|
2011-05-22 15:02:09 +00:00
|
|
|
#define FILTER_UNSPEC 0
|
|
|
|
#define FILTER_LINEAR 1
|
|
|
|
#define FILTER_NEAREST 2
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
static struct cg_program prg[RARCH_CG_MAX_SHADERS];
|
2012-01-25 20:56:21 +00:00
|
|
|
static const char **cg_arguments;
|
2011-01-05 16:22:12 +00:00
|
|
|
static bool cg_active = false;
|
2011-03-06 18:56:35 +00:00
|
|
|
static CGprofile cgVProf, cgFProf;
|
|
|
|
static unsigned active_index = 0;
|
2011-05-22 15:02:09 +00:00
|
|
|
static unsigned cg_shader_num = 0;
|
2012-04-21 21:25:32 +00:00
|
|
|
static struct gl_fbo_scale cg_scale[RARCH_CG_MAX_SHADERS];
|
|
|
|
static unsigned fbo_smooth[RARCH_CG_MAX_SHADERS];
|
2011-01-05 16:22:12 +00:00
|
|
|
|
2012-02-22 22:35:01 +00:00
|
|
|
static GLuint lut_textures[MAX_TEXTURES];
|
2011-05-22 16:48:43 +00:00
|
|
|
static unsigned lut_textures_num = 0;
|
|
|
|
static char lut_textures_uniform[MAX_TEXTURES][64];
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
static CGparameter cg_attribs[PREV_TEXTURES + 1 + 4 + RARCH_CG_MAX_SHADERS];
|
2011-11-12 17:31:22 +00:00
|
|
|
static unsigned cg_attrib_index;
|
|
|
|
|
2011-10-28 15:10:58 +00:00
|
|
|
#ifdef HAVE_CONFIGFILE
|
2012-04-07 10:17:40 +00:00
|
|
|
static state_tracker_t *state_tracker = NULL;
|
2011-10-28 15:10:58 +00:00
|
|
|
#endif
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
static void gl_cg_reset_attrib(void)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < cg_attrib_index; i++)
|
|
|
|
cgGLDisableClientState(cg_attribs[i]);
|
|
|
|
cg_attrib_index = 0;
|
|
|
|
}
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
bool gl_cg_set_mvp(const math_matrix *mat)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2011-05-23 19:43:08 +00:00
|
|
|
if (cg_active && prg[active_index].mvp)
|
2012-09-11 21:32:00 +00:00
|
|
|
{
|
2012-08-09 20:33:32 +00:00
|
|
|
cgGLSetMatrixParameterfc(prg[active_index].mvp, mat->data);
|
2012-09-11 21:32:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
#define SET_COORD(name, coords_name, len) do { \
|
|
|
|
if (prg[active_index].name) \
|
|
|
|
{ \
|
|
|
|
cgGLSetParameterPointer(prg[active_index].name, len, GL_FLOAT, 0, coords->coords_name); \
|
|
|
|
cgGLEnableClientState(prg[active_index].name); \
|
|
|
|
cg_attribs[cg_attrib_index++] = prg[active_index].name; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
|
|
|
|
2012-09-11 21:32:00 +00:00
|
|
|
bool gl_cg_set_coords(const struct gl_coords *coords)
|
|
|
|
{
|
2012-09-15 09:22:07 +00:00
|
|
|
if (!cg_active)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
SET_COORD(vertex, vertex, 2);
|
|
|
|
SET_COORD(tex, tex_coord, 2);
|
|
|
|
SET_COORD(lut_tex, lut_tex_coord, 2);
|
|
|
|
SET_COORD(color, color, 4);
|
|
|
|
|
|
|
|
return true;
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2011-05-23 19:43:08 +00:00
|
|
|
#define set_param_2f(param, x, y) \
|
|
|
|
if (param) cgGLSetParameter2f(param, x, y)
|
|
|
|
#define set_param_1f(param, x) \
|
|
|
|
if (param) cgGLSetParameter1f(param, x)
|
|
|
|
|
2011-01-05 16:22:12 +00:00
|
|
|
void gl_cg_set_params(unsigned width, unsigned height,
|
|
|
|
unsigned tex_width, unsigned tex_height,
|
2011-05-11 11:24:59 +00:00
|
|
|
unsigned out_width, unsigned out_height,
|
2011-05-23 15:41:52 +00:00
|
|
|
unsigned frame_count,
|
2011-05-23 17:57:52 +00:00
|
|
|
const struct gl_tex_info *info,
|
2011-07-03 13:39:35 +00:00
|
|
|
const struct gl_tex_info *prev_info,
|
2011-05-23 17:57:52 +00:00
|
|
|
const struct gl_tex_info *fbo_info,
|
|
|
|
unsigned fbo_info_cnt)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
if (!cg_active || (active_index == 0))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Set frame.
|
|
|
|
set_param_2f(prg[active_index].vid_size_f, width, height);
|
|
|
|
set_param_2f(prg[active_index].tex_size_f, tex_width, tex_height);
|
|
|
|
set_param_2f(prg[active_index].out_size_f, out_width, out_height);
|
|
|
|
set_param_1f(prg[active_index].frame_cnt_f, (float)frame_count);
|
|
|
|
set_param_1f(prg[active_index].frame_dir_f, g_extern.frame_is_reverse ? -1.0 : 1.0);
|
|
|
|
|
|
|
|
set_param_2f(prg[active_index].vid_size_v, width, height);
|
|
|
|
set_param_2f(prg[active_index].tex_size_v, tex_width, tex_height);
|
|
|
|
set_param_2f(prg[active_index].out_size_v, out_width, out_height);
|
|
|
|
set_param_1f(prg[active_index].frame_cnt_v, (float)frame_count);
|
|
|
|
set_param_1f(prg[active_index].frame_dir_v, g_extern.frame_is_reverse ? -1.0 : 1.0);
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
if (active_index == RARCH_CG_MENU_SHADER_INDEX)
|
2012-01-25 20:56:21 +00:00
|
|
|
return;
|
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
// Set orig texture.
|
|
|
|
CGparameter param = prg[active_index].orig.tex;
|
|
|
|
if (param)
|
|
|
|
{
|
|
|
|
cgGLSetTextureParameter(param, info->tex);
|
|
|
|
cgGLEnableTextureParameter(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
set_param_2f(prg[active_index].orig.vid_size_v, info->input_size[0], info->input_size[1]);
|
|
|
|
set_param_2f(prg[active_index].orig.vid_size_f, info->input_size[0], info->input_size[1]);
|
2012-01-25 20:56:21 +00:00
|
|
|
set_param_2f(prg[active_index].orig.tex_size_v, info->tex_size[0], info->tex_size[1]);
|
|
|
|
set_param_2f(prg[active_index].orig.tex_size_f, info->tex_size[0], info->tex_size[1]);
|
2011-11-12 17:31:22 +00:00
|
|
|
if (prg[active_index].orig.coord)
|
|
|
|
{
|
|
|
|
cgGLSetParameterPointer(prg[active_index].orig.coord, 2, GL_FLOAT, 0, info->coord);
|
|
|
|
cgGLEnableClientState(prg[active_index].orig.coord);
|
|
|
|
cg_attribs[cg_attrib_index++] = prg[active_index].orig.coord;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set prev textures.
|
|
|
|
for (unsigned i = 0; i < PREV_TEXTURES; i++)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
param = prg[active_index].prev[i].tex;
|
2011-05-26 00:03:38 +00:00
|
|
|
if (param)
|
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
cgGLSetTextureParameter(param, prev_info[i].tex);
|
2011-05-26 00:03:38 +00:00
|
|
|
cgGLEnableTextureParameter(param);
|
|
|
|
}
|
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
set_param_2f(prg[active_index].prev[i].vid_size_v, prev_info[i].input_size[0], prev_info[i].input_size[1]);
|
|
|
|
set_param_2f(prg[active_index].prev[i].vid_size_f, prev_info[i].input_size[0], prev_info[i].input_size[1]);
|
|
|
|
set_param_2f(prg[active_index].prev[i].tex_size_v, prev_info[i].tex_size[0], prev_info[i].tex_size[1]);
|
|
|
|
set_param_2f(prg[active_index].prev[i].tex_size_f, prev_info[i].tex_size[0], prev_info[i].tex_size[1]);
|
|
|
|
|
|
|
|
if (prg[active_index].prev[i].coord)
|
2011-05-26 00:03:38 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
cgGLSetParameterPointer(prg[active_index].prev[i].coord, 2, GL_FLOAT, 0, prev_info[i].coord);
|
|
|
|
cgGLEnableClientState(prg[active_index].prev[i].coord);
|
|
|
|
cg_attribs[cg_attrib_index++] = prg[active_index].prev[i].coord;
|
2011-05-26 00:03:38 +00:00
|
|
|
}
|
2011-11-12 17:31:22 +00:00
|
|
|
}
|
2011-05-26 00:03:38 +00:00
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
// Set lookup textures.
|
|
|
|
for (unsigned i = 0; i < lut_textures_num; i++)
|
|
|
|
{
|
|
|
|
CGparameter param = cgGetNamedParameter(prg[active_index].fprg, lut_textures_uniform[i]);
|
|
|
|
if (param)
|
2011-07-03 13:39:35 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
cgGLSetTextureParameter(param, lut_textures[i]);
|
|
|
|
cgGLEnableTextureParameter(param);
|
2011-07-03 13:39:35 +00:00
|
|
|
}
|
2011-11-12 17:31:22 +00:00
|
|
|
}
|
2011-07-03 13:39:35 +00:00
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
// Set FBO textures.
|
|
|
|
if (active_index > 2)
|
|
|
|
{
|
|
|
|
for (unsigned i = 0; i < fbo_info_cnt; i++)
|
2011-05-22 16:48:43 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
if (prg[active_index].fbo[i].tex)
|
2011-05-23 19:43:08 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
cgGLSetTextureParameter(prg[active_index].fbo[i].tex, fbo_info[i].tex);
|
|
|
|
cgGLEnableTextureParameter(prg[active_index].fbo[i].tex);
|
2011-05-23 19:43:08 +00:00
|
|
|
}
|
2011-05-23 19:04:25 +00:00
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
set_param_2f(prg[active_index].fbo[i].vid_size_v, fbo_info[i].input_size[0], fbo_info[i].input_size[1]);
|
|
|
|
set_param_2f(prg[active_index].fbo[i].vid_size_f, fbo_info[i].input_size[0], fbo_info[i].input_size[1]);
|
2011-05-23 19:04:25 +00:00
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
set_param_2f(prg[active_index].fbo[i].tex_size_v, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]);
|
|
|
|
set_param_2f(prg[active_index].fbo[i].tex_size_f, fbo_info[i].tex_size[0], fbo_info[i].tex_size[1]);
|
2011-05-23 19:04:25 +00:00
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
if (prg[active_index].fbo[i].coord)
|
|
|
|
{
|
|
|
|
cgGLSetParameterPointer(prg[active_index].fbo[i].coord, 2, GL_FLOAT, 0, fbo_info[i].coord);
|
|
|
|
cgGLEnableClientState(prg[active_index].fbo[i].coord);
|
|
|
|
cg_attribs[cg_attrib_index++] = prg[active_index].fbo[i].coord;
|
2011-05-23 19:04:25 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-12 17:31:22 +00:00
|
|
|
}
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-10-28 15:10:58 +00:00
|
|
|
#ifdef HAVE_CONFIGFILE
|
2011-11-12 17:31:22 +00:00
|
|
|
// Set state parameters
|
2012-04-07 10:17:40 +00:00
|
|
|
if (state_tracker)
|
2011-11-12 17:31:22 +00:00
|
|
|
{
|
2012-10-27 10:24:06 +00:00
|
|
|
// Only query uniforms in first pass.
|
2012-04-07 10:17:40 +00:00
|
|
|
static struct state_tracker_uniform info[MAX_VARIABLES];
|
2011-11-12 17:31:22 +00:00
|
|
|
static unsigned cnt = 0;
|
2011-06-08 15:59:29 +00:00
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
if (active_index == 1)
|
2012-04-07 10:17:40 +00:00
|
|
|
cnt = state_get_uniform(state_tracker, info, MAX_VARIABLES, frame_count);
|
2011-06-08 15:59:29 +00:00
|
|
|
|
2011-11-12 17:31:22 +00:00
|
|
|
for (unsigned i = 0; i < cnt; i++)
|
|
|
|
{
|
|
|
|
CGparameter param_v = cgGetNamedParameter(prg[active_index].vprg, info[i].id);
|
|
|
|
CGparameter param_f = cgGetNamedParameter(prg[active_index].fprg, info[i].id);
|
|
|
|
set_param_1f(param_v, info[i].value);
|
|
|
|
set_param_1f(param_f, info[i].value);
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
2011-11-12 17:31:22 +00:00
|
|
|
#endif
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 15:22:58 +00:00
|
|
|
static void gl_cg_deinit_progs(void)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2012-09-15 09:22:07 +00:00
|
|
|
RARCH_LOG("CG: Destroying programs.\n");
|
2012-02-20 15:22:58 +00:00
|
|
|
cgGLUnbindProgram(cgFProf);
|
|
|
|
cgGLUnbindProgram(cgVProf);
|
|
|
|
|
|
|
|
// Programs may alias [0].
|
2012-04-21 21:25:32 +00:00
|
|
|
for (unsigned i = 1; i < RARCH_CG_MAX_SHADERS; i++)
|
2012-02-20 15:22:58 +00:00
|
|
|
{
|
2012-09-15 09:22:07 +00:00
|
|
|
if (prg[i].fprg && prg[i].fprg != prg[0].fprg)
|
2012-02-20 15:22:58 +00:00
|
|
|
cgDestroyProgram(prg[i].fprg);
|
2012-09-15 09:22:07 +00:00
|
|
|
if (prg[i].vprg && prg[i].vprg != prg[0].vprg)
|
2012-02-20 15:22:58 +00:00
|
|
|
cgDestroyProgram(prg[i].vprg);
|
|
|
|
}
|
2011-06-11 20:02:05 +00:00
|
|
|
|
2012-02-20 15:22:58 +00:00
|
|
|
if (prg[0].fprg)
|
|
|
|
cgDestroyProgram(prg[0].fprg);
|
|
|
|
if (prg[0].vprg)
|
|
|
|
cgDestroyProgram(prg[0].vprg);
|
|
|
|
|
|
|
|
memset(prg, 0, sizeof(prg));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gl_cg_deinit_state(void)
|
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
gl_cg_reset_attrib();
|
|
|
|
|
2011-03-29 17:18:06 +00:00
|
|
|
cg_active = false;
|
2011-05-22 15:02:09 +00:00
|
|
|
cg_shader_num = 0;
|
2012-02-20 15:22:58 +00:00
|
|
|
|
|
|
|
gl_cg_deinit_progs();
|
|
|
|
|
2011-05-22 15:02:09 +00:00
|
|
|
memset(cg_scale, 0, sizeof(cg_scale));
|
|
|
|
memset(fbo_smooth, 0, sizeof(fbo_smooth));
|
2011-05-22 16:48:43 +00:00
|
|
|
|
|
|
|
glDeleteTextures(lut_textures_num, lut_textures);
|
|
|
|
lut_textures_num = 0;
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-10-28 15:10:58 +00:00
|
|
|
#ifdef HAVE_CONFIGFILE
|
2012-04-07 10:17:40 +00:00
|
|
|
if (state_tracker)
|
2011-05-27 00:25:26 +00:00
|
|
|
{
|
2012-04-07 10:17:40 +00:00
|
|
|
state_tracker_free(state_tracker);
|
|
|
|
state_tracker = NULL;
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
2011-10-28 15:10:58 +00:00
|
|
|
#endif
|
2012-02-20 15:22:58 +00:00
|
|
|
}
|
2011-06-11 20:02:05 +00:00
|
|
|
|
2012-02-20 15:22:58 +00:00
|
|
|
// Final deinit.
|
|
|
|
static void gl_cg_deinit_context_state(void)
|
|
|
|
{
|
2012-01-25 20:56:21 +00:00
|
|
|
if (menu_cg_program)
|
|
|
|
{
|
|
|
|
free(menu_cg_program);
|
|
|
|
menu_cg_program = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-20 15:22:58 +00:00
|
|
|
// Destroying context breaks on PS3 for some unknown reason.
|
2012-02-02 19:42:20 +00:00
|
|
|
#ifndef __CELLOS_LV2__
|
2012-02-20 15:22:58 +00:00
|
|
|
if (cgCtx)
|
|
|
|
{
|
2012-09-15 09:22:07 +00:00
|
|
|
RARCH_LOG("CG: Destroying context.\n");
|
2012-02-20 15:22:58 +00:00
|
|
|
cgDestroyContext(cgCtx);
|
|
|
|
cgCtx = NULL;
|
|
|
|
}
|
2012-02-02 19:42:20 +00:00
|
|
|
#endif
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 15:22:58 +00:00
|
|
|
// Full deinit.
|
|
|
|
void gl_cg_deinit(void)
|
|
|
|
{
|
|
|
|
if (!cg_active)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gl_cg_deinit_state();
|
|
|
|
gl_cg_deinit_context_state();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Deinit as much as possible without resetting context (broken on PS3),
|
|
|
|
// and reinit cleanly.
|
|
|
|
// If this fails, we're kinda screwed without resetting everything on PS3.
|
|
|
|
bool gl_cg_reinit(const char *path)
|
|
|
|
{
|
|
|
|
if (cg_active)
|
|
|
|
gl_cg_deinit_state();
|
|
|
|
|
|
|
|
return gl_cg_init(path);
|
|
|
|
}
|
|
|
|
|
2011-11-09 23:46:39 +00:00
|
|
|
#define SET_LISTING(type) \
|
|
|
|
{ \
|
|
|
|
const char *list = cgGetLastListing(cgCtx); \
|
|
|
|
if (list) \
|
|
|
|
listing_##type = strdup(list); \
|
|
|
|
}
|
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
static bool load_program(unsigned index, const char *prog, bool path_is_file)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2012-01-25 20:56:21 +00:00
|
|
|
bool ret = true;
|
2012-01-25 21:55:34 +00:00
|
|
|
char *listing_f = NULL;
|
|
|
|
char *listing_v = NULL;
|
2011-07-04 11:33:09 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
if (path_is_file)
|
2011-01-05 16:22:12 +00:00
|
|
|
{
|
2012-01-25 21:55:34 +00:00
|
|
|
prg[index].fprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, prog, cgFProf, "main_fragment", cg_arguments);
|
|
|
|
SET_LISTING(f);
|
|
|
|
prg[index].vprg = cgCreateProgramFromFile(cgCtx, CG_SOURCE, prog, cgVProf, "main_vertex", cg_arguments);
|
|
|
|
SET_LISTING(v);
|
2011-03-06 18:56:35 +00:00
|
|
|
}
|
|
|
|
else
|
2011-05-22 15:02:09 +00:00
|
|
|
{
|
2012-01-25 21:55:34 +00:00
|
|
|
prg[index].fprg = cgCreateProgram(cgCtx, CG_SOURCE, prog, cgFProf, "main_fragment", cg_arguments);
|
|
|
|
SET_LISTING(f);
|
|
|
|
prg[index].vprg = cgCreateProgram(cgCtx, CG_SOURCE, prog, cgVProf, "main_vertex", cg_arguments);
|
|
|
|
SET_LISTING(v);
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
if (!prg[index].fprg || !prg[index].vprg)
|
2011-03-06 18:56:35 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("CG error: %s\n", cgGetErrorString(cgGetError()));
|
2012-01-25 21:55:34 +00:00
|
|
|
if (listing_f)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Fragment:\n%s\n", listing_f);
|
2012-01-25 21:55:34 +00:00
|
|
|
else if (listing_v)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Vertex:\n%s\n", listing_v);
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-01-05 16:22:12 +00:00
|
|
|
}
|
2011-03-06 18:56:35 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
cgGLLoadProgram(prg[index].fprg);
|
|
|
|
cgGLLoadProgram(prg[index].vprg);
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
end:
|
2012-01-25 21:55:34 +00:00
|
|
|
free(listing_f);
|
|
|
|
free(listing_v);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
static void set_program_base_attrib(unsigned i);
|
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
static bool load_stock(void)
|
|
|
|
{
|
|
|
|
if (!load_program(0, stock_cg_program, false))
|
2011-11-09 23:46:39 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to compile passthrough shader, is something wrong with your environment?\n");
|
2012-01-25 21:55:34 +00:00
|
|
|
return false;
|
2011-11-09 23:46:39 +00:00
|
|
|
}
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
set_program_base_attrib(0);
|
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
return true;
|
2012-01-25 20:56:21 +00:00
|
|
|
}
|
2011-07-04 11:33:09 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
static bool load_plain(const char *path)
|
2012-01-25 20:56:21 +00:00
|
|
|
{
|
2012-01-25 21:55:34 +00:00
|
|
|
if (!load_stock())
|
|
|
|
return false;
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Loading Cg file: %s\n", path);
|
2012-01-25 21:55:34 +00:00
|
|
|
|
|
|
|
if (!load_program(1, path, true))
|
|
|
|
return false;
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
if (*g_settings.video.second_pass_shader && g_settings.video.render_to_texture)
|
2011-07-04 11:33:09 +00:00
|
|
|
{
|
2012-01-25 21:55:34 +00:00
|
|
|
if (!load_program(2, g_settings.video.second_pass_shader, true))
|
|
|
|
return false;
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
cg_shader_num = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prg[2] = prg[0];
|
|
|
|
cg_shader_num = 1;
|
2011-07-04 11:33:09 +00:00
|
|
|
}
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
return true;
|
|
|
|
}
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
static bool load_menu_shader(void)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
return load_program(RARCH_CG_MENU_SHADER_INDEX, menu_cg_program, true);
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
|
2011-05-31 13:03:59 +00:00
|
|
|
#define print_buf(buf, ...) snprintf(buf, sizeof(buf), __VA_ARGS__)
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-05-26 18:44:12 +00:00
|
|
|
#ifdef HAVE_CONFIGFILE
|
2012-01-25 21:55:34 +00:00
|
|
|
static void load_texture_data(GLuint *obj, const struct texture_image *img, bool smooth)
|
|
|
|
{
|
|
|
|
glGenTextures(1, obj);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, *obj);
|
|
|
|
|
|
|
|
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, smooth ? GL_LINEAR : GL_NEAREST);
|
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, smooth ? GL_LINEAR : GL_NEAREST);
|
|
|
|
|
2012-10-02 18:23:10 +00:00
|
|
|
#ifndef HAVE_PSGL
|
2012-01-25 21:55:34 +00:00
|
|
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
2012-10-02 18:23:10 +00:00
|
|
|
#endif
|
2012-01-25 21:55:34 +00:00
|
|
|
glTexImage2D(GL_TEXTURE_2D,
|
2012-10-19 23:12:02 +00:00
|
|
|
0, RARCH_GL_INTERNAL_FORMAT32, img->width, img->height,
|
|
|
|
0, RARCH_GL_TEXTURE_TYPE32, RARCH_GL_FORMAT32, img->pixels);
|
2012-01-25 21:55:34 +00:00
|
|
|
|
|
|
|
free(img->pixels);
|
|
|
|
}
|
|
|
|
|
2011-05-22 16:48:43 +00:00
|
|
|
static bool load_textures(const char *dir_path, config_file_t *conf)
|
|
|
|
{
|
2012-01-25 20:56:21 +00:00
|
|
|
bool ret = true;
|
|
|
|
char *textures = NULL;
|
2011-05-22 16:48:43 +00:00
|
|
|
if (!config_get_string(conf, "textures", &textures)) // No textures here ...
|
|
|
|
return true;
|
|
|
|
|
2012-06-24 00:11:22 +00:00
|
|
|
char *save;
|
|
|
|
const char *id = strtok_r(textures, ";", &save);
|
2011-05-22 16:48:43 +00:00
|
|
|
while (id && lut_textures_num < MAX_TEXTURES)
|
|
|
|
{
|
2012-02-20 14:45:38 +00:00
|
|
|
char path[PATH_MAX];
|
|
|
|
if (!config_get_array(conf, id, path, sizeof(path)))
|
2011-05-22 16:48:43 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Cannot find path to texture \"%s\" ...\n", id);
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 16:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char id_filter[64];
|
2011-05-27 00:25:26 +00:00
|
|
|
print_buf(id_filter, "%s_linear", id);
|
2012-02-20 14:45:38 +00:00
|
|
|
|
|
|
|
bool smooth = true;
|
2011-05-22 16:48:43 +00:00
|
|
|
if (!config_get_bool(conf, id_filter, &smooth))
|
|
|
|
smooth = true;
|
|
|
|
|
2012-02-20 14:45:38 +00:00
|
|
|
char id_absolute[64];
|
|
|
|
print_buf(id_absolute, "%s_absolute", id);
|
|
|
|
|
|
|
|
bool absolute = false;
|
|
|
|
if (!config_get_bool(conf, id_absolute, &absolute))
|
|
|
|
absolute = false;
|
|
|
|
|
2011-05-22 16:48:43 +00:00
|
|
|
char image_path[512];
|
2012-02-20 14:45:38 +00:00
|
|
|
if (absolute)
|
|
|
|
print_buf(image_path, "%s", path);
|
|
|
|
else
|
|
|
|
print_buf(image_path, "%s%s", dir_path, path);
|
2011-05-22 16:48:43 +00:00
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Loading image from: \"%s\".\n", image_path);
|
2011-05-22 16:48:43 +00:00
|
|
|
struct texture_image img;
|
|
|
|
if (!texture_image_load(image_path, &img))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load picture ...\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 16:48:43 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 14:45:38 +00:00
|
|
|
strlcpy(lut_textures_uniform[lut_textures_num],
|
|
|
|
id, sizeof(lut_textures_uniform[lut_textures_num]));
|
2011-05-22 16:48:43 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
load_texture_data(&lut_textures[lut_textures_num], &img, smooth);
|
2011-05-22 16:48:43 +00:00
|
|
|
lut_textures_num++;
|
|
|
|
|
2012-06-24 00:11:22 +00:00
|
|
|
id = strtok_r(NULL, ";", &save);
|
2011-05-22 16:48:43 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
end:
|
2011-05-22 16:48:43 +00:00
|
|
|
free(textures);
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
2012-01-25 20:56:21 +00:00
|
|
|
return ret;
|
2011-05-22 16:48:43 +00:00
|
|
|
}
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-06-06 18:18:31 +00:00
|
|
|
static bool load_imports(const char *dir_path, config_file_t *conf)
|
2011-05-27 00:25:26 +00:00
|
|
|
{
|
2012-01-25 20:56:21 +00:00
|
|
|
bool ret = true;
|
2011-05-27 00:25:26 +00:00
|
|
|
char *imports = NULL;
|
|
|
|
|
|
|
|
if (!config_get_string(conf, "imports", &imports))
|
|
|
|
return true;
|
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
struct state_tracker_uniform_info info[MAX_VARIABLES];
|
2011-05-27 00:25:26 +00:00
|
|
|
unsigned info_cnt = 0;
|
2012-04-07 10:17:40 +00:00
|
|
|
struct state_tracker_info tracker_info = {0};
|
2011-12-24 12:46:12 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_PYTHON
|
2012-09-15 09:22:07 +00:00
|
|
|
char script_path[PATH_MAX];
|
2011-12-24 12:46:12 +00:00
|
|
|
char *script = NULL;
|
|
|
|
char *script_class = NULL;
|
|
|
|
#endif
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2012-06-24 00:11:22 +00:00
|
|
|
char *save;
|
|
|
|
const char *id = strtok_r(imports, ";", &save);
|
2011-05-27 00:25:26 +00:00
|
|
|
while (id && info_cnt < MAX_VARIABLES)
|
|
|
|
{
|
|
|
|
char semantic_buf[64];
|
|
|
|
char wram_buf[64];
|
2011-06-11 18:02:17 +00:00
|
|
|
char input_slot_buf[64];
|
2011-05-29 21:58:04 +00:00
|
|
|
char mask_buf[64];
|
2012-02-12 17:05:33 +00:00
|
|
|
char equal_buf[64];
|
2011-05-27 00:25:26 +00:00
|
|
|
|
|
|
|
print_buf(semantic_buf, "%s_semantic", id);
|
|
|
|
print_buf(wram_buf, "%s_wram", id);
|
2011-06-11 18:02:17 +00:00
|
|
|
print_buf(input_slot_buf, "%s_input_slot", id);
|
2011-05-29 21:58:04 +00:00
|
|
|
print_buf(mask_buf, "%s_mask", id);
|
2012-02-12 17:05:33 +00:00
|
|
|
print_buf(equal_buf, "%s_equal", id);
|
2011-05-27 00:25:26 +00:00
|
|
|
|
|
|
|
char *semantic = NULL;
|
|
|
|
|
|
|
|
config_get_string(conf, semantic_buf, &semantic);
|
|
|
|
|
|
|
|
if (!semantic)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("No semantic for import variable.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
enum state_tracker_type tracker_type;
|
2012-04-21 21:25:32 +00:00
|
|
|
enum state_ram_type ram_type = RARCH_STATE_NONE;
|
2011-05-27 00:25:26 +00:00
|
|
|
|
|
|
|
if (strcmp(semantic, "capture") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_CAPTURE;
|
2011-05-27 00:25:26 +00:00
|
|
|
else if (strcmp(semantic, "transition") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_TRANSITION;
|
2011-06-06 19:32:10 +00:00
|
|
|
else if (strcmp(semantic, "transition_count") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_TRANSITION_COUNT;
|
2011-05-27 00:25:26 +00:00
|
|
|
else if (strcmp(semantic, "capture_previous") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_CAPTURE_PREV;
|
2011-05-27 00:25:26 +00:00
|
|
|
else if (strcmp(semantic, "transition_previous") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_TRANSITION_PREV;
|
2011-06-06 18:18:31 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
else if (strcmp(semantic, "python") == 0)
|
2012-04-21 21:25:32 +00:00
|
|
|
tracker_type = RARCH_STATE_PYTHON;
|
2011-06-06 18:18:31 +00:00
|
|
|
#endif
|
2011-05-27 00:25:26 +00:00
|
|
|
else
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Invalid semantic.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2011-06-06 18:18:31 +00:00
|
|
|
unsigned addr = 0;
|
|
|
|
#ifdef HAVE_PYTHON
|
2012-04-21 21:25:32 +00:00
|
|
|
if (tracker_type != RARCH_STATE_PYTHON)
|
2011-06-06 18:18:31 +00:00
|
|
|
#endif
|
2011-10-26 17:51:10 +00:00
|
|
|
{
|
2011-06-11 18:02:17 +00:00
|
|
|
unsigned input_slot = 0;
|
|
|
|
if (config_get_hex(conf, input_slot_buf, &input_slot))
|
|
|
|
{
|
|
|
|
switch (input_slot)
|
|
|
|
{
|
|
|
|
case 1:
|
2012-04-21 21:25:32 +00:00
|
|
|
ram_type = RARCH_STATE_INPUT_SLOT1;
|
2011-06-11 18:02:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2012-04-21 21:25:32 +00:00
|
|
|
ram_type = RARCH_STATE_INPUT_SLOT2;
|
2011-06-11 18:02:17 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Invalid input slot for import.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-06-11 18:02:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (config_get_hex(conf, wram_buf, &addr))
|
2012-04-21 21:25:32 +00:00
|
|
|
ram_type = RARCH_STATE_WRAM;
|
2011-06-06 18:18:31 +00:00
|
|
|
else
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("No address assigned to semantic.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-06-06 18:18:31 +00:00
|
|
|
}
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2011-10-26 17:51:10 +00:00
|
|
|
unsigned memtype;
|
2011-05-27 00:25:26 +00:00
|
|
|
switch (ram_type)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
case RARCH_STATE_WRAM:
|
2012-04-07 10:17:40 +00:00
|
|
|
memtype = RETRO_MEMORY_SYSTEM_RAM;
|
2011-05-28 13:06:46 +00:00
|
|
|
break;
|
2011-06-11 18:02:17 +00:00
|
|
|
|
2011-05-27 00:25:26 +00:00
|
|
|
default:
|
2011-10-26 17:51:10 +00:00
|
|
|
memtype = -1u;
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
if ((memtype != -1u) && (addr >= pretro_get_memory_size(memtype)))
|
2011-05-28 13:06:46 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Address out of bounds.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-28 13:06:46 +00:00
|
|
|
}
|
|
|
|
|
2012-04-11 18:17:17 +00:00
|
|
|
unsigned bitmask = 0;
|
2011-05-29 21:58:04 +00:00
|
|
|
if (!config_get_hex(conf, mask_buf, &bitmask))
|
|
|
|
bitmask = 0;
|
2012-04-11 18:17:17 +00:00
|
|
|
unsigned bitequal = 0;
|
2012-02-12 17:05:33 +00:00
|
|
|
if (!config_get_hex(conf, equal_buf, &bitequal))
|
|
|
|
bitequal = 0;
|
2011-05-29 21:58:04 +00:00
|
|
|
|
2011-05-27 00:25:26 +00:00
|
|
|
strlcpy(info[info_cnt].id, id, sizeof(info[info_cnt].id));
|
|
|
|
info[info_cnt].addr = addr;
|
|
|
|
info[info_cnt].type = tracker_type;
|
|
|
|
info[info_cnt].ram_type = ram_type;
|
2011-05-29 21:58:04 +00:00
|
|
|
info[info_cnt].mask = bitmask;
|
2012-02-12 17:05:33 +00:00
|
|
|
info[info_cnt].equal = bitequal;
|
2011-05-27 00:25:26 +00:00
|
|
|
|
|
|
|
info_cnt++;
|
2011-05-27 01:48:59 +00:00
|
|
|
free(semantic);
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2012-06-24 00:11:22 +00:00
|
|
|
id = strtok_r(NULL, ";", &save);
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2012-04-09 20:30:29 +00:00
|
|
|
tracker_info.wram = (uint8_t*)pretro_get_memory_data(RETRO_MEMORY_SYSTEM_RAM);
|
2011-12-24 12:46:12 +00:00
|
|
|
tracker_info.info = info;
|
|
|
|
tracker_info.info_elem = info_cnt;
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-06-06 18:18:31 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
if (config_get_string(conf, "import_script", &script))
|
|
|
|
{
|
|
|
|
strlcpy(script_path, dir_path, sizeof(script_path));
|
|
|
|
strlcat(script_path, script, sizeof(script_path));
|
|
|
|
|
|
|
|
tracker_info.script = script_path;
|
|
|
|
}
|
|
|
|
if (config_get_string(conf, "import_script_class", &script_class))
|
|
|
|
tracker_info.script_class = script_class;
|
2011-06-07 13:33:29 +00:00
|
|
|
|
|
|
|
tracker_info.script_is_file = true;
|
2011-06-06 18:18:31 +00:00
|
|
|
#endif
|
|
|
|
|
2012-04-07 10:17:40 +00:00
|
|
|
state_tracker = state_tracker_init(&tracker_info);
|
|
|
|
if (!state_tracker)
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("Failed to initialize state tracker.\n");
|
2011-05-27 00:25:26 +00:00
|
|
|
|
2011-06-06 18:18:31 +00:00
|
|
|
#ifdef HAVE_PYTHON
|
|
|
|
if (script)
|
|
|
|
free(script);
|
|
|
|
if (script_class)
|
|
|
|
free(script_class);
|
|
|
|
#endif
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
end:
|
2011-05-27 00:25:26 +00:00
|
|
|
free(imports);
|
2012-01-25 20:56:21 +00:00
|
|
|
return ret;
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
2011-05-26 18:44:12 +00:00
|
|
|
#endif
|
2011-05-22 16:48:43 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
static bool load_shader(const char *dir_path, unsigned i, config_file_t *conf)
|
|
|
|
{
|
2012-04-11 18:17:17 +00:00
|
|
|
char *shader_path = NULL;
|
2012-01-25 21:55:34 +00:00
|
|
|
char attr_buf[64];
|
|
|
|
char path_buf[PATH_MAX];
|
|
|
|
|
|
|
|
print_buf(attr_buf, "shader%u", i);
|
|
|
|
if (config_get_string(conf, attr_buf, &shader_path))
|
|
|
|
{
|
|
|
|
strlcpy(path_buf, dir_path, sizeof(path_buf));
|
|
|
|
strlcat(path_buf, shader_path, sizeof(path_buf));
|
|
|
|
free(shader_path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Didn't find shader path in config ...\n");
|
2012-01-25 21:55:34 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Loading Cg shader: \"%s\".\n", path_buf);
|
2012-01-25 21:55:34 +00:00
|
|
|
|
|
|
|
if (!load_program(i + 1, path_buf, true))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool load_shader_params(unsigned i, config_file_t *conf)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
char *scale_type = NULL;
|
|
|
|
char *scale_type_x = NULL;
|
|
|
|
char *scale_type_y = NULL;
|
|
|
|
bool has_scale_type;
|
|
|
|
bool has_scale_type_x;
|
|
|
|
bool has_scale_type_y;
|
|
|
|
|
|
|
|
char scale_name_buf[64];
|
|
|
|
print_buf(scale_name_buf, "scale_type%u", i);
|
|
|
|
has_scale_type = config_get_string(conf, scale_name_buf, &scale_type);
|
|
|
|
print_buf(scale_name_buf, "scale_type_x%u", i);
|
|
|
|
has_scale_type_x = config_get_string(conf, scale_name_buf, &scale_type_x);
|
|
|
|
print_buf(scale_name_buf, "scale_type_y%u", i);
|
|
|
|
has_scale_type_y = config_get_string(conf, scale_name_buf, &scale_type_y);
|
|
|
|
|
|
|
|
if (!has_scale_type && !has_scale_type_x && !has_scale_type_y)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (has_scale_type)
|
|
|
|
{
|
|
|
|
free(scale_type_x);
|
|
|
|
free(scale_type_y);
|
|
|
|
|
|
|
|
scale_type_x = strdup(scale_type);
|
|
|
|
scale_type_y = strdup(scale_type);
|
|
|
|
|
|
|
|
free(scale_type);
|
|
|
|
scale_type = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char attr_name_buf[64];
|
2012-04-11 18:17:17 +00:00
|
|
|
float fattr = 0.0f;
|
|
|
|
int iattr = 0;
|
2012-01-25 21:55:34 +00:00
|
|
|
struct gl_fbo_scale *scale = &cg_scale[i + 1]; // Shader 0 is passthrough shader. Start at 1.
|
|
|
|
|
|
|
|
scale->valid = true;
|
2012-04-21 21:25:32 +00:00
|
|
|
scale->type_x = RARCH_SCALE_INPUT;
|
|
|
|
scale->type_y = RARCH_SCALE_INPUT;
|
2012-01-25 21:55:34 +00:00
|
|
|
scale->scale_x = 1.0;
|
|
|
|
scale->scale_y = 1.0;
|
2012-04-07 10:17:40 +00:00
|
|
|
|
|
|
|
const struct retro_game_geometry *geom = &g_extern.system.av_info.geometry;
|
|
|
|
scale->abs_x = geom->base_width;
|
|
|
|
scale->abs_y = geom->base_height;
|
2012-01-25 21:55:34 +00:00
|
|
|
|
2012-05-28 12:05:03 +00:00
|
|
|
if (scale_type_x)
|
2012-01-25 21:55:34 +00:00
|
|
|
{
|
2012-05-28 12:05:03 +00:00
|
|
|
if (strcmp(scale_type_x, "source") == 0)
|
|
|
|
scale->type_x = RARCH_SCALE_INPUT;
|
|
|
|
else if (strcmp(scale_type_x, "viewport") == 0)
|
|
|
|
scale->type_x = RARCH_SCALE_VIEWPORT;
|
|
|
|
else if (strcmp(scale_type_x, "absolute") == 0)
|
|
|
|
scale->type_x = RARCH_SCALE_ABSOLUTE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_ERR("Invalid attribute.\n");
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
2012-01-25 21:55:34 +00:00
|
|
|
}
|
|
|
|
|
2012-05-28 12:05:03 +00:00
|
|
|
if (scale_type_y)
|
2012-01-25 21:55:34 +00:00
|
|
|
{
|
2012-05-28 12:05:03 +00:00
|
|
|
if (strcmp(scale_type_y, "source") == 0)
|
|
|
|
scale->type_y = RARCH_SCALE_INPUT;
|
|
|
|
else if (strcmp(scale_type_y, "viewport") == 0)
|
|
|
|
scale->type_y = RARCH_SCALE_VIEWPORT;
|
|
|
|
else if (strcmp(scale_type_y, "absolute") == 0)
|
|
|
|
scale->type_y = RARCH_SCALE_ABSOLUTE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
RARCH_ERR("Invalid attribute.\n");
|
|
|
|
ret = false;
|
|
|
|
goto end;
|
|
|
|
}
|
2012-01-25 21:55:34 +00:00
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
if (scale->type_x == RARCH_SCALE_ABSOLUTE)
|
2012-01-25 21:55:34 +00:00
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale%u", i);
|
|
|
|
if (config_get_int(conf, attr_name_buf, &iattr))
|
|
|
|
scale->abs_x = iattr;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale_x%u", i);
|
|
|
|
if (config_get_int(conf, attr_name_buf, &iattr))
|
|
|
|
scale->abs_x = iattr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale%u", i);
|
2012-02-13 21:04:25 +00:00
|
|
|
if (config_get_float(conf, attr_name_buf, &fattr))
|
2012-01-25 21:55:34 +00:00
|
|
|
scale->scale_x = fattr;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale_x%u", i);
|
2012-02-13 21:04:25 +00:00
|
|
|
if (config_get_float(conf, attr_name_buf, &fattr))
|
2012-01-25 21:55:34 +00:00
|
|
|
scale->scale_x = fattr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
if (scale->type_y == RARCH_SCALE_ABSOLUTE)
|
2012-01-25 21:55:34 +00:00
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale%u", i);
|
|
|
|
if (config_get_int(conf, attr_name_buf, &iattr))
|
|
|
|
scale->abs_y = iattr;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale_y%u", i);
|
|
|
|
if (config_get_int(conf, attr_name_buf, &iattr))
|
|
|
|
scale->abs_y = iattr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale%u", i);
|
2012-02-13 21:04:25 +00:00
|
|
|
if (config_get_float(conf, attr_name_buf, &fattr))
|
2012-01-25 21:55:34 +00:00
|
|
|
scale->scale_y = fattr;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
print_buf(attr_name_buf, "scale_y%u", i);
|
2012-02-13 21:04:25 +00:00
|
|
|
if (config_get_float(conf, attr_name_buf, &fattr))
|
2012-01-25 21:55:34 +00:00
|
|
|
scale->scale_y = fattr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
end:
|
|
|
|
free(scale_type);
|
|
|
|
free(scale_type_x);
|
|
|
|
free(scale_type_y);
|
|
|
|
return ret;
|
|
|
|
}
|
2011-05-26 21:55:27 +00:00
|
|
|
|
2011-05-22 15:02:09 +00:00
|
|
|
static bool load_preset(const char *path)
|
|
|
|
{
|
2011-05-26 18:44:12 +00:00
|
|
|
#ifdef HAVE_CONFIGFILE
|
2012-01-25 20:56:21 +00:00
|
|
|
bool ret = true;
|
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
if (!load_stock())
|
2011-05-22 15:02:09 +00:00
|
|
|
return false;
|
|
|
|
|
2012-04-11 18:17:17 +00:00
|
|
|
int shaders = 0;
|
2011-12-24 12:46:12 +00:00
|
|
|
// Basedir.
|
2012-01-02 12:32:25 +00:00
|
|
|
char dir_path[PATH_MAX];
|
2011-12-24 12:46:12 +00:00
|
|
|
char *ptr = NULL;
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_LOG("Loading Cg meta-shader: %s\n", path);
|
2011-05-22 15:02:09 +00:00
|
|
|
config_file_t *conf = config_file_new(path);
|
|
|
|
if (!conf)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load preset.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
|
2011-05-22 15:07:47 +00:00
|
|
|
if (!config_get_int(conf, "shaders", &shaders))
|
2011-05-22 15:02:09 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Cannot find \"shaders\" param.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (shaders < 1)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Need to define at least 1 shader.\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cg_shader_num = shaders;
|
2012-04-21 21:25:32 +00:00
|
|
|
if (shaders > RARCH_CG_MAX_SHADERS - 3)
|
2011-05-22 16:48:43 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_WARN("Too many shaders ... Capping shader amount to %d.\n", RARCH_CG_MAX_SHADERS - 3);
|
|
|
|
cg_shader_num = shaders = RARCH_CG_MAX_SHADERS - 3;
|
2011-05-22 16:48:43 +00:00
|
|
|
}
|
2011-05-26 21:55:27 +00:00
|
|
|
// If we aren't using last pass non-FBO shader,
|
|
|
|
// this shader will be assumed to be "fixed-function".
|
|
|
|
// Just use prg[0] for that pass, which will be
|
|
|
|
// pass-through.
|
|
|
|
prg[shaders + 1] = prg[0];
|
2011-05-22 15:02:09 +00:00
|
|
|
|
|
|
|
// Check filter params.
|
2011-12-24 12:46:12 +00:00
|
|
|
for (int i = 0; i < shaders; i++)
|
2011-05-22 15:02:09 +00:00
|
|
|
{
|
2012-04-11 18:17:17 +00:00
|
|
|
bool smooth = false;
|
2011-05-22 15:02:09 +00:00
|
|
|
char filter_name_buf[64];
|
2011-05-26 21:55:27 +00:00
|
|
|
print_buf(filter_name_buf, "filter_linear%u", i);
|
2011-05-22 15:02:09 +00:00
|
|
|
if (config_get_bool(conf, filter_name_buf, &smooth))
|
|
|
|
fbo_smooth[i + 1] = smooth ? FILTER_LINEAR : FILTER_NEAREST;
|
|
|
|
}
|
|
|
|
|
2011-05-22 15:07:47 +00:00
|
|
|
strlcpy(dir_path, path, sizeof(dir_path));
|
2011-12-24 12:46:12 +00:00
|
|
|
ptr = strrchr(dir_path, '/');
|
2011-05-22 15:07:47 +00:00
|
|
|
if (!ptr) ptr = strrchr(dir_path, '\\');
|
2011-05-22 15:36:18 +00:00
|
|
|
if (ptr)
|
|
|
|
ptr[1] = '\0';
|
|
|
|
else // No directory.
|
|
|
|
dir_path[0] = '\0';
|
2011-05-22 15:07:47 +00:00
|
|
|
|
2011-12-24 12:46:12 +00:00
|
|
|
for (int i = 0; i < shaders; i++)
|
2011-05-22 15:02:09 +00:00
|
|
|
{
|
2012-01-25 21:55:34 +00:00
|
|
|
if (!load_shader_params(i, conf))
|
2011-05-22 15:02:09 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load shader params ...\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
if (!load_shader(dir_path, i, conf))
|
2011-05-22 15:02:09 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load shaders ...\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-22 16:48:43 +00:00
|
|
|
if (!load_textures(dir_path, conf))
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load lookup textures ...\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-22 16:48:43 +00:00
|
|
|
}
|
2011-05-22 15:02:09 +00:00
|
|
|
|
2011-06-06 18:18:31 +00:00
|
|
|
if (!load_imports(dir_path, conf))
|
2011-05-27 00:25:26 +00:00
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to load imports ...\n");
|
2012-01-25 20:56:21 +00:00
|
|
|
ret = false;
|
|
|
|
goto end;
|
2011-05-27 00:25:26 +00:00
|
|
|
}
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
end:
|
2011-05-22 15:02:09 +00:00
|
|
|
if (conf)
|
|
|
|
config_file_free(conf);
|
2012-01-25 20:56:21 +00:00
|
|
|
return ret;
|
|
|
|
|
2011-05-26 18:44:12 +00:00
|
|
|
#else
|
|
|
|
(void)path;
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("No config file support compiled in.\n");
|
2011-05-26 18:44:12 +00:00
|
|
|
return false;
|
|
|
|
#endif
|
2011-05-22 15:02:09 +00:00
|
|
|
}
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
static void set_program_base_attrib(unsigned i)
|
|
|
|
{
|
|
|
|
CGparameter param = cgGetFirstParameter(prg[i].vprg, CG_PROGRAM);
|
|
|
|
for (; param; param = cgGetNextParameter(param))
|
|
|
|
{
|
|
|
|
if (cgGetParameterDirection(param) != CG_IN || cgGetParameterVariability(param) != CG_VARYING)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const char *semantic = cgGetParameterSemantic(param);
|
|
|
|
if (!semantic)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
RARCH_LOG("CG: Found semantic \"%s\" in prog #%u.\n", semantic, i);
|
|
|
|
|
|
|
|
if (strcmp(semantic, "TEXCOORD") == 0 || strcmp(semantic, "TEXCOORD0") == 0)
|
|
|
|
prg[i].tex = param;
|
|
|
|
else if (strcmp(semantic, "COLOR") == 0 || strcmp(semantic, "COLOR0") == 0)
|
|
|
|
prg[i].color = param;
|
|
|
|
else if (strcmp(semantic, "POSITION") == 0)
|
|
|
|
prg[i].vertex = param;
|
|
|
|
else if (strcmp(semantic, "TEXCOORD1") == 0)
|
|
|
|
prg[i].lut_tex = param;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
static void set_program_attributes(unsigned i)
|
|
|
|
{
|
|
|
|
cgGLBindProgram(prg[i].fprg);
|
|
|
|
cgGLBindProgram(prg[i].vprg);
|
|
|
|
|
2012-09-15 09:22:07 +00:00
|
|
|
set_program_base_attrib(i);
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
prg[i].vid_size_f = cgGetNamedParameter(prg[i].fprg, "IN.video_size");
|
|
|
|
prg[i].tex_size_f = cgGetNamedParameter(prg[i].fprg, "IN.texture_size");
|
|
|
|
prg[i].out_size_f = cgGetNamedParameter(prg[i].fprg, "IN.output_size");
|
|
|
|
prg[i].frame_cnt_f = cgGetNamedParameter(prg[i].fprg, "IN.frame_count");
|
|
|
|
prg[i].frame_dir_f = cgGetNamedParameter(prg[i].fprg, "IN.frame_direction");
|
|
|
|
prg[i].vid_size_v = cgGetNamedParameter(prg[i].vprg, "IN.video_size");
|
|
|
|
prg[i].tex_size_v = cgGetNamedParameter(prg[i].vprg, "IN.texture_size");
|
|
|
|
prg[i].out_size_v = cgGetNamedParameter(prg[i].vprg, "IN.output_size");
|
|
|
|
prg[i].frame_cnt_v = cgGetNamedParameter(prg[i].vprg, "IN.frame_count");
|
|
|
|
prg[i].frame_dir_v = cgGetNamedParameter(prg[i].vprg, "IN.frame_direction");
|
|
|
|
prg[i].mvp = cgGetNamedParameter(prg[i].vprg, "modelViewProj");
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
if (i == RARCH_CG_MENU_SHADER_INDEX)
|
2012-01-25 20:56:21 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
prg[i].orig.tex = cgGetNamedParameter(prg[i].fprg, "ORIG.texture");
|
|
|
|
prg[i].orig.vid_size_v = cgGetNamedParameter(prg[i].vprg, "ORIG.video_size");
|
|
|
|
prg[i].orig.vid_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.video_size");
|
|
|
|
prg[i].orig.tex_size_v = cgGetNamedParameter(prg[i].vprg, "ORIG.texture_size");
|
|
|
|
prg[i].orig.tex_size_f = cgGetNamedParameter(prg[i].fprg, "ORIG.texture_size");
|
|
|
|
prg[i].orig.coord = cgGetNamedParameter(prg[i].vprg, "ORIG.tex_coord");
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < PREV_TEXTURES; j++)
|
|
|
|
{
|
|
|
|
char attr_buf_tex[64];
|
|
|
|
char attr_buf_vid_size[64];
|
|
|
|
char attr_buf_tex_size[64];
|
|
|
|
char attr_buf_coord[64];
|
|
|
|
static const char *prev_names[PREV_TEXTURES] = {
|
|
|
|
"PREV",
|
|
|
|
"PREV1",
|
|
|
|
"PREV2",
|
|
|
|
"PREV3",
|
|
|
|
"PREV4",
|
|
|
|
"PREV5",
|
|
|
|
"PREV6",
|
|
|
|
};
|
|
|
|
|
|
|
|
snprintf(attr_buf_tex, sizeof(attr_buf_tex), "%s.texture", prev_names[j]);
|
|
|
|
snprintf(attr_buf_vid_size, sizeof(attr_buf_vid_size), "%s.video_size", prev_names[j]);
|
|
|
|
snprintf(attr_buf_tex_size, sizeof(attr_buf_tex_size), "%s.texture_size", prev_names[j]);
|
|
|
|
snprintf(attr_buf_coord, sizeof(attr_buf_coord), "%s.tex_coord", prev_names[j]);
|
|
|
|
|
|
|
|
prg[i].prev[j].tex = cgGetNamedParameter(prg[i].fprg, attr_buf_tex);
|
|
|
|
|
|
|
|
prg[i].prev[j].vid_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf_vid_size);
|
|
|
|
prg[i].prev[j].vid_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf_vid_size);
|
|
|
|
|
|
|
|
prg[i].prev[j].tex_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf_tex_size);
|
|
|
|
prg[i].prev[j].tex_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf_tex_size);
|
|
|
|
|
|
|
|
prg[i].prev[j].coord = cgGetNamedParameter(prg[i].vprg, attr_buf_coord);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (unsigned j = 0; j < i - 1; j++)
|
|
|
|
{
|
|
|
|
char attr_buf[64];
|
|
|
|
|
|
|
|
snprintf(attr_buf, sizeof(attr_buf), "PASS%u.texture", j + 1);
|
|
|
|
prg[i].fbo[j].tex = cgGetNamedParameter(prg[i].fprg, attr_buf);
|
|
|
|
|
|
|
|
snprintf(attr_buf, sizeof(attr_buf), "PASS%u.video_size", j + 1);
|
|
|
|
prg[i].fbo[j].vid_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf);
|
|
|
|
prg[i].fbo[j].vid_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf);
|
|
|
|
|
|
|
|
snprintf(attr_buf, sizeof(attr_buf), "PASS%u.texture_size", j + 1);
|
|
|
|
prg[i].fbo[j].tex_size_v = cgGetNamedParameter(prg[i].vprg, attr_buf);
|
|
|
|
prg[i].fbo[j].tex_size_f = cgGetNamedParameter(prg[i].fprg, attr_buf);
|
|
|
|
|
|
|
|
snprintf(attr_buf, sizeof(attr_buf), "PASS%u.tex_coord", j + 1);
|
|
|
|
prg[i].fbo[j].coord = cgGetNamedParameter(prg[i].vprg, attr_buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-22 15:02:09 +00:00
|
|
|
bool gl_cg_init(const char *path)
|
|
|
|
{
|
2012-09-27 15:45:49 +00:00
|
|
|
#ifdef HAVE_CG_RUNTIME_COMPILER
|
2011-12-03 00:26:56 +00:00
|
|
|
cgRTCgcInit();
|
|
|
|
#endif
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-02-20 15:22:58 +00:00
|
|
|
if (!cgCtx)
|
|
|
|
cgCtx = cgCreateContext();
|
|
|
|
|
2011-05-22 15:02:09 +00:00
|
|
|
if (cgCtx == NULL)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Failed to create Cg context\n");
|
2011-05-22 15:02:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-04-21 21:25:32 +00:00
|
|
|
#ifdef RARCH_CG_DEBUG
|
2011-05-23 19:43:08 +00:00
|
|
|
cgGLSetDebugMode(CG_TRUE);
|
|
|
|
cgSetErrorHandler(cg_error_handler, NULL);
|
|
|
|
#endif
|
|
|
|
|
2011-05-22 15:02:09 +00:00
|
|
|
cgFProf = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
|
|
|
cgVProf = cgGLGetLatestProfile(CG_GL_VERTEX);
|
|
|
|
if (cgFProf == CG_PROFILE_UNKNOWN || cgVProf == CG_PROFILE_UNKNOWN)
|
|
|
|
{
|
2012-04-21 21:25:32 +00:00
|
|
|
RARCH_ERR("Invalid profile type\n");
|
2011-05-22 15:02:09 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
cgGLSetOptimalOptions(cgFProf);
|
|
|
|
cgGLSetOptimalOptions(cgVProf);
|
2011-05-22 15:36:18 +00:00
|
|
|
cgGLEnableProfile(cgFProf);
|
|
|
|
cgGLEnableProfile(cgVProf);
|
2011-05-22 15:02:09 +00:00
|
|
|
|
|
|
|
if (strstr(path, ".cgp"))
|
|
|
|
{
|
|
|
|
if (!load_preset(path))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!load_plain(path))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
if (menu_cg_program && !load_menu_shader())
|
|
|
|
return false;
|
|
|
|
|
2011-05-23 19:43:08 +00:00
|
|
|
prg[0].mvp = cgGetNamedParameter(prg[0].vprg, "modelViewProj");
|
|
|
|
|
2011-07-04 11:33:09 +00:00
|
|
|
for (unsigned i = 1; i <= cg_shader_num; i++)
|
2012-01-25 20:56:21 +00:00
|
|
|
set_program_attributes(i);
|
2011-05-23 19:04:25 +00:00
|
|
|
|
2012-01-25 20:56:21 +00:00
|
|
|
if (menu_cg_program)
|
2012-04-21 21:25:32 +00:00
|
|
|
set_program_attributes(RARCH_CG_MENU_SHADER_INDEX);
|
2011-03-06 18:56:35 +00:00
|
|
|
|
|
|
|
cgGLBindProgram(prg[1].fprg);
|
|
|
|
cgGLBindProgram(prg[1].vprg);
|
|
|
|
|
|
|
|
cg_active = true;
|
|
|
|
return true;
|
2011-01-22 23:48:47 +00:00
|
|
|
}
|
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
void gl_cg_use(unsigned index)
|
2011-01-22 23:48:47 +00:00
|
|
|
{
|
2011-05-22 15:02:09 +00:00
|
|
|
if (cg_active && prg[index].vprg && prg[index].fprg)
|
2011-01-22 23:48:47 +00:00
|
|
|
{
|
2011-11-12 17:31:22 +00:00
|
|
|
gl_cg_reset_attrib();
|
|
|
|
|
2011-03-06 18:56:35 +00:00
|
|
|
active_index = index;
|
|
|
|
cgGLBindProgram(prg[index].vprg);
|
|
|
|
cgGLBindProgram(prg[index].fprg);
|
2011-01-22 23:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
2011-03-12 14:30:57 +00:00
|
|
|
|
|
|
|
unsigned gl_cg_num(void)
|
|
|
|
{
|
|
|
|
if (cg_active)
|
2011-05-22 15:02:09 +00:00
|
|
|
return cg_shader_num;
|
2011-03-12 14:30:57 +00:00
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
2011-03-14 20:28:30 +00:00
|
|
|
|
|
|
|
bool gl_cg_filter_type(unsigned index, bool *smooth)
|
|
|
|
{
|
2011-05-22 15:02:09 +00:00
|
|
|
if (cg_active)
|
|
|
|
{
|
|
|
|
if (fbo_smooth[index] == FILTER_UNSPEC)
|
|
|
|
return false;
|
|
|
|
*smooth = (fbo_smooth[index] == FILTER_LINEAR);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return false;
|
2011-03-14 20:28:30 +00:00
|
|
|
}
|
2011-03-14 21:09:35 +00:00
|
|
|
|
2011-03-14 21:51:03 +00:00
|
|
|
void gl_cg_shader_scale(unsigned index, struct gl_fbo_scale *scale)
|
2011-03-14 21:09:35 +00:00
|
|
|
{
|
2011-05-22 15:02:09 +00:00
|
|
|
if (cg_active)
|
|
|
|
*scale = cg_scale[index];
|
|
|
|
else
|
|
|
|
scale->valid = false;
|
2011-03-14 21:09:35 +00:00
|
|
|
}
|
2012-01-25 20:56:21 +00:00
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
void gl_cg_set_menu_shader(const char *path)
|
2012-01-25 20:56:21 +00:00
|
|
|
{
|
|
|
|
if (menu_cg_program)
|
|
|
|
free(menu_cg_program);
|
|
|
|
|
2012-01-25 21:55:34 +00:00
|
|
|
menu_cg_program = strdup(path);
|
2012-01-25 20:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gl_cg_set_compiler_args(const char **argv)
|
|
|
|
{
|
|
|
|
cg_arguments = argv;
|
|
|
|
}
|
|
|
|
|
2012-01-29 22:43:11 +00:00
|
|
|
bool gl_cg_load_shader(unsigned index, const char *path)
|
|
|
|
{
|
|
|
|
if (!cg_active)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (index == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (prg[index].fprg)
|
|
|
|
{
|
|
|
|
cgGLUnbindProgram(cgFProf);
|
|
|
|
|
|
|
|
if (prg[0].fprg != prg[index].fprg)
|
|
|
|
cgDestroyProgram(prg[index].fprg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prg[index].vprg)
|
|
|
|
{
|
|
|
|
cgGLUnbindProgram(cgVProf);
|
|
|
|
|
|
|
|
if (prg[0].vprg != prg[index].vprg)
|
|
|
|
cgDestroyProgram(prg[index].vprg);
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(&prg[index], 0, sizeof(prg[index]));
|
|
|
|
|
2012-05-06 20:34:57 +00:00
|
|
|
if (path)
|
2012-01-29 22:43:11 +00:00
|
|
|
{
|
2012-05-06 20:34:57 +00:00
|
|
|
if (load_program(index, path, true))
|
|
|
|
{
|
|
|
|
set_program_attributes(index);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Always make sure we have a valid shader.
|
2012-05-06 20:38:25 +00:00
|
|
|
prg[index] = prg[0];
|
2012-05-06 20:34:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-01-29 22:43:11 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-06 20:34:57 +00:00
|
|
|
prg[index] = prg[0];
|
|
|
|
return true;
|
2012-01-29 22:43:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-08 16:23:44 +00:00
|
|
|
bool gl_cg_save_cgp(const char *path, const struct gl_cg_cgp_info *info)
|
|
|
|
{
|
|
|
|
if (!info->shader[0] || !*info->shader[0])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
FILE *file = fopen(path, "w");
|
|
|
|
if (!file)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
unsigned shaders = info->shader[1] && *info->shader[1] ? 2 : 1;
|
|
|
|
fprintf(file, "shaders = %u\n", shaders);
|
|
|
|
|
2012-02-20 14:45:38 +00:00
|
|
|
fprintf(file, "shader0 = \"%s\"\n", info->shader[0]);
|
2012-02-08 16:23:44 +00:00
|
|
|
if (shaders == 2)
|
2012-02-20 14:45:38 +00:00
|
|
|
fprintf(file, "shader1 = \"%s\"\n", info->shader[1]);
|
2012-02-08 16:23:44 +00:00
|
|
|
|
|
|
|
fprintf(file, "filter_linear0 = %s\n", info->filter_linear[0] ? "true" : "false");
|
|
|
|
|
|
|
|
if (info->render_to_texture)
|
|
|
|
{
|
|
|
|
fprintf(file, "filter_linear1 = %s\n", info->filter_linear[1] ? "true" : "false");
|
|
|
|
fprintf(file, "scale_type0 = source\n");
|
|
|
|
fprintf(file, "scale0 = %.1f\n", info->fbo_scale);
|
|
|
|
}
|
|
|
|
|
2012-02-20 14:45:38 +00:00
|
|
|
if (info->lut_texture_path && info->lut_texture_id)
|
|
|
|
{
|
|
|
|
fprintf(file, "textures = %s\n", info->lut_texture_id);
|
|
|
|
fprintf(file, "%s = \"%s\"\n",
|
|
|
|
info->lut_texture_id, info->lut_texture_path);
|
|
|
|
|
|
|
|
fprintf(file, "%s_absolute = %s\n",
|
|
|
|
info->lut_texture_id,
|
|
|
|
info->lut_texture_absolute ? "true" : "false");
|
|
|
|
}
|
|
|
|
|
2012-02-08 16:23:44 +00:00
|
|
|
fclose(file);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-02-22 19:45:58 +00:00
|
|
|
void gl_cg_invalidate_context(void)
|
|
|
|
{
|
|
|
|
cgCtx = NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-22 22:35:01 +00:00
|
|
|
unsigned gl_cg_get_lut_info(struct gl_cg_lut_info *info, unsigned elems)
|
|
|
|
{
|
|
|
|
if (!cg_active)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
elems = elems > lut_textures_num ? lut_textures_num : elems;
|
|
|
|
|
|
|
|
for (unsigned i = 0; i < elems; i++)
|
|
|
|
{
|
|
|
|
strlcpy(info[i].id, lut_textures_uniform[i], sizeof(info[i].id));
|
|
|
|
info[i].tex = lut_textures[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
return elems;
|
|
|
|
}
|
|
|
|
|
2012-11-14 21:51:08 +00:00
|
|
|
const gl_shader_backend_t gl_cg_backend = {
|
|
|
|
gl_cg_init,
|
|
|
|
gl_cg_deinit,
|
|
|
|
gl_cg_set_params,
|
|
|
|
gl_cg_use,
|
|
|
|
gl_cg_num,
|
|
|
|
gl_cg_filter_type,
|
|
|
|
gl_cg_shader_scale,
|
|
|
|
gl_cg_set_coords,
|
|
|
|
gl_cg_set_mvp,
|
|
|
|
};
|
|
|
|
|