@Override public void clearTexture() { if (tex > 0) { ctx.destroyTexture(tex); tex = 0; } }
@Override public void clearTexture() { if (tex > 0) { ctx.destroyTexture(tex); tex = 0; } }
public void run() { destroyTexture(tex); } });
protected void clearTexture() { ctx.destroyTexture(tex); tex = 0; ctx.deleteFramebuffer(fbuf); fbuf = 0; }
@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); } } }
private int scaleTexture() { int scaledWidth = scale.scaledCeil(width()); int scaledHeight = scale.scaledCeil(height()); // GL requires pow2 on axes that repeat int width = GLUtil.nextPowerOfTwo(scaledWidth), height = GLUtil.nextPowerOfTwo(scaledHeight); // TODO: if width/height > platform_max_size, repeatedly scale by 0.5 until within bounds // platform_max_size = 1024 for iOS, GL10.GL_MAX_TEXTURE_SIZE on android, etc. // no need to scale if our source data is already a power of two if ((width == 0) && (height == 0)) { int reptex = createPow2RepTex(scaledWidth, scaledHeight, repeatX, repeatY, mipmapped); if (mipmapped) ctx.generateMipmap(reptex); return reptex; } // otherwise we need to scale our non-repeated texture, so load that normally int tex = createMainTex(); // width/height == 0 => already a power of two. if (width == 0) width = scaledWidth; if (height == 0) height = scaledHeight; // create our texture and point a new framebuffer at it try { return convertToRepTex(ctx, tex, width, height, repeatX, repeatY, mipmapped); } finally { // delete the non-repeated texture ctx.destroyTexture(tex); } }