VOGONS


First post, by Serious Callers Only

User metadata
Rank Member
Rank
Member

I'm doing a small patch to dosbox to use these from package install.

What i want is to be able to use the files by just specifying their filename (note: not path), like the built in shaders.

So i want to add another fallback after the 'currentdir/shader.glsl' and 'configdir/glshaders/shader.glsl'. Trouble is i don't understand the code very well.

This is the code:

	char* shader_src = render.shader_src;
Prop_path *sh = section->Get_path("glshader");
f = (std::string)sh->GetValue();
if (f.empty() || f=="none") {
free(render.shader_src);
render.shader_src = NULL;
} else if (!RENDER_GetShader(sh->realpath)) {
std::string path;
Cross::GetPlatformConfigDir(path);
path = path + "glshaders" + CROSS_FILESPLIT + f;
if (!RENDER_GetShader(path) && (sh->realpath==f || !RENDER_GetShader(f))) {
sh->SetValue("none");
LOG_MSG("Shader file \"%s\" not found", f.c_str());
}
}

RENDER_GetShader gets the shader definition and returns true if it succeed. I was thinking of changing this code to add another dir fallback - remember this code only runs on the package install, so linux only, so i don't need to care about portable paths

My trouble is not understanding what's the difference between the 'f' from 'sh->getValue' and 'sh->realpath'. It appears that the fail condition is super complicated for no reason if those two are always equal like i suspect, and i could do :

		std::string path;
std::string path2;
Cross::GetPlatformConfigDir(path);
path = path + "glshaders" + CROSS_FILESPLIT + f;
path2 = "/usr/share/dosbox/glshaders/"+f
if (! (RENDER_GetShader(path) || RENDER_GetShader(path2)) ) {
sh->SetValue("none");
LOG_MSG("Shader file \"%s\" not found", f.c_str());
}

Can sh->getValue here really be different from sh->realpath ? If so what's the difference, getValue is the filename and realpath the whole path?

[edit by Dominus: split this off some more shaders for SVN r4319 and later]

Last edited by Dominus on 2020-04-15, 15:14. Edited 3 times in total.

Reply 1 of 9, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

If it's in the right folder you can already use them by name only.

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 2 of 9, by Serious Callers Only

User metadata
Rank Member
Rank
Member
Dominus wrote on 2020-04-15, 11:35:

If it's in the right folder you can already use them by name only.

You're missing the point maybe, i can't place glsl files on a user dir during a package install because it's not allowed, and if it was it would be broken as soon as the user deleted the dosbox conf home. Package files need to go into read only package dirs, to be updated when the package updates (which it does automatically with launchpad ppas). So in order to use the 'small name' i need to have a extra fallback to that system dir.

Reply 3 of 9, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

ok, that wasn't very clear how and why. But anyway, this doesn't seem the right thread for this problem.

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper

Reply 4 of 9, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie
Serious Callers Only wrote on 2020-04-15, 11:30:

Can sh->getValue here really be different from sh->realpath ? If so what's the difference, getValue is the filename and realpath the whole path?

Paths in the config file may be relative to the location of that file, realpath handles that translation.

Reply 5 of 9, by Serious Callers Only

User metadata
Rank Member
Rank
Member

Still confused jmarsh :

else if (!RENDER_GetShader(sh->realpath)) //tries to turn path relative to current conf file and check if it exists,
....
if ( !RENDER_GetShader(path) //if that fails tries to read from config path+raw 'glsl path' string
&& (sh->realpath==f || !RENDER_GetShader(f))) //if that fails, and if the raw path is different from the 'relative to conf' path, try to read from the raw path

Shouldn't the order be
1. check path relative to current conf file
2. check raw path
3. only fallback to confhome+raw after both of these fail?

Like this:

 else if (!RENDER_GetShader(sh->realpath) && (sh->realpath==f || !RENDER_GetShader(f)) ) {
std::string path;
Cross::GetPlatformConfigDir(path);
path = path + "glshaders" + CROSS_FILESPLIT + f;
if ( !RENDER_GetShader(path)) {
sh->SetValue("none");
LOG_MSG("Shader file \"%s\" not found", f.c_str());
}
}

which i'd turn into

 else if (!RENDER_GetShader(sh->realpath) && (sh->realpath==f || !RENDER_GetShader(f)) ) {
std::string path;
std::string path2;
Cross::GetPlatformConfigDir(path);
path = path + "glshaders" + CROSS_FILESPLIT + f;
path2= "/usr/share/dosbox/glsl/"+f;
if ( !RENDER_GetShader(path) && !RENDER_GetShader(path2)) {
sh->SetValue("none");
LOG_MSG("Shader file \"%s\" not found", f.c_str());
}
}

edit: mmh, maybe i should just remove the sh->realpath==f check and reorder. It looks like a optimization.

Last edited by Serious Callers Only on 2020-04-15, 12:55. Edited 3 times in total.

Reply 6 of 9, by jmarsh

User metadata
Rank Oldbie
Rank
Oldbie
Serious Callers Only wrote on 2020-04-15, 12:47:

Shouldn't the order be

No. The ability to override the built-in shaders was intentional in case it was discovered they didn't work with certain hardware.

Reply 7 of 9, by Serious Callers Only

User metadata
Rank Member
Rank
Member

that makes sense.

	} else if (!RENDER_GetShader(sh->realpath)) {
std::string path;
std::string path2;
Cross::GetPlatformConfigDir(path);
path = path + "glshaders" + CROSS_FILESPLIT + f;
path2 = "/usr/share/dosbox/glshaders/"+f;
if ( !RENDER_GetShader(path) && !RENDER_GetShader(path2) && !RENDER_GetShader(f) ) {
sh->SetValue("none");
LOG_MSG("Shader file \"%s\" not found", f.c_str());
}
}

read relative to conf, read from dosbox dir to override, read from the 'fixed' shader path, read raw file. The sh->realpath==f looks like a optimization and it makes my feeble brain not understand the condition, so if it goes away i'm almost sure it's correct. Files in path2 won't be the same as the builtin shaders, and files in the dosbox main dir will override always if not relative to the conf file, so it's ok. I think.

Reply 8 of 9, by Dominus

User metadata
Rank DOSBox Moderator
Rank
DOSBox Moderator

split this from some more shaders for SVN r4319 and later

if you need a more appropriate subject, let me know 😀

Windows 3.1x guide for DOSBox
60 seconds guide to DOSBox
DOSBox SVN snapshot for macOS (10.4-11.x ppc/intel 32/64bit) notarized for gatekeeper