Easiest way to check if extension exists?

Started by
9 comments, last by code_evo 20 years ago
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
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.
glGetString( GL_EXTENSIONS ) will return a string of space separated extension names. Just check if the extension is in the list to determine if it''s available.

~nz

// Website // Google // GameDev // NeHe // MSDN // OpenGL Extensions //
~neoztar "Any lock can be picked with a big enough hammer"my website | opengl extensions | try here firstguru of the week | msdn library | c++ faq lite

sweet i forgot about that function
//////////////////////////////////// EXTENSION DETECT /////////////////////////////////*// Based Off Of Code Supplied At OpenGL.orgbool 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;}
#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
"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
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.

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
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

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

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

Doh!
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]

This topic is closed to new replies.

Advertisement