protected override void OnRendering(IHostScreen screen, ref FBO currentFbo) { currentFbo = _gBuffer.FBO; FBO.Bind(currentFbo, FBO.Target.FrameBuffer); ElffyGL.Clear(ClearMask.ColorBufferBit | ClearMask.DepthBufferBit); _gBuffer.ClearColorBuffers(); }
public RenderTexture(int width, int height, Filter filterMode = Filter.Linear, Wrapping wrapMode = Wrapping.Repeat, string path = "") : base(path, false) { fbo = new FBO(); fbo.Bind(); Handle = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, Handle); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, width, height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero); depthStencil = GL.GenTexture(); GL.BindTexture(TextureTarget.Texture2D, depthStencil); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Depth24Stencil8, width, height, 0, PixelFormat.DepthStencil, PixelType.UnsignedInt248, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.ClampToBorder); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.ClampToBorder); var metaData = LoadMetaData(); SetFilter(metaData.Count >= 1 ? (Filter)Convert.ToInt32(metaData[0].value) : filterMode, false); SetWrapping(metaData.Count >= 2 ? (Wrapping)Convert.ToInt32(metaData[1].value) : wrapMode); fbo.AttachTexture(Handle); fbo.AttachDepthStencilTexture(depthStencil); if (GL.Ext.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) { Logging.LogWarning(this, "Framebuffer is not complete!"); } fbo.Unbind(); }
static (IHostScreen Screen, FBO Fbo, TextureObject DepthTex, Vector2i Size) Create(int width, int height) { var screen = Engine.GetValidCurrentContext(); var size = new Vector2i(width, height); var depth = TextureObject.Empty; var fbo = FBO.Empty; try { depth = TextureObject.Create(); TextureObject.Bind2D(depth); TextureObject.DepthImage2DUninitialized(size); TextureObject.Parameter2DMinFilter(TextureShrinkMode.NearestNeighbor, TextureMipmapMode.None); TextureObject.Parameter2DMagFilter(TextureExpansionMode.NearestNeighbor); TextureObject.Parameter2DWrapS(TextureWrapMode.ClampToBorder); TextureObject.Parameter2DWrapT(TextureWrapMode.ClampToBorder); fbo = FBO.Create(); FBO.Bind(fbo, FBO.Target.FrameBuffer); FBO.SetTexture2DBuffer(depth, FBO.Attachment.DepthAttachment); GL.DrawBuffer(DrawBufferMode.None); GL.ReadBuffer(ReadBufferMode.None); FBO.ThrowIfInvalidStatus(); FBO.Unbind(FBO.Target.FrameBuffer); return(Screen : screen, Fbo : fbo, DepthTex : depth, Size : size); } catch { TextureObject.Delete(ref depth); FBO.Delete(ref fbo); throw; } }
public void BindForWriting() { SaveViewport(); FBO.Bind(FramebufferTarget.DrawFramebuffer); GL.Viewport(0, 0, Width, Height); SetDrawBuffers(); if (WantDepth) { GL.Enable(EnableCap.DepthTest); GL.DepthMask(true); } }
/// <summary> /// Bind GBuffer for writing to the supplied textures /// </summary> /// <param name="outputTextures"></param> public void BindForWritingTo(params TextureSlot[] outputTextures) { // shouldn't call this if we've got any texture slots defined. SaveViewport(); FBO.Bind(FramebufferTarget.DrawFramebuffer); GL.Viewport(0, 0, Width, Height); for (int i = 0; i < outputTextures.Length; i++) { outputTextures[i].AttachToFramebuffer(FBO.Target); } GL.DrawBuffers(outputTextures.Length, outputTextures.Select(t => t.DrawBufferSlot).ToArray()); }
protected override void OnRendered(IHostScreen screen, ref FBO currentFbo) { var targetFbo = FBO.Empty; var gBuffer = _gBuffer; var screenSize = screen.FrameBufferSize; var gBufSize = gBuffer.Size; Debug.Assert(_postProcess is not null); Debug.Assert(_ppProgram is not null); FBO.Bind(targetFbo, FBO.Target.FrameBuffer); if (IsVisible) { _ppProgram.Render(screenSize, (Vector2)screenSize / (Vector2)gBufSize); } currentFbo = targetFbo; }
public void Load() { LogTrace($"Creating G-Buffer of size {Width}x{Height}"); FBO.Load(); FBO.Bind(); UnloadAndDestroyAllTextures(); InitAllTextures(); if (WantDepth) { InitAndAttachDepthTexture(); } SetDrawBuffers(); var status = FBO.GetStatus(); LogTrace($"FBO state is {FBO.Status}"); FBO.Unbind(); }
public void RenderFrame() { // ------------------------------------------------------------ // Out of frame loop Debug.Assert(_currentTiming == CurrentFrameTiming.OutOfFrameLoop); var isCloseRequested = _isCloseRequested; var layers = Layers; var frameTimingPoints = TimingPoints; Mouse.InitFrame(); Keyboard.InitFrame(); // ------------------------------------------------------------ // First Frame initializing if (_state == RenderingAreaLifeState.Activating) { _currentTiming = CurrentFrameTiming.FirstFrameInitializing; try { Initialized?.Invoke(OwnerScreen); } catch { if (EngineSetting.UserCodeExceptionCatchMode == UserCodeExceptionCatchMode.Throw) { throw; } // Don't throw. (Ignore exceptions in user code) } finally { _state = RenderingAreaLifeState.Alive; } } // ------------------------------------------------------------ // Frame initializing _currentTiming = CurrentFrameTiming.FrameInitializing; if (isCloseRequested && _state == RenderingAreaLifeState.Alive) { _state = RenderingAreaLifeState.Terminating; _runningTokenSource.Cancel(); layers.TerminateAllLayers(this, onDead: static self => { self._state = RenderingAreaLifeState.Dead; }); } layers.ApplyAdd(); frameTimingPoints.FrameInitializing.DoQueuedEvents(); // ------------------------------------------------------------ // Early update _currentTiming = CurrentFrameTiming.EarlyUpdate; frameTimingPoints.EarlyUpdate.DoQueuedEvents(); layers.EarlyUpdate(); // ------------------------------------------------------------ // Update _currentTiming = CurrentFrameTiming.Update; frameTimingPoints.Update.DoQueuedEvents(); layers.Update(); // ------------------------------------------------------------ // Late update _currentTiming = CurrentFrameTiming.LateUpdate; frameTimingPoints.LateUpdate.DoQueuedEvents(); layers.LateUpdate(); // ------------------------------------------------------------ // Before rendering _currentTiming = CurrentFrameTiming.BeforeRendering; FBO.Bind(FBO.Empty, FBO.Target.FrameBuffer); ElffyGL.Clear(ClearMask.ColorBufferBit | ClearMask.DepthBufferBit); frameTimingPoints.BeforeRendering.DoQueuedEvents(); // ------------------------------------------------------------ // Rendering _currentTiming = CurrentFrameTiming.Rendering; layers.Render(); // ------------------------------------------------------------ // After rendering _currentTiming = CurrentFrameTiming.AfterRendering; frameTimingPoints.AfterRendering.DoQueuedEvents(); // ------------------------------------------------------------ // Frame finalizing _currentTiming = CurrentFrameTiming.FrameFinalizing; layers.ApplyRemove(); // ------------------------------------------------------------ // End of frame (only internal accessible) _currentTiming = CurrentFrameTiming.Internal_EndOfFrame; frameTimingPoints.InternalEndOfFrame.DoQueuedEvents(); // ------------------------------------------------------------ // Out of frame loop _currentTiming = CurrentFrameTiming.OutOfFrameLoop; ContextAssociatedMemorySafety.CollectIfExist(OwnerScreen); if (_state == RenderingAreaLifeState.Dead) { Dispose(); } }
protected override void OnRenderFrame(FrameEventArgs e) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _frameBuffer.Bind();//TODO GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); //gt.updateTimer(); //Console.WriteLine(gt.renderPartialTicks); DateTime now = DateTime.Now; _partialTicks = (float)MathHelper.Clamp((now - _updateTimer).TotalSeconds / TargetUpdatePeriod, 0, 1); if (_ticked) { _ticked = false; //Console.WriteLine(_partialTicks); _partialTicks %= 1f; } if ((now - _lastFpsDate).TotalMilliseconds >= 1000) { _fpsCounterLast = _fpsCounter; _fpsCounter = 0; _lastFpsDate = now; } RunGlTasks(); HandleMouseMovement(); Camera.UpdateViewMatrix(); //RENDER SCREEN if (World != null) { SkyboxRenderer?.Render(_partialTicks); WorldRenderer?.Render(World, _partialTicks); ParticleRenderer?.Render(_partialTicks); EntityRenderer?.Render(_partialTicks); } //render other gui if (Player != null) { GuiRenderer?.RenderCrosshair(); GuiRenderer?.RenderHUD(); } //render gui screen if (GuiScreen != null) { CursorVisible = true; GuiRenderer?.Render(GuiScreen); } if (_takeScreenshot) { _takeScreenshot = false; CaptureScreen(); } _frameBuffer.BindDefault(); _frameBuffer.CopyToScreen();//TODO SwapBuffers(); _fpsCounter++; //_spinner.SpinOnce(); }
protected override void OnRendering(IHostScreen screen, ref FBO currentFbo) { FBO.Bind(FBO.Empty, FBO.Target.FrameBuffer); currentFbo = FBO.Empty; }
public void Bind() { fbo.Bind(); }