1
1

common.d 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module three.common;
  2. public import derelict.opengl3.gl3;
  3. public import derelict.glfw3.glfw3;
  4. public import derelict.anttweakbar.anttweakbar;
  5. public import derelict.freeimage.freeimage;
  6. public import derelict.freetype.ft;
  7. public import derelict.assimp3.assimp;
  8. alias SoA(T) = T[];
  9. import std.traits : ReturnType;
  10. ReturnType!func glCheck(alias func, string file = __FILE__, size_t line = __LINE__, string mod = __MODULE__, string funcd = __FUNCTION__, string pretty = __PRETTY_FUNCTION__, Args...)(Args args) nothrow {
  11. import std.stdio;
  12. import std.stdio : stderr;
  13. import std.array : join;
  14. import std.range : repeat;
  15. import std.string : format;
  16. try{
  17. debug scope(exit) {
  18. GLenum err = glGetError();
  19. if(err != GL_NO_ERROR) {
  20. stderr.writeln("\n===============================");
  21. stderr.writeln("File: ", file, "\nLine: ", line, "\nModule: ",mod, "\nFunction: ",funcd, "\n",pretty);
  22. stderr.writeln("-------------------------------");
  23. stderr.writefln(`OpenGL function "%s(%s)" failed: "%s."`, func.stringof, format("%s".repeat(Args.length).join(", "), args), glErrorString(err));
  24. stderr.writeln("=============================== \n");
  25. assert(false);
  26. }
  27. }
  28. }
  29. catch(Exception e){
  30. }
  31. debug if(func is null) {
  32. try{
  33. stderr.writefln("%s is null! OpenGL loaded? Required OpenGL version not supported?".format(func.stringof));
  34. }
  35. catch(Exception e){
  36. assert(false);
  37. }
  38. assert(false);
  39. }
  40. return func(args);
  41. }
  42. string glErrorString(GLenum error) pure @safe nothrow @nogc {
  43. final switch(error) {
  44. case GL_NO_ERROR: return "no error";
  45. case GL_INVALID_ENUM: return "invalid enum";
  46. case GL_INVALID_VALUE: return "invalid value";
  47. case GL_INVALID_OPERATION: return "invalid operation";
  48. //case GL_STACK_OVERFLOW: return "stack overflow";
  49. //case GL_STACK_UNDERFLOW: return "stack underflow";
  50. case GL_INVALID_FRAMEBUFFER_OPERATION: return "invalid framebuffer operation";
  51. case GL_OUT_OF_MEMORY: return "out of memory";
  52. }
  53. assert(false, "invalid enum");
  54. }