33 #ifdef G4VIS_BUILD_OPENGLQT_DRIVER
39 #ifdef G4MULTITHREADED
42 #include <qapplication.h>
43 #include <qtabwidget.h>
45 #ifdef G4OPENGL_VERSION_2
46 #include <qglshaderprogram.h>
50 G4OpenGLImmediateQtViewer::G4OpenGLImmediateQtViewer
51 (G4OpenGLImmediateSceneHandler& sceneHandler,
53 G4VViewer (sceneHandler, sceneHandler.IncrementViewCount (), name),
54 G4OpenGLViewer (sceneHandler),
55 G4OpenGLQtViewer (sceneHandler),
56 G4OpenGLImmediateViewer (sceneHandler)
58 fQGLWidgetInitialiseCompleted =
false;
60 setFocusPolicy(Qt::StrongFocus);
61 fHasToRepaint =
false;
62 fPaintEventLock =
false;
66 #ifdef G4OPENGL_VERSION_2
67 setVboDrawer(
new G4OpenGLVboDrawer(
this,
"OGL-VBO"));
70 fUpdateGLLock =
false;
72 if (fViewId < 0)
return;
75 G4OpenGLImmediateQtViewer::~G4OpenGLImmediateQtViewer() {
79 void G4OpenGLImmediateQtViewer::Initialise() {
82 fQGLWidgetInitialiseCompleted =
false;
83 CreateMainWindow (
this,QString(GetName()));
85 glDrawBuffer (GL_BACK);
88 if (QGLWidget::parentWidget()) {
89 QTabWidget *parentTab =
dynamic_cast<QTabWidget*
> (QGLWidget::parentWidget()->parent()) ;
91 parentTab->setCurrentIndex(parentTab->count()-1);
95 fQGLWidgetInitialiseCompleted =
true;
98 void G4OpenGLImmediateQtViewer::initializeGL () {
100 #ifndef G4OPENGL_VERSION_2
103 QGLShaderProgram *aQGLShaderProgram =
new QGLShaderProgram (
context());
104 fShaderProgram = aQGLShaderProgram->programId ();
106 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Vertex,
107 fVboDrawer->getVertexShaderSrc());
109 aQGLShaderProgram->addShaderFromSourceCode(QGLShader::Fragment,
110 fVboDrawer->getFragmentShaderSrc());
112 aQGLShaderProgram->link();
113 aQGLShaderProgram->bind();
115 fVertexPositionAttribute = glGetAttribLocation(fShaderProgram,
"aVertexPosition");
116 fcMatrixUniform = glGetUniformLocation(fShaderProgram,
"uCMatrix");
117 fpMatrixUniform = glGetUniformLocation(fShaderProgram,
"uPMatrix");
118 ftMatrixUniform = glGetUniformLocation(fShaderProgram,
"uTMatrix");
119 fmvMatrixUniform = glGetUniformLocation(fShaderProgram,
"uMVMatrix");
122 float identity[16] = {
128 glUniformMatrix4fv (fcMatrixUniform, 1, 0, identity);
129 glUniformMatrix4fv (fpMatrixUniform, 1, 0, identity);
130 glUniformMatrix4fv (ftMatrixUniform, 1, 0, identity);
131 glUniformMatrix4fv(fmvMatrixUniform, 1, 0, identity);
133 glUseProgram(fShaderProgram);
143 if (fSceneHandler.GetScene() == 0) {
144 fHasToRepaint =
false;
156 void G4OpenGLImmediateQtViewer::DrawView() {
157 #ifdef G4MULTITHREADED
167 void G4OpenGLImmediateQtViewer::ComputeView () {
183 HaloingSecondPass ();
194 fHasToRepaint =
true;
200 void G4OpenGLImmediateQtViewer::resizeGL(
204 if ((aWidth > 0) && (aHeight > 0)) {
205 ResizeWindow(aWidth,aHeight);
206 fHasToRepaint = sizeHasChanged();
211 void G4OpenGLImmediateQtViewer::paintGL()
213 updateToolbarAndMouseContextMenu();
215 if (fPaintEventLock) {
218 if (!fQGLWidgetInitialiseCompleted) {
219 fPaintEventLock =
false;
222 if ((getWinWidth() == 0) && (getWinHeight() == 0)) {
227 if ( !fHasToRepaint) {
232 if (!isMaximized() && !isFullScreen()) {
233 sw = normalGeometry().width();
234 sh = normalGeometry().height();
236 sw = frameGeometry().width();
237 sh = frameGeometry().height();
239 if ((getWinWidth() == (
unsigned int)sw) &&(getWinHeight() == (
unsigned int)sh)) {
242 }
else if ((sw == 0) && (sh == 0)) {
243 if (((getWinWidth() == (
unsigned int)width())) &&(getWinHeight() == (
unsigned int) height())) {
254 fHasToRepaint =
false;
256 fPaintEventLock =
false;
259 void G4OpenGLImmediateQtViewer::mousePressEvent(QMouseEvent *event)
261 G4MousePressEvent(event);
264 void G4OpenGLImmediateQtViewer::keyPressEvent (QKeyEvent * event)
266 G4keyPressEvent(event);
269 void G4OpenGLImmediateQtViewer::keyReleaseEvent (QKeyEvent * event)
271 G4keyReleaseEvent(event);
274 void G4OpenGLImmediateQtViewer::wheelEvent (QWheelEvent * event)
279 void G4OpenGLImmediateQtViewer::showEvent (QShowEvent *)
281 if (fQGLWidgetInitialiseCompleted) {
282 fHasToRepaint =
true;
291 void G4OpenGLImmediateQtViewer::mouseDoubleClickEvent(QMouseEvent *)
293 G4MouseDoubleClickEvent();
296 void G4OpenGLImmediateQtViewer::mouseReleaseEvent(QMouseEvent *event)
298 G4MouseReleaseEvent(event);
301 void G4OpenGLImmediateQtViewer::mouseMoveEvent(QMouseEvent *event)
303 G4MouseMoveEvent(event);
307 void G4OpenGLImmediateQtViewer::contextMenuEvent(QContextMenuEvent *e)
309 G4manageContextMenuEvent(e);
312 void G4OpenGLImmediateQtViewer::paintEvent(QPaintEvent *) {
313 if (! fQGLWidgetInitialiseCompleted) {
317 fHasToRepaint = isFramebufferReady();
318 if ( fHasToRepaint) {
324 void G4OpenGLImmediateQtViewer::updateQWidget() {
329 if (! isCurrentWidget()){
333 fUpdateGLLock =
true;
336 updateViewerPropertiesTableWidget();
337 updateSceneTreeWidget();
338 fUpdateGLLock=
false;
342 void G4OpenGLImmediateQtViewer::ShowView (
349 fHasToRepaint =
true;