void VRShadowEngine::lightRenderEnter(Light *pLight, RenderAction *pAction) { if(pLight->getOn() == false) return; StateChunk *pChunk = pLight->getChunk(); UInt32 uiSlot = pChunk->getClassId(); Int32 iLightIndex = pAction->allocateLightIndex(); // LightChunk *pLightChunk = dynamic_cast<LightChunk *>(pChunk); // Color4f tmpVal(0.0, 0.0, 0.0, 1.0); // pLightChunk->setAmbient(tmpVal); if(iLightIndex >= 0) { pAction->addOverride(uiSlot + iLightIndex, pChunk); } else { SWARNING << "maximum light source limit (" << -iLightIndex << ") is reached" << " skipping light sources!" << std::endl; } }
StateChunk *ChunkMaterial::find(const FieldContainerType &type, Int32 slot) const { UInt32 index = 0; for(UInt32 i = 0; i < _mfChunks.size(); ++i) { StateChunk *p = _mfChunks[i]; Int32 s = State::AutoSlotReplace; if(i < getMFSlots()->size()) s = getSlots(i); if(s == State::AutoSlotReplace) s = index; if(p->getType() == type) { if(slot == State::AutoSlotReplace || slot == s) return (p); ++index; } } return NULL; }
void DrawEnv::updateChunk(State *pState) { StateChunk *c = pState->getChunk(State::UpdateChunk); UInt32 const climit = pState->getCoreGLChunkLimit(); if(c != NULL && c->getIgnore() == false && c->getClassId() < climit) { (c)->changeFrom(this, c, UInt32(0)); } }
void StateChunkBase::execSyncV( FieldContainer &oFrom, ConstFieldMaskArg whichField, AspectOffsetStore &oOffsets, ConstFieldMaskArg syncMode, const UInt32 uiSyncInfo) { StateChunk *pThis = static_cast<StateChunk *>(this); pThis->execSync(static_cast<StateChunk *>(&oFrom), whichField, oOffsets, syncMode, uiSyncInfo); }
void DrawEnv::updateChunk(State *pState, StateOverride *pOverride) { StateChunk *c = pState->getChunk(State::UpdateChunk); UInt32 const climit = pState->getCoreGLChunkLimit(); if(pOverride->size() > 0 && pOverride->begin()->first == State::UpdateChunk ) { c = pOverride->begin()->second; } if(c != NULL && c->getIgnore() == false && c->getClassId() < climit) { c->changeFrom(this, c, UInt32(0)); } }
void DrawEnv::update(State *pState, StateOverride *pOverride) { #if 0 MFUnrecStateChunkPtr::const_iterator cIt = pState->getMFChunks()->begin(); MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end (); StateOverride::ChunkStoreIt overIt = pOverride->begin(); Int32 ind = 0; UInt32 cind = osgMin(State::SkipNumChunks, pState->getMFChunks()->size()); StateChunk *c = NULL; OSG_SKIP_IT(cIt, cind); for(; cIt != cEnd && cind < State::UpdateBelow; ++cIt, ++cind) { if(overIt != pOverride->end() && overIt->first == cind) { c = overIt->second; ++overIt; } else { c = *cIt; } if(c != NULL && c->getIgnore() == false) { c->changeFrom(this, c, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(cind)) ind = 0; } #endif }
void State::changeFrom(DrawEnv *pEnv, State *pOld) const { MFChunksType::const_iterator cIt = _mfChunks.begin(); MFChunksType::const_iterator cEnd = _mfChunks.end (); Int32 ind = 0; UInt32 i; UInt32 cind = osgMin(State::SkipNumChunks, _mfChunks.size32() ); UInt32 const climit = _uiCoreGLChunkLimit; OSG_SKIP_IT(cIt, cind); for(; (cIt != cEnd) && (cind < climit); ++cIt, ++cind) { StateChunk *o = pOld->getChunk(cind); StateChunk *n = *cIt; if(n != NULL && n->getIgnore() == false) { if(o != NULL && o->getIgnore() == false) { n->changeFrom(pEnv, o, UInt32(ind)); } else { n->activate(pEnv, UInt32(ind)); } } else if(o != NULL && o->getIgnore() == false) { o->deactivate(pEnv, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(cind)) ind = 0; } if(ind >= StateChunkClass::getNumSlots(cind)) ind = 0; for(i = cind; (i < pOld->getMFChunks()->size()) && (i < climit); ++i) { StateChunk *o = pOld->getChunk(i); if(o != NULL && o->getIgnore() == false) { o->deactivate(pEnv, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(i)) { ind = 0; } } }
void SkyBackground::clear(DrawEnv *pEnv) { #if !defined(OSG_OGL_COREONLY) || defined(OSG_CHECK_COREONLY) glPushAttrib(GL_POLYGON_BIT | GL_DEPTH_BUFFER_BIT | GL_LIGHTING_BIT); glDisable(GL_LIGHTING); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_DEPTH_TEST); glMatrixMode(GL_MODELVIEW); glPushMatrix(); Matrix m,t; /* action->getCamera()->getViewing(m, viewport->getPixelWidth(), viewport->getPixelHeight()); action->getCamera()->getProjectionTranslation(t, viewport->getPixelWidth(), viewport->getPixelHeight()); */ m = pEnv->getCameraViewing(); t = pEnv->getCameraProjectionTrans(); m.multLeft(t); if(getBeacon() != NULL) { getBeacon()->getToWorld(t); m.mult(t); } m[3][0] = m[3][1] = m[3][2] = 0; glLoadMatrixf(m.getValues()); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); glTranslatef(0.f, 0.f, 0.5); glScalef(1.f, 1.f, 0.f); /* action->getCamera()->getProjection(m, viewport->getPixelWidth(), viewport->getPixelHeight()); */ m = pEnv->getCameraProjection(); glMultMatrixf(m.getValues()); UInt32 i, j; UInt32 sr = _sfSphereRes.getValue() + 1; // sphere resolution if(_cosval.size() != sr) { Real32 da = 2 * Pi / (sr - 1); _cosval.resize(sr); _sinval.resize(sr); for(i = 0; i < sr; ++i) { _cosval[i] = osgCos(i * da); _sinval[i] = osgSin(i * da); } } Real32 vcos1,vsin1,vcos2,vsin2; // better always clear and set a defined color... glColor3f(1, 1, 1); if(_mfSkyColor.size() > 0) { glClearColor(_mfSkyColor[0][0], _mfSkyColor[0][1], _mfSkyColor[0][2], _mfSkyColor[0][2]); } else { glClearColor(0, 0, 0, 1); } glClear(GL_COLOR_BUFFER_BIT); if(_mfSkyAngle.size() > 0) { vcos1 = osgCos(_mfSkyAngle[0]); vsin1 = osgSin(_mfSkyAngle[0]); glBegin(GL_TRIANGLE_FAN); glColor4fv( static_cast<const GLfloat *>(_mfSkyColor[0].getValuesRGBA())); glVertex3f(0, 1, 0); glColor4fv( static_cast<const GLfloat *>(_mfSkyColor[1].getValuesRGBA())); for(i = 0; i < sr; ++i) { glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]); } glEnd(); for(j = 0; j < _mfSkyAngle.size() - 1; ++j) { Color4f c1, c2; c1 = _mfSkyColor[j+1]; c2 = _mfSkyColor[j+2]; vcos1 = osgCos(_mfSkyAngle[j ]); vsin1 = osgSin(_mfSkyAngle[j ]); vcos2 = osgCos(_mfSkyAngle[j+1]); vsin2 = osgSin(_mfSkyAngle[j+1]); glBegin(GL_TRIANGLE_STRIP); for(i = 0; i < sr; ++i) { glColor4fv(static_cast<const GLfloat *>(c1.getValuesRGBA())); glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]); glColor4fv(static_cast<const GLfloat *>(c2.getValuesRGBA())); glVertex3f(vsin2 * _sinval[i], vcos2, vsin2 * _cosval[i]); } glEnd(); } //if(osgAbs(_mfSkyAngle[j] - Pi) > TypeTraits<Real32>::getDefaultEps()) { glBegin(GL_TRIANGLE_FAN); glColor4fv( static_cast<const GLfloat *>(_mfSkyColor[j+1].getValuesRGBA())); glVertex3f(0, -1, 0); vcos1 = osgCos(_mfSkyAngle[j]); vsin1 = osgSin(_mfSkyAngle[j]); for(i = 0; i < sr; ++i) { glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]); } glEnd(); } } // Draw the ground. // It's possible to be smarter about this, but for now just overdraw. if(_mfGroundAngle.size() > 0) { vcos1 = -osgCos(_mfGroundAngle[0]); vsin1 = osgSin(_mfGroundAngle[0]); glBegin(GL_TRIANGLE_FAN); if(_mfGroundColor.size()) { glColor4fv( static_cast<const GLfloat* >( _mfGroundColor[0].getValuesRGBA())); } glVertex3f(0, -1, 0); if(_mfGroundColor.size() > 1) { glColor4fv( static_cast<const GLfloat *>( _mfGroundColor[1].getValuesRGBA())); } for(i = 0; i < sr; ++i) { glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]); } glEnd(); for(j = 0; j < _mfGroundAngle.size() - 1; ++j) { Color4f c1, c2; if (_mfGroundColor.size() > j+2) { c1 = _mfGroundColor[j+1]; c2 = _mfGroundColor[j+2]; } vcos1 = -osgCos(_mfGroundAngle[j ]); vsin1 = osgSin(_mfGroundAngle[j ]); vcos2 = -osgCos(_mfGroundAngle[j+1]); vsin2 = osgSin(_mfGroundAngle[j+1]); glBegin(GL_TRIANGLE_STRIP); for(i = 0; i < sr; ++i) { glColor4fv(static_cast<const GLfloat *>(c1.getValuesRGBA())); glVertex3f(vsin1 * _sinval[i], vcos1, vsin1 * _cosval[i]); glColor4fv(static_cast<const GLfloat *>(c2.getValuesRGBA())); glVertex3f(vsin2 * _sinval[i], vcos2, vsin2 * _cosval[i]); } glEnd(); } } // now draw the textures, if set StateChunk *tchunk = NULL; const Vec3f *pTexCoords; pTexCoords = selectTexCoords( getMFBackTexCoord()->size() ? &getMFBackTexCoord()->front() : NULL, getBackTexture(), 1); drawFace(pEnv, getBackTexture(), tchunk, Pnt3f( 0.5, -0.5, 0.5), Pnt3f(-0.5, -0.5, 0.5), Pnt3f(-0.5, 0.5, 0.5), Pnt3f( 0.5, 0.5, 0.5), pTexCoords ); pTexCoords = selectTexCoords( getMFFrontTexCoord()->size() ? &getMFFrontTexCoord()->front() : NULL, getFrontTexture(), 2); drawFace(pEnv, getFrontTexture(), tchunk, Pnt3f(-0.5, -0.5, -0.5), Pnt3f( 0.5, -0.5, -0.5), Pnt3f( 0.5, 0.5, -0.5), Pnt3f(-0.5, 0.5, -0.5), pTexCoords ); pTexCoords = selectTexCoords( getMFBottomTexCoord()->size() ? &getMFBottomTexCoord()->front() : NULL, getBottomTexture(), 3); drawFace(pEnv, getBottomTexture(), tchunk, Pnt3f(-0.5, -0.5, 0.5), Pnt3f( 0.5, -0.5, 0.5), Pnt3f( 0.5, -0.5, -0.5), Pnt3f(-0.5, -0.5, -0.5), pTexCoords ); pTexCoords = selectTexCoords( getMFTopTexCoord()->size() ? &getMFTopTexCoord()->front() : NULL, getTopTexture(), 4); drawFace(pEnv, getTopTexture(), tchunk, Pnt3f(-0.5, 0.5, -0.5), Pnt3f( 0.5, 0.5, -0.5), Pnt3f( 0.5, 0.5, 0.5), Pnt3f(-0.5, 0.5, 0.5), pTexCoords ); pTexCoords = selectTexCoords( getMFLeftTexCoord()->size() ? &getMFLeftTexCoord()->front() : NULL, getLeftTexture(), 5); drawFace(pEnv, getLeftTexture(), tchunk, Pnt3f(-0.5, -0.5, 0.5), Pnt3f(-0.5, -0.5, -0.5), Pnt3f(-0.5, 0.5, -0.5), Pnt3f(-0.5, 0.5, 0.5), pTexCoords ); pTexCoords = selectTexCoords( getMFRightTexCoord()->size() ? &getMFRightTexCoord()->front() : NULL, getRightTexture(), 6); drawFace(pEnv, getRightTexture(), tchunk, Pnt3f( 0.5, -0.5, -0.5), Pnt3f( 0.5, -0.5, 0.5), Pnt3f( 0.5, 0.5, 0.5), Pnt3f( 0.5, 0.5, -0.5), pTexCoords ); if(tchunk != NULL) tchunk->deactivate(pEnv); Int32 bit = getClearStencilBit(); glClearDepth(1.f); if(bit >= 0) { glClearStencil(bit); glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); } else { glClear(GL_DEPTH_BUFFER_BIT); } glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); glColor3f(1.0, 1.0, 1.0); #endif }
void DrawEnv::changeTo(State *pState, StateOverride *pOverride, State *pOld, StateOverride *pOldOverride) { MFUnrecStateChunkPtr::const_iterator cIt = pState->getMFChunks()->begin(); MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end (); StateOverride::ChunkStoreIt newOverIt = pOverride ->begin(); StateOverride::ChunkStoreIt oldOverIt = pOldOverride->begin(); Int32 ind = 0; UInt32 i; SizeT cind = osgMin(State::SkipNumChunks, pState->getMFChunks()->size()); StateChunk *n = NULL; OSG_SKIP_IT(cIt, cind); for(; cIt != cEnd; ++cIt, ++cind) { StateChunk *o = pOld->getChunk(cind); n = *cIt; if(oldOverIt != pOldOverride->end() && oldOverIt->first == cind) { o = oldOverIt->second; ++oldOverIt; } if(newOverIt != pOverride->end() && newOverIt->first == cind) { n = newOverIt->second; ++newOverIt; } if(n != NULL && n->getIgnore() == false) { if(o != NULL && o->getIgnore() == false) { n->changeFrom(this, o, UInt32(ind)); } else { n->activate(this, UInt32(ind)); } } else if(o != NULL && o->getIgnore() == false) { o->deactivate(this, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(cind)) { ind = 0; } } if(ind >= StateChunkClass::getNumSlots(cind)) ind = 0; cind = osgMax(cind, State::SkipNumChunks); for(i = cind; i < pOld->getMFChunks()->size(); ++i) { StateChunk *o = pOld->getChunk(i); n = NULL; if(oldOverIt != pOldOverride->end() && oldOverIt->first == cind) { o = oldOverIt->second; ++oldOverIt; } if(newOverIt != pOverride->end() && newOverIt->first == cind) { n = newOverIt->second; ++newOverIt; } if(n != NULL && n->getIgnore() == false) { if(o != NULL && o->getIgnore() == false) { n->changeFrom(this, o, UInt32(ind)); } else { n->activate(this, UInt32(ind)); } } else if(o != NULL && o->getIgnore() == false) { o->deactivate(this, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(i)) { ind = 0; } } while(oldOverIt != pOldOverride->end()) { n = NULL; if(newOverIt != pOverride->end() && newOverIt->first == oldOverIt->first ) { n = newOverIt->second; ++newOverIt; } if(n != NULL && n->getIgnore() == false) { if(oldOverIt->second->getIgnore() == false) { n->changeFrom(this, oldOverIt->second, UInt32(oldOverIt->first - oldOverIt->second->getClassId())); } else { n->activate(this, UInt32(oldOverIt->first - oldOverIt->second->getClassId())); } } else if(oldOverIt->second->getIgnore() == false) { oldOverIt->second->deactivate( this, UInt32(oldOverIt->first - oldOverIt->second->getClassId())); } ++oldOverIt; } while(newOverIt != pOverride->end()) { if(newOverIt->second->getIgnore() == false) { newOverIt->second->activate(this, UInt32( newOverIt->first - newOverIt->second->getClassId())); } ++newOverIt; } ++_uiNumStateChanges; }
void DrawEnv::changeTo(State *pState, StateOverride *pOverride, State *pOld) { MFUnrecStateChunkPtr::const_iterator cIt = pState->getMFChunks()->begin(); MFUnrecStateChunkPtr::const_iterator cEnd = pState->getMFChunks()->end (); StateOverride::ChunkStoreConstIt overIt = pOverride->begin(); Int32 ind = 0; UInt32 i; UInt32 cind = osgMin(State::SkipNumChunks, pState->getMFChunks()->size32()); UInt32 const climit = pState->getCoreGLChunkLimit(); StateChunk *n = NULL; OSG_SKIP_IT(cIt, cind); for(; (cIt != cEnd) && (cind < climit); ++cIt, ++cind) { StateChunk *o = pOld->getChunk(cind); n = *cIt; if(overIt != pOverride->end() && overIt->first == cind) { n = overIt->second; ++overIt; } if(n != NULL && n->getIgnore() == false) { if(o != NULL && o->getIgnore() == false) { n->changeFrom(this, o, UInt32(ind)); } else { n->activate(this, UInt32(ind)); } } else if(o != NULL && o->getIgnore() == false) { o->deactivate(this, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(cind)) { ind = 0; } } if(ind >= StateChunkClass::getNumSlots(cind)) ind = 0; cind = osgMax(cind, State::SkipNumChunks); for(i = cind; (i < pOld->getMFChunks()->size32()) && (i < climit); ++i) { StateChunk *o = pOld->getChunk(i); n = NULL; if(overIt != pOverride->end() && overIt->first == cind) { n = overIt->second; ++overIt; } if(n != NULL && n->getIgnore() == false) { if(o != NULL && o->getIgnore() == false) { n->changeFrom(this, o, UInt32(ind)); } else { n->activate(this, UInt32(ind)); } } else if(o != NULL && o->getIgnore() == false) { o->deactivate(this, UInt32(ind)); } if(++ind >= StateChunkClass::getNumSlots(i)) { ind = 0; } } while(overIt != pOverride->end()) { if(overIt->first >= climit) break; if(overIt->second->getIgnore() == false) { overIt->second->activate(this, UInt32(overIt->first - overIt->second->getClassId())); } ++overIt; } ++_uiNumStateChanges; }