mirror of
https://gitlab.com/shinovon/re3-symbian.git
synced 2026-05-23 01:57:21 +03:00
Symbian^3 port
This commit is contained in:
parent
77cdaaf97e
commit
3eb71f2cc5
106 changed files with 2098 additions and 745 deletions
214
vendor/librw/src/gl/gl3raster.cpp
vendored
214
vendor/librw/src/gl/gl3raster.cpp
vendored
|
|
@ -68,7 +68,7 @@ rasterCreateTexture(Raster *raster)
|
|||
Gl3Raster *natras = GETGL3RASTEREXT(raster);
|
||||
switch(raster->format & 0xF00){
|
||||
case Raster::C8888:
|
||||
natras->internalFormat = GL_RGBA8;
|
||||
natras->internalFormat = GL_RGBA;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_BYTE;
|
||||
natras->hasAlpha = 1;
|
||||
|
|
@ -76,15 +76,32 @@ rasterCreateTexture(Raster *raster)
|
|||
raster->depth = 32;
|
||||
break;
|
||||
case Raster::C888:
|
||||
natras->internalFormat = GL_RGB8;
|
||||
natras->internalFormat = GL_RGB;
|
||||
natras->format = GL_RGB;
|
||||
natras->type = GL_UNSIGNED_BYTE;
|
||||
natras->hasAlpha = 0;
|
||||
natras->bpp = 3;
|
||||
raster->depth = 24;
|
||||
break;
|
||||
case Raster::C565:
|
||||
natras->internalFormat = GL_RGB;
|
||||
natras->format = GL_RGB;
|
||||
natras->type = GL_UNSIGNED_SHORT_5_6_5;
|
||||
natras->hasAlpha = 0;
|
||||
natras->bpp = 2;
|
||||
raster->depth = 16;
|
||||
break;
|
||||
case Raster::C4444:
|
||||
natras->internalFormat = GL_RGBA;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
natras->hasAlpha = 1;
|
||||
natras->bpp = 2;
|
||||
raster->depth = 16;
|
||||
break;
|
||||
case Raster::C1555:
|
||||
natras->internalFormat = GL_RGB5_A1;
|
||||
// natras->internalFormat = GL_RGB5_A1;
|
||||
natras->internalFormat = GL_RGBA;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_SHORT_5_5_5_1;
|
||||
natras->hasAlpha = 1;
|
||||
|
|
@ -97,11 +114,7 @@ rasterCreateTexture(Raster *raster)
|
|||
}
|
||||
|
||||
if(gl3Caps.gles){
|
||||
// glReadPixels only supports GL_RGBA
|
||||
natras->internalFormat = GL_RGBA8;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_BYTE;
|
||||
natras->bpp = 4;
|
||||
natras->internalFormat = natras->format;
|
||||
}
|
||||
|
||||
raster->stride = raster->width*natras->bpp;
|
||||
|
|
@ -123,10 +136,13 @@ rasterCreateTexture(Raster *raster)
|
|||
glGenTextures(1, &natras->texid);
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||
raster->width, raster->height,
|
||||
// raster->width, raster->height,
|
||||
1,1,
|
||||
0, natras->format, natras->type, nil);
|
||||
// TODO: allocate other levels...probably
|
||||
#ifndef __SYMBIAN32__
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, natras->numLevels-1);
|
||||
#endif
|
||||
natras->filterMode = 0;
|
||||
natras->addressU = 0;
|
||||
natras->addressV = 0;
|
||||
|
|
@ -148,22 +164,37 @@ rasterCreateCameraTexture(Raster *raster)
|
|||
Gl3Raster *natras = GETGL3RASTEREXT(raster);
|
||||
switch(raster->format & 0xF00){
|
||||
case Raster::C8888:
|
||||
natras->internalFormat = GL_RGBA8;
|
||||
natras->internalFormat = GL_RGBA;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_BYTE;
|
||||
natras->hasAlpha = 1;
|
||||
natras->bpp = 4;
|
||||
break;
|
||||
case Raster::C4444:
|
||||
natras->internalFormat = GL_RGBA;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_SHORT_4_4_4_4;
|
||||
natras->hasAlpha = 1;
|
||||
natras->bpp = 2;
|
||||
break;
|
||||
case Raster::C888:
|
||||
default:
|
||||
natras->internalFormat = GL_RGB8;
|
||||
natras->internalFormat = GL_RGB;
|
||||
natras->format = GL_RGB;
|
||||
natras->type = GL_UNSIGNED_BYTE;
|
||||
natras->hasAlpha = 0;
|
||||
natras->bpp = 3;
|
||||
break;
|
||||
case Raster::C565:
|
||||
natras->internalFormat = GL_RGB;
|
||||
natras->format = GL_RGB;
|
||||
natras->type = GL_UNSIGNED_SHORT_5_6_5;
|
||||
natras->hasAlpha = 0;
|
||||
natras->bpp = 2;
|
||||
break;
|
||||
case Raster::C1555:
|
||||
natras->internalFormat = GL_RGB5_A1;
|
||||
// natras->internalFormat = GL_RGB5_A1;
|
||||
natras->internalFormat = GL_RGBA;
|
||||
natras->format = GL_RGBA;
|
||||
natras->type = GL_UNSIGNED_SHORT_5_5_5_1;
|
||||
natras->hasAlpha = 1;
|
||||
|
|
@ -173,11 +204,7 @@ rasterCreateCameraTexture(Raster *raster)
|
|||
|
||||
// i don't remember why this was once here...
|
||||
if(gl3Caps.gles){
|
||||
// glReadPixels only supports GL_RGBA
|
||||
// natras->internalFormat = GL_RGBA8;
|
||||
// natras->format = GL_RGBA;
|
||||
// natras->type = GL_UNSIGNED_BYTE;
|
||||
// natras->bpp = 4;
|
||||
natras->internalFormat = natras->format;
|
||||
}
|
||||
|
||||
raster->stride = raster->width*natras->bpp;
|
||||
|
|
@ -187,7 +214,8 @@ rasterCreateCameraTexture(Raster *raster)
|
|||
glGenTextures(1, &natras->texid);
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||
raster->width, raster->height,
|
||||
// raster->width, raster->height,
|
||||
1,1,
|
||||
0, natras->format, natras->type, nil);
|
||||
natras->filterMode = 0;
|
||||
natras->addressU = 0;
|
||||
|
|
@ -197,10 +225,10 @@ rasterCreateCameraTexture(Raster *raster)
|
|||
bindTexture(prev);
|
||||
|
||||
|
||||
glGenFramebuffers(1, &natras->fbo);
|
||||
bindFramebuffer(natras->fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, natras->texid, 0);
|
||||
bindFramebuffer(0);
|
||||
// glGenFramebuffers(1, &natras->fbo);
|
||||
// bindFramebuffer(natras->fbo);
|
||||
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, natras->texid, 0);
|
||||
// bindFramebuffer(0);
|
||||
natras->fboMate = nil;
|
||||
|
||||
return raster;
|
||||
|
|
@ -214,14 +242,19 @@ rasterCreateCamera(Raster *raster)
|
|||
// TODO: set/check width, height, depth, format?
|
||||
|
||||
// used for locking right now
|
||||
raster->format = Raster::C888;
|
||||
natras->internalFormat = GL_RGB8;
|
||||
natras->format = GL_RGB;
|
||||
natras->type = GL_UNSIGNED_BYTE;
|
||||
natras->hasAlpha = 0;
|
||||
natras->bpp = 3;
|
||||
|
||||
natras->autogenMipmap = 0;
|
||||
// raster->format = Raster::C888;
|
||||
// natras->internalFormat = GL_RGB;
|
||||
// natras->format = GL_RGB;
|
||||
// natras->type = GL_UNSIGNED_BYTE;
|
||||
// natras->hasAlpha = 0;
|
||||
// natras->bpp = 3;
|
||||
//
|
||||
// natras->autogenMipmap = 0;
|
||||
|
||||
raster->originalWidth = raster->width;
|
||||
raster->originalHeight = raster->height;
|
||||
raster->stride = 0;
|
||||
raster->pixels = nil;
|
||||
|
||||
natras->texid = 0;
|
||||
natras->fbo = 0;
|
||||
|
|
@ -234,34 +267,45 @@ static Raster*
|
|||
rasterCreateZbuffer(Raster *raster)
|
||||
{
|
||||
Gl3Raster *natras = GETGL3RASTEREXT(raster);
|
||||
|
||||
raster->originalWidth = raster->width;
|
||||
raster->originalHeight = raster->height;
|
||||
raster->stride = 0;
|
||||
raster->pixels = nil;
|
||||
|
||||
if(gl3Caps.gles){
|
||||
// have to use RBO on GLES!!
|
||||
glGenRenderbuffers(1, &natras->texid);
|
||||
glBindRenderbuffer(GL_RENDERBUFFER, natras->texid);
|
||||
glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, raster->width, raster->height);
|
||||
}else{
|
||||
// TODO: set/check width, height, depth, format?
|
||||
natras->internalFormat = GL_DEPTH_STENCIL;
|
||||
natras->format = GL_DEPTH_STENCIL;
|
||||
natras->type = GL_UNSIGNED_INT_24_8;
|
||||
|
||||
natras->autogenMipmap = 0;
|
||||
|
||||
glGenTextures(1, &natras->texid);
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||
raster->width, raster->height,
|
||||
0, natras->format, natras->type, nil);
|
||||
natras->filterMode = 0;
|
||||
natras->addressU = 0;
|
||||
natras->addressV = 0;
|
||||
natras->maxAnisotropy = 1;
|
||||
|
||||
bindTexture(prev);
|
||||
}
|
||||
natras->fbo = 0;
|
||||
natras->fboMate = nil;
|
||||
// if(gl3Caps.gles){
|
||||
// // have to use RBO on GLES!!
|
||||
// glGenRenderbuffers(1, &natras->texid);
|
||||
// glBindRenderbuffer(GL_RENDERBUFFER, natras->texid);
|
||||
//#ifdef __SYMBIAN32__
|
||||
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, raster->width, raster->height);
|
||||
//#else
|
||||
// glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, raster->width, raster->height);
|
||||
//#endif
|
||||
//#ifndef __SYMBIAN32__
|
||||
// }else{
|
||||
// // TODO: set/check width, height, depth, format?
|
||||
// natras->internalFormat = GL_DEPTH_STENCIL;
|
||||
// natras->format = GL_DEPTH_STENCIL;
|
||||
// natras->type = GL_UNSIGNED_INT_24_8;
|
||||
//
|
||||
// natras->autogenMipmap = 0;
|
||||
//
|
||||
// glGenTextures(1, &natras->texid);
|
||||
// uint32 prev = bindTexture(natras->texid);
|
||||
// glTexImage2D(GL_TEXTURE_2D, 0, natras->internalFormat,
|
||||
// raster->width, raster->height,
|
||||
// 0, natras->format, natras->type, nil);
|
||||
// natras->filterMode = 0;
|
||||
// natras->addressU = 0;
|
||||
// natras->addressV = 0;
|
||||
// natras->maxAnisotropy = 1;
|
||||
//
|
||||
// bindTexture(prev);
|
||||
//#endif
|
||||
// }
|
||||
// natras->fbo = 0;
|
||||
// natras->fboMate = nil;
|
||||
|
||||
return raster;
|
||||
}
|
||||
|
|
@ -311,6 +355,7 @@ allocateDXT(Raster *raster, int32 dxt, int32 numLevels, bool32 hasAlpha)
|
|||
raster->depth = 16;
|
||||
|
||||
natras->isCompressed = 1;
|
||||
|
||||
if(raster->format & Raster::MIPMAP)
|
||||
natras->numLevels = numLevels;
|
||||
natras->autogenMipmap = (raster->format & (Raster::MIPMAP|Raster::AUTOMIPMAP)) == (Raster::MIPMAP|Raster::AUTOMIPMAP);
|
||||
|
|
@ -323,7 +368,9 @@ allocateDXT(Raster *raster, int32 dxt, int32 numLevels, bool32 hasAlpha)
|
|||
raster->width, raster->height,
|
||||
0, natras->format, natras->type, nil);
|
||||
// TODO: allocate other levels...probably
|
||||
#ifndef __SYMBIAN32__
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, natras->numLevels-1);
|
||||
#endif
|
||||
natras->filterMode = 0;
|
||||
natras->addressU = 0;
|
||||
natras->addressV = 0;
|
||||
|
|
@ -471,26 +518,33 @@ rasterLock(Raster *raster, int32 level, int32 lockMode)
|
|||
memcpy(px, natras->backingStore->levels[level].data, allocSz);
|
||||
}else{
|
||||
// GLES is losing here
|
||||
#ifndef __SYMBIAN32__ // TODO
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
glGetCompressedTexImage(GL_TEXTURE_2D, level, px);
|
||||
bindTexture(prev);
|
||||
#endif
|
||||
}
|
||||
#ifdef __SYMBIAN32__
|
||||
} else {
|
||||
#else
|
||||
}else if(gl3Caps.gles){
|
||||
#endif
|
||||
GLuint fbo;
|
||||
glGenFramebuffers(1, &fbo);
|
||||
bindFramebuffer(fbo);
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, natras->texid, 0);
|
||||
GLenum e = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
||||
assert(natras->format == GL_RGBA);
|
||||
glReadPixels(0, 0, raster->width, raster->height, natras->format, natras->type, px);
|
||||
//e = glGetError(); printf("GL err4 %x (%x)\n", e, natras->format);
|
||||
bindFramebuffer(0);
|
||||
glDeleteFramebuffers(1, &fbo);
|
||||
#ifndef __SYMBIAN32__
|
||||
}else{
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||
glGetTexImage(GL_TEXTURE_2D, level, natras->format, natras->type, px);
|
||||
bindTexture(prev);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -508,7 +562,11 @@ assert(natras->format == GL_RGBA);
|
|||
px = (uint8*)rwMalloc(allocSz, MEMDUR_EVENT | ID_DRIVER);
|
||||
assert(raster->pixels == nil);
|
||||
raster->pixels = px;
|
||||
#ifdef __SYMBIAN32__
|
||||
memset(px, 0, allocSz);
|
||||
#else
|
||||
glReadBuffer(GL_BACK);
|
||||
#endif
|
||||
glReadPixels(0, 0, raster->width, raster->height, GL_RGB, GL_UNSIGNED_BYTE, px);
|
||||
|
||||
raster->privateFlags = lockMode;
|
||||
|
|
@ -538,6 +596,7 @@ rasterUnlock(Raster *raster, int32 level)
|
|||
case Raster::TEXTURE:
|
||||
case Raster::CAMERATEXTURE:
|
||||
if(raster->privateFlags & Raster::LOCKWRITE){
|
||||
if (level != 0) break;
|
||||
uint32 prev = bindTexture(natras->texid);
|
||||
if(natras->isCompressed){
|
||||
glCompressedTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat,
|
||||
|
|
@ -550,10 +609,27 @@ rasterUnlock(Raster *raster, int32 level)
|
|||
natras->backingStore->levels[level].size);
|
||||
}
|
||||
}else{
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat,
|
||||
raster->width, raster->height,
|
||||
0, natras->format, natras->type, raster->pixels);
|
||||
// glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
if (raster->pixels != nil && natras->format == GL_RGBA && natras->type == GL_UNSIGNED_BYTE) {
|
||||
// convert to 16-bit
|
||||
uint16_t* pixels16 = (uint16_t*)malloc(raster->width * raster->height * sizeof(uint16_t));
|
||||
uint8_t* pixels8 = (uint8_t*)raster->pixels;
|
||||
|
||||
for (int i = 0; i < raster->width * raster->height; i++) {
|
||||
uint8_t r = pixels8[i * 4 + 0];
|
||||
uint8_t g = pixels8[i * 4 + 1];
|
||||
uint8_t b = pixels8[i * 4 + 2];
|
||||
uint8_t a = pixels8[i * 4 + 3];
|
||||
|
||||
pixels16[i] = ((r >> 4) << 12) | ((g >> 4) << 8) | ((b >> 4) << 4) | (a >> 4);
|
||||
}
|
||||
glTexImage2D(GL_TEXTURE_2D, level, GL_RGBA, raster->width, raster->height, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, pixels16);
|
||||
free(pixels16);
|
||||
} else {
|
||||
glTexImage2D(GL_TEXTURE_2D, level, natras->internalFormat,
|
||||
raster->width, raster->height,
|
||||
0, natras->format, natras->type, raster->pixels);
|
||||
}
|
||||
}
|
||||
if(level == 0 && natras->autogenMipmap)
|
||||
glGenerateMipmap(GL_TEXTURE_2D);
|
||||
|
|
@ -659,9 +735,7 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
assert(!natras->isCompressed);
|
||||
switch(image->depth){
|
||||
case 32:
|
||||
if(gl3Caps.gles)
|
||||
conv = conv_RGBA8888_from_RGBA8888;
|
||||
else if(format == Raster::C8888)
|
||||
if(format == Raster::C8888)
|
||||
conv = conv_RGBA8888_from_RGBA8888;
|
||||
else if(format == Raster::C888)
|
||||
conv = conv_RGB888_from_RGB888;
|
||||
|
|
@ -669,9 +743,7 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
goto err;
|
||||
break;
|
||||
case 24:
|
||||
if(gl3Caps.gles)
|
||||
conv = conv_RGBA8888_from_RGB888;
|
||||
else if(format == Raster::C8888)
|
||||
if(format == Raster::C8888)
|
||||
conv = conv_RGBA8888_from_RGB888;
|
||||
else if(format == Raster::C888)
|
||||
conv = conv_RGB888_from_RGB888;
|
||||
|
|
@ -679,7 +751,7 @@ rasterFromImage(Raster *raster, Image *image)
|
|||
goto err;
|
||||
break;
|
||||
case 16:
|
||||
if(gl3Caps.gles)
|
||||
if(format == Raster::C8888)
|
||||
conv = conv_RGBA8888_from_ARGB1555;
|
||||
else if(format == Raster::C1555)
|
||||
conv = conv_RGBA5551_from_ARGB1555;
|
||||
|
|
@ -850,7 +922,11 @@ destroyNativeRaster(void *object, int32 offset, int32)
|
|||
Gl3Raster *oldfb = GETGL3RASTEREXT(natras->fboMate);
|
||||
if(oldfb->fbo){
|
||||
bindFramebuffer(oldfb->fbo);
|
||||
#ifdef __SYMBIAN32__
|
||||
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, 0);
|
||||
#else
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_TEXTURE_2D, 0, 0);
|
||||
#endif
|
||||
}
|
||||
oldfb->fboMate = nil;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue