guiTSControl.h

Engine/source/gui/3d/guiTSControl.h

More...

Classes:

class

Abstract base class for 3D viewport GUIs.

Public Typedefs

GuiTSRenderStyles 

Detailed Description

Public Typedefs

typedef GuiTSCtrl::RenderStyles GuiTSRenderStyles 

Public Functions

DefineEnumType(GuiTSRenderStyles )

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _GUITSCONTROL_H_
 25#define _GUITSCONTROL_H_
 26
 27#ifndef _GUICONTAINER_H_
 28#include "gui/containers/guiContainer.h"
 29#endif
 30#ifndef _MMATH_H_
 31#include "math/mMath.h"
 32#endif
 33
 34
 35#ifndef _MATTEXTURETARGET_H_
 36#include "materials/matTextureTarget.h"
 37#endif
 38
 39#ifndef _GUIOFFSCREENCANVAS_H_
 40#include "gui/core/guiOffscreenCanvas.h"
 41#endif
 42
 43class IDisplayDevice;
 44class GuiOffscreenCanvas;
 45
 46struct CameraQuery
 47{
 48   SimObject*  object;
 49   F32         nearPlane;
 50   F32         farPlane;
 51   F32         fov;
 52   FovPort     fovPort[2]; // fov for each eye
 53   Point3F     eyeOffset[2];
 54   MatrixF     eyeTransforms[2];
 55   bool        ortho;
 56   bool        hasFovPort;
 57   bool        hasStereoTargets;
 58   MatrixF     cameraMatrix;
 59   MatrixF     headMatrix; // center matrix (for HMDs)
 60   S32         currentEye;
 61   RectI       stereoViewports[2]; // destination viewports
 62   GFXTextureTarget* stereoTargets[2];
 63   GuiCanvas* drawCanvas; // Canvas we are drawing to. Needed for VR
 64
 65   IDisplayDevice* displayDevice;
 66};
 67
 68/// Abstract base class for 3D viewport GUIs.
 69class GuiTSCtrl : public GuiContainer
 70{
 71   typedef GuiContainer Parent;
 72
 73public:
 74   enum RenderStyles {
 75      RenderStyleStandard           = 0,
 76      RenderStyleStereoSideBySide   = (1<<0),
 77      RenderStyleStereoSeparate     = (1<<1),
 78   };
 79
 80protected:
 81   static U32     smFrameCount;
 82   static bool    smUseLatestDisplayTransform;
 83   F32            mCameraZRot;
 84   F32            mForceFOV;
 85
 86   /// A list of GuiTSCtrl which are awake and 
 87   /// most likely rendering.
 88   static Vector<GuiTSCtrl*> smAwakeTSCtrls;
 89
 90   /// A scalar which controls how much of the reflection
 91   /// update timeslice for this viewport to get.
 92   F32 mReflectPriority;
 93
 94   /// The current render type
 95   U32 mRenderStyle;
 96
 97   F32         mOrthoWidth;
 98   F32         mOrthoHeight;
 99
100   MatrixF     mSaveModelview;
101   MatrixF     mSaveProjection;
102   RectI       mSaveViewport;
103   Frustum     mSaveFrustum;
104   
105   /// The saved world to screen space scale.
106   /// @see getWorldToScreenScale
107   Point2F mSaveWorldToScreenScale;
108
109   /// The last camera query set in onRender.
110   /// @see getLastCameraQuery
111   CameraQuery mLastCameraQuery;
112
113   NamedTexTargetRef mStereoGuiTarget;
114   GFXVertexBufferHandle<GFXVertexPCT> mStereoOverlayVB;
115   GFXStateBlockRef mStereoGuiSB;
116
117   GFXVertexBufferHandle<GFXVertexPCT> mStereoPreviewVB;
118   GFXStateBlockRef mStereoPreviewSB;
119
120   SimObjectPtr<GuiOffscreenCanvas> mStereoCanvas;
121   
122public:
123   
124   GuiTSCtrl();
125
126   void onPreRender();
127   void _internalRender(RectI guiViewport, RectI renderViewport, Frustum &frustum);
128   void onRender(Point2I offset, const RectI &updateRect);
129   virtual bool processCameraQuery(CameraQuery *query);
130
131   /// Subclasses can override this to perform 3D rendering.
132   virtual void renderWorld(const RectI &updateRect);
133
134   /// Subclasses can override this to perform 2D rendering.   
135   virtual void renderGui(Point2I offset, const RectI &updateRect) {}
136
137   static void initPersistFields();
138   static void consoleInit();
139
140   virtual bool onWake();
141   virtual void onSleep();
142
143   /// Returns the last World Matrix set in onRender.
144   const MatrixF& getLastWorldMatrix() const { return mSaveModelview; }
145
146   /// Returns the last Projection Matrix set in onRender.
147   const MatrixF& getLastProjectionMatrix() const { return mSaveProjection; }
148
149   /// Returns the last Viewport Rect set in onRender.
150   const RectI&   getLastViewportRect() const { return mSaveViewport; }
151
152   /// Returns the last Frustum set in onRender.
153   const Frustum& getLastFrustum() const { return mSaveFrustum; }
154
155   /// Returns the scale for converting world space 
156   /// units to screen space units... aka pixels.
157   /// @see GFXDevice::getWorldToScreenScale
158   const Point2F& getWorldToScreenScale() const { return mSaveWorldToScreenScale; }
159
160   /// Returns the last camera query set in onRender.
161   const CameraQuery& getLastCameraQuery() const { return mLastCameraQuery; }   
162   
163   /// Returns the screen space X,Y and Z for world space point.
164   /// The input z coord is depth, from 0 to 1.
165   bool project( const Point3F &pt, Point3F *dest ) const; 
166
167   /// Returns the world space point for X, Y and Z.  The ouput
168   /// z coord is depth, from 0 to 1
169   bool unproject( const Point3F &pt, Point3F *dest ) const;
170
171   ///
172   F32 projectRadius( F32 dist, F32 radius ) const;
173
174   /// Returns the distance required to fit the given
175   /// radius within the camera's view.
176   F32 calculateViewDistance(F32 radius);
177
178   /// Takes Points in World Space representing a Line or LineList.
179   /// These will be projected into screen space and rendered with the requested
180   /// width in pixels.
181   ///
182   /// This is a 2D drawing operation and should not be called from within
183   /// renderScene without preparing the GFX for 2D rendering first.   
184   ///
185   /// These methods are NOT optimized for performance in any way and are only
186   /// intended for debug rendering, editor rendering, or infrequent rendering.
187   ///
188   void drawLine( Point3F p0, Point3F p1, const ColorI &color, F32 width );
189   void drawLineList( const Vector<Point3F> &points, const ColorI color, F32 width );
190
191   static const U32& getFrameCount() { return smFrameCount; }
192
193   bool shouldRenderChildControls() { return mRenderStyle == RenderStyleStandard; }
194
195   void setStereoGui(GuiOffscreenCanvas *canvas);
196   void renderDisplayPreview(const RectI &updateRect, GFXTexHandle &previewTexture);
197
198   DECLARE_CONOBJECT(GuiTSCtrl);
199   DECLARE_CATEGORY( "Gui 3D" );
200   DECLARE_DESCRIPTION( "Abstract base class for controls that render a 3D viewport." );
201};
202
203typedef GuiTSCtrl::RenderStyles GuiTSRenderStyles;
204
205DefineEnumType( GuiTSRenderStyles );
206
207#endif // _GUITSCONTROL_H_
208