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
2
Question by kdu_timeplay · Oct 04, 2016 at 09:03 PM · openglcapturescreen

glReadPixels in Unity 5 always get black frame

I was following Kibsgaard's suggestion in this link text thread using glReadPixels under Unity 4 I can get very high performance video capturing feature in our game. The general idea is when game is running in openGL mode using glReadPixels in PostRender or EndOfFrame, the return buffer will contain the colors of screen pixels.

But recently after we upgrade project to Unity 5, we found this was no longer working, glReadPixels always returns black.

I tried add -force-opengl,let unity running in legacy mode. Tried bindFrameBuffer, but all these were not working for me.

Anyone knows how to fix this in Unity 5? We really need very high performance video capturing feature. I tried renderTexture solution under unity 4 which was 3 times slower than glReadPixels solution.

Comment
Add comment · Show 1
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 amonitzer · Oct 21, 2016 at 01:03 AM 0
Share

What I'm seeing is that it works in the editor, but fails in the player. Have you had any progress on that issue since posting this question?

3 Replies

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

Answer by kdu_timeplay · Oct 21, 2016 at 04:25 PM

Yes we have the Unity support helped us, it's solved by moving the native GL calls(glReadPixels/glGetTexImage) to the GL.IssuePluginEvent, and it works fine.

Comment
Add comment · Show 3 · 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 Kibsgaard · Dec 15, 2016 at 08:09 AM 0
Share

Hi kdu, great that you got it working! I have some issues with the transferred texture being from a different render texture, than the one bound by RenderTexture.active in Unity and it doesn't help to use a command buffer to bind the texture and issue the plugin. Did you get it to work reliably? If so, are you able to share the source for your plugin? Do you set the rendertexture in your plugin or from Unity? Is it with OpenGL Core or Legacy?

avatar image irbis85 Kibsgaard · Jul 18, 2018 at 10:03 AM 0
Share

Hi $$anonymous$$ibsgaard, have you find the way how to use GL.IssuePluginEvent for glReadPixels/glGetTexImage? How is it posssible to send an parameterst to the glReadPixels in this native plugin call? I would be very appreciate for any advise

avatar image Kibsgaard irbis85 · Jul 18, 2018 at 12:45 PM 0
Share

Hi irbis, yes I did eventually solve the problem, but it does require a bit of extra code in the native plugin. What I do now is:

  1. Create a RenderTexture in Unity and set it as the camera's render target

  2. Get native pointer from that RenderTexture using GetNativeTexturePtr(). Which is actually a pointer to the ColorAttachment and not the framebuffer (RenderTexture) itself.

  3. Create a framebuffer (in the native code plugin) that uses the same ColorAttachment and store it for later use

  4. Issues the transfer once done rendering using GL.IssuePluginEvent()

  5. The transfer should start by binding the framebuffer, binding the colorattachment, glreadpixels and finish by unbinding the framebuffer (Unity 5+ actually cares if you clean properly up now or not)

If you don't use a RenderTexture for your camera, maybe you can bind the front/backbuffers directly ins$$anonymous$$d, however, I didn't need that and didn't find a quick way of getting a reference to those.

I just found out that Unity 2018.1 has a new function to async read back data from the GPU. $$anonymous$$aybe this is useful for you. In our case, the read back is highest priority and waiting even a couple of frames is bad.

avatar image
0

Answer by isaac_champ · Oct 25, 2016 at 07:06 AM

We also have this issue on iOS and by calling glGetError() we get the message, GL_INVALID_FRAMEBUFFER_OPERATION.

It was so strange that before calling glReadPixels, we have check the frame buffer status and it's GL_FRAMEBUFFER_COMPLETE.

 GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
 NSLog(@"Bind framebuffer : %x", status);
 if (status != GL_FRAMEBUFFER_COMPLETE)
     NSLog(@"Bind framebuffer error! : %x", status);
  • Unity version : 5.4.1f1 (649f48bbbf0f)

  • iOS : 9.3.5

  • OpenGL ES : 3.0

Anyone knows how to fix it? or give us some tips to check this?

Thanks!

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 isaac_champ · Nov 02, 2016 at 01:21 PM 0
Share

By changing to $$anonymous$$etal and using CVPixelBuffer retrieve the pixel data, fix it!

avatar image
0

Answer by kyewong · Feb 04, 2017 at 09:51 AM

I've got what you mean @kdu_timeplay . Native glReadPixels function must be put in the callback of GL.IssuePluginEvent to ensure that it is called in the render thread. While in Unity 5.1 version it is not compulsory

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

Class Application.CaptureScreen no running in android 0 Answers

Cannot update texture from plugin (windows) 4 Answers

Opengl plugin for Android 0 Answers

P/Invoke slow when in OnGui()? 0 Answers

normal maps on iOS with a custom shader.. Works, but not the way I need it to 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