2009-09-03 08:53:55 +02:00
|
|
|
// Copyright (c) 2009, Amar Takhar <verm@aegisub.org>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2009-09-26 11:22:54 +02:00
|
|
|
/// @file platform.cpp
|
2009-09-03 08:53:55 +02:00
|
|
|
/// @brief Base functions for the Platform class.
|
2009-09-26 11:38:17 +02:00
|
|
|
/// @ingroup base
|
2009-09-03 08:53:55 +02:00
|
|
|
|
|
|
|
#ifndef R_PRECOMP
|
2011-01-03 16:46:21 +01:00
|
|
|
#include <sstream>
|
2009-09-27 06:15:41 +02:00
|
|
|
#include <wx/string.h>
|
|
|
|
#include <wx/app.h>
|
2009-09-03 08:53:55 +02:00
|
|
|
#include <wx/gdicmn.h> // Display* functions.
|
|
|
|
#include <wx/version.h> // Version info.
|
|
|
|
#include <wx/intl.h> // Locale info.
|
2009-09-27 06:15:41 +02:00
|
|
|
#include <wx/glcanvas.h>
|
2009-09-03 08:53:55 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "include/platform.h"
|
2011-01-08 16:24:35 +01:00
|
|
|
#include "platform_windows.h"
|
2009-09-03 08:53:55 +02:00
|
|
|
#include "platform_unix.h"
|
|
|
|
#include "platform_unix_bsd.h"
|
2011-01-08 16:24:35 +01:00
|
|
|
#include "platform_unix_linux.h"
|
|
|
|
#include "platform_unix_osx.h"
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2009-09-27 06:15:41 +02:00
|
|
|
extern "C" {
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
#include "OpenGL/glu.h"
|
|
|
|
#include "OpenGL/gl.h"
|
|
|
|
#else
|
|
|
|
#include <GL/glu.h>
|
|
|
|
#include <GL/gl.h>
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-09-03 08:53:55 +02:00
|
|
|
/// @brief Constructor.
|
|
|
|
Platform* Platform::GetPlatform() {
|
2009-10-03 19:45:34 +02:00
|
|
|
#if defined(__WINDOWS__)
|
|
|
|
Platform *p = new PlatformWindows;
|
|
|
|
#elif defined(__UNIX__)
|
2009-09-26 22:05:54 +02:00
|
|
|
# if defined(__FREEBSD__)
|
2009-09-03 08:53:55 +02:00
|
|
|
Platform *p = new PlatformUnixBSD;
|
2009-09-26 22:05:54 +02:00
|
|
|
# elif defined(__LINUX__)
|
2009-09-26 18:44:36 +02:00
|
|
|
Platform *p = new PlatformUnixLinux;
|
2009-09-27 03:47:11 +02:00
|
|
|
# elif defined(__APPLE__)
|
|
|
|
Platform *p = new PlatformUnixOSX;
|
2009-09-26 22:05:54 +02:00
|
|
|
# else
|
2009-09-03 08:53:55 +02:00
|
|
|
Platform *p = new PlatformUnix;
|
|
|
|
# endif
|
2009-10-03 19:16:52 +02:00
|
|
|
#else
|
|
|
|
Platform *p = NULL;
|
2009-09-03 08:53:55 +02:00
|
|
|
#endif // __UNIX__
|
|
|
|
p->Init();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// @brief Init variables to avoid duplicate instantiations.
|
|
|
|
void Platform::Init() {
|
|
|
|
locale = new wxLocale();
|
|
|
|
locale->Init();
|
2011-01-03 17:14:43 +01:00
|
|
|
|
|
|
|
int attList[] = { WX_GL_RGBA, WX_GL_DOUBLEBUFFER, 0 };
|
|
|
|
glc = new wxGLCanvas(wxTheApp->GetTopWindow(), wxID_ANY, attList, wxDefaultPosition, wxSize(0,0));
|
|
|
|
ctx = new wxGLContext(glc, 0);
|
|
|
|
wxGLCanvas &cr = *glc;
|
|
|
|
ctx->SetCurrent(cr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Platform::~Platform() {
|
|
|
|
delete ctx;
|
|
|
|
delete glc;
|
|
|
|
delete locale;
|
2009-09-27 06:15:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gather video adapter information via OpenGL
|
|
|
|
*
|
|
|
|
*/
|
2011-01-03 14:33:53 +01:00
|
|
|
std::string Platform::GetVideoInfo(enum Platform::VideoInfo which) {
|
2009-09-27 06:15:41 +02:00
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string value;
|
2009-09-27 11:50:04 +02:00
|
|
|
|
|
|
|
switch (which) {
|
2009-09-27 15:26:23 +02:00
|
|
|
case VIDEO_EXT:
|
2011-01-03 14:33:53 +01:00
|
|
|
return reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
|
2009-09-27 15:26:23 +02:00
|
|
|
break;
|
2009-09-27 11:50:04 +02:00
|
|
|
case VIDEO_RENDERER:
|
2011-01-03 14:33:53 +01:00
|
|
|
return reinterpret_cast<const char*>(glGetString(GL_RENDERER));
|
2009-09-27 11:50:04 +02:00
|
|
|
break;
|
|
|
|
case VIDEO_VENDOR:
|
2011-01-03 14:33:53 +01:00
|
|
|
return reinterpret_cast<const char*>(glGetString(GL_VENDOR));
|
2009-09-27 11:50:04 +02:00
|
|
|
break;
|
|
|
|
case VIDEO_VERSION:
|
2011-01-03 14:33:53 +01:00
|
|
|
return reinterpret_cast<const char*>(glGetString(GL_VERSION));
|
|
|
|
default:
|
|
|
|
return "";
|
2009-09-27 11:50:04 +02:00
|
|
|
}
|
2011-01-08 16:25:04 +01:00
|
|
|
return "";
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::ArchName() {
|
|
|
|
return std::string(plat.GetArchName());
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::OSFamily() {
|
|
|
|
return std::string(plat.GetOperatingSystemFamilyName());
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::OSName() {
|
|
|
|
return std::string(plat.GetOperatingSystemIdName());
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2009-09-03 08:53:55 +02:00
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::Endian() {
|
|
|
|
return std::string(plat.GetEndiannessName());
|
2011-12-28 22:27:06 +01:00
|
|
|
}
|
2009-09-03 08:53:55 +02:00
|
|
|
|
|
|
|
|
2011-01-03 14:33:53 +01:00
|
|
|
int Platform::DisplayDepth() {
|
|
|
|
return wxDisplayDepth();
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::DisplaySize() {
|
2009-09-03 08:53:55 +02:00
|
|
|
int x, y;
|
|
|
|
wxDisplaySize(&x, &y);
|
2011-01-03 16:46:21 +01:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << x << " " << y;
|
|
|
|
return ss.str();
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::DisplayPPI() {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << wxGetDisplayPPI().GetWidth() << " " << wxGetDisplayPPI().GetHeight();
|
|
|
|
return ss.str();
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::wxVersion() {
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << wxMAJOR_VERSION << "." << wxMINOR_VERSION << "." << wxRELEASE_NUMBER << "." << wxSUBRELEASE_NUMBER;
|
|
|
|
return ss.str();
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 16:46:21 +01:00
|
|
|
std::string Platform::Locale() {
|
|
|
|
return std::string(wxLocale().GetSysName());
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
const char* Platform::Language() {
|
2009-09-03 08:53:55 +02:00
|
|
|
const wxLanguageInfo *info = locale->GetLanguageInfo(locale->GetLanguage());
|
2011-01-03 13:00:12 +01:00
|
|
|
return info->CanonicalName.c_str();
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
const char* Platform::SystemLanguage() {
|
2009-09-03 08:53:55 +02:00
|
|
|
const wxLanguageInfo *info = locale->GetLanguageInfo(locale->GetSystemLanguage());
|
2011-01-03 13:00:12 +01:00
|
|
|
return info->CanonicalName.c_str();
|
2009-09-03 08:53:55 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
std::string Platform::Date() {
|
2009-09-03 08:53:55 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-01-03 13:00:12 +01:00
|
|
|
std::string Platform::Signature() {
|
2009-09-03 08:53:55 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2009-10-03 19:16:52 +02:00
|
|
|
#ifdef __UNIX__
|
2011-01-03 14:33:53 +01:00
|
|
|
const char* Platform::DesktopEnvironment() {
|
2009-09-03 08:53:55 +02:00
|
|
|
return "";
|
|
|
|
}
|
2009-10-03 19:16:52 +02:00
|
|
|
#endif
|
2009-09-27 03:47:11 +02:00
|
|
|
|
2011-01-03 14:33:53 +01:00
|
|
|
std::string Platform::OpenGLVendor() {
|
2009-09-27 11:50:04 +02:00
|
|
|
return GetVideoInfo(VIDEO_VENDOR);
|
2009-09-27 06:15:41 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 14:33:53 +01:00
|
|
|
std::string Platform::OpenGLRenderer() {
|
2009-09-27 11:50:04 +02:00
|
|
|
return GetVideoInfo(VIDEO_RENDERER);
|
2009-09-27 06:15:41 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 14:33:53 +01:00
|
|
|
std::string Platform::OpenGLVersion() {
|
2009-09-27 11:50:04 +02:00
|
|
|
return GetVideoInfo(VIDEO_VERSION);
|
2009-09-27 06:15:41 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 14:33:53 +01:00
|
|
|
std::string Platform::OpenGLExt() {
|
2009-09-27 15:26:23 +02:00
|
|
|
return GetVideoInfo(VIDEO_EXT);
|
|
|
|
}
|
|
|
|
|
2009-09-27 04:18:09 +02:00
|
|
|
#ifdef __APPLE__
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string Platform::PatchLevel() {
|
2009-09-27 03:47:11 +02:00
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2011-01-04 01:22:55 +01:00
|
|
|
std::string Platform::HardwareModel() {
|
2009-09-27 03:47:11 +02:00
|
|
|
return "";
|
|
|
|
}
|
2009-09-27 04:18:09 +02:00
|
|
|
|
|
|
|
#endif
|