-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglextension.cpp
60 lines (50 loc) · 1.68 KB
/
glextension.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "GLExtensions.hpp"
#include "afroCurlException.hpp"
namespace afroCurl
{
PFNGLGENBUFFERSPROC GLExt::glGenBuffers = 0;
PFNGLBINDBUFFERARBPROC GLExt::glBindBuffer = 0;
PFNGLBUFFERDATAARBPROC GLExt::glBufferData = 0;
PFNGLDELETEBUFFERSARBPROC GLExt::glDeleteBuffers = 0;
bool GLExt::mIsInited = false;
void GLExt::init()
{
if ( !checkExtension("GL_ARB_vertex_buffer_object") )
{
throw afroCurlException(" GLExt::init : extension \"GL_ARB_vertex_buffer_object\" is not available ");
}
glGenBuffers = reinterpret_cast< PFNGLGENBUFFERSPROC >( wglGetProcAddress("glGenBuffersARB") );
glBindBuffer = reinterpret_cast< PFNGLBINDBUFFERARBPROC >( wglGetProcAddress("glBindBufferARB") );
glBufferData = reinterpret_cast< PFNGLBUFFERDATAARBPROC >( wglGetProcAddress("glBufferDataARB") );
glDeleteBuffers = reinterpret_cast< PFNGLDELETEBUFFERSARBPROC >( wglGetProcAddress("glDeleteBuffersARB") );
mIsInited = true;
}
bool GLExt::checkExtension( const char *aExtensionName )
{
// Get ext. name length
size_t extNameLen = strlen( aExtensionName ), n = 0;
// Get extensions list
const char * p = (const char *) glGetString( GL_EXTENSIONS );
if ( p == 0 )
{
throw afroCurlException(" GLExt::checkExtension : no extensions are available ");
}
// End of extensions list, iterator
const char * end = p + strlen( p ), * i;
// For all extensions
while ( p < end )
{
// Get next extension position
for ( i = p; *i != ' ' && i < end; ++i );
n = i - p;
// Compare current ext. name with selected extension name
if ( ( extNameLen == n ) && ( strncmp( aExtensionName, p, n ) == 0 ) )
{
return true;
}
// Moves to next extension
p += n + 1;
}
return false;
}
} // namespace afroCurl