try { ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(mResourceId)); mByteBuffers = new ByteBuffer[]{texture.getData()}; setWidth(texture.getWidth()); setHeight(texture.getHeight()); setCompressionFormat(ETC1.ETC1_RGB8_OES); } catch (IOException e) { for (int i = 0, length = mResourceIds.length; i < length; i++) { ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(mResourceIds[i])); mipmapChain[i] = texture.getData(); if (i == 0) { mip_0_width = texture.getWidth(); mip_0_height = texture.getHeight();
private ETC1Util.ETC1Texture createTexture(InputStream input) throws IOException { int width = 0; int height = 0; byte[] ioBuffer = new byte[4096]; { if (input.read(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE) != ETC1.ETC_PKM_HEADER_SIZE) { throw new IOException("Unable to read PKM file header."); } if(headerBuffer==null){ headerBuffer = ByteBuffer.allocateDirect(ETC1.ETC_PKM_HEADER_SIZE) .order(ByteOrder.nativeOrder()); } headerBuffer.put(ioBuffer, 0, ETC1.ETC_PKM_HEADER_SIZE).position(0); if (!ETC1.isValid(headerBuffer)) { throw new IOException("Not a PKM file."); } width = ETC1.getWidth(headerBuffer); height = ETC1.getHeight(headerBuffer); } int encodedSize = ETC1.getEncodedDataSize(width, height); ByteBuffer dataBuffer = ByteBuffer.allocateDirect(encodedSize).order(ByteOrder.nativeOrder()); int len; while ((len =input.read(ioBuffer))!=-1){ dataBuffer.put(ioBuffer,0,len); } dataBuffer.position(0); return new ETC1Util.ETC1Texture(width, height, dataBuffer); }
public void setResourceIds(int[] resourceIds) { ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length]; Resources resources = TextureManager.getInstance().getContext().getResources(); int mip_0_width = 1, mip_0_height = 1; try { for (int i = 0, length = resourceIds.length; i < length; i++) { ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(resourceIds[i])); mipmapChain[i] = texture.getData(); if (i == 0) { mip_0_width = texture.getWidth(); mip_0_height = texture.getHeight(); } } setWidth(mip_0_width); setHeight(mip_0_height); setCompressionFormat(ETC1.ETC1_RGB8_OES); } catch (IOException e) { RajLog.e(e.getMessage()); e.printStackTrace(); } mByteBuffers = mipmapChain; }
public void setInputStream(InputStream compressedTexture, Bitmap fallbackTexture) { ETC1Util.ETC1Texture texture = null; try { texture = ETC1Util.createTexture(compressedTexture); } catch (IOException e) { RajLog.e("addEtc1Texture: " + e.getMessage()); } finally { if (texture == null) { setBitmap(fallbackTexture); if (RajLog.isDebugEnabled()) RajLog.d("Falling back to uncompressed texture"); } else { setByteBuffer(texture.getData()); setWidth(texture.getWidth()); setHeight(texture.getHeight()); if (RajLog.isDebugEnabled()) RajLog.d("ETC1 texture load successful"); } } } }
public void setResourceId(int resourceId) { mResourceId = resourceId; Resources resources = TextureManager.getInstance().getContext().getResources(); try { ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(resourceId)); mByteBuffers = new ByteBuffer[]{texture.getData()}; setWidth(texture.getWidth()); setHeight(texture.getHeight()); setCompressionFormat(ETC1.ETC1_RGB8_OES); } catch (IOException e) { RajLog.e(e.getMessage()); e.printStackTrace(); } }
Log.e("wuwang","is ETC null->"+(t==null)); if(t!=null&&tAlpha!=null){ Gl2Utils.getMatrix(SM,type,t.getWidth(),t.getHeight(),width,height); setMatrix(SM); onSetExpandData(); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,texture[0]); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D,0,0,GLES20.GL_RGB,GLES20 .GL_UNSIGNED_SHORT_5_6_5,new ETC1Util.ETC1Texture(width,height,emptyBuffer)); GLES20.glUniform1i(mHTexture,getTextureType()); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,texture[1]); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D,0,0,GLES20.GL_RGB,GLES20 .GL_UNSIGNED_SHORT_5_6_5,new ETC1Util.ETC1Texture(width,height,emptyBuffer)); GLES20.glUniform1i(mGlHAlpha,1+getTextureType()); isPlay=false;
Log.e("wuwang","is ETC null->"+(t==null)); if(t!=null&&tAlpha!=null){ MatrixUtils.getMatrix(super.getMatrix(),MatrixUtils.TYPE_FITEND,t.getWidth(),t.getHeight(),width,height); MatrixUtils.flip(super.getMatrix(),false,true); onSetExpandData(); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,texture[0]); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D,0,0,GLES20.GL_RGB,GLES20 .GL_UNSIGNED_SHORT_5_6_5,new ETC1Util.ETC1Texture(width,height,emptyBuffer)); GLES20.glUniform1i(mHTexture,getTextureType()); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,texture[1]); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D,0,0,GLES20.GL_RGB,GLES20 .GL_UNSIGNED_SHORT_5_6_5,new ETC1Util.ETC1Texture(width,height,emptyBuffer)); GLES20.glUniform1i(mGlHAlpha,1+getTextureType()); isPlay=false;
public void setInputStream(InputStream compressedTexture, Bitmap fallbackTexture) { ETC1Util.ETC1Texture texture = null; try { texture = ETC1Util.createTexture(compressedTexture); } catch (IOException e) { RajLog.e("addEtc1Texture: " + e.getMessage()); } finally { if (texture == null) { setBitmap(fallbackTexture); if (RajLog.isDebugEnabled()) RajLog.d("Falling back to uncompressed texture"); } else { setByteBuffer(texture.getData()); setWidth(texture.getWidth()); setHeight(texture.getHeight()); if (RajLog.isDebugEnabled()) RajLog.d("ETC1 texture load successful"); } } } }