2022-01-22 23:06:41 +08:00
|
|
|
package render
|
|
|
|
|
|
|
|
import (
|
|
|
|
"unsafe"
|
|
|
|
|
|
|
|
"github.com/go-gl/gl/all-core/gl"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
screenQuadVerts = []float32{
|
|
|
|
-1, -1,
|
2022-01-24 22:40:34 +08:00
|
|
|
0, 0,
|
2022-01-22 23:06:41 +08:00
|
|
|
1, -1,
|
2022-01-24 22:40:34 +08:00
|
|
|
1, 0,
|
|
|
|
1, 1,
|
2022-01-22 23:06:41 +08:00
|
|
|
1, 1,
|
|
|
|
-1, -1,
|
2022-01-24 22:40:34 +08:00
|
|
|
0, 0,
|
|
|
|
1, 1,
|
2022-01-22 23:06:41 +08:00
|
|
|
1, 1,
|
|
|
|
-1, 1,
|
2022-01-24 22:40:34 +08:00
|
|
|
0, 1,
|
2022-01-22 23:06:41 +08:00
|
|
|
}
|
|
|
|
screenQuadVAO uint32
|
|
|
|
screenQuadVBO uint32
|
|
|
|
)
|
|
|
|
|
|
|
|
func initScreenQuad() {
|
|
|
|
gl.GenBuffers(1, &screenQuadVBO)
|
|
|
|
gl.BindBuffer(gl.ARRAY_BUFFER, screenQuadVBO)
|
|
|
|
gl.BufferData(gl.ARRAY_BUFFER, int(unsafe.Sizeof(float32(0)))*len(screenQuadVerts), gl.Ptr(screenQuadVerts), gl.STATIC_DRAW)
|
|
|
|
|
|
|
|
gl.GenVertexArrays(1, &screenQuadVAO)
|
|
|
|
gl.BindVertexArray(screenQuadVAO)
|
|
|
|
|
2022-01-24 22:40:34 +08:00
|
|
|
gl.VertexAttribPointer(0, 2, gl.FLOAT, false, int32(4*unsafe.Sizeof(float32(0))), gl.PtrOffset(0))
|
|
|
|
gl.VertexAttribPointer(1, 2, gl.FLOAT, false, int32(4*unsafe.Sizeof(float32(0))), gl.PtrOffset(int(2*unsafe.Sizeof(float32(0)))))
|
2022-01-22 23:06:41 +08:00
|
|
|
gl.EnableVertexAttribArray(0)
|
2022-01-24 22:40:34 +08:00
|
|
|
gl.EnableVertexAttribArray(1)
|
2022-01-22 23:06:41 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// drawScreenQuad draws a Quad covering the entire screen.
|
|
|
|
//
|
|
|
|
// Attribute: vert: [ -1.0 --> 1.0]
|
|
|
|
func (r *WorldRenderer) drawScreenQuad() {
|
|
|
|
if screenQuadVAO == 0 {
|
|
|
|
initScreenQuad()
|
|
|
|
}
|
|
|
|
|
|
|
|
gl.Disable(gl.DEPTH_TEST)
|
|
|
|
gl.Disable(gl.CULL_FACE)
|
|
|
|
gl.BindVertexArray(screenQuadVAO)
|
|
|
|
gl.DrawArrays(gl.TRIANGLES, 0, 6)
|
|
|
|
}
|