public void Dispose() { GC.SuppressFinalize(this); if (frontBuffer != null) { frontBuffer.Dispose(); frontBuffer = null; } if (FrameBuffer != null) { FrameBuffer.Dispose(); FrameBuffer = null; } if (Rasterizer != null) { Rasterizer.Dispose(); Rasterizer = null; } if (ShaderData != null) { ShaderData.Dispose(); ShaderData = null; } if (ShaderMgr != null) { ShaderMgr.Dispose(); ShaderMgr = null; } Shader = null; UsingSubShader = null; UsingPass = null; }
public Buffer_Stencil StencilBuffer; // optional public _Attachment(FrameBuffer fbo, bool createDefaultBuff = true) { this.fbo = fbo; if (createDefaultBuff) { // required ColorBuffer = new Buffer_Color[MAX_COLOR_BUFF]; ColorBuffer[0] = new Buffer_Color(fbo.W, fbo.H); // required DepthBuffer = new Buffer_Depth(fbo.W, fbo.H); } }
public Buffer_Color SwapBuffer() { #if DOUBLE_BUFF if (bufferDirty) { bufferDirty = false; var t = FrameBuffer.Attachment.ColorBuffer[0]; FrameBuffer.Attachment.ColorBuffer[0] = frontBuffer; frontBuffer = t; } return(frontBuffer); #else return(FrameBuffer.Attachment.ColorBuffer[0]); #endif }
public void Set(Bitmap bmp) { Width = bmp.Width; Height = bmp.Height; ColorBuffer = new Buffer_Color(Width, Height); var bmd = bmp.LockBits(new Rectangle(0, 0, Width, Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); var ptr = bmd.Scan0; for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { var offset = (x + y * Width) * 4; var b = Marshal.ReadByte(ptr, offset) / 255f; var g = Marshal.ReadByte(ptr, offset + 1) / 255f; var r = Marshal.ReadByte(ptr, offset + 2) / 255f; var a = Marshal.ReadByte(ptr, offset + 3) / 255f; ColorBuffer[x, y] = Vector4.Get(r, g, b, a); } } bmp.UnlockBits(bmd); }
} // 当前输出的画布的像素单精度浮点数个数 public Renderer(int bufferW = 512, int bufferH = 512, PixelFormat outPixelFormat = PixelFormat.Format24bppRgb) { this.BackBufferWidth = bufferW; this.BackBufferHeight = bufferH; this.OutPxielFormat = outPixelFormat; this.OutPixelFormatSize = GetDevicePixelSize(outPixelFormat); this.defaultFrameBuffer = new FrameBuffer(bufferW, bufferH); this.FrameBuffer = this.defaultFrameBuffer; // using default buffer this.frontBuffer = new Buffer_Color(bufferW, bufferH); State = new RendererState(this); GlobalState = new GlobalRenderSstate(); Rasterizer = new Rasterizer(this); ShaderData = new ShaderData(1); ShaderMgr = new ShaderLoadMgr(this); if (Instance == null) { Instance = this; } }
private void FullScreenBlurHandle() { if (!GlobalState.fullscreen_blur) { return; } var w = BackBufferWidth; var h = BackBufferHeight; var backbuffer = FrameBuffer.Attachment.ColorBuffer[0]; if (blur_src_buffer == null || blur_src_buffer.Len != w * h) { blur_src_buffer = new Buffer_Color(w, h); } backbuffer.CopyTo(blur_src_buffer); var sampleOffset = new int[] { //x, y // 1 -1, 0, 1, 0, 0, 1, 0, -1, -1, -1, 1, -1, -1, 1, 1, 1, }; var sampleCount = sampleOffset.Length; var half_sampleCount = sampleCount / 2; var maxOX = w - 1; var maxOY = h - 1; var resampleCount = GlobalState.fullscreen_blur_resample_count; for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { var srcPosColor = backbuffer.Get(x, y); for (int rs = 0; rs < resampleCount; rs++) { for (int i = 0; i < sampleCount; i += 2) { var ox = sampleOffset[i] * (rs + 1) + x; var oy = sampleOffset[i + 1] * (rs + 1) + y; if (ox < 0) { ox = 0; } if (ox > maxOX) { ox = maxOX; } if (oy < 0) { oy = 0; } if (oy > maxOY) { oy = maxOY; } srcPosColor += blur_src_buffer[ox, oy]; } } srcPosColor /= half_sampleCount * resampleCount + 1; FrameBuffer.WriteColor(0, x, y, srcPosColor, ColorMask.RGBA); } } }
private void MSAAHandle() { var w = BackBufferWidth; var h = BackBufferHeight; var backbuffer = FrameBuffer.Attachment.ColorBuffer[0]; if (AA_src_buffer == null || AA_src_buffer.Len != w * h) { AA_src_buffer = new Buffer_Color(w, h); } backbuffer.CopyTo(AA_src_buffer); var sampleOffset = new int[] { //x, y // 1 -1, 0, 1, 0, //0,1, //0,-1, //-1, -1, //1, -1, //-1, 1, //1, 1, }; var sampleCount = sampleOffset.Length; var half_sampleCount = sampleCount / 2; var maxOX = w - 1; var maxOY = h - 1; var resampleCount = GlobalState.aa_resample_count; for (int i = 0; i < AA_edge_count; i += 2) { var x = AA_edgePosList[i]; var y = AA_edgePosList[i + 1]; var srcPosColor = backbuffer.Get(x, y); for (int rs = 0; rs < resampleCount; rs++) { for (int j = 0; j < sampleCount; j += 2) { var ox = sampleOffset[j] * (rs + 1) + x; var oy = sampleOffset[j + 1] * (rs + 1) + y; if (ox < 0) { ox = 0; } if (ox > maxOX) { ox = maxOX; } if (oy < 0) { oy = 0; } if (oy > maxOY) { oy = maxOY; } srcPosColor += AA_src_buffer[ox, oy]; } } srcPosColor /= half_sampleCount * resampleCount + 1; FrameBuffer.WriteColor(0, x, y, srcPosColor, ColorMask.RGBA); } }