From ff44637d49b65c11f4f831aadac1ef1123cadeed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Tue, 16 Jun 2015 15:31:59 +0200 Subject: [PATCH] Removed VBO override switch and some unnecessary code --- src/app/app.cpp | 29 ++----------- src/app/app.h | 9 ++-- src/graphics/core/device.h | 3 ++ src/graphics/core/nulldevice.cpp | 4 ++ src/graphics/core/nulldevice.h | 2 + src/graphics/opengl/gl21device.cpp | 4 +- src/graphics/opengl/gl21device.h | 6 +-- src/graphics/opengl/gl33device.cpp | 4 +- src/graphics/opengl/gl33device.h | 6 +-- src/graphics/opengl/gldevice.cpp | 69 ++++++++++-------------------- src/graphics/opengl/gldevice.h | 9 ++-- src/graphics/opengl/glutil.cpp | 14 +----- src/graphics/opengl/glutil.h | 28 +----------- 13 files changed, 54 insertions(+), 133 deletions(-) diff --git a/src/app/app.cpp b/src/app/app.cpp index b9961b3e..a558437e 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -224,7 +224,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) OPT_DATADIR, OPT_SAVEDIR, OPT_MOD, - OPT_VBO, OPT_RESOLUTION, OPT_HEADLESS, OPT_DEVICE @@ -242,7 +241,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) { "datadir", required_argument, nullptr, OPT_DATADIR }, { "savedir", required_argument, nullptr, OPT_SAVEDIR }, { "mod", required_argument, nullptr, OPT_MOD }, - { "vbo", required_argument, nullptr, OPT_VBO }, { "resolution", required_argument, nullptr, OPT_RESOLUTION }, { "headless", no_argument, nullptr, OPT_HEADLESS }, { "graphics", required_argument, nullptr, OPT_DEVICE }, @@ -286,7 +284,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) GetLogger()->Message(" -datadir path set custom data directory path\n"); GetLogger()->Message(" -savedir path set custom save directory path (must be writable)\n"); GetLogger()->Message(" -mod path load datadir mod from given path\n"); - GetLogger()->Message(" -vbo mode set OpenGL VBO mode (one of: auto, enable, disable)\n"); GetLogger()->Message(" -resolution WxH set resolution\n"); GetLogger()->Message(" -headless headless mode - disables graphics, sound and user interaction\n"); GetLogger()->Message(" -graphics changes graphics device (defaults to opengl)\n"); @@ -351,24 +348,6 @@ ParseArgsStatus CApplication::ParseArguments(int argc, char *argv[]) m_language = language; break; } - case OPT_VBO: - { - std::string vbo; - vbo = optarg; - if (vbo == "auto") - m_deviceConfig.vboMode = Gfx::VBO_MODE_AUTO; - else if (vbo == "enable") - m_deviceConfig.vboMode = Gfx::VBO_MODE_ENABLE; - else if (vbo == "disable") - m_deviceConfig.vboMode = Gfx::VBO_MODE_DISABLE; - else - { - GetLogger()->Error("Invalid vbo mode: '%s'\n", optarg); - return PARSE_ARGS_FAIL; - } - - break; - } case OPT_DATADIR: { m_pathManager->SetDataPath(optarg); @@ -718,7 +697,7 @@ bool CApplication::IsRestarting() return m_restart; } -bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig) +bool CApplication::ChangeVideoConfig(const Gfx::DeviceConfig &newConfig) { static bool restore = false; @@ -765,7 +744,7 @@ bool CApplication::ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig) } } - ( static_cast(m_device) )->ConfigChanged(m_deviceConfig); + m_device->ConfigChanged(m_deviceConfig); m_engine->ResetAfterDeviceChanged(); m_controller->GetRobotMain()->ResetAfterDeviceChanged(); @@ -1060,7 +1039,7 @@ Event CApplication::ProcessSystemEvent() } else if (m_private->currentEvent.type == SDL_VIDEORESIZE) { - Gfx::GLDeviceConfig newConfig = m_deviceConfig; + Gfx::DeviceConfig newConfig = m_deviceConfig; newConfig.size.x = m_private->currentEvent.resize.w; newConfig.size.y = m_private->currentEvent.resize.h; if (newConfig.size != m_deviceConfig.size) @@ -1384,7 +1363,7 @@ long long CApplication::GetRealRelTime() const return m_realRelTime; } -Gfx::GLDeviceConfig CApplication::GetVideoConfig() const +Gfx::DeviceConfig CApplication::GetVideoConfig() const { return m_deviceConfig; } diff --git a/src/app/app.h b/src/app/app.h index 7e1ecdb2..c4c3427d 100644 --- a/src/app/app.h +++ b/src/app/app.h @@ -31,7 +31,6 @@ #include "graphics/core/device.h" #include "graphics/engine/engine.h" -#include "graphics/opengl/gldevice.h" #include @@ -223,10 +222,10 @@ public: bool fullScreen, bool resizeable) const; //! Returns the current video mode - Gfx::GLDeviceConfig GetVideoConfig() const; + Gfx::DeviceConfig GetVideoConfig() const; //! Change the video mode to given mode - bool ChangeVideoConfig(const Gfx::GLDeviceConfig &newConfig); + bool ChangeVideoConfig(const Gfx::DeviceConfig &newConfig); //! Suspends animation (time will not be updated) void SuspendSimulation(); @@ -394,9 +393,9 @@ protected: std::string m_errorMessage; //! Current configuration of OpenGL display device - Gfx::GLDeviceConfig m_deviceConfig; + Gfx::DeviceConfig m_deviceConfig; //! Previous configuration of OpenGL display device - Gfx::GLDeviceConfig m_lastDeviceConfig; + Gfx::DeviceConfig m_lastDeviceConfig; //! Text set as window title std::string m_windowTitle; diff --git a/src/graphics/core/device.h b/src/graphics/core/device.h index 74600c81..db8b9225 100644 --- a/src/graphics/core/device.h +++ b/src/graphics/core/device.h @@ -286,6 +286,9 @@ public: //! Destroys the device, releasing every acquired resource virtual void Destroy() = 0; + //! Changes configuration + virtual void ConfigChanged(const DeviceConfig &newConfig) = 0; + //! Begins drawing the 3D scene virtual void BeginScene() = 0; //! Ends drawing the 3D scene diff --git a/src/graphics/core/nulldevice.cpp b/src/graphics/core/nulldevice.cpp index 3fe45a09..a983c502 100644 --- a/src/graphics/core/nulldevice.cpp +++ b/src/graphics/core/nulldevice.cpp @@ -57,6 +57,10 @@ void CNullDevice::Destroy() { } +void CNullDevice::ConfigChanged(const DeviceConfig &newConfig) +{ +} + void CNullDevice::BeginScene() { } diff --git a/src/graphics/core/nulldevice.h b/src/graphics/core/nulldevice.h index 583747d0..bf84a571 100644 --- a/src/graphics/core/nulldevice.h +++ b/src/graphics/core/nulldevice.h @@ -46,6 +46,8 @@ public: virtual bool Create(); virtual void Destroy(); + + virtual void ConfigChanged(const DeviceConfig &newConfig); virtual void BeginScene(); virtual void EndScene(); diff --git a/src/graphics/opengl/gl21device.cpp b/src/graphics/opengl/gl21device.cpp index f5f1d81d..ead25120 100644 --- a/src/graphics/opengl/gl21device.cpp +++ b/src/graphics/opengl/gl21device.cpp @@ -38,7 +38,7 @@ // Graphics module namespace namespace Gfx { -CGL21Device::CGL21Device(const GLDeviceConfig &config) +CGL21Device::CGL21Device(const DeviceConfig &config) { m_config = config; m_lighting = false; @@ -378,7 +378,7 @@ void CGL21Device::Destroy() m_textureStageParams.clear(); } -void CGL21Device::ConfigChanged(const GLDeviceConfig& newConfig) +void CGL21Device::ConfigChanged(const DeviceConfig& newConfig) { m_config = newConfig; diff --git a/src/graphics/opengl/gl21device.h b/src/graphics/opengl/gl21device.h index 2ca150cd..6e3655ed 100644 --- a/src/graphics/opengl/gl21device.h +++ b/src/graphics/opengl/gl21device.h @@ -52,7 +52,7 @@ struct GLDevicePrivate; class CGL21Device : public CDevice { public: - CGL21Device(const GLDeviceConfig &config); + CGL21Device(const DeviceConfig &config); virtual ~CGL21Device(); virtual void DebugHook() OVERRIDE; @@ -61,7 +61,7 @@ public: virtual bool Create() OVERRIDE; virtual void Destroy() OVERRIDE; - void ConfigChanged(const GLDeviceConfig &newConfig); + virtual void ConfigChanged(const DeviceConfig &newConfig) OVERRIDE; virtual void BeginScene() OVERRIDE; virtual void EndScene() OVERRIDE; @@ -157,7 +157,7 @@ private: private: //! Current config - GLDeviceConfig m_config; + DeviceConfig m_config; //! Current world matrix Math::Matrix m_worldMat; diff --git a/src/graphics/opengl/gl33device.cpp b/src/graphics/opengl/gl33device.cpp index e323fc75..599f799e 100644 --- a/src/graphics/opengl/gl33device.cpp +++ b/src/graphics/opengl/gl33device.cpp @@ -37,7 +37,7 @@ // Graphics module namespace namespace Gfx { -CGL33Device::CGL33Device(const GLDeviceConfig &config) +CGL33Device::CGL33Device(const DeviceConfig &config) { m_config = config; m_lighting = false; @@ -408,7 +408,7 @@ void CGL33Device::Destroy() m_textureStageParams.clear(); } -void CGL33Device::ConfigChanged(const GLDeviceConfig& newConfig) +void CGL33Device::ConfigChanged(const DeviceConfig& newConfig) { m_config = newConfig; diff --git a/src/graphics/opengl/gl33device.h b/src/graphics/opengl/gl33device.h index b1eb6214..f7b28790 100644 --- a/src/graphics/opengl/gl33device.h +++ b/src/graphics/opengl/gl33device.h @@ -50,7 +50,7 @@ namespace Gfx { class CGL33Device : public CDevice { public: - CGL33Device(const GLDeviceConfig &config); + CGL33Device(const DeviceConfig &config); virtual ~CGL33Device(); virtual void DebugHook() OVERRIDE; @@ -59,7 +59,7 @@ public: virtual bool Create() OVERRIDE; virtual void Destroy() OVERRIDE; - void ConfigChanged(const GLDeviceConfig &newConfig); + virtual void ConfigChanged(const DeviceConfig &newConfig) OVERRIDE; virtual void BeginScene() OVERRIDE; virtual void EndScene() OVERRIDE; @@ -158,7 +158,7 @@ private: private: //! Current config - GLDeviceConfig m_config; + DeviceConfig m_config; //! Current world matrix Math::Matrix m_worldMat; diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index f75d57e3..d37ec04c 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -36,7 +36,7 @@ // Graphics module namespace namespace Gfx { -CGLDevice::CGLDevice(const GLDeviceConfig &config) +CGLDevice::CGLDevice(const DeviceConfig &config) { m_config = config; m_lighting = false; @@ -244,40 +244,27 @@ bool CGLDevice::Create() GetLogger()->Info("Anisotropic filtering not available\n"); } - if (m_config.vboMode == VBO_MODE_ENABLE) - { - GetLogger()->Info("VBO enabled by override - using VBOs\n"); - SetVertexBufferType(VBT_VBO_CORE); - } - else if (m_config.vboMode == VBO_MODE_DISABLE) - { - GetLogger()->Info("VBO disabled by override - using display lists\n"); - SetVertexBufferType(VBT_DISPLAY_LIST); - } - else - { - GetLogger()->Info("Auto-detecting VBO support\n"); - - // detecting VBO ARB extension - bool vboARB = glewIsSupported("GL_ARB_vertex_buffer_object"); + GetLogger()->Info("Auto-detecting VBO support\n"); - // VBO is core OpenGL feature since 1.5 - // everything below 1.5 means no VBO support - if (m_glMajor > 1 || m_glMinor > 4) - { - GetLogger()->Info("Core VBO supported\n", m_glMajor, m_glMinor); - SetVertexBufferType(VBT_VBO_CORE); - } - else if(vboARB) // VBO ARB extension available - { - GetLogger()->Info("ARB VBO supported\n"); - SetVertexBufferType(VBT_VBO_ARB); - } - else // no VBO support - { - GetLogger()->Info("VBO not supported\n"); - SetVertexBufferType(VBT_DISPLAY_LIST); - } + // detecting VBO ARB extension + bool vboARB = glewIsSupported("GL_ARB_vertex_buffer_object"); + + // VBO is core OpenGL feature since 1.5 + // everything below 1.5 means no VBO support + if (m_glMajor > 1 || m_glMinor > 4) + { + GetLogger()->Info("Core VBO supported\n", m_glMajor, m_glMinor); + m_vertexBufferType = VBT_VBO_CORE; + } + else if(vboARB) // VBO ARB extension available + { + GetLogger()->Info("ARB VBO supported\n"); + m_vertexBufferType = VBT_VBO_ARB; + } + else // no VBO support + { + GetLogger()->Info("VBO not supported\n"); + m_vertexBufferType = VBT_DISPLAY_LIST; } } @@ -336,7 +323,7 @@ void CGLDevice::Destroy() m_textureStageParams.clear(); } -void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) +void CGLDevice::ConfigChanged(const DeviceConfig& newConfig) { m_config = newConfig; @@ -346,18 +333,6 @@ void CGLDevice::ConfigChanged(const GLDeviceConfig& newConfig) Create(); } -void CGLDevice::SetUseVbo(bool vboAvailable) -{ - m_vboAvailable = vboAvailable; - m_vertexBufferType = vboAvailable ? VBT_VBO_CORE : VBT_DISPLAY_LIST; -} - -void CGLDevice::SetVertexBufferType(VertexBufferType type) -{ - m_vertexBufferType = type; - m_vboAvailable = (type != VBT_DISPLAY_LIST); -} - void CGLDevice::BeginScene() { Clear(); diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index fc71d09c..ce72a490 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -70,7 +70,7 @@ struct GLDevicePrivate; class CGLDevice : public CDevice { public: - CGLDevice(const GLDeviceConfig &config); + CGLDevice(const DeviceConfig &config); virtual ~CGLDevice(); virtual void DebugHook() OVERRIDE; @@ -79,10 +79,7 @@ public: virtual bool Create() OVERRIDE; virtual void Destroy() OVERRIDE; - void ConfigChanged(const GLDeviceConfig &newConfig); - - void SetUseVbo(bool useVbo); - void SetVertexBufferType(VertexBufferType type); + virtual void ConfigChanged(const DeviceConfig &newConfig) OVERRIDE; virtual void BeginScene() OVERRIDE; virtual void EndScene() OVERRIDE; @@ -176,7 +173,7 @@ private: private: //! Current config - GLDeviceConfig m_config; + DeviceConfig m_config; //! Current world matrix Math::Matrix m_worldMat; diff --git a/src/graphics/opengl/glutil.cpp b/src/graphics/opengl/glutil.cpp index a6fbc0e4..a98820a7 100644 --- a/src/graphics/opengl/glutil.cpp +++ b/src/graphics/opengl/glutil.cpp @@ -28,22 +28,10 @@ // Graphics module namespace namespace Gfx { -GLDeviceConfig::GLDeviceConfig() -{ - LoadDefault(); -} - GLuint textureCoordinates[] = { GL_S, GL_T, GL_R, GL_Q }; GLuint textureCoordGen[] = { GL_TEXTURE_GEN_S, GL_TEXTURE_GEN_T, GL_TEXTURE_GEN_R, GL_TEXTURE_GEN_Q }; -void GLDeviceConfig::LoadDefault() -{ - DeviceConfig::LoadDefault(); - - vboMode = VBO_MODE_AUTO; -} - -CDevice* CreateDevice(const GLDeviceConfig &config, const char *name) +CDevice* CreateDevice(const DeviceConfig &config, const char *name) { if (name == nullptr) return nullptr; else if (std::strcmp(name, "default") == 0) return new CGLDevice(config); diff --git a/src/graphics/opengl/glutil.h b/src/graphics/opengl/glutil.h index fccc7e21..14c0f51b 100644 --- a/src/graphics/opengl/glutil.h +++ b/src/graphics/opengl/glutil.h @@ -31,34 +31,8 @@ namespace Gfx { -/** -\enum VBOMode -\brief VBO autodetect/override -*/ -enum VBOMode -{ - VBO_MODE_ENABLE, //! < override: enable - VBO_MODE_DISABLE, //! < override: disable - VBO_MODE_AUTO //! < autodetect -}; - -/** -\struct GLDeviceConfig -\brief Additional config with OpenGL-specific settings */ -struct GLDeviceConfig : public DeviceConfig -{ - //! VBO override/autodetect - VBOMode vboMode; - - //! Constructor calls LoadDefaults() - GLDeviceConfig(); - - //! Loads the default values - void LoadDefault(); -}; - //! Creates OpenGL device -CDevice* CreateDevice(const GLDeviceConfig &config, const char *name); +CDevice* CreateDevice(const DeviceConfig &config, const char *name); //! Returns OpenGL version as one number. // First digit is major part, second digit is minor part.