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>
17 #include "device_backend.h"
25 OpenGLDevice::OpenGLDevice(Graphics::Window &wnd, const Graphics::GLOptions &opts):
29 Graphics::GLOptions OpenGLDevice::create_default_options()
31 Graphics::GLOptions opts;
32 opts.gl_version_major = Graphics::GLOptions::LATEST_VERSION;
33 opts.core_profile = true;
37 void OpenGLDevice::fill_info()
39 DeviceInfo &info = static_cast<Device *>(this)->info;
41 if(const char *gl_ver_ptr = reinterpret_cast<const char *>(glGetString(GL_VERSION)))
43 string gl_ver = gl_ver_ptr;
44 if(!gl_ver.compare(0, 10, "OpenGL ES "))
47 Version ver(gl_ver.substr(0, gl_ver.find(' ')));
49 if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
51 Version force_ver(force_ver_ptr);
56 info.api_version = ver;
59 DeviceLimits &lim = info.limits;
60 glGetIntegerv(GL_MAX_CLIP_PLANES, reinterpret_cast<int *>(&lim.max_clip_planes));
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));
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)
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));
77 if(EXT_texture_filter_anisotropic)
78 glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &lim.max_anisotropy);
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;
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);