]> git.tdb.fi Git - libs/gl.git/blob - source/backends/opengl/device_backend.cpp
Check the flat qualifier from the correct member
[libs/gl.git] / source / backends / opengl / device_backend.cpp
1 #include <msp/gl/extensions/arb_enhanced_layouts.h>
2 #include <msp/gl/extensions/arb_explicit_attrib_location.h>
3 #include <msp/gl/extensions/arb_explicit_uniform_location.h>
4 #include <msp/gl/extensions/arb_gpu_shader5.h>
5 #include <msp/gl/extensions/arb_separate_shader_objects.h>
6 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
7 #include <msp/gl/extensions/arb_vertex_shader.h>
8 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
9 #include <msp/gl/extensions/ext_framebuffer_object.h>
10 #include <msp/gl/extensions/ext_gpu_shader4.h>
11 #include <msp/gl/extensions/ext_texture_array.h>
12 #include <msp/gl/extensions/ext_texture_filter_anisotropic.h>
13 #include <msp/gl/extensions/msp_clipping.h>
14 #include <msp/gl/extensions/nv_fbo_color_attachments.h>
15 #include "device.h"
16 #include "device_backend.h"
17 #include "gl.h"
18
19 using namespace std;
20
21 namespace Msp {
22 namespace GL {
23
24 OpenGLDevice::OpenGLDevice(Graphics::Window &wnd, const Graphics::GLOptions &opts):
25         context(wnd, opts)
26 { }
27
28 Graphics::GLOptions OpenGLDevice::create_default_options()
29 {
30         Graphics::GLOptions opts;
31         opts.gl_version_major = Graphics::GLOptions::LATEST_VERSION;
32         opts.core_profile = true;
33         return opts;
34 }
35
36 void OpenGLDevice::fill_info()
37 {
38         DeviceInfo &info = static_cast<Device *>(this)->info;
39
40         if(const char *gl_ver_ptr = reinterpret_cast<const char *>(glGetString(GL_VERSION)))
41         {
42                 string gl_ver = gl_ver_ptr;
43                 if(!gl_ver.compare(0, 10, "OpenGL ES "))
44                         gl_ver.erase(0, 10);
45
46                 Version ver(gl_ver.substr(0, gl_ver.find(' ')));
47
48                 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
49                 {
50                         Version force_ver(force_ver_ptr);
51                         if(force_ver<ver)
52                                 ver = force_ver;
53                 }
54
55                 info.api_version = ver;
56         }
57
58         DeviceLimits &lim = info.limits;
59         glGetIntegerv(GL_MAX_CLIP_PLANES, reinterpret_cast<int *>(&lim.max_clip_planes));
60         if(ARB_vertex_shader)
61         {
62                 glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast<int *>(&lim.max_vertex_attributes));
63                 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, reinterpret_cast<int *>(&lim.max_texture_bindings));
64         }
65         if(EXT_framebuffer_object)
66                 glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, reinterpret_cast<int *>(&lim.max_color_attachments));
67         if(EXT_framebuffer_multisample)
68                 glGetIntegerv(GL_MAX_SAMPLES, reinterpret_cast<int *>(&lim.max_samples));
69         if(ARB_uniform_buffer_object)
70         {
71                 glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<int *>(&lim.max_uniform_bindings));
72                 glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<int *>(&lim.uniform_buffer_alignment));
73         }
74         if(EXT_texture_filter_anisotropic)
75                 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &lim.max_anisotropy);
76
77         SL::Features &feat = info.glsl_features;
78         feat.target_api = get_backend_api();
79         feat.glsl_version = get_glsl_version();
80         feat.arb_enhanced_layouts = ARB_enhanced_layouts;
81         feat.arb_explicit_attrib_location = ARB_explicit_attrib_location;
82         feat.arb_explicit_uniform_location = ARB_explicit_uniform_location;
83         feat.arb_gpu_shader5 = ARB_gpu_shader5;
84         feat.arb_separate_shader_objects = ARB_separate_shader_objects;
85         feat.arb_uniform_buffer_object = ARB_uniform_buffer_object;
86         feat.ext_gpu_shader4 = EXT_gpu_shader4;
87         feat.ext_texture_array = EXT_texture_array;
88         feat.uniform_binding_range = lim.max_uniform_bindings;
89         feat.texture_binding_range = lim.max_texture_bindings;
90
91         state.bound_tex_targets.resize(lim.max_texture_bindings);
92         state.bound_uniform_blocks.resize(lim.max_uniform_bindings);
93 }
94
95 } // namespace GL
96 } // namespace Msp