public FormatInfo(int bytesPerPixel, int blockWidth, int blockHeight, TargetBuffer targetBuffer) { BytesPerPixel = bytesPerPixel; BlockWidth = blockWidth; BlockHeight = blockHeight; TargetBuffer = targetBuffer; }
public ImageDescriptor(int BytesPerPixel, int BlockWidth, int BlockHeight, TargetBuffer Target) { this.BytesPerPixel = BytesPerPixel; this.BlockWidth = BlockWidth; this.BlockHeight = BlockHeight; this.Target = Target; }
public TextureFormatInfo(uint bytesPerPixel, uint blockWidth, uint blockHeight, TargetBuffer buffer) { BytesPerPixel = bytesPerPixel; BlockWidth = blockWidth; BlockHeight = blockHeight; Buffer = buffer; }
public ImageDescriptor(int bytesPerPixel, int blockWidth, int blockHeight, int blockDepth, TargetBuffer target) { BytesPerPixel = bytesPerPixel; BlockWidth = blockWidth; BlockHeight = blockHeight; BlockDepth = blockDepth; Target = target; }
public FormatInfo(uint bytesPerPixel, uint blockWidth, uint blockHeight, uint blockDepth, TargetBuffer targetBuffer) { BytesPerPixel = bytesPerPixel; BlockWidth = blockWidth; BlockHeight = blockHeight; BlockDepth = blockDepth; TargetBuffer = targetBuffer; }
/// <summary> /// Create a new connecting block. /// </summary> /// <param name="name">The name of the blocks.</param> /// <param name="namedId">The string ID of the block.</param> /// <param name="flags">The flags describing the block.</param> /// <param name="boundingBox">The block bounding box.</param> /// <param name="targetBuffer">The target rendering buffer.</param> protected ConnectingBlock(string name, string namedId, BlockFlags flags, BoundingBox boundingBox, TargetBuffer targetBuffer) : base( name, namedId, flags, boundingBox, targetBuffer) { }
/// <summary> /// Create a custom pass to execute a fullscreen pass /// </summary> /// <param name="fullScreenMaterial">The material to use for your fullscreen pass. It must have a shader based on the Custom Pass Fullscreen shader or equivalent</param> /// <param name="targetColorBuffer"></param> /// <param name="targetDepthBuffer"></param> /// <returns></returns> public static CustomPass CreateFullScreenPass(Material fullScreenMaterial, TargetBuffer targetColorBuffer = TargetBuffer.Camera, TargetBuffer targetDepthBuffer = TargetBuffer.Camera) { return(new FullScreenCustomPass() { name = "FullScreen Pass", targetColorBuffer = targetColorBuffer, targetDepthBuffer = targetDepthBuffer, fullscreenPassMaterial = fullScreenMaterial, }); }
private void ProcessNeighbor(Pixel targetPixel, Int32 x, Int32 y, Single factor, Int32 redError, Int32 greenError, Int32 blueError) { Color oldColor = TargetBuffer.ReadColorUsingPixelFrom(targetPixel, x, y); oldColor = QuantizationHelper.ConvertAlpha(oldColor); Int32 red = GetClampedColorElementWithError(oldColor.R, factor, redError); Int32 green = GetClampedColorElementWithError(oldColor.G, factor, greenError); Int32 blue = GetClampedColorElementWithError(oldColor.B, factor, blueError); Color newColor = Color.FromArgb(255, red, green, blue); TargetBuffer.WriteColorUsingPixelAt(targetPixel, x, y, newColor, Quantizer); }
private void Update(EvaluationContext context) { var resourceManager = ResourceManager.Instance(); var device = resourceManager.Device; var deviceContext = device.ImmediateContext; var targetBuffer = TargetBuffer.GetValue(context); var sourceBufferUav = SourceBuffer.GetValue(context); if (targetBuffer == null || sourceBufferUav == null) { return; } deviceContext.CopyStructureCount(targetBuffer, DstAlignedByteOffset.GetValue(context), sourceBufferUav); }
public void UnBindBuffer(TargetBuffer Target, int Number = 0) { switch (Target) { case TargetBuffer.Color: colorBuffers[Number].UnBind(); break; case TargetBuffer.Depth: depthBuffer.UnBind(); break; case TargetBuffer.Stencil: stencilBuffer.UnBind(); break; } }
/// <summary> /// See <see cref="BaseColorDitherer.OnProcessPixel"/> for more details. /// </summary> protected override Boolean OnProcessPixel(Pixel sourcePixel, Pixel targetPixel) { // only process dithering when reducing from truecolor to indexed if (!TargetBuffer.IsIndexed) { return(false); } // retrieves the colors Color sourceColor = SourceBuffer.GetColorFromPixel(sourcePixel); Color targetColor = TargetBuffer.GetColorFromPixel(targetPixel); // converts alpha to solid color sourceColor = QuantizationHelper.ConvertAlpha(sourceColor); // calculates the difference (error) Int32 redError = sourceColor.R - targetColor.R; Int32 greenError = sourceColor.G - targetColor.G; Int32 blueError = sourceColor.B - targetColor.B; // only propagate non-zero error if (redError != 0 || greenError != 0 || blueError != 0) { // processes the matrix for (Int32 shiftY = -MatrixSideHeight; shiftY <= MatrixSideHeight; shiftY++) { for (Int32 shiftX = -MatrixSideWidth; shiftX <= MatrixSideWidth; shiftX++) { Int32 targetX = sourcePixel.X + shiftX; Int32 targetY = sourcePixel.Y + shiftY; Byte coeficient = CachedMatrix[shiftY + MatrixSideHeight, shiftX + MatrixSideWidth]; Single coeficientSummed = CachedSummedMatrix[shiftY + MatrixSideHeight, shiftX + MatrixSideWidth]; if (coeficient != 0 && targetX >= 0 && targetX < TargetBuffer.Width && targetY >= 0 && targetY < TargetBuffer.Height) { ProcessNeighbor(targetPixel, targetX, targetY, coeficientSummed, redError, greenError, blueError); } } } } // pixels are not processed, only neighbors are return(false); }
/// <summary> /// Create a Custom Pass to render objects /// </summary> /// <param name="queue">The render queue filter to select which object will be rendered</param> /// <param name="mask">The layer mask to select which layer(s) will be rendered</param> /// <param name="overrideMaterial">The replacement material to use when renering objects</param> /// <param name="overrideMaterialPassIndex">The pass to use in the override material</param> /// <param name="sorting">Sorting options when rendering objects</param> /// <param name="clearFlags">Clear options when the target buffers are bound. Before executing the pass</param> /// <param name="targetColorBuffer">Target Color buffer</param> /// <param name="targetDepthBuffer">Target Depth buffer. Note: It's also the buffer which will do the Depth Test</param> /// <returns></returns> public static CustomPass CreateDrawRenderersPass(RenderQueueType queue, LayerMask mask, Material overrideMaterial, int overrideMaterialPassIndex = 0, SortingCriteria sorting = SortingCriteria.CommonOpaque, ClearFlag clearFlags = ClearFlag.None, TargetBuffer targetColorBuffer = TargetBuffer.Camera, TargetBuffer targetDepthBuffer = TargetBuffer.Camera) { return(new DrawRenderersCustomPass() { name = "DrawRenderers Pass", renderQueueType = queue, layerMask = mask, overrideMaterial = overrideMaterial, overrideMaterialPassIndex = overrideMaterialPassIndex, sortingCriteria = sorting, clearFlags = clearFlags, targetColorBuffer = targetColorBuffer, targetDepthBuffer = targetDepthBuffer, }); }
/// <summary> /// Create a new block. /// </summary> /// <param name="name">The name of the block. Can be localized.</param> /// <param name="namedId">The named ID of the block. A unique and unlocalized identifier.</param> /// <param name="flags">The block flags setting specific options.</param> /// <param name="boundingBox">The base bounding box for this block. Is used for placement checks.</param> /// <param name="targetBuffer">The target rendering buffer.</param> protected Block(string name, string namedId, BlockFlags flags, BoundingBox boundingBox, TargetBuffer targetBuffer) { Name = name; NamedId = namedId; IsFull = flags.IsFull; IsOpaque = flags.IsOpaque; RenderFaceAtNonOpaques = flags.RenderFaceAtNonOpaques; IsSolid = flags.IsSolid; ReceiveCollisions = flags.ReceiveCollisions; IsTrigger = flags.IsTrigger; IsReplaceable = flags.IsReplaceable; IsInteractable = flags.IsInteractable; this.boundingBox = boundingBox; TargetBuffer = targetBuffer; Debug.Assert( (TargetBuffer != TargetBuffer.Simple) ^ IsFull, $"TargetBuffer '{nameof(TargetBuffer.Simple)}' requires {nameof(IsFull)} to be {!IsFull}, all other target buffers cannot be full."); Debug.Assert(IsFull || !IsOpaque, "A block that is not full cannot be opaque."); #pragma warning disable S3060 // "is" should not be used with "this" Debug.Assert( TargetBuffer == TargetBuffer.VaryingHeight == this is IHeightVariable, $"The target buffer should be {nameof(TargetBuffer.VaryingHeight)} if and only if the block implements {nameof(IHeightVariable)}."); #pragma warning restore S3060 // "is" should not be used with "this" if (blockList.Count < BlockLimit) { blockList.Add(this); namedBlockDictionary.Add(namedId, this); Id = (uint) (blockList.Count - 1); } else { Debug.Fail($"Not more than {BlockLimit} blocks are allowed."); } }
public void SetRenderBuffer(TargetBuffer Target, RenderbufferStorage Format, int Width, int Height, int Number = 0) { RenderBuffer buffer = new RenderBuffer(Format, Width, Height); switch (Target) { case TargetBuffer.Color: if (colorBuffers.ContainsKey(Number)) { UnBind(); colorBuffers[Number].Dispose(); Bind(); } colorBuffers[Number] = buffer; GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, (FramebufferAttachment)((int)FramebufferAttachment.ColorAttachment0 + Number), RenderbufferTarget.Renderbuffer, buffer.handle); break; case TargetBuffer.Depth: if (depthBuffer != null) { UnBind(); depthBuffer.Dispose(); Bind(); } depthBuffer = buffer; GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, buffer.handle); break; case TargetBuffer.Stencil: if (stencilBuffer != null) { UnBind(); stencilBuffer.Dispose(); Bind(); } stencilBuffer = buffer; GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, RenderbufferTarget.Renderbuffer, buffer.handle); break; } }
public void SetTextureBuffer(TargetBuffer Target, PixelInternalFormat InternalFormat, PixelFormat Format, PixelType Type, int Width, int Height, int Number = 0) { TextureBuffer buffer = new TextureBuffer(InternalFormat, Format, Type, Width, Height); switch (Target) { case TargetBuffer.Color: if (colorBuffers.ContainsKey(Number)) { UnBind(); colorBuffers[Number].Dispose(); Bind(); } colorBuffers[Number] = buffer; GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, (FramebufferAttachment)((int)FramebufferAttachment.ColorAttachment0 + Number), TextureTarget.Texture2D, buffer.handle, 0); break; case TargetBuffer.Depth: if (depthBuffer != null) { UnBind(); depthBuffer.Dispose(); Bind(); } depthBuffer = buffer; GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, TextureTarget.Texture2D, buffer.handle, 0); break; case TargetBuffer.Stencil: if (stencilBuffer != null) { UnBind(); stencilBuffer.Dispose(); Bind(); } stencilBuffer = buffer; GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, TextureTarget.Texture2D, buffer.handle, 0); break; } }
public void Release() { Stream.Dispose(); TargetBuffer.ReleaseLock(this); }
/// <summary> /// Reads pixels from the render target buffer. /// </summary> /// <param name="targetBuffer">The render target buffer.</param> /// <returns>The read pixels as a bitmap.</returns> public static Bitmap Read(TargetBuffer targetBuffer = TargetBuffer.Color0) { gl.ReadBuffer(targetBuffer.ToBuffer()); var bitmap = new Bitmap(Width, Height, PixelFormat.Format32bppRgb); bitmap.PinAsWriteOnly(PixelFormat.Format32bppRgb, data => gl.ReadPixels(0, 0, Width, Height, GL.BGRA, GL.UNSIGNED_BYTE, data)); bitmap.RotateFlip(RotateFlipType.RotateNoneFlipY); return bitmap; }
/// <summary> /// Configures the drawn render target buffers. /// </summary> /// <param name="targetBuffer0">The render target buffer 0.</param> /// <param name="targetBuffer1">The render target buffer 1.</param> /// <param name="targetBuffer2">The render target buffer 2.</param> /// <param name="targetBuffer3">The render target buffer 3.</param> public static void Draw(TargetBuffer targetBuffer0, TargetBuffer targetBuffer1 = TargetBuffer.None, TargetBuffer targetBuffer2 = TargetBuffer.None, TargetBuffer targetBuffer3 = TargetBuffer.None) { gl.DrawBuffers(targetBuffer0.ToBuffer(), targetBuffer1.ToBuffer(), targetBuffer2.ToBuffer(), targetBuffer3.ToBuffer()); }