From 009918e76dda88b0cb68fdaa20c63d6e952af260 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 30 Sep 2021 21:24:32 +0300 Subject: [PATCH] Wrap Limits into a DeviceInfo struct This allows adding more types of information. --- source/builders/sequencebuilder.cpp | 2 +- source/core/clipping.cpp | 2 +- source/core/deviceinfo.cpp | 7 ++++--- source/core/deviceinfo.h | 9 ++++++++- source/core/pipelinestate.cpp | 8 ++++---- source/core/texture2dmultisample.cpp | 2 +- source/core/uniformblock.cpp | 2 +- source/core/vertexsetup.cpp | 2 +- source/glsl/features.cpp | 2 +- 9 files changed, 22 insertions(+), 14 deletions(-) diff --git a/source/builders/sequencebuilder.cpp b/source/builders/sequencebuilder.cpp index a614a836..45d4f873 100644 --- a/source/builders/sequencebuilder.cpp +++ b/source/builders/sequencebuilder.cpp @@ -125,7 +125,7 @@ Sequence *SequenceBuilder::build(const Framebuffer &fbo) const FrameFormat SequenceBuilder::create_frame_format() const { - unsigned samples = min(tmpl.get_maximum_multisample(), Limits::get_global().max_samples); + unsigned samples = min(tmpl.get_maximum_multisample(), DeviceInfo::get_global().limits.max_samples); if(samples=Limits::get_global().max_clip_planes) + if(planes.size()>=DeviceInfo::get_global().limits.max_clip_planes) throw invalid_operation("Clipping::attach"); planes.push_back(&p); diff --git a/source/core/deviceinfo.cpp b/source/core/deviceinfo.cpp index acbd0a73..f91e44a9 100644 --- a/source/core/deviceinfo.cpp +++ b/source/core/deviceinfo.cpp @@ -20,10 +20,11 @@ Limits::Limits() glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, reinterpret_cast(&max_color_attachments)); } -const Limits &Limits::get_global() + +const DeviceInfo &DeviceInfo::get_global() { - static Limits limits; - return limits; + static DeviceInfo info; + return info; } } // namespace GL diff --git a/source/core/deviceinfo.h b/source/core/deviceinfo.h index 1eb120ff..6f208544 100644 --- a/source/core/deviceinfo.h +++ b/source/core/deviceinfo.h @@ -15,8 +15,15 @@ struct Limits unsigned max_color_attachments; Limits(); +}; + +struct DeviceInfo +{ + Limits limits; + + DeviceInfo(); - static const Limits &get_global(); + static const DeviceInfo &get_global(); }; } // namespace GL diff --git a/source/core/pipelinestate.cpp b/source/core/pipelinestate.cpp index d99a3878..97f353dc 100644 --- a/source/core/pipelinestate.cpp +++ b/source/core/pipelinestate.cpp @@ -46,9 +46,9 @@ PipelineState::PipelineState(): changes(0) { if(bound_tex_targets.empty()) - bound_tex_targets.resize(Limits::get_global().max_texture_bindings); + bound_tex_targets.resize(DeviceInfo::get_global().limits.max_texture_bindings); if(bound_uniform_blocks.empty()) - bound_uniform_blocks.resize(Limits::get_global().max_uniform_bindings); + bound_uniform_blocks.resize(DeviceInfo::get_global().limits.max_uniform_bindings); } PipelineState::~PipelineState() @@ -228,7 +228,7 @@ void PipelineState::apply(unsigned mask) const if(mask&CLIP_PLANES) { - unsigned max_clip_planes = Limits::get_global().max_clip_planes; + unsigned max_clip_planes = DeviceInfo::get_global().limits.max_clip_planes; for(unsigned i=0; i>i)&1) @@ -338,7 +338,7 @@ void PipelineState::clear() glUseProgram(0); glBindVertexArray(0); - unsigned max_clip_planes = Limits::get_global().max_clip_planes; + unsigned max_clip_planes = DeviceInfo::get_global().limits.max_clip_planes; for(unsigned i=0; ienabled_clip_planes>>i)&1) glDisable(GL_CLIP_PLANE0+i); diff --git a/source/core/texture2dmultisample.cpp b/source/core/texture2dmultisample.cpp index 85fa1950..782a5569 100644 --- a/source/core/texture2dmultisample.cpp +++ b/source/core/texture2dmultisample.cpp @@ -28,7 +28,7 @@ void Texture2DMultisample::storage(PixelFormat fmt, unsigned wd, unsigned ht, un } if(wd==0 || ht==0) throw invalid_argument("Texture2DMultisample::storage"); - if(!sm || sm>Limits::get_global().max_samples) + if(!sm || sm>DeviceInfo::get_global().limits.max_samples) throw invalid_argument("Texture2DMultisample::storage"); set_format(fmt); diff --git a/source/core/uniformblock.cpp b/source/core/uniformblock.cpp index 76d657a1..b06ddf92 100644 --- a/source/core/uniformblock.cpp +++ b/source/core/uniformblock.cpp @@ -19,7 +19,7 @@ UniformBlock::UniformBlock(const ReflectData::UniformBlockInfo &info): unsigned UniformBlock::get_alignment() const { - return Limits::get_global().uniform_buffer_alignment; + return DeviceInfo::get_global().limits.uniform_buffer_alignment; } void UniformBlock::store(const ReflectData::UniformInfo &info, unsigned array_size, const void *value) diff --git a/source/core/vertexsetup.cpp b/source/core/vertexsetup.cpp index f73e2889..55424d6c 100644 --- a/source/core/vertexsetup.cpp +++ b/source/core/vertexsetup.cpp @@ -102,7 +102,7 @@ bool VertexSetup::verify_format(const VertexFormat &fmt) if(fmt.empty()) return false; - unsigned max_attribs = Limits::get_global().max_vertex_attributes; + unsigned max_attribs = DeviceInfo::get_global().limits.max_vertex_attributes; for(VertexAttribute a: fmt) if(get_attribute_semantic(a)>=max_attribs) diff --git a/source/glsl/features.cpp b/source/glsl/features.cpp index db213e83..3c44c11b 100644 --- a/source/glsl/features.cpp +++ b/source/glsl/features.cpp @@ -41,7 +41,7 @@ Features Features::from_context() features.arb_uniform_buffer_object = ARB_uniform_buffer_object; features.ext_gpu_shader4 = EXT_gpu_shader4; features.ext_texture_array = EXT_texture_array; - const Limits &limits = Limits::get_global(); + const Limits &limits = DeviceInfo::get_global().limits; features.uniform_binding_range = limits.max_uniform_bindings; features.texture_binding_range = limits.max_texture_bindings; return features; -- 2.45.2