public int texWidth() { return image.pixelWidth(); } public int texHeight() { return image.pixelHeight(); }
/** * This image's width in display units. If this image is loaded asynchrously, this will return * 0 until loading is complete. See {@link #state}. */ public float width () { return scale().invScaled(pixelWidth()); }
/** * This image's width in display units. If this image is loaded asynchrously, this will return * 0 until loading is complete. See {@link #state}. */ public float width () { return scale().invScaled(pixelWidth()); }
/** 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)); }
/** * 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; }
/** * 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; }
/** Uploads {@code image} to this texture's GPU memory. {@code image} must have the exact same * size as this texture and must be fully loaded. This is generally useful for updating a * texture which was created from a canvas when the canvas has been changed. */ public void update (Image image) { // if we're a repeating texture (or we want mipmaps) and this image is non-POT on the relevant // axes, we need to scale it before we upload it; we'll just do this on the CPU since it feels // like creating a second texture, a frame buffer to render into it, sending a GPU batch and // doing all the blah blah blah is going to be more expensive overall if (config.repeatX || config.repeatY || config.mipmaps) { int pixWidth = image.pixelWidth(), pixHeight = image.pixelHeight(); int potWidth = config.toTexWidth(pixWidth), potHeight = config.toTexWidth(pixHeight); if (potWidth != pixWidth || potHeight != pixHeight) { Canvas scaled = gfx.createCanvasImpl(Scale.ONE, potWidth, potHeight); scaled.draw(image, 0, 0, potWidth, potHeight); scaled.image.upload(gfx, this); scaled.close(); } else image.upload(gfx, this); // fast path, woo! } else image.upload(gfx, this); // fast path, woo! if (config.mipmaps) gfx.gl.glGenerateMipmap(GL_TEXTURE_2D); }
/** Uploads {@code image} to this texture's GPU memory. {@code image} must have the exact same * size as this texture and must be fully loaded. This is generally useful for updating a * texture which was created from a canvas when the canvas has been changed. */ public void update (Image image) { // if we're a repeating texture (or we want mipmaps) and this image is non-POT on the relevant // axes, we need to scale it before we upload it; we'll just do this on the CPU since it feels // like creating a second texture, a frame buffer to render into it, sending a GPU batch and // doing all the blah blah blah is going to be more expensive overall if (config.repeatX || config.repeatY || config.mipmaps) { int pixWidth = image.pixelWidth(), pixHeight = image.pixelHeight(); int potWidth = config.toTexWidth(pixWidth), potHeight = config.toTexWidth(pixHeight); if (potWidth != pixWidth || potHeight != pixHeight) { Canvas scaled = gfx.createCanvasImpl(Scale.ONE, potWidth, potHeight); scaled.draw(image, 0, 0, potWidth, potHeight); scaled.image.upload(gfx, this); scaled.close(); } else image.upload(gfx, this); // fast path, woo! } else image.upload(gfx, this); // fast path, woo! if (config.mipmaps) gfx.gl.glGenerateMipmap(GL_TEXTURE_2D); }