OpenBarnyard
 
Loading...
Searching...
No Matches
ASysShader_DX8.cpp
Go to the documentation of this file.
1#include "pch.h"
2#include "ASysShader_DX8.h"
3#include "ASysMaterial_DX8.h"
4#include "ASysMesh_DX8.h"
5
6#ifdef TOSHI_SKU_WINDOWS
11#endif // TOSHI_SKU_WINDOWS
12
13//-----------------------------------------------------------------------------
14// Enables memory debugging.
15// Note: Should be the last include!
16//-----------------------------------------------------------------------------
17#include <Core/TMemoryDebugOn.h>
18
20
22
24{
25 Validate();
26
28 auto pRenderContext = TSTATICCAST(
30 TRenderD3DInterface::Interface()->GetCurrentContext()
31 );
32
33 pDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, 2 );
34 pDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, 2 );
35 pDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, 1 );
36 pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
37 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
38 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, 1 );
39 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 4 );
40 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
41 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, 1 );
42 pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
43 pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
44 pDevice->SetVertexShader( D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_XYZ );
45
46 static TMatrix44 s_Identity = TMatrix44::IDENTITY;
47
48 pDevice->SetTransform( D3DTS_PROJECTION, pRenderContext->GetProjectionMatrix() );
49 pDevice->SetTransform( D3DTS_VIEW, s_Identity );
50 pDevice->SetPixelShader( 0 );
51
52 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
53 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
54 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
55 pDevice->SetRenderState( D3DRS_ALPHAREF, 1 );
56 pDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
57 pDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
58 pDevice->SetRenderState( D3DRS_LIGHTING, 0 );
59 pDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
60
61 m_aOrderTables[ 0 ].Render();
62 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
63 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
64 pDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
65}
66
68{
69 Validate();
70
72 auto pRenderContext = TSTATICCAST(
74 TRenderD3DInterface::Interface()->GetCurrentContext()
75 );
76
77 pDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, 2 );
78 pDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, 2 );
79 pDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, 1 );
80 pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
81 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
82 pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, 1 );
83 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 4 );
84 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
85 pDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, 1 );
86 pDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
87 pDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
88 pDevice->SetVertexShader( D3DFVF_TEX1 | D3DFVF_DIFFUSE | D3DFVF_XYZ );
89
90 static TMatrix44 s_Identity = TMatrix44::IDENTITY;
91
92 pDevice->SetTransform( D3DTS_PROJECTION, (D3DMATRIX*)&pRenderContext->GetProjectionMatrix() );
93 pDevice->SetTransform( D3DTS_VIEW, s_Identity );
94 pDevice->SetPixelShader( 0 );
95
96 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
97 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
98 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
99 pDevice->SetRenderState( D3DRS_ALPHAREF, 1 );
100 pDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
101 pDevice->SetRenderState( D3DRS_SPECULARENABLE, FALSE );
102 pDevice->SetRenderState( D3DRS_LIGHTING, 0 );
103 pDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
104}
105
107{
109
110 pDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
111 pDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
112 pDevice->SetRenderState( D3DRS_FOGENABLE, FALSE );
113}
114
116{
117 TASSERT( TFALSE == IsCreated() );
118
119 m_aOrderTables[ 0 ].Create( this, -1000 );
120 m_aOrderTables[ 1 ].Create( this, 2000 );
121 m_aOrderTables[ 2 ].Create( this, -6000 );
122 m_aOrderTables[ 3 ].Create( this, -5990 );
123
124 ASysShader::Create();
125 return Validate();
126}
127
129{
130 if ( !IsValidated() )
131 {
132 return ASysShader::Validate();
133 }
134
135 return TTRUE;
136}
137
139{
140 if ( IsValidated() )
141 {
142 return ASysShader::Invalidate();
143 }
144}
145
147{
148 Invalidate();
149 return TTRUE;
150}
151
153{
154 Validate();
155 return TTRUE;
156}
157
159{
160 TASSERT( pPacket->GetMesh()->IsExactly( &TGetClass( ASysMeshHAL ) ) );
161
163 ASysMeshHAL* pMeshHAL = TSTATICCAST( ASysMeshHAL, pPacket->GetMesh() );
164
165 pDevice->SetTransform( D3DTS_WORLDMATRIX( 0 ), (D3DMATRIX*)&pPacket->GetModelViewMatrix() );
166 pDevice->SetRenderState( D3DRS_ZBIAS, pMeshHAL->GetZBias() );
167
168 auto pVertexPool = TDYNAMICCAST( TVertexPoolResource, pMeshHAL->GetVertexPool() );
169 auto pIndexPool = TDYNAMICCAST( TIndexPoolResource, pMeshHAL->GetIndexPool() );
170
171 TVertexBlockResource::HALBuffer vertexHALBuffer;
172 pVertexPool->GetHALBuffer( &vertexHALBuffer );
173
174 TIndexBlockResource::HALBuffer indexHALBuffer;
175 pIndexPool->GetHALBuffer( &indexHALBuffer );
176
177 pDevice->SetStreamSource( 0, vertexHALBuffer.apVertexBuffers[ 0 ], 24 );
178 pDevice->SetIndices( indexHALBuffer.pIndexBuffer, vertexHALBuffer.uiVertexOffset );
179
180 if ( ms_bRenderEnabled )
181 {
182 if ( pIndexPool->GetFlags() & 8 )
183 {
184 pDevice->DrawIndexedPrimitive(
185 D3DPT_TRIANGLESTRIP,
186 0,
187 pVertexPool->GetNumVertices(),
188 indexHALBuffer.uiIndexOffset,
189 pIndexPool->GetNumIndices() - 2
190 );
191 }
192 else
193 {
194 pDevice->DrawIndexedPrimitive(
195 D3DPT_TRIANGLELIST,
196 0,
197 pVertexPool->GetNumVertices(),
198 indexHALBuffer.uiIndexOffset,
199 pIndexPool->GetNumIndices() / 3
200 );
201 }
202 }
203
204 pDevice->SetRenderState( D3DRS_ZBIAS, 0 );
205}
206
208{
209 Validate();
210
211 auto pMaterialHAL = new ASysMaterialHAL();
212 pMaterialHAL->SetShader( this );
213 pMaterialHAL->SetOrderTable( &m_aOrderTables[ 0 ] );
214
215 return pMaterialHAL;
216}
217
219{
220 Validate();
221
222 auto pMeshHAL = new ASysMeshHAL();
223 pMeshHAL->SetOwnerShader( this );
224
225 return pMeshHAL;
226}
#define TASSERT(X,...)
Definition Defines.h:138
#define TSTATICCAST(POINTERTYPE, VALUE)
Definition Defines.h:69
#define TOSHI_NAMESPACE_USING
Definition Defines.h:46
#define TGetClass(CLASS)
Definition TObject.h:13
#define TDYNAMICCAST(T, OBJECT)
Definition TObject.h:227
#define TDEFINE_CLASS(...)
Definition TObject.h:120
char TCHAR
Definition Typedefs.h:20
#define TFALSE
Definition Typedefs.h:24
#define TTRUE
Definition Typedefs.h:25
bool TBOOL
Definition Typedefs.h:6
static constinit TMatrix44 IDENTITY
Definition TMatrix44.h:357
TFORCEINLINE IDirect3DDevice8 * GetDirect3DDevice() const
Gets the Direct3D device.
static TFORCEINLINE TRenderD3DInterface * Interface()
Gets the render interface singleton.
IDirect3DVertexBuffer8 * apVertexBuffers[TVertexFactoryFormat::MAX_NUM_STREAMS]
TMatrix44 & GetModelViewMatrix()
TMesh * GetMesh() const
TINT GetZBias() const
virtual TBOOL TryInvalidate() override
virtual TBOOL Validate() override
virtual void Invalidate() override
virtual ASysMesh * CreateMesh(const TCHAR *a_szName) override
virtual void Render(Toshi::TRenderPacket *pPacket) override
virtual void Flush() override
virtual TBOOL Create() override
virtual TBOOL TryValidate() override
static TBOOL ms_bRenderEnabled
virtual ASysMaterial * CreateMaterial(const TCHAR *a_szName) override
virtual void StartFlush() override
virtual void EndFlush() override
virtual Toshi::TIndexPoolResourceInterface * GetIndexPool()
Definition ASysMesh.cpp:198
virtual Toshi::TVertexPoolResourceInterface * GetVertexPool()
Definition ASysMesh.cpp:193