2014-08-26 14:03:00 +00:00
|
|
|
// Copyright 2014 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2014-09-17 22:07:50 +00:00
|
|
|
// +build !gldebug
|
|
|
|
|
2014-08-26 14:03:00 +00:00
|
|
|
package gl
|
|
|
|
|
|
|
|
//#cgo darwin LDFLAGS: -framework OpenGL
|
|
|
|
//#cgo linux LDFLAGS: -lGLESv2
|
|
|
|
//#include "gl2.h"
|
|
|
|
import "C"
|
2014-09-17 22:07:50 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"unsafe"
|
2014-08-26 14:03:00 +00:00
|
|
|
|
2014-09-17 22:07:50 +00:00
|
|
|
"code.google.com/p/go.mobile/f32"
|
2014-08-26 14:03:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Enum is equivalent to GLenum, and is normally used with one of the
|
|
|
|
// constants defined in this package.
|
|
|
|
type Enum uint32
|
|
|
|
|
2014-09-17 22:07:50 +00:00
|
|
|
// Types are defined a structs so that in debug mode they can carry
|
|
|
|
// extra information, such as a string name. See typesdebug.go.
|
|
|
|
|
|
|
|
// Attrib is an attribute index.
|
|
|
|
type Attrib struct {
|
|
|
|
Value uint
|
|
|
|
}
|
|
|
|
|
2014-08-26 14:03:00 +00:00
|
|
|
// Program identifies a compiled shader program.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Program struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
// Shader identifies a GLSL shader.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Shader struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
// Buffer identifies a GL buffer object.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Buffer struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
// Framebuffer identifies a GL framebuffer.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Framebuffer struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
// A Renderbuffer is a GL object that holds an image in an internal format.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Renderbuffer struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
// A Texture identifies a GL texture unit.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Texture struct {
|
|
|
|
Value uint32
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
// A Uniform identifies a GL uniform attribute value.
|
2014-09-17 22:07:50 +00:00
|
|
|
type Uniform struct {
|
|
|
|
Value int32
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteMat4 writes the contents of a 4x4 matrix to a GL uniform.
|
|
|
|
func (u Uniform) WriteMat4(m *f32.Mat4) {
|
|
|
|
UniformMatrix4fv(u, (*[16]float32)(unsafe.Pointer(m))[:])
|
|
|
|
}
|
|
|
|
|
|
|
|
// WriteVec4 writes the contents of a 4-element vector to a GL uniform.
|
|
|
|
func (u Uniform) WriteVec4(v *f32.Vec4) {
|
|
|
|
Uniform4f(u, v[0], v[1], v[2], v[3])
|
|
|
|
}
|
2014-08-26 14:03:00 +00:00
|
|
|
|
2014-09-17 22:07:50 +00:00
|
|
|
func (v Attrib) c() C.GLuint { return C.GLuint(v.Value) }
|
2014-08-26 14:03:00 +00:00
|
|
|
func (v Enum) c() C.GLenum { return C.GLenum(v) }
|
2014-09-17 22:07:50 +00:00
|
|
|
func (v Program) c() C.GLuint { return C.GLuint(v.Value) }
|
|
|
|
func (v Shader) c() C.GLuint { return C.GLuint(v.Value) }
|
|
|
|
func (v Buffer) c() C.GLuint { return C.GLuint(v.Value) }
|
|
|
|
func (v Framebuffer) c() C.GLuint { return C.GLuint(v.Value) }
|
|
|
|
func (v Renderbuffer) c() C.GLuint { return C.GLuint(v.Value) }
|
|
|
|
func (v Texture) c() C.GLuint { return C.GLuint(v.Value) }
|
|
|
|
func (v Uniform) c() C.GLint { return C.GLint(v.Value) }
|
2014-08-26 14:03:00 +00:00
|
|
|
|
|
|
|
func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d)", v) }
|
2014-09-17 22:07:50 +00:00
|
|
|
func (v Program) String() string { return fmt.Sprintf("Program(%d)", v.Value) }
|
|
|
|
func (v Shader) String() string { return fmt.Sprintf("Shader(%d)", v.Value) }
|
|
|
|
func (v Buffer) String() string { return fmt.Sprintf("Buffer(%d)", v.Value) }
|
|
|
|
func (v Framebuffer) String() string { return fmt.Sprintf("Framebuffer(%d)", v.Value) }
|
|
|
|
func (v Renderbuffer) String() string { return fmt.Sprintf("Renderbuffer(%d)", v.Value) }
|
|
|
|
func (v Texture) String() string { return fmt.Sprintf("Texture(%d)", v.Value) }
|
|
|
|
func (v Uniform) String() string { return fmt.Sprintf("Uniform(%d)", v.Value) }
|