Skip to content

Commit

Permalink
feat: add geometry set allocator for beam and rope
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Pollind <mpollind@gmail.com>
  • Loading branch information
pollend committed Dec 13, 2023
1 parent 1549519 commit 2e82b61
Show file tree
Hide file tree
Showing 10 changed files with 555 additions and 497 deletions.
2 changes: 1 addition & 1 deletion HPL2/include/graphics/GeometrySet.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ namespace hpl {
inline SharedBuffer& indexBuffer() { return m_indexBuffer; }
void operator=(GeometrySet&& set);
void operator=(const GeometrySet& set) = delete;
std::shared_ptr<GeometrySetSubAllocation> allocate(uint32_t numElements, uint32_t numIndecies);
std::shared_ptr<GeometrySet::GeometrySetSubAllocation> allocate(uint32_t numElements, uint32_t numIndecies);
private:
OffsetAllocator::Allocator m_vertexStreamAllocator;
OffsetAllocator::Allocator m_indexStreamAllocator;
Expand Down
9 changes: 4 additions & 5 deletions HPL2/include/graphics/GraphicsBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,8 @@ namespace hpl {
case BufferType::MappedBuffer:
switch(m_indexType) {
case IndexBufferType::Uint32:
ASSERT(m_asset->m_buffer.begin() + (m_byteOffset + (index * sizeof(uint32_t))) < m_asset->m_buffer.end());
return *reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + (m_byteOffset + (index * sizeof(uint32_t))));
case IndexBufferType::Uint16:
ASSERT(m_asset->m_buffer.begin() + (m_byteOffset + (index * sizeof(uint16_t))) < m_asset->m_buffer.end());
return *reinterpret_cast<uint16_t*>(reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + (m_byteOffset + (index * sizeof(uint16_t))));
}
break;
Expand Down Expand Up @@ -278,7 +276,6 @@ namespace hpl {
uint32_t v = value;
auto buf = std::span(reinterpret_cast<const uint8_t*>(&v), sizeof(uint32_t));
const size_t targetOffset = (m_byteOffset + (index * sizeof(uint32_t)));
details::testAndResize(m_asset->m_buffer, targetOffset + buf.size());
std::copy(buf.begin(), buf.end(), reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + targetOffset);
break;
}
Expand Down Expand Up @@ -399,8 +396,10 @@ namespace hpl {
ASSERT(m_asset->m_buffer.begin() + targetOffset < m_asset->m_buffer.end());
return *reinterpret_cast<T*>(m_asset->m_buffer.data() + targetOffset);
}
case BufferType::MappedBuffer: {
ASSERT(false);
case BufferType::MappedBuffer:
{
ASSERT(m_asset->m_mapped.m_size == 0 || targetOffset < m_asset->m_mapped.m_size);
return *reinterpret_cast<T*>(reinterpret_cast<uint8_t*>(m_asset->m_mapped.m_mappedData) + targetOffset);
break;
}
}
Expand Down
6 changes: 1 addition & 5 deletions HPL2/include/graphics/RendererDeferred2.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace hpl {
HPL_RTTI_IMPL_CLASS(iRenderer, cRendererDeferred, "{B3E5E5A1-1F9C-4F5C-9B9B-5B9B9B5B9B9B}")
public:

static constexpr TinyImageFormat DepthBufferFormat = TinyImageFormat_D32_SFLOAT_S8_UINT;
static constexpr TinyImageFormat DepthBufferFormat = TinyImageFormat_D32_SFLOAT;
static constexpr TinyImageFormat NormalBufferFormat = TinyImageFormat_R16G16B16A16_SFLOAT;
static constexpr TinyImageFormat PositionBufferFormat = TinyImageFormat_R32G32B32A32_SFLOAT;
static constexpr TinyImageFormat SpecularBufferFormat = TinyImageFormat_R8G8_UNORM;
Expand Down Expand Up @@ -169,10 +169,6 @@ namespace hpl {
SharedDescriptorSet m_sceneDescriptorConstSet;
std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_sceneDescriptorPerFrameSet;

//SharedRootSignature m_rootSignatureCopyDepth;
//std::array<SharedDescriptorSet, ForgeRenderer::SwapChainLength> m_descriptorCopyDepth;
//SharedShader m_copyDepthShader;

SharedShader m_visibilityBufferPassShader;
SharedShader m_visibilityBufferAlphaPassShader;
SharedShader m_visibilityShadePassShader;
Expand Down
1 change: 0 additions & 1 deletion HPL2/include/physics/VerletParticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ namespace hpl {
inline int GetUpdateCount() const { return mlUpdateCount; }

cVerletParticleIterator GetParticleIterator(){ return cVerletParticleIterator(&mlstParticles); }

protected:
virtual bool CheckParticleBodyCollision(iPhysicsBody *apBody)=0;
virtual bool CheckSpecificDataSleeping()=0; //Tested when container is NOT sleeping
Expand Down
251 changes: 139 additions & 112 deletions HPL2/include/scene/Beam.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with Amnesia: The Dark Descent. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef HPL_BEAM_H
#define HPL_BEAM_H
#pragma once

#include "math/MathTypes.h"
#include "graphics/GraphicsTypes.h"
Expand All @@ -28,131 +26,160 @@

namespace hpl {

class cMaterialManager;
class cResources;
class cGraphics;
class cFileSearcher;
class iLowLevelGraphics;
class cMaterial;
class iVertexBuffer;


class cBeam;
class cBeamEnd : public iEntity3D
{
friend class cBeam;
friend class cBeamEnd_UpdateCallback;
public:
cBeamEnd(const tString asName, cBeam *apBeam) : iEntity3D(asName),
mColor(1,1),mpBeam(apBeam) {}

void SetColor(const cColor &aColor);
const cColor& GetColor(){ return mColor;}

/////////////////////////////////
//Entity implementation
tString GetEntityType(){ return "BeamEnd";}
private:
cColor mColor;
cBeam *mpBeam;
};

//------------------------------------------

class cBeamEnd_UpdateCallback : public iEntityCallback
{
public:
void OnTransformUpdate(iEntity3D * apEntity);
};

//------------------------------------------

class cBeam : public iRenderable
{
friend class cBeamEnd;
public:
cBeam(const tString asName, cResources *apResources,cGraphics *apGraphics);
~cBeam();

void SetMaterial(cMaterial * apMaterial);

const tString& GetFileName(){return msFileName;}

/**
* Set the size. X= the thickness of the line, width of texture used. Y = the length that one texture height takes.
* \param avSize
*/
void SetSize(const cVector2f& avSize);
cVector2f GetSize(){ return mvSize;}

void SetColor(const cColor &aColor);
const cColor& GetColor(){ return mColor;}

void SetTileHeight(bool abX);
bool GetTileHeight(){ return mbTileHeight;}

void SetMultiplyAlphaWithColor(bool abX);
bool GetMultiplyAlphaWithColor(){ return mbMultiplyAlphaWithColor;}

cBeamEnd* GetEnd(){ return mpEnd;}

bool LoadXMLProperties(const tString asFile);

cVector3f GetAxis(){ return mvAxis;}
cVector3f GetMidPosition(){ return mvMidPosition;}

/////////////////////////////////
//Entity implementation
tString GetEntityType(){ return "Beam";}

bool IsVisible();

//Renderable implementations
virtual cMaterial *GetMaterial() override{ return mpMaterial;}
virtual iVertexBuffer* GetVertexBuffer() override{return mpVtxBuffer;}
class cMaterialManager;
class cResources;
class cGraphics;
class cFileSearcher;
class iLowLevelGraphics;
class cMaterial;
class iVertexBuffer;

class cBeam;
class cBeamEnd : public iEntity3D {
friend class cBeam;
friend class cBeamEnd_UpdateCallback;

public:
cBeamEnd(const tString asName, cBeam* apBeam)
: iEntity3D(asName)
, mColor(1, 1)
, mpBeam(apBeam) {
}

void SetColor(const cColor& aColor);
const cColor& GetColor() {
return mColor;
}

/////////////////////////////////
// Entity implementation
tString GetEntityType() {
return "BeamEnd";
}

private:
cColor mColor;
cBeam* mpBeam;
};

//------------------------------------------

class cBeamEnd_UpdateCallback : public iEntityCallback {
public:
void OnTransformUpdate(iEntity3D* apEntity);
};

//------------------------------------------

class cBeam : public iRenderable {
friend class cBeamEnd;

public:
cBeam(const tString asName, cResources* apResources, cGraphics* apGraphics);
~cBeam();

void SetMaterial(cMaterial* apMaterial);

const tString& GetFileName() {
return msFileName;
}

/**
* Set the size. X= the thickness of the line, width of texture used. Y = the length that one texture height takes.
* \param avSize
*/
void SetSize(const cVector2f& avSize);
cVector2f GetSize() {
return mvSize;
}

void SetColor(const cColor& aColor);
const cColor& GetColor() {
return mColor;
}

void SetTileHeight(bool abX);
bool GetTileHeight() {
return mbTileHeight;
}

void SetMultiplyAlphaWithColor(bool abX);
bool GetMultiplyAlphaWithColor() {
return mbMultiplyAlphaWithColor;
}

cBeamEnd* GetEnd() {
return mpEnd;
}

bool LoadXMLProperties(const tString asFile);

cVector3f GetAxis() {
return mvAxis;
}
cVector3f GetMidPosition() {
return mvMidPosition;
}

// Entity implementation
tString GetEntityType() {
return "Beam";
}

bool IsVisible();

// Renderable implementations
virtual cMaterial* GetMaterial() override {
return mpMaterial;
}
virtual iVertexBuffer* GetVertexBuffer() override {
return nullptr;
}
virtual DrawPacket ResolveDrawPacket(const ForgeRenderer::Frame& frame) override;

void UpdateGraphicsForFrame(float afFrameTime);
void UpdateGraphicsForFrame(float afFrameTime);

cBoundingVolume* GetBoundingVolume();
cBoundingVolume* GetBoundingVolume();

cMatrixf* GetModelMatrix(cFrustum *apFrustum);
cMatrixf* GetModelMatrix(cFrustum* apFrustum);

int GetMatrixUpdateCount();
int GetMatrixUpdateCount();

eRenderableType GetRenderType() {
return eRenderableType_Beam;
}

eRenderableType GetRenderType(){ return eRenderableType_Beam;}
private:
cMaterialManager* mpMaterialManager;
cFileSearcher *mpFileSearcher;
iLowLevelGraphics* mpLowLevelGraphics;
private:
std::shared_ptr<GeometrySet::GeometrySetSubAllocation> m_geometry;

cMaterial *mpMaterial;
iVertexBuffer* mpVtxBuffer;
cMaterialManager* mpMaterialManager;
cFileSearcher* mpFileSearcher;
iLowLevelGraphics* mpLowLevelGraphics;

cBeamEnd *mpEnd;
cMaterial* mpMaterial;
cBeamEnd* mpEnd;

tString msFileName;
tString msFileName;

int mlStartTransformCount;
int mlEndTransformCount;
int mlStartTransformCount;
int mlEndTransformCount;

cMatrixf m_mtxTempTransform;
cMatrixf m_mtxTempTransform;

int mlLastRenderCount;
int mlLastRenderCount;

cBeamEnd_UpdateCallback mEndCallback;
cBeamEnd_UpdateCallback mEndCallback;

cVector2f mvSize;
cVector2f mvSize;

cVector3f mvAxis;
cVector3f mvMidPosition;
cVector3f mvAxis;
cVector3f mvMidPosition;

bool mbTileHeight;
bool mbMultiplyAlphaWithColor;
bool mbTileHeight;
bool mbMultiplyAlphaWithColor;

cColor mColor;
};
cColor mColor = cColor(1,1,1,1);
uint8_t m_activeCopy = 0;
};

};
#endif // HPL_BEAM_H
}; // namespace hpl
11 changes: 5 additions & 6 deletions HPL2/include/scene/RopeEntity.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ namespace hpl {
void SetLengthTileSize(float afX){ mfLengthTileSize = afX;}
float GetLengthTileSize(){ return mfLengthTileSize;}


/////////////////////////////////
//Entity implementation
tString GetEntityType(){ return "RopeEntity";}

bool IsVisible();

/////////////////////////////////
//Renderable implementations
virtual cMaterial *GetMaterial() override{ return mpMaterial;}
virtual iVertexBuffer* GetVertexBuffer() override{return mpVtxBuffer;}
virtual iVertexBuffer* GetVertexBuffer() override{return nullptr;}
virtual DrawPacket ResolveDrawPacket(const ForgeRenderer::Frame& frame) override;

virtual void UpdateGraphicsForFrame(float afFrameTime) override;
Expand All @@ -101,7 +98,7 @@ namespace hpl {
iPhysicsRope *mpRope;

cMaterial *mpMaterial;
iVertexBuffer* mpVtxBuffer;
std::shared_ptr<GeometrySet::GeometrySetSubAllocation> m_geometry;

int mlMaxSegments;

Expand All @@ -113,6 +110,8 @@ namespace hpl {
bool mbMultiplyAlphaWithColor;

int mlLastUpdateCount;
};
uint8_t m_activeCopy = 0;
int m_numberSegments = 0;
};

};
Loading

0 comments on commit 2e82b61

Please sign in to comment.