private ClydeTexture GenTexture(GLHandle glHandle, Vector2i size, string?name, long memoryPressure = 0) { if (name != null) { ObjectLabelMaybe(ObjectLabelIdentifier.Texture, glHandle, name); } var(width, height) = size; var id = AllocRid(); var instance = new ClydeTexture(id, size, this); var loaded = new LoadedTexture { OpenGLObject = glHandle, Width = width, Height = height, Name = name, MemoryPressure = memoryPressure // TextureInstance = new WeakReference<ClydeTexture>(instance) }; _loadedTextures.Add(id, loaded); //GC.AddMemoryPressure(memoryPressure); return(instance); }
private unsafe void InitLighting() { LoadLightingShaders(); RegenerateLightingRenderTargets(); // Occlusion VAO. // Only handles positions, no other vertex data necessary. _occlusionVao = new GLHandle(GL.GenVertexArray()); GL.BindVertexArray(_occlusionVao.Handle); ObjectLabelMaybe(ObjectLabelIdentifier.VertexArray, _occlusionVao, nameof(_occlusionVao)); _occlusionVbo = new GLBuffer(this, BufferTarget.ArrayBuffer, BufferUsageHint.DynamicDraw, nameof(_occlusionVbo)); _occlusionEbo = new GLBuffer(this, BufferTarget.ElementArrayBuffer, BufferUsageHint.DynamicDraw, nameof(_occlusionEbo)); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(Vector3), IntPtr.Zero); GL.EnableVertexAttribArray(0); // FOV FBO. _fovRenderTarget = CreateRenderTarget((ShadowMapSize, 1), new RenderTargetFormatParameters(RenderTargetColorFormat.R32F, true), new TextureSampleParameters { WrapMode = TextureWrapMode.Repeat }, "FOV depth render target"); _fovDepthTextureObject = _fovRenderTarget.Texture; }
public RenderTarget(Vector2i size, ClydeTexture texture, OGLHandle objectHandle, Clyde clyde, ClydeHandle handle) { Size = size; Texture = texture; ObjectHandle = objectHandle; _clyde = clyde; Handle = handle; }
public RenderTarget(Vector2i size, ClydeTexture texture, OGLHandle objectHandle, Clyde clyde, ClydeHandle handle, OGLHandle stencilBuffer) { Size = size; Texture = texture; ObjectHandle = objectHandle; _clyde = clyde; Handle = handle; StencilBuffer = stencilBuffer; }
private void DeleteTexture(ClydeTexture texture) { if (!_loadedTextures.TryGetValue(texture.TextureId, out var loadedTexture)) { // Already deleted. return; } GL.DeleteTexture(loadedTexture.OpenGLObject.Handle); _loadedTextures.Remove(texture.TextureId); }
private void LoadStockTextures() { var white = new Image <Rgba32>(1, 1); white[0, 0] = Rgba32.White; _stockTextureWhite = (ClydeTexture)Texture.LoadFromImage(white); var blank = new Image <Rgba32>(1, 1); blank[0, 0] = Rgba32.Transparent; _stockTextureTransparent = (ClydeTexture)Texture.LoadFromImage(blank); }
private void LoadStockTextures() { var white = new Image <Rgba32>(1, 1); white[0, 0] = new Rgba32(255, 255, 255, 255); _stockTextureWhite = (ClydeTexture)Texture.LoadFromImage(white); var black = new Image <Rgba32>(1, 1); black[0, 0] = new Rgba32(0, 0, 0, 255); _stockTextureBlack = (ClydeTexture)Texture.LoadFromImage(black); var blank = new Image <Rgba32>(1, 1); blank[0, 0] = new Rgba32(0, 0, 0, 0); _stockTextureTransparent = (ClydeTexture)Texture.LoadFromImage(blank); }
private void CopyRenderTextureToTexture(RenderTexture source, ClydeTexture target) { LoadedRenderTarget sourceLoaded = RtToLoaded(source); bool pause = sourceLoaded != _currentBoundRenderTarget; FullStoredRendererState?store = null; if (pause) { store = PushRenderStateFull(); BindRenderTargetFull(source); CheckGlError(); } GL.BindTexture(TextureTarget.Texture2D, _loadedTextures[target.TextureId].OpenGLObject.Handle); CheckGlError(); GL.CopyTexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, 0, 0, source.Size.X, source.Size.Y); CheckGlError(); if (pause && store != null) { PopRenderStateFull((FullStoredRendererState)store); } }
public RenderTexture(Vector2i size, ClydeTexture texture, Clyde clyde, ClydeHandle handle) : base(clyde, handle) { Size = size; Texture = texture; }
private unsafe void InitLighting() { LoadLightingShaders(); RegenerateLightingRenderTargets(); // Occlusion VAO. // Only handles positions, no other vertex data necessary. _occlusionVao = new GLHandle(GL.GenVertexArray()); GL.BindVertexArray(_occlusionVao.Handle); ObjectLabelMaybe(ObjectLabelIdentifier.VertexArray, _occlusionVao, nameof(_occlusionVao)); _occlusionVbo = new GLBuffer(this, BufferTarget.ArrayBuffer, BufferUsageHint.DynamicDraw, nameof(_occlusionVbo)); _occlusionEbo = new GLBuffer(this, BufferTarget.ElementArrayBuffer, BufferUsageHint.DynamicDraw, nameof(_occlusionEbo)); GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, sizeof(Vector3), IntPtr.Zero); GL.EnableVertexAttribArray(0); // FOV FBO. _fovFbo = new GLHandle(GL.GenFramebuffer()); var boundDrawBuffer = GL.GetInteger(GetPName.DrawFramebufferBinding); var boundReadBuffer = GL.GetInteger(GetPName.ReadFramebufferBinding); GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fovFbo.Handle); _fovDepthTexture = new GLHandle(GL.GenTexture()); GL.BindTexture(TextureTarget.Texture2D, _fovDepthTexture.Handle); _fovDepthTextureObject = _genTexture(_fovDepthTexture, (ShadowMapSize, 1), "FOV depth texture"); GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.DepthComponent, ShadowMapSize, 1, 0, PixelFormat.DepthComponent, PixelType.Float, IntPtr.Zero); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)OGLTextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)OGLTextureWrapMode.Repeat); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest); GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest); GL.FramebufferTexture(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, _fovDepthTexture.Handle, 0); GL.DrawBuffer(DrawBufferMode.None); GL.ReadBuffer(ReadBufferMode.None); var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); DebugTools.Assert(status == FramebufferErrorCode.FramebufferComplete, $"new framebuffer has bad status {status}"); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, boundDrawBuffer); GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, boundReadBuffer); }