HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
tetprim/GR_PrimTetra.h
/*
* Copyright (c) 2026
* Side Effects Software Inc. All rights reserved.
*
* Redistribution and use of Houdini Development Kit samples in source and
* binary forms, with or without modification, are permitted provided that the
* following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. The name of Side Effects Software may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
* NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef __GR_PrimTetra__
#define __GR_PrimTetra__
namespace HDK_Sample
{
/// The primitive render hook which creates GR_PrimTetra objects.
class GR_PrimTetraHook : public GUI_PrimitiveHook
{
public:
~GR_PrimTetraHook() override;
/// This is called when a new GR_Primitive is required for a tetra.
/// gt_prim or geo_prim contains the GT or GEO primitive this object is
/// being created for, depending on whether this hook is registered to
/// capture GT or GEO primitives. info and cache_name should be passed down
/// to the GR_Primitive constructor. processed should return GR_PROCESSED or
/// GR_PROCESSED_NON_EXCLUSIVE if a primitive is created. Non-exclusive
/// allows other render hooks or the native Houdini primitives to be created
/// for the same primitive, which is useful for support hooks (drawing
/// decorations, bounding boxes, etc).
const GT_PrimitiveHandle &gt_prim,
const GEO_Primitive *geo_prim,
const GR_RenderInfo *info,
const char *cache_name,
GR_PrimAcceptResult &processed) override;
};
/// Primitive object that is created by GR_PrimTetraHook whenever a
/// tetrahedron primitive is found. This object can be persistent between
/// renders, though display flag changes or navigating though SOPs can cause
/// it to be deleted and recreated later.
///
/// The tetra is drawn in the Vulkan viewport using Houdini's builtin polygon
/// surface shaders (material/VK/psurf_*.prog), so it picks up materials,
/// lighting, shadows and object picking like any other surface.
class GR_PrimTetra : public GR_Primitive
{
public:
const GR_RenderInfo *info,
const char *cache_name,
const GEO_Primitive *prim);
~GR_PrimTetra() override;
const char *className() const override { return "GR_PrimTetra"; }
/// See if the tetra primitive can be consumed by this primitive. Only
/// tetra from the same detail will ever be passed in.
int geo_type,
const GT_PrimitiveHandle &ph,
const GEO_Primitive *prim) override;
/// Called whenever the parent detail is changed, draw modes are changed,
/// selection is changed, or certain volatile display options are changed
/// (such as level of detail).
void update(
const GT_PrimitiveHandle &primh,
const GR_UpdateParms &p) override;
/// Called whenever the primitive is required to render, which may be more
/// than one time per viewport redraw (beauty, shadow passes,
/// wireframe-over) It also may be called outside of a viewport redraw to do
/// picking of the geometry.
void render(
GR_RenderMode render_mode,
GR_DrawParms dp) override;
/// Called for each decoration (point markers, numbers, etc) that is
/// enabled in the display options.
const GR_DecorationParms &p) override;
const GR_DisplayOption *opt,
unsigned int pick_type,
GR_PickStyle pick_style,
bool has_pick_map) override;
/// The builtin shader programs used to draw the tetra.
{
};
private:
/// Draw the triangles with the given shader.
void drawSurface(
ShaderType shader_type,
const GR_DrawParms &dp);
/// Draw the edges, either as wireframe or blended over the surface.
void drawWire(RE_RenderContext r, bool wire_over, const GR_DrawParms &dp);
int myID;
/// GPU buffers and connectivity for the tetra.
/// The tetra's primitive number.
int myPrimIndex;
/// Descriptor sets holding the per-object uniforms (glH_Object). One per
/// shader, as the shaders may have different set layouts.
/// Per-object uniform blocks (glH_Object), shared by all shaders. A block
/// can't change between draws in the same render pass, so the surface and
/// wire, which may be drawn in the same pass, each have their own.
};
} // namespace HDK_Sample
#endif