-#include <stdexcept>
-#include <cstdlib>
#include "backend.h"
-#include "gl.h"
-
-using namespace std;
namespace Msp {
namespace GL {
#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
+#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 {
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
OpenGLDevice(Graphics::Window &, const Graphics::GLOptions &);
+ void fill_info();
+
Graphics::GLContext &get_context() { return context; }
};
+++ /dev/null
-#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
#endif
#include <msp/strings/format.h>
#include <msp/strings/utils.h>
+#include "device.h"
#include "error.h"
#include "extension.h"
#include "gl.h"
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"));
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);
/* 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");
}
}
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);
#include "blend.h"
#include "buffer.h"
#include "depthtest.h"
-#include "deviceinfo.h"
+#include "device.h"
#include "framebuffer.h"
#include "gl.h"
#include "pipelinestate.h"
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()
#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"
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);
#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"
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");
/** 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
DeviceBackend(w, o)
{
current = this;
+
+ info.api = get_backend_api();
+ fill_info();
}
Device::~Device()
#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.
*/
friend DeviceBackend;
private:
+ DeviceInfo info;
+
static Device *current;
public:
~Device();
using DeviceBackend::get_context;
+ const DeviceInfo &get_info() const { return info; }
static Device &get_current();
};
+++ /dev/null
-#include "deviceinfo.h"
-
-namespace Msp {
-namespace GL {
-
-const DeviceInfo &DeviceInfo::get_global()
-{
- static DeviceInfo info;
- return info;
-}
-
-} // namespace GL
-} // namespace Msp
+++ /dev/null
-#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
#include <msp/core/algorithm.h>
#include <msp/io/print.h>
-#include "deviceinfo.h"
+#include "device.h"
#include "module.h"
#include "resources.h"
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;
#include <msp/strings/format.h>
-#include "deviceinfo.h"
+#include "device.h"
#include "error.h"
#include "sampler.h"
{
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;
-#include "deviceinfo.h"
+#include "device.h"
#include "error.h"
#include "texture2dmultisample.h"
}
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);
#include <algorithm>
-#include "deviceinfo.h"
+#include "device.h"
#include "uniformblock.h"
using namespace std;
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)
-#include "deviceinfo.h"
+#include "device.h"
#include "error.h"
#include "vertexarray.h"
#include "vertexsetup.h"
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; });
}