Browse Source

Added Context::detectedDriver().

A general way to detect drivers, which can be later used for applying
driver-specific workarounds. Currently used for disabling
ARB_explicit_uniform_location on AMD drivers.
pull/55/merge
Vladimír Vondruš 12 years ago
parent
commit
7f4a986c38
  1. 1
      src/Magnum/CMakeLists.txt
  2. 31
      src/Magnum/Context.h
  3. 46
      src/Magnum/Implementation/detectedDriver.cpp
  4. 3
      src/Magnum/Implementation/setupDriverWorkarounds.cpp

1
src/Magnum/CMakeLists.txt

@ -62,6 +62,7 @@ set(Magnum_SRCS
Implementation/ShaderProgramState.cpp
Implementation/State.cpp
Implementation/TextureState.cpp
Implementation/detectedDriver.cpp
Implementation/maxTextureSize.cpp
Implementation/setupDriverWorkarounds.cpp

31
src/Magnum/Context.h

@ -38,6 +38,7 @@
#include "Magnum/Magnum.h"
#include "Magnum/OpenGL.h"
#include "Magnum/visibility.h"
#include "MagnumExternal/Optional/optional.hpp"
namespace Magnum {
@ -169,6 +170,25 @@ class MAGNUM_EXPORT Context {
*/
typedef Containers::EnumSet<State> States;
/**
* @brief Detected driver
*
* @see @ref DetectedDriver, @ref detectedDriver()
*/
enum class DetectedDriver: UnsignedShort {
#ifndef MAGNUM_TARGET_GLES
/** Binary AMD desktop drivers on Windows and Linux */
AMD = 1 << 0
#endif
};
/**
* @brief Detected drivers
*
* @see @ref detectedDriver()
*/
typedef Containers::EnumSet<DetectedDriver> DetectedDrivers;
/**
* @brief Constructor
*
@ -432,6 +452,15 @@ class MAGNUM_EXPORT Context {
*/
void resetState(States states = ~States{});
/**
* @brief Detect driver
*
* Tries to detect driver using various OpenGL state queries. Once the
* detection is done, the result is cached, repeated queries don't
* result in repeated GL calls.
*/
DetectedDrivers detectedDriver();
#ifndef DOXYGEN_GENERATING_OUTPUT
Implementation::State& state() { return *_state; }
#endif
@ -451,6 +480,8 @@ class MAGNUM_EXPORT Context {
std::vector<Extension> _supportedExtensions;
Implementation::State* _state;
std::optional<DetectedDrivers> _detectedDrivers;
};
/** @debugoperatorclassenum{Magnum::Context,Magnum::Context::Flag} */

46
src/Magnum/Implementation/detectedDriver.cpp

@ -0,0 +1,46 @@
/*
This file is part of Magnum.
Copyright © 2010, 2011, 2012, 2013, 2014
Vladimír Vondruš <mosra@centrum.cz>
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/
#include "Magnum/Context.h"
#include "Magnum/Math/Range.h"
namespace Magnum {
auto Context::detectedDriver() -> Context::DetectedDrivers {
if(_detectedDrivers) return *_detectedDrivers;
_detectedDrivers = DetectedDrivers{};
/* AMD binary desktop drivers */
#ifndef MAGNUM_TARGET_GLES
const std::string vendor = vendorString();
if(vendor.find("ATI Technologies Inc.") != std::string::npos)
return *_detectedDrivers |= DetectedDriver::AMD;
#endif
return *_detectedDrivers;
}
}

3
src/Magnum/Implementation/setupDriverWorkarounds.cpp

@ -35,8 +35,7 @@ void Context::setupDriverWorkarounds() {
#ifndef MAGNUM_TARGET_GLES
/* This extension causes crash in GLSL compiler on AMD linux drivers 13.251 */
const std::string vendor = vendorString();
if(vendor.find("ATI Technologies Inc.") != std::string::npos)
if(detectedDriver() & DetectedDriver::AMD)
_setRequiredVersion(GL::ARB::explicit_uniform_location, None);
#endif

Loading…
Cancel
Save