/** * Updates this image's default texture with the current contents of the image, and returns the * texture. If the texture has not yet been created, then this simply creates it. This is only * necessary if you want to update the default texture for an image associated with a {@link * Canvas}, or if you have used {@link #setRgb} to change the contents of this image. */ public Texture updateTexture () { if (texture == null || texture.disposed()) texture = createTexture(texconf); else texture.update(this); return texture; }
/** Decrements this texture's reference count. If the reference count of a managed texture goes * to zero, the texture is disposed (and is no longer usable). */ public void release () { if (config.managed) { assert refs > 0 : "Released a texture with no references!"; if (--refs == 0) close(); } }
/** Returns {@code sourceWidth} rounded up to a POT if necessary. */ public int toTexWidth (int sourceWidth) { return (repeatX || mipmaps) ? nextPOT(sourceWidth) : sourceWidth; } /** Returns {@code sourceHeight} rounded up to a POT if necessary. */
@Override public Tile tile () { if (tile == null) tile = image.texture().tile(rx, ry, rwidth, rheight); return tile; } @Override public RFuture<Tile> tileAsync () {
/** * Creates a texture with this image's bitmap data using {@code config}. NOTE: this creates a new * texture with every call. This is generally only needed if you plan to create multiple textures * from the same bitmap, with different configurations. Otherwise just use {@link #texture} to * create the image's "default" texture which will be shared by all callers. */ public Texture createTexture (Texture.Config config) { if (!isLoaded()) throw new IllegalStateException( "Cannot create texture from unready image: " + this); int texWidth = config.toTexWidth(pixelWidth()); int texHeight = config.toTexHeight(pixelHeight()); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " + texWidth + "x" + texHeight + " from: " + this); Texture tex = new Texture(gfx, gfx.createTexture(config), config, texWidth, texHeight, scale(), width(), height()); tex.update(this); // this will handle non-POT source image conversion return tex; }
protected void paintImpl (Surface surf) { // fill some shapes with patterns surf.setFillPattern(ttex).fillRect(10, 0, 100, 100); // render a sliding window of half of our triangles to test the slice rendering triangleBatch.addTris(ttex, Tint.NOOP_TINT, af, verts, offset*4, (hsamples+1)*4, ttex.width(), ttex.height(), indices, offset*6, hsamples*6, offset*2); offset += doff; if (offset == 0) doff = 1; else if (offset == hsamples) doff = -1; } private int offset = 0, doff = 1;
/** * Sets the texture rendered by this layer. One can supplied {@code null} to release and clear * any texture currently being rendered and leave this layer in an uninitialized state. This * isn't something one would normally do, but could be useful if one was free-listing image * layers for some reason. */ public ImageLayer setTile (Tile tile) { // avoid releasing and rereferencing texture if nothing changes if (this.tile != tile) { if (this.tile != null) this.tile.texture().release(); this.tile = tile; checkOrigin(); if (tile != null) tile.texture().reference(); } return this; }
/** Informs this layer that a drawing operation has just completed. The backing canvas image data * is uploaded to the GPU. */ public void end () { Texture tex = (Texture)tile(); Image image = canvas.image; // if our texture is already the right size, just update it if (tex != null && tex.pixelWidth == image.pixelWidth() && tex.pixelHeight == image.pixelHeight()) tex.update(image); // otherwise we need to create a new texture (setTexture will unreference the old texture which // will cause it to be destroyed) else super.setTile(canvas.image.createTexture(Texture.Config.DEFAULT)); }
/** * Returns, creating if necessary, this image's default texture. When the texture is created, it * will use the {@link Texture.Config} set via {@link #setConfig}. If an image's default texture * is {@link Texture#close}d, a subsequent call to this method will create a new default texture. */ public Texture texture () { if (texture == null || texture.disposed()) texture = createTexture(texconf); return texture; }
/** * Creates an empty texture into which one can render. The supplied width and height are in * display units and will be converted to pixels based on the current scale factor. */ public Texture createTexture (float width, float height, Texture.Config config) { int texWidth = config.toTexWidth(scale.scaledCeil(width)); int texHeight = config.toTexHeight(scale.scaledCeil(height)); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " + texWidth + "x" + texHeight); int id = createTexture(config); gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, null); return new Texture(this, id, config, texWidth, texHeight, scale, width, height); }
protected static Texture.Symbol decodeTexture (LibraryData.TextureData tdata, playn.core.Texture atlas) { float[] r = tdata.rect; return new Texture.Symbol(tdata.symbol, tdata.origin, atlas.tile(r[0], r[1], r[2], r[3])); } }
/** * Creates a texture with this image's bitmap data using {@code config}. NOTE: this creates a new * texture with every call. This is generally only needed if you plan to create multiple textures * from the same bitmap, with different configurations. Otherwise just use {@link #texture} to * create the image's "default" texture which will be shared by all callers. */ public Texture createTexture (Texture.Config config) { if (!isLoaded()) throw new IllegalStateException( "Cannot create texture from unready image: " + this); int texWidth = config.toTexWidth(pixelWidth()); int texHeight = config.toTexHeight(pixelHeight()); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " + texWidth + "x" + texHeight + " from: " + this); Texture tex = new Texture(gfx, gfx.createTexture(config), config, texWidth, texHeight, scale(), width(), height()); tex.update(this); // this will handle non-POT source image conversion return tex; }
/** * Returns, creating if necessary, this image's default texture. When the texture is created, it * will use the {@link Texture.Config} set via {@link #setConfig}. If an image's default texture * is {@link Texture#close}d, a subsequent call to this method will create a new default texture. */ public Texture texture () { if (texture == null || texture.disposed()) texture = createTexture(texconf); return texture; }
/** * Creates an empty texture into which one can render. The supplied width and height are in * display units and will be converted to pixels based on the current scale factor. */ public Texture createTexture (float width, float height, Texture.Config config) { int texWidth = config.toTexWidth(scale.scaledCeil(width)); int texHeight = config.toTexHeight(scale.scaledCeil(height)); if (texWidth <= 0 || texHeight <= 0) throw new IllegalArgumentException( "Invalid texture size: " + texWidth + "x" + texHeight); int id = createTexture(config); gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texWidth, texHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, null); return new Texture(this, id, config, texWidth, texHeight, scale, width, height); }
@Override public Tile tile () { if (tile == null) tile = image.texture().tile(rx, ry, rwidth, rheight); return tile; } @Override public RFuture<Tile> tileAsync () {
/** * Updates this image's default texture with the current contents of the image, and returns the * texture. If the texture has not yet been created, then this simply creates it. This is only * necessary if you want to update the default texture for an image associated with a {@link * Canvas}, or if you have used {@link #setRgb} to change the contents of this image. */ public Texture updateTexture () { if (texture == null || texture.disposed()) texture = createTexture(texconf); else texture.update(this); return texture; }
/** Disposes this image's default texture, if it has been already created. */ public void close () { if (texture != null) texture.close(); }
/** Returns {@code sourceHeight} rounded up to a POT if necessary. */ public int toTexHeight (int sourceHeight) { return (repeatY || mipmaps) ? nextPOT(sourceHeight) : sourceHeight; }
root.visitItems(new Slot<Node>() { @Override public void onEmit (Node n) { // Draw the item to the atlas n.item.draw(atlasTex, n.x, n.y); // Record its region packed.put(n.item.id, atlasTex.texture.tile(n.x, n.y, n.width, n.height)); }}); atlasTex.end();
protected void finalize () { this.close(); } }