more work on initialization

This commit is contained in:
aap 2016-06-25 23:14:18 +02:00
parent a906d58bcb
commit dd901ebfa3
14 changed files with 132 additions and 80 deletions

View File

@ -28,7 +28,7 @@ int32 build = 0xFFFF;
#elif RW_D3D9 #elif RW_D3D9
int32 platform = PLATFORM_D3D9; int32 platform = PLATFORM_D3D9;
#else #else
int32 platform = PLATFORM_nil; int32 platform = PLATFORM_NULL;
#endif #endif
char *debugFile = nil; char *debugFile = nil;

View File

@ -586,14 +586,9 @@ copyNativeRaster(void *dst, void *, int32 offset, int32)
return dst; return dst;
} }
void static void*
registerNativeRaster(void) nativeOpen(void*, int32, int32)
{ {
nativeRasterOffset = Raster::registerPlugin(sizeof(D3dRaster),
0x12340000 | PLATFORM_D3D9,
createNativeRaster,
destroyNativeRaster,
copyNativeRaster);
driver[PLATFORM_D3D8].rasterNativeOffset = nativeRasterOffset; driver[PLATFORM_D3D8].rasterNativeOffset = nativeRasterOffset;
driver[PLATFORM_D3D8].rasterCreate = rasterCreate; driver[PLATFORM_D3D8].rasterCreate = rasterCreate;
driver[PLATFORM_D3D8].rasterLock = rasterLock; driver[PLATFORM_D3D8].rasterLock = rasterLock;
@ -609,5 +604,22 @@ registerNativeRaster(void)
driver[PLATFORM_D3D9].rasterFromImage = rasterFromImage; driver[PLATFORM_D3D9].rasterFromImage = rasterFromImage;
} }
static void*
nativeClose(void*, int32, int32)
{
printf("d3d native close\n");
}
void
registerNativeRaster(void)
{
Engine::registerPlugin(0, ID_RASTERD3D9, nativeOpen, nativeClose);
nativeRasterOffset = Raster::registerPlugin(sizeof(D3dRaster),
ID_RASTERD3D9,
createNativeRaster,
destroyNativeRaster,
copyNativeRaster);
}
} }
} }

View File

@ -21,6 +21,8 @@ using namespace d3d;
void void
initializePlatform(void) initializePlatform(void)
{ {
if(nativeRasterOffset == 0)
registerNativeRaster();
driver[PLATFORM_D3D8].defaultPipeline = makeDefaultPipeline(); driver[PLATFORM_D3D8].defaultPipeline = makeDefaultPipeline();
} }

View File

@ -28,6 +28,8 @@ using namespace d3d;
void void
initializePlatform(void) initializePlatform(void)
{ {
if(nativeRasterOffset == 0)
registerNativeRaster();
driver[PLATFORM_D3D9].defaultPipeline = makeDefaultPipeline(); driver[PLATFORM_D3D9].defaultPipeline = makeDefaultPipeline();
} }

View File

@ -20,6 +20,7 @@ namespace xbox {
void void
initializePlatform(void) initializePlatform(void)
{ {
registerNativeRaster();
driver[PLATFORM_XBOX].defaultPipeline = makeDefaultPipeline(); driver[PLATFORM_XBOX].defaultPipeline = makeDefaultPipeline();
} }
@ -899,14 +900,9 @@ copyNativeRaster(void *dst, void *, int32 offset, int32)
return dst; return dst;
} }
void static void*
registerNativeRaster(void) nativeOpen(void*, int32, int32)
{ {
nativeRasterOffset = Raster::registerPlugin(sizeof(XboxRaster),
0x12340000 | PLATFORM_XBOX,
createNativeRaster,
destroyNativeRaster,
copyNativeRaster);
driver[PLATFORM_XBOX].rasterNativeOffset = nativeRasterOffset; driver[PLATFORM_XBOX].rasterNativeOffset = nativeRasterOffset;
driver[PLATFORM_XBOX].rasterCreate = rasterCreate; driver[PLATFORM_XBOX].rasterCreate = rasterCreate;
driver[PLATFORM_XBOX].rasterLock = rasterLock; driver[PLATFORM_XBOX].rasterLock = rasterLock;
@ -914,6 +910,23 @@ registerNativeRaster(void)
driver[PLATFORM_XBOX].rasterNumLevels = rasterNumLevels; driver[PLATFORM_XBOX].rasterNumLevels = rasterNumLevels;
} }
static void*
nativeClose(void*, int32, int32)
{
printf("xbox native close\n");
}
void
registerNativeRaster(void)
{
Engine::registerPlugin(0, ID_RASTERXBOX, nativeOpen, nativeClose);
nativeRasterOffset = Raster::registerPlugin(sizeof(XboxRaster),
ID_RASTERXBOX,
createNativeRaster,
destroyNativeRaster,
copyNativeRaster);
}
Texture* Texture*
readNativeTexture(Stream *stream) readNativeTexture(Stream *stream)
{ {

View File

@ -25,7 +25,7 @@ PluginList Engine::s_plglist = {sizeof(Engine), sizeof(Engine), nil, nil};
void void
Engine::init(void) Engine::init(void)
{ {
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_nil); ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
for(uint i = 0; i < NUM_PLATFORMS; i++){ for(uint i = 0; i < NUM_PLATFORMS; i++){
driver[i].defaultPipeline = defpipe; driver[i].defaultPipeline = defpipe;
@ -40,10 +40,12 @@ Engine::init(void)
} }
Frame::dirtyList.init(); Frame::dirtyList.init();
rw::gl3::registerNativeRaster(); ps2::initializePlatform();
rw::ps2::registerNativeRaster(); xbox::initializePlatform();
rw::xbox::registerNativeRaster(); d3d8::initializePlatform();
rw::d3d::registerNativeRaster(); d3d9::initializePlatform();
wdgl::initializePlatform();
gl3::initializePlatform();
} }
void void
@ -51,13 +53,6 @@ Engine::open(void)
{ {
rw::engine = (Engine*)malloc(s_plglist.size); rw::engine = (Engine*)malloc(s_plglist.size);
s_plglist.construct(rw::engine); s_plglist.construct(rw::engine);
ps2::initializePlatform();
xbox::initializePlatform();
d3d8::initializePlatform();
d3d9::initializePlatform();
gl3::initializePlatform();
wdgl::initializePlatform();
} }
namespace null { namespace null {

View File

@ -24,10 +24,15 @@ namespace gl3 {
void void
initializePlatform(void) initializePlatform(void)
{ {
registerNativeRaster();
#ifdef RW_OPENGL #ifdef RW_OPENGL
driver[PLATFORM_GL3].defaultPipeline = makeDefaultPipeline(); driver[PLATFORM_GL3].defaultPipeline = makeDefaultPipeline();
matFXGlobals.pipelines[PLATFORM_GL3] = makeMatFXPipeline();
skinGlobals.pipelines[PLATFORM_GL3] = makeSkinPipeline(); // uniforms need to be registered before any shaders are created
registerBlock("Scene");
registerBlock("Object");
registerUniform("u_matColor");
registerUniform("u_surfaceProps");
#endif #endif
initializeRender(); initializeRender();

View File

@ -113,7 +113,7 @@ copyNativeRaster(void *dst, void *, int32 offset, int32)
} }
static void* static void*
nativeOpen(void*, int32 offset, int32) nativeOpen(void*, int32, int32)
{ {
driver[PLATFORM_GL3].rasterNativeOffset = nativeRasterOffset; driver[PLATFORM_GL3].rasterNativeOffset = nativeRasterOffset;
driver[PLATFORM_GL3].rasterCreate = rasterCreate; driver[PLATFORM_GL3].rasterCreate = rasterCreate;
@ -124,16 +124,16 @@ nativeOpen(void*, int32 offset, int32)
} }
static void* static void*
nativeClose(void*, int32 offset, int32) nativeClose(void*, int32, int32)
{ {
printf("native close\n"); printf("gl3 native close\n");
} }
void registerNativeRaster(void) void registerNativeRaster(void)
{ {
Engine::registerPlugin(0, 0x1234, nativeOpen, nativeClose); Engine::registerPlugin(0, ID_RASTERGL3, nativeOpen, nativeClose);
nativeRasterOffset = Raster::registerPlugin(sizeof(Gl3Raster), nativeRasterOffset = Raster::registerPlugin(sizeof(Gl3Raster),
0x12340000 | PLATFORM_GL3, ID_RASTERGL3,
createNativeRaster, createNativeRaster,
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);

View File

@ -125,11 +125,6 @@ initializeRender(void)
glGenVertexArrays(1, &vao); glGenVertexArrays(1, &vao);
glBindVertexArray(vao); glBindVertexArray(vao);
registerBlock("Scene");
registerBlock("Object");
registerUniform("u_matColor");
registerUniform("u_surfaceProps");
glGenBuffers(1, &ubo_scene); glGenBuffers(1, &ubo_scene);
glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene); glBindBuffer(GL_UNIFORM_BUFFER, ubo_scene);
glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("Scene"), ubo_scene); glBindBufferBase(GL_UNIFORM_BUFFER, gl3::findBlock("Scene"), ubo_scene);

View File

@ -716,7 +716,7 @@ void
registerNativeRaster(void) registerNativeRaster(void)
{ {
nativeRasterOffset = Raster::registerPlugin(sizeof(GlRaster), nativeRasterOffset = Raster::registerPlugin(sizeof(GlRaster),
0x12340000 | PLATFORM_WDGL, ID_RASTERWDGL,
createNativeRaster, createNativeRaster,
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);

View File

@ -15,6 +15,7 @@
#include "d3d/rwd3d8.h" #include "d3d/rwd3d8.h"
#include "d3d/rwd3d9.h" #include "d3d/rwd3d9.h"
#include "gl/rwwdgl.h" #include "gl/rwwdgl.h"
#include "gl/rwgl3.h"
#define PLUGIN_ID 2 #define PLUGIN_ID 2
@ -717,21 +718,23 @@ skinRights(void *object, int32, int32, uint32)
void void
registerSkinPlugin(void) registerSkinPlugin(void)
{ {
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_nil); ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
defpipe->pluginID = ID_SKIN; defpipe->pluginID = ID_SKIN;
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;
skinGlobals.pipelines[PLATFORM_PS2] = skinGlobals.pipelines[PLATFORM_PS2] =
ps2::makeSkinPipeline(); ps2::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_WDGL] =
wdgl::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_XBOX] = skinGlobals.pipelines[PLATFORM_XBOX] =
xbox::makeSkinPipeline(); xbox::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_D3D8] = skinGlobals.pipelines[PLATFORM_D3D8] =
d3d8::makeSkinPipeline(); d3d8::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_D3D9] = skinGlobals.pipelines[PLATFORM_D3D9] =
d3d9::makeSkinPipeline(); d3d9::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_WDGL] =
wdgl::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_GL3] =
gl3::makeSkinPipeline();
skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN, skinGlobals.offset = Geometry::registerPlugin(sizeof(Skin*), ID_SKIN,
createSkin, createSkin,
@ -1220,21 +1223,23 @@ MatFX::enableEffects(Atomic *atomic)
void void
registerMatFXPlugin(void) registerMatFXPlugin(void)
{ {
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_nil); ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
defpipe->pluginID = 0; //ID_MATFX; defpipe->pluginID = 0; //ID_MATFX;
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;
matFXGlobals.pipelines[PLATFORM_PS2] = matFXGlobals.pipelines[PLATFORM_PS2] =
ps2::makeMatFXPipeline(); ps2::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_WDGL] =
wdgl::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_XBOX] = matFXGlobals.pipelines[PLATFORM_XBOX] =
xbox::makeMatFXPipeline(); xbox::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_D3D8] = matFXGlobals.pipelines[PLATFORM_D3D8] =
d3d8::makeMatFXPipeline(); d3d8::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_D3D9] = matFXGlobals.pipelines[PLATFORM_D3D9] =
d3d9::makeMatFXPipeline(); d3d9::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_WDGL] =
wdgl::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_GL3] =
gl3::makeMatFXPipeline();
matFXGlobals.atomicOffset = matFXGlobals.atomicOffset =
Atomic::registerPlugin(sizeof(int32), ID_MATFX, Atomic::registerPlugin(sizeof(int32), ID_MATFX,

View File

@ -21,6 +21,7 @@ namespace ps2 {
void void
initializePlatform(void) initializePlatform(void)
{ {
registerNativeRaster();
driver[PLATFORM_PS2].defaultPipeline = makeDefaultPipeline(); driver[PLATFORM_PS2].defaultPipeline = makeDefaultPipeline();
} }

View File

@ -477,7 +477,7 @@ getSizeMipmap(void*, int32, int32)
} }
static void* static void*
nativeOpen(void*, int32 offset, int32) nativeOpen(void*, int32, int32)
{ {
driver[PLATFORM_PS2].rasterNativeOffset = nativeRasterOffset; driver[PLATFORM_PS2].rasterNativeOffset = nativeRasterOffset;
driver[PLATFORM_PS2].rasterCreate = rasterCreate; driver[PLATFORM_PS2].rasterCreate = rasterCreate;
@ -487,19 +487,20 @@ nativeOpen(void*, int32 offset, int32)
} }
static void* static void*
nativeClose(void*, int32 offset, int32) nativeClose(void*, int32, int32)
{ {
printf("ps2 native close\n");
} }
void void
registerNativeRaster(void) registerNativeRaster(void)
{ {
Engine::registerPlugin(0, ID_RASTERPS2, nativeOpen, nativeClose);
nativeRasterOffset = Raster::registerPlugin(sizeof(Ps2Raster), nativeRasterOffset = Raster::registerPlugin(sizeof(Ps2Raster),
0x12340000 | PLATFORM_PS2, ID_RASTERPS2,
createNativeRaster, createNativeRaster,
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);
Engine::registerPlugin(0, 0x1234, nativeOpen, nativeClose);
Texture::registerPlugin(0, ID_SKYMIPMAP, nil, nil, nil); Texture::registerPlugin(0, ID_SKYMIPMAP, nil, nil, nil);
Texture::registerPluginStream(ID_SKYMIPMAP, readMipmap, writeMipmap, getSizeMipmap); Texture::registerPluginStream(ID_SKYMIPMAP, readMipmap, writeMipmap, getSizeMipmap);

View File

@ -255,7 +255,7 @@ public:
enum Platform enum Platform
{ {
PLATFORM_nil = 0, PLATFORM_NULL = 0,
// D3D7 // D3D7
PLATFORM_GL = 2, PLATFORM_GL = 2,
// MAC // MAC
@ -276,42 +276,63 @@ enum Platform
FOURCC_PS2 = 0x00325350 // 'PS2\0' FOURCC_PS2 = 0x00325350 // 'PS2\0'
}; };
#define MAKEPLUGINID(v, id) (((v & 0xFFFFFF) << 8) | (id & 0xFF))
enum VendorID
{
VEND_CORE = 0,
VEND_CRITERIONTK = 1,
VEND_CRITERIONINT = 4,
VEND_CRITERIONWORLD = 5,
// Used for platform-specific stuff like rasters
VEND_PLATFORM = 10,
};
enum PluginID enum PluginID
{ {
// Core // Core
ID_NAOBJECT = 0x0, ID_NAOBJECT = MAKEPLUGINID(VEND_CORE, 0x00),
ID_STRUCT = 0x1, ID_STRUCT = MAKEPLUGINID(VEND_CORE, 0x01),
ID_STRING = 0x2, ID_STRING = MAKEPLUGINID(VEND_CORE, 0x02),
ID_EXTENSION = 0x3, ID_EXTENSION = MAKEPLUGINID(VEND_CORE, 0x03),
ID_CAMERA = 0x5, ID_CAMERA = MAKEPLUGINID(VEND_CORE, 0x05),
ID_TEXTURE = 0x6, ID_TEXTURE = MAKEPLUGINID(VEND_CORE, 0x06),
ID_MATERIAL = 0x7, ID_MATERIAL = MAKEPLUGINID(VEND_CORE, 0x07),
ID_MATLIST = 0x8, ID_MATLIST = MAKEPLUGINID(VEND_CORE, 0x08),
ID_FRAMELIST = 0xE, ID_FRAMELIST = MAKEPLUGINID(VEND_CORE, 0x0E),
ID_GEOMETRY = 0xF, ID_GEOMETRY = MAKEPLUGINID(VEND_CORE, 0x0F),
ID_CLUMP = 0x10, ID_CLUMP = MAKEPLUGINID(VEND_CORE, 0x10),
ID_LIGHT = 0x12, ID_LIGHT = MAKEPLUGINID(VEND_CORE, 0x12),
ID_ATOMIC = 0x14, ID_ATOMIC = MAKEPLUGINID(VEND_CORE, 0x14),
ID_TEXTURENATIVE = 0x15, ID_TEXTURENATIVE = MAKEPLUGINID(VEND_CORE, 0x15),
ID_TEXDICTIONARY = 0x16, ID_TEXDICTIONARY = MAKEPLUGINID(VEND_CORE, 0x16),
ID_GEOMETRYLIST = 0x1A, ID_GEOMETRYLIST = MAKEPLUGINID(VEND_CORE, 0x1A),
ID_ANIMANIMATION = 0x1B, ID_ANIMANIMATION = MAKEPLUGINID(VEND_CORE, 0x1B),
ID_RIGHTTORENDER = 0x1F, ID_RIGHTTORENDER = MAKEPLUGINID(VEND_CORE, 0x1F),
ID_UVANIMDICT = 0x2B, ID_UVANIMDICT = MAKEPLUGINID(VEND_CORE, 0x2B),
// Toolkit // Toolkit
ID_SKYMIPMAP = 0x110, ID_SKYMIPMAP = MAKEPLUGINID(VEND_CRITERIONTK, 0x10),
ID_SKIN = 0x116, ID_SKIN = MAKEPLUGINID(VEND_CRITERIONTK, 0x16),
ID_HANIMPLUGIN = 0x11E, ID_HANIMPLUGIN = MAKEPLUGINID(VEND_CRITERIONTK, 0x1E),
ID_MATFX = 0x120, ID_MATFX = MAKEPLUGINID(VEND_CRITERIONTK, 0x20),
ID_PDS = 0x131, ID_PDS = MAKEPLUGINID(VEND_CRITERIONTK, 0x31),
ID_ADC = 0x134, ID_ADC = MAKEPLUGINID(VEND_CRITERIONTK, 0x34),
ID_UVANIMATION = 0x135, ID_UVANIMATION = MAKEPLUGINID(VEND_CRITERIONTK, 0x35),
// World // World
ID_MESH = 0x50E, ID_MESH = MAKEPLUGINID(VEND_CRITERIONWORLD, 0x0E),
ID_NATIVEDATA = 0x510, ID_NATIVEDATA = MAKEPLUGINID(VEND_CRITERIONWORLD, 0x10),
ID_VERTEXFMT = 0x511, ID_VERTEXFMT = MAKEPLUGINID(VEND_CRITERIONWORLD, 0x11),
// custom native raster
ID_RASTERGL = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_GL),
ID_RASTERPS2 = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_PS2),
ID_RASTERXBOX = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_XBOX),
ID_RASTERD3D8 = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_D3D8),
ID_RASTERD3D9 = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_D3D9),
ID_RASTERWDGL = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_WDGL),
ID_RASTERGL3 = MAKEPLUGINID(VEND_PLATFORM, PLATFORM_GL3),
}; };
#define ECODE(c, s) c, #define ECODE(c, s) c,