diff --git a/src/data/program_configuration.js b/src/data/program_configuration.js index 62323770265..d37baf45ba2 100644 --- a/src/data/program_configuration.js +++ b/src/data/program_configuration.js @@ -14,7 +14,6 @@ import { Uniform1f, UniformColor, Uniform4f, - type UniformBindings, type UniformLocations } from '../render/uniform_binding'; @@ -34,6 +33,12 @@ import type { import type {PossiblyEvaluated} from '../style/properties'; import type {FeatureStates} from '../source/source_state'; +export type BinderUniform = { + name: string, + property: string, + binding: Uniform +}; + function packColor(color: Color): [number, number] { return [ packUint8ToFloat(255 * color.r, 255 * color.g), @@ -659,26 +664,25 @@ export default class ProgramConfiguration { return this._buffers; } - getUniforms(context: Context, locations: UniformLocations): UniformBindings { - const result = {}; + getUniforms(context: Context, locations: UniformLocations): Array { + const uniforms = []; for (const property in this.binders) { const binder = this.binders[property]; for (const name of binder.uniformNames) { - result[name] = binder.getBinding(context, locations[name]); + if (locations[name]) { + const binding = binder.getBinding(context, locations[name]); + uniforms.push({name, property, binding}); + } } } - return result; + return uniforms; } - setUniforms(context: Context, uniformBindings: UniformBindings, properties: PossiblyEvaluated, globals: GlobalProperties) { + setUniforms(context: Context, binderUniforms: Array, properties: PossiblyEvaluated, globals: GlobalProperties) { // Uniform state bindings are owned by the Program, but we set them // from within the ProgramConfiguraton's binder members. - - for (const property in this.binders) { - const binder = this.binders[property]; - for (const uniformName of binder.uniformNames) { - binder.setUniforms(context, uniformBindings[uniformName], globals, properties.get(property), uniformName); - } + for (const {name, property, binding} of binderUniforms) { + this.binders[property].setUniforms(context, binding, globals, properties.get(property), name); } } diff --git a/src/render/program.js b/src/render/program.js index 6f9960454b3..398eb6111c2 100644 --- a/src/render/program.js +++ b/src/render/program.js @@ -16,6 +16,7 @@ import type StencilMode from '../gl/stencil_mode'; import type ColorMode from '../gl/color_mode'; import type CullFaceMode from '../gl/cull_face_mode'; import type {UniformBindings, UniformValues, UniformLocations} from './uniform_binding'; +import type {BinderUniform} from '../data/program_configuration'; export type DrawMode = | $PropertyType @@ -27,7 +28,7 @@ class Program { attributes: {[string]: number}; numAttributes: number; fixedUniforms: Us; - binderUniforms: UniformBindings; + binderUniforms: Array; constructor(context: Context, source: {fragmentSource: string, vertexSource: string},