241{
243 auto pD3DDevice = pRender->GetDirect3DDevice();
244
245 if ( a_pMaterial == m_pMaterial )
246 {
247 return;
248 }
249
250 pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 0 );
251 pD3DDevice->SetRenderState( D3DRS_CULLMODE, 1 );
253
254 if ( a_pMaterial ==
TNULL )
255 {
256 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
257 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
258 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
259 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 1 );
260 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
261 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 6 );
262 pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 2 );
263 pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 0 );
264 pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 2 );
265 pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 0 );
266 pD3DDevice->SetTextureStageState( 0, D3DTSS_MIPMAPLODBIAS, 0 );
267 pD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
268 pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
270 }
271 else
272 {
273 auto pTexture =
TSTATICCAST( Toshi::TTextureResourceHAL, a_pMaterial->m_pTextureResource );
274 pTexture->Validate();
275
276 pD3DDevice->SetTexture( 0, pTexture->GetD3DTexture() );
277 pRender->SetTextureAddress( 0, pTexture->GetAddressing(),
TEXCOORD_UV );
278
279 switch ( a_pMaterial->m_eBlendState )
280 {
281 case 0:
282 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 0 );
283 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
284 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
285 break;
286 case 1:
287 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
288 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
289 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
290 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 1 );
291 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
292 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 6 );
293 pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, 0 );
294 break;
295 case 2:
296 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
297 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
298 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
299 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 1 );
300 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
301 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 2 );
302 pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, 0 );
303 break;
304 case 3:
305 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
306 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
307 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
308 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 3 );
309 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
310 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 2 );
311 pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, 0 );
312 break;
313 case 4:
314 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 1 );
315 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 2 );
316 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
317 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 1 );
318 pD3DDevice->SetRenderState( D3DRS_ZENABLE, 1 );
319 pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, 1 );
320 pD3DDevice->SetRenderState( D3DRS_ZFUNC, 4 );
321 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0x3c );
322 pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 1 );
323 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 7 );
324
326 {
328 }
329 else
330 {
332 }
333
334 break;
335 case 5:
336 pD3DDevice->SetRenderState( D3DRS_ZENABLE, 1 );
337 pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, 0 );
338 pD3DDevice->SetRenderState( D3DRS_ZFUNC, 4 );
339 pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 0 );
340 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
341 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
342 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
343 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 6 );
344 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
345
347 {
350 }
351
352 break;
353 case 6:
354 pD3DDevice->SetRenderState( D3DRS_ALPHATESTENABLE, 0 );
355 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
356 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
357 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
358 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 1 );
359 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
360 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 6 );
361 pD3DDevice->SetRenderState( D3DRS_ZWRITEENABLE, 1 );
362 pD3DDevice->SetRenderState( D3DRS_ZFUNC, 4 );
365 break;
366 default:
367 pD3DDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, 1 );
368 pD3DDevice->SetRenderState( D3DRS_ALPHAFUNC, 5 );
369 pD3DDevice->SetRenderState( D3DRS_ALPHAREF, 0 );
370 pD3DDevice->SetRenderState( D3DRS_BLENDOP, 1 );
371 pD3DDevice->SetRenderState( D3DRS_SRCBLEND, 5 );
372 pD3DDevice->SetRenderState( D3DRS_DESTBLEND, 6 );
373 break;
374 }
375
376 if ( a_pMaterial->m_eTextureAddress == 1 )
377 {
378 pD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP );
379 pD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP );
380 }
381 else if ( a_pMaterial->m_eTextureAddress == 2 )
382 {
383 pD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_MIRROR );
384 pD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_MIRROR );
385 }
386 else
387 {
388 pD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP );
389 pD3DDevice->SetTextureStageState( 0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP );
390 }
391
392 pD3DDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, 2 );
393 pD3DDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, 2 );
394 pD3DDevice->SetTextureStageState( 0, D3DTSS_MIPFILTER, 1 );
395 pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, 4 );
396 pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, 2 );
397 pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, 0 );
398 pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, 4 );
399 pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG1, 2 );
400 pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, 0 );
401 pD3DDevice->SetTextureStageState( 0, D3DTSS_MIPMAPLODBIAS, a_pMaterial->m_iMipMapLODBias );
402 pD3DDevice->SetTextureStageState( 1, D3DTSS_COLOROP, 1 );
403 pD3DDevice->SetTextureStageState( 1, D3DTSS_ALPHAOP, 1 );
404 m_pMaterial = a_pMaterial;
405 }
406}