glc_state.cpp

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

SourceForge.net Logo

©2005-2011 Laurent Ribon