// Return size of array pointed to by s.Pointer(). func (s Vec2S) Sizeiptr() gl.Sizeiptr { if len(s) > 0 { return gl.Sizeiptr(int(s[0].Sizei()) * len(s)) } return gl.Sizeiptr(0) }
func display() { gl.ClearColor(0.19, 0.19, 0.21, 0) gl.ClearDepth(1) gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.UseProgram(theProgram) // Temporarily set the cam t clip id := gls.Identity() trans := getLookAtMatrix() // log.Println(trans) gls.UniformMatrix4fv(wtcm_unif, 1, false, trans) gls.UniformMatrix4fv(mtwm_unif, 1, false, id) // And here we do the actual rendering // Generate a name for vufferobj and store it gl.GenBuffers(1, &positionBufferObject) // Bind it to a target gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject) // Conver all nodes to a long array of vertexes! i := 0 // TODO: Fix this, based on 4 per eleemnts vpos := make([]float32, len(elements)*4*4) elms := make(map[uint32]mS, len(elements)) // Note that the order here is undefined! ii := 0 for k, v := range elements { elms[k] = mS{ii, len(v.Nodes())} for _, vv := range v.Nodes() { ii++ vpos[i] = float32(nodes[vv][0]) i++ vpos[i] = float32(nodes[vv][1]) i++ vpos[i] = float32(nodes[vv][2]) i++ vpos[i] = 1.0 i++ } } /* for _, v := range nodes { vpos[i] = float32(v[0]) i++ vpos[i] = float32(v[1]) i++ vpos[i] = float32(v[2]) i++ } */ gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(32/8*len(vpos)), (gl.Pointer)(&vpos[0]), gl.STATIC_DRAW) gl.BindBuffer(gl.ARRAY_BUFFER, 0) gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject) gl.EnableVertexAttribArray(0) gl.VertexAttribPointer(0, 4, gl.FLOAT, gl.FALSE, 0, (gl.Pointer)(nil)) /* for _,v := range elms { } */ for _, v := range elms { gl.DrawArrays(gl.LINE_LOOP, gl.Int(v.Start), gl.Sizei(v.Length)) } // Draw Coordinate acis /*for i := 9; i < 9+2*5; i += 2 { gl.DrawArrays(gl.LINE_STRIP, gl.Int(i), 2) }*/ }
func MakeAtomicCounters(glPtr *gl.Uint, num gl.Sizei) { gl.GenBuffers(1, glPtr) gl.BindBuffer(gl.ATOMIC_COUNTER_BUFFER, *glPtr) gl.BufferData(gl.ATOMIC_COUNTER_BUFFER, gl.Sizeiptr(4*num), gl.Pointer(nil), BufMode) gl.BindBuffer(gl.ATOMIC_COUNTER_BUFFER, 0) }
func glFillBuffer(vals []gl.Float, buf *gl.Uint) { gl.GenBuffers(1, buf) gl.BindBuffer(gl.ARRAY_BUFFER, *buf) gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(len(vals)*4), gl.Pointer(&vals[0]), gl.STATIC_DRAW) gl.BindBuffer(gl.ARRAY_BUFFER, 0) }
func MakeArrayBuffer(glPtr *gl.Uint, size uint64, sl interface{}, isLen, makeTex bool) gl.Uint { var ptr = gl.Pointer(nil) var glTex gl.Uint = 0 var glTexFormat gl.Enum = gl.R8UI var sizeFactor, sizeTotal uint64 = 1, 0 var tm = false var handle = func(sf uint64, glPtr gl.Pointer, le int, tf gl.Enum) { tm = true if le > 1 { ptr = glPtr } if size == 0 { size = uint64(le) isLen = true } if isLen { sizeFactor = sf } if tf != 0 { glTexFormat = tf } } if (sl == nil) && FillWithZeroes { sl = make([]uint8, size) } gl.GenBuffers(1, glPtr) gl.BindBuffer(gl.ARRAY_BUFFER, *glPtr) if sl != nil { if tv, tb := sl.([]uint8); tb { handle(1, gl.Pointer(&tv[0]), len(tv), gl.R8UI) } if tv, tb := sl.([]uint16); tb { handle(2, gl.Pointer(&tv[0]), len(tv), gl.R16UI) } if tv, tb := sl.([]uint32); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32UI) } if tv, tb := sl.([]uint64); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32UI) } if tv, tb := sl.([]int8); tb { handle(1, gl.Pointer(&tv[0]), len(tv), gl.R8I) } if tv, tb := sl.([]int16); tb { handle(2, gl.Pointer(&tv[0]), len(tv), gl.R16I) } if tv, tb := sl.([]int32); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32I) } if tv, tb := sl.([]int64); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32I) } if tv, tb := sl.([]float32); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32F) } if tv, tb := sl.([]float64); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32F) } if tv, tb := sl.([]gl.Bitfield); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R8UI) } if tv, tb := sl.([]gl.Byte); tb { handle(1, gl.Pointer(&tv[0]), len(tv), gl.R8I) } if tv, tb := sl.([]gl.Ubyte); tb { handle(1, gl.Pointer(&tv[0]), len(tv), gl.R8UI) } if tv, tb := sl.([]gl.Ushort); tb { handle(2, gl.Pointer(&tv[0]), len(tv), gl.R16UI) } if tv, tb := sl.([]gl.Short); tb { handle(2, gl.Pointer(&tv[0]), len(tv), gl.R16I) } if tv, tb := sl.([]gl.Uint); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32UI) } if tv, tb := sl.([]gl.Uint64); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32UI) } if tv, tb := sl.([]gl.Int); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32I) } if tv, tb := sl.([]gl.Int64); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32I) } if tv, tb := sl.([]gl.Clampd); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32F) } if tv, tb := sl.([]gl.Clampf); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32F) } if tv, tb := sl.([]gl.Float); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32F) } if tv, tb := sl.([]gl.Half); tb { handle(2, gl.Pointer(&tv[0]), len(tv), gl.R16F) } if tv, tb := sl.([]gl.Double); tb { handle(8, gl.Pointer(&tv[0]), len(tv), gl.RG32F) } if tv, tb := sl.([]gl.Enum); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32I) } if tv, tb := sl.([]gl.Sizei); tb { handle(4, gl.Pointer(&tv[0]), len(tv), gl.R32UI) } if tv, tb := sl.([]gl.Char); tb { handle(1, gl.Pointer(&tv[0]), len(tv), gl.R8UI) } if !tm { log.Panicf("MakeArrayBuffer() -- slice type unsupported:\n%+v", sl) } } sizeTotal = size * sizeFactor gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(sizeTotal), ptr, BufMode) if makeTex { if sizeTotal > MaxTextureBufferSize() { log.Panicf("Texture buffer size (%vMB) would exceed your GPU's maximum texture buffer size (%vMB)", sizeTotal/MB, maxTexBufSize/MB) } gl.GenTextures(1, &glTex) gl.BindTexture(gl.TEXTURE_BUFFER, glTex) gl.TexBuffer(gl.TEXTURE_BUFFER, glTexFormat, *glPtr) gl.BindTexture(gl.TEXTURE_2D, 0) } gl.BindBuffer(gl.ARRAY_BUFFER, 0) PanicIfErrors("MakeArrayBuffer()") return glTex }