1
0
Fork 0

Initial commit

This commit is contained in:
Henrik Hautakoski 2015-12-22 17:43:51 +01:00
commit edfc5298e1
252 changed files with 93965 additions and 0 deletions

150
source/Display/Display.cpp Normal file
View file

@ -0,0 +1,150 @@
#include <iostream>
#include <Spectre/Display/Display.h>
#include <Spectre/Display/GLContext.h>
#include <Spectre/System/SystemEvent.h>
#include <Platform/PlatformDisplay.h>
#define CAPTION_DEFAULT "Spectre"
#define ICON_DEFAULT "./assets/app.ico"
Display::Display()
{
m_caption = CAPTION_DEFAULT;
m_fmode = WINDOWED;
m_context = GLContext::create();
m_impl = PlatformDisplay::make(this);
}
Display::~Display()
{
delete m_context;
delete m_impl;
}
bool Display::create(DisplayDescription description)
{
destroy();
if (!m_impl->create(description)) {
return false;
}
if (!m_context->create(m_impl, description.mode.bpp)) {
return false;
}
init();
m_description = description;
return true;
}
void Display::init()
{
m_impl->setCaption(m_caption);
setIcon(ICON_DEFAULT);
activate(true);
enableVSync(false);
showCursor(true);
}
void Display::destroy()
{
m_context->destroy();
m_impl->destroy();
}
void Display::setCaption(const std::string& caption)
{
m_caption = caption;
m_impl->setCaption(m_caption);
}
const std::string& Display::getCaption() const
{
return m_caption;
}
void Display::setIcon(const std::string& filename)
{
m_impl->setIcon(filename);
}
void Display::setSize(unsigned int width, unsigned int height)
{
m_description.mode.width = width;
m_description.mode.height = height;
m_impl->setSize(width, height);
}
void Display::setVideoMode(Mode mode)
{
DisplayDescription desc;
if (m_fmode == mode) {
return;
}
if (mode == FULLSCREEN || mode == WINDOWEDFULLSCREEN) {
// True fullscreen
if (mode == FULLSCREEN) {
desc.mode = m_description.mode;
} else {
desc.mode = DisplayMode::getDesktopMode();
m_cacheDesc = m_description;
}
desc.decoration = DisplayDecorate::None;
} else {
desc = m_cacheDesc;
}
create(desc);
m_fmode = mode;
}
enum Display::Mode Display::getVideoMode() const
{
return m_fmode;
}
void Display::showCursor(bool value)
{
m_impl->showCursor(value);
}
bool Display::activate(bool value)
{
if (value) {
return m_context->activate();
}
return m_context->deactivate();
}
bool Display::enableVSync(bool value)
{
return m_context->setSwapInterval(value ? 1 : 0);
}
void Display::swapBuffers()
{
if (activate(true)) {
m_context->swapBuffers();
}
}
void Display::onReshape(int width, int height)
{
// Resize context if the windows resizes.
m_context->setSize(width, height);
}

View file

@ -0,0 +1,14 @@
#include <Spectre/Display/DisplayDescription.h>
DisplayDescription::DisplayDescription() :
mode (),
decoration (DisplayDecorate::Default)
{
}
DisplayDescription::DisplayDescription(DisplayMode mode, unsigned decoration) :
mode (mode),
decoration (decoration)
{
}

View file

@ -0,0 +1,54 @@
#include <Spectre/Display/DisplayMode.h>
#include <Platform/PlatformMisc.h>
#include <algorithm>
struct DisplayModeCmp
{
inline bool operator() (const DisplayMode& a, const DisplayMode& b)
{
if (a.bpp == b.bpp) {
if (a.width == b.width) {
return a.height > b.height;
}
return a.width > b.width;
}
return a.bpp > b.bpp;
}
};
DisplayMode::DisplayMode() :
width (0),
height (0),
bpp (32)
{
}
DisplayMode::DisplayMode(unsigned int width, unsigned int height, unsigned int bpp) :
width (width),
height (height),
bpp (bpp)
{
}
std::vector<DisplayMode> DisplayMode::getFullscreenModes()
{
static std::vector<DisplayMode> modes;
if (modes.size() < 1) {
PlatformMisc::GetDisplayModes(modes);
// Sort.
std::sort(modes.begin(), modes.end(), DisplayModeCmp());
// remove duplicates
modes.erase(std::unique(modes.begin(), modes.end()), modes.end());
}
return modes;
}
DisplayMode DisplayMode::getDesktopMode()
{
return PlatformMisc::GetDesktopMode();
}

View file

@ -0,0 +1,19 @@
#include <Spectre/Display/GLContext.h>
#ifdef _WIN32
#include <Platform/Win32/Win32GLContext.h>
typedef Win32GLContext ContextType;
#else
#error "No GLContext implementation exists"
#endif
GLContext* GLContext::create()
{
return new ContextType();
}
GLContext::~GLContext()
{
// Nothing to do.
}