mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
allow to change graphics engine in options
This commit is contained in:
@@ -53,7 +53,7 @@ bool Module::load()
|
||||
m_loadCallback();
|
||||
|
||||
m_loaded = true;
|
||||
g_logger.info(stdext::format("Loaded module '%s'", m_name));
|
||||
//g_logger.info(stdext::format("Loaded module '%s'", m_name));
|
||||
g_modules.updateModuleLoadOrder(asModule());
|
||||
|
||||
for(const std::string& modName : m_loadLaterModules) {
|
||||
@@ -73,7 +73,7 @@ void Module::unload()
|
||||
if(m_unloadCallback)
|
||||
m_unloadCallback();
|
||||
m_loaded = false;
|
||||
g_logger.info(stdext::format("Unloaded module '%s'", m_name));
|
||||
//g_logger.info(stdext::format("Unloaded module '%s'", m_name));
|
||||
g_modules.updateModuleLoadOrder(asModule());
|
||||
}
|
||||
}
|
||||
|
@@ -152,39 +152,53 @@ bool Graphics::parseOption(const std::string& option)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Graphics::isPainterEngineAvailable(Graphics::PainterEngine painterEngine)
|
||||
{
|
||||
#ifdef PAINTER_OGL2
|
||||
if(g_painterOGL2 && painterEngine == Painter_OpenGL2)
|
||||
return true;
|
||||
#endif
|
||||
|
||||
#ifdef PAINTER_OGL1
|
||||
if(g_painterOGL1 && painterEngine == Painter_OpenGL1)
|
||||
return true;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Graphics::selectPainterEngine(PainterEngine painterEngine)
|
||||
{
|
||||
bool found = false;
|
||||
Painter *painter = nullptr;
|
||||
#ifdef PAINTER_OGL2
|
||||
// always prefer OpenGL 2 over OpenGL 1
|
||||
if(!found && g_painterOGL2 && (painterEngine == Painter_OpenGL2 || painterEngine == Painter_Any)) {
|
||||
if(!painter && g_painterOGL2 && (painterEngine == Painter_OpenGL2 || painterEngine == Painter_Any)) {
|
||||
m_selectedPainterEngine = Painter_OpenGL2;
|
||||
g_painter = g_painterOGL2;
|
||||
found = true;
|
||||
painter = g_painterOGL2;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef PAINTER_OGL1
|
||||
// fallback to OpenGL 1 in older hardwares
|
||||
if(!found && g_painterOGL1 && (painterEngine == Painter_OpenGL1 || painterEngine == Painter_Any)) {
|
||||
if(!painter && g_painterOGL1 && (painterEngine == Painter_OpenGL1 || painterEngine == Painter_Any)) {
|
||||
m_selectedPainterEngine = Painter_OpenGL1;
|
||||
g_painter = g_painterOGL1;
|
||||
found = true;
|
||||
painter = g_painterOGL1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(!found)
|
||||
g_logger.fatal("Neither OpenGL 1.0 nor OpenGL 2.0 painter engine is supported by your platform, "
|
||||
"try updating your graphics drivers or your hardware and then run again.");
|
||||
|
||||
// switch painters GL state
|
||||
if(g_painter)
|
||||
g_painter->unbind();
|
||||
g_painter->bind();
|
||||
if(painter && painter != g_painter) {
|
||||
if(g_painter)
|
||||
g_painter->unbind();
|
||||
painter->bind();
|
||||
g_painter = painter;
|
||||
|
||||
if(painterEngine == Painter_Any)
|
||||
return true;
|
||||
return getPainterEngine() == painterEngine;
|
||||
if(painterEngine == Painter_Any)
|
||||
return true;
|
||||
} else
|
||||
g_logger.fatal("Neither OpenGL 1.0 nor OpenGL 2.0 painter engine is supported by your platform, "
|
||||
"try updating your graphics drivers or your hardware and then run again.");
|
||||
|
||||
return m_selectedPainterEngine == painterEngine;
|
||||
}
|
||||
|
||||
void Graphics::resize(const Size& size)
|
||||
|
@@ -32,7 +32,7 @@ public:
|
||||
Graphics();
|
||||
|
||||
enum PainterEngine {
|
||||
Painter_Any,
|
||||
Painter_Any = 0,
|
||||
Painter_OpenGL1,
|
||||
Painter_OpenGL2
|
||||
};
|
||||
@@ -41,8 +41,10 @@ public:
|
||||
void terminate();
|
||||
bool parseOption(const std::string& option);
|
||||
|
||||
bool isPainterEngineAvailable(PainterEngine painterEngine);
|
||||
bool selectPainterEngine(PainterEngine painterEngine);
|
||||
|
||||
PainterEngine getPainterEngine() { return m_selectedPainterEngine; }
|
||||
|
||||
void resize(const Size& size);
|
||||
void beginRender();
|
||||
void endRender();
|
||||
@@ -52,7 +54,6 @@ public:
|
||||
int getMaxTextureSize() { return m_maxTextureSize; }
|
||||
const Size& getViewportSize() { return m_viewportSize; }
|
||||
TexturePtr& getEmptyTexture() { return m_emptyTexture; }
|
||||
PainterEngine getPainterEngine() { return m_selectedPainterEngine; }
|
||||
|
||||
bool canUseDrawArrays();
|
||||
bool canUseShaders();
|
||||
|
@@ -192,7 +192,8 @@ void PainterOGL1::setMatrixMode(PainterOGL1::MatrixMode matrixMode)
|
||||
void PainterOGL1::setProjectionMatrix(const Matrix3& projectionMatrix)
|
||||
{
|
||||
m_projectionMatrix = projectionMatrix;
|
||||
updateGlProjectionMatrix();
|
||||
if(g_painter == this)
|
||||
updateGlProjectionMatrix();
|
||||
}
|
||||
|
||||
void PainterOGL1::setTextureMatrix(const Matrix3& textureMatrix)
|
||||
|
@@ -43,6 +43,8 @@ void PainterShaderManager::init()
|
||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
|
||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
|
||||
m_drawSolidColorProgram->link();
|
||||
|
||||
PainterShaderProgram::release();
|
||||
}
|
||||
|
||||
void PainterShaderManager::terminate()
|
||||
|
@@ -527,6 +527,12 @@ void Application::registerLuaFunctions()
|
||||
g_lua.bindClassStaticFunction("g_window", "isMaximized", std::bind(&PlatformWindow::isMaximized, &g_window));
|
||||
g_lua.bindClassStaticFunction("g_window", "hasFocus", std::bind(&PlatformWindow::hasFocus, &g_window));
|
||||
|
||||
// Graphics
|
||||
g_lua.registerStaticClass("g_graphics");
|
||||
g_lua.bindClassStaticFunction("g_graphics", "isPainterEngineAvailable", std::bind(&Graphics::isPainterEngineAvailable, &g_graphics, std::placeholders::_1));
|
||||
g_lua.bindClassStaticFunction("g_graphics", "selectPainterEngine", std::bind(&Graphics::selectPainterEngine, &g_graphics, std::placeholders::_1));
|
||||
g_lua.bindClassStaticFunction("g_graphics", "getPainterEngine", std::bind(&Graphics::getPainterEngine, &g_graphics));
|
||||
|
||||
// Logger
|
||||
g_lua.registerStaticClass("g_logger");
|
||||
g_lua.bindClassStaticFunction("g_logger", "log", std::bind(&Logger::log, &g_logger, std::placeholders::_1, std::placeholders::_2));
|
||||
|
Reference in New Issue
Block a user