librw/src/d3d/d3d8render.cpp

66 lines
1.8 KiB
C++
Raw Normal View History

2020-04-30 17:54:38 +02:00
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define WITH_D3D
#include "../rwbase.h"
#include "../rwplg.h"
#include "../rwpipeline.h"
#include "../rwobjects.h"
2017-08-09 10:57:32 +02:00
#include "../rwengine.h"
#include "rwd3d.h"
#include "rwd3d8.h"
namespace rw {
namespace d3d8 {
using namespace d3d;
#ifndef RW_D3D9
void defaultRenderCB(Atomic*, InstanceDataHeader*) {}
#else
2018-01-03 18:02:02 +01:00
// This is a bit abandoned, use d3d9 instead
void
defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
{
2017-08-04 19:54:03 +02:00
RawMatrix world;
d3d::lightingCB_Fix(atomic);
2017-08-09 10:57:32 +02:00
Geometry *geo = atomic->geometry;
2017-08-09 10:57:32 +02:00
d3d::setRenderState(D3DRS_LIGHTING, !!(geo->flags & rw::Geometry::LIGHT));
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);
InstanceData *inst = header->inst;
for(uint32 i = 0; i < header->numMeshes; i++){
d3d::setTexture(0, inst->material->texture);
d3d::setMaterial(inst->material->color, inst->material->surfaceProps);
2018-01-03 18:02:02 +01:00
d3d::setRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL);
d3d::setRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL);
2017-03-16 11:42:59 +01:00
if(geo->flags & Geometry::PRELIT)
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1);
2017-08-29 10:12:56 +02:00
else
d3d::setRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_MATERIAL);
2017-08-09 10:57:32 +02:00
d3ddevice->SetFVF(inst->vertexShader);
2020-04-24 19:06:11 +02:00
setStreamSource(0, (IDirect3DVertexBuffer9*)inst->vertexBuffer, 0, inst->stride);
setIndices((IDirect3DIndexBuffer9*)inst->indexBuffer);
uint32 numPrim = inst->primType == D3DPT_TRIANGLESTRIP ? inst->numIndices-2 : inst->numIndices/3;
d3d::flushCache();
2017-08-09 10:57:32 +02:00
d3ddevice->DrawIndexedPrimitive((D3DPRIMITIVETYPE)inst->primType, inst->baseIndex,
0, inst->numVertices, 0, numPrim);
inst++;
}
}
#endif
}
}