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]; static AnimInterpolatorInfo *interpInfoList[MAXINTERPINFO];
// TODO MEMORY: also clean it up again
void void
AnimInterpolatorInfo::registerInterp(AnimInterpolatorInfo *interpInfo) AnimInterpolatorInfo::registerInterp(AnimInterpolatorInfo *interpInfo)
{ {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ namespace gl3 {
// TODO: make some of these things platform-independent // TODO: make some of these things platform-independent
void* static void*
driverOpen(void *o, int32, int32) driverOpen(void *o, int32, int32)
{ {
#ifdef RW_OPENGL #ifdef RW_OPENGL
@ -38,28 +38,18 @@ driverOpen(void *o, int32, int32)
return o; return o;
} }
void* static void*
driverClose(void *o, int32, int32) driverClose(void *o, int32, int32)
{ {
return o; return o;
} }
void void
initializePlatform(void) registerPlatformPlugins(void)
{ {
Driver::registerPlugin(PLATFORM_GL3, 0, PLATFORM_GL3, Driver::registerPlugin(PLATFORM_GL3, 0, PLATFORM_GL3,
driverOpen, driverClose); driverOpen, driverClose);
registerNativeRaster(); 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]; UniformLight lights[MAX_LIGHTS];
}; };
GLuint vao; static GLuint vao;
GLuint ubo_state, ubo_scene, ubo_object; static GLuint ubo_state, ubo_scene, ubo_object;
GLuint whitetex; static GLuint whitetex;
UniformState uniformState; static UniformState uniformState;
UniformScene uniformScene; static UniformScene uniformScene;
UniformObject uniformObject; static UniformObject uniformObject;
int32 u_matColor;
int32 u_surfaceProps;
Shader *simpleShader; Shader *simpleShader;
@ -501,8 +505,11 @@ stopGLFW(void)
static int static int
initOpenGL(void) initOpenGL(void)
{ {
#include "shaders/simple_gl3.inc" registerBlock("Scene");
simpleShader = Shader::fromStrings(simple_vert_src, simple_frag_src); registerBlock("Object");
registerBlock("State");
u_matColor = registerUniform("u_matColor");
u_surfaceProps = registerUniform("u_surfaceProps");
glClearColor(0.25, 0.25, 0.25, 1.0); glClearColor(0.25, 0.25, 0.25, 1.0);
@ -511,6 +518,25 @@ initOpenGL(void)
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
glBindVertexArray(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); glGenBuffers(1, &ubo_state);
glBindBuffer(GL_UNIFORM_BUFFER, ubo_state); glBindBuffer(GL_UNIFORM_BUFFER, ubo_state);
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("State"), ubo_state); glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("State"), ubo_state);
@ -532,15 +558,6 @@ initOpenGL(void)
GL_DYNAMIC_DRAW); GL_DYNAMIC_DRAW);
glBindBuffer(GL_UNIFORM_BUFFER, 0); 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; return 1;
} }
@ -552,6 +569,8 @@ deviceSystem(DeviceReq req, void *arg0)
return startGLFW((EngineStartParams*)arg0); return startGLFW((EngineStartParams*)arg0);
case DEVICEINIT: case DEVICEINIT:
return initOpenGL(); return initOpenGL();
case DEVICEFINALIZE:
return finalizeOpenGL();
case DEVICESTOP: case DEVICESTOP:
return stopGLFW(); return stopGLFW();
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -11,17 +11,17 @@ enum {
struct UniformRegistry struct UniformRegistry
{ {
int numUniforms; int32 numUniforms;
char *uniformNames[MAX_UNIFORMS]; char *uniformNames[MAX_UNIFORMS];
int numBlocks; int32 numBlocks;
char *blockNames[MAX_BLOCKS]; char *blockNames[MAX_BLOCKS];
}; };
int registerUniform(const char *name); int32 registerUniform(const char *name);
int findUniform(const char *name); int32 findUniform(const char *name);
int registerBlock(const char *name); int32 registerBlock(const char *name);
int findBlock(const char *name); int32 findBlock(const char *name);
extern UniformRegistry uniformRegistry; 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 // NOTE: This is not really RW OpenGL! It's specific to WarDrum's GTA ports
void initializePlatform(void); void registerPlatformPlugins(void);
struct AttribDesc struct AttribDesc
{ {

View File

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

View File

@ -315,17 +315,9 @@ assert(t >= in1->time && t <= in2->time);
out->q = slerp(in1->q, in2->q, a); out->q = slerp(in1->q, in2->q, a);
} }
void static void*
registerHAnimPlugin(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); AnimInterpolatorInfo *info = rwNewT(AnimInterpolatorInfo, 1, MEMDUR_GLOBAL | ID_HANIM);
info->id = 1; info->id = 1;
info->interpKeyFrameSize = sizeof(HAnimInterpFrame); info->interpKeyFrameSize = sizeof(HAnimInterpFrame);
@ -340,6 +332,21 @@ registerHAnimPlugin(void)
info->streamWrite = hAnimFrameWrite; info->streamWrite = hAnimFrameWrite;
info->streamGetSize = hAnimFrameGetSize; info->streamGetSize = hAnimFrameGetSize;
AnimInterpolatorInfo::registerInterp(info); 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]; atomic->pipeline = matFXGlobals.pipelines[rw::platform];
} }
void static void*
registerMatFXPlugin(void) matfxOpen(void *o, int32, int32)
{ {
// init dummy pipelines // init dummy pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
@ -446,7 +446,20 @@ registerMatFXPlugin(void)
defpipe->pluginData = 0; defpipe->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] = 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(); ps2::initMatFX();
xbox::initMatFX(); xbox::initMatFX();
d3d8::initMatFX(); d3d8::initMatFX();

View File

@ -36,6 +36,8 @@ getPDSPipe(uint32 data)
void void
registerPDSPipe(Pipeline *pipe) registerPDSPipe(Pipeline *pipe)
{ {
if(pdsGlobals.pipes == nil)
pdsGlobals.pipes = rwNewT(Pipeline*, pdsGlobals.maxPipes, MEMDUR_GLOBAL | ID_PDS);
assert(pdsGlobals.numPipes < pdsGlobals.maxPipes); assert(pdsGlobals.numPipes < pdsGlobals.maxPipes);
pdsGlobals.pipes[pdsGlobals.numPipes++] = pipe; 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); // 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 void
registerPDSPlugin(int32 n) registerPDSPlugin(int32 n)
{ {
pdsGlobals.maxPipes = n; pdsGlobals.maxPipes = n;
pdsGlobals.numPipes = 0; 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::registerPlugin(0, ID_PDS, nil, nil, nil);
Atomic::setStreamRightsCallback(ID_PDS, atomicPDSRights); Atomic::setStreamRightsCallback(ID_PDS, atomicPDSRights);

View File

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

View File

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

View File

@ -463,6 +463,12 @@ enum PluginID
ID_DRIVER = MAKEPLUGINID(VEND_DRIVER, 0), 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, #define ECODE(c, s) c,
enum Errors enum Errors

View File

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

View File

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

View File

@ -278,8 +278,8 @@ copySkinAtm(void *dst, void *src, int32 offset, int32)
return dst; return dst;
} }
void static void*
registerSkinPlugin(void) skinOpen(void *o, int32, int32)
{ {
// init dummy pipelines // init dummy pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
@ -287,7 +287,20 @@ registerSkinPlugin(void)
defpipe->pluginData = 1; defpipe->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] = 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(); ps2::initSkin();
xbox::initSkin(); xbox::initSkin();
d3d8::initSkin(); d3d8::initSkin();

View File

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

View File

@ -201,6 +201,22 @@ InitRW(void)
return true; 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 void
Draw(float timeDelta) Draw(float timeDelta)
{ {
@ -210,6 +226,7 @@ Draw(float timeDelta)
camera->m_rwcam->beginUpdate(); camera->m_rwcam->beginUpdate();
clump->render(); clump->render();
im2dtest();
camera->m_rwcam->endUpdate(); camera->m_rwcam->endUpdate();
camera->m_rwcam->showRaster(); camera->m_rwcam->showRaster();