Scoped render states

This commit is contained in:
Silent 2019-03-05 21:26:46 +01:00
parent 5921dfddb3
commit cabd0c999a
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1
6 changed files with 37 additions and 25 deletions

View file

@ -66,9 +66,11 @@ void CObject::Render()
if ( m_bDoNotRender || !m_pRwObject )
return;
bool bCallRestore;
bool bCallRestore = false;
std::pair<void*,int> materialRestoreData[16];
RwScopedRenderState cullState(rwRENDERSTATECULLMODE);
const int32_t carPartModelIndex = m_wCarPartModelIndex.Get();
if ( carPartModelIndex != -1 && m_objectCreatedBy == TEMP_OBJECT && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC )
{
@ -84,24 +86,16 @@ void CObject::Render()
pData->first = nullptr;
// Disable backface culling for the part
#ifdef _DEBUG
RwCullMode oldCullMode;
RwRenderStateGet(rwRENDERSTATECULLMODE, &oldCullMode);
assert(oldCullMode == rwCULLMODECULLBACK);
#endif
RwRenderStateSet(rwRENDERSTATECULLMODE, reinterpret_cast<void*>(rwCULLMODECULLNONE));
bCallRestore = true;
}
else
bCallRestore = false;
CEntity::Render();
if ( bCallRestore )
{
ResetEditableMaterials(materialRestoreData);
RwRenderStateSet(rwRENDERSTATECULLMODE, reinterpret_cast<void*>(rwCULLMODECULLBACK));
}
}

View file

@ -3,6 +3,29 @@
#include <rwcore.h>
#include <rpworld.h>
class RwScopedRenderState
{
public:
RwScopedRenderState( RwRenderState state )
: m_state( state )
{
[[maybe_unused]] RwBool result = RwRenderStateGet( m_state, &m_value );
assert( result != FALSE );
}
~RwScopedRenderState()
{
[[maybe_unused]] RwBool result = RwRenderStateSet( m_state, m_value );
assert( result != FALSE );
}
private:
RwScopedRenderState( const RwScopedRenderState& ) = delete;
const RwRenderState m_state;
void* m_value = nullptr;
};
template <typename Pred>
Pred RwFrameForAllChildren(RwFrame* frame, Pred&& callback)
{

View file

@ -339,31 +339,23 @@ static RpAtomic* RenderAtomic(RpAtomic* pAtomic, float fComp)
static RpAtomic* StaticPropellerRender(RpAtomic* pAtomic)
{
int nPushedAlpha;
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha);
RwScopedRenderState alphaRef(rwRENDERSTATEALPHATESTFUNCTIONREF);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0);
pAtomic = AtomicDefaultRenderCallBack(pAtomic);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha));
return pAtomic;
}
static RpAtomic* MovingPropellerRender(RpAtomic* pAtomic)
{
int nPushedAlpha, nAlphaBlending;
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha);
RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending);
RwScopedRenderState alphaRef(rwRENDERSTATEALPHATESTFUNCTIONREF);
RwScopedRenderState vertexAlpha(rwRENDERSTATEVERTEXALPHAENABLE);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
pAtomic = AtomicDefaultRenderCallBack(pAtomic);
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha));
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(nAlphaBlending));
return pAtomic;
}
@ -399,6 +391,9 @@ void RenderWeapon(CPed* pPed)
void RenderWeaponPedsForPC()
{
RwScopedRenderState vertexAlpha(rwRENDERSTATEVERTEXALPHAENABLE);
RwScopedRenderState zWrite(rwRENDERSTATEZWRITEENABLE);
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);

View file

@ -243,7 +243,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
<ClInclude Include="PNGFile.h" />
<ClInclude Include="PoolsSA.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="rwpred.hpp" />
<ClInclude Include="RWUtils.hpp" />
<ClInclude Include="ScriptSA.h" />
<ClInclude Include="StdAfxSA.h" />
<ClInclude Include="TimerSA.h" />

View file

@ -146,9 +146,6 @@
<ClInclude Include="..\SilentPatch\DelimStringReader.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="rwpred.hpp">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\SilentPatch\TheFLAUtils.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -170,6 +167,9 @@
<ClInclude Include="..\SilentPatch\MemoryMgr.GTA.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="RWUtils.hpp">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc">

View file

@ -20,7 +20,7 @@
#include "MemoryMgr.h"
#include "MemoryMgr.GTA.h"
#include "Maths.h"
#include "rwpred.hpp"
#include "rwutils.hpp"
#include "TheFLAUtils.h"