mirror of https://github.com/AxioDL/boo.git
better OpenGL mipmap configuration
This commit is contained in:
parent
e9bd443e49
commit
77e9492b43
|
@ -267,12 +267,16 @@ class GraphicsDataToken
|
||||||
IGraphicsData* m_data = nullptr;
|
IGraphicsData* m_data = nullptr;
|
||||||
GraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data)
|
GraphicsDataToken(IGraphicsDataFactory* factory, IGraphicsData* data)
|
||||||
: m_factory(factory), m_data(data) {}
|
: m_factory(factory), m_data(data) {}
|
||||||
|
public:
|
||||||
void doDestroy()
|
void doDestroy()
|
||||||
{
|
{
|
||||||
if (m_factory && m_data)
|
if (m_factory && m_data)
|
||||||
|
{
|
||||||
m_factory->destroyData(m_data);
|
m_factory->destroyData(m_data);
|
||||||
|
m_factory = nullptr;
|
||||||
|
m_data = nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public:
|
|
||||||
GraphicsDataToken() = default;
|
GraphicsDataToken() = default;
|
||||||
GraphicsDataToken(const GraphicsDataToken& other) = delete;
|
GraphicsDataToken(const GraphicsDataToken& other) = delete;
|
||||||
GraphicsDataToken(GraphicsDataToken&& other)
|
GraphicsDataToken(GraphicsDataToken&& other)
|
||||||
|
|
|
@ -43,8 +43,9 @@ public:
|
||||||
|
|
||||||
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
||||||
const void* data, size_t sz);
|
const void* data, size_t sz);
|
||||||
ITextureS* newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
GraphicsDataToken
|
||||||
std::unique_ptr<uint8_t[]>&& data, size_t sz);
|
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,
|
ITextureSA* newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
|
||||||
const void* data, size_t sz);
|
const void* data, size_t sz);
|
||||||
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);
|
ITextureD* newDynamicTexture(size_t width, size_t height, TextureFormat fmt);
|
||||||
|
|
|
@ -127,7 +127,10 @@ class GLTextureS : public ITextureS
|
||||||
glBindTexture(GL_TEXTURE_2D, m_tex);
|
glBindTexture(GL_TEXTURE_2D, m_tex);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
if (mips > 1)
|
if (mips > 1)
|
||||||
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mips-1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
|
||||||
|
@ -147,7 +150,7 @@ class GLTextureS : public ITextureS
|
||||||
pxPitch = 1;
|
pxPitch = 1;
|
||||||
break;
|
break;
|
||||||
case TextureFormat::DXT1:
|
case TextureFormat::DXT1:
|
||||||
intFormat = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
|
intFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
|
||||||
compressed = true;
|
compressed = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -85,13 +85,18 @@ class MetalTextureS : public ITextureS
|
||||||
TextureFormat fmt, const void* data, size_t sz)
|
TextureFormat fmt, const void* data, size_t sz)
|
||||||
{
|
{
|
||||||
MTLPixelFormat pfmt = MTLPixelFormatRGBA8Unorm;
|
MTLPixelFormat pfmt = MTLPixelFormatRGBA8Unorm;
|
||||||
NSUInteger ppitch = 4;
|
NSUInteger ppitchNum = 4;
|
||||||
|
NSUInteger ppitchDenom = 1;
|
||||||
switch (fmt)
|
switch (fmt)
|
||||||
{
|
{
|
||||||
case TextureFormat::I8:
|
case TextureFormat::I8:
|
||||||
pfmt = MTLPixelFormatR8Unorm;
|
pfmt = MTLPixelFormatR8Unorm;
|
||||||
ppitch = 1;
|
ppitchNum = 1;
|
||||||
break;
|
break;
|
||||||
|
case TextureFormat::DXT1:
|
||||||
|
pfmt = MTLPixelFormatBC1_RGBA;
|
||||||
|
ppitchNum = 1;
|
||||||
|
ppitchDenom = 2;
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +115,8 @@ class MetalTextureS : public ITextureS
|
||||||
[m_tex replaceRegion:MTLRegionMake2D(0, 0, width, height)
|
[m_tex replaceRegion:MTLRegionMake2D(0, 0, width, height)
|
||||||
mipmapLevel:i
|
mipmapLevel:i
|
||||||
withBytes:dataIt
|
withBytes:dataIt
|
||||||
bytesPerRow:width * ppitch];
|
bytesPerRow:width * ppitchNum / ppitchDenom];
|
||||||
dataIt += width * height * ppitch;
|
dataIt += width * height * ppitchNum / ppitchDenom;
|
||||||
width /= 2;
|
width /= 2;
|
||||||
height /= 2;
|
height /= 2;
|
||||||
}
|
}
|
||||||
|
@ -873,15 +878,18 @@ ITextureS* MetalDataFactory::newStaticTexture(size_t width, size_t height, size_
|
||||||
m_deferredData->m_STexs.emplace_back(retval);
|
m_deferredData->m_STexs.emplace_back(retval);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
ITextureS* MetalDataFactory::newStaticTexture(size_t width, size_t height, size_t mips, TextureFormat fmt,
|
GraphicsDataToken
|
||||||
std::unique_ptr<uint8_t[]>&& data, size_t sz)
|
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, data, sz);
|
||||||
MetalTextureS* retval = new MetalTextureS(m_ctx, width, height, mips, fmt, d.get(), sz);
|
MetalData* tokData = new struct MetalData();
|
||||||
if (!m_deferredData.get())
|
tokData->m_STexs.emplace_back(retval);
|
||||||
m_deferredData.reset(new struct MetalData());
|
*texOut = retval;
|
||||||
m_deferredData->m_STexs.emplace_back(retval);
|
|
||||||
return 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,
|
ITextureSA* MetalDataFactory::newStaticArrayTexture(size_t width, size_t height, size_t layers, TextureFormat fmt,
|
||||||
const void* data, size_t sz)
|
const void* data, size_t sz)
|
||||||
|
|
Loading…
Reference in New Issue