Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

code_evo

Easiest way to check if extension exists?

This topic is 5210 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, is there a function or glGetxxxx i should be using or shall I just check if the function pointer is null? Thanks, /jeff

Share this post


Link to post
Share on other sites
Advertisement

Also, is there a way to check for cube mapping availability? Since its not an extension in the typical sense (no function pointers only defines) how can I check?

Thanks.

Share this post


Link to post
Share on other sites

//////////////////////////////////// EXTENSION DETECT /////////////////////////////////*


// Based Off Of Code Supplied At OpenGL.org

bool IsExtensionSupported( char* szTargetExtension )
{
const unsigned char *pszExtensions = NULL;
const unsigned char *pszStart;
unsigned char *pszWhere, *pszTerminator;

// Extension names should not have spaces

pszWhere = (unsigned char *) strchr( szTargetExtension, '' '' );
if( pszWhere || *szTargetExtension == ''\0'' )
return false;

// Get Extensions String

pszExtensions = glGetString( GL_EXTENSIONS );

// Search The Extensions String For An Exact Copy

pszStart = pszExtensions;
for(;;)
{
pszWhere = (unsigned char *) strstr( (const char *) pszStart, szTargetExtension );
if( !pszWhere )
break;
pszTerminator = pszWhere + strlen( szTargetExtension );
if( pszWhere == pszStart || *( pszWhere - 1 ) == '' '' )
if( *pszTerminator == '' '' || *pszTerminator == ''\0'' )
return true;
pszStart = pszTerminator;
}
return false;
}

Share this post


Link to post
Share on other sites

#include <string>

bool IsExtensionSupported( const std::string& TargetExtension )
{
const std::string Extensions = glGetString( GL_EXTENSIONS );
return Extensions.find( TargetExtension ) != std::string::npos;
}





“Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.”
— Brian W. Kernighan

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
#include <string>

bool IsExtensionSupported( const std::string& TargetExtension )
{
const std::string Extensions = glGetString( GL_EXTENSIONS );
return Extensions.find( TargetExtension ) != std::string::npos;
}



Technically, that SHOULD be implemented with a pass by value, not reference, so that you can do a

TargetExtension += " ";

beforehand, to make sure you don''t get a false positive on GL_SOM_EXT when GL_SOME_EXTENTION is present.

nitpick.

Share this post


Link to post
Share on other sites
quote:
Original post by C-Junkie
quote:
Original post by Fruny
#include <string>

bool IsExtensionSupported( const std::string& TargetExtension )
{
const std::string Extensions = glGetString( GL_EXTENSIONS );
return Extensions.find( TargetExtension ) != std::string::npos;
}



Technically, that SHOULD be implemented with a pass by value, not reference, so that you can do a

TargetExtension += " ";

beforehand, to make sure you don''t get a false positive on GL_SOM_EXT when GL_SOME_EXTENTION is present.

nitpick.




wich would mean the last extension could never get queried.. as it ends with \0, not with '' ''




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net

Share this post


Link to post
Share on other sites
quote:
Original post by davepermen
wich would mean the last extension could never get queried.. as it ends with \0, not with '' ''


Doh!

Share this post


Link to post
Share on other sites

bool isExtensionSupported(const std::string &extension)
{
boost::tokenizer extensions(glGetString(GL_EXTENSIONS));
return std::find(extensions.begin(), extensions.end(), extension) != extensions.end();
}



"Sneftel is correct, if rather vulgar." --Flarelocke

[edited by - sneftel on April 16, 2004 3:01:49 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!