<NME> ScriptDocument.hx
<BEF> 
class ScriptDocument extends ::APP_MAIN::
{
   public function new()
   {
      #if nme
      var added:nme.display.DisplayObject = null;

      var appMain = Type.resolveClass("ApplicationMain");
      if (appMain!=null)
         Reflect.field(appMain,"setAndroidViewHaxeObject")(this);

      if (Std.is(this, nme.display.DisplayObject))
      {
         added = cast this;
         nme.Lib.current.addChild(cast this);
      }

      super();

      if (added!=null && added.stage!=null)
         added.dispatchEvent(new nme.events.Event(nme.events.Event.ADDED_TO_STAGE, false, false));
      #end
   }
}


<MSG> Add accessor for DisplayObject.matrix. Add polygon offset constants. Add clipping option to triangle programs.

<DFF> @@ -10,7 +10,7 @@ class ScriptDocument extends ::APP_MAIN::
       if (appMain!=null)
          Reflect.field(appMain,"setAndroidViewHaxeObject")(this);
 
-      if (Std.is(this, nme.display.DisplayObject))
+      if (Std.isOfType(this, nme.display.DisplayObject))
       {
          added = cast this;
          nme.Lib.current.addChild(cast this);

{'commit': 'diff --git a/src/nme/display/DisplayObject.hx b/src/nme/display/DisplayObject.hx\nindex f2bd352a..0603f2ad 100644\n--- a/src/nme/display/DisplayObject.hx\n+++ b/src/nme/display/DisplayObject.hx\n@@ -261,6 +261,11 @@ class DisplayObject extends EventDispatcher implements IBitmapDrawable\n       return mtx;\n    }\n \n+   public function fillMatrix(outMatrix:Matrix, concatenated:Bool) : Void\n+   {\n+      nme_display_object_get_matrix(nmeHandle, outMatrix, concatenated);\n+   }\n+\n    /** @private */ public function nmeGetInteractiveObjectStack(outStack:Array<InteractiveObject>) {\n       var io = nmeAsInteractiveObject();\n \ndiff --git a/src/nme/geom/Matrix3D.hx b/src/nme/geom/Matrix3D.hx\nindex 542ff8b1..ea179003 100644\n--- a/src/nme/geom/Matrix3D.hx\n+++ b/src/nme/geom/Matrix3D.hx\n@@ -202,6 +202,9 @@ class Matrix3D\n \n    }\n \n+   public function oglString(join=\'\\n\')\n+      return \'[ $mxx $myx $mzx $mwz ]$join[ $mxy $myy $mzy $mwy ]$join[ $mxz $myz $mzz $mwz ]$join[ $tx $ty $tz $tw ]\';\n+\n \n    public function copyRowFrom( row:UInt, vector3D:Vector3D ) {\n \n@@ -414,10 +417,10 @@ class Matrix3D\n       }\n    }\n \n-   inline public function invert():Bool \n+   inline public function invert(minDet = 1e-11):Bool \n    {\n       var d = determinant;\n-      var invertable = Math.abs(d) > 0.00000000001;\n+      var invertable = Math.abs(d) > minDet;\n \n       if (invertable) \n       {\ndiff --git a/src/nme/geom/Vector3D.hx b/src/nme/geom/Vector3D.hx\nindex 8d6f5c69..84acdbbc 100644\n--- a/src/nme/geom/Vector3D.hx\n+++ b/src/nme/geom/Vector3D.hx\n@@ -34,6 +34,8 @@ class Vector3D\n       return this;\n    }\n \n+   inline public function toPoint() return new Point(x,y);\n+\n    inline public function add(a:Vector3D):Vector3D \n    {\n       return new Vector3D(this.x + a.x, this.y + a.y, this.z + a.z);\ndiff --git a/src/nme/gl/GL.hx b/src/nme/gl/GL.hx\nindex 82559530..07e94b7e 100644\n--- a/src/nme/gl/GL.hx\n+++ b/src/nme/gl/GL.hx\n@@ -227,7 +227,8 @@ class GL\n    public static inline var DEPTH_BITS                     = 0x0D56;\n    public static inline var STENCIL_BITS                   = 0x0D57;\n    public static inline var POLYGON_OFFSET_UNITS           = 0x2A00;\n-   /*      POLYGON_OFFSET_FILL */\n+   public static inline var POLYGON_OFFSET_POINT           = 0x2A01;\n+   public static inline var POLYGON_OFFSET_LINE            = 0x2A02;\n    public static inline var POLYGON_OFFSET_FACTOR          = 0x8038;\n    public static inline var TEXTURE_BINDING_2D             = 0x8069;\n    public static inline var SAMPLE_BUFFERS                 = 0x80A8;\n@@ -764,6 +765,8 @@ class GL\n    public static inline var TIMEOUT_IGNORED = -1;\n    public static inline var MAX_CLIENT_WAIT_TIMEOUT_WEBGL = 0x9247;\n \n+   public static inline var CLIP_DISTANCE0 = 0x3000;\n+\n \n    #if (neko||cpp)\n \ndiff --git a/src/nme/gl/ProgramBase.hx b/src/nme/gl/ProgramBase.hx\nindex 231bce11..e0f12ada 100644\n--- a/src/nme/gl/ProgramBase.hx\n+++ b/src/nme/gl/ProgramBase.hx\n@@ -1,6 +1,7 @@\n package nme.gl;\r\n \r\n import nme.geom.Matrix3D;\r\n+import nme.geom.Vector3D;\r\n import nme.utils.*;\r\n import nme.gl.GL;\r\n \r\n@@ -21,6 +22,32 @@ class ProgramBase\n \r\n    public function renderMtx(mvp:Matrix3D) render( Float32Array.fromMatrix(mvp) );\r\n \r\n+   public function renderClipped(mvp:Float32Array, plane:Vector3D) render(mvp);\r\n+\r\n+\r\n+   public static function lineCount(vertices:Float32Array, colours:Int32Array)\r\n+   {\r\n+      var count = vertices.length;\r\n+      if (count<1 || (count%6>0))\r\n+         throw "vertices length should be a multiple of 6";\r\n+      count = Std.int(count/3);\r\n+      if (colours.length!=count)\r\n+         throw "There should be one colour per vertex";\r\n+      return count;\r\n+   }\r\n+\r\n+   public static function triangleCount(vertices:Float32Array, colours:Int32Array)\r\n+   {\r\n+      var count = vertices.length;\r\n+      if (count<1 || (count%9>0))\r\n+         throw "vertices length should be a multiple of 9";\r\n+      count = Std.int(count/3);\r\n+      if (colours.length!=count)\r\n+         throw "There should be one colour per vertex";\r\n+      return count;\r\n+   }\r\n+\r\n+\r\n }\r\n \r\n \r\ndiff --git a/src/nme/gl/ProgramTPosCol.hx b/src/nme/gl/ProgramTPosCol.hx\nindex df4e6b89..30ea9fa2 100644\n--- a/src/nme/gl/ProgramTPosCol.hx\n+++ b/src/nme/gl/ProgramTPosCol.hx\n@@ -1,24 +1,38 @@\n package nme.gl;\r\n \r\n import nme.geom.Matrix3D;\r\n+import nme.geom.Vector3D;\r\n import nme.utils.*;\r\n import nme.gl.GL;\r\n \r\n // Used for drawing geometry using a view matrix and constant colour\r\n class ProgramTPosCol extends ProgramBase\r\n {\r\n-   static var prog:GLProgram;\r\n-   static var posLocation:Dynamic;\r\n-   static var colLocation:Dynamic;\r\n-   static var mvpLocation:Dynamic;\r\n+   static var progClipped:GLProgram;\r\n+   static var posLocationClip:Dynamic;\r\n+   static var colLocationClip:Dynamic;\r\n+   static var mvpLocationClip:Dynamic;\r\n+\r\n+   static var progUnclipped:GLProgram;\r\n+   static var posLocationUnclip:Dynamic;\r\n+   static var colLocationUnclip:Dynamic;\r\n+   static var mvpLocationUnclip:Dynamic;\r\n+\r\n+   static var clipLocation:Dynamic;\r\n+   var posLocation:Dynamic;\r\n+   var colLocation:Dynamic;\r\n+   var mvpLocation:Dynamic;\r\n \r\n    var posBuffer:GLBuffer;\r\n    var colBuffer:GLBuffer;\r\n+   var clipped:Bool;\r\n+   var prog:GLProgram;\r\n \r\n-   public function new(inVertices:Float32Array, inColours:Int32Array, inPrim:Int, inPrimCount:Int)\r\n+   public function new(inVertices:Float32Array, inColours:Int32Array, inPrim:Int, inPrimCount:Int,inClipped=false)\r\n    {\r\n       super(inPrim, inPrimCount);\r\n \r\n+      clipped = inClipped;\r\n       posBuffer = GL.createBuffer();\r\n       GL.bindBuffer(GL.ARRAY_BUFFER, posBuffer);\r\n       GL.bufferData(GL.ARRAY_BUFFER, inVertices, GL.STATIC_DRAW);\r\n@@ -29,19 +43,28 @@ class ProgramTPosCol extends ProgramBase\n \r\n       GL.bindBuffer(GL.ARRAY_BUFFER, null);\r\n \r\n+      prog = clipped ? progClipped : progUnclipped;\r\n+\r\n       if (prog==null || !prog.valid)\r\n       {\r\n-           var vertShader =\r\n+         var vertShader =\r\n               "in vec3 pos;" +\r\n               "in vec4 col;" + \r\n-              "out vec4 pCol;" + \r\n               "uniform mat4 mvp;" +\r\n+              (clipped ? "uniform vec4 clip;" : "") +\r\n+              "out vec4 pCol;" + \r\n               "void main() {" +\r\n               " pCol = col;" +\r\n-              " gl_Position = mvp * vec4(pos, 1.0);" +\r\n+              " vec4 p4 = vec4(pos, 1.0);" +\r\n+              " gl_Position = mvp * p4;";\r\n+\r\n+         if (clipped)\r\n+             vertShader += " gl_ClipDistance[0] = dot(p4,clip);";\r\n+\r\n+         vertShader +=\r\n               "}";\r\n \r\n-            var fragShader =\r\n+         var fragShader =\r\n               #if !desktop \'precision mediump float;\' + #end\r\n               "in vec4 pCol;" + \r\n               "void main() {" +\r\n@@ -52,6 +75,36 @@ class ProgramTPosCol extends ProgramBase\n          posLocation = GL.getAttribLocation(prog, "pos");\r\n          colLocation = GL.getAttribLocation(prog, "col");\r\n          mvpLocation = GL.getUniformLocation(prog, "mvp");\r\n+\r\n+         if (clipped)\r\n+            clipLocation = GL.getUniformLocation(prog, "clip");\r\n+\r\n+         if (clipped)\r\n+         {\r\n+            progClipped = prog;\r\n+            posLocationClip = posLocation;\r\n+            mvpLocationClip = mvpLocation;\r\n+            colLocationClip = colLocation;\r\n+         }\r\n+         else\r\n+         {\r\n+            progUnclipped = prog;\r\n+            posLocationUnclip = posLocation;\r\n+            mvpLocationUnclip = mvpLocation;\r\n+            colLocationUnclip = colLocation;\r\n+         }\r\n+      }\r\n+      else if (clipped)\r\n+      {\r\n+         posLocation = posLocationClip;\r\n+         mvpLocation = mvpLocationClip;\r\n+         colLocation = colLocationClip;\r\n+      }\r\n+      else\r\n+      {\r\n+         posLocation = posLocationUnclip;\r\n+         mvpLocation = mvpLocationUnclip;\r\n+         colLocation = colLocationUnclip;\r\n       }\r\n    }\r\n \r\n@@ -62,7 +115,9 @@ class ProgramTPosCol extends ProgramBase\n    }\r\n \r\n \r\n-   override public function render(mvp:Float32Array)\r\n+   override public function render(mvp:Float32Array) renderClipped(mvp,null);\r\n+\r\n+   override public function renderClipped(mvp:Float32Array, plane:Vector3D)\r\n    {\r\n       GL.useProgram(prog);\r\n \r\n@@ -76,34 +131,33 @@ class ProgramTPosCol extends ProgramBase\n \r\n       GL.uniformMatrix4fv(mvpLocation, false, mvp);\r\n \r\n+      if (clipped && plane!=null)\r\n+      {\r\n+         GL.uniform4f(clipLocation, plane.x, plane.y, plane.z, plane.w);\r\n+         GL.enable(GL.CLIP_DISTANCE0);\r\n+      }\r\n+\r\n       GL.drawArrays(primType, 0, primCount);\r\n \r\n       GL.disableVertexAttribArray(posLocation);\r\n       GL.disableVertexAttribArray(colLocation);\r\n       GL.bindBuffer(GL.ARRAY_BUFFER, null);\r\n+\r\n+      if (clipped && plane!=null)\r\n+         GL.disable(GL.CLIP_DISTANCE0);\r\n    }\r\n \r\n \r\n-   public static function createLines(vertices:Float32Array, colours:Int32Array)\r\n+   public static function createLines(vertices:Float32Array, colours:Int32Array,clipped=false)\r\n    {\r\n-      var count = vertices.length;\r\n-      if (count<1 || (count%6>0))\r\n-         throw "vertices length should be a multiple of 6";\r\n-      count = Std.int(count/3);\r\n-      if (colours.length!=count)\r\n-         throw "There should be one colour per vertex";\r\n-      return new ProgramTPosCol(vertices, colours, GL.LINES, count);\r\n+      var count = ProgramBase.lineCount(vertices,colours);\r\n+      return new ProgramTPosCol(vertices, colours, GL.LINES, count,clipped);\r\n    }\r\n \r\n-   public static function createTriangles(vertices:Float32Array, colours:Int32Array)\r\n+   public static function createTriangles(vertices:Float32Array, colours:Int32Array,clipped=false)\r\n    {\r\n-      var count = vertices.length;\r\n-      if (count<1 || (count%9>0))\r\n-         throw "vertices length should be a multiple of 9";\r\n-      count = Std.int(count/3);\r\n-      if (colours.length!=count)\r\n-         throw "There should be one colour per vertex";\r\n-      return new ProgramTPosCol(vertices, colours, GL.TRIANGLES, count);\r\n+      var count = ProgramBase.triangleCount(vertices,colours);\r\n+      return new ProgramTPosCol(vertices, colours, GL.TRIANGLES, count,clipped);\r\n    }\r\n \r\n }\r\ndiff --git a/templates/script/ScriptDocument.hx b/templates/script/ScriptDocument.hx\nindex f48924cc..9c10ae98 100644\n--- a/templates/script/ScriptDocument.hx\n+++ b/templates/script/ScriptDocument.hx\n@@ -10,7 +10,7 @@ class ScriptDocument extends ::APP_MAIN::\n       if (appMain!=null)\r\n          Reflect.field(appMain,"setAndroidViewHaxeObject")(this);\r\n \r\n-      if (Std.is(this, nme.display.DisplayObject))\r\n+      if (Std.isOfType(this, nme.display.DisplayObject))\r\n       {\r\n          added = cast this;\r\n          nme.Lib.current.addChild(cast this);\r\n', 'commit_subject': 'Add accessor for DisplayObject.matrix. Add polygon offset constants. Add clipping option to triangle programs.', 'repo_name': 'haxenme/nme', 'committer': {'name': 'Hugh Sanderson', 'email': 'addcc332247940d36e349261d1b5f2717fc37e0e@gmail.com', 'time_sec': '1617594949', 'tz_offset': '480', 'date': {'seconds': '1617594949'}}, 'commit_tree': '0a3741955aadb0864fad3c31e938d9dcbb884b36', 'commit_message': 'Add accessor for DisplayObject.matrix. Add polygon offset constants. Add clipping option to triangle programs.\n', 'language_name': 'Java', 'license': 'mit', 'hunks': '@@ -10,7 +10,7 @@ class ScriptDocument extends ::APP_MAIN::\n       if (appMain!=null)\r\n          Reflect.field(appMain,"setAndroidViewHaxeObject")(this);\r\n \r\n-      if (Std.is(this, nme.display.DisplayObject))\r\n+      if (Std.isOfType(this, nme.display.DisplayObject))\r\n       {\r\n          added = cast this;\r\n          nme.Lib.current.addChild(cast this);\r\n', 'addition_count': 1, 'deletion_count': 1, 'src_file': 'a/templates/script/ScriptDocument.hx', 'tgt_file': 'b/templates/script/ScriptDocument.hx', 'file_extension': '.hx', 'before_file': '\nclass ScriptDocument extends ::APP_MAIN::\n{\n   public function new()\n   {\n      #if nme\n      var added:nme.display.DisplayObject = null;\n\n      var appMain = Type.resolveClass("ApplicationMain");\n      if (appMain!=null)\r\n         Reflect.field(appMain,"setAndroidViewHaxeObject")(this);\r\n\r\n      if (Std.is(this, nme.display.DisplayObject))\r\n      {\r\n         added = cast this;\r\n         nme.Lib.current.addChild(cast this);\r\n      }\n\n      super();\n\n      if (added!=null && added.stage!=null)\n         added.dispatchEvent(new nme.events.Event(nme.events.Event.ADDED_TO_STAGE, false, false));\n      #end\n   }\n}\n\n', 'message': 'Add accessor for DisplayObject.matrix. Add polygon offset constants. Add clipping option to triangle programs.\n', 'author_name': 'Hugh Sanderson', 'lang': 'hx'}