allow to change graphics engine in options
This commit is contained in:
parent
e6d2e877f0
commit
079b7a5c41
|
@ -1,4 +1,25 @@
|
||||||
Panel
|
Panel
|
||||||
|
Label
|
||||||
|
!text: tr('Graphics Engine:')
|
||||||
|
anchors.left: parent.left
|
||||||
|
anchors.top: parent.top
|
||||||
|
|
||||||
|
ButtonBox
|
||||||
|
anchors.left: prev.right
|
||||||
|
anchors.verticalCenter: prev.verticalCenter
|
||||||
|
id: opengl1
|
||||||
|
text: OpenGL 1
|
||||||
|
size: 80 20
|
||||||
|
margin-left: 6
|
||||||
|
|
||||||
|
ButtonBox
|
||||||
|
anchors.left: prev.right
|
||||||
|
anchors.verticalCenter: prev.verticalCenter
|
||||||
|
id: opengl2
|
||||||
|
text: OpenGL 2
|
||||||
|
size: 80 20
|
||||||
|
margin-left: 4
|
||||||
|
|
||||||
OptionCheckBox
|
OptionCheckBox
|
||||||
id: vsync
|
id: vsync
|
||||||
!text: tr('Enable vertical synchronization')
|
!text: tr('Enable vertical synchronization')
|
||||||
|
|
|
@ -13,6 +13,33 @@ local options = { vsync = true,
|
||||||
showTimestampsInConsole = true,
|
showTimestampsInConsole = true,
|
||||||
showLevelsInConsole = true,
|
showLevelsInConsole = true,
|
||||||
showPrivateMessagesInConsole = false }
|
showPrivateMessagesInConsole = false }
|
||||||
|
local generalPanel
|
||||||
|
local graphicsPanel
|
||||||
|
|
||||||
|
local function setupGraphicsEngines()
|
||||||
|
local enginesRadioGroup = RadioGroup.create()
|
||||||
|
local ogl1 = graphicsPanel:getChildById('opengl1')
|
||||||
|
local ogl2 = graphicsPanel:getChildById('opengl2')
|
||||||
|
enginesRadioGroup:addWidget(ogl1)
|
||||||
|
enginesRadioGroup:addWidget(ogl2)
|
||||||
|
|
||||||
|
if g_graphics.getPainterEngine() == 2 then
|
||||||
|
enginesRadioGroup:selectWidget(ogl2)
|
||||||
|
else
|
||||||
|
enginesRadioGroup:selectWidget(ogl1)
|
||||||
|
end
|
||||||
|
|
||||||
|
ogl1:setEnabled(g_graphics.isPainterEngineAvailable(1))
|
||||||
|
ogl2:setEnabled(g_graphics.isPainterEngineAvailable(2))
|
||||||
|
|
||||||
|
enginesRadioGroup.onSelectionChange = function(self, selected)
|
||||||
|
if selected == ogl1 then
|
||||||
|
g_graphics.selectPainterEngine(1)
|
||||||
|
elseif selected == ogl2 then
|
||||||
|
g_graphics.selectPainterEngine(2)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function Options.init()
|
function Options.init()
|
||||||
-- load options
|
-- load options
|
||||||
|
@ -31,8 +58,14 @@ function Options.init()
|
||||||
optionsButton = TopMenu.addLeftButton('optionsButton', tr('Options') .. ' (Ctrl+P)', 'options.png', Options.toggle)
|
optionsButton = TopMenu.addLeftButton('optionsButton', tr('Options') .. ' (Ctrl+P)', 'options.png', Options.toggle)
|
||||||
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
|
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
|
||||||
optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
|
optionsTabBar:setContentWidget(optionsWindow:getChildById('optionsTabContent'))
|
||||||
optionsTabBar:addTab(tr('General'), loadUI('general.otui'))
|
|
||||||
optionsTabBar:addTab(tr('Graphics'), loadUI('graphics.otui'))
|
generalPanel = loadUI('general.otui')
|
||||||
|
optionsTabBar:addTab(tr('General'), generalPanel)
|
||||||
|
|
||||||
|
graphicsPanel = loadUI('graphics.otui')
|
||||||
|
optionsTabBar:addTab(tr('Graphics'), graphicsPanel)
|
||||||
|
|
||||||
|
setupGraphicsEngines()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Options.terminate()
|
function Options.terminate()
|
||||||
|
@ -43,6 +76,8 @@ function Options.terminate()
|
||||||
optionsButton:destroy()
|
optionsButton:destroy()
|
||||||
optionsButton = nil
|
optionsButton = nil
|
||||||
optionsTabBar = nil
|
optionsTabBar = nil
|
||||||
|
generalPanel = nil
|
||||||
|
graphicsPanel = nil
|
||||||
Options = nil
|
Options = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ OptionCheckBox < CheckBox
|
||||||
MainWindow
|
MainWindow
|
||||||
id: optionsWindow
|
id: optionsWindow
|
||||||
!text: tr('Options')
|
!text: tr('Options')
|
||||||
size: 350 230
|
size: 350 240
|
||||||
|
|
||||||
@onEnter: Options.hide()
|
@onEnter: Options.hide()
|
||||||
@onEscape: Options.hide()
|
@onEscape: Options.hide()
|
||||||
|
|
|
@ -57,5 +57,5 @@ ButtonBox < UICheckBox
|
||||||
color: #80c7f8
|
color: #80c7f8
|
||||||
|
|
||||||
$disabled:
|
$disabled:
|
||||||
color: #f0ad4d88
|
color: #666666ff
|
||||||
image-color: #ffffff88
|
image-color: #ffffff88
|
||||||
|
|
|
@ -53,7 +53,7 @@ bool Module::load()
|
||||||
m_loadCallback();
|
m_loadCallback();
|
||||||
|
|
||||||
m_loaded = true;
|
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());
|
g_modules.updateModuleLoadOrder(asModule());
|
||||||
|
|
||||||
for(const std::string& modName : m_loadLaterModules) {
|
for(const std::string& modName : m_loadLaterModules) {
|
||||||
|
@ -73,7 +73,7 @@ void Module::unload()
|
||||||
if(m_unloadCallback)
|
if(m_unloadCallback)
|
||||||
m_unloadCallback();
|
m_unloadCallback();
|
||||||
m_loaded = false;
|
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());
|
g_modules.updateModuleLoadOrder(asModule());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,39 +152,53 @@ bool Graphics::parseOption(const std::string& option)
|
||||||
return true;
|
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 Graphics::selectPainterEngine(PainterEngine painterEngine)
|
||||||
{
|
{
|
||||||
bool found = false;
|
Painter *painter = nullptr;
|
||||||
#ifdef PAINTER_OGL2
|
#ifdef PAINTER_OGL2
|
||||||
// always prefer OpenGL 2 over OpenGL 1
|
// 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;
|
m_selectedPainterEngine = Painter_OpenGL2;
|
||||||
g_painter = g_painterOGL2;
|
painter = g_painterOGL2;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef PAINTER_OGL1
|
#ifdef PAINTER_OGL1
|
||||||
// fallback to OpenGL 1 in older hardwares
|
// 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;
|
m_selectedPainterEngine = Painter_OpenGL1;
|
||||||
g_painter = g_painterOGL1;
|
painter = g_painterOGL1;
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
// switch painters GL state
|
||||||
if(g_painter)
|
if(painter && painter != g_painter) {
|
||||||
g_painter->unbind();
|
if(g_painter)
|
||||||
g_painter->bind();
|
g_painter->unbind();
|
||||||
|
painter->bind();
|
||||||
|
g_painter = painter;
|
||||||
|
|
||||||
if(painterEngine == Painter_Any)
|
if(painterEngine == Painter_Any)
|
||||||
return true;
|
return true;
|
||||||
return getPainterEngine() == painterEngine;
|
} 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)
|
void Graphics::resize(const Size& size)
|
||||||
|
|
|
@ -32,7 +32,7 @@ public:
|
||||||
Graphics();
|
Graphics();
|
||||||
|
|
||||||
enum PainterEngine {
|
enum PainterEngine {
|
||||||
Painter_Any,
|
Painter_Any = 0,
|
||||||
Painter_OpenGL1,
|
Painter_OpenGL1,
|
||||||
Painter_OpenGL2
|
Painter_OpenGL2
|
||||||
};
|
};
|
||||||
|
@ -41,7 +41,9 @@ public:
|
||||||
void terminate();
|
void terminate();
|
||||||
bool parseOption(const std::string& option);
|
bool parseOption(const std::string& option);
|
||||||
|
|
||||||
|
bool isPainterEngineAvailable(PainterEngine painterEngine);
|
||||||
bool selectPainterEngine(PainterEngine painterEngine);
|
bool selectPainterEngine(PainterEngine painterEngine);
|
||||||
|
PainterEngine getPainterEngine() { return m_selectedPainterEngine; }
|
||||||
|
|
||||||
void resize(const Size& size);
|
void resize(const Size& size);
|
||||||
void beginRender();
|
void beginRender();
|
||||||
|
@ -52,7 +54,6 @@ public:
|
||||||
int getMaxTextureSize() { return m_maxTextureSize; }
|
int getMaxTextureSize() { return m_maxTextureSize; }
|
||||||
const Size& getViewportSize() { return m_viewportSize; }
|
const Size& getViewportSize() { return m_viewportSize; }
|
||||||
TexturePtr& getEmptyTexture() { return m_emptyTexture; }
|
TexturePtr& getEmptyTexture() { return m_emptyTexture; }
|
||||||
PainterEngine getPainterEngine() { return m_selectedPainterEngine; }
|
|
||||||
|
|
||||||
bool canUseDrawArrays();
|
bool canUseDrawArrays();
|
||||||
bool canUseShaders();
|
bool canUseShaders();
|
||||||
|
|
|
@ -192,7 +192,8 @@ void PainterOGL1::setMatrixMode(PainterOGL1::MatrixMode matrixMode)
|
||||||
void PainterOGL1::setProjectionMatrix(const Matrix3& projectionMatrix)
|
void PainterOGL1::setProjectionMatrix(const Matrix3& projectionMatrix)
|
||||||
{
|
{
|
||||||
m_projectionMatrix = projectionMatrix;
|
m_projectionMatrix = projectionMatrix;
|
||||||
updateGlProjectionMatrix();
|
if(g_painter == this)
|
||||||
|
updateGlProjectionMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterOGL1::setTextureMatrix(const Matrix3& textureMatrix)
|
void PainterOGL1::setTextureMatrix(const Matrix3& textureMatrix)
|
||||||
|
|
|
@ -43,6 +43,8 @@ void PainterShaderManager::init()
|
||||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
|
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Vertex, glslMainVertexShader + glslPositionOnlyVertexShader);
|
||||||
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
|
m_drawSolidColorProgram->addShaderFromSourceCode(Shader::Fragment, glslMainFragmentShader + glslSolidColorFragmentShader);
|
||||||
m_drawSolidColorProgram->link();
|
m_drawSolidColorProgram->link();
|
||||||
|
|
||||||
|
PainterShaderProgram::release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PainterShaderManager::terminate()
|
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", "isMaximized", std::bind(&PlatformWindow::isMaximized, &g_window));
|
||||||
g_lua.bindClassStaticFunction("g_window", "hasFocus", std::bind(&PlatformWindow::hasFocus, &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
|
// Logger
|
||||||
g_lua.registerStaticClass("g_logger");
|
g_lua.registerStaticClass("g_logger");
|
||||||
g_lua.bindClassStaticFunction("g_logger", "log", std::bind(&Logger::log, &g_logger, std::placeholders::_1, std::placeholders::_2));
|
g_lua.bindClassStaticFunction("g_logger", "log", std::bind(&Logger::log, &g_logger, std::placeholders::_1, std::placeholders::_2));
|
||||||
|
|
Loading…
Reference in New Issue