remove deprecated luminance texture generation
[voxelands-alt.git] / src / graphics / opengl.c
blob6b4fa6c16748e6b787796dfda9006b6cc6fd6097
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 int cfg_pseudosdf;
36 } opengl_features = {
37 -1,
38 1.0,
44 1000,
49 /* command anisotropic setter */
50 int opengl_anisotropic_setter(char* value)
52 opengl_features.cfg_anisotropic = parse_bool(value);
53 return 0;
55 /* command bilinear setter */
56 int opengl_bilinear_setter(char* value)
58 opengl_features.cfg_bilinear = parse_bool(value);
59 return 0;
61 /* command trilinear setter */
62 int opengl_trilinear_setter(char* value)
64 opengl_features.cfg_trilinear = parse_bool(value);
65 return 0;
67 /* command mipmap setter */
68 int opengl_mipmap_setter(char* value)
70 opengl_features.cfg_mipmap = parse_bool(value);
71 return 0;
73 /* command particles setter */
74 int opengl_particles_setter(char* value)
76 opengl_features.cfg_particles = parse_bool(value);
77 return 0;
79 /* command particlesmax setter */
80 int opengl_particles_max_setter(char* value)
82 opengl_features.cfg_particles_max = strtol(value,NULL,10);
83 return 0;
85 /* command bumpmap setter */
86 int opengl_bumpmap_setter(char* value)
88 opengl_features.cfg_bumpmap = parse_bool(value);
89 return 0;
91 /* command psdf setter */
92 int opengl_psdf_setter(char* value)
94 opengl_features.cfg_pseudosdf = parse_bool(value);
95 return 0;
98 /* check for anisotropic filtering support */
99 int opengl_has_anisotropic()
101 if (opengl_features.anisotropic < 0) {
102 char* t = (char*)glGetString(GL_EXTENSIONS);
103 opengl_features.anisotropic = 0;
104 if (glGetError() == GL_NO_ERROR && strstr(t,"GL_EXT_texture_filter_anisotropic"))
105 opengl_features.anisotropic = 1;
106 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &opengl_features.anisotropic_max);
107 if (glGetError() == GL_NO_ERROR)
108 opengl_features.anisotropic_max = 1.0;
111 if (!opengl_features.anisotropic)
112 return 0;
114 if (opengl_features.cfg_anisotropic && opengl_features.cfg_mipmap)
115 return 1;
117 return 0;
120 /* get the maximum anisotropic filtering value */
121 float opengl_max_anisotropic()
123 return opengl_features.anisotropic_max;
126 /* check for bilinear filtering support */
127 int opengl_has_bilinear()
129 return opengl_features.cfg_bilinear;
132 /* check for trilinear filtering support */
133 int opengl_has_trilinear()
135 return opengl_features.cfg_trilinear;
138 /* check for mipmap support */
139 int opengl_has_mipmap()
141 return opengl_features.cfg_mipmap;
144 /* check if particle effects are enabled */
145 int opengl_has_particles()
147 return opengl_features.cfg_particles;
150 /* get the maximum number of particles allowed */
151 int opengl_particles_max()
153 if (!opengl_has_particles())
154 return 0;
155 return opengl_features.cfg_particles_max;
158 /* check if pseudo signed distance field rendering is enabled */
159 int opengl_has_psdf()
161 return opengl_features.cfg_pseudosdf;
164 /* converts an opengl error enum into a string */
165 char* opengl_error_string(GLenum e)
167 /* TODO: moar! */
168 switch (e) {
169 case GL_INVALID_ENUM:
170 return "OpenGL: GL_INVALID_ENUM";
171 break;
172 case GL_INVALID_VALUE:
173 return "OpenGL: GL_INVALID_VALUE";
174 break;
175 case GL_INVALID_OPERATION:
176 return "OpenGL: GL_INVALID_OPERATION";
177 break;
178 default:;
181 return "Unknown OpenGL Error";