- Home /
Android OpenGL error in Unity 5 but not in Unity 4.6
I am calling native opengl functions to render to a framebuffer from unity. Specifically, I'm rendering a movie image to a framebuffer with a texture from unity attached. It all works in Unity 4.6 but when I moved the project to Unity 5, the program returns an invalid operation error after the glDrawElements function, and the image fails to render to the framebuffer.
Removing the glDrawElements function allows the program to run without errors, and I confirmed that changing the clear color does reflect the change in unity.
I suspect I am missing some step that by chance Unity 4 was doing, but not Unity 5, but I cannot seem to find it.
Can anyone help me?
Below is the code called every frame to draw to the framebuffer.
public void DrawFrame() {
synchronized(this) {
if (updateSurface) {
updateSurface = false;
//Log.d(TAG, "Update texture");
} else {
return; //no need to render texture
}
}
checkGlError("preDrawFrame");
//long drawStart = System.currentTimeMillis();
mSurfaceTexture.updateTexImage(); //updates the texture mTexExtOES
mSurfaceTexture.getTransformMatrix(mSTMatrix);
//bind fbo
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFBO);
//GLES20.glDisable(GLES20.GL_DEPTH_TEST);
GLES20.glDisable(GLES20.GL_CULL_FACE);
//GLES20.glDisable(GLES20.GL_SCISSOR_TEST);
//GLES20.glDepthMask(false);
GLES20.glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
GLES20.glClearDepthf(1);
GLES20.glClear( GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
//shader
GLES20.glUseProgram(mProgram);
checkGlError("glUseProgram");
//texture
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, mTexExtOES); //no need to bind, updateTexImage does that
GLES20.glUniform1i(mExtSamplerHandle, 0); //make sure the sampler is bound to the right texture unit
//GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureID);
//position
GLES20.glEnableVertexAttribArray(maPositionHandle);
checkGlError("glEnableVertexAttribArray maPositionHandle");
GLES20.glVertexAttribPointer(maPositionHandle, 4, GLES20.GL_FLOAT, false, 0, mVertexBuffer);
checkGlError("glVertexAttribPointer maPosition");
//uv
GLES20.glEnableVertexAttribArray(maTextureHandle);
checkGlError("glEnableVertexAttribArray maTextureHandle");
GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false, 0, mTexCoordBuffer);
checkGlError("glVertexAttribPointer maTextureHandle");
//Apply the combined projection and camera view transformations
GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
GLES20.glViewport(0, 0, mTexWidth, mTexHeight); //render on the whole texture
checkGlError("glViewport");
GLES20.glDrawElements(GLES20.GL_TRIANGLE_STRIP, 4, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer);
checkGlError("glDrawElements");
//reset //unnecessary since we call GL.Invalidate in unity anyway
//GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
//GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
//GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
//GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
//GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0);
//GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER, 0);
GLES20.glDisableVertexAttribArray(maPositionHandle);
GLES20.glDisableVertexAttribArray(maTextureHandle);
//restore bindings
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
}
Your answer
Follow this Question
Related Questions
using shared libraries generated by Android project in Unity 0 Answers
Image Not Sharing after Oreo version? 0 Answers
GL_LUMINANCE format for texture uploads in Android plugin 0 Answers
Failed to re-package resources after adding unity in-app purchase service 1 Answer
Android Native Plugin (*.SO) 2 Answers