HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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  ~RE_RenderFlush() override;
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  void setZStart(fpreal32 zStart) override;
38  // Override to reuse OGL Buffers.
39  void draw(RE_Render *r) override;
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  static void debugOutput(bool enable);
135 
136 protected:
137  void setRender(RE_Render *r);
138 
139 private:
140  void flush(bool render_complete);
141  void updatePixelRatios();
142 
143  RE_Render *myRender;
144  UT_IntArray myStateStack;
145  UT_Array<UT_DimRect> myViewportStack;
146  UT_Array<UT_DimRect> myScissorRectStack;
147  UT_Array<bool> myScissorEnableStack;
148  UT_Array<UT_BoundingRect> myOrthoStack;
149  RE_Uniform myClipPlane0Uniform;
150  RE_PerContextData *myContextData;
151 
152  /// Flag to prevent recursive flushing of render data.
153  bool myFlushing;
154 
155  /// Keeps track of whether this object is being used for dawing
156  /// into a viewport or drawing regular UI.
157  bool myViewportRenderer;
158 
159  /// Cache our two available fonts.
160  static RE_Font *theViewportFont;
161  static RE_Font *theViewportSymbolFont;
162 
163 };
164 
165 inline bool
166 RE_RenderFlush::flushRender(bool render_complete)
167 {
168  // Ignore nested flush calls.
169  if (myFlushing)
170  return false;
171 
172  // If this is the last flush of a render pass, we can reset our Z value
173  // because the next thing we draw is a whole new render.
174  if (render_complete)
175  resetCurrentZ();
176 
177  // If we have nothing to do, bail out immediately.
178  if (!hasAnyData())
179  return false;
180 
181  flush(render_complete);
182 
183  return true;
184 }
185 
186 #endif // __RE_RenderFlush__
187 
#define RE_API
Definition: RE_API.h:10
SIM_API const UT_StringHolder angle
GLdouble GLdouble GLdouble z
Definition: glcorearb.h:848
virtual void setZStart(fpreal32 zStart)
void resetCurrentZ()
GLint y
Definition: glcorearb.h:103
float fpreal32
Definition: SYS_Types.h:200
RE_MatrixMode
Definition: RE_Types.h:446
GLdouble GLdouble x2
Definition: glad.h:2349
GA_API const UT_StringHolder scale
GLdouble n
Definition: glcorearb.h:2008
GLfloat f
Definition: glcorearb.h:1926
bool hasAnyData()
GLdouble y1
Definition: glad.h:2349
GLenum target
Definition: glcorearb.h:1667
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
GLint GLenum GLint x
Definition: glcorearb.h:409
ImageBuf OIIO_API rotate(const ImageBuf &src, float angle, string_view filtername=string_view(), float filterwidth=0.0f, bool recompute_roi=false, ROI roi={}, int nthreads=0)
GLdouble t
Definition: glad.h:2397
virtual void draw(RE_Render *r)
RE_PerContextData * getContextData()
GA_API const UT_StringHolder up
fpreal64 fpreal
Definition: SYS_Types.h:277
Definition: core.h:982
GLboolean r
Definition: glcorearb.h:1222
PUGI__FN char_t * translate(char_t *buffer, const char_t *from, const char_t *to, size_t to_length)
Definition: pugixml.cpp:8352
GLdouble GLdouble GLdouble y2
Definition: glad.h:2349
bool flushRender(bool render_complete=false)
Definition: RE_Uniform.h:389
Definition: format.h:895