librw/src/rwengine.h

187 lines
5.5 KiB
C
Raw Normal View History

2016-06-16 14:08:09 +02:00
namespace rw {
2017-08-09 10:57:32 +02:00
enum DeviceReq
{
2017-08-09 10:57:32 +02:00
// Device/Context creation
2017-08-29 10:12:56 +02:00
DEVICEOPEN,
// Device/Context shutdown
DEVICECLOSE,
2017-08-09 10:57:32 +02:00
// Device initialization before Engine/Driver plugins are opened
DEVICEINIT,
2017-08-29 10:12:56 +02:00
// Device de-initialization after Engine/Driver plugins are closed
DEVICETERM,
// Device initialization after Engine/Driver plugins are opened
DEVICEFINALIZE
2017-08-29 10:12:56 +02:00
// TODO? counterpart to FINALIZE?
2017-08-09 10:57:32 +02:00
};
2016-08-05 01:13:41 +02:00
2017-08-09 10:57:32 +02:00
typedef int DeviceSystem(DeviceReq req, void *arg0);
2017-08-29 10:12:56 +02:00
struct Camera;
struct Image;
struct Texture;
struct Raster;
class ObjPipeline;
2017-08-09 10:57:32 +02:00
// This is for the render device, we only have one
struct Device
{
2016-07-06 11:44:59 +02:00
float32 zNear, zFar;
void (*beginUpdate)(Camera*);
void (*endUpdate)(Camera*);
void (*clearCamera)(Camera*, RGBA *col, uint32 mode);
void (*showRaster)(Raster *raster);
void (*setRenderState)(int32 state, void *value);
void *(*getRenderState)(int32 state);
2017-08-29 10:12:56 +02:00
void (*im2DRenderLine)(void*, int32, int32, int32);
void (*im2DRenderTriangle)(void*, int32, int32, int32, int32);
void (*im2DRenderPrimitive)(PrimitiveType,
void*, int32);
void (*im2DRenderIndexedPrimitive)(PrimitiveType,
void*, int32, void*, int32);
2017-08-29 10:12:56 +02:00
// Not sure if this will stay...
void (*im3DTransform)(void *vertices, int32 numVertices, Matrix *world);
void (*im3DRenderIndexed)(PrimitiveType primType, void *indices, int32 numIndices);
void (*im3DEnd)(void);
2017-08-09 10:57:32 +02:00
DeviceSystem *system;
};
2017-08-09 10:57:32 +02:00
// This is for platform-dependent but portable things
// so the engine has one for every platform
struct Driver
2016-06-16 14:08:09 +02:00
{
ObjPipeline *defaultPipeline;
int32 rasterNativeOffset;
void (*rasterCreate)(Raster*);
2019-08-07 22:37:43 +02:00
uint8 *(*rasterLock)(Raster*, int32 level, int32 lockMode);
2016-06-16 14:08:09 +02:00
void (*rasterUnlock)(Raster*, int32 level);
2019-08-07 22:37:43 +02:00
uint8 *(*rasterLockPalette)(Raster*, int32 lockMode);
void (*rasterUnlockPalette)(Raster*);
2016-06-16 14:08:09 +02:00
int32 (*rasterNumLevels)(Raster*);
void (*rasterFromImage)(Raster*, Image*);
2016-07-15 11:55:52 +02:00
Image *(*rasterToImage)(Raster*);
static PluginList s_plglist[NUM_PLATFORMS];
static int32 registerPlugin(int32 platform, int32 size, uint32 id,
Constructor ctor, Destructor dtor){
return s_plglist[platform].registerPlugin(size, id,
ctor, dtor, nil);
}
2016-06-16 14:08:09 +02:00
};
2017-08-09 10:57:32 +02:00
struct EngineStartParams;
2017-08-24 15:10:34 +02:00
enum MemHint
{
MEMDUR_NA = 0,
// used inside function
MEMDUR_FUNCTION = 0x10000,
// used for one frame
MEMDUR_FRAME = 0x20000,
// used for longer time
MEMDUR_EVENT = 0x30000,
// used while the engine is running
MEMDUR_GLOBAL = 0x40000
};
struct MemoryFunctions
{
2017-08-25 14:06:53 +02:00
void *(*rwmalloc)(size_t sz, uint32 hint);
void *(*rwrealloc)(void *p, size_t sz, uint32 hint);
void (*rwfree)(void *p);
// These are temporary until we have better error handling
// TODO: Maybe don't put them here since they shouldn't really be switched out
void *(*rwmustmalloc)(size_t sz, uint32 hint);
void *(*rwmustrealloc)(void *p, size_t sz, uint32 hint);
2017-08-24 15:10:34 +02:00
};
2017-08-09 10:57:32 +02:00
// This is for platform independent things
// TODO: move more stuff into this
struct Engine
{
enum State {
Dead = 0,
Initialized,
Opened,
Started
};
void *currentCamera;
void *currentWorld;
LinkList frameDirtyList;
2017-08-09 10:57:32 +02:00
// Dynamically allocated because of plugins
Driver *driver[NUM_PLATFORMS];
Device device;
2017-08-24 15:10:34 +02:00
// These must always be available
static MemoryFunctions memfuncs;
2017-08-09 10:57:32 +02:00
static State state;
static bool32 init(void);
static bool32 open(void);
static bool32 start(EngineStartParams*);
2017-08-10 00:42:33 +02:00
static void term(void);
static void close(void);
2017-08-09 10:57:32 +02:00
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);
}
2017-08-09 10:57:32 +02:00
};
extern Engine *engine;
2016-06-16 14:08:09 +02:00
2017-08-25 14:06:53 +02:00
// These must be macros because we might want to pass __FILE__ and __LINE__ later
#define rwMalloc(s, h) rw::Engine::memfuncs.rwmalloc(s,h)
#define rwMallocT(t, s, h) (t*)rw::Engine::memfuncs.rwmalloc((s)*sizeof(t),h)
#define rwRealloc(p, s, h) rw::Engine::memfuncs.rwrealloc(p,s,h)
#define rwReallocT(t, p, s, h) (t*)rw::Engine::memfuncs.rwrealloc(p,(s)*sizeof(t),h)
#define rwFree(p) rw::Engine::memfuncs.rwfree(p)
#define rwNew(s, h) rw::Engine::memfuncs.rwmustmalloc(s,h)
#define rwNewT(t, s, h) (t*)rw::Engine::memfuncs.rwmustmalloc((s)*sizeof(t),h)
#define rwResize(p, s, h) rw::Engine::memfuncs.rwmustrealloc(p,s,h)
#define rwResizeT(t, p, s, h) (t*)rw::Engine::memfuncs.rwmustrealloc(p,(s)*sizeof(t),h)
2017-08-24 15:10:34 +02:00
2016-06-16 14:08:09 +02:00
namespace null {
void beginUpdate(Camera*);
void endUpdate(Camera*);
2016-07-05 18:22:22 +02:00
void clearCamera(Camera*, RGBA *col, uint32 mode);
2017-08-12 10:25:25 +02:00
void showRaster(Raster*);
void setRenderState(int32 state, void *value);
void *getRenderState(int32 state);
2016-07-05 11:36:43 +02:00
2016-06-16 14:08:09 +02:00
void rasterCreate(Raster*);
2019-08-07 22:37:43 +02:00
uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
2016-06-16 14:08:09 +02:00
void rasterUnlock(Raster*, int32 level);
2019-08-07 22:37:43 +02:00
uint8 *rasterLockPalette(Raster*, int32 lockMode);
void rasterUnlockPalette(Raster*);
2016-06-16 14:08:09 +02:00
int32 rasterNumLevels(Raster*);
void rasterFromImage(Raster*, Image*);
2016-07-15 11:55:52 +02:00
Image *rasterToImage(Raster*);
void im2DRenderLine(void*, int32, int32, int32);
void im2DRenderTriangle(void*, int32, int32, int32, int32);
void im2DRenderPrimitive(PrimitiveType, void*, int32);
void im2DRenderIndexedPrimitive(PrimitiveType,
void*, int32, void*, int32);
2017-08-09 10:57:32 +02:00
2017-08-29 10:12:56 +02:00
void im3DTransform(void *vertices, int32 numVertices, Matrix *world);
void im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices);
void im3DEnd(void);
2017-08-12 10:25:25 +02:00
int deviceSystem(DeviceReq req, void*);
2017-08-09 10:57:32 +02:00
extern Device renderdevice;
2016-06-16 14:08:09 +02:00
}
}