mirror of https://github.com/aap/librw.git
improved pipeline system
This commit is contained in:
parent
db00759b8c
commit
970786828d
|
@ -31,6 +31,7 @@ main(int argc, char *argv[])
|
|||
rw::registerNativeDataPlugin();
|
||||
// rw::ps2::registerNativeDataPlugin();
|
||||
rw::registerMeshPlugin();
|
||||
rw::Atomic::init();
|
||||
|
||||
rw::Clump *c;
|
||||
|
||||
|
|
32
insttest.cpp
32
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);
|
||||
ObjPipeline *p = a->getPipeline();
|
||||
if(uninstance)
|
||||
a->pipeline->uninstance(a);
|
||||
p->uninstance(a);
|
||||
else
|
||||
a->pipeline->instance(a);
|
||||
}else{
|
||||
printf("default pipeline\n");
|
||||
if(uninstance)
|
||||
defpipe->uninstance(a);
|
||||
else
|
||||
defpipe->instance(a);
|
||||
}
|
||||
p->instance(a);
|
||||
}
|
||||
|
||||
data = new rw::uint8[256*1024];
|
||||
|
|
|
@ -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
|
||||
|
|
72
src/ogl.cpp
72
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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -361,8 +361,13 @@ struct Atomic : PluginBase<Atomic>, 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<Clump>, Object
|
||||
|
|
15
src/rwogl.h
15
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);
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in New Issue