better OpenGL mipmap configuration

This commit is contained in:
Jack Andersen 2016-02-16 09:41:16 -10:00
parent e9bd443e49
commit 77e9492b43
4 changed files with 102 additions and 86 deletions

View File

@ -267,12 +267,16 @@ class GraphicsDataToken
IGraphicsData* m_data = nullptr;
GraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data)
: m_factory(factory), m_data(data) {}
public:
void doDestroy()
{
if (m_factory && m_data)
{
m_factory->destroyData(m_data);
m_factory = nullptr;
m_data = nullptr;
}
}
public:
GraphicsDataToken() = default;
GraphicsDataToken(const GraphicsDataToken& other) = delete;
GraphicsDataToken(GraphicsDataToken&& other)

View File

@ -43,8 +43,9 @@ public:
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz);
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
std::unique_ptr<uint8_t[]>&& data, size_t sz);
GraphicsDataToken
newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut);
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz);
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);

View File

@ -127,7 +127,10 @@ class GLTextureS : public ITextureS
glBindTexture(GL_TEXTURE_2D, m_tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
if (mips > 1)
{
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mips-1);
}
else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
@ -147,7 +150,7 @@ class GLTextureS : public ITextureS
pxPitch = 1;
break;
case TextureFormat::DXT1:
intFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
intFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
compressed = true;
break;
default:

View File

@ -85,13 +85,18 @@ class MetalTextureS : public ITextureS
TextureFormat fmt, const void* data, size_t sz)
{
MTLPixelFormat pfmt = MTLPixelFormatRGBA8Unorm;
NSUInteger ppitch = 4;
NSUInteger ppitchNum = 4;
NSUInteger ppitchDenom = 1;
switch (fmt)
{
case TextureFormat::I8:
pfmt = MTLPixelFormatR8Unorm;
ppitch = 1;
ppitchNum = 1;
break;
case TextureFormat::DXT1:
pfmt = MTLPixelFormatBC1_RGBA;
ppitchNum = 1;
ppitchDenom = 2;
default: break;
}
@ -110,8 +115,8 @@ class MetalTextureS : public ITextureS
[m_tex replaceRegion:MTLRegionMake2D(0, 0, width, height)
mipmapLevel:i
withBytes:dataIt
bytesPerRow:width * ppitch];
dataIt += width * height * ppitch;
bytesPerRow:width * ppitchNum / ppitchDenom];
dataIt += width * height * ppitchNum / ppitchDenom;
width /= 2;
height /= 2;
}
@ -873,15 +878,18 @@ ITextureS* MetalDataFactory::newStaticTexture(size_t width, size_t height, size_
m_deferredData->m_STexs.emplace_back(retval);
return retval;
}
ITextureS* MetalDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
std::unique_ptr<uint8_t[]>&& data, size_t sz)
GraphicsDataToken
MetalDataFactory::newStaticTextureNoContext(size_t width, size_t height, size_t mips, TextureFormat fmt,
const void* data, size_t sz, ITextureS** texOut)
{
std::unique_ptr<uint8_t[]> d = std::move(data);
MetalTextureS* retval = new MetalTextureS(m_ctx, width, height, mips, fmt, d.get(), sz);
if (!m_deferredData.get())
m_deferredData.reset(new struct MetalData());
m_deferredData->m_STexs.emplace_back(retval);
return retval;
MetalTextureS* retval = new MetalTextureS(m_ctx, width, height, mips, fmt, data, sz);
MetalData* tokData = new struct MetalData();
tokData->m_STexs.emplace_back(retval);
*texOut = retval;
std::unique_lock<std::mutex> lk(m_committedMutex);
m_committedData.insert(tokData);
return GraphicsDataToken(this, tokData);
}
ITextureSA* MetalDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
const void* data, size_t sz)