Java Code Examples for android.opengl.GLES20#glUniformMatrix3fv()
The following examples show how to use
android.opengl.GLES20#glUniformMatrix3fv() .
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: MediaEffectGLTexProjection.java From libcommon with Apache License 2.0 | 5 votes |
@Override protected void preDraw(@NonNull final int[] tex_ids, final float[] tex_matrix, final int offset) { // テクスチャ変換行列をセット if (muTexMatrixLoc2 >= 0) { GLES20.glUniformMatrix3fv(muTexMatrixLoc2, 1, false, texMatrix2, 0); GLHelper.checkGlError("glUniformMatrix3fv"); } super.preDraw(tex_ids, tex_matrix, offset); }
Example 2
Source File: VideoDecoderRenderer.java From MediaSDK with Apache License 2.0 | 4 votes |
@Override public void onDrawFrame(GL10 unused) { VideoDecoderOutputBuffer pendingOutputBuffer = pendingOutputBufferReference.getAndSet(null); if (pendingOutputBuffer == null && renderedOutputBuffer == null) { // There is no output buffer to render at the moment. return; } if (pendingOutputBuffer != null) { if (renderedOutputBuffer != null) { renderedOutputBuffer.release(); } renderedOutputBuffer = pendingOutputBuffer; } VideoDecoderOutputBuffer outputBuffer = renderedOutputBuffer; // Set color matrix. Assume BT709 if the color space is unknown. float[] colorConversion = kColorConversion709; switch (outputBuffer.colorspace) { case VideoDecoderOutputBuffer.COLORSPACE_BT601: colorConversion = kColorConversion601; break; case VideoDecoderOutputBuffer.COLORSPACE_BT2020: colorConversion = kColorConversion2020; break; case VideoDecoderOutputBuffer.COLORSPACE_BT709: default: break; // Do nothing } GLES20.glUniformMatrix3fv(colorMatrixLocation, 1, false, colorConversion, 0); for (int i = 0; i < 3; i++) { int h = (i == 0) ? outputBuffer.height : (outputBuffer.height + 1) / 2; GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, yuvTextures[i]); GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); GLES20.glTexImage2D( GLES20.GL_TEXTURE_2D, 0, GLES20.GL_LUMINANCE, outputBuffer.yuvStrides[i], h, 0, GLES20.GL_LUMINANCE, GLES20.GL_UNSIGNED_BYTE, outputBuffer.yuvPlanes[i]); } int[] widths = new int[3]; widths[0] = outputBuffer.width; // TODO: Handle streams where chroma channels are not stored at half width and height // compared to luma channel. See [Internal: b/142097774]. // U and V planes are being stored at half width compared to Y. widths[1] = widths[2] = (widths[0] + 1) / 2; for (int i = 0; i < 3; i++) { // Set cropping of stride if either width or stride has changed. if (previousWidths[i] != widths[i] || previousStrides[i] != outputBuffer.yuvStrides[i]) { Assertions.checkState(outputBuffer.yuvStrides[i] != 0); float widthRatio = (float) widths[i] / outputBuffer.yuvStrides[i]; // These buffers are consumed during each call to glDrawArrays. They need to be member // variables rather than local variables in order not to get garbage collected. textureCoords[i] = GlUtil.createBuffer( new float[] {0.0f, 0.0f, 0.0f, 1.0f, widthRatio, 0.0f, widthRatio, 1.0f}); GLES20.glVertexAttribPointer( texLocations[i], 2, GLES20.GL_FLOAT, false, 0, textureCoords[i]); previousWidths[i] = widths[i]; previousStrides[i] = outputBuffer.yuvStrides[i]; } } GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); GlUtil.checkGlError(); }
Example 3
Source File: ShaderProgram.java From VideoRecorder with Apache License 2.0 | 4 votes |
public void setUniformMatrix3fv(final int location, final float[] matrix) { GLES20.glUniformMatrix3fv(location, 1, false, matrix, 0); }
Example 4
Source File: FrameRenderer.java From DanDanPlayForAndroid with MIT License | 4 votes |
@Override public void onDrawFrame() { FrameBuffer pendingOutputBuffer = pendingOutputBufferReference.getAndSet(null); if (pendingOutputBuffer == null && renderedOutputBuffer == null) { // There is no output buffer to render at the moment. return; } if (pendingOutputBuffer != null) { if (renderedOutputBuffer != null) { renderedOutputBuffer.release(); } renderedOutputBuffer = pendingOutputBuffer; } FrameBuffer outputBuffer = renderedOutputBuffer; // Set color matrix. Assume BT709 if the color space is unknown. float[] colorConversion = kColorConversion709; /*switch (outputBuffer.pixelFormat) { case FrameBuffer.COLORSPACE_BT601: colorConversion = kColorConversion601; break; case FrameBuffer.COLORSPACE_BT2020: colorConversion = kColorConversion2020; break; case FrameBuffer.COLORSPACE_BT709: default: break; // Do nothing }*/ int bitDepth = outputBuffer.bitDepth; int format = bitDepth == 1 ? GLES20.GL_LUMINANCE : GLES20.GL_LUMINANCE_ALPHA; GLES20.glUniformMatrix3fv(colorMatrixLocation, 1, false, colorConversion, 0); GLES20.glUniform1f(bitDepthLocation, bitDepth); for (int i = 0; i < 3; i++) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + i); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, yuvTextures[i]); int width = outputBuffer.yuvStrides[i] / bitDepth; int height = (i == 0) ? outputBuffer.height : outputBuffer.height / 2; GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, format, width, height, 0, format, GLES20.GL_UNSIGNED_BYTE, outputBuffer.yuvPlanes[i]); } // Set cropping of stride if either width or stride has changed. if (previousWidth != outputBuffer.width || previousStride != outputBuffer.yuvStrides[0]) { float crop = (float) outputBuffer.width * bitDepth / outputBuffer.yuvStrides[0]; // This buffer is consumed during each call to glDrawArrays. It needs to be a member variable // rather than a local variable to ensure that it doesn't get garbage collected. textureCoords = nativeFloatBuffer( 0.0f, 0.0f, 0.0f, 1.0f, crop, 0.0f, crop, 1.0f); GLES20.glVertexAttribPointer( texLocation, 2, GLES20.GL_FLOAT, false, 0, textureCoords); previousWidth = outputBuffer.width; previousStride = outputBuffer.yuvStrides[0]; } GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); checkNoGLES2Error(); }
Example 5
Source File: Faltung3x3Filter.java From AAVT with Apache License 2.0 | 4 votes |
@Override protected void onSetExpandData() { super.onSetExpandData(); GLES20.glUniformMatrix3fv(mGLFaltung,1,false,mFaltung,0); }
Example 6
Source File: Uniform.java From YetAnotherPixelDungeon with GNU General Public License v3.0 | 4 votes |
public void valueM3( float[] value ) { GLES20.glUniformMatrix3fv( location, 1, false, value, 0 ); }
Example 7
Source File: AndroidGL.java From trekarta with GNU General Public License v3.0 | 4 votes |
@Override public void uniformMatrix3fv(int location, int count, boolean transpose, FloatBuffer value) { GLES20.glUniformMatrix3fv(location, count, transpose, value); }
Example 8
Source File: AndroidGL.java From trekarta with GNU General Public License v3.0 | 4 votes |
@Override public void uniformMatrix3fv(int location, int count, boolean transpose, float[] value, int offset) { GLES20.glUniformMatrix3fv(location, count, transpose, value, offset); }
Example 9
Source File: Uniform.java From remixed-dungeon with GNU General Public License v3.0 | 4 votes |
public void valueM3( float[] value ) { GLES20.glUniformMatrix3fv( location, 1, false, value, 0 ); }
Example 10
Source File: GLSprite.java From Tanks with MIT License | 4 votes |
@Override public void draw(RendererContext context) { Data data = dataProvider.get(); Vector3 color = data.colorCoefficients; ShaderSprite shader = (ShaderSprite)Shader.getCurrent(); // get dynamic resources Image image = GameContext.resources.getImage(new FileImageSource(data.imageName)); Texture textureData = GameContext.resources.getTexture(new FileTextureSource(image.getTextureName(), false)); // set texture matrix setTextureCoordinates(image.getCoordinates()); // build result matrix Matrix.multiplyMM(modelViewMatrix, 0, context.getOrthoMatrix(), 0, data.modelMatrix, 0); // bind texture to 0 slot GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle()); // send data to shader GLES20.glUniform1i(shader.uniformTextureHandle, 0); GLES20.glUniformMatrix3fv(shader.uniformTextureMatrixHandle, 1, false, textureMatrix.getArray(), 0); GLES20.glUniformMatrix4fv(shader.uniformModelViewMatrixHandle, 1, false, modelViewMatrix, 0); GLES20.glUniform4f(shader.uniformColorCoefficients, color.getX(), color.getY(), color.getZ(), 1); // set buffer or reset if dynamic GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle()); switch (geometryData.getMode()) { case Static: GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, 0); GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, 8); break; case Dynamic: FloatBuffer buffer = geometryData.getData(); buffer.position(0); GLES20.glVertexAttribPointer(shader.attributePositionHandle, 2, GLES20.GL_FLOAT, false, 16, buffer); buffer.position(2); GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 16, buffer); break; } // enable arrays GLES20.glEnableVertexAttribArray(shader.attributePositionHandle); GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle); // validating if debug shader.validate(); geometryData.validate(); textureData.validate(); // draw GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount()); // disable arrays GLES20.glDisableVertexAttribArray(shader.attributePositionHandle); GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle); // release dynamic resources GameContext.resources.release(image); GameContext.resources.release(textureData); }
Example 11
Source File: GLModel.java From Tanks with MIT License | 4 votes |
@Override public void draw(RendererContext context, Data data) { ShaderModel shader = (ShaderModel) Shader.getCurrent(); Light.Data light = context.getLight(); // build PVM matrix Matrix.multiplyMM(modelProjectionViewMatrix, 0, context.getProjectionViewMatrix(), 0, modelMatrix, 0); // bind texture to 0 slot GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureData.getHandle()); // send uniform data to shader GLES20.glUniform1i(shader.uniformTextureHandle, 0); GLES20.glUniformMatrix4fv(shader.uniformMatrixProjectionHandle, 1, false, modelProjectionViewMatrix, 0); GLES20.glUniformMatrix3fv(shader.uniformNormalMatrix, 1, false, modelNormalMatrix, 0); GLES20.glUniformMatrix4fv(shader.uniformMatrixHandle, 1, false, modelMatrix, 0); GLES20.glUniform3fv(shader.uniformLightVectorHandle, 1, light.Position.getRaw(), 0); GLES20.glUniform4f(shader.uniformColorCoefficients, data.redCoeff, data.greenCoeff, data.blueCoeff, 1.0f); // bind data buffer GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, geometryData.getHandle()); // set offsets to arrays for buffer GLES20.glVertexAttribPointer(shader.attributePositionHandle, 3, GLES20.GL_FLOAT, false, 32, 0); GLES20.glVertexAttribPointer(shader.attributeNormalHandle, 3, GLES20.GL_FLOAT, false, 32, 12); GLES20.glVertexAttribPointer(shader.attributeTexCoordHandle, 2, GLES20.GL_FLOAT, false, 32, 24); // enable attribute arrays GLES20.glEnableVertexAttribArray(shader.attributePositionHandle); GLES20.glEnableVertexAttribArray(shader.attributeNormalHandle); GLES20.glEnableVertexAttribArray(shader.attributeTexCoordHandle); // validating if debug shader.validate(); geometryData.validate(); textureData.validate(); // draw GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, geometryData.getPointsCount()); // disable attribute arrays GLES20.glDisableVertexAttribArray(shader.attributePositionHandle); GLES20.glDisableVertexAttribArray(shader.attributeNormalHandle); GLES20.glDisableVertexAttribArray(shader.attributeTexCoordHandle); }
Example 12
Source File: Uniform.java From PD-classes with GNU General Public License v3.0 | 4 votes |
public void valueM3( float[] value ) { GLES20.glUniformMatrix3fv( location, 1, false, value, 0 ); }
Example 13
Source File: SepiaEffect.java From media-for-mobile with Apache License 2.0 | 4 votes |
@Override protected void addEffectSpecific() { GLES20.glUniformMatrix3fv(weightsMatrixHandle, 1, false, getWeights(), 0); }
Example 14
Source File: ShaderRenderer.java From ShaderEditor with MIT License | 4 votes |
private void setRotationMatrix() { boolean haveInclination = false; if (gravityListener != null && magneticFieldListener != null && SensorManager.getRotationMatrix( rotationMatrix, inclinationMatrix, gravityValues, magneticFieldListener.filtered)) { haveInclination = true; } else if (rotationVectorListener != null) { SensorManager.getRotationMatrixFromVector( rotationMatrix, rotationVectorListener.values); } else { return; } if (deviceRotation != 0) { int x = SensorManager.AXIS_Y; int y = SensorManager.AXIS_MINUS_X; switch (deviceRotation) { default: break; case 270: x = SensorManager.AXIS_MINUS_Y; y = SensorManager.AXIS_X; break; } SensorManager.remapCoordinateSystem( rotationMatrix, x, y, rotationMatrix); } if (rotationMatrixLoc > -1) { GLES20.glUniformMatrix3fv(rotationMatrixLoc, 1, true, rotationMatrix, 0); } if (orientationLoc > -1) { SensorManager.getOrientation(rotationMatrix, orientation); GLES20.glUniform3fv(orientationLoc, 1, orientation, 0); } if (inclinationMatrixLoc > -1 && haveInclination) { GLES20.glUniformMatrix3fv(inclinationMatrixLoc, 1, true, inclinationMatrix, 0); } if (inclinationLoc > -1 && haveInclination) { GLES20.glUniform1f(inclinationLoc, SensorManager.getInclination(inclinationMatrix)); } }