Java Code Examples for android.opengl.GLES20#GL_TEXTURE_2D
The following examples show how to use
android.opengl.GLES20#GL_TEXTURE_2D .
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 |
/** * インスタンス生成のヘルパーメソッド(GL_TEXTURE_2D), デプスバッファ無し * テクスチャユニットはGL_TEXTURE0 * @param isGLES3 * @param tex_unit * @param width * @param height */ @SuppressLint("NewApi") public static GLSurface newInstance(final boolean isGLES3, final int tex_unit, final int width, final int height) { if (isGLES3 && BuildCheck.isAndroid4_3()) { return new GLSurfaceES3(GLES30.GL_TEXTURE_2D, tex_unit, -1, width, height, false, DEFAULT_ADJUST_POWER2); } else { return new GLSurfaceES2(GLES20.GL_TEXTURE_2D, tex_unit, -1, width, height, false, DEFAULT_ADJUST_POWER2); } }
Example 2
Source File: GLES20Canvas.java From android-openGL-canvas with Apache License 2.0 | 6 votes |
private void setupTextureFilter(int target, TextureFilter textureFilter) { if (textureFilter == null) { throw new NullPointerException("Texture filter is null."); } this.mTextureFilter = textureFilter; if (target == GLES20.GL_TEXTURE_2D) { if (mTextureFilterMapProgramId.containsKey(textureFilter)) { mTextureProgram = mTextureFilterMapProgramId.get(textureFilter); loadHandles(mTextureParameters, mTextureProgram); return; } mTextureProgram = loadAndAssemble(mTextureParameters, textureFilter.getVertexShader(), textureFilter.getFragmentShader()); mTextureFilterMapProgramId.put(textureFilter, mTextureProgram); } else { if (mOESTextureFilterMapProgramId.containsKey(textureFilter)) { mOesTextureProgram = mOESTextureFilterMapProgramId.get(textureFilter); loadHandles(mOesTextureParameters, mOesTextureProgram); return; } mOesTextureProgram = loadAndAssemble(mOesTextureParameters, textureFilter.getVertexShader(), textureFilter.getOesFragmentProgram()); mOESTextureFilterMapProgramId.put(textureFilter, mOesTextureProgram); } }
Example 3
Source File: GLSurface.java From libcommon with Apache License 2.0 | 6 votes |
/** * 既存のテクスチャ(GL_TEXTURE_2D)をwrapするためのインスタンス生成のヘルパーメソッド, デプスバッファなし * @param isGLES3 * @param tex_id * @param tex_unit * @param width * @param height */ @SuppressLint("NewApi") public static GLSurface newInstance(final boolean isGLES3, final int tex_unit, final int tex_id, final int width, final int height) { if (isGLES3 && BuildCheck.isAndroid4_3()) { return new GLSurfaceES3(GLES30.GL_TEXTURE_2D, tex_unit, tex_id, width, height, false, DEFAULT_ADJUST_POWER2); } else { return new GLSurfaceES2(GLES20.GL_TEXTURE_2D, tex_unit, tex_id, width, height, false, DEFAULT_ADJUST_POWER2); } }
Example 4
Source File: RawTexture.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
public void prepare(GLCanvas canvas) { GLId glId = canvas.getGLId(); mId = glId.generateTexture(); if (target == GLES20.GL_TEXTURE_2D) { canvas.initializeTextureSize(this, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE); } canvas.setTextureParameters(this); mState = STATE_LOADED; setAssociatedCanvas(canvas); }
Example 5
Source File: GLES20Canvas.java From TurboLauncher with Apache License 2.0 | 5 votes |
private ShaderParameter[] prepareTexture(BasicTexture texture) { ShaderParameter[] params; int program; if (texture.getTarget() == GLES20.GL_TEXTURE_2D) { params = mTextureParameters; program = mTextureProgram; } else { params = mOesTextureParameters; program = mOesTextureProgram; } prepareTexture(texture, program, params); return params; }
Example 6
Source File: ShaderRenderer.java From ShaderEditor with MIT License | 5 votes |
private void createTextures() { deleteTextures(); GLES20.glGenTextures(numberOfTextures, textureIds, 0); for (int i = 0; i < numberOfTextures; ++i) { String name = textureNames.get(i); if (UNIFORM_CAMERA_BACK.equals(name) || UNIFORM_CAMERA_FRONT.equals(name)) { // handled in onSurfaceChanged() because we need // the dimensions of the surface to pick a preview // resolution continue; } Bitmap bitmap = ShaderEditorApp.db.getTextureBitmap(name); if (bitmap == null) { continue; } switch (textureTargets[i]) { default: continue; case GLES20.GL_TEXTURE_2D: createTexture(textureIds[i], bitmap, textureParameters.get(i)); break; case GLES20.GL_TEXTURE_CUBE_MAP: createCubeTexture(textureIds[i], bitmap, textureParameters.get(i)); break; } bitmap.recycle(); } }
Example 7
Source File: GLES20Canvas.java From LB-Launcher with Apache License 2.0 | 5 votes |
private ShaderParameter[] prepareTexture(BasicTexture texture) { ShaderParameter[] params; int program; if (texture.getTarget() == GLES20.GL_TEXTURE_2D) { params = mTextureParameters; program = mTextureProgram; } else { params = mOesTextureParameters; program = mOesTextureProgram; } prepareTexture(texture, program, params); return params; }
Example 8
Source File: MultiTexOffScreenCanvas.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame() { mCanvas.clearBuffer(backgroundColor); if (producedTextureTarget != GLES20.GL_TEXTURE_2D) { for (GLTexture glTexture : producedTextureList) { glTexture.getSurfaceTexture().updateTexImage(); glTexture.getRawTexture().setNeedInvalidate(true); } } onGLDraw(mCanvas, producedTextureList, consumedTextures); }
Example 9
Source File: GLMultiTexProducerView.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
@Override public void onDrawFrame() { if (producedTextureTarget != GLES20.GL_TEXTURE_2D) { for (GLTexture glTexture : producedTextureList) { glTexture.getSurfaceTexture().updateTexImage(); glTexture.getRawTexture().setNeedInvalidate(true); } } super.onDrawFrame(); }
Example 10
Source File: GLES20Canvas.java From PhotoMovie with Apache License 2.0 | 5 votes |
protected ShaderParameter[] prepareTexture(BasicTexture texture) { ShaderParameter[] params; int program; if (texture.getTarget() == GLES20.GL_TEXTURE_2D) { params = mTextureParameters; program = mTextureProgram; } else { params = mOesTextureParameters; program = mOesTextureProgram; } prepareTexture(texture, program, params); return params; }
Example 11
Source File: GLSurface.java From libcommon with Apache License 2.0 | 5 votes |
/** * インスタンス生成のヘルパーメソッド(GL_TEXTURE_2D) * @param isGLES3 * @param tex_unit * @param width * @param height * @param use_depth_buffer * @param adjust_power2 */ @SuppressLint("NewApi") public static GLSurface newInstance(final boolean isGLES3, final int tex_unit, final int width, final int height, final boolean use_depth_buffer, final boolean adjust_power2) { if (isGLES3 && BuildCheck.isAndroid4_3()) { return new GLSurfaceES3(GLES30.GL_TEXTURE_2D, tex_unit, -1, width, height, use_depth_buffer, adjust_power2); } else { return new GLSurfaceES2(GLES20.GL_TEXTURE_2D, tex_unit, -1, width, height, use_depth_buffer, adjust_power2); } }
Example 12
Source File: Texture2dProgram.java From LiveVideoBroadcaster with Apache License 2.0 | 4 votes |
/** * Prepares the program in the current EGL activity. */ public Texture2dProgram(ProgramType programType) { mProgramType = programType; switch (programType) { case TEXTURE_2D: mTextureTarget = GLES20.GL_TEXTURE_2D; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D); break; case TEXTURE_EXT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT); break; case TEXTURE_EXT_BW: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_BW); break; case TEXTURE_EXT_GRAYSCALE: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_GRAY_SCALE); break; case TEXTURE_EXT_SEPIA: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_SEPIA); break; case TEXTURE_EXT_POSTERIZE: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_POSTERIZE); break; case TEXTURE_EXT_CROSSPROCESS: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_CROSSPROCESS); break; case TEXTURE_EXT_FILT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_FILT); break; default: throw new RuntimeException("Unhandled type " + programType); } if (mProgramHandle == 0) { throw new RuntimeException("Unable to create program"); } Log.d(TAG, "Created program " + mProgramHandle + " (" + programType + ")"); // get locations of attributes and uniforms maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); GlUtil.checkLocation(maPositionLoc, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix"); GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix"); GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix"); muKernelLoc = GLES20.glGetUniformLocation(mProgramHandle, "uKernel"); if (muKernelLoc < 0) { // no kernel in this one muKernelLoc = -1; muTexOffsetLoc = -1; muColorAdjustLoc = -1; } else { // has kernel, must also have tex offset and color adj muTexOffsetLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexOffset"); GlUtil.checkLocation(muTexOffsetLoc, "uTexOffset"); muColorAdjustLoc = GLES20.glGetUniformLocation(mProgramHandle, "uColorAdjust"); GlUtil.checkLocation(muColorAdjustLoc, "uColorAdjust"); // initialize default values setKernel(new float[] {0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f); setTexSize(256, 256); } }
Example 13
Source File: Texture2dProgram.java From cineio-broadcast-android with MIT License | 4 votes |
/** * Prepares the program in the current EGL context. */ public Texture2dProgram(ProgramType programType) { mProgramType = programType; switch (programType) { case TEXTURE_2D: mTextureTarget = GLES20.GL_TEXTURE_2D; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D); break; case TEXTURE_EXT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT); break; case TEXTURE_EXT_BW: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_BW); break; case TEXTURE_EXT_FILT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_FILT); break; default: throw new RuntimeException("Unhandled type " + programType); } if (mProgramHandle == 0) { throw new RuntimeException("Unable to create program"); } Log.d(TAG, "Created program " + mProgramHandle + " (" + programType + ")"); // get locations of attributes and uniforms maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); GlUtil.checkLocation(maPositionLoc, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix"); GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix"); GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix"); muKernelLoc = GLES20.glGetUniformLocation(mProgramHandle, "uKernel"); if (muKernelLoc < 0) { // no kernel in this one muKernelLoc = -1; muTexOffsetLoc = -1; muColorAdjustLoc = -1; } else { // has kernel, must also have tex offset and color adj muTexOffsetLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexOffset"); GlUtil.checkLocation(muTexOffsetLoc, "uTexOffset"); muColorAdjustLoc = GLES20.glGetUniformLocation(mProgramHandle, "uColorAdjust"); GlUtil.checkLocation(muColorAdjustLoc, "uColorAdjust"); // initialize default values setKernel(new float[]{0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f); setTexSize(256, 256); } }
Example 14
Source File: Texture2dProgram.java From FuAgoraDemoDroid with MIT License | 4 votes |
/** * Prepares the program in the current EGL context. */ public Texture2dProgram(ProgramType programType) { mProgramType = programType; switch (programType) { case TEXTURE_2D: mTextureTarget = GLES20.GL_TEXTURE_2D; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D); break; case TEXTURE_EXT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT); break; case TEXTURE_EXT_BW: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_BW); break; case TEXTURE_EXT_FILT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_FILT); break; default: throw new RuntimeException("Unhandled type " + programType); } if (mProgramHandle == 0) { throw new RuntimeException("Unable to create program"); } Log.d(TAG, "Created program " + mProgramHandle + " (" + programType + ")"); // get locations of attributes and uniforms maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); GlUtil.checkLocation(maPositionLoc, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix"); GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix"); GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix"); muKernelLoc = GLES20.glGetUniformLocation(mProgramHandle, "uKernel"); if (muKernelLoc < 0) { // no kernel in this one muKernelLoc = -1; muTexOffsetLoc = -1; muColorAdjustLoc = -1; } else { // has kernel, must also have tex offset and color adj muTexOffsetLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexOffset"); GlUtil.checkLocation(muTexOffsetLoc, "uTexOffset"); muColorAdjustLoc = GLES20.glGetUniformLocation(mProgramHandle, "uColorAdjust"); GlUtil.checkLocation(muColorAdjustLoc, "uColorAdjust"); // initialize default values setKernel(new float[]{0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f); setTexSize(256, 256); } }
Example 15
Source File: GLES20Canvas.java From android-openGL-canvas with Apache License 2.0 | 4 votes |
private void setRenderTarget(BasicTexture oldTexture, RawTexture texture) { // FIXME: 2016/11/18 If client version is 2, then bufferOES will crash... if (oldTexture == null && texture != null) { if (texture.getTarget() == GLES20.GL_TEXTURE_2D) { GLES20.glGenFramebuffers(1, mFrameBuffer, 0); checkError(); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffer[0]); checkError(); } else { GLES11Ext.glGenFramebuffersOES(1, mFrameBuffer, 0); checkError(); GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, mFrameBuffer[0]); checkError(); } } else if (oldTexture != null && texture == null) { if (oldTexture.getTarget() == GLES20.GL_TEXTURE_2D) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); checkError(); GLES20.glDeleteFramebuffers(1, mFrameBuffer, 0); checkError(); } else { GLES11Ext.glBindFramebufferOES(GLES11Ext.GL_FRAMEBUFFER_OES, 0); checkError(); GLES11Ext.glDeleteFramebuffersOES(1, mFrameBuffer, 0); checkError(); } } if (texture == null) { setSize(mScreenWidth, mScreenHeight); } else { setSize(texture.getWidth(), texture.getHeight()); if (!texture.isLoaded()) { texture.prepare(this); } if (texture.getTarget() == GLES20.GL_TEXTURE_2D) { GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, texture.getTarget(), texture.getId(), 0); checkError(); checkFramebufferStatus(); } else { GLES11Ext.glFramebufferTexture2DOES(GLES11Ext.GL_FRAMEBUFFER_OES, GLES11Ext.GL_COLOR_ATTACHMENT0_OES, texture.getTarget(), texture.getId(), 0); checkError(); checkFramebufferStatusOes(); } } }
Example 16
Source File: Texture2dProgram.java From PLDroidShortVideo with Apache License 2.0 | 4 votes |
/** * Prepares the program in the current EGL context. */ public Texture2dProgram(ProgramType programType) { mProgramType = programType; switch (programType) { case TEXTURE_2D: mTextureTarget = GLES20.GL_TEXTURE_2D; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D); break; case TEXTURE_EXT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT); break; case TEXTURE_EXT_BW: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_BW); break; case TEXTURE_EXT_FILT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_FILT); break; default: throw new RuntimeException("Unhandled type " + programType); } if (mProgramHandle == 0) { throw new RuntimeException("Unable to create program"); } Log.d(TAG, "Created program " + mProgramHandle + " (" + programType + ")"); // get locations of attributes and uniforms maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); GlUtil.checkLocation(maPositionLoc, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix"); GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix"); GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix"); muKernelLoc = GLES20.glGetUniformLocation(mProgramHandle, "uKernel"); if (muKernelLoc < 0) { // no kernel in this one muKernelLoc = -1; muTexOffsetLoc = -1; muColorAdjustLoc = -1; } else { // has kernel, must also have tex offset and color adj muTexOffsetLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexOffset"); GlUtil.checkLocation(muTexOffsetLoc, "uTexOffset"); muColorAdjustLoc = GLES20.glGetUniformLocation(mProgramHandle, "uColorAdjust"); GlUtil.checkLocation(muColorAdjustLoc, "uColorAdjust"); // initialize default values setKernel(new float[]{0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f); setTexSize(256, 256); } }
Example 17
Source File: Texture2dProgram.java From VideoRecorder with Apache License 2.0 | 4 votes |
/** * Prepares the program in the current EGL context. */ public Texture2dProgram(ProgramType programType) { mProgramType = programType; switch (programType) { case TEXTURE_2D: mTextureTarget = GLES20.GL_TEXTURE_2D; mProgramHandle = GLUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D); break; case TEXTURE_EXT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GLUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT); break; case TEXTURE_EXT_BW: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GLUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_BW); break; case TEXTURE_EXT_FILT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GLUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_FILT); break; default: throw new RuntimeException("Unhandled type " + programType); } if (mProgramHandle == 0) { throw new RuntimeException("Unable to create program"); } Log.d(TAG, "Created program " + mProgramHandle + " (" + programType + ")"); // get locations of attributes and uniforms maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); GLUtil.checkLocation(maPositionLoc, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); GLUtil.checkLocation(maTextureCoordLoc, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix"); GLUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix"); GLUtil.checkLocation(muTexMatrixLoc, "uTexMatrix"); muKernelLoc = GLES20.glGetUniformLocation(mProgramHandle, "uKernel"); if (muKernelLoc < 0) { // no kernel in this one muKernelLoc = -1; muTexOffsetLoc = -1; muColorAdjustLoc = -1; } else { // has kernel, must also have tex offset and color adj muTexOffsetLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexOffset"); GLUtil.checkLocation(muTexOffsetLoc, "uTexOffset"); muColorAdjustLoc = GLES20.glGetUniformLocation(mProgramHandle, "uColorAdjust"); GLUtil.checkLocation(muColorAdjustLoc, "uColorAdjust"); // initialize default values setKernel(new float[] {0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f); setTexSize(256, 256); } }
Example 18
Source File: EglUtil.java From media-for-mobile with Apache License 2.0 | 4 votes |
@Override public void drawFrameStart( Program program, FloatBuffer triangleVertices, float[] mvpMatrix, float[] stMatrix, float angle, TextureType textureType, int textureId, Resolution inputResolution, TextureRenderer.FillMode fillMode ) { checkEglError("onDrawFrame start"); Resolution out; switch (fillMode) { case PreserveSize: out = inputResolution; break; case PreserveAspectFit: case PreserveAspectCrop: out = getCurrentSurfaceResolution(); break; default: out = new Resolution(0, 0); break; } GLES20.glViewport(0, 0, out.width(), out.height()); GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f); GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT); GLES20.glUseProgram(program.programHandle); checkEglError("glUseProgram"); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); checkEglError("glActiveTexture"); int textureTypeId; if (textureType == TextureType.GL_TEXTURE_2D) { textureTypeId = GLES20.GL_TEXTURE_2D; } else { textureTypeId = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; } GLES20.glBindTexture(textureTypeId, textureId); checkEglError("glBindTexture"); triangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET); GLES20.glVertexAttribPointer(program.positionHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices); checkEglError("glVertexAttribPointer maPosition"); GLES20.glEnableVertexAttribArray(program.positionHandle); checkEglError("glEnableVertexAttribArray maPositionHandle"); triangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET); GLES20.glVertexAttribPointer(program.textureHandle, 3, GLES20.GL_FLOAT, false, TRIANGLE_VERTICES_DATA_STRIDE_BYTES, triangleVertices); checkEglError("glVertexAttribPointer maTextureHandle"); GLES20.glEnableVertexAttribArray(program.textureHandle); checkEglError("glEnableVertexAttribArray maTextureHandle"); Matrix.setIdentityM(mvpMatrix, 0); float scale[]; switch (fillMode) { case PreserveAspectFit: scale = scaleCalculator.getScale_PreserveAspectFit((int) angle, inputResolution.width(), inputResolution.height(), out.width(), out.height()); Matrix.scaleM(mvpMatrix, 0, scale[0], scale[1], 1); Matrix.rotateM(mvpMatrix, 0, -angle, 0.f, 0.f, 1.f); break; case PreserveAspectCrop: scale = scaleCalculator.getScale_PreserveAspectCrop((int) angle, inputResolution.width(), inputResolution.height(), out.width(), out.height()); Matrix.scaleM(mvpMatrix, 0, scale[0], scale[1], 1); Matrix.rotateM(mvpMatrix, 0, -angle, 0.f, 0.f, 1.f); break; case PreserveSize: if (angle == 90 || angle == 270) { Matrix.rotateM(mvpMatrix, 0, 180, 0.f, 0.f, 1.f); } break; default: break; } GLES20.glUniformMatrix4fv(program.mvpMatrixHandle, 1, false, mvpMatrix, 0); GLES20.glUniformMatrix4fv(program.stMatrixHandle, 1, false, stMatrix, 0); }
Example 19
Source File: Texture2dProgram.java From mobile-ar-sensor-logger with GNU General Public License v3.0 | 4 votes |
/** * Prepares the program in the current EGL context. */ public Texture2dProgram(ProgramType programType) { mProgramType = programType; switch (programType) { case TEXTURE_2D: mTextureTarget = GLES20.GL_TEXTURE_2D; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_2D); break; case TEXTURE_EXT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT); break; case TEXTURE_EXT_BW: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_BW); break; case TEXTURE_EXT_FILT: mTextureTarget = GLES11Ext.GL_TEXTURE_EXTERNAL_OES; mProgramHandle = GlUtil.createProgram(VERTEX_SHADER, FRAGMENT_SHADER_EXT_FILT); break; default: throw new RuntimeException("Unhandled type " + programType); } if (mProgramHandle == 0) { throw new RuntimeException("Unable to create program"); } Log.d(TAG, "Created program " + mProgramHandle + " (" + programType + ")"); // get locations of attributes and uniforms maPositionLoc = GLES20.glGetAttribLocation(mProgramHandle, "aPosition"); GlUtil.checkLocation(maPositionLoc, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(mProgramHandle, "aTextureCoord"); GlUtil.checkLocation(maTextureCoordLoc, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uMVPMatrix"); GlUtil.checkLocation(muMVPMatrixLoc, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexMatrix"); GlUtil.checkLocation(muTexMatrixLoc, "uTexMatrix"); muKernelLoc = GLES20.glGetUniformLocation(mProgramHandle, "uKernel"); if (muKernelLoc < 0) { // no kernel in this one muKernelLoc = -1; muTexOffsetLoc = -1; muColorAdjustLoc = -1; } else { // has kernel, must also have tex offset and color adj muTexOffsetLoc = GLES20.glGetUniformLocation(mProgramHandle, "uTexOffset"); GlUtil.checkLocation(muTexOffsetLoc, "uTexOffset"); muColorAdjustLoc = GLES20.glGetUniformLocation(mProgramHandle, "uColorAdjust"); GlUtil.checkLocation(muColorAdjustLoc, "uColorAdjust"); // initialize default values setKernel(new float[] {0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f}, 0f); setTexSize(256, 256); } }
Example 20
Source File: GLTexture.java From libcommon with Apache License 2.0 | 2 votes |
/** * コンストラクタ * テクスチャユニットが常時GL_TEXTURE0なので複数のテクスチャを同時に使えない * @param width テクスチャサイズ * @param height テクスチャサイズ * @param filter_param テクスチャの補間方法を指定 GL_LINEARとかGL_NEAREST */ public GLTexture(final int width, final int height, final int filter_param) { this(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE0, width, height, filter_param); }