Hi all.
I’m implementing a native plugin to create a dynamic texture which it is updated in a native plugin (I have to use native plugin because i’m using third party IOS framework).
After read some doc It seems that it will be quite easy in theory… In practice not errors are reported but Sprite texture not changes.
Inside Sprite script I do:
void Start () {
_texture = newTexture2D(255, 255 ,TextureFormat.ARGB32,false);
_texture.filterMode = FilterMode.Point;
}
void Update () {
UpdateDummyTexture(_texture.GetNativeTextureID(), _texture.width, _texture.height);
SpriteRendererrenderer = GetComponent ();
MaterialPropertyBlockblock = newMaterialPropertyBlock();
block.AddTexture(“_MainTex”,_texture);
renderer.SetPropertyBlock(block);
GL.InvalidateState();
}
[DllImport(“__Internal”)]
private static extern void UpdateDummyTexture (int textureID, int width, int height);
Inside Plugin Code I do:
void UpdateDummyTexture(int textureID, int width, int height)
{
printf(“[%s]{%d} Entering method with param %d.\n”, “UpdateDummyTexture”, LINE, textureID);
glBindTexture(GL_TEXTURE_2D, textureID);
int size = width * height * 3;
unsigned char pixels = (unsigned char)malloc(size);
fractal_generateArrayValue(pixels);
for(int y=0;y<height;y++)
{
for(int x=0;x<byteWidth;x+=3)
{
if(x < 10)
{
pixels[x + y * byteWidth] = 255;
pixels[x + y * byteWidth+1] += 10;
pixels[x + y * byteWidth+2] += 20;
}
else
{
pixels[x + y * byteWidth] = 0;
pixels[x + y * byteWidth+1] += 20;
pixels[x + y * byteWidth+2] += 20;
}
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,width,height,0,GL_RGB, GL_UNSIGNED_BYTE,pixels);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
free(pixels );
}
The result is a blank texture .
Any help will be highly appreciated.
Thank you very much.