System.hx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. package haxe;
  2. class System {
  3. public static var width = 800;
  4. public static var height = 600;
  5. public static var vsync = true;
  6. public static var buffer : haxe.io.Bytes = null;
  7. public static var ctx : mesa.Context;
  8. public static var name = "OSMesa";
  9. public static var savePathPrefix = "";
  10. public static var dataPathPrefix = "";
  11. public static function init() {
  12. var attribs : Array<Int> = [
  13. mesa.Context.FORMAT, mesa.Context.RGBA,
  14. mesa.Context.DEPTH_BITS, 16,
  15. mesa.Context.STENCIL_BITS, 8,
  16. mesa.Context.ACCUM_BITS, 0,
  17. mesa.Context.PROFILE, mesa.Context.CORE_PROFILE,
  18. mesa.Context.CONTEXT_MAJOR_VERSION, 3,
  19. mesa.Context.CONTEXT_MINOR_VERSION, 2,
  20. 0, 0,
  21. ];
  22. ctx = mesa.Context.create(hl.Bytes.getArray(attribs), null);
  23. if( ctx == null )
  24. throw "Failed to create Mesa context";
  25. if( buffer == null )
  26. buffer = haxe.io.Bytes.alloc(width*height*4);
  27. if( !ctx.makeCurrent(buffer, mesa.GL.UNSIGNED_BYTE, width, height) )
  28. throw "Failed to make Mesa current context";
  29. if( !mesa.GL.init() )
  30. throw "Failed to init GL API";
  31. return true;
  32. }
  33. public static dynamic function reportError(e:Dynamic) {
  34. var stack = haxe.CallStack.toString(haxe.CallStack.exceptionStack());
  35. var err = try Std.string(e) catch( _ : Dynamic ) "????";
  36. Sys.println(err + stack);
  37. }
  38. @:extern public static inline function beginFrame() {
  39. }
  40. public static function emitEvents(_) {
  41. return true;
  42. }
  43. public static function present() {
  44. }
  45. }