Check texture color formats available

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
stefbuet
Competition winner
Posts: 495
Joined: Sun Dec 09, 2007 4:13 pm
Location: france

Check texture color formats available

Post by stefbuet »

This will allow you to know whether a color format is supported or not by your GPU, with OpenGL. (DirectX not handled here).
This is an Irrlicht lib modification.

------------------------------------

Changelog:

1/ I needed the getOpenGLFormatAndParametersFromColorFormat method from COpenGLTexture (sources) but it was protected so I moved it from protected to public.

2/ Add to IVideoDriver.hpp (includes) as public:

Code: Select all

//! queries the floating point texture color format support, returns true if supported
		virtual bool queryRTTColorFormat(ECOLOR_FORMAT colorFormat)=0;
3/ Add to CNullDriver.h (sources) as public:

Code: Select all

//! queries the floating point texture color format support, returns true if supported
		bool queryRTTColorFormat(ECOLOR_FORMAT colorFormat);
4/ I didn't know how to do this with directX, so this feature is openGL only.
Add to CNullDriver.cpp (sources) :

Code: Select all

//! queries the floating point texture color format support, returns true if supported
bool CNullDriver::queryRTTColorFormat(ECOLOR_FORMAT colorFormat)
{
   return false;
}
5/ Add to COpenGLDriver.h (sources) as public:

Code: Select all

//! queries the floating point texture color format support, returns true if supported
		virtual bool queryRTTColorFormat(ECOLOR_FORMAT colorFormat);
6/ Add to COpenGLDriver.cpp (sources):

Code: Select all

//! queries the floating point texture color format support, returns true if supported
bool COpenGLDriver::queryRTTColorFormat(ECOLOR_FORMAT colorFormat)
{
    GLenum colorFormatGL, typeGL;
    GLint filtering;
    COpenGLTexture *proxy=(COpenGLTexture*)addTexture(core::dimension2d<u32>(1,1), L"proxy_text");
    if(!proxy) return false;
    GLint internalFormatGL=proxy->getOpenGLFormatAndParametersFromColorFormat(colorFormat, filtering, colorFormatGL, typeGL);
    glTexImage2D(GL_PROXY_TEXTURE_2D, 0, internalFormatGL, 256, 256, 0, colorFormatGL, typeGL, 0);
    removeTexture(proxy);
    return (glGetError()==GL_NO_ERROR)
     

}
-----------------------------------------------

Usage:

Code: Select all

//check if ECF_A16B16G16R16F is supported by the current GPU
std::cout<<"ARGB 16 bits supported?  --> "<<driver->queryRTTColorFormat(ECF_A16B16G16R16F)<<std::endl;
Note : the protected to public method from OGLTexture is a little bit annoying but I didn't find anything else to do...
Post Reply