mirror of https://github.com/aap/librw.git
forgot files :(
This commit is contained in:
parent
4a3cf2a602
commit
37ec9e041a
|
@ -0,0 +1,53 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <cassert>
|
||||
|
||||
#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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue