|
Hello, My short question is this: What is the packing of Color32 unity classes? I have been led to believe through the access violation errors in my c plugins, which write to pointer to Color32, that the packing is NOT 8888 for RGBA or 32 bbp as it is for the Color class. Long winded question, I have written a plugin to write color values to unity textures. My first iteration of the program used Color[] to store color values with unity. My C# unity side the program was taken from the texture plug sample located here : http://unity3d.com/support/resources/example-projects/texture-plugins. The relevant code snippet for creating and sending the texture pointer is: using UnityEngine; using System; using System.Runtime.InteropServices; public class TexturePlayback : MonoBehaviour { } The relevant C plugin code for the UpdateTexture function is: ... float* data = reinterpret_cast<float*>(destination); // destination is texture pointer "m_PixelsHandle.AddrOfPinnedObject()" from unity ... Everything is going swimmingly when I use Color class and the texture is correctly changed to red. However, SetPixel is rather slow for large textures and I heard SetPixel32 is faster. So I changed the C# code to Color32 and SetPixel32, from Color and SetPixel respectively. However, this now causes an access violation on my plugin, thus leading me to believe the color data for Color32 is packed differently than Color. Is this the case? And if so, how are the color values stored in the Color32 class? If this is not the case and the program is failing for another unforeseen reason, I would appreciate any kind words of enlightenment. thank you
(comments are locked)
|
|
Per NOAA_Julien's suggestion, the Color32 structure is indeed packed as bytes rather than floats. http://docs.unity3d.com/Documentation/ScriptReference/Color32.html So a little change to my above plug-in code to represent the texture array from unity as unsigned chars fixed the problem: Also, for those interested, the change from SetPixels to SetPixels32 is an increase of about 33% in frame rate on SD sized textures. Don't forget to give Julien a thumbs-up for their help! (and mark the answer as accepted so the question doesn't show up as unanswered)
Jun 28 '12 at 09:24 PM
Loius
(comments are locked)
|

Just briefly glancing at your code (apologies if this isn't the case): Color32 uses 4 byte values for rgba, not 4 floats. If you're trying to implicitly convert float to byte that could be your problem.