OpenSubdiv: opensubdiv/osd/bufferDescriptor.h Source File

| OpenSubdiv

Loading...
Searching...
No Matches
bufferDescriptor.h
Go to the documentation of this file.
1//
2// Copyright 2015 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://opensubdiv.org/license.
6//
7
8#ifndef OPENSUBDIV3_OSD_BUFFER_DESCRIPTOR_H
9#define OPENSUBDIV3_OSD_BUFFER_DESCRIPTOR_H
10
11#include "../version.h"
12#include <string.h>
13
14namespace OpenSubdiv {
15namespace OPENSUBDIV_VERSION {
16
17 namespace Osd {
18
29
30// example:
31// n
32// -----+----------------------------------------+-------------------------
33// | vertex 0 |
34// -----+----------------------------------------+-------------------------
35// | X Y Z R G B A Xu Yu Zu Xv Yv Zv |
36// -----+----------------------------------------+-------------------------
37// <------------- stride = 13 -------------->
38//
39// - XYZ (offset = n+0, length = 3, stride = 13)
40// - RGBA (offset = n+3, length = 4, stride = 13)
41// - uTangent (offset = n+7, length = 3, stride = 13)
42// - vTangent (offset = n+10, length = 3, stride = 13)
43//
44 struct BufferDescriptor {
45
47 BufferDescriptor() : offset(0), length(0), stride(0) { }
48
50 BufferDescriptor(int o, int l, int s) : offset(o), length(l), stride(s) { }
51
53 int GetLocalOffset() const {
54 return stride > 0 ? offset % stride : 0;
55 }
56
58 bool IsValid() const {
59 return ((length > 0) &&
60 (length <= stride - GetLocalOffset()));
61 }
62
64 void Reset() {
65 offset = length = stride = 0;
66 }
67
69 bool operator == (BufferDescriptor const &other) const {
70 return (offset == other.offset &&
71 length == other.length &&
72 stride == other.stride);
73 }
74
76 bool operator != (BufferDescriptor const &other) const {
77 return !(this->operator==(other));
78 }
79
81 int offset;
83 int length;
85 int stride;
86};
87
88} // end namespace Osd
89
90} // end namespace OPENSUBDIV_VERSION
91using namespace OPENSUBDIV_VERSION;
92
93} // end namespace OpenSubdiv
94
95#endif // OPENSUBDIV3_OSD_BUFFER_DESCRIPTOR_H
OpenSubdiv
Definition limits.h:15
OpenSubdiv::OPENSUBDIV_VERSION
Definition limits.h:16
OpenSubdiv::OPENSUBDIV_VERSION::Osd
Definition bufferDescriptor.h:17
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::stride
int stride
stride to the next element
Definition bufferDescriptor.h:85
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::Reset
void Reset()
Resets the descriptor to default.
Definition bufferDescriptor.h:64
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::BufferDescriptor
BufferDescriptor()
Default Constructor.
Definition bufferDescriptor.h:47
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::BufferDescriptor
BufferDescriptor(int o, int l, int s)
Constructor.
Definition bufferDescriptor.h:50
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::length
int length
number or length of the data
Definition bufferDescriptor.h:83
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::operator!=
bool operator!=(BufferDescriptor const &other) const
True if the descriptors are not identical.
Definition bufferDescriptor.h:76
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::operator==
bool operator==(BufferDescriptor const &other) const
True if the descriptors are identical.
Definition bufferDescriptor.h:69
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::IsValid
bool IsValid() const
True if the descriptor values are internally consistent.
Definition bufferDescriptor.h:58
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::GetLocalOffset
int GetLocalOffset() const
Returns the relative offset within a stride.
Definition bufferDescriptor.h:53
OpenSubdiv::OPENSUBDIV_VERSION::Osd::BufferDescriptor::offset
int offset
offset to desired element data
Definition bufferDescriptor.h:81