43 ClassImp(TGLSceneBase);
45 UInt_t TGLSceneBase::fgSceneIDSrc = 1;
49 TGLSceneBase::TGLSceneBase() :
54 fLOD (TGLRnrCtx::kLODHigh),
55 fStyle (TGLRnrCtx::kStyleUndef),
61 fBoundingBoxValid (kFALSE),
62 fDoFrustumCheck (kTRUE),
68 fSceneID = fgSceneIDSrc++;
69 fName = Form(
"unnamed-%d", fSceneID);
75 TGLSceneBase::~TGLSceneBase()
77 for (ViewerList_i i=fViewers.begin(); i!=fViewers.end(); ++i)
79 (*i)->SceneDestructing(
this);
86 void TGLSceneBase::AddViewer(TGLViewerBase* viewer)
88 ViewerList_i i = std::find(fViewers.begin(), fViewers.end(), viewer);
89 if (i == fViewers.end())
90 fViewers.push_back(viewer);
92 Warning(
"TGLSceneBase::AddViewer",
"viewer already in the list.");
100 void TGLSceneBase::RemoveViewer(TGLViewerBase* viewer)
102 ViewerList_i i = std::find(fViewers.begin(), fViewers.end(), viewer);
103 if (i != fViewers.end())
106 Warning(
"TGLSceneBase::RemoveViewer",
"viewer not found in the list.");
108 if (fViewers.empty() && fAutoDestruct)
111 Info(
"TGLSceneBase::RemoveViewer",
"scene '%s' not used - autodestructing.", GetName());
118 void TGLSceneBase::TagViewersChanged()
120 for (ViewerList_i i=fViewers.begin(); i!=fViewers.end(); ++i)
131 const char* TGLSceneBase::LockIdStr()
const
133 return Form(
"TGLSceneBase %s", fName.Data());
144 TGLSceneInfo* TGLSceneBase::CreateSceneInfo(TGLViewerBase* view)
146 return new TGLSceneInfo(view,
this);
154 void TGLSceneBase::RebuildSceneInfo(TGLRnrCtx& ctx)
156 TGLSceneInfo* sinfo = ctx.GetSceneInfo();
158 sinfo->SetLastClip(0);
159 sinfo->SetLastCamera(0);
172 void TGLSceneBase::UpdateSceneInfo(TGLRnrCtx& ctx)
176 Info(
"TGLSceneBase::UpdateSceneInfo",
178 GetName(), fTimeStamp);
181 TGLSceneInfo* sinfo = ctx.GetSceneInfo();
187 sinfo->SetLastLOD (TGLRnrCtx::kLODUndef);
188 sinfo->SetLastStyle (TGLRnrCtx::kStyleUndef);
189 sinfo->SetSceneStamp(fTimeStamp);
191 sinfo->InFrustum (kTRUE);
192 sinfo->InClip (kTRUE);
193 sinfo->ClipMode (TGLSceneInfo::kClipNone);
209 sinfo->SetLastClip(0);
210 sinfo->FrustumPlanes().clear();
211 sinfo->ClipPlanes().clear();
215 for (Int_t i=0; i<TGLCamera::kPlanesPerFrustum; ++i)
217 TGLPlane p = ctx.GetCamera()->FrustumPlane((TGLCamera::EFrustumPlane)i);
219 switch (BoundingBox().Overlap(p))
224 sinfo->FrustumPlanes().push_back(p);
227 sinfo->InFrustum(kFALSE);
233 if (fDoClipCheck && ctx.HasClip())
235 if (ctx.Clip()->GetMode() == TGLClip::kOutside)
236 sinfo->ClipMode(TGLSceneInfo::kClipOutside);
238 sinfo->ClipMode(TGLSceneInfo::kClipInside);
240 std::vector<TGLPlane> planeSet;
241 ctx.Clip()->PlaneSet(planeSet);
244 std::vector<TGLPlane>::iterator it = planeSet.begin();
245 while (it != planeSet.end())
248 switch (BoundingBox().Overlap(*it))
253 sinfo->ClipPlanes().push_back(*it);
256 if (sinfo->ClipMode() == TGLSceneInfo::kClipOutside)
259 sinfo->InClip(kFALSE);
265 sinfo->ClipMode(TGLSceneInfo::kClipNone);
268 sinfo->ClipPlanes().clear();
273 sinfo->SetLastClip(ctx.Clip());
274 sinfo->SetClipStamp(ctx.Clip()->TimeStamp());
277 sinfo->SetLastCamera(ctx.GetCamera());
278 sinfo->SetCameraStamp(ctx.GetCamera()->TimeStamp());
286 void TGLSceneBase::LodifySceneInfo(TGLRnrCtx& ctx)
290 Info(
"TGLSceneBase::LodifySceneInfo",
291 "'%s' timestamp=%u lod=%d",
292 GetName(), fTimeStamp, ctx.CombiLOD());
295 TGLSceneInfo & sInfo = * ctx.GetSceneInfo();
296 sInfo.SetLastLOD(ctx.CombiLOD());
311 void TGLSceneBase::PreDraw(TGLRnrCtx & rnrCtx)
313 if ( ! IsDrawOrSelectLock()) {
314 Error(
"TGLSceneBase::FullRender",
"expected Draw or Select Lock");
317 TGLSceneInfo& sInfo = * rnrCtx.GetSceneInfo();
321 if (fTimeStamp > sInfo.SceneStamp())
323 RebuildSceneInfo(rnrCtx);
327 Bool_t needUpdate = sInfo.HasUpdateTimeouted();
329 if (rnrCtx.GetCamera() != sInfo.LastCamera())
331 sInfo.ResetCameraStamp();
334 else if (rnrCtx.GetCamera()->TimeStamp() > sInfo.CameraStamp())
340 if (sInfo.Clip() != 0) clip = sInfo.Clip();
341 else if (fClip != 0) clip = fClip;
342 else clip = rnrCtx.ViewerClip();
343 if (clip != sInfo.LastClip())
345 sInfo.ResetClipStamp();
348 else if (clip && clip->TimeStamp() > sInfo.ClipStamp())
352 rnrCtx.SetClip(clip);
356 UpdateSceneInfo(rnrCtx);
362 if (sInfo.LOD() != TGLRnrCtx::kLODUndef) lod = sInfo.LOD();
363 else if (fLOD != TGLRnrCtx::kLODUndef) lod = fLOD;
364 else lod = rnrCtx.ViewerLOD();
365 rnrCtx.SetSceneLOD(lod);
366 rnrCtx.SetCombiLOD(TMath::Min(rnrCtx.ViewerLOD(), rnrCtx.SceneLOD()));
367 if (needUpdate || rnrCtx.CombiLOD() != sInfo.LastLOD())
369 LodifySceneInfo(rnrCtx);
374 if (sInfo.Style() != TGLRnrCtx::kStyleUndef) style = sInfo.Style();
375 else if (fStyle != TGLRnrCtx::kStyleUndef) style = fStyle;
376 else style = rnrCtx.ViewerStyle();
377 rnrCtx.SetSceneStyle(style);
378 sInfo.SetLastStyle(style);
382 if (sInfo.WFLineW() != 0) wf_linew = sInfo.WFLineW();
383 else if (fWFLineW != 0) wf_linew = fWFLineW;
384 else wf_linew = rnrCtx.ViewerWFLineW();
385 rnrCtx.SetSceneWFLineW(wf_linew);
386 sInfo.SetLastWFLineW(wf_linew);
389 if (sInfo.OLLineW() != 0) ol_linew = sInfo.OLLineW();
390 else if (fOLLineW != 0) ol_linew = fOLLineW;
391 else ol_linew = rnrCtx.ViewerOLLineW();
392 rnrCtx.SetSceneOLLineW(ol_linew);
393 sInfo.SetLastOLLineW(ol_linew);
402 void TGLSceneBase::PreRender(TGLRnrCtx & rnrCtx)
404 TGLSceneInfo& sInfo = * rnrCtx.GetSceneInfo();
406 rnrCtx.SetClip (sInfo.LastClip());
407 rnrCtx.SetCombiLOD (sInfo.LastLOD());
408 rnrCtx.SetSceneStyle (sInfo.LastStyle());
409 rnrCtx.SetSceneWFLineW (sInfo.LastWFLineW());
410 rnrCtx.SetSceneOLLineW (sInfo.LastOLLineW());
430 void TGLSceneBase::Render(TGLRnrCtx & rnrCtx)
432 RenderOpaque(rnrCtx);
433 RenderTransp(rnrCtx);
434 RenderSelOpaque(rnrCtx);
435 RenderSelTransp(rnrCtx);
441 void TGLSceneBase::RenderOpaque(TGLRnrCtx & )
448 void TGLSceneBase::RenderTransp(TGLRnrCtx & )
455 void TGLSceneBase::RenderSelOpaque(TGLRnrCtx & )
462 void TGLSceneBase::RenderSelTransp(TGLRnrCtx & )
469 void TGLSceneBase::RenderSelOpaqueForHighlight(TGLRnrCtx & )
476 void TGLSceneBase::RenderSelTranspForHighlight(TGLRnrCtx & )
483 void TGLSceneBase::PostRender(TGLRnrCtx & )
496 void TGLSceneBase::PostDraw(TGLRnrCtx & )
513 Bool_t TGLSceneBase::ResolveSelectRecord(TGLSelectRecord & ,