summaryrefslogtreecommitdiff
path: root/thirdparty/embree/kernels/geometry/instance.h
blob: 7c0e7e0f4963a240c0e4a88c628a93b36656bf48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2009-2021 Intel Corporation
// SPDX-License-Identifier: Apache-2.0

#pragma once

#include "primitive.h"
#include "../common/scene_instance.h"

namespace embree
{
  struct InstancePrimitive
  {
    struct Type : public PrimitiveType 
    {
      const char* name() const;
      size_t sizeActive(const char* This) const;
      size_t sizeTotal(const char* This) const;
      size_t getBytes(const char* This) const;
    };
    static Type type;

  public:

    /* primitive supports multiple time segments */
    static const bool singleTimeSegment = false;

    /* Returns maximum number of stored primitives */
    static __forceinline size_t max_size() { return 1; }

    /* Returns required number of primitive blocks for N primitives */
    static __forceinline size_t blocks(size_t N) { return N; }

  public:

    InstancePrimitive (const Instance* instance, unsigned int instID) 
    : instance(instance) 
    , instID_(instID)
    {}

    __forceinline void fill(const PrimRef* prims, size_t& i, size_t end, Scene* scene)
    {
      assert(end-i == 1);
      const PrimRef& prim = prims[i]; i++;
      const unsigned int geomID = prim.geomID();
      const Instance* instance = scene->get<Instance>(geomID);
      new (this) InstancePrimitive(instance, geomID);
    }

    __forceinline LBBox3fa fillMB(const PrimRef* prims, size_t& i, size_t end, Scene* scene, size_t itime)
    {
      assert(end-i == 1);
      const PrimRef& prim = prims[i]; i++;
      const unsigned int geomID = prim.geomID();
      const Instance* instance = scene->get<Instance>(geomID);
      new (this) InstancePrimitive(instance,geomID);
      return instance->linearBounds(0,itime);
    }

    __forceinline LBBox3fa fillMB(const PrimRefMB* prims, size_t& i, size_t end, Scene* scene, const BBox1f time_range)
    {
      assert(end-i == 1);
      const PrimRefMB& prim = prims[i]; i++;
      const unsigned int geomID = prim.geomID();
      const Instance* instance = scene->get<Instance>(geomID);
      new (this) InstancePrimitive(instance,geomID);
      return instance->linearBounds(0,time_range);
    }

    /* Updates the primitive */
    __forceinline BBox3fa update(Instance* instance) {
      return instance->bounds(0);
    }

  public:
    const Instance* instance;
    const unsigned int instID_ = std::numeric_limits<unsigned int>::max ();
  };
}