Add IMaterialRendererServices::startUseProgram/stopUseProgram

This makes it possible to set high-level shader constants (which are attached to shader programs) to be set outside
of OnSetConstants.
IShaderConstantSetCallBack::OnCreate has it set automatically now so it works the same as OnSetConstants.
D3D9 and burnings both work different, so there hadn't been a problem with those.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6469 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
cutealien
2023-04-24 14:46:09 +00:00
parent 16c960c5ed
commit c4bbbe1aaf
6 changed files with 71 additions and 18 deletions

View File

@ -3727,7 +3727,9 @@ s32 COpenGLDriver::addShaderMaterial(const c8* vertexShaderProgram,
r->drop();
if (callback && nr >= 0)
{
callback->OnCreate(this, userData);
}
return nr;
}
@ -3764,7 +3766,11 @@ s32 COpenGLDriver::addHighLevelShaderMaterial(
r->drop();
if (callback && nr >= 0)
{
r->startUseProgram();
callback->OnCreate(r, userData);
r->stopUseProgram();
}
return nr;
}

View File

@ -415,6 +415,12 @@ namespace video
//! Get current material.
const SMaterial& getCurrentMaterial() const;
//! Rest renderstates forcing stuff like OnSetMaterial to be called
void DoResetRenderStates()
{
ResetRenderStates = true;
}
COpenGLCacheHandler* getCacheHandler() const;
private:

View File

@ -237,13 +237,10 @@ void COpenGLSLMaterialRenderer::OnSetMaterial(const video::SMaterial& material,
COpenGLCacheHandler* cacheHandler = Driver->getCacheHandler();
if (material.MaterialType != lastMaterial.MaterialType || resetAllRenderstates)
{
if (Program2)
Driver->irrGlUseProgram(Program2);
else if (Program)
Driver->extGlUseProgramObject(Program);
}
if (Program2)
Driver->irrGlUseProgram(Program2);
else if (Program)
Driver->extGlUseProgramObject(Program);
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
@ -572,6 +569,23 @@ void COpenGLSLMaterialRenderer::setBasicRenderStates(const SMaterial& material,
Driver->setBasicRenderStates(material, lastMaterial, resetAllRenderstates);
}
void COpenGLSLMaterialRenderer::startUseProgram()
{
if (Program2)
Driver->irrGlUseProgram(Program2);
else if (Program)
Driver->extGlUseProgramObject(Program);
}
void COpenGLSLMaterialRenderer::stopUseProgram()
{
// Not going to reset irrGlUseProgram/extGlUseProgramObject as it shouldn't really matter
// Force reset of material to ensure OnSetMaterial will be called or we can miss
// the next UseProgram call
Driver->DoResetRenderStates();
}
s32 COpenGLSLMaterialRenderer::getVertexShaderConstantID(const c8* name)
{
return getPixelShaderConstantID(name);

View File

@ -73,6 +73,8 @@ public:
// implementations for IMaterialRendererServices
virtual void setBasicRenderStates(const SMaterial& material, const SMaterial& lastMaterial, bool resetAllRenderstates) IRR_OVERRIDE;
virtual void startUseProgram() IRR_OVERRIDE;
virtual void stopUseProgram() IRR_OVERRIDE;
virtual s32 getVertexShaderConstantID(const c8* name) IRR_OVERRIDE;
virtual s32 getPixelShaderConstantID(const c8* name) IRR_OVERRIDE;
virtual void setVertexShaderConstant(const f32* data, s32 startRegister, s32 constantAmount=1) IRR_OVERRIDE;