private void SetupNonMultisampled() { // Generate FBO if (this.handleMainFBO == null) { this.handleMainFBO = GraphicsBackend.GL.CreateFramebuffer(); } GraphicsBackend.GL.BindFramebuffer(WebGLRenderingContextBase.FRAMEBUFFER, this.handleMainFBO); // Attach textures int oglWidth = 0; int oglHeight = 0; for (int i = 0; i < this.targetInfos.Count; i++) { NativeTexture tex = this.targetInfos[i].Target; uint attachment = (WebGLRenderingContextBase.COLOR_ATTACHMENT0 + (uint)i); GraphicsBackend.GL.FramebufferTexture2D( WebGLRenderingContextBase.FRAMEBUFFER, attachment, WebGLRenderingContextBase.TEXTURE_2D, tex.Handle, 0); oglWidth = tex.Width; oglHeight = tex.Height; } // Generate or delete depth renderbuffer if (this.depthBuffer) { if (this.handleDepthRBO == null) { this.handleDepthRBO = GraphicsBackend.GL.CreateRenderbuffer(); } GraphicsBackend.GL.BindRenderbuffer(WebGLRenderingContextBase.RENDERBUFFER, this.handleDepthRBO); GraphicsBackend.GL.RenderbufferStorage(WebGLRenderingContextBase.RENDERBUFFER, WebGL2RenderingContextBase.DEPTH_COMPONENT24, oglWidth, oglHeight); GraphicsBackend.GL.FramebufferRenderbuffer(WebGLRenderingContextBase.FRAMEBUFFER, WebGLRenderingContextBase.DEPTH_ATTACHMENT, WebGLRenderingContextBase.RENDERBUFFER, this.handleDepthRBO); } else { GraphicsBackend.GL.FramebufferRenderbuffer(WebGLRenderingContextBase.FRAMEBUFFER, WebGLRenderingContextBase.DEPTH_ATTACHMENT, WebGLRenderingContextBase.RENDERBUFFER, null); if (this.handleDepthRBO != null) { GraphicsBackend.GL.DeleteRenderbuffer(this.handleDepthRBO); } this.handleDepthRBO = null; } // Check status int status = GraphicsBackend.GL.CheckFramebufferStatus(WebGLRenderingContextBase.FRAMEBUFFER); if (status != WebGLRenderingContextBase.FRAMEBUFFER_COMPLETE) { throw new BackendException(string.Format("Incomplete Framebuffer: {0}", status)); } GraphicsBackend.GL.BindRenderbuffer(WebGLRenderingContextBase.RENDERBUFFER, null); GraphicsBackend.GL.BindFramebuffer(WebGLRenderingContextBase.FRAMEBUFFER, null); }
public static void Bind(NativeTexture tex, int texUnit = 0) { if (!texInit) { InitTextureFields(); } if (curBound[texUnit] == tex) { return; } if (activeTexUnit != texUnit) { GraphicsBackend.GL.ActiveTexture(texUnits[texUnit]); } activeTexUnit = texUnit; if (tex == null) { GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, null); curBound[texUnit] = null; } else { GraphicsBackend.GL.BindTexture(WebGLRenderingContextBase.TEXTURE_2D, tex.Handle); curBound[texUnit] = tex; } }
/// <summary> /// Applies the specified parameter values to all currently active shaders. /// </summary> /// <param name="sharedParams"></param> /// <seealso cref="RetrieveActiveShaders"/> private void SetupSharedParameters(ShaderParameterCollection sharedParams) { this.sharedSamplerBindings = 0; this.sharedShaderParameters.Clear(); if (sharedParams == null) { return; } foreach (NativeShaderProgram shader in this.activeShaders) { NativeShaderProgram.Bind(shader); ShaderFieldInfo[] varInfo = shader.Fields; NativeShaderProgram.FieldLocation[] locations = shader.FieldLocations; // Setup shared sampler bindings and uniform data for (int i = 0; i < varInfo.Length; i++) { ref ShaderFieldInfo field = ref varInfo[i]; if (field.Scope == ShaderFieldScope.Attribute) { continue; } if (field.Type == ShaderFieldType.Sampler2D) { ContentRef <Texture> texRef; if (!sharedParams.TryGetInternal(field.Name, out texRef)) { continue; } NativeTexture.Bind(texRef, this.sharedSamplerBindings); GL.Uniform1i(locations[i].Uniform, this.sharedSamplerBindings); this.sharedSamplerBindings++; } else { float[] data; if (!sharedParams.TryGetInternal(field.Name, out data)) { continue; } NativeShaderProgram.SetUniform(ref field, locations[i].Uniform, data); } this.sharedShaderParameters.Add(field.Name); } }