From 8c39c5f11f9ab674ddec6ba43c66ae9d3cbd0952 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Thu, 2 Jan 2014 22:32:38 +0100 Subject: [PATCH] Platform: ability to request context version in GlutApplication. --- src/Platform/GlutApplication.cpp | 15 +++++++++++++++ src/Platform/GlutApplication.h | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/Platform/GlutApplication.cpp b/src/Platform/GlutApplication.cpp index f1e178d8a..c425035a0 100644 --- a/src/Platform/GlutApplication.cpp +++ b/src/Platform/GlutApplication.cpp @@ -24,7 +24,10 @@ #include "GlutApplication.h" +#include + #include "Context.h" +#include "Version.h" #include "Platform/ScreenedApplication.hpp" @@ -75,6 +78,18 @@ bool GlutApplication::tryCreateContext(const Configuration& configuration) { glutInitDisplayMode(flags); glutInitWindowSize(configuration.size().x(), configuration.size().y()); + + /* Set context version, if requested */ + if(configuration.version() != Version::None) { + Int major, minor; + std::tie(major, minor) = version(configuration.version()); + glutInitContextVersion(major, minor); + #ifndef MAGNUM_TARGET_GLES + if(configuration.version() >= Version::GL310) + glutInitContextProfile(GLUT_CORE_PROFILE); + #endif + } + if(!glutCreateWindow(configuration.title().data())) { Error() << "Platform::GlutApplication::tryCreateContext(): cannot create context"; return false; diff --git a/src/Platform/GlutApplication.h b/src/Platform/GlutApplication.h index 8e7391078..69c9ca410 100644 --- a/src/Platform/GlutApplication.h +++ b/src/Platform/GlutApplication.h @@ -290,6 +290,22 @@ class GlutApplication::Configuration { return *this; } + /** @brief Context version */ + Version version() const { return _version; } + + /** + * @brief Set context version + * + * If requesting version greater or equal to OpenGL 3.1, core profile + * is used. The created context will then have any version which is + * backwards-compatible with requested one. Default is + * @ref Version::None, i.e. any provided version is used. + */ + Configuration& setVersion(Version version) { + _version = version; + return *this; + } + /** @brief Sample count */ Int sampleCount() const { return _sampleCount; } @@ -310,6 +326,7 @@ class GlutApplication::Configuration { std::string _title; Vector2i _size; Int _sampleCount; + Version _version; }; /**