Browse Source

GL: return Containers::Pair from version().

This one was spectacular -- ALL uses of it had also #include <tuple> in
order to std::tie() the result into separate major & minor variables. So
much compile time overhead for so little.
pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
a2ca84d4f5
  1. 2
      doc/changelog.dox
  2. 4
      src/Magnum/GL/Context.cpp
  3. 7
      src/Magnum/GL/Test/VersionTest.cpp
  4. 10
      src/Magnum/GL/Version.cpp
  5. 16
      src/Magnum/GL/Version.h
  6. 8
      src/Magnum/Platform/GlfwApplication.cpp
  7. 8
      src/Magnum/Platform/Implementation/EglContextHandler.cpp
  8. 8
      src/Magnum/Platform/Implementation/GlxContextHandler.cpp
  9. 11
      src/Magnum/Platform/Sdl2Application.cpp

2
doc/changelog.dox

@ -1467,6 +1467,8 @@ See also:
@ref GL::Buffer::setLabel() "setLabel()" APIs now work with a
@relativeref{Corrade,Containers::StringView} /
@relativeref{Corrade,Containers::String} instead of a @ref std::string
- @ref GL::version(Version) now returns a
@relativeref{Corrade,Containers::Pair} instead of a @ref std::pair
- @ref MeshTools::compressIndices(), @ref MeshTools::removeDuplicates()
and related APIs now return a @relativeref{Corrade,Containers::Pair}
instead of a @ref std::pair

4
src/Magnum/GL/Context.cpp

@ -920,9 +920,9 @@ bool Context::tryCreate(const Configuration& configuration) {
#endif
{
#ifndef MAGNUM_TARGET_GLES
Error{} << "GL::Context: unsupported OpenGL version" << std::make_pair(majorVersion, minorVersion);
Error{} << "GL::Context: unsupported OpenGL version" << Containers::pair(majorVersion, minorVersion);
#else
Error{} << "GL::Context: unsupported OpenGL ES version" << std::make_pair(majorVersion, minorVersion);
Error{} << "GL::Context: unsupported OpenGL ES version" << Containers::pair(majorVersion, minorVersion);
#endif
/* Reset the version so the context is not marked as successfully created */

7
src/Magnum/GL/Test/VersionTest.cpp

@ -24,6 +24,7 @@
*/
#include <sstream>
#include <Corrade/Containers/Pair.h>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h>
@ -76,15 +77,15 @@ void VersionTest::fromNumber() {
void VersionTest::toNumber() {
#ifndef MAGNUM_TARGET_GLES
CORRADE_COMPARE(version(Version::GL430), std::make_pair(4, 3));
CORRADE_COMPARE(version(Version::GL430), Containers::pair(4, 3));
#else
CORRADE_COMPARE(version(Version::GLES300), std::make_pair(3, 0));
CORRADE_COMPARE(version(Version::GLES300), Containers::pair(3, 0));
#endif
}
#ifndef MAGNUM_TARGET_GLES
void VersionTest::toNumberES() {
CORRADE_COMPARE(version(Version::GLES310), std::make_pair(3, 1));
CORRADE_COMPARE(version(Version::GLES310), Containers::pair(3, 1));
}
#endif

10
src/Magnum/GL/Version.cpp

@ -25,10 +25,20 @@
#include "Version.h"
#include <Corrade/Containers/Pair.h>
#include <Corrade/Utility/Debug.h>
namespace Magnum { namespace GL {
Containers::Pair<Int, Int> version(const Version version) {
const Int v = Int(version)
#ifndef MAGNUM_TARGET_GLES
& ~Implementation::VersionESMask
#endif
;
return {v/100, (v%100)/10};
}
#ifndef DOXYGEN_GENERATING_OUTPUT
Debug& operator<<(Debug& debug, const Version value) {
switch(value) {

16
src/Magnum/GL/Version.h

@ -29,11 +29,14 @@
* @brief Enum @ref Magnum::GL::Version, function @ref Magnum::GL::version(), @ref Magnum::GL::isVersionES()
*/
#include <utility> /* std::pair */
#include "Magnum/Magnum.h"
#include "Magnum/GL/visibility.h"
#ifdef MAGNUM_BUILD_DEPRECATED
/* version() returned std::pair before */
#include <Corrade/Containers/PairStl.h>
#endif
namespace Magnum { namespace GL {
#ifndef MAGNUM_TARGET_GLES
@ -135,14 +138,7 @@ constexpr Version version(Int major, Int minor) {
@see @ref isVersionES()
*/
inline std::pair<Int, Int> version(Version version) {
const Int v = Int(version)
#ifndef MAGNUM_TARGET_GLES
& ~Implementation::VersionESMask
#endif
;
return {v/100, (v%100)/10};
}
MAGNUM_GL_EXPORT Containers::Pair<Int, Int> version(Version version);
/**
@brief Whether given version is OpenGL ES or WebGL

8
src/Magnum/Platform/GlfwApplication.cpp

@ -28,7 +28,6 @@
#include "GlfwApplication.h"
#include <tuple>
#include <Corrade/Containers/Array.h>
#include <Corrade/Containers/StridedArrayView.h>
#include <Corrade/Utility/Arguments.h>
@ -463,10 +462,9 @@ bool GlfwApplication::tryCreate(const Configuration& configuration, const GLConf
/* Set context version, if requested */
if(glConfiguration.version() != GL::Version::None) {
Int major, minor;
std::tie(major, minor) = version(glConfiguration.version());
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, major);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minor);
const Containers::Pair<Int, Int> versionMajorMinor = version(glConfiguration.version());
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, versionMajorMinor.first());
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, versionMajorMinor.second());
#ifndef MAGNUM_TARGET_GLES
if(glConfiguration.version() >= GL::Version::GL320) {
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

8
src/Magnum/Platform/Implementation/EglContextHandler.cpp

@ -25,7 +25,6 @@
#include "EglContextHandler.h"
#include <tuple>
#include <EGL/eglext.h>
#include <Corrade/Utility/Debug.h>
@ -112,13 +111,12 @@ void EglContextHandler::createContext(const AbstractXApplication::GLConfiguratio
EGL_KHR_create_context. */
/** @todo Test for presence of EGL_KHR_create_context extension */
if(glConfiguration.version() != GL::Version::None) {
Int major, minor;
std::tie(major, minor) = version(glConfiguration.version());
const Containers::Pair<Int, Int> versionMajorMinor = version(glConfiguration.version());
attributes[0] = EGL_CONTEXT_MAJOR_VERSION_KHR;
attributes[1] = major;
attributes[1] = versionMajorMinor.first();
attributes[2] = EGL_CONTEXT_MINOR_VERSION_KHR;
attributes[3] = minor;
attributes[3] = versionMajorMinor.second();
#ifndef MAGNUM_TARGET_GLES
if(glConfiguration.version() >= GL::Version::GL310) {

8
src/Magnum/Platform/Implementation/GlxContextHandler.cpp

@ -26,7 +26,6 @@
#include "GlxContextHandler.h"
#include <cstdlib>
#include <tuple>
#include <GL/glxext.h>
#include <Corrade/Utility/Debug.h>
@ -86,13 +85,12 @@ void GlxContextHandler::createContext(const AbstractXApplication::GLConfiguratio
/* Set context version, if requested */
if(glConfiguration.version() != GL::Version::None) {
Int major, minor;
std::tie(major, minor) = version(glConfiguration.version());
const Containers::Pair<Int, Int> versionMajorMinor = version(glConfiguration.version());
attributes[0] = GLX_CONTEXT_MAJOR_VERSION_ARB;
attributes[1] = major;
attributes[1] = versionMajorMinor.first();
attributes[2] = GLX_CONTEXT_MINOR_VERSION_ARB;
attributes[3] = minor;
attributes[3] = versionMajorMinor.second();
#ifndef MAGNUM_TARGET_GLES
if(glConfiguration.version() >= GL::Version::GL310) {

11
src/Magnum/Platform/Sdl2Application.cpp

@ -38,9 +38,7 @@
#ifdef CORRADE_TARGET_CLANG_CL
#pragma clang diagnostic pop
#endif
#ifndef CORRADE_TARGET_EMSCRIPTEN
#include <tuple>
#else
#ifdef CORRADE_TARGET_EMSCRIPTEN
#include <emscripten/emscripten.h>
#include <emscripten/html5.h>
#endif
@ -515,10 +513,9 @@ bool Sdl2Application::tryCreate(const Configuration& configuration, const GLConf
/* Set context version, if user-specified */
if(glConfiguration.version() != GL::Version::None) {
Int major, minor;
std::tie(major, minor) = version(glConfiguration.version());
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, major);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minor);
const Containers::Pair<Int, Int> versionMajorMinor = version(glConfiguration.version());
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, versionMajorMinor.first());
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, versionMajorMinor.second());
#ifndef MAGNUM_TARGET_GLES
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, glConfiguration.version() >= GL::Version::GL310 ?

Loading…
Cancel
Save