mirror of
https://github.com/hrydgard/ppsspp.git
synced 2025-04-02 11:01:50 -04:00
GLES: Fix unpack misalignment, Qt debugger freeing.
We no longer use unpack, so we should always decode to w not bufw.
This commit is contained in:
parent
8fcaa651a5
commit
ecd1a04e44
2 changed files with 26 additions and 45 deletions
|
@ -696,29 +696,6 @@ GLenum TextureCacheGLES::GetDestFormat(GETextureFormat format, GEPaletteFormat c
|
|||
}
|
||||
}
|
||||
|
||||
u8 *TextureCacheGLES::DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufwout) {
|
||||
void *finalBuf = nullptr;
|
||||
u32 texaddr = gstate.getTextureAddress(level);
|
||||
int bufw = GetTextureBufw(level, texaddr, format);
|
||||
if (bufwout)
|
||||
*bufwout = bufw;
|
||||
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
|
||||
int decPitch = 0;
|
||||
int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
||||
if (!(scaleFactor == 1 && gstate_c.Supports(GPU_SUPPORTS_UNPACK_SUBIMAGE)) && w != bufw) {
|
||||
decPitch = w * pixelSize;
|
||||
} else {
|
||||
decPitch = bufw * pixelSize;
|
||||
}
|
||||
|
||||
uint8_t *texBuf = (uint8_t *)AllocateAlignedMemory(std::max(w, bufw) * h * pixelSize, 16);
|
||||
DecodeTextureLevel(texBuf, decPitch, format, clutformat, texaddr, level, bufw, true, false, false);
|
||||
return texBuf;
|
||||
}
|
||||
|
||||
TexCacheEntry::TexStatus TextureCacheGLES::CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h) {
|
||||
CheckAlphaResult res;
|
||||
switch (dstFmt) {
|
||||
|
@ -766,15 +743,19 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r
|
|||
PROFILE_THIS_SCOPE("decodetex");
|
||||
|
||||
GEPaletteFormat clutformat = gstate.getClutPaletteFormat();
|
||||
int bufw;
|
||||
uint8_t *finalBuf = DecodeTextureLevelOld(GETextureFormat(entry.format), clutformat, level, dstFmt, scaleFactor, &bufw);
|
||||
if (!finalBuf) {
|
||||
return;
|
||||
}
|
||||
u32 texaddr = gstate.getTextureAddress(level);
|
||||
int bufw = GetTextureBufw(level, texaddr, GETextureFormat(entry.format));
|
||||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
|
||||
int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
||||
int decPitch = w * pixelSize;
|
||||
|
||||
pixelData = (uint8_t *)AllocateAlignedMemory(decPitch * h * pixelSize, 16);
|
||||
DecodeTextureLevel(pixelData, decPitch, GETextureFormat(entry.format), clutformat, texaddr, level, bufw, true, false, false);
|
||||
|
||||
// Textures are always aligned to 16 bytes bufw, so this could safely be 4 always.
|
||||
texByteAlign = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
||||
pixelData = finalBuf;
|
||||
|
||||
// We check before scaling since scaling shouldn't invent alpha from a full alpha texture.
|
||||
if ((entry.status & TexCacheEntry::STATUS_CHANGE_FREQUENT) == 0) {
|
||||
|
@ -787,8 +768,8 @@ void TextureCacheGLES::LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &r
|
|||
if (scaleFactor > 1) {
|
||||
uint8_t *rearrange = (uint8_t *)AllocateAlignedMemory(w * scaleFactor * h * scaleFactor * 4, 16);
|
||||
scaler.ScaleAlways((u32 *)rearrange, (u32 *)pixelData, dstFmt, w, h, scaleFactor);
|
||||
FreeAlignedMemory(pixelData);
|
||||
pixelData = rearrange;
|
||||
FreeAlignedMemory(finalBuf);
|
||||
}
|
||||
|
||||
if (replacer_.Enabled()) {
|
||||
|
@ -844,16 +825,17 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) {
|
|||
int w = gstate.getTextureWidth(level);
|
||||
int h = gstate.getTextureHeight(level);
|
||||
|
||||
void *finalBuf = DecodeTextureLevelOld(format, clutformat, level, dstFmt, 1);
|
||||
if (finalBuf == NULL) {
|
||||
return false;
|
||||
}
|
||||
int pixelSize = dstFmt == GL_UNSIGNED_BYTE ? 4 : 2;
|
||||
int decPitch = w * pixelSize;
|
||||
|
||||
void *finalBuf = AllocateAlignedMemory(decPitch * h * pixelSize, 16);
|
||||
DecodeTextureLevel((uint8_t *)finalBuf, decPitch, format, clutformat, texaddr, level, bufw, true, false, false);
|
||||
|
||||
switch (dstFmt) {
|
||||
case GL_UNSIGNED_SHORT_4_4_4_4:
|
||||
for (int y = 0; y < h; y++)
|
||||
for (int x = 0; x < bufw; x++) {
|
||||
u32 val = ((u16*)finalBuf)[y*bufw + x];
|
||||
for (int x = 0; x < w; x++) {
|
||||
u32 val = ((u16*)finalBuf)[y*w + x];
|
||||
u32 r = ((val>>12) & 0xF) * 17;
|
||||
u32 g = ((val>> 8) & 0xF) * 17;
|
||||
u32 b = ((val>> 4) & 0xF) * 17;
|
||||
|
@ -864,8 +846,8 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) {
|
|||
|
||||
case GL_UNSIGNED_SHORT_5_5_5_1:
|
||||
for (int y = 0; y < h; y++)
|
||||
for (int x = 0; x < bufw; x++) {
|
||||
u32 val = ((u16*)finalBuf)[y*bufw + x];
|
||||
for (int x = 0; x < w; x++) {
|
||||
u32 val = ((u16*)finalBuf)[y*w + x];
|
||||
u32 r = Convert5To8((val>>11) & 0x1F);
|
||||
u32 g = Convert5To8((val>> 6) & 0x1F);
|
||||
u32 b = Convert5To8((val>> 1) & 0x1F);
|
||||
|
@ -876,8 +858,8 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) {
|
|||
|
||||
case GL_UNSIGNED_SHORT_5_6_5:
|
||||
for (int y = 0; y < h; y++)
|
||||
for (int x = 0; x < bufw; x++) {
|
||||
u32 val = ((u16*)finalBuf)[y*bufw + x];
|
||||
for (int x = 0; x < w; x++) {
|
||||
u32 val = ((u16*)finalBuf)[y*w + x];
|
||||
u32 a = 0xFF;
|
||||
u32 r = Convert5To8((val>>11) & 0x1F);
|
||||
u32 g = Convert6To8((val>> 5) & 0x3F);
|
||||
|
@ -888,13 +870,15 @@ bool TextureCacheGLES::DecodeTexture(u8* output, const GPUgstate &state) {
|
|||
|
||||
default:
|
||||
for (int y = 0; y < h; y++)
|
||||
for (int x = 0; x < bufw; x++) {
|
||||
u32 val = ((u32*)finalBuf)[y*bufw + x];
|
||||
for (int x = 0; x < w; x++) {
|
||||
u32 val = ((u32*)finalBuf)[y*w + x];
|
||||
((u32*)output)[y*w + x] = ((val & 0xFF000000)) | ((val & 0x00FF0000)>>16) | ((val & 0x0000FF00)) | ((val & 0x000000FF)<<16);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
FreeAlignedMemory(finalBuf);
|
||||
|
||||
gstate = oldState;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -81,9 +81,6 @@ private:
|
|||
void LoadTextureLevel(TexCacheEntry &entry, ReplacedTexture &replaced, int level, bool replaceImages, int scaleFactor, GLenum dstFmt);
|
||||
GLenum GetDestFormat(GETextureFormat format, GEPaletteFormat clutFormat) const;
|
||||
|
||||
// Caller owns the returned buffer. Delete[].
|
||||
u8 *DecodeTextureLevelOld(GETextureFormat format, GEPaletteFormat clutformat, int level, GLenum dstFmt, int scaleFactor, int *bufw = 0);
|
||||
|
||||
TexCacheEntry::TexStatus CheckAlpha(const uint8_t *pixelData, GLenum dstFmt, int stride, int w, int h);
|
||||
void UpdateCurrentClut(GEPaletteFormat clutFormat, u32 clutBase, bool clutIndexIsSimple) override;
|
||||
void ApplyTextureFramebuffer(TexCacheEntry *entry, VirtualFramebuffer *framebuffer) override;
|
||||
|
|
Loading…
Add table
Reference in a new issue