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 methds that Houdini is natively capable of
10  * rendering with OpenGL.
11  */
12 #ifndef GR_GeoRender_H
13 #define GR_GeoRender_H
14 
15 class RE_ElementArray;
16 class RE_Geometry;
17 class RE_Render;
18 class RE_Shader;
19 class RE_VertexArray;
20 class OP_Node;
21 class GU_Detail;
22 class GR_DisplayOption;
23 class GR_RenderInfo;
24 class UT_StringArray;
25 class GT_CountArray;
26 class GA_BreakpointGroup;
27 class GR_Primitive;
28 
29 #include <RE/RE_Types.h>
30 #include <UT/UT_Array.h>
31 #include <UT/UT_Matrix4.h>
32 #include <UT/UT_UniquePtr.h>
33 #include <GT/GT_DataArray.h>
34 #include <GT/GT_Primitive.h>
35 #include <GA/GA_ElementGroup.h>
36 #include <GA/GA_EdgeGroup.h>
37 
38 #include "GR_DrawParms.h"
39 #include "GR_MaterialGroups.h"
40 #include "GR_UpdateParms.h"
41 #include "GR_ErrorManager.h"
42 
44 {
45 public:
46  GR_GeoRender(GR_Primitive *parent_prim);
47  virtual ~GR_GeoRender();
48 
49  virtual const char *className() const = 0;
50 
51  /// Update the geometry of this render object using the GT primitive. No
52  /// rendering commands should be issued.
53  virtual void update(RE_Render *r,
54  const GT_PrimitiveHandle &primh,
55  const GR_UpdateParms &p,
56  const char *cache_name) = 0;
57 
58  /// add an array to, or update an array in, an instance group. If
59  /// 'instance_group' is -1, RE_VertexArray must specify an instance group
60  /// via setInstanceGroup().
61  virtual void updateInstanceGroupArray(const RE_VertexArray *array,
62  int instance_group = -1,
63  const char *attrib_name = NULL,
66 
67  /// Called when the view changes, if the parent primitive requested view
68  /// changes
69  virtual void viewUpdate(RE_Render *r,
70  const GR_DisplayOption &opts,
71  const char *cache_name,
72  RE_CacheVersion geo_version,
73  RE_CacheVersion select_version)
74  {}
75 
76  /// Normal drawing method. Only issue rendering commands.
77  virtual void draw(RE_Render *r,
80  GR_DrawParms draw_parms) = 0;
81 
82  /// By default, no instanced drawing support.
83  virtual bool supportsInstances() const { return false; }
84 
85  RE_Geometry *createGeometry(int npoints = 0);
86  RE_Geometry *getGeometry() { return myGeometry; }
87  virtual bool isConvexed() const { return myConvexFlag; }
88 
89  /// Called if another entity makes changes to the RE_Geometry after update()
90  /// is called (usually the entity is a GR_Primitive object).
91  virtual void geometryUpdated(RE_Render *) {}
92 
93  /// returns true if this drawable renders some transparent elements
94  virtual bool hasTransparency() const { return false; }
95 
96 
97  /// return the number of GL primitives that this renderer produces. May be
98  /// roughly estimated.
99  virtual exint getNumGLPrimitives() const = 0;
100 
101  // Accessors to various high-level data
102  bool showSelections() const;
103  GR_RenderVersion getRenderVersion() const;
104 
105  virtual bool canFrustumCull() { return true; }
106  bool inViewFrustum(const UT_Matrix4D &objviewproj,
107  const UT_BoundingBoxD *bbox);
108  bool isRasterizedInView(
109  const UT_Matrix4F &objviewproj,
110  const UT_Vector2F &min_proj_size,
111  const UT_BoundingBoxF *bbox=nullptr);
112 
113  GR_BasePrimType getParentType() const;
114 
115  void buildInformation(bool prim_id,
116  bool point_id)
117  {
118  myBuildPrimInfo = prim_id;
119  myBuildPointInfo = point_id;
120  }
121  bool shouldBuildPrimID() const
122  { return myBuildPrimInfo; }
123  bool shouldBuildPointID() const
124  { return myBuildPointInfo; }
125 
126  void setSelectionMask(GR_AttribMask selection_mask)
127  { mySelectionMask = selection_mask; }
129  { return mySelectionMask; }
130 
132  { myCurrentSelection = m; }
134  { return myCurrentSelection; }
135 
137  { myCurrentPointSelectInstance = i; }
139  { return myCurrentPointSelectInstance; }
140 
141  void setMaterialOverride(int mat_index)
142  { myMaterialOverride = mat_index; }
144  { myMaterialOverride = -1; }
145 
146  bool getDetailPrimID(int &id) const
147  {
148  if(myHasDetailPrimID)
149  {
150  id = myDetailPrimID;
151  return true;
152  }
153  id = 0;
154  return false;
155  }
156 
157  virtual void retireGeometry();
158 
159  // Creates an RE_OverrideList (or adds to an existing one) for the color
160  // and uv overrides if required. Cleanup will undo any changes to the
161  // state setup made.
162  void setupGeoOverride(RE_Render *r,
163  const GR_DisplayOption *opt,
164  RE_Geometry *geo,
165  UT_UniquePtr<RE_OverrideList> &override_list);
166  void cleanupGeoOverride(RE_Render *r,
167  const GR_DisplayOption *opt,
168  RE_Geometry *geo);
169  void allowGeoOverride(bool allow_overrides);
170 
171  // Message and error reporting
172  void addUpdateMessage(GR_ErrorManager::Source err_source,
173  GR_ErrorCode gr_code,
174  UT_StringHolder extra_text=UT_StringHolder(),
175  UT_StringHolder src_name=UT_StringHolder());
176  void addUpdateWarning(GR_ErrorManager::Source err_source,
177  GR_ErrorCode gr_code,
178  UT_StringHolder extra_text=UT_StringHolder(),
179  UT_StringHolder src_name=UT_StringHolder());
180  void addUpdateError (GR_ErrorManager::Source err_source,
181  GR_ErrorCode gr_code,
182  UT_StringHolder extra_text=UT_StringHolder(),
183  UT_StringHolder src_name=UT_StringHolder());
184  void addUpdateFatal (GR_ErrorManager::Source err_source,
185  GR_ErrorCode gr_code,
186  UT_StringHolder extra_text=UT_StringHolder(),
187  UT_StringHolder src_name=UT_StringHolder());
188  void addRedrawMessage(GR_ErrorManager::Source err_source,
189  GR_ErrorCode gr_code,
190  UT_StringHolder extra_text=UT_StringHolder(),
191  UT_StringHolder src_name=UT_StringHolder());
192  void addRedrawWarning(GR_ErrorManager::Source err_source,
193  GR_ErrorCode gr_code,
194  UT_StringHolder extra_text=UT_StringHolder(),
195  UT_StringHolder src_name=UT_StringHolder());
196  void addRedrawError (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 addRedrawFatal (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 
205 
206  static RE_VertexArray *getDirtyAttribArray(
207  RE_Render *r,
208  RE_Geometry *geo,
209  const char *attrib_name,
210  const GT_DataArrayHandle &h,
211  const GR_DisplayOption &opts,
212  RE_ArrayType atype,
213  RE_CacheVersion attr_version);
214 
215  static void fillGeoAttribs(RE_Render *r,
216  const GT_Primitive *prim,
217  const GR_UpdateParms &p,
218  RE_Geometry *geo,
219  bool needs_nml,
220  bool needs_uv,
221  bool need_prim_vert_info,
222  const GT_DataArrayHandle &point_norm,
223  GR_BasePrimType packed_type,
224  bool build_point_id,
225  bool build_prim_id,
226  GR_GeoRender *geo_ren = nullptr,
227  bool *has_detail_prim_id = nullptr,
228  int *detail_prim_id = nullptr,
229  int *num_bone_deform = nullptr);
230 
231 protected:
232  void initLights(RE_Render *r,
233  RE_Shader *sh,
236  const GR_DisplayOption *opt);
237 
238  GR_AttribMask hasAttribute(const GT_Primitive *prim,
239  const char *name,
240  GT_DataArrayHandle &h) const;
241 
242  // For picking, these methods turn the GT __primitive_id, __vertex_id and
243  // points (__vertex_id + vertexlist)
244  void buildPointID(RE_Render *r,
245  const GT_Primitive &prim,
246  const GU_ConstDetailHandle &geo,
247  RE_CacheVersion geo_version);
248  void buildPrimitiveID(RE_Render *r,
249  const GT_Primitive &primh,
250  const GU_ConstDetailHandle &geo,
251  RE_CacheVersion geo_version);
252 
253  // GL32 stuff.
255  const GR_UpdateParms &parms,
256  RE_Geometry &obj,
257  const GT_PrimitiveHandle &primh,
258  const GT_DataArrayHandle &vertexlist);
259 
260  GR_SelectMode addToPointSelection(RE_Render *r,
261  RE_VertexArray *select_array,
262  int length,
263  const GU_Detail &geo,
264  const GT_DataArrayHandle &vh,
265  const GT_DataArrayHandle &vl,
266  const GA_PointGroup *pntsel,
267  bool use_vertex_for_point_select,
268  bool &init);
269 
270  GR_SelectMode addToVertexSelection(RE_Render *r,
271  RE_VertexArray *select_array,
272  int length,
273  const GU_Detail &geo,
274  const GT_DataArrayHandle &vh,
275  const GA_VertexGroup *vertsel,
276  bool &init);
277 
278  GR_SelectMode addToEdgeSelection(RE_Render *r,
279  RE_VertexArray *select_array,
280  int length,
281  const GU_Detail &geo,
282  const GT_DataArrayHandle &vt,
283  const GT_DataArrayHandle &vert_list,
284  const GA_EdgeGroup *edgesel,
285  bool &init);
286 
287  GR_SelectMode addToPrimSelection(RE_Render *r,
288  RE_VertexArray *sel_array,
289  const GT_DataArrayHandle &vh,
290  const GA_PrimitiveGroup *primsel,
291  bool &init);
292 
293  virtual GR_SelectMode addToBreakpointSelection(RE_Render *r,
295  int bpnt_len,
296  const GA_BreakpointGroup *bps,
297  bool &init);
298 
299  GR_SelectMode buildInstanceSelection(RE_Render *r,
300  const GR_UpdateParms &p,
301  RE_Geometry &obj);
302 
303  void fillAttributesGL3(RE_Render *r,
304  const GT_Primitive *prim,
305  const GR_UpdateParms &p,
306  RE_Geometry *geo,
307  bool needs_nml,
308  bool needs_uv,
309  bool need_prim_vert_info,
310  const GT_DataArrayHandle &point_norm);
311 
312  /// Set selection uniforms SELECT_MODE and SELECT_INSTANCE. Returns an int
313  /// which should be passed to cleanup selection.
314  virtual int setupSelection(RE_Render *r,
315  const GR_DisplayOption *opt,
316  GR_RenderFlags flags) const;
317 
318  /// Clean up selection uniforms; much be paired with a setupSelection().
319  virtual void cleanupSelection(RE_Render *r, int key) const;
320 
321  GT_PrimitiveHandle getCachedGTPrimitive();
322  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
323 
324  void updateWireColor(RE_Render *r,
325  RE_Geometry *geo,
326  const GR_DisplayOption *opt,
327  int start_draw_idx,
328  int num_draw_idx = 1) const;
329 
330  int getCurrentLayer() const
331  { return myCurrentLayer; }
332 
333  // for the materials in matlist, map them to the shop_*path in 'prim'.
334  // returns 'matmap' array which indicates what the index in shop_*path is
335  // for the materials it matlist.
336 #ifdef USE_MATERIAL_MAP
337  bool buildMaterialMap(const GT_Primitive *prim,
338  const RE_MaterialAtlas &mats,
339  UT_IntArray &matmap);
340 #endif
341 public:
342  // For derived class's parallel helpers
343  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
344  const GU_ConstDetailHandle &geo,
345  int npoints);
346  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
347  const GU_ConstDetailHandle &geo);
348 
349  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
350  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
351 
352 protected:
357  unsigned myBuildPointInfo : 1,
358  myBuildPrimInfo : 1,
359  myHasDetailPrimID : 1,
360  myHasInstancedTransform : 1,
361  myHasIdentityTransform : 1,
362  myUseBoneDeform : 1,
363  myNumBoneDeform : 2,
364  myAllowGeoOverride : 1;
365 
373 
374 private:
375  GR_Primitive *myParentPrim;
376  int myCurrentLayer;
377 };
378 
379 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:367
virtual void geometryUpdated(RE_Render *)
Definition: GR_GeoRender.h:91
GLuint const GLchar * name
Definition: glew.h:1814
int getCurrentLayer() const
Definition: GR_GeoRender.h:330
GLenum mode
Definition: glew.h:2163
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:356
bool shouldBuildPrimID() const
Definition: GR_GeoRender.h:121
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
Definition: glew.h:2864
RE_Geometry * myGeometry
Definition: GR_GeoRender.h:353
void setSelectionInstance(int i)
Definition: GR_GeoRender.h:136
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:138
GT_API const UT_StringHolder cache_name
GR_AttribMask getSelectionMask() const
Definition: GR_GeoRender.h:128
GR_AttribMask
Definition: GR_Defines.h:315
const GLdouble * m
Definition: glew.h:9124
GLhandleARB obj
Definition: glew.h:6236
A class that manages material assignments to different groups of primitives.
virtual bool canFrustumCull()
Definition: GR_GeoRender.h:105
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:33
set of parameters sent to GR_Primitive::update()
GT_API const UT_StringHolder point_id
RE_GenericAttribID
Definition: RE_Types.h:328
const GR_RenderInfo * myInfo
Definition: GR_GeoRender.h:354
GR_RenderMode
Definition: GR_Defines.h:44
GR_BasePrimType
Definition: GR_Defines.h:339
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4678
virtual bool isConvexed() const
Definition: GR_GeoRender.h:87
virtual bool hasTransparency() const
returns true if this drawable renders some transparent elements
Definition: GR_GeoRender.h:94
GLuint GLsizei GLsizei * length
Definition: glew.h:1825
#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:115
int myCurrentPointSelectInstance
Definition: GR_GeoRender.h:369
bool getDetailPrimID(int &id) const
Definition: GR_GeoRender.h:146
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
GR_API GR_SelectMode buildSelection(UT_Array< uint8 > &selected, const GR_UpdateParms &p, GT_DataArrayHandle prim_id, GT_DataArrayHandle pnt_id, GT_DataArrayHandle vert_id, bool is_offset, int repeat_count)
int myMaterialOverride
Definition: GR_GeoRender.h:370
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:131
GR_RenderFlags
Definition: GR_Defines.h:81
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GR_RenderVersion
Definition: GR_Defines.h:21
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
GR_SelectMode getSelectionDisplayMode() const
Definition: GR_GeoRender.h:133
void clearMaterialOverride()
Definition: GR_GeoRender.h:143
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:366
RE_ArrayType
Definition: RE_Types.h:317
bool shouldBuildPointID() const
Definition: GR_GeoRender.h:123
GLenum array
Definition: glew.h:9066
Simple class for a mutli-integer cache tag.
virtual bool supportsInstances() const
By default, no instanced drawing support.
Definition: GR_GeoRender.h:83
GR_MaterialGroups myMatGroups
Definition: GR_GeoRender.h:355
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:349
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:141
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:368
RE_Geometry * getGeometry()
Definition: GR_GeoRender.h:86
void setSelectionMask(GR_AttribMask selection_mask)
Definition: GR_GeoRender.h:126
GR_SelectMode
Definition: GR_Defines.h:220
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:350
virtual void viewUpdate(RE_Render *r, const GR_DisplayOption &opts, const char *cache_name, RE_CacheVersion geo_version, RE_CacheVersion select_version)
Definition: GR_GeoRender.h:69