]> git.tdb.fi Git - libs/gl.git/commitdiff
Store implementation limits in a central struct
authorMikko Rasa <tdb@tdb.fi>
Mon, 9 Aug 2021 09:12:06 +0000 (12:12 +0300)
committerMikko Rasa <tdb@tdb.fi>
Mon, 9 Aug 2021 09:16:53 +0000 (12:16 +0300)
14 files changed:
source/builders/sequencebuilder.cpp
source/core/buffer.cpp
source/core/buffer.h
source/core/clipping.cpp
source/core/clipping.h
source/core/deviceinfo.cpp [new file with mode: 0644]
source/core/deviceinfo.h [new file with mode: 0644]
source/core/renderbuffer.cpp
source/core/renderbuffer.h
source/core/texunit.cpp
source/core/texunit.h
source/core/uniformblock.cpp
source/core/vertexsetup.cpp
source/render/renderer.cpp

index 6cf34c0ee1b38307654699c43969e78b082cb59f..9bb8f1dcd6b05def0558b6f81cfa7767dd5061e7 100644 (file)
@@ -1,6 +1,7 @@
 #include <msp/core/algorithm.h>
 #include <msp/core/maputils.h>
 #include <msp/strings/format.h>
+#include "deviceinfo.h"
 #include "error.h"
 #include "renderbuffer.h"
 #include "sequence.h"
@@ -52,7 +53,7 @@ void SequenceBuilder::build(Sequence &sequence) const
 
        sequence.set_hdr(tmpl.get_hdr());
        sequence.set_alpha(tmpl.get_alpha());
-       unsigned samples = min(tmpl.get_maximum_multisample(), Renderbuffer::get_max_samples());
+       unsigned samples = min(tmpl.get_maximum_multisample(), Limits::get_global().max_samples);
        if(samples<tmpl.get_required_multisample())
                throw invalid_operation("SequenceBuilder::build");
 
index 00fd9cd3d42ac0597c255413b983f8d704b73bb4..5b3339a1d66721c51d417494ab77f80c6a58d78c 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/gl/extensions/khr_debug.h>
 #include <msp/strings/format.h>
 #include "buffer.h"
+#include "deviceinfo.h"
 #include "error.h"
 #include "misc.h"
 #include "vertexsetup.h"
@@ -297,7 +298,7 @@ const BufferRange *&BufferRange::binding(BufferType type, unsigned index)
 {
        if(type==UNIFORM_BUFFER)
        {
-               if(index>=get_n_uniform_buffer_bindings())
+               if(index>=Limits::get_global().max_uniform_bindings)
                        throw out_of_range("BufferRange::binding");
                if(bound_uniform.size()<=index)
                        bound_uniform.resize(index+1);
@@ -319,14 +320,12 @@ bool BufferRange::set_current(BufferType type, unsigned index, const BufferRange
 
 unsigned BufferRange::get_n_uniform_buffer_bindings()
 {
-       static unsigned count = get_i(GL_MAX_UNIFORM_BUFFER_BINDINGS);
-       return count;
+       return Limits::get_global().max_uniform_bindings;
 }
 
 unsigned BufferRange::get_uniform_buffer_alignment()
 {
-       static unsigned align = get_i(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT);
-       return align;
+       return Limits::get_global().uniform_buffer_alignment;
 }
 
 } // namespace GL
index 7ef846681a8d487a693ac59e177fee3e68cec970..ad3084298c55e74e0cfb4296bab53a556c5cceae 100644 (file)
@@ -163,8 +163,8 @@ private:
        static bool set_current(BufferType, unsigned, const BufferRange *);
 
 public:
-       static unsigned get_n_uniform_buffer_bindings();
-       static unsigned get_uniform_buffer_alignment();
+       DEPRECATED static unsigned get_n_uniform_buffer_bindings();
+       DEPRECATED static unsigned get_uniform_buffer_alignment();
 };
 
 } // namespace GL
index 18b706e78b1b34e9205879acd51cf83d10ad9cbb..644a2434c6b783bda0f806012f23e841e9acd5b8 100644 (file)
@@ -2,6 +2,7 @@
 #include <msp/gl/extensions/msp_clipping.h>
 #include "clipping.h"
 #include "clipplane.h"
+#include "deviceinfo.h"
 #include "error.h"
 #include "matrix.h"
 #include "misc.h"
@@ -13,16 +14,14 @@ namespace GL {
 
 unsigned Clipping::get_n_attach_points()
 {
-       static Require _req(MSP_clipping);
-       static int count = get_i(GL_MAX_CLIP_PLANES);
-       return count;
+       return Limits::get_global().max_clip_planes;
 }
 
 void Clipping::attach(const ClipPlane &p)
 {
        if(find_member(planes, &p, &AttachedPlane::plane)!=planes.end())
                return;
-       if(planes.size()>=get_n_attach_points())
+       if(planes.size()>=Limits::get_global().max_clip_planes)
                throw invalid_operation("Clipping::attach");
 
        planes.push_back(&p);
index d74763ab7c697f9cade4e94ab4b15bdb518e0a10..b07195231423ca139a174af18c202c80153f6602 100644 (file)
@@ -27,7 +27,7 @@ private:
        mutable ProgramData shdata;
 
 public:
-       static unsigned get_n_attach_points();
+       DEPRECATED static unsigned get_n_attach_points();
 
        void attach(const ClipPlane &);
        void detach(const ClipPlane &);
diff --git a/source/core/deviceinfo.cpp b/source/core/deviceinfo.cpp
new file mode 100644 (file)
index 0000000..54cb88b
--- /dev/null
@@ -0,0 +1,24 @@
+#include "deviceinfo.h"
+#include "gl.h"
+
+namespace Msp {
+namespace GL {
+
+Limits::Limits()
+{
+       glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, reinterpret_cast<int *>(&max_vertex_attributes));
+       glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, reinterpret_cast<int *>(&max_texture_bindings));
+       glGetIntegerv(GL_MAX_UNIFORM_BUFFER_BINDINGS, reinterpret_cast<int *>(&max_uniform_bindings));
+       glGetIntegerv(GL_MAX_CLIP_PLANES, reinterpret_cast<int *>(&max_clip_planes));
+       glGetIntegerv(GL_MAX_SAMPLES, reinterpret_cast<int *>(&max_samples));
+       glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT, reinterpret_cast<int *>(&uniform_buffer_alignment));
+}
+
+const Limits &Limits::get_global()
+{
+       static Limits limits;
+       return limits;
+}
+
+} // namespace GL
+} // namespace Msp
diff --git a/source/core/deviceinfo.h b/source/core/deviceinfo.h
new file mode 100644 (file)
index 0000000..9ea239b
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef MSP_GL_DEVICEINFO_H_
+#define MSP_GL_DEVICEINFO_H_
+
+namespace Msp {
+namespace GL {
+
+struct Limits
+{
+       unsigned max_vertex_attributes;
+       unsigned max_texture_bindings;
+       unsigned max_uniform_bindings;
+       unsigned max_clip_planes;
+       unsigned max_samples;
+       unsigned uniform_buffer_alignment;
+
+       Limits();
+
+       static const Limits &get_global();
+};
+
+} // namespace GL
+} // namespace Msp
+
+#endif
index 9af18daec9f1082ccd54c6e432e33a77478e9ed7..57b43eba7aaf6dcabc8b8899efff8310e66c11ac 100644 (file)
@@ -2,7 +2,7 @@
 #include <msp/gl/extensions/ext_framebuffer_multisample.h>
 #include <msp/gl/extensions/ext_framebuffer_object.h>
 #include <msp/gl/extensions/khr_debug.h>
-#include "misc.h"
+#include "deviceinfo.h"
 #include "renderbuffer.h"
 
 using namespace std;
@@ -41,8 +41,7 @@ void Renderbuffer::storage(PixelFormat fmt, unsigned wd, unsigned ht)
 
 unsigned Renderbuffer::get_max_samples()
 {
-       static unsigned max_samples = (EXT_framebuffer_multisample ? get_i(GL_MAX_SAMPLES) : 0);
-       return max_samples;
+       return Limits::get_global().max_samples;
 }
 
 void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsigned wd, unsigned ht)
@@ -51,7 +50,7 @@ void Renderbuffer::storage_multisample(unsigned samples, PixelFormat fmt, unsign
                return storage(fmt, wd, ht);
 
        static Require _req(EXT_framebuffer_multisample);
-       if(samples>get_max_samples())
+       if(samples>Limits::get_global().max_samples)
                throw out_of_range("Renderbuffer::storage_multisample");
 
        require_pixelformat(fmt);
index aea230804173c570fda45c1c2f0f016d2231f850..4462e31c12ce348ecb381eb546e98637cb75ebd6 100644 (file)
@@ -36,7 +36,7 @@ public:
 
        /** Returns the maximum supported sample count for multisampling.  If
        multisampling is not supported, returns 0. */
-       static unsigned get_max_samples();
+       DEPRECATED static unsigned get_max_samples();
 
        /** Allocates multisample storage for the renderbuffer.  All attachments in
        a framebuffer must have the same number of samples.  To transfer the
index 0659d6154e80523ffaa0baf75f6bf00ff96a05f2..7405d8da10a8d31ce1b8f70d757b28fff375067c 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdexcept>
 #include <msp/gl/extensions/arb_multitexture.h>
 #include <msp/gl/extensions/arb_vertex_shader.h>
+#include "deviceinfo.h"
 #include "gl.h"
 #include "misc.h"
 #include "texture.h"
@@ -42,24 +43,14 @@ void TexUnit::bind()
 
 unsigned TexUnit::get_n_units()
 {
-       static int count = -1;
-       if(count<0)
-       {
-               if(ARB_vertex_shader)
-                       count = get_i(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);
-               else if(ARB_multitexture)
-                       count = get_i(GL_MAX_TEXTURE_UNITS);
-               else
-                       count = 1;
-       }
-       return count;
+       return Limits::get_global().max_texture_bindings;
 }
 
 TexUnit &TexUnit::get_unit(unsigned n)
 {
        if(n>0)
                static Require _req(ARB_multitexture);
-       if(n>=get_n_units())
+       if(n>=Limits::get_global().max_texture_bindings)
                throw out_of_range("TexUnit::get_unit");
 
        if(units.size()<=n)
index 6253d8d914f52c85f7f9eec6a4beae0fcd733722..8fefc3a817c28fe1899e1d169e8a705f8097551d 100644 (file)
@@ -32,7 +32,7 @@ public:
        const Sampler *get_sampler() const { return sampler; }
        void bind();
 
-       static unsigned get_n_units();
+       DEPRECATED static unsigned get_n_units();
        static TexUnit &get_unit(unsigned);
        static TexUnit &current();
        static TexUnit *find_unit(const Texture *);
index f114ea584d04b7ff35ef550348febd4f9c38585d..59871cdde8249b3b90e0dd03a89db66963e2efd6 100644 (file)
@@ -3,6 +3,7 @@
 #include <msp/gl/extensions/arb_uniform_buffer_object.h>
 #include "buffer.h"
 #include "color.h"
+#include "deviceinfo.h"
 #include "error.h"
 #include "matrix.h"
 #include "uniform.h"
@@ -67,7 +68,7 @@ BufferBackedUniformBlock::~BufferBackedUniformBlock()
 
 unsigned BufferBackedUniformBlock::get_alignment() const
 {
-       return BufferRange::get_uniform_buffer_alignment();
+       return Limits::get_global().uniform_buffer_alignment;
 }
 
 void BufferBackedUniformBlock::location_changed(Buffer *buf, unsigned off, unsigned) const
index da79e7f6135f9b3d06badf30e024903e7d5b280a..1094bb21c9ef229359a09f70b35435c32f6e8444 100644 (file)
@@ -7,6 +7,7 @@
 #include <msp/gl/extensions/arb_vertex_shader.h>
 #include <msp/gl/extensions/khr_debug.h>
 #include "buffer.h"
+#include "deviceinfo.h"
 #include "error.h"
 #include "gl.h"
 #include "misc.h"
@@ -98,12 +99,10 @@ bool VertexSetup::verify_format(const VertexFormat &fmt)
        if(fmt.empty())
                return false;
 
-       static int max_attribs = -1;
-       if(max_attribs<0)
-               max_attribs = get_i(GL_MAX_VERTEX_ATTRIBS);
+       unsigned max_attribs = Limits::get_global().max_vertex_attributes;
 
        for(const unsigned char *a=fmt.begin(); a!=fmt.end(); ++a)
-               if(static_cast<int>(get_attribute_semantic(*a))>=max_attribs)
+               if(get_attribute_semantic(*a)>=max_attribs)
                        return false;
 
        return true;
index 8de24adbbca8aee385a5ddab15941b50ee41b9e6..a8f5ce3ab07f9ea3c6ef867678043315f84394de 100644 (file)
@@ -2,6 +2,7 @@
 #include "buffer.h"
 #include "camera.h"
 #include "clipping.h"
+#include "deviceinfo.h"
 #include "error.h"
 #include "lighting.h"
 #include "material.h"
@@ -401,7 +402,7 @@ Renderer::BoundProgramData::BoundProgramData(const ProgramData *d):
 Renderer::State::State():
        camera(0),
        texture_count(0),
-       lowest_effect_texunit(TexUnit::get_n_units()),
+       lowest_effect_texunit(Limits::get_global().max_texture_bindings),
        clipping(0),
        shprog(0),
        shdata_count(0),