more tidying up

This commit is contained in:
aap 2016-06-16 15:35:45 +02:00
parent 7a4fcce861
commit 416ee91bb7
21 changed files with 187 additions and 164 deletions

2
rw.h
View File

@ -13,4 +13,4 @@
#include "src/rwd3d.h" #include "src/rwd3d.h"
#include "src/rwd3d8.h" #include "src/rwd3d8.h"
#include "src/rwd3d9.h" #include "src/rwd3d9.h"
#include "src/rwogl.h" #include "src/rwwdgl.h"

View File

@ -10,10 +10,10 @@
#include "rwobjects.h" #include "rwobjects.h"
#include "rwengine.h" #include "rwengine.h"
#include "rwps2.h" #include "rwps2.h"
#include "rwogl.h"
#include "rwxbox.h" #include "rwxbox.h"
#include "rwd3d8.h" #include "rwd3d8.h"
#include "rwd3d9.h" #include "rwd3d9.h"
#include "rwwdgl.h"
using namespace std; using namespace std;

View File

@ -352,9 +352,10 @@ deleteObject(void *object)
int32 nativeRasterOffset; int32 nativeRasterOffset;
void static void
D3dRaster::create(Raster *raster) rasterCreate(Raster *raster)
{ {
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
static uint32 formatMap[] = { static uint32 formatMap[] = {
0, 0,
D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5,
@ -384,45 +385,49 @@ D3dRaster::create(Raster *raster)
uint32 format; uint32 format;
if(raster->format & (Raster::PAL4 | Raster::PAL8)){ if(raster->format & (Raster::PAL4 | Raster::PAL8)){
format = D3DFMT_P8; format = D3DFMT_P8;
this->palette = new uint8[4*256]; natras->palette = new uint8[4*256];
}else }else
format = formatMap[(raster->format >> 8) & 0xF]; format = formatMap[(raster->format >> 8) & 0xF];
this->format = 0; natras->format = 0;
this->hasAlpha = alphaMap[(raster->format >> 8) & 0xF]; natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
int32 levels = Raster::calculateNumLevels(raster->width, raster->height); int32 levels = Raster::calculateNumLevels(raster->width, raster->height);
this->texture = createTexture(raster->width, raster->height, natras->texture = createTexture(raster->width, raster->height,
raster->format & Raster::MIPMAP ? levels : 1, raster->format & Raster::MIPMAP ? levels : 1,
format); format);
} }
uint8* static uint8*
D3dRaster::lock(Raster*, int32 level) rasterLock(Raster *raster, int32 level)
{ {
return lockTexture(this->texture, level); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
return lockTexture(natras->texture, level);
} }
void static void
D3dRaster::unlock(Raster*, int32 level) rasterUnlock(Raster *raster, int32 level)
{ {
unlockTexture(this->texture, level); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
unlockTexture(natras->texture, level);
} }
int32 static int32
D3dRaster::getNumLevels(Raster*) rasterNumLevels(Raster *raster)
{ {
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
#ifdef RW_D3D9 #ifdef RW_D3D9
IDirect3DTexture9 *tex = (IDirect3DTexture9*)this->texture; IDirect3DTexture9 *tex = (IDirect3DTexture9*)natras->texture;
return tex->GetLevelCount(); return tex->GetLevelCount();
#else #else
RasterLevels *levels = (RasterLevels*)this->texture; RasterLevels *levels = (RasterLevels*)natras->texture;
return levels->numlevels; return levels->numlevels;
#endif #endif
} }
void static void
D3dRaster::fromImage(Raster *raster, Image *image) rasterFromImage(Raster *raster, Image *image)
{ {
int32 format; int32 format;
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
switch(image->depth){ switch(image->depth){
case 32: case 32:
format = image->hasAlpha() ? Raster::C8888 : Raster::C888; format = image->hasAlpha() ? Raster::C8888 : Raster::C888;
@ -447,7 +452,7 @@ D3dRaster::fromImage(Raster *raster, Image *image)
raster->type = format & 0x7; raster->type = format & 0x7;
raster->flags = format & 0xF8; raster->flags = format & 0xF8;
raster->format = format & 0xFF00; raster->format = format & 0xFF00;
this->create(raster); rasterCreate(raster);
uint8 *in, *out; uint8 *in, *out;
int pallength = 0; int pallength = 0;
@ -457,7 +462,7 @@ D3dRaster::fromImage(Raster *raster, Image *image)
pallength = 256; pallength = 256;
if(pallength){ if(pallength){
in = image->palette; in = image->palette;
out = (uint8*)this->palette; out = (uint8*)natras->palette;
for(int32 i = 0; i < pallength; i++){ for(int32 i = 0; i < pallength; i++){
out[0] = in[2]; out[0] = in[2];
out[1] = in[1]; out[1] = in[1];
@ -595,7 +600,18 @@ registerNativeRaster(void)
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);
engine[PLATFORM_D3D8].rasterNativeOffset = nativeRasterOffset; engine[PLATFORM_D3D8].rasterNativeOffset = nativeRasterOffset;
engine[PLATFORM_D3D8].rasterCreate = rasterCreate;
engine[PLATFORM_D3D8].rasterLock = rasterLock;
engine[PLATFORM_D3D8].rasterUnlock = rasterUnlock;
engine[PLATFORM_D3D8].rasterNumLevels = rasterNumLevels;
engine[PLATFORM_D3D8].rasterFromImage = rasterFromImage;
engine[PLATFORM_D3D9].rasterNativeOffset = nativeRasterOffset; engine[PLATFORM_D3D9].rasterNativeOffset = nativeRasterOffset;
engine[PLATFORM_D3D9].rasterCreate = rasterCreate;
engine[PLATFORM_D3D9].rasterLock = rasterLock;
engine[PLATFORM_D3D9].rasterUnlock = rasterUnlock;
engine[PLATFORM_D3D9].rasterNumLevels = rasterNumLevels;
engine[PLATFORM_D3D9].rasterFromImage = rasterFromImage;
} }
} }

View File

@ -7,6 +7,7 @@
#include "rwplg.h" #include "rwplg.h"
#include "rwpipeline.h" #include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwengine.h"
#include "rwd3d.h" #include "rwd3d.h"
#include "rwd3d8.h" #include "rwd3d8.h"
@ -16,6 +17,12 @@ namespace rw {
namespace d3d8 { namespace d3d8 {
using namespace d3d; using namespace d3d;
void
initializePlatform(void)
{
engine[PLATFORM_D3D8].defaultPipeline = makeDefaultPipeline();
}
uint32 uint32
makeFVFDeclaration(uint32 flags, int32 numTex) makeFVFDeclaration(uint32 flags, int32 numTex)
{ {

View File

@ -7,6 +7,7 @@
#include "rwplg.h" #include "rwplg.h"
#include "rwpipeline.h" #include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwengine.h"
#include "rwd3d.h" #include "rwd3d.h"
#include "rwd3d9.h" #include "rwd3d9.h"
@ -21,6 +22,12 @@ using namespace d3d;
#define NUMDECLELT 12 #define NUMDECLELT 12
void
initializePlatform(void)
{
engine[PLATFORM_D3D9].defaultPipeline = makeDefaultPipeline();
}
void* void*
createVertexDeclaration(VertexElement *elements) createVertexDeclaration(VertexElement *elements)
{ {

View File

@ -9,7 +9,7 @@
namespace rw { namespace rw {
Engine engines[NUM_PLATFORMS]; Engine engine[NUM_PLATFORMS];
namespace null { namespace null {
@ -33,7 +33,7 @@ rasterUnlock(Raster*, int32)
} }
int32 int32
rasterNumLevels(Raster*, int32) rasterNumLevels(Raster*)
{ {
assert(0 && "rasterNumLevels not implemented"); assert(0 && "rasterNumLevels not implemented");
return 0; return 0;

View File

@ -644,13 +644,7 @@ Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platf
raster->texels = raster->palette = NULL; raster->texels = raster->palette = NULL;
raster->constructPlugins(); raster->constructPlugins();
int32 offset = engine[raster->platform].rasterNativeOffset; engine[raster->platform].rasterCreate(raster);
assert(offset != 0 && "unimplemented raster platform");
printf("%X %d\n", offset, raster->platform);
NativeRaster *nr = PLUGINOFFSET(NativeRaster, raster, offset);
printf("%p\n", nr);
nr->create(raster);
printf("created\n");
return raster; return raster;
} }
@ -666,28 +660,19 @@ Raster::destroy(void)
uint8* uint8*
Raster::lock(int32 level) Raster::lock(int32 level)
{ {
int32 offset = engine[this->platform].rasterNativeOffset; return engine[this->platform].rasterLock(this, level);
assert(offset != 0 && "unimplemented raster platform");
NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset);
return nr->lock(this, level);
} }
void void
Raster::unlock(int32 level) Raster::unlock(int32 level)
{ {
int32 offset = engine[this->platform].rasterNativeOffset; engine[this->platform].rasterUnlock(this, level);
assert(offset != 0 && "unimplemented raster platform");
NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset);
nr->unlock(this, level);
} }
int32 int32
Raster::getNumLevels(void) Raster::getNumLevels(void)
{ {
int32 offset = engine[this->platform].rasterNativeOffset; return engine[this->platform].rasterNumLevels(this);
assert(offset != 0 && "unimplemented raster platform");
NativeRaster *nr = PLUGINOFFSET(NativeRaster, this, offset);
return nr->getNumLevels(this);
} }
int32 int32
@ -705,10 +690,7 @@ Raster::createFromImage(Image *image)
{ {
Raster *raster = Raster::create(image->width, image->height, Raster *raster = Raster::create(image->width, image->height,
image->depth, 4 | 0x80); image->depth, 4 | 0x80);
int32 offset = engine[raster->platform].rasterNativeOffset; engine[raster->platform].rasterFromImage(raster, image);
assert(offset != 0 && "unimplemented raster platform");
NativeRaster *nr = PLUGINOFFSET(NativeRaster, raster, offset);
nr->fromImage(raster, image);
return raster; return raster;
} }

View File

@ -10,10 +10,10 @@
#include "rwplugins.h" #include "rwplugins.h"
#include "rwps2.h" #include "rwps2.h"
#include "rwps2plg.h" #include "rwps2plg.h"
#include "rwogl.h"
#include "rwxbox.h" #include "rwxbox.h"
#include "rwd3d8.h" #include "rwd3d8.h"
#include "rwd3d9.h" #include "rwd3d9.h"
#include "rwwdgl.h"
using namespace std; using namespace std;
@ -336,7 +336,7 @@ writeMesh(Stream *stream, int32, void *object, int32, int32)
stream->write(buf, 8); stream->write(buf, 8);
if(geo->geoflags & Geometry::NATIVE){ if(geo->geoflags & Geometry::NATIVE){
assert(geo->instData != NULL); assert(geo->instData != NULL);
if(geo->instData->platform == PLATFORM_OGL) if(geo->instData->platform == PLATFORM_WDGL)
stream->write(mesh->indices, stream->write(mesh->indices,
mesh->numIndices*2); mesh->numIndices*2);
}else{ }else{
@ -363,7 +363,7 @@ getSizeMesh(void *object, int32, int32)
int32 size = 12 + geo->meshHeader->numMeshes*8; int32 size = 12 + geo->meshHeader->numMeshes*8;
if(geo->geoflags & Geometry::NATIVE){ if(geo->geoflags & Geometry::NATIVE){
assert(geo->instData != NULL); assert(geo->instData != NULL);
if(geo->instData->platform == PLATFORM_OGL) if(geo->instData->platform == PLATFORM_WDGL)
size += geo->meshHeader->totalIndices*2; size += geo->meshHeader->totalIndices*2;
}else{ }else{
size += geo->meshHeader->totalIndices*4; size += geo->meshHeader->totalIndices*4;
@ -407,8 +407,8 @@ destroyNativeData(void *object, int32 offset, int32 size)
return object; return object;
if(geometry->instData->platform == PLATFORM_PS2) if(geometry->instData->platform == PLATFORM_PS2)
return ps2::destroyNativeData(object, offset, size); return ps2::destroyNativeData(object, offset, size);
if(geometry->instData->platform == PLATFORM_OGL) if(geometry->instData->platform == PLATFORM_WDGL)
return gl::destroyNativeData(object, offset, size); return wdgl::destroyNativeData(object, offset, size);
if(geometry->instData->platform == PLATFORM_XBOX) if(geometry->instData->platform == PLATFORM_XBOX)
return xbox::destroyNativeData(object, offset, size); return xbox::destroyNativeData(object, offset, size);
if(geometry->instData->platform == PLATFORM_D3D8) if(geometry->instData->platform == PLATFORM_D3D8)
@ -446,7 +446,7 @@ readNativeData(Stream *stream, int32 len, void *object, int32 o, int32 s)
} }
}else{ }else{
stream->seek(-12); stream->seek(-12);
gl::readNativeData(stream, len, object, o, s); wdgl::readNativeData(stream, len, object, o, s);
} }
} }
@ -458,8 +458,8 @@ writeNativeData(Stream *stream, int32 len, void *object, int32 o, int32 s)
return; return;
if(geometry->instData->platform == PLATFORM_PS2) if(geometry->instData->platform == PLATFORM_PS2)
ps2::writeNativeData(stream, len, object, o, s); ps2::writeNativeData(stream, len, object, o, s);
else if(geometry->instData->platform == PLATFORM_OGL) else if(geometry->instData->platform == PLATFORM_WDGL)
gl::writeNativeData(stream, len, object, o, s); wdgl::writeNativeData(stream, len, object, o, s);
else if(geometry->instData->platform == PLATFORM_XBOX) else if(geometry->instData->platform == PLATFORM_XBOX)
xbox::writeNativeData(stream, len, object, o, s); xbox::writeNativeData(stream, len, object, o, s);
else if(geometry->instData->platform == PLATFORM_D3D8) else if(geometry->instData->platform == PLATFORM_D3D8)
@ -476,8 +476,8 @@ getSizeNativeData(void *object, int32 offset, int32 size)
return -1; return -1;
if(geometry->instData->platform == PLATFORM_PS2) if(geometry->instData->platform == PLATFORM_PS2)
return ps2::getSizeNativeData(object, offset, size); return ps2::getSizeNativeData(object, offset, size);
else if(geometry->instData->platform == PLATFORM_OGL) else if(geometry->instData->platform == PLATFORM_WDGL)
return gl::getSizeNativeData(object, offset, size); return wdgl::getSizeNativeData(object, offset, size);
else if(geometry->instData->platform == PLATFORM_XBOX) else if(geometry->instData->platform == PLATFORM_XBOX)
return xbox::getSizeNativeData(object, offset, size); return xbox::getSizeNativeData(object, offset, size);
else if(geometry->instData->platform == PLATFORM_D3D8) else if(geometry->instData->platform == PLATFORM_D3D8)
@ -558,8 +558,8 @@ readSkin(Stream *stream, int32 len, void *object, int32 offset, int32)
// TODO: function pointers // TODO: function pointers
if(geometry->instData->platform == PLATFORM_PS2) if(geometry->instData->platform == PLATFORM_PS2)
ps2::readNativeSkin(stream, len, object, offset); ps2::readNativeSkin(stream, len, object, offset);
else if(geometry->instData->platform == PLATFORM_OGL) else if(geometry->instData->platform == PLATFORM_WDGL)
gl::readNativeSkin(stream, len, object, offset); wdgl::readNativeSkin(stream, len, object, offset);
else if(geometry->instData->platform == PLATFORM_XBOX) else if(geometry->instData->platform == PLATFORM_XBOX)
xbox::readNativeSkin(stream, len, object, offset); xbox::readNativeSkin(stream, len, object, offset);
else else
@ -625,8 +625,8 @@ writeSkin(Stream *stream, int32 len, void *object, int32 offset, int32)
if(geometry->instData){ if(geometry->instData){
if(geometry->instData->platform == PLATFORM_PS2) if(geometry->instData->platform == PLATFORM_PS2)
ps2::writeNativeSkin(stream, len, object, offset); ps2::writeNativeSkin(stream, len, object, offset);
else if(geometry->instData->platform == PLATFORM_OGL) else if(geometry->instData->platform == PLATFORM_WDGL)
gl::writeNativeSkin(stream, len, object, offset); wdgl::writeNativeSkin(stream, len, object, offset);
else if(geometry->instData->platform == PLATFORM_XBOX) else if(geometry->instData->platform == PLATFORM_XBOX)
xbox::writeNativeSkin(stream, len, object, offset); xbox::writeNativeSkin(stream, len, object, offset);
else else
@ -672,8 +672,8 @@ getSizeSkin(void *object, int32 offset, int32)
if(geometry->instData){ if(geometry->instData){
if(geometry->instData->platform == PLATFORM_PS2) if(geometry->instData->platform == PLATFORM_PS2)
return ps2::getSizeNativeSkin(object, offset); return ps2::getSizeNativeSkin(object, offset);
if(geometry->instData->platform == PLATFORM_OGL) if(geometry->instData->platform == PLATFORM_WDGL)
return gl::getSizeNativeSkin(object, offset); return wdgl::getSizeNativeSkin(object, offset);
if(geometry->instData->platform == PLATFORM_XBOX) if(geometry->instData->platform == PLATFORM_XBOX)
return xbox::getSizeNativeSkin(object, offset); return xbox::getSizeNativeSkin(object, offset);
if(geometry->instData->platform == PLATFORM_D3D8) if(geometry->instData->platform == PLATFORM_D3D8)
@ -713,8 +713,8 @@ registerSkinPlugin(void)
skinGlobals.pipelines[i] = defpipe; skinGlobals.pipelines[i] = defpipe;
skinGlobals.pipelines[PLATFORM_PS2] = skinGlobals.pipelines[PLATFORM_PS2] =
ps2::makeSkinPipeline(); ps2::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_OGL] = skinGlobals.pipelines[PLATFORM_WDGL] =
gl::makeSkinPipeline(); wdgl::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_XBOX] = skinGlobals.pipelines[PLATFORM_XBOX] =
xbox::makeSkinPipeline(); xbox::makeSkinPipeline();
skinGlobals.pipelines[PLATFORM_D3D8] = skinGlobals.pipelines[PLATFORM_D3D8] =
@ -1200,8 +1200,8 @@ registerMatFXPlugin(void)
matFXGlobals.pipelines[i] = defpipe; matFXGlobals.pipelines[i] = defpipe;
matFXGlobals.pipelines[PLATFORM_PS2] = matFXGlobals.pipelines[PLATFORM_PS2] =
ps2::makeMatFXPipeline(); ps2::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_OGL] = matFXGlobals.pipelines[PLATFORM_WDGL] =
gl::makeMatFXPipeline(); wdgl::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_XBOX] = matFXGlobals.pipelines[PLATFORM_XBOX] =
xbox::makeMatFXPipeline(); xbox::makeMatFXPipeline();
matFXGlobals.pipelines[PLATFORM_D3D8] = matFXGlobals.pipelines[PLATFORM_D3D8] =

View File

@ -7,6 +7,7 @@
#include "rwplg.h" #include "rwplg.h"
#include "rwpipeline.h" #include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwengine.h"
#include "rwplugins.h" #include "rwplugins.h"
#include "rwps2.h" #include "rwps2.h"
#include "rwps2plg.h" #include "rwps2plg.h"
@ -14,6 +15,12 @@
namespace rw { namespace rw {
namespace ps2 { namespace ps2 {
void
initializePlatform(void)
{
engine[PLATFORM_PS2].defaultPipeline = makeDefaultPipeline();
}
ObjPipeline *defaultObjPipe; ObjPipeline *defaultObjPipe;
MatPipeline *defaultMatPipe; MatPipeline *defaultMatPipe;

View File

@ -68,8 +68,8 @@ struct dword
#define ALIGN64(x) ((x) + 0x3F & ~0x3F) #define ALIGN64(x) ((x) + 0x3F & ~0x3F)
void static void
Ps2Raster::create(Raster *raster) rasterCreate(Raster *raster)
{ {
uint64 bufferWidth[7], bufferBase[7]; uint64 bufferWidth[7], bufferBase[7];
int32 pageWidth, pageHeight; int32 pageWidth, pageHeight;
@ -370,7 +370,7 @@ Ps2Raster::create(Raster *raster)
*p++ = 0; *p++ = 0;
// GIF tag // GIF tag
uint32 sz = paletteSize - 0x50 + 0xF >> 4; uint32 sz = ras->paletteSize - 0x50 + 0xF >> 4;
*p++ = sz; *p++ = sz;
*p++ = 0x08000000; // IMAGE *p++ = 0x08000000; // IMAGE
*p++ = 0; *p++ = 0;
@ -379,8 +379,8 @@ Ps2Raster::create(Raster *raster)
} }
} }
uint8* static uint8*
Ps2Raster::lock(Raster *raster, int32 level) rasterLock(Raster *raster, int32 level)
{ {
// TODO // TODO
(void)raster; (void)raster;
@ -388,16 +388,16 @@ Ps2Raster::lock(Raster *raster, int32 level)
return NULL; return NULL;
} }
void static void
Ps2Raster::unlock(Raster *raster, int32 level) rasterUnlock(Raster *raster, int32 level)
{ {
// TODO // TODO
(void)raster; (void)raster;
(void)level; (void)level;
} }
int32 static int32
Ps2Raster::getNumLevels(Raster *raster) rasterNumLevels(Raster *raster)
{ {
Ps2Raster *ras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset); Ps2Raster *ras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset);
if(raster->texels == NULL) return 0; if(raster->texels == NULL) return 0;
@ -482,6 +482,11 @@ registerNativeRaster(void)
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);
engine[PLATFORM_PS2].rasterNativeOffset = nativeRasterOffset; engine[PLATFORM_PS2].rasterNativeOffset = nativeRasterOffset;
engine[PLATFORM_PS2].rasterCreate = rasterCreate;
engine[PLATFORM_PS2].rasterLock = rasterLock;
engine[PLATFORM_PS2].rasterUnlock = rasterUnlock;
engine[PLATFORM_PS2].rasterNumLevels = rasterNumLevels;
Texture::registerPlugin(0, ID_SKYMIPMAP, NULL, NULL, NULL); Texture::registerPlugin(0, ID_SKYMIPMAP, NULL, NULL, NULL);
Texture::registerPluginStream(ID_SKYMIPMAP, readMipmap, writeMipmap, getSizeMipmap); Texture::registerPluginStream(ID_SKYMIPMAP, readMipmap, writeMipmap, getSizeMipmap);
} }

View File

@ -12,10 +12,10 @@
#include "rwplugins.h" #include "rwplugins.h"
#include "rwengine.h" #include "rwengine.h"
#include "rwps2.h" #include "rwps2.h"
#include "rwogl.h"
#include "rwxbox.h" #include "rwxbox.h"
#include "rwd3d8.h" #include "rwd3d8.h"
#include "rwd3d9.h" #include "rwd3d9.h"
#include "rwwdgl.h"
using namespace std; using namespace std;
@ -26,7 +26,7 @@ int32 build = 0xFFFF;
#ifdef RW_PS2 #ifdef RW_PS2
int32 platform = PLATFORM_PS2; int32 platform = PLATFORM_PS2;
#elif RW_OPENGL #elif RW_OPENGL
int32 platform = PLATFORM_OGL; int32 platform = PLATFORM_WDGL;
#elif RW_D3D9 #elif RW_D3D9
int32 platform = PLATFORM_D3D9; int32 platform = PLATFORM_D3D9;
#else #else
@ -52,7 +52,10 @@ static Matrix3 identMat3 = {
void void
initialize(void) initialize(void)
{ {
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL);
for(uint i = 0; i < NUM_PLATFORMS; i++){ for(uint i = 0; i < NUM_PLATFORMS; i++){
engine[i].defaultPipeline = defpipe;
engine[i].rasterCreate = null::rasterCreate; engine[i].rasterCreate = null::rasterCreate;
engine[i].rasterLock = null::rasterLock; engine[i].rasterLock = null::rasterLock;
engine[i].rasterUnlock = null::rasterUnlock; engine[i].rasterUnlock = null::rasterUnlock;
@ -60,20 +63,13 @@ initialize(void)
engine[i].rasterFromImage = null::rasterFromImage; engine[i].rasterFromImage = null::rasterFromImage;
} }
// Atomic pipelines
ObjPipeline *defpipe = new ObjPipeline(PLATFORM_NULL); ps2::initializePlatform();
for(uint i = 0; i < NUM_PLATFORMS; i++) xbox::initializePlatform();
engine[i].defaultPipeline = defpipe; d3d8::initializePlatform();
engine[PLATFORM_PS2].defaultPipeline = d3d9::initializePlatform();
ps2::makeDefaultPipeline();
engine[PLATFORM_OGL].defaultPipeline = wdgl::initializePlatform();
gl::makeDefaultPipeline();
engine[PLATFORM_XBOX].defaultPipeline =
xbox::makeDefaultPipeline();
engine[PLATFORM_D3D8].defaultPipeline =
d3d8::makeDefaultPipeline();
engine[PLATFORM_D3D9].defaultPipeline =
d3d9::makeDefaultPipeline();
Frame::dirtyList.init(); Frame::dirtyList.init();
} }

View File

@ -227,7 +227,7 @@ enum Platform
{ {
PLATFORM_NULL = 0, PLATFORM_NULL = 0,
// D3D7 // D3D7
PLATFORM_OGL = 2, // TODO: remove, this is really WarDrum GL PLATFORM_GL = 2,
// MAC // MAC
PLATFORM_PS2 = 4, PLATFORM_PS2 = 4,
PLATFORM_XBOX = 5, PLATFORM_XBOX = 5,
@ -236,9 +236,11 @@ enum Platform
PLATFORM_D3D8 = 8, PLATFORM_D3D8 = 8,
PLATFORM_D3D9 = 9, PLATFORM_D3D9 = 9,
// non stock-RW platforms // non-stock-RW platforms
PLATFORM_WDGL = 10, // WarDrum OpenGL
PLATFORM_GL3 = 11, // my GL3 implementation
PLATFORM_GL3 = 10,
NUM_PLATFORMS, NUM_PLATFORMS,
FOURCC_PS2 = 0x00325350 // 'PS2\0' FOURCC_PS2 = 0x00325350 // 'PS2\0'

View File

@ -74,19 +74,13 @@ void deleteObject(void *object);
// Native Texture and Raster // Native Texture and Raster
struct D3dRaster : NativeRaster struct D3dRaster
{ {
void *texture; void *texture;
void *palette; void *palette;
uint32 format; uint32 format;
bool32 hasAlpha; bool32 hasAlpha;
bool32 customFormat; bool32 customFormat;
virtual void create(Raster *raster);
virtual uint8 *lock(Raster *raster, int32 level);
virtual void unlock(Raster *raster, int32 level);
virtual int32 getNumLevels(Raster *raster);
virtual void fromImage(Raster *raster, Image *img);
}; };
int32 getLevelSize(Raster *raster, int32 level); int32 getLevelSize(Raster *raster, int32 level);

View File

@ -1,6 +1,8 @@
namespace rw { namespace rw {
namespace d3d8 { namespace d3d8 {
void initializePlatform(void);
struct InstanceData struct InstanceData
{ {
uint32 minVert; uint32 minVert;

View File

@ -1,6 +1,8 @@
namespace rw { namespace rw {
namespace d3d9 { namespace d3d9 {
void initializePlatform(void);
struct VertexElement struct VertexElement
{ {
uint16 stream; uint16 stream;

View File

@ -226,20 +226,6 @@ extern bool32 loadTextures;
#define IGNORERASTERIMP 0 #define IGNORERASTERIMP 0
struct NativeRaster
{
virtual void create(Raster*)
{ assert(IGNORERASTERIMP && "NativeRaster::create unimplemented"); };
virtual uint8 *lock(Raster*, int32)
{ assert(IGNORERASTERIMP && "NativeRaster::lock unimplemented"); return NULL; };
virtual void unlock(Raster*, int32)
{ assert(IGNORERASTERIMP && "NativeRaster::unlock unimplemented"); };
virtual int32 getNumLevels(Raster*)
{ assert(IGNORERASTERIMP && "NativeRaster::getNumLevels unimplemented"); return 0; };
virtual void fromImage(Raster*, Image *img)
{ assert(IGNORERASTERIMP && "NativeRaster::fromImage unimplemented"); };
};
struct TexDictionary; struct TexDictionary;
struct Texture : PluginBase<Texture> struct Texture : PluginBase<Texture>

View File

@ -1,6 +1,8 @@
namespace rw { namespace rw {
namespace ps2 { namespace ps2 {
void initializePlatform(void);
struct InstanceData struct InstanceData
{ {
// 0 - addresses in ref tags need fixing // 0 - addresses in ref tags need fixing
@ -176,7 +178,7 @@ void registerPluginPDSPipes(void);
// Native Texture and Raster // Native Texture and Raster
struct Ps2Raster : NativeRaster struct Ps2Raster
{ {
uint32 tex0[2]; uint32 tex0[2];
uint32 tex1[2]; uint32 tex1[2];
@ -189,11 +191,6 @@ struct Ps2Raster : NativeRaster
uint8 *data; //tmp uint8 *data; //tmp
uint32 dataSize; uint32 dataSize;
virtual void create(Raster *raster);
virtual uint8 *lock(Raster *raster, int32 level);
virtual void unlock(Raster *raster, int32 level);
virtual int32 getNumLevels(Raster *raster);
}; };
extern int32 nativeRasterOffset; extern int32 nativeRasterOffset;

View File

@ -1,8 +1,10 @@
namespace rw { namespace rw {
namespace gl { 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);
struct AttribDesc struct AttribDesc
{ {
// arguments to glVertexAttribPointer (should use OpenGL types here) // arguments to glVertexAttribPointer (should use OpenGL types here)

View File

@ -1,6 +1,8 @@
namespace rw { namespace rw {
namespace xbox { namespace xbox {
void initializePlatform(void);
struct InstanceData struct InstanceData
{ {
uint32 minVert; uint32 minVert;
@ -66,18 +68,13 @@ void registerVertexFormatPlugin(void);
// Native Texture and Raster // Native Texture and Raster
struct XboxRaster : NativeRaster struct XboxRaster
{ {
void *texture; void *texture;
void *palette; void *palette;
uint32 format; uint32 format;
bool32 hasAlpha; bool32 hasAlpha;
bool32 unknownFlag; bool32 unknownFlag;
virtual void create(Raster *raster);
virtual uint8 *lock(Raster *raster, int32 level);
virtual void unlock(Raster *raster, int32 level);
virtual int32 getNumLevels(Raster *raster);
}; };
int32 getLevelSize(Raster *raster, int32 level); int32 getLevelSize(Raster *raster, int32 level);

View File

@ -7,8 +7,9 @@
#include "rwplg.h" #include "rwplg.h"
#include "rwpipeline.h" #include "rwpipeline.h"
#include "rwobjects.h" #include "rwobjects.h"
#include "rwengine.h"
#include "rwplugins.h" #include "rwplugins.h"
#include "rwogl.h" #include "rwwdgl.h"
#ifdef RW_OPENGL #ifdef RW_OPENGL
#include <GL/glew.h> #include <GL/glew.h>
@ -17,7 +18,14 @@
using namespace std; using namespace std;
namespace rw { namespace rw {
namespace gl { namespace wdgl {
void
initializePlatform(void)
{
engine[PLATFORM_WDGL].defaultPipeline = makeDefaultPipeline();
}
// VC // VC
// 8733 0 0 0 3 // 8733 0 0 0 3
@ -209,7 +217,7 @@ void*
destroyNativeData(void *object, int32, int32) destroyNativeData(void *object, int32, int32)
{ {
Geometry *geometry = (Geometry*)object; Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_OGL); assert(geometry->instData->platform == PLATFORM_WDGL);
InstanceDataHeader *header = InstanceDataHeader *header =
(InstanceDataHeader*)geometry->instData; (InstanceDataHeader*)geometry->instData;
geometry->instData = NULL; geometry->instData = NULL;
@ -226,7 +234,7 @@ readNativeData(Stream *stream, int32, void *object, int32, int32)
Geometry *geometry = (Geometry*)object; Geometry *geometry = (Geometry*)object;
InstanceDataHeader *header = new InstanceDataHeader; InstanceDataHeader *header = new InstanceDataHeader;
geometry->instData = header; geometry->instData = header;
header->platform = PLATFORM_OGL; header->platform = PLATFORM_WDGL;
header->vbo = 0; header->vbo = 0;
header->ibo = 0; header->ibo = 0;
header->numAttribs = stream->readU32(); header->numAttribs = stream->readU32();
@ -242,7 +250,7 @@ void
writeNativeData(Stream *stream, int32, void *object, int32, int32) writeNativeData(Stream *stream, int32, void *object, int32, int32)
{ {
Geometry *geometry = (Geometry*)object; Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_OGL); assert(geometry->instData->platform == PLATFORM_WDGL);
InstanceDataHeader *header = (InstanceDataHeader*)geometry->instData; InstanceDataHeader *header = (InstanceDataHeader*)geometry->instData;
stream->writeU32(header->numAttribs); stream->writeU32(header->numAttribs);
stream->write(header->attribs, header->numAttribs*sizeof(AttribDesc)); stream->write(header->attribs, header->numAttribs*sizeof(AttribDesc));
@ -253,7 +261,7 @@ int32
getSizeNativeData(void *object, int32, int32) getSizeNativeData(void *object, int32, int32)
{ {
Geometry *geometry = (Geometry*)object; Geometry *geometry = (Geometry*)object;
assert(geometry->instData->platform == PLATFORM_OGL); assert(geometry->instData->platform == PLATFORM_WDGL);
InstanceDataHeader *header = (InstanceDataHeader*)geometry->instData; InstanceDataHeader *header = (InstanceDataHeader*)geometry->instData;
return 4 + header->numAttribs*sizeof(AttribDesc) + header->dataSize; return 4 + header->numAttribs*sizeof(AttribDesc) + header->dataSize;
} }
@ -273,7 +281,7 @@ void
printPipeinfo(Atomic *a) printPipeinfo(Atomic *a)
{ {
Geometry *g = a->geometry; Geometry *g = a->geometry;
if(g->instData == NULL || g->instData->platform != PLATFORM_OGL) if(g->instData == NULL || g->instData->platform != PLATFORM_WDGL)
return; return;
int32 plgid = 0; int32 plgid = 0;
if(a->pipeline) if(a->pipeline)
@ -294,7 +302,7 @@ instance(rw::ObjPipeline *rwpipe, Atomic *atomic)
return; return;
InstanceDataHeader *header = new InstanceDataHeader; InstanceDataHeader *header = new InstanceDataHeader;
geo->instData = header; geo->instData = header;
header->platform = PLATFORM_OGL; header->platform = PLATFORM_WDGL;
header->vbo = 0; header->vbo = 0;
header->ibo = 0; header->ibo = 0;
header->numAttribs = header->numAttribs =
@ -420,7 +428,7 @@ uninstance(rw::ObjPipeline *rwpipe, Atomic *atomic)
if((geo->geoflags & Geometry::NATIVE) == 0) if((geo->geoflags & Geometry::NATIVE) == 0)
return; return;
assert(geo->instData != NULL); assert(geo->instData != NULL);
assert(geo->instData->platform == PLATFORM_OGL); assert(geo->instData->platform == PLATFORM_WDGL);
geo->geoflags &= ~Geometry::NATIVE; geo->geoflags &= ~Geometry::NATIVE;
geo->allocateData(); geo->allocateData();
@ -488,8 +496,8 @@ ObjPipeline::ObjPipeline(uint32 platform)
: rw::ObjPipeline(platform) : rw::ObjPipeline(platform)
{ {
this->numCustomAttribs = 0; this->numCustomAttribs = 0;
this->impl.instance = gl::instance; this->impl.instance = wdgl::instance;
this->impl.uninstance = gl::uninstance; this->impl.uninstance = wdgl::uninstance;
this->instanceCB = NULL; this->instanceCB = NULL;
this->uninstanceCB = NULL; this->uninstanceCB = NULL;
} }
@ -497,7 +505,7 @@ ObjPipeline::ObjPipeline(uint32 platform)
ObjPipeline* ObjPipeline*
makeDefaultPipeline(void) makeDefaultPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_OGL); ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL);
return pipe; return pipe;
} }
@ -509,7 +517,7 @@ readNativeSkin(Stream *stream, int32, void *object, int32 offset)
uint32 vers; uint32 vers;
Geometry *geometry = (Geometry*)object; Geometry *geometry = (Geometry*)object;
assert(findChunk(stream, ID_STRUCT, NULL, &vers)); assert(findChunk(stream, ID_STRUCT, NULL, &vers));
assert(stream->readU32() == PLATFORM_OGL); assert(stream->readU32() == PLATFORM_WDGL);
Skin *skin = new Skin; Skin *skin = new Skin;
*PLUGINOFFSET(Skin*, geometry, offset) = skin; *PLUGINOFFSET(Skin*, geometry, offset) = skin;
@ -522,7 +530,7 @@ void
writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset) writeNativeSkin(Stream *stream, int32 len, void *object, int32 offset)
{ {
writeChunkHeader(stream, ID_STRUCT, len-12); writeChunkHeader(stream, ID_STRUCT, len-12);
stream->writeU32(PLATFORM_OGL); stream->writeU32(PLATFORM_WDGL);
Skin *skin = *PLUGINOFFSET(Skin*, object, offset); Skin *skin = *PLUGINOFFSET(Skin*, object, offset);
stream->writeI32(skin->numBones); stream->writeI32(skin->numBones);
stream->write(skin->inverseMatrices, skin->numBones*64); stream->write(skin->inverseMatrices, skin->numBones*64);
@ -636,7 +644,7 @@ skinUninstanceCB(Geometry *geo)
ObjPipeline* ObjPipeline*
makeSkinPipeline(void) makeSkinPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_OGL); ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL);
pipe->pluginID = ID_SKIN; pipe->pluginID = ID_SKIN;
pipe->pluginData = 1; pipe->pluginData = 1;
pipe->numCustomAttribs = 2; pipe->numCustomAttribs = 2;
@ -648,7 +656,7 @@ makeSkinPipeline(void)
ObjPipeline* ObjPipeline*
makeMatFXPipeline(void) makeMatFXPipeline(void)
{ {
ObjPipeline *pipe = new ObjPipeline(PLATFORM_OGL); ObjPipeline *pipe = new ObjPipeline(PLATFORM_WDGL);
pipe->pluginID = ID_MATFX; pipe->pluginID = ID_MATFX;
pipe->pluginData = 0; pipe->pluginData = 0;
return pipe; return pipe;
@ -690,7 +698,7 @@ void
registerNativeRaster(void) registerNativeRaster(void)
{ {
nativeRasterOffset = Raster::registerPlugin(sizeof(GlRaster), nativeRasterOffset = Raster::registerPlugin(sizeof(GlRaster),
0x12340000 | PLATFORM_OGL, 0x12340000 | PLATFORM_WDGL,
createNativeRaster, createNativeRaster,
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);

View File

@ -18,6 +18,12 @@ using namespace std;
namespace rw { namespace rw {
namespace xbox { namespace xbox {
void
initializePlatform(void)
{
engine[PLATFORM_XBOX].defaultPipeline = makeDefaultPipeline();
}
void* void*
destroyNativeData(void *object, int32, int32) destroyNativeData(void *object, int32, int32)
{ {
@ -753,9 +759,10 @@ createTexture(int32 width, int32 height, int32 numlevels, uint32 format)
return levels; return levels;
} }
void static void
XboxRaster::create(Raster *raster) rasterCreate(Raster *raster)
{ {
XboxRaster *natras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
static uint32 formatMap[] = { static uint32 formatMap[] = {
D3DFMT_UNKNOWN, D3DFMT_UNKNOWN,
D3DFMT_A1R5G5B5, D3DFMT_A1R5G5B5,
@ -791,33 +798,35 @@ XboxRaster::create(Raster *raster)
uint32 format; uint32 format;
if(raster->format & (Raster::PAL4 | Raster::PAL8)){ if(raster->format & (Raster::PAL4 | Raster::PAL8)){
format = D3DFMT_P8; format = D3DFMT_P8;
this->palette = new uint8[4*256]; natras->palette = new uint8[4*256];
}else }else
format = formatMap[(raster->format >> 8) & 0xF]; format = formatMap[(raster->format >> 8) & 0xF];
this->format = 0; natras->format = 0;
this->hasAlpha = alphaMap[(raster->format >> 8) & 0xF]; natras->hasAlpha = alphaMap[(raster->format >> 8) & 0xF];
int32 levels = Raster::calculateNumLevels(raster->width, raster->height); int32 levels = Raster::calculateNumLevels(raster->width, raster->height);
this->texture = createTexture(raster->width, raster->height, natras->texture = createTexture(raster->width, raster->height,
raster->format & Raster::MIPMAP ? levels : 1, raster->format & Raster::MIPMAP ? levels : 1,
format); format);
} }
uint8* static uint8*
XboxRaster::lock(Raster*, int32 level) rasterLock(Raster *raster, int32 level)
{ {
RasterLevels *levels = (RasterLevels*)this->texture; XboxRaster *natras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
RasterLevels *levels = (RasterLevels*)natras->texture;
return levels->levels[level].data; return levels->levels[level].data;
} }
void static void
XboxRaster::unlock(Raster*, int32) rasterUnlock(Raster*, int32)
{ {
} }
int32 static int32
XboxRaster::getNumLevels(Raster*) rasterNumLevels(Raster *raster)
{ {
RasterLevels *levels = (RasterLevels*)this->texture; XboxRaster *natras = PLUGINOFFSET(XboxRaster, raster, nativeRasterOffset);
RasterLevels *levels = (RasterLevels*)natras->texture;
return levels->numlevels; return levels->numlevels;
} }
@ -870,6 +879,10 @@ registerNativeRaster(void)
destroyNativeRaster, destroyNativeRaster,
copyNativeRaster); copyNativeRaster);
engine[PLATFORM_XBOX].rasterNativeOffset = nativeRasterOffset; engine[PLATFORM_XBOX].rasterNativeOffset = nativeRasterOffset;
engine[PLATFORM_XBOX].rasterCreate = rasterCreate;
engine[PLATFORM_XBOX].rasterLock = rasterLock;
engine[PLATFORM_XBOX].rasterUnlock = rasterUnlock;
engine[PLATFORM_XBOX].rasterNumLevels = rasterNumLevels;
} }
Texture* Texture*