- Home /
Problem trying to update texture using glTexImage2D on iOS.
I'm creating a plugin using C&Obj-C for iphone. I use Texture.GetNativeTextureID() to get a GL texture handle and pass it into C Plugin, then use glTexImage2D to update pixels of it.But the texture displayed in my app didn't change.(On iPad) And all gl call ran with out any error. I wonder if there are any limit that using GLES on iOS or special rules I didn't know.
Here is some test code in my project.
//Code in unity3d
public class GamePluginTest : MonoBehaviour {
const int width = 512;
const int height = 512;
void OnGUI () {
if(GUI.Button(new Rect(20, 20, 240, 60), "UpdateTexture"))
{
GameObject go = GameObject.Find("Plane");
Material mat = go.renderer.material;
if(mat.mainTexture == null)
{
mat.mainTexture = new Texture2D(width, height, TextureFormat.RGB24, false);
}
iOSPlugin_UpdateTexture(mat.mainTexture.GetNativeTextureID(), width, height);
}
}
[DllImport("__Internal")]
static extern void iOSPlugin_UpdateTexture(int textureHandle, int width, int height);
}
//Code in XCode
void iOSPlugin_UpdateTexture(int textureHandle, int width, int height)
{
unsigned char* pixels = malloc(sizeof(unsigned char) * 3 * width * height);
for(int y = 0; y < height; ++y)
{
for(int x = 0; x < width; ++x)
{
int index = (y * width + x) * 3;
pixels[index + 0] = 0xFF;
pixels[index + 1] = 0xFF;
pixels[index + 2] = 0xFF;
}
}
glBindTexture(GL_TEXTURE_2D, textureHandle);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, pixels);
free(pixels);
}
By chance did you ever get this working? I am trying the same but am just ending up with a black blank texture.
Your answer
Follow this Question
Related Questions
iOS.RemoteNotification userInfo empty 2 Answers
iOS location permission plugin build fails 0 Answers
AudioServicesPlaySystemSound - iOS System Sounds from Unity 1 Answer
PBXProject and UNITY_IOS issue in PostProcessBuild step on 2018.1 0 Answers
Extremely slow texture upload in plugin when a model is being drawn 1 Answer