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