improved engine init and plugin registration

This commit is contained in:
aap 2017-08-26 20:08:23 +02:00
parent 45b48b8f4e
commit ea48c140c1
30 changed files with 246 additions and 124 deletions

View File

@ -24,6 +24,8 @@ namespace rw {
static AnimInterpolatorInfo *interpInfoList[MAXINTERPINFO];
// TODO MEMORY: also clean it up again
void
AnimInterpolatorInfo::registerInterp(AnimInterpolatorInfo *interpInfo)
{

View File

@ -20,7 +20,7 @@ namespace rw {
namespace d3d8 {
using namespace d3d;
void*
static void*
driverOpen(void *o, int32, int32)
{
engine->driver[PLATFORM_D3D8]->defaultPipeline = makeDefaultPipeline();
@ -35,14 +35,14 @@ driverOpen(void *o, int32, int32)
return o;
}
void*
static void*
driverClose(void *o, int32, int32)
{
return o;
}
void
initializePlatform(void)
registerPlatformPlugins(void)
{
Driver::registerPlugin(PLATFORM_D3D8, 0, PLATFORM_D3D8,
driverOpen, driverClose);

View File

@ -28,7 +28,7 @@ static VertexElement _d3ddec_end = {0xFF,0,D3DDECLTYPE_UNUSED,0,0,0};
#define NUMDECLELT 12
void*
static void*
driverOpen(void *o, int32, int32)
{
engine->driver[PLATFORM_D3D9]->defaultPipeline = makeDefaultPipeline();
@ -43,14 +43,14 @@ driverOpen(void *o, int32, int32)
return o;
}
void*
static void*
driverClose(void *o, int32, int32)
{
return o;
}
void
initializePlatform(void)
registerPlatformPlugins(void)
{
Driver::registerPlugin(PLATFORM_D3D9, 0, PLATFORM_D3D9,
driverOpen, driverClose);

View File

@ -1,7 +1,7 @@
namespace rw {
namespace d3d8 {
void initializePlatform(void);
void registerPlatformPlugins(void);
struct InstanceData
{

View File

@ -1,7 +1,7 @@
namespace rw {
namespace d3d9 {
void initializePlatform(void);
void registerPlatformPlugins(void);
struct VertexElement
{

View File

@ -1,7 +1,7 @@
namespace rw {
namespace xbox {
void initializePlatform(void);
void registerPlatformPlugins(void);
struct InstanceData
{

View File

@ -18,7 +18,7 @@
namespace rw {
namespace xbox {
void*
static void*
driverOpen(void *o, int32, int32)
{
engine->driver[PLATFORM_XBOX]->defaultPipeline = makeDefaultPipeline();
@ -33,14 +33,14 @@ driverOpen(void *o, int32, int32)
return o;
}
void*
static void*
driverClose(void *o, int32, int32)
{
return o;
}
void
initializePlatform(void)
registerPlatformPlugins(void)
{
Driver::registerPlugin(PLATFORM_XBOX, 0, PLATFORM_XBOX,
driverOpen, driverClose);

View File

@ -29,9 +29,10 @@
namespace rw {
Engine *engine;
PluginList Driver::s_plglist[NUM_PLATFORMS];
PluginList Engine::s_plglist;
Engine::State Engine::state = Dead;
MemoryFunctions Engine::memfuncs;
PluginList Driver::s_plglist[NUM_PLATFORMS];
void *malloc_h(size_t sz, uint32 hint) { if(sz == 0) return nil; return malloc(sz); }
void *realloc_h(void *p, size_t sz, uint32 hint) { return realloc(p, sz); }
@ -58,9 +59,6 @@ void *mustrealloc_h(void *p, size_t sz, uint32 hint)
}
// This function mainly registers engine plugins
// RW initializes memory related things here too and
// uses more plugins
// TODO: do this^ ?
bool32
Engine::init(void)
{
@ -69,6 +67,7 @@ Engine::init(void)
return 0;
}
// TODO: make this an argument
memfuncs.rwmalloc = malloc_h;
memfuncs.rwrealloc = realloc_h;
memfuncs.rwfree = free;
@ -78,22 +77,28 @@ Engine::init(void)
PluginList init = { sizeof(Driver), sizeof(Driver), nil, nil };
for(uint i = 0; i < NUM_PLATFORMS; i++)
Driver::s_plglist[i] = init;
Engine::s_plglist.size = sizeof(Engine);
Engine::s_plglist.defaultSize = sizeof(Engine);
Engine::s_plglist.first = nil;
Engine::s_plglist.last = nil;
// Register plugins
// TODO: these are wrong
ps2::initializePlatform();
xbox::initializePlatform();
d3d8::initializePlatform();
d3d9::initializePlatform();
wdgl::initializePlatform();
gl3::initializePlatform();
// core plugin attach here
Engine::registerPlugin(0, ID_FRAMEMODULE, Frame::_open, Frame::_close);
// driver plugin attach
ps2::registerPlatformPlugins();
xbox::registerPlatformPlugins();
d3d8::registerPlatformPlugins();
d3d9::registerPlatformPlugins();
wdgl::registerPlatformPlugins();
gl3::registerPlatformPlugins();
Engine::state = Initialized;
return 1;
}
// This is where RW allocates the engine and e.g. opens d3d
// TODO: this will take an argument with device specific data (HWND &c.)
// TODO: this will probably take an argument with device specific data
bool32
Engine::open(void)
{
@ -103,7 +108,7 @@ Engine::open(void)
}
// Allocate engine
engine = rwNewT(Engine, 1, MEMDUR_GLOBAL);
engine = (Engine*)rwNew(Engine::s_plglist.size, MEMDUR_GLOBAL);
engine->currentCamera = nil;
engine->currentWorld = nil;
engine->currentTexDictionary = nil;
@ -155,16 +160,14 @@ Engine::start(EngineStartParams *p)
return 0;
}
// Start device
engine->device.system(DEVICESTART, (void*)p);
engine->device.system(DEVICEINIT, nil);
// TODO: construct engine plugins
Frame::dirtyList.init();
Engine::s_plglist.construct(engine);
for(uint i = 0; i < NUM_PLATFORMS; i++)
Driver::s_plglist[i].construct(rw::engine->driver[i]);
// TODO: finalize device start
engine->device.system(DEVICEFINALIZE, nil);
Engine::state = Started;
return 1;
@ -174,19 +177,27 @@ void
Engine::term(void)
{
// TODO
for(uint i = 0; i < NUM_PLATFORMS; i++)
Driver::s_plglist[i].destruct(rw::engine->driver[i]);
Engine::s_plglist.destruct(engine);
Engine::state = Opened;
}
void
Engine::close(void)
{
// TODO
for(uint i = 0; i < NUM_PLATFORMS; i++)
rwFree(rw::engine->driver[i]);
rwFree(engine);
Engine::state = Initialized;
}
void
Engine::stop(void)
{
engine->device.system(DEVICESTOP, nil);
Engine::state = Dead;
}
namespace null {

View File

@ -12,8 +12,11 @@
namespace rw {
LinkList Frame::dirtyList;
PluginList Frame::s_plglist = { sizeof(Frame), sizeof(Frame), nil, nil };
void *Frame::_open(void *object, int32 offset, int32 size) { engine->frameDirtyList.init(); return object; }
void *Frame::_close(void *object, int32 offset, int32 size) { return object; }
Frame*
Frame::create(void)
@ -227,7 +230,7 @@ void
Frame::syncDirty(void)
{
Frame *frame;
FORLIST(lnk, Frame::dirtyList){
FORLIST(lnk, engine->frameDirtyList){
frame = LLLinkGetData(lnk, Frame, inDirtyList);
if(frame->object.privateFlags & Frame::HIERARCHYSYNCLTM){
// Sync root's LTM
@ -247,7 +250,7 @@ Frame::syncDirty(void)
// all clean now
frame->object.privateFlags &= ~(Frame::SYNCLTM | Frame::SYNCOBJ);
}
Frame::dirtyList.init();
engine->frameDirtyList.init();
}
void
@ -283,7 +286,7 @@ Frame::updateObjects(void)
{
// Mark root as dirty and insert into dirty list if necessary
if((this->root->object.privateFlags & HIERARCHYSYNC) == 0)
Frame::dirtyList.add(&this->root->inDirtyList);
engine->frameDirtyList.add(&this->root->inDirtyList);
this->root->object.privateFlags |= HIERARCHYSYNC;
// Mark subtree as dirty as well
this->object.privateFlags |= SUBTREESYNC;

View File

@ -210,8 +210,8 @@ getSizeMesh(void *object, int32, int32)
void
registerMeshPlugin(void)
{
Geometry::registerPlugin(0, 0x50E, nil, nil, nil);
Geometry::registerPluginStream(0x50E, readMesh, writeMesh, getSizeMesh);
Geometry::registerPlugin(0, ID_MESH, nil, nil, nil);
Geometry::registerPluginStream(ID_MESH, readMesh, writeMesh, getSizeMesh);
}
// Returns the maximum number of triangles. Just so

View File

@ -22,7 +22,7 @@ namespace gl3 {
// TODO: make some of these things platform-independent
void*
static void*
driverOpen(void *o, int32, int32)
{
#ifdef RW_OPENGL
@ -38,28 +38,18 @@ driverOpen(void *o, int32, int32)
return o;
}
void*
static void*
driverClose(void *o, int32, int32)
{
return o;
}
void
initializePlatform(void)
registerPlatformPlugins(void)
{
Driver::registerPlugin(PLATFORM_GL3, 0, PLATFORM_GL3,
driverOpen, driverClose);
registerNativeRaster();
#ifdef RW_OPENGL
// uniforms need to be registered before any shaders are created
registerBlock("Scene");
registerBlock("Object");
registerBlock("State");
registerUniform("u_matColor");
registerUniform("u_surfaceProps");
#endif
}
}

View File

@ -60,12 +60,16 @@ struct UniformObject
UniformLight lights[MAX_LIGHTS];
};
GLuint vao;
GLuint ubo_state, ubo_scene, ubo_object;
GLuint whitetex;
UniformState uniformState;
UniformScene uniformScene;
UniformObject uniformObject;
static GLuint vao;
static GLuint ubo_state, ubo_scene, ubo_object;
static GLuint whitetex;
static UniformState uniformState;
static UniformScene uniformScene;
static UniformObject uniformObject;
int32 u_matColor;
int32 u_surfaceProps;
Shader *simpleShader;
@ -501,8 +505,11 @@ stopGLFW(void)
static int
initOpenGL(void)
{
#include "shaders/simple_gl3.inc"
simpleShader = Shader::fromStrings(simple_vert_src, simple_frag_src);
registerBlock("Scene");
registerBlock("Object");
registerBlock("State");
u_matColor = registerUniform("u_matColor");
u_surfaceProps = registerUniform("u_surfaceProps");
glClearColor(0.25, 0.25, 0.25, 1.0);
@ -511,6 +518,25 @@ initOpenGL(void)
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF};
glGenTextures(1, &whitetex);
glBindTexture(GL_TEXTURE_2D, whitetex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
0, GL_RGBA, GL_UNSIGNED_BYTE, &whitepixel);
im2DInit();
return 1;
}
static int
finalizeOpenGL(void)
{
#include "shaders/simple_gl3.inc"
simpleShader = Shader::fromStrings(simple_vert_src, simple_frag_src);
glGenBuffers(1, &ubo_state);
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("State"), ubo_state);
@ -532,15 +558,6 @@ initOpenGL(void)
GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0);
byte whitepixel[4] = {0xFF, 0xFF, 0xFF, 0xFF};
glGenTextures(1, &whitetex);
glBindTexture(GL_TEXTURE_2D, whitetex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1,
0, GL_RGBA, GL_UNSIGNED_BYTE, &whitepixel);
im2DInit();
return 1;
}
@ -552,6 +569,8 @@ deviceSystem(DeviceReq req, void *arg0)
return startGLFW((EngineStartParams*)arg0);
case DEVICEINIT:
return initOpenGL();
case DEVICEFINALIZE:
return finalizeOpenGL();
case DEVICESTOP:
return stopGLFW();
}

View File

@ -25,13 +25,19 @@ namespace gl3 {
#ifdef RW_OPENGL
#define U(i) currentShader->uniformLocations[i]
// MatFX
Shader *envShader;
static Shader *envShader;
static int32 u_texMatrix;
static int32 u_coefficient;
static void*
matfxOpen(void *o, int32, int32)
{
u_texMatrix = registerUniform("u_texMatrix");
u_coefficient = registerUniform("u_coefficient");
#include "shaders/matfx_gl3.inc"
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
envShader = Shader::fromStrings(matfx_env_vert_src, matfx_env_frag_src);
@ -49,11 +55,8 @@ initMatFX(void)
{
Driver::registerPlugin(PLATFORM_GL3, 0, ID_MATFX,
matfxOpen, matfxClose);
registerUniform("u_texMatrix");
registerUniform("u_coefficient");
}
#define U(s) currentShader->uniformLocations[findUniform(s)]
void
matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
@ -66,13 +69,13 @@ matfxDefaultRender(InstanceDataHeader *header, InstanceData *inst)
simpleShader->use();
convColor(&col, &m->color);
glUniform4fv(U("u_matColor"), 1, (GLfloat*)&col);
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
surfProps[0] = m->surfaceProps.ambient;
surfProps[1] = m->surfaceProps.specular;
surfProps[2] = m->surfaceProps.diffuse;
surfProps[3] = 0.0f;
glUniform4fv(U("u_surfaceProps"), 1, surfProps);
glUniform4fv(U(u_surfaceProps), 1, surfProps);
setTexture(0, m->texture);
@ -160,18 +163,18 @@ matfxEnvRender(InstanceDataHeader *header, InstanceData *inst)
envShader->use();
convColor(&col, &m->color);
glUniform4fv(U("u_matColor"), 1, (GLfloat*)&col);
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
surfProps[0] = m->surfaceProps.ambient;
surfProps[1] = m->surfaceProps.specular;
surfProps[2] = m->surfaceProps.diffuse;
surfProps[3] = 0.0f;
glUniform4fv(U("u_surfaceProps"), 1, surfProps);
glUniform4fv(U(u_surfaceProps), 1, surfProps);
glUniform1fv(U("u_coefficient"), 1, &env->coefficient);
glUniform1fv(U(u_coefficient), 1, &env->coefficient);
calcEnvTexMatrix(env->frame, texMat);
glUniformMatrix4fv(U("u_texMatrix"), 1, GL_FALSE, texMat);
glUniformMatrix4fv(U(u_texMatrix), 1, GL_FALSE, texMat);
setTexture(0, env->tex);
@ -232,11 +235,13 @@ makeMatFXPipeline(void)
// Skin
Shader *skinShader;
static Shader *skinShader;
static int32 u_boneMatrices;
static void*
skinOpen(void *o, int32, int32)
{
u_boneMatrices = registerUniform("u_boneMatrices");
#include "shaders/simple_gl3.inc"
#include "shaders/skin_gl3.inc"
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline();
@ -255,7 +260,6 @@ initSkin(void)
{
Driver::registerPlugin(PLATFORM_GL3, 0, ID_SKIN,
skinOpen, skinClose);
registerUniform("u_boneMatrices");
}
enum
@ -416,8 +420,6 @@ skinUninstanceCB(Geometry *geo, InstanceDataHeader *header)
assert(0 && "can't uninstance");
}
#define U(s) currentShader->uniformLocations[findUniform(s)]
static float skinMatrices[64*16];
void
@ -464,20 +466,20 @@ skinRenderCB(Atomic *atomic, InstanceDataHeader *header)
skinShader->use();
updateSkinMatrices(atomic);
glUniformMatrix4fv(U("u_boneMatrices"), 64, GL_FALSE,
glUniformMatrix4fv(U(u_boneMatrices), 64, GL_FALSE,
(GLfloat*)skinMatrices);
while(n--){
m = inst->material;
convColor(&col, &m->color);
glUniform4fv(U("u_matColor"), 1, (GLfloat*)&col);
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
surfProps[0] = m->surfaceProps.ambient;
surfProps[1] = m->surfaceProps.specular;
surfProps[2] = m->surfaceProps.diffuse;
surfProps[3] = 0.0f;
glUniform4fv(U("u_surfaceProps"), 1, surfProps);
glUniform4fv(U(u_surfaceProps), 1, surfProps);
setTexture(0, m->texture);

View File

@ -64,7 +64,7 @@ lightingCB(void)
setAmbientLight(&ambLight);
}
#define U(s) currentShader->uniformLocations[findUniform(s)]
#define U(i) currentShader->uniformLocations[i]
void
defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
@ -90,13 +90,13 @@ defaultRenderCB(Atomic *atomic, InstanceDataHeader *header)
m = inst->material;
convColor(&col, &m->color);
glUniform4fv(U("u_matColor"), 1, (GLfloat*)&col);
glUniform4fv(U(u_matColor), 1, (GLfloat*)&col);
surfProps[0] = m->surfaceProps.ambient;
surfProps[1] = m->surfaceProps.specular;
surfProps[2] = m->surfaceProps.diffuse;
surfProps[3] = 0.0f;
glUniform4fv(U("u_surfaceProps"), 1, surfProps);
glUniform4fv(U(u_surfaceProps), 1, surfProps);
setTexture(0, m->texture);

View File

@ -18,17 +18,20 @@ namespace gl3 {
UniformRegistry uniformRegistry;
int
int32
registerUniform(const char *name)
{
int i;
i = findUniform(name);
if(i >= 0) return i;
// TODO: print error
if(uniformRegistry.numUniforms+1 >= MAX_UNIFORMS)
return -1;
uniformRegistry.uniformNames[uniformRegistry.numUniforms] = strdup(name);
return uniformRegistry.numUniforms++;
}
int
int32
findUniform(const char *name)
{
int i;
@ -38,17 +41,20 @@ findUniform(const char *name)
return -1;
}
int
int32
registerBlock(const char *name)
{
int i;
i = findBlock(name);
if(i >= 0) return i;
// TODO: print error
if(uniformRegistry.numBlocks+1 >= MAX_BLOCKS)
return -1;
uniformRegistry.blockNames[uniformRegistry.numBlocks] = strdup(name);
return uniformRegistry.numBlocks++;
}
int
int32
findBlock(const char *name)
{
int i;

View File

@ -16,7 +16,7 @@ struct EngineStartParams
namespace gl3 {
void initializePlatform(void);
void registerPlatformPlugins(void);
extern Device renderdevice;
@ -46,6 +46,10 @@ enum AttribIndices
ATTRIB_TEXCOORDS7,
};
// default uniform indices
extern int32 u_matColor;
extern int32 u_surfaceProps;
struct InstanceData
{
uint32 numIndex;

View File

@ -11,17 +11,17 @@ enum {
struct UniformRegistry
{
int numUniforms;
int32 numUniforms;
char *uniformNames[MAX_UNIFORMS];
int numBlocks;
int32 numBlocks;
char *blockNames[MAX_BLOCKS];
};
int registerUniform(const char *name);
int findUniform(const char *name);
int registerBlock(const char *name);
int findBlock(const char *name);
int32 registerUniform(const char *name);
int32 findUniform(const char *name);
int32 registerBlock(const char *name);
int32 findBlock(const char *name);
extern UniformRegistry uniformRegistry;

View File

@ -4,7 +4,7 @@ namespace wdgl {
// NOTE: This is not really RW OpenGL! It's specific to WarDrum's GTA ports
void initializePlatform(void);
void registerPlatformPlugins(void);
struct AttribDesc
{

View File

@ -22,21 +22,21 @@
namespace rw {
namespace wdgl {
void*
static void*
driverOpen(void *o, int32, int32)
{
engine->driver[PLATFORM_WDGL]->defaultPipeline = makeDefaultPipeline();
return o;
}
void*
static void*
driverClose(void *o, int32, int32)
{
return o;
}
void
initializePlatform(void)
registerPlatformPlugins(void)
{
Driver::registerPlugin(PLATFORM_WDGL, 0, PLATFORM_WDGL,
driverOpen, driverClose);

View File

@ -315,17 +315,9 @@ assert(t >= in1->time && t <= in2->time);
out->q = slerp(in1->q, in2->q, a);
}
void
registerHAnimPlugin(void)
static void*
hanimOpen(void *object, int32 offset, int32 size)
{
hAnimOffset = Frame::registerPlugin(sizeof(HAnimData), ID_HANIM,
createHAnim,
destroyHAnim, copyHAnim);
Frame::registerPluginStream(ID_HANIM,
readHAnim,
writeHAnim,
getSizeHAnim);
AnimInterpolatorInfo *info = rwNewT(AnimInterpolatorInfo, 1, MEMDUR_GLOBAL | ID_HANIM);
info->id = 1;
info->interpKeyFrameSize = sizeof(HAnimInterpFrame);
@ -340,6 +332,21 @@ registerHAnimPlugin(void)
info->streamWrite = hAnimFrameWrite;
info->streamGetSize = hAnimFrameGetSize;
AnimInterpolatorInfo::registerInterp(info);
return object;
}
static void *hanimClose(void *object, int32 offset, int32 size) { return object; }
void
registerHAnimPlugin(void)
{
Engine::registerPlugin(0, ID_HANIM, hanimOpen, hanimClose);
hAnimOffset = Frame::registerPlugin(sizeof(HAnimData), ID_HANIM,
createHAnim,
destroyHAnim, copyHAnim);
Frame::registerPluginStream(ID_HANIM,
readHAnim,
writeHAnim,
getSizeHAnim);}
}

View File

@ -437,8 +437,8 @@ MatFX::enableEffects(Atomic *atomic)
atomic->pipeline = matFXGlobals.pipelines[rw::platform];
}
void
registerMatFXPlugin(void)
static void*
matfxOpen(void *o, int32, int32)
{
// init dummy pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
@ -446,7 +446,20 @@ registerMatFXPlugin(void)
defpipe->pluginData = 0;
for(uint i = 0; i < nelem(matFXGlobals.pipelines); i++)
matFXGlobals.pipelines[i] = defpipe;
return o;
}
static void*
matfxClose(void *o, int32, int32)
{
return o;
}
void
registerMatFXPlugin(void)
{
Driver::registerPlugin(PLATFORM_NULL, 0, ID_MATFX,
matfxOpen, matfxClose);
ps2::initMatFX();
xbox::initMatFX();
d3d8::initMatFX();

View File

@ -36,6 +36,8 @@ getPDSPipe(uint32 data)
void
registerPDSPipe(Pipeline *pipe)
{
if(pdsGlobals.pipes == nil)
pdsGlobals.pipes = rwNewT(Pipeline*, pdsGlobals.maxPipes, MEMDUR_GLOBAL | ID_PDS);
assert(pdsGlobals.numPipes < pdsGlobals.maxPipes);
pdsGlobals.pipes[pdsGlobals.numPipes++] = pipe;
}
@ -56,12 +58,22 @@ materialPDSRights(void *object, int32, int32, uint32 data)
// printf("mat pds: %x %x %x\n", data, m->pipeline->pluginID, m->pipeline->pluginData);
}
static void *pdsOpen(void *object, int32 offset, int32 size) { return object; }
static void*
pdsClose(void *object, int32 offset, int32 size)
{
// TODO MEMORY: free registered pipelines
rwFree(pdsGlobals.pipes);
return object;
}
void
registerPDSPlugin(int32 n)
{
pdsGlobals.maxPipes = n;
pdsGlobals.numPipes = 0;
pdsGlobals.pipes = rwNewT(Pipeline*, n, MEMDUR_GLOBAL | ID_PDS);
pdsGlobals.pipes = nil;
Engine::registerPlugin(0, ID_PDS, pdsOpen, pdsClose);
Atomic::registerPlugin(0, ID_PDS, nil, nil, nil);
Atomic::setStreamRightsCallback(ID_PDS, atomicPDSRights);

View File

@ -21,7 +21,7 @@
namespace rw {
namespace ps2 {
void*
static void*
driverOpen(void *o, int32, int32)
{
engine->driver[PLATFORM_PS2]->defaultPipeline = makeDefaultPipeline();
@ -34,14 +34,14 @@ driverOpen(void *o, int32, int32)
return o;
}
void*
static void*
driverClose(void *o, int32, int32)
{
return o;
}
void
initializePlatform(void)
registerPlatformPlugins(void)
{
Driver::registerPlugin(PLATFORM_PS2, 0, PLATFORM_PS2,
driverOpen, driverClose);

View File

@ -8,7 +8,7 @@ struct EngineStartParams
namespace ps2 {
void initializePlatform(void);
void registerPlatformPlugins(void);
extern Device renderdevice;

View File

@ -463,6 +463,12 @@ enum PluginID
ID_DRIVER = MAKEPLUGINID(VEND_DRIVER, 0),
};
enum CoreModuleID
{
ID_NAMODULE = MAKEPLUGINID(VEND_CRITERIONINT, 0x00),
ID_FRAMEMODULE = MAKEPLUGINID(VEND_CRITERIONINT, 0x03),
};
#define ECODE(c, s) c,
enum Errors

View File

@ -49,6 +49,8 @@ enum DeviceReq
DEVICESTART,
// Device initialization before Engine/Driver plugins are opened
DEVICEINIT,
// Device initialization after plugins are opened
DEVICEFINALIZE,
// Device/Context shutdown
DEVICESTOP,
};
@ -120,7 +122,6 @@ struct MemoryFunctions
// This is for platform independent things
// TODO: move more stuff into this
// TODO: make this have plugins and allocate in Engine::open
struct Engine
{
enum State {
@ -132,6 +133,7 @@ struct Engine
void *currentCamera;
void *currentWorld;
Texture *imtexture;
LinkList frameDirtyList;
TexDictionary *currentTexDictionary;
// load textures from files
@ -152,6 +154,12 @@ struct Engine
static void term(void);
static void close(void);
static void stop(void);
static PluginList s_plglist;
static int32 registerPlugin(int32 size, uint32 id,
Constructor ctor, Destructor dtor){
return s_plglist.registerPlugin(size, id, ctor, dtor, nil);
}
};
extern Engine *engine;

View File

@ -136,8 +136,10 @@ struct Frame
Frame *cloneAndLink(Frame *clonedroot);
void purgeClone(void);
static LinkList dirtyList;
#ifndef RWPUBLIC
static void *_open(void*, int32, int32);
static void *_close(void*, int32, int32);
#endif
static void syncDirty(void);
};

View File

@ -278,8 +278,8 @@ copySkinAtm(void *dst, void *src, int32 offset, int32)
return dst;
}
void
registerSkinPlugin(void)
static void*
skinOpen(void *o, int32, int32)
{
// init dummy pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
@ -287,7 +287,20 @@ registerSkinPlugin(void)
defpipe->pluginData = 1;
for(uint i = 0; i < nelem(skinGlobals.pipelines); i++)
skinGlobals.pipelines[i] = defpipe;
return o;
}
static void*
skinClose(void *o, int32, int32)
{
return o;
}
void
registerSkinPlugin(void)
{
Driver::registerPlugin(PLATFORM_NULL, 0, ID_SKIN,
skinOpen, skinClose);
ps2::initSkin();
xbox::initSkin();
d3d8::initSkin();

View File

@ -337,11 +337,18 @@ getSizeUVAnim(void *object, int32 offset, int32)
return size ? size + 12 + 4 : 0;
}
static void*
uvanimOpen(void *object, int32 offset, int32 size)
{
registerUVAnimInterpolator();
return object;
}
static void *uvanimClose(void *object, int32 offset, int32 size) { return object; }
void
registerUVAnimPlugin(void)
{
registerUVAnimInterpolator();
Engine::registerPlugin(0, ID_UVANIMATION, uvanimOpen, uvanimClose);
uvAnimOffset = Material::registerPlugin(sizeof(UVAnim), ID_UVANIMATION,
createUVAnim, destroyUVAnim, copyUVAnim);
Material::registerPluginStream(ID_UVANIMATION,

View File

@ -201,6 +201,22 @@ InitRW(void)
return true;
}
void
im2dtest(void)
{
static rw::gl3::Im2DVertex verts[] = {
{ -0.5, -0.5, 0.0, 255, 0, 0, 255, 0.0, 0.0 },
{ 0.5, -0.5, 0.0, 0, 255, 0, 255, 0.0, 0.0 },
{ -0.5, 0.5, 0.0, 0, 0, 255, 255, 0.0, 0.0 },
{ 0.5, 0.5, 0.0, 0, 255, 255, 255, 0.0, 0.0 },
};
static short indices[] = {
0, 1, 2, 3
};
rw::engine->device.im2DRenderIndexedPrimitive(rw::PRIMTYPETRISTRIP,
&verts, 4, &indices, 4);
}
void
Draw(float timeDelta)
{
@ -210,6 +226,7 @@ Draw(float timeDelta)
camera->m_rwcam->beginUpdate();
clump->render();
im2dtest();
camera->m_rwcam->endUpdate();
camera->m_rwcam->showRaster();