34 #ifdef G4VIS_BUILD_OPENGL_DRIVER
46 G4OpenGLStoredViewer::G4OpenGLStoredViewer
47 (G4OpenGLStoredSceneHandler& sceneHandler):
49 G4OpenGLViewer (sceneHandler),
50 fG4OpenGLStoredSceneHandler (sceneHandler),
51 fDepthTestEnable(
true)
57 G4OpenGLStoredViewer::~G4OpenGLStoredViewer () {}
59 void G4OpenGLStoredViewer::KernelVisitDecision () {
64 if (!fG4OpenGLStoredSceneHandler.fTopPODL ||
65 CompareForKernelVisit(fLastVP)) {
77 (lastVP.
IsCulling () != fVP.IsCulling ()) ||
82 fVP.GetCBDAlgorithmNumber()) ||
83 (lastVP.
IsSection () != fVP.IsSection ()) ||
87 (lastVP.
IsCutaway () != fVP.IsCutaway ()) ||
90 (lastVP.
IsExplode () != fVP.IsExplode ()) ||
93 fVP.GetDefaultVisAttributes()->
GetColour()) ||
95 fVP.GetDefaultTextVisAttributes()->
GetColour()) ||
97 (lastVP.
IsPicking () != fVP.IsPicking ()) ||
99 fVP.GetVisAttributesModifiers())
126 if (lastVP.
GetCBDParameters().size() != fVP.GetCBDParameters().size())
return true;
140 void G4OpenGLStoredViewer::DrawDisplayLists () {
144 #define CONVENIENT_DOUBLE_ALIAS(q) const G4double& f##q = fVP.Get##q();
145 #define CONVENIENT_BOOL_ALIAS(q) const G4bool& f##q = fVP.Is##q();
146 CONVENIENT_DOUBLE_ALIAS(StartTime)
147 CONVENIENT_DOUBLE_ALIAS(EndTime)
148 CONVENIENT_DOUBLE_ALIAS(FadeFactor)
149 CONVENIENT_BOOL_ALIAS(DisplayHeadTime)
150 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeX)
151 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeY)
152 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeSize)
153 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeRed)
154 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeGreen)
155 CONVENIENT_DOUBLE_ALIAS(DisplayHeadTimeBlue)
156 CONVENIENT_BOOL_ALIAS(DisplayLightFront)
157 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontX)
158 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontY)
159 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontZ)
160 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontT)
161 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontRed)
162 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontGreen)
163 CONVENIENT_DOUBLE_ALIAS(DisplayLightFrontBlue)
165 const
G4Planes& cutaways = fVP.GetCutawayPlanes();
166 G4bool cutawayUnion = fVP.IsCutaway() &&
168 const
size_t nCutaways = cutawayUnion? cutaways.size(): 1;
171 G4bool thirdPassForNonHiddenMarkersRequested = false;
172 fDepthTestEnable =
true;
173 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
175 for (
size_t iCutaway = 0; iCutaway < nCutaways; ++iCutaway) {
179 a[0] = cutaways[iCutaway].a();
180 a[1] = cutaways[iCutaway].b();
181 a[2] = cutaways[iCutaway].c();
182 a[3] = cutaways[iCutaway].d();
183 glClipPlane (GL_CLIP_PLANE2, a);
184 glEnable (GL_CLIP_PLANE2);
187 G4bool isPicking = fVP.IsPicking();
190 iPO < fG4OpenGLStoredSceneHandler.fPOList.size(); ++iPO) {
191 if (POSelected(iPO)) {
192 G4OpenGLStoredSceneHandler::PO& po =
193 fG4OpenGLStoredSceneHandler.fPOList[iPO];
195 DisplayTimePOColourModification(c,iPO);
198 if (isTransparent && transparency_enabled) {
199 secondPassForTransparencyRequested =
true;
202 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
203 thirdPassForNonHiddenMarkersRequested =
true;
206 }
else if (iPass == 2) {
207 if (!isTransparent) {
211 if (!po.fMarkerOrPolyline) {
215 if (isPicking) glLoadName(po.fPickName);
216 if (transparency_enabled) {
221 if (po.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
222 if (fDepthTestEnable !=
false) {
223 glDisable (GL_DEPTH_TEST);
224 fDepthTestEnable =
false;
227 if (fDepthTestEnable !=
true) {
228 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
229 fDepthTestEnable =
true;
232 if (po.fpG4TextPlus) {
233 if (po.fpG4TextPlus->fProcessing2D) {
234 glMatrixMode (GL_PROJECTION);
237 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
238 glMatrixMode (GL_MODELVIEW);
241 G4OpenGLTransform3D oglt (po.fTransform);
242 glMultMatrixd (oglt.GetGLMatrix ());
244 AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
247 G4OpenGLTransform3D oglt (po.fTransform);
248 glMultMatrixd (oglt.GetGLMatrix ());
250 AddPrimitiveForASingleFrame(po.fpG4TextPlus->fG4Text);
254 if (po.fpG4TextPlus->fProcessing2D) {
255 glMatrixMode (GL_PROJECTION);
257 glMatrixMode (GL_MODELVIEW);
262 G4OpenGLTransform3D oglt (po.fTransform);
263 glMultMatrixd (oglt.GetGLMatrix ());
264 glCallList (po.fDisplayListId);
274 iTO < fG4OpenGLStoredSceneHandler.fTOList.size(); ++iTO) {
275 if (TOSelected(iTO)) {
276 G4OpenGLStoredSceneHandler::TO& to =
277 fG4OpenGLStoredSceneHandler.fTOList[iTO];
281 if (isTransparent && transparency_enabled) {
282 secondPassForTransparencyRequested =
true;
285 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
286 thirdPassForNonHiddenMarkersRequested =
true;
289 }
else if (iPass == 2) {
290 if (!isTransparent) {
294 if (!to.fMarkerOrPolyline) {
298 if (to.fMarkerOrPolyline && fVP.IsMarkerNotHidden()) {
299 if (fDepthTestEnable !=
false) {
300 glDisable (GL_DEPTH_TEST);
301 fDepthTestEnable =
false;
304 if (fDepthTestEnable !=
true) {
305 glEnable (GL_DEPTH_TEST); glDepthFunc (GL_LEQUAL);
306 fDepthTestEnable =
true;
309 if (to.fEndTime >= fStartTime && to.fStartTime <= fEndTime) {
310 if (fVP.IsPicking()) glLoadName(to.fPickName);
311 if (to.fpG4TextPlus) {
312 if (to.fpG4TextPlus->fProcessing2D) {
313 glMatrixMode (GL_PROJECTION);
316 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
317 glMatrixMode (GL_MODELVIEW);
321 G4OpenGLTransform3D oglt (to.fTransform);
322 glMultMatrixd (oglt.GetGLMatrix ());
324 AddPrimitiveForASingleFrame(to.fpG4TextPlus->fG4Text);
325 if (to.fpG4TextPlus->fProcessing2D) {
326 glMatrixMode (GL_PROJECTION);
328 glMatrixMode (GL_MODELVIEW);
332 if (to.fTransform != lastMatrixTransform) {
338 G4OpenGLTransform3D oglt (to.fTransform);
339 glMultMatrixd (oglt.GetGLMatrix ());
342 if (fFadeFactor > 0. && to.fEndTime < fEndTime) {
345 ((fEndTime - to.fEndTime) / (fEndTime - fStartTime));
346 const G4Colour& bg = fVP.GetBackgroundColour();
347 if (transparency_enabled) {
349 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
350 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
351 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue(),
352 bsf * cc.
GetAlpha() + (1. - bsf) * bg.GetAlpha());
355 (bsf * cc.
GetRed() + (1. - bsf) * bg.GetRed(),
356 bsf * cc.
GetGreen() + (1. - bsf) * bg.GetGreen(),
357 bsf * cc.
GetBlue() + (1. - bsf) * bg.GetBlue());
360 if (transparency_enabled) {
366 glCallList (to.fDisplayListId);
368 if (to.fTransform != lastMatrixTransform) {
369 lastMatrixTransform = to.fTransform;
378 if (cutawayUnion) glDisable (GL_CLIP_PLANE2);
381 if (iPass == 2) secondPassForTransparencyRequested =
false;
382 if (iPass == 3) thirdPassForNonHiddenMarkersRequested =
false;
384 if (secondPassForTransparencyRequested) iPass = 2;
385 else if (thirdPassForNonHiddenMarkersRequested) iPass = 3;
392 glMatrixMode (GL_PROJECTION);
395 g4GlOrtho (-1., 1., -1., 1., -G4OPENGL_FLT_BIG, G4OPENGL_FLT_BIG);
396 glMatrixMode (GL_MODELVIEW);
400 G4Point3D(fDisplayHeadTimeX, fDisplayHeadTimeY, 0.));
401 headTimeText.SetScreenSize(fDisplayHeadTimeSize);
403 (fDisplayHeadTimeRed,
404 fDisplayHeadTimeGreen,
405 fDisplayHeadTimeBlue));
406 headTimeText.SetVisAttributes(&visAtts);
407 AddPrimitiveForASingleFrame(headTimeText);
408 glMatrixMode (GL_PROJECTION);
410 glMatrixMode (GL_MODELVIEW);
416 G4double lightFrontRadius = (fEndTime - fDisplayLightFrontT) *
c_light;
417 if (lightFrontRadius > 0.) {
418 G4Point3D lightFrontCentre(fDisplayLightFrontX, fDisplayLightFrontY, fDisplayLightFrontZ);
419 G4Point3D circleCentre = lightFrontCentre;
420 G4double circleRadius = lightFrontRadius;
421 if (fVP.GetFieldHalfAngle() > 0.) {
423 G4Point3D targetPoint = fSceneHandler.GetScene()->GetStandardTargetPoint() +
424 fVP.GetCurrentTargetPoint();
425 G4double sceneRadius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
426 if(sceneRadius <= 0.) sceneRadius = 1.;
427 G4double cameraDistance = fVP.GetCameraDistance(sceneRadius);
428 G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().
unit();
429 G4Vector3D lightFrontToCameraDirection = cameraPosition - lightFrontCentre;
430 G4double lightFrontCentreDistance = lightFrontToCameraDirection.
mag();
439 if (lightFrontToCameraDirection * fVP.GetViewpointDirection() > 0. && lightFrontRadius < lightFrontCentreDistance) {
441 G4double sineHorizonAngle = lightFrontRadius / lightFrontCentreDistance;
442 circleCentre = lightFrontCentre + (lightFrontRadius * sineHorizonAngle) * lightFrontToCameraDirection.
unit();
443 circleRadius = lightFrontRadius * std::sqrt(1. - std::pow(sineHorizonAngle, 2));
454 if (circleRadius > 0.) {
456 lightFront.SetWorldRadius(circleRadius);
458 (fDisplayLightFrontRed,
459 fDisplayLightFrontGreen,
460 fDisplayLightFrontBlue));
461 lightFront.SetVisAttributes(visAtts);
462 AddPrimitiveForASingleFrame(lightFront);
468 void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(
const G4Text& text)
472 G4bool memoryForDisplayListsKeep = fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists;
473 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists =
false;
474 fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(text);
475 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists = memoryForDisplayListsKeep;
478 void G4OpenGLStoredViewer::AddPrimitiveForASingleFrame(
const G4Circle& circle)
482 G4bool memoryForDisplayListsKeep = fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists;
483 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists =
false;
484 fG4OpenGLStoredSceneHandler.G4OpenGLStoredSceneHandler::AddPrimitive(circle);
485 fG4OpenGLStoredSceneHandler.fMemoryForDisplayLists = memoryForDisplayListsKeep;