Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize setUniforms #7969

Merged
merged 2 commits into from
Mar 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions src/data/program_configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
Uniform1f,
UniformColor,
Uniform4f,
type UniformBindings,
type UniformLocations
} from '../render/uniform_binding';

Expand All @@ -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<any>
};

function packColor(color: Color): [number, number] {
return [
packUint8ToFloat(255 * color.r, 255 * color.g),
Expand Down Expand Up @@ -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<BinderUniform> {
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<Properties: Object>(context: Context, uniformBindings: UniformBindings, properties: PossiblyEvaluated<Properties>, globals: GlobalProperties) {
setUniforms<Properties: Object>(context: Context, binderUniforms: Array<BinderUniform>, properties: PossiblyEvaluated<Properties>, 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);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/render/program.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<WebGLRenderingContext, 'LINES'>
Expand All @@ -27,7 +28,7 @@ class Program<Us: UniformBindings> {
attributes: {[string]: number};
numAttributes: number;
fixedUniforms: Us;
binderUniforms: UniformBindings;
binderUniforms: Array<BinderUniform>;

constructor(context: Context,
source: {fragmentSource: string, vertexSource: string},
Expand Down