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 
17 #include <GT/GT_Primitive.h>
18 #include <GT/GT_Types.h>
19 #include <GU/GU_SelectType.h>
20 #include <GA/GA_Types.h>
21 #include <RE/RE_CachedObject.h>
22 #include <RE/RE_RenderContext.h>
23 #include <RE/RE_Types.h>
24 #include <UT/UT_BitArray.h>
25 #include <UT/UT_VectorTypes.h>
26 
27 #include <utility>
28 
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;
37 class GR_UpdateParms;
38 
39 /// Utility GR methods common to all renderers
40 namespace GR_Utils
41 {
42 /// Returns the selection type in p.geometry
44 
45 /// Returns true if prim_id is in the selection list for p.geometry
46 /// If geo is given it must be the unlocked p.geometry from a ReadLock
47 GR_API extern bool inPrimitiveSelection(const GR_UpdateParms &p,
48  GA_Offset prim_id,
49  const GU_Detail *geo = nullptr);
50 
51 /// Returns true if point_id is in the selection list for p.geometry
52 GR_API extern bool inPointSelection(const GR_UpdateParms &p,
54  const GU_Detail *geo = nullptr);
55 
56 /// Returns true if vert_id is in the selection list for p.geometry
57 GR_API extern bool inVertexSelection(const GR_UpdateParms &p,
58  GA_Offset vert_id,
59  const GU_Detail *geo = nullptr);
60 
61 /// @brief Checks if passed prim offsets are in p.geometry's selection.
62 /// Returns GR_SELECT_PRIM_PARTIAL/FULL if some or all of the prim offsets
63 /// are in the cook or temp selections, as indicated by the parms in p,
64 /// otherwise GR_SELECT_NONE is returned. The individual selection results
65 /// are returned in 'selected'
67  const UT_Array<GA_Offset>&pids,
68  UT_BitArray &selected);
69 
70 /// @brief Checks if passed point offsets are in p.geometry's selection.
71 /// Returns GR_SELECT_POINT_PARTIAL/FULL if some or all of the point offsets
72 /// are in the cook or temp selections, as indicated by the parms in p,
73 /// otherwise GR_SELECT_NONE is returned. The individual selection results
74 /// are returned in 'selected'
76  const UT_Array<GA_Offset> &pids,
77  UT_BitArray &selected);
78 
79 /// @brief Checks if passed vertex offsets are in p.geometry's selection.
81  const UT_Array<GA_Offset> &vids,
82  UT_BitArray &selected);
83 
84 /// Return the cache version for attribute 'ph'
86  RE_CacheVersion geo_version);
87 
88 /// Return the cache version for the topology of primitive 'prim'
90  RE_CacheVersion geo_version);
91 
92 /// Return true if the geometry has a per-prim transform or per-prim visibility
93 GR_API extern bool hasPrimTransform(const RE_Geometry *geo);
94 
95 // Call setupGhosting() to set up wire-ghosting (or other sample-based
96 // ghosting effects). opaque_data[] is just used to clean up correctly.
97 // transparency (1.0 - opacity) is rounded up to the nearest multiple of
98 // 1/s where s is the number of samples (at least 4 for ghosting to work).
99 GR_API extern void setupGhosting (RE_RenderContext r, int opaque_data[3],
100  fpreal transparency = 0.25f);
101 GR_API extern void cleanupGhosting(RE_RenderContext r, int opaque_data[3]);
102 
103 /// Convenience method to return an RE type from a GT storage type.
105 {
106  switch(s)
107  {
108  case GT_STORE_UINT8: return RE_GPU_UINT8;
109  case GT_STORE_INT32: return RE_GPU_INT32;
110  case GT_STORE_INT64: return RE_GPU_INT32; // no such 64b type
111  case GT_STORE_REAL16: return RE_GPU_FLOAT16;
112  case GT_STORE_REAL32: return RE_GPU_FLOAT32;
113  case GT_STORE_REAL64: return RE_GPU_FLOAT64;
114  case GT_STORE_STRING: return RE_GPU_INT32; // string indices
115  default:
116  UT_ASSERT(!"No available RE type");
117  return RE_GPU_UINT1;
118  break;
119  }
120 }
121 
122 /// Returns the GPU type and vector size of the attribute based on the
123 /// data array, display option settings
124 GR_API extern RE_GPUType getAttributeType(const char *attrib_name,
125  int &vsize,
126  const GT_DataArrayHandle &pa,
127  const GR_DisplayOption &opts,
128  RE_ArrayType array_type);
129 
130 GR_API extern void * fillAttribData(const char *attrib_name,
131  const GT_DataArrayHandle &pa,
132  const GR_DisplayOption &opts,
133  RE_ArrayType array,
134  bool build_string_tables = true);
135 
136 
161 
162 // Creates a center-point GeoRender where the transforms
163 // are used as individual points
165  const GT_PrimitiveHandle &handle,
166  const GR_UpdateParms &p,
167  const UT_Matrix4DArray &primxforms,
168  const GT_DataArrayHandle &prim_ids,
169  const GT_DataArrayHandle &pnt_ids,
170  const GT_DataArrayHandle &vtx_ids,
171  GR_GeoRender *gr,
172  const char *cache_name,
173  GT_PrimitiveHandle *pt_handle = nullptr,
174  GR_SelectMode *pnt_sel_mode = NULL,
175  bool is_offsets = true,
176  bool build_selection = true);
177 // Creates a center-point GeoRender where the transforms
178 // are used as instance transforms
180  const GT_PrimitiveHandle &handle,
181  const GR_UpdateParms &p,
182  const UT_Matrix4DArray &primxforms,
183  const GT_DataArrayHandle &prim_ids,
184  const GT_DataArrayHandle &pnt_ids,
185  const GT_DataArrayHandle &vtx_ids,
186  const UT_Vector3F &point,
187  RE_CacheVersion point_version,
188  GR_GeoRender *gr,
189  const char *cache_name,
190  GT_PrimitiveHandle *pt_handle = nullptr,
191  GR_SelectMode *pnt_sel_mode = NULL,
192  bool is_offsets = true);
193 
195  const GR_UpdateParms &p,
196  GT_DataArrayHandle prim_id,
197  GT_DataArrayHandle pnt_id,
198  GT_DataArrayHandle vert_id,
199  bool is_offset,
200  int repeat_count);
201 
203 
205 
206 GR_API extern bool inViewFrustum(const UT_BoundingBoxD &bbox,
207  const UT_Matrix4D &objviewproj,
208  const UT_Vector4D *frustum_area = NULL);
209 
210 GR_API extern bool inViewFrustum(const UT_BoundingBoxF &bbox,
211  const UT_Matrix4F &objviewproj);
212 
213 GR_API extern bool inViewFrustumWithLOD(const UT_BoundingBoxF &bbox,
214  const UT_Matrix4F &objviewproj,
215  bool &has_bounds,
216  UT_Vector2F &bounds_2d);
217 
218 GR_API extern bool isRasterized(const UT_Matrix4F &objviewproj,
219  const UT_Vector2F &min_proj_size,
220  const UT_BoundingBoxF &bbox);
221 
222 GR_API extern GU_Connectivity getConnectivityFromString(const char *str);
223 
225 {
226 public:
227  gr_MatBucket() : next(NULL) {}
230 };
232 bucketMaterials(const GT_DataArrayHandle &mat_id);
233 GR_API extern void cleanupBuckets(
234  UT_Array<std::pair<gr_MatBucket *, int>> *&buckets);
235 
237  std::ostream *os = NULL);
239  UT_WorkBuffer &buf);
241  std::ostream *os = NULL);
243  std::ostream *os = NULL);
245  UT_WorkBuffer &buf);
247  UT_WorkBuffer &buf);
248 
249 } // End namespace GR_Utils
250 
251 GR_API size_t
252 UTformatBuffer(char *buf, size_t bufsize, const GR_UpdateReason &r);
253 GR_API size_t
254 UTformatBuffer(char *buf, size_t bufsize, const GR_RenderFlags &r);
255 GR_API size_t
256 UTformatBuffer(char *buf, size_t bufsize, const GR_RenderMode &r);
257 GR_API size_t
258 UTformatBuffer(char *buf, size_t bufsize, const GR_AlphaPass &r);
259 
260 #endif
261 
GR_API void printUpdateReason(GR_UpdateReason r, std::ostream *os=NULL)
GT_Storage
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 int getMaxTexture3DSize(RE_RenderContext rc)
GR_API bool inViewFrustumWithLOD(const UT_BoundingBoxF &bbox, const UT_Matrix4F &objviewproj, bool &has_bounds, UT_Vector2F &bounds_2d)
GR_API void * fillAttribData(const char *attrib_name, const GT_DataArrayHandle &pa, const GR_DisplayOption &opts, RE_ArrayType array, bool build_string_tables=true)
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)
A collection of vertex arrays defining a geometry object. This class acts as a wrapper around multipl...
Definition: RE_Geometry.h:52
GR_API RE_Shader * getDepthCascadeLineShader(RE_Render *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.
GLdouble s
Definition: glad.h:3009
GR_API void printDrawFlags(GR_RenderFlags flags, std::ostream *os=NULL)
GR_API RE_Shader * getRibbonShader(RE_Render *r)
GR_AlphaPass
Definition: GR_Defines.h:125
Temporary container for either a RV_Render and an RE_Render.
GR_API RE_Shader * getColorShader(RE_Render *r)
GR_API RE_Shader * getDepthCubePointShader(RE_Render *r)
set of parameters sent to GR_Primitive::update()
GA_Size GA_Offset
Definition: GA_Types.h:653
GT_API const UT_StringHolder point_id
RE_GPUType
Definition: RE_Types.h:52
GR_AttribMask
Definition: GR_Defines.h:347
GLfloat f
Definition: glcorearb.h:1926
GR_API void cleanupBuckets(UT_Array< std::pair< gr_MatBucket *, int >> *&buckets)
GR_RenderMode
Definition: GR_Defines.h:48
GR_API RE_CacheVersion getAttribVersion(const GT_DataArrayHandle &ph, RE_CacheVersion geo_version)
Return the cache version for attribute 'ph'.
GR_API void buildInstancedCenterPoints(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, const UT_Vector3F &point, RE_CacheVersion point_version, GR_GeoRender *gr, const char *cache_name, GT_PrimitiveHandle *pt_handle=nullptr, GR_SelectMode *pnt_sel_mode=NULL, bool is_offsets=true)
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:104
GU_Connectivity
Definition: GU_SelectType.h:66
UT_IntArray prims
Definition: GR_Utils.h:228
#define GR_API
Definition: GR_API.h:10
GR_API RE_Shader * getDepthCubePrimTransformShader(RE_Render *r)
GR_UpdateReason
Definition: GR_Defines.h:317
GR_API bool inViewFrustum(const UT_BoundingBoxD &bbox, const UT_Matrix4D &objviewproj, const UT_Vector4D *frustum_area=NULL)
GR_API RE_GPUType getAttributeType(const char *attrib_name, int &vsize, const GT_DataArrayHandle &pa, const GR_DisplayOption &opts, RE_ArrayType array_type)
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 RE_Shader * getDepthCubeLineShader(RE_Render *r)
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:88
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 int getMaxTextureSize(RE_RenderContext rc)
GR_API RE_Shader * getWireShader(RE_Render *r)
GLenum mode
Definition: glcorearb.h:99
GR_API RE_Shader * getDepthLinearPrimTransformShader(RE_Render *r)
GR_API void drawModeString(GR_RenderMode mode, UT_WorkBuffer &buf)
GR_API RE_Shader * getDepthWireShader(RE_Render *r)
GR_API RE_Shader * getDepthCascadePointShader(RE_Render *r)
GR_API size_t UTformatBuffer(char *buf, size_t bufsize, const GR_UpdateReason &r)
GR_API RE_Shader * getDepthCubeShader(RE_Render *r)
GR_API RE_Shader * getDepthLinearDisplaceShader(RE_Render *r)
fpreal64 fpreal
Definition: SYS_Types.h:283
gr_MatBucket * next
Definition: GR_Utils.h:229
RE_ArrayType
Definition: RE_Types.h:344
GR_API UT_Array< std::pair< gr_MatBucket *, int > > * bucketMaterials(const GT_DataArrayHandle &mat_id)
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:165
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_SelectMode
Definition: GR_Defines.h:246