-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from outlandkarasu/64-create-opengl-context
close #64 create opengl context
- Loading branch information
Showing
9 changed files
with
275 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
Warabe OpenGL exception. | ||
*/ | ||
module warabe.opengl.exception; | ||
|
||
import std.string : fromStringz; | ||
|
||
import bindbc.opengl : glGetError; | ||
|
||
import warabe.exception : WarabeException; | ||
|
||
/** | ||
OpenGL related exception. | ||
*/ | ||
class OpenGLException : WarabeException | ||
{ | ||
/** | ||
construct by message. | ||
Params: | ||
msg = exception message. | ||
file = file name. | ||
line = source line number. | ||
nextInChain = exception chain. | ||
*/ | ||
@nogc nothrow pure @safe | ||
this(string msg, string file = __FILE__, size_t line = __LINE__, Throwable nextInChain = null) | ||
{ | ||
super(msg, file, line, nextInChain); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
OpenGL load module. | ||
*/ | ||
module warabe.opengl.load; | ||
|
||
import std.traits : isCallable; | ||
|
||
static import bindbc.opengl; | ||
|
||
import warabe.opengl.exception : OpenGLException; | ||
|
||
/** | ||
load OpenGL library and using it. | ||
Params: | ||
F = function using OpenGL. | ||
*/ | ||
void usingOpenGL(alias F)() if(isCallable!F) | ||
{ | ||
loadOpenGL(); | ||
scope(exit) unloadOpenGL(); | ||
|
||
F(); | ||
} | ||
|
||
private: | ||
|
||
/** | ||
load OpenGL library. | ||
*/ | ||
void loadOpenGL() @system | ||
{ | ||
immutable loadedVersion = bindbc.opengl.loadOpenGL(); | ||
if (loadedVersion == bindbc.opengl.GLSupport.noLibrary) | ||
{ | ||
throw new OpenGLException("OpenGL not found."); | ||
} | ||
else if (loadedVersion == bindbc.opengl.GLSupport.badLibrary) | ||
{ | ||
throw new OpenGLException("OpenGL bad library."); | ||
} | ||
else if (loadedVersion == bindbc.opengl.GLSupport.noContext) | ||
{ | ||
throw new OpenGLException("OpenGL no context."); | ||
} | ||
} | ||
|
||
/** | ||
unload OpenGL library. | ||
*/ | ||
void unloadOpenGL() @system | ||
{ | ||
bindbc.opengl.unloadOpenGL(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
OpenGL package. | ||
*/ | ||
module warabe.opengl; | ||
|
||
public import warabe.opengl.load; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.