• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by mtora · Jun 11, 2015 at 10:37 AM · androidunity 5pluginopenglnative

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);
     }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to access an Android native plugin in unity ? 0 Answers

Unity+ARToolkit embedded in AndroidStudio Help 2 Answers

Native c++ plugin on android 0 Answers

Any resource for creating jar without extending UnityActivityPlayer? 1 Answer

Problem with Google Play Game Services: Invalid Classname 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges