Improved Texture mipmap support
Former-commit-id: 0fc3e003a6524e5c026712a3dc695cf80817ea88
This commit is contained in:
parent
8ce5f879a8
commit
b01fad269e
|
|
@ -25,6 +25,9 @@ struct NzTextureImpl;
|
||||||
|
|
||||||
class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||||
{
|
{
|
||||||
|
friend class NzRenderer;
|
||||||
|
friend class NzRenderTexture;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NzTexture() = default;
|
NzTexture() = default;
|
||||||
explicit NzTexture(const NzImage& image);
|
explicit NzTexture(const NzImage& image);
|
||||||
|
|
@ -37,6 +40,8 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||||
|
|
||||||
bool EnableMipmapping(bool enable);
|
bool EnableMipmapping(bool enable);
|
||||||
|
|
||||||
|
void EnsureMipmapsUpdate() const;
|
||||||
|
|
||||||
nzUInt8 GetBytesPerPixel() const;
|
nzUInt8 GetBytesPerPixel() const;
|
||||||
unsigned int GetDepth() const;
|
unsigned int GetDepth() const;
|
||||||
nzPixelFormat GetFormat() const;
|
nzPixelFormat GetFormat() const;
|
||||||
|
|
@ -82,7 +87,6 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||||
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
|
bool UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRectui& rect, unsigned int srcWidth = 0, unsigned int srcHeight = 0, nzUInt8 level = 0);
|
||||||
|
|
||||||
// Fonctions OpenGL
|
// Fonctions OpenGL
|
||||||
bool Bind() const;
|
|
||||||
unsigned int GetOpenGLID() const;
|
unsigned int GetOpenGLID() const;
|
||||||
|
|
||||||
static unsigned int GetValidSize(unsigned int size);
|
static unsigned int GetValidSize(unsigned int size);
|
||||||
|
|
@ -91,6 +95,8 @@ class NAZARA_API NzTexture : public NzResource, NzNonCopyable
|
||||||
static bool IsTypeSupported(nzImageType type);
|
static bool IsTypeSupported(nzImageType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void InvalidateMipmaps();
|
||||||
|
|
||||||
NzTextureImpl* m_impl = nullptr;
|
NzTextureImpl* m_impl = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -398,6 +398,16 @@ bool NzTexture::EnableMipmapping(bool enable)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzTexture::EnsureMipmapsUpdate() const
|
||||||
|
{
|
||||||
|
if (m_impl->mipmapping && !m_impl->mipmapsUpdated)
|
||||||
|
{
|
||||||
|
NzOpenGL::BindTexture(m_impl->type, m_impl->id);
|
||||||
|
glGenerateMipmap(NzOpenGL::TextureTarget[m_impl->type]);
|
||||||
|
m_impl->mipmapsUpdated = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nzUInt8 NzTexture::GetBytesPerPixel() const
|
nzUInt8 NzTexture::GetBytesPerPixel() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
#if NAZARA_RENDERER_SAFE
|
||||||
|
|
@ -1224,19 +1234,6 @@ bool NzTexture::UpdateFace(nzCubemapFace face, const nzUInt8* pixels, const NzRe
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool NzTexture::Bind() const
|
|
||||||
{
|
|
||||||
NzOpenGL::BindTexture(m_impl->type, m_impl->id);
|
|
||||||
|
|
||||||
if (m_impl->mipmapping && !m_impl->mipmapsUpdated)
|
|
||||||
{
|
|
||||||
glGenerateMipmap(NzOpenGL::TextureTarget[m_impl->type]);
|
|
||||||
m_impl->mipmapsUpdated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int NzTexture::GetOpenGLID() const
|
unsigned int NzTexture::GetOpenGLID() const
|
||||||
{
|
{
|
||||||
#if NAZARA_RENDERER_SAFE
|
#if NAZARA_RENDERER_SAFE
|
||||||
|
|
@ -1372,3 +1369,16 @@ bool NzTexture::IsTypeSupported(nzImageType type)
|
||||||
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
|
NazaraError("Image type not handled (0x" + NzString::Number(type, 16) + ')');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NzTexture::InvalidateMipmaps()
|
||||||
|
{
|
||||||
|
#if NAZARA_RENDERER_SAFE
|
||||||
|
if (!m_impl)
|
||||||
|
{
|
||||||
|
NazaraInternalError("Texture must be valid");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
m_impl->mipmapsUpdated = false;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue