Resources resources = TextureManager.getInstance().getContext().getResources(); try { ETC1Util.ETC1Texture texture = ETC1Util.createTexture(resources.openRawResource(mResourceId)); mByteBuffers = new ByteBuffer[]{texture.getData()}; setWidth(texture.getWidth()); try { 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) {
public void load(GL10 gl) { Log.w(TAG, "ETC1 texture support: " + ETC1Util.isETC1Supported()); InputStream input = getResources().openRawResource(R.raw.androids); try { ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, input); } catch (IOException e) { Log.w(TAG, "Could not load texture: " + e); } finally { try { input.close(); } catch (IOException e) { // ignore exception thrown from close. } } } }
public void load(GL10 gl) { int width = 128; int height = 128; Buffer image = createImage(width, height); ETC1Util.ETC1Texture etc1Texture = ETC1Util.compressTexture(image, width, height, 3, 3 * width); if (USE_STREAM_IO) { // Test the ETC1Util APIs for reading and writing compressed textures to I/O streams. try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ETC1Util.writeTexture(etc1Texture, bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, bis); } catch (IOException e) { Log.w(TAG, "Could not load texture: " + e); } } else { ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, etc1Texture); } }
GLES20.glActiveTexture(GLES20.GL_TEXTURE0+getTextureType()); 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,t); GLES20.glUniform1i(mHTexture,getTextureType()); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D,0,0,GLES20.GL_RGB,GLES20 .GL_UNSIGNED_SHORT_5_6_5,tAlpha); GLES20.glUniform1i(mGlHAlpha,1+getTextureType()); GLES20.glActiveTexture(GLES20.GL_TEXTURE0+getTextureType()); 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()); 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());
public void load(GL10 gl) { Log.w(TAG, "ETC1 texture support: " + ETC1Util.isETC1Supported()); InputStream input = getResources().openRawResource(R.raw.androids); try { ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, input); } catch (IOException e) { Log.w(TAG, "Could not load texture: " + e); } finally { try { input.close(); } catch (IOException e) { // ignore exception thrown from close. } } } }
public void load(GL10 gl) { int width = 128; int height = 128; Buffer image = createImage(width, height); ETC1Util.ETC1Texture etc1Texture = ETC1Util.compressTexture(image, width, height, 3, 3 * width); if (USE_STREAM_IO) { // Test the ETC1Util APIs for reading and writing compressed textures to I/O streams. try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ETC1Util.writeTexture(etc1Texture, bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, bis); } catch (IOException e) { Log.w(TAG, "Could not load texture: " + e); } } else { ETC1Util.loadTexture(GLES10.GL_TEXTURE_2D, 0, 0, GLES10.GL_RGB, GLES10.GL_UNSIGNED_SHORT_5_6_5, etc1Texture); } }
GLES20.glActiveTexture(GLES20.GL_TEXTURE0+getTextureType()); 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,t); GLES20.glUniform1i(mHTexture,getTextureType()); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D,0,0,GLES20.GL_RGB,GLES20 .GL_UNSIGNED_SHORT_5_6_5,tAlpha); GLES20.glUniform1i(mGlHAlpha,1+getTextureType()); GLES20.glActiveTexture(GLES20.GL_TEXTURE0+getTextureType()); 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()); 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());
public static int loadECTTexture(Context context, int resourceId) { final int[] textureObjectIds = new int[1]; glGenTextures(1, textureObjectIds, 0); if (textureObjectIds[0] == 0) { Timber.d("Could not generate a new OpenGL texture object."); return 0; } // 设置缩小的情况下过滤方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); // 设置放大的情况下过滤方式 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); InputStream is = context.getResources().openRawResource(resourceId); try { ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D, 0, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_BYTE, is); } catch (Exception e) { Timber.e(e.getMessage(), e); } finally { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } return textureObjectIds[0]; }
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(); } }
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"); } } } }