假设您有一个适用于iOS的低级Unity插件,
所以在C#中
using System.Runtime.InteropServices;
using AOT;
public class Teste: MonoBehaviour {
[DllImport("__Internal")] private static extern
void set_texture_from_unity(System.IntPtr texture, int w, int h);
有一个纹理,.Apply()
然后将指针发送到本地iOS插件:
public void ClickPassTexture() {
tex = new Texture2D(256, 256, TextureFormat.ARGB32, false);
tex.filterMode = FilterMode.Point;
tex.Apply(); // ACTUALLY UPLOAD TO GPU
someMaterial.mainTexture = tex;
set_texture_from_unity(
tex.GetNativeTexturePtr(), tex.width, tex.height);
}
现在的C代码。
用几条彩色线制作一个纹理,并将其写入Unity纹理。
#include <OpenGLES/ES2/gl.h>
...
void set_texture_from_unity(void *g_TextureHandle, int w, int h)) {
// make a texture with a few gray rows
unsigned char* data = malloc( g_TextureWidth * 4 * g_TextureHeight );
for (int i = 0; i < 1000; ++i) { data[i] = 100; }
// now, write that to the texture pointer given to us from Unity
GLuint gltex = (GLuint)(size_t)(g_TextureHandle);
glBindTexture(GL_TEXTURE_2D, gltex);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
g_TextureWidth, g_TextureHeight, GL_RGBA, GL_UNSIGNED_BYTE, data);
free(data);
因此,在C代码中,我们似乎已经成功地修改了texture tex
。
然而。
精美的Unity doco docs.unity3d.com/Manual/NativePluginInterface.html
给出一个示例,其中Unity渲染链中的回调调用C纹理更改。
然而。
我们什么时候想?
我认为这可能简单地起作用:
set_texture_from_unity( tex.GetNativeTexturePtr(),
tex.width, tex.height);
// the plugin has changed the texture...
// perhaps an Apply will change it on screen?!
tex.Apply();
但不是!(如果您在之前等待几帧,则没有区别.Apply
。)
您可能会认为.Apply
会再次将纹理发送到GPU,但似乎不起作用。
简而言之,在C插件运行之后,如何处理所呈现的代码,以使其显示“ there and then”新纹理?
当您知道一个C插件已经修改了Texture时,在iOS上,如何获取Unity以显示更改?
来自Unity日本的(传奇人物)高桥敬次郎(Keijiro Takahashi)可能发布了Unity曾经发布过的最重要的一件事情:
https://github.com/keijiro/TextureUpdateExample
从插件更新(new)框架样式纹理的实际示例。
和IOS一起工作
同样,可以说的是,这几乎是Unity发行的最有价值的东西!!
关于所问的问题,我确实从未找到解决方案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句