1
0
Fork 0

Query SDL for available texture renderers

There's no point in hardcoding these values - they can be different to
every user (it depends on hardware, OS, SDL version, etc).

Also, future versions of SDL might introduce more renderers, so this way
the code is more future-proof.
This commit is contained in:
Patryk Obara 2019-12-25 08:02:17 +01:00 committed by Patryk Obara
parent 6ce7ff8b58
commit a7280cf1f7
3 changed files with 25 additions and 14 deletions

View file

@ -123,6 +123,7 @@ public:
Property(std::string const& _propname, Changeable::Value when):propname(_propname),change(when) { }
void Set_values(const char * const * in);
void Set_values(const std::vector<std::string> &in);
void Set_help(std::string const& str);
char const* Get_help();
virtual bool SetValue(std::string const& str)=0;

View file

@ -1731,6 +1731,21 @@ void GFX_ShowMsg(char const* format,...) {
if (!no_stdout) puts(buf); //Else buf is parsed again. (puts adds end of line)
}
static std::vector<std::string> Get_SDL_TextureRenderers()
{
const int n = SDL_GetNumRenderDrivers();
std::vector<std::string> drivers;
drivers.reserve(n + 1);
drivers.push_back("auto");
SDL_RendererInfo info;
for (int i = 0; i < n; i++) {
if (SDL_GetRenderDriverInfo(i, &info))
continue;
if (info.flags & SDL_RENDERER_TARGETTEXTURE)
drivers.push_back(info.name);
}
return drivers;
}
void Config_Add_SDL() {
Section_prop * sdl_sec=control->AddSection_prop("sdl",&GUI_StartUp);
@ -1772,25 +1787,12 @@ void Config_Add_SDL() {
Pstring->Set_help("What video system to use for output.");
Pstring->Set_values(outputs);
const char *renderers[] = {
"auto",
#ifdef WIN32
"direct3d",
#endif
"opengl",
#ifdef MACOSX
"metal",
#endif
"software",
0
};
Pstring = sdl_sec->Add_string("texture_renderer",
Property::Changeable::Always,
"auto");
Pstring->Set_help("Choose a renderer driver if output=texture or texturenb.\n"
"Use output=auto for an automatic choice.");
Pstring->Set_values(renderers);
Pstring->Set_values(Get_SDL_TextureRenderers());
Pbool = sdl_sec->Add_bool("autolock",Property::Changeable::Always,true);
Pbool->Set_help("Mouse will automatically lock, if you click on the screen. (Press CTRL-F10 to unlock)");

View file

@ -508,6 +508,14 @@ void Property::Set_values(const char * const *in) {
}
}
void Property::Set_values(const std::vector<std::string> & in) {
Value::Etype type = default_value.type;
for (auto &str : in) {
Value val(str, type);
suggested_values.push_back(val);
}
}
Prop_int* Section_prop::Add_int(string const& _propname, Property::Changeable::Value when, int _value) {
Prop_int* test=new Prop_int(_propname,when,_value);
properties.push_back(test);