22#include "TGLIncludes.h"
71 if (
vec.capacity() > (
size_t) maxSize) {
73 foo.reserve((
size_t) maxSize);
87 if (
vec.capacity() > (
size_t) maxSize) {
89 foo.reserve((
size_t) maxSize);
131 i->fPhysical->QuantizeShapeLOD(i->fPixelLOD, ctx.
CombiLOD(), i->fFinalLOD);
149 if (i->fPhysical->IsSelected())
151 if (i->fPhysical->IsTransparent())
156 if (i->fPhysical->IsTransparent())
205 std::map<TClass*, UInt_t>::iterator it =
fByShapeCnt.find(logIsA);
208 it =
fByShapeCnt.insert(std::make_pair(logIsA, 0u)).first;
224 out +=
Form(
"Drew scene (%s / %i LOD) - %i (Op %i Trans %i) %i pixel\n",
227 out +=
Form(
"\tInner phys nums: physicals=%d, of_interest=%lu, visible=%lu, op=%lu, trans=%lu",
235 out +=
"\n\tStatistics by shape:\n";
236 std::map<TClass*, UInt_t>::const_iterator it =
fByShapeCnt.begin();
238 out +=
Form(
"\t%-20s %u\n", it->first->GetName(), it->second);
242 Info(
"TGLScene::DumpDrawStats()",
"%s",out.
Data());
319 lit->second->DLCachePurge();
328 lit->second->DLCacheDrop();
384 if (sinfo ==
nullptr || sinfo->
GetScene() !=
this) {
385 Error(
"TGLScene::RebuildSceneInfo",
"Scene mismatch.");
428 if (sinfo ==
nullptr || sinfo->
GetScene() !=
this) {
429 Error(
"TGLScene::UpdateSceneInfo",
"Scene mismatch.");
444 Int_t checkCount = 0;
450 ++phys, ++checkCount)
467 std::vector<TGLPlane>::iterator pi = sinfo->
ClipPlanes().begin();
481 std::vector<TGLPlane>::iterator pi = sinfo->
ClipPlanes().begin();
500 std::vector<TGLPlane>::iterator pi = sinfo->
FrustumPlanes().begin();
526 Warning(
"TGLScene::UpdateSceneInfo",
527 "Timeout reached, not all elements processed.");
546 if (sinfo ==
nullptr || sinfo->
GetScene() !=
this) {
547 Error(
"TGLScene::LodifySceneInfo",
"Scene mismatch.");
570 if (sinfo ==
nullptr || sinfo->
GetScene() !=
this) {
572 Error(
"TGLScene::PreDraw",
"%s",
Form(
"SceneInfo mismatch (0x%zx, '%s').",
573 (
size_t)si, si ? si->
IsA()->
GetName() :
"<>"));
595 lit->second->DLCacheClear();
676 glEnable(GL_STENCIL_TEST);
681 glStencilFunc(GL_ALWAYS, 0x1, 0x1);
682 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
683 glClear(GL_STENCIL_BUFFER_BIT);
685 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
689 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
691 glStencilFunc(GL_NOTEQUAL, 0x1, 0x1);
692 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
698 glDisable(GL_STENCIL_TEST);
729 assert(sinfo !=
nullptr);
744 glEnable(GL_LIGHTING);
748 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
749 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
750 glDisable(GL_CULL_FACE);
769 glDisable(GL_LIGHTING);
770 glDisable(GL_CULL_FACE);
771 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
780 for (
Int_t i = 0; i < reqPasses; ++i)
791 glEnable(GL_POLYGON_OFFSET_FILL);
792 glPolygonOffset(0.5f, 0.5f);
798 glDisable(GL_POLYGON_OFFSET_FILL);
799 glDisable(GL_LIGHTING);
807 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
826 Info(
"TGLScene::RenderAllPasses()",
827 "%ld active clip planes", (
Long_t)planeSet.size());
831 glGetIntegerv(GL_MAX_CLIP_PLANES, &maxGLPlanes);
832 UInt_t maxPlanes = maxGLPlanes;
834 if (planeSet.size() < maxPlanes) {
835 maxPlanes = planeSet.size();
842 for (
UInt_t ii=0; ii<maxPlanes; ii++) {
843 glClipPlane(GL_CLIP_PLANE0+ii, planeSet[ii].CArr());
844 glEnable(GL_CLIP_PLANE0+ii);
856 std::vector<TGLPlane> activePlanes;
857 for (planeInd=0; planeInd<maxPlanes; planeInd++)
859 activePlanes.push_back(planeSet[planeInd]);
862 glClipPlane(GL_CLIP_PLANE0+planeInd, p.
CArr());
863 glEnable(GL_CLIP_PLANE0+planeInd);
870 glClipPlane(GL_CLIP_PLANE0+planeInd, p.
CArr());
874 for (planeInd=0; planeInd<maxPlanes; planeInd++) {
875 glDisable(GL_CLIP_PLANE0+planeInd);
881 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
882 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
883 glEnable(GL_CULL_FACE);
884 glEnable(GL_LIGHTING);
898 assert(sinfo !=
nullptr);
917 glPushName(drawShape->
ID());
918 drawShape->
Draw(rnrCtx);
926 if (check_timeout && (drawCount % 2000) == 0 &&
930 Warning(
"TGLScene::RenderElements",
931 "Timeout reached, not all elements rendered.");
951 if (curIdx >= rec.
GetN())
978 Double_t xMin, xMax, yMin, yMax, zMin, zMax;
979 xMin = xMax = yMin = yMax = zMin = zMax = 0.0;
984 physicalShape = physicalShapeIt->second;
992 xMin =
box.XMin(); xMax =
box.XMax();
993 yMin =
box.YMin(); yMax =
box.YMax();
994 zMin =
box.ZMin(); zMax =
box.ZMax();
996 if (
box.XMin() < xMin) { xMin =
box.XMin(); }
997 if (
box.XMax() > xMax) { xMax =
box.XMax(); }
998 if (
box.YMin() < yMin) { yMin =
box.YMin(); }
999 if (
box.YMax() > yMax) { yMax =
box.YMax(); }
1000 if (
box.ZMin() < zMin) { zMin =
box.ZMin(); }
1001 if (
box.ZMax() > zMax) { zMax =
box.ZMax(); }
1020 Error(
"TGLScene::AdoptLogical",
"expected ModifyLock");
1038 Error(
"TGLScene::DestroyLogical",
"expected ModifyLock");
1046 Error(
"TGLScene::DestroyLogical",
"logical not found in map.");
1058 Warning(
"TGLScene::DestroyLogical",
"an attached physical not found in map.");
1060 assert(logical->
Ref() == 0);
1075 Error(
"TGLScene::DestroyLogicals",
"expected ModifyLock");
1083 logicalShape = logicalShapeIt->second;
1085 if (logicalShape->
Ref() == 0) {
1087 delete logicalShape;
1131 Error(
"TGLScene::AdoptPhysical",
"expected ModifyLock");
1161 Error(
"TGLScene::DestroyPhysical",
"expected ModifyLock.");
1168 Error(
"TGLScene::DestroyPhysical::UpdatePhysical",
"physical not found.");
1185 Error(
"TGLScene::DestroyPhysicals",
"expected ModifyLock");
1197 if (lshp && lshp->
Ref() != 0)
1199 count += lshp->
Ref();
1285 Error(
"TGLScene::UpdateLogical",
"expected ModifyLock");
1291 if (log ==
nullptr) {
1292 Error(
"TGLScene::UpdateLogical",
"logical not found");
1296 log->DLCacheClear();
1297 log->UpdateBoundingBox();
1306 Error(
"TGLScene::UpdatePhysical",
"expected ModifyLock");
1312 if (phys ==
nullptr) {
1313 Error(
"TGLScene::UpdatePhysical",
"physical not found");
1327 Error(
"TGLScene::UpdatePhysical",
"expected ModifyLock");
1333 if (phys ==
nullptr) {
1334 Error(
"TGLScene::UpdatePhysical",
"physical not found");
1354 Error(
"TGLScene::UpdatePhysioLogical",
"expected ModifyLock");
1360 if (log ==
nullptr) {
1361 Error(
"TGLScene::UpdatePhysioLogical",
"logical not found");
1365 if (log->Ref() != 1) {
1366 Warning(
"TGLScene::UpdatePhysioLogical",
"expecting a single physical (%d).", log->Ref());
1381 Error(
"TGLScene::UpdatePhysioLogical",
"expected ModifyLock");
1387 if (log ==
nullptr) {
1388 Error(
"TGLScene::UpdatePhysioLogical",
"logical not found");
1392 if (log->Ref() != 1) {
1393 Warning(
"TGLScene::UpdatePhysioLogical",
"expecting a single physical (%d).", log->Ref());
1422 if (i->second->KeepDuringSmartRefresh() ==
kFALSE) {
1463 Warning(
"TGLScene::FindLogicalSmartRefresh",
"Wrong renderer-type found in cache.");
1494 printf(
"Size: Scene Only %u\n",
size);
1499 logicalShape = logicalShapeIt->second;
1500 size +=
sizeof(*logicalShape);
1504 printf(
"Size: Scene + Logical Shapes %u\n",
size);
1509 physicalShape = physicalShapeIt->second;
1510 size +=
sizeof(*physicalShape);
1514 printf(
"Size: Scene + Logical Shapes + Physical Shapes %u\n",
size);
1524 printf(
"Scene: %u Logicals / %u Physicals\n",
1534 if(
c)
c->GetRGB(rgba[0], rgba[1], rgba[2]);
1535 else rgba[0] = rgba[1] = rgba[2] = 0.5;
1536 rgba[3] = 1.0f - transp/100.0f;
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
char Char_t
Character 1 byte (char).
unsigned int UInt_t
Unsigned integer 4 bytes (unsigned int).
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
bool Bool_t
Boolean (0=false, 1=true) (bool).
short Short_t
Signed Short integer 2 bytes (short).
double Double_t
Double 8 bytes.
short Color_t
Color number (short).
float Float_t
Float 4 bytes (float).
Error("WriteTObject","The current directory (%s) is not associated with a file. The object (%s) has not been written.", GetName(), objname)
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
std::vector< TGLPlane > TGLPlaneSet_t
std::vector< TGLPlane >::const_iterator TGLPlaneSet_ci
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
TClass instances represent classes, structs and namespaces in the ROOT type system.
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Double_t Diagonal() const
Rgl::EOverlap Overlap(const TGLPlane &plane) const
Find overlap (Inside, Outside, Partial) of plane c.f. bounding box.
Bool_t OfInterest(const TGLBoundingBox &box, Bool_t ignoreSize) const
Calculate if the an object defined by world frame bounding box is 'of interest' to the camera.
Identifier of a shared GL-context.
Bool_t TakeLock(ELock lock) const
Lock the object in mode 'lock'.
Bool_t ReleaseLock(ELock lock) const
Release current lock, make sure it the same as the 'lock' argument.
Abstract logical shape - a GL 'drawable' - base for all shapes - faceset sphere etc.
UInt_t UnrefFirstPhysical()
Unreferenced first physical in the list, returning its id and making it fit for destruction somewhere...
TObject * GetExternal() const
void DestroyPhysicals()
Destroy all physicals attached to this logical.
static void SetEnvDefaults()
virtual void UpdateBoundingBox()
TGLScene * fScene
! scene where object is stored (can be zero!)
virtual TClass * IsA() const
virtual void DLCacheClear()
Clear all entries for all LODs for this drawable from the display list cache but keeping the reserved...
virtual Bool_t IgnoreSizeForOfInterest() const
Return true if size of this shape should be ignored when determining if the object should be drawn.
static TClass * GetGLRenderer(TClass *isa)
Return direct-rendering GL class for class isa.
Concrete physical shape - a GL drawable.
void SetTransform(const TGLMatrix &transform)
const TGLBoundingBox & BoundingBox() const
const TGLLogicalShape * GetLogical() const
virtual void CalculateShapeLOD(TGLRnrCtx &rnrCtx, Float_t &pixSize, Short_t &shapeLOD) const
Calculate shape-lod, suitable for use under projection defined by 'rnrCtx', taking account of which l...
void SetDiffuseColor(const Float_t rgba[4])
Set color from ROOT color index and transparency [0,100].
Bool_t IsTransparent() const
virtual void Draw(TGLRnrCtx &rnrCtx) const
Draw physical shape, using LOD flags, potential from display list cache.
3D plane class - of format Ax + By + Cz + D = 0
void Negate()
Negate the plane.
const Double_t * CArr() const
The TGLRnrCtx class aggregates data for a given redering context as needed by various parts of the RO...
void SetShapeLOD(Short_t LOD)
Short_t SceneStyle() const
Float_t SceneOLLineW() const
void SetShapePixSize(Float_t ps)
void SetHighlightOutline(Bool_t ho)
Bool_t IsStopwatchRunning() const
Short_t ViewerLOD() const
Bool_t HasStopwatchTimedOut()
Check if the stopwatch went beyond the render time limit.
void SetDrawPass(Short_t dpass)
Float_t SceneWFLineW() const
static const char * StyleName(Short_t style)
Return string describing the style.
TGLSceneInfo * GetSceneInfo()
TGLContextIdentity * GetGLCtxIdentity() const
virtual void PostDraw(TGLRnrCtx &rnrCtx)
Finalize drawing.
TGLSceneBase(const TGLSceneBase &)=delete
TGLBoundingBox fBoundingBox
virtual void LodifySceneInfo(TGLRnrCtx &ctx)
Setup LOD-dependant values in scene-info.
UInt_t GetMinorStamp() const
void InvalidateBoundingBox()
virtual void PreDraw(TGLRnrCtx &rnrCtx)
Perform basic pre-render initialization:
virtual void RebuildSceneInfo(TGLRnrCtx &ctx)
Fill scene-info with very basic information that is practically view independent.
virtual void UpdateSceneInfo(TGLRnrCtx &ctx)
Fill scene-info with information needed for rendering, take into account the render-context (viewer s...
void TagViewersChanged()
Tag all viewers as changed.
Base class for extended scene context.
Short_t LastStyle() const
Bool_t ShouldClip() const
virtual TClass * IsA() const
std::vector< TGLPlane > & ClipPlanes()
std::vector< TGLPlane > & FrustumPlanes()
void ResetUpdateTimeouted()
TGLSceneBase * GetScene() const
TGLSceneInfo(const TGLSceneInfo &)=delete
DrawElementPtrVec_t fSelTranspElements
void PostDraw()
Clean-up after drawing, nothing to be done here.
DrawElementPtrVec_t fTranspElements
void ClearAfterRebuild()
Clear DrawElementVector fVisibleElement and optionally resize it so that it doesn't take more space t...
void ResetDrawStats()
Reset draw statistics.
void DumpDrawStats()
Output draw stats to Info stream.
~TSceneInfo() override
Destructor.
TSceneInfo(TGLViewerBase *view=nullptr, TGLScene *scene=nullptr)
Constructor.
DrawElementVec_t fVisibleElements
void PreDraw()
Prepare for drawing - fill DrawElementPtrVectors from the contents of fVisibleElements if there was s...
DrawElementPtrVec_t fOpaqueElements
ShapeVec_t fShapesOfInterest
void ClearDrawElementVec(DrawElementVec_t &vec, Int_t maxSize)
Clear given vec and if it grew too large compared to the size of shape-of-interest also resize it.
void UpdateDrawStats(const TGLPhysicalShape &shape, Short_t lod)
Update draw stats, for newly drawn 'shape'.
std::map< TClass *, UInt_t > fByShapeCnt
DrawElementPtrVec_t fSelOpaqueElements
void ClearAfterUpdate()
Clear DrawElementPtrVectors and optionally resize them so that they don't take more space then requir...
void Lodify(TGLRnrCtx &ctx)
Quantize LODs for given render-context.
void ClearDrawElementPtrVec(DrawElementPtrVec_t &vec, Int_t maxSize)
Clear given vec and if it grew too large compared to the size of shape-of-interest also resize it.
Float_t fLastLineWidthScale
void UpdateSceneInfo(TGLRnrCtx &rnrCtx) override
Fill scene-info with information needed for rendering, take into account the render-context (viewer s...
std::vector< DrawElement_t > DrawElementVec_t
virtual TGLPhysicalShape * FindPhysical(UInt_t phid) const
Find and return physical shape identified by unique 'ID'.
PhysicalShapeMap_t::const_iterator PhysicalShapeMapCIt_t
void RenderOpaque(TGLRnrCtx &rnrCtx) override
Render opaque elements.
void CalcBoundingBox() const override
Encapsulates all physical shapes bounding box with axes aligned box.
virtual void DestroyPhysicalInternal(PhysicalShapeMapIt_t pit)
Virtual function to destroy a physical.
void PostDraw(TGLRnrCtx &rnrCtx) override
Called after the rendering is finished.
virtual Bool_t BeginUpdate()
Put scene in update mode, return true if lock acquired.
virtual void AdoptPhysical(TGLPhysicalShape &shape)
Adopt dynamically created physical 'shape' - add to internal map and take responsibility for deleting...
void ReleaseGLCtxIdentity()
Release all GL resources for current context identity.
LogicalShapeMap_t::const_iterator LogicalShapeMapCIt_t
void RebuildSceneInfo(TGLRnrCtx &rnrCtx) override
Major change in scene, need to rebuild all-element draw-vector and sort it.
virtual void EndUpdate(Bool_t minorChange=kTRUE, Bool_t sceneChanged=kTRUE, Bool_t updateViewers=kTRUE)
Exit scene update mode.
Float_t fLastPointSizeScale
static Bool_t ComparePhysicalVolumes(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare 'shape1' and 'shape2' bounding box volumes - return kTRUE if 'shape1' bigger than 'shape2'.
LogicalShapeMap_t fLogicalShapes
!
virtual Int_t DestroyPhysicals()
Destroy physical shapes.
virtual void RenderAllPasses(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout)
Do full rendering of scene.
virtual void AdoptLogical(TGLLogicalShape &shape)
Adopt dynamically created logical 'shape' - add to internal map and take responsibility for deleting.
void LodifySceneInfo(TGLRnrCtx &rnrCtx) override
Setup LOD-dependant values in scene-info.
virtual void RenderElements(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec, Bool_t check_timeout, const TGLPlaneSet_t *clipPlanes=nullptr)
Render DrawElements in elementVec with given timeout.
Bool_t ResolveSelectRecord(TGLSelectRecord &rec, Int_t curIdx) override
Process selection record rec.
static Bool_t IsOutside(const TGLBoundingBox &box, const TGLPlaneSet_t &planes)
Check if box is outside of all planes.
void RenderSelTranspForHighlight(TGLRnrCtx &rnrCtx) override
Render selected transparent elements for highlight.
void EndSmartRefresh()
Wipes logicals in refresh-cache.
virtual Bool_t DestroyLogical(TObject *logid, Bool_t mustFind=kTRUE)
Destroy logical shape defined by unique 'ID'.
std::vector< const TGLPhysicalShape * > ShapeVec_t
UInt_t SizeOfScene() const
Return memory cost of scene.
PhysicalShapeMap_t::iterator PhysicalShapeMapIt_t
LogicalShapeMap_t fSmartRefreshCache
!
TGLScene(const TGLScene &)=delete
virtual void RenderHighlight(TGLRnrCtx &rnrCtx, DrawElementPtrVec_t &elVec)
PhysicalShapeMap_t fPhysicalShapes
!
std::vector< DrawElement_t >::iterator DrawElementVec_i
TSceneInfo * CreateSceneInfo(TGLViewerBase *view) override
Create a scene-info instance appropriate for this scene class.
LogicalShapeMap_t::iterator LogicalShapeMapIt_t
PhysicalShapeMap_t::value_type PhysicalShapeMapValueType_t
LogicalShapeMap_t::value_type LogicalShapeMapValueType_t
std::vector< DrawElement_t * > DrawElementPtrVec_t
std::map< TObject *, TGLLogicalShape * > LogicalShapeMap_t
ShapeVec_t::iterator ShapeVec_i
void RenderSelOpaqueForHighlight(TGLRnrCtx &rnrCtx) override
Render selected opaque elements for highlight.
virtual void UpdatePhysioLogical(TObject *logid, Double_t *trans, UChar_t *col)
Reposition/recolor physical for given logical (assume TGLObject and a single physical).
virtual Bool_t DestroyPhysical(UInt_t phid)
Destroy physical shape defined by unique 'ID'.
static void RGBAFromColorIdx(Float_t rgba[4], Color_t ci, Char_t transp=0)
Fill rgba color from ROOT color-index ci and transparency (0->100).
void RenderTransp(TGLRnrCtx &rnrCtx) override
Render transparent elements.
virtual Int_t DestroyLogicals()
Destroy all logical shapes in scene.
TGLLogicalShape * FindLogicalSmartRefresh(TObject *ID) const
Find and return logical shape identified by unique 'ID' in refresh-cache.
~TGLScene() override
Destroy scene objects.
std::vector< DrawElement_t * >::iterator DrawElementPtrVec_i
void RenderSelTransp(TGLRnrCtx &rnrCtx) override
Render selected transparent elements.
virtual void UpdateLogical(TObject *logid)
Drop display-lists for the logical (assume TGLObject/direct rendering).
TGLContextIdentity * fGLCtxIdentity
void PreDraw(TGLRnrCtx &rnrCtx) override
Initialize rendering.
void DumpMapSizes() const
Print sizes of logical and physical-shape maps.
virtual void UpdatePhysical(UInt_t phid, Double_t *trans, UChar_t *col)
Reposition/recolor physical shape.
virtual UInt_t GetMaxPhysicalID()
Returns the maximum used physical id.
TGLLogicalShape * FindLogical(TObject *logid) const override
Find and return logical shape identified by unique logid.
UInt_t BeginSmartRefresh()
Moves logicals that support smart-refresh to intermediate cache.
static Bool_t ComparePhysicalDiagonals(const TGLPhysicalShape *shape1, const TGLPhysicalShape *shape2)
Compare 'shape1' and 'shape2' bounding box volumes - return kTRUE if 'shape1' bigger than 'shape2'.
void RenderSelOpaque(TGLRnrCtx &rnrCtx) override
Render selected opaque elements.
UInt_t GetItem(Int_t i) const
Standard selection record including information about containing scene and details ob out selected ob...
void SetSpecific(void *spec)
void SetTransparent(Bool_t t)
void SetPhysShape(TGLPhysicalShape *pshp)
void SetObject(TObject *obj)
void SetLogShape(TGLLogicalShape *lshp)
static Float_t GetPointSizeScale()
Get global point-size scale.
static Float_t GetLineWidthScale()
Returns global line-width scale.
static Float_t LineWidth()
Get the line-width, taking the global scaling into account.
3 component (x/y/z) vertex class.
Base class for GL viewers.
const char * GetName() const override
Returns name of object.
Mother of all ROOT objects.
virtual TClass * IsA() const
const char * Data() const
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)