Skip to content

Commit 79d60b8

Browse files
committed
dxDrawModel3D doubleSided argument
1 parent 7afa0cf commit 79d60b8

File tree

8 files changed

+211
-17
lines changed

8 files changed

+211
-17
lines changed

Client/game_sa/CRendererSA.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ CRendererSA::~CRendererSA()
2626
{
2727
}
2828

29-
void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting)
29+
void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided)
3030
{
3131
CBaseModelInfoSAInterface* pModelInfoSAInterface = pModelInfo->GetInterface();
3232
if (!pModelInfoSAInterface)
@@ -48,6 +48,13 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, flo
4848
// Setup ambient light multiplier
4949
SetLightColoursForPedsCarsAndObjects(lighting);
5050

51+
RwCullMode currentCullMode;
52+
if (doubleSided)
53+
{
54+
RwRenderStateGet(rwRENDERSTATECULLMODE, &currentCullMode);
55+
RwRenderStateSet(rwRENDERSTATECULLMODE, RWRSTATE(rwCULLMODECULLNONE));
56+
}
57+
5158
if (pRwObject->type == RP_TYPE_ATOMIC)
5259
{
5360
RpAtomic* pRpAtomic = reinterpret_cast<RpAtomic*>(pRwObject);
@@ -59,6 +66,9 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, flo
5966
RpClumpRender(pClump);
6067
}
6168

69+
if (doubleSided)
70+
RwRenderStateSet(rwRENDERSTATECULLMODE, RWRSTATE(currentCullMode));
71+
6272
// Restore ambient light
6373
SetAmbientColours();
6474
}

Client/game_sa/CRendererSA.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ class CRendererSA : public CRenderer
1919
CRendererSA();
2020
~CRendererSA();
2121

22-
void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) override;
22+
void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided) override;
2323
};

Client/mods/deathmatch/logic/CModelRenderer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@
1313
#include "game\CRenderer.h"
1414
#include "game\CVisibilityPlugins.h"
1515

16-
bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting)
16+
bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided)
1717
{
1818
if (g_pCore->IsWindowMinimized())
1919
return false;
2020

2121
if (pModelInfo && pModelInfo->IsLoaded())
2222
{
23-
m_Queue.emplace_back(pModelInfo, matrix, lighting);
23+
m_Queue.emplace_back(pModelInfo, matrix, lighting, doubleSided);
2424
return true;
2525
}
2626

@@ -54,7 +54,7 @@ void CModelRenderer::Render()
5454
for (auto& modelDesc : m_Queue)
5555
{
5656
if (modelDesc.pModelInfo->IsLoaded() && !modelDesc.pModelInfo->GetIdeFlag(eModelIdeFlag::DRAW_LAST))
57-
pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting);
57+
pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting, modelDesc.doubleSided);
5858
}
5959

6060
m_Queue.clear();
@@ -68,5 +68,5 @@ void CModelRenderer::RenderEntity(SModelToRender* modelDesc, float distance)
6868
CRenderer* pRenderer = g_pGame->GetRenderer();
6969
assert(pRenderer);
7070

71-
pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting);
71+
pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting, modelDesc->doubleSided);
7272
}

Client/mods/deathmatch/logic/CModelRenderer.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,20 @@ class CModelRenderer final
1717
struct SModelToRender final
1818
{
1919
CModelInfo* pModelInfo;
20-
CMatrix matrix;
21-
float lighting;
20+
CMatrix matrix;
21+
float lighting;
22+
bool doubleSided;
2223

23-
SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f) :
24+
SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f, bool doubleSided = false) :
2425
pModelInfo(pModelInfo),
2526
matrix(matrix),
26-
lighting(lighting)
27+
lighting(lighting),
28+
doubleSided(doubleSided)
2729
{
2830
}
2931
};
3032

31-
bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting);
33+
bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided);
3234

3335
void Update();
3436

Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,7 +2123,7 @@ bool CLuaDrawingDefs::DxDrawWiredSphere(lua_State* const luaVM, const CVector po
21232123
return true;
21242124
}
21252125

2126-
bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting)
2126+
bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting, std::optional<bool> doubleSided)
21272127
{
21282128
CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelID);
21292129
if (!pModelInfo)
@@ -2138,5 +2138,5 @@ bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVe
21382138
ConvertDegreesToRadians(rotation);
21392139

21402140
return g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo,
2141-
CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f));
2141+
CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f), doubleSided.value_or(false));
21422142
}

Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class CLuaDrawingDefs : public CLuaDefs
8282
static bool DxDrawWiredSphere(lua_State* const luaVM, const CVector position, const float radius, const std::optional<SColor> color,
8383
const std::optional<float> lineWidth, const std::optional<unsigned int> iterations);
8484

85-
static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting);
85+
static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting, std::optional<bool> doubleSided);
8686

8787
private:
8888
static void AddDxMaterialClass(lua_State* luaVM);

Client/sdk/game/CRenderer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ class CRenderer
1919
public:
2020
virtual ~CRenderer() {}
2121

22-
virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) = 0;
22+
virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided) = 0;
2323
};

Client/sdk/game/RenderWare.h

Lines changed: 184 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,19 @@
2222
#define RWFORCEENUMSIZEINT ((std::int32_t)((~((std::uint32_t)0)) >> 1))
2323
#endif
2424
#define RWPLUGINOFFSET(_type, _base, _offset) ((_type*)((std::uint8_t*)(_base) + (_offset)))
25+
#define RWSRCGLOBAL(variable) ((*(RwGlobals**)0xC97B24)->variable) // 0xC97B24 = RwEngineInstance pointer
26+
#define RWRSTATE(a) (reinterpret_cast<void*>(a))
2527
#define RW_STRUCT_ALIGN ((int)((~((unsigned int)0))>>1))
2628
#define RW_TEXTURE_NAME_LENGTH 32
2729
#define RW_FRAME_NAME_LENGTH 23
2830
#define RW_MAX_TEXTURE_COORDS 8
2931

32+
#define RwRenderStateGet(_state, _value) RwRenderStateGetMacro(_state, _value)
33+
#define RwRenderStateSet(_state, _value) RwRenderStateSetMacro(_state, _value)
34+
35+
#define RwRenderStateGetMacro(_state, _value) (RWSRCGLOBAL(dOpenDevice).fpRenderStateGet(_state, _value))
36+
#define RwRenderStateSetMacro(_state, _value) (RWSRCGLOBAL(dOpenDevice).fpRenderStateSet(_state, _value))
37+
3038
/* Type IDs */
3139

3240
#define RP_TYPE_ATOMIC 1
@@ -487,6 +495,177 @@ enum RwStreamMode
487495
STREAM_MODE_LAST = RW_STRUCT_ALIGN
488496
};
489497

498+
enum RwRenderState
499+
{
500+
rwRENDERSTATENARENDERSTATE = 0,
501+
502+
rwRENDERSTATETEXTURERASTER,
503+
/**<Raster used for texturing (normally used in immediate mode).
504+
* The value is a pointer to an \ref RwRaster.
505+
* Default: NULL.
506+
*/
507+
rwRENDERSTATETEXTUREADDRESS,
508+
/**<\ref RwTextureAddressMode: wrap, clamp, mirror or border.
509+
* Default: rwTEXTUREADDRESSWRAP.
510+
*/
511+
rwRENDERSTATETEXTUREADDRESSU,
512+
/**<\ref RwTextureAddressMode in u only.
513+
* Default: rwTEXTUREADDRESSWRAP.
514+
*/
515+
rwRENDERSTATETEXTUREADDRESSV,
516+
/**<\ref RwTextureAddressMode in v only.
517+
* Default: rwTEXTUREADDRESSWRAP.
518+
*/
519+
rwRENDERSTATETEXTUREPERSPECTIVE,
520+
/**<Perspective correction on/off (always enabled on many platforms).
521+
*/
522+
rwRENDERSTATEZTESTENABLE,
523+
/**<Z-buffer test on/off.
524+
* Default: TRUE.
525+
*/
526+
rwRENDERSTATESHADEMODE,
527+
/**<\ref RwShadeMode: flat or gouraud shading.
528+
* Default: rwSHADEMODEGOURAUD.
529+
*/
530+
rwRENDERSTATEZWRITEENABLE,
531+
/**<Z-buffer write on/off.
532+
* Default: TRUE.
533+
*/
534+
rwRENDERSTATETEXTUREFILTER,
535+
/**<\ref RwTextureFilterMode: point sample, bilinear, trilinear, etc.
536+
* Default: rwFILTERLINEAR.
537+
*/
538+
rwRENDERSTATESRCBLEND,
539+
/**<\ref RwBlendFunction used to modulate the source pixel color
540+
* when blending to the frame buffer.
541+
* Default: rwBLENDSRCALPHA.
542+
*/
543+
rwRENDERSTATEDESTBLEND,
544+
/**<\ref RwBlendFunction used to modulate the destination pixel
545+
* color in the frame buffer when blending. The resulting pixel
546+
* color is given by the formula
547+
* (SRCBLEND * srcColor + DESTBLEND * destColor) for each RGB
548+
* component. For a particular platform, not all combinations
549+
* of blend function are allowed (see platform specific
550+
* restrictions).
551+
* Default: rwBLENDINVSRCALPHA.
552+
*/
553+
rwRENDERSTATEVERTEXALPHAENABLE,
554+
/**<Alpha blending on/off (always enabled on some platforms).
555+
* This is normally used in immediate mode to enable alpha blending
556+
* when vertex colors or texture rasters have transparency. Retained
557+
* mode pipelines will usually set this state based on material colors
558+
* and textures.
559+
* Default: FALSE.
560+
*/
561+
rwRENDERSTATEBORDERCOLOR,
562+
/**<Border color for \ref RwTextureAddressMode
563+
* \ref rwTEXTUREADDRESSBORDER. The value should be a packed
564+
* RwUInt32 in a platform specific format. The macro
565+
* RWRGBALONG(r, g, b, a) may be used to construct this using
566+
* 8-bit color components.
567+
* Default: RWRGBALONG(0, 0, 0, 0).
568+
*/
569+
rwRENDERSTATEFOGENABLE,
570+
/**<Fogging on/off (all polygons will be fogged).
571+
* Default: FALSE.
572+
*/
573+
rwRENDERSTATEFOGCOLOR,
574+
/**<Color used for fogging. The value should be a packed RwUInt32
575+
* in a platform specific format. The macro RWRGBALONG(r, g, b, a)
576+
* may be used to construct this using 8-bit color components.
577+
* Default: RWRGBALONG(0, 0, 0, 0).
578+
*/
579+
rwRENDERSTATEFOGTYPE,
580+
/**<\ref RwFogType, the type of fogging to use.
581+
* Default: rwFOGTYPELINEAR.
582+
*/
583+
rwRENDERSTATEFOGDENSITY,
584+
/**<Fog density for \ref RwFogType of
585+
* \ref rwFOGTYPEEXPONENTIAL or \ref rwFOGTYPEEXPONENTIAL2.
586+
* The value should be a pointer to an RwReal in the
587+
* range 0 to 1.
588+
* Default: 1.
589+
*/
590+
rwRENDERSTATECULLMODE = 20,
591+
/**<\ref RwCullMode, for selecting front/back face culling, or
592+
* no culling.
593+
* Default: rwCULLMODECULLBACK.
594+
*/
595+
rwRENDERSTATESTENCILENABLE,
596+
/**<Stenciling on/off.
597+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
598+
* Default: FALSE.
599+
*/
600+
rwRENDERSTATESTENCILFAIL,
601+
/**<\ref RwStencilOperation used when the stencil test passes.
602+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
603+
* Default: rwSTENCILOPERATIONKEEP.
604+
*/
605+
rwRENDERSTATESTENCILZFAIL,
606+
/**<\ref RwStencilOperation used when the stencil test passes and
607+
* the depth test (z-test) fails.
608+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
609+
* Default: rwSTENCILOPERATIONKEEP.
610+
*/
611+
rwRENDERSTATESTENCILPASS,
612+
/**<\ref RwStencilOperation used when both the stencil and the depth
613+
* (z) tests pass.
614+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
615+
* Default: rwSTENCILOPERATIONKEEP.
616+
*/
617+
rwRENDERSTATESTENCILFUNCTION,
618+
/**<\ref RwStencilFunction for the stencil test.
619+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
620+
* Default: rwSTENCILFUNCTIONALWAYS.
621+
*/
622+
rwRENDERSTATESTENCILFUNCTIONREF,
623+
/**<Integer reference value for the stencil test.
624+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
625+
* Default: 0.
626+
*/
627+
rwRENDERSTATESTENCILFUNCTIONMASK,
628+
/**<Mask applied to the reference value and each stencil buffer
629+
* entry to determine the significant bits for the stencil test.
630+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
631+
* Default: 0xffffffff.
632+
*/
633+
rwRENDERSTATESTENCILFUNCTIONWRITEMASK,
634+
/**<Write mask applied to values written into the stencil buffer.
635+
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
636+
* Default: 0xffffffff.
637+
*/
638+
rwRENDERSTATEALPHATESTFUNCTION,
639+
/**<\ref RwAlphaTestFunction for the alpha test. When a pixel fails,
640+
* neither the frame buffer nor the Z-buffer are updated.
641+
* Default: rwALPHATESTFUNCTIONGREATER (GameCube, Xbox, D3D8, D3D9
642+
* and OpenGL). The default PS2 behaviour is to always update the
643+
* frame buffer and update the Z-buffer only if a greater than or
644+
* equal test passes.
645+
*/
646+
rwRENDERSTATEALPHATESTFUNCTIONREF,
647+
/**<Integer reference value for the alpha test.
648+
* <i> Range is 0 to 255, mapped to the platform's actual range </i>
649+
* Default: 128 (PS2) 0 (GameCube, Xbox, D3D8, D3D9 and OpenGL).
650+
*/
651+
652+
rwRENDERSTATEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
653+
};
654+
655+
enum RwCullMode
656+
{
657+
rwCULLMODENACULLMODE = 0,
658+
659+
rwCULLMODECULLNONE,
660+
/**<Both front and back-facing triangles are drawn. */
661+
rwCULLMODECULLBACK,
662+
/**<Only front-facing triangles are drawn */
663+
rwCULLMODECULLFRONT,
664+
/**<Only back-facing triangles are drawn */
665+
666+
rwCULLMODEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
667+
};
668+
490669
// RenderWare base types
491670
struct RwBuffer
492671
{
@@ -532,14 +711,17 @@ struct RwError
532711
/*****************************************************************************/
533712

534713
typedef bool (*RwSystemFunc)(std::int32_t, void*, void*, std::int32_t);
714+
using RwRenderStateSetFunction = bool(*)(RwRenderState, void*);
715+
using RwRenderStateGetFunction = bool(*)(RwRenderState, void*);
716+
535717
struct RwDevice
536718
{
537719
float gammaCorrection;
538720
RwSystemFunc fpSystem;
539721
float zBufferNear;
540722
float zBufferFar;
541-
// RwRenderStateSetFunction fpRenderStateSet;
542-
// RwRenderStateGetFunction fpRenderStateGet;
723+
RwRenderStateSetFunction fpRenderStateSet;
724+
RwRenderStateGetFunction fpRenderStateGet;
543725
// RwIm2DRenderLineFunction fpIm2DRenderLine;
544726
// RwIm2DRenderTriangleFunction fpIm2DRenderTriangle;
545727
// RwIm2DRenderPrimitiveFunction fpIm2DRenderPrimitive;

0 commit comments

Comments
 (0)