changes pipeline system a bit

This commit is contained in:
aap 2016-02-14 00:52:45 +01:00
parent 0e0cc1156c
commit dc4011ba7a
12 changed files with 140 additions and 123 deletions

View File

@ -196,13 +196,10 @@ registerNativeDataPlugin(void)
} }
ObjPipeline::ObjPipeline(uint32 platform) static void
: rw::ObjPipeline(platform), instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
instanceCB(NULL), uninstanceCB(NULL) { }
void
ObjPipeline::instance(Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(geo->geoflags & Geometry::NATIVE) if(geo->geoflags & Geometry::NATIVE)
return; return;
@ -240,15 +237,16 @@ ObjPipeline::instance(Atomic *atomic)
indices[j] = mesh->indices[j] - inst->minVert; indices[j] = mesh->indices[j] - inst->minVert;
unlockIndices(inst->indexBuffer); unlockIndices(inst->indexBuffer);
this->instanceCB(geo, inst); pipe->instanceCB(geo, inst);
mesh++; mesh++;
inst++; inst++;
} }
} }
void static void
ObjPipeline::uninstance(Atomic *atomic) uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if((geo->geoflags & Geometry::NATIVE) == 0) if((geo->geoflags & Geometry::NATIVE) == 0)
return; return;
@ -270,7 +268,7 @@ ObjPipeline::uninstance(Atomic *atomic)
mesh->indices[j] = indices[j] + inst->minVert; mesh->indices[j] = indices[j] + inst->minVert;
unlockIndices(inst->indexBuffer); unlockIndices(inst->indexBuffer);
this->uninstanceCB(geo, inst); pipe->uninstanceCB(geo, inst);
mesh++; mesh++;
inst++; inst++;
} }
@ -278,6 +276,15 @@ ObjPipeline::uninstance(Atomic *atomic)
destroyNativeData(geo, 0, 0); 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 void
defaultInstanceCB(Geometry *geo, InstanceData *inst) defaultInstanceCB(Geometry *geo, InstanceData *inst)
{ {

View File

@ -260,13 +260,10 @@ registerNativeDataPlugin(void)
getSizeNativeData); getSizeNativeData);
} }
ObjPipeline::ObjPipeline(uint32 platform) static void
: rw::ObjPipeline(platform), instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
instanceCB(NULL), uninstanceCB(NULL) { }
void
ObjPipeline::instance(Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(geo->geoflags & Geometry::NATIVE) if(geo->geoflags & Geometry::NATIVE)
return; return;
@ -313,12 +310,13 @@ ObjPipeline::instance(Atomic *atomic)
memset(&header->vertexStream, 0, 2*sizeof(VertexStream)); memset(&header->vertexStream, 0, 2*sizeof(VertexStream));
this->instanceCB(geo, header); pipe->instanceCB(geo, header);
} }
void static void
ObjPipeline::uninstance(Atomic *atomic) uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if((geo->geoflags & Geometry::NATIVE) == 0) if((geo->geoflags & Geometry::NATIVE) == 0)
return; return;
@ -343,11 +341,20 @@ ObjPipeline::uninstance(Atomic *atomic)
} }
unlockIndices(header->indexBuffer); unlockIndices(header->indexBuffer);
this->uninstanceCB(geo, header); pipe->uninstanceCB(geo, header);
geo->generateTriangles(); geo->generateTriangles();
destroyNativeData(geo, 0, 0); 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 void
defaultInstanceCB(Geometry *geo, InstanceDataHeader *header) defaultInstanceCB(Geometry *geo, InstanceDataHeader *header)
{ {

View File

@ -284,13 +284,10 @@ printPipeinfo(Atomic *a)
printf("\n"); printf("\n");
} }
ObjPipeline::ObjPipeline(uint32 platform) static void
: rw::ObjPipeline(platform), numCustomAttribs(0), instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
instanceCB(NULL), uninstanceCB(NULL) { }
void
ObjPipeline::instance(Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(geo->geoflags & Geometry::NATIVE) if(geo->geoflags & Geometry::NATIVE)
return; return;
@ -300,7 +297,7 @@ ObjPipeline::instance(Atomic *atomic)
header->vbo = 0; header->vbo = 0;
header->ibo = 0; header->ibo = 0;
header->numAttribs = header->numAttribs =
this->numCustomAttribs + 1 + (geo->numTexCoordSets > 0); pipe->numCustomAttribs + 1 + (geo->numTexCoordSets > 0);
if(geo->geoflags & Geometry::PRELIT) if(geo->geoflags & Geometry::PRELIT)
header->numAttribs++; header->numAttribs++;
if(geo->geoflags & Geometry::NORMALS) if(geo->geoflags & Geometry::NORMALS)
@ -353,8 +350,8 @@ ObjPipeline::instance(Atomic *atomic)
firstCustom++; firstCustom++;
} }
if(this->instanceCB) if(pipe->instanceCB)
offset += this->instanceCB(geo, firstCustom, offset); offset += pipe->instanceCB(geo, firstCustom, offset);
else{ else{
header->dataSize = offset*geo->numVertices; header->dataSize = offset*geo->numVertices;
header->data = new uint8[header->dataSize]; header->data = new uint8[header->dataSize];
@ -414,9 +411,10 @@ ObjPipeline::instance(Atomic *atomic)
geo->geoflags |= Geometry::NATIVE; geo->geoflags |= Geometry::NATIVE;
} }
void static void
ObjPipeline::uninstance(Atomic *atomic) uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if((geo->geoflags & Geometry::NATIVE) == 0) if((geo->geoflags & Geometry::NATIVE) == 0)
return; return;
@ -477,14 +475,24 @@ ObjPipeline::uninstance(Atomic *atomic)
} }
} }
if(this->uninstanceCB) if(pipe->uninstanceCB)
uninstanceCB(geo); pipe->uninstanceCB(geo);
geo->generateTriangles(); geo->generateTriangles();
destroyNativeData(geo, 0, 0); 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* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {

View File

@ -18,6 +18,8 @@ namespace rw {
void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*); void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*);
static void nothing(ObjPipeline *, Atomic*) {}
Pipeline::Pipeline(uint32 platform) Pipeline::Pipeline(uint32 platform)
{ {
this->pluginID = 0; this->pluginID = 0;
@ -25,38 +27,20 @@ Pipeline::Pipeline(uint32 platform)
this->platform = 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
{ //ObjPipeline::render(Atomic *atomic)
} //{
// if(defaultRenderCBs[rw::platform])
void // defaultRenderCBs[rw::platform](atomic);
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);
}
// helper functions // helper functions

View File

@ -611,12 +611,10 @@ MatPipeline::collectData(Geometry *g, InstanceData *inst, Mesh *m, uint8 *data[]
return raw; return raw;
} }
ObjPipeline::ObjPipeline(uint32 platform) static void
: rw::ObjPipeline(platform), groupPipeline(NULL) { } objInstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
void
ObjPipeline::instance(Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(geo->geoflags & Geometry::NATIVE) if(geo->geoflags & Geometry::NATIVE)
return; return;
@ -631,8 +629,8 @@ ObjPipeline::instance(Atomic *atomic)
InstanceData *instance = &header->instanceMeshes[i]; InstanceData *instance = &header->instanceMeshes[i];
MatPipeline *m; MatPipeline *m;
m = this->groupPipeline ? m = pipe->groupPipeline ?
this->groupPipeline : pipe->groupPipeline :
(MatPipeline*)mesh->material->pipeline; (MatPipeline*)mesh->material->pipeline;
if(m == NULL) if(m == NULL)
m = defaultMatPipe; m = defaultMatPipe;
@ -642,7 +640,7 @@ ObjPipeline::instance(Atomic *atomic)
geo->geoflags |= Geometry::NATIVE; geo->geoflags |= Geometry::NATIVE;
} }
void static void
printVertCounts(InstanceData *inst, int flag) printVertCounts(InstanceData *inst, int flag)
{ {
uint32 *d = (uint32*)inst->data; uint32 *d = (uint32*)inst->data;
@ -671,9 +669,10 @@ printVertCounts(InstanceData *inst, int flag)
} }
} }
void static void
ObjPipeline::uninstance(Atomic *atomic) objUninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if((geo->geoflags & Geometry::NATIVE) == 0) if((geo->geoflags & Geometry::NATIVE) == 0)
return; return;
@ -691,8 +690,8 @@ ObjPipeline::uninstance(Atomic *atomic)
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
Mesh *mesh = &geo->meshHeader->mesh[i]; Mesh *mesh = &geo->meshHeader->mesh[i];
MatPipeline *m; MatPipeline *m;
m = this->groupPipeline ? m = pipe->groupPipeline ?
this->groupPipeline : pipe->groupPipeline :
(MatPipeline*)mesh->material->pipeline; (MatPipeline*)mesh->material->pipeline;
if(m == NULL) m = defaultMatPipe; if(m == NULL) m = defaultMatPipe;
if(m->preUninstCB) m->preUninstCB(m, geo); if(m->preUninstCB) m->preUninstCB(m, geo);
@ -702,8 +701,8 @@ ObjPipeline::uninstance(Atomic *atomic)
Mesh *mesh = &geo->meshHeader->mesh[i]; Mesh *mesh = &geo->meshHeader->mesh[i];
InstanceData *instance = &header->instanceMeshes[i]; InstanceData *instance = &header->instanceMeshes[i];
MatPipeline *m; MatPipeline *m;
m = this->groupPipeline ? m = pipe->groupPipeline ?
this->groupPipeline : pipe->groupPipeline :
(MatPipeline*)mesh->material->pipeline; (MatPipeline*)mesh->material->pipeline;
if(m == NULL) m = defaultMatPipe; if(m == NULL) m = defaultMatPipe;
@ -716,8 +715,8 @@ ObjPipeline::uninstance(Atomic *atomic)
for(uint32 i = 0; i < header->numMeshes; i++){ for(uint32 i = 0; i < header->numMeshes; i++){
Mesh *mesh = &geo->meshHeader->mesh[i]; Mesh *mesh = &geo->meshHeader->mesh[i];
MatPipeline *m; MatPipeline *m;
m = this->groupPipeline ? m = pipe->groupPipeline ?
this->groupPipeline : pipe->groupPipeline :
(MatPipeline*)mesh->material->pipeline; (MatPipeline*)mesh->material->pipeline;
if(m == NULL) m = defaultMatPipe; if(m == NULL) m = defaultMatPipe;
if(m->postUninstCB) m->postUninstCB(m, geo); 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 int32
findVertex(Geometry *g, uint32 flags[], uint32 mask, Vertex *v) findVertex(Geometry *g, uint32 flags[], uint32 mask, Vertex *v)
{ {

View File

@ -42,8 +42,6 @@ public:
void (*uninstanceCB)(Geometry *geo, InstanceData *header); void (*uninstanceCB)(Geometry *geo, InstanceData *header);
ObjPipeline(uint32 platform); ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic);
virtual void uninstance(Atomic *atomic);
}; };
ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeDefaultPipeline(void);

View File

@ -65,8 +65,6 @@ public:
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
ObjPipeline(uint32 platform); ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic);
virtual void uninstance(Atomic *atomic);
}; };
ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeDefaultPipeline(void);

View File

@ -51,8 +51,6 @@ public:
void (*uninstanceCB)(Geometry *g); void (*uninstanceCB)(Geometry *g);
ObjPipeline(uint32 platform); ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic);
virtual void uninstance(Atomic *atomic);
}; };
ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeDefaultPipeline(void);

View File

@ -1,11 +1,5 @@
namespace rw { namespace rw {
struct PipeAttribute
{
const char *name;
uint32 attrib;
};
struct Atomic; struct Atomic;
class Pipeline class Pipeline
@ -16,18 +10,23 @@ public:
int32 platform; int32 platform;
Pipeline(uint32 platform); Pipeline(uint32 platform);
Pipeline(Pipeline *p);
~Pipeline(void);
virtual void dump(void);
}; };
class ObjPipeline : public Pipeline class ObjPipeline : public Pipeline
{ {
public: public:
ObjPipeline(uint32 platform) : Pipeline(platform) {} ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic); // TODO?: make these callbacks instead of virtual // not the most beautiful way of doing things but still
virtual void uninstance(Atomic *atomic); // TODO?: make these callbacks instead of virtual // better than virtual methods (i hope?).
virtual void render(Atomic *atomic); // TODO?: make these callbacks instead of virtual 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*); extern void (*defaultRenderCBs[rw::NUM_PLATFORMS])(Atomic*);

View File

@ -59,6 +59,12 @@ void fixDmaOffsets(InstanceData *inst);
void unfixDmaOffsets(InstanceData *inst); void unfixDmaOffsets(InstanceData *inst);
// //
struct PipeAttribute
{
const char *name;
uint32 attrib;
};
class MatPipeline : public rw::Pipeline class MatPipeline : public rw::Pipeline
{ {
public: public:
@ -70,6 +76,13 @@ public:
void (*uninstanceCB)(MatPipeline*, Geometry*, uint32*, Mesh*, uint8**); void (*uninstanceCB)(MatPipeline*, Geometry*, uint32*, Mesh*, uint8**);
void (*preUninstCB)(MatPipeline*, Geometry*); void (*preUninstCB)(MatPipeline*, Geometry*);
void (*postUninstCB)(MatPipeline*, Geometry*); void (*postUninstCB)(MatPipeline*, Geometry*);
// RW has more:
// instanceTestCB()
// resEntryAllocCB()
// bridgeCB()
// postMeshCB()
// vu1code
// primtype
static uint32 getVertCount(uint32 top, uint32 inAttribs, static uint32 getVertCount(uint32 top, uint32 inAttribs,
uint32 outAttribs, uint32 outBufs) { uint32 outAttribs, uint32 outBufs) {
@ -77,7 +90,7 @@ public:
} }
MatPipeline(uint32 platform); MatPipeline(uint32 platform);
virtual void dump(void); void dump(void);
void setTriBufferSizes(uint32 inputStride, uint32 stripCount); void setTriBufferSizes(uint32 inputStride, uint32 stripCount);
void instance(Geometry *g, InstanceData *inst, Mesh *m); void instance(Geometry *g, InstanceData *inst, Mesh *m);
uint8 *collectData(Geometry *g, InstanceData *inst, Mesh *m, uint8 *data[]); uint8 *collectData(Geometry *g, InstanceData *inst, Mesh *m, uint8 *data[]);
@ -87,10 +100,13 @@ class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
MatPipeline *groupPipeline; MatPipeline *groupPipeline;
// RW has more:
// setupCB()
// finalizeCB()
// lightOffset
// lightSize
ObjPipeline(uint32 platform); ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic);
virtual void uninstance(Atomic *atomic);
}; };
struct Vertex { struct Vertex {
@ -154,17 +170,6 @@ void allocateADC(Geometry *geo);
// PDS plugin // 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); Pipeline *getPDSPipe(uint32 data);
void registerPDSPipe(Pipeline *pipe); void registerPDSPipe(Pipeline *pipe);
void registerPDSPlugin(int32 n); void registerPDSPlugin(int32 n);

View File

@ -40,8 +40,6 @@ public:
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
ObjPipeline(uint32 platform); ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic);
virtual void uninstance(Atomic *atomic);
}; };
ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeDefaultPipeline(void);

View File

@ -140,18 +140,15 @@ registerNativeDataPlugin(void)
getSizeNativeData); getSizeNativeData);
} }
ObjPipeline::ObjPipeline(uint32 platform) static void
: rw::ObjPipeline(platform), instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
instanceCB(NULL), uninstanceCB(NULL) { }
void
ObjPipeline::instance(Atomic *atomic)
{ {
enum { enum {
D3DPT_TRIANGLELIST = 5, D3DPT_TRIANGLELIST = 5,
D3DPT_TRIANGLESTRIP = 6, D3DPT_TRIANGLESTRIP = 6,
}; };
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(geo->geoflags & Geometry::NATIVE) if(geo->geoflags & Geometry::NATIVE)
return; return;
@ -195,12 +192,13 @@ ObjPipeline::instance(Atomic *atomic)
} }
header->end = inst; header->end = inst;
this->instanceCB(geo, header); pipe->instanceCB(geo, header);
} }
void static void
ObjPipeline::uninstance(Atomic *atomic) uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
{ {
ObjPipeline *pipe = (ObjPipeline*)rwpipe;
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if((geo->geoflags & Geometry::NATIVE) == 0) if((geo->geoflags & Geometry::NATIVE) == 0)
return; return;
@ -220,11 +218,21 @@ ObjPipeline::uninstance(Atomic *atomic)
inst++; inst++;
} }
this->uninstanceCB(geo, header); pipe->uninstanceCB(geo, header);
geo->generateTriangles(); geo->generateTriangles();
destroyNativeData(geo, 0, 0); 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[] = { int v3dFormatMap[] = {
-1, VERT_BYTE3, VERT_SHORT3, VERT_NORMSHORT3, VERT_COMPNORM, VERT_FLOAT3 -1, VERT_BYTE3, VERT_SHORT3, VERT_NORMSHORT3, VERT_COMPNORM, VERT_FLOAT3
}; };