webgl

package
v0.0.0-...-0b38cba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 5 Imported by: 0

README

Very rough half-finished WebGL wrapper.

TODO: try out g3n

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAttribs

func CreateAttribs(gl *GL, data ObjectData) (map[string]*Attrib, error)

Types

type Attrib

type Attrib struct {
	Name string
	// Only needed when creating setters
	//Location      js.Value
	Buffer        *Buffer
	NumComponents int
	Type          GLType
	Normalize     bool
	Offset        int
	Stride        int
}

Attrib is shader attribute

func CreateAttrib

func CreateAttrib(gl *GL, name string, arr array.TypedArray, numComponents int, typ GLType) (*Attrib, error)

CreateAttrib from array

type Attribs

type Attribs map[string]*Attrib

Attribs map

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

func CreateBuffer

func CreateBuffer(gl *GL, arr array.TypedArray, bufType, drawType GLType) (*Buffer, error)

CreateBuffer from js typed array Default bufferType should be gl.Types.ArrayBuffer Default drawType should be gl.Types.StaticDraw

func (*Buffer) JSValue

func (b *Buffer) JSValue() js.Value

type BufferInfo

type BufferInfo struct {
	NumElements   int
	IndicesBuffer *Buffer
	Attribs       Attribs
}

func CreateBufferInfo

func CreateBufferInfo(gl *GL, data ObjectData) (*BufferInfo, error)

type GL

type GL struct {
	Types  GLTypes
	Width  GLType
	Height GLType
	// contains filtered or unexported fields
}

GL wrapper for WebGL

func NewGL

func NewGL(canvas js.Value) (*GL, error)

NewGL tries to get a new context

func (*GL) Ctx

func (gl *GL) Ctx() js.Value

Ctx of webgl

func (*GL) UniformMatrix4fv

func (gl *GL) UniformMatrix4fv(uniform Uniform, transform mgl32.Mat4)

UniformMatrix4fv wrapper.

type GLContext

type GLContext interface {
	Call(m string, args ...any) js.Value
}

GLContext specifies interface for calling the underlying GL implementation.

type GLType

type GLType int

func (GLType) JSValue

func (t GLType) JSValue() js.Value

type GLTypes

type GLTypes struct {
	StaticDraw         GLType
	ArrayBuffer        GLType
	ElementArrayBuffer GLType
	VertexShader       GLType
	FragmentShader     GLType
	DepthTest          GLType
	ColorBufferBit     GLType
	DepthBufferBit     GLType
	Triangles          GLType
	UnsignedShort      GLType
	UnsignedByte       GLType
	LineLoop           GLType
	CompileStatus      GLType
	LinkStatus         GLType
	Float              GLType
	FloatVec2          GLType
	FloatVec3          GLType
	FloatVec4          GLType
	Int                GLType
	IntVec2            GLType
	IntVec3            GLType
	IntVec4            GLType
	Bool               GLType
	BoolVec2           GLType
	BoolVec3           GLType
	BoolVec4           GLType
	FloatMat2          GLType
	FloatMat3          GLType
	FloatMat4          GLType
	Sampler2D          GLType
	SamplerCube        GLType
	Texture2D          GLType
	TextureCubeMap     GLType
	Texture0           GLType
	ActiveUniforms     GLType
	ActiveAttributes   GLType
	Rgba               GLType
	TextureMinFilter   GLType
	TextureMagFilter   GLType
	Nearest            GLType
	LEqual             GLType
}

GLTypes provides WebGL bindings.

type ObjectData

type ObjectData struct {
	// vec4 in shader?
	Positions []float32
	Normals   []float32
	TexCoords []float32
	Indices   []uint16
}

ObjectData vertices

type Program

type Program struct {
	UniformSetters map[string]func(gl *GL, val any)
	AttribMap      map[string]js.Value
	AttribSetters  map[string]func(*Attrib)
	// contains filtered or unexported fields
}

Program is a shader program.

func CreateProgram

func CreateProgram(gl *GL, vertShaderSrc, fragShaderSrc string, attribs []string) (*Program, error)

CreateProgram creates a new program from shader sources.

func (*Program) JSValue

func (p *Program) JSValue() js.Value

JSValue returns the js value.

func (*Program) SetAttributes

func (p *Program) SetAttributes(gl *GL, bufferInfo *BufferInfo)

func (*Program) SetBuffersAndAttributes

func (p *Program) SetBuffersAndAttributes(gl *GL, bufferInfo *BufferInfo)

type Shader

type Shader struct {
	// contains filtered or unexported fields
}

Shader represents a WebGL shader.

func CreateShader

func CreateShader(gl *GL, src string, typ GLType) (s Shader, err error)

CreateShader creates and compiles a WebGLShader.

func (Shader) JSValue

func (s Shader) JSValue() js.Value

JSValue the js value.

type ShaderProgram

type ShaderProgram struct {
	Uniforms map[string]Uniform
	// contains filtered or unexported fields
}

func CreateShaderProgram

func CreateShaderProgram(gl *GL, vertShader Shader, fragShader Shader) (p ShaderProgram, err error)

func (*ShaderProgram) JSValue

func (p *ShaderProgram) JSValue() js.Value

type Uniform

type Uniform struct {
	// contains filtered or unexported fields
}

func NewUniform

func NewUniform(name string, location js.Value, size int, glType GLType) Uniform

func (Uniform) Location

func (u Uniform) Location() js.Value

type UniformInfo

type UniformInfo struct {
	Name string
	Size GLType
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL