Skip to content
This repository has been archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
Implement auto detection of max. supported OpenGL version
Browse files Browse the repository at this point in the history
  • Loading branch information
Dgame committed Jun 5, 2015
1 parent 23d8480 commit e518cce
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
3 changes: 2 additions & 1 deletion source/Dgame/Window/GLContextSettings.d
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ struct GLContextSettings {
/**
* The supported OpenGL Versions
*/
enum Version : ubyte {
enum Version : byte {
Default = -1,
GLXX = 0, /// Highest supported version
GL21 = 21, ///
GL30 = 30, ///
Expand Down
48 changes: 48 additions & 0 deletions source/Dgame/Window/Internal/Init.d
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,50 @@ shared static ~this() {
bool _isGLInited = false;
bool _isSDLInited = false;

GLVersion findMaxAvailable() {
const char* verstr = glGetString(GL_VERSION);
char major = *verstr;
char minor = *(verstr + 2);

switch (major) {
case '4':
switch (minor) {
case '5':
return GLVersion.GL45;
case '4':
return GLVersion.GL44;
case '3':
return GLVersion.GL43;
case '2':
return GLVersion.GL42;
case '1':
return GLVersion.GL41;
default:
return GLVersion.GL40;
}
case '3':
switch (minor) {
case '3':
return GLVersion.GL33;
case '2':
return GLVersion.GL32;
case '1':
return GLVersion.GL31;
default:
return GLVersion.GL30;
}
case '2':
switch (minor) {
case '1':
return GLVersion.GL21;
default:
return GLVersion.GL20;
}
default:
assert(0, "No valid OpenGL version could not be detected");
}
}

package(Dgame):

void _initSDL() {
Expand Down Expand Up @@ -130,6 +174,10 @@ void _initGLAttr(const GLContextSettings gl) {
ubyte majorVersion, minorVersion;

if (gl.vers == GLContextSettings.Version.GLXX) {
const GLVersion vers = findMaxAvailable();
majorVersion = vers / 10;
minorVersion = vers % 10;
} else if (gl.vers == GLContextSettings.Version.Default) {
version (OSX) {
majorVersion = 2;
minorVersion = 1;
Expand Down

0 comments on commit e518cce

Please sign in to comment.