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

chore(TS): BREAKING move also defaults for filters away from prototype #8742

Merged
merged 49 commits into from
Feb 28, 2023

Conversation

asturur
Copy link
Member

@asturur asturur commented Feb 26, 2023

Motivation

Fortunately the defaults values for filters aren't important at all.
The only real change is the fragmentSource that doesn't exists anymore as a private string/object property but is always returned from the getFragmentSource function.

We still have a default value object otherwise we need to declare a constructor per instance.
Probably final typings will force us to add a constructor and in that case the concept of defaults for filters can be removed.
For now is at least terser because focus all the parameter logic in the base class.

The duality of BaseFilter or BaseFilter is not needed anymore and has been removed ( was introduced for the migration )

Removed the duality between diff and difference for BlendColor. diff was introduced 9 years ago, but the correct name is difference that was paired with it later. Was never deprecated

@github-actions
Copy link
Contributor

github-actions bot commented Feb 26, 2023

Build Stats

file / KB (diff) bundled minified
fabric 891.502 (-1.263) 304.527 (-1.771)

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

the fact that all the code i added saved 1.3kb leaves me a bit confused.
I definitely added more than removed, with all the getFragmentSource and imports files

@asturur asturur changed the title WIP: move also defaults for filters away from prototype chore(TS): BREAKING move also defaults for filters away from prototype Feb 28, 2023
@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

Ok this is ready to go.
There are probably optimizations that can be done for main parameter ( but unless they save me another half kb i m not committing them )

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

This is ready to go i think.
And i think it completes the part of the default values that is necessary for 6.0
If i can get away from type from objects as i did for filter i ll remove also that, otherwise not.

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

oh no controls yet.
But controls can be solved cleanly with the same strategy.

@ShaMan123
Copy link
Contributor

I will review now.
I did type as you suggested #8714

Copy link
Contributor

@ShaMan123 ShaMan123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great cleanup! Files are so much readable and less intimidating (for me they were, WebGL still is)

  • naming: can we keep camelCase or UpperFirst convesion? colorMatrix.shaders => ColorMatrixShaders, or perhaps create a folder Shaders and move all of them there. I like that you took it out and I like the idea of having them in a Shaders folder. They are consts so seems right to me.
  • moving fromObject to base class with new this will save a lot of lines, there are only 2-4 filters that override it
  • extract the rest of WebGL c code (is it c?) from filter files

import { T2DPipelineState, TWebGLUniformLocationMap } from './typedefs';
import { classRegistry } from '../ClassRegistry';
import { blendColorFragmentSource } from './blendColor.shaders';

type TBlendMode =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should export most types in general


export const blurDefaultValues: Partial<TClassProperties<Blur>> = {
blur: 0,
mainParameter: 'blur',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be static as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't want to waste time on this, every test is time consuming between changes, test fixes and surprises.
Not all classes have a mainParameter, and unless we codify it as none or something like that, is just a bunch of different cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(i already tried 3 times to remove it entirely or reduce its appareances)

Comment on lines 4 to 25
export function createColorMatrixFilter(key: string, matrix: number[]) {
return class GeneratedColorMatrix extends ColorMatrix {
/**
* Filter type
* @param {String} type
* @default
*/
type = key;

/**
* Colormatrix for the effect
* array of 20 floats. Numbers in positions 4, 9, 14, 19 loose meaning
* outside the -1, 1 range.
* @param {Array} matrix array of 20 numbers.
* @default
*/
matrix = matrix;

/**
* Lock the matrix export for this kind of static, parameter less filters.
*/
mainParameter = undefined;
const newClass = class extends ColorMatrix {
get type() {
return key;
}

/**
* Lock the colormatrix on the color part, skipping alpha
*/
colorsOnly = true;
static defaults = {
...colorMatrixDefaultValues,
/**
* Lock the matrix export for this kind of static, parameter less filters.
*/
mainParameter: undefined,
matrix,
};

static async fromObject(object: any) {
return new GeneratedColorMatrix(object);
return new this(object);
}
};
classRegistry.setClass(newClass, key);
return newClass;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ShaMan123 ShaMan123 Feb 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mixins suck in TS but that is not the only reason. The the class name is correct ad it reduces complexity of code as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this is not a mixin. this is a subclass generated with a function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant dynamic classes, sorry

Comment on lines +14 to +19
fragmentSourceTOP: `
precision highp float;
uniform sampler2D uTexture;
uniform vec2 uDelta;
varying vec2 vTexCoord;
`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency should be moved to a standalone file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this resize one is too messy. but shouldn't be a property either, i will move this

`,
};

type TResizeType = 'bilinear' | 'hermite' | 'sliceHack' | 'lanczos';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export

src/filters/BaseFilter.ts Outdated Show resolved Hide resolved
src/filters/BlendImage.ts Show resolved Hide resolved
ShaMan123 added a commit that referenced this pull request Feb 28, 2023
@ShaMan123
Copy link
Contributor

  • moving fromObject to base class with new this will save a lot of lines, there are only 2-4 filters that override it

when you do this make sure to spread the object and remove type from it so it won't override the getter (I am guessing that is happening currently)

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

  • moving fromObject to base class with new this will save a lot of lines, there are only 2-4 filters that override it

when you do this make sure to spread the object and remove type from it so it won't override the getter (I am guessing that is happening currently)

No is not happening because the constructor is avoing getting type in.
Right i forgot about new this(), and i played around with gettin the class from class registry and then i didn't like it.
i ll do this now, but not touching anything else for now.

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

  • naming: can we keep camelCase or UpperFirst convesion? colorMatrix.shaders => ColorMatrixShaders, or perhaps create a folder Shaders and move all of them there. I like that you took it out and I like the idea of having them in a Shaders folder. They are consts so seems right to me.

i can move them in a folder yes, that will make the .shader. go away

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

  • extract the rest of WebGL c code (is it c?) from filter files

is shader language, not sure the exact definition.
The syntax is C like but the rules are different.
Also the assumptions are different

@asturur
Copy link
Member Author

asturur commented Feb 28, 2023

There are additional things that can be done here:

  • resize filter can have the shader code extracted ( followup )
  • some optimizations on how we do sendUniformData and getUniformLocations so that they can be defined as a map of a function rather than methods (helps abstracting writing a filter) ( follow up)
  • the highp/medium/low precision code can be made common and injected in all shaders

@asturur asturur merged commit 0a37035 into master Feb 28, 2023
@asturur asturur deleted the defaults-for-filters branch February 28, 2023 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants