File tree 3 files changed +71
-0
lines changed
3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change
1
+ import SDBaseElement from './sd-base.js' ;
2
+
3
+ class SDUniformElement extends SDBaseElement {
4
+ disconnectedCallback ( ) { }
5
+
6
+ get x ( ) {
7
+ return parseFloat ( this . getAttribute ( 'x' ) ) ;
8
+ }
9
+
10
+ set x ( newX ) {
11
+ if ( newX != null ) this . setAttribute ( 'x' , newX ) ;
12
+ else this . removeAttribute ( 'x' ) ;
13
+ }
14
+
15
+ get type ( ) {
16
+ return this . getAttribute ( 'type' ) ;
17
+ }
18
+
19
+ set type ( newType ) {
20
+ if ( newType != null ) this . setAttribute ( 'type' , newType ) ;
21
+ else this . removeAttribute ( 'type' ) ;
22
+ }
23
+
24
+ static get observedAttributes ( ) {
25
+ return [ 'x' ] ;
26
+ }
27
+
28
+ attributeChangedCallback ( name , oldValue , newValue ) {
29
+ switch ( name ) {
30
+ case 'x' :
31
+ if ( newValue != null ) this . renderer . setUniform ( this . name , newValue ) ;
32
+ break ;
33
+ }
34
+ }
35
+
36
+ init ( program ) {
37
+ if ( ! this . name ) {
38
+ console . warn ( 'sd-uniform created without a name.' ) ;
39
+ return ;
40
+ }
41
+
42
+ this . program = program ;
43
+ this . renderer . addUniform ( this . name , this . x , this . type ) ;
44
+ }
45
+ }
46
+
47
+ if ( ! customElements . get ( 'sd-uniform' ) ) {
48
+ customElements . define ( 'sd-uniform' , SDUniformElement ) ;
49
+ }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import Template from './template.js';
2
2
import SDNodeElement from './sd-node.js' ;
3
3
import './sd-audio.js' ;
4
4
import './sd-texture.js' ;
5
+ import './sd-uniform.js' ;
5
6
6
7
import Surface from './webgl/Surface.js' ;
7
8
import Renderer from './webgl/Renderer.js' ;
Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ function Renderer() {
28
28
const surfaces = new Set ( ) ;
29
29
30
30
const ustate = cheapClone ( GLOBAL_UNIFORMS ) ;
31
+ /* TODO UNIFORM*/
31
32
32
33
const extensions = Extensions ( gl ) ;
33
34
extensions . get ( 'OES_texture_float' ) ;
@@ -106,6 +107,24 @@ function Renderer() {
106
107
surfaces . delete ( surface ) ;
107
108
}
108
109
110
+ function addUniform ( name , value , type ) {
111
+ ustate . push ( {
112
+ name,
113
+ value,
114
+ type,
115
+ toyname : name ,
116
+ } ) ;
117
+ }
118
+
119
+ function setUniform ( name , value ) {
120
+ for ( let i = 0 ; i < ustate . length ; i ++ ) {
121
+ if ( ustate [ i ] . name === name ) {
122
+ ustate [ i ] . value = value ;
123
+ break ;
124
+ }
125
+ }
126
+ }
127
+
109
128
function dispose ( ) {
110
129
surfaces . forEach ( s => s . dispose ( ) ) ;
111
130
surfaces . clear ( ) ;
@@ -128,6 +147,8 @@ function Renderer() {
128
147
} ,
129
148
addSurface,
130
149
removeSurface,
150
+ addUniform,
151
+ setUniform,
131
152
dispose,
132
153
} ) ;
133
154
}
You can’t perform that action at this time.
0 commit comments