mirror of https://github.com/aap/librw.git
rasters
This commit is contained in:
parent
5dff69431e
commit
40fc1e24fc
|
@ -443,7 +443,7 @@ rasterFromImage(Raster *raster, Image *image)
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
format |= 4;
|
format |= Raster::TEXTURE;
|
||||||
|
|
||||||
raster->type = format & 0x7;
|
raster->type = format & 0x7;
|
||||||
raster->flags = format & 0xF8;
|
raster->flags = format & 0xF8;
|
||||||
|
@ -505,6 +505,102 @@ rasterFromImage(Raster *raster, Image *image)
|
||||||
raster->unlock(0);
|
raster->unlock(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image*
|
||||||
|
rasterToImage(Raster *raster)
|
||||||
|
{
|
||||||
|
int32 depth;
|
||||||
|
Image *image;
|
||||||
|
D3dRaster *natras = PLUGINOFFSET(D3dRaster, raster, nativeRasterOffset);
|
||||||
|
if(natras->format)
|
||||||
|
assert(0 && "no custom formats yet");
|
||||||
|
switch(raster->format & 0xF00){
|
||||||
|
case Raster::C1555:
|
||||||
|
depth = 16;
|
||||||
|
break;
|
||||||
|
case Raster::C8888:
|
||||||
|
depth = 32;
|
||||||
|
break;
|
||||||
|
case Raster::C888:
|
||||||
|
depth = 24;
|
||||||
|
break;
|
||||||
|
case Raster::C555:
|
||||||
|
depth = 16;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
case Raster::C565:
|
||||||
|
case Raster::C4444:
|
||||||
|
case Raster::LUM8:
|
||||||
|
assert(0 && "unsupported raster format");
|
||||||
|
}
|
||||||
|
int32 pallength = 0;
|
||||||
|
if((raster->format & Raster::PAL4) == Raster::PAL4){
|
||||||
|
depth = 4;
|
||||||
|
pallength = 16;
|
||||||
|
}else if((raster->format & Raster::PAL4) == Raster::PAL8){
|
||||||
|
depth = 8;
|
||||||
|
pallength = 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8 *in, *out;
|
||||||
|
image = Image::create(raster->width, raster->height, depth);
|
||||||
|
image->allocate();
|
||||||
|
|
||||||
|
if(pallength){
|
||||||
|
out = image->palette;
|
||||||
|
in = (uint8*)natras->palette;
|
||||||
|
for(int32 i = 0; i < pallength; i++){
|
||||||
|
out[0] = in[2];
|
||||||
|
out[1] = in[1];
|
||||||
|
out[2] = in[0];
|
||||||
|
out[3] = in[3];
|
||||||
|
in += 4;
|
||||||
|
out += 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out = image->pixels;
|
||||||
|
in = raster->lock(0);
|
||||||
|
if(pallength)
|
||||||
|
memcpy(out, in, raster->width*raster->height);
|
||||||
|
else
|
||||||
|
// TODO: stride
|
||||||
|
for(int32 y = 0; y < image->height; y++)
|
||||||
|
for(int32 x = 0; x < image->width; x++)
|
||||||
|
switch(raster->format & 0xF00){
|
||||||
|
case Raster::C8888:
|
||||||
|
out[0] = in[2];
|
||||||
|
out[1] = in[1];
|
||||||
|
out[2] = in[0];
|
||||||
|
out[3] = in[3];
|
||||||
|
in += 4;
|
||||||
|
out += 4;
|
||||||
|
break;
|
||||||
|
case Raster::C888:
|
||||||
|
out[0] = in[2];
|
||||||
|
out[1] = in[1];
|
||||||
|
out[2] = in[0];
|
||||||
|
in += 4;
|
||||||
|
out += 3;
|
||||||
|
break;
|
||||||
|
case Raster::C1555:
|
||||||
|
out[0] = in[0];
|
||||||
|
out[1] = in[1];
|
||||||
|
in += 2;
|
||||||
|
out += 2;
|
||||||
|
break;
|
||||||
|
case Raster::C555:
|
||||||
|
out[0] = in[0];
|
||||||
|
out[1] = in[1] | 0x80;
|
||||||
|
in += 2;
|
||||||
|
out += 2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
raster->unlock(0);
|
||||||
|
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
|
||||||
int32
|
int32
|
||||||
getLevelSize(Raster *raster, int32 level)
|
getLevelSize(Raster *raster, int32 level)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,6 +31,7 @@ driverOpen(void *o, int32, int32)
|
||||||
driver[PLATFORM_D3D8]->rasterUnlock = rasterUnlock;
|
driver[PLATFORM_D3D8]->rasterUnlock = rasterUnlock;
|
||||||
driver[PLATFORM_D3D8]->rasterNumLevels = rasterNumLevels;
|
driver[PLATFORM_D3D8]->rasterNumLevels = rasterNumLevels;
|
||||||
driver[PLATFORM_D3D8]->rasterFromImage = rasterFromImage;
|
driver[PLATFORM_D3D8]->rasterFromImage = rasterFromImage;
|
||||||
|
driver[PLATFORM_D3D8]->rasterToImage = rasterToImage;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -470,7 +471,7 @@ readAsImage(Stream *stream, int32 width, int32 height, int32 depth, int32 format
|
||||||
}
|
}
|
||||||
|
|
||||||
delete[] data;
|
delete[] data;
|
||||||
Raster *ras = Raster::createFromImage(img);
|
Raster *ras = Raster::createFromImage(img, PLATFORM_D3D8);
|
||||||
img->destroy();
|
img->destroy();
|
||||||
return ras;
|
return ras;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ driverOpen(void *o, int32, int32)
|
||||||
driver[PLATFORM_D3D9]->rasterUnlock = rasterUnlock;
|
driver[PLATFORM_D3D9]->rasterUnlock = rasterUnlock;
|
||||||
driver[PLATFORM_D3D9]->rasterNumLevels = rasterNumLevels;
|
driver[PLATFORM_D3D9]->rasterNumLevels = rasterNumLevels;
|
||||||
driver[PLATFORM_D3D9]->rasterFromImage = rasterFromImage;
|
driver[PLATFORM_D3D9]->rasterFromImage = rasterFromImage;
|
||||||
|
driver[PLATFORM_D3D9]->rasterToImage = rasterToImage;
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,7 +178,7 @@ readNativeData(Stream *stream, int32, void *object, int32, int32)
|
||||||
for(int i = 0; i < 2; i++){
|
for(int i = 0; i < 2; i++){
|
||||||
stream->read(p, 16);
|
stream->read(p, 16);
|
||||||
s = &header->vertexStream[i];
|
s = &header->vertexStream[i];
|
||||||
s->vertexBuffer = (void*)*(uint32*)p; p += 4;
|
s->vertexBuffer = (void*)(uintptr)*(uint32*)p; p += 4;
|
||||||
s->offset = 0; p += 4;
|
s->offset = 0; p += 4;
|
||||||
s->stride = *(uint32*)p; p += 4;
|
s->stride = *(uint32*)p; p += 4;
|
||||||
s->geometryFlags = *(uint16*)p; p += 2;
|
s->geometryFlags = *(uint16*)p; p += 2;
|
||||||
|
|
|
@ -6,6 +6,7 @@ uint8 *rasterLock(Raster *raster, int32 level);
|
||||||
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);
|
void rasterFromImage(Raster *raster, Image *image);
|
||||||
|
Image *rasterToImage(Raster *raster);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,6 +63,7 @@ Driver::open(void)
|
||||||
driver[i]->rasterUnlock = null::rasterUnlock;
|
driver[i]->rasterUnlock = null::rasterUnlock;
|
||||||
driver[i]->rasterNumLevels = null::rasterNumLevels;
|
driver[i]->rasterNumLevels = null::rasterNumLevels;
|
||||||
driver[i]->rasterFromImage = null::rasterFromImage;
|
driver[i]->rasterFromImage = null::rasterFromImage;
|
||||||
|
driver[i]->rasterToImage = null::rasterToImage;
|
||||||
|
|
||||||
s_plglist[i].construct(rw::driver[i]);
|
s_plglist[i].construct(rw::driver[i]);
|
||||||
}
|
}
|
||||||
|
@ -109,5 +110,12 @@ rasterFromImage(Raster*, Image*)
|
||||||
assert(0 && "rasterFromImage not implemented");
|
assert(0 && "rasterFromImage not implemented");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image*
|
||||||
|
rasterToImage(Raster*)
|
||||||
|
{
|
||||||
|
assert(0 && "rasterToImage not implemented");
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -279,7 +279,8 @@ setTexture(int32 n, Texture *tex)
|
||||||
{
|
{
|
||||||
bool32 alpha;
|
bool32 alpha;
|
||||||
glActiveTexture(GL_TEXTURE0+n);
|
glActiveTexture(GL_TEXTURE0+n);
|
||||||
if(tex == nil){
|
if(tex == nil || tex->raster->platform != PLATFORM_GL3 ||
|
||||||
|
tex->raster->width == 0){
|
||||||
glBindTexture(GL_TEXTURE_2D, whitetex);
|
glBindTexture(GL_TEXTURE_2D, whitetex);
|
||||||
alpha = 0;
|
alpha = 0;
|
||||||
}else{
|
}else{
|
||||||
|
|
|
@ -23,19 +23,34 @@ int32 nativeRasterOffset;
|
||||||
void
|
void
|
||||||
rasterCreate(Raster *raster)
|
rasterCreate(Raster *raster)
|
||||||
{
|
{
|
||||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
|
||||||
if(raster->flags & Raster::DONTALLOCATE)
|
if(raster->flags & Raster::DONTALLOCATE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
assert(raster->depth == 32);
|
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
#ifdef RW_OPENGL
|
||||||
|
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
||||||
|
switch(raster->format & 0xF00){
|
||||||
|
case Raster::C8888:
|
||||||
|
natras->internalFormat = GL_RGBA;
|
||||||
|
natras->format = GL_RGBA;
|
||||||
|
natras->hasAlpha = 1;
|
||||||
|
break;
|
||||||
|
case Raster::C888:
|
||||||
|
natras->internalFormat = GL_RGB;
|
||||||
|
natras->format = GL_RGB;
|
||||||
|
natras->hasAlpha = 0;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0 && "unsupported raster format");
|
||||||
|
}
|
||||||
|
natras->type = GL_UNSIGNED_BYTE;
|
||||||
|
|
||||||
glGenTextures(1, &natras->texid);
|
glGenTextures(1, &natras->texid);
|
||||||
glBindTexture(GL_TEXTURE_2D, natras->texid);
|
glBindTexture(GL_TEXTURE_2D, natras->texid);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, raster->width, raster->height,
|
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||||
0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
|
raster->width, raster->height,
|
||||||
|
0, natras->format, natras->type, nil);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
#endif
|
#endif
|
||||||
|
@ -67,22 +82,30 @@ rasterFromImage(Raster *raster, Image *image)
|
||||||
int32 format;
|
int32 format;
|
||||||
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
Gl3Raster *natras = PLUGINOFFSET(Gl3Raster, raster, nativeRasterOffset);
|
||||||
|
|
||||||
format = Raster::C8888;
|
switch(image->depth){
|
||||||
format |= 4;
|
case 32:
|
||||||
|
format = Raster::C8888;
|
||||||
|
break;
|
||||||
|
case 24:
|
||||||
|
format = Raster::C888;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(0 && "image depth\n");
|
||||||
|
}
|
||||||
|
format |= Raster::TEXTURE;
|
||||||
|
|
||||||
raster->type = format & 0x7;
|
raster->type = format & 0x7;
|
||||||
raster->flags = format & 0xF8;
|
raster->flags = format & 0xF8;
|
||||||
raster->format = format & 0xFF00;
|
raster->format = format & 0xFF00;
|
||||||
rasterCreate(raster);
|
rasterCreate(raster);
|
||||||
|
|
||||||
assert(image->depth == 32);
|
|
||||||
|
|
||||||
natras->hasAlpha = image->hasAlpha();
|
natras->hasAlpha = image->hasAlpha();
|
||||||
|
|
||||||
#ifdef RW_OPENGL
|
#ifdef RW_OPENGL
|
||||||
glBindTexture(GL_TEXTURE_2D, natras->texid);
|
glBindTexture(GL_TEXTURE_2D, natras->texid);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, raster->width, raster->height,
|
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||||
0, GL_RGBA, GL_UNSIGNED_BYTE, image->pixels);
|
raster->width, raster->height,
|
||||||
|
0, natras->format, natras->type, image->pixels);
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,13 @@ extern int32 nativeRasterOffset;
|
||||||
|
|
||||||
struct Gl3Raster
|
struct Gl3Raster
|
||||||
{
|
{
|
||||||
|
// arguments to glTexImage2D
|
||||||
|
int32 internalFormat;
|
||||||
|
int32 type;
|
||||||
|
int32 format;
|
||||||
|
// texture object
|
||||||
uint32 texid;
|
uint32 texid;
|
||||||
|
|
||||||
bool32 hasAlpha;
|
bool32 hasAlpha;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -216,7 +216,7 @@ Texture::read(const char *name, const char *mask)
|
||||||
strncpy(tex->name, name, 32);
|
strncpy(tex->name, name, 32);
|
||||||
if(mask)
|
if(mask)
|
||||||
strncpy(tex->mask, mask, 32);
|
strncpy(tex->mask, mask, 32);
|
||||||
raster = Raster::create(0, 0, 0, 0x80);
|
raster = Raster::create(0, 0, 0, Raster::DONTALLOCATE);
|
||||||
tex->raster = raster;
|
tex->raster = raster;
|
||||||
}
|
}
|
||||||
if(currentTexDictionary){
|
if(currentTexDictionary){
|
||||||
|
@ -733,12 +733,19 @@ Raster::calculateNumLevels(int32 width, int32 height)
|
||||||
}
|
}
|
||||||
|
|
||||||
Raster*
|
Raster*
|
||||||
Raster::createFromImage(Image *image)
|
Raster::createFromImage(Image *image, int32 platform)
|
||||||
{
|
{
|
||||||
Raster *raster = Raster::create(image->width, image->height,
|
Raster *raster = Raster::create(image->width, image->height,
|
||||||
image->depth, 4 | 0x80);
|
image->depth, TEXTURE | DONTALLOCATE,
|
||||||
|
platform);
|
||||||
driver[raster->platform]->rasterFromImage(raster, image);
|
driver[raster->platform]->rasterFromImage(raster, image);
|
||||||
return raster;
|
return raster;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Image*
|
||||||
|
Raster::toImage(void)
|
||||||
|
{
|
||||||
|
return driver[this->platform]->rasterToImage(this);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,9 +53,9 @@ struct Engine
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
float32 zNear, zFar;
|
float32 zNear, zFar;
|
||||||
void (*beginUpdate)(Camera*);
|
void (*beginUpdate)(Camera*);
|
||||||
void (*endUpdate)(Camera*);
|
void (*endUpdate)(Camera*);
|
||||||
void (*clearCamera)(Camera*, RGBA *col, uint32 mode);
|
void (*clearCamera)(Camera*, RGBA *col, uint32 mode);
|
||||||
void (*setRenderState)(int32 state, uint32 value);
|
void (*setRenderState)(int32 state, uint32 value);
|
||||||
uint32 (*getRenderState)(int32 state);
|
uint32 (*getRenderState)(int32 state);
|
||||||
|
|
||||||
|
@ -76,6 +76,7 @@ struct Driver
|
||||||
void (*rasterUnlock)(Raster*, int32 level);
|
void (*rasterUnlock)(Raster*, int32 level);
|
||||||
int32 (*rasterNumLevels)(Raster*);
|
int32 (*rasterNumLevels)(Raster*);
|
||||||
void (*rasterFromImage)(Raster*, Image*);
|
void (*rasterFromImage)(Raster*, Image*);
|
||||||
|
Image *(*rasterToImage)(Raster*);
|
||||||
|
|
||||||
static PluginList s_plglist[NUM_PLATFORMS];
|
static PluginList s_plglist[NUM_PLATFORMS];
|
||||||
static void open(void);
|
static void open(void);
|
||||||
|
@ -108,6 +109,7 @@ namespace null {
|
||||||
void rasterUnlock(Raster*, int32 level);
|
void rasterUnlock(Raster*, int32 level);
|
||||||
int32 rasterNumLevels(Raster*);
|
int32 rasterNumLevels(Raster*);
|
||||||
void rasterFromImage(Raster*, Image*);
|
void rasterFromImage(Raster*, Image*);
|
||||||
|
Image *rasterToImage(Raster*);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -214,9 +214,11 @@ struct Raster : PluginBase<Raster>
|
||||||
uint8 *texels;
|
uint8 *texels;
|
||||||
uint8 *palette;
|
uint8 *palette;
|
||||||
|
|
||||||
static Raster *create(int32 width, int32 height, int32 depth, int32 format, int32 platform = 0);
|
static Raster *create(int32 width, int32 height, int32 depth,
|
||||||
|
int32 format, int32 platform = 0);
|
||||||
void destroy(void);
|
void destroy(void);
|
||||||
static Raster *createFromImage(Image *image);
|
static Raster *createFromImage(Image *image, int32 platform = 0);
|
||||||
|
Image *toImage(void);
|
||||||
uint8 *lock(int32 level);
|
uint8 *lock(int32 level);
|
||||||
void unlock(int32 level);
|
void unlock(int32 level);
|
||||||
int32 getNumLevels(void);
|
int32 getNumLevels(void);
|
||||||
|
|
Loading…
Reference in New Issue