private Nullable <RenderTextureDescriptor> GetRenderTextureDescriptor(advancedfx.Interop.ISurfaceInfo fbSurfaceInfo, bool isDepth) { RenderTextureDescriptor desc = new RenderTextureDescriptor((int)fbSurfaceInfo.Width, (int)fbSurfaceInfo.Height); Debug.Log("GetRenderTextureDescriptor: " + fbSurfaceInfo.Id + "(" + (isDepth ? "depth" : "color") + ")" + ": " + fbSurfaceInfo.Format + " (" + fbSurfaceInfo.Width + "," + fbSurfaceInfo.Height + ")"); switch (fbSurfaceInfo.Format) { case advancedfx.Interop.D3DFORMAT.D3DFMT_A8R8G8B8: desc.colorFormat = RenderTextureFormat.BGRA32; break; default: Debug.LogError("Unknown back buffer format: " + fbSurfaceInfo.Format); return(null); } desc.depthBufferBits = isDepth ? 0 : 32; desc.autoGenerateMips = false; desc.bindMS = false; desc.enableRandomWrite = false; desc.sRGB = false; // for windowed CS:GO at least (?). desc.msaaSamples = 1; desc.useMipMap = false; return(new Nullable <RenderTextureDescriptor>(desc)); }
void advancedfx.Interop.IImplementation.RegisterSurface(advancedfx.Interop.ISurfaceInfo surfaceInfo, out IntPtr sharedColorTextureHandle, out IntPtr sharedDepthTextureHandle) { Debug.Log("Registering Surface: " + surfaceInfo.Id); SurfaceData surfaceData = new SurfaceData(surfaceInfo); surfaceIdToSurfaceData[surfaceInfo.Id] = surfaceData; sharedColorTextureHandle = surfaceData.sharedColorTextureHandle; sharedDepthTextureHandle = surfaceData.sharedDepthTextureHandle; }
public SurfaceData(advancedfx.Interop.ISurfaceInfo surfaceInfo) { this.surfaceInfo = surfaceInfo; RenderTexture colorTexture = null; IntPtr sharedColorTextureHandle = IntPtr.Zero; RenderTexture depthTexture = null; IntPtr sharedDepthTextureHandle = IntPtr.Zero; Nullable <RenderTextureDescriptor> rdesc; rdesc = GetRenderTextureDescriptor(surfaceInfo, false); if (rdesc.HasValue) { AfxHookUnityBeginCreateRenderTexture(); colorTexture = new RenderTexture(rdesc.Value); colorTexture.Create(); sharedColorTextureHandle = AfxHookUnityGetSharedHandle(colorTexture.GetNativeTexturePtr()); Debug.Log("Color: " + colorTexture.GetNativeTexturePtr() + " -> " + sharedColorTextureHandle); } rdesc = GetRenderTextureDescriptor(surfaceInfo, true); if (rdesc.HasValue) { AfxHookUnityBeginCreateRenderTexture(); depthTexture = new RenderTexture(rdesc.Value); depthTexture.Create(); sharedDepthTextureHandle = AfxHookUnityGetSharedHandle(depthTexture.GetNativeTexturePtr()); Debug.Log("Depth: " + depthTexture.GetNativeTexturePtr() + " -> " + sharedDepthTextureHandle); } this.colorTexture = colorTexture; this.sharedColorTextureHandle = sharedColorTextureHandle; this.depthTexture = depthTexture; this.sharedDepthTextureHandle = sharedDepthTextureHandle; }