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
0
Question by Robert-Castle · Mar 27, 2012 at 06:47 PM · iostexturepluginopengl

Extremely slow texture upload in plugin when a model is being drawn

Hi,

I have an iOS unity app that calls a plugin to update a texture in unity. This runs reasonably fast with the texture upload taking about 3-4ms. This has been working fine for a few months.

When I am not drawing any 3d models it still runs at this speed, but as soon as I draw a model it takes 60ms plus!

This is my C++ texture upload code:

   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
   glBindTexture(GL_TEXTURE_2D, texID);
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, im->data());

It is solely the glTexImage2D part that becomes 15x slower when a model is drawn. Everything else in the calling path runs at the same speed.

Any clues as to why this is happening? The only real change has been upgrading from Unity 3.5 beta to 3.5 and it was working fine in 3.5.

Addendum:

  • The texture update is being called from an Update function in a script on every update.

  • The image is a 640x480 BGRA image.

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 slippdouglas · Apr 20, 2014 at 03:18 AM 0
Share

It was working fine in Unity 3.5, but not in Unity 3.5 beta?

1 Reply

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

Answer by Robert-Castle · Mar 28, 2012 at 06:43 PM

Well, I think I found the answer.

I needed to double buffer my texture. So while one is being used on screen, I update another one, and then swap over. Also using an unpack alignment of 4 was slightly beneficial as I am dealing with images that are divisible by 4. So my updated code looks something like this:

In plugin:

 void UpdateTexture( int texToUse )
 {
      if (texToUse == 0) {
         texID = unityTexture0;
       }
       else {
         texID = unityTexture1;
       }
     
     glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
     glBindTexture(GL_TEXTURE_2D, texID);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, im->data());
 }

and in Unity in Update()

 UpdateTexture(texToUse);
 videoMaterial.SetTexture("_MainTex", videoTextures[texToUse]);
 texToUse = (texToUse == 0) ? 1 : 0;

where videoTextures is an array of 2 Texture2Ds.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Issue with glDrawArrays in plugin 2 Answers

Problem, Textures updated by plugin won't behave as expected in combination with HLSL shader 2 Answers

Problem trying to update texture using glTexImage2D on iOS. 0 Answers

QR-Code Decoding for iOS and Android 0 Answers

GL_LUMINANCE format for texture uploads in Android plugin 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