public static int loadTexture(final Context context, final int resourceId, int[] size) { final int texId = genTexture(); if (texId != 0) { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false; // No pre-scaling options.inJustDecodeBounds = true; // Just decode bounds BitmapFactory.decodeResource(context.getResources(), resourceId, options); // Set return size size[0] = options.outWidth; size[1] = options.outHeight; // Decode options.inJustDecodeBounds = false; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), resourceId, options); // Load the bitmap into the bound texture. GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); // Recycle the bitmap, since its data has been loaded into OpenGL. bitmap.recycle(); } return texId; }
public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) { int textures[] = new int[1]; if (usedTexId == NO_TEXTURE) { GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId); GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img); textures[0] = usedTexId; } if (recycle) { img.recycle(); } return textures[0]; }
if (eglDisplay == EGL10.EGL_NO_DISPLAY) { throw new RuntimeException("eglGetDisplay failed " + android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); if (!egl10.eglInitialize(eglDisplay, version)) { throw new RuntimeException("eglInitialize failed " + android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); if (!egl10.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) { throw new IllegalArgumentException("eglChooseConfig failed " + android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError())); } else if (configsCount[0] > 0) { eglConfig = configs[0]; android.opengl.GLUtils.getEGLErrorString(error)); android.opengl.GLUtils.getEGLErrorString(egl10.eglGetError()));
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0); } else { final int format = GLUtils.getInternalFormat(bitmap); final int type = GLUtils.getType(bitmap); GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
throw new TextureException("Texture could not be updated because the bitmap format is different from the original"); GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, mBitmap, mBitmapFormat, GLES20.GL_UNSIGNED_BYTE); } else if(mByteBuffer != null) { if (mWidth == 0 || mHeight == 0 || mBitmapFormat == 0)
/** * Updates the content on GPU's memory. * * @param canvas */ public void updateContent(final GLCanvas canvas) { if (!isLoaded()) { if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) { return; } uploadToCanvas(canvas); } else if (!mContentValid) { final Bitmap bitmap = getBitmap(); final int format = GLUtils.getInternalFormat(bitmap); final int type = GLUtils.getType(bitmap); canvas.getGLInstance().glBindTexture(GL10.GL_TEXTURE_2D, mId); GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type); freeBitmap(); mContentValid = true; } }
public Texture(Bitmap bitmap) { if (bitmap == null || bitmap.isRecycled()) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "Texture", "constructor", (bitmap == null) ? "missingBitmap" : "invalidBitmap")); } int width = bitmap.getWidth(); int height = bitmap.getHeight(); int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); this.textureWidth = width; this.textureHeight = height; this.textureFormat = format; this.textureType = type; this.textureByteCount = estimateByteCount(width, height, format, type); this.texCoordTransform.setToVerticalFlip(); this.imageBitmap = bitmap; }
GLUtils.texImage2D(GL11.GL_TEXTURE_2D, 0, bitmap, 0); } else { int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); Config config = bitmap.getConfig(); gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, texWidth, texHeight, 0, format, type, null); GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, mBorder, mBorder, bitmap, format, type); GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, line, format, type); GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, 0, line, format, type); GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, mBorder + bWidth, 0, line, format, type); GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, 0, mBorder + bHeight, line, format, type);
/** * updates specific texture and recycles bitmap used for updating */ public void updateTexture(int texNum, Bitmap drawingCache) { GLES20.glActiveTexture(mTextureConsts[texNum - 1]); checkGlError("Texture generate"); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesIds[texNum]); checkGlError("Texture bind"); GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, drawingCache); checkGlError("Tex Sub Image"); drawingCache.recycle(); }
/** * Updates the content on GPU's memory. * @param canvas */ public void updateContent(GLCanvas canvas) { if (!isLoaded(canvas)) { if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) { return; } uploadToCanvas(canvas); } else if (!mContentValid) { try { Bitmap bitmap = getBitmap(); int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); canvas.getGLInstance().glBindTexture(GL11.GL_TEXTURE_2D, mId); GLUtils.texSubImage2D(GL11.GL_TEXTURE_2D, 0, mBorder, mBorder, bitmap, format, type); freeBitmap(); mContentValid = true; } catch (Error e) { Log.e(TAG, "Error loading bitmap", e); if (mBitmap != null) freeBitmap(); mContentValid = false; } } }
/** * Updates the content on GPU's memory. * @param canvas */ public void updateContent(GLCanvas canvas) { if (!isLoaded()) { if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) { return; } uploadToCanvas(canvas); } else if (!mContentValid) { Bitmap bitmap = getBitmap(); int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type); freeBitmap(); mContentValid = true; } }
@Override public void onSurfaceCreated(GL10 glUnused, EGLConfig config) { super.onSurfaceCreated(glUnused, config); Bitmap bitmap = BitmapFactory.decodeResource(mSurfaceView.getResources(), R.drawable.video_brightness_6_white_36dp); //创建bitmap GLES20.glGenTextures(1, mTexturesBitmap, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTexturesBitmap[0]); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_NEAREST); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0); bitmap.recycle(); }
public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) { int textures[] = new int[1]; if (usedTexId == NO_TEXTURE) { GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId); GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img); textures[0] = usedTexId; } if (recycle) { img.recycle(); } return textures[0]; }
@Override public void texSubImage2D(BasicTexture texture, int xOffset, int yOffset, Bitmap bitmap, int format, int type) { int target = texture.getTarget(); GLES20.glBindTexture(target, texture.getId()); checkError(); GLUtils.texSubImage2D(target, 0, xOffset, yOffset, bitmap, format, type); }
/** * Updates the content on GPU's memory. * @param canvas */ public void updateContent(GLCanvas canvas) { if (!isLoaded()) { if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) { return; } uploadToCanvas(canvas); } else if (!mContentValid) { Bitmap bitmap = getBitmap(); int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type); freeBitmap(); mContentValid = true; } }
/** * utility for checking GL errors * @param op */ public void checkGlError(String op) { int error; while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) { Log.e("SurfaceTest", op + ": glError " + GLUtils.getEGLErrorString(error)); } }
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, mBitmapEffect.getBitmap(), 0);
public static int loadTexture(final Bitmap img, final int usedTexId, final boolean recycle) { int textures[] = new int[1]; if (usedTexId == NO_TEXTURE) { GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textures[0]); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, img, 0); } else { GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, usedTexId); GLUtils.texSubImage2D(GLES20.GL_TEXTURE_2D, 0, 0, 0, img); textures[0] = usedTexId; } if (recycle) { img.recycle(); } return textures[0]; }
@Override public void texSubImage2D(BasicTexture texture, int xOffset, int yOffset, Bitmap bitmap, int format, int type) { int target = texture.getTarget(); GLES20.glBindTexture(target, texture.getId()); checkError(); GLUtils.texSubImage2D(target, 0, xOffset, yOffset, bitmap, format, type); }
/** * Updates the content on GPU's memory. * @param canvas */ public void updateContent(GLCanvas canvas) { if (!isLoaded()) { if (mThrottled && ++sUploadedCount > UPLOAD_LIMIT) { return; } uploadToCanvas(canvas); } else if (!mContentValid) { Bitmap bitmap = getBitmap(); int format = GLUtils.getInternalFormat(bitmap); int type = GLUtils.getType(bitmap); canvas.texSubImage2D(this, mBorder, mBorder, bitmap, format, type); freeBitmap(); mContentValid = true; } }