mirror of
https://github.com/PixarAnimationStudios/OpenSubdiv
synced 2025-01-11 00:50:10 +00:00
Refs #358. Added helpers functions to determine opengl version.
This commit is contained in:
parent
ff8b1c4148
commit
013a333680
@ -264,6 +264,85 @@ compileShader(GLenum shaderType, const char *source)
|
||||
return shader;
|
||||
}
|
||||
|
||||
///Helper function that parses the open gl version string, retrieving the major
|
||||
///and minor version from it.
|
||||
static void get_major_minor_version(int *major, int *minor){
|
||||
static bool initialized = false;
|
||||
int _major = -1, _minor = -1;
|
||||
if (!initialized || _major == -1 || _minor == -1){
|
||||
const GLubyte *ver = glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
if (!ver){
|
||||
_major = -1;
|
||||
_minor = -1;
|
||||
}
|
||||
else{
|
||||
std::string major_str(ver, ver + 1);
|
||||
std::string minor_str(ver + 2, ver + 3);
|
||||
std::stringstream ss;
|
||||
ss << major_str << " " << minor_str;
|
||||
ss >> _major;
|
||||
ss >> _minor;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
*major = _major;
|
||||
*minor = _minor;
|
||||
|
||||
}
|
||||
|
||||
/** Gets the shader version based on the current opengl version and returns
|
||||
* it in a string form */
|
||||
|
||||
const std::string &get_shader_version(){
|
||||
static bool initialized = false;
|
||||
static std::string shader_version;
|
||||
if (!initialized){
|
||||
|
||||
int major, minor;
|
||||
get_major_minor_version(&major, &minor);
|
||||
int version_number = major * 10 + minor;
|
||||
switch (version_number){
|
||||
case 20:
|
||||
shader_version = "110";
|
||||
break;
|
||||
case 21:
|
||||
shader_version = "120";
|
||||
break;
|
||||
case 30:
|
||||
shader_version = "130";
|
||||
break;
|
||||
case 31:
|
||||
shader_version = "140";
|
||||
break;
|
||||
case 32:
|
||||
shader_version = "150";
|
||||
break;
|
||||
default:
|
||||
std::stringstream ss;
|
||||
ss << version_number;
|
||||
shader_version = ss.str() + "0";
|
||||
break;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
return shader_version;
|
||||
}
|
||||
|
||||
/* Generates the version defintion needed by the glsl shaders based on the
|
||||
* opengl string
|
||||
*/
|
||||
static const std::string &get_shader_version_include(){
|
||||
static bool initialized = false;
|
||||
static std::string include;
|
||||
if (!initialized){
|
||||
include = "#version " + get_shader_version() + "\n";
|
||||
initialized = true;
|
||||
}
|
||||
return include;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static bool
|
||||
linkDefaultProgram() {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user