bufferDescriptor.h
Go to the documentation of this file.
1 //
2 // Copyright 2015 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24
25 #ifndef OPENSUBDIV3_OSD_BUFFER_DESCRIPTOR_H
26 #define OPENSUBDIV3_OSD_BUFFER_DESCRIPTOR_H
27
28 #include "../version.h"
29 #include <string.h>
30
31 namespace OpenSubdiv {
32 namespace OPENSUBDIV_VERSION {
33
34 namespace Osd {
35
46
47 // example:
48 // n
49 // -----+----------------------------------------+-------------------------
50 // | vertex 0 |
51 // -----+----------------------------------------+-------------------------
52 // | X Y Z R G B A Xu Yu Zu Xv Yv Zv |
53 // -----+----------------------------------------+-------------------------
54 // <------------- stride = 13 -------------->
55 //
56 // - XYZ (offset = n+0, length = 3, stride = 13)
57 // - RGBA (offset = n+3, length = 4, stride = 13)
58 // - uTangent (offset = n+7, length = 3, stride = 13)
59 // - vTangent (offset = n+10, length = 3, stride = 13)
60 //
61 struct BufferDescriptor {
62
64 BufferDescriptor() : offset(0), length(0), stride(0) { }
65
67 BufferDescriptor(int o, int l, int s) : offset(o), length(l), stride(s) { }
68
70 int GetLocalOffset() const {
71 return stride > 0 ? offset % stride : 0;
72 }
73
75 bool IsValid() const {
76 return ((length > 0) &&
77 (length <= stride - GetLocalOffset()));
78 }
79
81 void Reset() {
82 offset = length = stride = 0;
83 }
84
86 bool operator == (BufferDescriptor const &other) const {
87 return (offset == other.offset &&
88 length == other.length &&
89 stride == other.stride);
90 }
91
93 bool operator != (BufferDescriptor const &other) const {
94 return !(this->operator==(other));
95 }
96
98 int offset;
100 int length;
102 int stride;
103 };
104
105 } // end namespace Osd
106
107 } // end namespace OPENSUBDIV_VERSION
108 using namespace OPENSUBDIV_VERSION;
109
110 } // end namespace OpenSubdiv
111
112 #endif // OPENSUBDIV3_OSD_BUFFER_DESCRIPTOR_H
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::operator==
bool operator==(BufferDescriptor const &other) const
True if the descriptors are identical.
Definition: bufferDescriptor.h:86
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::length
int length
number or length of the data
Definition: bufferDescriptor.h:100
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::Reset
void Reset()
Resets the descriptor to default.
Definition: bufferDescriptor.h:81
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::stride
int stride
stride to the next element
Definition: bufferDescriptor.h:102
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::BufferDescriptor
BufferDescriptor()
Default Constructor.
Definition: bufferDescriptor.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor
BufferDescriptor is a struct which describes buffer elements in interleaved data buffers. Almost all Osd Evaluator APIs take BufferDescriptors along with device-specific buffer objects.
Definition: bufferDescriptor.h:61
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::operator!=
bool operator!=(BufferDescriptor const &other) const
True if the descriptors are not identical.
Definition: bufferDescriptor.h:93
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::offset
int offset
offset to desired element data
Definition: bufferDescriptor.h:98
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::BufferDescriptor
BufferDescriptor(int o, int l, int s)
Constructor.
Definition: bufferDescriptor.h:67
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::GetLocalOffset
int GetLocalOffset() const
Returns the relative offset within a stride.
Definition: bufferDescriptor.h:70
OpenSubdiv
Definition: error.h:30
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::IsValid
bool IsValid() const
True if the descriptor values are internally consistent.
Definition: bufferDescriptor.h:75