From 8fc446f13b8f8b0b577b388749bcae7ebe2c1339 Mon Sep 17 00:00:00 2001 From: aap Date: Mon, 21 Aug 2017 23:15:31 +0200 Subject: [PATCH] fixed handling of NATIVE flag --- src/clump.cpp | 19 +++++++++++++++++++ src/d3d/d3d8.cpp | 7 ++++--- src/d3d/d3d9.cpp | 7 ++++--- src/d3d/xbox.cpp | 4 ++-- src/geometry.cpp | 4 +++- src/gl/gl3pipe.cpp | 7 ++++--- src/gl/wdgl.cpp | 4 ++-- src/image.cpp | 5 +++-- src/ps2/ps2.cpp | 4 ++-- src/rwobjects.h | 7 +++++++ 10 files changed, 50 insertions(+), 18 deletions(-) diff --git a/src/clump.cpp b/src/clump.cpp index 258d737..7f9fbb7 100644 --- a/src/clump.cpp +++ b/src/clump.cpp @@ -529,6 +529,25 @@ Atomic::getPipeline(void) engine->driver[platform]->defaultPipeline; } +void +Atomic::instance(void) +{ + if(this->geometry->flags & Geometry::NATIVE) + return; + this->getPipeline()->instance(this); + this->geometry->flags |= Geometry::NATIVE; +} + +void +Atomic::uninstance(void) +{ + if(!(this->geometry->flags & Geometry::NATIVE)) + return; + this->getPipeline()->uninstance(this); + // this should be done by the CB already, just make sure + this->geometry->flags &= ~Geometry::NATIVE; +} + void Atomic::defaultRenderCB(Atomic *atomic) { diff --git a/src/d3d/d3d8.cpp b/src/d3d/d3d8.cpp index 454ff90..2404b8a 100644 --- a/src/d3d/d3d8.cpp +++ b/src/d3d/d3d8.cpp @@ -248,9 +248,9 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if(geo->flags & Geometry::NATIVE) + // TODO: allow for REINSTANCE + if(geo->instData) return; - geo->flags |= Geometry::NATIVE; InstanceDataHeader *header = new InstanceDataHeader; MeshHeader *meshh = geo->meshHeader; geo->instData = header; @@ -328,7 +328,8 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if((geo->flags & Geometry::NATIVE) == 0) + // TODO: allow for REINSTANCE + if(geo->instData == nil) pipe->instance(atomic); assert(geo->instData != nil); assert(geo->instData->platform == PLATFORM_D3D8); diff --git a/src/d3d/d3d9.cpp b/src/d3d/d3d9.cpp index a772b0c..9e9f9c4 100644 --- a/src/d3d/d3d9.cpp +++ b/src/d3d/d3d9.cpp @@ -313,9 +313,9 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if(geo->flags & Geometry::NATIVE) + // TODO: allow for REINSTANCE + if(geo->instData) return; - geo->flags |= Geometry::NATIVE; InstanceDataHeader *header = new InstanceDataHeader; MeshHeader *meshh = geo->meshHeader; geo->instData = header; @@ -399,7 +399,8 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if((geo->flags & Geometry::NATIVE) == 0) + // TODO: allow for REINSTANCE + if(geo->instData == nil) pipe->instance(atomic); assert(geo->instData != nil); assert(geo->instData->platform == PLATFORM_D3D9); diff --git a/src/d3d/xbox.cpp b/src/d3d/xbox.cpp index 5adb2c9..8994f43 100644 --- a/src/d3d/xbox.cpp +++ b/src/d3d/xbox.cpp @@ -197,9 +197,9 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic) ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if(geo->flags & Geometry::NATIVE) + // TODO: allow for REINSTANCE (or not, xbox can't render) + if(geo->instData) return; - geo->flags |= Geometry::NATIVE; InstanceDataHeader *header = new InstanceDataHeader; MeshHeader *meshh = geo->meshHeader; geo->instData = header; diff --git a/src/geometry.cpp b/src/geometry.cpp index b8f1791..6ea0567 100644 --- a/src/geometry.cpp +++ b/src/geometry.cpp @@ -19,6 +19,7 @@ PluginList Material::s_plglist = { sizeof(Material), sizeof(Material), nil, nil SurfaceProperties defaultSurfaceProps = { 1.0f, 1.0f, 1.0f }; +// TODO: allocate everything in one chunk Geometry* Geometry::create(int32 numVerts, int32 numTris, uint32 flags) { @@ -321,6 +322,7 @@ Geometry::hasColoredMaterial(void) return 0; } +// TODO: allocate as one chunk void Geometry::allocateData(void) { @@ -475,7 +477,7 @@ Geometry::correctTristripWinding(void) { MeshHeader *header = this->meshHeader; if(header == nil || header->flags != MeshHeader::TRISTRIP || - this->flags & NATIVE) + this->instData) return; MeshHeader *newhead = new MeshHeader; newhead->flags = header->flags; diff --git a/src/gl/gl3pipe.cpp b/src/gl/gl3pipe.cpp index f8dfd02..2eb6130 100644 --- a/src/gl/gl3pipe.cpp +++ b/src/gl/gl3pipe.cpp @@ -27,9 +27,9 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if(geo->flags & Geometry::NATIVE) + // TODO: allow for REINSTANCE + if(geo->instData) return; - geo->flags |= Geometry::NATIVE; InstanceDataHeader *header = new InstanceDataHeader; MeshHeader *meshh = geo->meshHeader; geo->instData = header; @@ -87,7 +87,8 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if((geo->flags & Geometry::NATIVE) == 0) + // TODO: allow for REINSTANCE + if(geo->instData == nil) pipe->instance(atomic); assert(geo->instData != nil); assert(geo->instData->platform == PLATFORM_GL3); diff --git a/src/gl/wdgl.cpp b/src/gl/wdgl.cpp index cd4def3..1981f6d 100644 --- a/src/gl/wdgl.cpp +++ b/src/gl/wdgl.cpp @@ -322,7 +322,8 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if(geo->flags & Geometry::NATIVE) + // TODO: allow for REINSTANCE (or not, wdgl can't render) + if(geo->instData) return; InstanceDataHeader *header = new InstanceDataHeader; geo->instData = header; @@ -441,7 +442,6 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic) } a++; } - geo->flags |= Geometry::NATIVE; } static void diff --git a/src/image.cpp b/src/image.cpp index e32606e..b05bc88 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -85,8 +85,9 @@ TexDictionary::streamRead(Stream *stream) return nil; } int32 numTex = stream->readI16(); - stream->readI16(); // some platform id (1 = d3d8, 2 = d3d9, 5 = opengl, - // 6 = ps2, 8 = xbox) + stream->readI16(); // device id (0 = unknown, 1 = d3d8, 2 = d3d9, + // 3 = gcn, 4 = null, 5 = opengl, + // 6 = ps2, 7 = softras, 8 = xbox, 9 = psp) TexDictionary *txd = TexDictionary::create(); if(txd == nil) return nil; diff --git a/src/ps2/ps2.cpp b/src/ps2/ps2.cpp index 1407532..f83f02d 100755 --- a/src/ps2/ps2.cpp +++ b/src/ps2/ps2.cpp @@ -749,7 +749,8 @@ objInstance(rw::ObjPipeline *rwpipe, Atomic *atomic) { ObjPipeline *pipe = (ObjPipeline*)rwpipe; Geometry *geo = atomic->geometry; - if(geo->flags & Geometry::NATIVE) + // TODO: allow for REINSTANCE + if(geo->instData) return; InstanceDataHeader *header = new InstanceDataHeader; geo->instData = header; @@ -770,7 +771,6 @@ objInstance(rw::ObjPipeline *rwpipe, Atomic *atomic) m->instance(geo, instance, mesh); instance->material = mesh->material; } - geo->flags |= Geometry::NATIVE; } /* diff --git a/src/rwobjects.h b/src/rwobjects.h index afd1846..275e4a6 100755 --- a/src/rwobjects.h +++ b/src/rwobjects.h @@ -403,6 +403,7 @@ struct MaterialList uint32 streamGetSize(void); }; +// TODO: implement locking struct Geometry { PLUGINBASE @@ -451,6 +452,10 @@ struct Geometry LIGHT = 0x20, MODULATE = 0x40, TEXTURED2 = 0x80, + // When this flag is set the geometry has + // native geometry. When streamed out this geometry + // is written out instead of the platform independent data. + // When streamed in with this flag, the geometry is mostly empty. NATIVE = 0x01000000, // Just for documentation: RW sets this flag // to prevent rendering when executing a pipeline, @@ -507,6 +512,8 @@ struct Atomic void setGeometry(Geometry *geo, uint32 flags); Sphere *getWorldBoundingSphere(void); ObjPipeline *getPipeline(void); + void instance(void); + void uninstance(void); void render(void) { this->renderCB(this); } void setRenderCB(RenderCB renderCB){ this->renderCB = renderCB;