HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GR_PrimTetra.C
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 #include "GEO_PrimTetra.h"
27 #include "GR_PrimTetra.h"
28 
29 #include <GR/GR_DisplayOption.h>
30 #include <GR/GR_DrawParms.h>
31 #include <GR/GR_Material.h>
32 #include <GR/GR_Uniforms.h>
33 #include <GR/GR_UpdateParms.h>
34 #include <GT/GT_GEOPrimitive.h>
35 #include <GU/GU_Detail.h>
36 #include <RE/RE_CachedObject.h>
37 #include <RV/RV_Geometry.h>
38 #include <RV/RV_Render.h>
39 #include <RV/RV_ShaderBlock.h>
40 #include <RV/RV_ShaderProgram.h>
42 #include <RV/RV_Type.h>
43 #include <RV/RV_VKBuffer.h>
44 #include <RV/RV_VKFramebuffer.h>
45 #include <SYS/SYS_StaticAssert.h>
46 #include <UT/UT_Matrix4.h>
47 #include <UT/UT_ScopeExit.h>
48 #include <UT/UT_Swap.h>
49 #include <UT/UT_Vector4.h>
50 
51 #include <iterator>
52 
53 using namespace HDK_Sample;
54 
55 // See GEO_PrimTetra::registerMyself() for installation of the hook.
56 
58 {
59 }
60 
62 {
63 }
64 
67  const GT_PrimitiveHandle &gt_prim,
68  const GEO_Primitive *geo_prim,
69  const GR_RenderInfo *info,
70  const char *cache_name,
71  GR_PrimAcceptResult &processed)
72 {
73  return new GR_PrimTetra(info, cache_name, geo_prim);
74 }
75 
76 namespace
77 {
78 
79 // The tetra has 4 points and 4 triangles. Each triangle has its own 3
80 // vertices (12 in all), so that each face can have its own normal.
81 const int theNumPoints = 4;
82 const int theNumFaces = 4;
83 const int theNumVertices = theNumFaces * 3;
84 // The tetra points of each face.
85 const int theFacePoints[theNumFaces][3] =
86 {
87  { 0, 1, 2 },
88  { 0, 2, 3 },
89  { 1, 2, 3 },
90  { 0, 3, 1 },
91 };
92 
93 // Line list of the 6 edges, as point indices.
94 const uint32 theWireIndices[] =
95 {
96  0, 1, 0, 2, 0, 3,
97  1, 2, 1, 3, 2, 3,
98 };
99 
100 const char *theWireColorName = "WireCd";
101 
102 // Connectivity groups. The triangles are drawn per vertex, the wireframe and
103 // point decorations per point.
104 const int theTriangleGroup = 0;
105 const int theWireGroup = 1;
106 const int thePointGroup = 2;
107 
108 // Decorations the tetra can draw. The tetra has no point normals, as each
109 // face is shaded with its own normal, so only vertex normals are shown.
110 const GR_Decoration theDecorations[] = {
114 
115 // Builtin Houdini shaders used to draw the tetra. These are the same .prog
116 // files that polygon meshes use, and are found in $HFS/houdini/glsl. The depth
117 // variants are used for shadow maps.
118 const struct
119 {
120  const char *myProgram;
121  const char *myDefines;
122 } theShaderInfo[] = {
123  {"material/VK/psurf_headlight.prog", nullptr},
124  {"material/VK/psurf_material.prog", nullptr},
125  {"material/VK/psurf_const.prog", nullptr},
126  {"material/VK/psurf_wireframe.prog", nullptr},
127  {"pick/VK/object_pick.prog", nullptr},
128  {"material/VK/psurf_matte.prog", nullptr},
129  {"material/VK/psurf_depth.prog", nullptr},
130  {"material/VK/psurf_depth.prog", "#define GEN_CASCADING"},
131  {"material/VK/psurf_depth.prog", "#define GEN_CUBEMAP"},
132  {"material/VK/psurf_depth.prog",
133  "#define GEN_CASCADING\n#define GEN_ONE_SHADOWMAP"},
134  {"material/VK/psurf_depth.prog",
135  "#define GEN_CUBEMAP\n#define GEN_ONE_SHADOWMAP"},
136 };
138 
139 // Shaders are shared by all tetras and loaded on first use
141 bool theShaderLoaded[GR_PrimTetra::NUM_SHADERS] = {};
142 
145 {
146  if (!theShaderLoaded[type])
147  {
148  // Searches HOUDINI_GLSL_PATH for the .prog. Extra defines compile a
149  // variant of the program.
150  theShaderLoaded[type] = true;
152  r->instance(), theShaderInfo[type].myProgram,
153  theShaderInfo[type].myDefines);
154  }
155  return theShaders[type];
156 }
157 
159 grGetDepthShader(RV_Render *r, GR_RenderMode render_mode)
160 {
161  if (render_mode == GR_RENDER_DEPTH)
163 
164  // Shadow maps render all cascades or cube faces at once using multiview
165  // if available, otherwise one at a time.
166  const RV_Framebuffer *fb = r->getDrawFramebuffer();
167  const bool single = fb && !fb->getMultiview();
168 
169  if (render_mode == GR_RENDER_DEPTH_CUBE)
172 
175 }
176 
177 // Find the material to shade with: the object's material, or the default
178 // material if materials are hidden.
180 grGetMaterial(
181  RV_Render *r,
184  const GR_DrawParms &dp)
185 {
186  if (!dp.vk_materials)
187  return GR_MaterialPtr();
188 
189  const GR_MaterialAtlas &atlas = *dp.vk_materials;
190  GR_MaterialPtr mat;
191 
192  if (dp.opts->common().showMaterials()
193  && !(flags & GR_RENDER_FLAG_HIDE_MATERIALS))
194  mat = atlas.get(0, dp);
195  else
196  mat = atlas.getFactoryMaterial();
197 
198  // The non-textured shaders used here can't bind textured materials, so
199  // fall back to the default or factory material.
200  for (const GR_MaterialPtr &m :
201  {mat, atlas.getDefaultMaterial(), atlas.getFactoryMaterial()})
202  {
203  if (m && m->checkCompatible(r, shader))
204  return m;
205  }
206  return GR_MaterialPtr();
207 }
208 
209 // Set up the transforms of instance group 0, which the shaders apply.
210 // Packed primitives may give the tetra its own transform, and instancing
211 // gives a list of transforms in p.instances, one per copy to draw.
212 void
213 grUpdateInstances(
214  RV_Render *r,
215  RV_Geometry *geo,
216  UT_Matrix4D prim_xform,
217  const GR_UpdateParms &p)
218 {
219  const UT_Matrix4DArray *instances = p.instances;
220  if (instances && instances->entries() > 1)
221  {
222  const int num_inst = instances->entries();
223 
224  // The primitive transform is applied to every instance.
225  geo->setConstInstanceGroupTransform(0, UT_Matrix4F(prim_xform), false);
226 
227  // Upload the instance transforms if they changed.
228  const bool changed = geo->setInstanceGroupAttrib(
229  0, "InstTransform", RV_GPU_MATRIX4, 1, 1, num_inst);
230  RE_CacheVersion inst_version;
231  geo->getInstanceAttribVersion(0, "InstTransform", inst_version);
232 
233  if ((changed || inst_version != p.instance_version)
234  && geo->populateBuffers(r))
235  {
236  UT_Matrix4FArray xforms(num_inst, num_inst);
237  for (int i = 0; i < num_inst; i++)
238  xforms(i) = UT_Matrix4F((*instances)(i));
239 
240  geo->getInstanceGroupAttrib(0, "InstTransform")
241  ->uploadData(r, xforms);
243  0, "InstTransform", p.instance_version);
244  }
245  }
246  else
247  {
248  // A single copy only needs one combined transform.
249  if (instances && instances->entries() == 1)
250  prim_xform = prim_xform * (*instances)(0);
251 
252  geo->setConstInstanceGroupTransform(0, UT_Matrix4F(prim_xform), true);
253  geo->freeInstanceGroupAttrib(0, "InstTransform");
254  }
255 }
256 
257 // A deferred draw that sets the light mask push constants read by the
258 // material shader before drawing.
259 class grLightMaskDrawTask : public RV_Render::DefaultDrawTask
260 {
261 public:
262  grLightMaskDrawTask(
263  RV_Geometry *geo,
264  int connect_group,
265  int instance_group,
266  int use_light_mask,
267  int light_mask)
268  : RV_Render::DefaultDrawTask(
269  geo, connect_group, nullptr, instance_group)
270  , myUseLightMask(use_light_mask)
271  , myLightMask(light_mask)
272  {
273  }
274 
275  bool runDraw(RV_Render *r) override
276  {
277  r->getPushConstants().bindInt("use_light_mask", myUseLightMask);
278  r->getPushConstants().bindInt("light_mask", myLightMask);
280  }
281 
282 private:
283  int myUseLightMask;
284  int myLightMask;
285 };
286 
287 } // End anonymous namespace.
288 
290  const GR_RenderInfo *info,
291  const char *cache_name,
292  const GEO_Primitive *prim)
293  : GR_Primitive(info, cache_name, GA_PrimCompat::TypeMask(0))
294 {
295  // The tetra's primitive type ID, used by acceptPrimitive().
296  myID = prim->getTypeId().get();
297  myPrimIndex = 0;
298 
299  // Only the decorations in theDecorations are drawn for the tetra.
300  int64 decor_mask = 0;
301  for (int i = 0; theDecorations[i] != GR_NO_DECORATION; i++)
302  decor_mask |= int64(1) << theDecorations[i];
303  setSupportedDecorations(decor_mask);
304 }
305 
307 {
308 }
309 
313  int geo_type,
314  const GT_PrimitiveHandle &ph,
315  const GEO_Primitive *prim)
316 {
317  if (geo_type == myID)
318  return GR_PROCESSED;
319 
320  return GR_NOT_PROCESSED;
321 }
322 
323 void
325  RE_RenderContext rc,
326  const GT_PrimitiveHandle &primh,
327  const GR_UpdateParms &p)
328 {
329  // Fetch the GEO primitive from the GT primitive handle
330  const GEO_PrimTetra *tet = nullptr;
331  getGEOPrimFromGT<GEO_PrimTetra>(primh, tet);
332 
333  if (!tet)
334  {
335  myGeo.reset();
336  return;
337  }
338 
339  RV_Render *r = rc;
340 
341  // Define the layout of the geometry once, as a tetra's topology never
342  // changes. The builtin surface shaders read P, N, Cd and Alpha. Any
343  // other attributes default to zero.
344  if (!myGeo)
345  {
346  myGeo = UTmakeUnique<RV_Geometry>();
347  myGeo->setName(getCacheName());
348  myGeo->setNumPoints(theNumPoints);
349  myGeo->setVertexBufferSize(theNumVertices);
350 
351  // Point attributes. pointID is shown by point number decorations.
352  myGeo->createAttribute("P", RV_GPU_FLOAT32, 4);
353  myGeo->createAttribute("pointID", RV_GPU_INT32, 1, -1, false);
354 
355  // Vertex attributes. PointIndex maps each vertex to its point, so
356  // per-vertex draws can read point attributes. polygonVertexIdx is
357  // shown by vertex number decorations.
358  myGeo->createVertexBuffer("N", RV_GPU_FLOAT32, 4);
359  myGeo->createVertexBuffer("PointIndex", RV_GPU_INT32, 1, -1, false);
360  myGeo->createVertexBuffer(
361  "polygonVertexIdx", RV_GPU_INT32, 1, -1, false);
362 
363  myGeo->createConstant("Cd", RV_GPU_FLOAT32, 4);
364  myGeo->createConstant("Alpha", RV_GPU_FLOAT32, 1);
365 
366  // Connectivity, for shaded, wireframe and point decorations
367  myGeo->connectSomeVerts(
368  theTriangleGroup, RV_PRIM_TRIANGLES, 0, theNumVertices);
369  myGeo->connectIndexedPrims(
370  theWireGroup, RV_PRIM_LINES, std::size(theWireIndices));
371  myGeo->connectAllPrims(thePointGroup, RV_PRIM_POINTS);
372 
373  // Allocate the GPU buffers before uploading any data to them.
374  if (!myGeo->populateBuffers(r))
375  {
376  myGeo.reset();
377  return;
378  }
379 
380  const fpreal32 col[4] = {1.0, 1.0, 1.0, 1.0};
381  const fpreal32 alpha = 1.0;
382 
383  myGeo->getAttribute("Cd")->uploadData(r, col, sizeof(col));
384  myGeo->getAttribute("Alpha")->uploadData(r, &alpha, sizeof(alpha));
385  myGeo->getIndexBuffer(theWireGroup)->uploadData(r, theWireIndices);
386  }
387 
388  // Set up the decoration renderer for the enabled decorations.
389  GR_UpdateParms decor_parms(p);
391  p.dopts, p.required_dec, decor_parms, theDecorations,
393 
394  UT_Matrix4D prim_xform(1.0);
395  if (primh->getPrimitiveTransform())
396  primh->getPrimitiveTransform()->getMatrix(prim_xform);
397 
398  grUpdateInstances(r, myGeo.get(), prim_xform, p);
399 
400  // If the cached version of P matches the geometry, no upload is required.
401  RE_CacheVersion pos_version;
402  if (myGeo->getAttributeVersion("P", pos_version)
403  && pos_version == p.geo_version)
404  return;
405 
406  // Extract tetra point positions and numbers.
407  UT_Vector3F pt[4];
408  int32 pt_num[4];
409  {
411  const GU_Detail *dtl = georl.getGdp();
412 
413  for (int v = 0; v < 4; v++)
414  {
415  const GA_Offset ptoff = dtl->vertexPoint(tet->getVertexOffset(v));
416  pt[v] = dtl->getPos3(ptoff);
417  pt_num[v] = dtl->pointIndex(ptoff);
418  }
419  }
420 
421  // The primitive number, for prim number decorations.
422  myPrimIndex = tet->getMapIndex();
423 
424  const UT_Vector3F center = (pt[0] + pt[1] + pt[2] + pt[3]) * 0.25f;
425  UT_Vector4F nml[theNumVertices];
426  int32 vtx_pt[theNumVertices];
427 
428  for (int f = 0; f < theNumFaces; f++)
429  {
430  int va = theFacePoints[f][0];
431  int vb = theFacePoints[f][1];
432  int vc = theFacePoints[f][2];
433  const UT_Vector3F &a = pt[va];
434 
435  // Houdini polygons wind clockwise when viewed from the outside, so
436  // order the triangle that way and point its normal outward.
437  UT_Vector3F n = cross(pt[vb] - a, pt[vc] - a);
438  if (dot(n, a - center) > 0)
439  UTswap(vb, vc);
440  else
441  n = -n;
442  n.normalize();
443 
444  nml[f * 3] = nml[f * 3 + 1] = nml[f * 3 + 2] = UT_Vector4F(n, 0.0f);
445 
446  vtx_pt[f * 3] = va;
447  vtx_pt[f * 3 + 1] = vb;
448  vtx_pt[f * 3 + 2] = vc;
449  }
450 
451  UT_Vector4F pos[theNumPoints];
452  for (int v = 0; v < theNumPoints; v++)
453  pos[v] = UT_Vector4F(pt[v], 1.0f);
454 
455  // Copy the new data to the GPU. The tetra points are also its vertex
456  // numbers, so vtx_pt is used for both PointIndex and polygonVertexIdx.
457  myGeo->getAttribute("P")->uploadData(r, pos);
458  myGeo->getAttribute("pointID")->uploadData(r, pt_num);
459  myGeo->getAttribute("N")->uploadData(r, nml);
460  myGeo->getAttribute("PointIndex")->uploadData(r, vtx_pt);
461  myGeo->getAttribute("polygonVertexIdx")->uploadData(r, vtx_pt);
462 
463  // Always set the cache version after assigning data.
464  myGeo->setAttributeVersion("P", p.geo_version);
465 }
466 
467 void
469  RE_RenderContext rc,
470  GR_RenderMode render_mode,
471  GR_RenderFlags flags,
472  GR_DrawParms dp)
473 {
474  // update() is always called before render(), so myGeo is ready to draw.
475  if (!myGeo || !rc.isVulkan())
476  return;
477 
478  const bool unlit = (flags & GR_RENDER_FLAG_UNLIT);
479  const bool wire_over = (flags & GR_RENDER_FLAG_WIRE_OVER);
480 
481  switch (render_mode)
482  {
483  // Beauty pass for headlight-only lighting, written directly to color.
484  case GR_RENDER_HEADLIGHT:
485  drawSurface(
486  rc, unlit ? SHADER_CONSTANT : SHADER_HEADLIGHT, flags, dp);
487  break;
488 
489  // Beauty pass for full lighting, written to the G-buffer which is lit
490  // later by the viewport.
491  case GR_RENDER_MATERIAL:
492  drawSurface(
493  rc, unlit ? SHADER_CONSTANT : SHADER_MATERIAL, flags, dp);
494  break;
495 
496  // Unlit, constant color.
497  case GR_RENDER_CONSTANT:
498  drawSurface(rc, SHADER_CONSTANT, flags, dp);
499  if (wire_over)
500  drawWire(rc, true, dp);
501  break;
502 
503  // Depth pre-pass and shadow maps.
504  case GR_RENDER_DEPTH:
507  drawSurface(rc, grGetDepthShader(rc, render_mode), flags, dp);
508  break;
509 
510  // Object selection at the scene level.
512  drawSurface(rc, SHADER_OBJECT_PICK, flags, dp);
513  break;
514 
515  // Mouseover (locate) highlight. The viewport sets the highlight color
516  // and blending, and the shader draws it over the existing surface.
517  case GR_RENDER_MATTE:
518  drawSurface(rc, SHADER_MATTE, flags, dp);
519  break;
520 
521  // Lines only.
522  case GR_RENDER_WIREFRAME:
523  case GR_RENDER_XRAY_LINE:
524  drawWire(rc, false, dp);
525  break;
526 
527  // Fill the depth buffer so the wires behind the tetra are hidden.
530  drawSurface(rc, SHADER_DEPTH, flags, dp);
531  drawWire(rc, false, dp);
532  break;
533 
534  // Wire-over-shaded drawn after the beauty pass.
536  if (wire_over)
537  drawWire(rc, true, dp);
538  break;
539 
540  default:
541  break;
542  }
543 }
544 
545 void
546 GR_PrimTetra::drawSurface(
547  RE_RenderContext rc,
548  ShaderType shader_type,
549  GR_RenderFlags flags,
550  const GR_DrawParms &dp)
551 {
552  RV_Render *r = rc;
553  RV_ShaderProgram *shader = grGetShader(r, shader_type);
554  if (!shader)
555  return;
556 
557  // Shaders that use a material (headlight, material, constant) need one
558  // bound to the material set.
559  GR_MaterialPtr mat;
560  if (shader->hasSet(RV_SET_MATERIAL))
561  {
562  mat = grGetMaterial(r, shader, flags, dp);
563  if (!mat)
564  return;
565  }
566 
567  // Object uniforms (glH_Object) contain the object transform, set up by
568  // the viewport. Push them so that changes don't affect other primitives.
569  GR_Uniforms *u = rc.uniforms();
570  u->pushObjectUniforms();
572 
574  u->setObjLightingEnabled((flags & GR_RENDER_FLAG_UNLIT) ? 0 : 1);
575 
576  // Save the pipeline state so it is restored after drawing.
577  r->pushPipeState();
579  r->setShader(shader);
580 
581  // The matte overlays the already drawn surface, so allow equal depth.
582  if (shader_type == SHADER_MATTE)
583  r->setDepthState(true, RE_ZLEQUAL);
584 
585  // Bind the pass (glH_PassInfo) and object (glH_Object) uniforms, and
586  // the material.
587  if (!u->prepareForDraw(r, myObjectSets[shader_type], mySurfaceBlock, shader)
588  || (mat && !mat->bind(r, shader, dp.opts)))
589  {
590  return;
591  }
592 
593  const bool instanced = dp.draw_instanced;
594  const int inst_group = dp.instance_group;
595 
596  if (shader_type == SHADER_MATERIAL)
597  {
598  // Which lights affect the surface.
599  const int use_light_mask = u->hasPrimLightMask() ? 1 : 0;
600  const int light_mask = u->getLightMask();
601 
602  // r->draw() takes a draw task to do a deferred draw. All the draws of
603  // the current render pass are run later, in a single VkRenderPass.
604  // None is active during render(), so commands that aren't allowed
605  // inside one, like vkCmdCopyBuffer(), can be used here.
606  //
607  // Because of this, draws in the same pass that need different values
608  // in the per-object uniform block need separate RV_ShaderBlocks, as
609  // a block can't be updated between them (see mySurfaceBlock and
610  // myWireBlock).
611  //
612  // The render state (depth, blend and viewport state, the bound shader
613  // and descriptor sets) is saved with each draw and restored when the
614  // task runs, but push constants are not, so the task sets them.
615  r->draw(UTmakeUnique<grLightMaskDrawTask>(
616  myGeo.get(), theTriangleGroup, instanced ? inst_group : -1,
617  use_light_mask, light_mask));
618  }
619  else if (instanced)
620  r->drawInstanced(myGeo.get(), theTriangleGroup, inst_group);
621  else
622  r->draw(myGeo.get(), theTriangleGroup);
623 }
624 
625 void
626 GR_PrimTetra::drawWire(
627  RE_RenderContext rc,
628  bool wire_over,
629  const GR_DrawParms &dp)
630 {
631  RV_Render *r = rc;
632  RV_ShaderProgram *shader = grGetShader(r, SHADER_WIREFRAME);
633  if (!shader)
634  return;
635 
636  GR_Uniforms *u = rc.uniforms();
637  u->pushObjectUniforms();
639 
641 
642  // The wire color is set up by the viewport. Wireframe lines are opaque.
643  UT_Vector4F wire_color = u->getObjWireColor();
644  if (!wire_over)
645  {
646  wire_color.w() = 1.0f;
647  u->setObjWireColor(wire_color);
648  }
649 
650  // The wireframe shader takes its color from Cd.
651  RV_OverrideList overrides;
652  RV_Buffer *wire_cd = myGeo->createAllocatedAttribute(
653  r, theWireColorName, RV_GPU_FLOAT32, 4, RV_ATTRIBUTE_CONSTANT);
654  if (wire_cd)
655  {
656  UT_Vector4F col = wire_color;
657  col.w() = 1.0f;
658  wire_cd->uploadData(
659  r, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, col.data(), sizeof(col));
660  overrides.append("Cd");
661  overrides.append(theWireColorName);
662  }
663 
664  r->pushPipeState();
666 
667  // wire-over lines are blended over the surface.
668  if (wire_over)
669  {
670  // Blend the lines over the surface without writing depth.
671  r->setBlendEnable(true);
672  r->setBlendFunction(
675  r->setDepthState(true, RE_ZLESS, false);
676  }
677  r->setShader(shader);
678 
679  if (!u->prepareForDraw(
680  r, myObjectSets[SHADER_WIREFRAME], myWireBlock, shader))
681  {
682  return;
683  }
684 
685  // Draw the lines, using the overridden Cd.
686  if (dp.draw_instanced)
687  {
688  r->drawInstanced(
689  myGeo.get(), theWireGroup, dp.instance_group, &overrides);
690  }
691  else
692  r->draw(myGeo.get(), theWireGroup, &overrides);
693 }
694 
695 void
698  GR_Decoration decor,
699  const GR_DecorationParms &p)
700 {
701  if (!myGeo)
702  return;
703 
704  // Point decorations draw the point group. Vertex and primitive
705  // decorations draw the triangles.
706  int connect_group = theTriangleGroup;
709 
710  if (decor == GR_POINT_MARKER || decor == GR_POINT_NUMBER
711  || decor == GR_POINT_POSITION)
712  {
713  connect_group = thePointGroup;
715  }
716 
717  // All 4 triangles are one primitive, so give the shaders its number.
718  GR_Uniforms *u = r.uniforms();
719  u->pushObjectUniforms();
721  u->setObjPrimConstandID(myPrimIndex + 1);
722 
724  r, myGeo.get(), connect_group, decor, p.opts, p.render_flags, p.overlay,
725  p.override_vis, p.instance_group, GR_SELECT_NONE, prim_type);
726 }
727 
728 int
731  const GR_DisplayOption *opt,
732  unsigned int pick_type,
733  GR_PickStyle pick_style,
734  bool has_pick_map)
735 {
736  // This example is not pickable.
737  return 0;
738 }
exint pushObjectUniforms()
type
Definition: core.h:556
void drawInstanced(RV_Geometry *geo, int connect_index, int instance_group, const RV_OverrideList *override_list=nullptr)
const GR_MaterialAtlas * vk_materials
Definition: GR_DrawParms.h:22
UT_IntrusivePtr< GR_Material > GR_MaterialPtr
Definition: GR_Defines.h:410
GLbitfield flags
Definition: glcorearb.h:1596
#define SYS_STATIC_ASSERT(expr)
#define UT_AT_SCOPE_EXIT(...)
Definition: UT_ScopeExit.h:95
RV_PushConstants & getPushConstants()
Definition: RV_Render.h:383
int int32
Definition: SYS_Types.h:39
constexpr size_t size(const OIIO::span< T, E > &c)
Definition: span.h:381
const GR_MaterialPtr & getFactoryMaterial() const
Definition: GR_Material.h:269
GR_DecorationRender * myDecorRender
Definition: GR_Primitive.h:658
void UTswap(T &a, T &b)
Definition: UT_Swap.h:35
GU_ConstDetailHandle geometry
const GR_DisplayOption * opts
const GLdouble * v
Definition: glcorearb.h:837
RE_CacheVersion geo_version
void setAlphaBlendFunction(RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor)
Set the blending weights for alpha only.
int instance_group
Definition: GR_DrawParms.h:25
void draw(RV_Geometry *geo, int connect_index, const RV_OverrideList *override_list=nullptr)
Draw the geometry 'geo' with the given connectivity group.
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
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
static RV_ShaderProgram * loadShaderProgram(RV_Instance *inst, const char *program, const char *extra_defines=nullptr)
SYS_FORCE_INLINE const GA_PrimitiveTypeId & getTypeId() const
Definition: GA_Primitive.h:177
const UT_Vector4 & getObjWireColor() const
Definition: GR_Uniforms.h:240
SYS_FORCE_INLINE UT_Vector3 getPos3(GA_Offset ptoff) const
The ptoff passed is the point offset.
Definition: GA_Detail.h:194
RE_CacheVersion instance_version
GR_Decoration
Definition: GR_Defines.h:167
void setConstInstanceGroupTransform(int instance_group, const UT_Matrix4F &xform, bool remove_instanced_xform)
float fpreal32
Definition: SYS_Types.h:200
bool getMultiview() const
Temporary container for either a RV_Render and an RE_Render.
void popObjectUniforms(exint l=-1)
void setBlendEnable(bool blend)
Enable framebuffer blending.
const char * getCacheName() const
The base GL cache name assigned to this primitive.
Definition: GR_Primitive.h:396
set of parameters sent to GR_Primitive::update()
GA_Size GA_Offset
Definition: GA_Types.h:653
bool hasSet(int set_num) const
Query if set 'set_num' is used by the shader.
void drawDecorationForGeo(RE_RenderContext r, RV_Geometry *geo, GR_Decoration dec, const GR_DisplayOption *opts, GR_DecorRenderFlags flags, bool overlay, bool override_vis, int instance_group, GR_SelectMode smode, GR_DecorationRender::PrimitiveType t=GR_DecorationRender::PRIM_TRIANGLE, RE_OverrideList *override_list=NULL)
GR_PrimAcceptResult acceptPrimitive(GT_PrimitiveType t, int geo_type, const GT_PrimitiveHandle &ph, const GEO_Primitive *prim) override
Definition: GR_PrimTetra.C:311
GLdouble n
Definition: glcorearb.h:2008
bool populateBuffers(RV_Render *r)
Populates all RV_Buffers declared above which haven't been populated yet.
GLfloat f
Definition: glcorearb.h:1926
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
void popPipeState()
Restore the pipeline state from a previous pushPipeState().
GR_RenderMode
Definition: GR_Defines.h:48
const GR_DisplayOption & dopts
GR_CommonDispOption & common()
GR_DecorRenderFlags render_flags
const GR_DisplayOption * opts
Definition: GR_DrawParms.h:21
void renderDecoration(RE_RenderContext r, GR_Decoration decor, const GR_DecorationParms &p) override
Definition: GR_PrimTetra.C:696
void setSupportedDecorations(int64 mask)
Definition: GR_Primitive.h:650
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
void setShader(RV_ShaderProgramBase *sh)
Set the current shader to 'sh'.
fpreal64 dot(const CE_VectorT< T > &a, const CE_VectorT< T > &b)
Definition: CE_Vector.h:138
UT_Matrix4T< fpreal32 > UT_Matrix4F
long long int64
Definition: SYS_Types.h:116
GLfloat GLfloat GLfloat alpha
Definition: glcorearb.h:112
bool bindInt(const UT_StringRef &name, int v, int array_index=0, int *opt_idx=nullptr)
SYS_FORCE_INLINE int get() const
SYS_FORCE_INLINE GA_Offset vertexPoint(GA_Offset vertex) const
Given a vertex, return the point it references.
Definition: GA_Detail.h:538
void setObjSelectMode(int v)
Definition: GR_Uniforms.h:285
GR_PrimAcceptResult
Definition: GR_Defines.h:364
GR_RenderFlags
Definition: GR_Defines.h:88
void pushPipeState()
GR_Uniforms * uniforms()
exint append()
Definition: UT_Array.h:142
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
bool getInstanceAttribVersion(int instance_group, const UT_StringHolder &name, RE_CacheVersion &out_ver) const
Fetch the per-instance attribute version (to avoid refilling)
void setObjWireColor(const UT_Vector4 &v)
Definition: GR_Uniforms.h:239
RV_Instance * instance()
The instance associated with this render.
Definition: RV_Render.h:91
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:669
SYS_FORCE_INLINE GA_Index pointIndex(GA_Offset offset) const
Given a point's data offset, return its index.
Definition: GA_Detail.h:358
GT_PrimitiveType
bool setInstanceGroupAttrib(int instance_group, const UT_StringHolder &name, RV_GPUType data_type, int vector_size, int instance_step, int num_instances, exint capacity=-1, bool normalized=true)
Create an per-instance attribute Reserve an buffer for per-instance data (call populateBuffers() to c...
GLuint shader
Definition: glcorearb.h:785
SYS_FORCE_INLINE GA_Index getMapIndex() const
Gets the index of this primitive in the detail containing it.
Definition: GA_Primitive.h:151
RV_Buffer * getInstanceGroupAttrib(int instance_group, const UT_StringHolder &name) const
Fetch the buffer backing an per-instance attribute, usually to fill it.
ShaderType
The builtin shader programs used to draw the tetra.
Definition: GR_PrimTetra.h:124
UT_Vector4T< fpreal32 > UT_Vector4F
RV_Framebuffer * getDrawFramebuffer()
Get the current framebuffer (may be null)
bool runDraw(RV_Render *r) override
void update(RE_RenderContext r, const GT_PrimitiveHandle &primh, const GR_UpdateParms &p) override
Definition: GR_PrimTetra.C:324
void setDepthState(bool enable, RE_ZFunction func=RE_ZLESS, bool writing=true, float near=0.0, float far=1.0, bool clamp=false)
Set the depth state for zbuffer operations.
constexpr SYS_FORCE_INLINE const T * data() const noexcept
Definition: UT_Vector4.h:226
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
bool hasPrimLightMask() const
Definition: GR_Uniforms.h:577
constexpr SYS_FORCE_INLINE T & w() noexcept
Definition: UT_Vector4.h:499
bool uploadData(RV_Render *r, VkBufferUsageFlags new_usage, const void *data, exint data_size, exint data_offset=0)
Upload data to the buffer Upload data to the buffer and add a barrier based on its usage...
bool freeInstanceGroupAttrib(int instance_group, const UT_StringHolder &name)
Remove per-instance attribute and free its resource.
GR_DecorationOverride required_dec
SYS_FORCE_INLINE GA_Offset getVertexOffset(GA_Size primvertexnum) const
Definition: GA_Primitive.h:244
void setInstanceAttribVersion(int instance_group, const UT_StringHolder &name, const RE_CacheVersion &ver)
Set the per-instance attribute version (to avoid refilling)
unsigned int uint32
Definition: SYS_Types.h:40
GR_PrimTetra(const GR_RenderInfo *info, const char *cache_name, const GEO_Primitive *prim)
Definition: GR_PrimTetra.C:289
unsigned getLightMask() const
Definition: GR_Uniforms.h:517
Simple class for a mutli-integer cache tag.
SYS_FORCE_INLINE UT_StorageMathFloat_t< T > normalize() noexcept
Definition: UT_Vector3.h:378
void setupFromDisplayOptions(const GR_DisplayOption &opts, GR_DecorationOverride select_dec, GR_UpdateParms &parms, const GR_Decoration *supported, GR_AttribMask mask)
GLboolean r
Definition: glcorearb.h:1222
set of parameters sent to GR_Primitive::update()
Definition: GR_Uniforms.h:56
A vulkan buffer object.
Definition: RV_VKBuffer.h:75
void setObjPrimConstandID(int v)
Definition: GR_Uniforms.h:297
bool prepareForDraw(RV_Render *r, UT_UniquePtr< RV_ShaderVariableSet > &obj_set, UT_UniquePtr< RV_ShaderBlock > &obj_ubo, const RV_ShaderProgramBase *shader)
const GR_MaterialPtr & getDefaultMaterial() const
Definition: GR_Material.h:265
void setBlendFunction(RE_BlendSourceFactor source_factor, RE_BlendDestFactor dest_factor)
Set the blending weights for color and alpha.
bool isVulkan() const
GR_MaterialPtr get(int material_id) const
Definition: GR_Material.h:276
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
const GU_Detail * getGdp() const
void setObjLightingEnabled(int v)
Definition: GR_Uniforms.h:380
bool draw_instanced
Definition: GR_DrawParms.h:24
const UT_Matrix4DArray * instances
GR_PickStyle
Definition: GR_Defines.h:257