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 needs_tangent,
222  bool need_prim_vert_info,
223  const GT_DataArrayHandle &point_norm,
224  GR_BasePrimType packed_type,
225  bool build_point_id,
226  bool build_prim_id,
227  GR_GeoRender *geo_ren = nullptr,
228  bool *has_detail_prim_id = nullptr,
229  int *detail_prim_id = nullptr,
230  int *num_bone_deform = nullptr);
231 
232 protected:
233  void initLights(RE_Render *r,
234  RE_Shader *sh,
237  const GR_DisplayOption *opt);
238 
239  GR_AttribMask hasAttribute(const GT_Primitive *prim,
240  const char *name,
241  GT_DataArrayHandle &h) const;
242 
243  // For picking, these methods turn the GT __primitive_id, __vertex_id and
244  // points (__vertex_id + vertexlist)
245  void buildPointID(RE_Render *r,
246  const GT_Primitive &prim,
247  const GU_ConstDetailHandle &geo,
248  RE_CacheVersion geo_version);
249  void buildPrimitiveID(RE_Render *r,
250  const GT_Primitive &primh,
251  const GU_ConstDetailHandle &geo,
252  RE_CacheVersion geo_version);
253 
254  // GL32 stuff.
256  const GR_UpdateParms &parms,
257  RE_Geometry &obj,
258  const GT_PrimitiveHandle &primh,
259  const GT_DataArrayHandle &vertexlist);
260 
261  GR_SelectMode addToPointSelection(RE_Render *r,
262  RE_VertexArray *select_array,
263  int length,
264  const GU_Detail &geo,
265  const GT_DataArrayHandle &vh,
266  const GT_DataArrayHandle &vl,
267  const GA_PointGroup *pntsel,
268  bool use_vertex_for_point_select,
269  bool &init);
270 
271  GR_SelectMode addToVertexSelection(RE_Render *r,
272  RE_VertexArray *select_array,
273  int length,
274  const GU_Detail &geo,
275  const GT_DataArrayHandle &vh,
276  const GA_VertexGroup *vertsel,
277  bool &init);
278 
279  GR_SelectMode addToEdgeSelection(RE_Render *r,
280  RE_VertexArray *select_array,
281  int length,
282  const GU_Detail &geo,
283  const GT_DataArrayHandle &vt,
284  const GT_DataArrayHandle &vert_list,
285  const GA_EdgeGroup *edgesel,
286  bool &init);
287 
288  GR_SelectMode addToPrimSelection(RE_Render *r,
289  RE_VertexArray *sel_array,
290  const GT_DataArrayHandle &vh,
291  const GA_PrimitiveGroup *primsel,
292  bool &init);
293 
294  virtual GR_SelectMode addToBreakpointSelection(RE_Render *r,
296  int bpnt_len,
297  const GA_BreakpointGroup *bps,
298  bool &init);
299 
300  GR_SelectMode buildInstanceSelection(RE_Render *r,
301  const GR_UpdateParms &p,
302  RE_Geometry &obj);
303 
304  void fillAttributesGL3(RE_Render *r,
305  const GT_Primitive *prim,
306  const GR_UpdateParms &p,
307  RE_Geometry *geo,
308  bool needs_nml,
309  bool needs_uv,
310  bool needs_tangent,
311  bool need_prim_vert_info,
312  const GT_DataArrayHandle &point_norm);
313 
314  /// Set selection uniforms SELECT_MODE and SELECT_INSTANCE. Returns an int
315  /// which should be passed to cleanup selection.
316  virtual int setupSelection(RE_Render *r,
317  const GR_DisplayOption *opt,
319  bool supports_outline = false) const;
320 
321  /// Clean up selection uniforms; much be paired with a setupSelection().
322  virtual void cleanupSelection(RE_Render *r, int key) const;
323 
324  GT_PrimitiveHandle getCachedGTPrimitive();
325  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
326 
327  void updateWireColor(RE_Render *r,
328  RE_Geometry *geo,
329  const GR_DisplayOption *opt,
330  int start_draw_idx,
331  int num_draw_idx = 1) const;
332 
333  int getCurrentLayer() const
334  { return myCurrentLayer; }
335 
336  // for the materials in matlist, map them to the shop_*path in 'prim'.
337  // returns 'matmap' array which indicates what the index in shop_*path is
338  // for the materials it matlist.
339 #ifdef USE_MATERIAL_MAP
340  bool buildMaterialMap(const GT_Primitive *prim,
341  const RE_MaterialAtlas &mats,
342  UT_IntArray &matmap);
343 #endif
344 public:
345  // For derived class's parallel helpers
346  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
347  const GU_ConstDetailHandle &geo,
348  int npoints);
349  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
350  const GU_ConstDetailHandle &geo);
351 
352  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
353  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
354 
355 protected:
360  unsigned myBuildPointInfo : 1,
361  myBuildPrimInfo : 1,
362  myHasDetailPrimID : 1,
363  myHasInstancedTransform : 1,
364  myHasIdentityTransform : 1,
365  myUseBoneDeform : 1,
366  myNumBoneDeform : 2,
367  myAllowGeoOverride : 1;
368 
376 
377 private:
378  GR_Primitive *myParentPrim;
379  int myCurrentLayer;
380 };
381 
382 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:370
virtual void geometryUpdated(RE_Render *)
Definition: GR_GeoRender.h:91
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
int getCurrentLayer() const
Definition: GR_GeoRender.h:333
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:359
bool shouldBuildPrimID() const
Definition: GR_GeoRender.h:121
RE_Geometry * myGeometry
Definition: GR_GeoRender.h:356
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:323
GLuint const GLchar * name
Definition: glcorearb.h:786
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:39
set of parameters sent to GR_Primitive::update()
GT_API const UT_StringHolder point_id
RE_GenericAttribID
Definition: RE_Types.h:329
const GR_RenderInfo * myInfo
Definition: GR_GeoRender.h:357
GLenum array
Definition: glew.h:9108
GR_RenderMode
Definition: GR_Defines.h:46
GR_BasePrimType
Definition: GR_Defines.h:347
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4816
virtual bool isConvexed() const
Definition: GR_GeoRender.h:87
GLhandleARB obj
Definition: glew.h:6266
virtual bool hasTransparency() const
returns true if this drawable renders some transparent elements
Definition: GR_GeoRender.h:94
#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:372
GLfloat GLfloat p
Definition: glew.h:16656
bool getDetailPrimID(int &id) const
Definition: GR_GeoRender.h:146
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:373
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:131
GR_RenderFlags
Definition: GR_Defines.h:84
GLbitfield flags
Definition: glcorearb.h:1596
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GR_RenderVersion
Definition: GR_Defines.h:21
GLenum mode
Definition: glcorearb.h:99
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
GR_SelectMode getSelectionDisplayMode() const
Definition: GR_GeoRender.h:133
void clearMaterialOverride()
Definition: GR_GeoRender.h:143
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:369
RE_ArrayType
Definition: RE_Types.h:318
bool shouldBuildPointID() const
Definition: GR_GeoRender.h:123
const GLdouble * m
Definition: glew.h:9166
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:358
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:352
GLboolean r
Definition: glcorearb.h:1222
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:141
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:371
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:224
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:353
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