OWL
Loading...
Searching...
No Matches
Geometry.h
1// ======================================================================== //
2// Copyright 2019-2020 Ingo Wald //
3// //
4// Licensed under the Apache License, Version 2.0 (the "License"); //
5// you may not use this file except in compliance with the License. //
6// You may obtain a copy of the License at //
7// //
8// http://www.apache.org/licenses/LICENSE-2.0 //
9// //
10// Unless required by applicable law or agreed to in writing, software //
11// distributed under the License is distributed on an "AS IS" BASIS, //
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. //
13// See the License for the specific language governing permissions and //
14// limitations under the License. //
15// ======================================================================== //
16
17#pragma once
18
19#include "RegisteredObject.h"
20#include "SBTObject.h"
21#include "Module.h"
22#include "Buffer.h"
23
24namespace owl {
25
26 struct Geom;
27
31 struct ProgramDesc {
32 Module::SP module;
33 std::string progName;
34 };
35
36 /* abstraction for any sort of geometry type - describes the
37 programs to use, and structure of the SBT records, when building
38 shader binding tables (SBTs) with geometries of this type. This
39 will later get subclassed into triangle geometries, user/custom
40 primtivie geometries, etc */
41 struct GeomType : public SBTObjectType {
42 typedef std::shared_ptr<GeomType> SP;
43
48 struct DeviceData : public RegisteredObject::DeviceData {
49 typedef std::shared_ptr<DeviceData> SP;
50
52 DeviceData(const DeviceContext::SP &device);
53
57
60 virtual void fillPGDesc(OptixProgramGroupDesc &pgDesc,
61 GeomType *gt, int rayType);
62
64 std::vector<OptixProgramGroup> hgPGs;
65 };
66
68 GeomType(Context *const context,
70 size_t varStructSize,
72 const std::vector<OWLVarDecl> &varDecls);
73
75 std::string toString() const override;
76
78 inline DeviceData &getDD(const DeviceContext::SP &device) const;
79
81 RegisteredObject::DeviceData::SP createOn(const DeviceContext::SP &device) override;
82
86 virtual std::shared_ptr<Geom> createGeom() = 0;
87
89 void setAnyHitProgram(int rayType,
90 Module::SP module,
91 const std::string &progName);
92
94 void setClosestHitProgram(int rayType,
95 Module::SP module,
96 const std::string &progName);
97
99 std::vector<ProgramDesc> closestHit;
100
102 std::vector<ProgramDesc> anyHit;
103 };
104
108 struct Geom : public SBTObject<GeomType> {
109 typedef std::shared_ptr<Geom> SP;
110
112 Geom(Context *const context, GeomType::SP geomType);
113
115 std::string toString() const override;
116
120 void writeSBTRecord(
121 uint8_t *const sbtRecord,
124 const DeviceContext::SP &device,
127 int rayTypeID);
128
131 GeomType::SP geomType;
132 };
133
134 // ------------------------------------------------------------------
135 // implementation section
136 // ------------------------------------------------------------------
137
139 inline GeomType::DeviceData &GeomType::getDD(const DeviceContext::SP &device) const
140 {
141 assert(device && device->ID >= 0 && device->ID < (int)deviceData.size());
142 return deviceData[device->ID]->as<DeviceData>();
143 }
144
145} // ::owl
Definition: Context.h:32
Definition: Geometry.h:48
void buildHitGroupPrograms(GeomType *gt)
std::vector< OptixProgramGroup > hgPGs
Definition: Geometry.h:64
virtual void fillPGDesc(OptixProgramGroupDesc &pgDesc, GeomType *gt, int rayType)
Definition: Geometry.cpp:33
Definition: Geometry.h:41
virtual std::shared_ptr< Geom > createGeom()=0
DeviceData & getDD(const DeviceContext::SP &device) const
Definition: Geometry.h:139
std::string toString() const override
Definition: Geometry.cpp:78
void setAnyHitProgram(int rayType, Module::SP module, const std::string &progName)
Definition: Geometry.cpp:95
std::vector< ProgramDesc > closestHit
Definition: Geometry.h:99
std::vector< ProgramDesc > anyHit
Definition: Geometry.h:102
void setClosestHitProgram(int rayType, Module::SP module, const std::string &progName)
Definition: Geometry.cpp:84
RegisteredObject::DeviceData::SP createOn(const DeviceContext::SP &device) override
Definition: Geometry.cpp:72
Definition: Geometry.h:108
std::string toString() const override
Definition: Geometry.cpp:118
void writeSBTRecord(uint8_t *const sbtRecord, const DeviceContext::SP &device, int rayTypeID)
Definition: Geometry.cpp:127
GeomType::SP geomType
Definition: Geometry.h:131
std::vector< DeviceData::SP > deviceData
Definition: Object.h:86
Definition: Geometry.h:31
Definition: SBTObject.h:33
const std::vector< OWLVarDecl > varDecls
Definition: SBTObject.h:70
const size_t varStructSize
Definition: SBTObject.h:66
Definition: SBTObject.h:118