2018-11-15 23:42:29 +00:00
|
|
|
/*****************************************************************************\
|
|
|
|
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
|
|
|
|
This file is licensed under the Snes9x License.
|
|
|
|
For further information, consult the LICENSE file in the root directory.
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
2018-05-24 09:55:17 +00:00
|
|
|
#ifndef __GLSL_H
|
|
|
|
#define __GLSL_H
|
|
|
|
|
2023-04-27 21:20:09 +00:00
|
|
|
#include "snes9x.h"
|
|
|
|
#include "../vulkan/slang_preset_ini.hpp"
|
2018-05-13 23:12:30 +00:00
|
|
|
#include "shader_platform.h"
|
2019-01-08 23:18:17 +00:00
|
|
|
#include <deque>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <vector>
|
2018-05-11 22:08:13 +00:00
|
|
|
|
|
|
|
static const unsigned int glsl_max_passes = 20;
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2019-01-08 23:18:17 +00:00
|
|
|
typedef void (*GLSLViewportCallback)(int source_width, int source_height,
|
|
|
|
int viewport_x, int viewport_y,
|
|
|
|
int viewport_width, int viewport_height,
|
|
|
|
int *out_dst_x, int *out_dst_y,
|
|
|
|
int *out_dst_width, int *out_dst_height);
|
2018-05-21 19:15:31 +00:00
|
|
|
|
2018-05-10 23:47:55 +00:00
|
|
|
enum GLSLScaleType
|
|
|
|
{
|
|
|
|
GLSL_NONE = 0,
|
|
|
|
GLSL_SOURCE,
|
|
|
|
GLSL_VIEWPORT,
|
|
|
|
GLSL_ABSOLUTE
|
|
|
|
};
|
|
|
|
|
|
|
|
enum GLSLFilter
|
|
|
|
{
|
|
|
|
GLSL_UNDEFINED = 0,
|
|
|
|
};
|
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct GLSLUniformMetrics
|
2018-05-10 23:47:55 +00:00
|
|
|
{
|
|
|
|
GLint Texture;
|
|
|
|
GLint InputSize;
|
|
|
|
GLint TextureSize;
|
|
|
|
GLint TexCoord;
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct GLSLUniforms
|
2018-05-10 23:47:55 +00:00
|
|
|
{
|
|
|
|
GLint Texture;
|
|
|
|
GLint InputSize;
|
|
|
|
GLint OutputSize;
|
|
|
|
GLint TextureSize;
|
|
|
|
|
|
|
|
GLint FrameCount;
|
|
|
|
GLint FrameDirection;
|
|
|
|
|
|
|
|
GLint TexCoord;
|
|
|
|
GLint LUTTexCoord;
|
|
|
|
GLint VertexCoord;
|
|
|
|
|
|
|
|
GLint OrigTexture;
|
|
|
|
GLint OrigInputSize;
|
|
|
|
GLint OrigTextureSize;
|
|
|
|
GLint OrigTexCoord;
|
|
|
|
|
|
|
|
unsigned int max_pass;
|
|
|
|
unsigned int max_prevpass;
|
|
|
|
GLSLUniformMetrics Prev[7];
|
2018-05-11 22:08:13 +00:00
|
|
|
GLSLUniformMetrics Pass[glsl_max_passes];
|
|
|
|
GLSLUniformMetrics PassPrev[glsl_max_passes];
|
2018-05-10 23:47:55 +00:00
|
|
|
GLint Lut[9];
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2019-01-25 19:28:24 +00:00
|
|
|
// Size must always follow texture type
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SL_INVALID = 0,
|
|
|
|
SL_PASSTEXTURE = 1,
|
|
|
|
SL_PASSSIZE = 2,
|
|
|
|
SL_PREVIOUSFRAMETEXTURE = 3,
|
|
|
|
SL_PREVIOUSFRAMESIZE = 4,
|
|
|
|
SL_LUTTEXTURE = 5,
|
|
|
|
SL_LUTSIZE = 6,
|
|
|
|
SL_MVP = 7,
|
|
|
|
SL_FRAMECOUNT = 8,
|
2019-01-27 22:28:18 +00:00
|
|
|
SL_PARAM = 9,
|
|
|
|
SL_FEEDBACK = 10
|
2019-01-25 19:28:24 +00:00
|
|
|
};
|
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct SlangUniform
|
2019-01-25 19:28:24 +00:00
|
|
|
{
|
|
|
|
// Source
|
|
|
|
int type;
|
|
|
|
int num;
|
|
|
|
|
|
|
|
// Output
|
|
|
|
GLint location; // -1 Indicates UBO
|
|
|
|
GLint offset;
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2019-01-25 19:28:24 +00:00
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct GLSLPass
|
2018-05-10 23:47:55 +00:00
|
|
|
{
|
|
|
|
char filename[PATH_MAX];
|
2018-05-11 20:56:58 +00:00
|
|
|
char alias[256];
|
2018-05-10 23:47:55 +00:00
|
|
|
int scale_type_x;
|
|
|
|
int scale_type_y;
|
|
|
|
float scale_x;
|
|
|
|
float scale_y;
|
|
|
|
bool fp;
|
2018-05-11 20:56:58 +00:00
|
|
|
bool srgb;
|
2018-05-10 23:47:55 +00:00
|
|
|
int frame_count_mod;
|
|
|
|
unsigned int frame_count;
|
|
|
|
|
|
|
|
GLuint program;
|
|
|
|
GLuint vertex_shader;
|
|
|
|
GLuint fragment_shader;
|
|
|
|
GLuint texture;
|
2018-05-14 19:27:07 +00:00
|
|
|
GLuint wrap_mode;
|
2018-05-10 23:47:55 +00:00
|
|
|
GLuint fbo;
|
|
|
|
GLuint width;
|
|
|
|
GLuint height;
|
|
|
|
GLuint filter;
|
2019-01-28 02:14:28 +00:00
|
|
|
bool mipmap_input;
|
2018-05-10 23:47:55 +00:00
|
|
|
|
|
|
|
GLSLUniforms unif;
|
2019-01-25 19:28:24 +00:00
|
|
|
#ifdef USE_SLANG
|
|
|
|
GLuint format;
|
|
|
|
std::vector<SlangUniform> uniforms;
|
|
|
|
std::vector<uint8_t> ubo_buffer;
|
|
|
|
GLuint ubo;
|
2019-01-27 23:43:22 +00:00
|
|
|
bool uses_feedback = false;
|
2019-01-27 22:28:18 +00:00
|
|
|
GLuint feedback_texture;
|
2019-01-25 19:28:24 +00:00
|
|
|
#endif
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct GLSLLut
|
2018-05-10 23:47:55 +00:00
|
|
|
{
|
2018-05-11 22:08:13 +00:00
|
|
|
char id[256];
|
2018-05-10 23:47:55 +00:00
|
|
|
char filename[PATH_MAX];
|
|
|
|
GLuint filter;
|
|
|
|
GLuint texture;
|
2018-05-11 20:56:58 +00:00
|
|
|
GLuint wrap_mode;
|
|
|
|
bool mipmap;
|
2019-01-25 19:28:24 +00:00
|
|
|
int width;
|
|
|
|
int height;
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct GLSLParam
|
2018-05-10 23:47:55 +00:00
|
|
|
{
|
2022-06-15 00:09:51 +00:00
|
|
|
std::string name;
|
|
|
|
std::string id;
|
2018-05-10 23:47:55 +00:00
|
|
|
float min;
|
|
|
|
float max;
|
2018-05-11 22:08:13 +00:00
|
|
|
float val;
|
2018-05-10 23:47:55 +00:00
|
|
|
float step;
|
2020-07-04 22:53:38 +00:00
|
|
|
int digits;
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2020-08-07 19:59:03 +00:00
|
|
|
struct GLSLShader
|
2018-05-10 23:47:55 +00:00
|
|
|
{
|
2020-06-30 21:53:52 +00:00
|
|
|
bool load_shader(const char *filename);
|
|
|
|
bool load_shader_preset_file(const char *filename);
|
2019-01-08 23:18:17 +00:00
|
|
|
void render(GLuint &orig, int width, int height, int viewport_x,
|
|
|
|
int viewport_y, int viewport_width, int viewport_height,
|
|
|
|
GLSLViewportCallback vpcallback);
|
2019-01-27 23:43:22 +00:00
|
|
|
void set_shader_vars(unsigned int pass, bool inverted);
|
2019-01-25 19:28:24 +00:00
|
|
|
void clear_shader_vars();
|
2019-01-30 16:25:19 +00:00
|
|
|
void read_shader_file_with_includes(std::string filename,
|
|
|
|
std::vector<std::string> &lines,
|
|
|
|
int p);
|
2019-01-09 01:43:51 +00:00
|
|
|
GLuint compile_shader(std::vector<std::string> &lines, const char *aliases,
|
2019-01-08 23:18:17 +00:00
|
|
|
const char *defines, GLuint type, GLuint *out);
|
|
|
|
void save(const char *filename);
|
2019-01-25 19:28:24 +00:00
|
|
|
void destroy();
|
|
|
|
void register_uniforms();
|
2018-05-10 23:47:55 +00:00
|
|
|
|
2023-04-27 21:20:09 +00:00
|
|
|
IniFile ini;
|
2018-05-11 22:08:13 +00:00
|
|
|
|
2018-05-10 23:47:55 +00:00
|
|
|
std::vector<GLSLPass> pass;
|
|
|
|
std::vector<GLSLLut> lut;
|
|
|
|
std::vector<GLSLParam> param;
|
2022-06-15 00:09:51 +00:00
|
|
|
std::vector<std::vector<GLint>> unif;
|
|
|
|
|
2018-05-10 23:47:55 +00:00
|
|
|
int max_prev_frame;
|
|
|
|
std::deque<GLSLPass> prev_frame;
|
|
|
|
std::vector<GLuint> vaos;
|
|
|
|
|
|
|
|
unsigned int frame_count;
|
|
|
|
GLuint vbo;
|
2019-01-25 19:28:24 +00:00
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
bool using_slang;
|
2019-01-25 19:28:24 +00:00
|
|
|
#ifdef USE_SLANG
|
|
|
|
std::string slang_get_stage(std::vector<std::string> &lines,
|
|
|
|
std::string name);
|
|
|
|
GLint slang_compile(std::vector<std::string> &lines, std::string stage);
|
|
|
|
void slang_introspect();
|
2019-01-27 23:43:22 +00:00
|
|
|
void slang_set_shader_vars(int p, bool inverted);
|
2019-01-25 19:28:24 +00:00
|
|
|
void slang_clear_shader_vars();
|
2019-01-27 22:28:18 +00:00
|
|
|
|
2019-01-29 23:49:40 +00:00
|
|
|
bool using_feedback;
|
2019-01-25 19:28:24 +00:00
|
|
|
#endif
|
2020-08-07 19:59:03 +00:00
|
|
|
};
|
2018-05-24 09:55:17 +00:00
|
|
|
|
2018-11-15 23:42:29 +00:00
|
|
|
#endif
|