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