allow to change graphics engine in options

This commit is contained in:
Eduardo Bart 2012-06-02 18:41:20 -03:00
parent e6d2e877f0
commit 079b7a5c41
10 changed files with 107 additions and 27 deletions

View File

@ -1,4 +1,25 @@
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
id: vsync
!text: tr('Enable vertical synchronization')

View File

@ -13,6 +13,33 @@ local options = { vsync = true,
showTimestampsInConsole = true,
showLevelsInConsole = true,
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()
-- load options
@ -31,8 +58,14 @@ function Options.init()
optionsButton = TopMenu.addLeftButton('optionsButton', tr('Options') .. ' (Ctrl+P)', 'options.png', Options.toggle)
optionsTabBar = optionsWindow:getChildById('optionsTabBar')
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
function Options.terminate()
@ -43,6 +76,8 @@ function Options.terminate()
optionsButton:destroy()
optionsButton = nil
optionsTabBar = nil
generalPanel = nil
graphicsPanel = nil
Options = nil
end

View File

@ -17,7 +17,7 @@ OptionCheckBox < CheckBox
MainWindow
id: optionsWindow
!text: tr('Options')
size: 350 230
size: 350 240
@onEnter: Options.hide()
@onEscape: Options.hide()

View File

@ -57,5 +57,5 @@ ButtonBox < UICheckBox
color: #80c7f8
$disabled:
color: #f0ad4d88
color: #666666ff
image-color: #ffffff88

View File

@ -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());
}
}

View File

@ -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)

View File

@ -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();

View File

@ -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)

View File

@ -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()

View File

@ -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));