summaryrefslogtreecommitdiffstats
path: root/Graphics/GraphicsEngine/interface/BufferView.h
blob: 412397ae85c7338eada743db9aabbe3aa518fe97 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/*
 *  Copyright 2019-2021 Diligent Graphics LLC
 *  Copyright 2015-2019 Egor Yusov
 *  
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 *  In no event and under no legal theory, whether in tort (including negligence), 
 *  contract, or otherwise, unless required by applicable law (such as deliberate 
 *  and grossly negligent acts) or agreed to in writing, shall any Contributor be
 *  liable for any damages, including any direct, indirect, special, incidental, 
 *  or consequential damages of any character arising as a result of this License or 
 *  out of the use or inability to use the software (including but not limited to damages 
 *  for loss of goodwill, work stoppage, computer failure or malfunction, or any and 
 *  all other commercial damages or losses), even if such Contributor has been advised 
 *  of the possibility of such damages.
 */

#pragma once

// clang-format off

/// \file
/// Definition of the Diligent::IBufferView interface and related data structures

#include "DeviceObject.h"

DILIGENT_BEGIN_NAMESPACE(Diligent)

// {E2E83490-E9D2-495B-9A83-ABB413A38B07}
static const struct INTERFACE_ID IID_BufferView =
    {0xe2e83490, 0xe9d2, 0x495b, {0x9a, 0x83, 0xab, 0xb4, 0x13, 0xa3, 0x8b, 0x7}};

/// Buffer format description
struct BufferFormat
{
    /// Type of components. For a formatted buffer views, this value cannot be VT_UNDEFINED
    VALUE_TYPE ValueType    DEFAULT_INITIALIZER(VT_UNDEFINED);

    /// Number of components. Allowed values: 1, 2, 3, 4. 
    /// For a formatted buffer, this value cannot be 0
    Uint8 NumComponents     DEFAULT_INITIALIZER(0);

    /// For signed and unsigned integer value types 
    /// (VT_INT8, VT_INT16, VT_INT32, VT_UINT8, VT_UINT16, VT_UINT32)
    /// indicates if the value should be normalized to [-1,+1] or 
    /// [0, 1] range respectively. For floating point types
    /// (VT_FLOAT16 and VT_FLOAT32), this member is ignored.
    Bool IsNormalized       DEFAULT_INITIALIZER(False);


#if DILIGENT_CPP_INTERFACE
    // We have to explicitly define constructors because otherwise Apple's clang fails to compile the following legitimate code:
    //     BufferFormat{VT_FLOAT32, 4}
    
    BufferFormat()noexcept{}

    BufferFormat(VALUE_TYPE _ValueType,
                 Uint8      _NumComponents,
                 Bool       _IsNormalized   = BufferFormat{}.IsNormalized)noexcept : 
        ValueType     {_ValueType    },
        NumComponents {_NumComponents},
        IsNormalized  {_IsNormalized }
    {}


    /// Tests if two structures are equivalent
    bool operator == (const BufferFormat& RHS)const
    {
        return ValueType     == RHS.ValueType && 
               NumComponents == RHS.NumComponents &&
               IsNormalized  == RHS.IsNormalized;
    }
#endif
};
typedef struct BufferFormat BufferFormat;

/// Buffer view description
struct BufferViewDesc DILIGENT_DERIVE(DeviceObjectAttribs)

    /// View type. See Diligent::BUFFER_VIEW_TYPE for details.
    BUFFER_VIEW_TYPE ViewType DEFAULT_INITIALIZER(BUFFER_VIEW_UNDEFINED);

    /// Format of the view. This member is only used for formatted and raw buffers.
    /// To create raw view of a raw buffer, set Format.ValueType member to VT_UNDEFINED
    /// (default value).
    struct BufferFormat Format;

    /// Offset in bytes from the beginnig of the buffer to the start of the
    /// buffer region referenced by the view
    Uint32 ByteOffset       DEFAULT_INITIALIZER(0);

    /// Size in bytes of the referenced buffer region
    Uint32 ByteWidth        DEFAULT_INITIALIZER(0);


#if DILIGENT_CPP_INTERFACE
    BufferViewDesc()noexcept{}

    explicit
    BufferViewDesc(BUFFER_VIEW_TYPE _ViewType,
                   BufferFormat     _Format     = BufferViewDesc{}.Format,
                   Uint32           _ByteOffset = BufferViewDesc{}.ByteOffset,
                   Uint32           _ByteWidth  = BufferViewDesc{}.ByteWidth)noexcept :
        ViewType    {_ViewType  },
        Format      {_Format    },
        ByteOffset  {_ByteOffset},
        ByteWidth   {_ByteWidth }
    {}

    /// Comparison operator tests if two structures are equivalent

    /// \param [in] RHS - reference to the structure to perform comparison with
    /// \return 
    /// - True if all members of the two structures are equal.
    /// - False otherwise
    /// \remarks
    /// The operator ignores DeviceObjectAttribs::Name field.
    bool operator==(const BufferViewDesc& RHS) const
    {
               // Name is primarily used for debug purposes and does not affect the view.
               // It is ignored in comparison operation.
        return //strcmp(Name, RHS.Name) == 0 &&
               ViewType  == RHS.ViewType   &&
               ByteOffset== RHS.ByteOffset &&
               ByteWidth == RHS.ByteWidth  &&
               Format    == RHS.Format;
    }
#endif
};
typedef struct BufferViewDesc BufferViewDesc;

#define DILIGENT_INTERFACE_NAME IBufferView
#include "../../../Primitives/interface/DefineInterfaceHelperMacros.h"

#define IBufferViewInclusiveMethods \
    IDeviceObjectInclusiveMethods;  \
    IBufferViewMethods BufferView

/// Buffer view interface

/// To create a buffer view, call IBuffer::CreateView().
/// \remarks
/// Buffer view holds strong references to the buffer. The buffer
/// will not be destroyed until all views are released.
DILIGENT_BEGIN_INTERFACE(IBufferView, IDeviceObject)
{
#if DILIGENT_CPP_INTERFACE
    /// Returns the buffer view description used to create the object
    virtual const BufferViewDesc& METHOD(GetDesc)() const override = 0;
#endif

    /// Returns pointer to the referenced buffer object.

    /// The method does *NOT* call AddRef() on the returned interface,
    /// so Release() must not be called.
    VIRTUAL struct IBuffer* METHOD(GetBuffer)(THIS) CONST PURE;
};
DILIGENT_END_INTERFACE

#include "../../../Primitives/interface/UndefInterfaceHelperMacros.h"

#if DILIGENT_C_INTERFACE

// clang-format off

#    define IBufferView_GetDesc(This) (const struct BufferViewDesc*)IDeviceObject_GetDesc(This)

#    define IBufferView_GetBuffer(This) CALL_IFACE_METHOD(BufferView, GetBuffer, This)

// clang-format on

#endif

DILIGENT_END_NAMESPACE // namespace Diligent