00001 /**************************************************************************** 00002 00003 This file is part of the GLC-lib library. 00004 Copyright (C) 2005-2008 Laurent Ribon (laumaya@users.sourceforge.net) 00005 Version 2.0.0, packaged on July 2010. 00006 00007 http://glc-lib.sourceforge.net 00008 00009 GLC-lib is free software; you can redistribute it and/or modify 00010 it under the terms of the GNU Lesser General Public License as published by 00011 the Free Software Foundation; either version 3 of the License, or 00012 (at your option) any later version. 00013 00014 GLC-lib is distributed in the hope that it will be useful, 00015 but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License 00020 along with GLC-lib; if not, write to the Free Software 00021 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00022 00023 *****************************************************************************/ 00024 00026 00027 #include "glc_state.h" 00028 #include "glc_ext.h" 00029 #include "../sceneGraph/glc_octree.h" 00030 00031 #include <QGLFramebufferObject> 00032 00033 bool GLC_State::m_VboSupported= false; 00034 bool GLC_State::m_UseVbo= true; 00035 bool GLC_State::m_GlslSupported= false; 00036 bool GLC_State::m_PointSpriteSupported= false; 00037 bool GLC_State::m_UseShader= true; 00038 bool GLC_State::m_UseSelectionShader= false; 00039 bool GLC_State::m_IsInSelectionMode= false; 00040 bool GLC_State::m_IsPixelCullingActivated= true; 00041 bool GLC_State::m_IsFrameBufferSupported= false; 00042 00043 QString GLC_State::m_Version; 00044 QString GLC_State::m_Vendor; 00045 QString GLC_State::m_Renderer; 00046 00047 bool GLC_State::m_UseCache= false; 00048 00049 GLC_CacheManager GLC_State::m_CacheManager; 00050 00051 bool GLC_State::m_IsSpacePartitionningActivated= false; 00052 bool GLC_State::m_IsFrustumCullingActivated= false; 00053 00054 GLC_State::~GLC_State() 00055 { 00056 } 00057 00058 bool GLC_State::vboSupported() 00059 { 00060 return m_VboSupported; 00061 } 00062 00063 bool GLC_State::vboUsed() 00064 { 00065 return m_UseVbo; 00066 } 00067 00068 bool GLC_State::glslSupported() 00069 { 00070 return m_GlslSupported; 00071 } 00072 00073 bool GLC_State::frameBufferSupported() 00074 { 00075 return m_IsFrameBufferSupported; 00076 } 00077 00078 bool GLC_State::glslUsed() 00079 { 00080 return m_UseShader && m_GlslSupported; 00081 } 00082 00083 bool GLC_State::pointSpriteSupported() 00084 { 00085 return m_PointSpriteSupported; 00086 } 00087 00088 bool GLC_State::selectionShaderUsed() 00089 { 00090 return m_UseSelectionShader; 00091 } 00092 00093 bool GLC_State::isInSelectionMode() 00094 { 00095 return m_IsInSelectionMode; 00096 } 00097 00098 QString GLC_State::version() 00099 { 00100 return m_Version; 00101 } 00102 00103 QString GLC_State::vendor() 00104 { 00105 return m_Vendor; 00106 } 00107 00108 QString GLC_State::renderer() 00109 { 00110 return m_Renderer; 00111 } 00112 00113 bool GLC_State::vendorIsNvidia() 00114 { 00115 return m_Vendor.contains("NVIDIA"); 00116 } 00117 00118 bool GLC_State::isPixelCullingActivated() 00119 { 00120 return m_IsPixelCullingActivated; 00121 } 00122 00123 bool GLC_State::cacheIsUsed() 00124 { 00125 return m_UseCache; 00126 } 00127 00128 GLC_CacheManager& GLC_State::currentCacheManager() 00129 { 00130 return m_CacheManager; 00131 } 00132 00133 bool GLC_State::isSpacePartitionningActivated() 00134 { 00135 return m_IsSpacePartitionningActivated; 00136 } 00137 00138 int GLC_State::defaultOctreeDepth() 00139 { 00140 return GLC_Octree::defaultDepth(); 00141 } 00142 00143 bool GLC_State::isFrustumCullingActivated() 00144 { 00145 return m_IsFrustumCullingActivated; 00146 } 00147 00148 void GLC_State::init() 00149 { 00150 setVboSupport(); 00151 setGlslSupport(); 00152 setPointSpriteSupport(); 00153 setFrameBufferSupport(); 00154 m_Version= (char *) glGetString(GL_VERSION); 00155 m_Vendor= (char *) glGetString(GL_VENDOR); 00156 m_Renderer= (char *) glGetString(GL_RENDERER); 00157 } 00158 00159 void GLC_State::setVboSupport() 00160 { 00161 m_VboSupported= glc::extensionIsSupported("ARB_vertex_buffer_object") && glc::loadVboExtension(); 00162 } 00163 00164 void GLC_State::setVboUsage(const bool vboUsed) 00165 { 00166 m_UseVbo= m_VboSupported && vboUsed; 00167 } 00168 00169 void GLC_State::setGlslSupport() 00170 { 00171 m_GlslSupported= glc::extensionIsSupported("GL_ARB_shading_language_100") && glc::loadGlSlExtension(); 00172 } 00173 00174 void GLC_State::setPointSpriteSupport() 00175 { 00176 m_PointSpriteSupported= glc::extensionIsSupported("GL_ARB_point_parameters") && glc::loadPointSpriteExtension(); 00177 } 00178 00179 void GLC_State::setFrameBufferSupport() 00180 { 00181 m_IsFrameBufferSupported= QGLFramebufferObject::hasOpenGLFramebufferObjects(); 00182 } 00183 00184 void GLC_State::setGlslUsage(const bool glslUsage) 00185 { 00186 m_UseShader= m_GlslSupported && glslUsage; 00187 } 00188 00189 void GLC_State::setSelectionShaderUsage(const bool shaderUsed) 00190 { 00191 m_UseSelectionShader= shaderUsed && m_GlslSupported; 00192 } 00193 00194 void GLC_State::setSelectionMode(const bool mode) 00195 { 00196 m_IsInSelectionMode= mode; 00197 } 00198 00199 void GLC_State::setPixelCullingUsage(const bool activation) 00200 { 00201 m_IsPixelCullingActivated= activation; 00202 } 00203 00204 void GLC_State::setCacheUsage(const bool cacheUsage) 00205 { 00206 m_UseCache= cacheUsage; 00207 } 00208 00209 void GLC_State::setCurrentCacheManager(const GLC_CacheManager& cacheManager) 00210 { 00211 m_CacheManager= cacheManager; 00212 } 00213 00214 void GLC_State::setSpacePartionningUsage(const bool usage) 00215 { 00216 m_IsSpacePartitionningActivated= usage; 00217 } 00218 00219 void GLC_State::setDefaultOctreeDepth(int depth) 00220 { 00221 GLC_Octree::setDefaultDepth(depth); 00222 } 00223 00224 void GLC_State::setFrustumCullingUsage(bool usage) 00225 { 00226 m_IsFrustumCullingActivated= usage; 00227 }