diff --git a/dffwrite.cpp b/dffwrite.cpp index e86f2a9..c11ed0e 100644 --- a/dffwrite.cpp +++ b/dffwrite.cpp @@ -31,6 +31,7 @@ main(int argc, char *argv[]) rw::registerNativeDataPlugin(); // rw::ps2::registerNativeDataPlugin(); rw::registerMeshPlugin(); + rw::Atomic::init(); rw::Clump *c; diff --git a/insttest.cpp b/insttest.cpp index 4400017..fccbd74 100644 --- a/insttest.cpp +++ b/insttest.cpp @@ -27,16 +27,10 @@ main(int argc, char *argv[]) rw::registerSkinPlugin(); rw::registerNativeDataPlugin(); rw::registerMeshPlugin(); + rw::Atomic::init(); 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 arg = 1; @@ -67,6 +61,13 @@ main(int argc, char *argv[]) // 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++){ Atomic *a = c->atomicList[i]; Pipeline *ap = a->pipeline; @@ -80,22 +81,11 @@ main(int argc, char *argv[]) for(int32 i = 0; i < c->numAtomics; i++){ Atomic *a = c->atomicList[i]; - if(a->pipeline){ - printf("has pipeline %x %x %x\n", - a->pipeline->pluginID, - a->pipeline->pluginData, - a->pipeline->platform); - if(uninstance) - a->pipeline->uninstance(a); - else - a->pipeline->instance(a); - }else{ - printf("default pipeline\n"); - if(uninstance) - defpipe->uninstance(a); - else - defpipe->instance(a); - } + ObjPipeline *p = a->getPipeline(); + if(uninstance) + p->uninstance(a); + else + p->instance(a); } data = new rw::uint8[256*1024]; diff --git a/src/clump.cpp b/src/clump.cpp index 621d36c..c8d27ba 100644 --- a/src/clump.cpp +++ b/src/clump.cpp @@ -9,6 +9,8 @@ #include "rwplugin.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwps2.h" +#include "rwogl.h" using namespace std; @@ -488,6 +490,28 @@ Atomic::streamGetSize(void) 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 static void diff --git a/src/ogl.cpp b/src/ogl.cpp index 8103445..d5c01c5 100644 --- a/src/ogl.cpp +++ b/src/ogl.cpp @@ -31,7 +31,7 @@ namespace gl { // 457 5 2 0 4 // 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 // 20043 1 3 0 2 texCoords: 2 shorts // 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); } +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 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) void -instance(Atomic *atomic) +ObjPipeline::instance(Atomic *atomic) { Geometry *geo = atomic->geometry; + if(geo->geoflags & Geometry::NATIVE) + return; InstanceDataHeader *header = new InstanceDataHeader; geo->instData = header; header->platform = PLATFORM_OGL; @@ -183,6 +204,8 @@ instance(Atomic *atomic) int32 offset = 0; header->attribs = new AttribDesc[header->numAttribs]; + printf("...instancing\n"); + AttribDesc *a = header->attribs; // Vertices a->index = 0; @@ -225,20 +248,17 @@ instance(Atomic *atomic) } // 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->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; float32 *vert = geo->morphTargets->vertices; for(int32 i = 0; i < geo->numVertices; i++){ packattrib(p, vert, a); vert += 3; - p += a->stride; + p += offset; } a++; @@ -248,7 +268,7 @@ instance(Atomic *atomic) for(int32 i = 0; i < geo->numVertices; i++){ packattrib(p, texcoord, a, 512.0f); texcoord += 2; - p += a->stride; + p += offset; } a++; } @@ -259,7 +279,7 @@ instance(Atomic *atomic) for(int32 i = 0; i < geo->numVertices; i++){ packattrib(p, norm, a); norm += 3; - p += a->stride; + p += offset; } a++; } @@ -275,13 +295,43 @@ instance(Atomic *atomic) f[3] = color[3]/255.0f; packattrib(p, f, a); color += 4; - p += a->stride; + p += offset; } a++; } + + a = header->attribs; + for(int32 i = 0; i < header->numAttribs; i++) + a[i].stride = offset; + 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 void uploadGeo(Geometry *geo) diff --git a/src/plugins.cpp b/src/plugins.cpp index ac89125..4abca04 100644 --- a/src/plugins.cpp +++ b/src/plugins.cpp @@ -556,6 +556,8 @@ registerSkinPlugin(void) skinGlobals.pipelines[i] = defpipe; skinGlobals.pipelines[platformIdx[PLATFORM_PS2]] = ps2::makeSkinPipeline(); + skinGlobals.pipelines[platformIdx[PLATFORM_OGL]] = + gl::makeSkinPipeline(); skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN, createSkin, @@ -888,6 +890,8 @@ registerMatFXPlugin(void) matFXGlobals.pipelines[i] = defpipe; matFXGlobals.pipelines[platformIdx[PLATFORM_PS2]] = ps2::makeMatFXPipeline(); + matFXGlobals.pipelines[platformIdx[PLATFORM_OGL]] = + gl::makeMatFXPipeline(); matFXGlobals.atomicOffset = Atomic::registerPlugin(sizeof(int32), ID_MATFX, diff --git a/src/rwbase.cpp b/src/rwbase.cpp index a99bece..ace5979 100644 --- a/src/rwbase.cpp +++ b/src/rwbase.cpp @@ -19,7 +19,7 @@ int build = 0xFFFF; #ifdef RW_PS2 int platform = PLATFORM_PS2; #elif RW_OPENGL - int platform = PLATFORM_OPENGL; + int platform = PLATFORM_OGL; #else int platform = PLATFORM_NULL; #endif diff --git a/src/rwobjects.h b/src/rwobjects.h index 889b6b4..63ac3ca 100644 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -361,8 +361,13 @@ struct Atomic : PluginBase, Object bool streamWriteClump(Stream *stream, Frame **frameList, int32 numFrames); uint32 streamGetSize(void); + ObjPipeline *getPipeline(void); + + static void init(void); }; +extern ObjPipeline *defaultPipelines[NUM_PLATFORMS]; + void registerAtomicRightsPlugin(void); struct Clump : PluginBase, Object diff --git a/src/rwogl.h b/src/rwogl.h index 3f336c8..b97a3d5 100644 --- a/src/rwogl.h +++ b/src/rwogl.h @@ -32,6 +32,21 @@ void writeNativeData(Stream *stream, int32 len, void *object, int32, int32); int32 getSizeNativeData(void *object, int32, int32); 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 void uploadGeo(Geometry *geo); diff --git a/tests/gl/main.cpp b/tests/gl/main.cpp index 98a575a..5754989 100755 --- a/tests/gl/main.cpp +++ b/tests/gl/main.cpp @@ -21,8 +21,7 @@ renderAtomic(rw::Atomic *atomic) GL_TRIANGLES, GL_TRIANGLE_STRIP }; Geometry *geo = atomic->geometry; - if(!(geo->geoflags & Geometry::NATIVE)) - gl::instance(atomic); + atomic->getPipeline()->instance(atomic); gl::InstanceDataHeader *inst = (gl::InstanceDataHeader*)geo->instData; MeshHeader *meshHeader = geo->meshHeader; @@ -199,10 +198,14 @@ init(void) gta::registerBreakableModelPlugin(); gta::registerExtraVertColorPlugin(); rw::ps2::registerADCPlugin(); + rw::ps2::registerPDSPlugin(); rw::registerSkinPlugin(); rw::registerNativeDataPlugin(); // rw::ps2::registerNativeDataPlugin(); rw::registerMeshPlugin(); + rw::Atomic::init(); + + printf("platform: %d\n", rw::platform); rw::StreamFile in; if(in.open(filename, "rb") == NULL) diff --git a/tests/ps2/main.cpp b/tests/ps2/main.cpp index 524a9d3..b97304d 100755 --- a/tests/ps2/main.cpp +++ b/tests/ps2/main.cpp @@ -236,10 +236,12 @@ main() gta::registerBreakableModelPlugin(); gta::registerExtraVertColorPlugin(); rw::ps2::registerADCPlugin(); + rw::ps2::registerPDSPlugin(); rw::registerSkinPlugin(); rw::registerNativeDataPlugin(); // rw::ps2::registerNativeDataPlugin(); rw::registerMeshPlugin(); + rw::Atomic::init(); defpipe = rw::ps2::makeDefaultPipeline();