Plasma Engine  2.0
Loading...
Searching...
No Matches
DynamicMeshBufferResource.h
1#pragma once
2
3#include <Core/ResourceManager/Resource.h>
4#include <RendererCore/Meshes/MeshBufferResource.h>
5#include <RendererCore/RendererCoreDLL.h>
6#include <RendererFoundation/RendererFoundationDLL.h>
7
9
11{
12 plGALPrimitiveTopology::Enum m_Topology = plGALPrimitiveTopology::Triangles;
13 plGALIndexType::Enum m_IndexType = plGALIndexType::UInt;
14 plUInt32 m_uiMaxPrimitives = 0;
15 plUInt32 m_uiMaxVertices = 0;
16 bool m_bColorStream = false;
17};
18
19struct PL_RENDERERCORE_DLL plDynamicMeshVertex
20{
21 PL_DECLARE_POD_TYPE();
22
23 plVec3 m_vPosition;
24 plVec2 m_vTexCoord;
25 plVec3 m_vEncodedNormal;
26 plVec4 m_vEncodedTangent;
27 //plColorLinearUB m_Color;
28
29 PL_ALWAYS_INLINE void EncodeNormal(const plVec3& vNormal)
30 {
31 // store in [0; 1] range
32 m_vEncodedNormal = vNormal * 0.5f + plVec3(0.5f);
33
34 // this is the same
35 //plMeshBufferUtils::EncodeNormal(normal, plByteArrayPtr(reinterpret_cast<plUInt8*>(&m_vEncodedNormal), sizeof(plVec3)), plMeshNormalPrecision::_32Bit).IgnoreResult();
36 }
37
38 PL_ALWAYS_INLINE void EncodeTangent(const plVec3& vTangent, float fBitangentSign)
39 {
40 // store in [0; 1] range
41 m_vEncodedTangent.x = vTangent.x * 0.5f + 0.5f;
42 m_vEncodedTangent.y = vTangent.y * 0.5f + 0.5f;
43 m_vEncodedTangent.z = vTangent.z * 0.5f + 0.5f;
44 m_vEncodedTangent.w = fBitangentSign < 0.0f ? 0.0f : 1.0f;
45
46 // this is the same
47 //plMeshBufferUtils::EncodeTangent(tangent, bitangentSign, plByteArrayPtr(reinterpret_cast<plUInt8*>(&m_vEncodedTangent), sizeof(plVec4)), plMeshNormalPrecision::_32Bit).IgnoreResult();
48 }
49};
50
51class PL_RENDERERCORE_DLL plDynamicMeshBufferResource : public plResource
52{
53 PL_ADD_DYNAMIC_REFLECTION(plDynamicMeshBufferResource, plResource);
54 PL_RESOURCE_DECLARE_COMMON_CODE(plDynamicMeshBufferResource);
56
57public:
60
61 PL_ALWAYS_INLINE const plDynamicMeshBufferResourceDescriptor& GetDescriptor() const { return m_Descriptor; }
62 PL_ALWAYS_INLINE plGALBufferHandle GetVertexBuffer() const { return m_hVertexBuffer; }
63 PL_ALWAYS_INLINE plGALBufferHandle GetIndexBuffer() const { return m_hIndexBuffer; }
64 PL_ALWAYS_INLINE plGALBufferHandle GetColorBuffer() const { return m_hColorBuffer; }
65
68 {
69 m_bAccessedVB = true;
70 return m_VertexData;
71 }
72
77 {
78 m_bAccessedIB = true;
79 return m_Index16Data;
80 }
81
86 {
87 m_bAccessedIB = true;
88 return m_Index32Data;
89 }
90
95 {
96 m_bAccessedCB = true;
97 return m_ColorData;
98 }
99
100 const plVertexDeclarationInfo& GetVertexDeclaration() const { return m_VertexDeclaration; }
101
112 void UpdateGpuBuffer(plGALCommandEncoder* pGALCommandEncoder, plUInt32 uiFirstVertex = 0, plUInt32 uiNumVertices = plMath::MaxValue<plUInt32>(), plUInt32 uiFirstIndex = 0, plUInt32 uiNumIndices = plMath::MaxValue<plUInt32>(), plGALUpdateMode::Enum mode = plGALUpdateMode::Discard);
113
114private:
115 virtual plResourceLoadDesc UnloadData(Unload WhatToUnload) override;
116 virtual plResourceLoadDesc UpdateContent(plStreamReader* Stream) override;
117 virtual void UpdateMemoryUsage(MemoryUsage& out_NewMemoryUsage) override;
118
119 bool m_bAccessedVB = false;
120 bool m_bAccessedIB = false;
121 bool m_bAccessedCB = false;
122
123 plGALBufferHandle m_hVertexBuffer;
124 plGALBufferHandle m_hIndexBuffer;
125 plGALBufferHandle m_hColorBuffer;
127
128 plVertexDeclarationInfo m_VertexDeclaration;
133};
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition DynamicArray.h:81
Definition DynamicMeshBufferResource.h:52
plArrayPtr< plColorLinearUB > AccessColorData()
Grants write access to the color data, and flags the data as 'dirty'.
Definition DynamicMeshBufferResource.h:94
plArrayPtr< plDynamicMeshVertex > AccessVertexData()
Grants write access to the vertex data, and flags the data as 'dirty'.
Definition DynamicMeshBufferResource.h:67
plArrayPtr< plUInt32 > AccessIndex32Data()
Grants write access to the 32 bit index data, and flags the data as 'dirty'.
Definition DynamicMeshBufferResource.h:85
plArrayPtr< plUInt16 > AccessIndex16Data()
Grants write access to the 16 bit index data, and flags the data as 'dirty'.
Definition DynamicMeshBufferResource.h:76
Definition RendererFoundationDLL.h:418
Definition CommandEncoder.h:11
The base class for all resources.
Definition Resource.h:10
Interface for binary in (read) streams.
Definition Stream.h:22
constexpr TYPE MaxValue()
Returns the largest possible positive value (that is not infinity).
Definition DynamicMeshBufferResource.h:11
Definition DynamicMeshBufferResource.h:20
Enum
Definition RendererFoundationDLL.h:336
@ Discard
Buffer must be completely overwritten. No old data will be read. Data will not persist across frames.
Definition RendererFoundationDLL.h:337
Describes in which loading state a resource currently is, and how many different quality levels there...
Definition Declarations.h:102
Definition MeshBufferResource.h:24