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 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
#pragma once
#include <wx/panel.h>
#include <wx/timer.h>
#include <sigc++/trackable.h>
#include "math/Matrix4.h"
#include "../XmlResourceBasedWidget.h"
#include "igl.h"
#include "iscenegraph.h"
#include "irender.h"
#include "../FreezePointer.h"
#include "render/NopRenderView.h"
#include "render/CamRenderer.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 onFrameSelected(wxSpinEvent& ev);
void onFrameConfirmed(wxCommandEvent& ev);
void jumpToSelectedFrame(wxSpinCtrl* spinCtrl);
void updateFrameSelector();
void onSizeAllocate(wxSizeEvent& ev);
void onFilterConfigChanged();
void onRenderModeChanged(wxCommandEvent& ev);
void onGridButtonClick(wxCommandEvent& ev);
void drawInfoText();
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;
render::CamRenderer::HighlightShaders _shaders;
bool _enableLightingModeAtStart;
protected:
const unsigned int MSEC_PER_FRAME = 16;
// The backend rendersystem instance
RenderSystemPtr _renderSystem;
// Uses a dummy VolumeTest implementation
render::NopRenderView _view;
// 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
wxToolBarToolBase* _filterTool;
IGLFont::Ptr _glFont;
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 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();
// Defaults to getSceneBounds().getOrigin()
virtual Vector3 getGridOrigin();
// 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();
// Base method will return true, which will also make the corresponding button appear on the toolbar
virtual bool canDrawGrid();
// Can be overridden by subclasses to update their scene/models
virtual void onRenderModeChanged() {}
// Returns the info text that is rendered in the lower left corner of the preview.
// Shows the render time by default, but can be overridden by subclasses.
virtual std::string getInfoText();
/**
* \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;
}
// Gets the position of the camera
const Vector3& getViewOrigin();
// Defines the position of the camera
void setViewOrigin(const Vector3& origin);
// Gets the view angles (euler angles)
const Vector3& getViewAngles();
// 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);
// Pass true to enable lighting mode right at startup
// Use this to define the mode before the render context is available,
// i.e. at dialog construction time
void setStartupLightingMode(bool enableAtStart);
/// Schedule a GL widget redraw operation
void queueDraw();
};
typedef std::shared_ptr<RenderPreview> RenderPreviewPtr;
} // namespace
|