--tk-median --> --track-median, etc.
[Ale.git] / accel.h
blob5c5b24418290d8251dd5f4b6d62862077bb0f6fe
1 // Copyright 2008 David Hilvert <dhilvert@auricle.dyndns.org>,
2 // <dhilvert@gmail.com>
4 /* This file is part of the Anti-Lamenessing Engine.
6 The Anti-Lamenessing Engine is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 The Anti-Lamenessing Engine is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with the Anti-Lamenessing Engine; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * accel.h: acceleration
25 #ifndef __accel_h__
26 #define __accel_h__
28 #include "gpu.h"
30 #include <assert.h>
31 #include <stdio.h>
32 #include <string.h>
33 #include <stdlib.h>
35 class accel {
36 static int use_gpu;
37 static int _mask_gpu;
39 public:
41 static void mask_gpu() {
42 _mask_gpu = 1;
45 static void unmask_gpu() {
46 _mask_gpu = 0;
49 static void set_gpu() {
50 use_gpu = 1;
53 static void set_none() {
54 use_gpu = 0;
57 static void set_auto() {
58 #ifdef USE_GLEW
59 const char *accel_default = getenv("ALE_GPU_ACCEL_DEFAULT");
60 if (accel_default && !strcmp(accel_default, "1") && gpu::is_ok())
61 use_gpu = 1;
62 else
63 use_gpu = 0;
64 #else
65 use_gpu = 0;
66 #endif
69 static int is_gpu() {
70 if (use_gpu == 2)
71 set_auto();
73 if (use_gpu == 0)
74 return 0;
76 if (_mask_gpu)
77 return 0;
79 if (!gpu::is_ok()) {
80 fprintf(stderr, "GPU acceleration error.\n");
81 exit(1);
84 #ifdef USE_GLEW
85 const char *extensions[] = {
86 "GL_ARB_fragment_shader",
87 "GL_ARB_texture_float",
88 "GL_ARB_texture_rectangle",
89 "GL_EXT_framebuffer_object",
90 NULL
93 int unsupported = 0;
94 for (const char **c = extensions; *c; c++) {
95 if (!glewIsSupported(*c)) {
96 fprintf(stderr, "GL feature %s not supported.\n", *c);
97 unsupported = 1;
100 if (unsupported)
101 exit(1);
102 #else
103 fprintf(stderr, "GLEW linkage is required for acceleration.\n");
104 exit(1);
105 #endif
107 return 1;
111 #endif