mirror of
https://github.com/CookiePLMonster/SilentPatch.git
synced 2024-11-22 21:42:28 +01:00
Scoped render states
This commit is contained in:
parent
5921dfddb3
commit
cabd0c999a
@ -66,9 +66,11 @@ void CObject::Render()
|
|||||||
if ( m_bDoNotRender || !m_pRwObject )
|
if ( m_bDoNotRender || !m_pRwObject )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
bool bCallRestore;
|
bool bCallRestore = false;
|
||||||
std::pair<void*,int> materialRestoreData[16];
|
std::pair<void*,int> materialRestoreData[16];
|
||||||
|
|
||||||
|
RwScopedRenderState cullState(rwRENDERSTATECULLMODE);
|
||||||
|
|
||||||
const int32_t carPartModelIndex = m_wCarPartModelIndex.Get();
|
const int32_t carPartModelIndex = m_wCarPartModelIndex.Get();
|
||||||
if ( carPartModelIndex != -1 && m_objectCreatedBy == TEMP_OBJECT && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC )
|
if ( carPartModelIndex != -1 && m_objectCreatedBy == TEMP_OBJECT && bObjectFlag7 && RwObjectGetType(m_pRwObject) == rpATOMIC )
|
||||||
{
|
{
|
||||||
@ -84,24 +86,16 @@ void CObject::Render()
|
|||||||
pData->first = nullptr;
|
pData->first = nullptr;
|
||||||
|
|
||||||
// Disable backface culling for the part
|
// Disable backface culling for the part
|
||||||
#ifdef _DEBUG
|
|
||||||
RwCullMode oldCullMode;
|
|
||||||
RwRenderStateGet(rwRENDERSTATECULLMODE, &oldCullMode);
|
|
||||||
assert(oldCullMode == rwCULLMODECULLBACK);
|
|
||||||
#endif
|
|
||||||
RwRenderStateSet(rwRENDERSTATECULLMODE, reinterpret_cast<void*>(rwCULLMODECULLNONE));
|
RwRenderStateSet(rwRENDERSTATECULLMODE, reinterpret_cast<void*>(rwCULLMODECULLNONE));
|
||||||
|
|
||||||
bCallRestore = true;
|
bCallRestore = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
bCallRestore = false;
|
|
||||||
|
|
||||||
CEntity::Render();
|
CEntity::Render();
|
||||||
|
|
||||||
if ( bCallRestore )
|
if ( bCallRestore )
|
||||||
{
|
{
|
||||||
ResetEditableMaterials(materialRestoreData);
|
ResetEditableMaterials(materialRestoreData);
|
||||||
RwRenderStateSet(rwRENDERSTATECULLMODE, reinterpret_cast<void*>(rwCULLMODECULLBACK));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,29 @@
|
|||||||
#include <rwcore.h>
|
#include <rwcore.h>
|
||||||
#include <rpworld.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>
|
template <typename Pred>
|
||||||
Pred RwFrameForAllChildren(RwFrame* frame, Pred&& callback)
|
Pred RwFrameForAllChildren(RwFrame* frame, Pred&& callback)
|
||||||
{
|
{
|
@ -339,31 +339,23 @@ static RpAtomic* RenderAtomic(RpAtomic* pAtomic, float fComp)
|
|||||||
|
|
||||||
static RpAtomic* StaticPropellerRender(RpAtomic* pAtomic)
|
static RpAtomic* StaticPropellerRender(RpAtomic* pAtomic)
|
||||||
{
|
{
|
||||||
int nPushedAlpha;
|
RwScopedRenderState alphaRef(rwRENDERSTATEALPHATESTFUNCTIONREF);
|
||||||
|
|
||||||
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha);
|
|
||||||
|
|
||||||
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0);
|
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0);
|
||||||
pAtomic = AtomicDefaultRenderCallBack(pAtomic);
|
pAtomic = AtomicDefaultRenderCallBack(pAtomic);
|
||||||
|
|
||||||
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha));
|
|
||||||
return pAtomic;
|
return pAtomic;
|
||||||
}
|
}
|
||||||
|
|
||||||
static RpAtomic* MovingPropellerRender(RpAtomic* pAtomic)
|
static RpAtomic* MovingPropellerRender(RpAtomic* pAtomic)
|
||||||
{
|
{
|
||||||
int nPushedAlpha, nAlphaBlending;
|
RwScopedRenderState alphaRef(rwRENDERSTATEALPHATESTFUNCTIONREF);
|
||||||
|
RwScopedRenderState vertexAlpha(rwRENDERSTATEVERTEXALPHAENABLE);
|
||||||
RwRenderStateGet(rwRENDERSTATEALPHATESTFUNCTIONREF, &nPushedAlpha);
|
|
||||||
RwRenderStateGet(rwRENDERSTATEVERTEXALPHAENABLE, &nAlphaBlending);
|
|
||||||
|
|
||||||
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0);
|
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, 0);
|
||||||
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
|
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
|
||||||
|
|
||||||
pAtomic = AtomicDefaultRenderCallBack(pAtomic);
|
pAtomic = AtomicDefaultRenderCallBack(pAtomic);
|
||||||
|
|
||||||
RwRenderStateSet(rwRENDERSTATEALPHATESTFUNCTIONREF, reinterpret_cast<void*>(nPushedAlpha));
|
|
||||||
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(nAlphaBlending));
|
|
||||||
return pAtomic;
|
return pAtomic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,6 +391,9 @@ void RenderWeapon(CPed* pPed)
|
|||||||
|
|
||||||
void RenderWeaponPedsForPC()
|
void RenderWeaponPedsForPC()
|
||||||
{
|
{
|
||||||
|
RwScopedRenderState vertexAlpha(rwRENDERSTATEVERTEXALPHAENABLE);
|
||||||
|
RwScopedRenderState zWrite(rwRENDERSTATEZWRITEENABLE);
|
||||||
|
|
||||||
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
|
RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, reinterpret_cast<void*>(TRUE));
|
||||||
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
|
RwRenderStateSet(rwRENDERSTATEZWRITEENABLE, FALSE);
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio
|
|||||||
<ClInclude Include="PNGFile.h" />
|
<ClInclude Include="PNGFile.h" />
|
||||||
<ClInclude Include="PoolsSA.h" />
|
<ClInclude Include="PoolsSA.h" />
|
||||||
<ClInclude Include="resource.h" />
|
<ClInclude Include="resource.h" />
|
||||||
<ClInclude Include="rwpred.hpp" />
|
<ClInclude Include="RWUtils.hpp" />
|
||||||
<ClInclude Include="ScriptSA.h" />
|
<ClInclude Include="ScriptSA.h" />
|
||||||
<ClInclude Include="StdAfxSA.h" />
|
<ClInclude Include="StdAfxSA.h" />
|
||||||
<ClInclude Include="TimerSA.h" />
|
<ClInclude Include="TimerSA.h" />
|
||||||
|
@ -146,9 +146,6 @@
|
|||||||
<ClInclude Include="..\SilentPatch\DelimStringReader.h">
|
<ClInclude Include="..\SilentPatch\DelimStringReader.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="rwpred.hpp">
|
|
||||||
<Filter>Header Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\SilentPatch\TheFLAUtils.h">
|
<ClInclude Include="..\SilentPatch\TheFLAUtils.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -170,6 +167,9 @@
|
|||||||
<ClInclude Include="..\SilentPatch\MemoryMgr.GTA.h">
|
<ClInclude Include="..\SilentPatch\MemoryMgr.GTA.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="RWUtils.hpp">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc">
|
<ResourceCompile Include="..\SilentPatch\SilentPatch.rc">
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include "MemoryMgr.h"
|
#include "MemoryMgr.h"
|
||||||
#include "MemoryMgr.GTA.h"
|
#include "MemoryMgr.GTA.h"
|
||||||
#include "Maths.h"
|
#include "Maths.h"
|
||||||
#include "rwpred.hpp"
|
#include "rwutils.hpp"
|
||||||
|
|
||||||
#include "TheFLAUtils.h"
|
#include "TheFLAUtils.h"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user