HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros 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 <UT/UT_VectorTypes.h>
19 #include <RE/RE_Types.h>
20 #include <RE/RE_CachedObject.h>
21 #include <GU/GU_SelectType.h>
22 #include <GA/GA_Types.h>
23 #include <GT/GT_Types.h>
24 #include <GT/GT_Primitive.h>
25 
26 class RE_Render;
27 class RE_VertexArray;
28 class RE_VertexArrayRef;
29 class RE_Geometry;
30 class RE_Shader;
31 class GR_DisplayOption;
32 
33 /// Utility GR methods common to all renderers
34 namespace GR_Utils
35 {
36 /// Returns the selection type in p.geometry
38 
39 /// Returns true if prim_id is in the selection list for p.geometry
40 /// If geo is given it must be the unlocked p.geometry from a ReadLock
41 GR_API extern bool inPrimitiveSelection(const GR_UpdateParms &p,
42  GA_Offset prim_id,
43  const GU_Detail *geo = nullptr);
44 
45 /// Returns true if point_id is in the selection list for p.geometry
46 GR_API extern bool inPointSelection(const GR_UpdateParms &p,
47  GA_Offset point_id,
48  const GU_Detail *geo = nullptr);
49 
50 /// Returns true if vert_id is in the selection list for p.geometry
51 GR_API extern bool inVertexSelection(const GR_UpdateParms &p,
52  GA_Offset vert_id,
53  const GU_Detail *geo = nullptr);
54 
55 /// @brief Checks if passed prim offsets are in p.geometry's selection.
56 /// Returns GR_SELECT_PRIM_PARTIAL/FULL if some or all of the prim offsets
57 /// are in the cook or temp selections, as indicated by the parms in p,
58 /// otherwise GR_SELECT_NONE is returned. The individual selection results
59 /// are returned in 'selected'
61  const UT_Array<GA_Offset>&pids,
62  UT_BitArray &selected);
63 
64 /// @brief Checks if passed point offsets are in p.geometry's selection.
65 /// Returns GR_SELECT_POINT_PARTIAL/FULL if some or all of the point offsets
66 /// are in the cook or temp selections, as indicated by the parms in p,
67 /// otherwise GR_SELECT_NONE is returned. The individual selection results
68 /// are returned in 'selected'
70  const UT_Array<GA_Offset> &pids,
71  UT_BitArray &selected);
72 
73 /// @brief Checks if passed vertex offsets are in p.geometry's selection.
75  const UT_Array<GA_Offset> &vids,
76  UT_BitArray &selected);
77 
78 /// Return the cache version for attribute 'ph'
80  RE_CacheVersion geo_version);
81 
82 /// Return the cache version for the topology of primitive 'prim'
84  RE_CacheVersion geo_version);
85 
86 /// Return true if the geometry has a per-prim transform or per-prim visibility
87 GR_API extern bool hasPrimTransform(const RE_Geometry *geo);
88 
89 // Call setupGhosting() to set up wire-ghosting (or other sample-based
90 // ghosting effects). opaque_data[] is just used to clean up correctly.
91 // transparency (1.0 - opacity) is rounded up to the nearest multiple of
92 // 1/s where s is the number of samples (at least 4 for ghosting to work).
93 GR_API extern void setupGhosting (RE_Render *r, int opaque_data[3],
94  fpreal transparency = 0.25f);
95 GR_API extern void cleanupGhosting(RE_Render *r, int opaque_data[3]);
96 
97 /// Convenience method to return an RE type from a GT storage type.
99 {
100  switch(s)
101  {
102  case GT_STORE_UINT8: return RE_GPU_UINT8;
103  case GT_STORE_INT32: return RE_GPU_INT32;
104  case GT_STORE_INT64: return RE_GPU_INT32; // no such 64b type
105  case GT_STORE_REAL16: return RE_GPU_FLOAT16;
106  case GT_STORE_REAL32: return RE_GPU_FLOAT32;
107  case GT_STORE_REAL64: return RE_GPU_FLOAT64;
108  case GT_STORE_STRING: return RE_GPU_INT32; // string indices
109  default:
110  UT_ASSERT(!"No available RE type");
111  return RE_GPU_UINT1;
112  break;
113  }
114 }
115 
116 GR_API extern void assignInstanceGroupArray(RE_Geometry *to_geo,
117  const RE_VertexArray *array,
118  int instance_group =-1);
119 GR_API extern bool removeInstanceGroupArray(RE_Geometry *from_geo,
120  int instance_group,
121  const char *attrib_name,
124 
125 /// Returns the GPU type and vector size of the attribute based on the
126 /// data array, display option settings and supported GL capabilities.
128  const char *attrib_name,
129  int &vsize,
130  const GT_DataArrayHandle &pa,
131  const GR_DisplayOption &opts,
132  RE_ArrayType array_type);
133 
134 
135 /// Builds an instance transform array for p.instances on 'geo'. The
136 /// optional transform parameter will be set to the primitive transform
137 /// Returns 'true' if the primitive is instanced.
139  const GT_PrimitiveHandle &h,
140  const GR_UpdateParms &p,
141  RE_Geometry *geo,
142  RE_CacheVersion version,
143  int instance_group = 0,
144  UT_Matrix4D *transform = NULL);
145 
146 /// Builds an instance index mapping from GL instance to Houdini instance to
147 /// allow a subset of instances to be drawn.
148 GR_API extern bool buildInstanceIndex(RE_Render *r,
149  RE_Geometry *geo,
150  bool has_partial_visibility,
151  const UT_IntArray &inst_indices,
152  int instance_group = 0);
153 
154 /// Builds weight and index arrays for bone transforms.
155 /// 'bone_limit' specifies the maximal number of bone allowed
156 /// 'ret_bone_limit' returns the current number of bones being used by the current data set.
157 // If more than bone_limit weights are present for a point, the top
158 /// contributors are taken (to fit in a up to 3 vec4/ivec4 attribute pairs).
160  RE_VertexArray **bone_idx,
161  RE_VertexArray **bone_weight,
162  const GT_DataArrayHandle &dh,
163  RE_CacheVersion version,
164  int bone_limit,
165  int &ret_bone_limit);
166 
167 /// creates (or finds in the cache) attribute 'attrib_name' on RE_Geometry,
168 /// filling it with the data from the data array 'h'.
170  RE_Geometry *geo,
171  const char *attrib_name,
172  const GT_DataArrayHandle &h,
173  const GR_DisplayOption &opts,
174  RE_ArrayType atype,
175  RE_CacheVersion geo_version);
176 
177 GR_API extern void * fillAttribData(RE_Render *r,
178  const char *attrib_name,
179  const GT_DataArrayHandle &pa,
180  const GR_DisplayOption &opts,
181  RE_ArrayType array,
182  bool build_string_tables = true);
183 
184 /// returns the #chars in the longest string.
185 GR_API extern int fillStringArray(const GT_DataArrayHandle &pa,
186  void *data);
187 // simple GL32 shaders
205 
206 GR_API extern void buildCenterPoint(RE_Render *r,
207  const GT_PrimitiveHandle &primh,
208  const GR_UpdateParms &p,
209  const UT_Matrix4DArray &prim_xforms,
210  const GT_DataArrayHandle &prim_ids,
211  const GT_DataArrayHandle &point_ids,
212  const GT_DataArrayHandle &vert_ids,
213  const UT_Vector3F &point,
214  RE_CacheVersion point_version,
215  RE_Geometry *geo,
216  RE_VertexArrayRef *p_ref,
217  RE_VertexArrayRef *inst_mat_ref,
218  GR_SelectMode *point_select_mode,
219  bool is_offsets);
220 
221 GR_API extern void buildCenterPoints(RE_Render *r,
222  const GT_PrimitiveHandle &handle,
223  const GR_UpdateParms &p,
224  const UT_Matrix4DArray &primxforms,
225  const GT_DataArrayHandle &prim_ids,
226  const GT_DataArrayHandle &pnt_ids,
227  const GT_DataArrayHandle &vtx_ids,
228  RE_Geometry *geo,
229  GR_SelectMode *pnt_sel_mode = NULL,
230  bool is_offsets = true);
231 
233  const GT_PrimitiveHandle &primh,
234  const GR_UpdateParms &p,
235  const GT_DataArrayHandle &prim_ids,
236  const GT_DataArrayHandle &pnt_ids,
237  const GT_DataArrayHandle &vert_ids,
238  RE_Geometry *geo,
239  GR_SelectMode *point_select_mode,
240  bool is_offsets);
241 
243  const GT_PrimitiveHandle&ph,
244  const GR_UpdateParms &p,
245  RE_Geometry *geo);
246 
247 GR_API extern void buildCenterPointIDs(RE_Render *r,
248  const GT_PrimitiveHandle &primh,
249  const GR_UpdateParms &p,
250  const GT_DataArrayHandle &prm_id,
251  const GT_DataArrayHandle &pnt_id,
252  const GT_DataArrayHandle &vtx_id,
253  RE_Geometry *geo,
254  bool is_offsets);
255 
257  const GR_UpdateParms &p,
258  GT_DataArrayHandle prim_id,
259  GT_DataArrayHandle pnt_id,
260  GT_DataArrayHandle vert_id,
261  bool is_offset,
262  int repeat_count);
263 
265  RE_Geometry *geo,
266  const GR_UpdateParms &p,
267  GT_DataArrayHandle primid,
268  GT_DataArrayHandle vtxid,
269  GT_DataArrayHandle vertid,
270  bool is_offsets = true,
271  int instances_per_prim = 1,
272  UT_Array<uint8> *result = NULL);
273 
274 GR_API extern bool inViewFrustum(const UT_BoundingBoxD &bbox,
275  const UT_Matrix4D &objviewproj,
276  const UT_Vector4D *frustum_area = NULL);
277 
278 GR_API extern bool inViewFrustum(const UT_BoundingBoxF &bbox,
279  const UT_Matrix4F &objviewproj);
280 
281 GR_API extern bool inViewFrustumWithLOD(const UT_BoundingBoxF &bbox,
282  const UT_Matrix4F &objviewproj,
283  bool &has_bounds,
284  UT_Vector2F &bounds_2d);
285 
286 GR_API extern GU_Connectivity getConnectivityFromString(const char *str);
287 
289 {
290 public:
291  gr_MatBucket() : next(NULL) {}
294 };
296 bucketMaterials(const GT_DataArrayHandle &mat_id);
297 GR_API extern void cleanupBuckets(
299 
301  std::ostream *os = NULL);
303  UT_WorkBuffer &buf);
305  std::ostream *os = NULL);
307  std::ostream *os = NULL);
309  UT_WorkBuffer &buf);
311  UT_WorkBuffer &buf);
312 
313 } // End namespace GR_Utils
314 
315 GR_API size_t format(char *buf, size_t bufsize, const GR_UpdateReason &r);
316 GR_API size_t format(char *buf, size_t bufsize, const GR_RenderFlags &r);
317 GR_API size_t format(char *buf, size_t bufsize, const GR_RenderMode &r);
318 
319 #endif
320 
GR_API void printUpdateReason(GR_UpdateReason r, 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)
GT_Storage
Definition: GT_Types.h:17
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 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 * 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 void cleanupBuckets(UT_Array< UT_Pair< gr_MatBucket *, int > > *&buckets)
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:303
GLbitfield flags
Definition: glcorearb.h:1595
GR_API void printDrawFlags(GR_RenderFlags flags, std::ostream *os=NULL)
GR_API int fillStringArray(const GT_DataArrayHandle &pa, void *data)
returns the #chars in the longest string.
GR_API void assignInstanceGroupArray(RE_Geometry *to_geo, const RE_VertexArray *array, int instance_group=-1)
GR_API bool buildInstanceIndex(RE_Render *r, RE_Geometry *geo, bool has_partial_visibility, const UT_IntArray &inst_indices, int instance_group=0)
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()
GA_Size GA_Offset
Definition: GA_Types.h:617
RE_GenericAttribID
Definition: RE_Types.h:321
RE_GPUType
Definition: RE_Types.h:42
GLfloat f
Definition: glcorearb.h:1925
GR_RenderMode
Definition: GR_Defines.h:42
GR_API RE_CacheVersion getAttribVersion(const GT_DataArrayHandle &ph, RE_CacheVersion geo_version)
Return the cache version for attribute 'ph'.
GR_API void drawFlagsString(GR_RenderFlags flags, UT_WorkBuffer &buf)
GR_API RE_Shader * getDepthLinearShader(RE_Render *r)
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:102
RE_GPUType getREType(GT_Storage s)
Convenience method to return an RE type from a GT storage type.
Definition: GR_Utils.h:98
GU_Connectivity
Definition: GU_SelectType.h:66
UT_IntArray prims
Definition: GR_Utils.h:292
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:278
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 * 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)
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)
GLboolean * data
Definition: glcorearb.h:130
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:77
GA_API const UT_StringHolder transform
The base class for all GT primitive types.
Definition: GT_Primitive.h:41
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
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 drawModeString(GR_RenderMode mode, UT_WorkBuffer &buf)
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2001
GR_API RE_Shader * getDepthWireShader(RE_Render *r)
double fpreal
Definition: SYS_Types.h:269
GR_API RE_Shader * getDepthCubeShader(RE_Render *r)
GR_API RE_Shader * getDepthLinearDisplaceShader(RE_Render *r)
gr_MatBucket * next
Definition: GR_Utils.h:293
RE_ArrayType
Definition: RE_Types.h:310
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)
GR_API UT_Array< UT_Pair< gr_MatBucket *, int > > * bucketMaterials(const GT_DataArrayHandle &mat_id)
Simple class for a mutli-integer cache tag.
GR_API RE_Shader * getMatteDisplaceShader(RE_Render *r)
GLboolean r
Definition: glcorearb.h:1221
GR_API RE_Shader * getMatteShader(RE_Render *r)
GR_API void setupGhosting(RE_Render *r, int opaque_data[3], fpreal transparency=0.25f)
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:215