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 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); } }
public TextureInfo addEtc1Texture(InputStream compressedTex, Bitmap fallbackTex, TextureType textureType) { ETC1Util.ETC1Texture texture = null; TextureInfo textureInfo = null; try { texture = ETC1Util.createTexture(compressedTex); } catch (IOException e) { Log.e("addEtc1Texture", e.getMessage()); } finally { if (texture == null) { textureInfo = addTexture(fallbackTex); Log.d("ETC1", "Falling back to uncompressed texture"); } else { textureInfo = addEtc1Texture(texture.getData(), texture.getWidth(), texture.getHeight(), textureType); Log.d("ETC1", "ETC1 texture load successful"); } } return textureInfo; }
/** * Add mipmap-chained ETC1 texture. */ public TextureInfo addEtc1Texture(int[] resourceIds, TextureType textureType, boolean isExistingTexture, WrapType wrapType, FilterType filterType) { if (resourceIds == null) return null; ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length]; 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(mContext.getResources().openRawResource(resourceIds[i])); mipmapChain[i] = texture.getData(); if (i == 0) { mip_0_width = texture.getWidth(); mip_0_height = texture.getHeight(); } } } catch (IOException e) { RajLog.e(e.getMessage()); e.printStackTrace(); } return addTexture(mipmapChain, null, mip_0_width, mip_0_height, textureType, null, true, false, isExistingTexture, wrapType, filterType, CompressionType.ETC1, ETC1.ETC1_RGB8_OES); }
public void setInputStream(InputStream compressedTexture, Bitmap fallbackTexture) { ETC1Util.ETC1Texture texture = null; try { texture = ETC1Util.createTexture(compressedTexture); } catch (IOException e) { Log.e("addEtc1Texture", e.getMessage()); } finally { if (texture == null) { setBitmap(fallbackTexture); Log.d("ETC1", "Falling back to uncompressed texture"); } else { setByteBuffer(texture.getData()); setWidth(texture.getWidth()); setHeight(texture.getHeight()); Log.d("ETC1", "ETC1 texture load successful"); } } }
/** * Load a texture from filesystem and bind it to texture * * @param gl * @param tex * @param name * @throws IOException */ public void loadTexture(GL10 gl, int tex, String name) throws IOException { gl.glBindTexture(GL10.GL_TEXTURE_2D, tex); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR); gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); InputStream textureStream; if (context.getFileStreamPath(name).exists()) { textureStream = context.openFileInput(name); } else { textureStream = context.getAssets().open(name); } ETC1Util.loadTexture(GL10.GL_TEXTURE_2D, 0, 0, GL10.GL_RGB, GL10.GL_UNSIGNED_SHORT_5_6_5, textureStream); textureStream.close(); }
private void makeImage(Render render, float angle, String name) throws IOException { Bitmap bitmap = render.getImage(angle); int dim = bitmap.getHeight(); ByteBuffer bb = ByteBuffer.allocateDirect(dim * dim * 3); for (int y = 0; y < dim; y += 1) { for (int x = 0; x < dim; x += 1) { int value = bitmap.getPixel(x, y); bb.put((byte) (value >> 16)); bb.put((byte) (value >> 8)); bb.put((byte) value); } } bb.rewind(); ETC1Texture compressed = ETC1Util.compressTexture(bb, dim, dim, 3, dim * 3); FileOutputStream outFile = openFileOutput(name, Context.MODE_PRIVATE); ETC1Util.writeTexture(compressed, outFile); outFile.close(); }
/** * Add mipmap-chained ETC1 texture. * @param context * @param resourceIds * @return */ public TextureInfo addEtc1Texture(int[] resourceIds, TextureType textureType, boolean isExistingTexture, WrapType wrapType, FilterType filterType) { if (resourceIds == null) return null; ByteBuffer[] mipmapChain = new ByteBuffer[resourceIds.length]; 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(mContext.getResources().openRawResource(resourceIds[i])); mipmapChain[i] = texture.getData(); if (i == 0) { mip_0_width = texture.getWidth(); mip_0_height = texture.getHeight(); } } } catch (IOException e) { RajLog.e(e.getMessage()); e.printStackTrace(); } return addTexture(mipmapChain, null, mip_0_width, mip_0_height, textureType, null, true, false, isExistingTexture, wrapType, filterType, CompressionType.ETC1, ETC1.ETC1_RGB8_OES); }
private void loadTexture(Context context, Render.DrawGroup drawGroup) { if (drawGroup.texture != null) { int resource = TEXTURES.get(drawGroup.texture.toLowerCase()); InputStream is = context.getResources().openRawResource(resource); try { ETC1Util.ETC1Texture tex = ETC1Util.createTexture(is); is.close(); drawGroup.loadedCompressedDiffuseTexture = tex; } catch (IOException e) { Log.e("Body", "Loading texture: " + e); } } else { int[] color = { Color.rgb( (int)(drawGroup.diffuseColor[0] * 255 + 0.5), (int)(drawGroup.diffuseColor[1] * 255 + 0.5), (int)(drawGroup.diffuseColor[2] * 255 + 0.5)) }; Bitmap bitmap = Bitmap.createBitmap(color, 1, 1, Bitmap.Config.RGB_565); drawGroup.loadedDiffuseTexture = bitmap; } }
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 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 static int loadTexture(ETC1Util.ETC1Texture etc1Texture) { // Note that unlike the js version, this does not cache textures. There // was just one cache hit. int tex = genTex(); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, tex); ETC1Util.loadTexture( GLES20.GL_TEXTURE_2D, 0, 0, GLES20.GL_RGB, GLES20.GL_UNSIGNED_SHORT_5_6_5, etc1Texture); return tex; }
@Override protected void writeTextureToHardware(final GLState pGLState) throws IOException { final InputStream inputStream = this.getInputStream(); ETC1Util.loadTexture(GLES20.GL_TEXTURE_2D, 0, 0, this.mPixelFormat.getGLFormat(), this.mPixelFormat.getGLType(), inputStream); }
public void determineGraphicSupport(GL10 gl) { final String extensions = gl.glGetString(GL10.GL_EXTENSIONS); final String version = GLES10.glGetString(GL10.GL_VERSION); final String renderer = gl.glGetString(GL10.GL_RENDERER); Log.w("GLExtensions", "Extensions: " + extensions); Log.w("GLVersion", "Version: " + version); Log.w("GLRenderer", "Renderer: " + renderer); // GL_EXT_debug_marker GL_OES_blend_func_separate GL_OES_blend_equation_separate GL_OES_blend_subtract // GL_OES_byte_coordinates GL_OES_compressed_paletted_texture GL_OES_point_size_array GL_OES_point_sprite // GL_OES_single_precision GL_OES_stencil_wrap GL_OES_texture_env_crossbar GL_OES_texture_mirored_repeat // GL_OES_EGL_image GL_OES_element_index_uint GL_OES_draw_texture GL_OES_texture_cube_map GL_OES_draw_texture // GL_OES_read_format GL_OES_framebuffer_object GL_OES_depth24 GL_OES_depth32 GL_OES_fbo_render_mipmap // GL_OES_rgb8_rgba8 GL_OES_stencil1 GL_OES_stencil4 GL_OES_stencil8 // GL_OES_packed_depth_stencil GL_EXT_texture_format_BGRA8888 GL_APPLE_texture_format_BGRA8888 // GL_OES_compressed_ETC1_RGB8_texture String enabledCompressions = ""; if (extensions.contains("GL_IMG_texture_compression_pvrtc")) { //Use PVR compressed textures Log.w("Ext", "Device supports PVR"); enabledCompressions += "Device supports PVR\n\t"; } if (extensions.contains("GL_AMD_compressed_ATC_texture") || extensions.contains("GL_ATI_texture_compression_atitc")) { //Load ATI Textures Log.w("Ext", "Device supports ATI"); enabledCompressions += "Device supports ATI\n\t"; } if (extensions.contains("GL_OES_texture_compression_S3TC") || extensions.contains("GL_EXT_texture_compression_s3tc")) { //Use DTX Textures Log.w("Ext", "Device supports S3TC"); enabledCompressions += "Device supports S3TC\n\t"; } if (extensions.contains("GL_EXT_texture_compression_dxt1")) { //Use DTX1 Textures Log.w("Ext", "Device supports DXT1"); enabledCompressions += "Device supports DXT1\n\t"; } if (extensions.contains("GL_EXT_texture_compression_dxt3")) { //Use DTX3 Textures Log.w("Ext", "Device supports DXT3"); enabledCompressions += "Device supports DXT3\n\t"; } if (extensions.contains("GL_EXT_texture_compression_dxt5")) { //Use DTX5 Textures Log.w("Ext", "Device supports DXT5"); enabledCompressions += "Device supports DXT5\n\t"; } if (extensions.contains("GL_AMD_compressed_3DC_texture")) { //Use 3DC Texture Log.w("Ext", "Device supports 3DC textures"); enabledCompressions += "Device supports 3DC textures\n\t"; } if (ETC1Util.isETC1Supported()) { //Use ETC1 Log.w("Ext", "Device supports ETC1 Rgb8 textures"); enabledCompressions += "Device supports ETC1 Rgb8 textures\n\t"; } final String enabComprFinal = enabledCompressions; String[] extArray = extensions.split(" "); final List<String> ordered = Arrays.asList(extArray); Collections.sort(ordered); CheckerActivity.this.runOnUiThread(new Runnable() { @Override public void run() { String extFormatted = ""; for (String singleExt : ordered) { extFormatted += singleExt + "\n\t"; } glExtensionsTv.setText("Extensions: \n\t" + extFormatted); glVersionTv.setText("Version: " + version); glRendererTv.setText("Renderer: " + renderer); glExtensionsEnabled.setText("Texture Compression Supported: \n\t" + enabComprFinal); } }); }