HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_GeoRender.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: GR_GeoRender.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Base class for all drawing methods that Houdini is natively capable of
10  * rendering.
11  */
12 #ifndef GR_GeoRender_H
13 #define GR_GeoRender_H
14 
15 class OP_Node;
16 class GU_Detail;
17 class GR_DisplayOption;
18 class GR_RenderInfo;
19 class UT_StringArray;
20 class GT_CountArray;
21 class GA_BreakpointGroup;
22 class GR_Primitive;
23 class RV_Geometry;
24 class RE_Geometry;
25 
26 #include <RE/RE_RenderContext.h>
27 #include <UT/UT_Array.h>
28 #include <UT/UT_Matrix4.h>
29 #include <UT/UT_UniquePtr.h>
30 #include <UT/UT_Vector4.h>
31 #include <GT/GT_DataArray.h>
32 #include <GT/GT_Primitive.h>
33 #include <GA/GA_ElementGroup.h>
34 #include <GA/GA_EdgeGroup.h>
35 
36 #include "GR_DrawParms.h"
37 #include "GR_MaterialGroups.h"
38 #include "GR_PickRecord.h"
39 #include "GR_UpdateParms.h"
40 #include "GR_ErrorManager.h"
41 
43 {
44 public:
45  enum RenderType { OPENGL, VULKAN };
46 
47  GR_GeoRender(GR_Primitive *parent_prim, RenderType type);
48  virtual ~GR_GeoRender();
49 
50  virtual const char *className() const = 0;
51 
52  bool isGL() const { return myRenderer == OPENGL; }
53  bool isVulkan() const { return myRenderer == VULKAN; }
54 
55  /// Update the geometry of this render object using the GT primitive. No
56  /// rendering commands should be issued.
57  virtual void update(RE_RenderContext r,
58  const GT_PrimitiveHandle &primh,
59  const GR_UpdateParms &p,
60  const char *cache_name) = 0;
61 
62  /// Called when the view changes, if the parent primitive requested view
63  /// changes
65  const GR_DisplayOption &opts,
66  const char *cache_name,
67  RE_CacheVersion geo_version,
68  RE_CacheVersion select_version)
69  {}
70 
71  /// Normal drawing method. Only issue rendering commands.
72  virtual void draw(RE_RenderContext r,
75  GR_DrawParms draw_parms) = 0;
76 
77  /// By default, no instanced drawing support.
78  virtual bool supportsInstances() const { return false; }
79 
80  virtual bool isConvexed() const { return myConvexFlag; }
81 
82  /// Called if another entity makes changes to the RE_Geometry after update()
83  /// is called (usually the entity is a GR_Primitive object).
85 
86  virtual void retireGeometry() {}
87 
88  /// returns true if this drawable renders some transparent elements
89  virtual bool hasTransparency() const { return false; }
90 
91 
92  /// return the number of GL primitives that this renderer produces. May be
93  /// roughly estimated.
94  virtual exint getNumGLPrimitives() const = 0;
95 
96  virtual RE_Geometry *getGeometry() { return nullptr; }
97 
98  virtual RV_Geometry *getVkGeometry() { return nullptr; }
99 
100  virtual void getPickConnectGroup(unsigned int pick_mode,
101  GR_PickGeometry pick_geo,
102  int &out_connect_start,
103  int &out_connect_num) {} // = 0;
104 
105  // Get connect group and num, then use them to get connect group end, used by
106  // some functions
107  void getPickConnectGroup(unsigned int pick_mode,
108  GR_PickGeometry pick_geo,
109  int &out_connect_start,
110  int &out_connect_num,
111  int &out_connect_end)
112  {
113  getPickConnectGroup(pick_mode, pick_geo,
114  out_connect_start,
115  out_connect_num);
116  if (out_connect_num > 0 &&
117  out_connect_num < 0x40000000)
118  {
119  out_connect_end = out_connect_start
120  + out_connect_num - 1;
121  }
122  else
123  out_connect_end = -1;
124  };
125 
126  /// check if there is a specifc geometry and connect group that should be
127  /// used for pick rendering
128  virtual RV_Geometry *getVkPickGeometry(unsigned int pick_mode)
129  {
130  return getVkGeometry();
131  }
132 
133  // Accessors to various high-level data
134  bool showSelections() const;
135  GR_RenderVersion getRenderVersion() const;
136 
137  void allowGeoOverride(bool allow_overrides);
138 
139  virtual bool canFrustumCull() { return true; }
140  bool inViewFrustum(const UT_Matrix4D &objviewproj,
141  const UT_BoundingBoxD *bbox);
142  bool isRasterizedInView(
143  const UT_Matrix4F &objviewproj,
144  const UT_Vector2F &min_proj_size,
145  const UT_BoundingBoxF *bbox=nullptr);
146 
147  GR_BasePrimType getParentType() const;
148 
149  RenderType getRenderType() const { return myRenderer; }
150 
151  GR_Primitive* getParent() { return myParentPrim; }
152 
153  void buildInformation(bool prim_id,
154  bool point_id)
155  {
156  myBuildPrimInfo = prim_id;
157  myBuildPointInfo = point_id;
158  }
159  bool shouldBuildPrimID() const
160  { return myBuildPrimInfo; }
161  bool shouldBuildPointID() const
162  { return myBuildPointInfo; }
163 
164  void setSelectionMask(GR_AttribMask selection_mask)
165  { mySelectionMask = selection_mask; }
167  { return mySelectionMask; }
168 
170  { myCurrentSelection = m; }
172  { return myCurrentSelection; }
173 
175  { myCurrentPointSelectInstance = i; }
177  { return myCurrentPointSelectInstance; }
178 
179  void setSelectedEdgeGroup(const GA_EdgeGroup* selected_edges)
180  { mySelectedEdges = selected_edges; }
181 
182  void setMaterialOverride(int mat_index)
183  { myMaterialOverride = mat_index; }
185  { myMaterialOverride = -1; }
186 
187  bool getDetailPrimID(int &id) const
188  {
189  if(myHasDetailPrimID)
190  {
191  id = myDetailPrimID;
192  return true;
193  }
194  id = 0;
195  return false;
196  }
197  virtual void gpuMemoryUsage(exint &used_bytes,
198  exint &unused_bytes,
199  exint &pinned_bytes) {}
200 
201  // Message and error reporting
202  void addUpdateMessage(GR_ErrorManager::Source err_source,
203  GR_ErrorCode gr_code,
204  UT_StringHolder extra_text=UT_StringHolder(),
205  UT_StringHolder src_name=UT_StringHolder());
206  void addUpdateWarning(GR_ErrorManager::Source err_source,
207  GR_ErrorCode gr_code,
208  UT_StringHolder extra_text=UT_StringHolder(),
209  UT_StringHolder src_name=UT_StringHolder());
210  void addUpdateError (GR_ErrorManager::Source err_source,
211  GR_ErrorCode gr_code,
212  UT_StringHolder extra_text=UT_StringHolder(),
213  UT_StringHolder src_name=UT_StringHolder());
214  void addUpdateFatal (GR_ErrorManager::Source err_source,
215  GR_ErrorCode gr_code,
216  UT_StringHolder extra_text=UT_StringHolder(),
217  UT_StringHolder src_name=UT_StringHolder());
218  void addRedrawMessage(GR_ErrorManager::Source err_source,
219  GR_ErrorCode gr_code,
220  UT_StringHolder extra_text=UT_StringHolder(),
221  UT_StringHolder src_name=UT_StringHolder());
222  void addRedrawWarning(GR_ErrorManager::Source err_source,
223  GR_ErrorCode gr_code,
224  UT_StringHolder extra_text=UT_StringHolder(),
225  UT_StringHolder src_name=UT_StringHolder());
226  void addRedrawError (GR_ErrorManager::Source err_source,
227  GR_ErrorCode gr_code,
228  UT_StringHolder extra_text=UT_StringHolder(),
229  UT_StringHolder src_name=UT_StringHolder());
230  void addRedrawFatal (GR_ErrorManager::Source err_source,
231  GR_ErrorCode gr_code,
232  UT_StringHolder extra_text=UT_StringHolder(),
233  UT_StringHolder src_name=UT_StringHolder());
234 
235 protected:
236  GR_AttribMask hasAttribute(const GT_Primitive *prim,
237  const char *name,
238  GT_DataArrayHandle &h) const;
239 
240 
241  GT_PrimitiveHandle getCachedGTPrimitive();
242  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
243 
244  int getCurrentLayer() const
245  { return myCurrentLayer; }
246 
247  // Helpers for selection
248 
249  // implemented for: T = uint8, T = int32
250  template <typename T>
251  GR_SelectMode addToPointSelection(const UT_Span<T> &out_select,
252  const GU_Detail &geo,
253  const GT_DataArrayHandle &vh,
254  const GT_DataArrayHandle &vl,
255  const GA_PointGroup *pntsel,
256  bool use_vertex_for_point_select,
257  bool &init);
258 
259  GR_SelectMode addToVertexSelection(const UT_Span<uint8> &out_select,
260  const GU_Detail &geo,
261  const GT_DataArrayHandle &vh,
262  const GA_VertexGroup *vertsel,
263  bool &init);
264 
265  // implemented for: T = uint8, T = int32
266  template <typename T>
267  GR_SelectMode addToEdgeSelection(const UT_Span<T> &out_select,
268  const GU_Detail &geo,
269  const GT_DataArrayHandle &vt,
270  const GT_DataArrayHandle &vert_list,
271  const GA_EdgeGroup *edgesel,
272  bool &init);
273 
274  GR_SelectMode addToPrimSelection(const UT_Span<uint8> &out_select,
275  const GT_DataArrayHandle &vh,
276  const GA_PrimitiveGroup *primsel,
277  bool &init);
278 
279 public:
280  // For derived class's parallel helpers
281  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
282  const GU_ConstDetailHandle &geo,
283  int npoints);
284  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
285  const GU_ConstDetailHandle &geo);
286 
287  static bool createTanAttrib(UT_Vector4F *tan_data,
288  const GT_DataArray *nml,
289  const GT_DataArray *tanu,
290  const GT_DataArray *tanv,
291  const GT_DataArray *vlist);
292 
293  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
294  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
295 
296 protected:
301  unsigned myBuildPointInfo : 1,
302  myBuildPrimInfo : 1,
303  myHasDetailPrimID : 1,
304  myHasInstancedTransform : 1,
305  myHasIdentityTransform : 1,
306  myUseBoneDeform : 1,
307  myNumBoneDeform : 2,
308  myAllowGeoOverride : 1;
309 
313  const GA_EdgeGroup *mySelectedEdges = nullptr;
318 
321 };
322 
323 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:311
virtual void gpuMemoryUsage(exint &used_bytes, exint &unused_bytes, exint &pinned_bytes)
Definition: GR_GeoRender.h:197
GLbitfield flags
Definition: glcorearb.h:1596
int getCurrentLayer() const
Definition: GR_GeoRender.h:244
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:300
bool shouldBuildPrimID() const
Definition: GR_GeoRender.h:159
void setSelectionInstance(int i)
Definition: GR_GeoRender.h:174
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:52
int64 exint
Definition: SYS_Types.h:125
int getSelectionInstance() const
Definition: GR_GeoRender.h:176
GT_API const UT_StringHolder cache_name
GR_AttribMask getSelectionMask() const
Definition: GR_GeoRender.h:166
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
A class that manages material assignments to different groups of primitives.
Temporary container for either a RV_Render and an RE_Render.
RenderType myRenderer
Definition: GR_GeoRender.h:297
bool isVulkan() const
Definition: GR_GeoRender.h:53
GR_Primitive * getParent()
Definition: GR_GeoRender.h:151
virtual RV_Geometry * getVkPickGeometry(unsigned int pick_mode)
Definition: GR_GeoRender.h:128
virtual bool canFrustumCull()
Definition: GR_GeoRender.h:139
set of parameters sent to GR_Primitive::update()
GT_API const UT_StringHolder point_id
const GR_RenderInfo * myInfo
Definition: GR_GeoRender.h:298
GR_AttribMask
Definition: GR_Defines.h:347
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:41
GR_RenderMode
Definition: GR_Defines.h:48
GR_BasePrimType
Definition: GR_Defines.h:371
GR_Primitive * myParentPrim
Definition: GR_GeoRender.h:319
virtual bool isConvexed() const
Definition: GR_GeoRender.h:80
virtual RV_Geometry * getVkGeometry()
Definition: GR_GeoRender.h:98
virtual bool hasTransparency() const
returns true if this drawable renders some transparent elements
Definition: GR_GeoRender.h:89
#define GR_API
Definition: GR_API.h:10
GR_API bool inViewFrustum(const UT_BoundingBoxD &bbox, const UT_Matrix4D &objviewproj, const UT_Vector4D *frustum_area=NULL)
void buildInformation(bool prim_id, bool point_id)
Definition: GR_GeoRender.h:153
int myCurrentPointSelectInstance
Definition: GR_GeoRender.h:314
bool getDetailPrimID(int &id) const
Definition: GR_GeoRender.h:187
GLuint const GLchar * name
Definition: glcorearb.h:786
int myMaterialOverride
Definition: GR_GeoRender.h:315
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:169
GR_RenderFlags
Definition: GR_Defines.h:88
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GR_RenderVersion
Definition: GR_Defines.h:22
bool isGL() const
Definition: GR_GeoRender.h:52
virtual void geometryUpdated(RE_RenderContext)
Definition: GR_GeoRender.h:84
GLenum mode
Definition: glcorearb.h:99
virtual void retireGeometry()
Definition: GR_GeoRender.h:86
virtual void getPickConnectGroup(unsigned int pick_mode, GR_PickGeometry pick_geo, int &out_connect_start, int &out_connect_num)
Definition: GR_GeoRender.h:100
GR_PickGeometry
Definition: GR_PickRecord.h:60
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GR_SelectMode getSelectionDisplayMode() const
Definition: GR_GeoRender.h:171
virtual RE_Geometry * getGeometry()
Definition: GR_GeoRender.h:96
void setSelectedEdgeGroup(const GA_EdgeGroup *selected_edges)
Definition: GR_GeoRender.h:179
void clearMaterialOverride()
Definition: GR_GeoRender.h:184
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:310
bool shouldBuildPointID() const
Definition: GR_GeoRender.h:161
Simple class for a mutli-integer cache tag.
virtual bool supportsInstances() const
By default, no instanced drawing support.
Definition: GR_GeoRender.h:78
GLboolean r
Definition: glcorearb.h:1222
GR_MaterialGroups myMatGroups
Definition: GR_GeoRender.h:299
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:293
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:182
RenderType getRenderType() const
Definition: GR_GeoRender.h:149
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:312
virtual void viewUpdate(RE_RenderContext r, const GR_DisplayOption &opts, const char *cache_name, RE_CacheVersion geo_version, RE_CacheVersion select_version)
Definition: GR_GeoRender.h:64
void setSelectionMask(GR_AttribMask selection_mask)
Definition: GR_GeoRender.h:164
GR_SelectMode
Definition: GR_Defines.h:246
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:294
void getPickConnectGroup(unsigned int pick_mode, GR_PickGeometry pick_geo, int &out_connect_start, int &out_connect_num, int &out_connect_end)
Definition: GR_GeoRender.h:107