-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec0de76
commit 0ed53eb
Showing
1 changed file
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import Resource from './Resource'; | ||
import Renderer from './Renderer'; | ||
|
||
export interface RenderBufferOptions { | ||
width: number; | ||
height: number; | ||
|
||
format: GLenum; | ||
} | ||
|
||
export default class RenderBuffer extends Resource<RenderBufferOptions> { | ||
public width: number; | ||
|
||
public height: number; | ||
|
||
#internalFormat: GLenum; | ||
|
||
constructor (renderer: Renderer, options: RenderBufferOptions = {} as RenderBufferOptions) { | ||
super(renderer, { | ||
...options, | ||
format: options.format || renderer.gl.DEPTH_COMPONENT16, | ||
}); | ||
|
||
this.#internalFormat = this.options.format as GLenum; | ||
|
||
this.width = this.options.width as number; | ||
this.height = this.options.height as number; | ||
|
||
console.assert( | ||
this.width > 0 && this.height > 0, | ||
'Renderbuffer object requires valid width and height greater than zero' | ||
); | ||
this.bind(); | ||
renderer.gl.renderbufferStorage(renderer.gl.RENDERBUFFER, this.#internalFormat, this.width, this.height); | ||
} | ||
|
||
resize (width, height) { | ||
if (width === this.width && height === this.height) return; | ||
this.bind(); | ||
this.gl.renderbufferStorage(this.gl.RENDERBUFFER, this.#internalFormat, width, height); | ||
this.unbind(); | ||
} | ||
|
||
bind () { | ||
this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, this.handle); | ||
} | ||
|
||
unbind () { | ||
this.gl.bindRenderbuffer(this.gl.RENDERBUFFER, null); | ||
} | ||
|
||
destroy () { | ||
this.unbind(); | ||
this.deleteHandle(); | ||
} | ||
|
||
createHandle () { | ||
return this.gl.createRenderbuffer(); | ||
} | ||
|
||
deleteHandle () { | ||
this.handle && this.gl.deleteRenderbuffer(this.handle); | ||
} | ||
} |