PageSourceSearch

https://statistics4ecologists-v2a.netlify.app/libs/rglwidgetClass-1.2.8/shaders.src.js

js statistics4ecologists-v2a.netlify.app collected 2026-10-03 11:27:06 UTC 6,522 bytes, 183 lines download raw bytes

1    /**
2     * Methods related to shaders
3     * @name ___METHODS_FOR_SHADERS___
4     * @memberof rglwidgetClass
5     * @kind function
6     * @instance
7     */
8     
9    /**
10     * Get flags that will end up as shader defines.
11     * Static method so it can be called from R
12     */
13    rglwidgetClass.getDefFlags = function(flags, type, normals, round_points) {
14      var f = {};
15      f.fat_lines = rglwidgetClass.isSet(flags, rglwidgetClass.f_fat_lines);
16      f.fixed_quads = rglwidgetClass.isSet(flags, rglwidgetClass.f_fixed_quads);
17      f.fixed_size = rglwidgetClass.isSet(flags, rglwidgetClass.f_fixed_size);
18      f.has_fog = rglwidgetClass.isSet(flags, rglwidgetClass.f_has_fog);
19      f.has_normals = (typeof normals !== "undefined") ||
20                        type === "spheres";
21      f.has_texture = rglwidgetClass.isSet(flags, rglwidgetClass.f_has_texture);
22      f.is_brush = rglwidgetClass.isSet(flags, rglwidgetClass.f_is_brush);
23      f.is_lines = rglwidgetClass.isSet(flags, rglwidgetClass.f_is_lines);
24      f.is_lit = rglwidgetClass.isSet(flags, rglwidgetClass.f_is_lit);
25      f.is_points = rglwidgetClass.isSet(flags, rglwidgetClass.f_is_points);
26      f.is_transparent = rglwidgetClass.isSet(flags, rglwidgetClass.f_is_transparent);
27      f.is_twosided = rglwidgetClass.isSet(flags, rglwidgetClass.f_is_twosided);
28      f.needs_vnormal = !rglwidgetClass.isSet(flags, rglwidgetClass.f_sprites_3d) &&
29        (f.is_lit && !f.fixed_quads && !f.is_brush) || (f.is_twosided && f.has_normals);
30      f.rotating = rglwidgetClass.isSet(flags, rglwidgetClass.f_rotating);
31      f.round_points = round_points;
32      return f;
33    };
34     
35    
36    /**
37     * Generate the defines for the shader code for an object.
38     * 
39     * This is a static method so it can be called from R.
40     * 
41     * @returns {string}
42     * @param  id - id of object
43     * @param  type - type of object
44     * @param  flags - object flags
45     * @param  nclipplanes - number of clipping planes in scene 
46     *         (may not all be active)
47     * @param  nlights - number of lights in scene (ditto)
48     * @param  normals - normals for object
49     * @param  pointSize - point size for object 
50     * @param  textype - texture type for object 
51     * @param  antialias - use antialiasing?
52     */
53    rglwidgetClass.getDefines = function(id, type, flags,
54      nclipplanes, nlights, normals, pointSize, textype,
55      texmode, texenvmap, antialias, fl) {
56      var
57        title, defines;
58      
59      if (typeof fl === "undefined")
60        fl = rglwidgetClass.getDefFlags(flags, type, normals, antialias);
61        
62      title = "  /* ****** "+type+" object "+id+" shader ****** */\n";
63      
64      defines = "#define NCLIPPLANES " + nclipplanes + "\n"+
65                "#define NLIGHTS " + nlights + "\n";
66      
67      if (fl.fat_lines)
68        defines = defines + "#define FAT_LINES 1\n";
69      
70      if (fl.fixed_quads)
71        defines = defines + "#define FIXED_QUADS 1\n";
72
73      if (fl.fixed_size)
74        defines = defines + "#define FIXED_SIZE 1\n";
75
76      if (fl.has_fog)
77        defines = defines + "#define HAS_FOG 1\n";
78        
79      if (fl.has_normals)
80        defines = defines + "#define HAS_NORMALS 1\n";
81        
82      if (fl.has_texture) {
83        defines = defines + "#define HAS_TEXTURE 1\n";
84        defines = defines + "#define TEXTURE_" + textype + "\n";
85        defines = defines + "#define TEXMODE_" + texmode + "\n";
86        if (texenvmap)
87          defines = defines + "#define USE_ENVMAP 1\n";
88      }
89      
90      if (fl.is_brush)
91        defines = defines + "#define IS_BRUSH 1\n";  
92
93      if (type === "linestrip")
94        defines = defines + "#define IS_LINESTRIP 1\n";         
95
96      if (fl.is_lit)
97        defines = defines + "#define IS_LIT 1\n"; 
98      
99      if (fl.is_points) {
100        defines = defines + "#define IS_POINTS 1\n";
101        defines = defines + "#define POINTSIZE " + Number.parseFloat(pointSize).toFixed(1) + "\n";
102      }
103        
104      if (type === "sprites")
105        defines = defines + "#define IS_SPRITES 1\n";
106        
107      if (type === "text")
108        defines = defines + "#define IS_TEXT 1\n";
109
110      if (fl.is_transparent)
111        defines = defines + "#define IS_TRANSPARENT 1\n"; 
112        
113      if (fl.is_twosided)
114        defines = defines + "#define IS_TWOSIDED 1\n";
115        
116      if (fl.needs_vnormal)
117        defines = defines + "#define NEEDS_VNORMAL 1\n";
118
119      if (fl.rotating)
120        defines = defines + "#define ROTATING 1\n";
121        
122      if (fl.round_points)        
123        defines = defines + "#define ROUND_POINTS 1\n";   
124
125      // console.log(result);
126      return title + defines;
127    };
128
129    /**
130     * Create code for vertex and fragment shaders
131     * @returns {Object}
132     * @param { number }
132 shaderType - gl code for shader type
133     * @param { string } code - code for the shader
134     */
135    rglwidgetClass.prototype.getShaders = function(obj) {
136      var header, 
137        vertex = obj.userVertexShader, 
138        fragment = obj.userFragmentShader;
139      
140      header = rglwidgetClass.getDefines(
141        obj.id, obj.type, obj.flags, 
142        this.countClipplanes(), this.countLights(), 
143        obj.normals, 
144        this.getMaterial(obj, "size"), 
145        this.getMaterial(obj, "textype"),
146        this.getMaterial(obj, "texmode"),
147        this.getMaterial(obj, "texenvmap"),
148        this.getMaterial(obj, "point_antialias"),
149        obj.defFlags
150      );
151
152      if (typeof vertex === "undefined")
153        vertex = rglwidgetClass.rgl_vertex_shader();
154        
155      if (typeof fragment === "undefined") 
156        fragment = rglwidgetClass.rgl_fragment_shader();
157
158//      console.log("vertex:");
159//      console.log(header + vertex);
160//      console.log("fragment:");
161//      console.log(header + fragment);
162      
163      return {vertex: header + vertex,
164              fragment: header + fragment};
165    };
166    
167    
168    /**
169     * Call gl functions to create and compile shader from code
170     * @returns {Object}
171     * @param { number } shaderType - gl code for shader type
172     * @param { string } code - code for the shader
173     */
174    rglwidgetClass.prototype.getShader = function(shaderType, code) {
175        var gl = this.gl, shader;
176        shader = gl.createShader(shaderType);
177        gl.shaderSource(shader, code);
178        gl.compileShader(shader);
179        if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS) && !gl.isContextLost())
180            alert(gl.getShaderInfoLog(shader));
181        return shader;
182    };
183

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.