mirror of https://github.com/aap/librw.git
reworked raster from image conversion, only d3d for now
This commit is contained in:
parent
206547b404
commit
4893889621
|
@ -17,4 +17,6 @@ ECODE(ERR_ENGINEOPEN,
|
|||
ECODE(ERR_ENGINESTART,
|
||||
"Engine could not be started"),
|
||||
ECODE(ERR_INVRASTER,
|
||||
"Invalid raster format")
|
||||
"Invalid raster format"),
|
||||
ECODE(ERR_NOTEXTURE,
|
||||
"Could not create texture")
|
||||
|
|
164
src/d3d/d3d.cpp
164
src/d3d/d3d.cpp
|
@ -5,6 +5,7 @@
|
|||
|
||||
#define WITH_D3D
|
||||
#include "../rwbase.h"
|
||||
#include "../rwerror.h"
|
||||
#include "../rwplg.h"
|
||||
#include "../rwpipeline.h"
|
||||
#include "../rwobjects.h"
|
||||
|
@ -12,6 +13,8 @@
|
|||
#include "rwd3d.h"
|
||||
#include "rwd3dimpl.h"
|
||||
|
||||
#define PLUGIN_ID ID_DRIVER
|
||||
|
||||
namespace rw {
|
||||
namespace d3d {
|
||||
|
||||
|
@ -238,7 +241,6 @@ createVertexBuffer(uint32 length, uint32 fvf, bool dynamic)
|
|||
return vbuf;
|
||||
#else
|
||||
(void)fvf;
|
||||
(void)pool;
|
||||
return rwNewT(uint8, length, MEMDUR_EVENT | ID_DRIVER);
|
||||
#endif
|
||||
}
|
||||
|
@ -487,7 +489,7 @@ rasterSetFormat(Raster *raster)
|
|||
natras->hasAlpha = formatInfoRW[(raster->format >> 8) & 0xF].hasAlpha;
|
||||
}
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateTexture(Raster *raster)
|
||||
{
|
||||
int32 levels;
|
||||
|
@ -496,29 +498,26 @@ rasterCreateTexture(Raster *raster)
|
|||
if(natras->format == D3DFMT_P8)
|
||||
natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
|
||||
levels = Raster::calculateNumLevels(raster->width, raster->height);
|
||||
// HACK
|
||||
// raster <- image has to be done differently to be compatible with RW
|
||||
// just delete texture here for the moment
|
||||
if(natras->texture){
|
||||
deleteObject(natras->texture);
|
||||
d3d9Globals.numTextures--;
|
||||
natras->texture = nil;
|
||||
}
|
||||
assert(natras->texture == nil);
|
||||
natras->texture = createTexture(raster->width, raster->height,
|
||||
raster->format & Raster::MIPMAP ? levels : 1,
|
||||
natras->format);
|
||||
assert(natras->texture && "couldn't create d3d texture");
|
||||
if(natras->texture == nil){
|
||||
RWERROR((ERR_NOTEXTURE));
|
||||
return nil;
|
||||
}
|
||||
return raster;
|
||||
}
|
||||
|
||||
#ifdef RW_D3D9
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateCameraTexture(Raster *raster)
|
||||
{
|
||||
if(raster->format & (Raster::PAL4 | Raster::PAL8))
|
||||
// TODO: give some error
|
||||
return;
|
||||
if(raster->format & (Raster::PAL4 | Raster::PAL8)){
|
||||
RWERROR((ERR_NOTEXTURE));
|
||||
return nil;
|
||||
}
|
||||
|
||||
int32 levels;
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
|
@ -531,12 +530,16 @@ rasterCreateCameraTexture(Raster *raster)
|
|||
(D3DFORMAT)natras->format, D3DPOOL_DEFAULT, &tex, nil);
|
||||
assert(natras->texture == nil);
|
||||
natras->texture = tex;
|
||||
assert(natras->texture && "couldn't create d3d camera texture");
|
||||
if(natras->texture == nil){
|
||||
RWERROR((ERR_NOTEXTURE));
|
||||
return nil;
|
||||
}
|
||||
d3d9Globals.numTextures++;
|
||||
addVidmemRaster(raster);
|
||||
return raster;
|
||||
}
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateCamera(Raster *raster)
|
||||
{
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
|
@ -548,9 +551,10 @@ rasterCreateCamera(Raster *raster)
|
|||
|
||||
natras->format = d3d9Globals.present.BackBufferFormat;
|
||||
raster->depth = findFormatDepth(natras->format);
|
||||
return raster;
|
||||
}
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateZbuffer(Raster *raster)
|
||||
{
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
|
@ -562,10 +566,11 @@ rasterCreateZbuffer(Raster *raster)
|
|||
|
||||
natras->format = d3d9Globals.present.AutoDepthStencilFormat;
|
||||
raster->depth = findFormatDepth(natras->format);
|
||||
return raster;
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
Raster*
|
||||
rasterCreate(Raster *raster)
|
||||
{
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
|
@ -580,29 +585,26 @@ rasterCreate(Raster *raster)
|
|||
if(raster->width == 0 || raster->height == 0){
|
||||
raster->flags |= Raster::DONTALLOCATE;
|
||||
raster->stride = 0;
|
||||
return;
|
||||
return raster;
|
||||
}
|
||||
|
||||
if(raster->flags & Raster::DONTALLOCATE)
|
||||
return;
|
||||
rasterCreateTexture(raster);
|
||||
break;
|
||||
return raster;
|
||||
return rasterCreateTexture(raster);
|
||||
|
||||
#ifdef RW_D3D9
|
||||
case Raster::CAMERATEXTURE:
|
||||
if(raster->flags & Raster::DONTALLOCATE)
|
||||
return;
|
||||
rasterCreateCameraTexture(raster);
|
||||
break;
|
||||
return raster;
|
||||
return rasterCreateCameraTexture(raster);
|
||||
|
||||
case Raster::ZBUFFER:
|
||||
rasterCreateZbuffer(raster);
|
||||
break;
|
||||
return rasterCreateZbuffer(raster);
|
||||
case Raster::CAMERA:
|
||||
rasterCreateCamera(raster);
|
||||
break;
|
||||
return rasterCreateCamera(raster);
|
||||
#endif
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
uint8*
|
||||
|
@ -632,25 +634,30 @@ rasterNumLevels(Raster *raster)
|
|||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
rasterFromImage(Raster *raster, Image *image)
|
||||
bool32
|
||||
imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat)
|
||||
{
|
||||
// Unpalettize image if necessary but don't change original
|
||||
Image *truecolimg = nil;
|
||||
if(image->depth <= 8 && !isP8supported){
|
||||
truecolimg = Image::create(image->width, image->height, image->depth);
|
||||
truecolimg->pixels = image->pixels;
|
||||
truecolimg->stride = image->stride;
|
||||
truecolimg->palette = image->palette;
|
||||
truecolimg->unindex();
|
||||
image = truecolimg;
|
||||
}
|
||||
int32 width, height, depth, format;
|
||||
|
||||
int32 format;
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
switch(image->depth){
|
||||
assert(type == Raster::TEXTURE);
|
||||
|
||||
for(width = 1; width < img->width; width <<= 1);
|
||||
for(height = 1; height < img->height; height <<= 1);
|
||||
|
||||
depth = img->depth;
|
||||
|
||||
if(depth <= 8 && !isP8supported)
|
||||
depth = 32;
|
||||
|
||||
switch(depth){
|
||||
case 32:
|
||||
format = image->hasAlpha() ? Raster::C8888 : Raster::C888;
|
||||
if(img->hasAlpha())
|
||||
format = Raster::C8888;
|
||||
else{
|
||||
format = Raster::C888;
|
||||
depth = 24;
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
format = Raster::C888;
|
||||
|
@ -665,14 +672,60 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
format = Raster::PAL4 | Raster::C8888;
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
format |= Raster::TEXTURE;
|
||||
|
||||
raster->type = format & 0x7;
|
||||
raster->flags = format & 0xF8;
|
||||
raster->format = format & 0xFF00;
|
||||
rasterCreate(raster);
|
||||
format |= type;
|
||||
|
||||
*pWidth = width;
|
||||
*pHeight = height;
|
||||
*pDepth = depth;
|
||||
*pFormat = format;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool32
|
||||
rasterFromImage(Raster *raster, Image *image)
|
||||
{
|
||||
if((raster->type&0xF) != Raster::TEXTURE)
|
||||
return 0;
|
||||
|
||||
// Unpalettize image if necessary but don't change original
|
||||
Image *truecolimg = nil;
|
||||
if(image->depth <= 8 && !isP8supported){
|
||||
truecolimg = Image::create(image->width, image->height, image->depth);
|
||||
truecolimg->pixels = image->pixels;
|
||||
truecolimg->stride = image->stride;
|
||||
truecolimg->palette = image->palette;
|
||||
truecolimg->unindex();
|
||||
image = truecolimg;
|
||||
}
|
||||
|
||||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
switch(image->depth){
|
||||
case 32:
|
||||
if(raster->format != Raster::C8888 &&
|
||||
raster->format != Raster::C888)
|
||||
goto err;
|
||||
break;
|
||||
case 24:
|
||||
if(raster->format != Raster::C888) goto err;
|
||||
break;
|
||||
case 16:
|
||||
if(raster->format != Raster::C1555) goto err;
|
||||
break;
|
||||
case 8:
|
||||
if(raster->format != (Raster::PAL8 | Raster::C8888)) goto err;
|
||||
break;
|
||||
case 4:
|
||||
if(raster->format != (Raster::PAL4 | Raster::C8888)) goto err;
|
||||
break;
|
||||
default:
|
||||
err:
|
||||
RWERROR((ERR_INVRASTER));
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8 *in, *out;
|
||||
int pallength = 0;
|
||||
|
@ -730,6 +783,8 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
|
||||
if(truecolimg)
|
||||
truecolimg->destroy();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Image*
|
||||
|
@ -918,11 +973,14 @@ destroyNativeRaster(void *object, int32 offset, int32)
|
|||
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, offset);
|
||||
#ifdef RW_D3D9
|
||||
destroyD3D9Raster(raster);
|
||||
#endif
|
||||
if(natras->texture){
|
||||
deleteObject(natras->texture);
|
||||
d3d9Globals.numTextures--;
|
||||
}
|
||||
#else
|
||||
if(natras->texture)
|
||||
deleteObject(natras->texture);
|
||||
#endif
|
||||
rwFree(natras->palette);
|
||||
return object;
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ driverOpen(void *o, int32, int32)
|
|||
engine->driver[PLATFORM_D3D8]->rasterLock = rasterLock;
|
||||
engine->driver[PLATFORM_D3D8]->rasterUnlock = rasterUnlock;
|
||||
engine->driver[PLATFORM_D3D8]->rasterNumLevels = rasterNumLevels;
|
||||
engine->driver[PLATFORM_D3D8]->imageFindRasterFormat = imageFindRasterFormat;
|
||||
engine->driver[PLATFORM_D3D8]->rasterFromImage = rasterFromImage;
|
||||
engine->driver[PLATFORM_D3D8]->rasterToImage = rasterToImage;
|
||||
return o;
|
||||
|
|
|
@ -39,6 +39,7 @@ driverOpen(void *o, int32, int32)
|
|||
engine->driver[PLATFORM_D3D9]->rasterLock = rasterLock;
|
||||
engine->driver[PLATFORM_D3D9]->rasterUnlock = rasterUnlock;
|
||||
engine->driver[PLATFORM_D3D9]->rasterNumLevels = rasterNumLevels;
|
||||
engine->driver[PLATFORM_D3D9]->imageFindRasterFormat = imageFindRasterFormat;
|
||||
engine->driver[PLATFORM_D3D9]->rasterFromImage = rasterFromImage;
|
||||
engine->driver[PLATFORM_D3D9]->rasterToImage = rasterToImage;
|
||||
return o;
|
||||
|
@ -688,18 +689,21 @@ readNativeTexture(Stream *stream)
|
|||
// is compressed
|
||||
assert((flags & 2) == 0 && "Can't have cube maps yet");
|
||||
raster = Raster::create(width, height, depth, format | type | Raster::DONTALLOCATE, PLATFORM_D3D9);
|
||||
assert(raster);
|
||||
ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
ext->format = d3dformat;
|
||||
ext->hasAlpha = flags & 1;
|
||||
ext->texture = createTexture(raster->width, raster->height,
|
||||
raster->format & Raster::MIPMAP ? numLevels : 1,
|
||||
ext->format);
|
||||
assert(ext->texture);
|
||||
raster->flags &= ~Raster::DONTALLOCATE;
|
||||
ext->customFormat = 1;
|
||||
}else if(flags & 2){
|
||||
assert(0 && "Can't have cube maps yet");
|
||||
}else{
|
||||
raster = Raster::create(width, height, depth, format | type, PLATFORM_D3D9);
|
||||
assert(raster);
|
||||
ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||
}
|
||||
tex->raster = raster;
|
||||
|
|
|
@ -61,11 +61,13 @@ int findFormatDepth(uint32 format);
|
|||
void destroyD3D9Raster(Raster *raster);
|
||||
#endif
|
||||
|
||||
void rasterCreate(Raster *raster);
|
||||
Raster *rasterCreate(Raster *raster);
|
||||
uint8 *rasterLock(Raster *raster, int32 level, int32 lockMode);
|
||||
void rasterUnlock(Raster *raster, int32 level);
|
||||
int32 rasterNumLevels(Raster *raster);
|
||||
void rasterFromImage(Raster *raster, Image *image);
|
||||
bool32 imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format);
|
||||
bool32 rasterFromImage(Raster *raster, Image *image);
|
||||
Image *rasterToImage(Raster *raster);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
namespace rw {
|
||||
namespace xbox {
|
||||
|
||||
void rasterCreate(Raster *raster);
|
||||
Raster *rasterCreate(Raster *raster);
|
||||
uint8 *rasterLock(Raster *raster, int32 level, int32 lockMode);
|
||||
void rasterUnlock(Raster*, int32);
|
||||
int32 rasterNumLevels(Raster *raster);
|
||||
|
|
|
@ -512,7 +512,7 @@ createTexture(int32 width, int32 height, int32 numlevels, uint32 format)
|
|||
return levels;
|
||||
}
|
||||
|
||||
void
|
||||
Raster*
|
||||
rasterCreate(Raster *raster)
|
||||
{
|
||||
static uint32 formatMap[] = {
|
||||
|
@ -554,14 +554,14 @@ rasterCreate(Raster *raster)
|
|||
if(raster->width == 0 || raster->height == 0){
|
||||
raster->flags |= Raster::DONTALLOCATE;
|
||||
raster->stride = 0;
|
||||
return;
|
||||
return raster;
|
||||
}
|
||||
|
||||
switch(raster->type){
|
||||
case Raster::NORMAL:
|
||||
case Raster::TEXTURE:
|
||||
if(raster->flags & Raster::DONTALLOCATE)
|
||||
return;
|
||||
return raster;
|
||||
if(raster->format & (Raster::PAL4 | Raster::PAL8)){
|
||||
format = D3DFMT_P8;
|
||||
natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
|
||||
|
@ -573,10 +573,14 @@ rasterCreate(Raster *raster)
|
|||
natras->texture = createTexture(raster->width, raster->height,
|
||||
raster->format & Raster::MIPMAP ? levels : 1,
|
||||
format);
|
||||
default:
|
||||
// unsupported
|
||||
return;
|
||||
if(natras->texture == nil){
|
||||
RWERROR((ERR_NOTEXTURE));
|
||||
return nil;
|
||||
}
|
||||
return raster;
|
||||
}
|
||||
// unsupported
|
||||
return nil;
|
||||
}
|
||||
|
||||
uint8*
|
||||
|
|
|
@ -154,6 +154,7 @@ Engine::open(EngineOpenParams *p)
|
|||
engine->driver[i]->rasterLockPalette = null::rasterLockPalette;
|
||||
engine->driver[i]->rasterUnlockPalette = null::rasterUnlockPalette;
|
||||
engine->driver[i]->rasterNumLevels = null::rasterNumLevels;
|
||||
engine->driver[i]->imageFindRasterFormat = null::imageFindRasterFormat;
|
||||
engine->driver[i]->rasterFromImage = null::rasterFromImage;
|
||||
engine->driver[i]->rasterToImage = null::rasterToImage;
|
||||
}
|
||||
|
@ -303,10 +304,11 @@ void im3DTransform(void *vertices, int32 numVertices, Matrix *world) { }
|
|||
void im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices) { }
|
||||
void im3DEnd(void) { }
|
||||
|
||||
void
|
||||
Raster*
|
||||
rasterCreate(Raster*)
|
||||
{
|
||||
assert(0 && "rasterCreate not implemented");
|
||||
return nil;
|
||||
}
|
||||
|
||||
uint8*
|
||||
|
@ -342,10 +344,19 @@ rasterNumLevels(Raster*)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
bool32
|
||||
imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format)
|
||||
{
|
||||
assert(0 && "imageFindRasterFormat not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool32
|
||||
rasterFromImage(Raster*, Image*)
|
||||
{
|
||||
assert(0 && "rasterFromImage not implemented");
|
||||
return 0;
|
||||
}
|
||||
|
||||
Image*
|
||||
|
|
|
@ -55,6 +55,8 @@ Frame::cloneHierarchy(void)
|
|||
void
|
||||
Frame::destroy(void)
|
||||
{
|
||||
FORLIST(lnk, this->objectList)
|
||||
ObjectWithFrame::fromFrame(lnk)->setFrame(nil);
|
||||
s_plglist.destruct(this);
|
||||
if(this->getParent())
|
||||
this->removeChild();
|
||||
|
|
|
@ -33,6 +33,7 @@ driverOpen(void *o, int32, int32)
|
|||
engine->driver[PLATFORM_GL3]->rasterLock = rasterLock;
|
||||
engine->driver[PLATFORM_GL3]->rasterUnlock = rasterUnlock;
|
||||
engine->driver[PLATFORM_GL3]->rasterNumLevels = rasterNumLevels;
|
||||
engine->driver[PLATFORM_GL3]->imageFindRasterFormat = imageFindRasterFormat;
|
||||
engine->driver[PLATFORM_GL3]->rasterFromImage = rasterFromImage;
|
||||
|
||||
return o;
|
||||
|
|
|
@ -15,12 +15,14 @@
|
|||
#include "rwgl3.h"
|
||||
#include "rwgl3shader.h"
|
||||
|
||||
#define PLUGIN_ID ID_DRIVER
|
||||
|
||||
namespace rw {
|
||||
namespace gl3 {
|
||||
|
||||
int32 nativeRasterOffset;
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateTexture(Raster *raster)
|
||||
{
|
||||
#ifdef RW_OPENGL
|
||||
|
@ -46,7 +48,8 @@ rasterCreateTexture(Raster *raster)
|
|||
natras->hasAlpha = 1;
|
||||
break;
|
||||
default:
|
||||
assert(0 && "unsupported raster format");
|
||||
RWERROR((ERR_INVRASTER));
|
||||
return nil;
|
||||
}
|
||||
|
||||
glGenTextures(1, &natras->texid);
|
||||
|
@ -59,6 +62,9 @@ rasterCreateTexture(Raster *raster)
|
|||
natras->addressV = 0;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return raster;
|
||||
#else
|
||||
return nil;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -67,12 +73,13 @@ rasterCreateTexture(Raster *raster)
|
|||
// This is totally fake right now, can't render to it. Only used to copy into from FB
|
||||
// For rendering the idea would probably be to render to the backbuffer and copy it here afterwards.
|
||||
// alternatively just use FBOs but that probably needs some more infrastructure.
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateCameraTexture(Raster *raster)
|
||||
{
|
||||
if(raster->format & (Raster::PAL4 | Raster::PAL8))
|
||||
// TODO: give some error
|
||||
return;
|
||||
if(raster->format & (Raster::PAL4 | Raster::PAL8)){
|
||||
RWERROR((ERR_NOTEXTURE));
|
||||
return nil;
|
||||
}
|
||||
|
||||
// TODO: figure out what the backbuffer is and use that as a default
|
||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
||||
|
@ -109,9 +116,10 @@ rasterCreateCameraTexture(Raster *raster)
|
|||
natras->addressV = 0;
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
return raster;
|
||||
}
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateCamera(Raster *raster)
|
||||
{
|
||||
// TODO: set/check width, height, depth, format?
|
||||
|
@ -120,18 +128,20 @@ rasterCreateCamera(Raster *raster)
|
|||
raster->originalHeight = raster->height;
|
||||
raster->stride = 0;
|
||||
raster->pixels = nil;
|
||||
return raster;
|
||||
}
|
||||
|
||||
static void
|
||||
static Raster*
|
||||
rasterCreateZbuffer(Raster *raster)
|
||||
{
|
||||
// TODO: set/check width, height, depth, format?
|
||||
raster->flags |= Raster::DONTALLOCATE;
|
||||
return raster;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void
|
||||
Raster*
|
||||
rasterCreate(Raster *raster)
|
||||
{
|
||||
switch(raster->type){
|
||||
|
@ -142,32 +152,29 @@ rasterCreate(Raster *raster)
|
|||
if(raster->width == 0 || raster->height == 0){
|
||||
raster->flags |= Raster::DONTALLOCATE;
|
||||
raster->stride = 0;
|
||||
return;
|
||||
return raster;
|
||||
}
|
||||
|
||||
if(raster->flags & Raster::DONTALLOCATE)
|
||||
return;
|
||||
rasterCreateTexture(raster);
|
||||
break;
|
||||
return raster;
|
||||
return rasterCreateTexture(raster);
|
||||
|
||||
#ifdef RW_OPENGL
|
||||
case Raster::CAMERATEXTURE:
|
||||
if(raster->flags & Raster::DONTALLOCATE)
|
||||
return;
|
||||
rasterCreateCameraTexture(raster);
|
||||
break;
|
||||
return raster;
|
||||
return rasterCreateCameraTexture(raster);
|
||||
|
||||
case Raster::ZBUFFER:
|
||||
rasterCreateZbuffer(raster);
|
||||
break;
|
||||
return rasterCreateZbuffer(raster);
|
||||
case Raster::CAMERA:
|
||||
rasterCreateCamera(raster);
|
||||
break;
|
||||
return rasterCreateCamera(raster);
|
||||
#endif
|
||||
|
||||
default:
|
||||
assert(0 && "unsupported format");
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
uint8*
|
||||
|
@ -190,9 +197,18 @@ rasterNumLevels(Raster*)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
bool32
|
||||
imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format)
|
||||
{
|
||||
assert(0 && "not yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool32
|
||||
rasterFromImage(Raster *raster, Image *image)
|
||||
{
|
||||
assert(0 && "not yet");
|
||||
int32 format;
|
||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
||||
|
||||
|
@ -225,6 +241,7 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
0, natras->format, natras->type, image->pixels);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void*
|
||||
|
|
|
@ -22,11 +22,13 @@ void im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices);
|
|||
void im3DEnd(void);
|
||||
#endif
|
||||
|
||||
void rasterCreate(Raster *raster);
|
||||
Raster *rasterCreate(Raster *raster);
|
||||
uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
|
||||
void rasterUnlock(Raster*, int32);
|
||||
int32 rasterNumLevels(Raster*);
|
||||
void rasterFromImage(Raster *raster, Image *image);
|
||||
bool32 imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format);
|
||||
bool32 rasterFromImage(Raster *raster, Image *image);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ driverOpen(void *o, int32, int32)
|
|||
engine->driver[PLATFORM_PS2]->rasterLockPalette = rasterLockPalette;
|
||||
engine->driver[PLATFORM_PS2]->rasterUnlockPalette = rasterUnlockPalette;
|
||||
engine->driver[PLATFORM_PS2]->rasterNumLevels = rasterNumLevels;
|
||||
engine->driver[PLATFORM_PS2]->imageFindRasterFormat = imageFindRasterFormat;
|
||||
engine->driver[PLATFORM_PS2]->rasterFromImage = rasterFromImage;
|
||||
engine->driver[PLATFORM_PS2]->rasterToImage = rasterToImage;
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
#include "../rwengine.h"
|
||||
#include "rwps2.h"
|
||||
|
||||
#define PLUGIN_ID 0
|
||||
#define PLUGIN_ID ID_DRIVER
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
@ -755,8 +755,8 @@ calcOffsets(int32 width_Px, int32 height_Px, int32 psm, uint64 *bufferBase_B, ui
|
|||
#undef REALHEIGHT
|
||||
}
|
||||
|
||||
static void
|
||||
createTexRaster(Raster *raster)
|
||||
static Raster*
|
||||
rasterCreateTexture(Raster *raster)
|
||||
{
|
||||
// We use a map for fast lookup, even for impossible depths
|
||||
static int32 pageWidths[32] = {
|
||||
|
@ -809,7 +809,7 @@ createTexRaster(Raster *raster)
|
|||
|
||||
// RW doesn't seem to check this, hm...
|
||||
if(raster->flags & Raster::DONTALLOCATE)
|
||||
return;
|
||||
return raster;
|
||||
|
||||
//printf("%x %x %x %x\n", raster->format, raster->flags, raster->type, noNewStyleRasters);
|
||||
pageWidth = pageWidths[depth-1];
|
||||
|
@ -841,7 +841,7 @@ createTexRaster(Raster *raster)
|
|||
paletteHeight = 2;
|
||||
}else{
|
||||
// can't happen, sanity check in getRasterFormat
|
||||
return;
|
||||
return nil;;
|
||||
}
|
||||
tcc = 1; // RGBA
|
||||
cld = 1;
|
||||
|
@ -857,7 +857,7 @@ createTexRaster(Raster *raster)
|
|||
palettePageheight = 32;
|
||||
}else
|
||||
// can't happen, sanity check in getRasterFormat
|
||||
return;
|
||||
return nil;;
|
||||
}else{
|
||||
paletteWidth = 0;
|
||||
paletteHeight = 0;
|
||||
|
@ -875,7 +875,7 @@ createTexRaster(Raster *raster)
|
|||
tcc = 1; // RGBA
|
||||
}else
|
||||
// can't happen, sanity check in getRasterFormat
|
||||
return;
|
||||
return nil;;
|
||||
}
|
||||
|
||||
for(int i = 0; i < 7; i++){
|
||||
|
@ -1308,13 +1308,14 @@ createTexRaster(Raster *raster)
|
|||
raster->originalStride = raster->stride;
|
||||
if(ras->flags & Ps2Raster::NEWSTYLE)
|
||||
raster->pixels = ((Ps2Raster::PixelPtr*)raster->pixels)->pixels + 0x50;
|
||||
return raster;
|
||||
}
|
||||
|
||||
void
|
||||
Raster*
|
||||
rasterCreate(Raster *raster)
|
||||
{
|
||||
if(!getRasterFormat(raster))
|
||||
return;
|
||||
return nil;
|
||||
|
||||
// init raster
|
||||
raster->pixels = nil;
|
||||
|
@ -1326,32 +1327,29 @@ rasterCreate(Raster *raster)
|
|||
raster->flags = Raster::DONTALLOCATE;
|
||||
raster->stride = 0;
|
||||
raster->originalStride = 0;
|
||||
return;
|
||||
return raster;
|
||||
}
|
||||
|
||||
switch(raster->type){
|
||||
case Raster::NORMAL:
|
||||
// TODO
|
||||
break;
|
||||
case Raster::TEXTURE:
|
||||
return rasterCreateTexture(raster);
|
||||
case Raster::ZBUFFER:
|
||||
// TODO. only RW_PS2
|
||||
// get info from video mode
|
||||
raster->flags = Raster::DONTALLOCATE;
|
||||
break;
|
||||
return raster;
|
||||
case Raster::CAMERA:
|
||||
// TODO. only RW_PS2
|
||||
// get info from video mode
|
||||
raster->flags = Raster::DONTALLOCATE;
|
||||
break;
|
||||
case Raster::TEXTURE:
|
||||
createTexRaster(raster);
|
||||
break;
|
||||
return raster;
|
||||
case Raster::CAMERATEXTURE:
|
||||
// TODO. only RW_PS2
|
||||
// check width/height and fall through to texture
|
||||
break;
|
||||
return nil;
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
static uint32
|
||||
|
@ -1595,9 +1593,18 @@ copyPSMT8(uint8 *dst, uint8 *src, int32 w, int32 h, int32 srcw)
|
|||
dst[y*w + x] = src[y*srcw + x];
|
||||
}
|
||||
|
||||
void
|
||||
bool32
|
||||
imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format)
|
||||
{
|
||||
assert(0 && "not yet");
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool32
|
||||
rasterFromImage(Raster *raster, Image *image)
|
||||
{
|
||||
assert(0 && "not yet");
|
||||
Ps2Raster *natras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset);
|
||||
|
||||
raster->flags &= ~Raster::DONTALLOCATE;
|
||||
|
@ -1669,6 +1676,7 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
}
|
||||
}
|
||||
raster->unlock(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
Image*
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
namespace rw {
|
||||
namespace ps2 {
|
||||
|
||||
void rasterCreate(Raster *raster);
|
||||
Raster *rasterCreate(Raster *raster);
|
||||
uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
|
||||
void rasterUnlock(Raster*, int32 level);
|
||||
uint8 *rasterLockPalette(Raster*, int32 lockMode);
|
||||
void rasterUnlockPalette(Raster*);
|
||||
int32 rasterNumLevels(Raster*);
|
||||
void rasterFromImage(Raster *raster, Image *image);
|
||||
bool32 imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format);
|
||||
bool32 rasterFromImage(Raster *raster, Image *image);
|
||||
Image *rasterToImage(Raster *raster);
|
||||
|
||||
}
|
||||
|
|
|
@ -75,8 +75,7 @@ Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platf
|
|||
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;
|
||||
return engine->driver[raster->platform]->rasterCreate(raster);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -147,14 +146,34 @@ Raster::formatHasAlpha(int32 format)
|
|||
(format & 0xF00) == Raster::C4444;
|
||||
}
|
||||
|
||||
bool32
|
||||
Raster::imageFindRasterFormat(Image *image, int32 type,
|
||||
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat,
|
||||
int32 platform)
|
||||
{
|
||||
return engine->driver[platform ? platform : rw::platform]->imageFindRasterFormat(
|
||||
image, type, pWidth, pHeight, pDepth, pFormat);
|
||||
}
|
||||
|
||||
Raster*
|
||||
Raster::setFromImage(Image *image, int32 platform)
|
||||
{
|
||||
if(engine->driver[platform ? platform : rw::platform]->rasterFromImage(this, image))
|
||||
return this;
|
||||
return nil;
|
||||
}
|
||||
|
||||
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;
|
||||
Raster *raster;
|
||||
int32 width, height, depth, format;
|
||||
if(!imageFindRasterFormat(image, TEXTURE, &width, &height, &depth, &format, platform))
|
||||
return nil;
|
||||
raster = Raster::create(width, height, depth, format, platform);
|
||||
if(raster == nil)
|
||||
return nil;
|
||||
return raster->setFromImage(image, platform);
|
||||
}
|
||||
|
||||
Image*
|
||||
|
|
|
@ -72,13 +72,15 @@ struct Driver
|
|||
ObjPipeline *defaultPipeline;
|
||||
int32 rasterNativeOffset;
|
||||
|
||||
void (*rasterCreate)(Raster*);
|
||||
Raster* (*rasterCreate)(Raster*);
|
||||
uint8 *(*rasterLock)(Raster*, int32 level, int32 lockMode);
|
||||
void (*rasterUnlock)(Raster*, int32 level);
|
||||
uint8 *(*rasterLockPalette)(Raster*, int32 lockMode);
|
||||
void (*rasterUnlockPalette)(Raster*);
|
||||
int32 (*rasterNumLevels)(Raster*);
|
||||
void (*rasterFromImage)(Raster*, Image*);
|
||||
bool32 (*imageFindRasterFormat)(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format);
|
||||
bool32 (*rasterFromImage)(Raster*, Image*);
|
||||
Image *(*rasterToImage)(Raster*);
|
||||
|
||||
static PluginList s_plglist[NUM_PLATFORMS];
|
||||
|
@ -203,13 +205,15 @@ namespace null {
|
|||
void setRenderState(int32 state, void *value);
|
||||
void *getRenderState(int32 state);
|
||||
|
||||
void rasterCreate(Raster*);
|
||||
Raster *rasterCreate(Raster*);
|
||||
uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
|
||||
void rasterUnlock(Raster*, int32 level);
|
||||
uint8 *rasterLockPalette(Raster*, int32 lockMode);
|
||||
void rasterUnlockPalette(Raster*);
|
||||
int32 rasterNumLevels(Raster*);
|
||||
void rasterFromImage(Raster*, Image*);
|
||||
bool32 imageFindRasterFormat(Image *img, int32 type,
|
||||
int32 *width, int32 *height, int32 *depth, int32 *format);
|
||||
bool32 rasterFromImage(Raster*, Image*);
|
||||
Image *rasterToImage(Raster*);
|
||||
|
||||
void im2DRenderLine(void*, int32, int32, int32);
|
||||
|
|
|
@ -196,6 +196,9 @@ struct Raster
|
|||
int32 format, int32 platform = 0);
|
||||
void subRaster(Raster *parent, Rect *r);
|
||||
void destroy(void);
|
||||
static bool32 imageFindRasterFormat(Image *image, int32 type,
|
||||
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat, int32 platform = 0);
|
||||
Raster *Raster::setFromImage(Image *image, int32 platform = 0);
|
||||
static Raster *createFromImage(Image *image, int32 platform = 0);
|
||||
Image *toImage(void);
|
||||
uint8 *lock(int32 level, int32 lockMode);
|
||||
|
|
Loading…
Reference in New Issue