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  void buildInformation(bool prim_id,
152  bool point_id)
153  {
154  myBuildPrimInfo = prim_id;
155  myBuildPointInfo = point_id;
156  }
157  bool shouldBuildPrimID() const
158  { return myBuildPrimInfo; }
159  bool shouldBuildPointID() const
160  { return myBuildPointInfo; }
161 
162  void setSelectionMask(GR_AttribMask selection_mask)
163  { mySelectionMask = selection_mask; }
165  { return mySelectionMask; }
166 
168  { myCurrentSelection = m; }
170  { return myCurrentSelection; }
171 
173  { myCurrentPointSelectInstance = i; }
175  { return myCurrentPointSelectInstance; }
176 
177  void setMaterialOverride(int mat_index)
178  { myMaterialOverride = mat_index; }
180  { myMaterialOverride = -1; }
181 
182  bool getDetailPrimID(int &id) const
183  {
184  if(myHasDetailPrimID)
185  {
186  id = myDetailPrimID;
187  return true;
188  }
189  id = 0;
190  return false;
191  }
192 
193  // Message and error reporting
194  void addUpdateMessage(GR_ErrorManager::Source err_source,
195  GR_ErrorCode gr_code,
196  UT_StringHolder extra_text=UT_StringHolder(),
197  UT_StringHolder src_name=UT_StringHolder());
198  void addUpdateWarning(GR_ErrorManager::Source err_source,
199  GR_ErrorCode gr_code,
200  UT_StringHolder extra_text=UT_StringHolder(),
201  UT_StringHolder src_name=UT_StringHolder());
202  void addUpdateError (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 addUpdateFatal (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 addRedrawMessage(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 addRedrawWarning(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 addRedrawError (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 addRedrawFatal (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 
227 protected:
228  GR_AttribMask hasAttribute(const GT_Primitive *prim,
229  const char *name,
230  GT_DataArrayHandle &h) const;
231 
232 
233  GT_PrimitiveHandle getCachedGTPrimitive();
234  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
235 
236  int getCurrentLayer() const
237  { return myCurrentLayer; }
238 
239  // for the materials in matlist, map them to the shop_*path in 'prim'.
240  // returns 'matmap' array which indicates what the index in shop_*path is
241  // for the materials it matlist.
242 #ifdef USE_MATERIAL_MAP
243  bool buildMaterialMap(const GT_Primitive *prim,
244  const RE_MaterialAtlas &mats,
245  UT_IntArray &matmap);
246 #endif
247 
248 
249  // Helpers for selection
250 
251  // implemented for: T = uint8, T = int32
252  template <typename T>
253  GR_SelectMode addToPointSelection(const UT_Span<T> &out_select,
254  const GU_Detail &geo,
255  const GT_DataArrayHandle &vh,
256  const GT_DataArrayHandle &vl,
257  const GA_PointGroup *pntsel,
258  bool use_vertex_for_point_select,
259  bool &init);
260 
261  GR_SelectMode addToVertexSelection(const UT_Span<uint8> &out_select,
262  const GU_Detail &geo,
263  const GT_DataArrayHandle &vh,
264  const GA_VertexGroup *vertsel,
265  bool &init);
266 
267  // implemented for: T = uint8, T = int32
268  template <typename T>
269  GR_SelectMode addToEdgeSelection(const UT_Span<T> &out_select,
270  const GU_Detail &geo,
271  const GT_DataArrayHandle &vt,
272  const GT_DataArrayHandle &vert_list,
273  const GA_EdgeGroup *edgesel,
274  bool &init);
275 
276  GR_SelectMode addToPrimSelection(const UT_Span<uint8> &out_select,
277  const GT_DataArrayHandle &vh,
278  const GA_PrimitiveGroup *primsel,
279  bool &init);
280 
281 public:
282  // For derived class's parallel helpers
283  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
284  const GU_ConstDetailHandle &geo,
285  int npoints);
286  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
287  const GU_ConstDetailHandle &geo);
288 
289  static bool createTanAttrib(UT_Vector4F *tan_data,
290  const GT_DataArray *nml,
291  const GT_DataArray *tanu,
292  const GT_DataArray *tanv,
293  const GT_DataArray *vlist);
294 
295  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
296  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
297 
298 protected:
303  unsigned myBuildPointInfo : 1,
304  myBuildPrimInfo : 1,
305  myHasDetailPrimID : 1,
306  myHasInstancedTransform : 1,
307  myHasIdentityTransform : 1,
308  myUseBoneDeform : 1,
309  myNumBoneDeform : 2,
310  myAllowGeoOverride : 1;
311 
319 
322 };
323 
324 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:313
GLbitfield flags
Definition: glcorearb.h:1596
int getCurrentLayer() const
Definition: GR_GeoRender.h:236
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:302
bool shouldBuildPrimID() const
Definition: GR_GeoRender.h:157
void setSelectionInstance(int i)
Definition: GR_GeoRender.h:172
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:174
GT_API const UT_StringHolder cache_name
GR_AttribMask getSelectionMask() const
Definition: GR_GeoRender.h:164
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:164
GR_AttribMask
Definition: GR_Defines.h:328
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:299
bool isVulkan() const
Definition: GR_GeoRender.h:53
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:300
Abstract data class for an array of float, int or string data.
Definition: GT_DataArray.h:40
GR_RenderMode
Definition: GR_Defines.h:47
GR_BasePrimType
Definition: GR_Defines.h:352
GR_Primitive * myParentPrim
Definition: GR_GeoRender.h:320
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:151
int myCurrentPointSelectInstance
Definition: GR_GeoRender.h:315
bool getDetailPrimID(int &id) const
Definition: GR_GeoRender.h:182
GLuint const GLchar * name
Definition: glcorearb.h:786
int myMaterialOverride
Definition: GR_GeoRender.h:316
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:167
GR_RenderFlags
Definition: GR_Defines.h:85
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:21
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:169
virtual RE_Geometry * getGeometry()
Definition: GR_GeoRender.h:96
void clearMaterialOverride()
Definition: GR_GeoRender.h:179
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:312
bool shouldBuildPointID() const
Definition: GR_GeoRender.h:159
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:301
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:295
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:177
type
Definition: core.h:1059
RenderType getRenderType() const
Definition: GR_GeoRender.h:149
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:314
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:162
GR_SelectMode
Definition: GR_Defines.h:229
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:296
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