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 Christian 4 · Dec 22, 2010 at 01:31 AM · texturepluginopengl

Cannot update texture from plugin (windows)

Hi all,

I'm trying to update a texture within a plugin using opengl (Windows, Visual C++), since SetPixlels() + Apply() seems to be way too slow for frequent updates.

It all compiles and runs fine, but the data does not make it into the texture, it displays random stuff. In my plugin, glBindTexture( GL_TEXTURE_2D, tex_id ) finishes with glGetError = GL_INVALID_OPERATION, which seems to be the root of the problem.

Does the Windows standard opengl implementation (GL/gl.h) even work well with unity in this way?

Unity Behaviour:

void init() { m_Texture = new Texture2D( tex_rgb_width, tex_rgb_height, TextureFormat.ARGB32, false); m_Texture.Apply();

GUITexture gui = GameObject.Find("gui").GetComponent<GUITexture>() as GUITexture; gui.texture = m_Texture; }

void update() { bool res = update_rgb_texture( m_Texture.GetNativeTextureID(), tex_rgb_width, tex_rgb_height, (int) Time.timeSinceLevelLoad*10 ); }

Plugin:

bool update_rgb_texture( int tex_id, int width, int height, int time ) {
  glBindTexture( GL_TEXTURE_2D, tex_id );
  int id;
  int w = width;
  int h = height;
  vector<unsigned char> t( w*h*4 );
  for (int i=0; i<height; i++) {
    for (int j=0; j<width; j++) {
      id = (4*j)+(4*w*i);
      t[id] = (GLubyte) time%255;
      t[id+1] = (GLubyte) time%255;
      t[id+2] = (GLubyte) (255-time)%255;
      t[id+3] = (GLubyte) (255-time)%255;
    }
  }
  glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, &t[0] );
  return true;
}

Thanks a lot!! Chris.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Mike 3 · Dec 22, 2010 at 02:01 AM

Are you forcing unity to be running in OpenGL mode? Windows defaults to DirectX by default so forcing opengl textures probably won't do a great deal

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 Christian 4 · Dec 30, 2010 at 12:04 AM 0
Share

Excellent, that fixed it. Thanks!

Are there any expected side effect of forcing OpenGL like that? Frame rates seem to be similar... haven't tested fully yet.

Cheers, Chris.

avatar image
1

Answer by Tito · Apr 13, 2012 at 05:10 PM

any chance of a code snippet of your working version?,any chance of a code snippet on how you did it?

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
avatar image
0

Answer by wtgo · Apr 08, 2012 at 03:32 AM

One more note for any onlookers: the bind & update call has to be on the render thread, or it will fail. GL.IssuePluginEvent did the trick for me, and now I have fast streaming alpha video textures with no calls to Texture2D.Apply!

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
avatar image
0

Answer by darmaz · Aug 30, 2012 at 11:06 AM

Hello! I've been trying to use nativeTextureIDs myself for a while, but they just doesn't seem to work [or, I just can't seem to get them working ;-) ].

I have an educational pro license, and I'm quite familiar with dll development. I modified the GL.IssuePluginEvent example project in order to send a RenderTexture ID to an external dll, while the dll UnityRenderEvent just binds to the texture id and applies the texture to a quad and then to a triangle. What I get is just the "for educational use only" string used as a texture over both the quad and triangle. Is that some limitation of trial/educational pro versions, or am I just forgetting something?

I also tried to randomly change the texture ID, and the result is always the same [and quite funny ;-) ]:

alt text

Thanks!!

Cheers, D.

P.S. The very same OpenGL code works with textures sent as Color32 arrays to secondary OpenGL/GLUT window (a different dll), but that was way too slow for my needs (sending RenderTexture on every frame). I tried to use native IDs in that case too, but with no luck (different opengl contexts: didn't work even if I explicitly tried to get the contexts handles).


screenshot.jpg (69.3 kB)
Comment
Add comment · Show 2 · 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 m_vini · Jun 21, 2013 at 02:42 PM 0
Share

Did you solve the problem? I have the same issue.

avatar image darmaz · Jun 21, 2013 at 02:59 PM 0
Share

Hi! I didn't solve the problem, sorry : (

Good luck with your project!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Creating a Texture or Texture2D from a plugin. 0 Answers

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

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

Issue with glDrawArrays in plugin 2 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