Use bufferSubData and dynamic buffer in when drawing glyphs

This commit is contained in:
bloeys
2022-07-11 11:57:41 +04:00
parent 869bbe3efd
commit d70a31dd26

View File

@ -365,8 +365,9 @@ func (gr *GlyphRend) Draw() {
return return
} }
gr.InstancedBuf.SetData(gr.GlyphVBO[:gr.GlyphCount*floatsPerGlyph]) gl.BindVertexArray(gr.InstancedBuf.VAOID)
gr.InstancedBuf.Bind() gl.BindBuffer(gl.ARRAY_BUFFER, gr.InstancedBuf.BufID)
gl.BufferSubData(gl.ARRAY_BUFFER, 0, int(gr.GlyphCount*floatsPerGlyph)*4, gl.Ptr(&gr.GlyphVBO[:gr.GlyphCount*floatsPerGlyph][0]))
gr.GlyphMat.Bind() gr.GlyphMat.Bind()
//We need to disable depth testing so that nearby characters don't occlude each other //We need to disable depth testing so that nearby characters don't occlude each other
@ -551,6 +552,9 @@ func NewGlyphRend(fontFile string, fontOptions *truetype.Options, screenWidth, s
gl.VertexAttribPointer(5, scaleEle.ElementType.CompCount(), scaleEle.ElementType.GLType(), false, gr.InstancedBuf.Stride, gl.PtrOffset(scaleEle.Offset)) gl.VertexAttribPointer(5, scaleEle.ElementType.CompCount(), scaleEle.ElementType.GLType(), false, gr.InstancedBuf.Stride, gl.PtrOffset(scaleEle.Offset))
gl.VertexAttribDivisor(5, 1) gl.VertexAttribDivisor(5, 1)
//Fill buffer with zeros and set to dynamic so in the actual draw calls we use bufferSubData which makes things a lot faster
gl.BufferData(gl.ARRAY_BUFFER, len(gr.GlyphVBO)*4, gl.Ptr(&gr.GlyphVBO[0]), buffers.BufUsage_Dynamic.ToGL())
gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindBuffer(gl.ARRAY_BUFFER, 0)
gr.InstancedBuf.UnBind() gr.InstancedBuf.UnBind()