Skip to content

Commit

Permalink
Inherit ProgramPosTex from ProgramBase. Add Matrix3D appendRadians
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Nov 30, 2023
1 parent 6497c26 commit a223416
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 7 additions & 0 deletions src/nme/geom/Matrix3D.hx
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ class Matrix3D
this.append(m);
}

public function appendRadians(radians:Float, axis:Vector3D, ?pivotPoint:Vector3D):Matrix3D
{
appendRotation( radians*180/Math.PI, axis, pivotPoint);
return this;
}


inline public function appendScale(xScale:Float, yScale:Float, zScale:Float):Void
{
this.append(new Matrix3D([xScale, 0.0, 0.0, 0.0, 0.0, yScale, 0.0, 0.0, 0.0, 0.0, zScale, 0.0, 0.0, 0.0, 0.0, 1.0]));
Expand Down
15 changes: 7 additions & 8 deletions src/nme/gl/ProgramPosTex.hx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package nme.gl;
import nme.display.BitmapData;
import nme.utils.*;

class ProgramPosTex
class ProgramPosTex extends ProgramBase
{
var prog:GLProgram;

var posLocation:Dynamic;
var mvpLocation:Dynamic;
var texLocation:Dynamic;
var primCount:Int;
var type:Int;
public var posDims:Int;
public var texDims:Int;
var posBuffer:GLBuffer;
Expand Down Expand Up @@ -46,6 +44,7 @@ class ProgramPosTex
fragShader:String, samplerName:String,
inPosDims=2, ?inBitmap:BitmapData)
{
super(GL.TRIANGLES, 0);
prog = Utils.createProgram(vertShader,fragShader);
posLocation = GL.getAttribLocation(prog, posName);
texLocation = GL.getAttribLocation(prog, texName);
Expand All @@ -55,7 +54,7 @@ class ProgramPosTex
posDims = inPosDims;
texDims = 2;
bitmap = inBitmap;
trace("-------------------- mvpLocation : " + mvpLocation);
//trace("-------------------- mvpLocation : " + mvpLocation);
if (bitmap==null)
{
createTexture();
Expand All @@ -74,7 +73,7 @@ class ProgramPosTex
public function setPosTex( pos:Array<Float>, texCoords:Array<Float>, inPrims:Int, inType:Int)
{
primCount = inPrims;
type = inType;
primType = inType;

if (posBuffer==null)
posBuffer = GL.createBuffer();
Expand Down Expand Up @@ -106,7 +105,7 @@ class ProgramPosTex
GL.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, 256, 256, 0, GL.RGBA, GL.UNSIGNED_BYTE, pixels);
}

public function dispose()
override public function dispose()
{
GL.deleteBuffer(posBuffer);
GL.deleteBuffer(texBuffer);
Expand All @@ -124,7 +123,7 @@ class ProgramPosTex
GL.bindTexture(GL.TEXTURE_2D, texture);
}

public function render(?mvp:Float32Array)
override public function render(mvp:Float32Array)
{
GL.useProgram(prog);

Expand All @@ -142,7 +141,7 @@ class ProgramPosTex

GL.enableVertexAttribArray(posLocation);
GL.enableVertexAttribArray(texLocation);
GL.drawArrays(type, 0, primCount);
GL.drawArrays(primType, 0, primCount);
GL.disableVertexAttribArray(texLocation);
GL.disableVertexAttribArray(posLocation);
}
Expand Down

0 comments on commit a223416

Please sign in to comment.