private void SetupMaterial(BatchInfo material, BatchInfo lastMaterial) { if (material == lastMaterial) { return; } DrawTechnique tech = material.Technique.Res ?? DrawTechnique.Solid.Res; DrawTechnique lastTech = lastMaterial != null ? lastMaterial.Technique.Res : null; // Setup BlendType if (lastTech == null || tech.Blending != lastTech.Blending) { this.SetupBlendType(tech.Blending, this.currentDevice.DepthWrite); } // Bind Shader ShaderProgram shader = tech.Shader.Res ?? ShaderProgram.Minimal.Res; NativeShaderProgram nativeShader = shader.Native as NativeShaderProgram; NativeShaderProgram.Bind(nativeShader); // Setup shader data ShaderFieldInfo[] varInfo = nativeShader.Fields; int[] locations = nativeShader.FieldLocations; // Setup sampler bindings automatically int curSamplerIndex = this.sharedSamplerBindings; for (int i = 0; i < varInfo.Length; i++) { if (locations[i] == -1) { continue; } if (varInfo[i].Type != ShaderFieldType.Sampler2D) { continue; } if (this.sharedShaderParameters.Contains(varInfo[i].Name)) { continue; } ContentRef <Texture> texRef = material.GetInternalTexture(varInfo[i].Name); NativeTexture.Bind(texRef, curSamplerIndex); GL.Uniform1(locations[i], curSamplerIndex); curSamplerIndex++; } NativeTexture.ResetBinding(curSamplerIndex); // Setup uniform data for (int i = 0; i < varInfo.Length; i++) { if (locations[i] == -1) { continue; } if (varInfo[i].Type == ShaderFieldType.Sampler2D) { continue; } if (this.sharedShaderParameters.Contains(varInfo[i].Name)) { continue; } float[] data; if (varInfo[i].Name == "ModelView") { data = modelViewData; } else if (varInfo[i].Name == "Projection") { data = projectionData; } else { data = material.GetInternalData(varInfo[i].Name); if (data == null) { continue; } } NativeShaderProgram.SetUniform(ref varInfo[i], locations[i], data); } }
private void SetupMaterial(BatchInfo material, BatchInfo lastMaterial) { DrawTechnique tech = material.Technique.Res ?? DrawTechnique.Solid.Res; DrawTechnique lastTech = lastMaterial != null ? lastMaterial.Technique.Res : null; // Setup BlendType if (lastTech == null || tech.Blending != lastTech.Blending) { this.SetupBlendState(tech.Blending); } // Bind Shader NativeShaderProgram nativeShader = tech.NativeShader as NativeShaderProgram; NativeShaderProgram.Bind(nativeShader); // Setup shader data ShaderFieldInfo[] varInfo = nativeShader.Fields; int[] locations = nativeShader.FieldLocations; // Setup sampler bindings and uniform data int curSamplerIndex = this.sharedSamplerBindings; for (int i = 0; i < varInfo.Length; i++) { ShaderFieldInfo field = varInfo[i]; int location = locations[i]; if (field.Scope == ShaderFieldScope.Attribute) { continue; } if (this.sharedShaderParameters.Contains(field.Name)) { continue; } if (field.Type == ShaderFieldType.Sampler2D) { ContentRef <Texture> texRef = material.GetInternalTexture(field.Name); if (texRef == null) { this.internalShaderState.TryGetInternal(field.Name, out texRef); } NativeTexture.Bind(texRef, curSamplerIndex); GL.Uniform1(location, curSamplerIndex); curSamplerIndex++; } else { float[] data = material.GetInternalData(field.Name); if (data == null && !this.internalShaderState.TryGetInternal(field.Name, out data)) { continue; } NativeShaderProgram.SetUniform(field, location, data); } } NativeTexture.ResetBinding(curSamplerIndex); }