void RenderActionTask::waitForBarrier(void)
{
    OSG_ASSERT(_uiTypeTask == HandleGLFinish);
    OSG_ASSERT(_pBarrier   != NULL          );

    _pBarrier->enter();
}
Action::ResultE
CPUSkinningAlgorithm::renderEnter(Action *action)
{
    Action::ResultE  res     = Action::Continue;
    SkinnedGeometry *skinGeo = getSkin    ();
    Skeleton        *skel    = getSkeleton();
    RenderAction    *ract    =
        boost::polymorphic_downcast<RenderAction *>(action); 

    OSG_ASSERT(skinGeo != NULL);
    OSG_ASSERT(skel    != NULL);

    CPUSkinningDataAttachmentUnrecPtr data = getCPUSkinningData(skinGeo);

    if(data == NULL)
    {
        data = CPUSkinningDataAttachment::create();
        skinGeo->addAttachment(data);
    }

    skel->renderEnter(action, skinGeo);

    if(data->getDataValid() == false)
    {
        transformGeometry(skinGeo, skel, data);

        data->setDataValid(true);
    }

    renderGeometry(ract, skinGeo, data);

    return res;
}
void CallbackDrawTask::execute(HardwareContext *pContext, DrawEnv *pEnv)
{
    Window *pWindow = pEnv->getWindow();

    OSG_ASSERT( pWindow != NULL);
    OSG_ASSERT(_fCallback      );

    switch(_uiTypeTask)
    {
        case Callback:
        {
            Inherited::setupContext(pWindow);

            _fCallback(pContext, pEnv);

            Inherited::finalizeContext(pWindow);
            
            if(_bBarrierActive == true)
                _pBarrier->enter();
        }
        break;

        default:
            break;
    }
}
void WindowDrawTask::waitForBarrier(void)
{
    OSG_ASSERT((_uiTypeTask == WaitAtBarrier) ||
               (_uiTypeTask == Swap         )  );
    OSG_ASSERT(_pBarrier    != NULL            );

    _pBarrier->enter();
}
void ShaderExecutableChunk::updateVariables(DrawEnv *pEnv,
                                            UInt32   uiProgram)
{
    if(uiProgram == 0)
        return;

    const ShaderProgramVariables::MFVariablesType       *pMFVars   = NULL;
          ShaderProgramVariables::MFVariableChangedType *pMFVarChg = NULL;

    if(_sfVariables.getValue() != NULL)
    {
        pMFVars   = _sfVariables.getValue()->getMFVariables       ();
        pMFVarChg = _sfVariables.getValue()->editMFVariableChanged();
    }

    if(pMFVars == NULL || pMFVars->size() == 0 || pMFVarChg == NULL)
    {
        return;
    }

    OSG_ASSERT(pMFVars->size() == pMFVarChg->size());

    MFInt32 &vVarLocations = *this->editMFVariableLocations();

    OSG_ASSERT(pMFVars->size() == vVarLocations.size());

    MFInt32::iterator mLocIt = vVarLocations.begin();

    ShaderProgramVariables::MFVariablesType::const_iterator mVarIt  =
        pMFVars->begin();
    ShaderProgramVariables::MFVariablesType::const_iterator mVarEnd =
        pMFVars->end  ();

    ShaderProgramVariables::MFVariableChangedType::iterator mVarChgIt =
        pMFVarChg->begin();

    bool warnUnknown = true;

    for(; mVarIt != mVarEnd; ++mVarIt, ++mLocIt, ++mVarChgIt)
    {
        ShaderVariable *pVar = *mVarIt;

        if(pVar == NULL)
            continue;

        if(*mVarChgIt == false)
            continue;

        *mVarChgIt = false;

        osgUniformShaderVariableSwitch(pEnv,    pVar,
                                       *mLocIt, uiProgram, warnUnknown);
    }
}
OSG_BEGIN_NAMESPACE

ColladaInstInfoTransitPtr
ColladaGeometry::ColladaGeometryInstInfo::create(
    ColladaNode *colInstParent, ColladaInstanceGeometry *colInst,
    Node        *parentN                                         )
{
    OSG_ASSERT(colInstParent != NULL);
    OSG_ASSERT(colInst       != NULL);

    return ColladaInstInfoTransitPtr(
        new ColladaGeometryInstInfo(colInstParent, colInst, parentN));
}
void ContainerChangeEntry::commitChanges(UInt32 AdditionalChangeOrigin)
{
#ifdef OSG_ENABLE_VALGRIND_CHECKS
    VALGRIND_CHECK_VALUE_IS_DEFINED(uiContainerId);
#endif
    FieldContainer *pTmp =
        FieldContainerFactory::the()->getContainer(uiContainerId);

    if(pTmp != NULL)
    {
#ifndef SILENT
        fprintf(stderr, "Commit for %u %s\n",
                uiContainerId, pTmp->getType().getCName());
#endif
        
        BitVector tmpChanges;
        //OSG_ASSERT(NULL !=  bvUncommittedChanges);

        if (NULL != bvUncommittedChanges)
        { 
#ifdef OSG_ENABLE_MEMORY_DEBUGGING
           OSG_ASSERT(*bvUncommittedChanges != 0xDEADBEEF);
#endif
           tmpChanges             = *bvUncommittedChanges; 
           whichField            |= *bvUncommittedChanges;
           *bvUncommittedChanges  = TypeTraits<BitVector>::BitsClear;

           pTmp->changed      (tmpChanges, ChangedOrigin::Commit | AdditionalChangeOrigin, 0);
        }
    }
}
static pascal OSStatus eventHandler(EventHandlerCallRef  nextHandler, 
                                    EventRef             event, 
                                    void                *userData   )
{
    ::UInt32 eventClass = GetEventClass(event);

    CSMNativeWindow *pWin = reinterpret_cast<CSMNativeWindow *>(userData);

    OSG_ASSERT(pWin != NULL);

    switch (eventClass)
    {
        // Mouse events
        case kEventClassMouse:
            return pWin->handleMouseEvent(nextHandler, event);
            
            // Key press events
        case kEventClassTextInput:
            return pWin->handleKeyEvent(nextHandler, event);
            
            // Window events
        case kEventClassWindow:
            return pWin->handleWindowEvent(nextHandler, event);
            
        default:
            return eventNotHandledErr;
    }
}
void RenderAction::readdPartitionByIndex(UInt32 uiPartIdx)
{
    OSG_ASSERT(uiPartIdx < _vRenderPartitions[_currentBuffer].size());

    _vRenderPartitions[_currentBuffer].push_back(
        _vRenderPartitions[_currentBuffer][uiPartIdx]);
}
Esempio n. 10
0
void DrawEnv::deactivateState(void)
{
    if(_pActiveState == NULL)
        return;

    StateChunk *pChunk = _pActiveState->getChunk(State::FullStateIndex);

    if(pChunk != NULL)
    {
        FullStateChunk *pFullChunk = 
            dynamic_cast<FullStateChunk *>(pChunk);

        OSG_ASSERT(pFullChunk != NULL);

        pFullChunk->deactivate(this, _pActiveState, _pActiveStateOverride);
    }
    else
    {
        if(_pActiveStateOverride != NULL)
        {
            deactivate(_pActiveState, _pActiveStateOverride);
        }
        else
        {
            deactivate(_pActiveState);
        }
    }

    _pActiveState         = NULL;
    _pActiveStateOverride = NULL;
}
void
ColladaNode::NodeLoaderState::popNodePath(void)
{
    OSG_ASSERT(_nodePath.empty() == false);

    _nodePath.pop_back();
}
void
ColladaLight::createAmbientLight(ColladaLightAmbientInstInfo *colInstInfo)
{
    OSG_COLLADA_LOG(("ColladaLight::createAmbientLight\n"));

    LightLoaderState *state =
        getGlobal()->getLoaderStateAs<LightLoaderState>(_loaderStateName);
    OSG_ASSERT(state != NULL);

    ChunkOverrideGroupUnrecPtr coGroup  = ChunkOverrideGroup::create();
    NodeUnrecPtr               coGroupN = makeNodeFor(coGroup);

    coGroup->addChunk(state->getLightModelChunk());

    Node *rootN = getGlobal()->getRoot();

    while(rootN->getNChildren() > 0)
    {
        coGroupN->addChild(rootN->getChild(0));
    }

    if(getGlobal()->getOptions()->getCreateNameAttachments() == true)
    {
        setName(coGroupN, "OpenSG_AmbientLight");
    }

    rootN->addChild(coGroupN);
}
Node *
ColladaNode::getBottomNode(UInt32 instIdx) const
{
    OSG_ASSERT(instIdx < _instDataStore.size());

    return _instDataStore[instIdx]._bottomN;
}
void SoundEmitter::update(EventDetails* const details)
{
    OSG_ASSERT(getParents().size() == 1 && "A Sound Emitter NodeCore MUST have 1 and only 1 parent.");

    Matrix wm;
    dynamic_cast<Node*>(_mfParents[0])->getToWorld(wm);
    Pnt3f Position(0, 0, 0);
    wm.mult(Pnt3f(0.0f,0.0f,0.0f),Position);

    if(getSound() != NULL)
    {
        //Remove all invalid
        for(std::set<UInt32>::iterator Itor(_EmittedSoundChannels.begin()) ; Itor != _EmittedSoundChannels.end() ;)
        {
            if(!getSound()->isValid(*Itor))
            {
                std::set<UInt32>::iterator EraseItor(Itor);
                ++Itor;
                _EmittedSoundChannels.erase(EraseItor);
            }
            else
            {

                //getSound()->setChannelVelocity(_PreviousPosition - Position * (1.0f/dynamic_cast<UpdateEventDetails* const>(details)->getElapsedTime()), *Itor);
                

                getSound()->setChannelPosition(Position, *Itor);
                ++Itor;
            }
        }
    }

    _PreviousPosition = Position;
}
//----------------------------------------------------------------------
// Returns information about a glyph.
// Author: pdaehne
//----------------------------------------------------------------------
const TextVectorGlyph &TextVectorFace::getVectorGlyph(TextGlyph::Index glyphIndex)
{
    if (glyphIndex == TextGlyph::INVALID_INDEX)
        return _emptyGlyph;

    // Try to find the glyph in the map of glyphs
    GlyphMap::const_iterator it = _glyphMap.find(glyphIndex);
    if (it != _glyphMap.end())
    {
        OSG_ASSERT(it->second != 0);
        return *(it->second);
    }

    // We did not find the glyph, so we have to create it
    auto_ptr<TextVectorGlyph> glyph = createGlyph(glyphIndex);

    // We could not create the glyph, return 0
    if (glyph.get() == 0)
        return _emptyGlyph;

    // Put the glyph into the glyph cache
    _glyphMap.insert(GlyphMap::value_type(glyphIndex, glyph.get()));

    // Return the glyph
    return *(glyph.release());
}
template<ChangeList::CommitFunction func> inline
void ChangeList::doCommitChanges(UInt32 AdditionalChangeOrigin)
{
    if(_workStore.empty() == false)
    {
        fprintf(stderr, "warning non empty workstore found\n");
        return;
    }


    const unsigned loop_detection_limit(25);
    unsigned loop_count(0);
    bool  detected_loop(false);
    
    _workStore.clear();

#if 0
    std::cerr << "----------- DETECTED LOOP START -------------" << std::endl;
    dump();
#endif

    while((_uncommitedChanges.empty() == false) && !detected_loop)
    {
        _workStore.swap(_uncommitedChanges);
        _uncommitedChanges.clear();

        ChangedStore::iterator       changesIt  = _workStore.begin();
        ChangedStore::const_iterator changesEnd = _workStore.end  ();

#if 0
        std::cerr << "--------- DETECTED LOOP1 START ----------" << std::endl;
        dump();
#endif

        while(changesIt != changesEnd )
        {
            OSG_ASSERT(NULL != (*changesIt));
            
            if((*changesIt)->uiEntryDesc == ContainerChangeEntry::Change)
            {
                ((*changesIt)->*func)(AdditionalChangeOrigin);
            }
            
            ++changesIt;
        }

#if 0
        std::cerr << "-------- DETECTED LOOP2 START ----------" << std::endl;
        dump();
#endif

        _workStore.clear();
        if(loop_count++ > loop_detection_limit)
        {
           detected_loop = true;
           std::cerr << "----------- DETECTED LOOP ------------" << std::endl;
           dump();
        }        
    }
}
void OcclusionCullingTreeBuilder::add(RenderActionBase    *pAction,
                                      RenderPartitionBase *pPart,
                                      DrawFunctor         &drawFunc,
                                      State               *pState,
                                      StateOverride       *pStateOverride)
{
    OSG_ASSERT((_ract == NULL) || (_ract == pAction));

    _ract = dynamic_cast<RenderAction *>(pAction);

    OSG_ASSERT(_ract != NULL);

    OCRenderTreeNode *pNode = createNode(pAction, pPart, drawFunc,
                                         pState,  pStateOverride);

    addNode(pNode);
}
void
ColladaNode::NodeLoaderState::popMatrix(void)
{
    OSG_ASSERT(_matrixStack.empty() == false);

    _worldMatrix = _matrixStack.back();
    _matrixStack.pop_back();
}
void ChangeList::addUncommited(ContainerChangeEntry *pEntry)
{
#ifndef SILENT
    fprintf(stderr, "Added changed %d\n", pEntry->uiContainerId);
#endif
    OSG_ASSERT(NULL != pEntry);
    _uncommitedChanges.push_back(pEntry);
}
Esempio n. 20
0
UInt32 Geometry::handleClassicGL(DrawEnv                 *pEnv, 
                                 UInt32                   id, 
                                 Window::GLObjectStatusE  mode,
                                 UInt32                   uiOptions)
{
    UInt32                   glid;
    Window                  *pWin = pEnv->getWindow();

#ifdef OSG_DEBUG
    Geometry *pAspectGeo = convertToCurrentAspect<Geometry *>(this);
    OSG_ASSERT(pAspectGeo == this);
#endif

    if(mode == Window::initialize || mode == Window::needrefresh ||
       mode == Window::reinitialize)
    {
        if(mode == Window::initialize)
        {
            glid = glGenLists(1);
            pWin->setGLObjectId(id, glid);
        }
        else
        {
            glid = pWin->getGLObjectId(id);
        }

        glNewList(glid, GL_COMPILE);

        GeoPumpGroup::PropertyCharacteristics prop;

        prop = GeoPumpGroup::characterizeGeometry(this);

        GeoPumpGroup::GeoPump pump;

        pump = GeoPumpGroup::findGeoPump(pEnv, prop);

        if (pump)
        {
            pump(pEnv, this);
        }
        else
        {
            SWARNING << "Geometry::handleGL: no Pump found for geometry "
                     << this
                     << std::endl;
        }

        glEndList();
    }
    else
    {
        SWARNING << "Geometry(" << this << "::handleGL: Illegal mode: "
                 << mode << " for id " << id << std::endl;
    }

    return 0;
}
void ShaderProgram::addParent(FieldContainer * const pParent,
                              UInt16                 uiParentFieldId)
{
    editMField(ParentsFieldMask, _mfParents);
    
    OSG_ASSERT(pParent != NULL);

    _mfParents.push_back(pParent, uiParentFieldId);
}
//----------------------------------------------------------------------
// Destructor
// Author: pdaehne
//----------------------------------------------------------------------
TextVectorFace::~TextVectorFace(void)
{
    // Delete all glyphs in the glyph cache
    GlyphMap::iterator it;
    for (it = _glyphMap.begin(); it != _glyphMap.end(); ++it)
    {
        OSG_ASSERT(it->second != 0);
        delete it->second;
    }
}
void
ColladaNode::appendChild(domNode  *child,
                         Node     *childN,
                         InstData &instData)
{
    domNodeRef node = getDOMElementAs<domNode>();

    // only add the child if it is not the first joint
    // in a hierarchy

    if(child->getType() != NODETYPE_JOINT ||
       node ->getType() != NODETYPE_NODE    )
    {
        OSG_ASSERT(instData._topN    != NULL);
        OSG_ASSERT(instData._bottomN != NULL);

        instData._bottomN->addChild(childN);
    }
}
Esempio n. 24
0
Action::ResultE IntersectAction::onLeaveNode(Node* node, Action* action)
{
    OSG_ASSERT(this == action && node == _actNode);

    ResultE result = Continue;

    _path.pop_back();

    return result;
}
void FieldDescriptionBase::shareValuesV(
     const Field         *pSrc,
     const UInt32         fieldId,
           FCPtrConstArg  pDst,
     const TypePtrVector &cloneTypes,
     const TypePtrVector &ignoreTypes,
     const TypeIdVector  &cloneGroupIds,
     const TypeIdVector  &ignoreGroupIds) const
{
   OSG_ASSERT(false && "Must define shareValuesV");
}
Esempio n. 26
0
void BlockingDrawTask::waitForBarrier(void)
{
    if(_bBarrierActive == false)
    {
        return;
    }

    OSG_ASSERT(_pBarrier != NULL);

    _pBarrier->enter();
}
void ClipPlaneChunk::deactivate(DrawEnv *, UInt32 idx)
{
#if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY)
    if(getEnable() == true)
    {
        glDisable( GL_CLIP_PLANE0 + idx);
    }
#else
    OSG_ASSERT(false);
#endif
}
/*------------------------- event producers ----------------------------------*/
void DialogWindowBase::produceEvent(UInt32 eventId, EventDetails* const e)
{
    switch(eventId)
    {
    case DialogWindowClosingEventId:
        OSG_ASSERT(dynamic_cast<DialogWindowClosingEventDetailsType* const>(e));

        _DialogWindowClosingEvent.set_combiner(ConsumableEventCombiner(e));
        _DialogWindowClosingEvent(dynamic_cast<DialogWindowClosingEventDetailsType* const>(e), DialogWindowClosingEventId);
        break;
    case DialogWindowClosedEventId:
        OSG_ASSERT(dynamic_cast<DialogWindowClosedEventDetailsType* const>(e));

        _DialogWindowClosedEvent.set_combiner(ConsumableEventCombiner(e));
        _DialogWindowClosedEvent(dynamic_cast<DialogWindowClosedEventDetailsType* const>(e), DialogWindowClosedEventId);
        break;
    default:
        Inherited::produceEvent(eventId, e);
        break;
    }
}
Esempio n. 29
0
Vec2i getParentTileOffset(Int32 iTileSize, Int32 iChildIndex)
{
    OSG_ASSERT(0 <= iChildIndex && iChildIndex < 4);
    
    const Int32 iHalfTileSize = iTileSize / 2;
    
    const Int32 iParentOffsetX[4] = { 0, iHalfTileSize, 0, iHalfTileSize };
    const Int32 iParentOffsetY[4] = { 0, 0, iHalfTileSize, iHalfTileSize };
    
    return Vec2i(iParentOffsetX[iChildIndex], 
                 iParentOffsetY[iChildIndex]);
}
Material *
ColladaMaterial::createInstance(ColladaInstInfo *colInstInfo)
{
    OSG_COLLADA_LOG(("ColladaMaterial::createInstance\n"));

    MaterialUnrecPtr            retVal        = NULL;
    domMaterialRef              material      = getDOMElementAs<domMaterial>();
    domInstance_effectRef       instEffect    = material->getInstance_effect();
    ColladaInstanceEffectRefPtr colInstEffect =
        getUserDataAs<ColladaInstanceEffect>(instEffect);

    if(getInstStore().empty() == true)
    {
        OSG_ASSERT(colInstEffect                  != NULL);
        OSG_ASSERT(colInstEffect->getTargetElem() != NULL);

        ColladaInstInfoRefPtr colEffectInstInfo =
            ColladaEffect::ColladaEffectInstInfo::create(this, colInstEffect);

        retVal = colInstEffect->getTargetElem()->createInstance(
            colEffectInstInfo);

        if(getGlobal()->getOptions()->getCreateNameAttachments() == true &&
           material->getName()                                   != NULL   )
        {
            setName(retVal, material->getName());
        }

        editInstStore().push_back(retVal);
    }
    else
    {
        retVal = dynamic_pointer_cast<Material>(getInstStore()[0]);

        getGlobal()->getStatCollector()->getElem(
            ColladaGlobal::statNMaterialUsed)->inc();
    }

    return retVal;
}