improved pipeline system

This commit is contained in:
aap 2015-08-03 18:30:10 +02:00
parent db00759b8c
commit 970786828d
10 changed files with 131 additions and 37 deletions

View File

@ -31,6 +31,7 @@ main(int argc, char *argv[])
rw::registerNativeDataPlugin(); rw::registerNativeDataPlugin();
// rw::ps2::registerNativeDataPlugin(); // rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin(); rw::registerMeshPlugin();
rw::Atomic::init();
rw::Clump *c; rw::Clump *c;

View File

@ -27,16 +27,10 @@ main(int argc, char *argv[])
rw::registerSkinPlugin(); rw::registerSkinPlugin();
rw::registerNativeDataPlugin(); rw::registerNativeDataPlugin();
rw::registerMeshPlugin(); rw::registerMeshPlugin();
rw::Atomic::init();
rw::platform = rw::PLATFORM_PS2; rw::platform = rw::PLATFORM_PS2;
rw::ps2::ObjPipeline *defpipe = rw::ps2::makeDefaultPipeline();
rw::ps2::ObjPipeline *skinpipe = rw::ps2::makeSkinPipeline();
rw::ps2::ObjPipeline *matfxpipe = rw::ps2::makeMatFXPipeline();
// rw::ps2::defaultMatPipe->dump();
// skinpipe->groupPipeline->dump();
// matfxpipe->groupPipeline->dump();
int uninstance = 0; int uninstance = 0;
int arg = 1; int arg = 1;
@ -67,6 +61,13 @@ main(int argc, char *argv[])
// printf("%s\n", argv[arg]); // printf("%s\n", argv[arg]);
// only opengl:
for(int32 i = 0; i < c->numAtomics; i++){
Atomic *a = c->atomicList[i];
gl::printPipeinfo(a);
}
return 0;
for(int32 i = 0; i < c->numAtomics; i++){ for(int32 i = 0; i < c->numAtomics; i++){
Atomic *a = c->atomicList[i]; Atomic *a = c->atomicList[i];
Pipeline *ap = a->pipeline; Pipeline *ap = a->pipeline;
@ -80,22 +81,11 @@ main(int argc, char *argv[])
for(int32 i = 0; i < c->numAtomics; i++){ for(int32 i = 0; i < c->numAtomics; i++){
Atomic *a = c->atomicList[i]; Atomic *a = c->atomicList[i];
if(a->pipeline){ ObjPipeline *p = a->getPipeline();
printf("has pipeline %x %x %x\n",
a->pipeline->pluginID,
a->pipeline->pluginData,
a->pipeline->platform);
if(uninstance) if(uninstance)
a->pipeline->uninstance(a); p->uninstance(a);
else else
a->pipeline->instance(a); p->instance(a);
}else{
printf("default pipeline\n");
if(uninstance)
defpipe->uninstance(a);
else
defpipe->instance(a);
}
} }
data = new rw::uint8[256*1024]; data = new rw::uint8[256*1024];

View File

@ -9,6 +9,8 @@
#include "rwplugin.h" #include "rwplugin.h"
#include "rwpipeline.h" #include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwps2.h"
#include "rwogl.h"
using namespace std; using namespace std;
@ -488,6 +490,28 @@ Atomic::streamGetSize(void)
return 12 + 16 + 12 + this->streamGetPluginSize(); return 12 + 16 + 12 + this->streamGetPluginSize();
} }
ObjPipeline *defaultPipelines[NUM_PLATFORMS];
ObjPipeline*
Atomic::getPipeline(void)
{
return this->pipeline ?
this->pipeline :
defaultPipelines[platformIdx[platform]];
}
void
Atomic::init(void)
{
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
defaultPipelines[i] = defpipe;
defaultPipelines[platformIdx[PLATFORM_PS2]] =
ps2::makeDefaultPipeline();
defaultPipelines[platformIdx[PLATFORM_OGL]] =
gl::makeDefaultPipeline();
}
// Atomic Rights plugin // Atomic Rights plugin
static void static void

View File

@ -31,7 +31,7 @@ namespace gl {
// 457 5 2 0 4 // 457 5 2 0 4
// SA // SA
// 20303 0 0 0 3 vertices: 3 float // 20303 0 0 0 3 vertices: 3 floats
// 53 1 0 0 2 texCoords: 2 floats // 53 1 0 0 2 texCoords: 2 floats
// 20043 1 3 0 2 texCoords: 2 shorts // 20043 1 3 0 2 texCoords: 2 shorts
// 6954 2 1 1 3 normal: 3 bytes normalized // 6954 2 1 1 3 normal: 3 bytes normalized
@ -85,6 +85,22 @@ readNativeData(Stream *stream, int32, void *object, int32, int32)
stream->read(header->data, header->dataSize); stream->read(header->data, header->dataSize);
} }
void
printPipeinfo(Atomic *a)
{
Geometry *g = a->geometry;
if(g->instData == NULL || g->instData->platform != PLATFORM_OGL)
return;
int32 plgid = 0;
if(a->pipeline)
plgid = a->pipeline->pluginID;
printf("%s %x: ", debugFile, plgid);
InstanceDataHeader *h = (InstanceDataHeader*)g->instData;
for(int i = 0; i < h->numAttribs; i++)
printf("%x(%x) ", h->attribs[i].index, h->attribs[i].type);
printf("\n");
}
void void
writeNativeData(Stream *stream, int32, void *object, int32, int32) writeNativeData(Stream *stream, int32, void *object, int32, int32)
{ {
@ -165,11 +181,16 @@ packattrib(uint8 *dst, float32 *src, AttribDesc *a, float32 scale=1.0f)
} }
} }
ObjPipeline::ObjPipeline(uint32 platform)
: rw::ObjPipeline(platform), numCustomAttribs(0), customAttribSize(0) { }
// TODO: make pipeline dependent (skin data, night colors) // TODO: make pipeline dependent (skin data, night colors)
void void
instance(Atomic *atomic) ObjPipeline::instance(Atomic *atomic)
{ {
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(geo->geoflags & Geometry::NATIVE)
return;
InstanceDataHeader *header = new InstanceDataHeader; InstanceDataHeader *header = new InstanceDataHeader;
geo->instData = header; geo->instData = header;
header->platform = PLATFORM_OGL; header->platform = PLATFORM_OGL;
@ -183,6 +204,8 @@ instance(Atomic *atomic)
int32 offset = 0; int32 offset = 0;
header->attribs = new AttribDesc[header->numAttribs]; header->attribs = new AttribDesc[header->numAttribs];
printf("...instancing\n");
AttribDesc *a = header->attribs; AttribDesc *a = header->attribs;
// Vertices // Vertices
a->index = 0; a->index = 0;
@ -225,20 +248,17 @@ instance(Atomic *atomic)
} }
// TODO: skin, extra colors; what to do with multiple coords? // TODO: skin, extra colors; what to do with multiple coords?
a = header->attribs;
for(int32 i = 0; i < header->numAttribs; i++)
a[i].stride = offset;
header->dataSize = offset*geo->numVertices; header->dataSize = offset*geo->numVertices;
header->data = new uint8[header->dataSize]; header->data = new uint8[header->dataSize];
memset(header->data, 0xFF, header->dataSize); // memset(header->data, 0xFF, header->dataSize);
a = header->attribs;
uint8 *p = header->data + a->offset; uint8 *p = header->data + a->offset;
float32 *vert = geo->morphTargets->vertices; float32 *vert = geo->morphTargets->vertices;
for(int32 i = 0; i < geo->numVertices; i++){ for(int32 i = 0; i < geo->numVertices; i++){
packattrib(p, vert, a); packattrib(p, vert, a);
vert += 3; vert += 3;
p += a->stride; p += offset;
} }
a++; a++;
@ -248,7 +268,7 @@ instance(Atomic *atomic)
for(int32 i = 0; i < geo->numVertices; i++){ for(int32 i = 0; i < geo->numVertices; i++){
packattrib(p, texcoord, a, 512.0f); packattrib(p, texcoord, a, 512.0f);
texcoord += 2; texcoord += 2;
p += a->stride; p += offset;
} }
a++; a++;
} }
@ -259,7 +279,7 @@ instance(Atomic *atomic)
for(int32 i = 0; i < geo->numVertices; i++){ for(int32 i = 0; i < geo->numVertices; i++){
packattrib(p, norm, a); packattrib(p, norm, a);
norm += 3; norm += 3;
p += a->stride; p += offset;
} }
a++; a++;
} }
@ -275,13 +295,43 @@ instance(Atomic *atomic)
f[3] = color[3]/255.0f; f[3] = color[3]/255.0f;
packattrib(p, f, a); packattrib(p, f, a);
color += 4; color += 4;
p += a->stride; p += offset;
} }
a++; a++;
} }
a = header->attribs;
for(int32 i = 0; i < header->numAttribs; i++)
a[i].stride = offset;
geo->geoflags |= Geometry::NATIVE; geo->geoflags |= Geometry::NATIVE;
} }
ObjPipeline*
makeDefaultPipeline(void)
{
ObjPipeline *pipe = new ObjPipeline(PLATFORM_OGL);
return pipe;
}
ObjPipeline*
makeSkinPipeline(void)
{
ObjPipeline *pipe = new ObjPipeline(PLATFORM_OGL);
pipe->pluginID = ID_SKIN;
pipe->pluginData = 1;
return pipe;
}
ObjPipeline*
makeMatFXPipeline(void)
{
ObjPipeline *pipe = new ObjPipeline(PLATFORM_OGL);
pipe->pluginID = ID_MATFX;
pipe->pluginData = 0;
return pipe;
}
#ifdef RW_OPENGL #ifdef RW_OPENGL
void void
uploadGeo(Geometry *geo) uploadGeo(Geometry *geo)

View File

@ -556,6 +556,8 @@ registerSkinPlugin(void)
skinGlobals.pipelines[i] = defpipe; skinGlobals.pipelines[i] = defpipe;
skinGlobals.pipelines[platformIdx[PLATFORM_PS2]] = skinGlobals.pipelines[platformIdx[PLATFORM_PS2]] =
ps2::makeSkinPipeline(); ps2::makeSkinPipeline();
skinGlobals.pipelines[platformIdx[PLATFORM_OGL]] =
gl::makeSkinPipeline();
skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN, skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
createSkin, createSkin,
@ -888,6 +890,8 @@ registerMatFXPlugin(void)
matFXGlobals.pipelines[i] = defpipe; matFXGlobals.pipelines[i] = defpipe;
matFXGlobals.pipelines[platformIdx[PLATFORM_PS2]] = matFXGlobals.pipelines[platformIdx[PLATFORM_PS2]] =
ps2::makeMatFXPipeline(); ps2::makeMatFXPipeline();
matFXGlobals.pipelines[platformIdx[PLATFORM_OGL]] =
gl::makeMatFXPipeline();
matFXGlobals.atomicOffset = matFXGlobals.atomicOffset =
Atomic::registerPlugin(sizeof(int32), ID_MATFX, Atomic::registerPlugin(sizeof(int32), ID_MATFX,

View File

@ -19,7 +19,7 @@ int build = 0xFFFF;
#ifdef RW_PS2 #ifdef RW_PS2
int platform = PLATFORM_PS2; int platform = PLATFORM_PS2;
#elif RW_OPENGL #elif RW_OPENGL
int platform = PLATFORM_OPENGL; int platform = PLATFORM_OGL;
#else #else
int platform = PLATFORM_NULL; int platform = PLATFORM_NULL;
#endif #endif

View File

@ -361,8 +361,13 @@ struct Atomic : PluginBase<Atomic>, Object
bool streamWriteClump(Stream *stream, bool streamWriteClump(Stream *stream,
Frame **frameList, int32 numFrames); Frame **frameList, int32 numFrames);
uint32 streamGetSize(void); uint32 streamGetSize(void);
ObjPipeline *getPipeline(void);
static void init(void);
}; };
extern ObjPipeline *defaultPipelines[NUM_PLATFORMS];
void registerAtomicRightsPlugin(void); void registerAtomicRightsPlugin(void);
struct Clump : PluginBase<Clump>, Object struct Clump : PluginBase<Clump>, Object

View File

@ -32,6 +32,21 @@ void writeNativeData(Stream *stream, int32 len, void *object, int32, int32);
int32 getSizeNativeData(void *object, int32, int32); int32 getSizeNativeData(void *object, int32, int32);
void instance(Atomic *atomic); void instance(Atomic *atomic);
void printPipeinfo(Atomic *a);
class ObjPipeline : public rw::ObjPipeline
{
public:
uint32 numCustomAttribs;
uint32 customAttribSize;
ObjPipeline(uint32 platform);
virtual void instance(Atomic *atomic);
};
ObjPipeline *makeDefaultPipeline(void);
ObjPipeline *makeSkinPipeline(void);
ObjPipeline *makeMatFXPipeline(void);
// only RW_OPENGL // only RW_OPENGL
void uploadGeo(Geometry *geo); void uploadGeo(Geometry *geo);

View File

@ -21,8 +21,7 @@ renderAtomic(rw::Atomic *atomic)
GL_TRIANGLES, GL_TRIANGLE_STRIP GL_TRIANGLES, GL_TRIANGLE_STRIP
}; };
Geometry *geo = atomic->geometry; Geometry *geo = atomic->geometry;
if(!(geo->geoflags & Geometry::NATIVE)) atomic->getPipeline()->instance(atomic);
gl::instance(atomic);
gl::InstanceDataHeader *inst = (gl::InstanceDataHeader*)geo->instData; gl::InstanceDataHeader *inst = (gl::InstanceDataHeader*)geo->instData;
MeshHeader *meshHeader = geo->meshHeader; MeshHeader *meshHeader = geo->meshHeader;
@ -199,10 +198,14 @@ init(void)
gta::registerBreakableModelPlugin(); gta::registerBreakableModelPlugin();
gta::registerExtraVertColorPlugin(); gta::registerExtraVertColorPlugin();
rw::ps2::registerADCPlugin(); rw::ps2::registerADCPlugin();
rw::ps2::registerPDSPlugin();
rw::registerSkinPlugin(); rw::registerSkinPlugin();
rw::registerNativeDataPlugin(); rw::registerNativeDataPlugin();
// rw::ps2::registerNativeDataPlugin(); // rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin(); rw::registerMeshPlugin();
rw::Atomic::init();
printf("platform: %d\n", rw::platform);
rw::StreamFile in; rw::StreamFile in;
if(in.open(filename, "rb") == NULL) if(in.open(filename, "rb") == NULL)

View File

@ -236,10 +236,12 @@ main()
gta::registerBreakableModelPlugin(); gta::registerBreakableModelPlugin();
gta::registerExtraVertColorPlugin(); gta::registerExtraVertColorPlugin();
rw::ps2::registerADCPlugin(); rw::ps2::registerADCPlugin();
rw::ps2::registerPDSPlugin();
rw::registerSkinPlugin(); rw::registerSkinPlugin();
rw::registerNativeDataPlugin(); rw::registerNativeDataPlugin();
// rw::ps2::registerNativeDataPlugin(); // rw::ps2::registerNativeDataPlugin();
rw::registerMeshPlugin(); rw::registerMeshPlugin();
rw::Atomic::init();
defpipe = rw::ps2::makeDefaultPipeline(); defpipe = rw::ps2::makeDefaultPipeline();