]> git.tdb.fi Git - libs/gl.git/commitdiff
Move backend information into Device
authorMikko Rasa <tdb@tdb.fi>
Tue, 9 Nov 2021 12:07:01 +0000 (14:07 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 9 Nov 2021 12:07:35 +0000 (14:07 +0200)
18 files changed:
source/backends/opengl/backend_opengl.cpp
source/backends/opengl/device_backend.cpp
source/backends/opengl/device_backend.h
source/backends/opengl/deviceinfo_backend.cpp [deleted file]
source/backends/opengl/extension.cpp
source/backends/opengl/pipelinestate_backend.cpp
source/backends/opengl/program_backend.cpp
source/builders/sequencebuilder.cpp
source/core/backend.h
source/core/device.cpp
source/core/device.h
source/core/deviceinfo.cpp [deleted file]
source/core/deviceinfo.h [deleted file]
source/core/module.cpp
source/core/sampler.cpp
source/core/texture2dmultisample.cpp
source/core/uniformblock.cpp
source/core/vertexsetup.cpp

index ce8fc17b181768b274279a9809013d691dcb5bd2..46d1ce2050eb2285a939e9272fa827bf815ec345 100644 (file)
@@ -1,9 +1,4 @@
-#include <stdexcept>
-#include <cstdlib>
 #include "backend.h"
-#include "gl.h"
-
-using namespace std;
 
 namespace Msp {
 namespace GL {
@@ -17,33 +12,5 @@ GraphicsApi get_backend_api()
 #endif
 }
 
-inline Version get_gl_version()
-{
-       const char *gl_ver_ptr = reinterpret_cast<const char *>(glGetString(GL_VERSION));
-       if(!gl_ver_ptr)
-               throw runtime_error("OpenGL version not available");
-
-       string gl_ver = gl_ver_ptr;
-       if(!gl_ver.compare(0, 10, "OpenGL ES "))
-               gl_ver.erase(0, 10);
-
-       Version ver(gl_ver.substr(0, gl_ver.find(' ')));
-
-       if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
-       {
-               Version force_ver(force_ver_ptr);
-               if(force_ver<ver)
-                       ver = force_ver;
-       }
-
-       return ver;
-}
-
-const Version &get_backend_version()
-{
-       static Version version = get_gl_version();
-       return version;
-}
-
 } // namespace GL
 } // namespace Msp
index 5429c0c1ced0b452e6b49625a534ff9204e0bb5b..1c51b132ca48500a26f5b78841bbb2e99c855cd3 100644 (file)
@@ -1,4 +1,22 @@
+#include <msp/gl/extensions/arb_enhanced_layouts.h>
+#include <msp/gl/extensions/arb_explicit_attrib_location.h>
+#include <msp/gl/extensions/arb_explicit_uniform_location.h>
+#include <msp/gl/extensions/arb_gpu_shader5.h>
+#include <msp/gl/extensions/arb_separate_shader_objects.h>
+#include <msp/gl/extensions/arb_uniform_buffer_object.h>
+#include <msp/gl/extensions/arb_vertex_shader.h>
+#include <msp/gl/extensions/ext_framebuffer_multisample.h>
+#include <msp/gl/extensions/ext_framebuffer_object.h>
+#include <msp/gl/extensions/ext_gpu_shader4.h>
+#include <msp/gl/extensions/ext_texture_array.h>
+#include <msp/gl/extensions/ext_texture_filter_anisotropic.h>
+#include <msp/gl/extensions/msp_clipping.h>
+#include <msp/gl/extensions/nv_fbo_color_attachments.h>
+#include "device.h"
 #include "device_backend.h"
+#include "gl.h"
+
+using namespace std;
 
 namespace Msp {
 namespace GL {
@@ -7,5 +25,61 @@ OpenGLDevice::OpenGLDevice(Graphics::Window &wnd, const Graphics::GLOptions &opt
        context(wnd, opts)
 { }
 
+void OpenGLDevice::fill_info()
+{
+       DeviceInfo &info = static_cast<Device *>(this)->info;
+
+       if(const char *gl_ver_ptr = reinterpret_cast<const char *>(glGetString(GL_VERSION)))
+       {
+               string gl_ver = gl_ver_ptr;
+               if(!gl_ver.compare(0, 10, "OpenGL ES "))
+                       gl_ver.erase(0, 10);
+
+               Version ver(gl_ver.substr(0, gl_ver.find(' ')));
+
+               if(const char *force_ver_ptr = getenv("MSPGL_FORCE_VERSION"))
+               {
+                       Version force_ver(force_ver_ptr);
+                       if(force_ver<ver)
+                               ver = force_ver;
+               }
+
+               info.api_version = ver;
+       }
+
+       DeviceLimits &lim = info.limits;
+       glGetIntegerv(GL_MAX_CLIP_PLANES, reinterpret_cast<int *>(&lim.max_clip_planes));
+       if(ARB_vertex_shader)
+       {
+               glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast<int *>(&lim.max_vertex_attributes));
+               glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, reinterpret_cast<int *>(&lim.max_texture_bindings));
+       }
+       if(EXT_framebuffer_object)
+               glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, reinterpret_cast<int *>(&lim.max_color_attachments));
+       if(EXT_framebuffer_multisample)
+               glGetIntegerv(GL_MAX_SAMPLES, reinterpret_cast<int *>(&lim.max_samples));
+       if(ARB_uniform_buffer_object)
+       {
+               glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<int *>(&lim.max_uniform_bindings));
+               glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<int *>(&lim.uniform_buffer_alignment));
+       }
+       if(EXT_texture_filter_anisotropic)
+               glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &lim.max_anisotropy);
+
+       SL::Features &feat = info.glsl_features;
+       feat.target_api = get_backend_api();
+       feat.glsl_version = get_glsl_version();
+       feat.arb_enhanced_layouts = ARB_enhanced_layouts;
+       feat.arb_explicit_attrib_location = ARB_explicit_attrib_location;
+       feat.arb_explicit_uniform_location = ARB_explicit_uniform_location;
+       feat.arb_gpu_shader5 = ARB_gpu_shader5;
+       feat.arb_separate_shader_objects = ARB_separate_shader_objects;
+       feat.arb_uniform_buffer_object = ARB_uniform_buffer_object;
+       feat.ext_gpu_shader4 = EXT_gpu_shader4;
+       feat.ext_texture_array = EXT_texture_array;
+       feat.uniform_binding_range = lim.max_uniform_bindings;
+       feat.texture_binding_range = lim.max_texture_bindings;
+}
+
 } // namespace GL
 } // namespace Msp
index e64352d3437b082b4f014efa76f894cfaef80f84..f3a8e48029b0b807e7484a6a5a9ab4b9c0130298 100644 (file)
@@ -14,6 +14,8 @@ protected:
 
        OpenGLDevice(Graphics::Window &, const Graphics::GLOptions &);
 
+       void fill_info();
+
        Graphics::GLContext &get_context() { return context; }
 };
 
diff --git a/source/backends/opengl/deviceinfo_backend.cpp b/source/backends/opengl/deviceinfo_backend.cpp
deleted file mode 100644 (file)
index df085dc..0000000
+++ /dev/null
@@ -1,60 +0,0 @@
-#include <msp/gl/extensions/arb_enhanced_layouts.h>
-#include <msp/gl/extensions/arb_explicit_attrib_location.h>
-#include <msp/gl/extensions/arb_explicit_uniform_location.h>
-#include <msp/gl/extensions/arb_gpu_shader5.h>
-#include <msp/gl/extensions/arb_separate_shader_objects.h>
-#include <msp/gl/extensions/arb_uniform_buffer_object.h>
-#include <msp/gl/extensions/arb_vertex_shader.h>
-#include <msp/gl/extensions/ext_framebuffer_multisample.h>
-#include <msp/gl/extensions/ext_framebuffer_object.h>
-#include <msp/gl/extensions/ext_gpu_shader4.h>
-#include <msp/gl/extensions/ext_texture_array.h>
-#include <msp/gl/extensions/ext_texture_filter_anisotropic.h>
-#include <msp/gl/extensions/msp_clipping.h>
-#include <msp/gl/extensions/nv_fbo_color_attachments.h>
-#include "deviceinfo.h"
-#include "gl.h"
-
-namespace Msp {
-namespace GL {
-
-Limits::Limits()
-{
-       glGetIntegerv(GL_MAX_CLIP_PLANES, reinterpret_cast<int *>(&max_clip_planes));
-       if(ARB_vertex_shader)
-       {
-               glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast<int *>(&max_vertex_attributes));
-               glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, reinterpret_cast<int *>(&max_texture_bindings));
-       }
-       if(EXT_framebuffer_object)
-               glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, reinterpret_cast<int *>(&max_color_attachments));
-       if(EXT_framebuffer_multisample)
-               glGetIntegerv(GL_MAX_SAMPLES, reinterpret_cast<int *>(&max_samples));
-       if(ARB_uniform_buffer_object)
-       {
-               glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<int *>(&max_uniform_bindings));
-               glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<int *>(&uniform_buffer_alignment));
-       }
-       if(EXT_texture_filter_anisotropic)
-               glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY, &max_anisotropy);
-}
-
-
-DeviceInfo::DeviceInfo()
-{
-       glsl_features.target_api = get_backend_api();
-       glsl_features.glsl_version = get_glsl_version();
-       glsl_features.arb_enhanced_layouts = ARB_enhanced_layouts;
-       glsl_features.arb_explicit_attrib_location = ARB_explicit_attrib_location;
-       glsl_features.arb_explicit_uniform_location = ARB_explicit_uniform_location;
-       glsl_features.arb_gpu_shader5 = ARB_gpu_shader5;
-       glsl_features.arb_separate_shader_objects = ARB_separate_shader_objects;
-       glsl_features.arb_uniform_buffer_object = ARB_uniform_buffer_object;
-       glsl_features.ext_gpu_shader4 = EXT_gpu_shader4;
-       glsl_features.ext_texture_array = EXT_texture_array;
-       glsl_features.uniform_binding_range = limits.max_uniform_bindings;
-       glsl_features.texture_binding_range = limits.max_texture_bindings;
-}
-
-} // namespace Msp
-} // namespace GL
index a55da9bac1c7b30ab965b6ce70e20390eafda6d1..84f8bd0a32d0789eb7dd340411b4b92ec73e701a 100644 (file)
@@ -10,6 +10,7 @@
 #endif
 #include <msp/strings/format.h>
 #include <msp/strings/utils.h>
+#include "device.h"
 #include "error.h"
 #include "extension.h"
 #include "gl.h"
@@ -64,7 +65,8 @@ bool is_supported(const string &ext)
 
        if(!init_done)
        {
-               if(get_backend_api()==OPENGL && get_backend_version()>=Version(3, 0))
+               const DeviceInfo &dev_info = Device::get_current().get_info();
+               if(dev_info.api==OPENGL && dev_info.api_version>=Version(3, 0))
                {
                        typedef GLubyte *(APIENTRY *FPtr_glGetStringi)(GLenum, GLuint);
                        FPtr_glGetStringi glGetStringi = reinterpret_cast<FPtr_glGetStringi>(get_proc_address("glGetStringi"));
@@ -90,7 +92,7 @@ bool is_supported(const string &ext)
 
 bool is_supported(const Version &core_version, const Version &deprecated_version)
 {
-       const Version &version = get_backend_version();
+       const Version &version = Device::get_current().get_info().api_version;
        if(deprecated_version && version>=deprecated_version && get_gl_profile()==CORE_PROFILE)
                return false;
        return (version>=core_version);
@@ -119,7 +121,7 @@ bool is_disabled(const string &ext)
 
                                /* AMD's uniform buffer objects only work with the core version of
                                shaders. */
-                               if(get_backend_version()<Version(2, 0))
+                               if(Device::get_current().get_info().api_version<Version(2, 0))
                                        disabled_exts.insert("GL_ARB_uniform_buffer_object");
                        }
                }
@@ -132,7 +134,8 @@ bool is_disabled(const string &ext)
 
 inline GLProfile _get_gl_profile()
 {
-       if(get_backend_api()==OPENGL && get_backend_version()>=Version(3, 0))
+       const DeviceInfo &dev_info = Device::get_current().get_info();
+       if(dev_info.api==OPENGL && dev_info.api_version>=Version(3, 0))
        {
                int mask;
                glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
index cda3439cbb6750b0a66ba8eaa0374371c019f859..58e12e7ff2126040eed1b2d62580b8c0bf68cbc4 100644 (file)
@@ -8,7 +8,7 @@
 #include "blend.h"
 #include "buffer.h"
 #include "depthtest.h"
-#include "deviceinfo.h"
+#include "device.h"
 #include "framebuffer.h"
 #include "gl.h"
 #include "pipelinestate.h"
@@ -35,9 +35,9 @@ unsigned OpenGLPipelineState::n_clip_distances = 0;
 OpenGLPipelineState::OpenGLPipelineState()
 {
        if(bound_tex_targets.empty())
-               bound_tex_targets.resize(DeviceInfo::get_global().limits.max_texture_bindings);
+               bound_tex_targets.resize(Device::get_current().get_info().limits.max_texture_bindings);
        if(bound_uniform_blocks.empty())
-               bound_uniform_blocks.resize(DeviceInfo::get_global().limits.max_uniform_bindings);
+               bound_uniform_blocks.resize(Device::get_current().get_info().limits.max_uniform_bindings);
 }
 
 OpenGLPipelineState::~OpenGLPipelineState()
index 32c6d6e137c36e4789b47ccb2b381a7823396be2..132ad1c05e823e5fd0da09887a9d54af82044638 100644 (file)
@@ -12,7 +12,7 @@
 #include <msp/gl/extensions/khr_debug.h>
 #include <msp/gl/extensions/nv_non_square_matrices.h>
 #include <msp/io/print.h>
-#include "deviceinfo.h"
+#include "device.h"
 #include "error.h"
 #include "program.h"
 #include "program_backend.h"
@@ -90,7 +90,7 @@ unsigned OpenGLProgram::add_stage(Stage type)
 
 void OpenGLProgram::add_glsl_stages(const GlslModule &mod, const map<string, int> &spec_values, TransientData &transient)
 {
-       SL::Compiler compiler(DeviceInfo::get_global().glsl_features);
+       SL::Compiler compiler(Device::get_current().get_info().glsl_features);
        compiler.set_source(mod.get_prepared_source(), "<module>");
        compiler.specialize(spec_values);
        compiler.compile(SL::Compiler::PROGRAM);
index dbb675acf2a7925a3ddf1e4b6b3969f04faaf8be..65aeaa13d01a02d1dfa12198dfb4ec8fc4f39be6 100644 (file)
@@ -1,7 +1,7 @@
 #include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/strings/format.h>
-#include "deviceinfo.h"
+#include "device.h"
 #include "error.h"
 #include "sequence.h"
 #include "sequencebuilder.h"
@@ -167,7 +167,7 @@ Sequence *SequenceBuilder::build(const Framebuffer &fbo) const
 
 FrameFormat SequenceBuilder::create_frame_format() const
 {
-       unsigned samples = min(tmpl.get_maximum_multisample(), DeviceInfo::get_global().limits.max_samples);
+       unsigned samples = min(tmpl.get_maximum_multisample(), Device::get_current().get_info().limits.max_samples);
        if(samples<tmpl.get_required_multisample())
                throw invalid_operation("SequenceBuilder::create_frame_format");
 
index ef04bd1182c4214eff56f6baed75c22a47ace1bc..2d58d38731a71402595fc50c17650d2518328729 100644 (file)
@@ -29,9 +29,6 @@ struct Version
 /** Returns the backend for which the library was compiled. */
 GraphicsApi get_backend_api();
 
-/** Returns the backend version number, as reported by the implementation. */
-const Version &get_backend_version();
-
 } // namespace GL
 } // namespace Msp
 
index 9a24a1f2c905ef1dc025f28b45227794305985de..e3b43e2db2cf3ad45feb8396f7e890d7605c24c6 100644 (file)
@@ -10,6 +10,9 @@ Device::Device(Graphics::Window &w, const DeviceOptions &o):
        DeviceBackend(w, o)
 {
        current = this;
+
+       info.api = get_backend_api();
+       fill_info();
 }
 
 Device::~Device()
index 6a6a76080fed875ec165622ef5b194b5a3539586..2b75e4c81a9d9613ee478fc64ac1e99c4aac3517 100644 (file)
@@ -2,11 +2,39 @@
 #define MSP_GL_DEVICE_H_
 
 #include <msp/graphics/window.h>
+#include "backend.h"
 #include "device_backend.h"
+#include "glsl/features.h"
 
 namespace Msp {
 namespace GL {
 
+/**
+Contains information about various limits imposed by the graphics device.
+*/
+struct DeviceLimits
+{
+       unsigned max_clip_planes = 6;
+       unsigned max_vertex_attributes = 16;
+       unsigned max_texture_bindings = 16;
+       unsigned max_color_attachments = 8;
+       unsigned max_samples = 4;
+       unsigned max_uniform_bindings = 24;
+       unsigned uniform_buffer_alignment = 256;
+       float max_anisotropy = 1.0f;
+};
+
+/**
+Contains information about a graphics device.
+*/
+struct DeviceInfo
+{
+       GraphicsApi api;
+       Version api_version;
+       DeviceLimits limits;
+       SL::Features glsl_features;
+};
+
 /**
 Represents a graphics device.  An instance must be created to use the library.
 */
@@ -15,6 +43,8 @@ class Device: public DeviceBackend
        friend DeviceBackend;
 
 private:
+       DeviceInfo info;
+
        static Device *current;
 
 public:
@@ -22,6 +52,7 @@ public:
        ~Device();
 
        using DeviceBackend::get_context;
+       const DeviceInfo &get_info() const { return info; }
 
        static Device &get_current();
 };
diff --git a/source/core/deviceinfo.cpp b/source/core/deviceinfo.cpp
deleted file mode 100644 (file)
index 8400ffd..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "deviceinfo.h"
-
-namespace Msp {
-namespace GL {
-
-const DeviceInfo &DeviceInfo::get_global()
-{
-       static DeviceInfo info;
-       return info;
-}
-
-} // namespace GL
-} // namespace Msp
diff --git a/source/core/deviceinfo.h b/source/core/deviceinfo.h
deleted file mode 100644 (file)
index a958411..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#ifndef MSP_GL_DEVICEINFO_H_
-#define MSP_GL_DEVICEINFO_H_
-
-#include "glsl/features.h"
-
-namespace Msp {
-namespace GL {
-
-/**
-Contains information about various limits imposed by the graphics device.
-*/
-struct Limits
-{
-       unsigned max_clip_planes = 6;
-       unsigned max_vertex_attributes = 16;
-       unsigned max_texture_bindings = 16;
-       unsigned max_color_attachments = 8;
-       unsigned max_samples = 4;
-       unsigned max_uniform_bindings = 24;
-       unsigned uniform_buffer_alignment = 256;
-       float max_anisotropy = 1.0f;
-
-       Limits();
-};
-
-/**
-Contains information about a graphics device.
-*/
-struct DeviceInfo
-{
-       Limits limits;
-       SL::Features glsl_features;
-
-       DeviceInfo();
-
-       /** Returns information for the device currently in use. */
-       static const DeviceInfo &get_global();
-};
-
-} // namespace GL
-} // namespace Msp
-
-#endif
index 89d418947f92b1685c9ddd0689d9811612114abd..15bd750cf0b299bd7ea8440ed6d0be5adc3788d1 100644 (file)
@@ -1,6 +1,6 @@
 #include <msp/core/algorithm.h>
 #include <msp/io/print.h>
-#include "deviceinfo.h"
+#include "device.h"
 #include "module.h"
 #include "resources.h"
 
@@ -69,8 +69,9 @@ void Module::load_source(IO::Base &io, const string &name)
 
 SL::Features Module::create_features() const
 {
-       const SL::Features &device_features = DeviceInfo::get_global().glsl_features;
-       SL::Features latest_features = SL::Features::latest(get_backend_api());
+       const DeviceInfo &dev_info = Device::get_current().get_info();
+       const SL::Features &device_features = dev_info.glsl_features;
+       SL::Features latest_features = SL::Features::latest(dev_info.api);
        SL::Features features;
        features.target_api = latest_features.target_api;
        features.glsl_version = latest_features.glsl_version;
index d45dee54242b9f6ef60b9c2fd7bacdc811a3b2ce..4da13833330dac12eace04b145f9ffacd4a0510b 100644 (file)
@@ -1,5 +1,5 @@
 #include <msp/strings/format.h>
-#include "deviceinfo.h"
+#include "device.h"
 #include "error.h"
 #include "sampler.h"
 
@@ -38,7 +38,7 @@ void Sampler::set_max_anisotropy(float a)
 {
        if(a<1.0f)
                throw invalid_argument("Sampler::set_max_anisotropy");
-       if(a>DeviceInfo::get_global().limits.max_anisotropy)
+       if(a>Device::get_current().get_info().limits.max_anisotropy)
                throw out_of_range("Sampler::set_max_anisotropy");
        bool supported = check_anisotropic(a>1.0f);
        max_anisotropy = a;
index ce35bdb795afb5487c226856eabf94b9f945d316..8ba52522fde8df1a8f5fd6b14560d571c58f960f 100644 (file)
@@ -1,4 +1,4 @@
-#include "deviceinfo.h"
+#include "device.h"
 #include "error.h"
 #include "texture2dmultisample.h"
 
@@ -17,7 +17,7 @@ void Texture2DMultisample::storage(PixelFormat fmt, unsigned wd, unsigned ht, un
        }
        if(wd==0 || ht==0)
                throw invalid_argument("Texture2DMultisample::storage");
-       if(!sm || sm>DeviceInfo::get_global().limits.max_samples)
+       if(!sm || sm>Device::get_current().get_info().limits.max_samples)
                throw invalid_argument("Texture2DMultisample::storage");
 
        set_format(fmt);
index 89032b5cf3f045e07c42d9a283f8693975a34687..adadf0561c8051c54d06c2ac43a3a3608e6539dd 100644 (file)
@@ -1,5 +1,5 @@
 #include <algorithm>
-#include "deviceinfo.h"
+#include "device.h"
 #include "uniformblock.h"
 
 using namespace std;
@@ -14,7 +14,7 @@ UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info):
 
 size_t UniformBlock::get_alignment() const
 {
-       return DeviceInfo::get_global().limits.uniform_buffer_alignment;
+       return Device::get_current().get_info().limits.uniform_buffer_alignment;
 }
 
 void UniformBlock::store(const ReflectData::UniformInfo &info, size_t array_size, const void *value)
index 50f9c1837d1eff8e6bf5bfdf89d956b2cec82827..61bf032c0fcaecae0ffac46fef15c95f86e95952 100644 (file)
@@ -1,4 +1,4 @@
-#include "deviceinfo.h"
+#include "device.h"
 #include "error.h"
 #include "vertexarray.h"
 #include "vertexsetup.h"
@@ -72,7 +72,7 @@ bool VertexSetup::verify_format(const VertexFormat &fmt)
        if(fmt.empty())
                return false;
 
-       static unsigned max_attribs = DeviceInfo::get_global().limits.max_vertex_attributes;
+       static unsigned max_attribs = Device::get_current().get_info().limits.max_vertex_attributes;
        return all_of(fmt.begin(), fmt.end(), [](VertexAttribute a){ return get_attribute_semantic(a)<max_attribs; });
 }