HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_PrimTetra.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2026
3  * Side Effects Software Inc. All rights reserved.
4  *
5  * Redistribution and use of Houdini Development Kit samples in source and
6  * binary forms, with or without modification, are permitted provided that the
7  * following conditions are met:
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  * 2. The name of Side Effects Software may not be used to endorse or
11  * promote products derived from this software without specific prior
12  * written permission.
13  *
14  * THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
15  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
17  * NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
19  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
20  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
23  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef __GR_PrimTetra__
27 #define __GR_PrimTetra__
28 
29 #include <GR/GR_Primitive.h>
30 #include <GUI/GUI_PrimitiveHook.h>
31 #include <RE/RE_RenderContext.h>
32 #include <UT/UT_UniquePtr.h>
33 
34 class RV_Geometry;
35 class RV_ShaderBlock;
37 
38 namespace HDK_Sample
39 {
40 
41 /// The primitive render hook which creates GR_PrimTetra objects.
43 {
44 public:
46  ~GR_PrimTetraHook() override;
47 
48  /// This is called when a new GR_Primitive is required for a tetra.
49  /// gt_prim or geo_prim contains the GT or GEO primitive this object is
50  /// being created for, depending on whether this hook is registered to
51  /// capture GT or GEO primitives. info and cache_name should be passed down
52  /// to the GR_Primitive constructor. processed should return GR_PROCESSED or
53  /// GR_PROCESSED_NON_EXCLUSIVE if a primitive is created. Non-exclusive
54  /// allows other render hooks or the native Houdini primitives to be created
55  /// for the same primitive, which is useful for support hooks (drawing
56  /// decorations, bounding boxes, etc).
58  const GT_PrimitiveHandle &gt_prim,
59  const GEO_Primitive *geo_prim,
60  const GR_RenderInfo *info,
61  const char *cache_name,
62  GR_PrimAcceptResult &processed) override;
63 };
64 
65 /// Primitive object that is created by GR_PrimTetraHook whenever a
66 /// tetrahedron primitive is found. This object can be persistent between
67 /// renders, though display flag changes or navigating though SOPs can cause
68 /// it to be deleted and recreated later.
69 ///
70 /// The tetra is drawn in the Vulkan viewport using Houdini's builtin polygon
71 /// surface shaders (material/VK/psurf_*.prog), so it picks up materials,
72 /// lighting, shadows and object picking like any other surface.
73 class GR_PrimTetra : public GR_Primitive
74 {
75 public:
77  const GR_RenderInfo *info,
78  const char *cache_name,
79  const GEO_Primitive *prim);
80  ~GR_PrimTetra() override;
81 
82  const char *className() const override { return "GR_PrimTetra"; }
83 
84  /// See if the tetra primitive can be consumed by this primitive. Only
85  /// tetra from the same detail will ever be passed in.
88  int geo_type,
89  const GT_PrimitiveHandle &ph,
90  const GEO_Primitive *prim) override;
91 
92  /// Called whenever the parent detail is changed, draw modes are changed,
93  /// selection is changed, or certain volatile display options are changed
94  /// (such as level of detail).
95  void update(
97  const GT_PrimitiveHandle &primh,
98  const GR_UpdateParms &p) override;
99 
100  /// Called whenever the primitive is required to render, which may be more
101  /// than one time per viewport redraw (beauty, shadow passes,
102  /// wireframe-over) It also may be called outside of a viewport redraw to do
103  /// picking of the geometry.
104  void render(
106  GR_RenderMode render_mode,
108  GR_DrawParms dp) override;
109 
110  /// Called for each decoration (point markers, numbers, etc) that is
111  /// enabled in the display options.
112  void renderDecoration(
114  GR_Decoration decor,
115  const GR_DecorationParms &p) override;
116  int renderPick(
118  const GR_DisplayOption *opt,
119  unsigned int pick_type,
120  GR_PickStyle pick_style,
121  bool has_pick_map) override;
122 
123  /// The builtin shader programs used to draw the tetra.
125  {
137 
139  };
140 
141 private:
142  /// Draw the triangles with the given shader.
143  void drawSurface(
145  ShaderType shader_type,
147  const GR_DrawParms &dp);
148  /// Draw the edges, either as wireframe or blended over the surface.
149  void drawWire(RE_RenderContext r, bool wire_over, const GR_DrawParms &dp);
150 
151  int myID;
152  /// GPU buffers and connectivity for the tetra.
154  /// The tetra's primitive number.
155  int myPrimIndex;
156 
157  /// Descriptor sets holding the per-object uniforms (glH_Object). One per
158  /// shader, as the shaders may have different set layouts.
160 
161  /// Per-object uniform blocks (glH_Object), shared by all shaders. A block
162  /// can't change between draws in the same render pass, so the surface and
163  /// wire, which may be drawn in the same pass, each have their own.
164  UT_UniquePtr<RV_ShaderBlock> mySurfaceBlock;
165  UT_UniquePtr<RV_ShaderBlock> myWireBlock;
166 };
167 
168 } // namespace HDK_Sample
169 
170 #endif
A collection of Vulkan UBO, SSBO, and Image shader bindings (descriptor set)
GLbitfield flags
Definition: glcorearb.h:1596
GT_API const UT_StringHolder cache_name
Object that represents drawable geometry. This object holds vertex, instancing and index buffers for ...
Definition: RV_Geometry.h:165
GR_Decoration
Definition: GR_Defines.h:167
Temporary container for either a RV_Render and an RE_Render.
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
set of parameters sent to GR_Primitive::update()
GR_PrimAcceptResult acceptPrimitive(GT_PrimitiveType t, int geo_type, const GT_PrimitiveHandle &ph, const GEO_Primitive *prim) override
Definition: GR_PrimTetra.C:311
GR_RenderMode
Definition: GR_Defines.h:48
The primitive render hook which creates GR_PrimTetra objects.
Definition: GR_PrimTetra.h:42
void renderDecoration(RE_RenderContext r, GR_Decoration decor, const GR_DecorationParms &p) override
Definition: GR_PrimTetra.C:696
int renderPick(RE_RenderContext r, const GR_DisplayOption *opt, unsigned int pick_type, GR_PickStyle pick_style, bool has_pick_map) override
Definition: GR_PrimTetra.C:729
const char * className() const override
Return a string version of this class's name.
Definition: GR_PrimTetra.h:82
GR_PrimAcceptResult
Definition: GR_Defines.h:364
GR_RenderFlags
Definition: GR_Defines.h:88
void render(RE_RenderContext r, GR_RenderMode render_mode, GR_RenderFlags flags, GR_DrawParms dp) override
Definition: GR_PrimTetra.C:468
GLdouble t
Definition: glad.h:2397
GT_PrimitiveType
ShaderType
The builtin shader programs used to draw the tetra.
Definition: GR_PrimTetra.h:124
void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p) override
Definition: GR_PrimTetra.C:324
GR_Primitive * createPrimitive(const GT_PrimitiveHandle &gt_prim, const GEO_Primitive *geo_prim, const GR_RenderInfo *info, const char *cache_name, GR_PrimAcceptResult &processed) override
Definition: GR_PrimTetra.C:66
GR_PrimTetra(const GR_RenderInfo *info, const char *cache_name, const GEO_Primitive *prim)
Definition: GR_PrimTetra.C:289
GLboolean r
Definition: glcorearb.h:1222
GR_PickStyle
Definition: GR_Defines.h:257