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 mituba · Sep 25, 2012 at 10:23 AM · iostexturepluginxcode

Problem trying to update texture using glTexImage2D on iOS.

I'm creating a plugin using C&Obj-C for iphone. I use Texture.GetNativeTextureID() to get a GL texture handle and pass it into C Plugin, then use glTexImage2D to update pixels of it.But the texture displayed in my app didn't change.(On iPad) And all gl call ran with out any error. I wonder if there are any limit that using GLES on iOS or special rules I didn't know.

Here is some test code in my project.

//Code in unity3d

 public class GamePluginTest : MonoBehaviour {
     
     const int width = 512;
     const int height = 512;
     
     void OnGUI () {
         if(GUI.Button(new Rect(20, 20, 240, 60), "UpdateTexture"))
         {
             GameObject go = GameObject.Find("Plane");
             Material mat = go.renderer.material;
             if(mat.mainTexture == null)
             {
                 mat.mainTexture = new Texture2D(width, height, TextureFormat.RGB24, false);
             }
             iOSPlugin_UpdateTexture(mat.mainTexture.GetNativeTextureID(), width, height);
         }
     }
     
     [DllImport("__Internal")]
     static extern void iOSPlugin_UpdateTexture(int textureHandle, int width, int height);
 }

//Code in XCode

 void iOSPlugin_UpdateTexture(int textureHandle, int width, int height)
 {
     unsigned char* pixels = malloc(sizeof(unsigned char) * 3 * width * height);
     for(int y = 0; y < height; ++y)
     {
         for(int x = 0; x < width; ++x)
         {
             int index = (y * width + x) * 3;
             pixels[index + 0] = 0xFF;
             pixels[index + 1] = 0xFF;
             pixels[index + 2] = 0xFF;
         }
     }
     glBindTexture(GL_TEXTURE_2D, textureHandle);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
     free(pixels);
 }
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 techmage · Apr 22, 2014 at 03:32 AM 0
Share

By chance did you ever get this working? I am trying the same but am just ending up with a black blank texture.

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.

Follow this Question

Answers Answers and Comments

11 People are following this question.

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

Related Questions

iOS.RemoteNotification userInfo empty 2 Answers

iOS location permission plugin build fails 0 Answers

AudioServicesPlaySystemSound - iOS System Sounds from Unity 1 Answer

PBXProject and UNITY_IOS issue in PostProcessBuild step on 2018.1 0 Answers

Extremely slow texture upload in plugin when a model is being drawn 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