public OpenGLESShaderConstantBindingSlots( ShaderSet shaderSet, ShaderResourceDescription[] constants) { var programID = ((OpenGLESShaderSet)shaderSet).ProgramID; int bindingIndex = 0; int constantsCount = constants.Length; _bindings = new UniformBinding[constantsCount]; for (int i = 0; i < constantsCount; i++) { ShaderResourceDescription description = constants[i]; int blockIndex = GL.GetUniformBlockIndex(programID, description.Name); if (blockIndex != -1) { ValidateBlockSize(programID, blockIndex, description.DataSizeInBytes, description.Name); _bindings[i] = new UniformBlockBinding( programID, blockIndex, bindingIndex, description.DataSizeInBytes); bindingIndex += 1; } else { int uniformLocation = GL.GetUniformLocation(programID, description.Name); if (uniformLocation == -1) { throw new VeldridException($"No uniform or uniform block with name {description.Name} was found."); } _bindings[i] = new UniformLocationBinding( programID, uniformLocation); } } }
public OpenGLShaderConstantBindings( RenderContext rc, ShaderSet shaderSet, MaterialInputs <MaterialGlobalInputElement> globalInputs, MaterialInputs <MaterialPerObjectInputElement> perObjectInputs) { var programID = ((OpenGLShaderSet)shaderSet).ProgramID; int globalInputsCount = globalInputs.Elements.Length; int bindingIndex = 0; _globalUniformBindings = new GlobalBindingPair[globalInputsCount]; for (int i = 0; i < globalInputsCount; i++) { var element = globalInputs.Elements[i]; ConstantBufferDataProvider dataProvider = element.UseGlobalNamedBuffer ? rc.GetNamedGlobalBufferProviderPair(element.GlobalProviderName).DataProvider : element.DataProvider; int blockIndex = GL.GetUniformBlockIndex(programID, element.Name); if (blockIndex != -1) { ValidateBlockSize(programID, blockIndex, dataProvider.DataSizeInBytes, element.Name); _globalUniformBindings[i] = new GlobalBindingPair( new UniformBlockBinding( programID, blockIndex, bindingIndex, new OpenGLConstantBuffer(dataProvider), dataProvider.DataSizeInBytes), dataProvider); bindingIndex += 1; } else { int uniformLocation = GL.GetUniformLocation(programID, element.Name); if (uniformLocation == -1) { throw new InvalidOperationException($"No uniform or uniform block with name {element.Name} was found."); } _globalUniformBindings[i] = new GlobalBindingPair( new UniformLocationBinding( programID, uniformLocation), dataProvider); } } int perObjectInputsCount = perObjectInputs.Elements.Length; _perObjectBindings = new UniformBinding[perObjectInputsCount]; for (int i = 0; i < perObjectInputsCount; i++) { var element = perObjectInputs.Elements[i]; int blockIndex = GL.GetUniformBlockIndex(programID, element.Name); if (blockIndex != -1) { _perObjectBindings[i] = new UniformBlockBinding( programID, blockIndex, bindingIndex, new OpenGLConstantBuffer(), element.BufferSizeInBytes); bindingIndex += 1; } else { int uniformLocation = GL.GetUniformLocation(programID, element.Name); if (uniformLocation == -1) { throw new InvalidOperationException($"No uniform or uniform block with name {element.Name} was found."); } _perObjectBindings[i] = new UniformLocationBinding( programID, uniformLocation); } } }