private void PlatformGetData <T>(int level, Rectangle?rect, T[] data, int startIndex, int elementCount) where T : struct { Rectangle r; if (rect.HasValue) { r = rect.Value; } else { r = new Rectangle(0, 0, Width, Height); } int rWidth = r.Width; int rHeight = r.Height; var sz = 4; // Loop through and extract the data but we need to load it var dataRowColOffset = 0; var pixelOffset = 0; var result = new Color(0, 0, 0, 0); byte[] imageInfo = new byte[(rWidth * rHeight) * sz]; ImageRect old_scissor = GraphicsDevice.Context.GetScissor(); ImageRect old_viewport = GraphicsDevice.Context.GetViewport(); FrameBuffer old_frame_buffer = GraphicsDevice.Context.GetFrameBuffer(); ColorBuffer color_buffer = new ColorBuffer(rWidth, rHeight, PixelFormat.Rgba); FrameBuffer frame_buffer = new FrameBuffer(); frame_buffer.SetColorTarget(color_buffer); GraphicsDevice.Context.SetFrameBuffer(frame_buffer); GraphicsDevice.Context.SetTexture(0, this._texture2D); GraphicsDevice.Context.ReadPixels(imageInfo, PixelFormat.Rgba, 0, 0, rWidth, rHeight); GraphicsDevice.Context.SetFrameBuffer(old_frame_buffer); GraphicsDevice.Context.SetScissor(old_scissor); GraphicsDevice.Context.SetViewport(old_viewport); for (int y = r.Top; y < rHeight; y++) { for (int x = r.Left; x < rWidth; x++) { dataRowColOffset = ((y * r.Width) + x); pixelOffset = dataRowColOffset * sz; result.R = imageInfo[pixelOffset]; result.G = imageInfo[pixelOffset + 1]; result.B = imageInfo[pixelOffset + 2]; result.A = imageInfo[pixelOffset + 3]; data[dataRowColOffset] = (T)(object)result; } } }
public Color[] ReadColors() { var colors = new Color[ColorBuffer.count]; ColorBuffer.GetData(colors); return(colors); }
/// Simplified to be single-threaded and blocking private unsafe static void Bilinear( Color32[] texColors, int texWidth, int texHeight, Color32[] newColors, int newWidth, int newHeight) { // A single pass of bilinear filtering blends 4 pixels together, // so don't try to reduce by more than a factor of 2 per iteration Debug.Assert(newWidth * newHeight == newColors.Length); fixed(Color32 *pTex = texColors) { ColorBuffer cur = new ColorBuffer(texColors, pTex, texWidth, texHeight); while (true) { int tmpWidth = moveTowardsLog(cur.width, newWidth); int tmpHeight = moveTowardsLog(cur.height, newHeight); if (newColors.Length == tmpWidth * tmpHeight) { fixed(Color32 *pNew = newColors) { SinglePassBilinear(cur.array, cur.length, cur.width, cur.height, pNew, newColors.Length, newWidth, newHeight); } return; } ColorBuffer tmp = new ColorBuffer(tmpWidth, tmpHeight); SinglePassBilinear(cur.array, cur.length, cur.width, cur.height, tmp.array, tmp.length, tmp.width, tmp.height); cur.Deallocate(); cur = tmp; } } }
public virtual void OnFillColor(ColorBuffer buffer, RectInt fillRect, RectInt clearRect) { if (buffer != null && m_TargetTexture != null && buffer.IsVaild) { m_TargetTexture.LoadRawTextureData <Color32>(buffer.OriginArray); m_TargetTexture.Apply(); } /* * bool isTexChg = false; * if (m_Device != null && buffer != null && m_TargetTexture != null) { * if ((clearRect.width > 0) && (clearRect.height > 0)) { * for (int r = clearRect.yMin; r < clearRect.yMax; ++r) { * for (int c = clearRect.xMin; c < clearRect.xMax; ++c) { * m_TargetTexture.SetPixel(c, r, m_Device.ClearColor); * } * } * isTexChg = true; * } * * * if ((fillRect.width > 0) && (fillRect.height > 0)) { * for (int r = fillRect.yMin; r < fillRect.yMax; ++r) { * for (int c = fillRect.xMin; c < fillRect.xMax; ++c) { * m_TargetTexture.SetPixel(c, r, buffer.GetItem(c, r)); * } * } * isTexChg = true; * } * * if (isTexChg) * m_TargetTexture.Apply(); * }*/ }
public void ChangeKeyboard() { var colors = new ColorBuffer[] { Section1, Section2, Section3, Section4 }; KeyboardModel myKeyboardModel = new KeyboardModel { function = "SetEffectALL", mode = "Lighting", effect = "Single", light = Dim, speed = "0", direction = "None", nv_save = "NOT_SAVE", backgroundcolor = 1, alphabet = "", solution = 0, level = 0, powerstatus = 1, type = 0, color = new Color() { isCircular = true, ColorBlocks = colors.Count(), ColorBuffer = colors } }; mQTTDatsService.PublishTopic("Keyboard/Ctrl", myKeyboardModel); }
private void UpdateImage() { if (!_dirty) { return; } if (_colorBuffer == null || _colorBuffer.Width != Map.Width || _colorBuffer.Height != Map.Height) { _colorBuffer = new ColorBuffer(Map.Width, Map.Height); } // Bottom layer UpdateLayer(tile => !_secondLayerTiles.Contains(tile.Info.Id)); // Top layer UpdateLayer(tile => _secondLayerTiles.Contains(tile.Info.Id)); var texture = _colorBuffer.CreateTexture2D(MyraEnvironment.GraphicsDevice); _image = new TextureRegion(texture); _dirty = false; }
public override void OnLoad() { // Create resource asset resolver var assetResolver = new ResourceAssetResolver(GetType().Assembly, "Myra.Samples.Plugin.LibGDX.Resources."); // Load image containing font & ui spritesheet var colorBuffer = ColorBuffer.FromStream(assetResolver.Open("ui_stylesheet_image.png")); colorBuffer.PremultiplyAlpha(); var texture = colorBuffer.CreateTexture2D(); // Load ui text atlas var textureAtlas = TextureRegionAtlas.FromGDX(assetResolver.ReadAsString("ui_stylesheet_atlas.atlas"), s => texture); // Load ui font(s) var font = SpriteFontHelper.LoadFromFnt(assetResolver.ReadAsString("ui_font.fnt"), textureAtlas["default"]); // Load stylesheet var stylesheet = Stylesheet.CreateFromSource(assetResolver.ReadAsString("ui_stylesheet.json"), s => textureAtlas[s], s => font); Stylesheet.Current = stylesheet; }
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 void Dispose() { resolveFramebuffer?.Dispose(); Framebuffer?.Dispose(); ColorBuffer?.Dispose(); DepthBuffer?.Dispose(); ResolvedTex?.Dispose(); }
public override void init() { c1 = pool.GetBuffer(); normal = Random.onUnitSphere; border = randomColor(.1f); position = 1.2f; speed = Random.value * 0.3f + 0.05f; }
public BufferPointer GetBufferRenderer(string bufferName, string varNameInShader) { if (bufferName == strPosition) { using (var buffer = new PositionBuffer(varNameInShader)) { buffer.Alloc(positions.Count); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < positions.Count; i++) { array[i] = positions[i]; } } return(buffer.GetBufferPtr()); } } else if (bufferName == strColor) { using (var buffer = new ColorBuffer(varNameInShader)) { buffer.Alloc(normals.Count); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < normals.Count; i++) { array[i] = normals[i]; } } return(buffer.GetBufferPtr()); } } else if (bufferName == strNormal) { using (var buffer = new NormalBuffer(varNameInShader)) { buffer.Alloc(normals.Count); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < normals.Count; i++) { array[i] = normals[i]; } } return(buffer.GetBufferPtr()); } } else { return(null); } }
public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == strPosition) { using (var buffer = new PositionBuffer(varNameInShader)) { buffer.Alloc(positions.Length); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < positions.Length; i++) { array[i] = positions[i]; } } return(buffer.GetBufferPtr() as PropertyBufferPtr); } } else if (bufferName == strColor) { using (var buffer = new ColorBuffer(varNameInShader)) { buffer.Alloc(colors.Length); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < colors.Length; i++) { array[i] = colors[i]; } } return(buffer.GetBufferPtr() as PropertyBufferPtr); } } else if (bufferName == strNormal) { using (var buffer = new NormalBuffer(varNameInShader)) { buffer.Alloc(normals.Length); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < normals.Length; i++) { array[i] = normals[i]; } } return(buffer.GetBufferPtr() as PropertyBufferPtr); } } else { return(null); } }
public GrahpicsBuffer(int width, int height) { Width = width; Height = height; ZBuffer = new float?[width, height]; CharacterBuffer = new CharacterBuffer(width, height); ColorBuffer = new ColorBuffer(width, height); }
private void button1_Click(object sender, EventArgs e) { colorDialog1.FullOpen = true; colorDialog1.ShowDialog(); var result = colorDialog1.Color; panel1.BackColor = result; Section1 = Section2 = Section3 = Section4 = new ColorBuffer(result.R, result.G, result.B); Thread.Sleep(200); ChangeKeyboard(); }
public ColorBuffer GetBuffer() { if (Pool.Count > 0) { ColorBuffer item = Pool[0]; Pool.Remove(item); return(item); } maxcount++; return(new ColorBuffer()); }
public void Dispose() { if (ColorBuffer != null) { ColorBuffer.Release(); } if (AlphaBuffer != null) { AlphaBuffer.Release(); } }
public int AddTextureBuffer() { var t = new ColorBuffer(); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, m_fboId); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0 + m_buffers.Count, TextureTarget.Texture2D, t.TextureId, 0); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); m_buffers.Add(t); Check(); return t.TextureId; }
public int AddTextureBuffer() { var t = new ColorBuffer(); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, m_fboId); GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0 + m_buffers.Count, TextureTarget.Texture2D, t.TextureId, 0); GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); m_buffers.Add(t); Check(); return(t.TextureId); }
public PropertyBufferPtr GetProperty(string bufferName, string varNameInShader) { if (bufferName == strPosition) { using (var positionBuffer = new PositionBuffer(varNameInShader)) { positionBuffer.Alloc(1); unsafe { var positionArray = (CubePosition *)positionBuffer.FirstElement(); positionArray[0] = this.position; } return(positionBuffer.GetBufferPtr() as PropertyBufferPtr); } } else if (bufferName == strColor) { using (var colorBuffer = new ColorBuffer(varNameInShader)) { colorBuffer.Alloc(1); unsafe { var colorArray = (CubeColor *)colorBuffer.FirstElement(); colorArray[0] = this.color; } return(colorBuffer.GetBufferPtr() as PropertyBufferPtr); } } else if (bufferName == strNormal) { using (var normalBuffer = new NormalBuffer(varNameInShader)) { normalBuffer.Alloc(1); unsafe { var normalArray = (CubeNormal *)normalBuffer.FirstElement(); normalArray[0] = this.normal; } return(normalBuffer.GetBufferPtr() as PropertyBufferPtr); } } else { return(null); } }
private static void ExtractColorImage(NuiLockedRect buf, ref Color32[] colorImage) { ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(buf.pBits, typeof(ColorBuffer)); int totalPixels = Constants.ImageWidth * Constants.ImageHeight; for (int pix = 0; pix < totalPixels; pix++) { int ind = totalPixels - pix - 1; colorImage[ind].r = cb.pixels[pix].r; colorImage[ind].g = cb.pixels[pix].g; colorImage[ind].b = cb.pixels[pix].b; colorImage[ind].a = 255; } }
private Color32[] extractColorImage(NuiImageBuffer buf) { int totalPixels = buf.m_Width * buf.m_Height; Color32[] colorBuf = colorImage; ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(buf.m_pBuffer, typeof(ColorBuffer)); for (int pix = 0; pix < totalPixels; pix++) { colorBuf[pix].r = cb.pixels[pix].r; colorBuf[pix].g = cb.pixels[pix].g; colorBuf[pix].b = cb.pixels[pix].b; } return(colorBuf); }
public void DrawPoint(Vector a, Color color) { var t = SpaceToNormalized(a); if (t.Z < -1 || t.Z > 1) { return; } var A = NormalizedToScreen(t); if (ShouldBeDrawn(A)) { ColorBuffer.SetPixel((int)Math.Ceiling(A.X), (int)Math.Ceiling(A.Y), color); } }
private Color32[] extractColorImage(NuiLockedRect buf) { int totalPixels = 640 * 480; Color32[] colorBuf = colorImage; ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(buf.pBits, typeof(ColorBuffer)); for (int pix = 0; pix < totalPixels; pix++) { colorBuf[pix].r = cb.pixels[pix].r; colorBuf[pix].g = cb.pixels[pix].g; colorBuf[pix].b = cb.pixels[pix].b; } return(colorBuf); }
public Objects.VertexBuffers.BufferRenderer GetColorBufferRenderer(string varNameInShader) { using (var buffer = new ColorBuffer(varNameInShader)) { buffer.Alloc(colors.Length); unsafe { var array = (GlyphColor *)buffer.FirstElement(); for (int i = 0; i < colors.Length; i++) { array[i] = colors[i]; } } return(buffer.GetRenderer()); } }
/// <summary> /// Called when [create render target and depth buffers]. /// </summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <returns></returns> protected override ShaderResourceViewProxy OnCreateBackBuffer(int width, int height) { if (swapChain == null || swapChain.IsDisposed) { swapChain = CreateSwapChain(surfacePtr); } else { swapChain.ResizeBuffers(swapChain.Description1.BufferCount, TargetWidth, TargetHeight, swapChain.Description.ModeDescription.Format, swapChain.Description.Flags); } var backBuffer = Collect(new ShaderResourceViewProxy(Device, Texture2D.FromSwapChain <Texture2D>(swapChain, 0))); var sampleDesc = swapChain.Description1.SampleDescription; ColorBuffer.CreateRenderTargetView(); d2dTarget = Collect(new D2DTargetProxy()); d2dTarget.Initialize(swapChain, DeviceContext2D); return(backBuffer); }
public CSharpGL.Objects.VertexBuffers.BufferRenderer GetColorBufferRenderer(string varNameInShader) { using (var buffer = new ColorBuffer(varNameInShader)) { vec3[] colors = this.model.colors; buffer.Alloc(colors.Length); unsafe { vec3 *header = (vec3 *)buffer.FirstElement(); for (int i = 0; i < colors.Length; i++) { header[i] = colors[i]; } } return(buffer.GetRenderer()); } }
protected void Dispose(bool disposing) { if (disposing) { PositionBuffer?.Dispose(); NormalBuffer?.Dispose(); TangentBuffer?.Dispose(); TexCoordBuffer?.Dispose(); TexCoord2Buffer?.Dispose(); ColorBuffer?.Dispose(); foreach (var indexTable in IndexTables) { indexTable.Dispose(); } } GL.DeleteVertexArray(VertexArrayID); }
public void Update(float[] vertices, uint[] indexes, float[] colors, float[] normals) { Bind(); ElementBuffer.Bind(); ElementBuffer.SetData(sizeof(uint) * indexes.Length, indexes); VertexBuffer.Bind(); VertexBuffer.SetData(sizeof(float) * vertices.Length, vertices); ColorBuffer.Bind(); ColorBuffer.SetData(sizeof(float) * colors.Length, colors); NormalBuffer.Bind(); NormalBuffer.SetData(sizeof(float) * normals.Length, normals); VertexCount = indexes.Length; Unbind(); }
//public static bool PollColor(IntPtr colorStreamHandle, ref byte[] videoBuffer, ref Color32[] colorImage) public static bool PollColor(IntPtr colorStreamHandle, ref Color32[] colorImage) { IntPtr imageFramePtr = IntPtr.Zero; bool newColor = false; int hr = KinectWrapper.NuiImageStreamGetNextFrame(colorStreamHandle, 0, ref imageFramePtr); if (hr == 0) { newColor = 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); ColorBuffer cb = (ColorBuffer)Marshal.PtrToStructure(lockedRectPtr.pBits, typeof(ColorBuffer)); int totalPixels = Constants.ColorImageWidth * Constants.ColorImageHeight; for (int pix = 0; pix < totalPixels; pix++) { int ind = pix; // totalPixels - pix - 1; colorImage[ind].r = cb.pixels[pix].r; colorImage[ind].g = cb.pixels[pix].g; colorImage[ind].b = cb.pixels[pix].b; colorImage[ind].a = 255; // videoBuffer[4 * ind] = cb.pixels[pix].b; // videoBuffer[4 * ind + 1] = cb.pixels[pix].g; // videoBuffer[4 * ind + 2] = cb.pixels[pix].r; // videoBuffer[4 * ind + 3] = 255; } frameTexture.UnlockRect(0); hr = KinectWrapper.NuiImageStreamReleaseFrame(colorStreamHandle, imageFramePtr); } return(newColor); }
CSharpGL.Objects.VertexBuffers.BufferPointer IConvert2BufferPointer.GetBufferRenderer(string bufferName, string varNameInShader) { if (bufferName == strposition) { using (var buffer = new PositionBuffer(bufferName)) { buffer.Alloc(this.positionList.Count); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < this.positionList.Count; i++) { array[i] = this.positionList[i]; } } return(buffer.GetRenderer()); } } else if (bufferName == strcolor) { using (var buffer = new ColorBuffer(bufferName)) { buffer.Alloc(this.colorList.Count); unsafe { var array = (vec3 *)buffer.FirstElement(); for (int i = 0; i < this.colorList.Count; i++) { array[i] = this.colorList[i]; } } return(buffer.GetRenderer()); } } throw new NotImplementedException(); }
// Polls for new color frame data public static bool PollColorFrame(ref ColorBuffer colorImage) { bool bNewFrame = false; IntPtr imagePtr = IntPtr.Zero; Int64 liFrameTime = 0; int hr = PollImageFrameData(FrameSource.TypeColor); if (hr == 0) { hr = GetNewColorFrameData(ref imagePtr, ref liFrameTime); if (hr == 0) { colorImage = (ColorBuffer)Marshal.PtrToStructure(imagePtr, typeof(ColorBuffer)); bNewFrame = true; } } return(bNewFrame); }
// Polls for new color frame data public static bool PollColorFrame(ref ColorBuffer colorImage) { bool bNewFrame = false; IntPtr imagePtr = IntPtr.Zero; Int64 liFrameTime = 0; int hr = PollImageFrameData(FrameSource.TypeColor); if (hr == 0) { hr = GetNewColorFrameData(ref imagePtr, ref liFrameTime); if(hr == 0) { colorImage = (ColorBuffer)Marshal.PtrToStructure(imagePtr, typeof(ColorBuffer)); bNewFrame = true; } } return bNewFrame; }
public void Add(string name, Texture2D texture, int tiles_x, int tiles_y) { int tile_width = (int)FMath.Round((float)texture.Width / (float)tiles_x); int tile_height = (int)FMath.Round((float)texture.Height / (float)tiles_y); tile_width /= ScaleDivisor; tile_height /= ScaleDivisor; tile_width = System.Math.Max(1, tile_width); tile_height = System.Math.Max(1, tile_height); ColorBuffer color_buffer = new ColorBuffer(tile_width, tile_height, PixelFormat.Rgba); FrameBuffer frame_buffer = new FrameBuffer(); frame_buffer.SetColorTarget(color_buffer); FrameBuffer old_frame_buffer = Director.Instance.GL.Context.GetFrameBuffer(); Director.Instance.GL.Context.SetFrameBuffer(frame_buffer); ShaderProgram.SetAttributeBinding(0, "iPosition"); ShaderProgram.SetAttributeBinding(1, "iUV"); texture.SetWrap(TextureWrapMode.ClampToEdge); texture.SetFilter(TextureFilterMode.Linear); Director.Instance.GL.Context.SetTexture(0, texture); Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer); Director.Instance.GL.Context.SetShaderProgram(ShaderProgram); ImageRect old_scissor = Director.Instance.GL.Context.GetScissor(); ImageRect old_viewport = Director.Instance.GL.Context.GetViewport(); Director.Instance.GL.Context.SetScissor(0, 0, tile_width, tile_height); Director.Instance.GL.Context.SetViewport(0, 0, tile_width, tile_height); Entry entry = new Entry(); entry.TilesX = tiles_x; entry.TilesY = tiles_y; entry.TileWidth = tile_width; entry.TileHeight = tile_height; entry.Data = new List<List<byte>>(); for (int i = 0; i < tiles_y * tiles_x; ++i) entry.Data.Add(new List<byte>()); Vector2 uv_step = new Vector2(1.0f, 1.0f) / new Vector2(tiles_x, tiles_y); for (int y = 0; y < tiles_y; y++) { for (int x = 0; x < tiles_x; x++) { float uv_x0 = uv_step.X * (x + 0); float uv_x1 = uv_step.X * (x + 1); float uv_y0 = uv_step.Y * (tiles_y - 1 - y + 0); float uv_y1 = uv_step.Y * (tiles_y - 1 - y + 1); VertexDataArray[0] = new VertexData() { position = new Vector2(-1.0f, -1.0f), uv = new Vector2(uv_x0, uv_y1) }; VertexDataArray[1] = new VertexData() { position = new Vector2(-1.0f, +1.0f), uv = new Vector2(uv_x0, uv_y0) }; VertexDataArray[2] = new VertexData() { position = new Vector2(+1.0f, +1.0f), uv = new Vector2(uv_x1, uv_y0) }; VertexDataArray[3] = new VertexData() { position = new Vector2(+1.0f, -1.0f), uv = new Vector2(uv_x1, uv_y1) }; VertexBuffer.SetIndices(IndexDataArray, 0, 0, 4); VertexBuffer.SetVertices(VertexDataArray, 0, 0, 4); Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer); Director.Instance.GL.Context.DrawArrays(DrawMode.TriangleFan, 0, 4); byte[] data = new byte[tile_width * tile_height * 4]; // DEBUG: fill with visible memory pattern //for (int i = 0; i< tile_width * tile_height * 4; ++i) //data[i] = (byte)(i % (tile_width / 4)); Director.Instance.GL.Context.ReadPixels(data, PixelFormat.Rgba, 0, 0, tile_width, tile_height); List<byte> output = entry.Data[tiles_x * y + x]; for (int i = 0; i < tile_width * tile_height * 4; ++i) output.Add(data[i]); } } Director.Instance.GL.Context.SetVertexBuffer(0, null); Director.Instance.GL.Context.SetShaderProgram(null); Director.Instance.GL.Context.SetFrameBuffer(old_frame_buffer); Director.Instance.GL.Context.SetScissor(old_scissor); Director.Instance.GL.Context.SetViewport(old_viewport); TileData[name] = entry; }
public void TestOffscreen(string name, Texture2D texture) { const int Width = 32; const int Height = 32; ImageRect old_scissor = Director.Instance.GL.Context.GetScissor(); ImageRect old_viewport = Director.Instance.GL.Context.GetViewport(); FrameBuffer old_frame_buffer = Director.Instance.GL.Context.GetFrameBuffer(); ColorBuffer color_buffer = new ColorBuffer(Width, Height, PixelFormat.Rgba); FrameBuffer frame_buffer = new FrameBuffer(); frame_buffer.SetColorTarget(color_buffer); System.Console.WriteLine("SetFrameBuffer(): enter"); Director.Instance.GL.Context.SetFrameBuffer(frame_buffer); System.Console.WriteLine("SetFrameBuffer(): exit"); ShaderProgram.SetAttributeBinding(0, "iPosition"); ShaderProgram.SetAttributeBinding(1, "iUV"); texture.SetWrap(TextureWrapMode.ClampToEdge); texture.SetFilter(TextureFilterMode.Linear); Director.Instance.GL.Context.SetTexture(0, texture); Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer); Director.Instance.GL.Context.SetShaderProgram(ShaderProgram); Director.Instance.GL.Context.SetScissor(0, 0, Width, Height); Director.Instance.GL.Context.SetViewport(0, 0, Width, Height); float uv_x0 = 0.0f; float uv_x1 = 1.0f; float uv_y0 = 0.0f; float uv_y1 = 1.0f; VertexDataArray[0] = new VertexData() { position = new Vector2(-1.0f, -1.0f), uv = new Vector2(uv_x0, uv_y1) }; VertexDataArray[1] = new VertexData() { position = new Vector2(-1.0f, +1.0f), uv = new Vector2(uv_x0, uv_y0) }; VertexDataArray[2] = new VertexData() { position = new Vector2(+1.0f, +1.0f), uv = new Vector2(uv_x1, uv_y0) }; VertexDataArray[3] = new VertexData() { position = new Vector2(+1.0f, -1.0f), uv = new Vector2(uv_x1, uv_y1) }; VertexBuffer.SetIndices(IndexDataArray, 0, 0, 4); VertexBuffer.SetVertices(VertexDataArray, 0, 0, 4); Director.Instance.GL.Context.SetVertexBuffer(0, VertexBuffer); Director.Instance.GL.Context.DrawArrays(DrawMode.TriangleFan, 0, 4); int count = Width * Height * 4; byte[] data = new byte[count]; System.Console.WriteLine("ReadPixels(): enter"); Director.Instance.GL.Context.ReadPixels(data, PixelFormat.Rgba, 0, 0, Width, Height); System.Console.WriteLine("ReadPixels(): exit"); int nonzero = 0; int nonclear = 0; for (int i = 0; i < count; ++i) { if (data[i] != 0) nonzero++; if (data[i] != 0xfe) nonclear++; System.Console.Write("{0} ", data[i]); if (i % Width == 0) System.Console.WriteLine(""); } System.Console.WriteLine(""); System.Console.WriteLine("nonzero: {0}, nonclear: {1}", nonzero, nonclear); Director.Instance.GL.Context.SetVertexBuffer(0, null); Director.Instance.GL.Context.SetShaderProgram(null); Director.Instance.GL.Context.SetFrameBuffer(old_frame_buffer); Director.Instance.GL.Context.SetScissor(old_scissor); Director.Instance.GL.Context.SetViewport(old_viewport); System.Console.WriteLine("SwapBuffers(): enter"); Director.Instance.GL.Context.SwapBuffers(); System.Console.WriteLine("SwapBuffers(): exit"); Thread.Sleep(250); }