--- /dev/null
+#include <stdexcept>
+#include <cstdlib>
+#include <msp/strings/lexicalcast.h>
+#include <msp/strings/utils.h>
+#include "backend.h"
+#include "gl.h"
+
+using namespace std;
+
+namespace Msp {
+namespace GL {
+
+Version::Version()
+{
+ major = 0;
+ minor = 0;
+}
+
+Version::Version(unsigned short a, unsigned short i)
+{
+ major = a;
+ minor = i;
+}
+
+Version::Version(const string &s)
+{
+ vector<string> parts = split(s, '.');
+ major = lexical_cast<unsigned>(parts[0]);
+ minor = lexical_cast<unsigned>(parts[1]);
+}
+
+bool Version::operator>=(const Version &other) const
+{
+ return major>other.major || (major==other.major && minor>=other.minor);
+}
+
+
+GraphicsApi get_backend_api()
+{
+#ifdef GL_ES_VERSION_2_0
+ return OPENGL_ES;
+#else
+ return OPENGL;
+#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
--- /dev/null
+#ifndef MSP_GL_BACKEND_H_
+#define MSP_GL_BACKEND_H_
+
+#include <string>
+
+namespace Msp {
+namespace GL {
+
+enum GraphicsApi
+{
+ OPENGL,
+ OPENGL_ES
+};
+
+struct Version
+{
+ unsigned short major;
+ unsigned short minor;
+
+ Version();
+ Version(unsigned short, unsigned short);
+ Version(const std::string &);
+
+ bool operator>=(const Version &) const;
+ bool operator<(const Version &o) const { return !(*this>=o); }
+ operator bool() const { return major || minor; }
+};
+
+/** 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
+
+#endif
DeviceInfo::DeviceInfo()
{
- glsl_features.gl_api = get_gl_api();
+ 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;
namespace Msp {
namespace GL {
-Version::Version()
-{
- major = 0;
- minor = 0;
-}
-
-Version::Version(unsigned short a, unsigned short i)
-{
- major = a;
- minor = i;
-}
-
-Version::Version(const string &s)
-{
- vector<string> parts = split(s, '.');
- major = lexical_cast<unsigned>(parts[0]);
- minor = lexical_cast<unsigned>(parts[1]);
-}
-
-bool Version::operator>=(const Version &other) const
-{
- return major>other.major || (major==other.major && minor>=other.minor);
-}
-
-
Extension::Extension(const char *n, InitFunc f):
name(n),
init_func(f),
if(!init_done)
{
- if(get_gl_api()==OPENGL && get_gl_version()>=Version(3, 0))
+ if(get_backend_api()==OPENGL && get_backend_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_gl_version();
+ const Version &version = get_backend_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_gl_version()<Version(2, 0))
+ if(get_backend_version()<Version(2, 0))
disabled_exts.insert("GL_ARB_uniform_buffer_object");
}
}
return disabled_exts.count(ext);
}
-GLApi get_gl_api()
-{
-#ifdef GL_ES_VERSION_2_0
- return OPENGL_ES2;
-#else
- return OPENGL;
-#endif
-}
-
inline GLProfile _get_gl_profile()
{
- if(get_gl_api()==OPENGL && get_gl_version()>=Version(3, 0))
+ if(get_backend_api()==OPENGL && get_backend_version()>=Version(3, 0))
{
int mask;
glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &mask);
return profile;
}
-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_gl_version()
-{
- static Version version = _get_gl_version();
- return version;
-}
-
inline Version _get_glsl_version()
{
const char *glsl_ver_ptr = reinterpret_cast<const char *>(glGetString(GL_SHADING_LANGUAGE_VERSION));
#define MSP_GL_EXTENSION_H_
#include <string>
+#include "backend.h"
namespace Msp {
namespace GL {
-enum GLApi
-{
- OPENGL,
- OPENGL_ES2
-};
-
enum GLProfile
{
CORE_PROFILE,
};
-struct Version
-{
- unsigned short major;
- unsigned short minor;
-
- Version();
- Version(unsigned short, unsigned short);
- Version(const std::string &);
-
- bool operator>=(const Version &) const;
- bool operator<(const Version &o) const { return !(*this>=o); }
- operator bool() const { return major || minor; }
-};
-
-
/**
Holds metadata about an extension. Evaluates to true if the extension is
supported.
for a driver bug. Only intended for internal use. */
bool is_disabled(const std::string &);
-/** Returns the API for which the library was compiled. */
-GLApi get_gl_api();
-
/** Returns the OpenGL profile for the active context. */
GLProfile get_gl_profile();
-/** Returns the OpenGL version number, as reported by the implementation. */
-const Version &get_gl_version();
-
/** Returns the GLSL version number, as reported by the implementation. */
const Version &get_glsl_version();
if(swizzle==NO_SWIZZLE)
return;
- if(get_gl_api()==OPENGL_ES2)
+ if(get_backend_api()==OPENGL_ES)
{
set_parameter_i(GL_TEXTURE_SWIZZLE_R, swizzle_orders[swizzle*4]);
set_parameter_i(GL_TEXTURE_SWIZZLE_G, swizzle_orders[swizzle*4+1]);
void Compiler::generate(Stage &stage)
{
- stage.required_features.gl_api = features.gl_api;
+ stage.required_features.target_api = features.target_api;
if(module->shared.required_features.glsl_version>stage.required_features.glsl_version)
stage.required_features.glsl_version = module->shared.required_features.glsl_version;
namespace SL {
Features::Features():
- gl_api(OPENGL),
+ target_api(OPENGL),
arb_enhanced_layouts(false),
arb_explicit_attrib_location(false),
arb_explicit_uniform_location(false),
Features Features::from_version(const Version &ver)
{
Features features;
- features.gl_api = OPENGL;
+ features.target_api = OPENGL;
features.glsl_version = ver;
features.arb_enhanced_layouts = (ver>=Version(4, 40));
features.arb_explicit_attrib_location = (ver>=Version(1, 30));
#ifndef MSP_GL_SL_FEATURES_H_
#define MSP_GL_SL_FEATURES_H_
-#include <msp/gl/extension.h>
+#include <msp/gl/backend.h>
namespace Msp {
namespace GL {
struct Features
{
- GLApi gl_api;
+ GraphicsApi target_api;
Version glsl_version;
bool arb_enhanced_layouts;
bool arb_explicit_attrib_location;
void PrecisionConverter::visit(Precision &prec)
{
- if(stage->required_features.gl_api==OPENGL_ES2)
+ if(stage->required_features.target_api==OPENGL_ES)
have_default.insert(prec.type);
else
nodes_to_remove.insert(&prec);
void PrecisionConverter::visit(VariableDeclaration &var)
{
- if(stage->required_features.gl_api!=OPENGL_ES2)
+ if(stage->required_features.target_api!=OPENGL_ES)
{
var.precision.clear();
return;
NodeRemover().apply(s, nodes_to_remove);
if(!stage->required_features.glsl_version)
- stage->required_features.glsl_version = Version(1, (stage->required_features.gl_api==OPENGL_ES2 ? 0 : 10));
+ stage->required_features.glsl_version = Version(1, (stage->required_features.target_api==OPENGL_ES ? 0 : 10));
}
else
unsupported(format("Stage %s is not supported", Stage::get_stage_name(s.type)));
{
if(st==Stage::GEOMETRY)
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 20));
else
return check_version(Version(1, 50));
bool LegacyConverter::supports_unified_interface_syntax() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 0));
else
return check_version(Version(1, 30));
bool LegacyConverter::supports_unified_sampling_functions() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 0));
else
return check_version(Version(1, 30));
bool LegacyConverter::supports_interface_layouts() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 0));
else if(check_version(Version(3, 30)))
return true;
bool LegacyConverter::supports_stage_interface_layouts() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 10));
else if(check_version(Version(4, 10)))
return true;
bool LegacyConverter::supports_centroid_sampling() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 0));
else if(check_version(Version(1, 20)))
return true;
bool LegacyConverter::supports_sample_sampling() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 20));
else if(check_version(Version(4, 0)))
return true;
bool LegacyConverter::supports_uniform_location() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 10));
else if(check_version(Version(4, 30)))
return true;
bool LegacyConverter::supports_binding() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 10));
else
return check_version(Version(4, 20));
bool LegacyConverter::supports_interface_blocks(const string &iface) const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
{
if(iface=="uniform")
return check_version(Version(3, 0));
bool LegacyConverter::supports_interface_block_location() const
{
- if(features.gl_api==OPENGL_ES2)
+ if(features.target_api==OPENGL_ES)
return check_version(Version(3, 20));
else if(check_version(Version(4, 40)))
return true;
if(ver)
{
append(format("#version %d%02d", ver.major, ver.minor));
- if(s.required_features.gl_api==OPENGL_ES2 && ver>=Version(3, 0))
+ if(s.required_features.target_api==OPENGL_ES && ver>=Version(3, 0))
append(" es");
formatted += '\n';
}