refactor renderer resizes
This commit is contained in:
parent
203b77c32f
commit
5155008bf0
@ -293,6 +293,21 @@ func (r *WorldRenderer) Init(w *world.World) (err error) {
|
|||||||
// ResizeDisplay resizes the size of the internal buffers dependent on the window size.
|
// ResizeDisplay resizes the size of the internal buffers dependent on the window size.
|
||||||
// It is called automatically most of the time.
|
// It is called automatically most of the time.
|
||||||
func (r *WorldRenderer) ResizeDisplay(newSize itype.Vec2i) {
|
func (r *WorldRenderer) ResizeDisplay(newSize itype.Vec2i) {
|
||||||
|
gl.BindTexture(gl.TEXTURE_2D, r.gbuffer.pos) // G-Buffer, Position
|
||||||
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.FLOAT, nil)
|
||||||
|
gl.BindTexture(gl.TEXTURE_2D, r.gbuffer.norm) // G-Buffer, Normal
|
||||||
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.FLOAT, nil)
|
||||||
|
gl.BindTexture(gl.TEXTURE_2D, r.gbuffer.color) // G-Buffer, Albedo Color
|
||||||
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
|
||||||
|
gl.BindRenderbuffer(gl.RENDERBUFFER, r.gbuffer.depth) // G-Buffer, Depth (Renderbuffer)
|
||||||
|
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]))
|
||||||
|
gl.BindTexture(gl.TEXTURE_2D, r.ssao.ambient) // SSAO Output Ambient Strength
|
||||||
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RED, gl.UNSIGNED_BYTE, nil)
|
||||||
|
gl.BindTexture(gl.TEXTURE_2D, r.ssao.blur.output) // SSAO Blurred Output
|
||||||
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RED, gl.UNSIGNED_BYTE, nil)
|
||||||
|
gl.BindTexture(gl.TEXTURE_2D, r.output.tex) // Output Texture
|
||||||
|
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
|
||||||
|
r.lastDisplaySize = newSize
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -312,21 +327,7 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
|
|||||||
|
|
||||||
// re-generate the G-buffers if the display size changed
|
// re-generate the G-buffers if the display size changed
|
||||||
if r.lastDisplaySize != io.DisplaySize {
|
if r.lastDisplaySize != io.DisplaySize {
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.gbuffer.pos) // G-Buffer, Position
|
r.ResizeDisplay(io.DisplaySize)
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.FLOAT, nil)
|
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.gbuffer.norm) // G-Buffer, Normal
|
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA16F, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.FLOAT, nil)
|
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.gbuffer.color) // G-Buffer, Albedo Color
|
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
|
|
||||||
gl.BindRenderbuffer(gl.RENDERBUFFER, r.gbuffer.depth) // G-Buffer, Depth (Renderbuffer)
|
|
||||||
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]))
|
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.ssao.ambient) // SSAO Output Ambient Strength
|
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RED, gl.UNSIGNED_BYTE, nil)
|
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.ssao.blur.output) // SSAO Blurred Output
|
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RED, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RED, gl.UNSIGNED_BYTE, nil)
|
|
||||||
gl.BindTexture(gl.TEXTURE_2D, r.output.tex) // Output Texture
|
|
||||||
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(io.DisplaySize[0]), int32(io.DisplaySize[1]), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
|
|
||||||
r.lastDisplaySize = io.DisplaySize
|
|
||||||
}
|
}
|
||||||
|
|
||||||
imgui.SliderFloat3("Sun", &sun, -1, 1)
|
imgui.SliderFloat3("Sun", &sun, -1, 1)
|
||||||
|
Loading…
Reference in New Issue
Block a user