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 RE_Geometry;
24 class RV_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 setMaterialOverride(int mat_index)
180  { myMaterialOverride = mat_index; }
182  { myMaterialOverride = -1; }
183 
184  bool getDetailPrimID(int &id) const
185  {
186  if(myHasDetailPrimID)
187  {
188  id = myDetailPrimID;
189  return true;
190  }
191  id = 0;
192  return false;
193  }
194  virtual void gpuMemoryUsage(exint &used_bytes,
195  exint &unused_bytes,
196  exint &pinned_bytes) {}
197 
198  // Message and error reporting
199  void addUpdateMessage(GR_ErrorManager::Source err_source,
200  GR_ErrorCode gr_code,
201  UT_StringHolder extra_text=UT_StringHolder(),
202  UT_StringHolder src_name=UT_StringHolder());
203  void addUpdateWarning(GR_ErrorManager::Source err_source,
204  GR_ErrorCode gr_code,
205  UT_StringHolder extra_text=UT_StringHolder(),
206  UT_StringHolder src_name=UT_StringHolder());
207  void addUpdateError (GR_ErrorManager::Source err_source,
208  GR_ErrorCode gr_code,
209  UT_StringHolder extra_text=UT_StringHolder(),
210  UT_StringHolder src_name=UT_StringHolder());
211  void addUpdateFatal (GR_ErrorManager::Source err_source,
212  GR_ErrorCode gr_code,
213  UT_StringHolder extra_text=UT_StringHolder(),
214  UT_StringHolder src_name=UT_StringHolder());
215  void addRedrawMessage(GR_ErrorManager::Source err_source,
216  GR_ErrorCode gr_code,
217  UT_StringHolder extra_text=UT_StringHolder(),
218  UT_StringHolder src_name=UT_StringHolder());
219  void addRedrawWarning(GR_ErrorManager::Source err_source,
220  GR_ErrorCode gr_code,
221  UT_StringHolder extra_text=UT_StringHolder(),
222  UT_StringHolder src_name=UT_StringHolder());
223  void addRedrawError (GR_ErrorManager::Source err_source,
224  GR_ErrorCode gr_code,
225  UT_StringHolder extra_text=UT_StringHolder(),
226  UT_StringHolder src_name=UT_StringHolder());
227  void addRedrawFatal (GR_ErrorManager::Source err_source,
228  GR_ErrorCode gr_code,
229  UT_StringHolder extra_text=UT_StringHolder(),
230  UT_StringHolder src_name=UT_StringHolder());
231 
232 protected:
233  GR_AttribMask hasAttribute(const GT_Primitive *prim,
234  const char *name,
235  GT_DataArrayHandle &h) const;
236 
237 
238  GT_PrimitiveHandle getCachedGTPrimitive();
239  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
240 
241  int getCurrentLayer() const
242  { return myCurrentLayer; }
243 
244  // for the materials in matlist, map them to the shop_*path in 'prim'.
245  // returns 'matmap' array which indicates what the index in shop_*path is
246  // for the materials it matlist.
247 #ifdef USE_MATERIAL_MAP
248  bool buildMaterialMap(const GT_Primitive *prim,
249  const RE_MaterialAtlas &mats,
250  UT_IntArray &matmap);
251 #endif
252 
253 
254  // Helpers for selection
255 
256  // implemented for: T = uint8, T = int32
257  template <typename T>
258  GR_SelectMode addToPointSelection(const UT_Span<T> &out_select,
259  const GU_Detail &geo,
260  const GT_DataArrayHandle &vh,
261  const GT_DataArrayHandle &vl,
262  const GA_PointGroup *pntsel,
263  bool use_vertex_for_point_select,
264  bool &init);
265 
266  GR_SelectMode addToVertexSelection(const UT_Span<uint8> &out_select,
267  const GU_Detail &geo,
268  const GT_DataArrayHandle &vh,
269  const GA_VertexGroup *vertsel,
270  bool &init);
271 
272  // implemented for: T = uint8, T = int32
273  template <typename T>
274  GR_SelectMode addToEdgeSelection(const UT_Span<T> &out_select,
275  const GU_Detail &geo,
276  const GT_DataArrayHandle &vt,
277  const GT_DataArrayHandle &vert_list,
278  const GA_EdgeGroup *edgesel,
279  bool &init);
280 
281  GR_SelectMode addToPrimSelection(const UT_Span<uint8> &out_select,
282  const GT_DataArrayHandle &vh,
283  const GA_PrimitiveGroup *primsel,
284  bool &init);
285 
286 public:
287  // For derived class's parallel helpers
288  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
289  const GU_ConstDetailHandle &geo,
290  int npoints);
291  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
292  const GU_ConstDetailHandle &geo);
293 
294  static bool createTanAttrib(UT_Vector4F *tan_data,
295  const GT_DataArray *nml,
296  const GT_DataArray *tanu,
297  const GT_DataArray *tanv,
298  const GT_DataArray *vlist);
299 
300  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
301  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
302 
303 protected:
308  unsigned myBuildPointInfo : 1,
309  myBuildPrimInfo : 1,
310  myHasDetailPrimID : 1,
311  myHasInstancedTransform : 1,
312  myHasIdentityTransform : 1,
313  myUseBoneDeform : 1,
314  myNumBoneDeform : 2,
315  myAllowGeoOverride : 1;
316 
324 
327 };
328 
329 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:318
virtual void gpuMemoryUsage(exint &used_bytes, exint &unused_bytes, exint &pinned_bytes)
Definition: GR_GeoRender.h:194
GLbitfield flags
Definition: glcorearb.h:1596
int getCurrentLayer() const
Definition: GR_GeoRender.h:241
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:307
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
GR_AttribMask
Definition: GR_Defines.h:344
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:304
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:305
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:40
GR_RenderMode
Definition: GR_Defines.h:48
GR_BasePrimType
Definition: GR_Defines.h:368
GR_Primitive * myParentPrim
Definition: GR_GeoRender.h:325
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:320
bool getDetailPrimID(int &id) const
Definition: GR_GeoRender.h:184
GLuint const GLchar * name
Definition: glcorearb.h:786
int myMaterialOverride
Definition: GR_GeoRender.h:321
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 clearMaterialOverride()
Definition: GR_GeoRender.h:181
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:317
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:306
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:300
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:179
RenderType getRenderType() const
Definition: GR_GeoRender.h:149
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:319
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:243
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:301
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