32 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
38 #ifdef G4MULTITHREADED
41 #include <qapplication.h>
42 #include <qtabwidget.h>
44 #ifdef G4OPENGL_VERSION_2
45 #include <qglshaderprogram.h>
49 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
50 (G4OpenGLImmediateSceneHandler& sceneHandler,
52 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
53 G4OpenGLViewer (sceneHandler),
54 G4OpenGLQtViewer (sceneHandler),
55 G4OpenGLImmediateViewer (sceneHandler)
57 fQGLWidgetInitialiseCompleted =
false;
59 setFocusPolicy(Qt::StrongFocus);
60 fHasToRepaint =
false;
61 fPaintEventLock =
false;
65 #ifdef G4OPENGL_VERSION_2
66 setVboDrawer(
new G4OpenGLVboDrawer(
this,
"OGL-VBO"));
69 fUpdateGLLock =
false;
71 if (fViewId < 0)
return;
74 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
78 void G4OpenGLImmediateQtViewer::Initialise() {
81 fQGLWidgetInitialiseCompleted =
false;
82 CreateMainWindow (
this,QString(GetName()));
84 glDrawBuffer (GL_BACK);
87 if (QGLWidget::parentWidget()) {
88 QTabWidget *parentTab =
dynamic_cast<QTabWidget*
> (QGLWidget::parentWidget()->parent()) ;
90 parentTab->setCurrentIndex(parentTab->count()-1);
94 fQGLWidgetInitialiseCompleted =
true;
97 void G4OpenGLImmediateQtViewer::initializeGL () {
99 #ifndef G4OPENGL_VERSION_2
102 QGLShaderProgram *aQGLShaderProgram =
new QGLShaderProgram (
context());
103 fShaderProgram = aQGLShaderProgram->programId ();
105 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Vertex,
106 fVboDrawer->getVertexShaderSrc());
108 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Fragment,
109 fVboDrawer->getFragmentShaderSrc());
111 aQGLShaderProgram->link();
112 aQGLShaderProgram->bind();
114 fVertexPositionAttribute = glGetAttribLocation(fShaderProgram,
"aVertexPosition");
115 fcMatrixUniform = glGetUniformLocation(fShaderProgram,
"uCMatrix");
116 fpMatrixUniform = glGetUniformLocation(fShaderProgram,
"uPMatrix");
117 ftMatrixUniform = glGetUniformLocation(fShaderProgram,
"uTMatrix");
118 fmvMatrixUniform = glGetUniformLocation(fShaderProgram,
"uMVMatrix");
127 glUniformMatrix4fv (fcMatrixUniform, 1, 0, identity);
128 glUniformMatrix4fv (fpMatrixUniform, 1, 0, identity);
129 glUniformMatrix4fv (ftMatrixUniform, 1, 0, identity);
130 glUniformMatrix4fv(fmvMatrixUniform, 1, 0, identity);
132 glUseProgram(fShaderProgram);
142 if (fSceneHandler.GetScene() == 0) {
143 fHasToRepaint =
false;
155 void G4OpenGLImmediateQtViewer::DrawView() {
156 #ifdef G4MULTITHREADED
166 void G4OpenGLImmediateQtViewer::ComputeView () {
182 HaloingSecondPass ();
193 fHasToRepaint =
true;
199 void G4OpenGLImmediateQtViewer::resizeGL(
203 if ((aWidth > 0) && (aHeight > 0)) {
204 ResizeWindow(aWidth,aHeight);
205 fHasToRepaint = sizeHasChanged();
210 void G4OpenGLImmediateQtViewer::paintGL()
212 updateToolbarAndMouseContextMenu();
214 if (fPaintEventLock) {
217 if (!fQGLWidgetInitialiseCompleted) {
218 fPaintEventLock =
false;
221 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
226 if ( !fHasToRepaint) {
231 if (!isMaximized() && !isFullScreen()) {
232 sw = normalGeometry().width();
233 sh = normalGeometry().height();
235 sw = frameGeometry().width();
236 sh = frameGeometry().height();
238 if ((getWinWidth() == (
unsigned int)sw) &&(getWinHeight() == (
unsigned int)sh)) {
241 }
else if ((sw == 0) && (sh == 0)) {
242 if (((getWinWidth() == (
unsigned int)
width())) &&(getWinHeight() == (
unsigned int) height())) {
253 fHasToRepaint =
false;
255 fPaintEventLock =
false;
258 void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
260 G4MousePressEvent(event);
263 void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
265 G4keyPressEvent(event);
268 void G4OpenGLImmediateQtViewer::keyReleaseEvent (QKeyEvent * event)
270 G4keyReleaseEvent(event);
273 void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
278 void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *)
280 if (fQGLWidgetInitialiseCompleted) {
281 fHasToRepaint =
true;
290 void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
292 G4MouseDoubleClickEvent();
295 void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event)
297 G4MouseReleaseEvent(event);
300 void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
302 G4MouseMoveEvent(event);
306 void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *
e)
308 G4manageContextMenuEvent(e);
311 void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
312 if (! fQGLWidgetInitialiseCompleted) {
316 fHasToRepaint = isFramebufferReady();
317 if ( fHasToRepaint) {
323 void G4OpenGLImmediateQtViewer::updateQWidget() {
328 if (! isCurrentWidget()){
332 fUpdateGLLock =
true;
335 updateViewerPropertiesTableWidget();
336 updateSceneTreeWidget();
337 fUpdateGLLock=
false;
341 void G4OpenGLImmediateQtViewer::ShowView (
346 fHasToRepaint =
true;