#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"
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");
#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"
{
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);
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
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
#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"
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);
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 &);
--- /dev/null
+#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
--- /dev/null
+#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
#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;
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)
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);
/** 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
#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"
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)
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 ¤t();
static TexUnit *find_unit(const Texture *);
#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"
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
#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"
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;
#include "buffer.h"
#include "camera.h"
#include "clipping.h"
+#include "deviceinfo.h"
#include "error.h"
#include "lighting.h"
#include "material.h"
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),