/********************************************************************** * * * cgt - CAMP Graphics Toolbox, Copyright (C) 2012-2015 * * Chair for Computer Aided Medical Procedures * * Technische Universitaet Muenchen, Germany. * * * * * * forked from tgt - Tiny Graphics Toolbox, Copyright (C) 2006-2011 * * Visualization and Computer Graphics Group, Department of * * Computer Science, University of Muenster, Germany. * * * * * * This file is part of the cgt library. This library is free * * software; you can redistribute it and/or modify it under the terms * * of the GNU Lesser General Public License version 2.1 as published * * by the Free Software Foundation. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Lesser General Public License for more details. * * * * You should have received a copy of the GNU Lesser General Public * * License in the file "LICENSE.txt" along with this library. * * If not, see . * * * **********************************************************************/ #ifndef CGT_GPUCAPABILITIES_H #define CGT_GPUCAPABILITIES_H #include #include #include "cgt/singleton.h" #include "cgt/cgt_gl.h" #include "cgt/types.h" namespace cgt { class GpuCapabilities; #ifdef DLL_TEMPLATE_INST template class CGT_API Singleton; #endif /** * This cgt-Singleton provides information about the graphics system. * This information includes: * - Operating system * - OpenGL version * - Supported OpenGL extensions * - GPU vendor * - Texturing and shader capabilities * * All data except the operating system information is exclusively retrieved * through the OpenGL API and can thus be regarded as reliable. * * The global identifier of this class' singleton is GpuCaps. */ class CGT_API GpuCapabilities : public Singleton { public: /** * Specifies the version * of the OpenGL/glsl implementation. * CGT_GL_VERSION_x_y denotes OpenGL version x.y. * * CGT prefix is necessary due to name clashes with glew. */ class CGT_API GlVersion { public: explicit GlVersion(int major = 0, int minor = 0, int release = 0); /** * Parse OpenGL version string as specified: * * The GL_VERSION and GL_SHADING_LANGUAGE_VERSION strings begin with a version number. * The version number uses one of these forms: * major_number.minor_number * major_number.minor_number.release_number * * Vendor-specific information may follow the version number. * Its format depends on the implementation, but a space always separates the version number and the vendor-specific information. */ bool parseVersionString(const std::string& st); int major_; int minor_; int release_; int major() const { return major_; } int minor() const { return minor_; } int release() const { return release_; } CGT_API friend bool operator==(const GlVersion& x, const GlVersion& y); CGT_API friend bool operator!=(const GlVersion& x, const GlVersion& y); CGT_API friend bool operator<(const GlVersion& x, const GlVersion& y); CGT_API friend bool operator<=(const GlVersion& x, const GlVersion& y); CGT_API friend bool operator>(const GlVersion& x, const GlVersion& y); CGT_API friend bool operator>=(const GlVersion& x, const GlVersion& y); CGT_API friend std::ostream& operator<<(std::ostream& s, const GlVersion& v); static const GlVersion CGT_GL_VERSION_1_0; static const GlVersion CGT_GL_VERSION_1_1; static const GlVersion CGT_GL_VERSION_1_2; static const GlVersion CGT_GL_VERSION_1_3; static const GlVersion CGT_GL_VERSION_1_4; static const GlVersion CGT_GL_VERSION_1_5; static const GlVersion CGT_GL_VERSION_2_0; static const GlVersion CGT_GL_VERSION_2_1; static const GlVersion CGT_GL_VERSION_3_0; static const GlVersion CGT_GL_VERSION_3_1; static const GlVersion CGT_GL_VERSION_3_2; static const GlVersion CGT_GL_VERSION_3_3; static const GlVersion CGT_GL_VERSION_4_0; static const GlVersion CGT_GL_VERSION_4_1; static const GlVersion CGT_GL_VERSION_4_2; static const GlVersion CGT_GL_VERSION_4_3; static const GlVersion CGT_GL_VERSION_4_4; static const GlVersion CGT_GL_VERSION_4_5; static const GlVersion SHADER_VERSION_110; ///< GLSL version 1.10 static const GlVersion SHADER_VERSION_120; ///< GLSL version 1.20 static const GlVersion SHADER_VERSION_130; ///< GLSL version 1.30 static const GlVersion SHADER_VERSION_140; ///< GLSL version 1.40 static const GlVersion SHADER_VERSION_150; ///< GLSL version 1.50 static const GlVersion SHADER_VERSION_330; ///< GLSL version 3.30 static const GlVersion SHADER_VERSION_400; ///< GLSL version 4.00 static const GlVersion SHADER_VERSION_410; ///< GLSL version 4.10 static const GlVersion SHADER_VERSION_420; ///< GLSL version 4.20 static const GlVersion SHADER_VERSION_430; ///< GLSL version 4.30 static const GlVersion SHADER_VERSION_440; ///< GLSL version 4.40 static const GlVersion SHADER_VERSION_450; ///< GLSL version 4.50 }; /** * Identifies the vendor of the GPU * (not the graphics board's vendor). */ enum GpuVendor { GPU_VENDOR_NVIDIA, GPU_VENDOR_ATI, GPU_VENDOR_INTEL, GPU_VENDOR_UNKNOWN }; /** * Defines the DirectX shader model * supported by the GPU. This value * can be used to derive information * about the GPU's GLSL shader capabilities. * The shader model is fully downwards compatible. */ enum ShaderModel { SHADER_MODEL_UNKNOWN, SHADER_MODEL_2, ///< implied by OpenGL version 2.0 SHADER_MODEL_3, ///< extension NV_vertex_program3 or ATI_shader_texture_lod SHADER_MODEL_4, ///< extension ARB_geometry_shader4 SHADER_MODEL_5 ///< extension ARB_tessellation_shader }; /** * Identifies the used operating system. */ enum OSVersion { OS_UNKNOWN, OS_WIN_2000, OS_WIN_XP, OS_WIN_VISTA, OS_WIN_SERVER_2003, OS_WIN_SERVER_2008, OS_WIN_7, OS_WIN_8, OS_WIN_8_1, OS_WIN_10, OS_POSIX ///< For Linux and other POSIX-like OS. Have a look at getOSVersionString for details. }; /** * Creates an object for the detection of graphics system properties. If detectCapabilities * is set to false, the capabilities of the graphics card aren't detected right away in the * constructor. This way you can use GpuCapabilitiesWindows to detect the amount of memory * on the graphics card before initGL() is called. Otherwise GpuCapabilities tries to * detect GL values while initGL() isn't called yet and produces a crash. */ explicit GpuCapabilities(bool detectCaps = true); virtual ~GpuCapabilities() {} /** * Returns the OpenGL version implemented by the driver. * * @see GlVersion */ GlVersion getGlVersion(); /** * Returns whether a certain OpenGL version is supported. * * @param version the OpenGL version to check * * @see GlVersion */ bool isOpenGlVersionSupported(GlVersion version); /** * Returns the vendor of the GPU. * * @see GpuVendor */ GpuVendor getVendor(); /** * Returns the vendor of the GPU. * * @see GpuVendor */ std::string getVendorAsString(); /** * Returns wether a certain OpenGL extension * is supported by this implementation. The * check is done by parsing the OpenGL * extensions-string provided by the graphics driver. * * @param extension the exact name string of the extension * as found in http://www.opengl.org/registry/ */ bool isExtensionSupported(std::string extension); /** * Returns the complete OpenGL version string * retrieved by glGetString(GL_VERSION). */ std::string getGlVersionString(); /** * Returns the complete OpenGL vendor string * retrieved by glGetString(GL_VENDOR). */ std::string getGlVendorString(); /** * Returns the complete OpenGL renderer string * retrieved by glGetString(GL_RENDERER). */ std::string getGlRendererString(); /** * Returns the complete OpenGL extensions-string * retrieved by glGetStringi(GL_EXTENSIONS). * This strings contains all OpenGL extensions supported * by this OpenGL implementation */ const std::vector& getGlExtensions(); /** * Returns the complete Shading Language Version string * retrieved by glGetString(GL_SHADING_LANGUAGE_VERSION). */ std::string getShadingLanguageVersionString(); /** * Returns whether shaders are supported, which * is true for OpenGL version 2.0 or later. */ bool areShadersSupported(); /** * Returns whether shaders are supported, which * is true for OpenGL version 4.3 or later. */ bool areComputeShadersSupported(); /** * Returns whether the ARB shader extensions * are supported (GL_ARB_vertex_program and * GL_ARB_fragment_program). * * \warning If you want to use shaders based on these * extensions, you have call the ARB variants of the * shader functions, e.g. glCompileShaderARB instead of * glCompileShader */ bool areShadersSupportedARB(); /** * Returns the GLSL shading language version * supported by the GPU. * * @see GlVersion */ GlVersion getShaderVersion(); /** * Returns the DirectX shader model * supported by the GPU. * * @see ShaderModel */ ShaderModel getShaderModel(); /** * Returns wether a certain shader model * is supported. * * @param shaderModel the shader model to check */ bool isShaderModelSupported(ShaderModel shaderModel); /** * Returns the maximal side length of 1D and 2D textures. * * @see getMax3DTextureSize */ int getMaxTextureSize(); /** * Returns wether 3D textures are supported. * This is the case for OpenGL version 1.2 * and later. */ bool is3DTexturingSupported(); /** * Returns the maximal side length * of 3D textures. If 3D texturing * is not supported, 0 is returned. */ int getMax3DTextureSize(); /** * Returns the number of texture units * provided by the GPU. */ int getNumTextureUnits(); /** * Returns the number of image units * provided by the GPU. */ int getNumImageUnits(); /** * Returns wether non-power-of-two textures * are supported (extension GL_ARB_texture_non_power_of_two). */ bool isNpotSupported(); /** * Returns wether texture rectangles * are supported (extension GL_ARB_texture_rectangle). */ bool areTextureRectanglesSupported(); /** * Returns wether anisotropic texture filtering * is supported (extension GL_EXT_texture_filter_anisotropic). */ bool isAnisotropicFilteringSupported(); /** * Returns the maximum anisotropy. If * anisotropic texture filtering is not * supported, 1.0 is returned. */ float getMaxTextureAnisotropy(); /** * Returns wether texture compression * is supported (extension GL_ARB_texture_compression). */ bool isTextureCompressionSupported(); /** * Returns wether FramebufferObjects (FBOs) * are supported (extension GL_EXT_framebuffer_object). */ bool areFramebufferObjectsSupported(); ///Returns the maximal number of color attachments for a FBO int getMaxColorAttachments(); /** * Overrides the detected GLSL language version. * * @return false, if the passed version string could not be parsed. * In this case, the detected GLSL version is kept. */ bool overrideGLSLVersion(const std::string& versionString); /** * Writes the most important GPU features to the * log (debug-level info). * * @param extensionsString determines wether the * extensions string is also written. This is disabled by default * since the extensions string is usually very long. * @param osString determines wether the operating system describing string * is also written */ virtual void logCapabilities(bool extensionsString = false, bool osString = true); /** * Get the OS version. * Note: On windows > 8, still windows 8 will be reported unless the application is * manifested properly (not easily possible with cmake). * See https://msdn.microsoft.com/de-de/library/windows/desktop/ms724451 for more info. */ OSVersion getOSVersion(); /** * Get the OS version as string. */ std::string getOSVersionString(); protected: /** * Is called by the constructor and performs the * complete hardware detection. The results * are internally stored. */ virtual void detectCapabilities(); /** * Is called by the constructor to query all extensions and * populate \a glExtensions_ */ void queryExtensions(); /** * Is called by the constructor and performs the * operating system detection. The results * are internally stored. */ virtual void detectOS(); static const std::string loggerCat_; private: // detection results are stored in the following members OSVersion osVersion_; std::string osVersionString_; GlVersion glVersion_; std::string glVersionString_; std::vector glExtensions_; std::string glVendorString_; std::string glRendererString_; std::string glslVersionString_; GpuVendor vendor_; bool shaderSupport_; bool shaderSupportARB_; bool computeShaderSupport_; GlVersion shaderVersion_; ShaderModel shaderModel_; int maxTexSize_; bool texturing3D_; int max3DTexSize_; int numTextureUnits_; int numImageUnits_; bool npotTextures_; bool textureRectangles_; bool anisotropicFiltering_; float maxTextureAnisotropy_; bool textureCompression_; bool framebufferObjects_; int maxColorAttachments_; }; } // namespace cgt #define GpuCaps cgt::Singleton::getRef() #endif // CGT_GPUCAPABILITIES_H