public DepthStencil(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { video = parent.FindParentOrSelfWithException<Video>(); PixelFormat format = PixelFormat.None; switch (depthStencilFormats) { case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } depthBuffer = new DepthBuffer(width, height, format); } catch (Exception e) { Dispose(); throw e; } }
public void Prepare(int width, int height, int samples) { if (Width == width && Height == height && Samples == samples) { return; } Width = width; Height = height; Samples = samples; Framebuffer.Detach(FramebufferAttachmentPoint.Color0); Framebuffer.Detach(FramebufferAttachmentPoint.DepthStencil); ColorBuffer?.Dispose(); DepthBuffer?.Dispose(); ResolvedTex?.Dispose(); ColorBuffer = infra.GlContext.Create.Renderbuffer(width, height, Format.Srgb8Alpha8, samples); DepthBuffer = infra.GlContext.Create.Renderbuffer(width, height, Format.Depth24Stencil8, samples); ResolvedTex = infra.GlContext.Create.Texture2D(width, height, GraphicsHelper.TextureMipCount(width, height), Format.Srgb8Alpha8); Framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.Color0, ColorBuffer); Framebuffer.AttachRenderbuffer(FramebufferAttachmentPoint.DepthStencil, DepthBuffer); }
public DepthStencil(DisposableI parent, int width, int height, DepthStencilFormats depthStencilFormats) : base(parent) { try { video = parent.FindParentOrSelfWithException <Video>(); PixelFormat format = PixelFormat.None; switch (depthStencilFormats) { case DepthStencilFormats.Defualt: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24Stencil8: format = PixelFormat.Depth24Stencil8; break; case DepthStencilFormats.Depth16: format = PixelFormat.Depth16; break; case DepthStencilFormats.Depth24: format = PixelFormat.Depth24; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } depthBuffer = new DepthBuffer(width, height, format); } catch (Exception e) { Dispose(); throw e; } }
///<summary> /// This function acts very similar to <see cref="GLES2FBORenderTexture.AttachDepthBuffer">The difference between D3D & OGL is that D3D setups the DepthBuffer before rendering, /// while OGL setups the DepthBuffer per FBO. So the DepthBuffer (RenderBuffer) needs to /// be attached for OGL. ///</summary> ///<param name="depthBuffer"> </param> public void AttachDepthBuffer(DepthBuffer depthBuffer) { var glDepthBuffer = depthBuffer as GLES2DepthBuffer; GL.BindFramebuffer(GLenum.Framebuffer, this._multiSampleFB > 0 ? this._multiSampleFB : this._fb); GLES2Config.GlCheckError(this); if (glDepthBuffer != null) { GLES2RenderBuffer depthBuf = glDepthBuffer.DepthBuffer; GLES2RenderBuffer stencilBuf = glDepthBuffer.StencilBuffer; //Attach depth buffer, if it has one. if (depthBuf != null) { depthBuf.BindToFramebuffer(GLenum.DepthAttachment, 0); } //Attach stencil buffer, if it has one. if (stencilBuf != null) { stencilBuf.BindToFramebuffer(GLenum.StencilAttachment, 0); } } else { GL.FramebufferRenderbuffer(GLenum.Framebuffer, GLenum.DepthAttachment, GLenum.Renderbuffer, 0); GLES2Config.GlCheckError(this); GL.FramebufferRenderbuffer(GLenum.Framebuffer, GLenum.StencilAttachment, GLenum.Renderbuffer, 0); GLES2Config.GlCheckError(this); } }
// Polls for new depth frame data public static bool PollDepthFrame(ref DepthBuffer depthImage, ref BodyIndexBuffer bodyIndexImage, ref int minDepth, ref int maxDepth) { bool bNewFrame = false; IntPtr imagePtr = IntPtr.Zero; Int64 liFrameTime = 0; int hr = PollImageFrameData(FrameSource.TypeDepth | FrameSource.TypeBodyIndex); if (hr == 0) { hr = GetNewDepthFrameData(ref imagePtr, ref liFrameTime, ref minDepth, ref maxDepth); if (hr == 0) { depthImage = (DepthBuffer)Marshal.PtrToStructure(imagePtr, typeof(DepthBuffer)); hr = GetNewBodyIndexFrameData(ref imagePtr, ref liFrameTime); if (hr == 0) { bodyIndexImage = (BodyIndexBuffer)Marshal.PtrToStructure(imagePtr, typeof(BodyIndexBuffer)); bNewFrame = true; } } } return(bNewFrame); }
public Frame() { shader = new ShaderProgram( new Shader("def_vs.glsl", ShaderType.VertexShader), new Shader("def_fs.glsl", ShaderType.FragmentShader) ); depthShader = new ShaderProgram( new Shader("depth_vs.glsl", ShaderType.VertexShader), new Shader("empty_fs.glsl", ShaderType.FragmentShader) ); light = new DirectionalLight(); depthBuffer = new DepthBuffer(); camera = Core.Unit.Player.Camera; GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); GL.Enable(EnableCap.Multisample); post = new Postprocessor(); }
public void Dispose() { GL.DeleteFramebuffer(Id); DepthBuffer.Dispose(); BackBuffer.Dispose(); REngine.CheckGLError(); }
public void Dispose() { resolveFramebuffer?.Dispose(); Framebuffer?.Dispose(); ColorBuffer?.Dispose(); DepthBuffer?.Dispose(); ResolvedTex?.Dispose(); }
private void DestroyBuffers() { ImmediateContext.OutputMerger.SetRenderTargets((RenderTargetView)null); BackBufferView.Dispose(); BackBuffer.Dispose(); DepthBufferView.Dispose(); DepthBuffer.Dispose(); }
public TextureDrawingContext(DeviceManager deviceManager, int width, int height) : base(deviceManager: deviceManager) { Width = width; Height = height; _textureBuffer = new TextureBuffer(deviceManager, width, height); _depthBuffer = new DepthBuffer(deviceManager, width, height); }
public override void Dispose() { disposeChilderen(); if (depthBuffer != null) { depthBuffer.Dispose(); depthBuffer = null; } base.Dispose(); }
private void ClearDepth() { for (int i = 0; i < DepthBuffer.GetLength(0); i++) { for (int j = 0; j < DepthBuffer.GetLength(1); j++) { DepthBuffer[i, j] = farClipDistance; } } }
public override void Dispose() { disposeChilderen(); if (depthBuffer != null) { depthBuffer.Dispose(); depthBuffer = null; } base.Dispose(); }
public override bool AttachDepthBuffer(DepthBuffer ndepthBuffer) { bool result = base.AttachDepthBuffer(depthBuffer); if (result) { this.fbo.AttachDepthBuffer(depthBuffer); } return(result); }
public override bool AttachDepthBuffer( DepthBuffer ndepthBuffer ) { bool result; result = base.AttachDepthBuffer( ndepthBuffer ); if ( result ) { this.fb.AttachDepthBuffer( ndepthBuffer ); } return result; }
public void DestroyBuffers() { if (BackBuffer != null) { ImmediateContext.OutputMerger.SetRenderTargets((RenderTargetView)null); BackBufferView.Dispose(); BackBuffer.Dispose(); DepthBufferView.Dispose(); DepthBuffer.Dispose(); BackBuffer = null; } }
public RenderTexture(int width, int height) { view = new View(new Viewport(0, height, width, 0), new Vector2(0, 0), new Vector2(width, height)); depthBuffer = new DepthBuffer(width, height); framebuffer = new Framebuffer(); deviceTexture = new DeviceTexture(DefaultShader.DEFFAULT_TEXTURE_UNIFORM_NAME, width, height, false); deviceTexture.Bind(); framebuffer.Bind(); deviceTexture.CopyRawData(IntPtr.Zero, 0); framebuffer.AttachDepthBuffer(depthBuffer); framebuffer.AttachTexture(deviceTexture); deviceTexture.Unbind(); framebuffer.Use(); framebuffer.Check(); texture = Texture.FromDeviceTexture(deviceTexture); framebuffer.Unbind(); }
public Depth() { if(depth == null) { depth = new ShaderProgram(VFS.GetFileBytes("vfs1:/shaders/Depth.cgx")); depth.SetAttributeBinding(0, "a_Position"); depth.SetUniformBinding(0, "WorldViewProj"); } RenderPassTarget = new Texture2D((int)RootNode.graphicsContext.GetDisplay().Width, (int)RootNode.graphicsContext.GetDisplay().Height , false, PixelFormat.Rgba, PixelBufferOption.Renderable); RenderPassBuf = new FrameBuffer(); RenderPassBuf.SetColorTarget(RenderPassTarget,0); DepthBuffer temp = new DepthBuffer(RenderPassTarget.Width, RenderPassTarget.Height, PixelFormat.Depth24Stencil8); RenderPassBuf.SetDepthTarget(temp); }
public WindowDrawingContext(GraphicsContext graphics, IInputContext input) : base(graphics.DeviceManager) { if (graphics == null) { throw new ArgumentNullException("graphics"); } if (input == null) { throw new ArgumentNullException("input"); } Graphics = graphics; _window = new AppWindow(input); _window.SizeChanged += win => Initialize(); _depthBuffer = new DepthBuffer(DeviceManager, _window.ClientWidth, _window.ClientHeight); _windowTextureBuffer = new WindowTextureBuffer(DeviceManager, _window.Form.Handle, _window.ClientWidth, _window.ClientHeight); }
public void UnloadDirect3D() { if (!Ready) { return; } TextureCache.Dispose(); DefaultTextureView.Dispose(); DefaultTexture.Dispose(); SampleState.Dispose(); DefaultEffect.Dispose(); BackBufferView.Dispose(); BackBuffer.Dispose(); DepthBufferView.Dispose(); DepthBuffer.Dispose(); Device.Dispose(); }
static void Init() { graphics = new GraphicsContext(); stopwatch = new Stopwatch(); stopwatch.Start(); SampleDraw.Init(graphics); // framebuffer frameBuffer = new FrameBuffer(); renderTexture = new Texture2D(offscreenWidth, offscreenHeight, false, PixelFormat.Rgba, PixelBufferOption.Renderable); depthBuffer = new DepthBuffer(offscreenWidth, offscreenHeight, PixelFormat.Depth16); frameBuffer.SetColorTarget(renderTexture, 0); frameBuffer.SetDepthTarget(depthBuffer); // vcolor shader vcolorShader = new ShaderProgram("/Application/Sample/Graphics/PixelBufferSample/shaders/VertexColor.cgx"); vcolorShader.SetUniformBinding(0, "WorldViewProj"); vcolorShader.SetAttributeBinding(0, "a_Position"); vcolorShader.SetAttributeBinding(1, "a_Color0"); // texture shader textureShader = new ShaderProgram("/Application/Sample/Graphics/PixelBufferSample/shaders/Texture.cgx"); textureShader.SetUniformBinding(0, "WorldViewProj"); textureShader.SetAttributeBinding(0, "a_Position"); textureShader.SetAttributeBinding(1, "a_TexCoord"); // vertex buffer triangleVertices = CreateTriangleVertices(); cubeVertices = CreateCubeVertices(); // renderstate graphics.Enable(EnableMode.DepthTest); graphics.Enable(EnableMode.CullFace); graphics.SetCullFace(CullFaceMode.Back, CullFaceDirection.Ccw); graphics.Enable(EnableMode.CullFace, false); }
void Update() { if (nowResolution != mainCanvas.GetComponent <RectTransform>().sizeDelta || nowgraphics != _graphics || nowdepthBuffer != _depthBuffer) { nowgraphics = _graphics; nowdepthBuffer = _depthBuffer; nowResolution = mainCanvas.GetComponent <RectTransform>().sizeDelta; if (targetCamera.targetTexture != null) { targetCamera.targetTexture.Release(); } targetCamera.targetTexture = new RenderTexture((int)nowResolution.x, (int)nowResolution.y, (int)nowdepthBuffer, nowgraphics) { name = $"{(int) nowResolution.x}x{(int) nowResolution.y}" }; rawImage.texture = targetCamera.targetTexture; } }
/// <summary> /// Dispose contained fields. /// </summary> public void Dispose() { if (SwapTextureSet != null) { SwapTextureSet.Dispose(); SwapTextureSet = null; } if (Textures != null) { foreach (Texture2D texture in Textures) { texture.Dispose(); } Textures = null; } if (RenderTargetViews != null) { foreach (RenderTargetView renderTargetView in RenderTargetViews) { renderTargetView.Dispose(); } RenderTargetViews = null; } if (DepthBuffer != null) { DepthBuffer.Dispose(); DepthBuffer = null; } if (DepthStencilView != null) { DepthStencilView.Dispose(); DepthStencilView = null; } }
// Polls for new infrared frame data public static bool PollInfraredFrame(ref DepthBuffer infraredImage) { bool bNewFrame = false; IntPtr imagePtr = IntPtr.Zero; Int64 liFrameTime = 0; int hr = PollImageFrameData(FrameSource.TypeInfrared); if (hr == 0) { hr = GetNewInfraredFrameData(ref imagePtr, ref liFrameTime); if (hr == 0) { infraredImage = (DepthBuffer)Marshal.PtrToStructure(imagePtr, typeof(DepthBuffer)); bNewFrame = true; } } return(bNewFrame); }
public static bool PollDepth(IntPtr depthStreamHandle, bool isNearMode, ref ushort[] depthPlayerData) { IntPtr imageFramePtr = IntPtr.Zero; bool newDepth = false; if (isNearMode) { KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.EnableNearMode); } else { KinectWrapper.NuiImageStreamSetImageFrameFlags(depthStreamHandle, NuiImageStreamFlags.None); } int hr = KinectWrapper.NuiImageStreamGetNextFrame(depthStreamHandle, 0, ref imageFramePtr); if (hr == 0) { newDepth = true; NuiImageFrame imageFrame = (NuiImageFrame)Marshal.PtrToStructure(imageFramePtr, typeof(NuiImageFrame)); INuiFrameTexture frameTexture = (INuiFrameTexture)Marshal.GetObjectForIUnknown(imageFrame.pFrameTexture); NuiLockedRect lockedRectPtr = new NuiLockedRect(); IntPtr r = IntPtr.Zero; frameTexture.LockRect(0, ref lockedRectPtr, r, 0); DepthBuffer db = (DepthBuffer)Marshal.PtrToStructure(lockedRectPtr.pBits, typeof(DepthBuffer)); depthPlayerData = db.pixels; frameTexture.UnlockRect(0); hr = KinectWrapper.NuiImageStreamReleaseFrame(depthStreamHandle, imageFramePtr); } return(newDepth); }
public int SolvePart2() { var buffer = new DepthBuffer(); buffer.Push(GetNextDepthValue()); buffer.Push(GetNextDepthValue()); buffer.Push(GetNextDepthValue()); var previousWindowSum = buffer.Sum(); while (!buffer.Stop()) { if (buffer.Sum() > previousWindowSum) { _WindowSumIncreaseCount++; } previousWindowSum = buffer.Sum(); buffer.Push(GetNextDepthValue()); } return(_WindowSumIncreaseCount); }
private short[] extractDepthImage(NuiImageBuffer buf) { DepthBuffer db = (DepthBuffer)Marshal.PtrToStructure(buf.m_pBuffer, typeof(DepthBuffer)); return(db.pixels); }
public virtual void _DetachDepthBuffer() { depthBuffer = null; }
public virtual void DetachDepthBuffer() { if (depthBuffer == null) return; depthBuffer.NotifyRenderTargetDetached(this); depthBuffer = null; }
public virtual bool AttachDepthBuffer(DepthBuffer ndepthBuffer) { var retVal = false; if (ndepthBuffer.IsCompatible(this)) { retVal = true; DetachDepthBuffer(); depthBuffer = ndepthBuffer; depthBuffer.NotifyRenderTargetAttached(this); } return retVal; }
///<summary> /// This function acts very similar to <see cref="GLES2FBORenderTexture.AttachDepthBuffer">The difference between D3D & OGL is that D3D setups the DepthBuffer before rendering, /// while OGL setups the DepthBuffer per FBO. So the DepthBuffer (RenderBuffer) needs to /// be attached for OGL. ///</summary> ///<param name="depthBuffer"> </param> public void AttachDepthBuffer( DepthBuffer depthBuffer ) { var glDepthBuffer = depthBuffer as GLES2DepthBuffer; GL.BindFramebuffer( GLenum.Framebuffer, this._multiSampleFB > 0 ? this._multiSampleFB : this._fb ); GLES2Config.GlCheckError( this ); if ( glDepthBuffer != null ) { GLES2RenderBuffer depthBuf = glDepthBuffer.DepthBuffer; GLES2RenderBuffer stencilBuf = glDepthBuffer.StencilBuffer; //Attach depth buffer, if it has one. if ( depthBuf != null ) { depthBuf.BindToFramebuffer( GLenum.DepthAttachment, 0 ); } //Attach stencil buffer, if it has one. if ( stencilBuf != null ) { stencilBuf.BindToFramebuffer( GLenum.StencilAttachment, 0 ); } } else { GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.DepthAttachment, GLenum.Renderbuffer, 0 ); GLES2Config.GlCheckError( this ); GL.FramebufferRenderbuffer( GLenum.Framebuffer, GLenum.StencilAttachment, GLenum.Renderbuffer, 0 ); GLES2Config.GlCheckError( this ); } }
public void ClearRenderTargets() { DepthBuffer.Clear(float.MaxValue); }
// Polls for new depth frame data public static bool PollDepthFrame(ref DepthBuffer depthImage, ref BodyIndexBuffer bodyIndexImage, ref int minDepth, ref int maxDepth) { bool bNewFrame = false; IntPtr imagePtr = IntPtr.Zero; Int64 liFrameTime = 0; int hr = PollImageFrameData(FrameSource.TypeDepth | FrameSource.TypeBodyIndex); if (hr == 0) { hr = GetNewDepthFrameData(ref imagePtr, ref liFrameTime, ref minDepth, ref maxDepth); if(hr == 0) { depthImage = (DepthBuffer)Marshal.PtrToStructure(imagePtr, typeof(DepthBuffer)); hr = GetNewBodyIndexFrameData(ref imagePtr, ref liFrameTime); if(hr == 0) { bodyIndexImage = (BodyIndexBuffer)Marshal.PtrToStructure(imagePtr, typeof(BodyIndexBuffer)); bNewFrame = true; } } } return bNewFrame; }
// Polls for new infrared frame data public static bool PollInfraredFrame(ref DepthBuffer infraredImage) { bool bNewFrame = false; IntPtr imagePtr = IntPtr.Zero; Int64 liFrameTime = 0; int hr = PollImageFrameData(FrameSource.TypeInfrared); if (hr == 0) { hr = GetNewInfraredFrameData(ref imagePtr, ref liFrameTime); if(hr == 0) { infraredImage = (DepthBuffer)Marshal.PtrToStructure(imagePtr, typeof(DepthBuffer)); bNewFrame = true; } } return bNewFrame; }
private void RenderFrame(RenderTargetTexture targetTexture, DepthBuffer depthBuffer, RenderTypes renderType) { CurrentRenderType = renderType; bool offscreenRender = targetTexture != null; Tile.deepestLevel = 0; try { if (offscreenRender) { RenderContext11.SetOffscreenRenderTargets(targetTexture, depthBuffer); } else { RenderContext11.SetDisplayRenderTargets(); } //Clear the backbuffer to a black color RenderContext11.ClearRenderTarget(new SharpDX.Color(SkyColor.R, SkyColor.G, SkyColor.B, SkyColor.A)); RenderContext11.RenderType = CurrentImageSet.DataSetType; RenderContext11.BlendMode = BlendMode.Alpha; if (CurrentImageSet.DataSetType == ImageSetType.Sandbox) { // Start Sandbox mode RenderContext11.SunPosition = LayerManager.GetPrimarySandboxLight(); RenderContext11.SunlightColor = LayerManager.GetPrimarySandboxLightColor(); RenderContext11.ReflectedLightColor = Color.Black; RenderContext11.HemisphereLightColor = Color.Black; SkyColor = Color.Black; if ((int)SolarSystemTrack < (int)SolarSystemObjects.Custom) { double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack); double distance = SolarSystemCameraDistance; double camAngle = fovLocal; double distrad = distance / (radius * Math.Tan(.5 * camAngle)); if (distrad < 1) { planetFovWidth = Math.Asin(distrad); } else { planetFovWidth = Math.PI; } } else { planetFovWidth = Math.PI; } SetupMatricesSolarSystem11(false, renderType); Matrix3d matLocal = RenderContext11.World; matLocal.Multiply(Matrix3d.Translation(-viewCamera.ViewTarget)); RenderContext11.World = matLocal; RenderContext11.WorldBase = RenderContext11.World; RenderContext11.WorldBaseNonRotating = RenderContext11.World; RenderContext11.NominalRadius = 1; Earth3d.MainWindow.MakeFrustum(); double zoom = Earth3d.MainWindow.ZoomFactor; LayerManager.Draw(RenderContext11, 1.0f, false, "Sandbox", true, false); if ((SolarSystemMode) && label != null && !TourPlayer.Playing) { label.Draw(RenderContext11, true); } RenderContext11.setRasterizerState(TriangleCullMode.Off); // end Sandbox Mode } else if (CurrentImageSet.DataSetType == ImageSetType.SolarSystem) { { SkyColor = Color.Black; if ((int)SolarSystemTrack < (int)SolarSystemObjects.Custom) { double radius = Planets.GetAdjustedPlanetRadius((int)SolarSystemTrack); double distance = SolarSystemCameraDistance; double camAngle = fovLocal; double distrad = distance / (radius * Math.Tan(.5 * camAngle)); if (distrad < 1) { planetFovWidth = Math.Asin(distrad); } else { planetFovWidth = Math.PI; } } else { planetFovWidth = Math.PI; } if (trackingObject == null) { trackingObject = Search.FindCatalogObjectExact("Sun"); } SetupMatricesSolarSystem11(true, renderType); float skyOpacity = 1.0f - Planets.CalculateSkyBrightnessFactor(RenderContext11.View, viewCamera.ViewTarget); if (float.IsNaN(skyOpacity)) { skyOpacity = 0f; } double zoom = Earth3d.MainWindow.ZoomFactor; float milkyWayBlend = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 8.4)) / 4.2); float milkyWayBlendIn = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 17.9)) / 2.3); if (Properties.Settings.Default.SolarSystemMilkyWay.State) { if (milkyWayBlend < 1) // Solar System mode Milky Way background { if (milkyWayBackground == null) { milkyWayBackground = GetImagesetByName("Digitized Sky Survey (Color)"); } if (milkyWayBackground != null) { float c = ((1 - milkyWayBlend)) / 4; Matrix3d matOldMW = RenderContext11.World; Matrix3d matLocalMW = RenderContext11.World; matLocalMW.Multiply(Matrix3d.Scaling(100000, 100000, 100000)); matLocalMW.Multiply(Matrix3d.RotationX(-23.5 / 180 * Math.PI)); matLocalMW.Multiply(Matrix3d.RotationY(Math.PI)); matLocalMW.Multiply(Matrix3d.Translation(cameraOffset)); RenderContext11.World = matLocalMW; RenderContext11.WorldBase = matLocalMW; Earth3d.MainWindow.MakeFrustum(); RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White); RenderContext11.DepthStencilMode = DepthStencilMode.Off; DrawTiledSphere(milkyWayBackground, c * Properties.Settings.Default.SolarSystemMilkyWay.Opacity, Color.FromArgb(255, 255, 255, 255)); RenderContext11.World = matOldMW; RenderContext11.WorldBase = matOldMW; RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } } } // CMB float cmbBlend = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 33)) / 2.3); double cmbLog = Math.Log(zoom); if (Properties.Settings.Default.SolarSystemCMB.State) { if (cmbBlend > 0) // Solar System mode Milky Way background { if (cmbBackground == null) { cmbBackground = GetImagesetByName("Planck CMB"); } if (cmbBackground != null) { float c = ((cmbBlend)) / 16; Matrix3d matOldMW = RenderContext11.World; Matrix3d matLocalMW = RenderContext11.World; matLocalMW.Multiply(Matrix3d.Scaling(2.9090248982E+15, 2.9090248982E+15, 2.9090248982E+15)); matLocalMW.Multiply(Matrix3d.RotationX(-23.5 / 180 * Math.PI)); matLocalMW.Multiply(Matrix3d.RotationY(Math.PI)); RenderContext11.World = matLocalMW; RenderContext11.WorldBase = matLocalMW; Earth3d.MainWindow.MakeFrustum(); RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White); RenderContext11.DepthStencilMode = DepthStencilMode.Off; DrawTiledSphere(cmbBackground, c * Properties.Settings.Default.SolarSystemCMB.Opacity, Color.FromArgb(255, 255, 255, 255)); RenderContext11.World = matOldMW; RenderContext11.WorldBase = matOldMW; RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } } } { Matrix3d matOld = RenderContext11.World; Matrix3d matLocal = RenderContext11.World; matLocal.Multiply(Matrix3d.Translation(viewCamera.ViewTarget)); RenderContext11.World = matLocal; Earth3d.MainWindow.MakeFrustum(); if (Properties.Settings.Default.SolarSystemCosmos.State) { RenderContext11.DepthStencilMode = DepthStencilMode.Off; Grids.DrawCosmos3D(RenderContext11, Properties.Settings.Default.SolarSystemCosmos.Opacity * skyOpacity); RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } if (true) { RenderContext11.DepthStencilMode = DepthStencilMode.Off; Grids.DrawCustomCosmos3D(RenderContext11, skyOpacity); RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } if (Properties.Settings.Default.SolarSystemMilkyWay.State && milkyWayBlendIn > 0) { Grids.DrawGalaxy3D(RenderContext11, Properties.Settings.Default.SolarSystemMilkyWay.Opacity * skyOpacity * milkyWayBlendIn); } if (Properties.Settings.Default.SolarSystemStars.State) { Grids.DrawStars3D(RenderContext11, Properties.Settings.Default.SolarSystemStars.Opacity * skyOpacity); } LayerManager.Draw(RenderContext11, 1.0f, true, "Sky", true, false); RenderContext11.World = matOld; Earth3d.MainWindow.MakeFrustum(); } if (SolarSystemCameraDistance < 15000) { SetupMatricesSolarSystem11(false, renderType); if (Properties.Settings.Default.SolarSystemMinorPlanets.State) { MinorPlanets.DrawMPC3D(RenderContext11, Properties.Settings.Default.SolarSystemMinorPlanets.Opacity, viewCamera.ViewTarget); } Planets.DrawPlanets3D(RenderContext11, Properties.Settings.Default.SolarSystemPlanets.Opacity, viewCamera.ViewTarget); } double p = Math.Log(zoom); double d = (180 / SolarSystemCameraDistance) * 100; float sunAtDistance = (float)Math.Min(1, Math.Max(0, (Math.Log(zoom) - 7.5)) / 3); if (sunAtDistance > 0 && Settings.Active.SolarSystemPlanets) { Planets.DrawPointPlanet(RenderContext11, new Vector3d(0, 0, 0), (float)d * sunAtDistance, Color.FromArgb(192, 191, 128), false, 1); } if ((SolarSystemMode) && label != null && !TourPlayer.Playing) { label.Draw(RenderContext11, true); } } RenderContext11.setRasterizerState(TriangleCullMode.Off); } else { if (CurrentImageSet.DataSetType == ImageSetType.Panorama || CurrentImageSet.DataSetType == ImageSetType.Sky) { SkyColor = Color.Black; if ((int)renderType < 5) { SetupMatricesSpaceDome(false, renderType); } else { SetupMatricesSpace11(ZoomFactor, renderType); } RenderContext11.DepthStencilMode = DepthStencilMode.Off; } else { if (Settings.DomeView) { SetupMatricesLandDome(renderType); } else { SetupMatricesLand11(renderType); } RenderContext11.DepthStencilMode = DepthStencilMode.ZReadWrite; } ComputeViewParameters(CurrentImageSet); // Update Context pane CurrentViewCorners = new Coordinates[] { GetCoordinatesForScreenPoint(0, 0), GetCoordinatesForScreenPoint(ViewWidth, 0), GetCoordinatesForScreenPoint(ViewWidth, renderWindow.ClientRectangle.Height), GetCoordinatesForScreenPoint(0, renderWindow.ClientRectangle.Height) }; Coordinates temp = GetCoordinatesForScreenPoint(ViewWidth / 2, renderWindow.ClientRectangle.Height / 2); if (contextPanel != null && ((int)renderType > 4 || renderType == RenderTypes.DomeFront)) { contextPanel.SetViewRect(CurrentViewCorners); } UpdateKmlViewInfo(); if (KmlMarkers != null) { KmlMarkers.ClearGroundOverlays(); } string referenceFrame = GetCurrentReferenceFrame(); if (PlanetLike || Space) { LayerManager.PreDraw(RenderContext11, 1.0f, Space, referenceFrame, true); } if (Properties.Settings.Default.EarthCutawayView.State && !Space && CurrentImageSet.DataSetType == ImageSetType.Earth) { Grids.DrawEarthStructure(RenderContext11, 1f); } RenderContext11.SetupBasicEffect(BasicEffect.TextureColorOpacity, 1, Color.White); if (KmlMarkers != null) { KmlMarkers.SetupGroundOverlays(RenderContext11); } if (PlanetLike) { RenderContext11.setRasterizerState(TriangleCullMode.Off); } // Call DrawTiledSphere instead of PaintLayerFull, because PaintLayerFull // will reset ground layer state DrawTiledSphere(CurrentImageSet, 1.0f, Color.White); if (imageStackVisible) { foreach (ImageSet set in ImageStackList) { PaintLayerFull11(set, StudyOpacity); } } if (studyImageset != null) { if (studyImageset.DataSetType != CurrentImageSet.DataSetType) { StudyImageset = null; } else { PaintLayerFull11(studyImageset, StudyOpacity); } } if (previewImageset != null && PreviewBlend.State) { if (previewImageset.DataSetType != CurrentImageSet.DataSetType) { previewImageset = null; } else { PaintLayerFull11(previewImageset, PreviewBlend.Opacity * 100.0f); } } else { PreviewBlend.State = false; previewImageset = null; } if (Space && (CurrentImageSet.Name == "Plotted Sky")) { Grids.DrawStars(RenderContext11, 1f); } if (Space && Properties.Settings.Default.ShowSolarSystem.State) { Planets.DrawPlanets(RenderContext11, Properties.Settings.Default.ShowSolarSystem.Opacity); } if (PlanetLike || Space) { if (!Space) { //todo fix this for other planets.. double angle = Coordinates.MstFromUTC2(SpaceTimeController.Now, 0) / 180.0 * Math.PI; RenderContext11.WorldBaseNonRotating = Matrix3d.RotationY(angle) * RenderContext11.WorldBase; RenderContext11.NominalRadius = CurrentImageSet.MeanRadius; } else { RenderContext11.WorldBaseNonRotating = RenderContext11.World; RenderContext11.NominalRadius = CurrentImageSet.MeanRadius; RenderContext11.DepthStencilMode = DepthStencilMode.Off; } LayerManager.Draw(RenderContext11, 1.0f, Space, referenceFrame, true, Space); } if (Space && !hemisphereView && Settings.Active.LocalHorizonMode && !Settings.DomeView && !ProjectorServer) { Grids.DrawHorizon(RenderContext11, 1f); } if (Settings.Active.ShowClouds && !Space && CurrentImageSet.DataSetType == ImageSetType.Earth) { DrawClouds(); } // Draw Field of view indicator if (Settings.Active.ShowFieldOfView) { fovBlend.TargetState = true; } else { fovBlend.TargetState = false; } if (fovBlend.State) { if (fov != null && Space) { fov.Draw3D(RenderContext11, fovBlend.Opacity, RA, Dec); } } if (label != null && !TourPlayer.Playing) { label.Draw(RenderContext11, PlanetLike); } if (ShowKmlMarkers && KmlMarkers != null) { KmlMarkers.DrawLabels(RenderContext11); } // End Planet & space } if (uiController != null) { { uiController.Render(this); } } if (videoOverlay != null) { if ((int)renderType < 5) { SetupMatricesVideoOverlayDome(false, renderType); } else { SetupMatricesVideoOverlay(ZoomFactor); } DepthStencilMode mode = RenderContext11.DepthStencilMode = DepthStencilMode.Off; PaintLayerFull11(videoOverlay, 100f); RenderContext11.DepthStencilMode = mode; } if (measuringDrag && measureLines != null) { measureLines.DrawLines(RenderContext11, 1.0f, Color.Yellow); } if (Properties.Settings.Default.ShowCrosshairs && !TourPlayer.Playing && renderType == RenderTypes.Normal) { float aspect = RenderContext11.ViewPort.Height / RenderContext11.ViewPort.Width; crossHairPoints[0].X = .01f * aspect; crossHairPoints[1].X = -.01f * aspect; crossHairPoints[0].Y = 0; crossHairPoints[1].Y = 0; crossHairPoints[0].Z = .9f; crossHairPoints[1].Z = .9f; crossHairPoints[0].W = 1f; crossHairPoints[1].W = 1f; crossHairPoints[0].Color = Color.White; crossHairPoints[1].Color = Color.White; crossHairPoints[2].X = 0; crossHairPoints[3].X = 0; crossHairPoints[2].Y = -.01f; crossHairPoints[3].Y = .01f; crossHairPoints[2].Z = .9f; crossHairPoints[3].Z = .9f; crossHairPoints[2].W = 1f; crossHairPoints[3].W = 1f; crossHairPoints[2].Color = Color.White; crossHairPoints[3].Color = Color.White; Sprite2d.DrawLines(RenderContext11, crossHairPoints, 4, SharpDX.Matrix.OrthoLH(1f, 1f, 1, -1), false); } if (Properties.Settings.Default.ShowTouchControls && (!TourPlayer.Playing || mover == null) && ( renderType == RenderTypes.Normal || renderType == RenderTypes.LeftEye || renderType == RenderTypes.RightEye) && !rift ) { DrawTouchControls(); } DrawKinectUI(); SetupMatricesAltAz(); Reticle.DrawAll(RenderContext11); } catch (Exception e) { if (Earth3d.Logging) { Earth3d.WriteLogMessage("RenderFrame: Exception"); } if (offscreenRender) { throw e; } } finally { if (offscreenRender) { RenderContext11.SetDisplayRenderTargets(); } } PresentFrame11(offscreenRender); }
public void Render() { if (!readyToRender) { return; } if (SyncLayerNeeded) { NetControl.SyncLayersUiThread(); } if (SyncTourNeeded) { NetControl.SyncTourUiThread(); } if (Tile.fastLoad) { Tile.fastLoadAutoReset = true; } if (!TourPlayer.Playing) { Earth3d.MainWindow.CrossFadeFrame = false; } Int64 ticks = HiResTimer.TickCount; double elapsedSeconds = ((double)(ticks - lastRenderTickCount)) / HiResTimer.Frequency; if (Properties.Settings.Default.TargetFrameRate != 0 && !(Properties.Settings.Default.FrameSync && Properties.Settings.Default.TargetFrameRate == 60)) { int frameRate = Properties.Settings.Default.TargetFrameRate; if (elapsedSeconds < (1.0 / (double)frameRate)) { return; } } lastRenderTickCount = ticks; lastFrameTime = (Math.Min(.1, elapsedSeconds)); //Update MetaNow to current realtime for entire frame to render exactly on time SpaceTimeController.MetaNow = DateTime.Now; LoadTileBudget = 1; if (IsPaused() || !Initialized) { System.Threading.Thread.Sleep(100); return; } if (ProjectorServer) { UpdateNetworkStatus(); } //oculus rift support rift = StereoMode == StereoModes.OculusRift; if (rift) { GetSensorSample(); } TileCache.PurgeLRU(); TileCache.DecimateQueue(); Tile.imageQuality = Properties.Settings.Default.ImageQuality; Tile.CurrentRenderGeneration++; IconCacheEntry.CurrentFrame = Tile.CurrentRenderGeneration; Tile.lastDeepestLevel = Tile.deepestLevel; Tile.TilesInView = 0; Tile.TrianglesRendered = 0; Tile.TilesTouched = 0; if (ZoomFactor == 0 || TargetZoom == 0 || double.IsNaN(ZoomFactor) || double.IsNaN(TargetZoom)) { ZoomFactor = TargetZoom = 360; } if (contextPanel != null) { contextPanel.QueueProgress = TileCache.QueuePercent; } TileCache.InitNextWaitingTile(); // reset dome matrix Cache DomeMatrixFresh = false; if (mover != null) { SpaceTimeController.Now = mover.CurrentDateTime; } else { SpaceTimeController.UpdateClock(); LayerManager.UpdateLayerTime(); } if (uiController != null) { { uiController.PreRender(this); } } if (Space) { Planets.UpdatePlanetLocations(false); } else if (CurrentImageSet.DataSetType == ImageSetType.SolarSystem) { // todo allow update of focus planet Planets.UpdatePlanetLocations(true); Planets.UpdateOrbits(0); } UpdateSpaceNavigator(); UpdateXInputState(); UpdateNetControlState(); if (mover != null) { UpdateMover(mover); } else { if (!SandboxMode) { if (SolarSystemTrack == SolarSystemObjects.Undefined | (SolarSystemTrack == SolarSystemObjects.Custom && viewCamera.ViewTarget == Vector3d.Empty)) { SolarSystemTrack = SolarSystemObjects.Sun; } } } UpdateViewParameters(); if (SolarSystemMode) { if (SolarSystemTrack != SolarSystemObjects.Custom) { viewCamera.ViewTarget = Planets.GetPlanet3dLocation(SolarSystemTrack); } } ClampZoomValues(); if (blink) { TimeSpan ts = DateTime.Now - lastBlink; if (ts.TotalMilliseconds > 500) { if (StudyOpacity > 0) { StudyOpacity = 0; } else { StudyOpacity = 100; } lastBlink = DateTime.Now; } } LayerManager.PrepTourLayers(); if (Settings.MasterController) { SendMove(); } if (contextPanel != null) { contextPanel.QueueProgress = TileCache.QueuePercent; if (Space) { contextPanel.ViewLevel = fovAngle; contextPanel.RA = RA; contextPanel.Dec = Dec; if (constellationCheck != null) { constellation = this.constellationCheck.FindConstellationForPoint(RA, Dec); contextPanel.Constellation = Constellations.FullName(Constellation); } } else if (SolarSystemMode || SandboxMode) { if (SandboxMode) { contextPanel.Sandbox = true; contextPanel.Distance = SolarSystemCameraDistance; } else { contextPanel.Sandbox = false; contextPanel.Distance = SolarSystemCameraDistance; } if (!SandboxMode && (viewCamera.Target != SolarSystemObjects.Custom && viewCamera.Target != SolarSystemObjects.Undefined)) { Vector3d pnt = Coordinates.GeoTo3dDouble(ViewLat, ViewLong + 90); Matrix3d EarthMat = Planets.EarthMatrixInv; pnt = Vector3d.TransformCoordinate(pnt, EarthMat); pnt.Normalize(); Vector2d radec = Coordinates.CartesianToLatLng(pnt); if (viewCamera.Target != SolarSystemObjects.Earth) { if (radec.X < 0) { radec.X += 360; } } contextPanel.RA = radec.X; contextPanel.Dec = radec.Y; } else { contextPanel.RA = ViewLong; contextPanel.Dec = ViewLat; } contextPanel.Constellation = null; } else if (PlanetLike) { contextPanel.Sandbox = false; contextPanel.Distance = SolarSystemCameraDistance / UiTools.KilometersPerAu * 370; contextPanel.RA = ViewLong; contextPanel.Dec = ViewLat; contextPanel.Constellation = null; } else { contextPanel.Sandbox = false; contextPanel.ViewLevel = fovAngle; contextPanel.RA = ViewLong; contextPanel.Dec = ViewLat; contextPanel.Constellation = null; } } if (StereoMode != StereoModes.Off && (!Space || rift)) { RenderContext11.ViewPort = new SharpDX.Direct3D11.Viewport(0, 0, ViewWidth, renderWindow.Height, 0.0f, 1.0f); // Ensure that the dome depth/stencil buffer matches our requirements if (domeZbuffer != null) { if (domeZbuffer.Width != ViewWidth || domeZbuffer.Height != renderWindow.Height) { domeZbuffer.Dispose(); GC.SuppressFinalize(domeZbuffer); domeZbuffer = null; } } if (leftEye != null) { if (leftEye.RenderTexture.Height != renderWindow.Height || leftEye.RenderTexture.Width != ViewWidth) { leftEye.Dispose(); GC.SuppressFinalize(leftEye); leftEye = null; } } if (rightEye != null) { if (rightEye.RenderTexture.Height != renderWindow.Height || rightEye.RenderTexture.Width != ViewWidth) { rightEye.Dispose(); GC.SuppressFinalize(rightEye); rightEye = null; } } if (stereoRenderTexture != null) { if (stereoRenderTexture.RenderTexture.Height != renderWindow.Height || stereoRenderTexture.RenderTexture.Width != ViewWidth) { stereoRenderTexture.Dispose(); GC.SuppressFinalize(stereoRenderTexture); stereoRenderTexture = null; } } if (domeZbuffer == null) { domeZbuffer = new DepthBuffer(ViewWidth, renderWindow.Height); } if (leftEye == null) { leftEye = new RenderTargetTexture(ViewWidth, renderWindow.Height, 1); } if (rightEye == null) { rightEye = new RenderTargetTexture(ViewWidth, renderWindow.Height, 1); } if (RenderContext11.MultiSampleCount > 1) { // When multisample anti-aliasing is enabled, render to an offscreen buffer and then // resolve to the left and then the right eye textures. if (stereoRenderTexture == null) { stereoRenderTexture = new RenderTargetTexture(ViewWidth, renderWindow.Height); } RenderFrame(stereoRenderTexture, domeZbuffer, RenderTypes.LeftEye); RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(stereoRenderTexture.RenderTexture.Texture, 0, leftEye.RenderTexture.Texture, 0, RenderContext11.DefaultColorFormat); RenderFrame(stereoRenderTexture, domeZbuffer, RenderTypes.RightEye); RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(stereoRenderTexture.RenderTexture.Texture, 0, rightEye.RenderTexture.Texture, 0, RenderContext11.DefaultColorFormat); } else { // When anti-aliasing is not enabled, render directly to the left and right eye textures. RenderFrame(leftEye, domeZbuffer, RenderTypes.LeftEye); RenderFrame(rightEye, domeZbuffer, RenderTypes.RightEye); } if (StereoMode == StereoModes.InterlineEven || StereoMode == StereoModes.InterlineOdd) { RenderSteroPairInterline(leftEye, rightEye); } else if (StereoMode == StereoModes.AnaglyphMagentaGreen || StereoMode == StereoModes.AnaglyphRedCyan || StereoMode == StereoModes.AnaglyphYellowBlue) { RenderSteroPairAnaglyph(leftEye, rightEye); } else if (StereoMode == StereoModes.OculusRift) { RenderSteroOculurRift(leftEye, rightEye); } else { if (StereoMode == StereoModes.CrossEyed) { RenderSteroPairSideBySide(rightEye, leftEye); } else { RenderSteroPairSideBySide(leftEye, rightEye); } } } else if (Settings.DomeView) { int cubeFaceSize = 512; if (usingLargeTextures) { cubeFaceSize = 1024; } if (CaptureVideo && dumpFrameParams.Dome) { cubeFaceSize = 2048; } if (usingLargeTextures != Properties.Settings.Default.LargeDomeTextures) { refreshDomeTextures = true; } if (currentCubeFaceSize != cubeFaceSize) { refreshDomeTextures = true; } if (refreshDomeTextures) { usingLargeTextures = Properties.Settings.Default.LargeDomeTextures; for (int face = 0; face < 5; face++) { if (domeCube[face] != null) { domeCube[face].Dispose(); GC.SuppressFinalize(domeCube[face]); domeCube[face] = null; } } if (domeZbuffer != null) { domeZbuffer.Dispose(); GC.SuppressFinalize(domeZbuffer); domeZbuffer = null; } if (domeCubeFaceMultisampled != null) { domeCubeFaceMultisampled.Dispose(); GC.SuppressFinalize(domeCubeFaceMultisampled); domeCubeFaceMultisampled = null; } } // Ensure that the dome depth/stencil buffer matches our requirements if (domeZbuffer != null) { if (domeZbuffer.Width != cubeFaceSize || domeZbuffer.Height != cubeFaceSize) { domeZbuffer.Dispose(); GC.SuppressFinalize(domeZbuffer); domeZbuffer = null; } } if (domeZbuffer == null) { domeZbuffer = new DepthBuffer(cubeFaceSize, cubeFaceSize); } if (domeCubeFaceMultisampled == null && RenderContext11.MultiSampleCount > 1) { domeCubeFaceMultisampled = new RenderTargetTexture(cubeFaceSize, cubeFaceSize); } for (int face = 0; face < 5; face++) { if (domeCube[face] == null) { domeCube[face] = new RenderTargetTexture(cubeFaceSize, cubeFaceSize, 1); currentCubeFaceSize = cubeFaceSize; refreshDomeTextures = false; } if (RenderContext11.MultiSampleCount > 1) { // When MSAA is enabled, we render each face to the same multisampled render target, // then resolve to a different texture for each face. This saves memory and works around // the fact that multisample textures are not permitted to have mipmaps. RenderFrame(domeCubeFaceMultisampled, domeZbuffer, (RenderTypes)face); RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(domeCubeFaceMultisampled.RenderTexture.Texture, 0, domeCube[face].RenderTexture.Texture, 0, RenderContext11.DefaultColorFormat); } else { RenderFrame(domeCube[face], domeZbuffer, (RenderTypes)face); } RenderContext11.PrepDevice.ImmediateContext.GenerateMips(domeCube[face].RenderTexture.ResourceView); } if (Properties.Settings.Default.DomeTypeIndex > 0) { RenderWarpedFisheye(); } else { if (CaptureVideo && dumpFrameParams.Dome) { if (!dumpFrameParams.WaitDownload || TileCache.QueuePercent == 100) { RenderDomeMaster(); } } RenderFisheye(false); } } else if (config.UseDistrotionAndBlend) { if (undistorted == null) { undistorted = new RenderTargetTexture(config.Width, config.Height); } // Ensure that the dome depth/stencil buffer matches our requirements if (domeZbuffer != null) { if (domeZbuffer.Width != config.Width || domeZbuffer.Height != config.Height) { domeZbuffer.Dispose(); GC.SuppressFinalize(domeZbuffer); domeZbuffer = null; } } if (domeZbuffer == null) { domeZbuffer = new DepthBuffer(config.Width, config.Height); } // * If there's no multisampling, draw directly into the undistorted texture // * When multisampling is on, draw into an intermediate buffer, then resolve // it into the undistorted texture RenderFrame(undistorted, domeZbuffer, RenderTypes.Normal); RenderDistort(); } else if (Properties.Settings.Default.FlatScreenWarp) { if (undistorted == null) { undistorted = new RenderTargetTexture(ViewWidth, renderWindow.ClientRectangle.Height); } if (domeZbuffer != null) { if (domeZbuffer.Width != ViewWidth || domeZbuffer.Height != renderWindow.ClientRectangle.Height) { domeZbuffer.Dispose(); GC.SuppressFinalize(domeZbuffer); domeZbuffer = null; } } if (domeZbuffer == null) { domeZbuffer = new DepthBuffer(ViewWidth, renderWindow.ClientRectangle.Height); } RenderFrame(undistorted, domeZbuffer, RenderTypes.Normal); RenderFlatDistort(); } else { if (renderWindow.ClientSize.Height != RenderContext11.DisplayViewport.Height || renderWindow.ClientSize.Width != RenderContext11.DisplayViewport.Width) { RenderContext11.Resize(renderWindow); } RenderFrame(null, null, RenderTypes.Normal); } UpdateStats(); lastRender = HiResTimer.TickCount; if (CaptureVideo) { if (!dumpFrameParams.WaitDownload || TileCache.QueuePercent == 100) { if (!dumpFrameParams.Dome) { Int64 ticksa = HiResTimer.TickCount; SaveFrame(); } SpaceTimeController.NextFrame(); } if (SpaceTimeController.DoneDumping()) { SpaceTimeController.CancelFrameDump = false; DomeFrameDumping(); } } if (Tile.fastLoadAutoReset) { Tile.fastLoad = false; Tile.fastLoadAutoReset = false; } }
public void SetOffscreenRenderTargets(RenderTargetTexture targetTexture, DepthBuffer depthBuffer) { currentTargetView = targetTexture.renderView; if (depthBuffer != null) { currentDepthView = depthBuffer.DepthView; } else { currentDepthView = null; } devContext.OutputMerger.ResetTargets(); ViewPort = new Viewport(0, 0, targetTexture.Width, targetTexture.Height, 0.0f, 1.0f); if (depthBuffer != null) { devContext.OutputMerger.SetTargets(depthBuffer.DepthView, targetTexture.renderView); } else { devContext.OutputMerger.SetTargets(targetTexture.renderView); } }
public void setDepthBuffer(DepthBuffer db) { this.db = db; }
public void CaptureMegaShot(string filename, int width, int height) { megaHeight = height; megaWidth = width; megaFrameDump = true; RenderTargetTexture megaTextureAA = new RenderTargetTexture(width, height); RenderTargetTexture megaTexture = new RenderTargetTexture(width, height, 1); DepthBuffer megaZbuffer = new DepthBuffer(width, height); while (true) { if (RenderContext11.MultiSampleCount > 1) { // When MSAA is enabled, we render each face to the same multisampled render target, // then resolve to a different texture for each face. This saves memory and works around // the fact that multisample textures are not permitted to have mipmaps. RenderFrame(megaTextureAA.renderView, megaZbuffer.DepthView, RenderTypes.Normal, width, height); RenderContext11.PrepDevice.ImmediateContext.ResolveSubresource(megaTextureAA.RenderTexture.Texture, 0, megaTexture.RenderTexture.Texture, 0, RenderContext11.DefaultColorFormat); } else { RenderFrame(megaTexture.renderView, megaZbuffer.DepthView, RenderTypes.Normal, width, height); } if (TileCache.QueuePercent == 100) { break; } Application.DoEvents(); } SharpDX.Direct3D11.Texture2D.ToFile(RenderContext11.devContext, megaTexture.RenderTexture.Texture, SharpDX.Direct3D11.ImageFileFormat.Png, filename); megaFrameDump = false; megaTexture.Dispose(); megaTextureAA.Dispose(); megaZbuffer.Dispose(); }
public void render() { //Begin Rendering GraphicsContext graphics = getGraphicsContext(); //Load Textures as Needed lock(this.texturesToLoad) { foreach(LoadableTexture lt in new List<LoadableTexture>(this.texturesToLoad)) { lock(lt) {try { Game.GAME_INSTANCE.getLogger().log ("Loading Texture " + lt.getTextureName()); this.texturesToLoad.Remove(lt); if(lt.isLoaded()) continue; Texture2D texture; if(lt.getTextureName() != null) { texture = new Texture2D(lt.getTextureName(), false); } else { texture = new Texture2D(lt.getWidth(), lt.getHeight(), false, PixelFormat.Rgba, PixelBufferOption.Renderable); } if(lt.getImage() != null) { texture.SetPixels(0, lt.getImage().ToBuffer(), 0, 0, lt.getWidth(), lt.getHeight()); } lt.setTexture(texture); Game.GAME_INSTANCE.getLogger().log ("...Done loading " + lt.getTextureName()); } catch(Exception e) {Game.GAME_INSTANCE.getLogger().log ("Failed to load Texture..");}} } } //Generate Depth Buffer Objects as Needed lock(this.depthBuffersToMake) { foreach(ThreadSafeDepthBuffer dsfb in new List<ThreadSafeDepthBuffer>(this.depthBuffersToMake)) { if(dsfb == null) continue; if(dsfb.getDepthBuffer() != null) continue; DepthBuffer db = new DepthBuffer(dsfb.getWidth(), dsfb.getHeight(), PixelFormat.Depth16); dsfb.setDepthBuffer(db); this.depthBuffersToMake.Remove(dsfb); } } //Generate Frame Buffer Objects as Needed lock(this.frameBuffersToMake) { foreach(ThreadSafeFrameBuffer tsfb in new List<ThreadSafeFrameBuffer>(this.frameBuffersToMake)) { if(tsfb == null) continue; if(tsfb.getFrameBuffer() != null) continue; FrameBuffer fb = new FrameBuffer(); tsfb.setFrameBuffer(fb); if(tsfb.getLoadableTexture() != null && tsfb.getLoadableTexture().isLoaded()) { fb.SetColorTarget(tsfb.getLoadableTexture().getTexture(), 0); } if(tsfb.getThreadSafeDepthBuffer() != null && tsfb.getThreadSafeDepthBuffer().getDepthBuffer() != null) { fb.SetDepthTarget(tsfb.getThreadSafeDepthBuffer().getDepthBuffer()); } this.frameBuffersToMake.Remove(tsfb); } } //Put Things on VBO as needed lock(this.vboWaitingList) { foreach(Model m in new List<Model>(this.vboWaitingList)) { Game.GAME_INSTANCE.getLogger().log ("Putting " + m.GetType() + "(" + m.getName() + ") on the VBO"); m.putOnVBO(); this.vboWaitingList.Remove(m); } } lock(this.getCamera()) { List<Model> models = this.getModels(); try { models.Sort( delegate(Model p1, Model p2) { if(p1 == null || p2 == null) return 0; lock(p1) { lock(p2) { Location p1Abs = p1.getLocation().getAbsoluteLocation(); Location p2Abs = p2.getLocation().getAbsoluteLocation(); double p1Dist = getCamera().getLocation().getDistance(p1Abs); double p2Dist = getCamera().getLocation().getDistance(p2Abs); return p1Dist.CompareTo(p2Dist); } } } ); } catch(Exception e) {} //Render Objects if(Scene.getActiveScene() != null) { try { lock(Scene.getActiveScene()) { Scene.getActiveScene().onRender(); } } catch(Exception e) {} } renderToBuffer(models, getCamera()); //Add Custom Models as Needed if(Game.GAME_INSTANCE.getDebugMode()) { FontModel fps = new FontModel("FPS: " + this.getCamera().getFrameRate()); fps.render(getCamera()); fps.getTexture().Dispose(); fps.getVBO().Dispose(); fps.Dispose(); } } graphics.SwapBuffers (); System.GC.Collect(); }
private short[] extractDepthImage(NuiLockedRect lockedRect) { DepthBuffer db = (DepthBuffer)Marshal.PtrToStructure(lockedRect.pBits, typeof(DepthBuffer)); return(db.pixels); }
/// <summary> /// Simple XOr Hashcode /// </summary> /// <returns>a semi reliable hash code</returns> public override int GetHashCode() { return(RenderedTexture.GetHashCode() ^ FrameBuffer.GetHashCode() ^ DepthBuffer.GetHashCode()); }
public RenderTarget(int width, int height) { ColorBuffer = new ColorBuffer(width, height); DepthBuffer = new DepthBuffer(width, height); }