Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
1
Question by Bork Awesome · Sep 03, 2012 at 02:46 PM · iosgraphicstexture2dunity 4beta

Unity 4 BETA: iOS: Texture2D ReadPixels not responding to bound framebuffer

In Unity 3.x/iOS I've had success with retrieving texture data from an image rendered on the device with the following process:

[Unity]

  • Create Texture2D

  • Pass texture handle to device

[Device/OpenGL]

  • Create frame buffer and bind texture

  • Do custom texture rasterisation into framebuffer

[Unity]

  • Set texture framebuffer as active

  • Call ReadPixels() on Texture2D to pull hardware texture into memory

  • Restore Unity/native framebuffer

Now using the Unity 4.x BETA/iOS ReadPixels() pulls in the full Unity scene render and not just my custom stuff. After reading the docs (again) there is a mention that ReadPixels() on mobile devices is deferred until the end of the frame, so I've tried a co-routine approach with WaitTillEndOfFrame() and that still brings in the full Unity scene render.

I've also had a tinker with Render Textures but they aren't responding at all (there should be no need for a RenderTexture as I just need a hardware texture handle).

I'm wondering if there is a change in ReadPixels() that forces a read from the Unity context (even though I'm explicitly telling OpenGL to set my framebuffer as the active framebuffer) and overriding my approach? I think I've tried everything to counter any possible timing issues..

Any suggestions would be greatly appreciated!

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

1 Reply

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

Answer by Bork Awesome · Sep 03, 2012 at 04:07 PM

So I've hacked a fix!

The problem is down to forcing my framebuffer to stick whilst calling ReadPixels; so what I do is create a placeholder RenderTexture (min OpenGL 64x64) to be the context, then wrap my old calls with setting the RenderTexture to active to stave off any errant Unity under-the-hood-jiggery-pokery!

Scraping the barrel, but it works, 'fixes' in bold (note use of RenderTexture means this is a Pro only hack):

[Unity]

  • Create Texture2D

  • Pass texture handle to device

[Device/OpenGL]

  • Create frame buffer and bind texture

  • Do custom texture rasterisation into framebuffer

[Unity]

  • Create temp RenderTexture

  • Set RenderTexture.active to temp RenderTexture

  • Set texture framebuffer as active

  • Call ReadPixels() on Texture2D to pull hardware texture into memory

  • Restore Unity/native framebuffer

  • Set RenderTexture.active to null

  • Release RenderTexture

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

7 People are following this question.

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

Related Questions

gl class iOS 1 Answer

iOS crashing on Texture2D LoadImage 1 Answer

iOS "Best Performance" Gives Odd Resolutions (Unity 4.0)? 2 Answers

How to Convert Image to Texture2d 1 Answer

Convert System.Drawing.Bitmap to Texture2D 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