Debian Codegraph @

src/Gui/CoinRiftWidget.h

raw
1 /****************************************************************************
2 * Copyright (c) 2014 Bastiaan Veelo <Bastiaan a_t Veelo d_o_t net> *
3 * Copyright (c) 2014 Jürgen Riegel <[email protected]> *
4 * *
5 * All rights reserved. Contact me if the below is too restrictive for you. *
6 * *
7 * Redistribution and use in source and binary forms, with or without *
8 * modification, are permitted provided that the following conditions are *
9 * met: *
10 * *
11 * Redistributions of source code must retain the above copyright notice, *
12 * this list of conditions and the following disclaimer. *
13 * *
14 * Redistributions in binary form must reproduce the above copyright *
15 * notice, this list of conditions and the following disclaimer in the *
16 * documentation and/or other materials provided with the distribution. *
17 * *
18 * Neither the name of the copyright holder nor the names of its *
19 * contributors may be used to endorse or promote products derived from *
20 * this software without specific prior written permission. *
21 * *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT *
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR *
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT *
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, *
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT *
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, *
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY *
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE *
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
33 \****************************************************************************/
34 #ifndef GUI_CoinRiftWidget
35 #define GUI_CoinRiftWidget
36
37 #if BUILD_VR
38
39 // defines which method to use to render
40 # define USE_SO_OFFSCREEN_RENDERER
41
42 # ifdef USE_SO_OFFSCREEN_RENDERER
43 # ifdef USE_FRAMEBUFFER
44 # error "Mutually exclusive options defined."
45 # endif
46 # endif
47
48 # include <algorithm>
49 # include <QApplication>
50 # include <QGLWidget>
51 # include <QTimer>
52 # include <QDebug>
53 # include <Inventor/SoDB.h>
54 # include <Inventor/SoInput.h>
55 # ifdef USE_SO_OFFSCREEN_RENDERER
56 # include <Inventor/SoOffscreenRenderer.h>
57 # endif
58 # ifdef USE_FRAMEBUFFER
59 # include <Inventor/SoSceneManager.h>
60 # endif
61 # include <Inventor/nodes/SoSeparator.h>
62 # include <Inventor/nodes/SoFrustumCamera.h>
63 # include <Inventor/nodes/SoDirectionalLight.h>
64
65 # include <OVR.h>
66 # include <OVR_Kernel.h>
67 # include <OVR_Version.h>
68 # include <../Src/OVR_CAPI_GL.h>
69 # include <../Src/CAPI/GL/CAPI_GL_Util.h> // For framebuffer functions.
70
71
72 class CoinRiftWidget: public QGLWidget
73 {
74 ovrHmd hmd;
75 ovrEyeRenderDesc eyeRenderDesc[2];
76 ovrTexture eyeTexture[2];
77
78 # ifdef USE_FRAMEBUFFER
79 GLuint frameBufferID[2], depthBufferID[2];
80 // A SoSceneManager has a SoRenderManager to do the rendering -- should we not use
81 // SoRenderManager instead? We are probably not that interested in events.
82 // SoSceneManager::setSceneGraph() searches for the camera and sets it in SoRenderManager, but
83 // its is actually only used for built-in stereo rendering.
84 // FIXME: We should probably eliminate that search...
85 SoSceneManager* m_sceneManager;
86 # endif
87 # ifdef USE_SO_OFFSCREEN_RENDERER
88 SoOffscreenRenderer* renderer;
89 # endif
90 SoSeparator* rootScene[2];
91 SoFrustumCamera* camera[2];
92 SoNode* scene;
93
94 public:
95 explicit CoinRiftWidget();
96 ~CoinRiftWidget();
97 virtual void setSceneGraph(SoNode* sceneGraph);
98 void setBase(const SbVec3f& pos)
99 {
100 basePosition = pos;
101 }
102 void setBackgroundColor(const SbColor& Col);
103
104 SbVec3f basePosition;
105 SbRotation baseOrientation;
106
107 protected:
108 void handlingSafetyWarning(void);
109 void initializeGL();
110 void paintGL();
111 void resizeGL(int width, int height);
112
113 SbColor BackgroundColor;
114 SoTranslation* lightTranslation;
115 };
116
117
118 #endif // BUILD_VR
119
120 #endif // GUI_CoinRiftWidget