Diligent Engine API Reference
Buffer.h
1 /* Copyright 2015-2018 Egor Yusov
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
10  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF ANY PROPRIETARY RIGHTS.
12  *
13  * In no event and under no legal theory, whether in tort (including negligence),
14  * contract, or otherwise, unless required by applicable law (such as deliberate
15  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
16  * liable for any damages, including any direct, indirect, special, incidental,
17  * or consequential damages of any character arising as a result of this License or
18  * out of the use or inability to use the software (including but not limited to damages
19  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
20  * all other commercial damages or losses), even if such Contributor has been advised
21  * of the possibility of such damages.
22  */
23 
24 #pragma once
25 
28 
29 #include "DeviceObject.h"
30 
31 namespace Diligent
32 {
33 
34 // {EC47EAD3-A2C4-44F2-81C5-5248D14F10E4}
35 static constexpr INTERFACE_ID IID_Buffer =
36 { 0xec47ead3, 0xa2c4, 0x44f2, { 0x81, 0xc5, 0x52, 0x48, 0xd1, 0x4f, 0x10, 0xe4 } };
37 
39 
41 enum BUFFER_MODE : Int32
42 {
45 
48 
51 
54 };
55 
58 {
60  Uint32 uiSizeInBytes;
61 
63 
68  Uint32 BindFlags;
69 
72 
76 
79 
81  struct BufferFormat
82  {
85 
88  Uint32 NumComponents;
89 
96 
98 
107  NumComponents( 0 ),
108  IsNormalized(True)
109  {}
110 
112  bool operator == (const BufferFormat& RHS)const
113  {
114  return ValueType == RHS.ValueType &&
115  NumComponents == RHS.NumComponents &&
116  IsNormalized == RHS.IsNormalized;
117  }
118  };
119 
121 
125 
132 
134 
146  uiSizeInBytes(0),
147  BindFlags(0),
149  CPUAccessFlags(0),
152  {}
153 
154 
156 
163  bool operator == (const BufferDesc& RHS)const
164  {
165  return uiSizeInBytes == RHS.uiSizeInBytes &&
166  BindFlags == RHS.BindFlags &&
167  Usage == RHS.Usage &&
169  Mode == RHS.Mode &&
170  Format == RHS.Format &&
172  }
173 };
174 
177 {
179  const void* pData;
180 
182  Uint32 DataSize;
183 
185 
192  pData(nullptr),
193  DataSize(0)
194  {}
195 };
196 
198 
200 class IBuffer : public IDeviceObject
201 {
202 public:
204  virtual void QueryInterface( const Diligent::INTERFACE_ID &IID, IObject **ppInterface ) = 0;
205 
207  virtual const BufferDesc& GetDesc()const = 0;
208 
210 
215  virtual void UpdateData( class IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData) = 0;
216 
218 
225  virtual void CopyData( IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size ) = 0;
226 
228 
233  virtual void Map( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData ) = 0;
234 
241  virtual void Unmap( IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags ) = 0;
242 
244 
254  virtual void CreateView( const struct BufferViewDesc &ViewDesc, class IBufferView **ppView ) = 0;
255 
257 
263  virtual IBufferView* GetDefaultView( BUFFER_VIEW_TYPE ViewType ) = 0;
264 
266 
270  virtual void* GetNativeHandle() = 0;
271 };
272 
273 }
bool operator==(const BufferDesc &RHS) const
Tests if two structures are equivalent.
Definition: Buffer.h:163
Buffer view description.
Definition: BufferView.h:39
Helper value storing the total number of modes in the enumeration.
Definition: Buffer.h:53
BufferData()
Initializes the structure members with default values.
Definition: Buffer.h:191
Describes the buffer initial data.
Definition: Buffer.h:176
Base interface for all objects created by the render device Diligent::IRenderDevice.
Definition: DeviceObject.h:40
virtual void CreateView(const struct BufferViewDesc &ViewDesc, class IBufferView **ppView)=0
Creates a new buffer view.
virtual void UpdateData(class IDeviceContext *pContext, Uint32 Offset, Uint32 Size, const PVoid pData)=0
Updates the data in the buffer.
Undefined type.
Definition: GraphicsTypes.h:41
BUFFER_MODE Mode
Buffer mode.
Definition: Buffer.h:78
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Uint32 ElementByteStride
Buffer element stride, in bytes. For a structured buffer (BufferDesc::Mode equals Diligent::BUFFER_MO...
Definition: Buffer.h:131
USAGE Usage
Buffer usage, see Diligent::USAGE for details.
Definition: Buffer.h:71
Undefined mode.
Definition: Buffer.h:44
bool operator==(const BufferFormat &RHS) const
Tests if two structures are equivalent.
Definition: Buffer.h:112
Structured buffer.
Definition: Buffer.h:50
BufferFormat()
Initializes the structure members with default values.
Definition: Buffer.h:105
virtual void Unmap(IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags)=0
Unmaps the previously mapped buffer.
BufferDesc()
Initializes the structure members with default values.
Definition: Buffer.h:145
Buffer interface.
Definition: Buffer.h:200
Formated buffer.
Definition: Buffer.h:47
Device context interface.
Definition: DeviceContext.h:443
BUFFER_MODE
Describes the buffer access mode.
Definition: Buffer.h:41
Uint32 uiSizeInBytes
Size of the buffer, in bytes. For a uniform buffer, this must be multiple of 16.
Definition: Buffer.h:60
virtual void * GetNativeHandle()=0
Returns native buffer handle specific to the underlying graphics API.
A resource that requires read and write access by the GPU and can also be occasionally written by the...
Definition: GraphicsTypes.h:95
Buffer description.
Definition: Buffer.h:57
VALUE_TYPE
Value type.
Definition: GraphicsTypes.h:39
virtual void CopyData(IDeviceContext *pContext, IBuffer *pSrcBuffer, Uint32 SrcOffset, Uint32 DstOffset, Uint32 Size)=0
Copies the data from other buffer.
VALUE_TYPE ValueType
Type of components. For a formatted buffer, this value cannot be VT_UNDEFINED.
Definition: Buffer.h:84
virtual void Map(IDeviceContext *pContext, MAP_TYPE MapType, Uint32 MapFlags, PVoid &pMappedData)=0
Maps the buffer.
USAGE
Resource usage.
Definition: GraphicsTypes.h:84
Buffer format description.
Definition: Buffer.h:81
virtual IBufferView * GetDefaultView(BUFFER_VIEW_TYPE ViewType)=0
Returns the pointer to the default view.
Describes common device object attributes.
Definition: GraphicsTypes.h:900
virtual void QueryInterface(const Diligent::INTERFACE_ID &IID, IObject **ppInterface)=0
Queries the specific interface, see IObject::QueryInterface() for details.
Uint32 DataSize
Data size, in bytes.
Definition: Buffer.h:182
Uint32 NumComponents
Number of components. Allowed values: 1, 2, 3, 4. For a formatted buffer, this value cannot be 0...
Definition: Buffer.h:88
BufferFormat Format
Buffer format.
Definition: Buffer.h:124
Uint32 BindFlags
Buffer bind flags, see Diligent::BIND_FLAGS for details.
Definition: Buffer.h:68
Buffer view interface.
Definition: BufferView.h:91
const void * pData
Pointer to the data.
Definition: Buffer.h:179
MAP_TYPE
Resource mapping type.
Definition: GraphicsTypes.h:125
Uint32 CPUAccessFlags
CPU access flags or 0 if no CPU access is allowed, see Diligent::CPU_ACCESS_FLAG for details...
Definition: Buffer.h:75
BUFFER_VIEW_TYPE
Buffer view type.
Definition: GraphicsTypes.h:219
virtual const BufferDesc & GetDesc() const =0
Returns the buffer description used to create the object.
Bool IsNormalized
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.
Definition: Buffer.h:95