From 37ec9e041ae9fd57518badb5b678ff278f21183b Mon Sep 17 00:00:00 2001 From: aap Date: Tue, 16 Feb 2016 16:27:18 +0100 Subject: [PATCH] forgot files :( --- src/d3d8render.cpp | 53 ++++++++++++++++++++++++++++++++++++++ src/d3d9render.cpp | 54 +++++++++++++++++++++++++++++++++++++++ src/d3ddriver.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 170 insertions(+) create mode 100644 src/d3d8render.cpp create mode 100644 src/d3d9render.cpp create mode 100644 src/d3ddriver.cpp diff --git a/src/d3d8render.cpp b/src/d3d8render.cpp new file mode 100644 index 0000000..153d150 --- /dev/null +++ b/src/d3d8render.cpp @@ -0,0 +1,53 @@ +#include +#include +#include +#include + +#include "rwbase.h" +#include "rwplugin.h" +#include "rwpipeline.h" +#include "rwobjects.h" +#include "rwd3d.h" +#include "rwd3d8.h" + +namespace rw { +namespace d3d8 { +using namespace d3d; + +#ifndef RW_D3D9 +void defaultRenderCB(Atomic*, InstanceDataHeader*) {} +#else + +void +defaultRenderCB(Atomic *atomic, InstanceDataHeader *header) +{ + Geometry *geo = atomic->geometry; + Frame *f = atomic->getFrame(); + device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)f->getLTM()); + + InstanceData *inst = header->inst; + for(uint32 i = 0; i < header->numMeshes; i++){ + if(inst->material->texture) + setTexture(inst->material->texture); + else + device->SetTexture(0, NULL); + setMaterial(inst->material); + device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(0xFF, 0x40, 0x40, 0x40)); + device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); + device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); + if(geo->geoflags & Geometry::PRELIT) + device->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); + + device->SetFVF(inst->vertexShader); + device->SetStreamSource(0, (IDirect3DVertexBuffer9*)inst->vertexBuffer, 0, inst->stride); + device->SetIndices((IDirect3DIndexBuffer9*)inst->indexBuffer); + uint32 numPrim = inst->primType == D3DPT_TRIANGLESTRIP ? inst->numIndices-2 : inst->numIndices/3; + device->DrawIndexedPrimitive((D3DPRIMITIVETYPE)inst->primType, inst->baseIndex, + 0, inst->numVertices, 0, numPrim); + inst++; + } +} + +#endif +} +} \ No newline at end of file diff --git a/src/d3d9render.cpp b/src/d3d9render.cpp new file mode 100644 index 0000000..f2e0ea1 --- /dev/null +++ b/src/d3d9render.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include + +#include "rwbase.h" +#include "rwplugin.h" +#include "rwpipeline.h" +#include "rwobjects.h" +#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) +{ + Geometry *geo = atomic->geometry; + Frame *f = atomic->getFrame(); + device->SetTransform(D3DTS_WORLD, (D3DMATRIX*)f->getLTM()); + + device->SetStreamSource(0, (IDirect3DVertexBuffer9*)header->vertexStream[0].vertexBuffer, + 0, header->vertexStream[0].stride); + device->SetIndices((IDirect3DIndexBuffer9*)header->indexBuffer); + device->SetVertexDeclaration((IDirect3DVertexDeclaration9*)header->vertexDeclaration); + + InstanceData *inst = header->inst; + for(uint32 i = 0; i < header->numMeshes; i++){ + if(inst->material->texture) + setTexture(inst->material->texture); + else + device->SetTexture(0, NULL); + setMaterial(inst->material); + device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_ARGB(0xFF, 0x40, 0x40, 0x40)); + device->SetRenderState(D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_MATERIAL); + device->SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL); + if(geo->geoflags & Geometry::PRELIT) + device->SetRenderState(D3DRS_EMISSIVEMATERIALSOURCE, D3DMCS_COLOR1); + device->DrawIndexedPrimitive((D3DPRIMITIVETYPE)header->primType, inst->baseIndex, + 0, inst->numVertices, + inst->startIndex, inst->numPrimitives); + inst++; + } +} + +#endif +} +} \ No newline at end of file diff --git a/src/d3ddriver.cpp b/src/d3ddriver.cpp new file mode 100644 index 0000000..12b2e0a --- /dev/null +++ b/src/d3ddriver.cpp @@ -0,0 +1,63 @@ +#include +#include +#include +#include + +#include "rwbase.h" +#include "rwplugin.h" +#include "rwpipeline.h" +#include "rwobjects.h" +#include "rwd3d.h" + +namespace rw { +namespace d3d { +#ifdef RW_D3D9 + +void +setTexture(Texture *tex) +{ + static DWORD filternomip[] = { + 0, D3DTEXF_POINT, D3DTEXF_LINEAR, + D3DTEXF_POINT, D3DTEXF_LINEAR, + D3DTEXF_POINT, D3DTEXF_LINEAR + }; + static DWORD wrap[] = { + 0, D3DTADDRESS_WRAP, D3DTADDRESS_MIRROR, + D3DTADDRESS_CLAMP, D3DTADDRESS_BORDER + }; + + D3dRaster *raster = PLUGINOFFSET(D3dRaster, tex->raster, nativeRasterOffset); + if(tex->raster && raster->texture){ + device->SetTexture(0, (IDirect3DTexture9*)raster->texture); + device->SetSamplerState(0, D3DSAMP_MAGFILTER, filternomip[tex->filterAddressing & 0xFF]); + device->SetSamplerState(0, D3DSAMP_MINFILTER, filternomip[tex->filterAddressing & 0xFF]); + device->SetSamplerState(0, D3DSAMP_ADDRESSU, wrap[(tex->filterAddressing >> 8) & 0xF]); + device->SetSamplerState(0, D3DSAMP_ADDRESSV, wrap[(tex->filterAddressing >> 12) & 0xF]); + }else + device->SetTexture(0, NULL); +} + +void +setMaterial(Material *mat) +{ + D3DMATERIAL9 mat9; + D3DCOLORVALUE black = { 0, 0, 0, 0 }; + float ambmult = mat->surfaceProps.ambient/255.0f; + float diffmult = mat->surfaceProps.diffuse/255.0f; + mat9.Ambient.r = mat->color.red*ambmult; + mat9.Ambient.g = mat->color.green*ambmult; + mat9.Ambient.b = mat->color.blue*ambmult; + mat9.Ambient.a = mat->color.alpha*ambmult; + mat9.Diffuse.r = mat->color.red*diffmult; + mat9.Diffuse.g = mat->color.green*diffmult; + mat9.Diffuse.b = mat->color.blue*diffmult; + mat9.Diffuse.a = mat->color.alpha*diffmult; + mat9.Power = 0.0f; + mat9.Emissive = black; + mat9.Specular = black; + device->SetMaterial(&mat9); +} + +#endif +} +} \ No newline at end of file