Skip to content

Commit

Permalink
Main: factor out common D3D11 and GL3Plus UBO code
Browse files Browse the repository at this point in the history
  • Loading branch information
paroj committed Sep 8, 2024
1 parent 2b00a11 commit 677c00e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 20 deletions.
4 changes: 4 additions & 0 deletions OgreMain/include/OgreRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -1201,13 +1201,17 @@ namespace Ogre
void setFFPLightParams(uint32 index, bool enabled);
bool flipFrontFace() const;
static CompareFunction reverseCompareFunction(CompareFunction func);

const HardwareBufferPtr& updateDefaultUniformBuffer(GpuProgramType type, const ConstantList& params);
private:
StencilState mStencilState;

/// a global vertex buffer for global instancing
HardwareVertexBufferSharedPtr mGlobalInstanceVertexBuffer;
/// a vertex declaration for the global vertex buffer for the global instancing
VertexDeclaration* mGlobalInstanceVertexDeclaration;
/// buffers for default uniform blocks
HardwareBufferPtr mUniformBuffer[GPT_COUNT];
/// the number of global instances (this number will be multiply by the render op instance number)
uint32 mGlobalNumberOfInstances;
};
Expand Down
12 changes: 12 additions & 0 deletions OgreMain/src/OgreRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ namespace Ogre {
mFixedFunctionParams->setAutoConstant(light_offset + 5, GpuProgramParameters::ACT_SPOTLIGHT_PARAMS, index);
}

const HardwareBufferPtr& RenderSystem::updateDefaultUniformBuffer(GpuProgramType gptype, const ConstantList& params)
{
auto& ubo = mUniformBuffer[gptype];
if (!ubo || ubo->getSizeInBytes() < params.size())
{
ubo = HardwareBufferManager::getSingleton().createUniformBuffer(params.size());
}

ubo->writeData(0, params.size(), params.data(), true);

return ubo;
}
//-----------------------------------------------------------------------
RenderSystem::~RenderSystem()
{
Expand Down
2 changes: 0 additions & 2 deletions RenderSystems/Direct3D11/include/OgreD3D11RenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ namespace Ogre
ID3D11ShaderResourceView * mBoundTextures[OGRE_MAX_TEXTURE_LAYERS];
size_t mBoundTexturesCount;

HardwareBufferPtr mConstantBuffer[GPT_COUNT]; // for $Globals OR $Params

// List of class instances per shader stage
ID3D11ClassInstance* mClassInstances[6][8];

Expand Down
11 changes: 2 additions & 9 deletions RenderSystems/Direct3D11/src/OgreD3D11RenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2272,16 +2272,9 @@ namespace Ogre

std::vector<ID3D11Buffer*> buffers = {NULL};

auto paramsSize = params->getConstantList().size();
if(paramsSize)
if(params->getConstantList().size())
{
auto& cbuffer = mConstantBuffer[gptype];

if(!cbuffer || cbuffer->getSizeInBytes() < paramsSize)
cbuffer = mHardwareBufferManager->createUniformBuffer(paramsSize);

cbuffer->writeData(0, paramsSize, params->getConstantList().data(), true);

auto& cbuffer = updateDefaultUniformBuffer(gptype, params->getConstantList());
buffers[0] = static_cast<D3D11HardwareBuffer*>(cbuffer.get())->getD3DBuffer();
}

Expand Down
2 changes: 0 additions & 2 deletions RenderSystems/GL3Plus/include/OgreGL3PlusRenderSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ namespace Ogre {

std::array<GLSLShader*, GPT_COUNT> mCurrentShader;

HardwareBufferPtr mUniformBuffer[GPT_COUNT];

GLenum getBlendMode(SceneBlendFactor ogreBlend) const;

void bindVertexElementToGpu(const VertexElement& elem,
Expand Down
8 changes: 1 addition & 7 deletions RenderSystems/GL3Plus/src/OgreGL3PlusRenderSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,13 +1652,7 @@ namespace Ogre {
if (paramsSize && getCapabilities()->hasCapability(RSC_SEPARATE_SHADER_OBJECTS) &&
!params->hasLogicalIndexedParameters())
{
auto& ubo = mUniformBuffer[gptype];
if(!ubo || ubo->getSizeInBytes() < paramsSize)
{
ubo = mHardwareBufferManager->createUniformBuffer(paramsSize);
}

ubo->writeData(0, ubo->getSizeInBytes(), params->getConstantList().data(), true);
auto& ubo = updateDefaultUniformBuffer(gptype, params->getConstantList());

int binding = gptype == GPT_COMPUTE_PROGRAM ? 0 : (int(gptype) % GPT_PIPELINE_COUNT);
static_cast<GL3PlusHardwareBuffer*>(ubo.get())->setGLBufferBinding(binding);
Expand Down

0 comments on commit 677c00e

Please sign in to comment.