MCPcopy Create free account
hub / github.com/gre/gl-react / createFBO

Function createFBO

packages/gl-react/src/Node.tsx:172–234  ·  view source on GitHub ↗
(
  gl: WebGLRenderingContext,
  width: number,
  height: number
)

Source from the content-addressed store, hash-verified

170
171// minimal version of gl-fbo
172const createFBO = (
173 gl: WebGLRenderingContext,
174 width: number,
175 height: number
176): Framebuffer => {
177 var handle = gl.createFramebuffer()!;
178 gl.bindFramebuffer(gl.FRAMEBUFFER, handle);
179 var color = gl.createTexture();
180 if (!color) throw new Error("createTexture returned null");
181 gl.bindTexture(gl.TEXTURE_2D, color);
182 gl.texImage2D(
183 gl.TEXTURE_2D,
184 0,
185 gl.RGBA,
186 width,
187 height,
188 0,
189 gl.RGBA,
190 gl.UNSIGNED_BYTE,
191 null
192 );
193 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
194 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
195 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
196 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
197 gl.framebufferTexture2D(
198 gl.FRAMEBUFFER,
199 gl.COLOR_ATTACHMENT0,
200 gl.TEXTURE_2D,
201 color,
202 0
203 );
204 return {
205 handle,
206 color,
207 bind: () => {
208 gl.bindFramebuffer(gl.FRAMEBUFFER, handle);
209 gl.viewport(0, 0, width, height);
210 },
211 syncSize: (w: number, h: number) => {
212 if (w !== width || h !== height) {
213 width = w;
214 height = h;
215 gl.bindTexture(gl.TEXTURE_2D, color);
216 gl.texImage2D(
217 gl.TEXTURE_2D,
218 0,
219 gl.RGBA,
220 w,
221 h,
222 0,
223 gl.RGBA,
224 gl.UNSIGNED_BYTE,
225 null
226 );
227 }
228 },
229 dispose: () => {

Callers 1

_prepareGLObjectsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…