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 
108  GR_BasePrimType getParentType() const;
109 
110  void buildInformation(bool prim_id,
111  bool point_id)
112  {
113  myBuildPrimInfo = prim_id;
114  myBuildPointInfo = point_id;
115  }
116  bool shouldBuildPrimID() const
117  { return myBuildPrimInfo; }
118  bool shouldBuildPointID() const
119  { return myBuildPointInfo; }
120 
121  void setSelectionMask(GR_AttribMask selection_mask)
122  { mySelectionMask = selection_mask; }
124  { return mySelectionMask; }
125 
127  { myCurrentSelection = m; }
129  { return myCurrentSelection; }
130 
132  { myCurrentPointSelectInstance = i; }
134  { return myCurrentPointSelectInstance; }
135 
136  void setMaterialOverride(int mat_index)
137  { myMaterialOverride = mat_index; }
139  { myMaterialOverride = -1; }
140 
141  bool getDetailPrimID(int &id) const
142  {
143  if(myHasDetailPrimID)
144  {
145  id = myDetailPrimID;
146  return true;
147  }
148  id = 0;
149  return false;
150  }
151 
152  virtual void retireGeometry();
153 
154  // Creates an RE_OverrideList (or adds to an existing one) for the color
155  // and uv overrides if required. Cleanup will undo any changes to the
156  // state setup made.
157  void setupGeoOverride(RE_Render *r,
158  const GR_DisplayOption *opt,
159  RE_Geometry *geo,
160  UT_UniquePtr<RE_OverrideList> &override_list);
161  void cleanupGeoOverride(RE_Render *r,
162  const GR_DisplayOption *opt,
163  RE_Geometry *geo);
164 
165  // Message and error reporting
166  void addUpdateMessage(GR_ErrorManager::Source err_source,
167  GR_ErrorCode gr_code,
168  UT_StringHolder extra_text=UT_StringHolder(),
169  UT_StringHolder src_name=UT_StringHolder());
170  void addUpdateWarning(GR_ErrorManager::Source err_source,
171  GR_ErrorCode gr_code,
172  UT_StringHolder extra_text=UT_StringHolder(),
173  UT_StringHolder src_name=UT_StringHolder());
174  void addUpdateError (GR_ErrorManager::Source err_source,
175  GR_ErrorCode gr_code,
176  UT_StringHolder extra_text=UT_StringHolder(),
177  UT_StringHolder src_name=UT_StringHolder());
178  void addUpdateFatal (GR_ErrorManager::Source err_source,
179  GR_ErrorCode gr_code,
180  UT_StringHolder extra_text=UT_StringHolder(),
181  UT_StringHolder src_name=UT_StringHolder());
182  void addRedrawMessage(GR_ErrorManager::Source err_source,
183  GR_ErrorCode gr_code,
184  UT_StringHolder extra_text=UT_StringHolder(),
185  UT_StringHolder src_name=UT_StringHolder());
186  void addRedrawWarning(GR_ErrorManager::Source err_source,
187  GR_ErrorCode gr_code,
188  UT_StringHolder extra_text=UT_StringHolder(),
189  UT_StringHolder src_name=UT_StringHolder());
190  void addRedrawError (GR_ErrorManager::Source err_source,
191  GR_ErrorCode gr_code,
192  UT_StringHolder extra_text=UT_StringHolder(),
193  UT_StringHolder src_name=UT_StringHolder());
194  void addRedrawFatal (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 
199 
200  static RE_VertexArray *getDirtyAttribArray(
201  RE_Render *r,
202  RE_Geometry *geo,
203  const char *attrib_name,
204  const GT_DataArrayHandle &h,
205  const GR_DisplayOption &opts,
206  RE_ArrayType atype,
207  RE_CacheVersion attr_version);
208 
209  static void fillGeoAttribs(RE_Render *r,
210  const GT_Primitive *prim,
211  const GR_UpdateParms &p,
212  RE_Geometry *geo,
213  bool needs_nml,
214  bool needs_uv,
215  bool need_prim_vert_info,
216  const GT_DataArrayHandle &point_norm,
217  GR_BasePrimType packed_type,
218  bool build_point_id,
219  bool build_prim_id,
220  GR_GeoRender *geo_ren = nullptr,
221  bool *has_detail_prim_id = nullptr,
222  int *detail_prim_id = nullptr,
223  int *num_bone_deform = nullptr);
224 
225 protected:
226  void initLights(RE_Render *r,
227  RE_Shader *sh,
230  const GR_DisplayOption *opt);
231 
232  GR_AttribMask hasAttribute(const GT_Primitive *prim,
233  const char *name,
234  GT_DataArrayHandle &h) const;
235 
236  // For picking, these methods turn the GT __primitive_id, __vertex_id and
237  // points (__vertex_id + vertexlist)
238  void buildPointID(RE_Render *r,
239  const GT_Primitive &prim,
240  const GU_ConstDetailHandle &geo,
241  RE_CacheVersion geo_version);
242  void buildPrimitiveID(RE_Render *r,
243  const GT_Primitive &primh,
244  const GU_ConstDetailHandle &geo,
245  RE_CacheVersion geo_version);
246 
247  // GL32 stuff.
249  const GR_UpdateParms &parms,
250  RE_Geometry &obj,
251  const GT_PrimitiveHandle &primh,
252  const GT_DataArrayHandle &vertexlist);
253 
254  GR_SelectMode addToPointSelection(RE_Render *r,
255  RE_VertexArray *select_array,
256  int length,
257  const GU_Detail &geo,
258  const GT_DataArrayHandle &vh,
259  const GT_DataArrayHandle &vl,
260  const GA_PointGroup *pntsel,
261  bool use_vertex_for_point_select,
262  bool &init);
263 
264  GR_SelectMode addToVertexSelection(RE_Render *r,
265  RE_VertexArray *select_array,
266  int length,
267  const GU_Detail &geo,
268  const GT_DataArrayHandle &vh,
269  const GA_VertexGroup *vertsel,
270  bool &init);
271 
272  GR_SelectMode addToEdgeSelection(RE_Render *r,
273  RE_VertexArray *select_array,
274  int length,
275  const GU_Detail &geo,
276  const GT_DataArrayHandle &vt,
277  const GT_DataArrayHandle &vert_list,
278  const GA_EdgeGroup *edgesel,
279  bool &init);
280 
281  GR_SelectMode addToPrimSelection(RE_Render *r,
282  RE_VertexArray *sel_array,
283  const GT_DataArrayHandle &vh,
284  const GA_PrimitiveGroup *primsel,
285  bool &init);
286 
287  virtual GR_SelectMode addToBreakpointSelection(RE_Render *r,
288  RE_VertexArray *select,
289  int bpnt_len,
290  const GA_BreakpointGroup *bps,
291  bool &init);
292 
293  GR_SelectMode buildInstanceSelection(RE_Render *r,
294  const GR_UpdateParms &p,
295  RE_Geometry &obj);
296 
297  void fillAttributesGL3(RE_Render *r,
298  const GT_Primitive *prim,
299  const GR_UpdateParms &p,
300  RE_Geometry *geo,
301  bool needs_nml,
302  bool needs_uv,
303  bool need_prim_vert_info,
304  const GT_DataArrayHandle &point_norm);
305 
306  /// Set selection uniforms SELECT_MODE and SELECT_INSTANCE. Returns an int
307  /// which should be passed to cleanup selection.
308  virtual int setupSelection(RE_Render *r,
309  const GR_DisplayOption *opt,
310  GR_RenderFlags flags) const;
311 
312  /// Clean up selection uniforms; much be paired with a setupSelection().
313  virtual void cleanupSelection(RE_Render *r, int key) const;
314 
315  GT_PrimitiveHandle getCachedGTPrimitive();
316  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
317 
318  void updateWireColor(RE_Render *r,
319  RE_Geometry *geo,
320  const GR_DisplayOption *opt,
321  int start_draw_idx,
322  int num_draw_idx = 1) const;
323 
324  int getCurrentLayer() const
325  { return myCurrentLayer; }
326 
327  // for the materials in matlist, map them to the shop_*path in 'prim'.
328  // returns 'matmap' array which indicates what the index in shop_*path is
329  // for the materials it matlist.
330 #ifdef USE_MATERIAL_MAP
331  bool buildMaterialMap(const GT_Primitive *prim,
332  const RE_MaterialAtlas &mats,
333  UT_IntArray &matmap);
334 #endif
335 public:
336  // For derived class's parallel helpers
337  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
338  const GU_ConstDetailHandle &geo,
339  int npoints);
340  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
341  const GU_ConstDetailHandle &geo);
342 
343  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
344  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
345 
346 protected:
351  unsigned myBuildPointInfo : 1,
352  myBuildPrimInfo : 1,
353  myHasDetailPrimID : 1,
354  myHasInstancedTransform : 1,
355  myHasIdentityTransform : 1,
356  myUseBoneDeform : 1,
357  myNumBoneDeform : 2;
358 
366 
367 private:
368  GR_Primitive *myParentPrim;
369  int myCurrentLayer;
370 };
371 
372 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:360
virtual void geometryUpdated(RE_Render *)
Definition: GR_GeoRender.h:91
int getCurrentLayer() const
Definition: GR_GeoRender.h:324
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:350
bool shouldBuildPrimID() const
Definition: GR_GeoRender.h:116
RE_Geometry * myGeometry
Definition: GR_GeoRender.h:347
void setSelectionInstance(int i)
Definition: GR_GeoRender.h:131
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:133
GT_API const UT_StringHolder cache_name
GR_AttribMask getSelectionMask() const
Definition: GR_GeoRender.h:123
GR_AttribMask
Definition: GR_Defines.h:311
GLbitfield flags
Definition: glcorearb.h:1595
A class that manages material assignments to different groups of primitives.
png_uint_32 i
Definition: png.h:2877
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:348
GR_RenderMode
Definition: GR_Defines.h:44
GR_BasePrimType
Definition: GR_Defines.h:335
int64 exint
Definition: SYS_Types.h:116
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
#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:110
int myCurrentPointSelectInstance
Definition: GR_GeoRender.h:362
bool getDetailPrimID(int &id) const
Definition: GR_GeoRender.h:141
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:363
GLuint const GLchar * name
Definition: glcorearb.h:785
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:126
GR_RenderFlags
Definition: GR_Defines.h:79
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
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:98
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GR_SelectMode getSelectionDisplayMode() const
Definition: GR_GeoRender.h:128
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:47
void clearMaterialOverride()
Definition: GR_GeoRender.h:138
UT_Matrix4D myPrimitiveTransform
Definition: GR_GeoRender.h:359
RE_ArrayType
Definition: RE_Types.h:312
bool shouldBuildPointID() const
Definition: GR_GeoRender.h:118
Simple class for a mutli-integer cache tag.
virtual bool supportsInstances() const
By default, no instanced drawing support.
Definition: GR_GeoRender.h:83
GLboolean r
Definition: glcorearb.h:1221
GR_MaterialGroups myMatGroups
Definition: GR_GeoRender.h:349
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:343
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:136
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:361
RE_Geometry * getGeometry()
Definition: GR_GeoRender.h:86
void setSelectionMask(GR_AttribMask selection_mask)
Definition: GR_GeoRender.h:121
GR_SelectMode
Definition: GR_Defines.h:217
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:344
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
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794