199 lines
4.1 KiB
C++
199 lines
4.1 KiB
C++
![]() |
#include <cstdio>
|
||
|
#include <cstdlib>
|
||
|
#include <cstring>
|
||
|
#include <cassert>
|
||
|
|
||
|
#include "rwbase.h"
|
||
|
#include "rwerror.h"
|
||
|
#include "rwplg.h"
|
||
|
#include "rwpipeline.h"
|
||
|
#include "rwobjects.h"
|
||
|
#include "rwengine.h"
|
||
|
//#include "ps2/rwps2.h"
|
||
|
//#include "d3d/rwd3d.h"
|
||
|
//#include "d3d/rwxbox.h"
|
||
|
//#include "d3d/rwd3d8.h"
|
||
|
//#include "d3d/rwd3d9.h"
|
||
|
|
||
|
#define PLUGIN_ID 0
|
||
|
|
||
|
namespace rw {
|
||
|
|
||
|
struct RasterGlobals
|
||
|
{
|
||
|
int32 sp;
|
||
|
Raster *stack[32];
|
||
|
};
|
||
|
int32 rasterModuleOffset;
|
||
|
|
||
|
#define RASTERGLOBAL(v) (PLUGINOFFSET(RasterGlobals, engine, rasterModuleOffset)->v)
|
||
|
|
||
|
static void*
|
||
|
rasterOpen(void *object, int32 offset, int32 size)
|
||
|
{
|
||
|
int i;
|
||
|
rasterModuleOffset = offset;
|
||
|
RASTERGLOBAL(sp) = -1;
|
||
|
for(i = 0; i < nelem(RASTERGLOBAL(stack)); i++)
|
||
|
RASTERGLOBAL(stack)[i] = nil;
|
||
|
return object;
|
||
|
}
|
||
|
|
||
|
static void*
|
||
|
rasterClose(void *object, int32 offset, int32 size)
|
||
|
{
|
||
|
return object;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Raster::registerModule(void)
|
||
|
{
|
||
|
Engine::registerPlugin(sizeof(RasterGlobals), ID_RASTERMODULE, rasterOpen, rasterClose);
|
||
|
}
|
||
|
|
||
|
Raster*
|
||
|
Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platform)
|
||
|
{
|
||
|
// TODO: pass arguments through to the driver and create the raster there
|
||
|
Raster *raster = (Raster*)rwMalloc(s_plglist.size, MEMDUR_EVENT); // TODO
|
||
|
assert(raster != nil);
|
||
|
raster->parent = raster;
|
||
|
raster->offsetX = 0;
|
||
|
raster->offsetY = 0;
|
||
|
raster->platform = platform ? platform : rw::platform;
|
||
|
raster->type = format & 0x7;
|
||
|
raster->flags = format & 0xF8;
|
||
|
raster->privateFlags = 0;
|
||
|
raster->format = format & 0xFF00;
|
||
|
raster->width = width;
|
||
|
raster->height = height;
|
||
|
raster->depth = depth;
|
||
|
raster->pixels = raster->palette = nil;
|
||
|
s_plglist.construct(raster);
|
||
|
|
||
|
// printf("%d %d %d %d\n", raster->type, raster->width, raster->height, raster->depth);
|
||
|
engine->driver[raster->platform]->rasterCreate(raster);
|
||
|
return raster;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Raster::subRaster(Raster *parent, Rect *r)
|
||
|
{
|
||
|
if((this->flags & DONTALLOCATE) == 0)
|
||
|
return;
|
||
|
this->width = r->w;
|
||
|
this->height = r->h;
|
||
|
this->offsetX += r->x;
|
||
|
this->offsetY += r->y;
|
||
|
this->parent = parent->parent;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Raster::destroy(void)
|
||
|
{
|
||
|
s_plglist.destruct(this);
|
||
|
// delete[] this->texels;
|
||
|
// delete[] this->palette;
|
||
|
rwFree(this);
|
||
|
}
|
||
|
|
||
|
uint8*
|
||
|
Raster::lock(int32 level, int32 lockMode)
|
||
|
{
|
||
|
return engine->driver[this->platform]->rasterLock(this, level, lockMode);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Raster::unlock(int32 level)
|
||
|
{
|
||
|
engine->driver[this->platform]->rasterUnlock(this, level);
|
||
|
}
|
||
|
|
||
|
uint8*
|
||
|
Raster::lockPalette(int32 lockMode)
|
||
|
{
|
||
|
return engine->driver[this->platform]->rasterLockPalette(this, lockMode);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
Raster::unlockPalette(void)
|
||
|
{
|
||
|
engine->driver[this->platform]->rasterUnlockPalette(this);
|
||
|
}
|
||
|
|
||
|
int32
|
||
|
Raster::getNumLevels(void)
|
||
|
{
|
||
|
return engine->driver[this->platform]->rasterNumLevels(this);
|
||
|
}
|
||
|
|
||
|
int32
|
||
|
Raster::calculateNumLevels(int32 width, int32 height)
|
||
|
{
|
||
|
int32 size = width >= height ? width : height;
|
||
|
int32 n;
|
||
|
for(n = 0; size != 0; n++)
|
||
|
size /= 2;
|
||
|
return n;
|
||
|
}
|
||
|
|
||
|
bool
|
||
|
Raster::formatHasAlpha(int32 format)
|
||
|
{
|
||
|
return (format & 0xF00) == Raster::C8888 ||
|
||
|
(format & 0xF00) == Raster::C1555 ||
|
||
|
(format & 0xF00) == Raster::C4444;
|
||
|
}
|
||
|
|
||
|
Raster*
|
||
|
Raster::createFromImage(Image *image, int32 platform)
|
||
|
{
|
||
|
Raster *raster = Raster::create(image->width, image->height,
|
||
|
image->depth, TEXTURE | DONTALLOCATE,
|
||
|
platform);
|
||
|
engine->driver[raster->platform]->rasterFromImage(raster, image);
|
||
|
return raster;
|
||
|
}
|
||
|
|
||
|
Image*
|
||
|
Raster::toImage(void)
|
||
|
{
|
||
|
return engine->driver[this->platform]->rasterToImage(this);
|
||
|
}
|
||
|
|
||
|
Raster*
|
||
|
Raster::pushContext(Raster *raster)
|
||
|
{
|
||
|
RasterGlobals *g = PLUGINOFFSET(RasterGlobals, engine, rasterModuleOffset);
|
||
|
if(g->sp >= (int32)nelem(g->stack)-1)
|
||
|
return nil;
|
||
|
return g->stack[++g->sp] = raster;
|
||
|
}
|
||
|
|
||
|
Raster*
|
||
|
Raster::popContext(void)
|
||
|
{
|
||
|
RasterGlobals *g = PLUGINOFFSET(RasterGlobals, engine, rasterModuleOffset);
|
||
|
if(g->sp < 0)
|
||
|
return nil;
|
||
|
return g->stack[g->sp--];
|
||
|
}
|
||
|
|
||
|
Raster*
|
||
|
Raster::getCurrentContext(void)
|
||
|
{
|
||
|
RasterGlobals *g = PLUGINOFFSET(RasterGlobals, engine, rasterModuleOffset);
|
||
|
if(g->sp < 0 || g->sp >= (int32)nelem(g->stack))
|
||
|
return nil;
|
||
|
return g->stack[g->sp];
|
||
|
}
|
||
|
|
||
|
bool32
|
||
|
Raster::renderFast(int32 x, int32 y)
|
||
|
{
|
||
|
return engine->device.rasterRenderFast(this,x, y);
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|