HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 protected:
201  RE_VertexArray *getDirtyAttribArray(RE_Render *r,
202  const char *attrib_name,
203  const GT_DataArrayHandle &h,
204  const GR_DisplayOption &opts,
205  RE_ArrayType atype,
206  RE_CacheVersion attr_version);
207 
208  void initLights(RE_Render *r,
209  RE_Shader *sh,
212  const GR_DisplayOption *opt);
213 
214  GR_AttribMask hasAttribute(const GT_Primitive *prim,
215  const char *name,
216  GT_DataArrayHandle &h) const;
217 
218  // For picking, these methods turn the GT __primitive_id, __vertex_id and
219  // points (__vertex_id + vertexlist)
220  void buildPointID(RE_Render *r,
221  const GT_Primitive &prim,
222  const GU_ConstDetailHandle &geo,
223  RE_CacheVersion geo_version);
224  void buildPrimitiveID(RE_Render *r,
225  const GT_Primitive &primh,
226  const GU_ConstDetailHandle &geo,
227  RE_CacheVersion geo_version);
228 
229  // GL32 stuff.
231  const GR_UpdateParms &parms,
232  RE_Geometry &obj,
233  const GT_PrimitiveHandle &primh,
234  const GT_DataArrayHandle &vertexlist);
235 
236  GR_SelectMode addToPointSelection(RE_Render *r,
237  RE_VertexArray *select_array,
238  int length,
239  const GU_Detail &geo,
240  const GT_DataArrayHandle &vh,
241  const GT_DataArrayHandle &vl,
242  const GA_PointGroup *pntsel,
243  bool use_vertex_for_point_select,
244  bool &init);
245 
246  GR_SelectMode addToVertexSelection(RE_Render *r,
247  RE_VertexArray *select_array,
248  int length,
249  const GU_Detail &geo,
250  const GT_DataArrayHandle &vh,
251  const GA_VertexGroup *vertsel,
252  bool &init);
253 
254  GR_SelectMode addToEdgeSelection(RE_Render *r,
255  RE_VertexArray *select_array,
256  int length,
257  const GU_Detail &geo,
258  const GT_DataArrayHandle &vt,
259  const GT_DataArrayHandle &vert_list,
260  const GA_EdgeGroup *edgesel,
261  bool &init);
262 
263  GR_SelectMode addToPrimSelection(RE_Render *r,
264  RE_VertexArray *sel_array,
265  const GT_DataArrayHandle &vh,
266  const GA_PrimitiveGroup *primsel,
267  bool &init);
268 
269  virtual GR_SelectMode addToBreakpointSelection(RE_Render *r,
270  RE_VertexArray *select,
271  int bpnt_len,
272  const GA_BreakpointGroup *bps,
273  bool &init);
274 
275  GR_SelectMode buildInstanceSelection(RE_Render *r,
276  const GR_UpdateParms &p,
277  RE_Geometry &obj);
278 
279  void fillAttributesGL3(RE_Render *r,
280  const GT_Primitive *prim,
281  const GR_UpdateParms &p,
282  RE_Geometry *geo,
283  bool fast_pnt,
284  bool needs_nml,
285  bool needs_uv,
286  bool need_prim_vert_info,
287  const GT_DataArrayHandle &point_norm);
288 
289  /// Set selection uniforms SELECT_MODE and SELECT_INSTANCE. Returns an int
290  /// which should be passed to cleanup selection.
291  virtual int setupSelection(RE_Render *r,
292  const GR_DisplayOption *opt,
293  GR_RenderFlags flags) const;
294 
295  /// Clean up selection uniforms; much be paired with a setupSelection().
296  virtual void cleanupSelection(RE_Render *r, int key) const;
297 
298  GT_PrimitiveHandle getCachedGTPrimitive();
299  void cacheGTPrimitive(GT_PrimitiveHandle &primh);
300 
301  void updateWireColor(RE_Render *r,
302  RE_Geometry *geo,
303  const GR_DisplayOption *opt,
304  int start_draw_idx,
305  int num_draw_idx = 1) const;
306 
307  int getCurrentLayer() const
308  { return myCurrentLayer; }
309 
310  // for the materials in matlist, map them to the shop_*path in 'prim'.
311  // returns 'matmap' array which indicates what the index in shop_*path is
312  // for the materials it matlist.
313 #ifdef USE_MATERIAL_MAP
314  bool buildMaterialMap(const GT_Primitive *prim,
315  const RE_MaterialAtlas &mats,
316  UT_IntArray &matmap);
317 #endif
318 public:
319  // For derived class's parallel helpers
320  GT_DataArrayHandle buildPointIDData(const GT_Primitive &prim,
321  const GU_ConstDetailHandle &geo,
322  int npoints);
323  GT_DataArrayHandle buildPrimitiveIDData(const GT_Primitive &prim,
324  const GU_ConstDetailHandle &geo);
325 
326  void setGeoBounds(const UT_BoundingBox &b) { myBounds = b; }
327  const UT_BoundingBoxD &getGeoBounds() const { return myBounds; }
328 
329 protected:
334  unsigned myBuildPointInfo : 1,
335  myBuildPrimInfo : 1,
336  myHasDetailPrimID : 1,
337  myHasInstancedTransform : 1,
338  myHasIdentityTransform : 1,
339  myUseBoneDeform : 1,
340  myNumBoneDeform : 2;
341 
349 
350 private:
351  GR_Primitive *myParentPrim;
352  int myCurrentLayer;
353 };
354 
355 #endif
GR_AttribMask mySelectionMask
Definition: GR_GeoRender.h:343
virtual void geometryUpdated(RE_Render *)
Definition: GR_GeoRender.h:91
int getCurrentLayer() const
Definition: GR_GeoRender.h:307
GR_ErrorCode
Definition: GR_Error.h:16
UT_BoundingBoxD myBounds
Definition: GR_GeoRender.h:333
bool shouldBuildPrimID() const
Definition: GR_GeoRender.h:116
RE_Geometry * myGeometry
Definition: GR_GeoRender.h:330
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
GR_AttribMask getSelectionMask() const
Definition: GR_GeoRender.h:123
GR_AttribMask
Definition: GR_Defines.h:303
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()
RE_GenericAttribID
Definition: RE_Types.h:321
const GR_RenderInfo * myInfo
Definition: GR_GeoRender.h:331
GR_RenderMode
Definition: GR_Defines.h:42
GR_BasePrimType
Definition: GR_Defines.h:327
int64 exint
Definition: SYS_Types.h:109
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:345
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:346
GLuint const GLchar * name
Definition: glcorearb.h:785
void setSelectionDisplayMode(GR_SelectMode m)
Definition: GR_GeoRender.h:126
GR_RenderFlags
Definition: GR_Defines.h:77
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1221
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
GR_RenderVersion
Definition: GR_Defines.h:19
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:342
RE_ArrayType
Definition: RE_Types.h:310
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:332
void setGeoBounds(const UT_BoundingBox &b)
Definition: GR_GeoRender.h:326
void setMaterialOverride(int mat_index)
Definition: GR_GeoRender.h:136
GR_SelectMode myCurrentSelection
Definition: GR_GeoRender.h:344
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:215
const UT_BoundingBoxD & getGeoBounds() const
Definition: GR_GeoRender.h:327
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