Skip to content
Permalink
Browse files

Update OpenGL Settings

Rename GLSettings to GLContextSettings
  • Loading branch information...
Dgame committed May 31, 2015
1 parent aee98c1 commit 164db7a5c596d10600f9e5879caf39beb1091e4f
@@ -1,32 +1,42 @@
module Dgame.Window.GLSettings;
module Dgame.Window.GLContextSettings;

/**
* The GLSettings structure defines a way to tell OpenGL important user settings,
* The GLContextSettings structure defines a way to tell OpenGL important user settings,
* like the desired major / minor version or the anti aliasing level.
*
* Note: if anti aliasing is activated you will notice a drastic reduction of your framerate.
*
* Author: Randy Schuett (rswhite4@googlemail.com)
*/
struct GLSettings {
struct GLContextSettings {
/**
* The profile of the OpenGL Context
*/
enum Profile : ubyte {
Default, /// profile depends on platform
Compatibility, /// OpenGL compatibility profile - deprecated functions are allowed (default)
Core, /// OpenGL core profile - deprecated functions are disabled
ES, /// OpenGL ES profile - only a subset of the base OpenGL functionality is available
None, /// profile depends on platform
}

/**
* Major Version of OpenGL. 0 means highest possible.
* The supported OpenGL Versions
*/
ubyte majorVersion = 0;
/**
* Minor Version of OpenGL. 0 means highest possible.
*/
ubyte minorVersion = 0;
enum Version : ubyte {
GLXX = 0,
GL21 = 21, ///
GL30 = 30, ///
GL31 = 31, ///
GL32 = 32, ///
GL33 = 33, ///
GL40 = 40, ///
GL41 = 41, ///
GL42 = 42, ///
GL43 = 43, ///
GL44 = 44, ///
GL45 = 45, ///
}

/**
* Anti aliasing level. 0 means deactivated.
*
@@ -35,7 +45,11 @@ struct GLSettings {
*
* Typical values are 2, 4 or 8
*/
ubyte antiAliasLevel = 0;
ubyte antiAlias = 0;
/**
* The OpenGL Version. Default is the highest supported version.
*/
Version vers = Version.GLXX;
/**
* The OpenGL Context profile. Default is Profile.Compatibility
*/
@@ -45,9 +59,9 @@ struct GLSettings {
* CTor
*/
@nogc
this(ubyte major, ubyte minor, ubyte antiAlias) pure nothrow {
this.majorVersion = major;
this.minorVersion = minor;
this.antiAliasLevel = antiAlias;
this(ubyte antiAlias, Version vers = Version.GLXX, Profile profile = Profile.Compatibility) pure nothrow {
this.antiAlias = antiAlias;
this.vers = vers;
this.profile = profile;
}
}
@@ -31,7 +31,7 @@ import derelict.sdl2.ttf;
import derelict.sdl2.image;
import derelict.sdl2.mixer;

import Dgame.Window.GLSettings;
import Dgame.Window.GLContextSettings;
import Dgame.Internal.Error;

shared static this() {
@@ -126,50 +126,60 @@ void _initSDL() {
}

@nogc
void _initGLAttr(GLSettings gl) {
version (OSX) {
if (gl.majorVersion == 0) {
gl.majorVersion = 2;
gl.minorVersion = 1;
void _initGLAttr(const GLContextSettings gl) {
ubyte majorVersion, minorVersion;

if (gl.vers == GLContextSettings.Version.GLXX) {
version (OSX) {
majorVersion = 2;
minorVersion = 1;
}
} else {
majorVersion = gl.vers / 10;
minorVersion = gl.vers % 10;
}

if (gl.majorVersion != 0) {
int result = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl.majorVersion);
if (majorVersion != 0) {
int result = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, majorVersion);
assert_fmt(result == 0, "Error by initializing OpenGL: %s\n", SDL_GetError());

result = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gl.minorVersion);
result = SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, minorVersion);
assert_fmt(result == 0, "Error by initializing OpenGL: %s\n", SDL_GetError());

debug print_fmt("OpenGL Context created in OpenGL version %d.%d\n", majorVersion, minorVersion);
}

final switch (gl.profile) {
case GLSettings.Profile.None:
case GLContextSettings.Profile.Default:
break;
case GLSettings.Profile.Core:
case GLContextSettings.Profile.Core:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
break;
case GLSettings.Profile.Compatibility:
case GLContextSettings.Profile.Compatibility:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
break;
case GLSettings.Profile.ES:
case GLContextSettings.Profile.ES:
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
break;
}

if (gl.antiAliasLevel > 0) {
if (gl.antiAlias > 0) {
debug print_fmt("Set %d as anti alias level\n", gl.antiAlias);

int result = SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
assert_fmt(result == 0, "Error by initializing OpenGL: %s\n", SDL_GetError());

int max_samples;
glGetIntegerv(GL_MAX_SAMPLES, &max_samples);

if (gl.antiAliasLevel > max_samples) {
print_fmt("Your anti-alias level (%d) is too high and will be reduced to %d.\n",gl.antiAliasLevel, max_samples);
gl.antiAliasLevel = cast(ubyte) max_samples;
ubyte antiAlias = gl.antiAlias;
if (antiAlias > max_samples) {
print_fmt("Your anti-alias (%d) is too high and will be reduced to %d.\n",gl.antiAlias, max_samples);
antiAlias = cast(ubyte) max_samples;
}

result = SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, gl.antiAliasLevel);
result = SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, antiAlias);
assert_fmt(result == 0, "Error by initializing OpenGL: %s\n", SDL_GetError());
}

@@ -41,7 +41,7 @@ import Dgame.Math.Rect;
import Dgame.Math.Geometry;

import Dgame.Window.Event;
import Dgame.Window.GLSettings;
import Dgame.Window.GLContextSettings;
import Dgame.Window.DisplayMode;
import Dgame.Window.Internal.Init;

@@ -117,16 +117,16 @@ public:
* CTor
* Position of the Window is default 100x, 100y and the VerticalSync is disabled
*/
this(uint width, uint height, string title, uint style = Style.Default, GLSettings gl = GLSettings.init) {
this(Rect(DefPosX, DefPosY, width, height), title, style);
this(uint width, uint height, string title, uint style = Style.Default, GLContextSettings gl = GLContextSettings.init) {
this(Rect(DefPosX, DefPosY, width, height), title, style, gl);
}

/**
* CTor
* Position is at 100x, 100y and the VerticalSync is enabled, if mode.refreshRate > 0
*/
this(const DisplayMode mode, string title, uint style = Style.Default, GLSettings gl = GLSettings.init) {
this(Rect(DefPosX, DefPosY, mode.width, mode.height), title, style);
this(const DisplayMode mode, string title, uint style = Style.Default, GLContextSettings gl = GLContextSettings.init) {
this(Rect(DefPosX, DefPosY, mode.width, mode.height), title, style, gl);

if (mode.refreshRate > 0)
this.setVerticalSync(VerticalSync.Enable);
@@ -136,7 +136,7 @@ public:
* CTor
* Position is specifiable and the VerticalSync is disabled
*/
this(const Rect view, string title, uint style = Style.Default, GLSettings gl = GLSettings.init) {
this(const Rect view, string title, uint style = Style.Default, GLContextSettings gl = GLContextSettings.init) {
if (_count == 0)
_initSDL();

@@ -4,5 +4,5 @@ public:

import Dgame.Window.DisplayMode;
import Dgame.Window.Event;
import Dgame.Window.GLSettings;
import Dgame.Window.GLContextSettings;
import Dgame.Window.Window;
@@ -0,0 +1,113 @@
<html><head>
<META http-equiv="content-type" content="text/html; charset=utf-8">
<title>Dgame.Window.GLContextSettings</title>
</head><body>
<h1>Dgame.Window.GLContextSettings</h1>
<!-- Generated by Ddoc from ..\Window\GLContextSettings.d -->
<br><br>
<dl><dt><big><a name="GLContextSettings"></a>struct <u>GLContextSettings</u>;
</big></dt>
<dd>The <u>GLContextSettings</u> structure defines a way to tell OpenGL important user settings,
like the desired major / minor version or the anti aliasing level.
<br><br>
<b>Note:</b><br>
if anti aliasing is activated you will notice a drastic reduction of your framerate.

<br><br>
<b>Author:</b><br>
Randy Schuett (rswhite4@googlemail.com)<br><br>

<dl><dt><big><a name="GLContextSettings.Profile"></a>enum <u>Profile</u>: ubyte;
</big></dt>
<dd>The profile of the OpenGL Context<br><br>

<dl><dt><big><a name="GLContextSettings.Profile.Default"></a><u>Default</u></big></dt>
<dd>profile depends on platform<br><br>

</dd>
<dt><big><a name="GLContextSettings.Profile.Compatibility"></a><u>Compatibility</u></big></dt>
<dd>OpenGL compatibility profile - deprecated functions are allowed (default)<br><br>

</dd>
<dt><big><a name="GLContextSettings.Profile.Core"></a><u>Core</u></big></dt>
<dd>OpenGL core profile - deprecated functions are disabled<br><br>

</dd>
<dt><big><a name="GLContextSettings.Profile.ES"></a><u>ES</u></big></dt>
<dd>OpenGL <u>ES</u> profile - only a subset of the base OpenGL functionality is available<br><br>

</dd>
</dl>
</dd>
<dt><big><a name="GLContextSettings.Version"></a>enum <u>Version</u>: ubyte;
</big></dt>
<dd>The supported OpenGL Versions<br><br>

<dl><dt><big><a name="GLContextSettings.Version.GL21"></a><u>GL21</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL30"></a><u>GL30</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL31"></a><u>GL31</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL32"></a><u>GL32</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL33"></a><u>GL33</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL40"></a><u>GL40</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL41"></a><u>GL41</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL42"></a><u>GL42</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL43"></a><u>GL43</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL44"></a><u>GL44</u></big></dt>
<dd><br><br>
</dd>
<dt><big><a name="GLContextSettings.Version.GL45"></a><u>GL45</u></big></dt>
<dd><br><br>
</dd>
</dl>
</dd>
<dt><big><a name="GLContextSettings.antiAlias"></a>ubyte <u>antiAlias</u>;
</big></dt>
<dd>Anti aliasing level. 0 means deactivated.
<br><br>
<b>Note:</b><br>
A too high value may crash your application at the beginning
because your driver does not support it.
<br><br>

Typical values are 2, 4 or 8<br><br>

</dd>
<dt><big><a name="GLContextSettings.vers"></a>Version <u>vers</u>;
</big></dt>
<dd>The OpenGL Version. Default is the highest supported version.<br><br>

</dd>
<dt><big><a name="GLContextSettings.profile"></a>Profile <u>profile</u>;
</big></dt>
<dd>The OpenGL Context <u>profile</u>. Default is Profile.Compatibility<br><br>

</dd>
<dt><big><a name="GLContextSettings.this"></a>pure nothrow @nogc this(ubyte <i>antiAlias</i>, Version <i>vers</i> = Version.GLXX, Profile <i>profile</i> = Profile.Compatibility);
</big></dt>
<dd>CTor<br><br>

</dd>
</dl>
</dd>
</dl>

<hr><small>Page generated by <a href="http://dlang.org/ddoc.html">Ddoc</a>. </small>
</body></html>
@@ -17,39 +17,12 @@ <h1>Dgame.Window.GLSettings</h1>
<b>Author:</b><br>
Randy Schuett (rswhite4@googlemail.com)<br><br>

<dl><dt><big><a name="GLSettings.Profile"></a>enum <u>Profile</u>: ubyte;
<dl><dt><big><a name="GLSettings.vers"></a>GL.Version <u>vers</u>;
</big></dt>
<dd>The profile of the OpenGL Context<br><br>

<dl><dt><big><a name="GLSettings.Profile.Compatibility"></a><u>Compatibility</u></big></dt>
<dd>OpenGL compatibility profile - deprecated functions are allowed (default)<br><br>

</dd>
<dt><big><a name="GLSettings.Profile.Core"></a><u>Core</u></big></dt>
<dd>OpenGL core profile - deprecated functions are disabled<br><br>

</dd>
<dt><big><a name="GLSettings.Profile.ES"></a><u>ES</u></big></dt>
<dd>OpenGL <u>ES</u> profile - only a subset of the base OpenGL functionality is available<br><br>

</dd>
<dt><big><a name="GLSettings.Profile.None"></a><u>None</u></big></dt>
<dd>profile depends on platform<br><br>

</dd>
</dl>
</dd>
<dt><big><a name="GLSettings.majorVersion"></a>ubyte <u>majorVersion</u>;
</big></dt>
<dd>Major Version of OpenGL. 0 means highest possible.<br><br>

</dd>
<dt><big><a name="GLSettings.minorVersion"></a>ubyte <u>minorVersion</u>;
</big></dt>
<dd>Minor Version of OpenGL. 0 means highest possible.<br><br>
<dd>The OpenGL Version. Default is the highest supported version.<br><br>

</dd>
<dt><big><a name="GLSettings.antiAliasLevel"></a>ubyte <u>antiAliasLevel</u>;
<dt><big><a name="GLSettings.antiAlias"></a>ubyte <u>antiAlias</u>;
</big></dt>
<dd>Anti aliasing level. 0 means deactivated.
<br><br>
@@ -61,12 +34,12 @@ <h1>Dgame.Window.GLSettings</h1>
Typical values are 2, 4 or 8<br><br>

</dd>
<dt><big><a name="GLSettings.profile"></a>Profile <u>profile</u>;
<dt><big><a name="GLSettings.profile"></a>GL.Profile <u>profile</u>;
</big></dt>
<dd>The OpenGL Context <u>profile</u>. Default is Profile.Compatibility<br><br>

</dd>
<dt><big><a name="GLSettings.this"></a>pure nothrow @nogc this(ubyte <i>major</i>, ubyte <i>minor</i>, ubyte <i>antiAlias</i>);
<dt><big><a name="GLSettings.this"></a>pure nothrow @nogc this(ubyte <i>antiAlias</i>, GL.Version <i>vers</i> = GL.Version.Default, GL.Profile = GL.Profile.Compatibility);
</big></dt>
<dd>CTor<br><br>

Oops, something went wrong.

0 comments on commit 164db7a

Please sign in to comment.
You can’t perform that action at this time.