Removed VBO override switch and some unnecessary code

master
Tomasz Kapuściński 2015-06-16 15:31:59 +02:00
parent 26ec927b37
commit ff44637d49
13 changed files with 54 additions and 133 deletions

View File

@ -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<Gfx::CGLDevice*>(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;
}

View File

@ -31,7 +31,6 @@
#include "graphics/core/device.h"
#include "graphics/engine/engine.h"
#include "graphics/opengl/gldevice.h"
#include <string>
@ -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;

View File

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

View File

@ -57,6 +57,10 @@ void CNullDevice::Destroy()
{
}
void CNullDevice::ConfigChanged(const DeviceConfig &newConfig)
{
}
void CNullDevice::BeginScene()
{
}

View File

@ -46,6 +46,8 @@ public:
virtual bool Create();
virtual void Destroy();
virtual void ConfigChanged(const DeviceConfig &newConfig);
virtual void BeginScene();
virtual void EndScene();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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