1
0
mirror of https://github.com/RPCS3/rpcs3.git synced 2024-11-22 10:42:36 +01:00

more rsx texture (address, control0, image rect)

This commit is contained in:
elisha464 2014-02-05 22:48:30 +02:00
parent d2bd0b0ccf
commit c515cb8fb6
4 changed files with 159 additions and 166 deletions

View File

@ -53,8 +53,10 @@ public:
case 2: return GL_MIRRORED_REPEAT;
case 3: return GL_CLAMP_TO_EDGE;
case 4: return GL_CLAMP_TO_BORDER;
case 5: return GL_CLAMP_TO_EDGE;//GL_CLAMP;
//case 6: return GL_MIRROR_CLAMP_TO_EDGE_EXT;
case 5: return GL_CLAMP_TO_EDGE;
case 6: return GL_MIRROR_CLAMP_TO_EDGE_EXT;
case 7: return GL_MIRROR_CLAMP_TO_BORDER_EXT;
case 8: return GL_MIRROR_CLAMP_EXT;
}
ConLog.Error("Texture wrap error: bad wrap (%d).", wrap);
@ -83,7 +85,7 @@ public:
switch(format)
{
case 0x81:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BLUE, GL_UNSIGNED_BYTE, pixels);
checkForGlError("GLTexture::Init() -> glTexImage2D");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
@ -95,39 +97,39 @@ public:
break;
case 0x85:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels);
checkForGlError("GLTexture::Init() -> glTexImage2D");
break;
case 0x86:
{
u32 size = ((tex.m_width + 3) / 4) * ((tex.m_height + 3) / 4) * 8;
u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 8;
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, tex.m_width, tex.m_height, 0, size, pixels);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels);
checkForGlError("GLTexture::Init() -> glCompressedTexImage2D");
}
break;
case 0x87:
{
u32 size = ((tex.m_width + 3) / 4) * ((tex.m_height + 3) / 4) * 16;
u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16;
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, tex.m_width, tex.m_height, 0, size, pixels);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels);
checkForGlError("GLTexture::Init() -> glCompressedTexImage2D");
}
break;
case 0x88:
{
u32 size = ((tex.m_width + 3) / 4) * ((tex.m_height + 3) / 4) * 16;
u32 size = ((tex.GetWidth() + 3) / 4) * ((tex.GetHeight() + 3) / 4) * 16;
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, tex.m_width, tex.m_height, 0, size, pixels);
glCompressedTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, tex.GetWidth(), tex.GetHeight(), 0, size, pixels);
checkForGlError("GLTexture::Init() -> glCompressedTexImage2D");
}
break;
case 0x94:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_RED, GL_SHORT, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_RED, GL_SHORT, pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_ONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_G, GL_ONE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_ONE);
@ -136,13 +138,13 @@ public:
break;
case 0x9a:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BGRA, GL_HALF_FLOAT, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_HALF_FLOAT, pixels);
checkForGlError("GLTexture::Init() -> glTexImage2D");
break;
case 0x9e:
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.m_width, tex.m_height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tex.GetWidth(), tex.GetHeight(), 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, pixels);
checkForGlError("GLTexture::Init() -> glTexImage2D");
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_ONE);
}
@ -189,16 +191,16 @@ public:
GL_ALWAYS,
};
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrap(tex.m_wraps));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.m_wrapt));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.m_wrapr));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[tex.m_zfunc]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GetGlWrap(tex.GetWrapS()));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GetGlWrap(tex.GetWrapT()));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GetGlWrap(tex.GetWrapR()));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, gl_tex_zfunc[tex.GetZfunc()]);
checkForGlError("GLTexture::Init() -> parameters1");
glTexEnvi(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, tex.m_bias);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, tex.m_minlod);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, tex.m_maxlod);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, (tex.GetMinLOD() >> 8));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, (tex.GetMaxLOD() >> 8));
checkForGlError("GLTexture::Init() -> parameters2");
@ -224,9 +226,9 @@ public:
void Save(RSXTexture& tex, const wxString& name)
{
if(!m_id || !tex.GetOffset() || !tex.m_width || !tex.m_height) return;
if(!m_id || !tex.GetOffset() || !tex.GetWidth() || !tex.GetHeight()) return;
u32* alldata = new u32[tex.m_width * tex.m_height];
u32* alldata = new u32[tex.GetWidth() * tex.GetHeight()];
Bind();
@ -247,15 +249,15 @@ public:
{
wxFile f(name + ".raw", wxFile::write);
f.Write(alldata, tex.m_width * tex.m_height * 4);
f.Write(alldata, tex.GetWidth() * tex.GetHeight() * 4);
}
u8* data = new u8[tex.m_width * tex.m_height * 3];
u8* alpha = new u8[tex.m_width * tex.m_height];
u8* data = new u8[tex.GetWidth() * tex.GetHeight() * 3];
u8* alpha = new u8[tex.GetWidth() * tex.GetHeight()];
u8* src = (u8*)alldata;
u8* dst_d = data;
u8* dst_a = alpha;
for(u32 i=0; i<tex.m_width*tex.m_height;i++)
for(u32 i=0; i<tex.GetWidth()*tex.GetHeight();i++)
{
*dst_d++ = *src++;
*dst_d++ = *src++;
@ -264,7 +266,7 @@ public:
}
wxImage out;
out.Create(tex.m_width, tex.m_height, data, alpha);
out.Create(tex.GetWidth(), tex.GetHeight(), data, alpha);
out.SaveFile(name, wxBITMAP_TYPE_PNG);
free(alldata);

View File

@ -2,18 +2,7 @@
#include "RSXThread.h"
RSXTexture::RSXTexture()
: m_width(0)
, m_height(0)
, m_enabled(false)
, m_minlod(0)
, m_maxlod(1000)
, m_maxaniso(0)
, m_wraps(1)
, m_wrapt(1)
, m_wrapr(3)
, m_zfunc(0)
, m_gamma(0)
, m_bias(0)
: m_bias(0)
, m_remap(0xE4)
, m_min_filter(1)
, m_mag_filter(2)
@ -22,18 +11,7 @@ RSXTexture::RSXTexture()
}
RSXTexture::RSXTexture(u8 index)
: m_width(0)
, m_height(0)
, m_enabled(false)
, m_minlod(0)
, m_maxlod(1000)
, m_maxaniso(0)
, m_wraps(1)
, m_wrapt(1)
, m_wrapr(3)
, m_zfunc(0)
, m_gamma(0)
, m_bias(0)
: m_bias(0)
, m_remap(0xE4)
, m_min_filter(1)
, m_mag_filter(2)
@ -41,6 +19,27 @@ RSXTexture::RSXTexture(u8 index)
m_index = index;
}
void RSXTexture::Init()
{
// Offset
methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*4)] = 0;
// Format
methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] = 0;
// Address
methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] =
((/*wraps*/1) | ((/*anisoBias*/0) << 4) | ((/*wrapt*/1) << 8) | ((/*unsignedRemap*/0) << 12) |
((/*wrapr*/2) << 16) | ((/*gamma*/0) << 20) |((/*signedRemap*/0) << 24) | ((/*zfunc*/0) << 28));
// Control0
methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] =
(((/*alphakill*/0) << 2) | (/*maxaniso*/0) << 4) | ((/*maxlod*/0xc00) << 7) | ((/*minlod*/0) << 19) | ((/*enable*/0) << 31);
// Image Rect
methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*4)] = (/*height*/1) | ((/*width*/1) << 16);
}
u32 RSXTexture::GetOffset() const
{
return methodRegisters[NV4097_SET_TEXTURE_OFFSET + (m_index*4)];
@ -76,30 +75,83 @@ u16 RSXTexture::Getmipmap() const
return ((methodRegisters[NV4097_SET_TEXTURE_FORMAT + (m_index*4)] >> 16) & 0xffff);
}
void RSXTexture::SetRect(const u32 width, const u32 height)
u8 RSXTexture::GetWrapS() const
{
m_width = width;
m_height = height;
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)]) & 0xf);
}
void RSXTexture::SetAddress(u8 wraps, u8 wrapt, u8 wrapr, u8 unsigned_remap, u8 zfunc, u8 gamma, u8 aniso_bias, u8 signed_remap)
u8 RSXTexture::GetWrapT() const
{
m_wraps = wraps;
m_wrapt = wrapt;
m_wrapr = wrapr;
m_unsigned_remap = unsigned_remap;
m_zfunc = zfunc;
m_gamma = gamma;
m_aniso_bias = aniso_bias;
m_signed_remap = signed_remap;
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 8) & 0xf);
}
u8 RSXTexture::GetWrapR() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 16) & 0xf);
}
u8 RSXTexture::GetUnsignedRemap() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 12) & 0xf);
}
u8 RSXTexture::GetZfunc() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 28) & 0xf);
}
u8 RSXTexture::GetGamma() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 20) & 0xf);
}
u8 RSXTexture::GetAnisoBias() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 4) & 0xf);
}
u8 RSXTexture::GetSignedRemap() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_ADDRESS + (m_index*4)] >> 24) & 0xf);
}
bool RSXTexture::IsEnabled() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 31) & 0x1);
}
u16 RSXTexture::GetMinLOD() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 19) & 0xfff);
}
u16 RSXTexture::GetMaxLOD() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 7) & 0xfff);
}
u8 RSXTexture::GetMaxAniso() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 4) & 0x7);
}
bool RSXTexture::IsAlphaKillEnabled() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_CONTROL0 + (m_index*4)] >> 2) & 0x1);
}
u16 RSXTexture::GetWidth() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*4)] >> 16) & 0xffff);
}
u16 RSXTexture::GetHeight() const
{
return ((methodRegisters[NV4097_SET_TEXTURE_IMAGE_RECT + (m_index*4)]) & 0xffff);
}
void RSXTexture::SetControl0(const bool enable, const u16 minlod, const u16 maxlod, const u8 maxaniso)
{
m_enabled = enable;
m_minlod = minlod;
m_maxlod = maxlod;
m_maxaniso = maxaniso;
}
void RSXTexture::SetControl1(u32 remap)
@ -123,14 +175,4 @@ void RSXTexture::SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_
m_r_signed = r_signed;
m_g_signed = g_signed;
m_b_signed = b_signed;
}
wxSize RSXTexture::GetRect() const
{
return wxSize(m_width, m_height);
}
bool RSXTexture::IsEnabled() const
{
return m_enabled;
}

View File

@ -200,33 +200,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
case_16(NV4097_SET_TEXTURE_OFFSET, 0x20):
{
RSXTexture& tex = m_textures[index];
const u32 offset = ARGS(0);
u32 a1 = ARGS(1);
u8 location = (a1 & 0x3) - 1;
const bool cubemap = (a1 >> 2) & 0x1;
const u8 dimension = (a1 >> 4) & 0xf;
const u8 format = (a1 >> 8) & 0xff;
const u16 mipmap = (a1 >> 16) & 0xffff;
CMD_LOG("index = %d, offset=0x%x, location=0x%x, cubemap=0x%x, dimension=0x%x, format=0x%x, mipmap=0x%x",
index, offset, location, cubemap, dimension, format, mipmap);
if(location == 2)
{
ConLog.Error("Bad texture location.");
location = 1;
}
u32 tex_addr = GetAddress(offset, location);
if(!Memory.IsGoodAddr(tex_addr))
ConLog.Error("Bad texture[%d] addr = 0x%x #offset = 0x%x, location=%d", index, tex_addr, offset, location);
//ConLog.Warning("texture addr = 0x%x #offset = 0x%x, location=%d", tex_addr, offset, location);
if(!tex.m_width || !tex.m_height)
{
gcmBuffer* buffers = (gcmBuffer*)Memory.GetMemFromAddr(m_gcm_buffers_addr);
if(!tex.m_width) tex.m_width = re(buffers[m_gcm_current_buffer].width);
if(!tex.m_height) tex.m_height = re(buffers[m_gcm_current_buffer].height);
}
}
break;
@ -341,19 +314,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
case_16(NV4097_SET_TEXTURE_ADDRESS, 0x20):
{
RSXTexture& tex = m_textures[index];
u32 a0 = ARGS(0);
u8 wraps = a0 & 0xf;
u8 aniso_bias = (a0 >> 4) & 0xf;
u8 wrapt = (a0 >> 8) & 0xf;
u8 unsigned_remap = (a0 >> 12) & 0xf;
u8 wrapr = (a0 >> 16) & 0xf;
u8 gamma = (a0 >> 20) & 0xf;
u8 signed_remap = (a0 >> 24) & 0xf;
u8 zfunc = a0 >> 28;
tex.SetAddress(wraps, wrapt, wrapr, unsigned_remap, zfunc, gamma, aniso_bias, signed_remap);
}
break;
@ -363,26 +323,6 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
case_16(NV4097_SET_TEXTURE_IMAGE_RECT, 32):
{
RSXTexture& tex = m_textures[index];
u16 height = ARGS(0) & 0xffff;
u16 width = ARGS(0) >> 16;
CMD_LOG("width=%d, height=%d", width, height);
if(!width || !height)
{
ConLog.Warning("Bad texture rect: %dx%d (%dx%d)", width, height, tex.m_width, tex.m_height);
for(int i=0; i<count; ++i)
{
ConLog.Warning("*** 0x%x", ARGS(i));
}
if(!width) width = tex.m_width;
if(!height) height = tex.m_height;
}
tex.SetRect(width, height);
}
break;
@ -1404,6 +1344,11 @@ void RSXThread::DoCmd(const u32 fcmd, const u32 cmd, mem32_ptr_t& args, const u3
m_fog_param1 = (float&)a1;
}
break;
case NV4097_SET_VIEWPORT_SCALE:
{
}
break;
default:
{

View File

@ -19,26 +19,9 @@ class RSXTexture
{
u8 m_index;
public:
bool m_enabled;
u32 m_width, m_height;
u32 m_pitch;
u16 m_depth;
u16 m_minlod;
u16 m_maxlod;
u8 m_maxaniso;
u8 m_wraps;
u8 m_wrapt;
u8 m_wrapr;
u8 m_unsigned_remap;
u8 m_zfunc;
u8 m_gamma;
u8 m_aniso_bias;
u8 m_signed_remap;
u16 m_bias;
u8 m_min_filter;
u8 m_mag_filter;
@ -51,25 +34,46 @@ public:
u32 m_remap;
public:
RSXTexture();
RSXTexture();
RSXTexture(u8 index);
void Init();
u32 GetOffset() const;
u8 GetLocation() const;
bool isCubemap() const;
u8 GetBorderType() const;
u8 GetDimension() const;
u8 GetFormat() const;
u16 Getmipmap() const;
// Offset
u32 GetOffset() const;
// Format
u8 GetLocation() const;
bool isCubemap() const;
u8 GetBorderType() const;
u8 GetDimension() const;
u8 GetFormat() const;
u16 Getmipmap() const;
// Address
u8 GetWrapS() const;
u8 GetWrapT() const;
u8 GetWrapR() const;
u8 GetUnsignedRemap() const;
u8 GetZfunc() const;
u8 GetGamma() const;
u8 GetAnisoBias() const;
u8 GetSignedRemap() const;
// Control0
bool IsEnabled() const;
u16 GetMinLOD() const;
u16 GetMaxLOD() const;
u8 GetMaxAniso() const;
bool IsAlphaKillEnabled() const;
// Image Rect
u16 GetWidth() const;
u16 GetHeight() const;
void SetRect(const u32 width, const u32 height);
void SetAddress(u8 wraps, u8 wrapt, u8 wrapr, u8 unsigned_remap, u8 zfunc, u8 gamma, u8 aniso_bias, u8 signed_remap);
void SetControl0(const bool enable, const u16 minlod, const u16 maxlod, const u8 maxaniso);
void SetControl1(u32 remap);
void SetControl3(u16 depth, u32 pitch);
void SetFilter(u16 bias, u8 min, u8 mag, u8 conv, u8 a_signed, u8 r_signed, u8 g_signed, u8 b_signed);
wxSize GetRect() const;
bool IsEnabled() const;
};
struct RSXVertexData
@ -546,7 +550,7 @@ protected:
for(uint i=0; i<m_textures_count; ++i)
{
m_textures[i].m_enabled = false;
m_textures[i].Init();
}
}