Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 ahuertasLOOT · Apr 04, 2016 at 06:02 PM · graphicsrendertexturejavaandroidpluginopengl es 2.0

Using Rendertexture on Android Native JAR

Hello, I'm trying to render an image using GLES in an Android Java library. When I try to clear the color buffer or attempt to draw to the binded rendertexture, I get a glerror 1286. From what I researched, this error is a result of an invalid framebuffer being used. Are unity rendertextures the same as a framebuffer? How should I use a GL_TEXTURE_EXTERNAL_OES texture in Unity?

Here's what I have so far:

Java:

         public void drawFrame(SurfaceTexture st, boolean invert, int renderTexture) {
             //bind to unity rendertexture
             GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, renderTexture);
             checkGlError("glBindFramebuffer");
             GLES20.glViewport(0,0, 512, 512);
             checkGlError("glViewport");
             GLES20.glDisable(GLES20.GL_DEPTH_TEST);
             checkGlError("onDrawFrame start");
             st.getTransformMatrix(mSTMatrix);
             if (invert) {
                 mSTMatrix[5] = -mSTMatrix[5];
                 mSTMatrix[13] = 1.0f - mSTMatrix[13];
             }
 
             GLES20.glUseProgram(mProgram);
             checkGlError("glUseProgram");
 
             //binding the gl texture oes from an android surfacetexture
             GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
             GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureID);
             mTriangleVertices.position(TRIANGLE_VERTICES_DATA_POS_OFFSET);
             GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false,
                     TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
             checkGlError("glVertexAttribPointer maPosition");
             GLES20.glEnableVertexAttribArray(maPositionHandle);
             checkGlError("glEnableVertexAttribArray maPositionHandle");
 
             mTriangleVertices.position(TRIANGLE_VERTICES_DATA_UV_OFFSET);
             GLES20.glVertexAttribPointer(maTextureHandle, 2, GLES20.GL_FLOAT, false,
                     TRIANGLE_VERTICES_DATA_STRIDE_BYTES, mTriangleVertices);
             checkGlError("glVertexAttribPointer maTextureHandle");
             GLES20.glEnableVertexAttribArray(maTextureHandle);
             checkGlError("glEnableVertexAttribArray maTextureHandle");
 
             Matrix.setIdentityM(mMVPMatrix, 0);
             GLES20.glUniformMatrix4fv(muMVPMatrixHandle, 1, false, mMVPMatrix, 0);
             GLES20.glUniformMatrix4fv(muSTMatrixHandle, 1, false, mSTMatrix, 0);
 
             //draw the surfacetexture to the rendertexture returning glError 1286
             GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
             checkGlError("glDrawArrays");
 
             GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
             GLES20.glEnable(GLES20.GL_DEPTH_TEST);
             //unbind rendertexture
             GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
         }

Unity C#:

         if (!textureTarget)
         {
             textureTarget = new RenderTexture(512, 512, 16, RenderTextureFormat.ARGB32);
             textureTarget.filterMode = FilterMode.Point;
             textureTarget.wrapMode = TextureWrapMode.Clamp;
             textureTarget.Create();
             if (material) material.sharedMaterial.mainTexture = textureTarget;
         }
         //update surfacetexture
         exoPlayer.Call("updateTexture");
         //draw to rendertexture
         exoPlayer.Call("drawFrame", (int)textureTarget.GetNativeTexturePtr());


Comment
Add comment · Show 5
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
avatar image thefallengamesstudio · Nov 14, 2016 at 07:11 PM 0
Share

did you solve your issue? I'm trying to achieve something similar

avatar image ahuertasLOOT thefallengamesstudio · Nov 14, 2016 at 07:24 PM 0
Share

When Unity can parse the #extension correctly on 5.4, I wrote the shader in Unity rather than in native. Right now we are using a 3rd party solution to render out the video. If you want to still use the GL_OES_EGL_image_external extension, I have to set the texture pointer in native and draw in Unity.

avatar image thefallengamesstudio ahuertasLOOT · Nov 14, 2016 at 07:40 PM 0
Share

thanks. will a simple texture without any frame buffer be enough? And by "se the texture pointer in native" you mean creating it native code rather than in unity-side?

Show more comments
Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Kajos · Jul 15, 2016 at 03:01 PM

You'll need to adjust the shader to use the GL_TEXTURE_EXTERNAL_OES texture as well, else it won't work. Add to your shader instead of sampler2D:

  #extension GL_OES_EGL_image_external : require
 uniform samplerExternalOES texture

Comment
Add comment · Show 1 · Share
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
avatar image ahuertasLOOT · Nov 14, 2016 at 07:21 PM 0
Share

Used to not work before, but starting on Unity 5.4 (only tested on beta), setting the extensions worked. Not sure if it is still working on the lastest Unity as we're using a 3rd party plugin to render the video.

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.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Complex Depth Shader 0 Answers

Having issue with "unable to convert class to dex format" extremely simple JAR in empty project. 0 Answers

How to load android app when the button clicked in unity scene? 4 Answers

Reading Native Surface Texture into Streaming Unity Texture [Android]? 3 Answers

Rendering a screen aligned quad with Graphics.blit - not working? 0 Answers


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