Added automatic graphics detection (-graphics auto)
parent
a880210b3d
commit
012eb10e19
|
@ -35,9 +35,7 @@
|
|||
|
||||
#include "graphics/engine/modelmanager.h"
|
||||
#include "graphics/core/nulldevice.h"
|
||||
#include "graphics/opengl/gldevice.h"
|
||||
#include "graphics/opengl/gl21device.h"
|
||||
#include "graphics/opengl/gl33device.h"
|
||||
#include "graphics/opengl/glutil.h"
|
||||
|
||||
#include "object/robotmain.h"
|
||||
#include "object/objman.h"
|
||||
|
@ -563,14 +561,9 @@ bool CApplication::Create()
|
|||
|
||||
if(!m_headless)
|
||||
{
|
||||
// The video is ready, we can create and initalize the graphics device
|
||||
if (m_graphics == "opengl")
|
||||
m_device = new Gfx::CGLDevice(m_deviceConfig);
|
||||
else if (m_graphics == "gl21")
|
||||
m_device = new Gfx::CGL21Device(m_deviceConfig);
|
||||
else if (m_graphics == "gl33")
|
||||
m_device = new Gfx::CGL33Device(m_deviceConfig);
|
||||
else
|
||||
m_device = Gfx::CreateDevice(m_deviceConfig, m_graphics.c_str());
|
||||
|
||||
if (m_device == nullptr)
|
||||
{
|
||||
m_device = new Gfx::CNullDevice();
|
||||
GetLogger()->Error("Unknown graphics device: %s\n", m_graphics.c_str());
|
||||
|
|
|
@ -65,6 +65,20 @@ struct DeviceConfig
|
|||
//! No window frame (also set with full screen)
|
||||
bool noFrame;
|
||||
|
||||
//! Size of red channel in bits
|
||||
int redSize;
|
||||
//! Size of green channel in bits
|
||||
int greenSize;
|
||||
//! Size of blue channel in bits
|
||||
int blueSize;
|
||||
//! Size of alpha channel in bits
|
||||
int alphaSize;
|
||||
//! Color depth in bits
|
||||
int depthSize;
|
||||
|
||||
//! Force hardware acceleration (video mode set will fail on lack of hw accel)
|
||||
bool hardwareAccel;
|
||||
|
||||
//! Constructor calls LoadDefault()
|
||||
DeviceConfig() { LoadDefault(); }
|
||||
|
||||
|
@ -77,6 +91,14 @@ struct DeviceConfig
|
|||
resizeable = true;
|
||||
doubleBuf = true;
|
||||
noFrame = false;
|
||||
|
||||
hardwareAccel = true;
|
||||
|
||||
redSize = 8;
|
||||
blueSize = 8;
|
||||
greenSize = 8;
|
||||
alphaSize = 8;
|
||||
depthSize = 24;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
*/
|
||||
|
||||
#include "graphics/opengl/glutil.h"
|
||||
#include "graphics/opengl/gldevice.h"
|
||||
#include "graphics/opengl/gl21device.h"
|
||||
#include "graphics/opengl/gl33device.h"
|
||||
#include "common/logger.h"
|
||||
#include <physfs.h>
|
||||
|
||||
|
@ -36,17 +39,38 @@ void GLDeviceConfig::LoadDefault()
|
|||
{
|
||||
DeviceConfig::LoadDefault();
|
||||
|
||||
hardwareAccel = true;
|
||||
|
||||
redSize = 8;
|
||||
blueSize = 8;
|
||||
greenSize = 8;
|
||||
alphaSize = 8;
|
||||
depthSize = 24;
|
||||
|
||||
vboMode = VBO_MODE_AUTO;
|
||||
}
|
||||
|
||||
CDevice* CreateDevice(const GLDeviceConfig &config, const char *name)
|
||||
{
|
||||
if (name == nullptr) return nullptr;
|
||||
else if (strcmp(name, "default") == 0) return new CGLDevice(config);
|
||||
else if (strcmp(name, "opengl") == 0) return new CGLDevice(config);
|
||||
else if (strcmp(name, "gl14") == 0) return new CGLDevice(config);
|
||||
else if (strcmp(name, "gl21") == 0) return new CGL21Device(config);
|
||||
else if (strcmp(name, "gl33") == 0) return new CGL33Device(config);
|
||||
else if (strcmp(name, "auto") == 0)
|
||||
{
|
||||
int version = GetOpenGLVersion();
|
||||
|
||||
if (version >= 33) return new CGL33Device(config);
|
||||
else if (version >= 21) return new CGL21Device(config);
|
||||
else return new CGLDevice(config);
|
||||
}
|
||||
else return nullptr;
|
||||
}
|
||||
|
||||
int GetOpenGLVersion()
|
||||
{
|
||||
const char *version = reinterpret_cast<const char*>(glGetString(GL_VERSION));
|
||||
int major = 0, minor = 0;
|
||||
|
||||
sscanf(version, "%d.%d", &major, &minor);
|
||||
|
||||
return 10 * major + minor;
|
||||
}
|
||||
|
||||
GLenum TranslateGfxPrimitive(PrimitiveType type)
|
||||
{
|
||||
GLenum flag = 0;
|
||||
|
|
|
@ -47,20 +47,6 @@ enum VBOMode
|
|||
\brief Additional config with OpenGL-specific settings */
|
||||
struct GLDeviceConfig : public DeviceConfig
|
||||
{
|
||||
//! Size of red channel in bits
|
||||
int redSize;
|
||||
//! Size of green channel in bits
|
||||
int greenSize;
|
||||
//! Size of blue channel in bits
|
||||
int blueSize;
|
||||
//! Size of alpha channel in bits
|
||||
int alphaSize;
|
||||
//! Color depth in bits
|
||||
int depthSize;
|
||||
|
||||
//! Force hardware acceleration (video mode set will fail on lack of hw accel)
|
||||
bool hardwareAccel;
|
||||
|
||||
//! VBO override/autodetect
|
||||
VBOMode vboMode;
|
||||
|
||||
|
@ -71,6 +57,13 @@ struct GLDeviceConfig : public DeviceConfig
|
|||
void LoadDefault();
|
||||
};
|
||||
|
||||
//! Creates OpenGL device
|
||||
CDevice* CreateDevice(const GLDeviceConfig &config, const char *name);
|
||||
|
||||
//! Returns OpenGL version as one number.
|
||||
// First digit is major part, second digit is minor part.
|
||||
int GetOpenGLVersion();
|
||||
|
||||
//! Translate Gfx primitive type to OpenGL primitive type
|
||||
GLenum TranslateGfxPrimitive(PrimitiveType type);
|
||||
|
||||
|
|
Loading…
Reference in New Issue