graphics3d/rendertarget
렌더 타겟. (오프스크린 프레임버퍼 + 컬러 텍스처 [+ 깊이 렌더버퍼 / 깊이 텍스처])
Render target. (offscreen framebuffer + color texture [+ depth renderbuffer / depth texture])
RenderTargetextends Object
렌더 타겟. (오프스크린 프레임버퍼 + 컬러 텍스처 [+ 깊이 렌더버퍼 / 깊이 텍스처])
- 포스트 프로세싱 체인의 기본 단위.
- 옵션으로 다중 컬러 어태치먼트(MRT) / 반정밀 실수 컬러(HDR) / 깊이 텍스처 / 멀티샘플 / 깊이 비트를 켤 수 있다. { colorAttachmentCount: 1, useFloatColor: false, useDepthTexture: false, sampleCount: 0, depthBits: 16 }
- sampleCount 가 2 이상이면 멀티샘플(MSAA) 렌더버퍼에 그리고 resolve() 가 컬러 텍스처(와 깊이 텍스처)로 푼다. 기기가 받는 수(MAX_SAMPLES, 포맷마다 받는 표본 수)를 넘으면 그 밑의 가장 큰 수로 줄이고, 못 받거나 프레임버퍼가 완성되지 않으면 멀티샘플 없이 짓는다. (getSampleCount) 멀티샘플이면 getFramebuffer 는 그리는 멀티샘플 프레임버퍼, getResolveFramebuffer 는 텍스처가 붙은 프레임버퍼다. 텍스처를 읽기 전에 resolve() 를 부른다.
- resolve() 는 푼 뒤에도 멀티샘플 색과 깊이를 그대로 둔다. (invalidateFramebuffer 로 버리는 것은 아이패드와 아이폰 사파리에서 프레임마다 수 ~ 수십 ms 가 붙고 이득이 재어지지 않아 하지 않는다, 풀고 나서 이어 그리는 것도 된다)
- depthBits 는 깊이 렌더버퍼의 비트 수(16 이나 24)다. 깊이 텍스처는 늘 24 비트다. 멀티샘플이면서 깊이 텍스처를 쓰면 멀티샘플 깊이도 24 비트로 지어 그대로 푼다.
Render target. (offscreen framebuffer + color texture [+ depth renderbuffer / depth texture])
- The basic unit of the post processing chain.
- Multiple color attachments (MRT) / half precision float color (HDR) / depth texture / multisample / depth bits can be enabled as options. { colorAttachmentCount: 1, useFloatColor: false, useDepthTexture: false, sampleCount: 0, depthBits: 16 }
- If sampleCount is 2 or more, draws into a multisample (MSAA) renderbuffer and resolve() resolves it into the color texture (and the depth texture). If it exceeds what the device accepts (MAX_SAMPLES, the sample counts each format accepts), it is reduced to the largest number below that, and if none is accepted or the framebuffer is incomplete, it is built without multisampling. (getSampleCount) When multisampled, getFramebuffer is the multisample framebuffer that is drawn into, and getResolveFramebuffer is the framebuffer with the textures attached. Call resolve() before reading the textures.
- resolve() leaves the multisample color and depth as they are after resolving. (Discarding them with invalidateFramebuffer is not done because it added several to tens of ms per frame in Safari on iPad and iPhone and showed no measured gain; drawing more after resolving also works)
- depthBits is the bit count (16 or 24) of the depth renderbuffer. The depth texture is always 24 bits. When multisampled with a depth texture, the multisample depth is also built at 24 bits and resolved as is.
import { RenderTarget } from "./build/vanilla.js";
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const renderTarget = new RenderTarget(webGL2RenderingContext, 256, 256, true, { useDepthTexture: true, sampleCount: 4 });
renderTarget.bind();
webGL2RenderingContext.clearColor(0.2, 0.4, 0.8, 1.0);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
renderTarget.resolve();
webGL2RenderingContext.bindFramebuffer(webGL2RenderingContext.FRAMEBUFFER, null);
const sampleCount = renderTarget.getSampleCount();
const colorTexture = renderTarget.getColorTexture();
const depthTexture = renderTarget.getDepthTexture();
console.log(sampleCount, colorTexture !== null, depthTexture !== null);
renderTarget.destroy();생성.
Constructor.
- webGL2RenderingContextWebGL2RenderingContext
- WebGL2 렌더링 컨텍스트.WebGL2 rendering context.
- widthnumber
- 가로 크기. (픽셀)Width. (pixels)
- heightnumber
- 세로 크기. (픽셀)Height. (pixels)
- useDepthboolean
- 깊이 어태치먼트를 붙일지.Whether to attach depth.
- optionsobject | null
- { colorAttachmentCount = 1, useFloatColor = false, useDepthTexture = false, sampleCount = 0, depthBits = 16 } (null 이면 모두 기본값){ colorAttachmentCount = 1, useFloatColor = false, useDepthTexture = false, sampleCount = 0, depthBits = 16 } (all defaults when null)
짝Counterpart: vanilla-engine RenderTarget.new
import { RenderTarget } from "./build/vanilla.js";
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const renderTarget = new RenderTarget(webGL2RenderingContext, 320, 180, true, { colorAttachmentCount: 2, useFloatColor: true });
const firstTexture = renderTarget.getColorTexture(0);
const secondTexture = renderTarget.getColorTexture(1);
console.log(firstTexture !== null, secondTexture !== null);
renderTarget.resize(640, 360);
const width = renderTarget.getWidth();
const height = renderTarget.getHeight();
console.log(width, height);
renderTarget.destroy();크기 변경. (같은 크기면 무시, 다르면 리소스 재생성)
Resize. (Ignored if the same size, otherwise recreates resources)
- widthnumber
- 새 가로 크기. (픽셀)New width. (pixels)
- heightnumber
- 새 세로 크기. (픽셀)New height. (pixels)
짝Counterpart: vanilla-engine RenderTarget.resize
기기가 받는 표본 수. (요청 수를 MAX_SAMPLES 와 포맷마다 받는 표본 수 밑의 가장 큰 수로, 2 밑이면 0)
The sample count the device accepts. (The requested count reduced to the largest number below MAX_SAMPLES and the sample counts each format accepts, 0 if below 2)
- requestedSampleCountnumber
- 요청한 표본 수.Requested sample count.
- internalFormatListArray<number>
- 렌더버퍼 내부 포맷 목록. (모든 포맷이 받는 수로 줄인다)List of renderbuffer internal formats. (reduced to a count every format accepts)
반환Returnsnumber 기기가 받는 표본 수. (2 밑이면 0)Sample count the device accepts. (0 when below 2)
짝Counterpart: vanilla-engine RenderTarget.read_supported_sample_count
멀티샘플을 텍스처로 풀기. (컬러 어태치먼트마다와 깊이 텍스처, 묶여 있던 프레임버퍼로 돌림)
- 푼 뒤에도 멀티샘플 색과 깊이는 그대로 남는다. (invalidateFramebuffer 로 버리지 않는다, 아이패드와 아이폰 사파리에서 프레임마다 수 ~ 수십 ms 가 붙고 이득이 재어지지 않았다)
Resolves multisample into textures. (For each color attachment and the depth texture, restores the previously bound framebuffer)
- The multisample color and depth stay as they are after resolving. (They are not discarded with invalidateFramebuffer, which added several to tens of ms per frame in Safari on iPad and iPhone and showed no measured gain)
- isAttachmentKeptboolean
- 더는 쓰지 않는다. (옛 꼴과 맞추려고 남김, 어느 쪽이든 푼 뒤에 멀티샘플 색과 깊이를 버리지 않는다)No longer used. (Kept to match the old shape, either way the multisample color and depth are not discarded after resolving)
짝Counterpart: vanilla-engine RenderTarget.resolve
import { RenderTarget } from "./build/vanilla.js";
const canvas = document.createElement("canvas");
const webGL2RenderingContext = canvas.getContext("webgl2");
const renderTarget = new RenderTarget(webGL2RenderingContext, 128, 128, true, { sampleCount: 4 });
renderTarget.bind();
webGL2RenderingContext.clearColor(0.1, 0.2, 0.3, 1.0);
webGL2RenderingContext.clear(webGL2RenderingContext.COLOR_BUFFER_BIT | webGL2RenderingContext.DEPTH_BUFFER_BIT);
renderTarget.resolve(true);
renderTarget.bind();
renderTarget.resolve();
webGL2RenderingContext.bindFramebuffer(webGL2RenderingContext.FRAMEBUFFER, null);
console.log(renderTarget.getSampleCount());렌더링 대상으로 바인드. (프레임버퍼 + 뷰포트)
Binds as the rendering target. (framebuffer + viewport)
짝Counterpart: vanilla-engine RenderTarget.bind
파괴. (GL 리소스 해제)
Destroy. (Releases GL resources)
짝Counterpart: vanilla-engine RenderTarget.destroy
멀티샘플 프레임버퍼와 렌더버퍼 지우기.
Deletes the multisample framebuffer and renderbuffers.
렌더링 컨텍스트 반환.
Returns the rendering context.
반환ReturnsWebGL2RenderingContext 렌더링 컨텍스트.Rendering context.
프레임버퍼 반환. (그리는 프레임버퍼, 멀티샘플이면 멀티샘플 프레임버퍼)
Returns the framebuffer. (The framebuffer that is drawn into, the multisample framebuffer when multisampled)
반환ReturnsWebGLFramebuffer | null 그리는 프레임버퍼. (멀티샘플이면 멀티샘플 프레임버퍼, 파괴 뒤면 null)Framebuffer to draw into. (the multisample framebuffer when multisampled, null after destroy)
짝Counterpart: vanilla-engine RenderTarget.get_framebuffer
텍스처가 붙은 프레임버퍼 반환. (멀티샘플이 아니면 getFramebuffer 와 같음)
Returns the framebuffer with the textures attached. (Same as getFramebuffer if not multisampled)
반환ReturnsWebGLFramebuffer | null 컬러 텍스처가 붙은 프레임버퍼. (파괴 뒤면 null)Framebuffer with the color textures attached. (null after destroy)
짝Counterpart: vanilla-engine RenderTarget.get_resolve_framebuffer
실제로 지은 표본 수 반환. (0 이면 멀티샘플 없음)
Returns the sample count actually built. (0 means no multisampling)
반환Returnsnumber 실제로 지은 표본 수. (0 이면 멀티샘플 없음)Sample count actually built. (0 means no multisampling)
짝Counterpart: vanilla-engine RenderTarget.get_sample_count
깊이 렌더버퍼 비트 수 반환. (16 이나 24)
Returns the depth renderbuffer bit count. (16 or 24)
반환Returnsnumber 깊이 렌더버퍼 비트 수. (16 이나 24)Depth renderbuffer bit count. (16 or 24)
짝Counterpart: vanilla-engine RenderTarget.get_depth_bits
컬러 텍스처 반환. (어태치먼트 인덱스, 기본 0)
Returns the color texture. (attachment index, default 0)
- attachmentIndexnumber
- 컬러 어태치먼트 번호. (기본 0)Color attachment index. (default 0)
반환ReturnsWebGLTexture | null 컬러 텍스처. (번호가 범위 밖이면 null)Color texture. (null when the index is out of range)
짝Counterpart: vanilla-engine RenderTarget.get_color_texture
깊이 텍스처 반환. (useDepthTexture 옵션일 때만 존재)
Returns the depth texture. (Exists only with the useDepthTexture option)
반환ReturnsWebGLTexture | null 깊이 텍스처. (useDepth 와 useDepthTexture 를 함께 켰을 때만, 아니면 null)Depth texture. (only when both useDepth and useDepthTexture are on, otherwise null)
짝Counterpart: vanilla-engine RenderTarget.get_depth_texture
컬러 어태치먼트 개수 반환.
Returns the color attachment count.
반환Returnsnumber 컬러 어태치먼트 개수.Number of color attachments.
짝Counterpart: vanilla-engine RenderTarget.get_color_attachment_count
실수 컬러 사용 여부 반환.
Returns whether float color is used.
반환Returnsboolean 컬러가 RGBA16F 면 참.True when the color is RGBA16F.
짝Counterpart: vanilla-engine RenderTarget.get_use_float_color
깊이 텍스처 사용 여부 반환.
Returns whether the depth texture is used.
반환Returnsboolean 깊이 텍스처를 쓰면 참.True when a depth texture is used.
짝Counterpart: vanilla-engine RenderTarget.get_use_depth_texture
가로 크기 반환.
Returns the width.
반환Returnsnumber 가로 크기. (픽셀, 파괴 뒤면 0)Width. (pixels, 0 after destroy)
짝Counterpart: vanilla-engine RenderTarget.get_width
세로 크기 반환.
Returns the height.
반환Returnsnumber 세로 크기. (픽셀, 파괴 뒤면 0)Height. (pixels, 0 after destroy)
짝Counterpart: vanilla-engine RenderTarget.get_height