@Override void drawImpl(GLShader shader, InternalTransform xform, int tex, int tint, float dx, float dy, float dw, float dh, float sl, float st, float sr, float sb) { if (tex > 0) { // we have to invert y here due to GL origin shenanigans ctx.quadShader(shader).prepareTexture(tex, tint).addQuad( xform, dx, dy, dx + dw, dy + dh, sl, 1-st, sr, 1-sb); } }
void drawImpl(GLShader shader, InternalTransform xform, int tex, int tint, float dx, float dy, float dw, float dh, float sl, float st, float sr, float sb) { if (tex > 0) { ctx.quadShader(shader).prepareTexture(tex, tint).addQuad( xform, dx, dy, dx + dw, dy + dh, sl, st, sr, sb); } }
void draw(GLShader shader, InternalTransform xform, int curTint) { if (tint != Tint.NOOP_TINT) curTint = Tint.combine(curTint, tint); // Draw this layer to the screen upside-down, because its contents are flipped (This happens // because it uses the same vertex program as everything else, which flips vertically to put // the origin at the top-left). ctx.quadShader(shader).prepareTexture(tex, curTint).addQuad( xform, 0, height, width, 0, 0, 0, 1, 1); }
@Override public void onSurfaceCreated() { createTexture(); if (cachedPixels != null) { try { AndroidGLContext actx = (AndroidGLContext) ctx; ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4); FileInputStream in = new FileInputStream(cachedPixels); in.read(pixelBuffer.array()); in.close(); int bufferTex = actx.createTexture(false, false, false); actx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, texWidth, texHeight, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer); // bind our surface framebuffer and render the saved texture data into it bindFramebuffer(); ctx.quadShader(null).prepareTexture(bufferTex, Tint.NOOP_TINT).addQuad( StockInternalTransform.IDENTITY, 0, texHeight, texWidth, 0, 0, 0, 1, 1); // rebind the default frame buffer (which will flush the rendering operation) ctx.bindFramebuffer(); ctx.destroyTexture(bufferTex); pixelBuffer = null; cachedPixels.delete(); cachedPixels = null; } catch (IOException e) { PlayN.reportError("Error reading cached surface pixels from file.", e); } } }
@Override public void onSurfaceCreated() { createTexture(); if (cachedPixels != null) { try { AndroidGLContext actx = (AndroidGLContext) ctx; ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4); FileInputStream in = new FileInputStream(cachedPixels); in.read(pixelBuffer.array()); in.close(); int bufferTex = actx.createTexture(false, false, false); actx.gl.glTexImage2D(GL20.GL_TEXTURE_2D, 0, GL20.GL_RGBA, texWidth, texHeight, 0, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer); // bind our surface framebuffer and render the saved texture data into it bindFramebuffer(); ctx.quadShader(null).prepareTexture(bufferTex, Tint.NOOP_TINT).addQuad( StockInternalTransform.IDENTITY, 0, texHeight, texWidth, 0, 0, 0, 1, 1); // rebind the default frame buffer (which will flush the rendering operation) ctx.bindFramebuffer(); ctx.destroyTexture(bufferTex); pixelBuffer = null; cachedPixels.delete(); cachedPixels = null; } catch (IOException e) { PlayN.reportError("Error reading cached surface pixels from file.", e); } } }
@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; }
if (tex > 0) { shader.prepareTexture(tex, tint); shader.addQuad(l, 0, 0, length, width, 0, 0, length/fillPattern.width(), width/fillPattern.height()); int tex = ctx.fillImage().ensureTexture(); shader.prepareTexture(tex, Tint.combine(fillColor, tint)); shader.addQuad(l, 0, 0, length, width, 0, 0, 1, 1);
protected static int convertToRepTex(GLContext ctx, int tex, int width, int height, boolean repeatX, boolean repeatY, boolean mipmapped) { int reptex = ctx.createTexture(width, height, repeatX, repeatY, mipmapped); int fbuf = ctx.createFramebuffer(reptex); ctx.pushFramebuffer(fbuf, width, height); try { // render the non-repeated texture into the framebuffer properly scaled ctx.clear(0, 0, 0, 0); GLShader shader = ctx.quadShader(null).prepareTexture(tex, Tint.NOOP_TINT); shader.addQuad(ctx.createTransform(), 0, height, width, 0, 0, 0, 1, 1); shader.flush(); // if we're mipmapped, we can now generate our mipmaps if (mipmapped) ctx.generateMipmap(reptex); return reptex; } finally { // we no longer need this framebuffer; rebind the previous framebuffer and delete ours ctx.popFramebuffer(); ctx.deleteFramebuffer(fbuf); } } }
float sl = this.x, st = this.y, sr = sl + this.width, sb = st + this.height; GLShader shader = ctx.quadShader(null).prepareTexture(tex, Tint.NOOP_TINT); shader.addQuad(ctx.createTransform(), 0, height, width, 0, sl / tw, st / th, sr / tw, sb / th); shader.flush();