Implement queryTextureFormat for es1 and es2 drivers.

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/branches/ogl-es@5525 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2017-08-21 14:34:56 +00:00
parent f184d58cfe
commit 62ac2fd2e1
4 changed files with 85 additions and 11 deletions

View File

@ -2652,9 +2652,10 @@ COGLES2Driver::~COGLES2Driver()
return bits;
}
void COGLES2Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*))
bool COGLES2Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*)) const
{
bool supported = false;
pixelFormat = GL_RGBA;
pixelType = GL_UNSIGNED_BYTE;
*converter = 0;
@ -2662,19 +2663,23 @@ COGLES2Driver::~COGLES2Driver()
switch (format)
{
case ECF_A1R5G5B5:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_UNSIGNED_SHORT_5_5_5_1;
*converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1;
break;
case ECF_R5G6B5:
supported = true;
pixelFormat = GL_RGB;
pixelType = GL_UNSIGNED_SHORT_5_6_5;
break;
case ECF_R8G8B8:
supported = true;
pixelFormat = GL_RGB;
pixelType = GL_UNSIGNED_BYTE;
break;
case ECF_A8R8G8B8:
supported = true;
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_IMG_texture_format_BGRA8888) ||
queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_format_BGRA8888) ||
queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_APPLE_texture_format_BGRA8888))
@ -2690,6 +2695,7 @@ COGLES2Driver::~COGLES2Driver()
break;
#ifdef GL_EXT_texture_compression_s3tc
case ECF_DXT1:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
break;
@ -2697,6 +2703,7 @@ COGLES2Driver::~COGLES2Driver()
#ifdef GL_EXT_texture_compression_s3tc
case ECF_DXT2:
case ECF_DXT3:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
break;
@ -2704,65 +2711,76 @@ COGLES2Driver::~COGLES2Driver()
#ifdef GL_EXT_texture_compression_s3tc
case ECF_DXT4:
case ECF_DXT5:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
break;
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_RGB2:
supported = true;
pixelFormat = GL_RGB;
pixelType = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
break;
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_ARGB2:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
break;
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_RGB4:
supported = true;
pixelFormat = GL_RGB;
pixelType = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
break;
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_ARGB4:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
break;
#endif
#ifdef GL_IMG_texture_compression_pvrtc2
case ECF_PVRTC2_ARGB2:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG;
break;
#endif
#ifdef GL_IMG_texture_compression_pvrtc2
case ECF_PVRTC2_ARGB4:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG;
break;
#endif
#ifdef GL_OES_compressed_ETC1_RGB8_texture
case ECF_ETC1:
supported = true;
pixelFormat = GL_RGB;
pixelType = GL_ETC1_RGB8_OES;
break;
#endif
#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available
case ECF_ETC2_RGB:
supported = true;
pixelFormat = GL_RGB;
pixelType = GL_COMPRESSED_RGB8_ETC2;
break;
#endif
#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available
case ECF_ETC2_ARGB:
supported = true;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA8_ETC2_EAC;
break;
#endif
case ECF_D16:
supported = true;
pixelFormat = GL_DEPTH_COMPONENT;
pixelType = GL_UNSIGNED_SHORT;
break;
@ -2770,6 +2788,7 @@ COGLES2Driver::~COGLES2Driver()
#if defined(GL_OES_depth32)
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32))
{
supported = true;
pixelFormat = GL_DEPTH_COMPONENT;
pixelType = GL_UNSIGNED_INT;
}
@ -2781,6 +2800,7 @@ COGLES2Driver::~COGLES2Driver()
#ifdef GL_OES_packed_depth_stencil
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_packed_depth_stencil))
{
supported = true;
pixelFormat = GL_DEPTH_STENCIL_OES;
pixelType = GL_UNSIGNED_INT_24_8_OES;
}
@ -2791,6 +2811,7 @@ COGLES2Driver::~COGLES2Driver()
case ECF_R8:
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg))
{
supported = true;
pixelFormat = GL_RED_EXT;
pixelType = GL_UNSIGNED_BYTE;
}
@ -2801,6 +2822,7 @@ COGLES2Driver::~COGLES2Driver()
#if defined(GL_EXT_texture_rg)
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_rg))
{
supported = true;
pixelFormat = GL_RG_EXT;
pixelType = GL_UNSIGNED_BYTE;
}
@ -2820,6 +2842,7 @@ COGLES2Driver::~COGLES2Driver()
&& queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)
)
{
supported = true;
pixelFormat = GL_RED_EXT;
pixelType = GL_HALF_FLOAT_OES ;
}
@ -2833,6 +2856,7 @@ COGLES2Driver::~COGLES2Driver()
&& queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_half_float)
)
{
supported = true;
pixelFormat = GL_RG_EXT;
pixelType = GL_HALF_FLOAT_OES ;
}
@ -2849,6 +2873,7 @@ COGLES2Driver::~COGLES2Driver()
&& queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float)
)
{
supported = true;
pixelFormat = GL_RED_EXT;
pixelType = GL_FLOAT;
}
@ -2862,6 +2887,7 @@ COGLES2Driver::~COGLES2Driver()
&& queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_texture_float)
)
{
supported = true;
pixelFormat = GL_RG_EXT;
pixelType = GL_FLOAT;
}
@ -2887,6 +2913,17 @@ COGLES2Driver::~COGLES2Driver()
if (internalFormat == GL_BGRA)
internalFormat = GL_RGBA;
#endif
return supported;
}
bool COGLES2Driver::queryTextureFormat(ECOLOR_FORMAT format) const
{
GLint dummyInternalFormat;
GLenum dummyPixelFormat;
GLenum dummyPixelType;
void (*dummyConverter)(const void*, s32, void*);
return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter);
}
const SMaterial& COGLES2Driver::getCurrentMaterial() const

View File

@ -303,7 +303,10 @@ namespace video
return VendorName;
};
void removeTexture(ITexture* texture) _IRR_OVERRIDE_;
virtual void removeTexture(ITexture* texture) _IRR_OVERRIDE_;
//! Check if the driver supports creating textures with the given color format
virtual bool queryTextureFormat(ECOLOR_FORMAT format) const _IRR_OVERRIDE_;
//! Convert E_BLEND_FACTOR to OpenGL equivalent
GLenum getGLBlend(E_BLEND_FACTOR factor) const;
@ -311,8 +314,8 @@ namespace video
//! Get ZBuffer bits.
GLenum getZBufferBits() const;
void getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*));
bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*)) const;
//! Get current material.
const SMaterial& getCurrentMaterial() const;

View File

@ -3008,9 +3008,10 @@ GLenum COGLES1Driver::getZBufferBits() const
return bits;
}
void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*))
bool COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*)) const
{
bool supported = false;
internalFormat = GL_RGBA;
pixelFormat = GL_RGBA;
pixelType = GL_UNSIGNED_BYTE;
@ -3019,22 +3020,26 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
switch (format)
{
case ECF_A1R5G5B5:
supported = true;
internalFormat = GL_RGBA;
pixelFormat = GL_RGBA;
pixelType = GL_UNSIGNED_SHORT_5_5_5_1;
*converter = CColorConverter::convert_A1R5G5B5toR5G5B5A1;
break;
case ECF_R5G6B5:
supported = true;
internalFormat = GL_RGB;
pixelFormat = GL_RGB;
pixelType = GL_UNSIGNED_SHORT_5_6_5;
break;
case ECF_R8G8B8:
supported = true;
internalFormat = GL_RGB;
pixelFormat = GL_RGB;
pixelType = GL_UNSIGNED_BYTE;
break;
case ECF_A8R8G8B8:
supported = true;
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_IMG_texture_format_BGRA8888) ||
queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_EXT_texture_format_BGRA8888) ||
queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_APPLE_texture_format_BGRA8888))
@ -3052,6 +3057,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
break;
#ifdef GL_EXT_texture_compression_s3tc
case ECF_DXT1:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
@ -3060,6 +3066,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#ifdef GL_EXT_texture_compression_s3tc
case ECF_DXT2:
case ECF_DXT3:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
@ -3068,6 +3075,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#ifdef GL_EXT_texture_compression_s3tc
case ECF_DXT4:
case ECF_DXT5:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
@ -3075,6 +3083,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_RGB2:
supported = true;
internalFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
pixelFormat = GL_RGB;
pixelType = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
@ -3082,6 +3091,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_ARGB2:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
@ -3089,6 +3099,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_RGB4:
supported = true;
internalFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
pixelFormat = GL_RGB;
pixelType = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
@ -3096,6 +3107,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_IMG_texture_compression_pvrtc
case ECF_PVRTC_ARGB4:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
@ -3103,6 +3115,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_IMG_texture_compression_pvrtc2
case ECF_PVRTC2_ARGB2:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_2BPPV2_IMG;
@ -3110,6 +3123,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_IMG_texture_compression_pvrtc2
case ECF_PVRTC2_ARGB4:
supported = true;
internalFormat = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA_PVRTC_4BPPV2_IMG;
@ -3117,6 +3131,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_OES_compressed_ETC1_RGB8_texture
case ECF_ETC1:
supported = true;
internalFormat = GL_ETC1_RGB8_OES;
pixelFormat = GL_RGB;
pixelType = GL_ETC1_RGB8_OES;
@ -3124,6 +3139,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available
case ECF_ETC2_RGB:
supported = true;
internalFormat = GL_COMPRESSED_RGB8_ETC2;
pixelFormat = GL_RGB;
pixelType = GL_COMPRESSED_RGB8_ETC2;
@ -3131,12 +3147,14 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#endif
#ifdef GL_ES_VERSION_3_0 // TO-DO - fix when extension name will be available
case ECF_ETC2_ARGB:
supported = true;
internalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
pixelFormat = GL_RGBA;
pixelType = GL_COMPRESSED_RGBA8_ETC2_EAC;
break;
#endif
case ECF_D16:
supported = true;
internalFormat = GL_DEPTH_COMPONENT16;
pixelFormat = GL_DEPTH_COMPONENT;
pixelType = GL_UNSIGNED_SHORT;
@ -3145,6 +3163,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#if defined(GL_OES_depth32)
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_depth32))
{
supported = true;
internalFormat = GL_DEPTH_COMPONENT32_OES;
pixelFormat = GL_DEPTH_COMPONENT;
pixelType = GL_UNSIGNED_INT;
@ -3157,6 +3176,7 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
#ifdef GL_OES_packed_depth_stencil
if (queryOpenGLFeature(COGLESCoreExtensionHandler::IRR_GL_OES_packed_depth_stencil))
{
supported = true;
internalFormat = GL_DEPTH24_STENCIL8_OES;
pixelFormat = GL_DEPTH_STENCIL_OES;
pixelType = GL_UNSIGNED_INT_24_8_OES;
@ -3204,6 +3224,17 @@ void COGLES1Driver::getColorFormatParameters(ECOLOR_FORMAT format, GLint& intern
if (internalFormat == GL_BGRA)
internalFormat = GL_RGBA;
#endif
return supported;
}
bool COGLES1Driver::queryTextureFormat(ECOLOR_FORMAT format) const
{
GLint dummyInternalFormat;
GLenum dummyPixelFormat;
GLenum dummyPixelType;
void (*dummyConverter)(const void*, s32, void*);
return getColorFormatParameters(format, dummyInternalFormat, dummyPixelFormat, dummyPixelType, &dummyConverter);
}
COGLES1CacheHandler* COGLES1Driver::getCacheHandler() const

View File

@ -278,9 +278,12 @@ namespace video
}
//! Get the maximal texture size for this driver
core::dimension2du getMaxTextureSize() const _IRR_OVERRIDE_;
virtual core::dimension2du getMaxTextureSize() const _IRR_OVERRIDE_;
void removeTexture(ITexture* texture) _IRR_OVERRIDE_;
virtual void removeTexture(ITexture* texture) _IRR_OVERRIDE_;
//! Check if the driver supports creating textures with the given color format
virtual bool queryTextureFormat(ECOLOR_FORMAT format) const _IRR_OVERRIDE_;
//! Convert E_BLEND_FACTOR to OpenGL equivalent
GLenum getGLBlend(E_BLEND_FACTOR factor) const;
@ -288,8 +291,8 @@ namespace video
//! Get ZBuffer bits.
GLenum getZBufferBits() const;
void getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*));
bool getColorFormatParameters(ECOLOR_FORMAT format, GLint& internalFormat, GLenum& pixelFormat,
GLenum& pixelType, void(**converter)(const void*, s32, void*)) const;
COGLES1CacheHandler* getCacheHandler() const;