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
0
Question by PaulUsul · Jun 05, 2011 at 09:45 AM · textureisreadable

How can I bypass texture isReadable

Is there a way to copy a texture from the gfx card to system memory, thereby setting isReadable to true.

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
0
Best Answer

Answer by PaulUsul · Jun 19, 2011 at 03:22 PM

It is possible when using opengl.

in c

 void EXPORT_API SetTexture(int textureID) 
 {
     freopen("debug.txt", "a", stdout);
     printf("SetTexture id:%d\n" ,textureID);

     glBindTexture(GL_TEXTURE_2D, textureID);

     glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &textureWidth);
     glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &textureHeight);
     printf("w:%d h:%d\n" ,textureWidth ,textureHeight);

     buffer = (GLfloat *)malloc(textureWidth * textureHeight * (sizeof(GLfloat) * 4));
     glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_FLOAT, buffer);
 }
     
 bool EXPORT_API GetTexture(float* resultPixels, int* resultPixelLength)
 {
     *resultPixelLength = (textureWidth * textureHeight) * 4;
     printf("GetTexture pixels%d \n", resultPixelLength);
     
     for(int i = 0; i < *resultPixelLength; i++)
     {
         resultPixels[+i] = (float) buffer[i];
     }
     
     count++;
     return true;
 }

 void EXPORT_API FreeMemory() 
 {
     printf("\n");
     //delete(buffer);
     free(buffer);
     //free(bufferTest);
 }
 
 void EXPORT_API Close() 
 {
     fclose (stdout);
 }



in c#

 [DllImport("Unity3dTextureSteal")]
 private static extern void SetTexture(int textureId);
 [DllImport("Unity3dTextureSteal")]
 private static extern bool GetTexture(System.IntPtr ptrResultVerts, ref int resultVertLength);
 [DllImport("Unity3dTextureSteal")]
 private static extern void FreeMemory();
 [DllImport("Unity3dTextureSteal")]
 private static extern void Close();

 public static Texture2D FindTexture(Texture2D tex)
 {
     //Debug.Log(tex.name + " " + tex.format);
     SetTexture(tex.GetNativeTextureID());

     float[] pix = new float[tex.width * tex.height * 4];
     int resultVertLength = 0;
     GCHandle pArray = GCHandle.Alloc(pix, GCHandleType.Pinned);

     if (GetTexture(pArray.AddrOfPinnedObject(), ref resultVertLength))
     {
         pArray.Free();
         Color[] colors = new Color[tex.width * tex.height];
         //Debug.Log(pix.Length + " " + resultVertLength);
         int i, c;
         for (c = 0, i = 0; c < colors.Length; c++)
         {
             Color co = new Color();
             co[0] = pix[i];
             i++;
             co[1] = pix[i];
             i++;
             co[2] = pix[i];
             i++;
             co[3] = pix[i];
             i++;
             colors[c] = co;
         }
 
         Texture2D texture = new Texture2D(tex.width, tex.height, TextureFormat.RGBA32, false);
         texture.SetPixels(colors, 0);
         texture.Apply(false);

         FreeMemory();

         return texture;
     }
     return null;
 }
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

2 People are following this question.

avatar image avatar image

Related Questions

Assigning UV Map to model at runtime 0 Answers

Set TextureImporter.isReadable to true in script 0 Answers

Texture "Read/Write Enabled" checkbox keeps resetting 1 Answer

Dynamically create Texture2D that is readable 2 Answers

How do I add a texture to a cube (yes I know I'm a scrub)? 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