render (display) geometry buffers on F3 via ImGUI

This commit is contained in:
Edgaru089 2022-02-10 19:59:58 +08:00
parent 06cd549eb7
commit a17a43505c

View File

@ -7,6 +7,7 @@ import (
"unsafe" "unsafe"
"edgaru089.ml/go/gl01/internal/asset" "edgaru089.ml/go/gl01/internal/asset"
"edgaru089.ml/go/gl01/internal/igwrap"
"edgaru089.ml/go/gl01/internal/io" "edgaru089.ml/go/gl01/internal/io"
"edgaru089.ml/go/gl01/internal/util" "edgaru089.ml/go/gl01/internal/util"
"edgaru089.ml/go/gl01/internal/util/itype" "edgaru089.ml/go/gl01/internal/util/itype"
@ -269,6 +270,10 @@ func (r *WorldRenderer) Init(w *world.World) (err error) {
// attach textures // attach textures
r.output.shader.SetUniformTextureHandle("tex", r.output.tex) r.output.shader.SetUniformTextureHandle("tex", r.output.tex)
// set the texture flags for ImGUI
igwrap.SetTextureFlag(r.gbuffer.color, igwrap.TextureFlag_Linear)
igwrap.SetTextureFlag(r.ssao.ambient, igwrap.TextureFlag_Red)
gl.BindFramebuffer(gl.FRAMEBUFFER, 0) gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
r.lastDisplaySize = io.DisplaySize r.lastDisplaySize = io.DisplaySize
r.startTime = time.Now() r.startTime = time.Now()
@ -421,8 +426,22 @@ func (r *WorldRenderer) Render(world *world.World, view *View) {
DrawScreenQuad() DrawScreenQuad()
// Show G-buffers? // Show G-buffers?
/*if io.ShowDebugInfo { if io.ShowDebugInfo {
DrawTexture(r.gbuffer.pos, itype.Rectf{0.5, 0.5, 0.5, 0.5}, DrawTextureChannels_R|DrawTextureChannels_G|DrawTextureChannels_B, 0, 32) imgui.SetNextWindowPosV(imgui.Vec2{X: float32(r.lastDisplaySize[0]), Y: 0}, imgui.ConditionAlways, imgui.Vec2{X: 1, Y: 0})
DrawTexture(r.gbuffer.depth, itype.Rectf{0.5, 0, 0.5, 0.5}, DrawTextureChannels_R, 0, 1) if igwrap.Begin("Renderer Textures/Outputs", nil, imgui.WindowFlagsAlwaysAutoResize|imgui.WindowFlagsNoBackground|imgui.WindowFlagsNoNavFocus|imgui.WindowFlagsNoDecoration|imgui.WindowFlagsNoInputs|imgui.WindowFlagsNoSavedSettings|imgui.WindowFlagsNoFocusOnAppearing) {
}*/ imgui.PushStyleVarVec2(imgui.StyleVarItemSpacing, imgui.Vec2{})
imageSize := r.lastDisplaySize.ToFloat32().Multiply(0.25)
imageSize[1] -= imgui.CurrentStyle().WindowPadding().Y / 2
imageSize[0] = imageSize[1] / float32(r.lastDisplaySize[1]) * float32(r.lastDisplaySize[0])
igwrap.Image(r.gbuffer.pos, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.gbuffer.norm, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.gbuffer.color, imageSize, itype.Rectf{0, 0, 1, 1})
igwrap.Image(r.ssao.ambient, imageSize, itype.Rectf{0, 0, 1, 1})
imgui.PopStyleVar()
imgui.End()
}
}
} }