MCPcopy Index your code
hub / github.com/PavelDoGreat/WebGL-Fluid-Simulation / getWebGLContext

Function getWebGLContext

script.js:118–168  ·  view source on GitHub ↗
(canvas)

Source from the content-addressed store, hash-verified

116startGUI();
117
118function getWebGLContext (canvas) {
119 const params = { alpha: true, depth: false, stencil: false, antialias: false, preserveDrawingBuffer: false };
120
121 let gl = canvas.getContext('webgl2', params);
122 const isWebGL2 = !!gl;
123 if (!isWebGL2)
124 gl = canvas.getContext('webgl', params) || canvas.getContext('experimental-webgl', params);
125
126 let halfFloat;
127 let supportLinearFiltering;
128 if (isWebGL2) {
129 gl.getExtension('EXT_color_buffer_float');
130 supportLinearFiltering = gl.getExtension('OES_texture_float_linear');
131 } else {
132 halfFloat = gl.getExtension('OES_texture_half_float');
133 supportLinearFiltering = gl.getExtension('OES_texture_half_float_linear');
134 }
135
136 gl.clearColor(0.0, 0.0, 0.0, 1.0);
137
138 const halfFloatTexType = isWebGL2 ? gl.HALF_FLOAT : halfFloat.HALF_FLOAT_OES;
139 let formatRGBA;
140 let formatRG;
141 let formatR;
142
143 if (isWebGL2)
144 {
145 formatRGBA = getSupportedFormat(gl, gl.RGBA16F, gl.RGBA, halfFloatTexType);
146 formatRG = getSupportedFormat(gl, gl.RG16F, gl.RG, halfFloatTexType);
147 formatR = getSupportedFormat(gl, gl.R16F, gl.RED, halfFloatTexType);
148 }
149 else
150 {
151 formatRGBA = getSupportedFormat(gl, gl.RGBA, gl.RGBA, halfFloatTexType);
152 formatRG = getSupportedFormat(gl, gl.RGBA, gl.RGBA, halfFloatTexType);
153 formatR = getSupportedFormat(gl, gl.RGBA, gl.RGBA, halfFloatTexType);
154 }
155
156 ga('send', 'event', isWebGL2 ? 'webgl2' : 'webgl', formatRGBA == null ? 'not supported' : 'supported');
157
158 return {
159 gl,
160 ext: {
161 formatRGBA,
162 formatRG,
163 formatR,
164 halfFloatTexType,
165 supportLinearFiltering
166 }
167 };
168}
169
170function getSupportedFormat (gl, internalFormat, format, type)
171{

Callers 1

script.jsFile · 0.85

Calls 1

getSupportedFormatFunction · 0.85

Tested by

no test coverage detected