Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
hlms.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <OGRE/Hlms/Unlit/OgreHlmsUnlit.h>
4 #include <OGRE/Hlms/Pbs/OgreHlmsPbs.h>
5 #include <OGRE/OgreHlmsListener.h>
6 
7 #define SHADER_ADDONS_PARAM_ID 8000000u
8 
10 {
11 protected:
12  typedef Ogre::vector<Ogre::ConstBufferPacked*>::type ConstBufferPackedVec;
13 
18 
20  Ogre::ConstBufferPacked* ogre_nullable mCurrPerObjectDataBuffer;
21 
25  Ogre::ConstBufferPacked* ogre_nullable mLastMainConstBuffer;
26 
28  float* ogre_nullable mCurrPerObjectDataPtr;
29 
31  Ogre::VaoManager* ogre_nullable mOwnVaoManager;
32 
39  void bindObjectDataBuffer(Ogre::CommandBuffer* commandBuffer, uint16_t perObjectDataBufferSlot);
40 
59  float* mapObjectDataBufferFor(uint32_t instanceIdx, Ogre::CommandBuffer* commandBuffer,
60  Ogre::VaoManager* vaoManager,
61  const ConstBufferPackedVec& constBuffers,
62  uint32_t currConstBufferIdx, uint32_t* startMappedConstBuffer,
63  uint16_t perObjectDataBufferSlot,
64  uint16_t element_count);
65 
67  void unmapObjectDataBuffer();
68 
71 };
72 
73 class BlamHlmsPbs : public Ogre::HlmsPbs, public Ogre::HlmsListener, SharedHelperForHlms {
74 public:
77  //static constexpr Ogre::uint32 kColourId = 7895211u;
78 
79  BlamHlmsPbs(Ogre::Archive* dataFolder, Ogre::ArchiveVec* libraryFolders) :
80  HlmsPbs(dataFolder, libraryFolders)
81  {
82  // Set ourselves as our own listener.
83  setListener(this);
84  }
85 
86  void hlmsTypeChanged(bool casterPass, Ogre::CommandBuffer* commandBuffer,
87  const Ogre::HlmsDatablock* datablock, size_t texUnit) override;
88 
89  void calculateHashForPreCreate(Ogre::Renderable* renderable, Ogre::PiecesMap* inOutPieces) override;
90 
91  using HlmsPbs::setupRootLayout;
92  void setupRootLayout(Ogre::RootLayout& rootLayout, const Ogre::HlmsPropertyVec& properties,
93  size_t tid) const override;
94 
95  Ogre::uint32 fillBuffersForV1(const Ogre::HlmsCache* cache, const Ogre::QueuedRenderable& queuedRenderable,
96  bool casterPass, Ogre::uint32 lastCacheHash,
97  Ogre::CommandBuffer* commandBuffer) override;
98 
99  Ogre::uint32 fillBuffersForV2(const Ogre::HlmsCache* cache, const Ogre::QueuedRenderable& queuedRenderable,
100  bool casterPass, Ogre::uint32 lastCacheHash,
101  Ogre::CommandBuffer* commandBuffer) override;
102 
103  void preCommandBufferExecution(Ogre::CommandBuffer* commandBuffer) override;
104  void frameEnded() override;
105 };
BlamHlmsPbs::fillBuffersForV2
Ogre::uint32 fillBuffersForV2(const Ogre::HlmsCache *cache, const Ogre::QueuedRenderable &queuedRenderable, bool casterPass, Ogre::uint32 lastCacheHash, Ogre::CommandBuffer *commandBuffer) override
Definition: BlamHlmsPbs.cpp:209
RENDERABLE_SHADER_USER_KEY
#define RENDERABLE_SHADER_USER_KEY
Definition: world_objects.h:19
SharedHelperForHlms::unmapObjectDataBuffer
void unmapObjectDataBuffer()
Unmaps the current buffer holding per-object data from memory.
Definition: BlamHlmsPbs.cpp:109
SHADER_ADDONS_PARAM_ID
#define SHADER_ADDONS_PARAM_ID
Definition: hlms.h:7
world_objects.h
hlms.h
Blam::Rendering::Shaders::FillInstanceParameterBuffer
BLAM void FillInstanceParameterBuffer(float *address, BlamWorldObject_Tag *object, shader *program)
Definition: shaders_hlms.cpp:223
SharedHelperForHlms
Definition: hlms.h:9
rendering.h
BlamWorldObject_Tag
Class representing a tag-based world object.
Definition: world_objects.h:278
SharedHelperForHlms::~SharedHelperForHlms
~SharedHelperForHlms()
Definition: BlamHlmsPbs.cpp:29
Blam::Rendering::Shaders::CalculateInstanceBufferElementCount
BLAM uint16_t CalculateInstanceBufferElementCount(shader *program)
Definition: shaders_hlms.cpp:251
BlamHlmsPbs::fillBuffersForV1
Ogre::uint32 fillBuffersForV1(const Ogre::HlmsCache *cache, const Ogre::QueuedRenderable &queuedRenderable, bool casterPass, Ogre::uint32 lastCacheHash, Ogre::CommandBuffer *commandBuffer) override
Definition: BlamHlmsPbs.cpp:155
shader
Definition: shader.h:31
BlamHlmsPbs
Definition: hlms.h:73
SharedHelperForHlms::mCurrPerObjectDataPtr
float *ogre_nullable mCurrPerObjectDataPtr
The mapped contents of currPerObjectDataBuffer.
Definition: hlms.h:28
BlamHlmsPbs::hlmsTypeChanged
void hlmsTypeChanged(bool casterPass, Ogre::CommandBuffer *commandBuffer, const Ogre::HlmsDatablock *datablock, size_t texUnit) override
Definition: BlamHlmsPbs.cpp:136
BlamHlmsPbs::preCommandBufferExecution
void preCommandBufferExecution(Ogre::CommandBuffer *commandBuffer) override
Definition: BlamHlmsPbs.cpp:265
SharedHelperForHlms::SharedHelperForHlms
SharedHelperForHlms()
Definition: BlamHlmsPbs.cpp:21
BlamHlmsPbs::frameEnded
void frameEnded() override
Definition: BlamHlmsPbs.cpp:271
SharedHelperForHlms::mapObjectDataBufferFor
float * mapObjectDataBufferFor(uint32_t instanceIdx, Ogre::CommandBuffer *commandBuffer, Ogre::VaoManager *vaoManager, const ConstBufferPackedVec &constBuffers, uint32_t currConstBufferIdx, uint32_t *startMappedConstBuffer, uint16_t perObjectDataBufferSlot, uint16_t element_count)
Definition: BlamHlmsPbs.cpp:51
SharedHelperForHlms::mLastMainConstBuffer
Ogre::ConstBufferPacked *ogre_nullable mLastMainConstBuffer
The last content of mCurrentConstBuffer.
Definition: hlms.h:25
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
BlamHlmsPbs::calculateHashForPreCreate
void calculateHashForPreCreate(Ogre::Renderable *renderable, Ogre::PiecesMap *inOutPieces) override
Definition: BlamHlmsPbs.cpp:123
OBJECT_DATA_BUFFER_SLOT
#define OBJECT_DATA_BUFFER_SLOT
The slot where to bind mCurrPerObjectDataBuffer HlmsPbs might consume slot 3, so we always use slot 4...
Definition: BlamHlmsPbs.cpp:19
shader_program.h
WORLD_OBJECT_USER_KEY
#define WORLD_OBJECT_USER_KEY
Definition: world_objects.h:18
SharedHelperForHlms::bindObjectDataBuffer
void bindObjectDataBuffer(Ogre::CommandBuffer *commandBuffer, uint16_t perObjectDataBufferSlot)
Binds currPerObjectDataBuffer to the right slot.
Definition: BlamHlmsPbs.cpp:40
BlamHlmsPbs::BlamHlmsPbs
BlamHlmsPbs(Ogre::Archive *dataFolder, Ogre::ArchiveVec *libraryFolders)
This value is completely arbitrary.
Definition: hlms.h:79
shader.h
SharedHelperForHlms::mOwnVaoManager
Ogre::VaoManager *ogre_nullable mOwnVaoManager
Pointer to Ogre's VAO manager. Used here for destroying const buffers.
Definition: hlms.h:31
Blam::Content::Tags::GetShaderTag
BLAM shader * GetShaderTag(std::string tag_path)
Definition: shader.cpp:13
SharedHelperForHlms::mPerObjectDataBuffers
ConstBufferPackedVec mPerObjectDataBuffers
Vector of buffers holding per-object data.
Definition: hlms.h:17
SharedHelperForHlms::ConstBufferPackedVec
Ogre::vector< Ogre::ConstBufferPacked * >::type ConstBufferPackedVec
Definition: hlms.h:12
uint16_t
unsigned short uint16_t
Definition: stdint.h:16
BlamHlmsPbs::setupRootLayout
void setupRootLayout(Ogre::RootLayout &rootLayout, const Ogre::HlmsPropertyVec &properties, size_t tid) const override
Definition: BlamHlmsPbs.cpp:143
SharedHelperForHlms::mCurrPerObjectDataBuffer
Ogre::ConstBufferPacked *ogre_nullable mCurrPerObjectDataBuffer
The buffer currently use. Can be nullptr. It is contained in mPerObjectDataBuffers.
Definition: hlms.h:20