Exemple #1
0
func NewRenderer(bufferSize int) (r *Renderer, err error) {
	var (
		instance       renderInstance
		instanceStride = unsafe.Sizeof(instance)
	)
	r = &Renderer{
		shader:     core.NewProgram(),
		bufferSize: bufferSize,
		buffer:     make([]renderInstance, bufferSize),
		stride:     instanceStride,
	}
	if err = r.shader.Load(VERTEX, FRAGMENT); err != nil {
		return
	}
	r.shader.Bind()

	r.vbo = core.NewArrayBuffer()

	r.shader.Attrib("f_InstanceFrame", instanceStride).Float(unsafe.Offsetof(instance.frame), 1)
	r.shader.Attrib("m_Model", instanceStride).Mat4(unsafe.Offsetof(instance.model), 1)
	r.shader.Attrib("v_Color", instanceStride).Vec4(unsafe.Offsetof(instance.color), 1)

	r.textureData = r.shader.UniformBlock("TextureData", 1)

	r.uView = r.shader.Uniform("m_View")
	r.uProj = r.shader.Uniform("m_Projection")

	if e := gl.GetError(); e != 0 {
		err = fmt.Errorf("ERROR: OpenGL error %X", e)
	}
	return
}
Exemple #2
0
func NewGeometry(capacity int) (out *Geometry) {
	var (
		point  Point
		stride uintptr = unsafe.Sizeof(point)
	)
	out = &Geometry{
		Points: make([]Point, 0, capacity),
		Dirty:  true,
		stride: stride,
		vbo:    core.NewArrayBuffer(),
	}
	return
}