mirror of
https://github.com/FunkyFr3sh/cnc-ddraw.git
synced 2025-03-14 22:03:27 +01:00
add option to select built-in opengl shaders
This commit is contained in:
parent
62bb150c71
commit
e9f1023a31
@ -778,14 +778,25 @@ void __fastcall TConfigForm::FormCreate(TObject *Sender)
|
||||
|
||||
for (int i = 0; i < list.Length; i++)
|
||||
ShaderCbx->AddItem(list[i], NULL);
|
||||
|
||||
auto shader = ini->ReadString("ddraw", "shader", "");
|
||||
ShaderCbx->ItemIndex = ShaderCbx->Items->IndexOf(shader);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
}
|
||||
|
||||
if (ShaderCbx->Items->Count == 0) {
|
||||
ShaderCbx->AddItem("Nearest neighbor", NULL);
|
||||
ShaderCbx->AddItem("Bilinear", NULL);
|
||||
ShaderCbx->AddItem("Bicubic", NULL);
|
||||
}
|
||||
|
||||
auto shader = ini->ReadString("ddraw", "shader", "Bicubic");
|
||||
ShaderCbx->ItemIndex = ShaderCbx->Items->IndexOf(shader);
|
||||
|
||||
if (ShaderCbx->ItemIndex == -1) {
|
||||
ShaderCbx->AddItem(shader, NULL);
|
||||
ShaderCbx->ItemIndex = ShaderCbx->Items->Count - 1;
|
||||
}
|
||||
|
||||
int d3d9_filter = ini->ReadInteger("ddraw", "d3d9_filter", 2);
|
||||
|
||||
switch (d3d9_filter) {
|
||||
|
@ -15,25 +15,25 @@ const char PASSTHROUGH_VERT_SHADER_110[] =
|
||||
|
||||
const char PALETTE_FRAG_SHADER_110[] =
|
||||
"#version 110\n"
|
||||
"uniform sampler2D SurfaceTex; \n"
|
||||
"uniform sampler2D PaletteTex; \n"
|
||||
"uniform sampler2D Texture; \n"
|
||||
"uniform sampler2D PaletteTexture; \n"
|
||||
"varying vec2 TEX0; \n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 pIndex = texture2D(SurfaceTex, TEX0); \n"
|
||||
" gl_FragColor = texture2D(PaletteTex, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0)); \n"
|
||||
" vec4 pIndex = texture2D(Texture, TEX0); \n"
|
||||
" gl_FragColor = texture2D(PaletteTexture, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0)); \n"
|
||||
"}\n";
|
||||
|
||||
|
||||
const char PASSTHROUGH_FRAG_SHADER_110[] =
|
||||
"#version 110\n"
|
||||
"uniform sampler2D SurfaceTex; \n"
|
||||
"uniform sampler2D Texture; \n"
|
||||
"varying vec2 TEX0; \n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 texel = texture2D(SurfaceTex, TEX0); \n"
|
||||
" vec4 texel = texture2D(Texture, TEX0); \n"
|
||||
" gl_FragColor = texel; \n"
|
||||
"}\n";
|
||||
|
||||
@ -59,26 +59,26 @@ const char PASSTHROUGH_VERT_SHADER[] =
|
||||
const char PALETTE_FRAG_SHADER[] =
|
||||
"#version 130\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform sampler2D SurfaceTex;\n"
|
||||
"uniform sampler2D PaletteTex;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"uniform sampler2D PaletteTexture;\n"
|
||||
"in vec4 TEX0;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 pIndex = texture(SurfaceTex, TEX0.xy);\n"
|
||||
" FragColor = texture(PaletteTex, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0));\n"
|
||||
" vec4 pIndex = texture(Texture, TEX0.xy);\n"
|
||||
" FragColor = texture(PaletteTexture, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0));\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
const char PASSTHROUGH_FRAG_SHADER[] =
|
||||
"#version 130\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform sampler2D SurfaceTex;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec4 TEX0;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 texel = texture(SurfaceTex, TEX0.xy);\n"
|
||||
" vec4 texel = texture(Texture, TEX0.xy);\n"
|
||||
" FragColor = texel;\n"
|
||||
"}\n";
|
||||
|
||||
@ -104,26 +104,26 @@ const char PASSTHROUGH_VERT_SHADER_CORE[] =
|
||||
const char PALETTE_FRAG_SHADER_CORE[] =
|
||||
"#version 150\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform sampler2D SurfaceTex;\n"
|
||||
"uniform sampler2D PaletteTex;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"uniform sampler2D PaletteTexture;\n"
|
||||
"in vec4 TEX0;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 pIndex = texture(SurfaceTex, TEX0.xy);\n"
|
||||
" FragColor = texture(PaletteTex, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0));\n"
|
||||
" vec4 pIndex = texture(Texture, TEX0.xy);\n"
|
||||
" FragColor = texture(PaletteTexture, vec2(pIndex.r * (255.0/256.0) + (0.5/256.0), 0));\n"
|
||||
"}\n";
|
||||
|
||||
|
||||
const char PASSTHROUGH_FRAG_SHADER_CORE[] =
|
||||
"#version 150\n"
|
||||
"out vec4 FragColor;\n"
|
||||
"uniform sampler2D SurfaceTex;\n"
|
||||
"uniform sampler2D Texture;\n"
|
||||
"in vec4 TEX0;\n"
|
||||
"\n"
|
||||
"void main()\n"
|
||||
"{\n"
|
||||
" vec4 texel = texture(SurfaceTex, TEX0.xy);\n"
|
||||
" vec4 texel = texture(Texture, TEX0.xy);\n"
|
||||
" FragColor = texel;\n"
|
||||
"}\n";
|
||||
|
||||
|
@ -275,7 +275,8 @@ static void cfg_create_ini()
|
||||
"\n"
|
||||
"; Preliminary libretro shader support - (Requires 'renderer=opengl*') https://github.com/libretro/glsl-shaders\n"
|
||||
"; 2x scaling example: https://imgur.com/a/kxsM1oY - 4x scaling example: https://imgur.com/a/wjrhpFV\n"
|
||||
"; Note: Defauls to Bicubic Catmull-Rom if no shader specified or file was not found\n"
|
||||
"; You can specify a full path to a .glsl shader file here or use one of the values listed below\n"
|
||||
"; Possible values: Nearest neighbor, Bilinear, Bicubic\n"
|
||||
"shader=Shaders\\cubic\\catmull-rom-bilinear.glsl\n"
|
||||
"\n"
|
||||
"; Window position, -32000 = center to screen\n"
|
||||
|
@ -185,15 +185,24 @@ static void ogl_build_programs()
|
||||
(g_ddraw->render.viewport.width != g_ddraw->width ||
|
||||
g_ddraw->render.viewport.height != g_ddraw->height))
|
||||
{
|
||||
g_ogl.scale_program = oglu_build_program(PASSTHROUGH_VERT_SHADER, CATMULL_ROM_FRAG_SHADER);
|
||||
g_ogl.scale_program =
|
||||
oglu_build_program(
|
||||
PASSTHROUGH_VERT_SHADER,
|
||||
_stricmp(g_ddraw->shader, "Nearest neighbor") == 0 ? PASSTHROUGH_FRAG_SHADER :
|
||||
_stricmp(g_ddraw->shader, "Bilinear") == 0 ? PASSTHROUGH_FRAG_SHADER :
|
||||
CATMULL_ROM_FRAG_SHADER);
|
||||
|
||||
if (!g_ogl.scale_program)
|
||||
{
|
||||
g_ogl.scale_program =
|
||||
oglu_build_program(PASSTHROUGH_VERT_SHADER_CORE, CATMULL_ROM_FRAG_SHADER_CORE);
|
||||
oglu_build_program(
|
||||
PASSTHROUGH_VERT_SHADER_CORE,
|
||||
_stricmp(g_ddraw->shader, "Nearest neighbor") == 0 ? PASSTHROUGH_FRAG_SHADER_CORE :
|
||||
_stricmp(g_ddraw->shader, "Bilinear") == 0 ? PASSTHROUGH_FRAG_SHADER_CORE :
|
||||
CATMULL_ROM_FRAG_SHADER_CORE);
|
||||
}
|
||||
|
||||
bilinear = TRUE;
|
||||
bilinear = _stricmp(g_ddraw->shader, "Nearest neighbor") != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -365,10 +374,10 @@ static void ogl_init_main_program()
|
||||
|
||||
glUseProgram(g_ogl.main_program);
|
||||
|
||||
glUniform1i(glGetUniformLocation(g_ogl.main_program, "SurfaceTex"), 0);
|
||||
glUniform1i(glGetUniformLocation(g_ogl.main_program, "Texture"), 0);
|
||||
|
||||
if (g_ddraw->bpp == 8)
|
||||
glUniform1i(glGetUniformLocation(g_ogl.main_program, "PaletteTex"), 1);
|
||||
glUniform1i(glGetUniformLocation(g_ogl.main_program, "PaletteTexture"), 1);
|
||||
|
||||
if (g_oglu_got_version3)
|
||||
{
|
||||
@ -521,11 +530,25 @@ static void ogl_init_scale_program()
|
||||
output_size[0] = (float)g_ddraw->render.viewport.width;
|
||||
output_size[1] = (float)g_ddraw->render.viewport.height;
|
||||
|
||||
glUniform2fv(glGetUniformLocation(g_ogl.scale_program, "OutputSize"), 1, output_size);
|
||||
glUniform2fv(glGetUniformLocation(g_ogl.scale_program, "TextureSize"), 1, texture_size);
|
||||
glUniform2fv(glGetUniformLocation(g_ogl.scale_program, "InputSize"), 1, input_size);
|
||||
glUniform1i(glGetUniformLocation(g_ogl.scale_program, "FrameDirection"), 1);
|
||||
glUniform1i(glGetUniformLocation(g_ogl.scale_program, "Texture"), 0);
|
||||
GLint loc = glGetUniformLocation(g_ogl.scale_program, "OutputSize");
|
||||
if (loc != -1)
|
||||
glUniform2fv(loc, 1, output_size);
|
||||
|
||||
loc = glGetUniformLocation(g_ogl.scale_program, "TextureSize");
|
||||
if (loc != -1)
|
||||
glUniform2fv(loc, 1, texture_size);
|
||||
|
||||
loc = glGetUniformLocation(g_ogl.scale_program, "InputSize");
|
||||
if (loc != -1)
|
||||
glUniform2fv(loc, 1, input_size);
|
||||
|
||||
loc = glGetUniformLocation(g_ogl.scale_program, "FrameDirection");
|
||||
if (loc != -1)
|
||||
glUniform1i(loc, 1);
|
||||
|
||||
loc = glGetUniformLocation(g_ogl.scale_program, "Texture");
|
||||
if (loc != -1)
|
||||
glUniform1i(loc, 0);
|
||||
|
||||
const float mvp_matrix[16] = {
|
||||
1,0,0,0,
|
||||
|
Loading…
x
Reference in New Issue
Block a user