Java Code Examples for android.opengl.GLES30#glActiveTexture()
The following examples show how to use
android.opengl.GLES30#glActiveTexture() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GLSurface.java From libcommon with Apache License 2.0 | 6 votes |
/** * Bitmapから画像をテクスチャに読み込む * @param bitmap */ @Override public void loadBitmap(@NonNull final Bitmap bitmap) { final int width = bitmap.getWidth(); final int height = bitmap.getHeight(); if ((width > mTexWidth) || (height > mTexHeight)) { mWidth = width; mHeight = height; releaseFrameBuffer(); createFrameBuffer(width, height); } GLES30.glActiveTexture(TEX_UNIT); GLES30.glBindTexture(TEX_TARGET, mFBOTexId); GLUtils.texImage2D(TEX_TARGET, 0, bitmap, 0); GLES30.glBindTexture(TEX_TARGET, 0); // initialize texture matrix Matrix.setIdentityM(mTexMatrix, 0); mTexMatrix[0] = width / (float)mTexWidth; mTexMatrix[5] = height / (float)mTexHeight; }
Example 2
Source File: OverlayRendererHolder.java From libcommon with Apache License 2.0 | 6 votes |
/** * internalOnStartの下請け、GLES3用 */ @WorkerThread private void internalOnStartES3() { if (DEBUG) Log.v(TAG, String.format("internalOnStartES3:init overlay texture(%dx%d)", width(), height())); if (DEBUG) Log.v(TAG, "internalOnStartES3:shader=" + MY_FRAGMENT_SHADER_EXT_ES3); mDrawer.updateShader(MY_FRAGMENT_SHADER_EXT_ES3); final int uTex1 = mDrawer.glGetUniformLocation("sTexture"); GLES30.glUniform1i(uTex1, 0); if (DEBUG) Log.v(TAG, "internalOnStart:uTex1=" + uTex1); final int uTex2 = mDrawer.glGetUniformLocation("sTexture2"); mOverlayTexId = GLHelper.initTex( GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE1, GLES30.GL_LINEAR, GLES30.GL_LINEAR, GLES30.GL_CLAMP_TO_EDGE); mOverlayTexture = new SurfaceTexture(mOverlayTexId); mOverlayTexture.setDefaultBufferSize(width(), height()); mOverlaySurface = new Surface(mOverlayTexture); GLES30.glActiveTexture(GLES30.GL_TEXTURE1); GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mOverlayTexId); GLES30.glUniform1i(uTex2, 1); if (DEBUG) Log.v(TAG, "internalOnStart:uTex2=" + uTex2); }
Example 3
Source File: GLHelper.java From libcommon with Apache License 2.0 | 5 votes |
/** * テクスチャ名を生成(GL_TEXTURE0のみ) * @param texTarget テクスチャのタイプ, GL_TEXTURE_EXTERNAL_OESかGL_TEXTURE_2D * @param texUnit テクスチャユニット, GL_TEXTURE0...GL_TEXTURE31 * @param minFilter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST * @param magFilter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST * @param wrap テクスチャのクランプ方法, GL_CLAMP_TO_EDGE等 * @return */ public static int initTex(final int texTarget, final int texUnit, final int minFilter, final int magFilter, final int wrap) { if (DEBUG) Log.v(TAG, "initTex:target=" + texTarget); final int[] tex = new int[1]; GLES30.glActiveTexture(texUnit); GLES30.glGenTextures(1, tex, 0); GLES30.glBindTexture(texTarget, tex[0]); GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_WRAP_S, wrap); GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_WRAP_T, wrap); GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_MIN_FILTER, minFilter); GLES30.glTexParameteri(texTarget, GLES30.GL_TEXTURE_MAG_FILTER, magFilter); return tex[0]; }
Example 4
Source File: GLTexture.java From libcommon with Apache License 2.0 | 5 votes |
/** * このインスタンスで管理しているテクスチャを有効にする(バインドする) */ @Override public void makeCurrent() { // if (DEBUG) Log.v(TAG, "makeCurrent:"); GLES30.glActiveTexture(mTextureUnit); // テクスチャユニットを選択 GLES30.glBindTexture(mTextureTarget, mTextureId); setViewPort(viewPortX, viewPortY, viewPortWidth, viewPortHeight); }
Example 5
Source File: GLTexture.java From libcommon with Apache License 2.0 | 5 votes |
/** * このインスタンスで管理しているテクスチャを無効にする(アンバインドする) */ @Override public void swap() { // if (DEBUG) Log.v(TAG, "swap:"); GLES30.glActiveTexture(mTextureUnit); // テクスチャユニットを選択 GLES30.glBindTexture(mTextureTarget, 0); }
Example 6
Source File: GLSurface.java From libcommon with Apache License 2.0 | 5 votes |
/** * ISurfaceの実装 * オフスクリーン描画用のレンダリングバッファに切り替える * Viewportも変更になるので必要であればunbind後にViewportの設定をすること */ @Override public void makeCurrent() { if (DEBUG) Log.v(TAG, "makeCurrent:"); GLES30.glActiveTexture(TEX_UNIT); GLES30.glBindTexture(TEX_TARGET, mFBOTexId); GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFrameBufferObj); setViewPort(viewPortX, viewPortY, viewPortWidth, viewPortHeight); }
Example 7
Source File: GLSurface.java From libcommon with Apache License 2.0 | 5 votes |
/** * ISurfaceの実装 */ @Override public void swap() { if (DEBUG) Log.v(TAG, "swap:"); GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0); GLES30.glActiveTexture(TEX_UNIT); GLES30.glBindTexture(TEX_TARGET, 0); }
Example 8
Source File: OverlayRendererHolder.java From libcommon with Apache License 2.0 | 5 votes |
@SuppressLint("NewApi") @WorkerThread private void handleUpdateOverlay(final int targetId, @NonNull final Bitmap overlay) { if (DEBUG) Log.v(TAG, "handleUpdateOverlay:" + overlay); if (isGLES3()) { GLES30.glActiveTexture(GLES30.GL_TEXTURE1); GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mOverlayTexId); } else { GLES20.glActiveTexture(GLES20.GL_TEXTURE1); GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mOverlayTexId); } try { final Canvas canvas = mOverlaySurface.lockCanvas(null); try { if (overlay != null) { canvas.drawBitmap(overlay, 0, 0, null); } else if (DEBUG) { // DEBUGフラグtrueでオーバーレイ映像が設定されていないときは全面を薄赤色にする canvas.drawColor(0x7fff0000); // ARGB } else { // DEBUGフラグfalseでオーバーレイ映像が設定されていなければ全面透過 canvas.drawColor(0x00000000); // ARGB } } finally { mOverlaySurface.unlockCanvasAndPost(canvas); } } catch (final Exception e) { Log.w(TAG, e); } requestFrame(); }
Example 9
Source File: MixRendererHolder.java From libcommon with Apache License 2.0 | 5 votes |
/** * マスク用のBitmapをセットする * Bitmapがnullの時はα=1で全面を塗りつぶす(見えるように赤) * @param mask */ protected void handleSetMask(@Nullable final Bitmap mask) { if (DEBUG) Log.v(TAG, "handleSetMask:" + mask); if (isGLES3()) { GLES30.glActiveTexture(GLES30.GL_TEXTURE2); GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mMaskTexId); } else { GLES20.glActiveTexture(GLES20.GL_TEXTURE2); GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mMaskTexId); } try { final Canvas canvas = mMaskSurface.lockCanvas(null); try { if (mask != null) { canvas.drawBitmap(mask, 0, 0, null); } else if (DEBUG) { // DEBUGフラグtrueでオーバーレイ映像が設定されていないときは全面を薄赤色にする canvas.drawColor(0x7fff0000); // ARGB } else { // DEBUGフラグfalseでオーバーレイ映像が設定されていなければ全面透過 canvas.drawColor(0xff000000); // ARGB } } finally { mMaskSurface.unlockCanvasAndPost(canvas); } } catch (final Exception e) { Log.w(TAG, e); } requestFrame(); if (DEBUG) Log.v(TAG, "handleSetMask:finished"); }
Example 10
Source File: GLSurface.java From libcommon with Apache License 2.0 | 4 votes |
/** * 指定したテクスチャをこのオフスクリーンに割り当てる * @param texture_name * @param width * @param height */ public void assignTexture(final int texture_name, final int width, final int height) { if ((width > mTexWidth) || (height > mTexHeight)) { mWidth = width; mHeight = height; releaseFrameBuffer(); createFrameBuffer(width, height); } mFBOTexId = texture_name; GLES30.glActiveTexture(TEX_UNIT); // フレームバッファオブジェクトをbindする GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, mFrameBufferObj); com.serenegiant.glutils.es3.GLHelper.checkGlError("glBindFramebuffer " + mFrameBufferObj); // フレームバッファにカラーバッファ(テクスチャ)を接続する GLES30.glFramebufferTexture2D(GLES30.GL_FRAMEBUFFER, GLES30.GL_COLOR_ATTACHMENT0, TEX_TARGET, mFBOTexId, 0); com.serenegiant.glutils.es3.GLHelper.checkGlError("glFramebufferTexture2D"); if (mHasDepthBuffer) { // フレームバッファにデプスバッファを接続する GLES30.glFramebufferRenderbuffer(GLES30.GL_FRAMEBUFFER, GLES30.GL_DEPTH_ATTACHMENT, GLES30.GL_RENDERBUFFER, mDepthBufferObj); com.serenegiant.glutils.es3.GLHelper.checkGlError("glFramebufferRenderbuffer"); } // 正常に終了したかどうかを確認する final int status = GLES30.glCheckFramebufferStatus(GLES30.GL_FRAMEBUFFER); if (status != GLES30.GL_FRAMEBUFFER_COMPLETE) { throw new RuntimeException("Framebuffer not complete, status=" + status); } // デフォルトのフレームバッファに戻す GLES30.glBindFramebuffer(GLES30.GL_FRAMEBUFFER, 0); // テクスチャ座標変換行列を初期化 Matrix.setIdentityM(mTexMatrix, 0); mTexMatrix[0] = width / (float)mTexWidth; mTexMatrix[5] = height / (float)mTexHeight; }
Example 11
Source File: GLDrawer2DES3.java From libcommon with Apache License 2.0 | 4 votes |
@Override protected void bindTexture(final int texId) { GLES30.glActiveTexture(GLES30.GL_TEXTURE0); GLES30.glBindTexture(mTexTarget, texId); }
Example 12
Source File: MixRendererHolder.java From libcommon with Apache License 2.0 | 4 votes |
/** * internalOnStartの下請け、GLES3用 */ @SuppressLint("NewApi") @WorkerThread private void internalOnStartES3() { if (DEBUG) Log.v(TAG, String.format("internalOnStartES3:init mix texture(%dx%d)", width(), height())); mDrawer.updateShader(MY_FRAGMENT_SHADER_EXT_ES3); final int uTex1 = mDrawer.glGetUniformLocation("sTexture"); GLES30.glUniform1i(uTex1, 0); // アルファブレンド用テクスチャ/SurfaceTexture/Surfaceを生成 final int uTex2 = mDrawer.glGetUniformLocation("sTexture2"); mTexId2 = GLHelper.initTex( GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE1, GLES30.GL_LINEAR, GLES30.GL_LINEAR, GLES30.GL_CLAMP_TO_EDGE); mMasterTexture2 = new SurfaceTexture(mTexId2); mMasterTexture2.setDefaultBufferSize(width(), height()); mMasterSurface2 = new Surface(mMasterTexture2); if (BuildCheck.isAndroid5()) { mMasterTexture2.setOnFrameAvailableListener( mOnFrameAvailableListener, mAsyncHandler); } else { mMasterTexture2.setOnFrameAvailableListener( mOnFrameAvailableListener); } GLES30.glActiveTexture(GLES30.GL_TEXTURE1); GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexId2); GLES30.glUniform1i(uTex2, 1); // マスク用テクスチャ/SurfaceTexture/Surfaceを生成 final int uTex3 = mDrawer.glGetUniformLocation("sTexture3"); mMaskTexId = GLHelper.initTex( GL_TEXTURE_EXTERNAL_OES, GLES30.GL_TEXTURE2, GLES30.GL_LINEAR, GLES30.GL_LINEAR, GLES30.GL_CLAMP_TO_EDGE); mMaskTexture = new SurfaceTexture(mMaskTexId); mMaskTexture.setDefaultBufferSize(width(), height()); mMaskSurface = new Surface(mMaskTexture); GLES30.glActiveTexture(GLES30.GL_TEXTURE2); GLES30.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mMaskTexId); GLES30.glUniform1i(uTex3, 2); }