HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RE_RenderFlush.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RE_RenderFlush.h ( RE Library, C++)
7  */
8 
9 #ifndef __RE_RenderFlush__
10 #define __RE_RenderFlush__
11 
12 #include "RE_API.h"
13 #include "RE_ShaderHandle.h"
14 #include "RE_Uniform.h"
15 #include "RE_RenderUI.h"
16 #include <UT/UT_BoundingRect.h>
17 #include <UT/UT_Rect.h>
18 
19 class RE_Light;
20 class RE_PerContextData;
21 
23 {
24 public:
26  virtual ~RE_RenderFlush();
27 
28  /// Flag this object as being used to render into a 3D viewport.
29  void setViewportRenderer();
30  static RE_Font &getViewportFont();
31 
32  /// Holds a pointer to per-context data we use to provide OGL buffers.
33  void setContextData(RE_PerContextData *data);
34  RE_PerContextData *getContextData() { return myContextData; }
35 
36  // Override for setting the base Z value.
37  virtual void setZStart(fpreal32 zStart);
38  // Override to reuse OGL Buffers.
39  virtual void draw(RE_Render *r);
40  // Flush render commands built up to this point.
41  bool flushRender(bool render_complete = false);
42 
43  // TRANSFORMATION ------------------------------------------------------
44  void pushViewport();
45  void popViewport();
46 
47  // pushes both the viewport and the matrix.
48  void pushState(int viewing);
49  void popState();
50 
51  // Called by RE_OGLRender when our viewport changes.
52  void handleViewportUpdate(const UT_DimRect &rect);
53  void handleScissorRectUpdate(const UT_DimRect &rect);
54  void handleScissorEnableUpdate(bool enable);
55 
56  // Clipping plane support.
57  void clipPlaneDisable(int which);
58  void clipPlaneEnable(int which, const UT_Vector4D &plane);
59 
60  UT_Vector4D planeToEyeCoords(const UT_Vector4D &plane);
61 
62  // NB: The following methods to push/pop the clip plane assume that they
63  // occur within a clipPlaneEnable()/clipPlaneDisable() block, hence
64  // the "replace" prefix.
65  void replacePushClipPlane(int which, const UT_Vector4D &plane,
66  bool xform_to_eye_coords,
67  RE_UniformStackEntry &stack_entry);
68  void replacePopClipPlane(int which,
69  const RE_UniformStackEntry &stack_entry);
70 
71  // Matrix operations.
72  void pushMatrix(bool all_matrices = true,
74  void popMatrix(bool all_matrices = true,
76 
77  void loadIdentityMatrix(RE_MatrixMode mmode = RE_MATRIX_VIEWING);
78  void loadMatrix(const UT_Matrix4 &m,
80  void loadMatrix(const UT_DMatrix4 &m,
82 
83  void getMatrix(UT_Matrix4 &m,
85  void getMatrix(UT_DMatrix4 &m,
87 
88  void multiplyMatrix(const UT_Matrix4 &m);
89  void multiplyMatrix(const UT_DMatrix4 &m);
90 
91  void translate(float x, float y, float z = 0.0);
92  void scale(float x = 1.0, float y = 1.0, float z = 1.0);
93  void rotate(float angle, char axis);
94 
95  void ortho2DW(float l, float r, float b, float t);
96  void orthoFromViewport2DI(const UT_DimRect &rect);
97  void ortho3DW(float l, float r, float b, float t,
98  float n, float f);
99  void window3DW(float l, float r, float b, float t,
100  float n, float f);
101 
102  // Generates a matrix equivalent to glOrtho.
103  static UT_DMatrix4 getOrthoMatrix(float l, float r,
104  float b, float t,
105  float n, float f);
106  // Generates a matrix equivalent to glFrustum.
107  static UT_DMatrix4 getPerspectiveMatrix(float l, float r,
108  float b, float t,
109  float n, float f);
110  // Generates a matrix equivalent to gluLookAt.
111  static UT_DMatrix4 getLookatMatrix(const UT_Vector3F &eye,
112  const UT_Vector3F &target,
113  const UT_Vector3F &up);
114 
115  // Maps screen space coordinates to a world space position and a ray
116  // into the scene. Lets you know where in the scene the mouse is.
117  static bool mapWorld(fpreal xs, fpreal ys,
118  const UT_DimRect &viewport,
119  const UT_Matrix4D &proj,
120  const UT_Matrix4D &view,
121  fpreal *x1, fpreal *y1, fpreal *z1,
122  fpreal *x2, fpreal *y2, fpreal *z2);
123  // Maps world space coordinates into a screen space position. This is the
124  // pixel location of an object in the scene.
125  static bool mapScreen(fpreal xw, fpreal yw, fpreal zw,
126  const UT_DimRect &viewport,
127  const UT_Matrix4D &proj,
128  const UT_Matrix4D &view,
129  fpreal *xs, fpreal *ys);
130 
131  void getProjectiveTextureTransform(const RE_Light *light,
132  bool bias, UT_Matrix4 &mat);
133 
134 protected:
135  void setRender(RE_Render *r);
136 
137 private:
138  void flush(bool render_complete);
139  void updatePixelRatios();
140 
141  RE_Render *myRender;
142  UT_IntArray myStateStack;
143  UT_Array<UT_DimRect> myViewportStack;
144  UT_Array<UT_DimRect> myScissorRectStack;
145  UT_Array<bool> myScissorEnableStack;
146  UT_Array<UT_BoundingRect> myOrthoStack;
147  RE_Uniform myClipPlane0Uniform;
148  RE_PerContextData *myContextData;
149 
150  /// Flag to prevent recursive flushing of render data.
151  bool myFlushing;
152 
153  /// Keeps track of whether this object is being used for dawing
154  /// into a viewport or drawing regular UI.
155  bool myViewportRenderer;
156 
157  /// Cache our two available fonts.
158  static RE_Font *theViewportFont;
159  static RE_Font *theViewportSymbolFont;
160 
161 };
162 
163 inline bool
164 RE_RenderFlush::flushRender(bool render_complete)
165 {
166  // Ignore nested flush calls.
167  if (myFlushing)
168  return false;
169 
170  // If this is the last flush of a render pass, we can reset our Z value
171  // because the next thing we draw is a whole new render.
172  if (render_complete)
173  resetCurrentZ();
174 
175  // If we have nothing to do, bail out immediately.
176  if (!hasAnyData())
177  return false;
178 
179  flush(render_complete);
180 
181  return true;
182 }
183 
184 #endif // __RE_RenderFlush__
185 
#define RE_API
Definition: RE_API.h:10
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:847
virtual void setZStart(fpreal32 zStart)
void resetCurrentZ()
GLint y
Definition: glcorearb.h:102
RE_MatrixMode
Definition: RE_Types.h:415
GA_API const UT_StringHolder scale
GLdouble n
Definition: glcorearb.h:2007
GLfloat f
Definition: glcorearb.h:1925
bool hasAnyData()
T angle(const Vec2< T > &v1, const Vec2< T > &v2)
Definition: Vec2.h:480
GLenum target
Definition: glcorearb.h:1666
GLboolean * data
Definition: glcorearb.h:130
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
virtual void draw(RE_Render *r)
double fpreal
Definition: SYS_Types.h:269
RE_PerContextData * getContextData()
GA_API const UT_StringHolder up
GLint GLenum GLint x
Definition: glcorearb.h:408
GLboolean r
Definition: glcorearb.h:1221
float fpreal32
Definition: SYS_Types.h:190
bool flushRender(bool render_complete=false)
Definition: RE_Uniform.h:364