Import Geant4 11.2.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2023-06-30 09:09:57 +02:00
parent aef78ca386
commit dd1f179cda
3780 changed files with 212808 additions and 142780 deletions
-134
View File
@@ -1,134 +0,0 @@
name := G4OpenGL
ifndef G4INSTALL
G4INSTALL = ../../..
endif
# Definition of macro for moc files (for Qt use only)
ifdef G4VIS_BUILD_OPENGLQT_DRIVER
MOC_MACRO = -DG4VIS_BUILD_OPENGLQT_DRIVER
endif
# For debug mode
# CPPFLAGS += -DG4DEBUG_VIS_OGL
GLOBLIBS = libG4vis_management.lib libG4modeling.lib libG4tools.lib
ifdef G4LIB_BUILD_ZLIB
GLOBLIBS += libG4zlib.lib
endif
GLOBLIBS += libG4interfaces.lib libG4run.lib libG4event.lib
GLOBLIBS += libG4tracking.lib libG4processes.lib libG4digits_hits.lib
GLOBLIBS += libG4track.lib libG4particles.lib libG4geometry.lib
GLOBLIBS += libG4materials.lib libG4graphics_reps.lib
GLOBLIBS += libG4intercoms.lib libG4global.lib
include $(G4INSTALL)/config/architecture.gmk
include $(G4INSTALL)/config/G4VIS_BUILD.gmk
include $(G4INSTALL)/config/G4UI_BUILD.gmk
include $(G4INSTALL)/config/interactivity.gmk
CPPFLAGS += -I$(G4BASE)/visualization/externals/gl2ps/include
CPPFLAGS += -I$(G4BASE)/visualization/management/include
CPPFLAGS += -I$(G4BASE)/visualization/modeling/include
CPPFLAGS += -I$(G4BASE)/externals/g4tools/include
CPPFLAGS += -I$(G4BASE)/global/management/include
CPPFLAGS += -I$(G4BASE)/global/HEPGeometry/include
CPPFLAGS += -I$(G4BASE)/global/HEPRandom/include
CPPFLAGS += -I$(G4BASE)/geometry/solids/CSG/include
CPPFLAGS += -I$(G4BASE)/geometry/solids/specific/include
CPPFLAGS += -I$(G4BASE)/graphics_reps/include
CPPFLAGS += -I$(G4BASE)/geometry/management/include
CPPFLAGS += -I$(G4BASE)/geometry/navigation/include
CPPFLAGS += -I$(G4BASE)/geometry/volumes/include
CPPFLAGS += -I$(G4BASE)/processes/management/include
CPPFLAGS += -I$(G4BASE)/intercoms/include
CPPFLAGS += -I$(G4BASE)/interfaces/common/include
CPPFLAGS += -I$(G4BASE)/interfaces/basic/include
CPPFLAGS += -I$(G4BASE)/materials/include
CPPFLAGS += -I$(G4BASE)/track/include
CPPFLAGS += -I$(G4BASE)/tracking/include
CPPFLAGS += -I$(G4BASE)/digits_hits/digits/include
CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include
CPPFLAGS += -I$(G4BASE)/particles/management/include
CPPFLAGS += -I$(G4BASE)/event/include
CPPFLAGS += -I$(G4BASE)/run/include
CPPFLAGS += -I$(G4BASE)/tasking/include
# Locally adjust source list before including common.gmk
sources := $(addprefix src/,G4OpenGLImmediateViewer.cc \
G4OpenGLImmediateSceneHandler.cc \
G4OpenGLViewer.cc \
G4OpenGLStoredViewer.cc \
G4OpenGLStoredSceneHandler.cc \
G4OpenGLFontBaseStore.cc \
G4OpenGLSceneHandler.cc \
G4OpenGLViewerMessenger.cc \
G4OpenGLTransform3D.cc \
G4VisFeaturesOfOpenGL.cc \
G4gl2ps.cc)
ifdef G4VIS_BUILD_OPENGLX_DRIVER
sources += $(addprefix src/,\
G4OpenGLImmediateX.cc \
G4OpenGLImmediateXViewer.cc \
G4OpenGLStoredX.cc \
G4OpenGLStoredXViewer.cc \
G4OpenGLXViewer.cc)
endif
ifdef G4VIS_BUILD_OPENGLXM_DRIVER
sources += $(addprefix src/,\
G4OpenGLImmediateXm.cc \
G4OpenGLImmediateXmViewer.cc \
G4OpenGLStoredXm.cc \
G4OpenGLStoredXmViewer.cc \
G4OpenGLXm.cc \
G4OpenGLXmBox.cc \
G4OpenGLXmConvenienceRoutines.cc \
G4OpenGLXmFourArrowButtons.cc \
G4OpenGLXmFramedBox.cc \
G4OpenGLXmMainMenubarCallbacks.cc \
G4OpenGLXmPanningCallbacks.cc \
G4OpenGLXmPushButton.cc \
G4OpenGLXmRadioButton.cc \
G4OpenGLXmRotationCallbacks.cc \
G4OpenGLXmSeparator.cc \
G4OpenGLXmSliderBar.cc \
G4OpenGLXmStyleCallbacks.cc \
G4OpenGLXmTextField.cc \
G4OpenGLXmTopLevelShell.cc \
G4OpenGLXmViewer.cc \
G4OpenGLXmViewerMessenger.cc \
G4OpenGLXmVWidgetComponent.cc \
G4OpenGLXmVWidgetContainer.cc \
G4OpenGLXmVWidgetObject.cc \
G4OpenGLXmVWidgetShell.cc \
G4OpenGLXmWindowHandlingCallbacks.cc)
endif
ifdef G4VIS_BUILD_OPENGLQT_DRIVER
sources += $(addprefix src/, \
G4OpenGLImmediateQt.cc \
G4OpenGLImmediateQtViewer.cc \
G4OpenGLQt.cc \
G4OpenGLQtExportDialog.cc \
G4OpenGLQtMovieDialog.cc \
G4OpenGLVboDrawer.cc \
G4OpenGLQtViewer.cc \
G4OpenGLStoredQt.cc \
G4OpenGLStoredQtSceneHandler.cc \
G4OpenGLStoredQtViewer.cc)
endif
ifdef G4VIS_BUILD_OPENGLWIN32_DRIVER
sources += $(addprefix src/, \
G4OpenGLImmediateWin32.cc \
G4OpenGLImmediateWin32Viewer.cc \
G4OpenGLStoredWin32.cc \
G4OpenGLStoredWin32Viewer.cc \
G4OpenGLWin32Viewer.cc)
endif
include $(G4INSTALL)/config/moc.gmk
include $(G4INSTALL)/config/common.gmk
+64
View File
@@ -6,6 +6,70 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
# 2023-05-31 Ben Morgan (opengl-V11-01-09)
- Remove support for Qt < 5.9
- Clarify remaining version checks using QT_VERSION_CHECK instead of raw hex
- Add inclusion of qdesktopwidget header required by Qt < 5.10
## 2023-05-16 John Allison (opengl-V11-01-08)
- G4OpenGLQtViewer: Disable the "old" scene tree.
- Comment out just two lines:
- Prevent G4OpenGLQtViewer overwriting the "new" scene tree.
- Prevent G4OpenGLQtViewer registering the "old" widget.
- The problem is G4OpenGLQtViewer removes the "new" scene tree and
registers the "old" one, not just for the OGLSQt viewer,
but for *all* subsequent viewers, so using OGLSQt completely prevents
use of the "new" scene tree. Geant4 examples execute
"/vis/open OGL" in the "vis.mac" macro, so the "new" scene tree is
never seen nor used.
- This is a "stop-gap" solution - we need to decide how to proceed.
- We could keep the "old" scene tree as an option.
- In favour of this: the "old" tree is more highly featured.
- We could remove the "old" scene tree completely.
- We should then transfer nice features of the "old" scene tree
to the "new" one.
- In any case, new features will be progressively added to the
"new" scene tree in future developments.
## 2023-04-27 Ben Morgan (opengl-V11-01-07)
- Minimum build and code changes required to compile/link against both Qt5 and Qt6
## 2023-04-14 John Allison (opengl-V11-01-06)
- Co-working: visman-V11-01-04, greps-V11-01-03, interfaces-V11-01-11,
openinventor-V11-01-04, vis_toolssg-V11-01-05.
- New Scene Tree Phase 2 - first implementation of a no-frills GUI-side
- See visualization/management/History for full description.
- Revert earlier changes for the new scene tree.
- After the introduction of virtual G4VInteractiveSession::UpdateSceneTree
they are no loner necessary.
## 2023-04-02 Ben Morgan (opengl-V11-01-05)
- No longer link to QtPrintSupport, which is not used in the toolkit.
- Remove inclusion of qprinter.h.
## 2023-03-28 John Allison (opengl-V11-01-04)
- G4OpenGLQtViewer:
- Move G4UIQt* fUiQt from private to protected.
- Implement UpdateGUISceneTree.
- fUiQt->UpdateSceneTree(fSceneTree).
- G4OpenGLImmediateQtViewer.cc:
- Use UpdateGUISceneTree in DrawView.
- G4OpenGLStoredQtViewer.cc:
- Use UpdateGUISceneTree if (kernelVisitWasNeeded).
## 2023-03-22 Ben Morgan (opengl-V11-01-03)
- Export public compile definitions to indicate availablity of specific drivers. Moves to
"use on link" model.
## 2023-03-03 Ben Morgan (opengl-V11-01-02)
- Remove obsolete G4OPENGL_VERSION_2 symbol and G4OpenGLVboDrawer class.
## 2023-01-30 Ben Morgan (opengl-V11-01-01)
- Link to new G4UIcore/UIimplementation modules in place of former G4UIbasic/UIcommon
## 2023-01-28 Ben Morgan (opengl-V11-01-00)
- Make G4modeling a private dependency, unless Qt is active, when it must be public.
## 2022-11-25 Gabriele Cosmo (opengl-V11-00-21)
- Fixed compilation warnings for implicit type conversions on macOS/XCode 14.1.
@@ -71,21 +71,13 @@
#if defined (G4VIS_BUILD_OPENGLX_DRIVER) || defined (G4VIS_USE_OPENGLX)
#else
#ifdef __MACH__
//# define G4OPENGL_VERSION_2 1
#include <OpenGL/gl.h>
#else
#include <GL/gl.h>
#endif
#include <qgl.h>
#endif
#endif
#ifdef G4OPENGL_VERSION_2
# undef G4VIS_BUILD_OPENGL_GL2PS
// include all redefinitions of openGl functions for Vertex Buffer Objects
# include "G4OpenGLVboDrawer.hh"
#endif
#define G4OPENGL_FLT_BIG 1.e20
#endif
@@ -35,14 +35,12 @@
#include "G4OpenGLImmediateViewer.hh"
#include "G4OpenGLQtViewer.hh"
#include <qgl.h> // include <qglwidget.h>
#include "globals.hh"
class G4OpenGLImmediateSceneHandler;
class G4OpenGLImmediateQtViewer:
public G4OpenGLQtViewer, public G4OpenGLImmediateViewer, public QGLWidget {
public G4OpenGLQtViewer, public G4OpenGLImmediateViewer, public G4QGLWidgetType {
public:
G4OpenGLImmediateQtViewer (G4OpenGLImmediateSceneHandler& scene,
@@ -49,7 +49,15 @@ class G4UImanager;
class G4Text;
class G4UIcommand;
class QGLWidget;
#include <QtGlobal>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QGLWidget>
using G4QGLWidgetType = QGLWidget;
#else
#include <QOpenGLWidget>
using G4QGLWidgetType = QOpenGLWidget;
#endif
class QDialog;
class QTextEdit;
class QContextMenuEvent;
@@ -72,9 +80,6 @@ class QColor;
class G4OpenGLSceneHandler;
class G4OpenGLQtMovieDialog;
class QLineEdit;
#if QT_VERSION < 0x050600
class QSignalMapper;
#endif
class G4UIQt;
class QTableWidget;
class QTableWidgetItem;
@@ -166,7 +171,7 @@ public:
protected:
void CreateGLQtContext ();
virtual void CreateMainWindow (QGLWidget*,const QString&);
virtual void CreateMainWindow (G4QGLWidgetType*,const QString&);
void G4manageContextMenuEvent(QContextMenuEvent *e);
void rotateQtScene(float, float);
void rotateQtSceneToggle(float, float);
@@ -184,6 +189,7 @@ protected:
bool isCurrentWidget();
protected:
G4UIQt* fUiQt;
QWidget* fGLWidget;
void savePPMToTemp();
int fRecordFrameNumber;
@@ -307,7 +313,7 @@ private:
G4OpenGLQtMovieDialog* fMovieParametersDialog;
RECORDING_STEP fRecordingStep;
QProcess *fProcess;
#if QT_VERSION < 0x050e00
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
QTime *fLastEventTime;
#else
QElapsedTimer *fLastEventTime;
@@ -358,12 +364,7 @@ private:
QTreeWidgetItem* fModelShortNameItem;
int fNumber;
int fMaxPOindexInserted;
G4UIQt* fUiQt;
#if QT_VERSION < 0x050600
QSignalMapper *fSignalMapperMouse;
QSignalMapper *fSignalMapperSurface;
QSignalMapper *fSignalMapperPicking;
#endif
// quick map index to find next item
std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIterator;
std::map <int, QTreeWidgetItem*>::const_iterator fLastSceneTreeWidgetAskForIteratorEnd;
@@ -103,31 +103,6 @@ public:
static void SetFlushAction(FlushAction action)
{fFlushAction = action;}
#ifdef G4OPENGL_VERSION_2
private :
// vertex vector to be given to the graphic card
std::vector<double> fOglVertex;
// indices vector to be given to the graphic card
std::vector<unsigned short> fOglIndices;
// before, drawyType (as GL_QUADS, GL_TRIANGLES...) was
// given in glBegin. Now it has to be given in glDrawArray (at the end)
GLenum fDrawArrayType;
// emulate GL_QUADS behaviour by inverting two last positions
bool fEmulate_GL_QUADS;
// Try to optimize a bit the pipeline
void OptimizeVBOForTrd();
void OptimizeVBOForCons(G4int aNoFacet);
// emulating glEnd and glBegin
void glEndVBO();
void glBeginVBO(GLenum type);
void drawVBOArray(std::vector<double> vertices);
// Buffers used to access vertex and indices elements
GLuint fVertexBufferObject;
GLuint fIndicesBufferObject;
#endif //G4OPENGL_VERSION_2
protected:
G4OpenGLSceneHandler (G4VGraphicsSystem& system,
@@ -141,19 +116,6 @@ protected:
void ClearAndDestroyAtts(); // Destroys att holders and clears pick map.
#ifdef G4OPENGL_VERSION_2
// Special case for VBO, we want to have acces to the VBO drawer everywhere
// because instead of OpenGL call which are static, VBO openGL functions :
// - Are functions of an WGLWidget object(G4OpenGLImmediateViewer in our case)
// - Needs an access to the QGLSHader
// - Have to be redefined in a VBO way
inline void setVboDrawer(G4OpenGLVboDrawer* drawer) {
fVboDrawer = drawer;
}
G4OpenGLVboDrawer* fVboDrawer;
#endif // G4OPENGL_VERSION_2
GLuint fPickName;
std::map<GLuint, G4AttHolder*> fPickMap; // For picking.
@@ -34,7 +34,6 @@
#include "G4OpenGLStoredViewer.hh"
#include "G4OpenGLQtViewer.hh"
#include <qgl.h> // include qglwidget
class QMouseEvent;
class QWheelEvent;
@@ -43,7 +42,7 @@ class QContextMenuEvent;
class G4OpenGLStoredSceneHandler;
class G4OpenGLStoredQtViewer:
public G4OpenGLQtViewer, public G4OpenGLStoredViewer, public QGLWidget {
public G4OpenGLQtViewer, public G4OpenGLStoredViewer, public G4QGLWidgetType {
public:
G4OpenGLStoredQtViewer (G4OpenGLStoredSceneHandler& scene,
@@ -1,161 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
//
// G4OpenGLVboDrawer : Class to provide Wt and Qt specific
// functionality for OpenGL in GEANT4
// All references to Wt removed - 1/3/21 JA
#ifndef G4OpenGLVboDrawer_HH
#define G4OpenGLVboDrawer_HH
#include "G4OpenGL.hh"
#ifdef G4OPENGL_VERSION_2
// GL2PS
#define GL2PS_TEXT_B 4
#define GL2PS_TEXT_BL 5
#define GL2PS_TEXT_BR 6
#define GL2PS_EPS 1
#define GL2PS_PDF 2
#define GL2PS_PS 3
#define GL2PS_SVG 4
#define glEdgeFlag(a) fVboDrawer->empty()
#define glRenderMode(a) fVboDrawer->returnNULL()
#define glClipPlane(a,b) fVboDrawer->empty()
#define glGetIntegerv(a,b) fVboDrawer->empty()
#define glGetFloatv(a,b) fVboDrawer->empty()
#define glGetDoublev(a,b) fVboDrawer->empty()
#define glPassThrough fVboDrawer->empty()
#define glGetBooleanv fVboDrawer->empty()
#define glLoadName(a) fVboDrawer->empty()
#define glPushMatrix() fVboDrawer->empty()
#define glLoadIdentity() fVboDrawer->empty()
#define glPopMatrix() fVboDrawer->empty()
#define glCallList(a) fVboDrawer->empty()
#define glGenLists(a) fVboDrawer->returnNULL()
#define glVertex3d fVboDrawer->empty()
#define glBegin fVboDrawer->empty()
#define glEnd fVboDrawer->empty()
#define glNewList(a,b) fVboDrawer->empty()
#define glEndList() fVboDrawer->empty()
#define glPolygonMode(a,b) fVboDrawer->empty()
#define glDrawBuffer(a) fVboDrawer->empty()
#define glDeleteLists(a,b) fVboDrawer->empty()
#define glStencilFunc(a,b,c) fVboDrawer->empty()
#define glStencilOp(a,b,c) fVboDrawer->empty()
#define glColorMaterial(a,b) fVboDrawer->empty()
#define glLightfv(a,b,c) fVboDrawer->empty()
#define glScaled(a,b,c) fVboDrawer->empty()
#define gluLookAt fVboDrawer->empty()
#define gluPickMatrix fVboDrawer->empty()
#define glSelectBuffer(a,b) fVboDrawer->empty()
#define glInitNames() fVboDrawer->empty()
#define glPushNames(a) fVboDrawer->empty()
#define glPushName(a) fVboDrawer->empty()
#define glPixelStorei(a,b) fVboDrawer->empty()
#define glRasterPos3d(a,b,c) fVboDrawer->empty()
#define Geant4_gl2psTextOpt(a,b,c,d,e) fVboDrawer->empty()
#define glMaterialfv(a,b,c) fVboDrawer->empty()
#define glCullFace(a) fVboDrawer->empty()
#define glReadBuffer(a) fVboDrawer->empty()
#define glReadPixels(a,b,c,d,e,f,g) fVboDrawer->empty()
#define glTranslatef(a,b,c) fVboDrawer->empty() // TO BE FIXED
// +--------------------------------+
// + QT (OpenGL ES) case +
// +--------------------------------+
class G4OpenGLImmediateQtViewer;
#define glOrtho fVboDrawer->vboGlOrtho
#define glFrustum fVboDrawer->vboGlFrustum
#define glMultMatrixf fVboDrawer->vboGlMultMatrixf
#define glMultMatrixd fVboDrawer->vboGlMultMatrixd
#define glMatrixMode fVboDrawer->vboGlMatrixMode
#define glPointSize fVboDrawer->vboGlPointSize
#define glColor3d fVboDrawer->vboGlColor3d
#define glColor4d fVboDrawer->vboGlColor4d
#define glColor4fv fVboDrawer->vboGlColor4fv
class G4OpenGLViewer;
class G4OpenGLVboDrawer {
public:
G4OpenGLVboDrawer (G4OpenGLViewer*, std::string type);
// Create a new OpenGL Drawer. Type could be one of the following :
// OGL-ES, OGL-Stored, OGL-Immediate, OGL-VBO
virtual ~G4OpenGLVboDrawer ();
void vboGlMultMatrixf( const GLfloat *m );
void vboGlMultMatrixd( const GLdouble *m );
void vboGlFlush();
void vboGlOrtho(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
void vboGlFrustum(GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble);
void vboGlMatrixMode(GLenum);
void vboGlPointSize(float size);
inline void vboGlColor3d(int red,int green,int blue) {
vboGlColor4d(red,green, blue, 1.0);
}
void vboGlColor4d(int red,int green,int blue,int alpha);
void vboGlColor4fv(const GLfloat*);
inline const char * getFragmentShaderSrc() {
return fFragmentShaderSrc;
}
inline const char * getVertexShaderSrc() {
return fVertexShaderSrc;
}
inline bool isVBO() {
if ((fOGLType == "OGL-ES") || (fOGLType == "OGL-VBO")) {
return true;
}
return false;
}
inline void empty() {}
inline GLuint returnNULL() {
return 0;
}
private:
const char *fFragmentShaderSrc;
const char *fVertexShaderSrc;
std::string fOGLType;
GLenum fMatrixMode;
G4OpenGLImmediateQtViewer* fVboViewer;
};
#endif // G4OPENGL_VERSION_2
#endif // G4OpenGLVboDrawer_HH
@@ -34,9 +34,6 @@
#include "G4VViewer.hh"
#include "G4OpenGL.hh"
#ifdef G4OPENGL_VERSION_2
#include "G4OpenGLVboDrawer.hh"
#endif
class G4OpenGLSceneHandler;
class G4gl2ps;
@@ -110,16 +107,6 @@ public:
virtual bool exportImage(std::string name="", int width=-1, int height=-1);
bool setExportImageFormat(std::string format,bool quiet = false);
#ifdef G4OPENGL_VERSION_2
void setVboDrawer(G4OpenGLVboDrawer* drawer);
G4OpenGLVboDrawer* fVboDrawer;
inline bool isInitialized() {
return fGlViewInitialized;
}
#endif
protected:
G4OpenGLViewer (G4OpenGLSceneHandler& scene);
virtual ~G4OpenGLViewer ();
@@ -241,39 +228,6 @@ private :
bool fIsGettingPickInfos;
// Block SetView() during picking
#ifdef G4OPENGL_VERSION_2
public:
inline GLuint getShaderProgram() {
return fShaderProgram;
}
inline GLuint getShaderProjectionMatrix() {
return fpMatrixUniform;
}
inline GLuint getShaderTransformMatrix() {
return ftMatrixUniform;
}
inline GLuint getShaderViewModelMatrix() {
return fmvMatrixUniform;
}
protected :
// define the keyword shader to handle it in a better way for OpenGL and WebGL
#define Shader GLuint
// define some attributes and variables for OpenGL and WebGL
GLuint fShaderProgram;
// Program and related variables
GLuint fVertexPositionAttribute;
GLuint fVertexNormalAttribute;
GLuint fpMatrixUniform;
GLuint fcMatrixUniform;
GLuint fmvMatrixUniform;
GLuint fnMatrixUniform;
GLuint ftMatrixUniform;
#endif
};
#endif
+31 -10
View File
@@ -32,7 +32,6 @@ geant4_add_module(G4OpenGL
geant4_module_link_libraries(G4OpenGL
PUBLIC
G4globman
G4modeling
G4graphics_reps
G4hepgeometry
G4intercoms
@@ -41,6 +40,17 @@ geant4_module_link_libraries(G4OpenGL
G4geometrymng
G4run)
# Minor hack: G4modeling is a private dependency, unless Qt is activated when it
# becomes a public dependency. CMake will deduplicate the link in favour of PUBLIC
# when appropriate, but we can't then check consistency reliably. So we have to
# make the link dependent on building for Qt...
# Another demonstratation of awkward vis system of more than one driver per library...
if(GEANT4_USE_QT)
geant4_module_link_libraries(G4OpenGL PUBLIC G4modeling)
else()
geant4_module_link_libraries(G4OpenGL PRIVATE G4modeling)
endif()
#----------------------------------------------------------------------------
# Add X11 OpenGL Support if requested
if(GEANT4_USE_OPENGL_X11)
@@ -59,7 +69,9 @@ if(GEANT4_USE_OPENGL_X11)
G4OpenGLXViewer.cc)
# Add the compile definitions needed for the X11 component (G4OpenGL.hh, G4OpenGLViewer.cc)
geant4_module_compile_definitions(G4OpenGL PRIVATE G4VIS_BUILD_OPENGLX_DRIVER)
geant4_module_compile_definitions(G4OpenGL
PUBLIC G4VIS_USE_OPENGLX
PRIVATE G4VIS_BUILD_OPENGLX_DRIVER)
endif()
#----------------------------------------------------------------------------
@@ -123,10 +135,12 @@ if(GEANT4_USE_XM)
endif()
# Add the compile definitions needed for the Xm component (G4OpenGL.hh, G4OpenGLViewer.cc)
geant4_module_compile_definitions(G4OpenGL PRIVATE G4VIS_BUILD_OPENGLXM_DRIVER)
geant4_module_compile_definitions(G4OpenGL
PUBLIC G4VIS_USE_OPENGLXM
PRIVATE G4VIS_BUILD_OPENGLXM_DRIVER)
# Add in Xm and needed modules
geant4_module_link_libraries(G4OpenGL PUBLIC Motif::Xm PRIVATE G4UIcommon)
geant4_module_link_libraries(G4OpenGL PUBLIC Motif::Xm PRIVATE G4UIimplementation)
endif()
# Common X11/Xm link libraries
@@ -149,7 +163,6 @@ if(GEANT4_USE_QT)
G4OpenGLQt.hh
G4OpenGLQtExportDialog.hh
G4OpenGLQtMovieDialog.hh
G4OpenGLVboDrawer.hh
G4OpenGLQtViewer.hh
G4OpenGLStoredQt.hh
G4OpenGLStoredQtSceneHandler.hh
@@ -160,19 +173,24 @@ if(GEANT4_USE_QT)
G4OpenGLQt.cc
G4OpenGLQtExportDialog.cc
G4OpenGLQtMovieDialog.cc
G4OpenGLVboDrawer.cc
G4OpenGLQtViewer.cc
G4OpenGLStoredQt.cc
G4OpenGLStoredQtSceneHandler.cc
G4OpenGLStoredQtViewer.cc)
# Add the definitions (G4OpenGL.hh, G4OpenGLViewer.cc)
geant4_module_compile_definitions(G4OpenGL PRIVATE G4VIS_BUILD_OPENGLQT_DRIVER)
geant4_module_compile_definitions(G4OpenGL
PUBLIC G4VIS_USE_OPENGLQT
PRIVATE G4VIS_BUILD_OPENGLQT_DRIVER)
# Add in Qt libraries and geant4 modules
geant4_module_link_libraries(G4OpenGL
PUBLIC Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::PrintSupport Qt${QT_VERSION_MAJOR}::Widgets OpenGL::GL
PRIVATE G4UIbasic G4UIcommon)
PUBLIC Qt${QT_VERSION_MAJOR}::OpenGL Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Widgets OpenGL::GL
PRIVATE G4UIimplementation)
if(QT_VERSION_MAJOR GREATER 5)
geant4_module_link_libraries(G4OpenGL PRIVATE Qt${QT_VERSION_MAJOR}::OpenGLWidgets)
endif()
endif()
#----------------------------------------------------------------------------
@@ -194,7 +212,10 @@ if(GEANT4_USE_OPENGL_WIN32)
G4OpenGLWin32Viewer.cc )
# Add the compile definitions (G4OpenGL.hh, G4OpenGLViewer.cc)
geant4_module_compile_definitions(G4OpenGL PRIVATE G4VIS_BUILD_OPENGLWIN32_DRIVER)
geant4_module_compile_definitions(G4OpenGL
PUBLIC G4VIS_USE_OPENGLWIN32
PRIVATE G4VIS_BUILD_OPENGLWIN32_DRIVER)
geant4_module_link_libraries(G4OpenGL PUBLIC OpenGL::GL)
endif()
@@ -39,10 +39,6 @@
#include <qapplication.h>
#include <qtabwidget.h>
#ifdef G4OPENGL_VERSION_2
#include <qglshaderprogram.h>
#endif
G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
(G4OpenGLImmediateSceneHandler& sceneHandler,
@@ -57,13 +53,6 @@ G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
setFocusPolicy(Qt::StrongFocus); // enable keybord events
fHasToRepaint = false;
fPaintEventLock = false;
// Create a new drawer
// register the QtDrawer to the OpenGLViewer
#ifdef G4OPENGL_VERSION_2
setVboDrawer(new G4OpenGLVboDrawer(this,"OGL-VBO"));
#endif
fUpdateGLLock = false;
if (fViewId < 0) return; // In case error in base class instantiation.
@@ -82,8 +71,8 @@ void G4OpenGLImmediateQtViewer::Initialise() {
glDrawBuffer (GL_BACK);
// set the good tab active
if (QGLWidget::parentWidget()) {
QTabWidget *parentTab = dynamic_cast<QTabWidget*> (QGLWidget::parentWidget()->parent()) ;
if (G4QGLWidgetType::parentWidget()) {
auto *parentTab = dynamic_cast<QTabWidget*> (G4QGLWidgetType::parentWidget()->parent()) ;
if (parentTab) {
parentTab->setCurrentIndex(parentTab->count()-1);
}
@@ -94,42 +83,7 @@ void G4OpenGLImmediateQtViewer::Initialise() {
void G4OpenGLImmediateQtViewer::initializeGL () {
#ifndef G4OPENGL_VERSION_2
InitializeGLView ();
#else
QGLShaderProgram *aQGLShaderProgram = new QGLShaderProgram (context());
fShaderProgram = aQGLShaderProgram->programId ();
aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Vertex,
fVboDrawer->getVertexShaderSrc());
aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Fragment,
fVboDrawer->getFragmentShaderSrc());
aQGLShaderProgram->link();
aQGLShaderProgram->bind();
fVertexPositionAttribute = glGetAttribLocation(fShaderProgram, "aVertexPosition");
fcMatrixUniform = glGetUniformLocation(fShaderProgram, "uCMatrix");
fpMatrixUniform = glGetUniformLocation(fShaderProgram, "uPMatrix");
ftMatrixUniform = glGetUniformLocation(fShaderProgram, "uTMatrix");
fmvMatrixUniform = glGetUniformLocation(fShaderProgram, "uMVMatrix");
// Load identity at beginning
float identity[16] = {
1.0f, 0, 0, 0,
0, 1.0f, 0, 0,
0, 0, 1.0f, 0,
0, 0, 0, 1.0f
};
glUniformMatrix4fv (fcMatrixUniform, 1, 0, identity);
glUniformMatrix4fv (fpMatrixUniform, 1, 0, identity);
glUniformMatrix4fv (ftMatrixUniform, 1, 0, identity);
glUniformMatrix4fv(fmvMatrixUniform, 1, 0, identity);
glUseProgram(fShaderProgram);
#endif
// If a double buffer context has been forced upon us, ignore the
// back buffer for this OpenGLImmediate view.
@@ -314,7 +268,12 @@ void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
// Force a repaint next time if the FRAMEBUFFER is not READY
fHasToRepaint = isFramebufferReady();
if ( fHasToRepaint) {
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
updateGL();
#else
// Not sure this is correct....
paintGL();
#endif
}
}
@@ -248,9 +248,7 @@ void G4OpenGLImmediateSceneHandler::BeginPrimitives2D
G4OpenGLTransform3D oglt (objectTransformation);
glMultMatrixd (oglt.GetGLMatrix ());
glDisable(GL_DEPTH_TEST); // But see parent scene handler!! In
#ifndef G4OPENGL_VERSION_2
glDisable (GL_LIGHTING); // some cases, we need to re-iterate this.
#endif
}
void G4OpenGLImmediateSceneHandler::EndPrimitives2D()
@@ -68,7 +68,7 @@ G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
// global layout
QVBoxLayout* globalVLayout = new QVBoxLayout(this);
globalVLayout->setMargin(10);
globalVLayout->setContentsMargins(10,10,10,10);
globalVLayout->setSpacing(10);
@@ -78,14 +78,14 @@ G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
QWidget * sizeWidget = new QWidget(this); // widget containing group button
QVBoxLayout * sizeWidgetLayout = new QVBoxLayout(sizeWidget);
sizeWidgetLayout->setMargin (10);
sizeWidgetLayout->setContentsMargins(10,10,10,10);
// original and modify radiobuttons
sizeGroupBox = new QGroupBox(tr("Size"));
QVBoxLayout *sizeGroupBoxLayout = new QVBoxLayout(sizeGroupBox);
QButtonGroup * sizeButtonGroupBox = new QButtonGroup();
sizeGroupBoxLayout->setMargin (15);
sizeGroupBoxLayout->setContentsMargins(15,15,15,15);
original = new QRadioButton("Original");
modify = new QRadioButton("Modify");
@@ -157,7 +157,7 @@ G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
QVBoxLayout * EPSGroupBoxLayout = new QVBoxLayout(EPSWidgetGroupBox);
EPSGroupBoxLayout->setMargin (15);
EPSGroupBoxLayout->setContentsMargins(15,15,15,15);
// colorButton = new QRadioButton("Color",EPSWidgetGroupBox);
// BWButton = new QRadioButton("Grayscale",EPSWidgetGroupBox);
@@ -187,7 +187,7 @@ G4OpenGLQtExportDialog::G4OpenGLQtExportDialog(
QGroupBox *imageGroupBox = new QGroupBox(tr("Image quality"),this);
QHBoxLayout *hSliderLayout = new QHBoxLayout(imageGroupBox);
hSliderLayout->setMargin (15);
hSliderLayout->setContentsMargins(15,15,15,15);
qualitySlider= new QSlider(Qt::Horizontal,imageGroupBox);
qualitySlider->setMinimum(0);
@@ -74,7 +74,7 @@ G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
// global layout
QVBoxLayout* globalVLayout = new QVBoxLayout(this);
globalVLayout->setMargin(10);
globalVLayout->setContentsMargins(10,10,10,10);
globalVLayout->setSpacing(10);
// Encoder group box
@@ -92,7 +92,7 @@ G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
fEncoderStatus = new QLabel(encoderGroupBox);
fEncoderStatus->setWordWrap(true);
encoderVGroupBoxLayout->setMargin(15);
encoderVGroupBoxLayout->setContentsMargins(15,15,15,15);
fEncoderStatus->setText("");
@@ -122,7 +122,7 @@ G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
fTempFolderStatus = new QLabel(tempFolderGroupBox);
fTempFolderStatus->setWordWrap(true);
tempFolderVGroupBoxLayout->setMargin(15);
tempFolderVGroupBoxLayout->setContentsMargins(15,15,15,15);
fTempFolderStatus->setText("");
tempFolderHBoxLayout->addWidget(fTempFolderPath);
@@ -153,7 +153,7 @@ G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
fSaveFileStatus = new QLabel(saveFileGroupBox);
fSaveFileStatus->setWordWrap(true);
saveFileVGroupBoxLayout->setMargin(15);
saveFileVGroupBoxLayout->setContentsMargins(15,15,15,15);
fSaveFileStatus->setText("");
saveFileHBoxLayout->addWidget(fSaveFileName);
@@ -177,7 +177,7 @@ G4OpenGLQtMovieDialog::G4OpenGLQtMovieDialog(
QVBoxLayout *statusVGroupBoxLayout = new QVBoxLayout(statusGroupBox);
fRecordingStatus = new QLabel(statusGroupBox);
statusVGroupBoxLayout->setMargin(15);
statusVGroupBoxLayout->setContentsMargins(15,15,15,15);
fRecordingStatus->setWordWrap(true);
QPalette mypalette( fRecordingStatus->palette() );
mypalette.setColor( QPalette::Text, Qt::green);
@@ -57,8 +57,6 @@
#include <qdialog.h>
#include <qpushbutton.h>
#include <qprocess.h>
#include <qdesktopwidget.h>
#include <qmenu.h>
#include <qimagewriter.h>
@@ -67,13 +65,14 @@
#include <qapplication.h>
#include <qmessagebox.h>
#include <qfiledialog.h>
#include <qprinter.h>
#include <qdatetime.h>
#if QT_VERSION >= 0x050e00
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#include <qelapsedtimer.h>
#endif
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
#include "qdesktopwidget.h"
#endif
#include <qpainter.h>
#include <qgl.h> // include <qglwidget.h>
#include <qdialog.h>
#include <qcolordialog.h>
#include <qevent.h> //include <qcontextmenuevent.h>
@@ -81,11 +80,7 @@
#include <qgroupbox.h>
#include <qcombobox.h>
#include <qlineedit.h>
#if QT_VERSION < 0x050600
#include <qsignalmapper.h>
#else
#include <qscreen.h>
#endif
#include <qmainwindow.h>
#include <qtablewidget.h>
#include <qheaderview.h>
@@ -95,6 +90,12 @@
#include <qcursor.h>
#include <qthread.h>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#include <QGLContext>
#else
#include <QOpenGLContext>
#endif
#ifndef G4GMAKE
#include "moc_G4OpenGLQtViewer.cpp"
#endif
@@ -112,7 +113,7 @@ namespace
//////////////////////////////////////////////////////////////////////////////
void G4OpenGLQtViewer::CreateMainWindow (
QGLWidget* glWidget
G4QGLWidgetType* glWidget
,const QString& name
)
//////////////////////////////////////////////////////////////////////////////
@@ -177,7 +178,7 @@ void G4OpenGLQtViewer::CreateMainWindow (
glWidget->setParent(glDialogWidget);
QHBoxLayout *mainLayout = new QHBoxLayout();
mainLayout->setMargin(0);
mainLayout->setContentsMargins(0,0,0,0);
mainLayout->setSpacing(0);
mainLayout->addWidget(fGLWidget);
if (fGLWidget->inherits("QMainWindow")) {
@@ -187,20 +188,20 @@ void G4OpenGLQtViewer::CreateMainWindow (
//useful for MACOSX, we have to compt the menuBar height
#if QT_VERSION >= 0x050a00
G4int offset = QApplication::desktop()->height()
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
G4int offset = QGuiApplication::primaryScreen()->availableGeometry().height()
- QGuiApplication::screenAt(QPoint(20,20))->availableGeometry().height();
#else
G4int offset = QApplication::desktop()->height()
- QApplication::desktop()->availableGeometry().height();
#endif
G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height());
if (fVP.GetWindowAbsoluteLocationHintY(QApplication::desktop()->height())< offset) {
G4int YPos= fVP.GetWindowAbsoluteLocationHintY(QGuiApplication::primaryScreen()->availableGeometry().height());
if (fVP.GetWindowAbsoluteLocationHintY(QGuiApplication::primaryScreen()->availableGeometry().height())< offset) {
YPos = offset;
}
glDialogWidget->resize(getWinWidth(), getWinHeight());
glDialogWidget->move(fVP.GetWindowAbsoluteLocationHintX(QApplication::desktop()->width()),YPos);
glDialogWidget->move(fVP.GetWindowAbsoluteLocationHintX(QGuiApplication::primaryScreen()->availableGeometry().width()),YPos);
glDialogWidget->show();
}
@@ -218,6 +219,7 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
)
:G4VViewer (scene, -1)
,G4OpenGLViewer (scene)
,fUiQt(NULL)
,fGLWidget(NULL)
,fRecordFrameNumber(0)
,fMouseOnSceneTree(false)
@@ -266,12 +268,6 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
,fSceneTreeDepth(1)
,fModelShortNameItem(NULL)
,fMaxPOindexInserted(-1)
,fUiQt(NULL)
#if QT_VERSION < 0x050600
,fSignalMapperMouse(NULL)
,fSignalMapperSurface(NULL)
,fSignalMapperPicking(NULL)
#endif
,fTreeIconOpen(NULL)
,fTreeIconClosed(NULL)
,fLastExportSliderValue(80)
@@ -298,14 +294,10 @@ G4OpenGLQtViewer::G4OpenGLQtViewer (
initMovieParameters();
#if QT_VERSION < 0x050e00
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
fLastEventTime = new QTime();
#else
fLastEventTime = new QElapsedTimer();
#endif
#if QT_VERSION < 0x050600
fSignalMapperMouse = new QSignalMapper(this);
fSignalMapperSurface = new QSignalMapper(this);
#endif
// Set default path and format
fFileSavePath = QDir::currentPath();
@@ -546,20 +538,11 @@ void G4OpenGLQtViewer::createPopupMenu() {
fContextMenu = new QMenu("All");
QMenu *mMouseAction = fContextMenu->addMenu("&Mouse actions");
#if QT_VERSION < 0x050600
fMouseRotateAction = mMouseAction->addAction("Rotate", fSignalMapperMouse, SLOT(map()));
fMouseMoveAction = mMouseAction->addAction("Move", fSignalMapperMouse, SLOT(map()));
fMousePickAction = mMouseAction->addAction("Pick", fSignalMapperMouse, SLOT(map()));
fMouseZoomOutAction = mMouseAction->addAction("Zoom out", fSignalMapperMouse, SLOT(map()));
fMouseZoomInAction = mMouseAction->addAction("Zoom in", fSignalMapperMouse, SLOT(map()));
#else
fMouseRotateAction = mMouseAction->addAction("Rotate", this, [this](){ this->toggleMouseAction(1); });
fMouseMoveAction = mMouseAction->addAction("Move", this, [this](){ this->toggleMouseAction(2); });
fMousePickAction = mMouseAction->addAction("Pick", this, [this](){ this->toggleMouseAction(3); });
fMouseZoomOutAction = mMouseAction->addAction("Zoom out", this, [this](){ this->toggleMouseAction(4); });
fMouseZoomInAction = mMouseAction->addAction("Zoom in", this, [this](){ this->toggleMouseAction(5); });
#endif
QAction *shortcutsAction = mMouseAction->addAction("Show shortcuts");
fMouseRotateAction->setCheckable(true);
@@ -569,15 +552,6 @@ void G4OpenGLQtViewer::createPopupMenu() {
fMouseZoomInAction->setCheckable(true);
shortcutsAction->setCheckable(false);
#if QT_VERSION < 0x050600
connect(fSignalMapperMouse, SIGNAL(mapped(int)),this, SLOT(toggleMouseAction(int)));
fSignalMapperMouse->setMapping(fMouseRotateAction,1);
fSignalMapperMouse->setMapping(fMouseMoveAction,2);
fSignalMapperMouse->setMapping(fMousePickAction,3);
fSignalMapperMouse->setMapping(fMouseZoomOutAction,4);
fSignalMapperMouse->setMapping(fMouseZoomInAction,5);
#endif
QObject::connect(shortcutsAction,
SIGNAL(triggered(bool)),
this,
@@ -588,46 +562,15 @@ void G4OpenGLQtViewer::createPopupMenu() {
QMenu *mProjection = mStyle->addMenu("&Projection");
#if QT_VERSION < 0x050600
fProjectionOrtho = mProjection->addAction("Orthographic", fSignalMapperSurface, SLOT(map()));
fProjectionPerspective = mProjection->addAction("Perspective", fSignalMapperSurface, SLOT(map()));
// INIT mProjection
if (fVP.GetFieldHalfAngle() == 0) {
createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(bool)),1);
} else {
createRadioAction(fProjectionOrtho, fProjectionPerspective,SLOT(toggleProjection(bool)),2);
}
#else
// no more radioAction, not realy useful and could be confusing to use context menu and icon at the same time
fProjectionOrtho = mProjection->addAction("Orthographic", this, [this](){ this->toggleProjection(true); });
fProjectionPerspective = mProjection->addAction("Perspective", this, [this](){ this->toggleProjection(false); });
#endif
// === Drawing Menu ===
QMenu *mDrawing = mStyle->addMenu("&Drawing");
#if QT_VERSION < 0x050600
fDrawingWireframe = mDrawing->addAction("Wireframe", fSignalMapperSurface, SLOT(map()));
fDrawingLineRemoval = mDrawing->addAction("Hidden line removal", fSignalMapperSurface, SLOT(map()));
fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal", fSignalMapperSurface, SLOT(map()));
fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal", fSignalMapperSurface, SLOT(map()));
#endif
#if QT_VERSION < 0x050600
connect(fSignalMapperSurface, SIGNAL(mapped(int)),this, SLOT(toggleSurfaceAction(int)));
fSignalMapperSurface->setMapping(fDrawingWireframe,1);
fSignalMapperSurface->setMapping(fDrawingLineRemoval,2);
fSignalMapperSurface->setMapping(fDrawingSurfaceRemoval,3);
fSignalMapperSurface->setMapping(fDrawingLineSurfaceRemoval,4);
#else
fDrawingWireframe = mDrawing->addAction("Wireframe", this, [this](){ this->toggleSurfaceAction(1); });
fDrawingLineRemoval = mDrawing->addAction("Hidden line removal", this, [this](){ this->toggleSurfaceAction(2); });
fDrawingSurfaceRemoval = mDrawing->addAction("Hidden Surface removal", this, [this](){ this->toggleSurfaceAction(3); });
fDrawingLineSurfaceRemoval = mDrawing->addAction("Hidden line and surface removal", this, [this](){ this->toggleSurfaceAction(4); });
#endif
fDrawingWireframe->setCheckable(true);
fDrawingLineRemoval->setCheckable(true);
@@ -1067,7 +1010,7 @@ void G4OpenGLQtViewer::savePPMToTemp() {
if (fMovieTempFolderPath == "") {
return;
}
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return;
}
@@ -1075,7 +1018,11 @@ void G4OpenGLQtViewer::savePPMToTemp() {
QString filePath =fMovieTempFolderPath+fileName;
QImage image;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
image = qGLW->grabFrameBuffer();
#else
image = qGLW->grabFramebuffer();
#endif
bool res = false;
res = image.save(filePath,0);
@@ -1168,17 +1115,11 @@ void G4OpenGLQtViewer::actionChangeBackgroundColor() {
// //background colour in its drawing...
// // (Note added by JA 13/9/2005) Background now handled in view
// // parameters. A kernel visit is triggered on change of background.
#if QT_VERSION < 0x040500
bool a;
const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::black).rgba(),&a,fGLWidget));
#else
const QColor color =
QColorDialog::getColor(Qt::black,
fGLWidget,
" Get background color and transparency",
QColorDialog::ShowAlphaChannel);
#endif
if (color.isValid()) {
G4Colour colour(((G4double)color.red())/255,
((G4double)color.green())/255,
@@ -1192,17 +1133,11 @@ void G4OpenGLQtViewer::actionChangeBackgroundColor() {
}
void G4OpenGLQtViewer::actionChangeTextColor() {
#if QT_VERSION < 0x040500
bool a;
const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::yellow).rgba(),&a,fGLWidget));
#else
const QColor& color =
QColorDialog::getColor(Qt::yellow,
fGLWidget,
" Get text color and transparency",
QColorDialog::ShowAlphaChannel);
#endif
if (color.isValid()) {
G4Colour colour(((G4double)color.red())/255,
((G4double)color.green())/255,
@@ -1217,17 +1152,11 @@ void G4OpenGLQtViewer::actionChangeTextColor() {
}
void G4OpenGLQtViewer::actionChangeDefaultColor() {
#if QT_VERSION < 0x040500
bool a;
const QColor color = QColor(QColorDialog::getRgba (QColor(Qt::white).rgba(),&a,fGLWidget));
#else
const QColor& color =
QColorDialog::getColor(Qt::white,
fGLWidget,
" Get default color and transparency",
QColorDialog::ShowAlphaChannel);
#endif
if (color.isValid()) {
G4Colour colour(((G4double)color.red())/255,
((G4double)color.green())/255,
@@ -1361,7 +1290,7 @@ void G4OpenGLQtViewer::G4MouseReleaseEvent(QMouseEvent *evnt)
}
fAutoMove = true;
#if QT_VERSION < 0x050e00
#if (QT_VERSION < QT_VERSION_CHECK(5, 14, 0))
QTime lastMoveTime;
#else
QElapsedTimer lastMoveTime;
@@ -1458,7 +1387,12 @@ void G4OpenGLQtViewer::G4MouseMoveEvent(QMouseEvent *evnt)
fLastPos3 = fLastPos2;
fLastPos2 = fLastPos1;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
fLastPos1 = QPoint(evnt->x(), evnt->y());
#else
fLastPos1 = QPoint(evnt->position().x(), evnt->position().y());
#endif
int deltaX = fLastPos2.x()-fLastPos1.x();
int deltaY = fLastPos2.y()-fLastPos1.y();
@@ -1599,11 +1533,9 @@ void G4OpenGLQtViewer::rescaleImage(
void G4OpenGLQtViewer::G4wheelEvent (QWheelEvent * evnt)
{
#if QT_VERSION < 0x050F00
// Before Qt5.15
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->delta())/1200));
#else
// Qt5.15 and beyond
fVP.SetZoomFactor(fVP.GetZoomFactor()+(fVP.GetZoomFactor()*(evnt->angleDelta().y())/1200));
#endif
updateQWidget();
@@ -1904,11 +1836,9 @@ void G4OpenGLQtViewer::initMovieParameters() {
QObject ::connect(fProcess,SIGNAL(finished ( int)),
this,SLOT(processLookForFinished()));
fProcess->setProcessChannelMode(QProcess::MergedChannels);
#if QT_VERSION < 0x050F00
// Before Qt5.15
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
fProcess->start ("which ppmtompeg");
#else
// Qt5.15 and beyond
fProcess->start ("which ppmtompeg", QStringList());
#endif
}
@@ -2186,7 +2116,7 @@ QString G4OpenGLQtViewer::removeTempFolder() {
*/
bool G4OpenGLQtViewer::exportImage(std::string name, int width, int height) {
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto* qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return false;
}
@@ -2209,7 +2139,11 @@ bool G4OpenGLQtViewer::exportImage(std::string name, int width, int height) {
// Then try Qt saving functions
} else {
QImage image;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
image = qGLW->grabFrameBuffer();
#else
image = qGLW->grabFramebuffer();
#endif
bool res = image.save(QString(getRealPrintFilename().c_str()),0,fLastExportSliderValue);
@@ -2380,18 +2314,11 @@ void G4OpenGLQtViewer::encodeVideo()
setRecordingStatus(ENCODING);
fProcess = new QProcess();
#if QT_VERSION > 0x040100
QObject ::connect(fProcess,SIGNAL(finished ( int,QProcess::ExitStatus)),
this,SLOT(processEncodeFinished()));
QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
this,SLOT(processEncodeStdout()));
#else
QObject ::connect(fProcess,SIGNAL(finished ( int)),
this,SLOT(processEncodeFinished()));
QObject ::connect(fProcess,SIGNAL(readyReadStandardOutput ()),
this,SLOT(processEncodeStdout()));
#endif
#if QT_VERSION < 0x050a00
#if (QT_VERSION < QT_VERSION_CHECK(5, 10, 0))
fProcess->setReadChannelMode(QProcess::MergedChannels);
#else
fProcess->setProcessChannelMode(QProcess::MergedChannels);
@@ -2536,7 +2463,7 @@ void G4OpenGLQtViewer::createSceneTreeWidget() {
}
}
} else {
wItem->widget()->hide();
// wItem->widget()->hide();
}
}
}
@@ -2552,7 +2479,7 @@ void G4OpenGLQtViewer::createSceneTreeWidget() {
fSceneTreeWidget->setWindowTitle(QString(GetName().data()));
if (fUISceneTreeWidget != NULL) {
fUISceneTreeWidget->layout()->addWidget(fSceneTreeWidget);
// fUISceneTreeWidget->layout()->addWidget(fSceneTreeWidget);
}
// not available for Immediate mode
@@ -2576,21 +2503,10 @@ void G4OpenGLQtViewer::createSceneTreeComponent(){
fFilterOutput->setStyleSheet ("padding: 0px ");
QPixmap* searchIcon = fUiQt->getSearchIcon();
#if QT_VERSION > 0x050100
fFilterOutput->addAction(*searchIcon,QLineEdit::TrailingPosition);
fFilterOutput->setStyleSheet ("border-radius:7px;");
#else
QPushButton *coutTBFilterButton = new QPushButton();
coutTBFilterButton->setIcon(*searchIcon);
coutTBFilterButton->setStyleSheet ("padding-left: 0px; border:0px;");
fFilterOutput->setStyleSheet ("padding-right: 0px;");
#endif
layoutCoutTBButtons->addWidget(fFilterOutput);
#if QT_VERSION <= 0x050100
layoutCoutTBButtons->addWidget(coutTBFilterButton);
#endif
coutButtonWidget->setLayout(layoutCoutTBButtons);
vLayout->addWidget(coutButtonWidget);
@@ -2794,7 +2710,7 @@ void G4OpenGLQtViewer::setCheckComponent(QTreeWidgetItem* item,bool check)
void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
{
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto* qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return;
}
@@ -2828,12 +2744,12 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
// Calculate move for centre and right adjustment
QFontMetrics* f = new QFontMetrics (font);
#if QT_VERSION > 0x050110
G4double span = f->boundingRect(textCString).width();
#else
G4double span = f->width(textCString);
#endif
G4double xmove = 0., ymove = 0.;
// Marked as such due to current un-use when building with Qt6
// See use of renderText at end of function.
[[maybe_unused]] G4double xmove = 0.;
[[maybe_unused]] G4double ymove = 0.;
switch (g4text.GetLayout()) {
case G4Text::left: break;
case G4Text::centre: xmove -= span / 2.; break;
@@ -2853,13 +2769,16 @@ void G4OpenGLQtViewer::DrawText(const G4Text& g4text)
xmove *= fudgeFactor;
ymove *= fudgeFactor;
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
qGLW->renderText
((position.x()+(2*xmove)/getWinWidth()),
(position.y()+(2*ymove)/getWinHeight()),
position.z(),
textCString,
font);
#else
// Not yet obvious how to do this in Qt6....
#endif
}
}
@@ -3616,15 +3535,10 @@ void G4OpenGLQtViewer::changeColorAndTransparency(QTreeWidgetItem* item,int) {
}
const QColor& old = QColor(item->data(2,Qt::UserRole).value<QColor>());
#if QT_VERSION < 0x040500
bool a;
const QColor& color = QColor(QColorDialog::getRgba (old.rgba(),&a,fSceneTreeComponentTreeWidget));
#else
const QColor& color = QColorDialog::getColor(old,
fSceneTreeComponentTreeWidget,
" Get color and transparency",
QColorDialog::ShowAlphaChannel);
#endif
if (color.isValid()) {
@@ -4202,6 +4116,7 @@ void G4OpenGLQtViewer::updateToolbarAndMouseContextMenu(){
}
}
/**
Update the scene tree widget
*/
@@ -4553,12 +4468,6 @@ void G4OpenGLQtViewer::updatePickInfosWidget(int aX, int aY) {
}
}
// Create a new signalMapper
#if QT_VERSION < 0x050600
delete fSignalMapperPicking;
fSignalMapperPicking = new QSignalMapper(this);
#endif
// parse all pick results
G4int nPickedObjectsWithAttributes = 0;
for (unsigned int a=0; a< pickMapVector.size(); a++) {
@@ -4625,19 +4534,11 @@ void G4OpenGLQtViewer::updatePickInfosWidget(int aX, int aY) {
ed->setVisible((false));
ed->append(newStr.join(""));
#if QT_VERSION < 0x050600
connect(pickCoutButton, SIGNAL(clicked()), fSignalMapperPicking, SLOT(map()));
fSignalMapperPicking->setMapping(pickCoutButton,fPickInfosWidget->layout()->count()-1);
#else
std::cout << pickCoutButton->text().toStdString() << " "<< fPickInfosWidget->layout()->count()-1<< std::endl;
int tmp = fPickInfosWidget->layout()->count()-1;
connect(pickCoutButton, &QPushButton::clicked , [this, tmp](){ this->toggleSceneTreeComponentPickingCout(tmp);});
#endif
}
}
#if QT_VERSION < 0x050600
connect(fSignalMapperPicking, SIGNAL(mapped(int)),this, SLOT(toggleSceneTreeComponentPickingCout(int)));
#endif
// add a label to push everything up!
QLabel * pushUp = new QLabel("");
@@ -4807,7 +4708,7 @@ void G4OpenGLQtViewer::SwitchToVisSubThread()
{
// Called by VisSub Thread !
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return;
}
@@ -4833,7 +4734,7 @@ void G4OpenGLQtViewer::SwitchToVisSubThread()
void G4OpenGLQtViewer::DoneWithVisSubThread()
{
// Called by vis sub thread
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return;
}
@@ -4841,17 +4742,15 @@ void G4OpenGLQtViewer::DoneWithVisSubThread()
// finish with this vis sub thread context
qGLW->doneCurrent();
#if QT_VERSION > 0x050000
// and move it back to the main thread
qGLW->context()->moveToThread(fQGLContextMainThread);
#endif
}
void G4OpenGLQtViewer::SwitchToMasterThread()
{
// Called by VisSub Thread !
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return;
}
@@ -4868,7 +4767,7 @@ void G4OpenGLQtViewer::SwitchToMasterThread()
void G4OpenGLQtViewer::MovingToVisSubThread(){
// Called by Main Thread !
QGLWidget* qGLW = dynamic_cast<QGLWidget*> (fGLWidget) ;
auto qGLW = dynamic_cast<G4QGLWidgetType*> (fGLWidget) ;
if (! qGLW) {
return;
}
@@ -4887,9 +4786,7 @@ void G4OpenGLQtViewer::MovingToVisSubThread(){
// finish with this main thread context
qGLW->doneCurrent();
#if QT_VERSION > 0x050000
qGLW->context()->moveToThread(fQGLContextVisSubThread);
#endif
G4CONDITIONBROADCAST(&c2_VisSubThreadQtOpenGLContextMoved);
}
@@ -84,9 +84,6 @@ G4OpenGLSceneHandler::G4OpenGLSceneHandler (G4VGraphicsSystem& system,
G4int id,
const G4String& name):
G4VSceneHandler (system, id, name),
#ifdef G4OPENGL_VERSION_2
fEmulate_GL_QUADS(false),
#endif
fPickName(0),
fThreePassCapable(false),
fSecondPassForTransparencyRequested(false),
@@ -349,9 +346,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
// Note: colour and depth test treated in sub-class.
#ifndef G4OPENGL_VERSION_2
glDisable (GL_LIGHTING);
#endif
G4double lineWidth = GetLineWidth(fpVisAttribs);
// Need access to method in G4OpenGLViewer. static_cast doesn't
@@ -362,7 +357,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
if (pGLViewer) pGLViewer->ChangeLineWidth(lineWidth);
fEdgeFlag = true;
#ifndef G4OPENGL_VERSION_2
glBegin (GL_LINE_STRIP);
// No ned glEdgeFlag for lines :
// Boundary and nonboundary edge flags on vertices are significant only if GL_POLYGON_MODE is set to GL_POINT or GL_LINE. See glPolygonMode.
@@ -376,21 +370,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyline& line)
glVertex3d (x, y, z);
}
glEnd ();
#else
glBeginVBO(GL_LINE_STRIP);
for (std::size_t iPoint = 0; iPoint < nPoints; ++iPoint) {
fOglVertex.push_back(line[iPoint].x());
fOglVertex.push_back(line[iPoint].y());
fOglVertex.push_back(line[iPoint].z());
// normal
fOglVertex.push_back(0);
fOglVertex.push_back(0);
fOglVertex.push_back(1);
}
glEndVBO();
#endif
}
void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
@@ -401,9 +380,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
// Note: colour and depth test treated in sub-class.
#ifndef G4OPENGL_VERSION_2
glDisable (GL_LIGHTING);
#endif
MarkerSizeType sizeType;
G4double size = GetMarkerSize(polymarker, sizeType);
@@ -477,7 +454,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
G4int i;
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
fEdgeFlag = true;
#ifndef G4OPENGL_VERSION_2
glBegin (GL_POLYGON);
for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
G4Vector3D r = start; r.rotate(phi, viewpointDirection);
@@ -485,22 +461,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
glVertex3d (p.x(), p.y(), p.z());
}
glEnd ();
#else
glBeginVBO (GL_TRIANGLE_STRIP);
for (i = 0, phi = startPhi; i < nSides; i++, phi += dPhi) {
G4Vector3D r = start; r.rotate(phi, viewpointDirection);
G4Vector3D p = polymarker[iPoint] + r;
fOglVertex.push_back(p.x());
fOglVertex.push_back(p.y());
fOglVertex.push_back(p.z());
// normal
fOglVertex.push_back(0);
fOglVertex.push_back(0);
fOglVertex.push_back(1);
}
glEndVBO ();
#endif
}
} else { // Size specified in screen (window) coordinates.
@@ -508,7 +468,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
pGLViewer->ChangePointSize(size);
//Antialiasing only for circles
#ifndef G4OPENGL_VERSION_2
switch (polymarker.GetMarkerType()) {
default:
case G4Polymarker::dots:
@@ -517,36 +476,17 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
case G4Polymarker::squares:
glDisable (GL_POINT_SMOOTH); break;
}
#endif
#ifndef G4OPENGL_VERSION_2
glBegin (GL_POINTS);
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
G4Point3D centre = polymarker[iPoint];
glVertex3d(centre.x(),centre.y(),centre.z());
}
glEnd();
#else
glBeginVBO(GL_POINTS);
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
fOglVertex.push_back(polymarker[iPoint].x());
fOglVertex.push_back(polymarker[iPoint].y());
fOglVertex.push_back(polymarker[iPoint].z());
fOglVertex.push_back(0);
fOglVertex.push_back(0);
fOglVertex.push_back(1);
}
glEndVBO();
#endif
}
}
void G4OpenGLSceneHandler::AddPrimitive (const G4Text& text) {
// Pass to specific viewer via virtual function DrawText.
// FIXME : Not ready for OPENGL2 for the moment
#ifdef G4OPENGL_VERSION_2
return;
#endif
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
if (pGLViewer) pGLViewer->DrawText(text);
}
@@ -614,9 +554,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
G4bool clipping = pGLViewer->fVP.IsSection() || pGLViewer->fVP.IsCutaway();
// Lighting disabled unless otherwise requested
#ifndef G4OPENGL_VERSION_2
glDisable (GL_LIGHTING);
#endif
switch (drawing_style) {
case (G4ViewParameters::hlhsr):
@@ -658,9 +596,7 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
// Transparent...
glDepthMask (GL_FALSE); // Make depth buffer read-only.
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
#ifndef G4OPENGL_VERSION_2
glEnable(GL_COLOR_MATERIAL);
#endif
//glDisable (GL_CULL_FACE);
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
} else {
@@ -673,17 +609,13 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
} else {
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
#ifndef G4OPENGL_VERSION_2
glEnable(GL_COLOR_MATERIAL);
#endif
//glEnable (GL_CULL_FACE);
//glCullFace (GL_BACK);
glPolygonMode (GL_FRONT, GL_FILL);
}
}
#ifndef G4OPENGL_VERSION_2
if (!fProcessing2D) glEnable (GL_LIGHTING);
#endif
break;
case (G4ViewParameters::wireframe):
default:
@@ -696,13 +628,8 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
//Loop through all the facets...
fEdgeFlag = true;
#ifndef G4OPENGL_VERSION_2
glBegin (GL_QUADS);
glEdgeFlag (GL_TRUE);
#else
fEmulate_GL_QUADS = true;
glBeginVBO(GL_TRIANGLE_STRIP);
#endif
G4bool notLastFace;
do {
@@ -719,7 +646,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
if (isAuxEdgeVisible) {
edgeFlag[edgeCount] = 1;
}
#ifndef G4OPENGL_VERSION_2
if (edgeFlag[edgeCount] > 0) {
if (fEdgeFlag != true) {
glEdgeFlag (GL_TRUE);
@@ -737,18 +663,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
#else
fOglVertex.push_back(vertex[edgeCount].x());
fOglVertex.push_back(vertex[edgeCount].y());
fOglVertex.push_back(vertex[edgeCount].z());
fOglVertex.push_back(normals[edgeCount].x());
fOglVertex.push_back(normals[edgeCount].y());
fOglVertex.push_back(normals[edgeCount].z());
#endif
}
// HepPolyhedron produces triangles too; in that case add an extra
@@ -757,7 +671,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
G4int edgeCount = 3;
normals[edgeCount] = normals[0];
vertex[edgeCount] = vertex[0];
#ifndef G4OPENGL_VERSION_2
edgeFlag[edgeCount] = -1;
if (fEdgeFlag != false) {
glEdgeFlag (GL_FALSE);
@@ -770,16 +683,6 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
#else
fOglVertex.push_back(vertex[edgeCount].x());
fOglVertex.push_back(vertex[edgeCount].y());
fOglVertex.push_back(vertex[edgeCount].z());
fOglVertex.push_back(normals[edgeCount].x());
fOglVertex.push_back(normals[edgeCount].y());
fOglVertex.push_back(normals[edgeCount].z());
#endif
}
// Trap situation where number of edges is > 4...
if (nEdges > 4) {
@@ -793,15 +696,9 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
if (drawing_style == G4ViewParameters::hlr ||
drawing_style == G4ViewParameters::hlhsr) {
#ifndef G4OPENGL_VERSION_2
glDisable(GL_COLOR_MATERIAL); // Revert to glMaterial for hlr/sr.
#endif
#ifndef G4OPENGL_VERSION_2
glEnd (); // Placed here to balance glBegin above, allowing GL
#else
glEndVBO();
#endif
// state changes below, then glBegin again. Avoids
// having glBegin/End pairs *inside* loop in the more
// usual case of no hidden line removal.
@@ -848,17 +745,11 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE, painting_colour);
}
glColor4fv (painting_colour);
#ifndef G4OPENGL_VERSION_2
glBegin (GL_QUADS);
glEdgeFlag (GL_TRUE);
fEdgeFlag = true;
#else
fEmulate_GL_QUADS = true;
glBeginVBO(GL_TRIANGLE_STRIP);
#endif
for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
#ifndef G4OPENGL_VERSION_2
if (edgeFlag[edgeCount] > 0) {
if (fEdgeFlag != true) {
glEdgeFlag (GL_TRUE);
@@ -876,22 +767,8 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
#else
fOglVertex.push_back(vertex[edgeCount].x());
fOglVertex.push_back(vertex[edgeCount].y());
fOglVertex.push_back(vertex[edgeCount].z());
fOglVertex.push_back(normals[edgeCount].x());
fOglVertex.push_back(normals[edgeCount].y());
fOglVertex.push_back(normals[edgeCount].z());
#endif
}
#ifndef G4OPENGL_VERSION_2
glEnd ();
#else
glEndVBO();
#endif
end_of_drawing_through_stencil:
// and once more to reset the stencil bits...
@@ -916,16 +793,10 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glDisable (GL_LIGHTING);
glColor4fv (current_colour);
fEdgeFlag = true;
#ifndef G4OPENGL_VERSION_2
glBegin (GL_QUADS);
glEdgeFlag (GL_TRUE);
fEdgeFlag = true;
#else
fEmulate_GL_QUADS = true;
glBeginVBO(GL_TRIANGLE_STRIP);
#endif
for (int edgeCount = 0; edgeCount < 4; ++edgeCount) {
#ifndef G4OPENGL_VERSION_2
if (edgeFlag[edgeCount] > 0) {
if (fEdgeFlag != true) {
glEdgeFlag (GL_TRUE);
@@ -943,64 +814,24 @@ void G4OpenGLSceneHandler::AddPrimitive (const G4Polyhedron& polyhedron) {
glVertex3d (vertex[edgeCount].x(),
vertex[edgeCount].y(),
vertex[edgeCount].z());
#else
fOglVertex.push_back(vertex[edgeCount].x());
fOglVertex.push_back(vertex[edgeCount].y());
fOglVertex.push_back(vertex[edgeCount].z());
fOglVertex.push_back(normals[edgeCount].x());
fOglVertex.push_back(normals[edgeCount].y());
fOglVertex.push_back(normals[edgeCount].z());
#endif
}
#ifndef G4OPENGL_VERSION_2
glEnd ();
#else
glEndVBO();
#endif
glDepthFunc (GL_LEQUAL); // Revert for next facet.
fEdgeFlag = true;
#ifndef G4OPENGL_VERSION_2
glBegin (GL_QUADS); // Ready for next facet. GL
glEdgeFlag (GL_TRUE);
fEdgeFlag = true;
// says it ignores incomplete
// quadrilaterals, so final empty
// glBegin/End sequence should be OK.
#else
fEmulate_GL_QUADS = true;
glBeginVBO(GL_TRIANGLE_STRIP);
#endif
}
} while (notLastFace);
#ifndef G4OPENGL_VERSION_2
glEnd ();
#else
// FIXME: du grand n'importe quoi en test
// Cube optimization
// store old DrawType because in case of optimization it could be changed
GLenum oldDrawArrayType = fDrawArrayType;
if (dynamic_cast<const G4PolyhedronTrd2*>(&polyhedron)) {
// OptimizeVBOForTrd();
} else if (dynamic_cast<const G4PolyhedronCons*>(&polyhedron)) {
// OptimizeVBOForCons((polyhedron.GetNoVertices()-2)/2 ); // top + bottom + all faces
}
glEndVBO();
fDrawArrayType = oldDrawArrayType;
#endif
glDisable (GL_STENCIL_TEST); // Revert to default for next primitive.
glDepthMask (GL_TRUE); // Revert to default for next primitive.
#ifndef G4OPENGL_VERSION_2
glDisable (GL_LIGHTING); // Revert to default for next primitive.
#endif
}
void G4OpenGLSceneHandler::AddCompound(const G4VTrajectory& traj) {
@@ -1026,278 +857,3 @@ void G4OpenGLSceneHandler::AddCompound(const G4THitsMap<G4StatDouble>& hits) {
void G4OpenGLSceneHandler::AddCompound(const G4Mesh& mesh) {
StandardSpecialMeshRendering(mesh);
}
#ifdef G4OPENGL_VERSION_2
// Optimize vertex and indices in order to render less vertex in OpenGL VBO/IBO
void G4OpenGLSceneHandler::OptimizeVBOForTrd(){
/* HOW IT IS BUILD (as we receive it from fOglVertex :
*/
std::vector<double> vertices;
vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+6*6); // ABCDEF
vertices.insert (vertices.end(),fOglVertex.begin()+9*6,fOglVertex.begin()+9*6+6); // G
vertices.insert (vertices.end(),fOglVertex.begin()+13*6,fOglVertex.begin()+13*6+6); // H
fOglVertex = vertices;
int myarray [] = {
3,2,0,1,4,5,7,6, 6,0,4,3,7,2,6,1,5
};
fOglIndices.insert(fOglIndices.begin(), myarray, myarray+17/*36*/);
fDrawArrayType = GL_TRIANGLE_STRIP;
}
// Optimize vertex and indices in order to render less vertex in OpenGL VBO/IBO
void G4OpenGLSceneHandler::OptimizeVBOForCons(G4int aNoFaces){
// Optimized, 1st level : 10f/15sec with 1000 cones
// DrawElements:208 vertex and 605 (2*100+2*100+2*100+5) indices for a 100 face cone
/* surface of polycone : could be optimized
for 100 faces :
- 100*4 = 400 points
- 100*2+2 = 202 points with TRIANGLE_STRIP
Total :
n*4+n*4+n*4 = n*12
optimize : n*2+2+1+n+1 = n*3+3 (factor 4)
but could do better : n faces should give = n*2+2
*/
/*
0
/ \
2---4 6 ....2
| |
3---5 7 ....3
\ /
1
*/
// First, faces
std::vector<double> vertices;
// Add bottom and top vertex
// aNoFaces*4*6+6 : nb Faces * 4 points per face * 6 vertex by point + 1 point offset
vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*4)*6,fOglVertex.begin()+(aNoFaces*4)*6+6); // 0
vertices.insert (vertices.end(),fOglVertex.begin()+ (aNoFaces*8+1)*6,fOglVertex.begin()+(aNoFaces*8+1)*6+6); // 1
// Add facets points
G4int posInVertice;
for (G4int a = 0; a<aNoFaces; a++) {
posInVertice = a*4*6;
vertices.insert (vertices.end(),fOglVertex.begin()+posInVertice,fOglVertex.begin()+posInVertice+1*6+6); // AB
}
vertices.insert (vertices.end(),fOglVertex.begin(),fOglVertex.begin()+1*6*6); // AB
fOglVertex = vertices;
// Add indices for top :
// simple version : 0-2-0-4-0-6-0-8-0-10..
// optimized version : 2-0-4-6- 6-0-8-10.. but we have to deal with odd faces numbers
for (G4int a=0; a<aNoFaces; a++) {
fOglIndices.push_back(0);
fOglIndices.push_back(a*2+2);
}
// close strip
fOglIndices.push_back(0);
fOglIndices.push_back(2);
// Add indices for faces
for (G4int a = 0; a<aNoFaces; a++) {
fOglIndices.push_back(a*2+2);
fOglIndices.push_back(a*2+1+2);
}
fOglIndices.push_back(2);
fOglIndices.push_back(2+1);
// Second : top
// 3-1-5-1-7-1-9-1..
for (G4int a=0; a<aNoFaces; a++) {
fOglIndices.push_back(a*2+3);
fOglIndices.push_back(1);
}
// close strip
fOglIndices.push_back(0+3);
fDrawArrayType = GL_TRIANGLE_STRIP;
fEmulate_GL_QUADS = false;
}
void G4OpenGLSceneHandler::glBeginVBO(GLenum type) {
fDrawArrayType = type;
glGenBuffers(1,&fVertexBufferObject);
glGenBuffers(1,&fIndicesBufferObject);
// clear data and indices for OpenGL
fOglVertex.clear();
fOglIndices.clear();
}
// 2 cases :
/*
glDrawArray : if there is no vertex indices : fOglIndices.size() == 0
glDrawElements : if there is vertex indices : fOglIndices.size() != 0
*/
void G4OpenGLSceneHandler::glEndVBO() {
if (fOglIndices.size() == 0) {
std::vector<double> vertices;
// check if it is a GL_QUADS emulation
if (fEmulate_GL_QUADS == true) {
fEmulate_GL_QUADS = false;
// A point has 6 double : Vx Vy Vz Nx Ny Nz
// A QUAD should be like this
/*
0 3/4 7/8 ..
1 2/5 6/9 ..
*/
// And if 3==4 and 2==5, we should do it like this for a TRIANGLES_STRIP
/*
0 4 8 ..
| / | / |
1 5 9 ..
// Optimized, 1st level : 24f/15sec with 10 cones
// non Optimized, 1st level : 12f/15sec with 10 cones
*/
// should be 4 points
for (unsigned int a=0; a<fOglVertex.size(); a+=6*4) {
vertices.insert (vertices.end(),fOglVertex.begin()+a,fOglVertex.begin()+a+1*6+6); // 0-1
// if 2-3 == 4-5, do not add them
// if differents, we are obliged to create a new GL_TRIANGLE_STRIP
if (a+4*6+5 < fOglVertex.size()) {
if ((fOglVertex[a+2*6+0] != fOglVertex[a+5*6+0]) || //Vx for 2 and 5
(fOglVertex[a+2*6+1] != fOglVertex[a+5*6+1]) || //Vy for 2 and 5
(fOglVertex[a+2*6+2] != fOglVertex[a+5*6+2]) || //Vz for 2 and 5
(fOglVertex[a+2*6+3] != fOglVertex[a+5*6+3]) || //Px for 2 and 5
(fOglVertex[a+2*6+4] != fOglVertex[a+5*6+4]) || //Py for 2 and 5
(fOglVertex[a+2*6+5] != fOglVertex[a+5*6+5]) || //Pz for 2 and 5
(fOglVertex[a+3*6+0] != fOglVertex[a+4*6+0]) || //Vx for 3 and 4
(fOglVertex[a+3*6+1] != fOglVertex[a+4*6+1]) || //Vy for 3 and 4
(fOglVertex[a+3*6+2] != fOglVertex[a+4*6+2]) || //Vz for 3 and 4
(fOglVertex[a+3*6+3] != fOglVertex[a+4*6+3]) || //Px for 3 and 4
(fOglVertex[a+3*6+4] != fOglVertex[a+4*6+4]) || //Py for 3 and 4
(fOglVertex[a+3*6+5] != fOglVertex[a+4*6+5])) { //Pz for 3 and 4
// add last points
vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6); // 3
vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6); // 2
// build and send the GL_TRIANGLE_STRIP
drawVBOArray(vertices);
vertices.clear();
}
} else { // end of volume
vertices.insert (vertices.end(),fOglVertex.begin()+a+3*6,fOglVertex.begin()+a+3*6+6); // 3
vertices.insert (vertices.end(),fOglVertex.begin()+a+2*6,fOglVertex.begin()+a+2*6+6); // 2
}
}
fOglVertex = vertices;
}
drawVBOArray(fOglVertex);
} else {
// Bind VBO
glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
// Load fOglVertex into VBO
int sizeV = fOglVertex.size();
// FIXME : perhaps a problem withBufferData in OpenGL other than WebGL ?
// void glBufferData( GLenum target, GLsizeiptr size, const GLvoid * data, GLenum usage);
glBufferData(GL_ARRAY_BUFFER, sizeof(double)*sizeV, &fOglVertex[0], GL_STATIC_DRAW);
// Bind IBO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
// Load fOglVertex into VBO
int sizeI = fOglIndices.size();
glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(int)*sizeI, &fOglIndices[0], GL_STATIC_DRAW);
//----------------------------
// Draw VBO
//----------------------------
glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
// the fVertexPositionAttribute is inside the G4OpenGLViewer
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
if (pGLViewer) {
glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
3, // size: Every vertex has an X, Y anc Z component
GL_FLOAT, // type: They are floats
GL_FALSE, // normalized: Please, do NOT normalize the vertices
2*3*4, // stride: The first byte of the next vertex is located this
// amount of bytes further. The format of the VBO is
// vx, vy, vz, nx, ny, nz and every element is a
// Float32, hence 4 bytes large
0); // offset: The byte position of the first vertex in the buffer
}
glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, fIndicesBufferObject);
// glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
glDrawElements(fDrawArrayType, fOglIndices.size(), GL_UNSIGNED_SHORT, 0);
if (pGLViewer) {
glDisableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
}
// delete the buffer
glDeleteBuffers(1,&fVertexBufferObject);
}
}
void G4OpenGLSceneHandler::drawVBOArray(std::vector<double> vertices) {
glGenBuffers(1,&fVertexBufferObject);
glGenBuffers(1,&fIndicesBufferObject);
// Bind this buffer
glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
// Load oglData into VBO
int s = vertices.size();
glBufferData(GL_ARRAY_BUFFER, sizeof(double)*s, &vertices[0], GL_STATIC_DRAW);
//----------------------------
// Draw VBO
//----------------------------
glBindBuffer(GL_ARRAY_BUFFER, fVertexBufferObject);
// the fVertexPositionAttribute is inside the G4OpenGLViewer
G4OpenGLViewer* pGLViewer = dynamic_cast<G4OpenGLViewer*>(fpViewer);
if (pGLViewer) {
glEnableVertexAttribArray(pGLViewer->fVertexPositionAttribute);
// glVertexAttribPointer(GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, const GLvoid *pointer)
/*
GL_DOUBLE
Warning: This section describes legacy OpenGL APIs that have been removed from core OpenGL 3.1 and above (they are only deprecated in OpenGL 3.0). It is recommended that you not use this functionality in your programs.
glLoadMatrixd, glRotated and any other function that have to do with the double type. Most GPUs don't support GL_DOUBLE (double) so the driver will convert the data to GL_FLOAT (float) and send to the GPU. If you put GL_DOUBLE data in a VBO, the performance might even be much worst than immediate mode (immediate mode means glBegin, glVertex, glEnd). GL doesn't offer any better way to know what the GPU prefers.
*/
glVertexAttribPointer(pGLViewer->fVertexPositionAttribute,
3, // size: Every vertex has an X, Y anc Z component
GL_DOUBLE, // type: They are double
GL_FALSE, // normalized: Please, do NOT normalize the vertices
6*sizeof(double), // stride: The first byte of the next vertex is located this
// amount of bytes further. The format of the VBO is
// vx, vy, vz, nx, ny, nz and every element is a
// Float32, hence 4 bytes large
0); // offset: The byte position of the first vertex in the buffer
}
glDrawArrays(fDrawArrayType, // GL_POINTS, GL_LINE_STRIP, GL_LINE_LOOP, GL_LINES, GL_TRIANGLE_FAN, GL_TRIANGLE_STRIP, and GL_TRIANGLES
0, vertices.size()/6);
if (pGLViewer) {
glDisableClientState( GL_VERTEX_ARRAY );
}
// delete the buffer
glDeleteBuffers(1,&fVertexBufferObject);
}
#endif
@@ -36,6 +36,7 @@
#ifdef G4MULTITHREADED
#include "G4Threading.hh"
#endif
#include "G4UIQt.hh"
#include <qapplication.h>
#include <qtabwidget.h>
@@ -47,14 +48,14 @@ G4OpenGLStoredQtViewer::G4OpenGLStoredQtViewer
G4OpenGLViewer (sceneHandler),
G4OpenGLQtViewer (sceneHandler),
G4OpenGLStoredViewer (sceneHandler), // FIXME : gerer le pb du parent !
QGLWidget()
G4QGLWidgetType()
{
if (fViewId < 0) return; // In case error in base class instantiation.
fQGLWidgetInitialiseCompleted = false;
// Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike WA_OpaquePaintEvent, newly exposed areas are never filled with the background (e.g., after showing a window for the first time the user can see "through" it until the application processes the paint events). This flag is set or cleared by the widget's author.
QGLWidget::setAttribute (Qt::WA_NoSystemBackground);
G4QGLWidgetType::setAttribute (Qt::WA_NoSystemBackground);
setFocusPolicy(Qt::StrongFocus); // enable keybord events
fHasToRepaint = false;
@@ -78,8 +79,8 @@ void G4OpenGLStoredQtViewer::Initialise() {
glDrawBuffer (GL_BACK);
// set the good tab active
if (QGLWidget::parentWidget()) {
QTabWidget *parentTab = dynamic_cast<QTabWidget*> (QGLWidget::parentWidget()->parent()) ;
if (G4QGLWidgetType::parentWidget()) {
auto *parentTab = dynamic_cast<QTabWidget*> (G4QGLWidgetType::parentWidget()->parent()) ;
if (parentTab) {
parentTab->setCurrentIndex(parentTab->count()-1);
}
@@ -353,7 +354,12 @@ void G4OpenGLStoredQtViewer::paintEvent(QPaintEvent *) {
// The widget's rendering context will become the current context and initializeGL()
// will be called if it hasn't already been called.
// Copies the back buffer of a double-buffered context to the front buffer.
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
updateGL();
#else
// Not sure this is correct....
paintGL();
#endif
}
}
@@ -1,254 +0,0 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
//
//
//
// Class to provide Vertex Buffer Object (VBO) specific
// functionality for OpenGL > 2.0 in GEANT4
#include "G4OpenGLViewer.hh"
#ifdef G4OPENGL_VERSION_2
#include "G4OpenGLVboDrawer.hh"
#include "G4OpenGLImmediateQtViewer.hh"
//////////////////////////////////////////////////////////////////////////////
G4OpenGLVboDrawer::G4OpenGLVboDrawer (G4OpenGLViewer* viewer,
std::string type
):
fVboViewer(NULL),
fOGLType(type)
//////////////////////////////////////////////////////////////////////////////
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
{
G4OpenGLImmediateQtViewer* v = dynamic_cast<G4OpenGLImmediateQtViewer*>(viewer);
if (v) {
fVboViewer = v;
}
fFragmentShaderSrc =
"#ifdef GL_ES\n"
"precision highp float;\n"
"#endif\n"
"\n"
"varying vec3 vLightWeighting;\n"
"uniform vec4 uPointColor; // Point Color\n"
"\n"
"void main(void) {\n"
" vec4 matColor = uPointColor;\n"
" gl_FragColor = vec4(matColor.rgb, matColor.a);\n"
"}\n";
fVertexShaderSrc =
"attribute highp vec4 aVertexPosition;\n"
"attribute vec3 aVertexNormal;\n"
"uniform highp mat4 uCMatrix;\n"
"uniform highp mat4 uPMatrix; // Perspective [P]rojection matrix\n"
"uniform highp mat4 uMVMatrix; // [M]odel[V]iew matrix\n"
"uniform highp mat4 uTMatrix; // [T]ransformation matrix\n"
"uniform float uPointSize; // Point size\n"
"void main(void)\n"
"{\n"
" gl_Position = uPMatrix * uCMatrix * uMVMatrix * uTMatrix * aVertexPosition;\n"
" // Phong shading\n"
// " vec3 transformedNormal = normalize((uNMatrix * vec4(normalize(aVertexNormal), 0)).xyz);\n"
" vec3 lightingDirection = normalize(vec3(1, 1, 1));\n"
// " float directionalLightWeighting = max(dot(transformedNormal, lightingDirection), 0.0);\n"
// " vec3 uAmbientLightColor = vec3(0.2, 0.2, 0.2);\n"
// " vec3 uDirectionalColor = vec3(0.8, 0.8, 0.8);\n"
" gl_PointSize = uPointSize;\n"
// " vLightWeighting = uAmbientLightColor + uDirectionalColor * directionalLightWeighting;\n"
"}";
}
//////////////////////////////////////////////////////////////////////////////
G4OpenGLVboDrawer::~G4OpenGLVboDrawer (
)
//////////////////////////////////////////////////////////////////////////////
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
{
}
// +--------------------------------+
// + QT (OpenGL ES) case +
// +--------------------------------+
void G4OpenGLVboDrawer:: vboGlMultMatrixf(const GLfloat *matrix){
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
// FIXME
// glUniformMatrix4fv(12, 1, 0, 0x7fff5fbf5d00)
// Error: GL_INVALID_OPERATION
if (fMatrixMode == GL_MODELVIEW) {
glUniformMatrix4fv(fVboViewer->getShaderTransformMatrix(),1,0,matrix);
} else {
G4cerr << "glMultMatrixf could only be used in GL_MODELVIEW mode" << G4endl;
}
}
}
}
void G4OpenGLVboDrawer:: vboGlMultMatrixd(const GLdouble *matrix){
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
// FIXME !
// if (fMatrixMode == GL_MODELVIEW) {
// printf("G4OpenGLVboDrawer:: vboGlMultMatrixd %d %d\n",fVboViewer->getShaderTransformMatrix(), matrix);
//!! TEST !!
float mat[16] = {
matrix[0],matrix[1],matrix[2],matrix[3],
matrix[4],matrix[5],matrix[6],matrix[7],
matrix[8],matrix[9],matrix[10],matrix[11],
matrix[12],matrix[13],matrix[14],matrix[15]
};
glUniformMatrix4fv(fVboViewer->getShaderTransformMatrix(),1,0,mat);
GLenum e = glGetError();
printf("GL error : %d",e);
// } else {
// G4cerr << "glMultMatrixd could only be used in GL_MODELVIEW mode" << G4endl;
// }
}
}
}
// +--------------------------------+
// + All case +
// +--------------------------------+
void G4OpenGLVboDrawer::vboGlOrtho(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) {
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
printf("glOrtho implemented --- %f %f %f %f %f %f \n",left, right, bottom, top, zNear, zFar);
float a = 2.0f / (right - left);
float b = 2.0f / (top - bottom);
float c = -2.0f / (zFar - zNear);
float tx = - (right + left)/(right - left);
float ty = - (top + bottom)/(top - bottom);
float tz = - (zFar + zNear)/(zFar - zNear);
float ortho[16] = {
a, 0, 0, 0,
0, b, 0, 0,
0, 0, c, 0,
tx, ty, tz, 1
};
// FIXME :
// glUniformMatrix4fv(0, 1, 0, 0x7fff5fbf5d00)
// Error: GL_INVALID_OPERATION
if (fMatrixMode == GL_PROJECTION) {
glUniformMatrix4fv(fVboViewer->getShaderProjectionMatrix(), 1, 0, ortho);
} else {
G4cerr << "glFrustum could only be used in GL_PROJECTION mode" << G4endl;
}
}
}
}
void G4OpenGLVboDrawer::vboGlFrustum(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) {
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
float deltaX = right - left;
float deltaY = top - bottom;
float deltaZ = zFar - zNear;
float a = 2.0f * zNear / deltaX;
float b = 2.0f * zNear / deltaY;
float c = (right + left) / deltaX;
float d = (top + bottom) / deltaY;
float e = -(zFar + zNear) / (zFar - zNear);
float f = -2.0f * zFar * zNear / deltaZ;
float proj[16] = {
a, 0, 0, 0,
0, b, 0, 0,
c, d, e, -1.0f,
0, 0, f, 0
};
if (fMatrixMode == GL_PROJECTION) {
glUniformMatrix4fv(fVboViewer->getShaderProjectionMatrix(), 1, 0, proj);
} else {
G4cerr << "glFrustrum could only be used in GL_PROJECTION mode" << G4endl;
}
}
}
}
void G4OpenGLVboDrawer::vboGlMatrixMode(GLenum a) {
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
printf("G4OpenGLVboDrawer::vboGlMatrixMode CHANGED :%d \n",a);
fMatrixMode = a;
}
}
}
void G4OpenGLVboDrawer::vboGlColor4d(int red,int green,int blue,int alpha) {
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
// double color [] = { red, green, blue, alpha };
// FIXME : REMOVE /2 , used to render transparents for testing purpose
alpha = 0.7;
glUniform4f (glGetUniformLocation(fVboViewer->getShaderProgram(), "uPointColor"),red, green, blue, alpha);
}
}
}
void G4OpenGLVboDrawer:: vboGlColor4fv(const GLfloat* data) {
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
double color [] = { (data[0]), (data[1]), (data[2]), 0.7};
// FIXME : REMOVE /2 , used to render transparents for testing purpose
glUniform4f (glGetUniformLocation(fVboViewer->getShaderProgram(), "uPointColor"),color[0],color[1],color[2], color[3]);
}
}
}
void G4OpenGLVboDrawer:: vboGlPointSize(float size) {
if (fVboViewer) {
if (fVboViewer->isInitialized()) {
glUniform1f (glGetUniformLocation(fVboViewer->getShaderProgram(), "uPointSize"),size);
}
}
}
#endif
@@ -51,22 +51,12 @@
#include "G4AttCheck.hh"
#include "G4Text.hh"
#ifdef G4OPENGL_VERSION_2
#include "G4OpenGLVboDrawer.hh"
#endif
// GL2PS
//#include "Geant4_gl2ps.h"
#include <sstream>
#include <string>
#include <iomanip>
G4OpenGLViewer::G4OpenGLViewer (G4OpenGLSceneHandler& scene):
G4VViewer (scene, -1),
#ifdef G4OPENGL_VERSION_2
fVboDrawer(NULL),
#endif
fPrintColour (true),
fVectoredPs (true),
fOpenGLSceneHandler(scene),
@@ -90,15 +80,6 @@ fGl2psDefaultLineWith(1),
fGl2psDefaultPointSize(2),
fGlViewInitialized(false),
fIsGettingPickInfos(false)
#ifdef G4OPENGL_VERSION_2
,fShaderProgram(0)
,fVertexPositionAttribute(0)
,fVertexNormalAttribute(0)
,fpMatrixUniform(0)
,fcMatrixUniform(0)
,fmvMatrixUniform(0)
,fnMatrixUniform(0)
#endif
{
// Make changes to view parameters for OpenGL...
fVP.SetAutoRefresh(true);
@@ -142,54 +123,6 @@ G4OpenGLViewer::~G4OpenGLViewer ()
void G4OpenGLViewer::InitializeGLView ()
{
#ifdef G4OPENGL_VERSION_2
if (fVboDrawer) {
// First, load a simple shader
fShaderProgram = glCreateProgram();
Shader vertexShader = glCreateShader(GL_VERTEX_SHADER);
const char * vSrc = fVboDrawer->getVertexShaderSrc();
glShaderSource(vertexShader, 1, &vSrc, NULL);
glCompileShader(vertexShader);
glAttachShader(fShaderProgram, vertexShader);
Shader fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);
const char * fSrc = fVboDrawer->getFragmentShaderSrc();
glShaderSource(fragmentShader, 1, &fSrc, NULL);
glCompileShader(fragmentShader);
glAttachShader(fShaderProgram, fragmentShader);
glLinkProgram(fShaderProgram);
glUseProgram(fShaderProgram);
// UniformLocation uColor = getUniformLocation(fShaderProgram, "uColor");
// uniform4fv(uColor, [0.0, 0.3, 0.0, 1.0]);
// Extract the references to the attributes from the shader.
fVertexPositionAttribute =
glGetAttribLocation(fShaderProgram, "aVertexPosition");
glEnableVertexAttribArray(fVertexPositionAttribute);
// Extract the references the uniforms from the shader
fpMatrixUniform = glGetUniformLocation(fShaderProgram, "uPMatrix");
fcMatrixUniform = glGetUniformLocation(fShaderProgram, "uCMatrix");
fmvMatrixUniform = glGetUniformLocation(fShaderProgram, "uMVMatrix");
fnMatrixUniform = glGetUniformLocation(fShaderProgram, "uNMatrix");
ftMatrixUniform = glGetUniformLocation(fShaderProgram, "uTMatrix");
/* glUniformMatrix4fv(fcMatrixUniform, 1, 0, identity);
glUniformMatrix4fv(fpMatrixUniform, 1, 0, identity);
glUniformMatrix4fv(ftMatrixUniform, 1, 0, identity);
glUniformMatrix4fv(fmvMatrixUniform, 1, 0, identity);
*/
// We have to set that in order to avoid calls on opengl commands before all is ready
fGlViewInitialized = true;
}
#endif
if (fWinSize_x == 0) {
fWinSize_x = fVP.GetWindowSizeHintX();
}
@@ -199,10 +132,8 @@ void G4OpenGLViewer::InitializeGLView ()
glClearColor (0.0, 0.0, 0.0, 0.0);
glClearDepth (1.0);
#ifndef G4OPENGL_VERSION_2
glDisable (GL_LINE_SMOOTH);
glDisable (GL_POLYGON_SMOOTH);
#endif
// clear the buffers and window?
ClearView ();
@@ -1513,21 +1444,6 @@ void G4OpenGLViewer::g4GlFrustum (GLdouble left, GLdouble right, GLdouble bottom
}
#ifdef G4OPENGL_VERSION_2
// Associate the VBO drawer to the OpenGLViewer and the OpenGLSceneHandler
void G4OpenGLViewer::setVboDrawer(G4OpenGLVboDrawer* drawer) {
fVboDrawer = drawer;
try {
G4OpenGLSceneHandler& sh = dynamic_cast<G4OpenGLSceneHandler&>(fSceneHandler);
sh.setVboDrawer(fVboDrawer);
} catch(std::bad_cast exp) { }
}
#endif
G4String G4OpenGLViewerPickMap::print() {
std::ostringstream txt;
for (unsigned int a=0; a<fAttributes.size(); a++) {