mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-16 18:01:40 +00:00
Improve texture creation logging and checking
This commit is contained in:
parent
ae97435d80
commit
b1cb5fcb9f
6 changed files with 37 additions and 19 deletions
|
@ -119,6 +119,11 @@ const c8 *const ColorFormatNames[] = {
|
||||||
static_assert(sizeof(ColorFormatNames) / sizeof(ColorFormatNames[0])
|
static_assert(sizeof(ColorFormatNames) / sizeof(ColorFormatNames[0])
|
||||||
== ECF_UNKNOWN + 2, "name table size mismatch");
|
== ECF_UNKNOWN + 2, "name table size mismatch");
|
||||||
|
|
||||||
|
inline const c8 *ColorFormatName(ECOLOR_FORMAT format)
|
||||||
|
{
|
||||||
|
return ColorFormatNames[format < ECF_UNKNOWN ? format : ECF_UNKNOWN];
|
||||||
|
}
|
||||||
|
|
||||||
//! Creates a 16 bit A1R5G5B5 color
|
//! Creates a 16 bit A1R5G5B5 color
|
||||||
inline u16 RGBA16(u32 r, u32 g, u32 b, u32 a = 0xFF)
|
inline u16 RGBA16(u32 r, u32 g, u32 b, u32 a = 0xFF)
|
||||||
{
|
{
|
||||||
|
|
|
@ -56,15 +56,18 @@ public:
|
||||||
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
HasMipMaps = Driver->getTextureCreationFlag(ETCF_CREATE_MIP_MAPS);
|
||||||
KeepImage = Driver->getTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY);
|
KeepImage = Driver->getTextureCreationFlag(ETCF_ALLOW_MEMORY_COPY);
|
||||||
|
|
||||||
|
if (!name.empty())
|
||||||
|
os::Printer::log("COpenGLCoreTexture: name", name.c_str(), ELL_DEBUG);
|
||||||
|
|
||||||
getImageValues(srcImages[0]);
|
getImageValues(srcImages[0]);
|
||||||
if (!InternalFormat)
|
if (!InternalFormat)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
char lbuf[128];
|
char lbuf[128];
|
||||||
snprintf_irr(lbuf, sizeof(lbuf),
|
snprintf_irr(lbuf, sizeof(lbuf),
|
||||||
"COpenGLCoreTexture: Type = %d Size = %dx%d (%dx%d) ColorFormat = %d (%d)%s -> %#06x %#06x %#06x%s",
|
"COpenGLCoreTexture: Type = %d Size = %dx%d (%dx%d) ColorFormat = %s (%s)%s -> %#06x %#06x %#06x%s",
|
||||||
(int)Type, Size.Width, Size.Height, OriginalSize.Width, OriginalSize.Height,
|
(int)Type, Size.Width, Size.Height, OriginalSize.Width, OriginalSize.Height,
|
||||||
(int)ColorFormat, (int)OriginalColorFormat,
|
ColorFormatName(ColorFormat), ColorFormatName(OriginalColorFormat),
|
||||||
HasMipMaps ? " +Mip" : "",
|
HasMipMaps ? " +Mip" : "",
|
||||||
InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : ""
|
InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : ""
|
||||||
);
|
);
|
||||||
|
@ -147,6 +150,9 @@ public:
|
||||||
HasMipMaps = false;
|
HasMipMaps = false;
|
||||||
IsRenderTarget = true;
|
IsRenderTarget = true;
|
||||||
|
|
||||||
|
if (!name.empty())
|
||||||
|
os::Printer::log("COpenGLCoreTexture: name", name.c_str(), ELL_DEBUG);
|
||||||
|
|
||||||
OriginalColorFormat = format;
|
OriginalColorFormat = format;
|
||||||
|
|
||||||
if (ECF_UNKNOWN == OriginalColorFormat)
|
if (ECF_UNKNOWN == OriginalColorFormat)
|
||||||
|
@ -157,10 +163,17 @@ public:
|
||||||
OriginalSize = size;
|
OriginalSize = size;
|
||||||
Size = OriginalSize;
|
Size = OriginalSize;
|
||||||
|
|
||||||
|
if (Size.Width == 0 || Size.Height == 0) {
|
||||||
|
char buf[64];
|
||||||
|
snprintf_irr(buf, sizeof(buf), "%dx%d", Size.Width, Size.Height);
|
||||||
|
os::Printer::log("Invalid size for render target", buf, ELL_ERROR);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
|
Pitch = Size.Width * IImage::getBitsPerPixelFromFormat(ColorFormat) / 8;
|
||||||
|
|
||||||
if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) {
|
if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) {
|
||||||
os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR);
|
os::Printer::log("COpenGLCoreTexture: Color format is not supported", ColorFormatName(ColorFormat), ELL_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +189,8 @@ public:
|
||||||
|
|
||||||
char lbuf[100];
|
char lbuf[100];
|
||||||
snprintf_irr(lbuf, sizeof(lbuf),
|
snprintf_irr(lbuf, sizeof(lbuf),
|
||||||
"COpenGLCoreTexture: RTT Type = %d Size = %dx%d ColorFormat = %d -> %#06x %#06x %#06x%s",
|
"COpenGLCoreTexture: RTT Type = %d Size = %dx%d (S:%d) ColorFormat = %s -> %#06x %#06x %#06x%s",
|
||||||
(int)Type, Size.Width, Size.Height, (int)ColorFormat,
|
(int)Type, Size.Width, Size.Height, (int)MSAA, ColorFormatName(ColorFormat),
|
||||||
InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : ""
|
InternalFormat, PixelFormat, PixelType, Converter ? " (c)" : ""
|
||||||
);
|
);
|
||||||
os::Printer::log(lbuf, ELL_DEBUG);
|
os::Printer::log(lbuf, ELL_DEBUG);
|
||||||
|
@ -458,7 +471,7 @@ protected:
|
||||||
ColorFormat = getBestColorFormat(OriginalColorFormat);
|
ColorFormat = getBestColorFormat(OriginalColorFormat);
|
||||||
|
|
||||||
if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) {
|
if (!Driver->getColorFormatParameters(ColorFormat, InternalFormat, PixelFormat, PixelType, &Converter)) {
|
||||||
os::Printer::log("getImageValues: Color format is not supported", ColorFormatNames[ColorFormat < ECF_UNKNOWN ? ColorFormat : ECF_UNKNOWN], ELL_ERROR);
|
os::Printer::log("getImageValues: Color format is not supported", ColorFormatName(ColorFormat), ELL_ERROR);
|
||||||
InternalFormat = 0;
|
InternalFormat = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -471,7 +484,9 @@ protected:
|
||||||
Size = OriginalSize;
|
Size = OriginalSize;
|
||||||
|
|
||||||
if (Size.Width == 0 || Size.Height == 0) {
|
if (Size.Width == 0 || Size.Height == 0) {
|
||||||
os::Printer::log("Invalid size of image for texture.", ELL_ERROR);
|
char buf[64];
|
||||||
|
snprintf_irr(buf, sizeof(buf), "%dx%d", Size.Width, Size.Height);
|
||||||
|
os::Printer::log("Invalid size of image for texture", buf, ELL_ERROR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,6 +535,7 @@ protected:
|
||||||
if (HasMipMaps) {
|
if (HasMipMaps) {
|
||||||
levels = core::u32_log2(core::max_(Size.Width, Size.Height)) + 1;
|
levels = core::u32_log2(core::max_(Size.Width, Size.Height)) + 1;
|
||||||
}
|
}
|
||||||
|
assert(levels > 0);
|
||||||
|
|
||||||
// reference: <https://www.khronos.org/opengl/wiki/Texture_Storage>
|
// reference: <https://www.khronos.org/opengl/wiki/Texture_Storage>
|
||||||
bool use_tex_storage = Driver->getFeature().TexStorage;
|
bool use_tex_storage = Driver->getFeature().TexStorage;
|
||||||
|
@ -543,7 +559,7 @@ protected:
|
||||||
TEST_GL_ERROR(Driver);
|
TEST_GL_ERROR(Driver);
|
||||||
break;
|
break;
|
||||||
case ETT_2D_MS: {
|
case ETT_2D_MS: {
|
||||||
GLint max_samples = 0;
|
GLint max_samples = 1;
|
||||||
GL.GetIntegerv(GL_MAX_SAMPLES, &max_samples);
|
GL.GetIntegerv(GL_MAX_SAMPLES, &max_samples);
|
||||||
MSAA = core::min_(MSAA, (u8)max_samples);
|
MSAA = core::min_(MSAA, (u8)max_samples);
|
||||||
|
|
||||||
|
@ -663,7 +679,8 @@ protected:
|
||||||
return GL_TEXTURE_2D_ARRAY;
|
return GL_TEXTURE_2D_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
os::Printer::log("COpenGLCoreTexture::TextureTypeIrrToGL unknown texture type", ELL_WARNING);
|
auto s = std::to_string(type);
|
||||||
|
os::Printer::log("COpenGLCoreTexture: unknown texture type", s.c_str(), ELL_WARNING);
|
||||||
return GL_TEXTURE_2D;
|
return GL_TEXTURE_2D;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1597,6 +1597,7 @@ inline void COpenGLDriver::getGLTextureMatrix(GLfloat *o, const core::matrix4 &m
|
||||||
|
|
||||||
ITexture *COpenGLDriver::createDeviceDependentTexture(const io::path &name, E_TEXTURE_TYPE type, const std::vector<IImage*> &images)
|
ITexture *COpenGLDriver::createDeviceDependentTexture(const io::path &name, E_TEXTURE_TYPE type, const std::vector<IImage*> &images)
|
||||||
{
|
{
|
||||||
|
assert(type == ETT_2D);
|
||||||
return new COpenGLTexture(name, images, ETT_2D, this);
|
return new COpenGLTexture(name, images, ETT_2D, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -278,9 +278,6 @@ bool COpenGL3DriverBase::genericDriverInit(const core::dimension2d<u32> &screenS
|
||||||
// set fog mode
|
// set fog mode
|
||||||
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
|
setFog(FogColor, FogType, FogStart, FogEnd, FogDensity, PixelFog, RangeFog);
|
||||||
|
|
||||||
// create matrix for flipping textures
|
|
||||||
TextureFlipMatrix.buildTextureTransform(0.0f, core::vector2df(0, 0), core::vector2df(0, 1.0f), core::vector2df(1.0f, -1.0f));
|
|
||||||
|
|
||||||
// We need to reset once more at the beginning of the first rendering.
|
// We need to reset once more at the beginning of the first rendering.
|
||||||
// This fixes problems with intermediate changes to the material during texture load.
|
// This fixes problems with intermediate changes to the material during texture load.
|
||||||
ResetRenderStates = true;
|
ResetRenderStates = true;
|
||||||
|
|
|
@ -324,15 +324,13 @@ protected:
|
||||||
bool LockRenderStateMode;
|
bool LockRenderStateMode;
|
||||||
u8 AntiAlias;
|
u8 AntiAlias;
|
||||||
|
|
||||||
core::matrix4 TextureFlipMatrix;
|
|
||||||
|
|
||||||
using FColorConverter = void (*)(const void *source, s32 count, void *dest);
|
using FColorConverter = void (*)(const void *source, s32 count, void *dest);
|
||||||
struct STextureFormatInfo
|
struct STextureFormatInfo
|
||||||
{
|
{
|
||||||
GLenum InternalFormat;
|
GLenum InternalFormat = 0;
|
||||||
GLenum PixelFormat;
|
GLenum PixelFormat = 0;
|
||||||
GLenum PixelType;
|
GLenum PixelType = 0;
|
||||||
FColorConverter Converter;
|
FColorConverter Converter = nullptr;
|
||||||
};
|
};
|
||||||
STextureFormatInfo TextureFormats[ECF_UNKNOWN] = {};
|
STextureFormatInfo TextureFormats[ECF_UNKNOWN] = {};
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ bool TextureBuffer::ensureTexture(video::ITexture **texture, const TextureDefini
|
||||||
if (definition.valid) {
|
if (definition.valid) {
|
||||||
if (!m_driver->queryTextureFormat(definition.format)) {
|
if (!m_driver->queryTextureFormat(definition.format)) {
|
||||||
errorstream << "Failed to create texture \"" << definition.name
|
errorstream << "Failed to create texture \"" << definition.name
|
||||||
<< "\": unsupported format " << video::ColorFormatNames[definition.format]
|
<< "\": unsupported format " << video::ColorFormatName(definition.format)
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue