engine

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

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

Go to latest
Published: Oct 16, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Package engine provides an abstraction layer on top of OpenGL. It contains entities relevant for rendering.

Index

Constants

This section is empty.

Variables

View Source
var MAX_THETA = math.Pi - MIN_THETA
View Source
var MIN_THETA = 0.000001

Functions

func CheckGLError

func CheckGLError()

CheckGLError can be used after any interaction with OpenGL to grab the last error from the GPU.

Types

type Camera

type Camera interface {
	Update()
	Rotate(theta, phi float32)
	Zoom(distance float32)

	GetView() mgl32.Mat4
	GetPerspective() mgl32.Mat4
	GetViewPerspective() mgl32.Mat4
}

Camera abstracts a camera model with either perspective or orthographic projection.

type CameraFPS

type CameraFPS struct {
	Pos    mgl32.Vec3
	Target mgl32.Vec3
	Up     mgl32.Vec3
	Right  mgl32.Vec3
	Fov    float32
	Near   float32
	Far    float32
	// contains filtered or unexported fields
}

CameraFPS moves in the view direction while the viewing direction can be changed.

func MakeCameraFPS

func MakeCameraFPS(width, height int, pos mgl32.Vec3, speed, fov, near, far float32) CameraFPS

MakeDefaultCameraFPS creates a CameraFPS with the viewport of width and height and a radius from the origin. It assumes a field of view of 45 degrees and a near and far plane at 0.1 and 100.0 respectively.

func (*CameraFPS) GetOrtho

func (camera *CameraFPS) GetOrtho() mgl32.Mat4

GetOrtho returns the orthographic projection of the camera.

func (*CameraFPS) GetPerspective

func (camera *CameraFPS) GetPerspective() mgl32.Mat4

GetPerspective returns the perspective projection of the camera.

func (*CameraFPS) GetView

func (camera *CameraFPS) GetView() mgl32.Mat4

GetView returns the view matrix of the camera.

func (*CameraFPS) GetViewPerspective

func (camera *CameraFPS) GetViewPerspective() mgl32.Mat4

GetViewPerspective returns P*V.

func (*CameraFPS) OnCursorPosMove

func (camera *CameraFPS) OnCursorPosMove(x, y, dx, dy float64) bool

OnCursorPosMove is a callback handler that is called every time the cursor moves.

func (*CameraFPS) OnKeyPress

func (camera *CameraFPS) OnKeyPress(key, action, mods int) bool

OnKeyPress is a callback handler that is called every time a keyboard key is pressed.

func (*CameraFPS) OnMouseButtonPress

func (camera *CameraFPS) OnMouseButtonPress(leftPressed, rightPressed bool) bool

OnMouseButtonPress is a callback handler that is called every time a mouse button is pressed or released.

func (*CameraFPS) OnMouseScroll

func (camera *CameraFPS) OnMouseScroll(x, y float64) bool

OnMouseScroll is a callback handler that is called every time the mouse wheel moves.

func (*CameraFPS) Rotate

func (camera *CameraFPS) Rotate(theta, phi float32)

Rotate adds delta angles in degrees to the theta and phi angles. Where theta is the vertical angle and phi the horizontal angle.

func (*CameraFPS) SetPos

func (camera *CameraFPS) SetPos(pos mgl32.Vec3)

SetPos updates the target point of the camera. It requires to call Update to take effect.

func (*CameraFPS) Update

func (camera *CameraFPS) Update()

Update recalculates the position of the camera. Call it every time after calling Rotate or Zoom.

func (*CameraFPS) Zoom

func (camera *CameraFPS) Zoom(distance float32)

Zoom changes the radius of the camera to the target point.

type CameraTrackball

type CameraTrackball struct {
	Pos    mgl32.Vec3
	Target mgl32.Vec3
	Up     mgl32.Vec3
	Fov    float32
	Near   float32
	Far    float32
	// contains filtered or unexported fields
}

CameraTrackball moves on a sphere around a target point with a specified radius.

func MakeCameraTrackball

func MakeCameraTrackball(width, height int, radius float32, target mgl32.Vec3, fov, near, far float32) CameraTrackball

MakeCameraTrackball creates a CameraTrackball with the viewport of width and height, the radius from the target, the target position the camera is orbiting around, the field of view and the distance of the near and far plane.

func MakeDefaultCameraTrackball

func MakeDefaultCameraTrackball(width, height int, radius float32) CameraTrackball

MakeDefaultCameraTrackbal creates a CameraTrackball with the viewport of width and height and a radius from the origin. It assumes a field of view of 45 degrees and a near and far plane at 0.1 and 100.0 respectively.

func NewCameraTrackball

func NewCameraTrackball(width, height int, radius float32, target mgl32.Vec3, fov, near, far float32) *CameraTrackball

MakeCameraTrackball creates a reference to a CameraTrackball with the viewport of width and height, the radius from the target, the target position the camera is orbiting around, the field of view and the distance of the near and far plane.

func NewDefaultCameraTrackball

func NewDefaultCameraTrackball(width, height int, radius float32) *CameraTrackball

NewDefaultCameraTrackball creates a reference to a CameraTrackball with the viewport of width and height and a radius from the origin. It assumes a field of view of 45 degrees and a near and far plane at 0.1 and 100.0 respectively.

func (*CameraTrackball) GetOrtho

func (camera *CameraTrackball) GetOrtho() mgl32.Mat4

GetOrtho returns the orthographic projection of the camera.

func (*CameraTrackball) GetPerspective

func (camera *CameraTrackball) GetPerspective() mgl32.Mat4

GetPerspective returns the perspective projection of the camera.

func (*CameraTrackball) GetView

func (camera *CameraTrackball) GetView() mgl32.Mat4

GetView returns the view matrix of the camera.

func (*CameraTrackball) GetViewPerspective

func (camera *CameraTrackball) GetViewPerspective() mgl32.Mat4

GetViewPerspective returns P*V.

func (*CameraTrackball) OnCursorPosMove

func (camera *CameraTrackball) OnCursorPosMove(x, y, dx, dy float64) bool

OnCursorPosMove is a callback handler that is called every time the cursor moves.

func (*CameraTrackball) OnKeyPress

func (camera *CameraTrackball) OnKeyPress(key, action, mods int) bool

OnKeyPress is a callback handler that is called every time a keyboard key is pressed.

func (*CameraTrackball) OnMouseButtonPress

func (camera *CameraTrackball) OnMouseButtonPress(leftPressed, rightPressed bool) bool

OnMouseButtonPress is a callback handler that is called every time a mouse button is pressed or released.

func (*CameraTrackball) OnMouseScroll

func (camera *CameraTrackball) OnMouseScroll(x, y float64) bool

OnMouseScroll is a callback handler that is called every time the mouse wheel moves.

func (*CameraTrackball) Rotate

func (camera *CameraTrackball) Rotate(theta, phi float32)

Rotate adds delta angles in degrees to the theta and phi angles. Where theta is the vertical angle and phi the horizontal angle.

func (*CameraTrackball) SetPos

func (camera *CameraTrackball) SetPos(pos mgl32.Vec3)

SetPos updates the target point of the camera. It requires to call Update to take effect.

func (*CameraTrackball) Update

func (camera *CameraTrackball) Update()

Update recalculates the position of the camera. Call it every time after calling Rotate or Zoom.

func (*CameraTrackball) Zoom

func (camera *CameraTrackball) Zoom(distance float32)

Zoom changes the radius of the camera to the target point.

type Cube

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

Cube is a Renderable that can be specified with different dimensions..

func MakeCube

func MakeCube(halfWidth, halfHeight, halfDepth float32) Cube

MakeCube creates a Cube with the specified half width, height and depth.

func (Cube) Build

func (cube Cube) Build(shaderProgramHandle uint32)

Build prepares the vertex buffers for rendering. It is called by the RenderProgram after adding it using AddRenderable thus it is usually not advised to call it on your own.

func (*Cube) Delete

func (cube *Cube) Delete()

Delete destroys this Renderable.

func (Cube) Render

func (cube Cube) Render()

Render draws the geometry of this Renderable using the currently bound shader.

func (Cube) RenderInstanced

func (cube Cube) RenderInstanced(instancecount int32)

RenderInstanced draws the geometry of this Renderable multiple times according to the instancecount.

type CursorPosHandler

type CursorPosHandler func(float64, float64, float64, float64) bool

CursorPosHandler is called every time the cursor position changes.

type FBO

type FBO struct {
	ColorTextures []*Texture
	DepthTexture  *Texture
	// contains filtered or unexported fields
}

FBO can hold multiple color textues and up to one depth texture. It can be bound as alternative render target contrary to the default frame buffer.

func MakeEmptyFBO

func MakeEmptyFBO() FBO

MakeEmpty FBO creates an empty FBO that works as the default frame buffer.

func MakeFBO

func MakeFBO(width, height int32) FBO

MakeFBO creates an FBO with one color and depth texture of the specified width and height.

func MakeMultisampleFBO

func MakeMultisampleFBO() FBO

MakeMultisampleFBO make an empty multisampled frame buffer.

func (*FBO) AttachColorTexture

func (fbo *FBO) AttachColorTexture(texture Texture, index uint32)

AttachColorTexture adds a color texture at the position specified by index.

func (*FBO) AttachDepthTexture

func (fbo *FBO) AttachDepthTexture(texture Texture)

AttachDepthTexture adds a depth texture to the FBO.

func (*FBO) Bind

func (fbo *FBO) Bind()

Bind sets this FBO as current render target.

func (*FBO) Clear

func (fbo *FBO) Clear()

Clear clears the color and depth buffer if this FBO has been bound before.

func (*FBO) CopyAttachmentColorToFBO

func (fbo *FBO) CopyAttachmentColorToFBO(other *FBO, index1, index2 uint32, x, y, width, height int32)

CopyAttachmentColorToFBO copies a color texture specified by index1 to the color texture of another FBO at index2.

func (*FBO) CopyAttachmentColorToFBORegionSmooth

func (fbo *FBO) CopyAttachmentColorToFBORegionSmooth(other *FBO, index1, index2 uint32, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyAttachmentColorToFBORegionSmooth copies a texture specfied by index2 within a region specified by the position (x1,y1) and width w1 and height h1 to the color texture of another FBO at index2 in the region (x2,y2) and the width w2 and height h2 using linear interpolation using linear interpolation.

func (*FBO) CopyAttachmentColorToFBOSmooth

func (fbo *FBO) CopyAttachmentColorToFBOSmooth(other *FBO, index1, index2 uint32, x, y, width, height int32)

CopyAttachmentColorToFBOSmooth copies a color texture specified by index1 to the color texture of another FBO at index2 using linear interpolation.

func (*FBO) CopyColorAttachmentToFBORegion

func (fbo *FBO) CopyColorAttachmentToFBORegion(other *FBO, index1, index2 uint32, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyColorAttachmentToFBORegion copies a texture specfied by index2 within a region specified by the position (x1,y1) and width w1 and height h1 to the color texture of another FBO at index2 in the region (x2,y2) and the width w2 and height h2 using linear interpolation.

func (*FBO) CopyColorToFBO

func (fbo *FBO) CopyColorToFBO(other *FBO, x, y, width, height int32)

CopyColorToFBO copies all color textures to another FBO.

func (*FBO) CopyColorToFBORegion

func (fbo *FBO) CopyColorToFBORegion(other *FBO, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyColorToFBORegion copies all color textures within a region specified by the position (x1,y1) and width w1 and height h1 to another FBO in the region (x2,y2) and the width w2 and height h2.

func (*FBO) CopyColorToFBORegionSmooth

func (fbo *FBO) CopyColorToFBORegionSmooth(other *FBO, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyColorToFBORegionSmooth copies all color textures within a region specified by the position (x1,y1) and width w1 and height h1 to another FBO in the region (x2,y2) and the width w2 and height h2 using linear interpolation.

func (*FBO) CopyColorToFBOSmooth

func (fbo *FBO) CopyColorToFBOSmooth(other *FBO, x, y, width, height int32)

CopyColorToFBOSmooth copies all color textures to another FBO using linear interpolation.

func (*FBO) CopyDepthToFBO

func (fbo *FBO) CopyDepthToFBO(other *FBO, x, y, width, height int32)

CopyDepthToFBO copies the depth texture to another FBO.

func (*FBO) CopyDepthToFBORegion

func (fbo *FBO) CopyDepthToFBORegion(other *FBO, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyDepthToFBORegion copies the depth texture within a region specified by the position (x1,y1) and width w1 and height h1 to another FBO in the region (x2,y2) and the width w2 and height h2.

func (*FBO) CopyToFBO

func (fbo *FBO) CopyToFBO(other *FBO, x, y, width, height int32)

CopyToFBO copies all color and depth textures to another FBO.

func (*FBO) CopyToFBORegion

func (fbo *FBO) CopyToFBORegion(other *FBO, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyToFBORegion copies all color and depth textures within a region specified by the position (x1,y1) and width w1 and height h1 to another FBO in the region (x2,y2) and the width w2 and height h2.

func (*FBO) CopyToScreen

func (fbo *FBO) CopyToScreen(index uint32, x, y, width, height int32)

CopyToScreen copies all color and depth textures to the default frame buffer.

func (*FBO) CopyToScreenRegion

func (fbo *FBO) CopyToScreenRegion(index uint32, x1, y1, w1, h1, x2, y2, w2, h2 int32)

CopyToScreenRegion copies all color and depth textures within a region specified by the position (x1,y1) and width w1 and height h1 to the default frame buffer in the region (x2,y2) and the width w2 and height h2.

func (*FBO) Delete

func (fbo *FBO) Delete()

Delete destroys this FBO and all associated color and depth textures.

func (*FBO) IsComplete

func (fbo *FBO) IsComplete() bool

Checks if the framebuffer is complete

func (*FBO) Unbind

func (fbo *FBO) Unbind()

Unbind sets the default frame buffer as current render target.

type Face

type Face struct {
	Vertices  []int
	Normals   []int
	Texcoords []int
}

Face specifies three or more vertices with vertex position, normal and texture coordinate.

type IBO

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

IBO contains indices to vertex attributes. It has to be used together with a VAO.

func MakeIBO

func MakeIBO(data []uint16, usage uint32) IBO

MakeIBO constructs an IBO with the indices specified in data and the usage.

func (*IBO) Delete

func (ibo *IBO) Delete()

Delete detroys this IBO.

type Image

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

Image holds image information of the data, dimensions and formats.

func MakeImage

func MakeImage(path string) (Image, error)

MakeImage loads an Image from the specified path.

type Interactable

type Interactable interface {
	OnCursorPosMove(x, y, dx, dy float64) bool
	OnMouseButtonPress(leftPressed, rightPressed bool) bool
	OnMouseScroll(x, y float64) bool
	OnKeyPress(key, action, mods int) bool
}

Interactable is an entity that listens to different events and reacts to them.

type KeyPressHandler

type KeyPressHandler func(int, int, int) bool

KeyPressHandler is called every time a keyboard key is pressed of released.

type Mesh

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

Mesh holds the geometry of the object.

func MakeEmptyMesh

func MakeEmptyMesh(mode uint32) Mesh

MakeEmptyMesh constructs a Mesh without any geometry specified.

func MakeMesh

func MakeMesh(filepath string, mode uint32) (Mesh, error)

MakeMesh loads an .obj file and constructs a Mesh.

func MakeMeshFromArrays

func MakeMeshFromArrays(positions, normals, texcoords []float32, pname, nname, tname string, pcount, ncount, tcount uint32, mode uint32) (Mesh, error)

MakeMeshFromArrays constructs a Mesh with vertex positions, normals and texture coordinates. Normals and texture coordinates can be set to Nil if they are not required.

func MakeSimpleMesh

func MakeSimpleMesh(positions []float32, pcount uint32, mode, usage uint32) (Mesh, error)

MakeSimpleMesh constructs a Mesh that only has vertex positions.

func (Mesh) Build

func (mesh Mesh) Build(shaderProgramHandle uint32)

Build is called by the Shader. It sets up it's buffers.

func (*Mesh) Delete

func (mesh *Mesh) Delete()

Delete destroy the Mesh and it's buffers.

func (*Mesh) GetVAO

func (mesh *Mesh) GetVAO() *VAO

GetVAO returns a pointer to the VAO.

func (Mesh) Render

func (mesh Mesh) Render()

Render draws the Mesh using the currently bound Shader.

func (Mesh) RenderInstanced

func (mesh Mesh) RenderInstanced(instancecount int32)

RenderInstanced draws the Mesh multiple times specified by instancecount using the currently bound Shader.

func (*Mesh) SetVAO

func (mesh *Mesh) SetVAO(vao VAO)

SetVAO updates the VAO.

type MouseButtonHandler

type MouseButtonHandler func(bool, bool) bool

MouseButtonHandler is called every time the left or right mouse button is pressed or released.

type MouseScrollHandler

type MouseScrollHandler func(float64, float64) bool

MouseScrollHandler is called every time the mouse scroll is used.

type Obj

type Obj struct {
	Vertices  []float32
	Normals   []float32
	Texcoords []float32
}

Obj contains vertices, normals and texture coordinates.

func LoadObj

func LoadObj(filepath string) (Obj, error)

LoadObj load an Obj from the specified filepath.

type RawImageData

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

RawImageData stores the image data on the CPU.

func MakeRawImageData

func MakeRawImageData(path string) (RawImageData, error)

MakeRawImageData loads the raw image data from the specified path.

func (*RawImageData) GetA

func (data *RawImageData) GetA(x, y int32) uint8

GetA returns the alpha value of the pixel at (x,y).

func (*RawImageData) GetB

func (data *RawImageData) GetB(x, y int32) uint8

GetB returns the blue value of the pixel at (x,y).

func (*RawImageData) GetG

func (data *RawImageData) GetG(x, y int32) uint8

GetG returns the green value of the pixel at (x,y).

func (*RawImageData) GetHeight

func (data *RawImageData) GetHeight() int32

GetHeight returns the height of the image.

func (*RawImageData) GetR

func (data *RawImageData) GetR(x, y int32) uint8

GetR returns the red value of the pixel at (x,y).

func (*RawImageData) GetRGB

func (data *RawImageData) GetRGB(x, y int32) (uint8, uint8, uint8)

GetRGB returns the RGB values of the pixel at (x,y).

func (*RawImageData) GetRGBA

func (data *RawImageData) GetRGBA(x, y int32) (uint8, uint8, uint8, uint8)

GetRGBA returns the RGBA value of the pixel at (x,y).

func (*RawImageData) GetWidth

func (data *RawImageData) GetWidth() int32

GetWidth returns the width of the image.

func (*RawImageData) SetA

func (data *RawImageData) SetA(x, y int32, a uint8)

SetA sets the alpha value of the pixel at (x,y).

func (*RawImageData) SetB

func (data *RawImageData) SetB(x, y int32, b uint8)

SetB sets the blue value of the pixel at (x,y).

func (*RawImageData) SetG

func (data *RawImageData) SetG(x, y int32, g uint8)

SetG sets the green value of the pixel at (x,y).

func (*RawImageData) SetR

func (data *RawImageData) SetR(x, y int32, r uint8)

SetR sets the red value of the pixel at (x,y).

func (*RawImageData) SetRGB

func (data *RawImageData) SetRGB(x, y int32, r, g, b uint8)

SetRGB sets the RGB values of the pixel at (x,y).

func (*RawImageData) SetRGBA

func (data *RawImageData) SetRGBA(x, y int32, r, g, b, a uint8)

SetRGBA sets the RGBA values of the pixel at (x,y).

type Renderable

type Renderable interface {
	Build(shaderProgramHandle uint32)
	Render()
	RenderInstanced(instancecount int32)
}

Renderable is an object that can be drawn by a renderer.

type SSBO

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

SSBO is a buffer that can hold different kinds of data. The typesize specifies the byte size of one element and len specifes the number of elements.

func MakeEmptySSBO

func MakeEmptySSBO(typesize int) SSBO

MakeEmptySSBO constructs a SSBO with the byte size of one element and a length of zero.

func MakeSSBO

func MakeSSBO(typesize, len int) SSBO

MakeSSBO constructs a SSBO with the byte size of one element and the number of elements.

func (*SSBO) Bind

func (ssbo *SSBO) Bind(pos int32)

Bind makes this buffer available at the specified position. The pos attribute has to coincide with the order of buffer within the shader.

func (*SSBO) Delete

func (ssbo *SSBO) Delete()

Delete destroys the SSBO and deletes the buffer data on the GPU.

func (*SSBO) Download

func (ssbo *SSBO) Download() []float32

Download returns a copy of the data on GPU.

func (*SSBO) GetHandle

func (ssbo *SSBO) GetHandle() uint32

GetHandle returns the handle to the buffer on the GPU.

func (*SSBO) Len

func (ssbo *SSBO) Len() int

Len returns the current size of the SSBO.

func (*SSBO) Resize

func (ssbo *SSBO) Resize(len int)

Resize changes the length of the buffer.

func (*SSBO) Unbind

func (ssbo *SSBO) Unbind()

Unbind makes this buffer unavailable for reading and writing.

func (*SSBO) UploadArray

func (ssbo *SSBO) UploadArray(values []float32)

UploadArray replaces the data on the GPU with the data in values. Make sure that the size of values matches the bytesize*len of the SSBO.

func (*SSBO) UploadArrayInRange

func (ssbo *SSBO) UploadArrayInRange(values []float32, start, len int)

UploadArray replaces the data on the GPU with the data in values in the range from start to start+len. Make sure that the size of values matches the bytesize*len specified in the arguments.

func (*SSBO) UploadValue

func (ssbo *SSBO) UploadValue(value []float32)

UploadValue fills the buffer with one element N times where N is the length of the buffer. Thus the length of value has to match the bytesize specified on construction of the SSBO.

func (*SSBO) UploadValueInRange

func (ssbo *SSBO) UploadValueInRange(value []float32, start, len int)

UploadValueInRange value fills the buffer with one element starting at start len times into this SSBO. Thus the length of value has to match the bytesize specified on construction of the SSBO.

type ShaderProgram

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

ShaderProgram represents a shader program object and contains all Renderables that share the same shader.

func MakeComputeProgram

func MakeComputeProgram(computeShaderPath string) (ShaderProgram, error)

MakeComputeProgram contrusts a ShaderProgram that consists of a compute shader.

func MakeGeomProgram

func MakeGeomProgram(vertexShaderPath, geometryShaderPath, fragmentShaderPath string) (ShaderProgram, error)

MakeGeomProgram contrusts a ShaderProgram that consists of a vertex, geometry and fragment shader.

func MakeProgram

func MakeProgram(vertexShaderPath, fragmentShaderPath string) (ShaderProgram, error)

MakeProgram contrusts a ShaderProgram that consists of a vertex and fragment shader.

func (*ShaderProgram) AddRenderable

func (shaderProgram *ShaderProgram) AddRenderable(renderable Renderable)

AddRenderable adds a Rendereable to the slices of Renderables that should be rendered.

func (*ShaderProgram) Compute

func (ShaderProgram *ShaderProgram) Compute(numgroupsx, numgroupsy, numgroupsz uint32)

Compute needs to be called when the shader is a compute shader. The group sizes of the compute shader have to specified in the x,y and z dimension. The dimensions need to be > 1.

func (*ShaderProgram) Delete

func (shaderProgram *ShaderProgram) Delete()

Delete deletes the OpenGL ShaderProgram handle.

func (*ShaderProgram) GetHandle

func (shaderProgram *ShaderProgram) GetHandle() uint32

Returns a handle to the ShaderProgram.

func (*ShaderProgram) RemoveAllRenderables

func (ShaderProgram *ShaderProgram) RemoveAllRenderables()

RemoveAllRenderables removes all Renderables.

func (*ShaderProgram) Render

func (shaderProgram *ShaderProgram) Render()

Render draws all Renderables that had been added to this ShaderProgram.

func (*ShaderProgram) RenderInstanced

func (shaderProgram *ShaderProgram) RenderInstanced(instancecount int32)

RenderInstances draws all Renderables each multiple times defined by instancecount.

func (*ShaderProgram) UpdateFloat32

func (shaderProgram *ShaderProgram) UpdateFloat32(uniformName string, f32 float32)

UpdateInt32 updates the value of an 32bit float in the shader.

func (*ShaderProgram) UpdateInt32

func (shaderProgram *ShaderProgram) UpdateInt32(uniformName string, i32 int32)

UpdateInt32 updates the value of an 32bit int in the shader.

func (*ShaderProgram) UpdateMat4

func (shaderProgram *ShaderProgram) UpdateMat4(uniformName string, mat mgl32.Mat4)

UpdateInt32 updates the value of an mat4 in the shader.

func (*ShaderProgram) UpdateVec2

func (shaderProgram *ShaderProgram) UpdateVec2(uniformName string, vec2 mgl32.Vec2)

UpdateInt32 updates the value of an vec2 in the shader.

func (*ShaderProgram) UpdateVec3

func (shaderProgram *ShaderProgram) UpdateVec3(uniformName string, vec3 mgl32.Vec3)

UpdateInt32 updates the value of an vec3 in the shader.

func (*ShaderProgram) Use

func (shaderProgram *ShaderProgram) Use()

Use binds the shader for rendering. Call it before calling Render.

type Skybox

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

Skybox is a cube of size 2 ranging from -1 to 1 in all three dimensions. It requires a cubemap as texture for its six sides.

func MakeSkybox

func MakeSkybox(cubeTexture Texture) Skybox

MakeSkybox constructs a Skybox object with the given cubemapTexture.

func (Skybox) Build

func (skybox Skybox) Build(shaderProgramHandle uint32)

Build prepares the vertex buffers for rendering. It is called by the RenderProgram after adding it using AddRenderable thus it is usually not advised to call it on your own.

func (*Skybox) Delete

func (skybox *Skybox) Delete()

Delete destroys this Renderable as well as the cubemapTexture.

func (Skybox) Render

func (skybox Skybox) Render()

Render draws the geometry of this Renderable using the currently bound shader.

func (Skybox) RenderInstanced

func (skybox Skybox) RenderInstanced(instancecount int32)

RenderInstanced draws the geometry of this Renderable multiple times according to the instancecount.

type Texture

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

Texture holds no to several images.

func MakeColorMultisampleTexture

func MakeColorMultisampleTexture(width, height, samples int32) Texture

MakeColorMultisampleTexture creates a multisample color texture of the given width and height and the number of samples that should be used.

func MakeColorTexture

func MakeColorTexture(width, height int32) Texture

MakeColorTexture creates a color texture of the specified size.

func MakeCubeMapTexture

func MakeCubeMapTexture(right, left, top, bottom, front, back string) (Texture, error)

MakeCupeMapTexture creates a cube map with the images specfied from the path.

func MakeDepthMultisampleTexture

func MakeDepthMultisampleTexture(width, height, samples int32) Texture

MakeDepthMultisampleTexture creates a multisample depth texture of the given width and height and the number of samples that should be used.

func MakeDepthTexture

func MakeDepthTexture(width, height int32) Texture

MakeDepthTexture creates a depth texture of the specfied size.

func MakeEmptyTexture

func MakeEmptyTexture() Texture

MakeEmptyTexture creates a Texture with no image data.

func MakeMultisampleTexture

func MakeMultisampleTexture(width, height, samples int32, format uint32, min, mag, s, t int32) Texture

MakeMultisampleTexture creates a multisample texture of the given width and height and the number of samples that should be used. Internalformat, format and pixelType specifed the layout of the data. Data is pointing to the data that is going to be uploaded. Min and mag specify the behaviour when down and upscaling the texture. S and t specify the behaviour at the borders of the image.

func MakeTexture

func MakeTexture(width, height, internalformat int32, format, pixelType uint32, data unsafe.Pointer, min, mag, s, t int32) Texture

MakeTexture creates a texture the given width and height. Internalformat, format and pixelType specifed the layout of the data. Data is pointing to the data that is going to be uploaded. Min and mag specify the behaviour when down and upscaling the texture. S and t specify the behaviour at the borders of the image.

func MakeTextureFromPath

func MakeTextureFromPath(path string) (Texture, error)

MakeTextureFromPath creates a texture with the image data specifed in path.

func (*Texture) Bind

func (tex *Texture) Bind(index uint32)

Bind makes the texure available at the specified position.

func (*Texture) Delete

func (tex *Texture) Delete()

Delete destroys the Texture.

func (*Texture) GenMipmap

func (tex *Texture) GenMipmap()

GenMipmap generates mipmap levels. Chooses the two mipmaps that most closely match the size of the pixel being textured and uses the GL_LINEAR criterion to produce a texture value.

func (*Texture) GenMipmapNearest

func (tex *Texture) GenMipmapNearest()

GenMipmap generates mipmap levels. Chooses the mipmap that most closely matches the size of the pixel being textured and uses the GL_LINEAR criterion to produce a texture value.

func (*Texture) Unbind

func (tex *Texture) Unbind()

Unbind makes the texture unavailable for reading.

type VAO

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

VAO is a buffer that holds multiple vertex buffers and zero to one index buffer.

func MakeVAO

func MakeVAO(mode uint32) VAO

Creates a new VAO. 'mode' specified the drawing mode used. Some modes would be TRIANGLE, TRIANGLE_STRIP, TRIANGLE_FAN

func (*VAO) AddIndexBuffer

func (vao *VAO) AddIndexBuffer(ibo *IBO)

AddIndexBuffer sets the index buffer.

func (*VAO) AddVertexBuffer

func (vao *VAO) AddVertexBuffer(vbo *VBO)

AddVertexBuffer adds a vertex buffer at the end.

func (*VAO) BuildBuffers

func (vao *VAO) BuildBuffers(shaderProgramHandle uint32)

BuildBuffers gets called by the Shader to setup all added buffers.

func (*VAO) Delete

func (vao *VAO) Delete()

Delete destroys this and all vertex and index buffers associated with this VAO.

func (*VAO) GetIndexBuffer

func (vao *VAO) GetIndexBuffer() *IBO

GetIndexBuffer returns the only index buffer.

func (*VAO) GetVertexBuffer

func (vao *VAO) GetVertexBuffer(idx int) *VBO

GetVertexBuffer returns the vertex buffer at the specifed index.

func (*VAO) Render

func (vao *VAO) Render()

Render draws the geometry. It uses indexed rendering if a index buffer is present.

func (*VAO) RenderInstanced

func (vao *VAO) RenderInstanced(instancecount int32)

RenderInstanced draws the geomtry multiple times defined by the instancecount. It uses indexed rendering if a index buffer is present.

type VBO

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

VBO is a buffer that stores vertex attributes.

func MakeVBO

func MakeVBO(data []float32, elementsPerVertex uint32, usage uint32) VBO

MakeVBO construct a VBO width the specified data and the size of one element. The usage gives the GPU a hint how to treat the data usage. Usage patterns are GL_STREAM_DRAW, GL_STREAM_READ, GL_STREAM_COPY, GL_STATIC_DRAW, GL_STATIC_READ, GL_STATIC_COPY, GL_DYNAMIC_DRAW, GL_DYNAMIC_READ, or GL_DYNAMIC_COPY

func (*VBO) AddVertexAttribute

func (vbo *VBO) AddVertexAttribute(name string, count int32, glType uint32)

AddVertexAttribute adds a new vertex layout for the given name the number of elements and the data type of the elements.

func (*VBO) BuildVertexAttributes

func (vbo *VBO) BuildVertexAttributes(shaderProgramHandle uint32)

BuildVertexAttributes is called by the shader and binds the vertex data to the variable specified by name.

func (*VBO) Delete

func (vbo *VBO) Delete()

Delete detroys this VBO and all vertex attributes.

func (*VBO) UpdateData

func (vbo *VBO) UpdateData(data []float32)

UpdateData replaces the previous data with this data. Make sure that the data follows the same layout as specified by the vertex attributes.

type VertexAttribute

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

VertexAttribute specifies the layout of the vertex buffer.

type WindowManager

type WindowManager struct {
	Window *glfw.Window
	Width  int
	Height int
	// contains filtered or unexported fields
}

WindowManager takes care of window creation and interaction.

func NewWindowManager

func NewWindowManager(title string, width, height int) (*WindowManager, error)

NewWindowManager returns a pointer to a WindowManager with the specified window title and window width and height.

func (*WindowManager) AddCursorPosHandler

func (windowManager *WindowManager) AddCursorPosHandler(handler CursorPosHandler)

AddCursorPosHandler registers a CursorPosHandler in the WindowManager.

func (*WindowManager) AddInteractable

func (windowManager *WindowManager) AddInteractable(interactable Interactable)

AddInteractable registers all handlers of the interactable in the Windowmanager.

func (*WindowManager) AddKeyPressHandler

func (windowManager *WindowManager) AddKeyPressHandler(handler KeyPressHandler)

AddKeyPressHandler registers a KeyPressHandler in the WindowManager.

func (*WindowManager) AddMouseButtonHandler

func (windowManager *WindowManager) AddMouseButtonHandler(handler MouseButtonHandler)

AddMouseButtonHandler registers a MouseButtonHandler in the WindowManager.

func (*WindowManager) AddMouseScrollHandler

func (windowManager *WindowManager) AddMouseScrollHandler(handler MouseScrollHandler)

AddMouseScrollHandler registers a MouseScrollHandler in the WindowManager.

func (*WindowManager) Close

func (windowManager *WindowManager) Close()

Close cleans up the WindowManager.

func (*WindowManager) EnableCursorLoop

func (windowManager *WindowManager) EnableCursorLoop()

EnableCursorLoop hides the cursor and loops it inside the window in x and y direction.

func (*WindowManager) GetFPS

func (windowManager *WindowManager) GetFPS() float64

GetFPS returns the fps of the previous frame.

func (*WindowManager) LockFPS

func (windowManager *WindowManager) LockFPS(fps float64)

LockFPS provides an upper bound for the FPS. The fps has to be greater than zero.

func (*WindowManager) RunMainLoop

func (windowManager *WindowManager) RunMainLoop(render func())

RunMainLoop calls the specified render function each frame until the window is being closed.

func (*WindowManager) SetClearColor

func (windowManager *WindowManager) SetClearColor(r, g, b float32)

SetClearColor updates the color used for a new frame and when clearing a FBO.

func (*WindowManager) SetTitle

func (windowManager *WindowManager) SetTitle(title string)

SetTitle updates the window title.

Jump to

Keyboard shortcuts

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