void INativeRenderTarget.GetData <T>(T[] buffer, ColorDataLayout dataLayout, ColorDataElementType dataElementType, int targetIndex, int x, int y, int width, int height) { DefaultOpenTKBackendPlugin.GuardSingleThreadState(); NativeRenderTarget lastRt = BoundRT; Bind(this); { GL.ReadBuffer((ReadBufferMode)((int)ReadBufferMode.ColorAttachment0 + targetIndex)); GL.ReadPixels(x, y, width, height, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), buffer); GL.ReadBuffer(ReadBufferMode.Back); } Bind(lastRt); }
void INativeTexture.GetData(IntPtr target, ColorDataLayout dataLayout, ColorDataElementType dataElementType) { DefaultOpenTKBackendPlugin.GuardSingleThreadState(); int lastTexId; GL.GetInteger(GetPName.TextureBinding2D, out lastTexId); GL.BindTexture(TextureTarget.Texture2D, this.handle); GL.GetTexImage(TextureTarget.Texture2D, 0, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), target); GL.BindTexture(TextureTarget.Texture2D, lastTexId); }
void INativeRenderTarget.GetData <T>(T[] buffer, ColorDataLayout dataLayout, ColorDataElementType dataElementType, int targetIndex, int x, int y, int width, int height) { DefaultOpenTKBackendPlugin.GuardSingleThreadState(); this.ApplyPostRender(); if (curBound != this) { ApplyGLBind(this); } { GL.Ext.BindFramebuffer(FramebufferTarget.ReadFramebuffer, this.handleMainFBO); GL.ReadBuffer((ReadBufferMode)((int)ReadBufferMode.ColorAttachment0 + targetIndex)); GL.ReadPixels(x, y, width, height, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), buffer); } ApplyGLBind(curBound); }
void IGraphicsBackend.GetOutputPixelData(IntPtr buffer, ColorDataLayout dataLayout, ColorDataElementType dataElementType, int x, int y, int width, int height) { //DefaultOpenTKBackendPlugin.GuardSingleThreadState(); NativeRenderTarget lastRt = NativeRenderTarget.BoundRT; NativeRenderTarget.Bind(null); { // Use a temporary local buffer, since the image will be upside-down because // of OpenGL's coordinate system and we'll need to flip it before returning. byte[] byteData = new byte[width * height * 4]; // Retrieve pixel data GL.ReadPixels(x, y, width, height, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), byteData); // Flip the retrieved image vertically int bytesPerLine = width * 4; byte[] switchLine = new byte[width * 4]; for (int flipY = 0; flipY < height / 2; flipY++) { int lineIndex = flipY * width * 4; int lineIndex2 = (height - 1 - flipY) * width * 4; // Copy the current line to the switch buffer for (int lineX = 0; lineX < bytesPerLine; lineX++) { switchLine[lineX] = byteData[lineIndex + lineX]; } // Copy the opposite line to the current line for (int lineX = 0; lineX < bytesPerLine; lineX++) { byteData[lineIndex + lineX] = byteData[lineIndex2 + lineX]; } // Copy the switch buffer to the opposite line for (int lineX = 0; lineX < bytesPerLine; lineX++) { byteData[lineIndex2 + lineX] = switchLine[lineX]; } } // Copy the flipped data to the output buffer Marshal.Copy(byteData, 0, buffer, width * height * 4); } NativeRenderTarget.Bind(lastRt); }
void INativeTexture.LoadData(TexturePixelFormat format, int width, int height, IntPtr data, ColorDataLayout dataLayout, ColorDataElementType dataElementType) { DefaultOpenTKBackendPlugin.GuardSingleThreadState(); int lastTexId; GL.GetInteger(GetPName.TextureBinding2D, out lastTexId); GL.BindTexture(TextureTarget.Texture2D, this.handle); // Load pixel data to video memory GL.TexImage2D(TextureTarget.Texture2D, 0, ToOpenTKPixelFormat(format), width, height, 0, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), data); this.width = width; this.height = height; this.format = format; GL.BindTexture(TextureTarget.Texture2D, lastTexId); }
void IGraphicsBackend.GetOutputPixelData <T>(T[] buffer, ColorDataLayout dataLayout, ColorDataElementType dataElementType, int x, int y, int width, int height) { // Removed thread guards because of performance //DefaultOpenTKBackendPlugin.GuardSingleThreadState(); NativeRenderTarget lastRt = NativeRenderTarget.BoundRT; NativeRenderTarget.Bind(null); { GL.ReadPixels(x, y, width, height, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), buffer); // The image will be upside-down because of OpenGL's coordinate system. Flip it. int structSize = Marshal.SizeOf(typeof(T)); T[] switchLine = new T[width * 4 / structSize]; for (int flipY = 0; flipY < height / 2; flipY++) { int lineIndex = flipY * width * 4 / structSize; int lineIndex2 = (height - 1 - flipY) * width * 4 / structSize; // Copy the current line to the switch buffer for (int lineX = 0; lineX < width; lineX++) { switchLine[lineX] = buffer[lineIndex + lineX]; } // Copy the opposite line to the current line for (int lineX = 0; lineX < width; lineX++) { buffer[lineIndex + lineX] = buffer[lineIndex2 + lineX]; } // Copy the switch buffer to the opposite line for (int lineX = 0; lineX < width; lineX++) { buffer[lineIndex2 + lineX] = switchLine[lineX]; } } } NativeRenderTarget.Bind(lastRt); }
unsafe void INativeTexture.LoadData(TexturePixelFormat format, int width, int height, IntPtr data, ColorDataLayout dataLayout, ColorDataElementType dataElementType) { // Removed thread guards because of performance //DefaultOpenTKBackendPlugin.GuardSingleThreadState(); WebGLTexture lastTexId = (WebGLTexture)GraphicsBackend.GL.GetParameter(WebGLRenderingContextBase.TEXTURE_BINDING_2D); GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, this.handle); // Load pixel data to video memory GraphicsBackend.GL.TexImage2D(WebGLRenderingContextBase.TEXTURE_2D, 0, ToOpenTKPixelInternalFormat(format), width, height, 0, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), TypedArray <Uint8ClampedArray, byte> .From(new Span <byte>(data.ToPointer(), /*ToDo*/ (width * height * 4)))); GraphicsBackend.GL.GenerateMipmap(WebGLRenderingContextBase.TEXTURE_2D); this.width = width; this.height = height; this.format = format; GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, lastTexId); }
void INativeTexture.LoadData <T>(TexturePixelFormat format, int width, int height, T[] data, ColorDataLayout dataLayout, ColorDataElementType dataElementType) { // Removed thread guards because of performance //DefaultOpenTKBackendPlugin.GuardSingleThreadState(); int lastTexId; GL.GetInteger(GetPName.TextureBinding2D, out lastTexId); GL.BindTexture(TextureTarget.Texture2D, this.handle); // Load pixel data to video memory GL.TexImage2D(TextureTarget.Texture2D, 0, ToOpenTKPixelInternalFormat(format), width, height, 0, dataLayout.ToOpenTK(), dataElementType.ToOpenTK(), data); GL.GenerateMipmap(TextureTarget.Texture2D); this.width = width; this.height = height; this.format = format; GL.BindTexture(TextureTarget.Texture2D, lastTexId); }