reworked raster from image conversion, only d3d for now

This commit is contained in:
aap 2020-04-17 21:44:32 +02:00
parent 206547b404
commit 4893889621
18 changed files with 262 additions and 121 deletions

View File

@ -17,4 +17,6 @@ ECODE(ERR_ENGINEOPEN,
ECODE(ERR_ENGINESTART, ECODE(ERR_ENGINESTART,
"Engine could not be started"), "Engine could not be started"),
ECODE(ERR_INVRASTER, ECODE(ERR_INVRASTER,
"Invalid raster format") "Invalid raster format"),
ECODE(ERR_NOTEXTURE,
"Could not create texture")

View File

@ -5,6 +5,7 @@
#define WITH_D3D #define WITH_D3D
#include "../rwbase.h" #include "../rwbase.h"
#include "../rwerror.h"
#include "../rwplg.h" #include "../rwplg.h"
#include "../rwpipeline.h" #include "../rwpipeline.h"
#include "../rwobjects.h" #include "../rwobjects.h"
@ -12,6 +13,8 @@
#include "rwd3d.h" #include "rwd3d.h"
#include "rwd3dimpl.h" #include "rwd3dimpl.h"
#define PLUGIN_ID ID_DRIVER
namespace rw { namespace rw {
namespace d3d { namespace d3d {
@ -238,7 +241,6 @@ createVertexBuffer(uint32 length, uint32 fvf, bool dynamic)
return vbuf; return vbuf;
#else #else
(void)fvf; (void)fvf;
(void)pool;
return rwNewT(uint8, length, MEMDUR_EVENT | ID_DRIVER); return rwNewT(uint8, length, MEMDUR_EVENT | ID_DRIVER);
#endif #endif
} }
@ -487,7 +489,7 @@ rasterSetFormat(Raster *raster)
natras->hasAlpha = formatInfoRW[(raster->format >> 8) & 0xF].hasAlpha; natras->hasAlpha = formatInfoRW[(raster->format >> 8) & 0xF].hasAlpha;
} }
static void static Raster*
rasterCreateTexture(Raster *raster) rasterCreateTexture(Raster *raster)
{ {
int32 levels; int32 levels;
@ -496,29 +498,26 @@ rasterCreateTexture(Raster *raster)
if(natras->format == D3DFMT_P8) if(natras->format == D3DFMT_P8)
natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER); natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
levels = Raster::calculateNumLevels(raster->width, raster->height); 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); assert(natras->texture == nil);
natras->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,
natras->format); natras->format);
assert(natras->texture && "couldn't create d3d texture"); if(natras->texture == nil){
RWERROR((ERR_NOTEXTURE));
return nil;
}
return raster;
} }
#ifdef RW_D3D9 #ifdef RW_D3D9
static void static Raster*
rasterCreateCameraTexture(Raster *raster) rasterCreateCameraTexture(Raster *raster)
{ {
if(raster->format & (Raster::PAL4 | Raster::PAL8)) if(raster->format & (Raster::PAL4 | Raster::PAL8)){
// TODO: give some error RWERROR((ERR_NOTEXTURE));
return; return nil;
}
int32 levels; int32 levels;
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
@ -531,12 +530,16 @@ rasterCreateCameraTexture(Raster *raster)
(D3DFORMAT)natras->format, D3DPOOL_DEFAULT, &tex, nil); (D3DFORMAT)natras->format, D3DPOOL_DEFAULT, &tex, nil);
assert(natras->texture == nil); assert(natras->texture == nil);
natras->texture = tex; natras->texture = tex;
assert(natras->texture && "couldn't create d3d camera texture"); if(natras->texture == nil){
RWERROR((ERR_NOTEXTURE));
return nil;
}
d3d9Globals.numTextures++; d3d9Globals.numTextures++;
addVidmemRaster(raster); addVidmemRaster(raster);
return raster;
} }
static void static Raster*
rasterCreateCamera(Raster *raster) rasterCreateCamera(Raster *raster)
{ {
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
@ -548,9 +551,10 @@ rasterCreateCamera(Raster *raster)
natras->format = d3d9Globals.present.BackBufferFormat; natras->format = d3d9Globals.present.BackBufferFormat;
raster->depth = findFormatDepth(natras->format); raster->depth = findFormatDepth(natras->format);
return raster;
} }
static void static Raster*
rasterCreateZbuffer(Raster *raster) rasterCreateZbuffer(Raster *raster)
{ {
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
@ -562,10 +566,11 @@ rasterCreateZbuffer(Raster *raster)
natras->format = d3d9Globals.present.AutoDepthStencilFormat; natras->format = d3d9Globals.present.AutoDepthStencilFormat;
raster->depth = findFormatDepth(natras->format); raster->depth = findFormatDepth(natras->format);
return raster;
} }
#endif #endif
void Raster*
rasterCreate(Raster *raster) rasterCreate(Raster *raster)
{ {
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
@ -580,29 +585,26 @@ rasterCreate(Raster *raster)
if(raster->width == 0 || raster->height == 0){ if(raster->width == 0 || raster->height == 0){
raster->flags |= Raster::DONTALLOCATE; raster->flags |= Raster::DONTALLOCATE;
raster->stride = 0; raster->stride = 0;
return; return raster;
} }
if(raster->flags & Raster::DONTALLOCATE) if(raster->flags & Raster::DONTALLOCATE)
return; return raster;
rasterCreateTexture(raster); return rasterCreateTexture(raster);
break;
#ifdef RW_D3D9 #ifdef RW_D3D9
case Raster::CAMERATEXTURE: case Raster::CAMERATEXTURE:
if(raster->flags & Raster::DONTALLOCATE) if(raster->flags & Raster::DONTALLOCATE)
return; return raster;
rasterCreateCameraTexture(raster); return rasterCreateCameraTexture(raster);
break;
case Raster::ZBUFFER: case Raster::ZBUFFER:
rasterCreateZbuffer(raster); return rasterCreateZbuffer(raster);
break;
case Raster::CAMERA: case Raster::CAMERA:
rasterCreateCamera(raster); return rasterCreateCamera(raster);
break;
#endif #endif
} }
return nil;
} }
uint8* uint8*
@ -632,25 +634,30 @@ rasterNumLevels(Raster *raster)
#endif #endif
} }
void bool32
rasterFromImage(Raster *raster, Image *image) imageFindRasterFormat(Image *img, int32 type,
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat)
{ {
// Unpalettize image if necessary but don't change original int32 width, height, depth, format;
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 format; assert(type == Raster::TEXTURE);
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
switch(image->depth){ 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: case 32:
format = image->hasAlpha() ? Raster::C8888 : Raster::C888; if(img->hasAlpha())
format = Raster::C8888;
else{
format = Raster::C888;
depth = 24;
}
break; break;
case 24: case 24:
format = Raster::C888; format = Raster::C888;
@ -665,14 +672,60 @@ rasterFromImage(Raster *raster, Image *image)
format = Raster::PAL4 | Raster::C8888; format = Raster::PAL4 | Raster::C8888;
break; break;
default: default:
return; return 0;
} }
format |= Raster::TEXTURE;
raster->type = format & 0x7; format |= type;
raster->flags = format & 0xF8;
raster->format = format & 0xFF00; *pWidth = width;
rasterCreate(raster); *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; uint8 *in, *out;
int pallength = 0; int pallength = 0;
@ -730,6 +783,8 @@ rasterFromImage(Raster *raster, Image *image)
if(truecolimg) if(truecolimg)
truecolimg->destroy(); truecolimg->destroy();
return 1;
} }
Image* Image*
@ -918,11 +973,14 @@ destroyNativeRaster(void *object, int32 offset, int32)
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, offset); D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, offset);
#ifdef RW_D3D9 #ifdef RW_D3D9
destroyD3D9Raster(raster); destroyD3D9Raster(raster);
#endif
if(natras->texture){ if(natras->texture){
deleteObject(natras->texture); deleteObject(natras->texture);
d3d9Globals.numTextures--; d3d9Globals.numTextures--;
} }
#else
if(natras->texture)
deleteObject(natras->texture);
#endif
rwFree(natras->palette); rwFree(natras->palette);
return object; return object;
} }

View File

@ -31,6 +31,7 @@ driverOpen(void *o, int32, int32)
engine->driver[PLATFORM_D3D8]->rasterLock = rasterLock; engine->driver[PLATFORM_D3D8]->rasterLock = rasterLock;
engine->driver[PLATFORM_D3D8]->rasterUnlock = rasterUnlock; engine->driver[PLATFORM_D3D8]->rasterUnlock = rasterUnlock;
engine->driver[PLATFORM_D3D8]->rasterNumLevels = rasterNumLevels; engine->driver[PLATFORM_D3D8]->rasterNumLevels = rasterNumLevels;
engine->driver[PLATFORM_D3D8]->imageFindRasterFormat = imageFindRasterFormat;
engine->driver[PLATFORM_D3D8]->rasterFromImage = rasterFromImage; engine->driver[PLATFORM_D3D8]->rasterFromImage = rasterFromImage;
engine->driver[PLATFORM_D3D8]->rasterToImage = rasterToImage; engine->driver[PLATFORM_D3D8]->rasterToImage = rasterToImage;
return o; return o;

View File

@ -39,6 +39,7 @@ driverOpen(void *o, int32, int32)
engine->driver[PLATFORM_D3D9]->rasterLock = rasterLock; engine->driver[PLATFORM_D3D9]->rasterLock = rasterLock;
engine->driver[PLATFORM_D3D9]->rasterUnlock = rasterUnlock; engine->driver[PLATFORM_D3D9]->rasterUnlock = rasterUnlock;
engine->driver[PLATFORM_D3D9]->rasterNumLevels = rasterNumLevels; engine->driver[PLATFORM_D3D9]->rasterNumLevels = rasterNumLevels;
engine->driver[PLATFORM_D3D9]->imageFindRasterFormat = imageFindRasterFormat;
engine->driver[PLATFORM_D3D9]->rasterFromImage = rasterFromImage; engine->driver[PLATFORM_D3D9]->rasterFromImage = rasterFromImage;
engine->driver[PLATFORM_D3D9]->rasterToImage = rasterToImage; engine->driver[PLATFORM_D3D9]->rasterToImage = rasterToImage;
return o; return o;
@ -688,18 +689,21 @@ readNativeTexture(Stream *stream)
// is compressed // is compressed
assert((flags & 2) == 0 && "Can't have cube maps yet"); assert((flags & 2) == 0 && "Can't have cube maps yet");
raster = Raster::create(width, height, depth, format | type | Raster::DONTALLOCATE, PLATFORM_D3D9); raster = Raster::create(width, height, depth, format | type | Raster::DONTALLOCATE, PLATFORM_D3D9);
assert(raster);
ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
ext->format = d3dformat; ext->format = d3dformat;
ext->hasAlpha = flags & 1; ext->hasAlpha = flags & 1;
ext->texture = createTexture(raster->width, raster->height, ext->texture = createTexture(raster->width, raster->height,
raster->format & Raster::MIPMAP ? numLevels : 1, raster->format & Raster::MIPMAP ? numLevels : 1,
ext->format); ext->format);
assert(ext->texture);
raster->flags &= ~Raster::DONTALLOCATE; raster->flags &= ~Raster::DONTALLOCATE;
ext->customFormat = 1; ext->customFormat = 1;
}else if(flags & 2){ }else if(flags & 2){
assert(0 && "Can't have cube maps yet"); assert(0 && "Can't have cube maps yet");
}else{ }else{
raster = Raster::create(width, height, depth, format | type, PLATFORM_D3D9); raster = Raster::create(width, height, depth, format | type, PLATFORM_D3D9);
assert(raster);
ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset); ext = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
} }
tex->raster = raster; tex->raster = raster;

View File

@ -61,11 +61,13 @@ int findFormatDepth(uint32 format);
void destroyD3D9Raster(Raster *raster); void destroyD3D9Raster(Raster *raster);
#endif #endif
void rasterCreate(Raster *raster); Raster *rasterCreate(Raster *raster);
uint8 *rasterLock(Raster *raster, int32 level, int32 lockMode); uint8 *rasterLock(Raster *raster, int32 level, int32 lockMode);
void rasterUnlock(Raster *raster, int32 level); void rasterUnlock(Raster *raster, int32 level);
int32 rasterNumLevels(Raster *raster); 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); Image *rasterToImage(Raster *raster);
} }

View File

@ -1,7 +1,7 @@
namespace rw { namespace rw {
namespace xbox { namespace xbox {
void rasterCreate(Raster *raster); Raster *rasterCreate(Raster *raster);
uint8 *rasterLock(Raster *raster, int32 level, int32 lockMode); uint8 *rasterLock(Raster *raster, int32 level, int32 lockMode);
void rasterUnlock(Raster*, int32); void rasterUnlock(Raster*, int32);
int32 rasterNumLevels(Raster *raster); int32 rasterNumLevels(Raster *raster);

View File

@ -512,7 +512,7 @@ createTexture(int32 width, int32 height, int32 numlevels, uint32 format)
return levels; return levels;
} }
void Raster*
rasterCreate(Raster *raster) rasterCreate(Raster *raster)
{ {
static uint32 formatMap[] = { static uint32 formatMap[] = {
@ -554,14 +554,14 @@ rasterCreate(Raster *raster)
if(raster->width == 0 || raster->height == 0){ if(raster->width == 0 || raster->height == 0){
raster->flags |= Raster::DONTALLOCATE; raster->flags |= Raster::DONTALLOCATE;
raster->stride = 0; raster->stride = 0;
return; return raster;
} }
switch(raster->type){ switch(raster->type){
case Raster::NORMAL: case Raster::NORMAL:
case Raster::TEXTURE: case Raster::TEXTURE:
if(raster->flags & Raster::DONTALLOCATE) if(raster->flags & Raster::DONTALLOCATE)
return; return raster;
if(raster->format & (Raster::PAL4 | Raster::PAL8)){ if(raster->format & (Raster::PAL4 | Raster::PAL8)){
format = D3DFMT_P8; format = D3DFMT_P8;
natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER); natras->palette = (uint8*)rwNew(4*256, MEMDUR_EVENT | ID_DRIVER);
@ -573,10 +573,14 @@ rasterCreate(Raster *raster)
natras->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);
default: if(natras->texture == nil){
// unsupported RWERROR((ERR_NOTEXTURE));
return; return nil;
}
return raster;
} }
// unsupported
return nil;
} }
uint8* uint8*

View File

@ -154,6 +154,7 @@ Engine::open(EngineOpenParams *p)
engine->driver[i]->rasterLockPalette = null::rasterLockPalette; engine->driver[i]->rasterLockPalette = null::rasterLockPalette;
engine->driver[i]->rasterUnlockPalette = null::rasterUnlockPalette; engine->driver[i]->rasterUnlockPalette = null::rasterUnlockPalette;
engine->driver[i]->rasterNumLevels = null::rasterNumLevels; engine->driver[i]->rasterNumLevels = null::rasterNumLevels;
engine->driver[i]->imageFindRasterFormat = null::imageFindRasterFormat;
engine->driver[i]->rasterFromImage = null::rasterFromImage; engine->driver[i]->rasterFromImage = null::rasterFromImage;
engine->driver[i]->rasterToImage = null::rasterToImage; 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 im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices) { }
void im3DEnd(void) { } void im3DEnd(void) { }
void Raster*
rasterCreate(Raster*) rasterCreate(Raster*)
{ {
assert(0 && "rasterCreate not implemented"); assert(0 && "rasterCreate not implemented");
return nil;
} }
uint8* uint8*
@ -342,10 +344,19 @@ rasterNumLevels(Raster*)
return 0; 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*) rasterFromImage(Raster*, Image*)
{ {
assert(0 && "rasterFromImage not implemented"); assert(0 && "rasterFromImage not implemented");
return 0;
} }
Image* Image*

View File

@ -55,6 +55,8 @@ Frame::cloneHierarchy(void)
void void
Frame::destroy(void) Frame::destroy(void)
{ {
FORLIST(lnk, this->objectList)
ObjectWithFrame::fromFrame(lnk)->setFrame(nil);
s_plglist.destruct(this); s_plglist.destruct(this);
if(this->getParent()) if(this->getParent())
this->removeChild(); this->removeChild();

View File

@ -33,6 +33,7 @@ driverOpen(void *o, int32, int32)
engine->driver[PLATFORM_GL3]->rasterLock = rasterLock; engine->driver[PLATFORM_GL3]->rasterLock = rasterLock;
engine->driver[PLATFORM_GL3]->rasterUnlock = rasterUnlock; engine->driver[PLATFORM_GL3]->rasterUnlock = rasterUnlock;
engine->driver[PLATFORM_GL3]->rasterNumLevels = rasterNumLevels; engine->driver[PLATFORM_GL3]->rasterNumLevels = rasterNumLevels;
engine->driver[PLATFORM_GL3]->imageFindRasterFormat = imageFindRasterFormat;
engine->driver[PLATFORM_GL3]->rasterFromImage = rasterFromImage; engine->driver[PLATFORM_GL3]->rasterFromImage = rasterFromImage;
return o; return o;

View File

@ -15,12 +15,14 @@
#include "rwgl3.h" #include "rwgl3.h"
#include "rwgl3shader.h" #include "rwgl3shader.h"
#define PLUGIN_ID ID_DRIVER
namespace rw { namespace rw {
namespace gl3 { namespace gl3 {
int32 nativeRasterOffset; int32 nativeRasterOffset;
static void static Raster*
rasterCreateTexture(Raster *raster) rasterCreateTexture(Raster *raster)
{ {
#ifdef RW_OPENGL #ifdef RW_OPENGL
@ -46,7 +48,8 @@ rasterCreateTexture(Raster *raster)
natras->hasAlpha = 1; natras->hasAlpha = 1;
break; break;
default: default:
assert(0 && "unsupported raster format"); RWERROR((ERR_INVRASTER));
return nil;
} }
glGenTextures(1, &natras->texid); glGenTextures(1, &natras->texid);
@ -59,6 +62,9 @@ rasterCreateTexture(Raster *raster)
natras->addressV = 0; natras->addressV = 0;
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
return raster;
#else
return nil;
#endif #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 // 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. // 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. // alternatively just use FBOs but that probably needs some more infrastructure.
static void static Raster*
rasterCreateCameraTexture(Raster *raster) rasterCreateCameraTexture(Raster *raster)
{ {
if(raster->format & (Raster::PAL4 | Raster::PAL8)) if(raster->format & (Raster::PAL4 | Raster::PAL8)){
// TODO: give some error RWERROR((ERR_NOTEXTURE));
return; return nil;
}
// TODO: figure out what the backbuffer is and use that as a default // TODO: figure out what the backbuffer is and use that as a default
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset); Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
@ -109,9 +116,10 @@ rasterCreateCameraTexture(Raster *raster)
natras->addressV = 0; natras->addressV = 0;
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
return raster;
} }
static void static Raster*
rasterCreateCamera(Raster *raster) rasterCreateCamera(Raster *raster)
{ {
// TODO: set/check width, height, depth, format? // TODO: set/check width, height, depth, format?
@ -120,18 +128,20 @@ rasterCreateCamera(Raster *raster)
raster->originalHeight = raster->height; raster->originalHeight = raster->height;
raster->stride = 0; raster->stride = 0;
raster->pixels = nil; raster->pixels = nil;
return raster;
} }
static void static Raster*
rasterCreateZbuffer(Raster *raster) rasterCreateZbuffer(Raster *raster)
{ {
// TODO: set/check width, height, depth, format? // TODO: set/check width, height, depth, format?
raster->flags |= Raster::DONTALLOCATE; raster->flags |= Raster::DONTALLOCATE;
return raster;
} }
#endif #endif
void Raster*
rasterCreate(Raster *raster) rasterCreate(Raster *raster)
{ {
switch(raster->type){ switch(raster->type){
@ -142,32 +152,29 @@ rasterCreate(Raster *raster)
if(raster->width == 0 || raster->height == 0){ if(raster->width == 0 || raster->height == 0){
raster->flags |= Raster::DONTALLOCATE; raster->flags |= Raster::DONTALLOCATE;
raster->stride = 0; raster->stride = 0;
return; return raster;
} }
if(raster->flags & Raster::DONTALLOCATE) if(raster->flags & Raster::DONTALLOCATE)
return; return raster;
rasterCreateTexture(raster); return rasterCreateTexture(raster);
break;
#ifdef RW_OPENGL #ifdef RW_OPENGL
case Raster::CAMERATEXTURE: case Raster::CAMERATEXTURE:
if(raster->flags & Raster::DONTALLOCATE) if(raster->flags & Raster::DONTALLOCATE)
return; return raster;
rasterCreateCameraTexture(raster); return rasterCreateCameraTexture(raster);
break;
case Raster::ZBUFFER: case Raster::ZBUFFER:
rasterCreateZbuffer(raster); return rasterCreateZbuffer(raster);
break;
case Raster::CAMERA: case Raster::CAMERA:
rasterCreateCamera(raster); return rasterCreateCamera(raster);
break;
#endif #endif
default: default:
assert(0 && "unsupported format"); assert(0 && "unsupported format");
} }
return nil;
} }
uint8* uint8*
@ -190,9 +197,18 @@ rasterNumLevels(Raster*)
return 0; 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) rasterFromImage(Raster *raster, Image *image)
{ {
assert(0 && "not yet");
int32 format; int32 format;
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset); Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
@ -225,6 +241,7 @@ rasterFromImage(Raster *raster, Image *image)
0, natras->format, natras->type, image->pixels); 0, natras->format, natras->type, image->pixels);
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
#endif #endif
return 1;
} }
static void* static void*

View File

@ -22,11 +22,13 @@ void im3DRenderIndexed(PrimitiveType primType, void *indices, int32 numIndices);
void im3DEnd(void); void im3DEnd(void);
#endif #endif
void rasterCreate(Raster *raster); Raster *rasterCreate(Raster *raster);
uint8 *rasterLock(Raster*, int32 level, int32 lockMode); uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
void rasterUnlock(Raster*, int32); void rasterUnlock(Raster*, int32);
int32 rasterNumLevels(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);
} }
} }

View File

@ -35,6 +35,7 @@ driverOpen(void *o, int32, int32)
engine->driver[PLATFORM_PS2]->rasterLockPalette = rasterLockPalette; engine->driver[PLATFORM_PS2]->rasterLockPalette = rasterLockPalette;
engine->driver[PLATFORM_PS2]->rasterUnlockPalette = rasterUnlockPalette; engine->driver[PLATFORM_PS2]->rasterUnlockPalette = rasterUnlockPalette;
engine->driver[PLATFORM_PS2]->rasterNumLevels = rasterNumLevels; engine->driver[PLATFORM_PS2]->rasterNumLevels = rasterNumLevels;
engine->driver[PLATFORM_PS2]->imageFindRasterFormat = imageFindRasterFormat;
engine->driver[PLATFORM_PS2]->rasterFromImage = rasterFromImage; engine->driver[PLATFORM_PS2]->rasterFromImage = rasterFromImage;
engine->driver[PLATFORM_PS2]->rasterToImage = rasterToImage; engine->driver[PLATFORM_PS2]->rasterToImage = rasterToImage;

View File

@ -11,7 +11,7 @@
#include "../rwengine.h" #include "../rwengine.h"
#include "rwps2.h" #include "rwps2.h"
#define PLUGIN_ID 0 #define PLUGIN_ID ID_DRIVER
#define min(a, b) ((a) < (b) ? (a) : (b)) #define min(a, b) ((a) < (b) ? (a) : (b))
#define max(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 #undef REALHEIGHT
} }
static void static Raster*
createTexRaster(Raster *raster) rasterCreateTexture(Raster *raster)
{ {
// We use a map for fast lookup, even for impossible depths // We use a map for fast lookup, even for impossible depths
static int32 pageWidths[32] = { static int32 pageWidths[32] = {
@ -809,7 +809,7 @@ createTexRaster(Raster *raster)
// RW doesn't seem to check this, hm... // RW doesn't seem to check this, hm...
if(raster->flags & Raster::DONTALLOCATE) if(raster->flags & Raster::DONTALLOCATE)
return; return raster;
//printf("%x %x %x %x\n", raster->format, raster->flags, raster->type, noNewStyleRasters); //printf("%x %x %x %x\n", raster->format, raster->flags, raster->type, noNewStyleRasters);
pageWidth = pageWidths[depth-1]; pageWidth = pageWidths[depth-1];
@ -841,7 +841,7 @@ createTexRaster(Raster *raster)
paletteHeight = 2; paletteHeight = 2;
}else{ }else{
// can't happen, sanity check in getRasterFormat // can't happen, sanity check in getRasterFormat
return; return nil;;
} }
tcc = 1; // RGBA tcc = 1; // RGBA
cld = 1; cld = 1;
@ -857,7 +857,7 @@ createTexRaster(Raster *raster)
palettePageheight = 32; palettePageheight = 32;
}else }else
// can't happen, sanity check in getRasterFormat // can't happen, sanity check in getRasterFormat
return; return nil;;
}else{ }else{
paletteWidth = 0; paletteWidth = 0;
paletteHeight = 0; paletteHeight = 0;
@ -875,7 +875,7 @@ createTexRaster(Raster *raster)
tcc = 1; // RGBA tcc = 1; // RGBA
}else }else
// can't happen, sanity check in getRasterFormat // can't happen, sanity check in getRasterFormat
return; return nil;;
} }
for(int i = 0; i < 7; i++){ for(int i = 0; i < 7; i++){
@ -1308,13 +1308,14 @@ createTexRaster(Raster *raster)
raster->originalStride = raster->stride; raster->originalStride = raster->stride;
if(ras->flags & Ps2Raster::NEWSTYLE) if(ras->flags & Ps2Raster::NEWSTYLE)
raster->pixels = ((Ps2Raster::PixelPtr*)raster->pixels)->pixels + 0x50; raster->pixels = ((Ps2Raster::PixelPtr*)raster->pixels)->pixels + 0x50;
return raster;
} }
void Raster*
rasterCreate(Raster *raster) rasterCreate(Raster *raster)
{ {
if(!getRasterFormat(raster)) if(!getRasterFormat(raster))
return; return nil;
// init raster // init raster
raster->pixels = nil; raster->pixels = nil;
@ -1326,32 +1327,29 @@ rasterCreate(Raster *raster)
raster->flags = Raster::DONTALLOCATE; raster->flags = Raster::DONTALLOCATE;
raster->stride = 0; raster->stride = 0;
raster->originalStride = 0; raster->originalStride = 0;
return; return raster;
} }
switch(raster->type){ switch(raster->type){
case Raster::NORMAL: case Raster::NORMAL:
// TODO case Raster::TEXTURE:
break; return rasterCreateTexture(raster);
case Raster::ZBUFFER: case Raster::ZBUFFER:
// TODO. only RW_PS2 // TODO. only RW_PS2
// get info from video mode // get info from video mode
raster->flags = Raster::DONTALLOCATE; raster->flags = Raster::DONTALLOCATE;
break; return raster;
case Raster::CAMERA: case Raster::CAMERA:
// TODO. only RW_PS2 // TODO. only RW_PS2
// get info from video mode // get info from video mode
raster->flags = Raster::DONTALLOCATE; raster->flags = Raster::DONTALLOCATE;
break; return raster;
case Raster::TEXTURE:
createTexRaster(raster);
break;
case Raster::CAMERATEXTURE: case Raster::CAMERATEXTURE:
// TODO. only RW_PS2 // TODO. only RW_PS2
// check width/height and fall through to texture // check width/height and fall through to texture
break; return nil;
} }
return nil;
} }
static uint32 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]; 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) rasterFromImage(Raster *raster, Image *image)
{ {
assert(0 && "not yet");
Ps2Raster *natras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset); Ps2Raster *natras = PLUGINOFFSET(Ps2Raster, raster, nativeRasterOffset);
raster->flags &= ~Raster::DONTALLOCATE; raster->flags &= ~Raster::DONTALLOCATE;
@ -1669,6 +1676,7 @@ rasterFromImage(Raster *raster, Image *image)
} }
} }
raster->unlock(0); raster->unlock(0);
return 1;
} }
Image* Image*

View File

@ -1,13 +1,15 @@
namespace rw { namespace rw {
namespace ps2 { namespace ps2 {
void rasterCreate(Raster *raster); Raster *rasterCreate(Raster *raster);
uint8 *rasterLock(Raster*, int32 level, int32 lockMode); uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
void rasterUnlock(Raster*, int32 level); void rasterUnlock(Raster*, int32 level);
uint8 *rasterLockPalette(Raster*, int32 lockMode); uint8 *rasterLockPalette(Raster*, int32 lockMode);
void rasterUnlockPalette(Raster*); void rasterUnlockPalette(Raster*);
int32 rasterNumLevels(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); Image *rasterToImage(Raster *raster);
} }

View File

@ -75,8 +75,7 @@ Raster::create(int32 width, int32 height, int32 depth, int32 format, int32 platf
s_plglist.construct(raster); s_plglist.construct(raster);
// printf("%d %d %d %d\n", raster->type, raster->width, raster->height, raster->depth); // printf("%d %d %d %d\n", raster->type, raster->width, raster->height, raster->depth);
engine->driver[raster->platform]->rasterCreate(raster); return engine->driver[raster->platform]->rasterCreate(raster);
return raster;
} }
void void
@ -147,14 +146,34 @@ Raster::formatHasAlpha(int32 format)
(format & 0xF00) == Raster::C4444; (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*
Raster::createFromImage(Image *image, int32 platform) Raster::createFromImage(Image *image, int32 platform)
{ {
Raster *raster = Raster::create(image->width, image->height, Raster *raster;
image->depth, TEXTURE | DONTALLOCATE, int32 width, height, depth, format;
platform); if(!imageFindRasterFormat(image, TEXTURE, &width, &height, &depth, &format, platform))
engine->driver[raster->platform]->rasterFromImage(raster, image); return nil;
return raster; raster = Raster::create(width, height, depth, format, platform);
if(raster == nil)
return nil;
return raster->setFromImage(image, platform);
} }
Image* Image*

View File

@ -72,13 +72,15 @@ struct Driver
ObjPipeline *defaultPipeline; ObjPipeline *defaultPipeline;
int32 rasterNativeOffset; int32 rasterNativeOffset;
void (*rasterCreate)(Raster*); Raster* (*rasterCreate)(Raster*);
uint8 *(*rasterLock)(Raster*, int32 level, int32 lockMode); uint8 *(*rasterLock)(Raster*, int32 level, int32 lockMode);
void (*rasterUnlock)(Raster*, int32 level); void (*rasterUnlock)(Raster*, int32 level);
uint8 *(*rasterLockPalette)(Raster*, int32 lockMode); uint8 *(*rasterLockPalette)(Raster*, int32 lockMode);
void (*rasterUnlockPalette)(Raster*); void (*rasterUnlockPalette)(Raster*);
int32 (*rasterNumLevels)(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*); Image *(*rasterToImage)(Raster*);
static PluginList s_plglist[NUM_PLATFORMS]; static PluginList s_plglist[NUM_PLATFORMS];
@ -203,13 +205,15 @@ namespace null {
void setRenderState(int32 state, void *value); void setRenderState(int32 state, void *value);
void *getRenderState(int32 state); void *getRenderState(int32 state);
void rasterCreate(Raster*); Raster *rasterCreate(Raster*);
uint8 *rasterLock(Raster*, int32 level, int32 lockMode); uint8 *rasterLock(Raster*, int32 level, int32 lockMode);
void rasterUnlock(Raster*, int32 level); void rasterUnlock(Raster*, int32 level);
uint8 *rasterLockPalette(Raster*, int32 lockMode); uint8 *rasterLockPalette(Raster*, int32 lockMode);
void rasterUnlockPalette(Raster*); void rasterUnlockPalette(Raster*);
int32 rasterNumLevels(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*); Image *rasterToImage(Raster*);
void im2DRenderLine(void*, int32, int32, int32); void im2DRenderLine(void*, int32, int32, int32);

View File

@ -196,6 +196,9 @@ struct Raster
int32 format, int32 platform = 0); int32 format, int32 platform = 0);
void subRaster(Raster *parent, Rect *r); void subRaster(Raster *parent, Rect *r);
void destroy(void); 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); static Raster *createFromImage(Image *image, int32 platform = 0);
Image *toImage(void); Image *toImage(void);
uint8 *lock(int32 level, int32 lockMode); uint8 *lock(int32 level, int32 lockMode);