// Token: 0x06000DEC RID: 3564 RVA: 0x00058A74 File Offset: 0x00056C74 private RenderModel_TextureMap_t MarshalRenderModel_TextureMap(IntPtr pRenderModel) { if (Environment.OSVersion.Platform == PlatformID.MacOSX || Environment.OSVersion.Platform == PlatformID.Unix) { RenderModel_TextureMap_t_Packed renderModel_TextureMap_t_Packed = (RenderModel_TextureMap_t_Packed)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t_Packed)); RenderModel_TextureMap_t result = default(RenderModel_TextureMap_t); renderModel_TextureMap_t_Packed.Unpack(ref result); return(result); } return((RenderModel_TextureMap_t)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t))); }
/// <summary> /// Helper function to handle the inconvenient fact that the packing for RenderModel_TextureMap_t is /// different on Linux/OSX (4) than it is on Windows (8) /// </summary> /// <param name="pRenderModel">native pointer to the RenderModel_TextureMap_t</param> /// <returns></returns> private RenderModel_TextureMap_t MarshalRenderModel_TextureMap(IntPtr pRenderModel) { if ((Environment.OSVersion.Platform == PlatformID.MacOSX) || (Environment.OSVersion.Platform == PlatformID.Unix)) { var packedModel = (RenderModel_TextureMap_t_Packed)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t_Packed)); RenderModel_TextureMap_t model = new RenderModel_TextureMap_t(); packedModel.Unpack(ref model); return(model); } return((RenderModel_TextureMap_t)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t))); }
/// <summary> /// Helper function to handle the inconvenient fact that the packing for RenderModel_TextureMap_t is /// different on Linux/OSX (4) than it is on Windows (8) /// </summary> /// <param name="pTextureMap">native pointer to the RenderModel_TextureMap_t</param> /// <returns></returns> private static RenderModel_TextureMap_t MarshalRenderModelTextureMap(IntPtr pTextureMap) { if (false)//((Environment.OSVersion.Platform == PlatformID.MacOSX) || //(Environment.OSVersion.Platform == PlatformID.Unix)) { var packedModel = (RenderModel_TextureMap_t_Packed)Marshal.PtrToStructure(pTextureMap, typeof(RenderModel_TextureMap_t_Packed)); var model = new RenderModel_TextureMap_t(); packedModel.Unpack(ref model); return(model); } else { return((RenderModel_TextureMap_t)Marshal.PtrToStructure(pTextureMap, typeof(RenderModel_TextureMap_t))); } }
/// <summary> /// Helper function to handle the inconvenient fact that the packing for RenderModel_TextureMap_t is /// different on Linux/OSX (4) than it is on Windows (8) /// </summary> /// <param name="pRenderModel">native pointer to the RenderModel_TextureMap_t</param> /// <returns></returns> private RenderModel_TextureMap_t MarshalRenderModel_TextureMap(System.IntPtr pRenderModel) { #if UNITY_STANDALONE if ((System.Environment.OSVersion.Platform == System.PlatformID.MacOSX) || (System.Environment.OSVersion.Platform == System.PlatformID.Unix)) { var packedModel = (RenderModel_TextureMap_t_Packed)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t_Packed)); RenderModel_TextureMap_t model = new RenderModel_TextureMap_t(); packedModel.Unpack(ref model); return(model); } else { return((RenderModel_TextureMap_t)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t))); } #else return((RenderModel_TextureMap_t)Marshal.PtrToStructure(pRenderModel, typeof(RenderModel_TextureMap_t))); #endif }
// Token: 0x06000DDF RID: 3551 RVA: 0x00058090 File Offset: 0x00056290 private SteamVR_RenderModel.RenderModel LoadRenderModel(CVRRenderModels renderModels, string renderModelName, string baseName) { IntPtr zero = IntPtr.Zero; EVRRenderModelError evrrenderModelError; for (;;) { evrrenderModelError = renderModels.LoadRenderModel_Async(renderModelName, ref zero); if (evrrenderModelError != EVRRenderModelError.Loading) { break; } SteamVR_RenderModel.Sleep(); } if (evrrenderModelError != EVRRenderModelError.None) { Debug.LogError(string.Format("Failed to load render model {0} - {1}", renderModelName, evrrenderModelError.ToString())); return(null); } RenderModel_t renderModel_t = this.MarshalRenderModel(zero); 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)) { RenderModel_Vertex_t renderModel_Vertex_t = (RenderModel_Vertex_t)Marshal.PtrToStructure(new IntPtr(renderModel_t.rVertexData.ToInt64() + (long)(num * Marshal.SizeOf(typeFromHandle))), 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++; } uint num2 = 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; Material material = SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] as Material; if (material == null || material.mainTexture == null) { IntPtr zero2 = IntPtr.Zero; for (;;) { evrrenderModelError = renderModels.LoadTexture_Async(renderModel_t.diffuseTextureId, ref zero2); if (evrrenderModelError != EVRRenderModelError.Loading) { break; } SteamVR_RenderModel.Sleep(); } if (evrrenderModelError == EVRRenderModelError.None) { RenderModel_TextureMap_t renderModel_TextureMap_t = this.MarshalRenderModel_TextureMap(zero2); Texture2D texture2D = new Texture2D((int)renderModel_TextureMap_t.unWidth, (int)renderModel_TextureMap_t.unHeight, TextureFormat.ARGB32, false); if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11) { texture2D.Apply(); for (;;) { evrrenderModelError = renderModels.LoadIntoTextureD3D11_Async(renderModel_t.diffuseTextureId, texture2D.GetNativeTexturePtr()); if (evrrenderModelError != EVRRenderModelError.Loading) { break; } SteamVR_RenderModel.Sleep(); } } 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) ? this.shader : Shader.Find("Standard")); material.mainTexture = texture2D; SteamVR_RenderModel.materials[renderModel_t.diffuseTextureId] = material; renderModels.FreeTexture(zero2); } else { 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 abstract void FreeTexture(ref RenderModel_TextureMap_t pTexture);
public override void FreeTexture(ref RenderModel_TextureMap_t pTexture) { CheckIfUsable(); VRNativeEntrypoints.VR_IVRRenderModels_FreeTexture(m_pVRRenderModels,ref pTexture); }
public static GLRenderModel Create(string name, RenderModel_t renderModel, RenderModel_TextureMap_t diffuseTexture) { // create and bind a VAO to hold the state for this model int vao = OpenGLUtil.CreateVertexArrayObject(); GL.BindVertexArray(vao); // populate the vertex buffer int vbo = OpenGLUtil.CreateBufferObject(); GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); GL.BufferData(BufferTarget.ArrayBuffer, Marshal.SizeOf <RenderModel_Vertex_t>() * (int)renderModel.unVertexCount, renderModel.rVertexData, BufferUsageHint.StaticDraw); // identity the components in teh vertex buffer GL.EnableVertexAttribArray(0); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, Marshal.SizeOf <RenderModel_Vertex_t>(), Marshal.OffsetOf <RenderModel_Vertex_t>("vPosition")); // this might have to be size of 4? GL.EnableVertexAttribArray(1); GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, Marshal.SizeOf <RenderModel_Vertex_t>(), Marshal.OffsetOf <RenderModel_Vertex_t>("vNormal")); GL.EnableVertexAttribArray(2); GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, Marshal.SizeOf <RenderModel_Vertex_t>(), Marshal.OffsetOf <RenderModel_Vertex_t>("rfTextureCoord0")); // create and populate the index buffer int indexBuffer = OpenGLUtil.CreateBufferObject(); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer); GL.BufferData(BufferTarget.ElementArrayBuffer, Marshal.SizeOf <ushort>() * (int)renderModel.unTriangleCount * 3, renderModel.rIndexData, BufferUsageHint.StaticDraw); GL.BindVertexArray(0); // create and populate the texture int texture = OpenGLUtil.CreateTexture(); GL.BindTexture(TextureTarget.Texture2D, texture); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, diffuseTexture.unWidth, diffuseTexture.unHeight, 0, PixelFormat.Rgba, PixelType.UnsignedByte, diffuseTexture.rubTextureMapData); GL.GenerateMipmap(GenerateMipmapTarget.Texture2D); GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, new[] { (int)TextureParameterName.ClampToEdge }); GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, new[] { (int)TextureParameterName.ClampToEdge }); GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, new[] { (int)TextureMagFilter.Linear }); GL.TexParameterI(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, new[] { (int)TextureMinFilter.LinearMipmapLinear }); // *****missing stuff about anisotropy ***** // not sure if this is right float largest = GL.GetFloat((GetPName)0x84FF); GL.TexParameter(TextureTarget.Texture2D, (TextureParameterName)0x84FE, largest); GL.BindTexture(TextureTarget.Texture2D, 0); return(new GLRenderModel(vbo, indexBuffer, vao, texture, (int)renderModel.unTriangleCount * 3, name)); }