@Override public void addCallback(final Callback<? super Image> callback) { parent.addCallback(new Callback<Image>() { public void onSuccess(Image image) { callback.onSuccess(ImageRegionGL.this); } public void onFailure(Throwable err) { callback.onFailure(err); } }); }
@Override public void setRepeat(boolean repeatX, boolean repeatY) { if (repeatX != this.repeatX || repeatY != this.repeatY) { this.repeatX = repeatX; this.repeatY = repeatY; clearTexture(); } }
/** * Draws this image with the supplied transform, and source and target dimensions. */ void draw(GLShader shader, InternalTransform xform, int tint, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { float texWidth = width(), texHeight = height(); drawImpl(shader, xform, ensureTexture(), tint, dx, dy, dw, dh, sx / texWidth, sy / texHeight, (sx + sw) / texWidth, (sy + sh) / texHeight); }
@Override public ImageLayer setImage(Image img) { assert img == null || img instanceof AbstractImageGL<?>; // avoid releasing and rereferencing image if nothing changes if (this.img != img) { if (this.img != null) this.img.release(); this.img = (AbstractImageGL<?>) img; if (this.img != null) this.img.reference(); } return this; }
@Override public Surface fillRect(float x, float y, float width, float height) { bindFramebuffer(); GLShader shader = ctx.quadShader(this.shader); if (fillPattern != null) { int tex = fillPattern.ensureTexture(); if (tex > 0) { shader.prepareTexture(tex, tint); float tw = fillPattern.width(), th = fillPattern.height(), r = x+width, b = y+height; shader.addQuad(topTransform(), x, y, x+width, y+height, x / tw, y / th, r / tw, b / th); } } else { int tex = ctx.fillImage().ensureTexture(); shader.prepareTexture(tex, Tint.combine(fillColor, tint)); shader.addQuad(topTransform(), x, y, x+width, y+height, 0, 0, 1, 1); } return this; }
@Override void draw(GLShader shader, InternalTransform xform, int tint, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { if (repeatX || repeatY) { // if we're repeating, then we have our own texture and want to draw it normally super.draw(shader, xform, tint, dx, dy, dw, dh, sx, sy, sw, sh); } else { float texWidth = (tex > 0) ? width : parent.width(); float texHeight = (tex > 0) ? height : parent.height(); sx += x(); sy += y(); parent.drawImpl(shader, xform, ensureTexture(), tint, dx, dy, dw, dh, sx / texWidth, sy / texHeight, (sx + sw) / texWidth, (sy + sh) / texHeight); } }
@Override public void draw(GC gc, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { parent.draw(gc, dx, dy, dw, dh, x+sx, y+sy, sw, sh); }
@Override public int ensureTexture() { if (!isReady()) { return 0; } else if (repeatX || repeatY) { return (tex > 0) ? tex : (tex = scaleTexture()); } else { return parent.ensureTexture(); } }
@Override public float height() { if (heightSet) return height; assert img != null : "Image has not yet been set"; return img.height(); }
@Override public void getRgb(int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) { parent.getRgb(startX + (int) x, startY + (int) y, width, height, rgbArray, offset, scanSize); }
@Override public void reference() { parent.reference(); }
@Override public boolean isReady() { return parent.isReady(); }
@Override public void release() { parent.release(); }
@Override public Surface fillTriangles(float[] xys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) { bindFramebuffer(); GLShader shader = ctx.trisShader(this.shader); if (fillPattern != null) { int tex = fillPattern.ensureTexture(); if (tex > 0) { shader.prepareTexture(tex, tint); shader.addTriangles(topTransform(), xys, xysOffset, xysLen, fillPattern.width(), fillPattern.height(), indices, indicesOffset, indicesLen, indexBase); } } else { int tex = ctx.fillImage().ensureTexture(); shader.prepareTexture(tex, Tint.combine(fillColor, tint)); shader.addTriangles(topTransform(), xys, xysOffset, xysLen, 1, 1, indices, indicesOffset, indicesLen, indexBase); } return this; }
@Override public Canvas drawImage(Image img, float dx, float dy, float dw, float dh, float sx, float sy, float sw, float sh) { @SuppressWarnings("unchecked") AbstractImageGL<GC> d = (AbstractImageGL<GC>) img; d.draw(gc(), dx, dy, dw, dh, sx, sy, sw, sh); isDirty = true; return this; }
@Override public Surface fillTriangles(float[] xys, float[] sxys, int xysOffset, int xysLen, int[] indices, int indicesOffset, int indicesLen, int indexBase) { bindFramebuffer(); if (fillPattern == null) throw new IllegalStateException("No fill pattern currently set"); int tex = fillPattern.ensureTexture(); if (tex > 0) { GLShader shader = ctx.trisShader(this.shader).prepareTexture(tex, tint); shader.addTriangles(topTransform(), xys, sxys, xysOffset, xysLen, indices, indicesOffset, indicesLen, indexBase); } return this; }
int tex = fillPattern.ensureTexture(); if (tex > 0) { shader.prepareTexture(tex, tint); shader.addQuad(l, 0, 0, length, width, 0, 0, length/fillPattern.width(), width/fillPattern.height());
@Override public Canvas drawImage(Image img, float x, float y, float w, float h) { @SuppressWarnings("unchecked") AbstractImageGL<GC> d = (AbstractImageGL<GC>) img; d.draw(gc(), x, y, w, h); isDirty = true; return this; }
/** * Decrements this image's reference count. Called by {@link ImageLayerGL} to let the image know * that may no longer be part of the scene graph. */ public void release() { assert refs > 0 : "Released an image with no references!"; if (--refs == 0) { clearTexture(); } }