1// Copyright 2009-2021 Intel Corporation
2// SPDX-License-Identifier: Apache-2.0
3
4#pragma once
5
6#include "primitive.h"
7#include "../common/scene_instance.h"
8
9namespace embree
10{
11 struct InstancePrimitive
12 {
13 struct Type : public PrimitiveType
14 {
15 const char* name() const;
16 size_t sizeActive(const char* This) const;
17 size_t sizeTotal(const char* This) const;
18 size_t getBytes(const char* This) const;
19 };
20 static Type type;
21
22 public:
23
24 /* primitive supports multiple time segments */
25 static const bool singleTimeSegment = false;
26
27 /* Returns maximum number of stored primitives */
28 static __forceinline size_t max_size() { return 1; }
29
30 /* Returns required number of primitive blocks for N primitives */
31 static __forceinline size_t blocks(size_t N) { return N; }
32
33 public:
34
35 InstancePrimitive (const Instance* instance, unsigned int instID)
36 : instance(instance)
37 , instID_(instID)
38 {}
39
40 __forceinline void fill(const PrimRef* prims, size_t& i, size_t end, Scene* scene)
41 {
42 assert(end-i == 1);
43 const PrimRef& prim = prims[i]; i++;
44 const unsigned int geomID = prim.geomID();
45 const Instance* instance = scene->get<Instance>(geomID);
46 new (this) InstancePrimitive(instance, geomID);
47 }
48
49 __forceinline LBBox3fa fillMB(const PrimRef* prims, size_t& i, size_t end, Scene* scene, size_t itime)
50 {
51 assert(end-i == 1);
52 const PrimRef& prim = prims[i]; i++;
53 const unsigned int geomID = prim.geomID();
54 const Instance* instance = scene->get<Instance>(geomID);
55 new (this) InstancePrimitive(instance,geomID);
56 return instance->linearBounds(0,itime);
57 }
58
59 __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t& i, size_t end, Scene* scene, const BBox1f time_range)
60 {
61 assert(end-i == 1);
62 const PrimRefMB& prim = prims[i]; i++;
63 const unsigned int geomID = prim.geomID();
64 const Instance* instance = scene->get<Instance>(geomID);
65 new (this) InstancePrimitive(instance,geomID);
66 return instance->linearBounds(0,time_range);
67 }
68
69 /* Updates the primitive */
70 __forceinline BBox3fa update(Instance* instance) {
71 return instance->bounds(0);
72 }
73
74 public:
75 const Instance* instance;
76 const unsigned int instID_ = std::numeric_limits<unsigned int>::max ();
77 };
78}
79