Package playn.core
Class TriangleBatch
java.lang.Object
playn.core.GLBatch
playn.core.TexturedBatch
playn.core.QuadBatch
playn.core.TriangleBatch
- All Implemented Interfaces:
AutoCloseable,Closeable
A batch which renders indexed triangles. It serves as a
QuadBatch, but can also render
arbitrary triangles via addTris(playn.core.Texture, int, pythagoras.f.AffineTransform, float[], int, int, float, float, int[], int, int, int).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThe source for the stock triangle batch shader program.Nested classes/interfaces inherited from interface react.Closeable
Closeable.Set, Closeable.Util -
Field Summary
Fields inherited from class playn.core.TexturedBatch
gl -
Constructor Summary
ConstructorsConstructorDescriptionTriangleBatch(GL20 gl) Creates a triangle batch with the default shader program.TriangleBatch(GL20 gl, TriangleBatch.Source source) Creates a triangle batch with the supplied custom shader program. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddQuad(int tint, float m00, float m01, float m10, float m11, float tx, float ty, float x1, float y1, float sx1, float sy1, float x2, float y2, float sx2, float sy2, float x3, float y3, float sx3, float sy3, float x4, float y4, float sx4, float sy4) Adds a transformed axis-aligned quad to this batch.voidaddTris(float[] xys, float[] sxys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds triangle primitives to a prepared batch.voidaddTris(float[] xys, int xysOffset, int xysLen, float tw, float th, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds triangle primitives to a prepared batch.voidaddTris(Texture tex, int tint, AffineTransform xf, float[] xys, float[] sxys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds a collection of textured triangles to the current render operation.voidaddTris(Texture tex, int tint, AffineTransform xf, float[] xys, int xysOffset, int xysLen, float tw, float th, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds a collection of textured triangles to the current render operation.voidbegin(float fbufWidth, float fbufHeight, boolean flip) Must be called before this batch is used to accumulate and send drawing commands.voidclose()Releases any GPU resources retained by this batch.voidend()Must be called when one is done using this batch to accumulate and send drawing commands.voidflush()Sends any accumulated drawing calls to the GPU.voidprepare(int tint, float m00, float m01, float m10, float m11, float tx, float ty) voidprepare(int tint, AffineTransform xf) Prepares to add primitives with the specified tint and transform.toString()Methods inherited from class playn.core.TexturedBatch
setTexture
-
Constructor Details
-
TriangleBatch
Creates a triangle batch with the default shader program. -
TriangleBatch
Creates a triangle batch with the supplied custom shader program.
-
-
Method Details
-
prepare
Prepares to add primitives with the specified tint and transform. This configuresstableAttrswith all of the attributes that are the same for every vertex. -
prepare
public void prepare(int tint, float m00, float m01, float m10, float m11, float tx, float ty) -
addTris
public void addTris(Texture tex, int tint, AffineTransform xf, float[] xys, int xysOffset, int xysLen, float tw, float th, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds a collection of textured triangles to the current render operation.- Parameters:
xys- a list of x/y coordinates as:[x1, y1, x2, y2, ...].xysOffset- the offset of the coordinates array, must not be negative and no greater thanxys.length. Note: this is an absolute offset; sincexyscontains pairs of values, this will be some multiple of two.xysLen- the number of coordinates to read, must be no less than zero and no greater thanxys.length - xysOffset. Note: this is an absolute length; sincexyscontains pairs of values, this will be some multiple of two.tw- the width of the texture for which we will auto-generate texture coordinates.th- the height of the texture for which we will auto-generate texture coordinates.indices- the index of the triangle vertices in thexysarray. Because this method renders a slice ofxys, one must also specifyindexBasewhich tells us how to interpret indices. The index intoxyswill be computed as:2*(indices[ii] - indexBase), so if your indices reference vertices relative to the whole array you should passxysOffset/2forindexBase, but if your indices reference vertices relative to the slice then you should pass zero.indicesOffset- the offset of the indices array, must not be negative and no greater thanindices.length.indicesLen- the number of indices to read, must be no less than zero and no greater thanindices.length - indicesOffset.indexBase- the basis for interpretingindices. See the docs forindicesfor details.
-
addTris
public void addTris(Texture tex, int tint, AffineTransform xf, float[] xys, float[] sxys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds a collection of textured triangles to the current render operation. SeeaddTris(Texture,int,AffineTransform,float[],int,int,float,float,int[],int,int,int)for parameter documentation.- Parameters:
sxys- a list of sx/sy texture coordinates as:[sx1, sy1, sx2, sy2, ...]. This must be of the same length asxys.
-
addTris
public void addTris(float[] xys, int xysOffset, int xysLen, float tw, float th, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds triangle primitives to a prepared batch. This must be preceded by calls toTexturedBatch.setTexture(playn.core.Texture)andprepare(int, pythagoras.f.AffineTransform)to configure the texture and stable attributes. -
addTris
public void addTris(float[] xys, float[] sxys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) Adds triangle primitives to a prepared batch. This must be preceded by calls toTexturedBatch.setTexture(playn.core.Texture)andprepare(int, pythagoras.f.AffineTransform)to configure the texture and stable attributes. -
addQuad
public void addQuad(int tint, float m00, float m01, float m10, float m11, float tx, float ty, float x1, float y1, float sx1, float sy1, float x2, float y2, float sx2, float sy2, float x3, float y3, float sx3, float sy3, float x4, float y4, float sx4, float sy4) Description copied from class:QuadBatchAdds a transformed axis-aligned quad to this batch.m00, m01, m10, m11, tx, tydefine the affine transform applied to the quad.x1, y1, .., x4, y4define the corners of the quad.sx1, sy1, .., sx4, sy4define the texture coordinate of the quad. -
begin
public void begin(float fbufWidth, float fbufHeight, boolean flip) Description copied from class:GLBatchMust be called before this batch is used to accumulate and send drawing commands. -
flush
public void flush()Description copied from class:GLBatchSends any accumulated drawing calls to the GPU. Depending on the nature of the batch, this may be necessary before certain state changes (like switching to a new texture). This should be a NOOP if there's nothing to flush. -
end
public void end()Description copied from class:GLBatchMust be called when one is done using this batch to accumulate and send drawing commands. The default implementation callsGLBatch.flush()and marks this batch as inactive.- Overrides:
endin classTexturedBatch
-
close
public void close()Description copied from class:GLBatchReleases any GPU resources retained by this batch. This should be called when the batch will never again be used. -
toString
-