changed pipe new to explicit create

This commit is contained in:
aap 2020-08-14 13:54:44 +02:00
parent 5e299fb12e
commit 2568e77fac
30 changed files with 294 additions and 149 deletions

View File

@ -344,9 +344,10 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic)
pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData);
} }
ObjPipeline::ObjPipeline(uint32 platform) void
: rw::ObjPipeline(platform) ObjPipeline::init(void)
{ {
this->rw::ObjPipeline::init(PLATFORM_D3D8);
this->impl.instance = d3d8::instance; this->impl.instance = d3d8::instance;
this->impl.uninstance = d3d8::uninstance; this->impl.uninstance = d3d8::uninstance;
this->impl.render = d3d8::render; this->impl.render = d3d8::render;
@ -355,6 +356,14 @@ ObjPipeline::ObjPipeline(uint32 platform)
this->renderCB = nil; this->renderCB = nil;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
void void
defaultInstanceCB(Geometry *geo, InstanceData *inst) defaultInstanceCB(Geometry *geo, InstanceData *inst)
{ {
@ -428,7 +437,7 @@ defaultUninstanceCB(Geometry *geo, InstanceData *inst)
ObjPipeline* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D8); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = defaultRenderCB; pipe->renderCB = defaultRenderCB;

View File

@ -28,6 +28,8 @@ matfxOpen(void *o, int32, int32)
static void* static void*
matfxClose(void *o, int32, int32) matfxClose(void *o, int32, int32)
{ {
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_D3D8])->destroy();
matFXGlobals.pipelines[PLATFORM_D3D8] = nil;
return o; return o;
} }
@ -41,7 +43,7 @@ initMatFX(void)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D8); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = defaultRenderCB; pipe->renderCB = defaultRenderCB;

View File

@ -28,6 +28,8 @@ skinOpen(void *o, int32, int32)
static void* static void*
skinClose(void *o, int32, int32) skinClose(void *o, int32, int32)
{ {
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_D3D8])->destroy();
skinGlobals.pipelines[PLATFORM_D3D8] = nil;
return o; return o;
} }
@ -41,7 +43,7 @@ initSkin(void)
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D8); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = defaultRenderCB; pipe->renderCB = defaultRenderCB;

View File

@ -464,9 +464,10 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic)
pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData);
} }
ObjPipeline::ObjPipeline(uint32 platform) void
: rw::ObjPipeline(platform) ObjPipeline::init(void)
{ {
this->rw::ObjPipeline::init(PLATFORM_D3D9);
this->impl.instance = d3d9::instance; this->impl.instance = d3d9::instance;
this->impl.uninstance = d3d9::uninstance; this->impl.uninstance = d3d9::uninstance;
this->impl.render = d3d9::render; this->impl.render = d3d9::render;
@ -475,6 +476,14 @@ ObjPipeline::ObjPipeline(uint32 platform)
this->renderCB = nil; this->renderCB = nil;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
void void
defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance) defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
{ {
@ -682,7 +691,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header)
ObjPipeline* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = defaultRenderCB_Shader; pipe->renderCB = defaultRenderCB_Shader;

View File

@ -274,6 +274,8 @@ matfxClose(void *o, int32, int32)
destroyMatFXShaders(); destroyMatFXShaders();
#endif #endif
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_D3D9])->destroy();
matFXGlobals.pipelines[PLATFORM_D3D9] = nil;
return o; return o;
} }
@ -287,7 +289,7 @@ initMatFX(void)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = matfxRenderCB_Shader; pipe->renderCB = matfxRenderCB_Shader;

View File

@ -366,6 +366,8 @@ skinClose(void *o, int32, int32)
destroySkinShaders(); destroySkinShaders();
#endif #endif
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_D3D9])->destroy();
skinGlobals.pipelines[PLATFORM_D3D9] = nil;
return o; return o;
} }
@ -379,7 +381,7 @@ initSkin(void)
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = skinInstanceCB; pipe->instanceCB = skinInstanceCB;
pipe->uninstanceCB = nil; pipe->uninstanceCB = nil;
pipe->renderCB = skinRenderCB; pipe->renderCB = skinRenderCB;

View File

@ -40,11 +40,12 @@ void registerNativeDataPlugin(void);
class ObjPipeline : public rw::ObjPipeline class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
void init(void);
static ObjPipeline *create(void);
void (*instanceCB)(Geometry *geo, InstanceData *header); void (*instanceCB)(Geometry *geo, InstanceData *header);
void (*uninstanceCB)(Geometry *geo, InstanceData *header); void (*uninstanceCB)(Geometry *geo, InstanceData *header);
void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); void (*renderCB)(Atomic *atomic, InstanceDataHeader *header);
ObjPipeline(uint32 platform);
}; };
void defaultInstanceCB(Geometry *geo, InstanceData *header); void defaultInstanceCB(Geometry *geo, InstanceData *header);

View File

@ -73,11 +73,12 @@ void registerNativeDataPlugin(void);
class ObjPipeline : public rw::ObjPipeline class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
void init(void);
static ObjPipeline *create(void);
void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); void (*renderCB)(Atomic *atomic, InstanceDataHeader *header);
ObjPipeline(uint32 platform);
}; };
void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);

View File

@ -41,10 +41,11 @@ void registerNativeDataPlugin(void);
class ObjPipeline : public rw::ObjPipeline class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
void init(void);
static ObjPipeline *create(void);
void (*instanceCB)(Geometry *geo, InstanceDataHeader *header); void (*instanceCB)(Geometry *geo, InstanceDataHeader *header);
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
ObjPipeline(uint32 platform);
}; };
ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeDefaultPipeline(void);

View File

@ -286,15 +286,23 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
destroyNativeData(geo, 0, 0); destroyNativeData(geo, 0, 0);
} }
ObjPipeline::ObjPipeline(uint32 platform) void
: rw::ObjPipeline(platform) ObjPipeline::init(void)
{ {
this->rw::ObjPipeline::init(PLATFORM_XBOX);
this->impl.instance = xbox::instance; this->impl.instance = xbox::instance;
this->impl.uninstance = xbox::uninstance; this->impl.uninstance = xbox::uninstance;
this->instanceCB = nil; this->instanceCB = nil;
this->uninstanceCB = nil; this->uninstanceCB = nil;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
int v3dFormatMap[] = { int v3dFormatMap[] = {
-1, VERT_BYTE3, VERT_SHORT3, VERT_NORMSHORT3, VERT_COMPNORM, VERT_FLOAT3 -1, VERT_BYTE3, VERT_SHORT3, VERT_NORMSHORT3, VERT_COMPNORM, VERT_FLOAT3
@ -385,7 +393,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header)
ObjPipeline* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_XBOX); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
return pipe; return pipe;

View File

@ -26,6 +26,8 @@ matfxOpen(void *o, int32, int32)
static void* static void*
matfxClose(void *o, int32, int32) matfxClose(void *o, int32, int32)
{ {
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_XBOX])->destroy();
matFXGlobals.pipelines[PLATFORM_XBOX] = nil;
return o; return o;
} }
@ -39,7 +41,7 @@ initMatFX(void)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_XBOX); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->pluginID = ID_MATFX; pipe->pluginID = ID_MATFX;

View File

@ -225,6 +225,8 @@ skinOpen(void *o, int32, int32)
static void* static void*
skinClose(void *o, int32, int32) skinClose(void *o, int32, int32)
{ {
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_XBOX])->destroy();
skinGlobals.pipelines[PLATFORM_XBOX] = nil;
return o; return o;
} }
@ -238,7 +240,7 @@ initSkin(void)
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_XBOX); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = skinInstanceCB; pipe->instanceCB = skinInstanceCB;
pipe->uninstanceCB = skinUninstanceCB; pipe->uninstanceCB = skinUninstanceCB;
pipe->pluginID = ID_SKIN; pipe->pluginID = ID_SKIN;

View File

@ -240,12 +240,12 @@ Engine::open(EngineOpenParams *p)
engine->device.system(DEVICEOPEN, (void*)p, 0); engine->device.system(DEVICEOPEN, (void*)p, 0);
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); engine->dummyDefaultPipeline = ObjPipeline::create();
for(uint i = 0; i < NUM_PLATFORMS; i++){ for(uint i = 0; i < NUM_PLATFORMS; i++){
rw::engine->driver[i] = (Driver*)rwNew(Driver::s_plglist[i].size, rw::engine->driver[i] = (Driver*)rwNew(Driver::s_plglist[i].size,
MEMDUR_GLOBAL); MEMDUR_GLOBAL);
engine->driver[i]->defaultPipeline = defpipe; engine->driver[i]->defaultPipeline = engine->dummyDefaultPipeline;
engine->driver[i]->rasterCreate = null::rasterCreate; engine->driver[i]->rasterCreate = null::rasterCreate;
engine->driver[i]->rasterLock = null::rasterLock; engine->driver[i]->rasterLock = null::rasterLock;
@ -324,6 +324,7 @@ Engine::close(void)
engine->device.system(DEVICECLOSE, nil, 0); engine->device.system(DEVICECLOSE, nil, 0);
for(uint i = 0; i < NUM_PLATFORMS; i++) for(uint i = 0; i < NUM_PLATFORMS; i++)
rwFree(rw::engine->driver[i]); rwFree(rw::engine->driver[i]);
engine->dummyDefaultPipeline->destroy();
rwFree(engine); rwFree(engine);
engine = nil; engine = nil;
Engine::state = Initialized; Engine::state = Initialized;

View File

@ -33,41 +33,6 @@ static int32 u_texMatrix;
static int32 u_fxparams; static int32 u_fxparams;
static int32 u_colorClamp; static int32 u_colorClamp;
static void*
matfxOpen(void *o, int32, int32)
{
u_texMatrix = registerUniform("u_texMatrix");
u_fxparams = registerUniform("u_fxparams");
u_colorClamp = registerUniform("u_colorClamp");
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
#ifdef RW_GLES2
#include "gl2_shaders/matfx_gl2.inc"
#else
#include "shaders/matfx_gl3.inc"
#endif
const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
const char *fs[] = { shaderDecl, header_frag_src, matfx_env_frag_src, nil };
envShader = Shader::create(vs, fs);
assert(envShader);
return o;
}
static void*
matfxClose(void *o, int32, int32)
{
return o;
}
void
initMatFX(void)
{
Driver::registerPlugin(PLATFORM_GL3, 0, ID_MATFX,
matfxOpen, matfxClose);
}
void void
matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst) matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
{ {
@ -197,7 +162,7 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_GL3); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = matfxRenderCB; pipe->renderCB = matfxRenderCB;
@ -206,6 +171,47 @@ makeMatFXPipeline(void)
return pipe; return pipe;
} }
static void*
matfxOpen(void *o, int32, int32)
{
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
#ifdef RW_GLES2
#include "gl2_shaders/matfx_gl2.inc"
#else
#include "shaders/matfx_gl3.inc"
#endif
const char *vs[] = { shaderDecl, header_vert_src, matfx_env_vert_src, nil };
const char *fs[] = { shaderDecl, header_frag_src, matfx_env_frag_src, nil };
envShader = Shader::create(vs, fs);
assert(envShader);
return o;
}
static void*
matfxClose(void *o, int32, int32)
{
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_GL3])->destroy();
matFXGlobals.pipelines[PLATFORM_GL3] = nil;
envShader->destroy();
envShader = nil;
return o;
}
void
initMatFX(void)
{
u_texMatrix = registerUniform("u_texMatrix");
u_fxparams = registerUniform("u_fxparams");
u_colorClamp = registerUniform("u_colorClamp");
Driver::registerPlugin(PLATFORM_GL3, 0, ID_MATFX,
matfxOpen, matfxClose);
}
#else #else
void initMatFX(void) { } void initMatFX(void) { }

View File

@ -148,9 +148,10 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic)
pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData);
} }
ObjPipeline::ObjPipeline(uint32 platform) void
: rw::ObjPipeline(platform) ObjPipeline::init(void)
{ {
this->rw::ObjPipeline::init(PLATFORM_GL3);
this->impl.instance = gl3::instance; this->impl.instance = gl3::instance;
this->impl.uninstance = gl3::uninstance; this->impl.uninstance = gl3::uninstance;
this->impl.render = gl3::render; this->impl.render = gl3::render;
@ -159,6 +160,14 @@ ObjPipeline::ObjPipeline(uint32 platform)
this->renderCB = nil; this->renderCB = nil;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
void void
defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance) defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
{ {
@ -310,7 +319,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header)
ObjPipeline* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_GL3); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = defaultInstanceCB; pipe->instanceCB = defaultInstanceCB;
pipe->uninstanceCB = defaultUninstanceCB; pipe->uninstanceCB = defaultUninstanceCB;
pipe->renderCB = defaultRenderCB; pipe->renderCB = defaultRenderCB;

View File

@ -31,40 +31,6 @@ namespace gl3 {
static Shader *skinShader; static Shader *skinShader;
static int32 u_boneMatrices; static int32 u_boneMatrices;
static void*
skinOpen(void *o, int32, int32)
{
u_boneMatrices = registerUniform("u_boneMatrices");
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline();
#ifdef RW_GLES2
#include "gl2_shaders/simple_fs_gl2.inc"
#include "gl2_shaders/skin_gl2.inc"
#else
#include "shaders/simple_fs_gl3.inc"
#include "shaders/skin_gl3.inc"
#endif
const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
skinShader = Shader::create(vs, fs);
assert(skinShader);
return o;
}
static void*
skinClose(void *o, int32, int32)
{
return o;
}
void
initSkin(void)
{
Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN,
skinOpen, skinClose);
}
void void
skinInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance) skinInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance)
{ {
@ -318,10 +284,51 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
#endif #endif
} }
static void*
skinOpen(void *o, int32, int32)
{
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline();
#ifdef RW_GLES2
#include "gl2_shaders/simple_fs_gl2.inc"
#include "gl2_shaders/skin_gl2.inc"
#else
#include "shaders/simple_fs_gl3.inc"
#include "shaders/skin_gl3.inc"
#endif
const char *vs[] = { shaderDecl, header_vert_src, skin_vert_src, nil };
const char *fs[] = { shaderDecl, header_frag_src, simple_frag_src, nil };
skinShader = Shader::create(vs, fs);
assert(skinShader);
return o;
}
static void*
skinClose(void *o, int32, int32)
{
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_GL3])->destroy();
skinGlobals.pipelines[PLATFORM_GL3] = nil;
skinShader->destroy();
skinShader = nil;
return o;
}
void
initSkin(void)
{
u_boneMatrices = registerUniform("u_boneMatrices");
Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN,
skinOpen, skinClose);
}
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_GL3); ObjPipeline *pipe = ObjPipeline::create();
pipe->instanceCB = skinInstanceCB; pipe->instanceCB = skinInstanceCB;
pipe->uninstanceCB = skinUninstanceCB; pipe->uninstanceCB = skinUninstanceCB;
pipe->renderCB = skinRenderCB; pipe->renderCB = skinRenderCB;

View File

@ -197,11 +197,12 @@ void flushCache(void);
class ObjPipeline : public rw::ObjPipeline class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
void init(void);
static ObjPipeline *create(void);
void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);
void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header);
void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); void (*renderCB)(Atomic *atomic, InstanceDataHeader *header);
ObjPipeline(uint32 platform);
}; };
void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance);

View File

@ -49,11 +49,12 @@ void printPipeinfo(Atomic *a);
class ObjPipeline : public rw::ObjPipeline class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
void init(void);
static ObjPipeline *create(void);
uint32 numCustomAttribs; uint32 numCustomAttribs;
uint32 (*instanceCB)(Geometry *g, int32 i, uint32 offset); uint32 (*instanceCB)(Geometry *g, int32 i, uint32 offset);
void (*uninstanceCB)(Geometry *g); void (*uninstanceCB)(Geometry *g);
ObjPipeline(uint32 platform);
}; };
ObjPipeline *makeDefaultPipeline(void); ObjPipeline *makeDefaultPipeline(void);

View File

@ -519,9 +519,10 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
destroyNativeData(geo, 0, 0); destroyNativeData(geo, 0, 0);
} }
ObjPipeline::ObjPipeline(uint32 platform) void
: rw::ObjPipeline(platform) ObjPipeline::init(void)
{ {
this->rw::ObjPipeline::init(PLATFORM_GL3);
this->numCustomAttribs = 0; this->numCustomAttribs = 0;
this->impl.instance = wdgl::instance; this->impl.instance = wdgl::instance;
this->impl.uninstance = wdgl::uninstance; this->impl.uninstance = wdgl::uninstance;
@ -529,10 +530,18 @@ ObjPipeline::ObjPipeline(uint32 platform)
this->uninstanceCB = nil; this->uninstanceCB = nil;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
ObjPipeline* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL); ObjPipeline *pipe = ObjPipeline::create();
return pipe; return pipe;
} }
@ -696,6 +705,8 @@ skinOpen(void *o, int32, int32)
static void* static void*
skinClose(void *o, int32, int32) skinClose(void *o, int32, int32)
{ {
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_WDGL])->destroy();
skinGlobals.pipelines[PLATFORM_WDGL] = nil;
return o; return o;
} }
@ -709,7 +720,7 @@ initSkin(void)
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL); ObjPipeline *pipe = ObjPipeline::create();
pipe->pluginID = ID_SKIN; pipe->pluginID = ID_SKIN;
pipe->pluginData = 1; pipe->pluginData = 1;
pipe->numCustomAttribs = 2; pipe->numCustomAttribs = 2;
@ -730,6 +741,8 @@ matfxOpen(void *o, int32, int32)
static void* static void*
matfxClose(void *o, int32, int32) matfxClose(void *o, int32, int32)
{ {
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_WDGL])->destroy();
matFXGlobals.pipelines[PLATFORM_WDGL] = nil;
return o; return o;
} }
@ -743,7 +756,7 @@ initMatFX(void)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL); ObjPipeline *pipe = ObjPipeline::create();
pipe->pluginID = ID_MATFX; pipe->pluginID = ID_MATFX;
pipe->pluginData = 0; pipe->pluginData = 0;
return pipe; return pipe;

View File

@ -585,17 +585,21 @@ static void*
matfxOpen(void *o, int32, int32) matfxOpen(void *o, int32, int32)
{ {
// init dummy pipelines // init dummy pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); matFXGlobals.dummypipe = ObjPipeline::create();
defpipe->pluginID = 0; //ID_MATFX; matFXGlobals.dummypipe->pluginID = 0; //ID_MATFX;
defpipe->pluginData = 0; matFXGlobals.dummypipe->pluginData = 0;
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++) for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
matFXGlobals.pipelines[i] = defpipe; matFXGlobals.pipelines[i] = matFXGlobals.dummypipe;
return o; return o;
} }
static void* static void*
matfxClose(void *o, int32, int32) matfxClose(void *o, int32, int32)
{ {
matFXGlobals.dummypipe->destroy();
matFXGlobals.dummypipe = nil;
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
matFXGlobals.pipelines[i] = nil;
return o; return o;
} }

View File

@ -7,6 +7,7 @@
#include "rwplg.h" #include "rwplg.h"
#include "rwpipeline.h" #include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwengine.h"
#define COLOR_ARGB(a,r,g,b) \ #define COLOR_ARGB(a,r,g,b) \
((uint32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) ((uint32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff)))
@ -15,21 +16,29 @@ namespace rw {
static void nothing(ObjPipeline *, Atomic*) {} static void nothing(ObjPipeline *, Atomic*) {}
Pipeline::Pipeline(uint32 platform) void
{ ObjPipeline::init(uint32 platform)
this->pluginID = 0;
this->pluginData = 0;
this->platform = platform;
}
ObjPipeline::ObjPipeline(uint32 platform)
: Pipeline(platform)
{ {
Pipeline::init(platform);
this->impl.instance = nothing; this->impl.instance = nothing;
this->impl.uninstance = nothing; this->impl.uninstance = nothing;
this->impl.render = nothing; this->impl.render = nothing;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init(PLATFORM_NULL);
return pipe;
}
void
ObjPipeline::destroy(void)
{
rwFree(this);
}
// helper functions // helper functions
void void

View File

@ -84,8 +84,10 @@ registerPDSPlugin(int32 n)
void void
registerPluginPDSPipes(void) registerPluginPDSPipes(void)
{ {
// TODO: how do we destroy them?
// rwPDS_G3_Skin_GrpMatPipeID // rwPDS_G3_Skin_GrpMatPipeID
MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); MatPipeline *pipe = MatPipeline::create();
pipe->pluginID = ID_PDS; pipe->pluginID = ID_PDS;
pipe->pluginData = 0x11001; pipe->pluginData = 0x11001;
pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_XYZ] = &attribXYZ;
@ -103,14 +105,14 @@ registerPluginPDSPipes(void)
registerPDSPipe(pipe); registerPDSPipe(pipe);
// rwPDS_G3_Skin_GrpAtmPipeID // rwPDS_G3_Skin_GrpAtmPipeID
ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); ObjPipeline *opipe = ObjPipeline::create();
opipe->pluginID = ID_PDS; opipe->pluginID = ID_PDS;
opipe->pluginData = 0x11002; opipe->pluginData = 0x11002;
opipe->groupPipeline = pipe; opipe->groupPipeline = pipe;
registerPDSPipe(opipe); registerPDSPipe(opipe);
// rwPDS_G3_MatfxUV1_GrpMatPipeID // rwPDS_G3_MatfxUV1_GrpMatPipeID
pipe = new MatPipeline(PLATFORM_PS2); pipe = MatPipeline::create();
pipe->pluginID = ID_PDS; pipe->pluginID = ID_PDS;
pipe->pluginData = 0x1100b; pipe->pluginData = 0x1100b;
pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_XYZ] = &attribXYZ;
@ -124,14 +126,14 @@ registerPluginPDSPipes(void)
registerPDSPipe(pipe); registerPDSPipe(pipe);
// rwPDS_G3_MatfxUV1_GrpAtmPipeID // rwPDS_G3_MatfxUV1_GrpAtmPipeID
opipe = new ObjPipeline(PLATFORM_PS2); opipe = ObjPipeline::create();
opipe->pluginID = ID_PDS; opipe->pluginID = ID_PDS;
opipe->pluginData = 0x1100d; opipe->pluginData = 0x1100d;
opipe->groupPipeline = pipe; opipe->groupPipeline = pipe;
registerPDSPipe(opipe); registerPDSPipe(opipe);
// rwPDS_G3_MatfxUV2_GrpMatPipeID // rwPDS_G3_MatfxUV2_GrpMatPipeID
pipe = new MatPipeline(PLATFORM_PS2); pipe = MatPipeline::create();
pipe->pluginID = ID_PDS; pipe->pluginID = ID_PDS;
pipe->pluginData = 0x1100c; pipe->pluginData = 0x1100c;
pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_XYZ] = &attribXYZ;
@ -145,7 +147,7 @@ registerPluginPDSPipes(void)
registerPDSPipe(pipe); registerPDSPipe(pipe);
// rwPDS_G3_MatfxUV2_GrpAtmPipeID // rwPDS_G3_MatfxUV2_GrpAtmPipeID
opipe = new ObjPipeline(PLATFORM_PS2); opipe = ObjPipeline::create();
opipe->pluginID = ID_PDS; opipe->pluginID = ID_PDS;
opipe->pluginData = 0x1100e; opipe->pluginData = 0x1100e;
opipe->groupPipeline = pipe; opipe->groupPipeline = pipe;
@ -154,19 +156,19 @@ registerPluginPDSPipes(void)
// RW World plugin // RW World plugin
// rwPDS_G3x_Generic_AtmPipeID // rwPDS_G3x_Generic_AtmPipeID
opipe = new ObjPipeline(PLATFORM_PS2); opipe = ObjPipeline::create();
opipe->pluginID = ID_PDS; opipe->pluginID = ID_PDS;
opipe->pluginData = 0x50001; opipe->pluginData = 0x50001;
registerPDSPipe(opipe); registerPDSPipe(opipe);
// rwPDS_G3x_Skin_AtmPipeID // rwPDS_G3x_Skin_AtmPipeID
opipe = new ObjPipeline(PLATFORM_PS2); opipe = ObjPipeline::create();
opipe->pluginID = ID_PDS; opipe->pluginID = ID_PDS;
opipe->pluginData = 0x5000b; opipe->pluginData = 0x5000b;
registerPDSPipe(opipe); registerPDSPipe(opipe);
// rwPDS_G3xd_A4D_MatPipeID // rwPDS_G3xd_A4D_MatPipeID
pipe = new MatPipeline(PLATFORM_PS2); pipe = MatPipeline::create();
pipe->pluginID = ID_PDS; pipe->pluginID = ID_PDS;
pipe->pluginData = 0x5002f; pipe->pluginData = 0x5002f;
pipe->attribs[0] = &attribXYZW; pipe->attribs[0] = &attribXYZW;
@ -180,7 +182,7 @@ registerPluginPDSPipes(void)
registerPDSPipe(pipe); registerPDSPipe(pipe);
// rwPDS_G3xd_A4DSkin_MatPipeID // rwPDS_G3xd_A4DSkin_MatPipeID
pipe = new MatPipeline(PLATFORM_PS2); pipe = MatPipeline::create();
pipe->pluginID = ID_PDS; pipe->pluginID = ID_PDS;
pipe->pluginData = 0x5003e; pipe->pluginData = 0x5003e;
pipe->attribs[0] = &attribXYZW; pipe->attribs[0] = &attribXYZW;

View File

@ -437,12 +437,30 @@ instanceNormal(uint32 *wp, Geometry *g, Mesh *m, uint32 idx, uint32 n)
return (uint32*)p; return (uint32*)p;
} }
MatPipeline::MatPipeline(uint32 platform) void
: rw::Pipeline(platform), instanceCB(nil), uninstanceCB(nil), MatPipeline::init(void)
preUninstCB(nil), postUninstCB(nil)
{ {
this->rw::Pipeline::init(PLATFORM_PS2);
for(int i = 0; i < 10; i++) for(int i = 0; i < 10; i++)
this->attribs[i] = nil; this->attribs[i] = nil;
this->instanceCB = nil;
this->uninstanceCB = nil;
this->preUninstCB = nil;
this->postUninstCB = nil;
}
MatPipeline*
MatPipeline::create(void)
{
MatPipeline *pipe = rwNewT(MatPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
void
MatPipeline::destroy(void)
{
rwFree(this);
} }
void void
@ -911,14 +929,23 @@ objUninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
*/ */
} }
ObjPipeline::ObjPipeline(uint32 platform) void
: rw::ObjPipeline(platform) ObjPipeline::init(void)
{ {
this->rw::ObjPipeline::init(PLATFORM_PS2);
this->groupPipeline = nil; this->groupPipeline = nil;
this->impl.instance = objInstance; this->impl.instance = objInstance;
this->impl.uninstance = objUninstance; this->impl.uninstance = objUninstance;
} }
ObjPipeline*
ObjPipeline::create(void)
{
ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL);
pipe->init();
return pipe;
}
void void
insertVertex(Geometry *geo, int32 i, uint32 mask, Vertex *v) insertVertex(Geometry *geo, int32 i, uint32 mask, Vertex *v)
{ {
@ -1082,7 +1109,7 @@ ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
if(defaultMatPipe == nil){ if(defaultMatPipe == nil){
MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); MatPipeline *pipe = MatPipeline::create();
pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_XYZ] = &attribXYZ;
pipe->attribs[AT_UV] = &attribUV; pipe->attribs[AT_UV] = &attribUV;
pipe->attribs[AT_RGBA] = &attribRGBA; pipe->attribs[AT_RGBA] = &attribRGBA;
@ -1095,7 +1122,7 @@ makeDefaultPipeline(void)
} }
if(defaultObjPipe == nil){ if(defaultObjPipe == nil){
ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); ObjPipeline *opipe = ObjPipeline::create();
defaultObjPipe = opipe; defaultObjPipe = opipe;
} }
return defaultObjPipe; return defaultObjPipe;

View File

@ -29,6 +29,9 @@ matfxOpen(void *o, int32, int32)
static void* static void*
matfxClose(void *o, int32, int32) matfxClose(void *o, int32, int32)
{ {
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_PS2])->groupPipeline->destroy();
((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_PS2])->destroy();
matFXGlobals.pipelines[PLATFORM_PS2] = nil;
return o; return o;
} }
@ -42,7 +45,7 @@ initMatFX(void)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); MatPipeline *pipe = MatPipeline::create();
pipe->pluginID = ID_MATFX; pipe->pluginID = ID_MATFX;
pipe->pluginData = 0; pipe->pluginData = 0;
pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_XYZ] = &attribXYZ;
@ -54,7 +57,7 @@ makeMatFXPipeline(void)
pipe->vifOffset = pipe->inputStride*vertCount; pipe->vifOffset = pipe->inputStride*vertCount;
pipe->uninstanceCB = genericUninstanceCB; pipe->uninstanceCB = genericUninstanceCB;
ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); ObjPipeline *opipe = ObjPipeline::create();
opipe->pluginID = ID_MATFX; opipe->pluginID = ID_MATFX;
opipe->pluginData = 0; opipe->pluginData = 0;
opipe->groupPipeline = pipe; opipe->groupPipeline = pipe;

View File

@ -31,6 +31,10 @@ skinOpen(void *o, int32, int32)
static void* static void*
skinClose(void *o, int32, int32) skinClose(void *o, int32, int32)
{ {
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_PS2])->groupPipeline->destroy();
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_PS2])->groupPipeline = nil;
((ObjPipeline*)skinGlobals.pipelines[PLATFORM_PS2])->destroy();
skinGlobals.pipelines[PLATFORM_PS2] = nil;
return o; return o;
} }
@ -44,7 +48,7 @@ initSkin(void)
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); MatPipeline *pipe = MatPipeline::create();
pipe->pluginID = ID_SKIN; pipe->pluginID = ID_SKIN;
pipe->pluginData = 1; pipe->pluginData = 1;
pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_XYZ] = &attribXYZ;
@ -60,7 +64,7 @@ makeSkinPipeline(void)
pipe->preUninstCB = skinPreCB; pipe->preUninstCB = skinPreCB;
pipe->postUninstCB = skinPostCB; pipe->postUninstCB = skinPostCB;
ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); ObjPipeline *opipe = ObjPipeline::create();
opipe->pluginID = ID_SKIN; opipe->pluginID = ID_SKIN;
opipe->pluginData = 1; opipe->pluginData = 1;
opipe->groupPipeline = pipe; opipe->groupPipeline = pipe;

View File

@ -132,7 +132,9 @@ public:
return (top-outBufs)/(inAttribs*2+outAttribs*outBufs); return (top-outBufs)/(inAttribs*2+outAttribs*outBufs);
} }
MatPipeline(uint32 platform); void init(void);
static MatPipeline *create(void);
void destroy(void);
void dump(void); void dump(void);
void setTriBufferSizes(uint32 inputStride, uint32 bufferSize); void setTriBufferSizes(uint32 inputStride, uint32 bufferSize);
void instance(Geometry *g, InstanceData *inst, Mesh *m); void instance(Geometry *g, InstanceData *inst, Mesh *m);
@ -142,14 +144,15 @@ public:
class ObjPipeline : public rw::ObjPipeline class ObjPipeline : public rw::ObjPipeline
{ {
public: public:
void init(void);
static ObjPipeline *create(void);
MatPipeline *groupPipeline; MatPipeline *groupPipeline;
// RW has more: // RW has more:
// setupCB() // setupCB()
// finalizeCB() // finalizeCB()
// lightOffset // lightOffset
// lightSize // lightSize
ObjPipeline(uint32 platform);
}; };
struct Vertex { struct Vertex {

View File

@ -153,6 +153,7 @@ struct Engine
// Dynamically allocated because of plugins // Dynamically allocated because of plugins
Driver *driver[NUM_PLATFORMS]; Driver *driver[NUM_PLATFORMS];
Device device; Device device;
ObjPipeline *dummyDefaultPipeline;
// These must always be available // These must always be available
static MemoryFunctions memfuncs; static MemoryFunctions memfuncs;

View File

@ -9,13 +9,20 @@ public:
uint32 pluginData; uint32 pluginData;
int32 platform; int32 platform;
Pipeline(uint32 platform); void init(uint32 platform) {
this->pluginID = 0;
this->pluginData = 0;
this->platform = platform;
}
}; };
class ObjPipeline : public Pipeline class ObjPipeline : public Pipeline
{ {
public: public:
ObjPipeline(uint32 platform); void init(uint32 platform);
static ObjPipeline *create(void); // always PLATFORM_NULL
void destroy(void);
// not the most beautiful way of doing things but still // not the most beautiful way of doing things but still
// better than virtual methods (i hope?). // better than virtual methods (i hope?).
struct { struct {

View File

@ -168,6 +168,7 @@ struct MatFXGlobals
int32 atomicOffset; int32 atomicOffset;
int32 materialOffset; int32 materialOffset;
ObjPipeline *pipelines[NUM_PLATFORMS]; ObjPipeline *pipelines[NUM_PLATFORMS];
ObjPipeline *dummypipe;
}; };
extern MatFXGlobals matFXGlobals; extern MatFXGlobals matFXGlobals;
void registerMatFXPlugin(void); void registerMatFXPlugin(void);
@ -182,6 +183,7 @@ struct SkinGlobals
int32 geoOffset; int32 geoOffset;
int32 atomicOffset; int32 atomicOffset;
ObjPipeline *pipelines[NUM_PLATFORMS]; ObjPipeline *pipelines[NUM_PLATFORMS];
ObjPipeline *dummypipe;
}; };
extern SkinGlobals skinGlobals; extern SkinGlobals skinGlobals;

View File

@ -331,17 +331,21 @@ static void*
skinOpen(void *o, int32, int32) skinOpen(void *o, int32, int32)
{ {
// init dummy pipelines // init dummy pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); skinGlobals.dummypipe = ObjPipeline::create();
defpipe->pluginID = ID_SKIN; skinGlobals.dummypipe->pluginID = ID_SKIN;
defpipe->pluginData = 1; skinGlobals.dummypipe->pluginData = 1;
for(uint i = 0; i < nelem(skinGlobals.pipelines); i++) for(uint i = 0; i < nelem(skinGlobals.pipelines); i++)
skinGlobals.pipelines[i] = defpipe; skinGlobals.pipelines[i] = skinGlobals.dummypipe;
return o; return o;
} }
static void* static void*
skinClose(void *o, int32, int32) skinClose(void *o, int32, int32)
{ {
skinGlobals.dummypipe->destroy();
skinGlobals.dummypipe = nil;
for(uint i = 0; i < nelem(skinGlobals.pipelines); i++)
skinGlobals.pipelines[i] = nil;
return o; return o;
} }