From dc4011ba7a63eed9fd7ffb121c376babefe12584 Mon Sep 17 00:00:00 2001 From: aap Date: Sun, 14 Feb 2016 00:52:45 +0100 Subject: [PATCH] changes pipeline system a bit --- src/d3d8.cpp | 27 +++++++++++++++++---------- src/d3d9.cpp | 27 +++++++++++++++++---------- src/ogl.cpp | 34 +++++++++++++++++++++------------- src/pipeline.cpp | 42 +++++++++++++----------------------------- src/ps2.cpp | 39 +++++++++++++++++++++++---------------- src/rwd3d8.h | 2 -- src/rwd3d9.h | 2 -- src/rwogl.h | 2 -- src/rwpipeline.h | 25 ++++++++++++------------- src/rwps2.h | 33 +++++++++++++++++++-------------- src/rwxbox.h | 2 -- src/xbox.cpp | 28 ++++++++++++++++++---------- 12 files changed, 140 insertions(+), 123 deletions(-) diff --git a/src/d3d8.cpp b/src/d3d8.cpp index 370ad0d..fafdbfd 100644 --- a/src/d3d8.cpp +++ b/src/d3d8.cpp @@ -196,13 +196,10 @@ registerNativeDataPlugin(void) } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform), - instanceCB(NULL), uninstanceCB(NULL) { } - -void -ObjPipeline::instance(Atomic *atomic) +static void +instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if(geo->geoflags & Geometry::NATIVE) return; @@ -240,15 +237,16 @@ ObjPipeline::instance(Atomic *atomic) indices[j] = mesh->indices[j] - inst->minVert; unlockIndices(inst->indexBuffer); - this->instanceCB(geo, inst); + pipe->instanceCB(geo, inst); mesh++; inst++; } } -void -ObjPipeline::uninstance(Atomic *atomic) +static void +uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if((geo->geoflags & Geometry::NATIVE) == 0) return; @@ -270,7 +268,7 @@ ObjPipeline::uninstance(Atomic *atomic) mesh->indices[j] = indices[j] + inst->minVert; unlockIndices(inst->indexBuffer); - this->uninstanceCB(geo, inst); + pipe->uninstanceCB(geo, inst); mesh++; inst++; } @@ -278,6 +276,15 @@ ObjPipeline::uninstance(Atomic *atomic) destroyNativeData(geo, 0, 0); } +ObjPipeline::ObjPipeline(uint32 platform) + : rw::ObjPipeline(platform) +{ + this->impl.instance = d3d8::instance; + this->impl.uninstance = d3d8::uninstance; + this->instanceCB = NULL; + this->uninstanceCB = NULL; +} + void defaultInstanceCB(Geometry *geo, InstanceData *inst) { diff --git a/src/d3d9.cpp b/src/d3d9.cpp index e30a306..021d428 100644 --- a/src/d3d9.cpp +++ b/src/d3d9.cpp @@ -260,13 +260,10 @@ registerNativeDataPlugin(void) getSizeNativeData); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform), - instanceCB(NULL), uninstanceCB(NULL) { } - -void -ObjPipeline::instance(Atomic *atomic) +static void +instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if(geo->geoflags & Geometry::NATIVE) return; @@ -313,12 +310,13 @@ ObjPipeline::instance(Atomic *atomic) memset(&header->vertexStream, 0, 2*sizeof(VertexStream)); - this->instanceCB(geo, header); + pipe->instanceCB(geo, header); } -void -ObjPipeline::uninstance(Atomic *atomic) +static void +uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if((geo->geoflags & Geometry::NATIVE) == 0) return; @@ -343,11 +341,20 @@ ObjPipeline::uninstance(Atomic *atomic) } unlockIndices(header->indexBuffer); - this->uninstanceCB(geo, header); + pipe->uninstanceCB(geo, header); geo->generateTriangles(); destroyNativeData(geo, 0, 0); } +ObjPipeline::ObjPipeline(uint32 platform) + : rw::ObjPipeline(platform) +{ + this->impl.instance = d3d9::instance; + this->impl.uninstance = d3d9::uninstance; + this->instanceCB = NULL; + this->uninstanceCB = NULL; +} + void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header) { diff --git a/src/ogl.cpp b/src/ogl.cpp index 75c9a1b..ceb5333 100644 --- a/src/ogl.cpp +++ b/src/ogl.cpp @@ -284,13 +284,10 @@ printPipeinfo(Atomic *a) printf("\n"); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform), numCustomAttribs(0), - instanceCB(NULL), uninstanceCB(NULL) { } - -void -ObjPipeline::instance(Atomic *atomic) +static void +instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if(geo->geoflags & Geometry::NATIVE) return; @@ -300,7 +297,7 @@ ObjPipeline::instance(Atomic *atomic) header->vbo = 0; header->ibo = 0; header->numAttribs = - this->numCustomAttribs + 1 + (geo->numTexCoordSets > 0); + pipe->numCustomAttribs + 1 + (geo->numTexCoordSets > 0); if(geo->geoflags & Geometry::PRELIT) header->numAttribs++; if(geo->geoflags & Geometry::NORMALS) @@ -353,8 +350,8 @@ ObjPipeline::instance(Atomic *atomic) firstCustom++; } - if(this->instanceCB) - offset += this->instanceCB(geo, firstCustom, offset); + if(pipe->instanceCB) + offset += pipe->instanceCB(geo, firstCustom, offset); else{ header->dataSize = offset*geo->numVertices; header->data = new uint8[header->dataSize]; @@ -414,9 +411,10 @@ ObjPipeline::instance(Atomic *atomic) geo->geoflags |= Geometry::NATIVE; } -void -ObjPipeline::uninstance(Atomic *atomic) +static void +uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if((geo->geoflags & Geometry::NATIVE) == 0) return; @@ -477,14 +475,24 @@ ObjPipeline::uninstance(Atomic *atomic) } } - if(this->uninstanceCB) - uninstanceCB(geo); + if(pipe->uninstanceCB) + pipe->uninstanceCB(geo); geo->generateTriangles(); destroyNativeData(geo, 0, 0); } +ObjPipeline::ObjPipeline(uint32 platform) + : rw::ObjPipeline(platform) +{ + this->numCustomAttribs = 0; + this->impl.instance = gl::instance; + this->impl.uninstance = gl::uninstance; + this->instanceCB = NULL; + this->uninstanceCB = NULL; +} + ObjPipeline* makeDefaultPipeline(void) { diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 9e27505..5db6a33 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -18,6 +18,8 @@ namespace rw { void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*); +static void nothing(ObjPipeline *, Atomic*) {} + Pipeline::Pipeline(uint32 platform) { this->pluginID = 0; @@ -25,38 +27,20 @@ Pipeline::Pipeline(uint32 platform) this->platform = platform; } -Pipeline::Pipeline(Pipeline *) +ObjPipeline::ObjPipeline(uint32 platform) + : Pipeline(platform) { - assert(0 && "Can't copy pipeline"); + this->impl.instance = nothing; + this->impl.uninstance = nothing; + this->impl.render = nothing; } -Pipeline::~Pipeline(void) -{ -} - -void -Pipeline::dump(void) -{ -} - -void -ObjPipeline::instance(Atomic*) -{ - fprintf(stderr, "This pipeline can't instance\n"); -} - -void -ObjPipeline::uninstance(Atomic*) -{ - fprintf(stderr, "This pipeline can't uninstance\n"); -} - -void -ObjPipeline::render(Atomic *atomic) -{ - if(defaultRenderCBs[rw::platform]) - defaultRenderCBs[rw::platform](atomic); -} +//void +//ObjPipeline::render(Atomic *atomic) +//{ +// if(defaultRenderCBs[rw::platform]) +// defaultRenderCBs[rw::platform](atomic); +//} // helper functions diff --git a/src/ps2.cpp b/src/ps2.cpp index 8fce8b4..b2af046 100644 --- a/src/ps2.cpp +++ b/src/ps2.cpp @@ -611,12 +611,10 @@ MatPipeline::collectData(Geometry *g, InstanceData *inst, Mesh *m, uint8 *data[] return raw; } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform), groupPipeline(NULL) { } - -void -ObjPipeline::instance(Atomic *atomic) +static void +objInstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if(geo->geoflags & Geometry::NATIVE) return; @@ -631,8 +629,8 @@ ObjPipeline::instance(Atomic *atomic) InstanceData *instance = &header->instanceMeshes[i]; MatPipeline *m; - m = this->groupPipeline ? - this->groupPipeline : + m = pipe->groupPipeline ? + pipe->groupPipeline : (MatPipeline*)mesh->material->pipeline; if(m == NULL) m = defaultMatPipe; @@ -642,7 +640,7 @@ ObjPipeline::instance(Atomic *atomic) geo->geoflags |= Geometry::NATIVE; } -void +static void printVertCounts(InstanceData *inst, int flag) { uint32 *d = (uint32*)inst->data; @@ -671,9 +669,10 @@ printVertCounts(InstanceData *inst, int flag) } } -void -ObjPipeline::uninstance(Atomic *atomic) +static void +objUninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if((geo->geoflags & Geometry::NATIVE) == 0) return; @@ -691,8 +690,8 @@ ObjPipeline::uninstance(Atomic *atomic) for(uint32 i = 0; i < header->numMeshes; i++){ Mesh *mesh = &geo->meshHeader->mesh[i]; MatPipeline *m; - m = this->groupPipeline ? - this->groupPipeline : + m = pipe->groupPipeline ? + pipe->groupPipeline : (MatPipeline*)mesh->material->pipeline; if(m == NULL) m = defaultMatPipe; if(m->preUninstCB) m->preUninstCB(m, geo); @@ -702,8 +701,8 @@ ObjPipeline::uninstance(Atomic *atomic) Mesh *mesh = &geo->meshHeader->mesh[i]; InstanceData *instance = &header->instanceMeshes[i]; MatPipeline *m; - m = this->groupPipeline ? - this->groupPipeline : + m = pipe->groupPipeline ? + pipe->groupPipeline : (MatPipeline*)mesh->material->pipeline; if(m == NULL) m = defaultMatPipe; @@ -716,8 +715,8 @@ ObjPipeline::uninstance(Atomic *atomic) for(uint32 i = 0; i < header->numMeshes; i++){ Mesh *mesh = &geo->meshHeader->mesh[i]; MatPipeline *m; - m = this->groupPipeline ? - this->groupPipeline : + m = pipe->groupPipeline ? + pipe->groupPipeline : (MatPipeline*)mesh->material->pipeline; if(m == NULL) m = defaultMatPipe; if(m->postUninstCB) m->postUninstCB(m, geo); @@ -744,6 +743,14 @@ ObjPipeline::uninstance(Atomic *atomic) */ } +ObjPipeline::ObjPipeline(uint32 platform) + : rw::ObjPipeline(platform) +{ + this->groupPipeline = NULL; + this->impl.instance = objInstance; + this->impl.uninstance = objUninstance; +} + int32 findVertex(Geometry *g, uint32 flags[], uint32 mask, Vertex *v) { diff --git a/src/rwd3d8.h b/src/rwd3d8.h index 042c69d..f57bad5 100644 --- a/src/rwd3d8.h +++ b/src/rwd3d8.h @@ -42,8 +42,6 @@ public: void (*uninstanceCB)(Geometry *geo, InstanceData *header); ObjPipeline(uint32 platform); - virtual void instance(Atomic *atomic); - virtual void uninstance(Atomic *atomic); }; ObjPipeline *makeDefaultPipeline(void); diff --git a/src/rwd3d9.h b/src/rwd3d9.h index 7810746..64b9e36 100644 --- a/src/rwd3d9.h +++ b/src/rwd3d9.h @@ -65,8 +65,6 @@ public: void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); ObjPipeline(uint32 platform); - virtual void instance(Atomic *atomic); - virtual void uninstance(Atomic *atomic); }; ObjPipeline *makeDefaultPipeline(void); diff --git a/src/rwogl.h b/src/rwogl.h index f1cd89b..133aa8e 100644 --- a/src/rwogl.h +++ b/src/rwogl.h @@ -51,8 +51,6 @@ public: void (*uninstanceCB)(Geometry *g); ObjPipeline(uint32 platform); - virtual void instance(Atomic *atomic); - virtual void uninstance(Atomic *atomic); }; ObjPipeline *makeDefaultPipeline(void); diff --git a/src/rwpipeline.h b/src/rwpipeline.h index e7c8ec7..7c6ab18 100644 --- a/src/rwpipeline.h +++ b/src/rwpipeline.h @@ -1,11 +1,5 @@ namespace rw { -struct PipeAttribute -{ - const char *name; - uint32 attrib; -}; - struct Atomic; class Pipeline @@ -16,18 +10,23 @@ public: int32 platform; Pipeline(uint32 platform); - Pipeline(Pipeline *p); - ~Pipeline(void); - virtual void dump(void); }; class ObjPipeline : public Pipeline { public: - ObjPipeline(uint32 platform) : Pipeline(platform) {} - virtual void instance(Atomic *atomic); // TODO?: make these callbacks instead of virtual - virtual void uninstance(Atomic *atomic); // TODO?: make these callbacks instead of virtual - virtual void render(Atomic *atomic); // TODO?: make these callbacks instead of virtual + ObjPipeline(uint32 platform); + // not the most beautiful way of doing things but still + // better than virtual methods (i hope?). + struct { + void (*instance)(ObjPipeline *pipe, Atomic *atomic); + void (*uninstance)(ObjPipeline *pipe, Atomic *atomic); + void (*render)(ObjPipeline *pipe, Atomic *atomic); + } impl; + // just for convenience + void instance(Atomic *atomic) { this->impl.instance(this, atomic); } + void uninstance(Atomic *atomic) { this->impl.uninstance(this, atomic); } + void render(Atomic *atomic) { this->impl.render(this, atomic); } }; extern void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*); diff --git a/src/rwps2.h b/src/rwps2.h index 4d1ef27..11b968d 100644 --- a/src/rwps2.h +++ b/src/rwps2.h @@ -59,6 +59,12 @@ void fixDmaOffsets(InstanceData *inst); void unfixDmaOffsets(InstanceData *inst); // +struct PipeAttribute +{ + const char *name; + uint32 attrib; +}; + class MatPipeline : public rw::Pipeline { public: @@ -70,6 +76,13 @@ public: void (*uninstanceCB)(MatPipeline*, Geometry*, uint32*, Mesh*, uint8**); void (*preUninstCB)(MatPipeline*, Geometry*); void (*postUninstCB)(MatPipeline*, Geometry*); + // RW has more: + // instanceTestCB() + // resEntryAllocCB() + // bridgeCB() + // postMeshCB() + // vu1code + // primtype static uint32 getVertCount(uint32 top, uint32 inAttribs, uint32 outAttribs, uint32 outBufs) { @@ -77,7 +90,7 @@ public: } MatPipeline(uint32 platform); - virtual void dump(void); + void dump(void); void setTriBufferSizes(uint32 inputStride, uint32 stripCount); void instance(Geometry *g, InstanceData *inst, Mesh *m); uint8 *collectData(Geometry *g, InstanceData *inst, Mesh *m, uint8 *data[]); @@ -87,10 +100,13 @@ class ObjPipeline : public rw::ObjPipeline { public: MatPipeline *groupPipeline; + // RW has more: + // setupCB() + // finalizeCB() + // lightOffset + // lightSize ObjPipeline(uint32 platform); - virtual void instance(Atomic *atomic); - virtual void uninstance(Atomic *atomic); }; struct Vertex { @@ -154,17 +170,6 @@ void allocateADC(Geometry *geo); // PDS plugin -// IDs used by SA -// n atomic material -// 1892 53f20080 53f20081 // ? no night colors -// 1 53f20080 53f2008d // triad_buddha01.dff no night colors -// 56430 53f20082 53f20083 // world night colors -// 39 53f20082 53f2008f // reflective world night colors -// 6941 53f20084 53f20085 // vehicles -// 3423 53f20084 53f20087 // vehicles -// 4640 53f20084 53f2008b // vehicles -// 418 53f20088 53f20089 // peds - Pipeline *getPDSPipe(uint32 data); void registerPDSPipe(Pipeline *pipe); void registerPDSPlugin(int32 n); diff --git a/src/rwxbox.h b/src/rwxbox.h index d0b1774..651c50c 100644 --- a/src/rwxbox.h +++ b/src/rwxbox.h @@ -40,8 +40,6 @@ public: void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); ObjPipeline(uint32 platform); - virtual void instance(Atomic *atomic); - virtual void uninstance(Atomic *atomic); }; ObjPipeline *makeDefaultPipeline(void); diff --git a/src/xbox.cpp b/src/xbox.cpp index 8d6e448..f594363 100644 --- a/src/xbox.cpp +++ b/src/xbox.cpp @@ -140,18 +140,15 @@ registerNativeDataPlugin(void) getSizeNativeData); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform), - instanceCB(NULL), uninstanceCB(NULL) { } - -void -ObjPipeline::instance(Atomic *atomic) +static void +instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { enum { D3DPT_TRIANGLELIST = 5, D3DPT_TRIANGLESTRIP = 6, }; + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if(geo->geoflags & Geometry::NATIVE) return; @@ -195,12 +192,13 @@ ObjPipeline::instance(Atomic *atomic) } header->end = inst; - this->instanceCB(geo, header); + pipe->instanceCB(geo, header); } -void -ObjPipeline::uninstance(Atomic *atomic) +static void +uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { + ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; if((geo->geoflags & Geometry::NATIVE) == 0) return; @@ -220,11 +218,21 @@ ObjPipeline::uninstance(Atomic *atomic) inst++; } - this->uninstanceCB(geo, header); + pipe->uninstanceCB(geo, header); geo->generateTriangles(); destroyNativeData(geo, 0, 0); } +ObjPipeline::ObjPipeline(uint32 platform) + : rw::ObjPipeline(platform) +{ + this->impl.instance = xbox::instance; + this->impl.uninstance = xbox::uninstance; + this->instanceCB = NULL; + this->uninstanceCB = NULL; +} + + int v3dFormatMap[] = { -1, VERT_BYTE3, VERT_SHORT3, VERT_NORMSHORT3, VERT_COMPNORM, VERT_FLOAT3 };