internal int GetServerTextureId()
{
if (this.textureId == 0)
{
//server part
//gen texture
GL.GenTextures(1, out this.textureId);
//bind
GL.BindTexture(TextureTarget.Texture2D, this.textureId);
if (nativeImgMem != IntPtr.Zero)
{
GL.TexImage2D(TextureTarget.Texture2D, 0,
PixelInternalFormat.Rgba, this.width, this.height, 0,
PixelFormat.Rgba, //
PixelType.UnsignedByte, nativeImgMem);
}
else if (this.rawBuffer != null)
{
unsafe
{
//ES20 dose not have BGRA
//so in little-endian machine we need to convert
fixed (byte* bmpScan0 = &this.rawBuffer[0])
{
GL.TexImage2D(TextureTarget.Texture2D, 0,
PixelInternalFormat.Rgba, this.width, this.height, 0,
PixelFormat.Rgba, //
PixelType.UnsignedByte, (IntPtr)bmpScan0);
}
}
}
else if (this.rawIntBuffer != null)
{
unsafe
{
fixed (int* head = &rawIntBuffer[0])
{
GL.TexImage2D(TextureTarget.Texture2D, 0,
PixelInternalFormat.Rgba, this.width, this.height, 0,
PixelFormat.Rgba, //
PixelType.UnsignedByte, new IntPtr((void*)head));
}
}
}
else if (this.bmp != null)
{
GL.TexImage2D(TextureTarget.Texture2D, 0,
PixelInternalFormat.Rgba, this.width, this.height, 0,
PixelFormat.Rgba, //
PixelType.UnsignedByte, bmp.GetNativeImageHandle());
}
else
{
//use lazy provider
IntPtr bmpScan0 = this.lazyProvider.GetRawBufferHead();
GL.TexImage2D(TextureTarget.Texture2D, 0,
PixelInternalFormat.Rgba, this.width, this.height, 0,
PixelFormat.Rgba,
PixelType.UnsignedByte, (IntPtr)bmpScan0);
this.lazyProvider.ReleaseBufferHead();
}
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
}
return this.textureId;
}