Added support for multiple graphics context to osg::VertexProgram and osg::Impostor

This commit is contained in:
Robert Osfield
2003-04-10 12:11:40 +00:00
parent 0dd724e8b7
commit 22546b8085
7 changed files with 67 additions and 39 deletions

View File

@@ -22,12 +22,14 @@ Impostor::Impostor()
}
ImpostorSprite* Impostor::findBestImpostorSprite(const osg::Vec3& currLocalEyePoint)
ImpostorSprite* Impostor::findBestImpostorSprite(unsigned int contextID, const osg::Vec3& currLocalEyePoint) const
{
ImpostorSpriteList& impostorSpriteList = _impostorSpriteListBuffer[contextID];
float min_distance2 = FLT_MAX;
ImpostorSprite* impostorSprite = NULL;
for(ImpostorSpriteList::iterator itr=_impostorSpriteList.begin();
itr!=_impostorSpriteList.end();
for(ImpostorSpriteList::iterator itr=impostorSpriteList.begin();
itr!=impostorSpriteList.end();
++itr)
{
float distance2 = (currLocalEyePoint-(*itr)->getStoredLocalEyePoint()).length2();
@@ -40,18 +42,20 @@ ImpostorSprite* Impostor::findBestImpostorSprite(const osg::Vec3& currLocalEyePo
return impostorSprite;
}
void Impostor::addImpostorSprite(ImpostorSprite* is)
void Impostor::addImpostorSprite(unsigned int contextID, ImpostorSprite* is)
{
if (is && is->getParent()!=this)
{
ImpostorSpriteList& impostorSpriteList = _impostorSpriteListBuffer[contextID];
// add it to my impostor list first, so it remains referenced
// when its reference in the previous_owner is removed.
_impostorSpriteList.push_back(is);
impostorSpriteList.push_back(is);
if (is->getParent())
{
Impostor* previous_owner = is->getParent();
ImpostorSpriteList& isl = previous_owner->_impostorSpriteList;
ImpostorSpriteList& isl = previous_owner->_impostorSpriteListBuffer[contextID];
// find and erase reference to is.
for(ImpostorSpriteList::iterator itr=isl.begin();

View File

@@ -13,19 +13,18 @@
#include <osg/Notify>
#include <osg/GLExtensions>
#include <osg/VertexProgram>
#include <osg/State>
using namespace osg;
VertexProgram::VertexProgram() :
_vertexProgramId(0)
VertexProgram::VertexProgram()
{
}
VertexProgram::VertexProgram(const VertexProgram& vp,const CopyOp& copyop):
osg::StateAttribute(vp,copyop),
_vertexProgramId(vp._vertexProgramId)
osg::StateAttribute(vp,copyop)
{}
@@ -53,16 +52,19 @@ void VertexProgram::apply(State& state) const
static ProgramLocalParameter4fvProc s_glProgramLocalParameter4fv =
(ProgramLocalParameter4fvProc)osg::getGLExtensionFuncPtr("glProgramLocalParameter4fvARB");
GLuint& vertexProgramId=getVertexProgramID(state.getContextID());
// Vertex Program
if (_vertexProgramId != 0)
if (vertexProgramId != 0)
{
s_glBindProgram( GL_VERTEX_PROGRAM_ARB, _vertexProgramId );
s_glBindProgram( GL_VERTEX_PROGRAM_ARB, vertexProgramId );
}
else if (!_vertexProgram.empty())
{
::glGetError(); // Reset Error flags.
s_glGenPrograms( 1, &_vertexProgramId );
s_glBindProgram( GL_VERTEX_PROGRAM_ARB, _vertexProgramId );
s_glGenPrograms( 1, &vertexProgramId );
s_glBindProgram( GL_VERTEX_PROGRAM_ARB, vertexProgramId );
s_glProgramString( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
_vertexProgram.length(), _vertexProgram.c_str());

View File

@@ -580,6 +580,9 @@ void CullVisitor::apply(Impostor& node)
if (node_state) pushStateSet(node_state);
const BoundingSphere& bs = node.getBound();
unsigned int contextID = 0;
if (_state.valid()) contextID = _state->getContextID();
float distance2 = (eyeLocal-bs.center()).length2();
if (!_impostorActive ||
@@ -605,7 +608,7 @@ void CullVisitor::apply(Impostor& node)
RefMatrix& matrix = getModelViewMatrix();
// search for the best fit ImpostorSprite;
ImpostorSprite* impostorSprite = node.findBestImpostorSprite(eyeLocal);
ImpostorSprite* impostorSprite = node.findBestImpostorSprite(contextID,eyeLocal);
if (impostorSprite)
{
@@ -673,6 +676,9 @@ void CullVisitor::apply(Impostor& node)
ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
{
unsigned int contextID = 0;
if (_state.valid()) contextID = _state->getContextID();
// default to true right now, will dertermine if perspective from the
// projection matrix...
bool isPerspectiveProjection = true;
@@ -905,9 +911,10 @@ ImpostorSprite* CullVisitor::createImpostorSprite(Impostor& node)
// update frame number to show that impostor is in action.
impostorSprite->setLastFrameUsed(getTraversalNumber());
// have successfully created an impostor sprite so now need to
// add it into the impostor.
node.addImpostorSprite(impostorSprite);
node.addImpostorSprite(contextID,impostorSprite);
if (_depthSortImpostorSprites)
{