WebGL Framebuffers
文章推薦指數: 80 %
This article is meant to try to give you a mental image of what a framebuffer is in WebGL. Framebuffers come up as they allow you to render to a texture. A ...
English
Français
日本語
한국어
Polski
Portuguese
Русский
简体中文
TableofContents
WebGLFundamentals.org
Fix,Fork,Contribute
WebGLFramebuffers
Thisarticleismeanttotrytogiveyouamentalimage
ofwhataframebufferisinWebGL.Framebufferscomeup
astheyallowyoutorendertoatexture.
AFramebufferisjustacollectionofattachments.That'sit!Itis
usedtoallowrenderingtotexturesandrenderbuffers.
YoucanthinkofaFramebufferobjectlikethis
classFramebuffer{
constructor(){
this.attachments=newMap();//attachmentsbyattachmentpoint
}
}
AndtheWebGLRenderingContext(theglobject)likethis
//pseudocode
gl={
framebuffer:defaultFramebufferForCanvas,
}
Thereisonly1bindingpointinWebGL1.Itissetlikethis
gl.bindFramebuffer(target,framebuffer){
framebuffer=framebuffer||defaultFramebufferForCanvas;//ifnullusecanvas
switch(target){
case:gl.FRAMEBUFFER:
this.framebufferBinding=framebuffer;
break;
default:
...error...
}
}
Youcanaddattachmentstoaframebuffervia2functions,framebufferTexture2D,
andframebufferRenderbuffer.
Wecanimaginetheirimplementationtobesomethinglike
//pseudocode
gl._getFramebufferByTarget(target){
switch(target){
casegl.FRAMEBUFFER:
returnthis.framebufferBinding;
}
}
gl.framebufferTexture2D(target,attachmentPoint,texTarget,texture,mipLevel){
constframebuffer=this._getFramebufferByTarget(target);
framebuffer.attachments.set(attachmentPoint,{
texture,texTarget,mipLevel,
});
}
gl.framebufferRenderbuffer(target,attachmentPoint,renderbufferTarget,renderbuffer){
constframebuffer=this._getFramebufferByTarget(target);
framebuffer.attachments.set(attachmentPoint,{
renderbufferTarget,renderbuffer
});
}
IfyouhaveandenabletheWEBGL_draw_buffers
extensionthenaFramebufferconceptuallyexpandstothis
classFramebuffer{
constructor(){
this.attachments=newMap();
+this.drawBuffers=[gl.COLOR_ATTACHMENT0,gl.NONE,gl.NONE,gl.NONE,...];
}
}
Youcansetthedrawingbufferarraywithgl.drawBufferswhichwecan
imagineisimplementedlikethis
//pseudocode
ext.drawBuffersWebGL(drawBuffers){
constframebuffer=gl._getFramebufferByTarget(gl.FRAMEBUFFER);
for(leti=0;icodegoeshere
forcodeblocks
commentspoweredbyDisqus
延伸文章資訊
- 1一起幫忙解決難題,拯救IT 人的一天
Framebuffer. 如何在網頁中繪製3D 場景?從WebGL 的基礎開始說起系列第22 篇. PastLeo. 7 個月前‧ 283 瀏覽. 0. 大家好,我是西瓜,你現在看到的是2021...
- 2JavaScript WebGL framebuffer object - SegmentFault 思否
When How I built a wind map with WebGL , framebuffer was used in it, so I checked the data and tr...
- 3WebGL基础学习篇(Lesson 8) - GitHub
这个方法更易于实现而且也更利于大家了解选取的工作原理。 最基础的思想就是将每个物体都渲染成不同的颜色,并且将场景渲染到offscreen framebuffer中。接着,当用户 ...
- 4JavaScript webgl framebuffer object | Develop Paper
By default, the final drawing result of webgl is stored in the color buffer, and the frame buffer...
- 5How to work with framebuffers in webgl? - Stack Overflow
A fragment shader outputs to either the canvas or the attachments in a framebuffer. To be more te...