PageRenderTime 25ms CodeModel.GetById 18ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/xbmc/screensavers/rsxs-0.9/src/hyperspace/extensions.cc

http://github.com/xbmc/xbmc
C++ | 83 lines | 48 code | 12 blank | 23 comment | 10 complexity | a0d4c2116a3194eae368e3a60359d91b MD5 | raw file
 1/*
 2 * Really Slick XScreenSavers
 3 * Copyright (C) 2002-2006  Michael Chapman
 4 *
 5 * This program is free software; you can redistribute it and/or modify
 6 * it under the terms of the GNU General Public License version 2 as
 7 * published by the Free Software Foundation.
 8 *
 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 *
18 *****************************************************************************
19 *
20 * This is a Linux port of the Really Slick Screensavers,
21 * Copyright (C) 2005 Terence M. Welsh, available from www.reallyslick.com
22 */
23#include <common.hh>
24
25#include <extensions.hh>
26
27#if USE_GL_EXTENSIONS
28
29namespace Extensions {
30	PFNGLACTIVETEXTUREARBPROC glActiveTextureARB;
31	PFNGLDELETEPROGRAMSARBPROC glDeleteProgramsARB;
32	PFNGLGENPROGRAMSARBPROC glGenProgramsARB;
33	PFNGLBINDPROGRAMARBPROC glBindProgramARB;
34	PFNGLPROGRAMSTRINGARBPROC glProgramStringARB;
35};
36
37#if GLX_ARB_get_proc_address
38
39void Extensions::init() {
40	std::string extensions((const char*)glGetString(GL_EXTENSIONS));
41	TRACE("Extensions: " << extensions);
42
43	std::string::size_type a = 0;
44	unsigned int count = 0;
45	while (a < extensions.size()) {
46		std::string::size_type b = extensions.find(' ', a);
47		if (b == std::string::npos) b = extensions.size();
48		std::string s(extensions.substr(a, b - a));
49		if (
50			s == "GL_ARB_multitexture" ||
51			s == "GL_ARB_texture_cube_map" ||
52			s == "GL_ARB_vertex_program" ||
53			s == "GL_ARB_fragment_program"
54		)
55			count++;
56		a = b + 1;
57	}
58
59	if (count != 4)
60		throw Exception("Not all required GL extensions available");
61
62	glActiveTextureARB = PFNGLACTIVETEXTUREARBPROC(
63		glXGetProcAddressARB((const GLubyte*)"glActiveTextureARB"));
64	glDeleteProgramsARB = PFNGLDELETEPROGRAMSARBPROC(
65		glXGetProcAddressARB((const GLubyte*)"glDeleteProgramsARB"));
66	glGenProgramsARB = PFNGLGENPROGRAMSARBPROC(
67		glXGetProcAddressARB((const GLubyte*)"glGenProgramsARB"));
68	glBindProgramARB = PFNGLBINDPROGRAMARBPROC(
69		glXGetProcAddressARB((const GLubyte*)"glBindProgramARB"));
70	glProgramStringARB = PFNGLPROGRAMSTRINGARBPROC(
71		glXGetProcAddressARB((const GLubyte*)"glProgramStringARB"));
72}
73
74#else // !GLX_ARB_get_proc_address
75
76void Extensions::init() {
77	// This one's easy!
78	throw Exception("Can not dynamically get GL procedure addresses");
79}
80
81#endif // !GLX_ARB_get_proc_address
82
83#endif // USE_GL_EXTENSIONS