…aaand add PREFIX to the freebsd makefile too
[voxelands-alt.git] / src / graphics / opengl.c
blob87e55e9f1b075ed74e725891f1e88a1a517568e3
1 /************************************************************************
2 * opengl.c
3 * voxelands - 3d voxel world sandbox game
4 * Copyright (C) Lisa 'darkrose' Milne 2016 <lisa@ltmnet.com>
6 * This program 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 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>
18 ************************************************************************/
20 #include "common.h"
21 #include "graphics.h"
23 #include <string.h>
25 static struct {
26 int anisotropic;
27 float anisotropic_max;
28 int cfg_anisotropic;
29 int cfg_bilinear;
30 int cfg_trilinear;
31 int cfg_mipmap;
32 int cfg_particles;
33 int cfg_particles_max;
34 int cfg_bumpmap;
35 } opengl_features = {
36 -1,
37 1.0,
43 1000,
47 /* command anisotropic setter */
48 int opengl_anisotropic_setter(char* value)
50 opengl_features.cfg_anisotropic = parse_bool(value);
51 return 0;
53 /* command bilinear setter */
54 int opengl_bilinear_setter(char* value)
56 opengl_features.cfg_bilinear = parse_bool(value);
57 return 0;
59 /* command trilinear setter */
60 int opengl_trilinear_setter(char* value)
62 opengl_features.cfg_trilinear = parse_bool(value);
63 return 0;
65 /* command mipmap setter */
66 int opengl_mipmap_setter(char* value)
68 opengl_features.cfg_mipmap = parse_bool(value);
69 return 0;
71 /* command particles setter */
72 int opengl_particles_setter(char* value)
74 opengl_features.cfg_particles = parse_bool(value);
75 return 0;
77 /* command particlesmax setter */
78 int opengl_particles_max_setter(char* value)
80 opengl_features.cfg_particles_max = strtol(value,NULL,10);
81 return 0;
83 /* command bumpmap setter */
84 int opengl_bumpmap_setter(char* value)
86 opengl_features.cfg_bumpmap = parse_bool(value);
87 return 0;
90 /* check for anisotropic filtering support */
91 int opengl_has_anisotropic()
93 if (opengl_features.anisotropic < 0) {
94 char* t = (char*)glGetString(GL_EXTENSIONS);
95 opengl_features.anisotropic = 0;
96 if (glGetError() == GL_NO_ERROR && strstr(t,"GL_EXT_texture_filter_anisotropic"))
97 opengl_features.anisotropic = 1;
98 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &opengl_features.anisotropic_max);
99 if (glGetError() == GL_NO_ERROR)
100 opengl_features.anisotropic_max = 1.0;
103 if (!opengl_features.anisotropic)
104 return 0;
106 if (opengl_features.cfg_anisotropic && opengl_features.cfg_mipmap)
107 return 1;
109 return 0;
112 /* get the maximum anisotropic filtering value */
113 float opengl_max_anisotropic()
115 return opengl_features.anisotropic_max;
118 /* check for bilinear filtering support */
119 int opengl_has_bilinear()
121 return opengl_features.cfg_bilinear;
124 /* check for trilinear filtering support */
125 int opengl_has_trilinear()
127 return opengl_features.cfg_trilinear;
130 /* check for mipmap support */
131 int opengl_has_mipmap()
133 return opengl_features.cfg_mipmap;
136 /* check if particle effects are enabled */
137 int opengl_has_particles()
139 return opengl_features.cfg_particles;
142 /* check if backface culling is enabled */
143 int opengl_particles_max()
145 if (!opengl_has_particles())
146 return 0;
147 return opengl_features.cfg_particles_max;
150 /* converts an opengl error enum into a string */
151 char* opengl_error_string(GLenum e)
153 /* TODO: moar! */
154 switch (e) {
155 case GL_INVALID_ENUM:
156 return "OpenGL: GL_INVALID_ENUM";
157 break;
158 case GL_INVALID_VALUE:
159 return "OpenGL: GL_INVALID_VALUE";
160 break;
161 case GL_INVALID_OPERATION:
162 return "OpenGL: GL_INVALID_OPERATION";
163 break;
164 default:;
167 return "Unknown OpenGL Error";