mirror of
https://github.com/RetroDECK/Supermodel.git
synced 2025-04-10 19:15:14 +00:00
support 4 bit textures
This commit is contained in:
parent
e108b56664
commit
fd3eb49369
|
@ -738,9 +738,9 @@ void CLegacy3D::InsertVertex(ModelCache *Cache, const Vertex *V, const Poly *P,
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_SHININESS] = (GLfloat) shininess;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_SHININESS] = (GLfloat) shininess;
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_FOGINTENSITY] = fogIntensity;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_FOGINTENSITY] = fogIntensity;
|
||||||
|
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_NX] = fixedShading ? 0. : nx*normFlip;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_NX] = fixedShading ? 0.f : nx*normFlip;
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_NY] = fixedShading ? 0. : ny*normFlip;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_NY] = fixedShading ? 0.f : ny*normFlip;
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_NZ] = fixedShading ? 0. : nz*normFlip;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_NZ] = fixedShading ? 0.f : nz*normFlip;
|
||||||
|
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_U] = V->u;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_U] = V->u;
|
||||||
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_V] = V->v;
|
Cache->verts[s][baseIdx + VBO_VERTEX_OFFSET_V] = V->v;
|
||||||
|
|
|
@ -895,7 +895,7 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data)
|
||||||
currentMesh->fogIntensity = ph.LightModifier();
|
currentMesh->fogIntensity = ph.LightModifier();
|
||||||
|
|
||||||
if (ph.TexEnabled()) {
|
if (ph.TexEnabled()) {
|
||||||
currentMesh->format = ph.TexFormat();
|
currentMesh->format = m_texSheet.GetTexFormat(ph.TexFormat(), ph.AlphaTest());
|
||||||
currentMesh->x = ph.X();
|
currentMesh->x = ph.X();
|
||||||
currentMesh->y = ph.Y();
|
currentMesh->y = ph.Y();
|
||||||
currentMesh->width = ph.TexWidth();
|
currentMesh->width = ph.TexWidth();
|
||||||
|
|
|
@ -81,7 +81,7 @@ UINT32 Texture::UploadTexture(const UINT16* src, UINT8* scratch, int format, boo
|
||||||
|
|
||||||
switch (format)
|
switch (format)
|
||||||
{
|
{
|
||||||
default: // Debug texture, use TEXTURE_DEBUG mask
|
default: // Debug texture
|
||||||
for (yi = y; yi < (y + height); yi++)
|
for (yi = y; yi < (y + height); yi++)
|
||||||
{
|
{
|
||||||
for (xi = x; xi < (x + width); xi++)
|
for (xi = x; xi < (x + width); xi++)
|
||||||
|
@ -213,10 +213,73 @@ UINT32 Texture::UploadTexture(const UINT16* src, UINT8* scratch, int format, boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
//
|
||||||
|
// 4 bit texture types - all luminance textures (no alpha), only seem to be enabled when contour is enabled
|
||||||
|
//
|
||||||
|
|
||||||
|
case 8: // low byte, low nibble
|
||||||
|
for (yi = y; yi < (y + height); yi++)
|
||||||
|
{
|
||||||
|
for (xi = x; xi < (x + width); xi++)
|
||||||
|
{
|
||||||
|
texel = src[yi * 2048 + xi] & 0xFF;
|
||||||
|
c = (texel & 0xF) * 17;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = (c == 255 ? 0 : 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 9: // low byte, high nibble
|
||||||
|
for (yi = y; yi < (y + height); yi++)
|
||||||
|
{
|
||||||
|
for (xi = x; xi < (x + width); xi++)
|
||||||
|
{
|
||||||
|
texel = src[yi * 2048 + xi] & 0xFF;
|
||||||
|
c = ((texel >> 4) & 0xF) * 17;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = (c == 255 ? 0 : 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 10: // high byte, low nibble
|
||||||
|
for (yi = y; yi < (y + height); yi++)
|
||||||
|
{
|
||||||
|
for (xi = x; xi < (x + width); xi++)
|
||||||
|
{
|
||||||
|
texel = src[yi * 2048 + xi] >> 8;
|
||||||
|
c = (texel & 0xF) * 17;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = (c == 255 ? 0 : 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 11: // high byte, high nibble
|
||||||
|
|
||||||
|
for (yi = y; yi < (y + height); yi++)
|
||||||
|
{
|
||||||
|
for (xi = x; xi < (x + width); xi++)
|
||||||
|
{
|
||||||
|
texel = src[yi * 2048 + xi] >> 8;
|
||||||
|
c = ((texel >> 4) & 0xF) * 17;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = c;
|
||||||
|
scratch[i++] = (c == 255 ? 0 : 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
//remove debug mask
|
|
||||||
format &= 7;
|
|
||||||
|
|
||||||
GLfloat maxAnistrophy;
|
GLfloat maxAnistrophy;
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,6 @@
|
||||||
|
|
||||||
namespace New3D {
|
namespace New3D {
|
||||||
|
|
||||||
#define TEXTURE_DEBUG 0x8
|
|
||||||
#define TEXTURE_DEBUG_MASK 0x7
|
|
||||||
|
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -31,14 +31,14 @@ std::shared_ptr<Texture> TextureSheet::BindTexture(const UINT16* src, int format
|
||||||
|
|
||||||
index = ToIndex(x, y);
|
index = ToIndex(x, y);
|
||||||
|
|
||||||
auto range = m_texMap[format&TEXTURE_DEBUG_MASK].equal_range(index);
|
auto range = m_texMap[format].equal_range(index);
|
||||||
|
|
||||||
if (range.first == range.second) {
|
if (range.first == range.second) {
|
||||||
|
|
||||||
// nothing found so create a new texture
|
// nothing found so create a new texture
|
||||||
|
|
||||||
std::shared_ptr<Texture> t(new Texture());
|
std::shared_ptr<Texture> t(new Texture());
|
||||||
m_texMap[format&TEXTURE_DEBUG_MASK].insert(std::pair<int, std::shared_ptr<Texture>>(index, t));
|
m_texMap[format].insert(std::pair<int, std::shared_ptr<Texture>>(index, t));
|
||||||
t->UploadTexture(src, m_temp.data(), format, mirrorU, mirrorV, x, y, width, height);
|
t->UploadTexture(src, m_temp.data(), format, mirrorU, mirrorV, x, y, width, height);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ std::shared_ptr<Texture> TextureSheet::BindTexture(const UINT16* src, int format
|
||||||
// nothing found so create a new entry
|
// nothing found so create a new entry
|
||||||
|
|
||||||
std::shared_ptr<Texture> t(new Texture());
|
std::shared_ptr<Texture> t(new Texture());
|
||||||
m_texMap[format&TEXTURE_DEBUG_MASK].insert(std::pair<int, std::shared_ptr<Texture>>(index, t));
|
m_texMap[format].insert(std::pair<int, std::shared_ptr<Texture>>(index, t));
|
||||||
t->UploadTexture(src, m_temp.data(), format, mirrorU, mirrorV, x, y, width, height);
|
t->UploadTexture(src, m_temp.data(), format, mirrorU, mirrorV, x, y, width, height);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,7 @@ std::shared_ptr<Texture> TextureSheet::BindTexture(const UINT16* src, int format
|
||||||
|
|
||||||
void TextureSheet::Release()
|
void TextureSheet::Release()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 12; i++) {
|
||||||
m_texMap[i].clear();
|
m_texMap[i].clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ void TextureSheet::Invalidate(int x, int y, int width, int height)
|
||||||
|
|
||||||
int index = ToIndex(x + ((i%sWidth) * 32), y + ((i / sWidth) * 32));
|
int index = ToIndex(x + ((i%sWidth) * 32), y + ((i / sWidth) * 32));
|
||||||
|
|
||||||
for (int j = 0; j<8; j++) {
|
for (int j = 0; j<12; j++) {
|
||||||
|
|
||||||
if (m_texMap[j].count(index) > 0) {
|
if (m_texMap[j].count(index) > 0) {
|
||||||
|
|
||||||
|
@ -102,4 +102,22 @@ void TextureSheet::Invalidate(int x, int y, int width, int height)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int TextureSheet::GetTexFormat(int originalFormat, bool contour)
|
||||||
|
{
|
||||||
|
if (!contour) {
|
||||||
|
return originalFormat; // the same
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (originalFormat)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
case 2:
|
||||||
|
case 3:
|
||||||
|
case 4:
|
||||||
|
return originalFormat + 7; // these formats are identical to 1-4, except they lose the 4 bit alpha part when contour is enabled
|
||||||
|
default:
|
||||||
|
return originalFormat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // New3D
|
} // New3D
|
||||||
|
|
|
@ -20,12 +20,13 @@ public:
|
||||||
std::shared_ptr<Texture> BindTexture (const UINT16* src, int format, bool mirrorU, bool mirrorV, int x, int y, int width, int height);
|
std::shared_ptr<Texture> BindTexture (const UINT16* src, int format, bool mirrorU, bool mirrorV, int x, int y, int width, int height);
|
||||||
void Invalidate (int x, int y, int width, int height); // release parts of the memory
|
void Invalidate (int x, int y, int width, int height); // release parts of the memory
|
||||||
void Release (); // release all texture objects and memory
|
void Release (); // release all texture objects and memory
|
||||||
|
int GetTexFormat (int originalFormat, bool contour);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
int ToIndex(int x, int y);
|
int ToIndex(int x, int y);
|
||||||
|
|
||||||
std::unordered_multimap<int, std::shared_ptr<Texture>> m_texMap[8];
|
std::unordered_multimap<int, std::shared_ptr<Texture>> m_texMap[12];
|
||||||
|
|
||||||
// the key for the above maps is the x/y position in the 2048x2048 texture
|
// the key for the above maps is the x/y position in the 2048x2048 texture
|
||||||
// array of 8 planes for each texture type
|
// array of 8 planes for each texture type
|
||||||
|
|
Loading…
Reference in a new issue