All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  *
9  * Utility functions for GR.
10  */
11 #ifndef GR_Utils_h
12 #define GR_Utils_h
14 #include "GR_API.h"
15 #include "GR_Defines.h"
16 #include "GR_UpdateParms.h"
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_RenderContext.h>
24 #include <RE/RE_Types.h>
25 #include <UT/UT_VectorTypes.h>
27 #include <utility>
29 class RE_Render;
30 class RE_VertexArray;
31 class RE_VertexArrayRef;
32 class RE_Geometry;
33 class RE_Shader;
34 class GR_DisplayOption;
35 class GR_GeoRender;
36 class UT_WorkBuffer;
38 /// Utility GR methods common to all renderers
39 namespace GR_Utils
40 {
41 /// Returns the selection type in p.geometry
44 /// Returns true if prim_id is in the selection list for p.geometry
45 /// If geo is given it must be the unlocked p.geometry from a ReadLock
46 GR_API extern bool inPrimitiveSelection(const GR_UpdateParms &p,
47  GA_Offset prim_id,
48  const GU_Detail *geo = nullptr);
50 /// Returns true if point_id is in the selection list for p.geometry
51 GR_API extern bool inPointSelection(const GR_UpdateParms &p,
53  const GU_Detail *geo = nullptr);
55 /// Returns true if vert_id is in the selection list for p.geometry
56 GR_API extern bool inVertexSelection(const GR_UpdateParms &p,
57  GA_Offset vert_id,
58  const GU_Detail *geo = nullptr);
60 /// @brief Checks if passed prim offsets are in p.geometry's selection.
61 /// Returns GR_SELECT_PRIM_PARTIAL/FULL if some or all of the prim offsets
62 /// are in the cook or temp selections, as indicated by the parms in p,
63 /// otherwise GR_SELECT_NONE is returned. The individual selection results
64 /// are returned in 'selected'
66  const UT_Array<GA_Offset>&pids,
67  UT_BitArray &selected);
69 /// @brief Checks if passed point offsets are in p.geometry's selection.
70 /// Returns GR_SELECT_POINT_PARTIAL/FULL if some or all of the point offsets
71 /// are in the cook or temp selections, as indicated by the parms in p,
72 /// otherwise GR_SELECT_NONE is returned. The individual selection results
73 /// are returned in 'selected'
75  const UT_Array<GA_Offset> &pids,
76  UT_BitArray &selected);
78 /// @brief Checks if passed vertex offsets are in p.geometry's selection.
80  const UT_Array<GA_Offset> &vids,
81  UT_BitArray &selected);
83 /// Return the cache version for attribute 'ph'
85  RE_CacheVersion geo_version);
87 /// Return the cache version for the topology of primitive 'prim'
89  RE_CacheVersion geo_version);
91 /// Return true if the geometry has a per-prim transform or per-prim visibility
92 GR_API extern bool hasPrimTransform(const RE_Geometry *geo);
94 // Call setupGhosting() to set up wire-ghosting (or other sample-based
95 // ghosting effects). opaque_data[] is just used to clean up correctly.
96 // transparency (1.0 - opacity) is rounded up to the nearest multiple of
97 // 1/s where s is the number of samples (at least 4 for ghosting to work).
98 GR_API extern void setupGhosting (RE_RenderContext r, int opaque_data[3],
99  fpreal transparency = 0.25f);
100 GR_API extern void cleanupGhosting(RE_RenderContext r, int opaque_data[3]);
102 /// Convenience method to return an RE type from a GT storage type.
104 {
105  switch(s)
106  {
107  case GT_STORE_UINT8: return RE_GPU_UINT8;
108  case GT_STORE_INT32: return RE_GPU_INT32;
109  case GT_STORE_INT64: return RE_GPU_INT32; // no such 64b type
110  case GT_STORE_REAL16: return RE_GPU_FLOAT16;
111  case GT_STORE_REAL32: return RE_GPU_FLOAT32;
112  case GT_STORE_REAL64: return RE_GPU_FLOAT64;
113  case GT_STORE_STRING: return RE_GPU_INT32; // string indices
114  default:
115  UT_ASSERT(!"No available RE type");
116  return RE_GPU_UINT1;
117  break;
118  }
119 }
121 GR_API extern void assignInstanceGroupArray(RE_Geometry *to_geo,
122  const RE_VertexArray *array,
123  int instance_group =-1);
124 GR_API extern bool removeInstanceGroupArray(RE_Geometry *from_geo,
125  int instance_group,
126  const char *attrib_name,
130 /// Returns the GPU type and vector size of the attribute based on the
131 /// data array, display option settings and supported GL capabilities.
133  const char *attrib_name,
134  int &vsize,
135  const GT_DataArrayHandle &pa,
136  const GR_DisplayOption &opts,
137  RE_ArrayType array_type);
140 /// Builds an instance transform array for p.instances on 'geo'. The
141 /// optional transform parameter will be set to the primitive transform
142 /// Returns 'true' if the primitive is instanced.
144  const GT_PrimitiveHandle &h,
145  const GR_UpdateParms &p,
146  RE_Geometry *geo,
148  int instance_group = 0,
149  UT_Matrix4D *transform = NULL);
151 /// Builds an instance index mapping from GL instance to Houdini instance to
152 /// allow a subset of instances to be drawn.
153 GR_API extern void buildInstanceIndex(RE_Render *r,
154  RE_Geometry *geo,
155  bool has_partial_visibility,
156  const UT_IntArray &inst_indices,
157  int instance_group,
158  int max_capacity);
160 /// Builds weight and index arrays for bone transforms.
161 /// 'bone_limit' specifies the maximal number of bone allowed
162 /// 'ret_bone_limit' returns the current number of bones being used by the current data set.
163 // If more than bone_limit weights are present for a point, the top
164 /// contributors are taken (to fit in a up to 3 vec4/ivec4 attribute pairs).
166  RE_VertexArray **bone_idx,
167  RE_VertexArray **bone_weight,
168  const GT_DataArrayHandle &dh,
170  int bone_limit,
171  int &ret_bone_limit);
173 /// creates (or finds in the cache) attribute 'attrib_name' on RE_Geometry,
174 /// filling it with the data from the data array 'h'.
176  RE_Geometry *geo,
177  const char *attrib_name,
178  const GT_DataArrayHandle &h,
179  const GR_DisplayOption &opts,
180  RE_ArrayType atype,
181  RE_CacheVersion geo_version);
183 GR_API extern void * fillAttribData(RE_Render *r,
184  const char *attrib_name,
185  const GT_DataArrayHandle &pa,
186  const GR_DisplayOption &opts,
187  RE_ArrayType array,
188  bool build_string_tables = true);
190 GR_API extern void fillStringAttrib(RE_Render *r,
191  const GT_DataArrayHandle &dh,
192  RE_Geometry *geo,
193  RE_VertexArray *array,
194  const RE_CacheVersion &version);
221 GR_API extern void buildCenterPoint(RE_Render *r,
222  const GT_PrimitiveHandle &primh,
223  const GR_UpdateParms &p,
224  const UT_Matrix4DArray &prim_xforms,
225  const GT_DataArrayHandle &prim_ids,
226  const GT_DataArrayHandle &point_ids,
227  const GT_DataArrayHandle &vert_ids,
228  const UT_Vector3F &point,
229  RE_CacheVersion point_version,
230  RE_Geometry *geo,
231  RE_VertexArrayRef *p_ref,
232  RE_VertexArrayRef *inst_mat_ref,
233  GR_SelectMode *point_select_mode,
234  bool is_offsets);
237  const GT_PrimitiveHandle &handle,
238  const GR_UpdateParms &p,
239  const UT_Matrix4DArray &primxforms,
240  const GT_DataArrayHandle &prim_ids,
241  const GT_DataArrayHandle &pnt_ids,
242  const GT_DataArrayHandle &vtx_ids,
243  GR_GeoRender *gr,
244  const char *cache_name,
245  GT_PrimitiveHandle *pt_handle = nullptr,
246  GR_SelectMode *pnt_sel_mode = NULL,
247  bool is_offsets = true,
248  bool build_selection = true);
250 GR_API extern void buildCenterPoints(RE_Render *r,
251  const GT_PrimitiveHandle &handle,
252  const GR_UpdateParms &p,
253  const UT_Matrix4DArray &primxforms,
254  const GT_DataArrayHandle &prim_ids,
255  const GT_DataArrayHandle &pnt_ids,
256  const GT_DataArrayHandle &vtx_ids,
257  RE_Geometry *geo,
258  GR_SelectMode *pnt_sel_mode = NULL,
259  bool is_offsets = true,
260  bool build_selection = true);
263  const GT_PrimitiveHandle &primh,
264  const GR_UpdateParms &p,
265  const GT_DataArrayHandle &prim_ids,
266  const GT_DataArrayHandle &pnt_ids,
267  const GT_DataArrayHandle &vert_ids,
268  RE_Geometry *geo,
269  GR_SelectMode *point_select_mode,
270  bool is_offsets);
273  const GT_PrimitiveHandle&ph,
274  const GR_UpdateParms &p,
275  RE_Geometry *geo);
277 GR_API extern void buildCenterPointIDs(RE_Render *r,
278  const GT_PrimitiveHandle &primh,
279  const GR_UpdateParms &p,
280  const GT_DataArrayHandle &prm_id,
281  const GT_DataArrayHandle &pnt_id,
282  const GT_DataArrayHandle &vtx_id,
283  RE_Geometry *geo,
284  bool is_offsets);
287  const GR_UpdateParms &p,
288  GT_DataArrayHandle prim_id,
289  GT_DataArrayHandle pnt_id,
290  GT_DataArrayHandle vert_id,
291  bool is_offset,
292  int repeat_count);
295  RE_Geometry *geo,
296  const GR_UpdateParms &p,
297  RE_CacheVersion top_ver,
298  GT_DataArrayHandle primid,
299  GT_DataArrayHandle vtxid,
300  GT_DataArrayHandle vertid,
301  bool is_offsets = true,
302  int instances_per_prim = 1,
303  UT_Array<uint8> *result = NULL);
305 GR_API extern bool inViewFrustum(const UT_BoundingBoxD &bbox,
306  const UT_Matrix4D &objviewproj,
307  const UT_Vector4D *frustum_area = NULL);
309 GR_API extern bool inViewFrustum(const UT_BoundingBoxF &bbox,
310  const UT_Matrix4F &objviewproj);
312 GR_API extern bool inViewFrustumWithLOD(const UT_BoundingBoxF &bbox,
313  const UT_Matrix4F &objviewproj,
314  bool &has_bounds,
315  UT_Vector2F &bounds_2d);
317 GR_API extern bool isRasterized(const UT_Matrix4F &objviewproj,
318  const UT_Vector2F &min_proj_size,
319  const UT_BoundingBoxF &bbox);
321 GR_API extern GU_Connectivity getConnectivityFromString(const char *str);
324 {
325 public:
326  gr_MatBucket() : next(NULL) {}
329 };
331 bucketMaterials(const GT_DataArrayHandle &mat_id);
332 GR_API extern void cleanupBuckets(
333  UT_Array<std::pair<gr_MatBucket *, int>> *&buckets);
336  std::ostream *os = NULL);
338  UT_WorkBuffer &buf);
340  std::ostream *os = NULL);
342  std::ostream *os = NULL);
344  UT_WorkBuffer &buf);
346  UT_WorkBuffer &buf);
348 } // End namespace GR_Utils
350 GR_API size_t format(char *buf, size_t bufsize, const GR_UpdateReason &r);
351 GR_API size_t format(char *buf, size_t bufsize, const GR_RenderFlags &r);
352 GR_API size_t format(char *buf, size_t bufsize, const GR_RenderMode &r);
353 GR_API size_t format(char *buf, size_t bufsize, const GR_AlphaPass &r);
355 #endif
GR_API void printUpdateReason(GR_UpdateReason r, std::ostream *os=NULL)
Definition: GT_Types.h:19
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glcorearb.h:2540
GLbitfield flags
Definition: glcorearb.h:1596
GLenum GLuint GLsizei bufsize
Definition: glcorearb.h:1818
GR_API void buildCenterPoints(RE_RenderContext 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, GR_GeoRender *gr, const char *cache_name, GT_PrimitiveHandle *pt_handle=nullptr, GR_SelectMode *pnt_sel_mode=NULL, bool is_offsets=true, bool build_selection=true)
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)
GT_API const UT_StringHolder cache_name
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.
Definition: GR_Defines.h:328
GLdouble s
Definition: glad.h:3009
GR_API void printDrawFlags(GR_RenderFlags flags, std::ostream *os=NULL)
**But if you need a result
Definition: thread.h:613
GR_API void assignInstanceGroupArray(RE_Geometry *to_geo, const RE_VertexArray *array, int instance_group=-1)
GR_API RE_Shader * getRibbonShader(RE_Render *r)
Definition: GR_Defines.h:117
Temporary container for either a RV_Render and an RE_Render.
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:641
GT_API const UT_StringHolder point_id
Definition: RE_Types.h:348
Definition: RE_Types.h:44
GLfloat f
Definition: glcorearb.h:1926
GR_API void cleanupBuckets(UT_Array< std::pair< gr_MatBucket *, int >> *&buckets)
Definition: GR_Defines.h:47
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:103
Definition: GU_SelectType.h:66
UT_IntArray prims
Definition: GR_Utils.h:327
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)
Definition: GR_Defines.h:300
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)
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)
Definition: GR_Defines.h:85
GA_API const UT_StringHolder transform
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:99
GT_API const UT_StringHolder version
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:2002
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:328
Definition: RE_Types.h:337
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 GR_SelectMode buildInstSelectInfo(RE_Render *r, RE_Geometry *geo, const GR_UpdateParms &p, RE_CacheVersion top_ver, 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 void setupGhosting(RE_RenderContext r, int opaque_data[3], fpreal transparency=0.25f)
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 void cleanupGhosting(RE_RenderContext r, int opaque_data[3])
Simple class for a mutli-integer cache tag.
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156
GR_API RE_Shader * getMatteDisplaceShader(RE_Render *r)
GLboolean r
Definition: glcorearb.h:1222
GR_API RE_Shader * getMatteShader(RE_Render *r)
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)
Definition: GR_Defines.h:229