2003-01-22 00:45:36 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
2001-09-20 05:19:47 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <float.h>
|
|
|
|
|
|
|
|
#include <osg/Drawable>
|
|
|
|
#include <osg/State>
|
|
|
|
#include <osg/Notify>
|
2002-02-09 06:55:21 +08:00
|
|
|
#include <osg/Node>
|
2003-06-30 05:41:57 +08:00
|
|
|
#include <osg/GLExtensions>
|
2003-07-16 17:52:43 +08:00
|
|
|
#include <osg/Timer>
|
2003-10-09 05:29:45 +08:00
|
|
|
#include <osg/TriangleFunctor>
|
2002-02-09 06:55:21 +08:00
|
|
|
|
|
|
|
#include <algorithm>
|
2002-11-19 18:56:59 +08:00
|
|
|
#include <map>
|
2003-07-16 17:52:43 +08:00
|
|
|
#include <list>
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
#include <OpenThreads/ScopedLock>
|
|
|
|
#include <OpenThreads/Mutex>
|
2004-08-03 19:01:39 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
using namespace osg;
|
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
unsigned int Drawable::s_numberDrawablesReusedLastInLastFrame = 0;
|
2004-09-22 01:26:08 +08:00
|
|
|
unsigned int Drawable::s_numberNewDrawablesInLastFrame = 0;
|
|
|
|
unsigned int Drawable::s_numberDeletedDrawablesInLastFrame = 0;
|
|
|
|
|
2002-11-19 18:56:59 +08:00
|
|
|
// static cache of deleted display lists which can only
|
|
|
|
// by completely deleted once the appropriate OpenGL context
|
|
|
|
// is set. Used osg::Drawable::deleteDisplayList(..) and flushDeletedDisplayLists(..) below.
|
2004-09-23 20:27:56 +08:00
|
|
|
typedef std::multimap<unsigned int,GLuint> DisplayListMap;
|
|
|
|
typedef std::map<unsigned int,DisplayListMap> DeletedDisplayListCache;
|
2004-07-22 03:16:49 +08:00
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
static OpenThreads::Mutex s_mutex_deletedDisplayListCache;
|
2002-11-19 18:56:59 +08:00
|
|
|
static DeletedDisplayListCache s_deletedDisplayListCache;
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
GLuint Drawable::generateDisplayList(unsigned int contextID, unsigned int sizeHint)
|
2004-09-22 01:26:08 +08:00
|
|
|
{
|
2004-09-22 05:33:52 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedDisplayListCache);
|
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
DisplayListMap& dll = s_deletedDisplayListCache[contextID];
|
2004-09-22 05:33:52 +08:00
|
|
|
if (dll.empty())
|
|
|
|
{
|
|
|
|
++s_numberNewDrawablesInLastFrame;
|
|
|
|
return glGenLists( 1 );
|
|
|
|
}
|
2004-09-22 01:26:08 +08:00
|
|
|
else
|
|
|
|
{
|
2004-09-23 20:27:56 +08:00
|
|
|
DisplayListMap::iterator itr = dll.lower_bound(sizeHint);
|
|
|
|
if (itr!=dll.end())
|
|
|
|
{
|
|
|
|
// osg::notify(osg::NOTICE)<<"Reusing a display list of size = "<<itr->first<<" for requested size = "<<sizeHint<<std::endl;
|
|
|
|
|
|
|
|
++s_numberDrawablesReusedLastInLastFrame;
|
|
|
|
|
|
|
|
GLuint globj = itr->second;
|
|
|
|
dll.erase(itr);
|
|
|
|
|
|
|
|
return globj;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// osg::notify(osg::NOTICE)<<"Creating a new display list of size = "<<sizeHint<<" although "<<dll.size()<<" are available"<<std::endl;
|
|
|
|
++s_numberNewDrawablesInLastFrame;
|
|
|
|
return glGenLists( 1 );
|
|
|
|
}
|
2004-09-22 01:26:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
unsigned int s_minimumNumberOfDisplayListsToRetainInCache = 0;
|
|
|
|
void Drawable::setMinimumNumberOfDisplayListsToRetainInCache(unsigned int minimum)
|
|
|
|
{
|
|
|
|
s_minimumNumberOfDisplayListsToRetainInCache = minimum;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int Drawable::getMinimumNumberOfDisplayListsToRetainInCache()
|
|
|
|
{
|
|
|
|
return s_minimumNumberOfDisplayListsToRetainInCache;
|
|
|
|
}
|
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
void Drawable::deleteDisplayList(unsigned int contextID,GLuint globj, unsigned int sizeHint)
|
2003-01-23 07:34:18 +08:00
|
|
|
{
|
|
|
|
if (globj!=0)
|
|
|
|
{
|
2004-07-22 03:16:49 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedDisplayListCache);
|
2004-09-22 05:33:52 +08:00
|
|
|
|
2003-01-23 07:34:18 +08:00
|
|
|
// insert the globj into the cache for the appropriate context.
|
2004-09-23 20:27:56 +08:00
|
|
|
s_deletedDisplayListCache[contextID].insert(DisplayListMap::value_type(sizeHint,globj));
|
2003-01-23 07:34:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
void Drawable::flushAllDeletedDisplayLists(unsigned int contextID)
|
|
|
|
{
|
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedDisplayListCache);
|
|
|
|
|
|
|
|
DeletedDisplayListCache::iterator citr = s_deletedDisplayListCache.find(contextID);
|
|
|
|
if (citr!=s_deletedDisplayListCache.end())
|
|
|
|
{
|
2004-09-23 20:27:56 +08:00
|
|
|
DisplayListMap& dll = citr->second;
|
2004-09-22 05:33:52 +08:00
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
for(DisplayListMap::iterator ditr=dll.begin();
|
2004-09-22 05:33:52 +08:00
|
|
|
ditr!=dll.end();
|
|
|
|
++ditr)
|
|
|
|
{
|
2004-09-23 20:27:56 +08:00
|
|
|
glDeleteLists(ditr->second,1);
|
2004-09-22 05:33:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
dll.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::flushDeletedDisplayLists(unsigned int contextID, double& availableTime)
|
2003-01-23 07:34:18 +08:00
|
|
|
{
|
2003-07-16 17:52:43 +08:00
|
|
|
// if no time available don't try to flush objects.
|
|
|
|
if (availableTime<=0.0) return;
|
|
|
|
|
|
|
|
const osg::Timer& timer = *osg::Timer::instance();
|
|
|
|
osg::Timer_t start_tick = timer.tick();
|
|
|
|
double elapsedTime = 0.0;
|
|
|
|
|
|
|
|
unsigned int noDeleted = 0;
|
|
|
|
|
2003-01-23 07:34:18 +08:00
|
|
|
{
|
2004-07-22 03:16:49 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedDisplayListCache);
|
|
|
|
|
|
|
|
DeletedDisplayListCache::iterator citr = s_deletedDisplayListCache.find(contextID);
|
|
|
|
if (citr!=s_deletedDisplayListCache.end())
|
2003-01-23 07:34:18 +08:00
|
|
|
{
|
2004-09-23 20:27:56 +08:00
|
|
|
DisplayListMap& dll = citr->second;
|
2004-09-22 05:33:52 +08:00
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
|
|
|
|
bool trimFromFront = true;
|
|
|
|
if (trimFromFront)
|
2004-07-22 03:16:49 +08:00
|
|
|
{
|
2004-09-23 20:27:56 +08:00
|
|
|
unsigned int prev_size = dll.size();
|
|
|
|
|
|
|
|
DisplayListMap::iterator ditr=dll.begin();
|
|
|
|
unsigned int maxNumToDelete = (dll.size() > s_minimumNumberOfDisplayListsToRetainInCache) ? dll.size()-s_minimumNumberOfDisplayListsToRetainInCache : 0;
|
|
|
|
for(;
|
|
|
|
ditr!=dll.end() && elapsedTime<availableTime && noDeleted<maxNumToDelete;
|
|
|
|
++ditr)
|
|
|
|
{
|
|
|
|
glDeleteLists(ditr->second,1);
|
|
|
|
|
|
|
|
elapsedTime = timer.delta_s(start_tick,timer.tick());
|
|
|
|
++noDeleted;
|
|
|
|
|
|
|
|
++Drawable::s_numberDeletedDrawablesInLastFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ditr!=dll.begin()) dll.erase(dll.begin(),ditr);
|
|
|
|
|
|
|
|
if (noDeleted+dll.size() != prev_size)
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error in delete"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned int prev_size = dll.size();
|
|
|
|
|
|
|
|
DisplayListMap::reverse_iterator ditr=dll.rbegin();
|
|
|
|
unsigned int maxNumToDelete = (dll.size() > s_minimumNumberOfDisplayListsToRetainInCache) ? dll.size()-s_minimumNumberOfDisplayListsToRetainInCache : 0;
|
|
|
|
for(;
|
|
|
|
ditr!=dll.rend() && elapsedTime<availableTime && noDeleted<maxNumToDelete;
|
|
|
|
++ditr)
|
|
|
|
{
|
|
|
|
glDeleteLists(ditr->second,1);
|
|
|
|
|
|
|
|
elapsedTime = timer.delta_s(start_tick,timer.tick());
|
|
|
|
++noDeleted;
|
|
|
|
|
|
|
|
++Drawable::s_numberDeletedDrawablesInLastFrame;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ditr!=dll.rbegin()) dll.erase(ditr.base(),dll.end());
|
|
|
|
|
|
|
|
if (noDeleted+dll.size() != prev_size)
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error in delete"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
2004-07-22 03:16:49 +08:00
|
|
|
}
|
2003-01-23 07:34:18 +08:00
|
|
|
}
|
2004-09-22 01:26:08 +08:00
|
|
|
elapsedTime = timer.delta_s(start_tick,timer.tick());
|
2004-07-22 03:16:49 +08:00
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
// if (noDeleted) notify(NOTICE)<<"Number display lists deleted = "<<noDeleted<<" elapsed time"<<elapsedTime<<std::endl;
|
2003-07-16 17:52:43 +08:00
|
|
|
|
|
|
|
availableTime -= elapsedTime;
|
2003-01-23 07:34:18 +08:00
|
|
|
}
|
|
|
|
|
2004-07-22 03:16:49 +08:00
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
static OpenThreads::Mutex s_mutex_deletedVertexBufferObjectCache;
|
2004-07-22 03:16:49 +08:00
|
|
|
static DeletedDisplayListCache s_deletedVertexBufferObjectCache;
|
|
|
|
|
2003-06-30 05:41:57 +08:00
|
|
|
void Drawable::deleteVertexBufferObject(unsigned int contextID,GLuint globj)
|
|
|
|
{
|
|
|
|
if (globj!=0)
|
|
|
|
{
|
2004-07-22 03:16:49 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedVertexBufferObjectCache);
|
|
|
|
|
2003-06-30 05:41:57 +08:00
|
|
|
// insert the globj into the cache for the appropriate context.
|
2004-09-23 20:27:56 +08:00
|
|
|
s_deletedVertexBufferObjectCache[contextID].insert(DisplayListMap::value_type(0,globj));
|
2003-06-30 05:41:57 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** flush all the cached display list which need to be deleted
|
|
|
|
* in the OpenGL context related to contextID.*/
|
2003-07-16 17:52:43 +08:00
|
|
|
void Drawable::flushDeletedVertexBufferObjects(unsigned int contextID,double /*currentTime*/, double& availableTime)
|
2003-06-30 05:41:57 +08:00
|
|
|
{
|
2003-07-16 17:52:43 +08:00
|
|
|
// if no time available don't try to flush objects.
|
|
|
|
if (availableTime<=0.0) return;
|
|
|
|
|
|
|
|
const osg::Timer& timer = *osg::Timer::instance();
|
|
|
|
osg::Timer_t start_tick = timer.tick();
|
|
|
|
double elapsedTime = 0.0;
|
|
|
|
|
|
|
|
|
2003-06-30 05:41:57 +08:00
|
|
|
{
|
2004-07-22 03:16:49 +08:00
|
|
|
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(s_mutex_deletedVertexBufferObjectCache);
|
2003-06-30 05:41:57 +08:00
|
|
|
|
2004-07-22 03:16:49 +08:00
|
|
|
DeletedDisplayListCache::iterator citr = s_deletedVertexBufferObjectCache.find(contextID);
|
|
|
|
if (citr!=s_deletedVertexBufferObjectCache.end())
|
2003-06-30 05:41:57 +08:00
|
|
|
{
|
2004-07-22 03:16:49 +08:00
|
|
|
const Extensions* extensions = getExtensions(contextID,true);
|
2003-07-16 17:52:43 +08:00
|
|
|
|
2004-07-22 03:16:49 +08:00
|
|
|
unsigned int noDeleted = 0;
|
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
DisplayListMap& dll = citr->second;
|
2004-07-22 03:16:49 +08:00
|
|
|
|
2004-09-23 20:27:56 +08:00
|
|
|
DisplayListMap::iterator ditr=dll.begin();
|
|
|
|
for(;
|
2004-07-22 03:16:49 +08:00
|
|
|
ditr!=dll.end() && elapsedTime<availableTime;
|
2004-09-23 20:27:56 +08:00
|
|
|
++ditr)
|
2004-07-22 03:16:49 +08:00
|
|
|
{
|
2004-09-23 20:27:56 +08:00
|
|
|
extensions->glDeleteBuffers(1,&(ditr->second));
|
2004-07-22 03:16:49 +08:00
|
|
|
elapsedTime = timer.delta_s(start_tick,timer.tick());
|
|
|
|
++noDeleted;
|
|
|
|
}
|
2004-09-23 20:27:56 +08:00
|
|
|
if (ditr!=dll.begin()) dll.erase(dll.begin(),ditr);
|
2004-07-22 03:16:49 +08:00
|
|
|
|
|
|
|
if (noDeleted!=0) notify(osg::INFO)<<"Number VBOs deleted = "<<noDeleted<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
2003-07-16 17:52:43 +08:00
|
|
|
|
|
|
|
availableTime -= elapsedTime;
|
2003-06-30 05:41:57 +08:00
|
|
|
}
|
|
|
|
|
2003-01-23 07:34:18 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
Drawable::Drawable()
|
|
|
|
{
|
|
|
|
_bbox_computed = false;
|
|
|
|
|
|
|
|
// Note, if your are defining a subclass from drawable which is
|
|
|
|
// dynamically updated then you should set both the following to
|
|
|
|
// to false in your constructor. This will prevent any display
|
|
|
|
// lists from being automatically created and safeguard the
|
|
|
|
// dynamic updating of data.
|
|
|
|
_supportsDisplayList = true;
|
|
|
|
_useDisplayList = true;
|
2003-06-30 05:41:57 +08:00
|
|
|
|
|
|
|
_supportsVertexBufferObjects = false;
|
2003-07-10 22:53:07 +08:00
|
|
|
_useVertexBufferObjects = false;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2002-02-07 09:07:11 +08:00
|
|
|
Drawable::Drawable(const Drawable& drawable,const CopyOp& copyop):
|
|
|
|
Object(drawable,copyop),
|
2002-02-09 06:55:21 +08:00
|
|
|
_parents(), // leave empty as parentList is managed by Geode
|
2002-09-02 20:31:35 +08:00
|
|
|
_stateset(copyop(drawable._stateset.get())),
|
2002-10-30 21:27:15 +08:00
|
|
|
_bbox(drawable._bbox),
|
|
|
|
_bbox_computed(drawable._bbox_computed),
|
|
|
|
_shape(copyop(drawable._shape.get())),
|
2002-02-07 09:07:11 +08:00
|
|
|
_supportsDisplayList(drawable._supportsDisplayList),
|
|
|
|
_useDisplayList(drawable._useDisplayList),
|
2003-06-30 05:41:57 +08:00
|
|
|
_supportsVertexBufferObjects(drawable._supportsVertexBufferObjects),
|
|
|
|
_useVertexBufferObjects(drawable._useVertexBufferObjects),
|
2003-12-16 16:56:49 +08:00
|
|
|
_updateCallback(drawable._updateCallback),
|
|
|
|
_cullCallback(drawable._cullCallback),
|
|
|
|
_drawCallback(drawable._drawCallback)
|
2002-11-19 18:56:59 +08:00
|
|
|
{
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
Drawable::~Drawable()
|
|
|
|
{
|
|
|
|
dirtyDisplayList();
|
|
|
|
}
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
void Drawable::addParent(osg::Node* node)
|
|
|
|
{
|
|
|
|
_parents.push_back(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::removeParent(osg::Node* node)
|
|
|
|
{
|
|
|
|
ParentList::iterator pitr = std::find(_parents.begin(),_parents.end(),node);
|
|
|
|
if (pitr!=_parents.end()) _parents.erase(pitr);
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
osg::StateSet* Drawable::getOrCreateStateSet()
|
|
|
|
{
|
2002-12-16 21:40:58 +08:00
|
|
|
if (!_stateset) _stateset = new StateSet;
|
2002-09-02 20:31:35 +08:00
|
|
|
return _stateset.get();
|
|
|
|
}
|
|
|
|
|
2002-02-09 06:55:21 +08:00
|
|
|
void Drawable::dirtyBound()
|
|
|
|
{
|
|
|
|
if (_bbox_computed)
|
|
|
|
{
|
|
|
|
_bbox_computed = false;
|
|
|
|
|
|
|
|
// dirty parent bounding sphere's to ensure that all are valid.
|
|
|
|
for(ParentList::iterator itr=_parents.begin();
|
|
|
|
itr!=_parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
(*itr)->dirtyBound();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
void Drawable::compileGLObjects(State& state) const
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
if (!_useDisplayList) return;
|
|
|
|
|
|
|
|
// get the contextID (user defined ID of 0 upwards) for the
|
|
|
|
// current OpenGL context.
|
2003-02-14 19:41:52 +08:00
|
|
|
unsigned int contextID = state.getContextID();
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
// get the globj for the current contextID.
|
2003-02-15 00:52:47 +08:00
|
|
|
GLuint& globj = _globjList[contextID];
|
2001-09-20 05:19:47 +08:00
|
|
|
|
|
|
|
// call the globj if already set otherwise comple and execute.
|
|
|
|
if( globj != 0 )
|
2004-09-22 05:33:52 +08:00
|
|
|
{
|
2001-09-20 05:19:47 +08:00
|
|
|
glDeleteLists( globj, 1 );
|
|
|
|
}
|
|
|
|
|
2004-09-22 05:33:52 +08:00
|
|
|
globj = generateDisplayList(contextID, getGLObjectSizeHint());
|
2001-09-20 05:19:47 +08:00
|
|
|
glNewList( globj, GL_COMPILE );
|
2002-05-29 07:43:22 +08:00
|
|
|
|
|
|
|
if (_drawCallback.valid())
|
2002-11-06 23:43:11 +08:00
|
|
|
_drawCallback->drawImplementation(state,this);
|
2002-05-29 07:43:22 +08:00
|
|
|
else
|
2002-11-06 23:43:11 +08:00
|
|
|
drawImplementation(state);
|
2002-05-29 07:43:22 +08:00
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
glEndList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-07-20 13:37:59 +08:00
|
|
|
void Drawable::releaseGLObjects(State* state) const
|
|
|
|
{
|
|
|
|
if (!_useDisplayList) return;
|
|
|
|
|
|
|
|
if (state)
|
|
|
|
{
|
|
|
|
// get the contextID (user defined ID of 0 upwards) for the
|
|
|
|
// current OpenGL context.
|
|
|
|
unsigned int contextID = state->getContextID();
|
|
|
|
|
|
|
|
// get the globj for the current contextID.
|
|
|
|
GLuint& globj = _globjList[contextID];
|
|
|
|
|
|
|
|
// call the globj if already set otherwise comple and execute.
|
|
|
|
if( globj != 0 )
|
|
|
|
{
|
|
|
|
glDeleteLists( globj, 1 );
|
|
|
|
globj = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const_cast<Drawable*>(this)->dirtyDisplayList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void Drawable::setSupportsDisplayList(bool flag)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
// if value unchanged simply return.
|
|
|
|
if (_supportsDisplayList==flag) return;
|
|
|
|
|
|
|
|
// if previously set to true then need to check about display lists.
|
|
|
|
if (_supportsDisplayList)
|
|
|
|
{
|
|
|
|
if (_useDisplayList)
|
|
|
|
{
|
|
|
|
// used to support display lists and display lists switched
|
|
|
|
// on so now delete them and turn useDisplayList off.
|
|
|
|
dirtyDisplayList();
|
|
|
|
_useDisplayList = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// set with new value.
|
|
|
|
_supportsDisplayList=flag;
|
|
|
|
}
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
void Drawable::setUseDisplayList(bool flag)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
// if value unchanged simply return.
|
|
|
|
if (_useDisplayList==flag) return;
|
|
|
|
|
|
|
|
// if was previously set to true, remove display list.
|
|
|
|
if (_useDisplayList)
|
|
|
|
{
|
|
|
|
dirtyDisplayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_supportsDisplayList)
|
|
|
|
{
|
|
|
|
|
|
|
|
// set with new value.
|
|
|
|
_useDisplayList = flag;
|
|
|
|
|
|
|
|
}
|
|
|
|
else // does not support display lists.
|
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
{
|
2001-12-15 07:18:28 +08:00
|
|
|
notify(WARN)<<"Warning: attempt to setUseDisplayList(true) on a drawable with does not support display lists."<<std::endl;
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// set with new value.
|
|
|
|
_useDisplayList = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-06 03:49:06 +08:00
|
|
|
void Drawable::setUseVertexBufferObjects(bool flag)
|
|
|
|
{
|
|
|
|
// if value unchanged simply return.
|
|
|
|
if (_useVertexBufferObjects==flag) return;
|
|
|
|
|
|
|
|
// if was previously set to true, remove display list.
|
|
|
|
if (_useVertexBufferObjects)
|
|
|
|
{
|
|
|
|
dirtyDisplayList();
|
|
|
|
}
|
|
|
|
|
|
|
|
_useVertexBufferObjects = flag;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2001-09-20 05:19:47 +08:00
|
|
|
void Drawable::dirtyDisplayList()
|
|
|
|
{
|
2003-07-06 03:08:30 +08:00
|
|
|
unsigned int i;
|
|
|
|
for(i=0;i<_globjList.size();++i)
|
2001-09-20 05:19:47 +08:00
|
|
|
{
|
|
|
|
if (_globjList[i] != 0)
|
|
|
|
{
|
2004-09-22 01:26:08 +08:00
|
|
|
Drawable::deleteDisplayList(i,_globjList[i], getGLObjectSizeHint());
|
2001-09-20 05:19:47 +08:00
|
|
|
_globjList[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2003-06-30 05:41:57 +08:00
|
|
|
|
2003-07-06 03:08:30 +08:00
|
|
|
for(i=0;i<_vboList.size();++i)
|
2003-06-30 05:41:57 +08:00
|
|
|
{
|
|
|
|
if (_vboList[i] != 0)
|
|
|
|
{
|
|
|
|
Drawable::deleteVertexBufferObject(i,_vboList[i]);
|
|
|
|
_vboList[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
2001-09-20 05:19:47 +08:00
|
|
|
}
|
|
|
|
|
2002-07-10 23:35:47 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
void Drawable::setUpdateCallback(UpdateCallback* ac)
|
2002-07-10 23:35:47 +08:00
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_updateCallback==ac) return;
|
2002-07-10 23:35:47 +08:00
|
|
|
|
|
|
|
int delta = 0;
|
2002-12-19 23:55:40 +08:00
|
|
|
if (_updateCallback.valid()) --delta;
|
2002-07-10 23:35:47 +08:00
|
|
|
if (ac) ++delta;
|
2002-07-11 04:30:57 +08:00
|
|
|
|
2002-12-19 23:55:40 +08:00
|
|
|
_updateCallback = ac;
|
2002-07-10 23:35:47 +08:00
|
|
|
|
|
|
|
if (delta!=0)
|
|
|
|
{
|
|
|
|
for(ParentList::iterator itr=_parents.begin();
|
|
|
|
itr!=_parents.end();
|
|
|
|
++itr)
|
|
|
|
{
|
2002-12-19 23:55:40 +08:00
|
|
|
(*itr)->setNumChildrenRequiringUpdateTraversal((*itr)->getNumChildrenRequiringUpdateTraversal()+delta);
|
2002-07-10 23:35:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-07-19 06:35:54 +08:00
|
|
|
|
|
|
|
struct ComputeBound : public Drawable::PrimitiveFunctor
|
|
|
|
{
|
|
|
|
ComputeBound():_vertices(0) {}
|
|
|
|
|
2003-06-30 05:41:57 +08:00
|
|
|
virtual void setVertexArray(unsigned int,const Vec2*)
|
2003-06-24 23:40:09 +08:00
|
|
|
{
|
|
|
|
notify(WARN)<<"ComputeBound does not support Vec2* vertex arrays"<<std::endl;
|
|
|
|
}
|
|
|
|
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void setVertexArray(unsigned int,const Vec3* vertices) { _vertices = vertices; }
|
2002-07-19 06:35:54 +08:00
|
|
|
|
2003-06-30 05:41:57 +08:00
|
|
|
virtual void setVertexArray(unsigned int,const Vec4*)
|
2003-06-24 23:40:09 +08:00
|
|
|
{
|
|
|
|
notify(WARN)<<"ComputeBound does not support Vec4* vertex arrays"<<std::endl;
|
|
|
|
}
|
|
|
|
|
2002-07-19 06:35:54 +08:00
|
|
|
virtual void drawArrays(GLenum,GLint first,GLsizei count)
|
|
|
|
{
|
|
|
|
if (_vertices)
|
|
|
|
{
|
2002-11-06 18:24:33 +08:00
|
|
|
const osg::Vec3* vert = _vertices+first;
|
2002-07-19 06:35:54 +08:00
|
|
|
for(;count>0;--count,++vert)
|
|
|
|
{
|
|
|
|
_bb.expandBy(*vert);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void drawElements(GLenum,GLsizei count,const GLubyte* indices)
|
2002-07-19 06:35:54 +08:00
|
|
|
{
|
|
|
|
if (_vertices)
|
|
|
|
{
|
|
|
|
for(;count>0;--count,++indices)
|
|
|
|
{
|
|
|
|
_bb.expandBy(_vertices[*indices]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void drawElements(GLenum,GLsizei count,const GLushort* indices)
|
2002-07-19 06:35:54 +08:00
|
|
|
{
|
|
|
|
if (_vertices)
|
|
|
|
{
|
|
|
|
for(;count>0;--count,++indices)
|
|
|
|
{
|
|
|
|
_bb.expandBy(_vertices[*indices]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-06 18:24:33 +08:00
|
|
|
virtual void drawElements(GLenum,GLsizei count,const GLuint* indices)
|
2002-07-19 06:35:54 +08:00
|
|
|
{
|
|
|
|
if (_vertices)
|
|
|
|
{
|
|
|
|
for(;count>0;--count,++indices)
|
|
|
|
{
|
|
|
|
_bb.expandBy(_vertices[*indices]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void begin(GLenum) {}
|
2003-06-24 23:40:09 +08:00
|
|
|
virtual void vertex(const Vec2& vert) { _bb.expandBy(osg::Vec3(vert[0],vert[1],0.0f)); }
|
2002-07-19 06:35:54 +08:00
|
|
|
virtual void vertex(const Vec3& vert) { _bb.expandBy(vert); }
|
2003-06-24 23:40:09 +08:00
|
|
|
virtual void vertex(const Vec4& vert) { if (vert[3]!=0.0f) _bb.expandBy(osg::Vec3(vert[0],vert[1],vert[2])/vert[3]); }
|
|
|
|
virtual void vertex(float x,float y) { _bb.expandBy(x,y,1.0f); }
|
2002-07-19 06:35:54 +08:00
|
|
|
virtual void vertex(float x,float y,float z) { _bb.expandBy(x,y,z); }
|
2003-06-24 23:40:09 +08:00
|
|
|
virtual void vertex(float x,float y,float z,float w) { if (w!=0.0f) _bb.expandBy(x/w,y/w,z/w); }
|
2002-07-19 06:35:54 +08:00
|
|
|
virtual void end() {}
|
|
|
|
|
2002-11-06 18:24:33 +08:00
|
|
|
const Vec3* _vertices;
|
2002-07-19 06:35:54 +08:00
|
|
|
BoundingBox _bb;
|
|
|
|
};
|
|
|
|
|
2002-09-02 20:31:35 +08:00
|
|
|
bool Drawable::computeBound() const
|
2002-07-19 06:35:54 +08:00
|
|
|
{
|
|
|
|
ComputeBound cb;
|
|
|
|
|
|
|
|
Drawable* non_const_this = const_cast<Drawable*>(this);
|
|
|
|
non_const_this->accept(cb);
|
|
|
|
|
|
|
|
_bbox = cb._bb;
|
|
|
|
_bbox_computed = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-03-12 05:53:28 +08:00
|
|
|
void Drawable::setBound(const BoundingBox& bb) const
|
|
|
|
{
|
|
|
|
_bbox = bb;
|
|
|
|
_bbox_computed = true;
|
|
|
|
}
|
2003-06-30 05:41:57 +08:00
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Extension support
|
|
|
|
//
|
|
|
|
|
|
|
|
typedef buffered_value< ref_ptr<Drawable::Extensions> > BufferedExtensions;
|
|
|
|
static BufferedExtensions s_extensions;
|
|
|
|
|
|
|
|
Drawable::Extensions* Drawable::getExtensions(unsigned int contextID,bool createIfNotInitalized)
|
|
|
|
{
|
|
|
|
if (!s_extensions[contextID] && createIfNotInitalized) s_extensions[contextID] = new Drawable::Extensions;
|
|
|
|
return s_extensions[contextID].get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::setExtensions(unsigned int contextID,Extensions* extensions)
|
|
|
|
{
|
|
|
|
s_extensions[contextID] = extensions;
|
|
|
|
}
|
|
|
|
|
|
|
|
Drawable::Extensions::Extensions()
|
|
|
|
{
|
|
|
|
setupGLExtenions();
|
|
|
|
}
|
|
|
|
|
|
|
|
Drawable::Extensions::Extensions(const Extensions& rhs):
|
|
|
|
Referenced()
|
|
|
|
{
|
|
|
|
_isVertexProgramSupported = rhs._isVertexProgramSupported;
|
|
|
|
_isSecondaryColorSupported = rhs._isSecondaryColorSupported;
|
|
|
|
_isFogCoordSupported = rhs._isFogCoordSupported;
|
|
|
|
_isMultiTexSupported = rhs._isMultiTexSupported;
|
2003-07-24 04:53:53 +08:00
|
|
|
_isOcclusionQuerySupported = rhs._isOcclusionQuerySupported;
|
2003-06-30 05:41:57 +08:00
|
|
|
_glFogCoordfv = rhs._glFogCoordfv;
|
|
|
|
_glSecondaryColor3ubv = rhs._glSecondaryColor3ubv;
|
|
|
|
_glSecondaryColor3fv = rhs._glSecondaryColor3fv;
|
|
|
|
_glMultiTexCoord1f = rhs._glMultiTexCoord1f;
|
|
|
|
_glMultiTexCoord2fv = rhs._glMultiTexCoord2fv;
|
|
|
|
_glMultiTexCoord3fv = rhs._glMultiTexCoord3fv;
|
|
|
|
_glMultiTexCoord4fv = rhs._glMultiTexCoord4fv;
|
|
|
|
_glVertexAttrib1s = rhs._glVertexAttrib1s;
|
|
|
|
_glVertexAttrib1f = rhs._glVertexAttrib1f;
|
|
|
|
_glVertexAttrib2fv = rhs._glVertexAttrib2fv;
|
|
|
|
_glVertexAttrib3fv = rhs._glVertexAttrib3fv;
|
|
|
|
_glVertexAttrib4fv = rhs._glVertexAttrib4fv;
|
|
|
|
_glVertexAttrib4ubv = rhs._glVertexAttrib4ubv;
|
|
|
|
_glVertexAttrib4Nubv = rhs._glVertexAttrib4Nubv;
|
|
|
|
_glGenBuffers = rhs._glGenBuffers;
|
|
|
|
_glBindBuffer = rhs._glBindBuffer;
|
|
|
|
_glBufferData = rhs._glBufferData;
|
|
|
|
_glBufferSubData = rhs._glBufferSubData;
|
|
|
|
_glDeleteBuffers = rhs._glDeleteBuffers;
|
2003-07-24 04:53:53 +08:00
|
|
|
_glGenOcclusionQueries = rhs._glGenOcclusionQueries;
|
|
|
|
_glDeleteOcclusionQueries = rhs._glDeleteOcclusionQueries;
|
|
|
|
_glIsOcclusionQuery = rhs._glIsOcclusionQuery;
|
|
|
|
_glBeginOcclusionQuery = rhs._glBeginOcclusionQuery;
|
|
|
|
_glEndOcclusionQuery = rhs._glEndOcclusionQuery;
|
|
|
|
_glGetOcclusionQueryiv = rhs._glGetOcclusionQueryiv;
|
|
|
|
_glGetOcclusionQueryuiv = rhs._glGetOcclusionQueryuiv;
|
2003-12-09 19:20:44 +08:00
|
|
|
_gl_gen_queries_arb = rhs._gl_gen_queries_arb;
|
|
|
|
_gl_delete_queries_arb = rhs._gl_delete_queries_arb;
|
|
|
|
_gl_is_query_arb = rhs._gl_is_query_arb;
|
|
|
|
_gl_begin_query_arb = rhs._gl_begin_query_arb;
|
|
|
|
_gl_end_query_arb = rhs._gl_end_query_arb;
|
|
|
|
_gl_get_queryiv_arb = rhs._gl_get_queryiv_arb;
|
|
|
|
_gl_get_query_objectiv_arb = rhs._gl_get_query_objectiv_arb;
|
|
|
|
_gl_get_query_objectuiv_arb = rhs._gl_get_query_objectuiv_arb;
|
2003-06-30 05:41:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Drawable::Extensions::lowestCommonDenominator(const Extensions& rhs)
|
|
|
|
{
|
|
|
|
if (!rhs._isVertexProgramSupported) _isVertexProgramSupported = false;
|
|
|
|
if (!rhs._isSecondaryColorSupported) _isSecondaryColorSupported = false;
|
|
|
|
if (!rhs._isFogCoordSupported) _isFogCoordSupported = false;
|
|
|
|
if (!rhs._isMultiTexSupported) _isMultiTexSupported = false;
|
2003-07-24 04:53:53 +08:00
|
|
|
if (!rhs._isOcclusionQuerySupported) _isOcclusionQuerySupported = false;
|
2003-12-09 19:20:44 +08:00
|
|
|
if (!rhs._isARBOcclusionQuerySupported) _isARBOcclusionQuerySupported = false;
|
2003-06-30 05:41:57 +08:00
|
|
|
|
|
|
|
if (!rhs._glFogCoordfv) _glFogCoordfv = 0;
|
|
|
|
if (!rhs._glSecondaryColor3ubv) _glSecondaryColor3ubv = 0;
|
|
|
|
if (!rhs._glSecondaryColor3fv) _glSecondaryColor3fv = 0;
|
|
|
|
if (!rhs._glMultiTexCoord1f) _glMultiTexCoord1f = 0;
|
|
|
|
if (!rhs._glMultiTexCoord2fv) _glMultiTexCoord2fv = 0;
|
|
|
|
if (!rhs._glMultiTexCoord3fv) _glMultiTexCoord3fv = 0;
|
|
|
|
if (!rhs._glMultiTexCoord4fv) _glMultiTexCoord4fv = 0;
|
|
|
|
|
|
|
|
if (!rhs._glVertexAttrib1s) _glVertexAttrib1s = 0;
|
|
|
|
if (!rhs._glVertexAttrib1f) _glVertexAttrib1f = 0;
|
|
|
|
if (!rhs._glVertexAttrib2fv) _glVertexAttrib2fv = 0;
|
|
|
|
if (!rhs._glVertexAttrib3fv) _glVertexAttrib3fv = 0;
|
|
|
|
if (!rhs._glVertexAttrib4fv) _glVertexAttrib4fv = 0;
|
|
|
|
if (!rhs._glVertexAttrib4ubv) _glVertexAttrib4ubv = 0;
|
|
|
|
if (!rhs._glVertexAttrib4Nubv) _glVertexAttrib4Nubv = 0;
|
|
|
|
|
|
|
|
if (!rhs._glGenBuffers) _glGenBuffers = 0;
|
|
|
|
if (!rhs._glBindBuffer) _glBindBuffer = 0;
|
|
|
|
if (!rhs._glBufferData) _glBufferData = 0;
|
|
|
|
if (!rhs._glBufferSubData) _glBufferSubData = 0;
|
|
|
|
if (!rhs._glDeleteBuffers) _glDeleteBuffers = 0;
|
2003-07-24 04:53:53 +08:00
|
|
|
|
|
|
|
if (!rhs._glGenOcclusionQueries) _glGenOcclusionQueries = 0;
|
|
|
|
if (!rhs._glDeleteOcclusionQueries) _glDeleteOcclusionQueries = 0;
|
|
|
|
if (!rhs._glIsOcclusionQuery) _glIsOcclusionQuery = 0;
|
|
|
|
if (!rhs._glBeginOcclusionQuery) _glBeginOcclusionQuery = 0;
|
|
|
|
if (!rhs._glEndOcclusionQuery) _glEndOcclusionQuery = 0;
|
|
|
|
if (!rhs._glGetOcclusionQueryiv) _glGetOcclusionQueryiv = 0;
|
|
|
|
if (!rhs._glGetOcclusionQueryuiv) _glGetOcclusionQueryuiv = 0;
|
2003-12-09 19:20:44 +08:00
|
|
|
|
|
|
|
if (!rhs._gl_gen_queries_arb) _gl_gen_queries_arb = 0;
|
|
|
|
if (!rhs._gl_delete_queries_arb) _gl_delete_queries_arb = 0;
|
|
|
|
if (!rhs._gl_is_query_arb) _gl_is_query_arb = 0;
|
|
|
|
if (!rhs._gl_begin_query_arb) _gl_begin_query_arb = 0;
|
|
|
|
if (!rhs._gl_end_query_arb) _gl_end_query_arb = 0;
|
|
|
|
if (!rhs._gl_get_queryiv_arb) _gl_get_queryiv_arb = 0;
|
|
|
|
if (!rhs._gl_get_query_objectiv_arb) _gl_get_query_objectiv_arb = 0;
|
|
|
|
if (!rhs._gl_get_query_objectuiv_arb) _gl_get_query_objectuiv_arb = 0;
|
2003-06-30 05:41:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::setupGLExtenions()
|
|
|
|
{
|
|
|
|
_isVertexProgramSupported = isGLExtensionSupported("GL_ARB_vertex_program");
|
|
|
|
_isSecondaryColorSupported = isGLExtensionSupported("GL_EXT_secondary_color");
|
|
|
|
_isFogCoordSupported = isGLExtensionSupported("GL_EXT_fog_coord");
|
|
|
|
_isMultiTexSupported = isGLExtensionSupported("GL_ARB_multitexture");
|
2003-07-24 04:53:53 +08:00
|
|
|
_isOcclusionQuerySupported = osg::isGLExtensionSupported( "GL_NV_occlusion_query" );
|
2003-12-09 19:20:44 +08:00
|
|
|
_isARBOcclusionQuerySupported = osg::isGLExtensionSupported( "GL_ARB_occlusion_query" );
|
2003-06-30 05:41:57 +08:00
|
|
|
|
|
|
|
_glFogCoordfv = ((FogCoordProc)osg::getGLExtensionFuncPtr("glFogCoordfv","glFogCoordfvEXT"));
|
|
|
|
_glSecondaryColor3ubv = ((SecondaryColor3ubvProc)osg::getGLExtensionFuncPtr("glSecondaryColor3ubv","glSecondaryColor3ubvEXT"));
|
|
|
|
_glSecondaryColor3fv = ((SecondaryColor3fvProc)osg::getGLExtensionFuncPtr("glSecondaryColor3fv","glSecondaryColor3fvEXT"));
|
|
|
|
_glMultiTexCoord1f = ((MultiTexCoord1fProc)osg::getGLExtensionFuncPtr("glMultiTexCoord1f","glMultiTexCoord1fARB"));
|
|
|
|
_glMultiTexCoord2fv = ((MultiTexCoordfvProc)osg::getGLExtensionFuncPtr("glMultiTexCoord2fv","glMultiTexCoord2fvARB"));
|
|
|
|
_glMultiTexCoord3fv = ((MultiTexCoordfvProc)osg::getGLExtensionFuncPtr("glMultiTexCoord3fv","glMultiTexCoord3fvARB"));
|
|
|
|
_glMultiTexCoord4fv = ((MultiTexCoordfvProc)osg::getGLExtensionFuncPtr("glMultiTexCoord4fv","glMultiTexCoord4fvARB"));
|
|
|
|
|
|
|
|
_glVertexAttrib1s = ((VertexAttrib1sProc)osg::getGLExtensionFuncPtr("glVertexAttrib1s","glVertexAttrib1sARB"));
|
|
|
|
_glVertexAttrib1f = ((VertexAttrib1fProc)osg::getGLExtensionFuncPtr("glVertexAttrib1f","glVertexAttrib1fARB"));
|
|
|
|
_glVertexAttrib2fv = ((VertexAttribfvProc)osg::getGLExtensionFuncPtr("glVertexAttrib2fv","glVertexAttrib2fvARB"));
|
|
|
|
_glVertexAttrib3fv = ((VertexAttribfvProc)osg::getGLExtensionFuncPtr("glVertexAttrib3fv","glVertexAttrib3fvARB"));
|
|
|
|
_glVertexAttrib4fv = ((VertexAttribfvProc)osg::getGLExtensionFuncPtr("glVertexAttrib4fv","glVertexAttrib4fvARB"));
|
|
|
|
_glVertexAttrib4ubv = ((VertexAttribubvProc)osg::getGLExtensionFuncPtr("glVertexAttrib4ubv","glVertexAttrib4ubvARB"));
|
|
|
|
_glVertexAttrib4Nubv = ((VertexAttribubvProc)osg::getGLExtensionFuncPtr("glVertexAttrib4Nubv","glVertexAttrib4NubvARB"));
|
|
|
|
|
|
|
|
_glGenBuffers = ((GenBuffersProc)osg::getGLExtensionFuncPtr("glGenBuffers","glGenBuffersARB"));
|
|
|
|
_glBindBuffer = ((BindBufferProc)osg::getGLExtensionFuncPtr("glBindBuffer","glBindBufferARB"));
|
|
|
|
_glBufferData = ((BufferDataProc)osg::getGLExtensionFuncPtr("glBufferData","glBufferDataARB"));
|
|
|
|
_glBufferSubData = ((BufferSubDataProc)osg::getGLExtensionFuncPtr("glBufferSubData","glBufferSubDataARB"));
|
|
|
|
_glDeleteBuffers = ((DeleteBuffersProc)osg::getGLExtensionFuncPtr("glDeleteBuffers","glDeleteBuffersARB"));
|
|
|
|
|
2003-07-24 04:53:53 +08:00
|
|
|
_glGenOcclusionQueries = ((GenOcclusionQueriesProc)osg::getGLExtensionFuncPtr("glGenOcclusionQueries","glGenOcclusionQueriesNV"));
|
|
|
|
_glDeleteOcclusionQueries = ((DeleteOcclusionQueriesProc)osg::getGLExtensionFuncPtr("glDeleteOcclusionQueries","glDeleteOcclusionQueriesNV"));
|
|
|
|
_glIsOcclusionQuery = ((IsOcclusionQueryProc)osg::getGLExtensionFuncPtr("glIsOcclusionQuery","_glIsOcclusionQueryNV"));
|
|
|
|
_glBeginOcclusionQuery = ((BeginOcclusionQueryProc)osg::getGLExtensionFuncPtr("glBeginOcclusionQuery","glBeginOcclusionQueryNV"));
|
|
|
|
_glEndOcclusionQuery = ((EndOcclusionQueryProc)osg::getGLExtensionFuncPtr("glEndOcclusionQuery","glEndOcclusionQueryNV"));
|
|
|
|
_glGetOcclusionQueryiv = ((GetOcclusionQueryivProc)osg::getGLExtensionFuncPtr("glGetOcclusionQueryiv","glGetOcclusionQueryivNV"));
|
|
|
|
_glGetOcclusionQueryuiv = ((GetOcclusionQueryuivProc)osg::getGLExtensionFuncPtr("glGetOcclusionQueryuiv","glGetOcclusionQueryuivNV"));
|
2003-12-09 19:20:44 +08:00
|
|
|
|
|
|
|
_gl_gen_queries_arb = (GenQueriesProc)osg::getGLExtensionFuncPtr("glGenQueries", "glGenQueriesARB");
|
|
|
|
_gl_delete_queries_arb = (DeleteQueriesProc)osg::getGLExtensionFuncPtr("glDeleteQueries", "glDeleteQueriesARB");
|
|
|
|
_gl_is_query_arb = (IsQueryProc)osg::getGLExtensionFuncPtr("glIsQuery", "glIsQueryARB");
|
|
|
|
_gl_begin_query_arb = (BeginQueryProc)osg::getGLExtensionFuncPtr("glBeginQuery", "glBeginQueryARB");
|
|
|
|
_gl_end_query_arb = (EndQueryProc)osg::getGLExtensionFuncPtr("glEndQuery", "glEndQueryARB");
|
|
|
|
_gl_get_queryiv_arb = (GetQueryivProc)osg::getGLExtensionFuncPtr("glGetQueryiv", "glGetQueryivARB");
|
|
|
|
_gl_get_query_objectiv_arb = (GetQueryObjectivProc)osg::getGLExtensionFuncPtr("glGetQueryObjectiv","glGetQueryObjectivARB");
|
|
|
|
_gl_get_query_objectuiv_arb = (GetQueryObjectuivProc)osg::getGLExtensionFuncPtr("glGetQueryObjectuiv","glGetQueryObjectuivARB");
|
2003-06-30 05:41:57 +08:00
|
|
|
}
|
2003-07-24 04:53:53 +08:00
|
|
|
|
2003-06-30 05:41:57 +08:00
|
|
|
void Drawable::Extensions::glFogCoordfv(const GLfloat* coord) const
|
|
|
|
{
|
|
|
|
if (_glFogCoordfv)
|
|
|
|
{
|
|
|
|
_glFogCoordfv(coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glFogCoordfv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glSecondaryColor3ubv(const GLubyte* coord) const
|
|
|
|
{
|
|
|
|
if (_glSecondaryColor3ubv)
|
|
|
|
{
|
|
|
|
_glSecondaryColor3ubv(coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glSecondaryColor3ubv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glSecondaryColor3fv(const GLfloat* coord) const
|
|
|
|
{
|
|
|
|
if (_glSecondaryColor3fv)
|
|
|
|
{
|
|
|
|
_glSecondaryColor3fv(coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glSecondaryColor3fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glMultiTexCoord1f(GLenum target,GLfloat coord) const
|
|
|
|
{
|
|
|
|
if (_glMultiTexCoord1f)
|
|
|
|
{
|
|
|
|
_glMultiTexCoord1f(target,coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glMultiTexCoord1f not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glMultiTexCoord2fv(GLenum target,const GLfloat* coord) const
|
|
|
|
{
|
|
|
|
if (_glMultiTexCoord2fv)
|
|
|
|
{
|
|
|
|
_glMultiTexCoord2fv(target,coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glMultiTexCoord2fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glMultiTexCoord3fv(GLenum target,const GLfloat* coord) const
|
|
|
|
{
|
|
|
|
if (_glMultiTexCoord3fv)
|
|
|
|
{
|
|
|
|
_glMultiTexCoord3fv(target,coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: _glMultiTexCoord3fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glMultiTexCoord4fv(GLenum target,const GLfloat* coord) const
|
|
|
|
{
|
|
|
|
if (_glMultiTexCoord4fv)
|
|
|
|
{
|
|
|
|
_glMultiTexCoord4fv(target,coord);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glMultiTexCoord4fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib1s(unsigned int index, GLshort s) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib1s)
|
|
|
|
{
|
|
|
|
_glVertexAttrib1s(index,s);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib1s not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib1f(unsigned int index, GLfloat f) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib1f)
|
|
|
|
{
|
|
|
|
_glVertexAttrib1f(index,f);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib1f not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib2fv(unsigned int index, const GLfloat * v) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib2fv)
|
|
|
|
{
|
|
|
|
_glVertexAttrib2fv(index,v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib2fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib3fv(unsigned int index, const GLfloat * v) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib3fv)
|
|
|
|
{
|
|
|
|
_glVertexAttrib3fv(index,v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib3fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib4fv(unsigned int index, const GLfloat * v) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib4fv)
|
|
|
|
{
|
|
|
|
_glVertexAttrib4fv(index,v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib4fv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib4ubv(unsigned int index, const GLubyte * v) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib4ubv)
|
|
|
|
{
|
|
|
|
_glVertexAttrib4ubv(index,v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib4ubv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glVertexAttrib4Nubv(unsigned int index, const GLubyte * v) const
|
|
|
|
{
|
|
|
|
if (_glVertexAttrib4Nubv)
|
|
|
|
{
|
|
|
|
_glVertexAttrib4Nubv(index,v);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glVertexAttrib4Nubv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glGenBuffers(GLsizei n, GLuint *buffers) const
|
|
|
|
{
|
|
|
|
if (_glGenBuffers)
|
|
|
|
{
|
|
|
|
_glGenBuffers(n, buffers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glGenBuffers not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glBindBuffer(GLenum target, GLuint buffer) const
|
|
|
|
{
|
|
|
|
if (_glBindBuffer)
|
|
|
|
{
|
|
|
|
_glBindBuffer(target, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glBindBuffer not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glBufferData(GLenum target, GLsizeiptrARB size, const GLvoid *data, GLenum usage) const
|
|
|
|
{
|
|
|
|
if (_glBufferData)
|
|
|
|
{
|
|
|
|
_glBufferData(target, size, data, usage);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glBufferData not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glBufferSubData(GLenum target, GLintptrARB offset, GLsizeiptrARB size, const GLvoid *data) const
|
|
|
|
{
|
|
|
|
if (_glBufferSubData)
|
|
|
|
{
|
|
|
|
_glBufferSubData(target, offset, size, data);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glBufferData not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glDeleteBuffers(GLsizei n, const GLuint *buffers) const
|
|
|
|
{
|
|
|
|
if (_glDeleteBuffers)
|
|
|
|
{
|
|
|
|
_glDeleteBuffers(n, buffers);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
notify(WARN)<<"Error: glBufferData not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
2003-07-24 04:53:53 +08:00
|
|
|
|
|
|
|
void Drawable::Extensions::glGenOcclusionQueries( GLsizei n, GLuint *ids ) const
|
|
|
|
{
|
|
|
|
if (_glGenOcclusionQueries)
|
|
|
|
{
|
|
|
|
_glGenOcclusionQueries( n, ids );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glGenOcclusionQueries not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glDeleteOcclusionQueries( GLsizei n, const GLuint *ids ) const
|
|
|
|
{
|
|
|
|
if (_glDeleteOcclusionQueries)
|
|
|
|
{
|
|
|
|
_glDeleteOcclusionQueries( n, ids );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glDeleteOcclusionQueries not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean Drawable::Extensions::glIsOcclusionQuery( GLuint id ) const
|
|
|
|
{
|
|
|
|
if (_glIsOcclusionQuery)
|
|
|
|
{
|
|
|
|
return _glIsOcclusionQuery( id );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glIsOcclusionQuery not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
return GLboolean( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glBeginOcclusionQuery( GLuint id ) const
|
|
|
|
{
|
|
|
|
if (_glBeginOcclusionQuery)
|
|
|
|
{
|
|
|
|
_glBeginOcclusionQuery( id );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glBeginOcclusionQuery not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glEndOcclusionQuery() const
|
|
|
|
{
|
|
|
|
if (_glEndOcclusionQuery)
|
|
|
|
{
|
|
|
|
_glEndOcclusionQuery();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glEndOcclusionQuery not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glGetOcclusionQueryiv( GLuint id, GLenum pname, GLint *params ) const
|
|
|
|
{
|
|
|
|
if (_glGetOcclusionQueryiv)
|
|
|
|
{
|
|
|
|
_glGetOcclusionQueryiv( id, pname, params );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glGetOcclusionQueryiv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glGetOcclusionQueryuiv( GLuint id, GLenum pname, GLuint *params ) const
|
|
|
|
{
|
|
|
|
if (_glGetOcclusionQueryuiv)
|
|
|
|
{
|
|
|
|
_glGetOcclusionQueryuiv( id, pname, params );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
osg::notify(osg::WARN)<<"Error: glGetOcclusionQueryuiv not supported by OpenGL driver"<<std::endl;
|
|
|
|
}
|
|
|
|
}
|
2003-10-09 05:29:45 +08:00
|
|
|
|
2003-12-09 19:20:44 +08:00
|
|
|
void Drawable::Extensions::glGetQueryiv(GLenum target, GLenum pname, GLint *params) const
|
|
|
|
{
|
|
|
|
if (_gl_get_queryiv_arb)
|
|
|
|
_gl_get_queryiv_arb(target, pname, params);
|
|
|
|
else
|
|
|
|
osg::notify(osg::WARN) << "Error: glGetQueryiv not supported by OpenGL driver" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glGenQueries(GLsizei n, GLuint *ids) const
|
|
|
|
{
|
|
|
|
if (_gl_gen_queries_arb)
|
|
|
|
_gl_gen_queries_arb(n, ids);
|
|
|
|
else
|
|
|
|
osg::notify(osg::WARN) << "Error: glGenQueries not supported by OpenGL driver" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glBeginQuery(GLenum target, GLuint id) const
|
|
|
|
{
|
|
|
|
if (_gl_begin_query_arb)
|
|
|
|
_gl_begin_query_arb(target, id);
|
|
|
|
else
|
|
|
|
osg::notify(osg::WARN) << "Error: glBeginQuery not supported by OpenGL driver" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glEndQuery(GLenum target) const
|
|
|
|
{
|
|
|
|
if (_gl_end_query_arb)
|
|
|
|
_gl_end_query_arb(target);
|
|
|
|
else
|
|
|
|
osg::notify(osg::WARN) << "Error: glEndQuery not supported by OpenGL driver" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
GLboolean Drawable::Extensions::glIsQuery(GLuint id) const
|
|
|
|
{
|
|
|
|
if (_gl_is_query_arb) return _gl_is_query_arb(id);
|
|
|
|
|
|
|
|
osg::notify(osg::WARN) << "Error: glIsQuery not supported by OpenGL driver" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glGetQueryObjectiv(GLuint id, GLenum pname, GLint *params) const
|
|
|
|
{
|
|
|
|
if (_gl_get_query_objectiv_arb)
|
|
|
|
_gl_get_query_objectiv_arb(id, pname, params);
|
|
|
|
else
|
|
|
|
osg::notify(osg::WARN) << "Error: glGetQueryObjectiv not supported by OpenGL driver" << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Drawable::Extensions::glGetQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) const
|
|
|
|
{
|
|
|
|
if (_gl_get_query_objectuiv_arb)
|
|
|
|
_gl_get_query_objectuiv_arb(id, pname, params);
|
|
|
|
else
|
|
|
|
osg::notify(osg::WARN) << "Error: glGetQueryObjectuiv not supported by OpenGL driver" << std::endl;
|
|
|
|
}
|