mirror of https://github.com/aap/librw.git
implemented raster from image stuff for gl3 and ps2 (not tested)
This commit is contained in:
parent
bc9cb506ec
commit
59cedaa793
|
@ -641,13 +641,14 @@ rasterNumLevels(Raster *raster)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Almost the same as ps2 and gl3 function
|
||||||
bool32
|
bool32
|
||||||
imageFindRasterFormat(Image *img, int32 type,
|
imageFindRasterFormat(Image *img, int32 type,
|
||||||
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat)
|
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat)
|
||||||
{
|
{
|
||||||
int32 width, height, depth, format;
|
int32 width, height, depth, format;
|
||||||
|
|
||||||
assert(type == Raster::TEXTURE);
|
assert((type&0xF) == Raster::TEXTURE);
|
||||||
|
|
||||||
for(width = 1; width < img->width; width <<= 1);
|
for(width = 1; width < img->width; width <<= 1);
|
||||||
for(height = 1; height < img->height; height <<= 1);
|
for(height = 1; height < img->height; height <<= 1);
|
||||||
|
@ -679,6 +680,7 @@ imageFindRasterFormat(Image *img, int32 type,
|
||||||
format = Raster::PAL4 | Raster::C8888;
|
format = Raster::PAL4 | Raster::C8888;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
RWERROR((ERR_INVRASTER));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -842,7 +844,8 @@ rasterToImage(Raster *raster)
|
||||||
case Raster::C565:
|
case Raster::C565:
|
||||||
case Raster::C4444:
|
case Raster::C4444:
|
||||||
case Raster::LUM8:
|
case Raster::LUM8:
|
||||||
assert(0 && "unsupported raster format");
|
RWERROR((ERR_INVRASTER));
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
int32 pallength = 0;
|
int32 pallength = 0;
|
||||||
if((raster->format & Raster::PAL4) == Raster::PAL4){
|
if((raster->format & Raster::PAL4) == Raster::PAL4){
|
||||||
|
|
|
@ -22,10 +22,10 @@ namespace gl3 {
|
||||||
|
|
||||||
int32 nativeRasterOffset;
|
int32 nativeRasterOffset;
|
||||||
|
|
||||||
|
#ifdef RW_OPENGL
|
||||||
static Raster*
|
static Raster*
|
||||||
rasterCreateTexture(Raster *raster)
|
rasterCreateTexture(Raster *raster)
|
||||||
{
|
{
|
||||||
#ifdef RW_OPENGL
|
|
||||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
||||||
switch(raster->format & 0xF00){
|
switch(raster->format & 0xF00){
|
||||||
case Raster::C8888:
|
case Raster::C8888:
|
||||||
|
@ -63,13 +63,8 @@ rasterCreateTexture(Raster *raster)
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
return raster;
|
return raster;
|
||||||
#else
|
|
||||||
return nil;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
|
||||||
|
|
||||||
// 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.
|
||||||
|
@ -145,6 +140,7 @@ Raster*
|
||||||
rasterCreate(Raster *raster)
|
rasterCreate(Raster *raster)
|
||||||
{
|
{
|
||||||
switch(raster->type){
|
switch(raster->type){
|
||||||
|
#ifdef RW_OPENGL
|
||||||
case Raster::NORMAL:
|
case Raster::NORMAL:
|
||||||
case Raster::TEXTURE:
|
case Raster::TEXTURE:
|
||||||
// Dummy to use as subraster
|
// Dummy to use as subraster
|
||||||
|
@ -159,7 +155,6 @@ rasterCreate(Raster *raster)
|
||||||
return raster;
|
return raster;
|
||||||
return rasterCreateTexture(raster);
|
return rasterCreateTexture(raster);
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
|
||||||
case Raster::CAMERATEXTURE:
|
case Raster::CAMERATEXTURE:
|
||||||
if(raster->flags & Raster::DONTALLOCATE)
|
if(raster->flags & Raster::DONTALLOCATE)
|
||||||
return raster;
|
return raster;
|
||||||
|
@ -172,9 +167,9 @@ rasterCreate(Raster *raster)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
default:
|
default:
|
||||||
assert(0 && "unsupported format");
|
RWERROR((ERR_INVRASTER));
|
||||||
|
return nil;
|
||||||
}
|
}
|
||||||
return nil;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8*
|
uint8*
|
||||||
|
@ -197,24 +192,31 @@ rasterNumLevels(Raster*)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Almost the same as d3d9 and ps2 function
|
||||||
bool32
|
bool32
|
||||||
imageFindRasterFormat(Image *img, int32 type,
|
imageFindRasterFormat(Image *img, int32 type,
|
||||||
int32 *width, int32 *height, int32 *depth, int32 *format)
|
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat)
|
||||||
{
|
{
|
||||||
assert(0 && "not yet");
|
int32 width, height, depth, format;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool32
|
assert((type&0xF) == Raster::TEXTURE);
|
||||||
rasterFromImage(Raster *raster, Image *image)
|
|
||||||
{
|
|
||||||
assert(0 && "not yet");
|
|
||||||
int32 format;
|
|
||||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, 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)
|
||||||
|
depth = 32;
|
||||||
|
|
||||||
|
switch(depth){
|
||||||
case 32:
|
case 32:
|
||||||
format = Raster::C8888;
|
if(img->hasAlpha())
|
||||||
|
format = Raster::C8888;
|
||||||
|
else{
|
||||||
|
format = Raster::C888;
|
||||||
|
depth = 24;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 24:
|
case 24:
|
||||||
format = Raster::C888;
|
format = Raster::C888;
|
||||||
|
@ -222,15 +224,62 @@ rasterFromImage(Raster *raster, Image *image)
|
||||||
case 16:
|
case 16:
|
||||||
format = Raster::C1555;
|
format = Raster::C1555;
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
assert(0 && "image depth\n");
|
|
||||||
}
|
|
||||||
format |= Raster::TEXTURE;
|
|
||||||
|
|
||||||
raster->type = format & 0x7;
|
case 8:
|
||||||
raster->flags = format & 0xF8;
|
case 4:
|
||||||
raster->format = format & 0xFF00;
|
default:
|
||||||
rasterCreate(raster);
|
RWERROR((ERR_INVRASTER));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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){
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, 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:
|
||||||
|
case 4:
|
||||||
|
default:
|
||||||
|
err:
|
||||||
|
RWERROR((ERR_INVRASTER));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
natras->hasAlpha = image->hasAlpha();
|
natras->hasAlpha = image->hasAlpha();
|
||||||
|
|
||||||
|
|
|
@ -1593,33 +1593,87 @@ 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Almost the same as d3d9 and gl3 function
|
||||||
bool32
|
bool32
|
||||||
imageFindRasterFormat(Image *img, int32 type,
|
imageFindRasterFormat(Image *img, int32 type,
|
||||||
int32 *width, int32 *height, int32 *depth, int32 *format)
|
int32 *pWidth, int32 *pHeight, int32 *pDepth, int32 *pFormat)
|
||||||
{
|
{
|
||||||
assert(0 && "not yet");
|
int32 width, height, depth, format;
|
||||||
return 0;
|
|
||||||
|
assert((type&0xF) == Raster::TEXTURE);
|
||||||
|
|
||||||
|
for(width = 1; width < img->width; width <<= 1);
|
||||||
|
for(height = 1; height < img->height; height <<= 1);
|
||||||
|
|
||||||
|
depth = img->depth;
|
||||||
|
|
||||||
|
switch(depth){
|
||||||
|
case 32:
|
||||||
|
if(img->hasAlpha())
|
||||||
|
format = Raster::C8888;
|
||||||
|
else{
|
||||||
|
format = Raster::C888;
|
||||||
|
depth = 24;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
format = Raster::C888;
|
||||||
|
break;
|
||||||
|
case 16:
|
||||||
|
format = Raster::C1555;
|
||||||
|
break;
|
||||||
|
case 8:
|
||||||
|
format = Raster::PAL8 | Raster::C8888;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
format = Raster::PAL4 | Raster::C8888;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
RWERROR((ERR_INVRASTER));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
format |= type;
|
||||||
|
|
||||||
|
*pWidth = width;
|
||||||
|
*pHeight = height;
|
||||||
|
*pDepth = depth;
|
||||||
|
*pFormat = format;
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool32
|
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;
|
|
||||||
if(raster->format & (Raster::PAL4|Raster::PAL8) &&
|
|
||||||
(raster->format & 0xF00) == Raster::C1555){
|
|
||||||
raster->format &= 0xF000;
|
|
||||||
raster->format |= Raster::C8888;
|
|
||||||
}
|
|
||||||
rasterCreate(raster);
|
|
||||||
|
|
||||||
int32 pallength = 0;
|
int32 pallength = 0;
|
||||||
if(raster->format & Raster::PAL4)
|
switch(image->depth){
|
||||||
pallength = 16;
|
case 32:
|
||||||
else if(raster->format & Raster::PAL8)
|
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;
|
||||||
pallength = 256;
|
pallength = 256;
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
if(raster->format != (Raster::PAL4 | Raster::C8888)) goto err;
|
||||||
|
pallength = 16;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
err:
|
||||||
|
RWERROR((ERR_INVRASTER));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
uint8 *in, *out;
|
uint8 *in, *out;
|
||||||
if(image->depth <= 8){
|
if(image->depth <= 8){
|
||||||
|
|
|
@ -327,8 +327,8 @@ im3dtest(void)
|
||||||
verts[i].setV(vs[i].v);
|
verts[i].setV(vs[i].v);
|
||||||
}
|
}
|
||||||
|
|
||||||
// rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster);
|
rw::SetRenderStatePtr(rw::TEXTURERASTER, tex->raster);
|
||||||
rw::SetRenderStatePtr(rw::TEXTURERASTER, frontbuffer->raster);
|
// rw::SetRenderStatePtr(rw::TEXTURERASTER, frontbuffer->raster);
|
||||||
rw::SetRenderState(rw::TEXTUREADDRESS, rw::Texture::WRAP);
|
rw::SetRenderState(rw::TEXTUREADDRESS, rw::Texture::WRAP);
|
||||||
rw::SetRenderState(rw::TEXTUREFILTER, rw::Texture::NEAREST);
|
rw::SetRenderState(rw::TEXTUREFILTER, rw::Texture::NEAREST);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue