/* Updating the texture happens in the native plugin. * The Unity texture however gets initiated when the native plugin * is done with allocating resources. This happens here. */ void Update() { if (b_needs_init) { if (m_manager.hasResources(m_node_id) == 1) { TextureFormat fmt = 0; // Create a texture depending on HPV compression type of file if (HPV_Unity_Bridge.HPVCompressionType.HPV_TYPE_DXT1_NO_ALPHA == hpv_type) { fmt = TextureFormat.DXT1; if (m_texture_target) { m_texture_target.DisableKeyword("CT_CoCg_Y"); m_texture_target.EnableKeyword("CT_RGB"); } } else if (HPV_Unity_Bridge.HPVCompressionType.HPV_TYPE_DXT5_ALPHA == hpv_type) { fmt = TextureFormat.DXT5; { m_texture_target.DisableKeyword("CT_CoCg_Y"); m_texture_target.EnableKeyword("CT_RGB"); } } else if (HPV_Unity_Bridge.HPVCompressionType.HPV_TYPE_SCALED_DXT5_CoCg_Y == hpv_type) { fmt = TextureFormat.DXT5; { m_texture_target.DisableKeyword("CT_RGB"); m_texture_target.EnableKeyword("CT_CoCg_Y"); } } // get texture pointer from plugin //IntPtr ptr = m_manager.getTexturePtr(m_node_id); //Texture2D video_tex = Texture2D.CreateExternalTexture(width, height, fmt, false, true, ptr); //video_tex.filterMode = FilterMode.Bilinear; // Create a texture Texture2D video_tex = new Texture2D(width, height, fmt, false); video_tex.filterMode = FilterMode.Bilinear; video_tex.Apply(); // set texture onto our material if (m_texture_target) { m_texture_target.mainTexture = video_tex; } // ... or if no material is present, set to texture of this GameObject else { GetComponent <Renderer>().material.mainTexture = video_tex; } // Pass texture pointer to the plugin m_manager.setTexturePtr(m_node_id, video_tex.GetNativeTexturePtr()); b_needs_init = false; //Debug.Log("Done Creating unity texture"); } } }