Skip to content

Commit

Permalink
Added YUV texture support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Extrems committed Aug 22, 2021
1 parent 03b282c commit e2dda13
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 28 deletions.
54 changes: 35 additions & 19 deletions glN64_GX/TEV_combiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,14 @@ void Update_TEV_combine_Colors( TEVCombiner *TEVcombiner ) //Called from OGL_Upd
case TEV_K4:
GXconstantColor.r =
GXconstantColor.g =
GXconstantColor.b =
GXconstantColor.a = gDP.convert.k4;
GXconstantColor.b = gDP.convert.k4;
GXconstantColor.a = (gDP.convert.k4 * gDP.convert.k5 + 0x80) >> 8;
break;
case TEV_K5:
GXconstantColor.r =
GXconstantColor.g =
GXconstantColor.b =
GXconstantColor.a = gDP.convert.k5;
GXconstantColor.b = gDP.convert.k5;
GXconstantColor.a = (gDP.convert.k5 * gDP.convert.k4 + 0x80) >> 8;
break;
}
GX_SetTevKColor(TEVconstRegs[TEVcombiner->TEVconstant[i]].tev_regid, GXconstantColor);
Expand Down Expand Up @@ -487,6 +487,9 @@ TEVCombiner *Compile_TEV_combine( Combiner *color, Combiner *alpha )
sb = (gDP.primColor.r + gDP.primColor.b + gDP.primColor.g) / 3.0f;
else if (color->stage[i].op[j].param1 == ENVIRONMENT)
sb = (gDP.envColor.r + gDP.envColor.b + gDP.envColor.g) / 3.0f;
else if ((color->stage[i].op[j].param1 == K4) &&
(color->stage[i].op[j+1].param1 == K5))
sb = 1.0f;

// This helps with problems caused by not using signed values between texture units
//Instead of (A - B)*C + D do A*C - B*C + D
Expand Down Expand Up @@ -521,24 +524,37 @@ TEVCombiner *Compile_TEV_combine( Combiner *color, Combiner *alpha )
GX_TEV_ADD, colorTEX, colorCONST, colorCONST_AAA, GX_TEVREG0);
if (currStageC) TEVcombiner->TEVstage[currStageC-1].colorClamp = GX_ENABLE; //TEVPREV used in Mult!
currStageC++;
//TEVstage[currStageC++] -> ( d(PREV) - b(param1) * c(param2) );
colorTEX = (TEVArgs[color->stage[i].op[j].param1].TEV_TexCoordMap == GX_TEXMAP_NULL) ?
TEVArgs[color->stage[i].op[j+1].param1].TEV_TexCoordMap : TEVArgs[color->stage[i].op[j].param1].TEV_TexCoordMap;
colorCONST = (TEVArgs[color->stage[i].op[j].param1].TEV_inpType <= TEV_MAX_CONST) ?
TEVArgs[color->stage[i].op[j].param1].TEV_inpType : TEVArgs[color->stage[i].op[j+1].param1].TEV_inpType;
//TODO: The following would break if both RGB and AAA versions of the same constant are used.
colorCONST_AAA = TEVArgs[color->stage[i].op[j].param1].KonstAAA || TEVArgs[color->stage[i].op[j+1].param1].KonstAAA;
while((TEVcombiner->TEVstage[currStageC].texmap != GX_TEXMAP_NULL) &&
(TEVcombiner->TEVstage[currStageC].texmap != colorTEX))

if ((color->stage[i].op[j].param1 == K4) &&
(color->stage[i].op[j+1].param1 == K5))
{
SetColorTEVskip(currStageC);
//TEVstage[currStageC++] -> ( d(PREV) - b(param1) * c(param2) );
SetColorTEV(currStageC, TEVArgs[color->stage[i].op[j+1].param1].TEV_colorIn, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0,
GX_TEV_SUB, TEVArgs[color->stage[i].op[j+1].param1].TEV_TexCoordMap, TEVArgs[color->stage[i].op[j+1].param1].TEV_inpType, TRUE, GX_TEVREG0);
currStageC++;
j+=2;
}
else
{
//TEVstage[currStageC++] -> ( d(PREV) - b(param1) * c(param2) );
colorTEX = (TEVArgs[color->stage[i].op[j].param1].TEV_TexCoordMap == GX_TEXMAP_NULL) ?
TEVArgs[color->stage[i].op[j+1].param1].TEV_TexCoordMap : TEVArgs[color->stage[i].op[j].param1].TEV_TexCoordMap;
colorCONST = (TEVArgs[color->stage[i].op[j].param1].TEV_inpType <= TEV_MAX_CONST) ?
TEVArgs[color->stage[i].op[j].param1].TEV_inpType : TEVArgs[color->stage[i].op[j+1].param1].TEV_inpType;
//TODO: The following would break if both RGB and AAA versions of the same constant are used.
colorCONST_AAA = TEVArgs[color->stage[i].op[j].param1].KonstAAA || TEVArgs[color->stage[i].op[j+1].param1].KonstAAA;
while((TEVcombiner->TEVstage[currStageC].texmap != GX_TEXMAP_NULL) &&
(TEVcombiner->TEVstage[currStageC].texmap != colorTEX))
{
SetColorTEVskip(currStageC);
currStageC++;
}
SetColorTEV(currStageC, GX_CC_ZERO, TEVArgs[color->stage[i].op[j].param1].TEV_colorIn,
TEVArgs[color->stage[i].op[j+1].param1].TEV_colorIn, GX_CC_C0,
GX_TEV_SUB, colorTEX, colorCONST, colorCONST_AAA, GX_TEVREG0);
currStageC++;
j+=2;
}
SetColorTEV(currStageC, GX_CC_ZERO, TEVArgs[color->stage[i].op[j].param1].TEV_colorIn,
TEVArgs[color->stage[i].op[j+1].param1].TEV_colorIn, GX_CC_C0,
GX_TEV_SUB, colorTEX, colorCONST, colorCONST_AAA, GX_TEVREG0);
currStageC++;
j+=2;
}
else
{
Expand Down
52 changes: 47 additions & 5 deletions glN64_GX/Textures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,48 @@ inline u32 GXGetRGBA5551_RGB5A3( u64 *src, u16 x, u16 i, u8 palette )
return (u32) c;
}

inline u32 GXGetUYVY8888_RGBA8( u64 *src, u16 x, u16 i, u8 palette )
{
u16 color = ((u16*)src)[x^i];
s32 y, u, v;
s32 r, g, b;

if (x & 1)
{
y = color & 0xFF;
v = (color >> 8) - 0x80;
color = ((u16*)src)[x^i^1];
u = (color >> 8) - 0x80;
}
else
{
y = color & 0xFF;
u = (color >> 8) - 0x80;
color = ((u16*)src)[x^i^1];
v = (color >> 8) - 0x80;
}

if (palette & 1)
{
g = y + ((gDP.convert.k1 * u + gDP.convert.k2 * v + 0x80) >> 8);
if (g & ~0xFF)
g = ~g >> 31 & 0xFF;
b = y + ((gDP.convert.k3 * u + 0x80) >> 8);
if (b & ~0xFF)
b = ~b >> 31 & 0xFF;
color = (g << 8) | b;
}
else
{
r = y + ((gDP.convert.k0 * v + 0x80) >> 8);
if (r & ~0xFF)
r = ~r >> 31 & 0xFF;
color = (y << 8) | r;
}

return (u32) color;
}

inline u32 GXGetRGBA8888_RGBA8( u64 *src, u16 x, u16 i, u8 palette )
{
//set palette = 0 for AR texels and palette = 1 for GB texels
Expand Down Expand Up @@ -354,7 +396,7 @@ const struct
},
{ // 16-bit
{ GXGetRGBA5551_RGB5A3, GX_TF_RGB5A3, 2, 2, 2048 }, // RGBA
{ GetNone, GX_TF_I4, 0, 2, 2048 }, // YUV
{ GXGetUYVY8888_RGBA8, GX_TF_RGBA8, 4, 2, 2048 }, // YUV
{ GXGetIA88_IA8, GX_TF_IA8, 2, 2, 2048 }, // CI as IA
{ GXGetIA88_IA8, GX_TF_IA8, 2, 2, 2048 }, // IA
{ GetNone, GX_TF_I4, 0, 2, 2048 }, // I
Expand Down Expand Up @@ -384,7 +426,7 @@ const struct
},
{ // 16-bit
{ GXGetCI16RGBA_RGB5A3, GX_TF_RGB5A3, 2, 2, 1024 }, // RGBA
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // YUV
{ GXGetUYVY8888_RGBA8, GX_TF_RGBA8, 4, 2, 2048 }, // YUV
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // CI
{ GXGetCI16RGBA_RGB5A3, GX_TF_RGB5A3, 2, 2, 1024 }, // IA as CI
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // I
Expand Down Expand Up @@ -414,7 +456,7 @@ const struct
},
{ // 16-bit
{ GXGetCI16RGBA_RGB5A3, GX_TF_RGB5A3, 2, 2, 1024 }, // RGBA
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // YUV
{ GXGetUYVY8888_RGBA8, GX_TF_RGBA8, 4, 2, 2048 }, // YUV
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // CI
{ GXGetCI16RGBA_RGB5A3, GX_TF_RGB5A3, 2, 2, 1024 }, // IA as CI
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // I
Expand Down Expand Up @@ -444,7 +486,7 @@ const struct
},
{ // 16-bit
{ GXGetCI16IA_IA8, GX_TF_IA8, 2, 2, 1024 }, // RGBA
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // YUV
{ GXGetUYVY8888_RGBA8, GX_TF_RGBA8, 4, 2, 2048 }, // YUV
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // CI
{ GXGetCI16IA_IA8, GX_TF_IA8, 2, 2, 1024 }, // IA
{ GetNone, GX_TF_I4, 0, 2, 1024 }, // I
Expand Down Expand Up @@ -1203,7 +1245,7 @@ void TextureCache_Load( CachedTexture *texInfo )

line = texInfo->line;

if (texInfo->size == G_IM_SIZ_32b)
if (((texInfo->format == G_IM_FMT_YUV) && (texInfo->size == G_IM_SIZ_16b)) || (texInfo->size == G_IM_SIZ_32b))
line <<= 1;

if (texInfo->maskS)
Expand Down
8 changes: 4 additions & 4 deletions glN64_GX/gDP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -856,10 +856,10 @@ void gDPFillRectangle( s32 ulx, s32 uly, s32 lrx, s32 lry )

void gDPSetConvert( s32 k0, s32 k1, s32 k2, s32 k3, s32 k4, s32 k5 )
{
gDP.convert.k0 = k0;
gDP.convert.k1 = k1;
gDP.convert.k2 = k2;
gDP.convert.k3 = k3;
gDP.convert.k0 = (k0 << (32 - 9) >> (32 - 10)) + 1;
gDP.convert.k1 = (k1 << (32 - 9) >> (32 - 10)) + 1;
gDP.convert.k2 = (k2 << (32 - 9) >> (32 - 10)) + 1;
gDP.convert.k3 = (k3 << (32 - 9) >> (32 - 10)) + 1;
gDP.convert.k4 = k4;
gDP.convert.k5 = k5;
}
Expand Down

0 comments on commit e2dda13

Please sign in to comment.