Package playn.core
Class Surface
java.lang.Object
playn.core.Surface
- All Implemented Interfaces:
AutoCloseable
,Closeable
- Direct Known Subclasses:
TextureSurface
A surface provides a simple drawing API to a GPU accelerated render target. This can be either
the main frame buffer, or a frame buffer bound to a texture.
Note: all rendering operations to a surface must be enclosed in calls to
begin()
and end()
. This ensures that the batch into which
the surface is rendering is properly flushed to the GPU at the right times.
-
Nested Class Summary
Nested classes/interfaces inherited from interface react.Closeable
Closeable.Set, Closeable.Util
-
Constructor Summary
ConstructorsConstructorDescriptionSurface
(Graphics gfx, RenderTarget target, QuadBatch defaultBatch) Creates a surface which will render totarget
usingdefaultBatch
as its default quad renderer. -
Method Summary
Modifier and TypeMethodDescriptionfloat
alpha()
Returns the currently configured alpha.begin()
Starts a series of drawing commands to this surface.clear()
Clears the entire surface to transparent blackness.clear
(float red, float green, float blue, float alpha) Clears the entire surface to the specified color.void
close()
int
combineTint
(int tint) Combinestint
with the current tint viaTint.combine(int, int)
.concatenate
(AffineTransform xf, float originX, float originY) Concatenatesxf
onto this surface's transform, accounting for theorigin
.Draws a tile at the specified location:x, y
.Draws a tile at the specified location(x, y)
and size(w x h)
.Draws a scaled subset of an image (defined by(sx, sy)
and(w x h)
) at the specified location(dx, dy)
and size(dw x dh)
.Draws a tile at the specified location(x, y)
and size(w x h)
, with tinttint
.draw
(Tile tile, int tint, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) Draws a scaled subset of an image (defined by(sx, sy)
and(w x h)
) at the specified location(dx, dy)
and size(dw x dh)
, with tinttint
.drawCentered
(Tile tile, float x, float y) Draws a texture tile, centered at the specified location.drawLine
(float x0, float y0, float x1, float y1, float width) Fills a line between the specified coordinates, of the specified display unit width.Fills a line between the specified coordinates, of the specified display unit width.end()
Completes a series of drawing commands to this surface.void
Ends a series of drawing commands that were clipped per a call tostartClipped(int, int, int, int)
.fillRect
(float x, float y, float width, float height) Fills the specified rectangle.boolean
intersects
(float x, float y, float w, float h) Returns whether the given rectangle intersects the render target area of this surface.void
Restores the batch that was in effect prior to apushBatch(playn.core.QuadBatch)
call.Pre-concatenatesxf
onto this surface's transform.Configures this surface to usebatch
, if non-null.Restores the transform previously stored bysaveTx()
.rotate
(float angle) Rotates the current transformation matrix by the specified angle in radians.saveTx()
Saves the current transform.scale
(float sx, float sy) Scales the current transformation matrix by the specified amount on each axis.setAlpha
(float alpha) Set the alpha component of this surface's current tint.void
setCheckIntersection
(boolean checkIntersection) Configures this surface to check the bounds of drawnTile
s to ensure that they intersect our visible bounds before adding them to our GPU batch.setFillColor
(int color) Sets the color to be used for fill operations.setFillPattern
(Texture texture) Sets the texture to be used for fill operations.setTint
(int tint) Sets the tint to be applied to draw operations, asARGB
.boolean
startClipped
(int x, int y, int width, int height) Starts a series of drawing commands that are clipped to the specified rectangle (in view coordinates, not OpenGL coordinates).int
tint()
Returns the currently configured tint.transform
(float m00, float m01, float m10, float m11, float tx, float ty) Multiplies the current transformation matrix by the given matrix.translate
(float x, float y) Translates the current transformation matrix by the given amount.tx()
Returns the current transform.
-
Constructor Details
-
Surface
Creates a surface which will render totarget
usingdefaultBatch
as its default quad renderer.
-
-
Method Details
-
setCheckIntersection
public void setCheckIntersection(boolean checkIntersection) Configures this surface to check the bounds of drawnTile
s to ensure that they intersect our visible bounds before adding them to our GPU batch. If you draw a lot of totally out of bounds images, this may increase your draw performance. -
begin
Starts a series of drawing commands to this surface. -
end
Completes a series of drawing commands to this surface. -
pushBatch
Configures this surface to usebatch
, if non-null. NOOPs otherwise.- Returns:
- a batch which should be passed to
popBatch(playn.core.QuadBatch)
when rendering is done with this batch.
-
popBatch
Restores the batch that was in effect prior to apushBatch(playn.core.QuadBatch)
call. -
tx
Returns the current transform. -
saveTx
Saves the current transform. -
restoreTx
Restores the transform previously stored bysaveTx()
. -
startClipped
public boolean startClipped(int x, int y, int width, int height) Starts a series of drawing commands that are clipped to the specified rectangle (in view coordinates, not OpenGL coordinates). Thus must be followed by a call toendClipped()
when the clipped drawing commands are done.- Returns:
- whether the resulting clip rectangle is non-empty. Note: the caller may wish
to skip their drawing if this returns false, but they must still call
endClipped()
.
-
endClipped
public void endClipped()Ends a series of drawing commands that were clipped per a call tostartClipped(int, int, int, int)
. -
translate
Translates the current transformation matrix by the given amount. -
scale
Scales the current transformation matrix by the specified amount on each axis. -
rotate
Rotates the current transformation matrix by the specified angle in radians. -
transform
Multiplies the current transformation matrix by the given matrix. -
concatenate
Concatenatesxf
onto this surface's transform, accounting for theorigin
. -
preConcatenate
Pre-concatenatesxf
onto this surface's transform. -
alpha
public float alpha()Returns the currently configured alpha. -
setAlpha
Set the alpha component of this surface's current tint. Note that this value will be quantized to an integer between 0 and 255. Also seesetTint(int)
.Values outside the range [0,1] will be clamped to the range [0,1].
- Parameters:
alpha
- value in range [0,1] where 0 is transparent and 1 is opaque.
-
tint
public int tint()Returns the currently configured tint. -
setTint
Sets the tint to be applied to draw operations, asARGB
. NOTE: this will overwrite any value configured viasetAlpha(float)
. Either include your desired alpha in the high bits oftint
or callsetAlpha(float)
after calling this method. -
combineTint
public int combineTint(int tint) Combinestint
with the current tint viaTint.combine(int, int)
.- Returns:
- the tint prior to combination.
-
setFillColor
Sets the color to be used for fill operations. This replaces any existing fill color or pattern. -
setFillPattern
Sets the texture to be used for fill operations. This replaces any existing fill color or pattern. -
intersects
public boolean intersects(float x, float y, float w, float h) Returns whether the given rectangle intersects the render target area of this surface. -
clear
Clears the entire surface to transparent blackness. -
clear
Clears the entire surface to the specified color. The channels are values in the range[0,1]
. -
draw
Draws a tile at the specified location:x, y
. -
draw
Draws a tile at the specified location(x, y)
and size(w x h)
. -
draw
Draws a tile at the specified location(x, y)
and size(w x h)
, with tinttint
. Note: this will override any tint and alpha currently configured on this surface. -
draw
public Surface draw(Tile tile, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) Draws a scaled subset of an image (defined by(sx, sy)
and(w x h)
) at the specified location(dx, dy)
and size(dw x dh)
. -
draw
public Surface draw(Tile tile, int tint, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) Draws a scaled subset of an image (defined by(sx, sy)
and(w x h)
) at the specified location(dx, dy)
and size(dw x dh)
, with tinttint
. Note: this will override any tint and alpha currently configured on this surface. -
drawCentered
Draws a texture tile, centered at the specified location. -
drawLine
Fills a line between the specified coordinates, of the specified display unit width. -
drawLine
Fills a line between the specified coordinates, of the specified display unit width. -
fillRect
Fills the specified rectangle. -
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-