2016-06-24 15:24:58 +02:00
|
|
|
#include <cstdio>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "../rwbase.h"
|
|
|
|
#include "../rwplg.h"
|
|
|
|
#include "../rwpipeline.h"
|
|
|
|
#include "../rwobjects.h"
|
2017-08-09 10:57:32 +02:00
|
|
|
#include "../rwengine.h"
|
2018-01-03 18:02:02 +01:00
|
|
|
#include "../rwrender.h"
|
2016-06-24 15:24:58 +02:00
|
|
|
#include "rwd3d.h"
|
|
|
|
#include "rwd3d9.h"
|
|
|
|
|
|
|
|
namespace rw {
|
|
|
|
namespace d3d9 {
|
|
|
|
using namespace d3d;
|
|
|
|
|
|
|
|
#ifndef RW_D3D9
|
|
|
|
void defaultRenderCB(Atomic*, InstanceDataHeader*) {}
|
|
|
|
#else
|
|
|
|
|
|
|
|
void
|
|
|
|
defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
|
|
|
|
{
|
2017-08-04 19:54:03 +02:00
|
|
|
RawMatrix world;
|
2017-11-15 19:23:50 +01:00
|
|
|
Geometry *geo = atomic->geometry;
|
2017-08-04 19:54:03 +02:00
|
|
|
|
2017-11-15 19:23:50 +01:00
|
|
|
int lighting = !!(geo->flags & rw::Geometry::LIGHT);
|
|
|
|
if(lighting)
|
|
|
|
d3d::lightingCB();
|
2017-12-30 11:43:17 +01:00
|
|
|
// else
|
|
|
|
// return;
|
2017-08-09 10:57:32 +02:00
|
|
|
|
2017-11-15 19:23:50 +01:00
|
|
|
d3d::setRenderState(D3DRS_LIGHTING, lighting);
|
2017-08-09 10:57:32 +02:00
|
|
|
|
2016-06-24 15:24:58 +02:00
|
|
|
Frame *f = atomic->getFrame();
|
2017-08-04 19:54:03 +02:00
|
|
|
convMatrix(&world, f->getLTM());
|
2017-08-09 10:57:32 +02:00
|
|
|
d3ddevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&world);
|
2016-06-24 15:24:58 +02:00
|
|
|
|
2017-08-09 10:57:32 +02:00
|
|
|
d3ddevice->SetStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer,
|
|
|
|
0, header->vertexStream[0].stride);
|
|
|
|
d3ddevice->SetIndices((IDirect3DIndexBuffer9*)header->indexBuffer);
|
|
|
|
d3ddevice->SetVertexDeclaration((IDirect3DVertexDeclaration9*)header->vertexDeclaration);
|
2016-06-24 15:24:58 +02:00
|
|
|
|
|
|
|
InstanceData *inst = header->inst;
|
|
|
|
for(uint32 i = 0; i < header->numMeshes; i++){
|
2018-01-03 18:02:02 +01:00
|
|
|
// Texture
|
2016-06-24 15:24:58 +02:00
|
|
|
d3d::setTexture(0, inst->material->texture);
|
2017-12-30 11:43:17 +01:00
|
|
|
d3d::setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
|
|
|
d3d::setTextureStageState(0, D3DTSS_COLORARG1, D3DTA_CURRENT);
|
|
|
|
d3d::setTextureStageState(0, D3DTSS_COLORARG2, D3DTA_TEXTURE);
|
|
|
|
d3d::setTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
|
|
|
d3d::setTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
|
|
|
|
d3d::setTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_TEXTURE);
|
|
|
|
|
2018-01-03 18:02:02 +01:00
|
|
|
SetRenderState(VERTEXALPHA, inst->vertexAlpha || inst->material->color.alpha != 255);
|
|
|
|
|
|
|
|
// Material colour
|
|
|
|
const rw::RGBA *col = &inst->material->color;
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_CONSTANT, D3DCOLOR_ARGB(col->alpha,col->red,col->green,col->blue));
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_COLORARG1, D3DTA_CURRENT);
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CONSTANT);
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_ALPHAARG1, D3DTA_CURRENT);
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_ALPHAARG2, D3DTA_CONSTANT);
|
|
|
|
|
|
|
|
const static rw::RGBA white = { 255, 255, 255, 255 };
|
|
|
|
d3d::setMaterial(inst->material->surfaceProps, white);
|
2017-11-15 19:23:50 +01:00
|
|
|
|
2016-06-24 15:24:58 +02:00
|
|
|
d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
|
2017-03-16 11:42:59 +01:00
|
|
|
if(geo->flags & Geometry::PRELIT)
|
2016-06-24 15:24:58 +02:00
|
|
|
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1);
|
2017-08-29 10:12:56 +02:00
|
|
|
else
|
|
|
|
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
|
2018-01-03 18:02:02 +01:00
|
|
|
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, inst->vertexAlpha ? D3DMCS_COLOR1 : D3DMCS_MATERIAL);
|
2017-11-15 19:23:50 +01:00
|
|
|
|
2016-06-24 15:24:58 +02:00
|
|
|
d3d::flushCache();
|
2017-08-09 10:57:32 +02:00
|
|
|
d3ddevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)header->primType, inst->baseIndex,
|
|
|
|
0, inst->numVertices,
|
|
|
|
inst->startIndex, inst->numPrimitives);
|
2016-06-24 15:24:58 +02:00
|
|
|
inst++;
|
|
|
|
}
|
2018-01-03 18:02:02 +01:00
|
|
|
d3d::setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
|
|
|
|
d3d::setTextureStageState(1, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
|
2016-06-24 15:24:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|