From ad815102677a502f7cdcbd42bed0b4dd14a4eda5 Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 14 Feb 2016 12:28:03 +0100 Subject: [PATCH] moved d3d rendering code here --- librw.vcxproj | 3 +++ src/d3d9.cpp | 20 ++++++++++++++++++-- src/pipeline.cpp | 9 --------- src/rwd3d.h | 5 +++++ src/rwd3d9.h | 5 +++++ src/rwpipeline.h | 2 -- 6 files changed, 31 insertions(+), 13 deletions(-) diff --git a/librw.vcxproj b/librw.vcxproj index 997b042..b92783a 100644 --- a/librw.vcxproj +++ b/librw.vcxproj @@ -191,7 +191,10 @@ + + + diff --git a/src/d3d9.cpp b/src/d3d9.cpp index 021d428..d15cc37 100644 --- a/src/d3d9.cpp +++ b/src/d3d9.cpp @@ -10,8 +10,6 @@ #include "rwd3d.h" #include "rwd3d9.h" -using namespace std; - namespace rw { namespace d3d9 { using namespace d3d; @@ -346,13 +344,28 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) destroyNativeData(geo, 0, 0); } +static void +render(rw::ObjPipeline *rwpipe, Atomic *atomic) +{ + ObjPipeline *pipe = (ObjPipeline*)rwpipe; + Geometry *geo = atomic->geometry; + if((geo->geoflags & Geometry::NATIVE) == 0) + pipe->instance(atomic); + assert(geo->instData != NULL); + assert(geo->instData->platform == PLATFORM_D3D9); + if(pipe->renderCB) + pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); +} + ObjPipeline::ObjPipeline(uint32 platform) : rw::ObjPipeline(platform) { this->impl.instance = d3d9::instance; this->impl.uninstance = d3d9::uninstance; + this->impl.render = d3d9::render; this->instanceCB = NULL; this->uninstanceCB = NULL; + this->renderCB = NULL; } void @@ -494,6 +507,7 @@ makeDefaultPipeline(void) ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; + pipe->renderCB = defaultRenderCB; return pipe; } @@ -503,6 +517,7 @@ makeSkinPipeline(void) ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; + pipe->renderCB = defaultRenderCB; pipe->pluginID = ID_SKIN; pipe->pluginData = 1; return pipe; @@ -514,6 +529,7 @@ makeMatFXPipeline(void) ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; + pipe->renderCB = defaultRenderCB; pipe->pluginID = ID_MATFX; pipe->pluginData = 0; return pipe; diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 5db6a33..94ee501 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -16,8 +16,6 @@ using namespace std; namespace rw { -void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*); - static void nothing(ObjPipeline *, Atomic*) {} Pipeline::Pipeline(uint32 platform) @@ -35,13 +33,6 @@ ObjPipeline::ObjPipeline(uint32 platform) this->impl.render = nothing; } -//void -//ObjPipeline::render(Atomic *atomic) -//{ -// if(defaultRenderCBs[rw::platform]) -// defaultRenderCBs[rw::platform](atomic); -//} - // helper functions void diff --git a/src/rwd3d.h b/src/rwd3d.h index 2977292..e441b59 100644 --- a/src/rwd3d.h +++ b/src/rwd3d.h @@ -95,5 +95,10 @@ void setTexels(Raster *raster, void *texels, int32 level); extern int32 nativeRasterOffset; void registerNativeRaster(void); +// Rendering + +void setTexture(Texture *tex); +void setMaterial(Material *mat); + } } diff --git a/src/rwd3d9.h b/src/rwd3d9.h index 64b9e36..ff02318 100644 --- a/src/rwd3d9.h +++ b/src/rwd3d9.h @@ -63,10 +63,15 @@ class ObjPipeline : public rw::ObjPipeline public: void (*instanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); + void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); ObjPipeline(uint32 platform); }; +void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header); +void defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header); +void defaultRenderCB(Atomic *atomic, InstanceDataHeader *header); + ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeSkinPipeline(void); diff --git a/src/rwpipeline.h b/src/rwpipeline.h index 7c6ab18..076395a 100644 --- a/src/rwpipeline.h +++ b/src/rwpipeline.h @@ -29,8 +29,6 @@ public: void render(Atomic *atomic) { this->impl.render(this, atomic); } }; -extern void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*); - void findMinVertAndNumVertices(uint16 *indices, uint32 numIndices, uint32 *minVert, int32 *numVertices); // everything xbox, d3d8 and d3d9 may want to use