GRAPHICS: Create a dynamic list of available renderers

This allows us to not offer a renderer which is not available on the
platform.
This commit is contained in:
Le Philousophe 2022-04-09 23:07:38 +02:00
parent 6400589ee9
commit 8ec10f5892
3 changed files with 22 additions and 12 deletions

View File

@ -43,12 +43,19 @@ static const RendererTypeDescription rendererTypes[] = {
DECLARE_TRANSLATION_ADDITIONAL_CONTEXT("OpenGL with shaders", "lowres")
const RendererTypeDescription *Renderer::listTypes() {
return rendererTypes;
Common::Array<RendererTypeDescription> Renderer::listTypes() {
uint32 available = getAvailableTypes();
Common::Array<RendererTypeDescription> ret;
for (const RendererTypeDescription *rt = rendererTypes; rt->code; ++rt) {
if (available & rt->id) {
ret.push_back(*rt);
}
}
return ret;
}
RendererType Renderer::parseTypeCode(const Common::String &code) {
const RendererTypeDescription *rt = listTypes();
const RendererTypeDescription *rt = rendererTypes;
while (rt->code) {
if (rt->code == code) {
return rt->id;
@ -60,7 +67,7 @@ RendererType Renderer::parseTypeCode(const Common::String &code) {
}
Common::String Renderer::getTypeCode(RendererType type) {
const RendererTypeDescription *rt = listTypes();
const RendererTypeDescription *rt = rendererTypes;
while (rt->code) {
if (rt->id == type) {
return rt->code;

View File

@ -23,6 +23,7 @@
#define GRAPHICS_RENDERER_H
#include "common/scummsys.h"
#include "common/array.h"
#include "common/str.h"
namespace Graphics {
@ -56,7 +57,7 @@ struct RendererTypeDescription {
class Renderer {
public:
static const RendererTypeDescription *listTypes();
static Common::Array<RendererTypeDescription> listTypes();
/** Convert a renderer code to a RendererType enum value */
static RendererType parseTypeCode(const Common::String &code);
@ -75,7 +76,7 @@ public:
return getBestMatchingType(desired, getAvailableTypes() & supported);
}
};
/** @} */
/** @} */
} // End of namespace Graphics
#endif

View File

@ -1446,12 +1446,14 @@ void OptionsDialog::addGraphicControls(GuiObject *boss, const Common::String &pr
_rendererTypePopUp = new PopUpWidget(boss, prefix + "grRendererTypePopup");
_rendererTypePopUp->appendEntry(_("<default>"), Graphics::kRendererTypeDefault);
_rendererTypePopUp->appendEntry("");
const Graphics::RendererTypeDescription *rt = Graphics::Renderer::listTypes();
for (; rt->code; ++rt) {
if (g_system->getOverlayWidth() > 320)
_rendererTypePopUp->appendEntry(_(rt->description), rt->id);
else
_rendererTypePopUp->appendEntry(_c(rt->description, "lowres"), rt->id);
Common::Array<Graphics::RendererTypeDescription> rt = Graphics::Renderer::listTypes();
for (Common::Array<Graphics::RendererTypeDescription>::iterator it = rt.begin();
it != rt.end(); ++it) {
if (g_system->getOverlayWidth() > 320) {
_rendererTypePopUp->appendEntry(_(it->description), it->id);
} else {
_rendererTypePopUp->appendEntry(_c(it->description, "lowres"), it->id);
}
}
_antiAliasPopUpDesc = new StaticTextWidget(boss, prefix + "grAntiAliasPopupDesc", _("3D Anti-aliasing:"));