/
RenderPreview.h
221 lines (162 loc) · 5.63 KB
/
RenderPreview.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#pragma once
#include <wx/panel.h>
#include <wx/timer.h>
#include <sigc++/trackable.h>
#include "math/Matrix4.h"
#include "../XmlResourceBasedWidget.h"
#include "ifiltermenu.h"
#include "iscenegraph.h"
#include "irender.h"
#include "../FreezePointer.h"
#include "render/SimpleFrontendRenderer.h"
#include "render/SceneRenderWalker.h"
#include "render/NopVolumeTest.h"
class wxToolBarToolBase;
namespace wxutil
{
class GLWidget;
/**
* greebo: This class acts as base for widgets featuring
* a real time openGL render preview. It offers
* its own local SceneGraph, backend and frontend renderer
* plus all the logic for camera handling and filtering.
*
* Override the protected methods to have the scene set up
* in special ways or add custom toolbar items.
*
* After construction the local scene graph will be empty.
*/
class RenderPreview :
public wxEvtHandler,
public sigc::trackable,
private XmlResourceBasedWidget
{
private:
void connectToolbarSignals();
bool drawPreview();
void onGLScroll(wxMouseEvent& ev);
void onGLMouseClick(wxMouseEvent& ev);
void onGLMouseRelease(wxMouseEvent& ev);
void onGLMotion(wxMouseEvent& ev);
void onGLMotionDelta(int x, int y, unsigned int mouseState);
void onGLKeyPress(wxKeyEvent& ev);
void onStartPlaybackClick(wxCommandEvent& ev);
void onStopPlaybackClick(wxCommandEvent& ev);
void onPausePlaybackClick(wxCommandEvent& ev);
void onStepForwardClick(wxCommandEvent& ev);
void onStepBackClick(wxCommandEvent& ev);
void onSizeAllocate(wxSizeEvent& ev);
void onFilterConfigChanged();
void onRenderModeChanged(wxCommandEvent& ev);
void onGridButtonClick(wxCommandEvent& ev);
void drawTime();
void drawGrid();
// Called each frame by wxTimer
void _onFrame(wxTimerEvent& ev);
void updateModelViewMatrix();
void updateActiveRenderModeButton();
void setupToolbars(bool enableAnimation);
protected:
wxPanel* _mainPanel;
private:
// The scene we're rendering
scene::GraphPtr _scene;
// GL widget
GLWidget* _glWidget;
bool _initialised;
FreezePointer _freezePointer;
bool _renderGrid;
protected:
// The backend rendersystem instance
RenderSystemPtr _renderSystem;
// The front-end renderer, collecting the OpenGLRenderables
render::SimpleFrontendRenderer _renderer;
render::NopVolumeTest _volumeTest;
// The scene adaptor passing nodes into our front-end renderer
render::SceneRenderWalker _sceneWalker;
// Current viewer position and view angles
Vector3 _viewOrigin;
Vector3 _viewAngles;
// Current modelview matrix
Matrix4 _modelView;
// The local model orientation
Matrix4 _modelRotation;
int _lastX;
int _lastY;
// Mutex flag to avoid draw call bunching
bool _renderingInProgress;
wxTimer _timer;
int _previewWidth;
int _previewHeight;
wxSizer* _toolbarSizer;
// The filters menu
ui::IFilterMenuPtr _filtersMenu;
wxToolBarToolBase* _filterTool;
protected:
const scene::GraphPtr& getScene();
/// Add another one to the toolbar hbox
void addToolbar(wxToolBar* toolbar);
// Subclasses should at least add a single node as scene root, such that
// the rendersystem can be associated. This is called after initialisePreview()
virtual void setupSceneGraph();
virtual Matrix4 getProjectionMatrix(float near_z, float far_z, float fieldOfView, int width, int height);
virtual const Matrix4& getModelViewMatrix();
virtual Matrix4 calculateModelViewMatrix();
void resetModelRotation();
// When the user requests a model rotation change (by dragging)
virtual void onModelRotationChanged() {}
virtual void startPlayback();
virtual void stopPlayback();
// Override this to deliver accurate scene bounds, used for mousewheel-zooming
virtual AABB getSceneBounds();
// Called right before rendering, returning false will cancel the render algorithm
virtual bool onPreRender();
// Called after the render phase, can be used to draw custom stuff on the GL widget
virtual void onPostRender() {}
// Use this to render a wireframe view of the scene
void renderWireFrame();
// Override these to define the flags to render a fill/wireframe scene
virtual RenderStateFlags getRenderFlagsFill();
virtual RenderStateFlags getRenderFlagsWireframe();
void associateRenderSystem();
// Can be overridden by subclasses to update their scene/models
virtual void onRenderModeChanged() {}
/**
* \brief
* Construct a RenderPreview
*
* \param enableAnimation
* If true, display animation controls in toolbar, otherwise hide the
* animation controls.
*/
RenderPreview(wxWindow* parent, bool enableAnimation = true);
virtual ~RenderPreview();
public:
wxPanel* getWidget() const
{
return _mainPanel;
}
void setSize(int width, int height);
/**
* Initialise the GL preview. This clears the window and sets up the
* initial matrices and lights.
*/
void initialisePreview();
/// Get the RenderSystem used by the preview
const RenderSystemPtr& getRenderSystem()
{
return _renderSystem;
}
// Defines the position of the camera
void setViewOrigin(const Vector3& origin);
// Defines the view angles (euler angles in degrees)
void setViewAngles(const Vector3& angles);
// Check whether lighting mode is enabled
bool getLightingModeEnabled();
// Enable/disable lighting mode
void setLightingModeEnabled(bool enabled);
/// Schedule a GL widget redraw operation
void queueDraw();
};
typedef std::shared_ptr<RenderPreview> RenderPreviewPtr;
} // namespace