From 2568e77fac08ec9f5b78dc9819142548e347ff00 Mon Sep 17 00:00:00 2001 From: aap Date: Fri, 14 Aug 2020 13:54:44 +0200 Subject: [PATCH] changed pipe new to explicit create --- src/d3d/d3d8.cpp | 15 +++++++-- src/d3d/d3d8matfx.cpp | 4 ++- src/d3d/d3d8skin.cpp | 4 ++- src/d3d/d3d9.cpp | 15 +++++++-- src/d3d/d3d9matfx.cpp | 4 ++- src/d3d/d3d9skin.cpp | 4 ++- src/d3d/rwd3d8.h | 5 +-- src/d3d/rwd3d9.h | 5 +-- src/d3d/rwxbox.h | 5 +-- src/d3d/xbox.cpp | 14 ++++++-- src/d3d/xboxmatfx.cpp | 4 ++- src/d3d/xboxskin.cpp | 4 ++- src/engine.cpp | 5 +-- src/gl/gl3matfx.cpp | 78 +++++++++++++++++++++++-------------------- src/gl/gl3pipe.cpp | 15 +++++++-- src/gl/gl3skin.cpp | 77 +++++++++++++++++++++++------------------- src/gl/rwgl3.h | 5 +-- src/gl/rwwdgl.h | 5 +-- src/gl/wdgl.cpp | 23 ++++++++++--- src/matfx.cpp | 12 ++++--- src/pipeline.cpp | 27 ++++++++++----- src/ps2/pds.cpp | 22 ++++++------ src/ps2/ps2.cpp | 41 +++++++++++++++++++---- src/ps2/ps2matfx.cpp | 7 ++-- src/ps2/ps2skin.cpp | 8 +++-- src/ps2/rwps2.h | 9 +++-- src/rwengine.h | 1 + src/rwpipeline.h | 11 ++++-- src/rwplugins.h | 2 ++ src/skin.cpp | 12 ++++--- 30 files changed, 294 insertions(+), 149 deletions(-) diff --git a/src/d3d/d3d8.cpp b/src/d3d/d3d8.cpp index 73f4cd1..8932620 100644 --- a/src/d3d/d3d8.cpp +++ b/src/d3d/d3d8.cpp @@ -344,9 +344,10 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic) pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform) +void +ObjPipeline::init(void) { + this->rw::ObjPipeline::init(PLATFORM_D3D8); this->impl.instance = d3d8::instance; this->impl.uninstance = d3d8::uninstance; this->impl.render = d3d8::render; @@ -355,6 +356,14 @@ ObjPipeline::ObjPipeline(uint32 platform) this->renderCB = nil; } +ObjPipeline* +ObjPipeline::create(void) +{ + ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL); + pipe->init(); + return pipe; +} + void defaultInstanceCB(Geometry *geo, InstanceData *inst) { @@ -428,7 +437,7 @@ defaultUninstanceCB(Geometry *geo, InstanceData *inst) ObjPipeline* makeDefaultPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D8); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = defaultRenderCB; diff --git a/src/d3d/d3d8matfx.cpp b/src/d3d/d3d8matfx.cpp index 6c210c5..580203e 100644 --- a/src/d3d/d3d8matfx.cpp +++ b/src/d3d/d3d8matfx.cpp @@ -28,6 +28,8 @@ matfxOpen(void *o, int32, int32) static void* matfxClose(void *o, int32, int32) { + ((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_D3D8])->destroy(); + matFXGlobals.pipelines[PLATFORM_D3D8] = nil; return o; } @@ -41,7 +43,7 @@ initMatFX(void) ObjPipeline* makeMatFXPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D8); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = defaultRenderCB; diff --git a/src/d3d/d3d8skin.cpp b/src/d3d/d3d8skin.cpp index fc697db..d9b0921 100644 --- a/src/d3d/d3d8skin.cpp +++ b/src/d3d/d3d8skin.cpp @@ -28,6 +28,8 @@ skinOpen(void *o, int32, int32) static void* skinClose(void *o, int32, int32) { + ((ObjPipeline*)skinGlobals.pipelines[PLATFORM_D3D8])->destroy(); + skinGlobals.pipelines[PLATFORM_D3D8] = nil; return o; } @@ -41,7 +43,7 @@ initSkin(void) ObjPipeline* makeSkinPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D8); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = defaultRenderCB; diff --git a/src/d3d/d3d9.cpp b/src/d3d/d3d9.cpp index a5c62bd..3abe111 100644 --- a/src/d3d/d3d9.cpp +++ b/src/d3d/d3d9.cpp @@ -464,9 +464,10 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic) pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform) +void +ObjPipeline::init(void) { + this->rw::ObjPipeline::init(PLATFORM_D3D9); this->impl.instance = d3d9::instance; this->impl.uninstance = d3d9::uninstance; this->impl.render = d3d9::render; @@ -475,6 +476,14 @@ ObjPipeline::ObjPipeline(uint32 platform) this->renderCB = nil; } +ObjPipeline* +ObjPipeline::create(void) +{ + ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL); + pipe->init(); + return pipe; +} + void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance) { @@ -682,7 +691,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header) ObjPipeline* makeDefaultPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = defaultRenderCB_Shader; diff --git a/src/d3d/d3d9matfx.cpp b/src/d3d/d3d9matfx.cpp index c691b3a..e85540d 100644 --- a/src/d3d/d3d9matfx.cpp +++ b/src/d3d/d3d9matfx.cpp @@ -274,6 +274,8 @@ matfxClose(void *o, int32, int32) destroyMatFXShaders(); #endif + ((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_D3D9])->destroy(); + matFXGlobals.pipelines[PLATFORM_D3D9] = nil; return o; } @@ -287,7 +289,7 @@ initMatFX(void) ObjPipeline* makeMatFXPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = matfxRenderCB_Shader; diff --git a/src/d3d/d3d9skin.cpp b/src/d3d/d3d9skin.cpp index eb9ea81..c727074 100644 --- a/src/d3d/d3d9skin.cpp +++ b/src/d3d/d3d9skin.cpp @@ -366,6 +366,8 @@ skinClose(void *o, int32, int32) destroySkinShaders(); #endif + ((ObjPipeline*)skinGlobals.pipelines[PLATFORM_D3D9])->destroy(); + skinGlobals.pipelines[PLATFORM_D3D9] = nil; return o; } @@ -379,7 +381,7 @@ initSkin(void) ObjPipeline* makeSkinPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_D3D9); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = skinInstanceCB; pipe->uninstanceCB = nil; pipe->renderCB = skinRenderCB; diff --git a/src/d3d/rwd3d8.h b/src/d3d/rwd3d8.h index 4f06cd0..422379d 100644 --- a/src/d3d/rwd3d8.h +++ b/src/d3d/rwd3d8.h @@ -40,11 +40,12 @@ void registerNativeDataPlugin(void); class ObjPipeline : public rw::ObjPipeline { public: + void init(void); + static ObjPipeline *create(void); + void (*instanceCB)(Geometry *geo, InstanceData *header); void (*uninstanceCB)(Geometry *geo, InstanceData *header); void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); - - ObjPipeline(uint32 platform); }; void defaultInstanceCB(Geometry *geo, InstanceData *header); diff --git a/src/d3d/rwd3d9.h b/src/d3d/rwd3d9.h index 1bdbca0..9b5a25c 100644 --- a/src/d3d/rwd3d9.h +++ b/src/d3d/rwd3d9.h @@ -73,11 +73,12 @@ void registerNativeDataPlugin(void); class ObjPipeline : public rw::ObjPipeline { public: + void init(void); + static ObjPipeline *create(void); + void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); - - ObjPipeline(uint32 platform); }; void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); diff --git a/src/d3d/rwxbox.h b/src/d3d/rwxbox.h index 848bfb9..fef8284 100644 --- a/src/d3d/rwxbox.h +++ b/src/d3d/rwxbox.h @@ -41,10 +41,11 @@ void registerNativeDataPlugin(void); class ObjPipeline : public rw::ObjPipeline { public: + void init(void); + static ObjPipeline *create(void); + void (*instanceCB)(Geometry *geo, InstanceDataHeader *header); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); - - ObjPipeline(uint32 platform); }; ObjPipeline *makeDefaultPipeline(void); diff --git a/src/d3d/xbox.cpp b/src/d3d/xbox.cpp index 2c0f6d6..35c065e 100644 --- a/src/d3d/xbox.cpp +++ b/src/d3d/xbox.cpp @@ -286,15 +286,23 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) destroyNativeData(geo, 0, 0); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform) +void +ObjPipeline::init(void) { + this->rw::ObjPipeline::init(PLATFORM_XBOX); this->impl.instance = xbox::instance; this->impl.uninstance = xbox::uninstance; this->instanceCB = nil; this->uninstanceCB = nil; } +ObjPipeline* +ObjPipeline::create(void) +{ + ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL); + pipe->init(); + return pipe; +} int v3dFormatMap[] = { -1, VERT_BYTE3, VERT_SHORT3, VERT_NORMSHORT3, VERT_COMPNORM, VERT_FLOAT3 @@ -385,7 +393,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header) ObjPipeline* makeDefaultPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_XBOX); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; return pipe; diff --git a/src/d3d/xboxmatfx.cpp b/src/d3d/xboxmatfx.cpp index d65144f..a6b8718 100644 --- a/src/d3d/xboxmatfx.cpp +++ b/src/d3d/xboxmatfx.cpp @@ -26,6 +26,8 @@ matfxOpen(void *o, int32, int32) static void* matfxClose(void *o, int32, int32) { + ((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_XBOX])->destroy(); + matFXGlobals.pipelines[PLATFORM_XBOX] = nil; return o; } @@ -39,7 +41,7 @@ initMatFX(void) ObjPipeline* makeMatFXPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_XBOX); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->pluginID = ID_MATFX; diff --git a/src/d3d/xboxskin.cpp b/src/d3d/xboxskin.cpp index 39346b4..0ce5cba 100644 --- a/src/d3d/xboxskin.cpp +++ b/src/d3d/xboxskin.cpp @@ -225,6 +225,8 @@ skinOpen(void *o, int32, int32) static void* skinClose(void *o, int32, int32) { + ((ObjPipeline*)skinGlobals.pipelines[PLATFORM_XBOX])->destroy(); + skinGlobals.pipelines[PLATFORM_XBOX] = nil; return o; } @@ -238,7 +240,7 @@ initSkin(void) ObjPipeline* makeSkinPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_XBOX); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = skinInstanceCB; pipe->uninstanceCB = skinUninstanceCB; pipe->pluginID = ID_SKIN; diff --git a/src/engine.cpp b/src/engine.cpp index cfe26db..f1fabc5 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -240,12 +240,12 @@ Engine::open(EngineOpenParams *p) 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++){ rw::engine->driver[i] = (Driver*)rwNew(Driver::s_plglist[i].size, MEMDUR_GLOBAL); - engine->driver[i]->defaultPipeline = defpipe; + engine->driver[i]->defaultPipeline = engine->dummyDefaultPipeline; engine->driver[i]->rasterCreate = null::rasterCreate; engine->driver[i]->rasterLock = null::rasterLock; @@ -324,6 +324,7 @@ Engine::close(void) engine->device.system(DEVICECLOSE, nil, 0); for(uint i = 0; i < NUM_PLATFORMS; i++) rwFree(rw::engine->driver[i]); + engine->dummyDefaultPipeline->destroy(); rwFree(engine); engine = nil; Engine::state = Initialized; diff --git a/src/gl/gl3matfx.cpp b/src/gl/gl3matfx.cpp index 931834a..98f67da 100644 --- a/src/gl/gl3matfx.cpp +++ b/src/gl/gl3matfx.cpp @@ -33,41 +33,6 @@ static int32 u_texMatrix; static int32 u_fxparams; 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 matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst) { @@ -197,7 +162,7 @@ matfxRenderCB(Atomic *atomic, InstanceDataHeader *header) ObjPipeline* makeMatFXPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_GL3); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = matfxRenderCB; @@ -206,6 +171,47 @@ makeMatFXPipeline(void) 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 void initMatFX(void) { } diff --git a/src/gl/gl3pipe.cpp b/src/gl/gl3pipe.cpp index 89c4004..c76db6e 100644 --- a/src/gl/gl3pipe.cpp +++ b/src/gl/gl3pipe.cpp @@ -148,9 +148,10 @@ render(rw::ObjPipeline *rwpipe, Atomic *atomic) pipe->renderCB(atomic, (InstanceDataHeader*)geo->instData); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform) +void +ObjPipeline::init(void) { + this->rw::ObjPipeline::init(PLATFORM_GL3); this->impl.instance = gl3::instance; this->impl.uninstance = gl3::uninstance; this->impl.render = gl3::render; @@ -159,6 +160,14 @@ ObjPipeline::ObjPipeline(uint32 platform) this->renderCB = nil; } +ObjPipeline* +ObjPipeline::create(void) +{ + ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL); + pipe->init(); + return pipe; +} + void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance) { @@ -310,7 +319,7 @@ defaultUninstanceCB(Geometry *geo, InstanceDataHeader *header) ObjPipeline* makeDefaultPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_GL3); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = defaultInstanceCB; pipe->uninstanceCB = defaultUninstanceCB; pipe->renderCB = defaultRenderCB; diff --git a/src/gl/gl3skin.cpp b/src/gl/gl3skin.cpp index 494fa08..c8cfc95 100644 --- a/src/gl/gl3skin.cpp +++ b/src/gl/gl3skin.cpp @@ -31,40 +31,6 @@ namespace gl3 { static Shader *skinShader; 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 skinInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance) { @@ -318,10 +284,51 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header) #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* makeSkinPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_GL3); + ObjPipeline *pipe = ObjPipeline::create(); pipe->instanceCB = skinInstanceCB; pipe->uninstanceCB = skinUninstanceCB; pipe->renderCB = skinRenderCB; diff --git a/src/gl/rwgl3.h b/src/gl/rwgl3.h index 3daad85..b223f1e 100644 --- a/src/gl/rwgl3.h +++ b/src/gl/rwgl3.h @@ -197,11 +197,12 @@ void flushCache(void); class ObjPipeline : public rw::ObjPipeline { public: + void init(void); + static ObjPipeline *create(void); + void (*instanceCB)(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); void (*uninstanceCB)(Geometry *geo, InstanceDataHeader *header); void (*renderCB)(Atomic *atomic, InstanceDataHeader *header); - - ObjPipeline(uint32 platform); }; void defaultInstanceCB(Geometry *geo, InstanceDataHeader *header, bool32 reinstance); diff --git a/src/gl/rwwdgl.h b/src/gl/rwwdgl.h index cda69a6..b336ba3 100644 --- a/src/gl/rwwdgl.h +++ b/src/gl/rwwdgl.h @@ -49,11 +49,12 @@ void printPipeinfo(Atomic *a); class ObjPipeline : public rw::ObjPipeline { public: + void init(void); + static ObjPipeline *create(void); + uint32 numCustomAttribs; uint32 (*instanceCB)(Geometry *g, int32 i, uint32 offset); void (*uninstanceCB)(Geometry *g); - - ObjPipeline(uint32 platform); }; ObjPipeline *makeDefaultPipeline(void); diff --git a/src/gl/wdgl.cpp b/src/gl/wdgl.cpp index 842440b..061ce7c 100644 --- a/src/gl/wdgl.cpp +++ b/src/gl/wdgl.cpp @@ -519,9 +519,10 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) destroyNativeData(geo, 0, 0); } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform) +void +ObjPipeline::init(void) { + this->rw::ObjPipeline::init(PLATFORM_GL3); this->numCustomAttribs = 0; this->impl.instance = wdgl::instance; this->impl.uninstance = wdgl::uninstance; @@ -529,10 +530,18 @@ ObjPipeline::ObjPipeline(uint32 platform) this->uninstanceCB = nil; } +ObjPipeline* +ObjPipeline::create(void) +{ + ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL); + pipe->init(); + return pipe; +} + ObjPipeline* makeDefaultPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL); + ObjPipeline *pipe = ObjPipeline::create(); return pipe; } @@ -696,6 +705,8 @@ skinOpen(void *o, int32, int32) static void* skinClose(void *o, int32, int32) { + ((ObjPipeline*)skinGlobals.pipelines[PLATFORM_WDGL])->destroy(); + skinGlobals.pipelines[PLATFORM_WDGL] = nil; return o; } @@ -709,7 +720,7 @@ initSkin(void) ObjPipeline* makeSkinPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL); + ObjPipeline *pipe = ObjPipeline::create(); pipe->pluginID = ID_SKIN; pipe->pluginData = 1; pipe->numCustomAttribs = 2; @@ -730,6 +741,8 @@ matfxOpen(void *o, int32, int32) static void* matfxClose(void *o, int32, int32) { + ((ObjPipeline*)matFXGlobals.pipelines[PLATFORM_WDGL])->destroy(); + matFXGlobals.pipelines[PLATFORM_WDGL] = nil; return o; } @@ -743,7 +756,7 @@ initMatFX(void) ObjPipeline* makeMatFXPipeline(void) { - ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL); + ObjPipeline *pipe = ObjPipeline::create(); pipe->pluginID = ID_MATFX; pipe->pluginData = 0; return pipe; diff --git a/src/matfx.cpp b/src/matfx.cpp index 457106f..44806f9 100644 --- a/src/matfx.cpp +++ b/src/matfx.cpp @@ -585,17 +585,21 @@ static void* matfxOpen(void *o, int32, int32) { // init dummy pipelines - ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); - defpipe->pluginID = 0; //ID_MATFX; - defpipe->pluginData = 0; + matFXGlobals.dummypipe = ObjPipeline::create(); + matFXGlobals.dummypipe->pluginID = 0; //ID_MATFX; + matFXGlobals.dummypipe->pluginData = 0; for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++) - matFXGlobals.pipelines[i] = defpipe; + matFXGlobals.pipelines[i] = matFXGlobals.dummypipe; return o; } static void* 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; } diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 7707a35..6284f68 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -7,6 +7,7 @@ #include "rwplg.h" #include "rwpipeline.h" #include "rwobjects.h" +#include "rwengine.h" #define COLOR_ARGB(a,r,g,b) \ ((uint32)((((a)&0xff)<<24)|(((r)&0xff)<<16)|(((g)&0xff)<<8)|((b)&0xff))) @@ -15,21 +16,29 @@ namespace rw { static void nothing(ObjPipeline *, Atomic*) {} -Pipeline::Pipeline(uint32 platform) -{ - this->pluginID = 0; - this->pluginData = 0; - this->platform = platform; -} - -ObjPipeline::ObjPipeline(uint32 platform) - : Pipeline(platform) +void +ObjPipeline::init(uint32 platform) { + Pipeline::init(platform); this->impl.instance = nothing; this->impl.uninstance = 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 void diff --git a/src/ps2/pds.cpp b/src/ps2/pds.cpp index 1b3faa0..afdc6e8 100644 --- a/src/ps2/pds.cpp +++ b/src/ps2/pds.cpp @@ -84,8 +84,10 @@ registerPDSPlugin(int32 n) void registerPluginPDSPipes(void) { + // TODO: how do we destroy them? + // rwPDS_G3_Skin_GrpMatPipeID - MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); + MatPipeline *pipe = MatPipeline::create(); pipe->pluginID = ID_PDS; pipe->pluginData = 0x11001; pipe->attribs[AT_XYZ] = &attribXYZ; @@ -103,14 +105,14 @@ registerPluginPDSPipes(void) registerPDSPipe(pipe); // rwPDS_G3_Skin_GrpAtmPipeID - ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); + ObjPipeline *opipe = ObjPipeline::create(); opipe->pluginID = ID_PDS; opipe->pluginData = 0x11002; opipe->groupPipeline = pipe; registerPDSPipe(opipe); // rwPDS_G3_MatfxUV1_GrpMatPipeID - pipe = new MatPipeline(PLATFORM_PS2); + pipe = MatPipeline::create(); pipe->pluginID = ID_PDS; pipe->pluginData = 0x1100b; pipe->attribs[AT_XYZ] = &attribXYZ; @@ -124,14 +126,14 @@ registerPluginPDSPipes(void) registerPDSPipe(pipe); // rwPDS_G3_MatfxUV1_GrpAtmPipeID - opipe = new ObjPipeline(PLATFORM_PS2); + opipe = ObjPipeline::create(); opipe->pluginID = ID_PDS; opipe->pluginData = 0x1100d; opipe->groupPipeline = pipe; registerPDSPipe(opipe); // rwPDS_G3_MatfxUV2_GrpMatPipeID - pipe = new MatPipeline(PLATFORM_PS2); + pipe = MatPipeline::create(); pipe->pluginID = ID_PDS; pipe->pluginData = 0x1100c; pipe->attribs[AT_XYZ] = &attribXYZ; @@ -145,7 +147,7 @@ registerPluginPDSPipes(void) registerPDSPipe(pipe); // rwPDS_G3_MatfxUV2_GrpAtmPipeID - opipe = new ObjPipeline(PLATFORM_PS2); + opipe = ObjPipeline::create(); opipe->pluginID = ID_PDS; opipe->pluginData = 0x1100e; opipe->groupPipeline = pipe; @@ -154,19 +156,19 @@ registerPluginPDSPipes(void) // RW World plugin // rwPDS_G3x_Generic_AtmPipeID - opipe = new ObjPipeline(PLATFORM_PS2); + opipe = ObjPipeline::create(); opipe->pluginID = ID_PDS; opipe->pluginData = 0x50001; registerPDSPipe(opipe); // rwPDS_G3x_Skin_AtmPipeID - opipe = new ObjPipeline(PLATFORM_PS2); + opipe = ObjPipeline::create(); opipe->pluginID = ID_PDS; opipe->pluginData = 0x5000b; registerPDSPipe(opipe); // rwPDS_G3xd_A4D_MatPipeID - pipe = new MatPipeline(PLATFORM_PS2); + pipe = MatPipeline::create(); pipe->pluginID = ID_PDS; pipe->pluginData = 0x5002f; pipe->attribs[0] = &attribXYZW; @@ -180,7 +182,7 @@ registerPluginPDSPipes(void) registerPDSPipe(pipe); // rwPDS_G3xd_A4DSkin_MatPipeID - pipe = new MatPipeline(PLATFORM_PS2); + pipe = MatPipeline::create(); pipe->pluginID = ID_PDS; pipe->pluginData = 0x5003e; pipe->attribs[0] = &attribXYZW; diff --git a/src/ps2/ps2.cpp b/src/ps2/ps2.cpp index ffcc85c..dbbcd0a 100644 --- a/src/ps2/ps2.cpp +++ b/src/ps2/ps2.cpp @@ -437,12 +437,30 @@ instanceNormal(uint32 *wp, Geometry *g, Mesh *m, uint32 idx, uint32 n) return (uint32*)p; } -MatPipeline::MatPipeline(uint32 platform) - : rw::Pipeline(platform), instanceCB(nil), uninstanceCB(nil), - preUninstCB(nil), postUninstCB(nil) +void +MatPipeline::init(void) { + this->rw::Pipeline::init(PLATFORM_PS2); for(int i = 0; i < 10; i++) 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 @@ -911,14 +929,23 @@ objUninstance(rw::ObjPipeline *rwpipe, Atomic *atomic) */ } -ObjPipeline::ObjPipeline(uint32 platform) - : rw::ObjPipeline(platform) +void +ObjPipeline::init(void) { + this->rw::ObjPipeline::init(PLATFORM_PS2); this->groupPipeline = nil; this->impl.instance = objInstance; this->impl.uninstance = objUninstance; } +ObjPipeline* +ObjPipeline::create(void) +{ + ObjPipeline *pipe = rwNewT(ObjPipeline, 1, MEMDUR_GLOBAL); + pipe->init(); + return pipe; +} + void insertVertex(Geometry *geo, int32 i, uint32 mask, Vertex *v) { @@ -1082,7 +1109,7 @@ ObjPipeline* makeDefaultPipeline(void) { if(defaultMatPipe == nil){ - MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); + MatPipeline *pipe = MatPipeline::create(); pipe->attribs[AT_XYZ] = &attribXYZ; pipe->attribs[AT_UV] = &attribUV; pipe->attribs[AT_RGBA] = &attribRGBA; @@ -1095,7 +1122,7 @@ makeDefaultPipeline(void) } if(defaultObjPipe == nil){ - ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); + ObjPipeline *opipe = ObjPipeline::create(); defaultObjPipe = opipe; } return defaultObjPipe; diff --git a/src/ps2/ps2matfx.cpp b/src/ps2/ps2matfx.cpp index 7fcf30f..6972a05 100644 --- a/src/ps2/ps2matfx.cpp +++ b/src/ps2/ps2matfx.cpp @@ -29,6 +29,9 @@ matfxOpen(void *o, int32, int32) static void* 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; } @@ -42,7 +45,7 @@ initMatFX(void) ObjPipeline* makeMatFXPipeline(void) { - MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); + MatPipeline *pipe = MatPipeline::create(); pipe->pluginID = ID_MATFX; pipe->pluginData = 0; pipe->attribs[AT_XYZ] = &attribXYZ; @@ -54,7 +57,7 @@ makeMatFXPipeline(void) pipe->vifOffset = pipe->inputStride*vertCount; pipe->uninstanceCB = genericUninstanceCB; - ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); + ObjPipeline *opipe = ObjPipeline::create(); opipe->pluginID = ID_MATFX; opipe->pluginData = 0; opipe->groupPipeline = pipe; diff --git a/src/ps2/ps2skin.cpp b/src/ps2/ps2skin.cpp index a4c5c92..d4c9d79 100644 --- a/src/ps2/ps2skin.cpp +++ b/src/ps2/ps2skin.cpp @@ -31,6 +31,10 @@ skinOpen(void *o, int32, int32) static void* 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; } @@ -44,7 +48,7 @@ initSkin(void) ObjPipeline* makeSkinPipeline(void) { - MatPipeline *pipe = new MatPipeline(PLATFORM_PS2); + MatPipeline *pipe = MatPipeline::create(); pipe->pluginID = ID_SKIN; pipe->pluginData = 1; pipe->attribs[AT_XYZ] = &attribXYZ; @@ -60,7 +64,7 @@ makeSkinPipeline(void) pipe->preUninstCB = skinPreCB; pipe->postUninstCB = skinPostCB; - ObjPipeline *opipe = new ObjPipeline(PLATFORM_PS2); + ObjPipeline *opipe = ObjPipeline::create(); opipe->pluginID = ID_SKIN; opipe->pluginData = 1; opipe->groupPipeline = pipe; diff --git a/src/ps2/rwps2.h b/src/ps2/rwps2.h index 01a60b7..e8c779b 100644 --- a/src/ps2/rwps2.h +++ b/src/ps2/rwps2.h @@ -132,7 +132,9 @@ public: return (top-outBufs)/(inAttribs*2+outAttribs*outBufs); } - MatPipeline(uint32 platform); + void init(void); + static MatPipeline *create(void); + void destroy(void); void dump(void); void setTriBufferSizes(uint32 inputStride, uint32 bufferSize); void instance(Geometry *g, InstanceData *inst, Mesh *m); @@ -142,14 +144,15 @@ public: class ObjPipeline : public rw::ObjPipeline { public: + void init(void); + static ObjPipeline *create(void); + MatPipeline *groupPipeline; // RW has more: // setupCB() // finalizeCB() // lightOffset // lightSize - - ObjPipeline(uint32 platform); }; struct Vertex { diff --git a/src/rwengine.h b/src/rwengine.h index ebf6a64..d09de11 100644 --- a/src/rwengine.h +++ b/src/rwengine.h @@ -153,6 +153,7 @@ struct Engine // Dynamically allocated because of plugins Driver *driver[NUM_PLATFORMS]; Device device; + ObjPipeline *dummyDefaultPipeline; // These must always be available static MemoryFunctions memfuncs; diff --git a/src/rwpipeline.h b/src/rwpipeline.h index bd8d8c1..9a0410a 100644 --- a/src/rwpipeline.h +++ b/src/rwpipeline.h @@ -9,13 +9,20 @@ public: uint32 pluginData; int32 platform; - Pipeline(uint32 platform); + void init(uint32 platform) { + this->pluginID = 0; + this->pluginData = 0; + this->platform = platform; + } }; class ObjPipeline : public Pipeline { 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 // better than virtual methods (i hope?). struct { diff --git a/src/rwplugins.h b/src/rwplugins.h index 4b90c87..326d4af 100644 --- a/src/rwplugins.h +++ b/src/rwplugins.h @@ -168,6 +168,7 @@ struct MatFXGlobals int32 atomicOffset; int32 materialOffset; ObjPipeline *pipelines[NUM_PLATFORMS]; + ObjPipeline *dummypipe; }; extern MatFXGlobals matFXGlobals; void registerMatFXPlugin(void); @@ -182,6 +183,7 @@ struct SkinGlobals int32 geoOffset; int32 atomicOffset; ObjPipeline *pipelines[NUM_PLATFORMS]; + ObjPipeline *dummypipe; }; extern SkinGlobals skinGlobals; diff --git a/src/skin.cpp b/src/skin.cpp index 75ed1e0..dfccd83 100644 --- a/src/skin.cpp +++ b/src/skin.cpp @@ -331,17 +331,21 @@ static void* skinOpen(void *o, int32, int32) { // init dummy pipelines - ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); - defpipe->pluginID = ID_SKIN; - defpipe->pluginData = 1; + skinGlobals.dummypipe = ObjPipeline::create(); + skinGlobals.dummypipe->pluginID = ID_SKIN; + skinGlobals.dummypipe->pluginData = 1; for(uint i = 0; i < nelem(skinGlobals.pipelines); i++) - skinGlobals.pipelines[i] = defpipe; + skinGlobals.pipelines[i] = skinGlobals.dummypipe; return o; } static void* 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; }