Created
September 16, 2022 07:13
-
-
Save daddyYukio/4c0720f0375a923735100e9c9fc8ae8e to your computer and use it in GitHub Desktop.
スマホでVR写真表示アプリを作る(Xamarin) - OpenGLView LoadTexture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void LoadTexture(int tex_id, byte[] texture) | |
{ | |
GL.BindTexture(TextureTarget.Texture2D, tex_id); | |
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)All.NearestMipmapLinear); | |
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); | |
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat); | |
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat); | |
// | |
// 画像のロード&RGBA色空間への変換&OpenGLへの適用は、デバイス依存の処理になる | |
#if __ANDROID__ | |
using (var ms = new MemoryStream(texture)) | |
{ | |
var b = BitmapFactory.DecodeStream(ms); | |
// | |
// GLUTの関数を使って、良しなに設定する | |
Android.Opengl.GLUtils.TexImage2D((int)All.Texture2D, 0, b, 0); | |
b.Recycle(); | |
} | |
#endif | |
#if __IOS__ | |
var b = UIImage.LoadFromData(NSData.FromArray(texture)); | |
CGImage cgimage = b.CGImage; | |
using (var dataProvider = cgimage.DataProvider) | |
using (var data = dataProvider.CopyData()) | |
{ | |
GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, | |
(int)cgimage.Width, (int)cgimage.Height, 0, | |
PixelFormat.Rgba, PixelType.UnsignedByte, | |
data.Bytes); | |
} | |
#endif | |
GL.GenerateMipmap(TextureTarget.Texture2D); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment