Rise
The Vieneo Province
Loading...
Searching...
No Matches
Geometry11.h
Go to the documentation of this file.
1#pragma once
2#include "FixedFunction11.h"
3#include <vector>
4#include <map>
5#include <cstdint>
6
7namespace Rendering
8{
9 // The authored layouts are retained on the CPU for mesh editing and physics.
10 // Their GPU representation belongs exclusively to the D3D11 device.
12 {
13 static constexpr UINT Absent=UINT(-1);
15 UINT uv[2]{Absent,Absent},uvDimensions[2]{2,2};
16 bool transformed=false;
17 bool Valid() const;
18 std::vector<D3D11_INPUT_ELEMENT_DESC> Elements() const;
19 UINT PackedColors() const {return (diffuse!=Absent ? 1u : 0u)|(specular!=Absent ? 2u : 0u);}
20 bool operator<(const VertexLayout11& other) const;
21 };
22
24 {
25 public:
26 Geometry11()=default;
27 Geometry11(const Geometry11&)=delete;
31 HRESULT Create(ID3D11Device* device,UINT bytes,bool dynamic,bool index=false,bool indices32=false);
32 HRESULT Lock(UINT offset,UINT size,void** destination,bool readOnly=false,bool discard=false);
34 HRESULT BindVertices(ID3D11DeviceContext* context,const VertexLayout11& layout,UINT byteOffset,bool canonical);
35 HRESULT BindIndices(ID3D11DeviceContext* context);
36 HRESULT NativeBuffer(ID3D11DeviceContext* context,ID3D11Buffer** result);
37 const std::vector<uint8_t>& Bytes() const {return bytes;}
38 UINT Size() const {return UINT(bytes.size());}
39 bool Indices32() const {return indices32;}
40 bool Locked() const {return locked;}
41 uint64_t Revision() const {return revision;}
42 // Keep authored CPU data while releasing every reference to a lost device.
43 void ReleaseDevice();
44 HRESULT RestoreDevice(ID3D11Device* device);
45 void Reset();
46 private:
47 struct Converted
48 {
49 Microsoft::WRL::ComPtr<ID3D11Buffer> buffer;
50 uint64_t revision=0;
51 };
52 HRESULT Upload(ID3D11DeviceContext* context);
53 Microsoft::WRL::ComPtr<ID3D11Device> device;
54 Microsoft::WRL::ComPtr<ID3D11Buffer> native;
55 std::vector<uint8_t> bytes;
56 std::map<VertexLayout11,Converted> converted;
57 uint64_t revision=1,uploaded=0;
58 bool dynamic=false,index=false,indices32=false,locked=false,readOnly=false;
59 };
60}
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
HRESULT Create(ID3D11Device *device, UINT bytes, bool dynamic, bool index=false, bool indices32=false)
bool Indices32() const
Definition Geometry11.h:39
HRESULT NativeBuffer(ID3D11DeviceContext *context, ID3D11Buffer **result)
HRESULT RestoreDevice(ID3D11Device *device)
Geometry11(Geometry11 &&)=default
Microsoft::WRL::ComPtr< ID3D11Device > device
Definition Geometry11.h:53
Geometry11 & operator=(Geometry11 &&)=default
HRESULT BindIndices(ID3D11DeviceContext *context)
std::map< VertexLayout11, Converted > converted
Definition Geometry11.h:56
HRESULT Lock(UINT offset, UINT size, void **destination, bool readOnly=false, bool discard=false)
Microsoft::WRL::ComPtr< ID3D11Buffer > native
Definition Geometry11.h:54
Geometry11(const Geometry11 &)=delete
std::vector< uint8_t > bytes
Definition Geometry11.h:55
HRESULT Upload(ID3D11DeviceContext *context)
bool Locked() const
Definition Geometry11.h:40
uint64_t Revision() const
Definition Geometry11.h:41
UINT Size() const
Definition Geometry11.h:38
HRESULT BindVertices(ID3D11DeviceContext *context, const VertexLayout11 &layout, UINT byteOffset, bool canonical)
const std::vector< uint8_t > & Bytes() const
Definition Geometry11.h:37
Geometry11 & operator=(const Geometry11 &)=delete
Microsoft::WRL::ComPtr< ID3D11Buffer > buffer
Definition Geometry11.h:49
bool operator<(const VertexLayout11 &other) const
static constexpr UINT Absent
Definition Geometry11.h:13
UINT PackedColors() const
Definition Geometry11.h:19
std::vector< D3D11_INPUT_ELEMENT_DESC > Elements() const