public static RenderAPI_D3D11 Create(UnityEngine.Texture2D tex, UnityEngine.Mesh mesh) { using (var dxTexture = new SharpDX.Direct3D11.Texture2D(tex.GetNativeTexturePtr())) { var d3d11 = new RenderAPI_D3D11(dxTexture.Device); d3d11.SetTextureFromUnity(tex.GetNativeTexturePtr(), tex.width, tex.height); d3d11.SetMeshBuffersFromUnity(mesh.GetNativeVertexBufferPtr(0) , mesh.vertexCount , mesh.vertices , mesh.normals , mesh.uv); return(d3d11); } }
private void CreateTextureAndPassToPlugin() { // Create a texture Texture2D tex = new Texture2D(256,256,TextureFormat.ARGB32,false); // Set point filtering just so we can see the pixels clearly tex.filterMode = FilterMode.Point; // Call Apply() so it's actually uploaded to the GPU tex.Apply(); // Set texture onto our matrial GetComponent<Renderer>().material.mainTexture = tex; // Pass texture pointer to the plugin #if UNITY_GLES_RENDERER SetTextureFromUnity (tex.GetNativeTexturePtr(), tex.width, tex.height); #else SetTextureFromUnity (tex.GetNativeTexturePtr()); #endif }
private void CreateTextureAndPassToPlugin() { // Create a texture Texture2D tex = new Texture2D(256,256,TextureFormat.ARGB32,false); // Set point filtering just so we can see the pixels clearly tex.filterMode = FilterMode.Point; // Call Apply() so it's actually uploaded to the GPU tex.Apply(); // Set texture onto our matrial renderer.material.mainTexture = tex; // Pass texture pointer to the plugin SetTextureFromUnity (tex.GetNativeTexturePtr()); }
void Init(CameraSource cam) { // TODO: might depend on module.. var imageWidth = cam.SourceWidth; var imageHeight = cam.SourceHeight; TextureFormat txFormat = (cam.SourceChannels == 4) ? TextureFormat.BGRA32 : TextureFormat.RGB24; var camTexture = new Texture2D(imageWidth, imageHeight, txFormat, false); camTexture.wrapMode = TextureWrapMode.Clamp; GetComponent<Renderer>().materials[0].SetTexture("_MainTex", camTexture); var texturePtr = camTexture.GetNativeTexturePtr(); _output = new DirectXOutput(texturePtr, Eye); ProcessingPipeline.AddOutput(_output); if (AutoAlign) { var ovrCam = cam as OvrvisionCameraSource; if (ovrCam != null) { var IMAGE_ZOFFSET = 0.02f; float xOffset = (Eye == DirectXOutput.Eye.Left) ? -0.032f : ovrCam.GetHMDRightGap().x - 0.040f; transform.localPosition = new Vector3(xOffset, 0, ovrCam.GetFocalPoint() + IMAGE_ZOFFSET); var aspectW = (float)imageWidth / GetImageBaseHeight(ovrCam.CamQuality); var aspectH = (float)imageHeight / GetImageBaseHeight(ovrCam.CamQuality); transform.localScale = new Vector3(aspectW, -aspectH, 1.0f); } else { var aspectRatio = new Vector2((float)(imageWidth) / (float)(imageHeight), -1); transform.localScale = new Vector3(aspectRatio.x, aspectRatio.y, 1.0f); transform.localPosition = new Vector3(0, 0, 0.35f); } } }
void OnEnable() { if (overlayMaterial == null) { overlayMaterial = new Material(Shader.Find("Custom/SteamVR_Overlay")); } // Use OpenVR's mirror texture if available. if (mirrorTexture == null) { var vr = SteamVR.instance; if (vr != null && vr.graphicsAPI == EGraphicsAPIConvention.API_DirectX) { var tex = new Texture2D(2, 2); var nativeTex = System.IntPtr.Zero; if (vr.compositor.GetMirrorTextureD3D11(EVREye.Eye_Right, tex.GetNativeTexturePtr(), ref nativeTex) == EVRCompositorError.None) { uint width = 0, height = 0; OpenVR.System.GetRecommendedRenderTargetSize(ref width, ref height); mirrorTexture = Texture2D.CreateExternalTexture((int)width, (int)height, TextureFormat.RGBA32, false, false, nativeTex); } } } }
/// <summary> /// Initializes the UWKWebView, registers default delagates, and creates textures for the page and icon /// to lack of constructor parameters /// </summary> void Awake() { // ensure core is up UWKCore.Init(); if (createMode) { URL = createURL; MaxWidth = createMaxWidth; MaxHeight = createMaxHeight; CurrentWidth = MaxWidth; CurrentHeight = MaxHeight; } if (MaxWidth < 64) MaxWidth = 64; if (MaxHeight < 64) MaxHeight = 64; if (CurrentWidth > MaxWidth) CurrentWidth = MaxWidth; if (CurrentHeight > MaxHeight) CurrentHeight = MaxHeight; maxWidth = MaxWidth; maxHeight = MaxHeight; // default delegate handlers LoadFinished += loadFinished; URLChanged += urlChanged; TitleChanged += titleChanged; JSConsole += jsConsole; JSMessageReceived += jsMessageReceived; LoadProgress += loadProgress; ContentSizeChanged += contentSizeChanged; NewViewRequested += newViewRequested; TextureFormat format = TextureFormat.ARGB32; if (SystemInfo.graphicsDeviceVersion.IndexOf("Direct3D 11") != -1) { format = TextureFormat.BGRA32; } // note that on Direct3D11 shared gpu textures, mipmapping is not allowed WebTexture = new Texture2D( MaxWidth, MaxHeight, format, false); Color32[] colors = new Color32[MaxWidth * MaxHeight]; for (int i = 0; i < MaxWidth * MaxHeight; i++) { colors[i]. r = colors[i].g = colors[i].b = colors[i]. a = 0; } WebTexture.SetPixels32(colors); WebTexture.Apply(); ID = UWKCore.CreateView(this, MaxWidth, MaxHeight, "", WebTexture.GetNativeTexturePtr()); }
public void AssignTexture(hwTextureType type, Texture2D tex) { HairWorksIntegration.hwInstanceSetTexture(m_iid, type, tex.GetNativeTexturePtr()); }
private void CreateTextureAndPassToPlugin() { //movingCamera = GameObject.Find("MonoCamera").GetComponent<Camera>();//Camera.allCameras[2]; movingCamera = GameObject.Find("Camera").GetComponent<Camera>();//Camera.allCameras[2]; //**This is the stereo renderer //movingCamera.rect = new Rect(0,0,width,height); // Create a texture tex = new Texture2D(width,height,TextureFormat.RGB24,false); // Set point filtering just so we can see the pixels clearly //tex.filterMode = FilterMode.Point; // Call Apply() so it's actually uploaded to the GPU tex.Apply(); // Set texture onto our matrial //renderer.material.mainTexture = tex; // Pass texture pointer to the plugin SetTextureFromUnity (tex.GetNativeTexturePtr()); }
// Use this for initialization void Start() { if (!OvrPro.camStatus) return; // Initialize camera plane object(Left) CameraLeft = this.transform.FindChild("LeftCamera").gameObject; CameraRight = this.transform.FindChild("RightCamera").gameObject; CameraPlaneLeft = CameraLeft.transform.FindChild("LeftImagePlane").gameObject; CameraPlaneRight = CameraRight.transform.FindChild("RightImagePlane").gameObject; CameraLeft.transform.localPosition = Vector3.zero; CameraRight.transform.localPosition = Vector3.zero; CameraLeft.transform.localRotation = Quaternion.identity; CameraRight.transform.localRotation = Quaternion.identity; //Create cam texture CameraTexLeft = new Texture2D(OvrPro.imageSizeW, OvrPro.imageSizeH, TextureFormat.BGRA32, false); CameraTexRight = new Texture2D(OvrPro.imageSizeW, OvrPro.imageSizeH, TextureFormat.BGRA32, false); //Cam setting CameraTexLeft.wrapMode = TextureWrapMode.Clamp; CameraTexRight.wrapMode = TextureWrapMode.Clamp; CameraTexLeft.Apply(); CameraTexRight.Apply(); CameraTexLeftPtr = CameraTexLeft.GetNativeTexturePtr(); CameraTexRightPtr = CameraTexRight.GetNativeTexturePtr(); //Mesh Mesh m = CreateCameraPlaneMesh(); CameraPlaneLeft.GetComponent<MeshFilter>().mesh = m; CameraPlaneRight.GetComponent<MeshFilter>().mesh = m; //SetShader SetShader(camViewShader); CameraPlaneLeft.GetComponent<Renderer>().materials[0].SetTexture("_MainTex", CameraTexLeft); CameraPlaneRight.GetComponent<Renderer>().materials[0].SetTexture("_MainTex", CameraTexRight); CameraPlaneLeft.GetComponent<Renderer>().materials[1].SetTexture("_MainTex", CameraTexLeft); CameraPlaneRight.GetComponent<Renderer>().materials[1].SetTexture("_MainTex", CameraTexRight); CameraRightGap = OvrPro.HMDCameraRightGap(); //Plane reset CameraPlaneLeft.transform.localScale = new Vector3(OvrPro.aspectW, -1.0f, 1.0f); CameraPlaneRight.transform.localScale = new Vector3(OvrPro.aspectW, -1.0f, 1.0f); CameraPlaneLeft.transform.localPosition = new Vector3(-0.032f, 0.0f, OvrPro.GetFloatPoint() + IMAGE_ZOFFSET); CameraPlaneRight.transform.localPosition = new Vector3(CameraRightGap.x - 0.040f, 0.0f, OvrPro.GetFloatPoint() + IMAGE_ZOFFSET); UnityEngine.VR.InputTracking.Recenter(); if (useOvrvisionTrack) { OvrPro.useOvrvisionTrack_Calib = true; CameraPlaneRight.active = !OvrPro.useOvrvisionTrack_Calib; } }
RenderModel LoadRenderModel(CVRRenderModels renderModels, string renderModelName, string baseName) { var pRenderModel = System.IntPtr.Zero; EVRRenderModelError error; while ( true ) { error = renderModels.LoadRenderModel_Async(renderModelName, ref pRenderModel); if (error != EVRRenderModelError.Loading) break; System.Threading.Thread.Sleep(1); } if (error != EVRRenderModelError.None) { Debug.LogError(string.Format("Failed to load render model {0} - {1}", renderModelName, error.ToString())); return null; } var renderModel = (RenderModel_t)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_t)); var vertices = new Vector3[renderModel.unVertexCount]; var normals = new Vector3[renderModel.unVertexCount]; var uv = new Vector2[renderModel.unVertexCount]; var type = typeof(RenderModel_Vertex_t); for (int iVert = 0; iVert < renderModel.unVertexCount; iVert++) { var ptr = new System.IntPtr(renderModel.rVertexData.ToInt64() + iVert * Marshal.SizeOf(type)); var vert = (RenderModel_Vertex_t)Marshal.PtrToStructure(ptr, type); vertices[iVert] = new Vector3(vert.vPosition.v0, vert.vPosition.v1, -vert.vPosition.v2); normals[iVert] = new Vector3(vert.vNormal.v0, vert.vNormal.v1, -vert.vNormal.v2); uv[iVert] = new Vector2(vert.rfTextureCoord0, vert.rfTextureCoord1); } int indexCount = (int)renderModel.unTriangleCount * 3; var indices = new short[indexCount]; Marshal.Copy(renderModel.rIndexData, indices, 0, indices.Length); var triangles = new int[indexCount]; for (int iTri = 0; iTri < renderModel.unTriangleCount; iTri++) { triangles[iTri * 3 + 0] = (int)indices[iTri * 3 + 2]; triangles[iTri * 3 + 1] = (int)indices[iTri * 3 + 1]; triangles[iTri * 3 + 2] = (int)indices[iTri * 3 + 0]; } var mesh = new Mesh(); mesh.vertices = vertices; mesh.normals = normals; mesh.uv = uv; mesh.triangles = triangles; mesh.Optimize(); //mesh.hideFlags = HideFlags.DontUnloadUnusedAsset; // Check cache before loading texture. var material = materials[renderModel.diffuseTextureId] as Material; if (material == null || material.mainTexture == null) { var pDiffuseTexture = System.IntPtr.Zero; while (true) { error = renderModels.LoadTexture_Async(renderModel.diffuseTextureId, ref pDiffuseTexture); if (error != EVRRenderModelError.Loading) break; System.Threading.Thread.Sleep(1); } if (error == EVRRenderModelError.None) { var diffuseTexture = (RenderModel_TextureMap_t)Marshal.PtrToStructure(pDiffuseTexture, typeof(RenderModel_TextureMap_t)); var texture = new Texture2D(diffuseTexture.unWidth, diffuseTexture.unHeight, TextureFormat.ARGB32, false); if (SystemInfo.graphicsDeviceVersion.StartsWith("OpenGL")) { var textureMapData = new byte[diffuseTexture.unWidth * diffuseTexture.unHeight * 4]; // RGBA Marshal.Copy(diffuseTexture.rubTextureMapData, textureMapData, 0, textureMapData.Length); var colors = new Color32[diffuseTexture.unWidth * diffuseTexture.unHeight]; int iColor = 0; for (int iHeight = 0; iHeight < diffuseTexture.unHeight; iHeight++) { for (int iWidth = 0; iWidth < diffuseTexture.unWidth; iWidth++) { var r = textureMapData[iColor++]; var g = textureMapData[iColor++]; var b = textureMapData[iColor++]; var a = textureMapData[iColor++]; colors[iHeight * diffuseTexture.unWidth + iWidth] = new Color32(r, g, b, a); } } texture.SetPixels32(colors); texture.Apply(); } else { texture.Apply(); while (true) { error = renderModels.LoadIntoTextureD3D11_Async(renderModel.diffuseTextureId, texture.GetNativeTexturePtr()); if (error != EVRRenderModelError.Loading) break; System.Threading.Thread.Sleep(1); } } material = new Material(shader != null ? shader : Shader.Find("Standard")); material.mainTexture = texture; //material.hideFlags = HideFlags.DontUnloadUnusedAsset; materials[renderModel.diffuseTextureId] = material; renderModels.FreeTexture(pDiffuseTexture); } else { Debug.Log("Failed to load render model texture for render model " + renderModelName); } } // Delay freeing when we can since we'll often get multiple requests for the same model right // after another (e.g. two controllers or two basestations). #if UNITY_EDITOR if (!Application.isPlaying) renderModels.FreeRenderModel(pRenderModel); else #endif StartCoroutine(FreeRenderModel(pRenderModel)); return new RenderModel(mesh, material); }
public static void SetThumbnailTargetTexture(Texture2D texture) { if (EveryplayInstance != null) { currentThumbnailTargetTexture = texture; #if !UNITY_3_5 #if EVERYPLAY_IPHONE_ENABLED if (texture != null) { EveryplaySetThumbnailTargetTexture(currentThumbnailTargetTexture.GetNativeTexturePtr()); EveryplaySetThumbnailTargetTextureWidth(currentThumbnailTargetTexture.width); EveryplaySetThumbnailTargetTextureHeight(currentThumbnailTargetTexture.height); } else { EveryplaySetThumbnailTargetTexture(System.IntPtr.Zero); } #elif EVERYPLAY_ANDROID_ENABLED if (texture != null) { EveryplaySetThumbnailTargetTextureId(currentThumbnailTargetTexture.GetNativeTextureID()); EveryplaySetThumbnailTargetTextureWidth(currentThumbnailTargetTexture.width); EveryplaySetThumbnailTargetTextureHeight(currentThumbnailTargetTexture.height); } else { EveryplaySetThumbnailTargetTextureId(0); } #endif #endif } }
protected void Start () { // Check if we are running MiddleVR if(MiddleVR.VRKernel == null) { Debug.Log("[X] VRManager is missing from the scene !"); enabled = false; return; } m_VirtualMousePosition = new Vector2(0, 0); if (Application.isEditor) { // Get the vrCameras corresponding Cameras m_Cameras = new List<Camera>(); uint camerasNb = MiddleVR.VRDisplayMgr.GetCamerasNb(); for (uint i = 0; i < camerasNb; ++i) { vrCamera vrcamera = MiddleVR.VRDisplayMgr.GetCameraByIndex(i); GameObject cameraObj = GameObject.Find(vrcamera.GetName()); Camera camera = cameraObj.GetComponent<Camera>(); if (camera != null) { m_Cameras.Add(camera); } } } m_Texture = new Texture2D(m_Width, m_Height, TextureFormat.ARGB32, false); m_Texture.wrapMode = TextureWrapMode.Clamp; // Create vrImage and Texture2D #if VRWEBVIEW_UNITY_FREE // Texture2D.SetPixels takes RGBA. m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_RGBA); m_Pixels = m_Texture.GetPixels32 (0); m_PixelsHandle = GCHandle.Alloc(m_Pixels, GCHandleType.Pinned); #else // OpenGL and Direct3D 9: Memory order for texture upload is BGRA (little-endian representation of ARGB32) // Direct3D 11: Unity seems to ignore TextureFormat.ARGB32 and always creates an RGBA texture. // We let vrImage do the pixel format conversion because this operation is done in another thread. if (SystemInfo.graphicsDeviceVersion.Contains("Direct3D 11")) { m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_RGBA); } else { m_Image = new vrImage("", (uint)m_Width, (uint)m_Height, VRImagePixelFormat.VRImagePixelFormat_BGRA); } #endif // Fill texture Color32[] colors = new Color32[(m_Width * m_Height)]; for (int i = 0; i < (m_Width * m_Height); i++) { colors[i].r = 0; colors[i].g = 0; colors[i].b = 0; colors[i].a = 0; } m_Texture.SetPixels32(colors); m_Texture.Apply(false, false); #if !VRWEBVIEW_UNITY_FREE m_NativeTexturePtr = m_Texture.GetNativeTexturePtr(); #endif // Attach texture if (gameObject != null && gameObject.GetComponent<GUITexture>() == null && gameObject.GetComponent<Renderer>() != null) { var renderer = gameObject.GetComponent<Renderer>(); // Assign the material/shader to the object attached renderer.material = Resources.Load("VRWebViewMaterial", typeof(Material)) as Material; renderer.material.mainTexture = this.m_Texture; } else if (gameObject != null && gameObject.GetComponent<GUITexture>() != null ) { gameObject.GetComponent<GUITexture>().texture = this.m_Texture; } else { MiddleVR.VRLog(2, "VRWebView must be attached to a GameObject with a renderer or a GUITexture !"); enabled = false; return; } // Handle Cluster if ( MiddleVR.VRClusterMgr.IsServer() && ! MiddleVR.VRKernel.GetEditorMode() ) { MiddleVR.VRClusterMgr.AddSynchronizedObject( m_Image ); } if( ! MiddleVR.VRClusterMgr.IsClient() ) { if (m_DirectoryProviders.Length == 0 && m_ArchiveProviders.Length == 0) { m_WebView = new vrWebView("", GetAbsoluteURL(m_URL), (uint)m_Width, (uint)m_Height, m_Image); } else { m_WebView = new vrWebView("", "", (uint)m_Width, (uint)m_Height, m_Image); int order = 0; foreach(VRWebViewDirectoryProvider directoryProvider in m_DirectoryProviders) { m_WebView.AddDirectoryProvider(directoryProvider.m_URL, Application.dataPath + System.IO.Path.DirectorySeparatorChar + directoryProvider.m_DirectoryPath, order, "VRWebViewProvider" + order); order++; } foreach(VRWebViewArchiveProvider archiveProvider in m_ArchiveProviders) { m_WebView.AddArchiveProvider(archiveProvider.m_URL, Application.dataPath + System.IO.Path.DirectorySeparatorChar + archiveProvider.m_ArchivePath, archiveProvider.m_Password, order, "VRWebViewProvider" + order); order++; } m_WebView.SetURL(GetAbsoluteURL(m_URL)); } m_WebView.SetZoom( m_Zoom ); } }
public static void FaceCamSetTargetTexture(Texture2D texture) { if(EveryplayInstance != null) { #if !UNITY_3_5 #if !UNITY_EDITOR #if UNITY_IPHONE && EVERYPLAY_IPHONE if(texture != null) { EveryplayFaceCamSetTargetTexture(texture.GetNativeTexturePtr()); EveryplayFaceCamSetTargetTextureWidth(texture.width); EveryplayFaceCamSetTargetTextureHeight(texture.height); } else { EveryplayFaceCamSetTargetTexture(System.IntPtr.Zero); } #elif UNITY_ANDROID && EVERYPLAY_ANDROID if(texture != null) { EveryplayFaceCamSetTargetTextureId(texture.GetNativeTextureID()); EveryplayFaceCamSetTargetTextureWidth(texture.width); EveryplayFaceCamSetTargetTextureHeight(texture.height); } else { EveryplayFaceCamSetTargetTextureId(0); } #endif #endif #endif } }
public static void FaceCamSetTargetTexture(Texture2D texture) { if (EveryplayInstance != null && hasMethods == true) { #if !UNITY_3_5 #if EVERYPLAY_FACECAM_BINDINGS_ENABLED #if EVERYPLAY_IPHONE_ENABLED || EVERYPLAY_OSX_ENABLED if (texture != null) { EveryplayFaceCamSetTargetTexture(texture.GetNativeTexturePtr()); EveryplayFaceCamSetTargetTextureWidth(texture.width); EveryplayFaceCamSetTargetTextureHeight(texture.height); } else { EveryplayFaceCamSetTargetTexture(System.IntPtr.Zero); } #elif EVERYPLAY_ANDROID_ENABLED if (texture != null) { EveryplayFaceCamSetTargetTextureId(texture.GetNativeTextureID()); EveryplayFaceCamSetTargetTextureWidth(texture.width); EveryplayFaceCamSetTargetTextureHeight(texture.height); } else { EveryplayFaceCamSetTargetTextureId(0); } #endif #endif #endif } }
private SteamVR_RenderModel.RenderModel LoadRenderModel(CVRRenderModels renderModels, string renderModelName, string baseName) { IntPtr zero = IntPtr.Zero; EVRRenderModelError eVRRenderModelError; while (true) { eVRRenderModelError = renderModels.LoadRenderModel_Async(renderModelName, ref zero); if (eVRRenderModelError != EVRRenderModelError.Loading) { break; } Thread.Sleep(1); } if (eVRRenderModelError != EVRRenderModelError.None) { UnityEngine.Debug.LogError(string.Format("Failed to load render model {0} - {1}", renderModelName, eVRRenderModelError.ToString())); return null; } RenderModel_t renderModel_t = (RenderModel_t)Marshal.PtrToStructure(zero, typeof(RenderModel_t)); Vector3[] array = new Vector3[renderModel_t.unVertexCount]; Vector3[] array2 = new Vector3[renderModel_t.unVertexCount]; Vector2[] array3 = new Vector2[renderModel_t.unVertexCount]; Type typeFromHandle = typeof(RenderModel_Vertex_t); int num = 0; while ((long)num < (long)((ulong)renderModel_t.unVertexCount)) { IntPtr ptr = new IntPtr(renderModel_t.rVertexData.ToInt64() + (long)(num * Marshal.SizeOf(typeFromHandle))); RenderModel_Vertex_t renderModel_Vertex_t = (RenderModel_Vertex_t)Marshal.PtrToStructure(ptr, typeFromHandle); array[num] = new Vector3(renderModel_Vertex_t.vPosition.v0, renderModel_Vertex_t.vPosition.v1, -renderModel_Vertex_t.vPosition.v2); array2[num] = new Vector3(renderModel_Vertex_t.vNormal.v0, renderModel_Vertex_t.vNormal.v1, -renderModel_Vertex_t.vNormal.v2); array3[num] = new Vector2(renderModel_Vertex_t.rfTextureCoord0, renderModel_Vertex_t.rfTextureCoord1); num++; } int num2 = (int)(renderModel_t.unTriangleCount * 3u); short[] array4 = new short[num2]; Marshal.Copy(renderModel_t.rIndexData, array4, 0, array4.Length); int[] array5 = new int[num2]; int num3 = 0; while ((long)num3 < (long)((ulong)renderModel_t.unTriangleCount)) { array5[num3 * 3] = (int)array4[num3 * 3 + 2]; array5[num3 * 3 + 1] = (int)array4[num3 * 3 + 1]; array5[num3 * 3 + 2] = (int)array4[num3 * 3]; num3++; } Mesh mesh = new Mesh(); mesh.vertices = array; mesh.normals = array2; mesh.uv = array3; mesh.triangles = array5; mesh.Optimize(); Material material = SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] as Material; if (material == null || material.mainTexture == null) { IntPtr zero2 = IntPtr.Zero; while (true) { eVRRenderModelError = renderModels.LoadTexture_Async(renderModel_t.diffuseTextureId, ref zero2); if (eVRRenderModelError != EVRRenderModelError.Loading) { break; } Thread.Sleep(1); } if (eVRRenderModelError == EVRRenderModelError.None) { RenderModel_TextureMap_t renderModel_TextureMap_t = (RenderModel_TextureMap_t)Marshal.PtrToStructure(zero2, typeof(RenderModel_TextureMap_t)); Texture2D texture2D = new Texture2D((int)renderModel_TextureMap_t.unWidth, (int)renderModel_TextureMap_t.unHeight, TextureFormat.ARGB32, false); if (SteamVR.instance.graphicsAPI == EGraphicsAPIConvention.API_DirectX) { texture2D.Apply(); while (true) { eVRRenderModelError = renderModels.LoadIntoTextureD3D11_Async(renderModel_t.diffuseTextureId, texture2D.GetNativeTexturePtr()); if (eVRRenderModelError != EVRRenderModelError.Loading) { break; } Thread.Sleep(1); } } else { byte[] array6 = new byte[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight * '\u0004')]; Marshal.Copy(renderModel_TextureMap_t.rubTextureMapData, array6, 0, array6.Length); Color32[] array7 = new Color32[(int)(renderModel_TextureMap_t.unWidth * renderModel_TextureMap_t.unHeight)]; int num4 = 0; for (int i = 0; i < (int)renderModel_TextureMap_t.unHeight; i++) { for (int j = 0; j < (int)renderModel_TextureMap_t.unWidth; j++) { byte r = array6[num4++]; byte g = array6[num4++]; byte b = array6[num4++]; byte a = array6[num4++]; array7[i * (int)renderModel_TextureMap_t.unWidth + j] = new Color32(r, g, b, a); } } texture2D.SetPixels32(array7); texture2D.Apply(); } material = new Material((!(this.shader != null)) ? Shader.Find("Standard") : this.shader); material.mainTexture = texture2D; SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] = material; renderModels.FreeTexture(zero2); } else { UnityEngine.Debug.Log("Failed to load render model texture for render model " + renderModelName); } } base.StartCoroutine(this.FreeRenderModel(zero)); return new SteamVR_RenderModel.RenderModel(mesh, material); }
public static bool Write(Texture2D dst_tex, IntPtr src, int src_num, tDataFormat src_fmt) { return tWriteTexture( dst_tex.GetNativeTexturePtr(), dst_tex.width, dst_tex.height, GetTextureFormat(dst_tex), src, src_num, src_fmt) != 0; }