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 
170  // Message and error reporting
171  void addUpdateMessage(GR_ErrorManager::Source err_source,
172  GR_ErrorCode gr_code,
173  UT_StringHolder extra_text=UT_StringHolder(),
174  UT_StringHolder src_name=UT_StringHolder());
175  void addUpdateWarning(GR_ErrorManager::Source err_source,
176  GR_ErrorCode gr_code,
177  UT_StringHolder extra_text=UT_StringHolder(),
178  UT_StringHolder src_name=UT_StringHolder());
179  void addUpdateError (GR_ErrorManager::Source err_source,
180  GR_ErrorCode gr_code,
181  UT_StringHolder extra_text=UT_StringHolder(),
182  UT_StringHolder src_name=UT_StringHolder());
183  void addUpdateFatal (GR_ErrorManager::Source err_source,
184  GR_ErrorCode gr_code,
185  UT_StringHolder extra_text=UT_StringHolder(),
186  UT_StringHolder src_name=UT_StringHolder());
187  void addRedrawMessage(GR_ErrorManager::Source err_source,
188  GR_ErrorCode gr_code,
189  UT_StringHolder extra_text=UT_StringHolder(),
190  UT_StringHolder src_name=UT_StringHolder());
191  void addRedrawWarning(GR_ErrorManager::Source err_source,
192  GR_ErrorCode gr_code,
193  UT_StringHolder extra_text=UT_StringHolder(),
194  UT_StringHolder src_name=UT_StringHolder());
195  void addRedrawError (GR_ErrorManager::Source err_source,
196  GR_ErrorCode gr_code,
197  UT_StringHolder extra_text=UT_StringHolder(),
198  UT_StringHolder src_name=UT_StringHolder());
199  void addRedrawFatal (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 
204 
205  static RE_VertexArray *getDirtyAttribArray(
206  RE_Render *r,
207  RE_Geometry *geo,
208  const char *attrib_name,
209  const GT_DataArrayHandle &h,
210  const GR_DisplayOption &opts,
211  RE_ArrayType atype,
212  RE_CacheVersion attr_version);
213 
214  static void fillGeoAttribs(RE_Render *r,
215  const GT_Primitive *prim,
216  const GR_UpdateParms &p,
217  RE_Geometry *geo,
218  bool needs_nml,
219  bool needs_uv,
220  bool need_prim_vert_info,
221  const GT_DataArrayHandle &point_norm,
222  GR_BasePrimType packed_type,
223  bool build_point_id,
224  bool build_prim_id,
225  GR_GeoRender *geo_ren = nullptr,
226  bool *has_detail_prim_id = nullptr,
227  int *detail_prim_id = nullptr,
228  int *num_bone_deform = nullptr);
229 
230 protected:
231  void initLights(RE_Render *r,
232  RE_Shader *sh,
235  const GR_DisplayOption *opt);
236 
237  GR_AttribMask hasAttribute(const GT_Primitive *prim,
238  const char *name,
239  GT_DataArrayHandle &h) const;
240 
241  // For picking, these methods turn the GT __primitive_id, __vertex_id and
242  // points (__vertex_id + vertexlist)
243  void buildPointID(RE_Render *r,
244  const GT_Primitive &prim,
245  const GU_ConstDetailHandle &geo,
246  RE_CacheVersion geo_version);
247  void buildPrimitiveID(RE_Render *r,
248  const GT_Primitive &primh,
249  const GU_ConstDetailHandle &geo,
250  RE_CacheVersion geo_version);
251 
252  // GL32 stuff.
254  const GR_UpdateParms &parms,
255  RE_Geometry &obj,
256  const GT_PrimitiveHandle &primh,
257  const GT_DataArrayHandle &vertexlist);
258 
259  GR_SelectMode addToPointSelection(RE_Render *r,
260  RE_VertexArray *select_array,
261  int length,
262  const GU_Detail &geo,
263  const GT_DataArrayHandle &vh,
264  const GT_DataArrayHandle &vl,
265  const GA_PointGroup *pntsel,
266  bool use_vertex_for_point_select,
267  bool &init);
268 
269  GR_SelectMode addToVertexSelection(RE_Render *r,
270  RE_VertexArray *select_array,
271  int length,
272  const GU_Detail &geo,
273  const GT_DataArrayHandle &vh,
274  const GA_VertexGroup *vertsel,
275  bool &init);
276 
277  GR_SelectMode addToEdgeSelection(RE_Render *r,
278  RE_VertexArray *select_array,
279  int length,
280  const GU_Detail &geo,
281  const GT_DataArrayHandle &vt,
282  const GT_DataArrayHandle &vert_list,
283  const GA_EdgeGroup *edgesel,
284  bool &init);
285 
286  GR_SelectMode addToPrimSelection(RE_Render *r,
287  RE_VertexArray *sel_array,
288  const GT_DataArrayHandle &vh,
289  const GA_PrimitiveGroup *primsel,
290  bool &init);
291 
292  virtual GR_SelectMode addToBreakpointSelection(RE_Render *r,
294  int bpnt_len,
295  const GA_BreakpointGroup *bps,
296  bool &init);
297 
298  GR_SelectMode buildInstanceSelection(RE_Render *r,
299  const GR_UpdateParms &p,
300  RE_Geometry &obj);
301 
302  void fillAttributesGL3(RE_Render *r,
303  const GT_Primitive *prim,
304  const GR_UpdateParms &p,
305  RE_Geometry *geo,
306  bool needs_nml,
307  bool needs_uv,
308  bool need_prim_vert_info,
309  const GT_DataArrayHandle &point_norm);
310 
311  /// Set selection uniforms SELECT_MODE and SELECT_INSTANCE. Returns an int
312  /// which should be passed to cleanup selection.
313  virtual int setupSelection(RE_Render *r,
314  const GR_DisplayOption *opt,
315  GR_RenderFlags flags) const;
316 
317  /// Clean up selection uniforms; much be paired with a setupSelection().
318  virtual void cleanupSelection(RE_Render *r, int key) const;
319 
320  GT_PrimitiveHandle getCachedGTPrimitive();
321  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
322 
323  void updateWireColor(RE_Render *r,
324  RE_Geometry *geo,
325  const GR_DisplayOption *opt,
326  int start_draw_idx,
327  int num_draw_idx = 1) const;
328 
329  int getCurrentLayer() const
330  { return myCurrentLayer; }
331 
332  // for the materials in matlist, map them to the shop_*path in 'prim'.
333  // returns 'matmap' array which indicates what the index in shop_*path is
334  // for the materials it matlist.
335 #ifdef USE_MATERIAL_MAP
336  bool buildMaterialMap(const GT_Primitive *prim,
337  const RE_MaterialAtlas &mats,
338  UT_IntArray &matmap);
339 #endif
340 public:
341  // For derived class's parallel helpers
342  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
343  const GU_ConstDetailHandle &geo,
344  int npoints);
345  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
346  const GU_ConstDetailHandle &geo);
347 
348  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
349  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
350 
351 protected:
356  unsigned myBuildPointInfo : 1,
357  myBuildPrimInfo : 1,
358  myHasDetailPrimID : 1,
359  myHasInstancedTransform : 1,
360  myHasIdentityTransform : 1,
361  myUseBoneDeform : 1,
362  myNumBoneDeform : 2;
363 
371 
372 private:
373  GR_Primitive *myParentPrim;
374  int myCurrentLayer;
375 };
376 
377 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:365
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:329
GLenum mode
Definition: glew.h:2163
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:355
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:352
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
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:314
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
set of parameters sent to GR_Primitive::update()
GT_API const UT_StringHolder point_id
RE_GenericAttribID
Definition: RE_Types.h:323
const GR_RenderInfo * myInfo
Definition: GR_GeoRender.h:353
GR_RenderMode
Definition: GR_Defines.h:44
GR_BasePrimType
Definition: GR_Defines.h:338
vint4 select(const vbool4 &mask, const vint4 &a, const vint4 &b)
Definition: simd.h:4678
int64 exint
Definition: SYS_Types.h:120
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:367
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:368
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:131
GR_RenderFlags
Definition: GR_Defines.h:80
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
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:47
void clearMaterialOverride()
Definition: GR_GeoRender.h:143
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:364
RE_ArrayType
Definition: RE_Types.h:312
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:354
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:348
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:141
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:366
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:219
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:349
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