HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_Utils.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_Utils.h ( GR Library, C++)
7  *
8  * COMMENTS:
9  * Utility functions for GR.
10  */
11 #ifndef GR_Utils_h
12 #define GR_Utils_h
13 
14 #include "GR_API.h"
15 #include "GR_Defines.h"
16 #include "GR_UpdateParms.h"
17 
18 #include <GT/GT_Primitive.h>
19 #include <GT/GT_Types.h>
20 #include <GU/GU_SelectType.h>
21 #include <GA/GA_Types.h>
22 #include <RE/RE_CachedObject.h>
23 #include <RE/RE_Types.h>
24 #include <UT/UT_VectorTypes.h>
25 
26 #include <utility>
27 
28 class RE_Render;
29 class RE_VertexArray;
30 class RE_VertexArrayRef;
31 class RE_Geometry;
32 class RE_Shader;
33 class GR_DisplayOption;
34 class UT_WorkBuffer;
35 
36 /// Utility GR methods common to all renderers
37 namespace GR_Utils
38 {
39 /// Returns the selection type in p.geometry
41 
42 /// Returns true if prim_id is in the selection list for p.geometry
43 /// If geo is given it must be the unlocked p.geometry from a ReadLock
44 GR_API extern bool inPrimitiveSelection(const GR_UpdateParms &p,
45  GA_Offset prim_id,
46  const GU_Detail *geo = nullptr);
47 
48 /// Returns true if point_id is in the selection list for p.geometry
49 GR_API extern bool inPointSelection(const GR_UpdateParms &p,
51  const GU_Detail *geo = nullptr);
52 
53 /// Returns true if vert_id is in the selection list for p.geometry
54 GR_API extern bool inVertexSelection(const GR_UpdateParms &p,
55  GA_Offset vert_id,
56  const GU_Detail *geo = nullptr);
57 
58 /// @brief Checks if passed prim offsets are in p.geometry's selection.
59 /// Returns GR_SELECT_PRIM_PARTIAL/FULL if some or all of the prim offsets
60 /// are in the cook or temp selections, as indicated by the parms in p,
61 /// otherwise GR_SELECT_NONE is returned. The individual selection results
62 /// are returned in 'selected'
64  const UT_Array<GA_Offset>&pids,
65  UT_BitArray &selected);
66 
67 /// @brief Checks if passed point offsets are in p.geometry's selection.
68 /// Returns GR_SELECT_POINT_PARTIAL/FULL if some or all of the point offsets
69 /// are in the cook or temp selections, as indicated by the parms in p,
70 /// otherwise GR_SELECT_NONE is returned. The individual selection results
71 /// are returned in 'selected'
73  const UT_Array<GA_Offset> &pids,
74  UT_BitArray &selected);
75 
76 /// @brief Checks if passed vertex offsets are in p.geometry's selection.
78  const UT_Array<GA_Offset> &vids,
79  UT_BitArray &selected);
80 
81 /// Return the cache version for attribute 'ph'
83  RE_CacheVersion geo_version);
84 
85 /// Return the cache version for the topology of primitive 'prim'
87  RE_CacheVersion geo_version);
88 
89 /// Return true if the geometry has a per-prim transform or per-prim visibility
90 GR_API extern bool hasPrimTransform(const RE_Geometry *geo);
91 
92 // Call setupGhosting() to set up wire-ghosting (or other sample-based
93 // ghosting effects). opaque_data[] is just used to clean up correctly.
94 // transparency (1.0 - opacity) is rounded up to the nearest multiple of
95 // 1/s where s is the number of samples (at least 4 for ghosting to work).
96 GR_API extern void setupGhosting (RE_Render *r, int opaque_data[3],
97  fpreal transparency = 0.25f);
98 GR_API extern void cleanupGhosting(RE_Render *r, int opaque_data[3]);
99 
100 /// Convenience method to return an RE type from a GT storage type.
102 {
103  switch(s)
104  {
105  case GT_STORE_UINT8: return RE_GPU_UINT8;
106  case GT_STORE_INT32: return RE_GPU_INT32;
107  case GT_STORE_INT64: return RE_GPU_INT32; // no such 64b type
108  case GT_STORE_REAL16: return RE_GPU_FLOAT16;
109  case GT_STORE_REAL32: return RE_GPU_FLOAT32;
110  case GT_STORE_REAL64: return RE_GPU_FLOAT64;
111  case GT_STORE_STRING: return RE_GPU_INT32; // string indices
112  default:
113  UT_ASSERT(!"No available RE type");
114  return RE_GPU_UINT1;
115  break;
116  }
117 }
118 
119 GR_API extern void assignInstanceGroupArray(RE_Geometry *to_geo,
120  const RE_VertexArray *array,
121  int instance_group =-1);
122 GR_API extern bool removeInstanceGroupArray(RE_Geometry *from_geo,
123  int instance_group,
124  const char *attrib_name,
127 
128 /// Returns the GPU type and vector size of the attribute based on the
129 /// data array, display option settings and supported GL capabilities.
131  const char *attrib_name,
132  int &vsize,
133  const GT_DataArrayHandle &pa,
134  const GR_DisplayOption &opts,
135  RE_ArrayType array_type);
136 
137 
138 /// Builds an instance transform array for p.instances on 'geo'. The
139 /// optional transform parameter will be set to the primitive transform
140 /// Returns 'true' if the primitive is instanced.
142  const GT_PrimitiveHandle &h,
143  const GR_UpdateParms &p,
144  RE_Geometry *geo,
146  int instance_group = 0,
147  UT_Matrix4D *transform = NULL);
148 
149 /// Builds an instance index mapping from GL instance to Houdini instance to
150 /// allow a subset of instances to be drawn.
151 GR_API extern void buildInstanceIndex(RE_Render *r,
152  RE_Geometry *geo,
153  bool has_partial_visibility,
154  const UT_IntArray &inst_indices,
155  int instance_group,
156  int max_capacity);
157 
158 /// Builds weight and index arrays for bone transforms.
159 /// 'bone_limit' specifies the maximal number of bone allowed
160 /// 'ret_bone_limit' returns the current number of bones being used by the current data set.
161 // If more than bone_limit weights are present for a point, the top
162 /// contributors are taken (to fit in a up to 3 vec4/ivec4 attribute pairs).
164  RE_VertexArray **bone_idx,
165  RE_VertexArray **bone_weight,
166  const GT_DataArrayHandle &dh,
168  int bone_limit,
169  int &ret_bone_limit);
170 
171 /// creates (or finds in the cache) attribute 'attrib_name' on RE_Geometry,
172 /// filling it with the data from the data array 'h'.
174  RE_Geometry *geo,
175  const char *attrib_name,
176  const GT_DataArrayHandle &h,
177  const GR_DisplayOption &opts,
178  RE_ArrayType atype,
179  RE_CacheVersion geo_version);
180 
181 GR_API extern void * fillAttribData(RE_Render *r,
182  const char *attrib_name,
183  const GT_DataArrayHandle &pa,
184  const GR_DisplayOption &opts,
186  bool build_string_tables = true);
187 
188 GR_API extern void fillStringAttrib(RE_Render *r,
189  const GT_DataArrayHandle &dh,
190  RE_Geometry *geo,
192  const RE_CacheVersion &version);
193 
218 
219 GR_API extern void buildCenterPoint(RE_Render *r,
220  const GT_PrimitiveHandle &primh,
221  const GR_UpdateParms &p,
222  const UT_Matrix4DArray &prim_xforms,
223  const GT_DataArrayHandle &prim_ids,
224  const GT_DataArrayHandle &point_ids,
225  const GT_DataArrayHandle &vert_ids,
226  const UT_Vector3F &point,
227  RE_CacheVersion point_version,
228  RE_Geometry *geo,
229  RE_VertexArrayRef *p_ref,
230  RE_VertexArrayRef *inst_mat_ref,
231  GR_SelectMode *point_select_mode,
232  bool is_offsets);
233 
234 GR_API extern void buildCenterPoints(RE_Render *r,
235  const GT_PrimitiveHandle &handle,
236  const GR_UpdateParms &p,
237  const UT_Matrix4DArray &primxforms,
238  const GT_DataArrayHandle &prim_ids,
239  const GT_DataArrayHandle &pnt_ids,
240  const GT_DataArrayHandle &vtx_ids,
241  RE_Geometry *geo,
242  GR_SelectMode *pnt_sel_mode = NULL,
243  bool is_offsets = true,
244  bool build_selection = true);
245 
247  const GT_PrimitiveHandle &primh,
248  const GR_UpdateParms &p,
249  const GT_DataArrayHandle &prim_ids,
250  const GT_DataArrayHandle &pnt_ids,
251  const GT_DataArrayHandle &vert_ids,
252  RE_Geometry *geo,
253  GR_SelectMode *point_select_mode,
254  bool is_offsets);
255 
257  const GT_PrimitiveHandle&ph,
258  const GR_UpdateParms &p,
259  RE_Geometry *geo);
260 
261 GR_API extern void buildCenterPointIDs(RE_Render *r,
262  const GT_PrimitiveHandle &primh,
263  const GR_UpdateParms &p,
264  const GT_DataArrayHandle &prm_id,
265  const GT_DataArrayHandle &pnt_id,
266  const GT_DataArrayHandle &vtx_id,
267  RE_Geometry *geo,
268  bool is_offsets);
269 
271  const GR_UpdateParms &p,
272  GT_DataArrayHandle prim_id,
273  GT_DataArrayHandle pnt_id,
274  GT_DataArrayHandle vert_id,
275  bool is_offset,
276  int repeat_count);
277 
279  RE_Geometry *geo,
280  const GR_UpdateParms &p,
281  GT_DataArrayHandle primid,
282  GT_DataArrayHandle vtxid,
283  GT_DataArrayHandle vertid,
284  bool is_offsets = true,
285  int instances_per_prim = 1,
286  UT_Array<uint8> *result = NULL);
287 
288 GR_API extern bool inViewFrustum(const UT_BoundingBoxD &bbox,
289  const UT_Matrix4D &objviewproj,
290  const UT_Vector4D *frustum_area = NULL);
291 
292 GR_API extern bool inViewFrustum(const UT_BoundingBoxF &bbox,
293  const UT_Matrix4F &objviewproj);
294 
295 GR_API extern bool inViewFrustumWithLOD(const UT_BoundingBoxF &bbox,
296  const UT_Matrix4F &objviewproj,
297  bool &has_bounds,
298  UT_Vector2F &bounds_2d);
299 
300 GR_API extern bool isRasterized(const UT_Matrix4F &objviewproj,
301  const UT_Vector2F &min_proj_size,
302  const UT_BoundingBoxF &bbox);
303 
304 GR_API extern GU_Connectivity getConnectivityFromString(const char *str);
305 
307 {
308 public:
309  gr_MatBucket() : next(NULL) {}
312 };
314 bucketMaterials(const GT_DataArrayHandle &mat_id);
315 GR_API extern void cleanupBuckets(
316  UT_Array<std::pair<gr_MatBucket *, int>> *&buckets);
317 
319  std::ostream *os = NULL);
321  UT_WorkBuffer &buf);
323  std::ostream *os = NULL);
325  std::ostream *os = NULL);
327  UT_WorkBuffer &buf);
329  UT_WorkBuffer &buf);
330 
331 } // End namespace GR_Utils
332 
333 GR_API size_t format(char *buf, size_t bufsize, const GR_UpdateReason &r);
334 GR_API size_t format(char *buf, size_t bufsize, const GR_RenderFlags &r);
335 GR_API size_t format(char *buf, size_t bufsize, const GR_RenderMode &r);
336 GR_API size_t format(char *buf, size_t bufsize, const GR_AlphaPass &r);
337 
338 #endif
339 
GR_API void printUpdateReason(GR_UpdateReason r, std::ostream *os=NULL)
GT_Storage
Definition: GT_Types.h:18
GLenum GLuint GLsizei bufsize
Definition: glcorearb.h:1817
GR_API GR_AttribMask hasSelection(const GR_UpdateParms &p)
Returns the selection type in p.geometry.
GR_API bool isRasterized(const UT_Matrix4F &objviewproj, const UT_Vector2F &min_proj_size, const UT_BoundingBoxF &bbox)
GR_API bool hasPrimTransform(const RE_Geometry *geo)
Return true if the geometry has a per-prim transform or per-prim visibility.
GR_API void buildBoneRegionsAndWeights(RE_Render *r, RE_VertexArray **bone_idx, RE_VertexArray **bone_weight, const GT_DataArrayHandle &dh, RE_CacheVersion version, int bone_limit, int &ret_bone_limit)
contributors are taken (to fit in a up to 3 vec4/ivec4 attribute pairs).
GR_API bool inViewFrustumWithLOD(const UT_BoundingBoxF &bbox, const UT_Matrix4F &objviewproj, bool &has_bounds, UT_Vector2F &bounds_2d)
GR_API RE_CacheVersion getTopologyVersion(const GT_Primitive *prim, RE_CacheVersion geo_version)
Return the cache version for the topology of primitive 'prim'.
GR_API RE_Shader * getDepthCascadePrimTransformShader(RE_Render *r)
GR_API RE_Shader * getDepthCascadeShader(RE_Render *r)
GR_API RE_Shader * getDepthCubeDisplaceShader(RE_Render *r)
GR_API RE_Shader * getDepthPrimTransformShader(RE_Render *r)
GR_API RE_VertexArray * fillAttribArray(RE_Render *r, RE_Geometry *geo, const char *attrib_name, const GT_DataArrayHandle &h, const GR_DisplayOption &opts, RE_ArrayType atype, RE_CacheVersion geo_version)
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:53
GR_API RE_Shader * getDepthCascadeLineShader(RE_Render *r)
GR_API size_t format(char *buf, size_t bufsize, const GR_UpdateReason &r)
GR_API bool inPointSelection(const GR_UpdateParms &p, GA_Offset point_id, const GU_Detail *geo=nullptr)
Returns true if point_id is in the selection list for p.geometry.
GR_AttribMask
Definition: GR_Defines.h:321
GR_API void printDrawFlags(GR_RenderFlags flags, std::ostream *os=NULL)
GR_API void buildCenterPoints(RE_Render *r, const GT_PrimitiveHandle &handle, const GR_UpdateParms &p, const UT_Matrix4DArray &primxforms, const GT_DataArrayHandle &prim_ids, const GT_DataArrayHandle &pnt_ids, const GT_DataArrayHandle &vtx_ids, RE_Geometry *geo, GR_SelectMode *pnt_sel_mode=NULL, bool is_offsets=true, bool build_selection=true)
GR_API void assignInstanceGroupArray(RE_Geometry *to_geo, const RE_VertexArray *array, int instance_group=-1)
GR_API RE_Shader * getRibbonShader(RE_Render *r)
GR_AlphaPass
Definition: GR_Defines.h:113
GR_API RE_Shader * getColorShader(RE_Render *r)
GR_API void * fillAttribData(RE_Render *r, const char *attrib_name, const GT_DataArrayHandle &pa, const GR_DisplayOption &opts, RE_ArrayType array, bool build_string_tables=true)
GR_API RE_Shader * getDepthCubePointShader(RE_Render *r)
set of parameters sent to GR_Primitive::update()
GLuint GLenum GLenum transform
Definition: glew.h:15055
GA_Size GA_Offset
Definition: GA_Types.h:640
GT_API const UT_StringHolder point_id
RE_GenericAttribID
Definition: RE_Types.h:328
GLenum array
Definition: glew.h:9108
RE_GPUType
Definition: RE_Types.h:44
GLuint64EXT * result
Definition: glew.h:14311
GR_API void cleanupBuckets(UT_Array< std::pair< gr_MatBucket *, int >> *&buckets)
GR_RenderMode
Definition: GR_Defines.h:46
GR_API RE_CacheVersion getAttribVersion(const GT_DataArrayHandle &ph, RE_CacheVersion geo_version)
Return the cache version for attribute 'ph'.
GR_API RE_Shader * getRibbonUVShader(RE_Render *r)
GR_API void drawFlagsString(GR_RenderFlags flags, UT_WorkBuffer &buf)
GR_API RE_Shader * getDepthLinearShader(RE_Render *r)
RE_GPUType getREType(GT_Storage s)
Convenience method to return an RE type from a GT storage type.
Definition: GR_Utils.h:101
GU_Connectivity
Definition: GU_SelectType.h:66
UT_IntArray prims
Definition: GR_Utils.h:310
GR_API void buildCenterPointIDs(RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const GT_DataArrayHandle &prm_id, const GT_DataArrayHandle &pnt_id, const GT_DataArrayHandle &vtx_id, RE_Geometry *geo, bool is_offsets)
#define GR_API
Definition: GR_API.h:10
GR_API RE_Shader * getDepthCubePrimTransformShader(RE_Render *r)
GR_UpdateReason
Definition: GR_Defines.h:295
GR_API bool inViewFrustum(const UT_BoundingBoxD &bbox, const UT_Matrix4D &objviewproj, const UT_Vector4D *frustum_area=NULL)
GR_API GU_Connectivity getConnectivityFromString(const char *str)
GR_API RE_Shader * getDepthCascadeDisplaceShader(RE_Render *r)
GR_API RE_Shader * getDepthWirePrimTransformShader(RE_Render *r)
GR_API bool inVertexSelection(const GR_UpdateParms &p, GA_Offset vert_id, const GU_Detail *geo=nullptr)
Returns true if vert_id is in the selection list for p.geometry.
GR_API bool buildInstanceObjectMatrix(RE_Render *r, const GT_PrimitiveHandle &h, const GR_UpdateParms &p, RE_Geometry *geo, RE_CacheVersion version, int instance_group=0, UT_Matrix4D *transform=NULL)
GLfloat GLfloat p
Definition: glew.h:16656
GR_API RE_Shader * getDepthCubeLineShader(RE_Render *r)
GR_API void buildCenterPointSelection(RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const GT_DataArrayHandle &prim_ids, const GT_DataArrayHandle &pnt_ids, const GT_DataArrayHandle &vert_ids, RE_Geometry *geo, GR_SelectMode *point_select_mode, bool is_offsets)
GR_API void buildCenterPoint(RE_Render *r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p, const UT_Matrix4DArray &prim_xforms, const GT_DataArrayHandle &prim_ids, const GT_DataArrayHandle &point_ids, const GT_DataArrayHandle &vert_ids, const UT_Vector3F &point, RE_CacheVersion point_version, RE_Geometry *geo, RE_VertexArrayRef *p_ref, RE_VertexArrayRef *inst_mat_ref, GR_SelectMode *point_select_mode, bool is_offsets)
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)
GR_RenderFlags
Definition: GR_Defines.h:84
GLbitfield flags
Definition: glcorearb.h:1595
The base class for all GT primitive types.
Definition: GT_Primitive.h:43
GR_API RE_Shader * getDepthShader(RE_Render *r)
GR_API RE_Shader * getConstPointShader(RE_Render *r)
GR_API RE_Shader * getWireShader(RE_Render *r)
GLenum mode
Definition: glcorearb.h:98
GT_API const UT_StringHolder version
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2539
GR_API RE_Shader * getDepthLinearPrimTransformShader(RE_Render *r)
GR_API bool removeInstanceGroupArray(RE_Geometry *from_geo, int instance_group, const char *attrib_name, RE_GenericAttribID id=RE_GENATTRIB_NONE)
GR_API void buildInstanceIndex(RE_Render *r, RE_Geometry *geo, bool has_partial_visibility, const UT_IntArray &inst_indices, int instance_group, int max_capacity)
GR_API void fillStringAttrib(RE_Render *r, const GT_DataArrayHandle &dh, RE_Geometry *geo, RE_VertexArray *array, const RE_CacheVersion &version)
GR_API void drawModeString(GR_RenderMode mode, UT_WorkBuffer &buf)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GR_API RE_Shader * getDepthWireShader(RE_Render *r)
GR_API RE_Shader * getDepthCascadePointShader(RE_Render *r)
GR_API RE_Shader * getDepthCubeShader(RE_Render *r)
GR_API RE_Shader * getDepthLinearDisplaceShader(RE_Render *r)
fpreal64 fpreal
Definition: SYS_Types.h:277
gr_MatBucket * next
Definition: GR_Utils.h:311
RE_ArrayType
Definition: RE_Types.h:317
GR_API UT_Array< std::pair< gr_MatBucket *, int > > * bucketMaterials(const GT_DataArrayHandle &mat_id)
GR_API RE_GPUType getAttributeType(RE_Render *r, const char *attrib_name, int &vsize, const GT_DataArrayHandle &pa, const GR_DisplayOption &opts, RE_ArrayType array_type)
GR_API void printDrawMode(GR_RenderMode mode, std::ostream *os=NULL)
GR_API bool inPrimitiveSelection(const GR_UpdateParms &p, GA_Offset prim_id, const GU_Detail *geo=nullptr)
GR_API GR_SelectMode buildInstSelectInfo(RE_Render *r, RE_Geometry *geo, const GR_UpdateParms &p, GT_DataArrayHandle primid, GT_DataArrayHandle vtxid, GT_DataArrayHandle vertid, bool is_offsets=true, int instances_per_prim=1, UT_Array< uint8 > *result=NULL)
GLfloat f
Definition: glcorearb.h:1925
Simple class for a mutli-integer cache tag.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:171
GR_API RE_Shader * getMatteDisplaceShader(RE_Render *r)
GR_API RE_Shader * getMatteShader(RE_Render *r)
GLboolean r
Definition: glcorearb.h:1221
GR_API void setupGhosting(RE_Render *r, int opaque_data[3], fpreal transparency=0.25f)
GLdouble s
Definition: glew.h:1395
GR_API void cleanupGhosting(RE_Render *r, int opaque_data[3])
GR_API void updateReasonString(GR_UpdateReason r, UT_WorkBuffer &buf)
GR_API void createCenterPointAttribs(RE_Render *r, const GT_PrimitiveHandle &ph, const GR_UpdateParms &p, RE_Geometry *geo)
GR_SelectMode
Definition: GR_Defines.h:224