Skip to content

Commit

Permalink
Minor cleanups in framebuffer manager
Browse files Browse the repository at this point in the history
  • Loading branch information
hrydgard committed Apr 30, 2022
1 parent 815910c commit 6bc7a69
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
24 changes: 0 additions & 24 deletions Common/Data/Convert/ColorConv.cpp
Expand Up @@ -34,30 +34,6 @@
#endif
#endif

inline u16 RGBA8888toRGB565(u32 px) {
return ((px >> 3) & 0x001F) | ((px >> 5) & 0x07E0) | ((px >> 8) & 0xF800);
}

inline u16 RGBA8888toRGBA4444(u32 px) {
return ((px >> 4) & 0x000F) | ((px >> 8) & 0x00F0) | ((px >> 12) & 0x0F00) | ((px >> 16) & 0xF000);
}

inline u16 BGRA8888toRGB565(u32 px) {
return ((px >> 19) & 0x001F) | ((px >> 5) & 0x07E0) | ((px << 8) & 0xF800);
}

inline u16 BGRA8888toRGBA4444(u32 px) {
return ((px >> 20) & 0x000F) | ((px >> 8) & 0x00F0) | ((px << 4) & 0x0F00) | ((px >> 16) & 0xF000);
}

inline u16 BGRA8888toRGBA5551(u32 px) {
return ((px >> 19) & 0x001F) | ((px >> 6) & 0x03E0) | ((px << 7) & 0x7C00) | ((px >> 16) & 0x8000);
}

inline u16 RGBA8888toRGBA5551(u32 px) {
return ((px >> 3) & 0x001F) | ((px >> 6) & 0x03E0) | ((px >> 9) & 0x7C00) | ((px >> 16) & 0x8000);
}

// convert 4444 image to 8888, parallelizable
void convert4444_gl(u16* data, u32* out, int width, int l, int u) {
for (int y = l; y < u; ++y) {
Expand Down
24 changes: 24 additions & 0 deletions Common/Data/Convert/ColorConv.h
Expand Up @@ -35,6 +35,30 @@ inline u8 Convert6To8(u8 v) {
return (v << 2) | (v >> 4);
}

inline u16 RGBA8888toRGB565(u32 px) {
return ((px >> 3) & 0x001F) | ((px >> 5) & 0x07E0) | ((px >> 8) & 0xF800);
}

inline u16 RGBA8888toRGBA4444(u32 px) {
return ((px >> 4) & 0x000F) | ((px >> 8) & 0x00F0) | ((px >> 12) & 0x0F00) | ((px >> 16) & 0xF000);
}

inline u16 BGRA8888toRGB565(u32 px) {
return ((px >> 19) & 0x001F) | ((px >> 5) & 0x07E0) | ((px << 8) & 0xF800);
}

inline u16 BGRA8888toRGBA4444(u32 px) {
return ((px >> 20) & 0x000F) | ((px >> 8) & 0x00F0) | ((px << 4) & 0x0F00) | ((px >> 16) & 0xF000);
}

inline u16 BGRA8888toRGBA5551(u32 px) {
return ((px >> 19) & 0x001F) | ((px >> 6) & 0x03E0) | ((px << 7) & 0x7C00) | ((px >> 16) & 0x8000);
}

inline u16 RGBA8888toRGBA5551(u32 px) {
return ((px >> 3) & 0x001F) | ((px >> 6) & 0x03E0) | ((px >> 9) & 0x7C00) | ((px >> 16) & 0x8000);
}

inline u32 RGBA4444ToRGBA8888(u16 src) {
const u32 r = (src & 0x000F) << 0;
const u32 g = (src & 0x00F0) << 4;
Expand Down
6 changes: 3 additions & 3 deletions GPU/Common/FramebufferManagerCommon.cpp
Expand Up @@ -1699,9 +1699,9 @@ void FramebufferManagerCommon::ApplyClearToMemory(int x1, int y1, int x2, int y2
if (bpp == 2) {
u16 clear16 = 0;
switch (gstate.FrameBufFormat()) {
case GE_FORMAT_565: ConvertRGBA8888ToRGB565(&clear16, &clearColor, 1); break;
case GE_FORMAT_5551: ConvertRGBA8888ToRGBA5551(&clear16, &clearColor, 1); break;
case GE_FORMAT_4444: ConvertRGBA8888ToRGBA4444(&clear16, &clearColor, 1); break;
case GE_FORMAT_565: clear16 = RGBA8888toRGB565(clearColor); break;
case GE_FORMAT_5551: clear16 = RGBA8888toRGBA5551(clearColor); break;
case GE_FORMAT_4444: clear16 = RGBA8888toRGBA4444(clearColor); break;
default: _dbg_assert_(0); break;
}
clearBits = clear16 | (clear16 << 16);
Expand Down
3 changes: 0 additions & 3 deletions GPU/Common/GPUStateUtils.h
Expand Up @@ -54,9 +54,6 @@ bool IsAlphaTestAgainstZero();
bool NeedsTestDiscard();
bool IsStencilTestOutputDisabled();

// If not, we have to emulate it in the shader, similar to blend replace.
bool IsColorMaskSimple(uint32_t colorMask);

StencilValueType ReplaceAlphaWithStencilType();
ReplaceAlphaType ReplaceAlphaWithStencil(ReplaceBlendType replaceBlend);
ReplaceBlendType ReplaceBlendWithShader(bool allowShaderBlend, GEBufferFormat bufferFormat);
Expand Down

0 comments on commit 6bc7a69

Please sign in to comment.