10 using System.Runtime.InteropServices;
20 public Shader RGBBackgroundShader;
21 public Shader YuvBackgroundShader;
22 public Shader AndroidYuvBackgroundShader;
23 public Color32 pauseColor =
new Color32(255, 255, 255, 255);
32 instance = FindObjectOfType<AbstractCameraBackgroundBehaviour>();
39 private int cameraWidth = 0;
40 private int cameraHeight = 0;
41 private Texture2D rgbTexture = null;
42 private bool keepRendering =
false;
44 private Texture2D yTexture = null;
45 private Texture2D uvTexture = null;
49 Debug.Log(
"Current graphics device type is " + SystemInfo.graphicsDeviceType +
".");
51 if (Application.platform == RuntimePlatform.Android ||
52 Application.platform == RuntimePlatform.IPhonePlayer)
62 void OnApplicationPause(
bool pause)
89 private void StartRendering()
91 GetComponent<Renderer>().material.SetFloat(
"pauseMode", 0.0f);
92 Debug.Log(
"StartRendering");
96 private void StopRendering()
98 GetComponent<Renderer>().material.SetFloat(
"pauseMode", 1.0f);
99 Debug.Log(
"StopRendering");
100 keepRendering =
false;
103 private void CreateCameraTexture(
int imageWidth,
int imageHeight,
ColorFormat imageFormat)
105 if(rgbTexture != null || yTexture != null) {
110 rgbTexture =
new Texture2D(imageWidth, imageHeight, TextureFormat.RGB24,
false);
111 GetComponent<Renderer>().material =
new Material(RGBBackgroundShader);
112 GetComponent<Renderer>().material.mainTexture = rgbTexture;
114 yTexture =
new Texture2D(imageWidth, imageHeight, TextureFormat.R8,
false);
115 uvTexture =
new Texture2D(imageWidth / 2, imageHeight / 2, TextureFormat.RG16,
false);
117 if (Application.platform == RuntimePlatform.Android) {
118 GetComponent<Renderer>().material =
new Material(AndroidYuvBackgroundShader);
120 GetComponent<Renderer>().material =
new Material(YuvBackgroundShader);
123 GetComponent<Renderer>().material.SetTexture(
"_YTex", yTexture);
124 GetComponent<Renderer>().material.SetTexture(
"_UVTex", uvTexture);
127 Mesh mesh = GetComponent<MeshFilter>().mesh;
128 Vector3[] vertices = mesh.vertices;
129 Vector2[] uvs =
new Vector2[vertices.Length];
131 uvs[0].x = 0; uvs[0].y = 1;
132 uvs[1].x = 1; uvs[1].y = 0;
133 uvs[2].x = 1; uvs[2].y = 1;
134 uvs[3].x = 0; uvs[3].y = 0;
137 GetComponent<Renderer>().material.SetColor(
"_PauseColor", pauseColor);
138 GetComponent<Renderer>().material.renderQueue = 1500;
139 Debug.Log(
"Create background texture");
142 private void Update()
153 UpdateInternal(image);
160 IntPtr cameraFrameBuffer = image.GetDataPtr();
162 if (cameraFrameBuffer != IntPtr.Zero)
167 if(rgbTexture != null) {
168 rgbTexture.LoadRawTextureData(cameraFrameBuffer, image.
GetWidth() * image.
GetHeight() * 3);
175 if(yTexture != null) {
180 byte* pointer = (byte*)cameraFrameBuffer.ToPointer();
181 yPtr = (IntPtr)pointer;
183 uvPtr = (IntPtr)pointer;
198 internal bool RenderingEnabled()
200 return keepRendering;
int GetHeight()
Get height
static void SetScreenOrientation(int orientation)
Notify screen orientation chagned
Container for individual tracking information
ColorFormat GetFormat()
Image format
TrackingState GetTrackingState()
Get saved TrackingState value
Handles native background rendering. Background rendering includes camera image, feature point...
ColorFormat
Camera image format
image data which is used for tracker and rendering
static TrackerManager GetInstance()
Get TrackerManager instance
Control AR Engine (Singletone)