mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
N64: Try to avoid crash when although width * height * pixel size of a texture fits within 4096 bytes, after aligning each row to 8 bytes, row pitch * height does not fit within 4096 bytes
This commit is contained in:
parent
df7a5eefd4
commit
7d26562277
1 changed files with 7 additions and 0 deletions
|
@ -121,12 +121,19 @@ typedef struct CCTexture {
|
|||
GLuint textureID;
|
||||
} CCTexture;
|
||||
|
||||
#define ALIGNUP8(size) (((size) + 7) & ~0x07)
|
||||
|
||||
// A8 B8 G8 R8 > A1 B5 G5 B5
|
||||
#define To16BitPixel(src) \
|
||||
((src & 0x80) >> 7) | ((src & 0xF800) >> 10) | ((src & 0xF80000) >> 13) | ((src & 0xF8000000) >> 16);
|
||||
|
||||
static GfxResourceID Gfx_AllocTexture(struct Bitmap* bmp, cc_uint8 flags, cc_bool mipmaps) {
|
||||
cc_bool bit16 = flags & TEXTURE_FLAG_LOWRES;
|
||||
// rows are actually 8 byte aligned in TMEM https://github.com/DragonMinded/libdragon/blob/f360fa1bb1fb3ff3d98f4ab58692d40c828636c9/src/rdpq/rdpq_tex.c#L132
|
||||
// so even though width * height * pixel size may fit within 4096 bytes, after adjusting for 8 byte alignment, row pitch * height may exceed 4096 bytes
|
||||
int pitch = bit16 ? ALIGNUP8(bmp->width * 2) : ALIGNUP8(bmp->width * 4);
|
||||
if (pitch * bmp->height > 4096) return 0;
|
||||
|
||||
CCTexture* tex = Mem_Alloc(1, sizeof(CCTexture), "texture");
|
||||
|
||||
glGenTextures(1, &tex->textureID);
|
||||
|
|
Loading…
Reference in a new issue