public override void BufferSubData( OpenGLDevice device, OpenGLDevice.GLenum buffer, bool discard, OpenGLDevice.IOpenGLBuffer handle, int elementSizeInBytes, int offsetInBytes, Array data, int startIndex, int elementCount ) { if (discard) { device.glBufferData( OpenGLDevice.GLenum.GL_ELEMENT_ARRAY_BUFFER, (IntPtr)handle.BufferSize, IntPtr.Zero, handle.Dynamic ); } GCHandle dataHandle = GCHandle.Alloc(data, GCHandleType.Pinned); device.glBufferSubData( OpenGLDevice.GLenum.GL_ELEMENT_ARRAY_BUFFER, offsetInBytes, elementSizeInBytes * elementCount, (IntPtr)(dataHandle.AddrOfPinnedObject().ToInt64() + startIndex * elementSizeInBytes) ); dataHandle.Free(); }
public abstract void BufferSubData( OpenGLDevice device, OpenGLDevice.GLenum buffer, bool discard, OpenGLDevice.IOpenGLBuffer bufferHandle, int elementSizeInBytes, int offsetInBytes, Array data, int startIndex, int elementCount );
public override void BufferSubData( OpenGLDevice device, OpenGLDevice.GLenum buffer, bool discard, OpenGLDevice.IOpenGLBuffer handle, int elementSizeInBytes, int offsetInBytes, Array data, int startIndex, int elementCount ) { var gl = GetWebGLContext(); if (discard) { gl.bufferData( (int)buffer, handle.BufferSize, (int)handle.Dynamic ); } var view = Verbatim.Expression("new Uint8Array($0.buffer, $1, $2)", data, offsetInBytes, elementSizeInBytes * elementCount); gl.bufferSubData((int)buffer, startIndex, view); }
public void SetRenderTargets(params RenderTargetBinding[] renderTargets) { // Checking for redundant SetRenderTargets... if (renderTargets == null && RenderTargetCount == 0) { return; } else if (renderTargets != null && renderTargets.Length == RenderTargetCount) { bool isRedundant = true; for (int i = 0; i < renderTargets.Length; i += 1) { if (renderTargets[i].RenderTarget != renderTargetBindings[i].RenderTarget || renderTargets[i].CubeMapFace != renderTargetBindings[i].CubeMapFace) { isRedundant = false; } } if (isRedundant) { return; } } Array.Clear(renderTargetBindings, 0, renderTargetBindings.Length); if (renderTargets == null || renderTargets.Length == 0) { GLDevice.SetRenderTargets(null, null, 0, DepthFormat.None); RenderTargetCount = 0; // Set the viewport to the size of the backbuffer. Viewport = new Viewport(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight); // Set the scissor rectangle to the size of the backbuffer. ScissorRectangle = new Rectangle(0, 0, PresentationParameters.BackBufferWidth, PresentationParameters.BackBufferHeight); if (PresentationParameters.RenderTargetUsage == RenderTargetUsage.DiscardContents) { Clear(DiscardColor); } } else { uint[] glTarget = new uint[renderTargets.Length]; OpenGLDevice.GLenum[] glTargetFace = new OpenGLDevice.GLenum[renderTargets.Length]; for (int i = 0; i < renderTargets.Length; i += 1) { glTarget[i] = renderTargets[i].RenderTarget.texture.Handle; if (renderTargets[i].RenderTarget is RenderTarget2D) { glTargetFace[i] = OpenGLDevice.GLenum.GL_TEXTURE_2D; } else { glTargetFace[i] = OpenGLDevice.GLenum.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (int)renderTargets[i].CubeMapFace; } } IRenderTarget target = renderTargets[0].RenderTarget as IRenderTarget; GLDevice.SetRenderTargets( glTarget, glTargetFace, target.DepthStencilBuffer, target.DepthStencilFormat ); Array.Copy(renderTargets, renderTargetBindings, renderTargets.Length); RenderTargetCount = renderTargets.Length; // Set the viewport to the size of the first render target. Viewport = new Viewport(0, 0, target.Width, target.Height); // Set the scissor rectangle to the size of the first render target. ScissorRectangle = new Rectangle(0, 0, target.Width, target.Height); if (target.RenderTargetUsage == RenderTargetUsage.DiscardContents) { Clear(DiscardColor); } } }
protected void GetGLSurfaceFormat() { switch (Format) { case SurfaceFormat.Color: glInternalFormat = OpenGLDevice.GLenum.GL_RGBA; glFormat = OpenGLDevice.GLenum.GL_RGBA; glType = OpenGLDevice.GLenum.GL_UNSIGNED_BYTE; break; case SurfaceFormat.Bgr565: glInternalFormat = OpenGLDevice.GLenum.GL_RGB; glFormat = OpenGLDevice.GLenum.GL_RGB; glType = OpenGLDevice.GLenum.GL_UNSIGNED_SHORT_5_6_5; break; case SurfaceFormat.Bgra4444: glInternalFormat = OpenGLDevice.GLenum.GL_RGBA4; glFormat = OpenGLDevice.GLenum.GL_BGRA; glType = OpenGLDevice.GLenum.GL_UNSIGNED_SHORT_4_4_4_4; break; case SurfaceFormat.Bgra5551: glInternalFormat = OpenGLDevice.GLenum.GL_RGBA; glFormat = OpenGLDevice.GLenum.GL_BGRA; glType = OpenGLDevice.GLenum.GL_UNSIGNED_SHORT_5_5_5_1; break; case SurfaceFormat.Alpha8: glInternalFormat = OpenGLDevice.GLenum.GL_LUMINANCE; glFormat = OpenGLDevice.GLenum.GL_LUMINANCE; glType = OpenGLDevice.GLenum.GL_UNSIGNED_BYTE; break; case SurfaceFormat.Dxt1: glInternalFormat = OpenGLDevice.GLenum.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; glFormat = OpenGLDevice.GLenum.GL_COMPRESSED_TEXTURE_FORMATS; break; case SurfaceFormat.Dxt3: glInternalFormat = OpenGLDevice.GLenum.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; glFormat = OpenGLDevice.GLenum.GL_COMPRESSED_TEXTURE_FORMATS; break; case SurfaceFormat.Dxt5: glInternalFormat = OpenGLDevice.GLenum.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; glFormat = OpenGLDevice.GLenum.GL_COMPRESSED_TEXTURE_FORMATS; break; case SurfaceFormat.Single: glInternalFormat = OpenGLDevice.GLenum.GL_R32F; glFormat = OpenGLDevice.GLenum.GL_RED; glType = OpenGLDevice.GLenum.GL_FLOAT; break; case SurfaceFormat.HalfVector2: glInternalFormat = OpenGLDevice.GLenum.GL_RG16F; glFormat = OpenGLDevice.GLenum.GL_RG; glType = OpenGLDevice.GLenum.GL_HALF_FLOAT; break; case SurfaceFormat.HdrBlendable: case SurfaceFormat.HalfVector4: glInternalFormat = OpenGLDevice.GLenum.GL_RGBA16F; glFormat = OpenGLDevice.GLenum.GL_RGBA; glType = OpenGLDevice.GLenum.GL_HALF_FLOAT; break; case SurfaceFormat.HalfSingle: glInternalFormat = OpenGLDevice.GLenum.GL_R16F; glFormat = OpenGLDevice.GLenum.GL_RED; glType = OpenGLDevice.GLenum.GL_HALF_FLOAT; break; case SurfaceFormat.Vector2: glInternalFormat = OpenGLDevice.GLenum.GL_RG32F; glFormat = OpenGLDevice.GLenum.GL_RG; glType = OpenGLDevice.GLenum.GL_FLOAT; break; case SurfaceFormat.Vector4: glInternalFormat = OpenGLDevice.GLenum.GL_RGBA32F; glFormat = OpenGLDevice.GLenum.GL_RGBA; glType = OpenGLDevice.GLenum.GL_FLOAT; break; case SurfaceFormat.NormalizedByte2: // Unconfirmed! glInternalFormat = OpenGLDevice.GLenum.GL_RG8I; glFormat = OpenGLDevice.GLenum.GL_RG; glType = OpenGLDevice.GLenum.GL_BYTE; break; case SurfaceFormat.NormalizedByte4: // Unconfirmed! glInternalFormat = OpenGLDevice.GLenum.GL_RGBA8I; glFormat = OpenGLDevice.GLenum.GL_RGBA; glType = OpenGLDevice.GLenum.GL_BYTE; break; case SurfaceFormat.Rg32: glInternalFormat = OpenGLDevice.GLenum.GL_RG16; glFormat = OpenGLDevice.GLenum.GL_RG; glType = OpenGLDevice.GLenum.GL_UNSIGNED_SHORT; break; case SurfaceFormat.Rgba64: glInternalFormat = OpenGLDevice.GLenum.GL_RGBA16; glFormat = OpenGLDevice.GLenum.GL_RGBA; glType = OpenGLDevice.GLenum.GL_UNSIGNED_SHORT; break; case SurfaceFormat.Rgba1010102: glInternalFormat = OpenGLDevice.GLenum.GL_RGB10_A2_EXT; glFormat = OpenGLDevice.GLenum.GL_RGBA; glType = OpenGLDevice.GLenum.GL_UNSIGNED_INT_10_10_10_2; break; default: throw new NotSupportedException(); } }