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)
: 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)
{

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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

View File

@ -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)
{

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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*);

View File

@ -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);

View File

@ -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);

View File

@ -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
};