Documentation
¶
Overview ¶
Camera helper functions
GL Helper Functions ¶
Shader GL Helper Functions
Index ¶
- Variables
- func BindBufferSubData[T mgl32.Mat4 | mgl32.Vec3](data []T, buffer uint32)
- func BindTexture(texID uint32)
- func BufferData[T float32](target uint32, data []T, usage uint32)
- func CheckShadersforChanges()
- func CreateComputeShader(source, sourceFile string) uint32
- func CreateFragmentShader(shaderFile string) (uint32, error)
- func CreateNewUniformBuffer[T mgl64.Mat4 | mgl64.Vec3](data []T, n int) uint32
- func CreateProgram(vertPath, fragPath string) (uint32, error)
- func CreateShader(ShaderSource string, ShaderType uint32) (uint32, error)
- func CreateVertexShader(shaderFile string) (uint32, error)
- func GenBindBuffers(target uint32) uint32
- func GenBindTexture() uint32
- func GenBindVertexArrays() uint32
- func InitSdlNoWindow() (*sdl.Window, sdl.GLContext)
- func LoadTexture(filePath string) uint32
- func PrintVersionGL()
- func SetUBO[T mgl64.Mat4 | mgl64.Vec3](data []T, UBOn uint32)
- func TriangleNormalCalc(p1, p2, p3 mgl32.Vec3) mgl32.Vec3
- type Camera
- type Direction
- type ShaderInfo
- type ShaderManager
- func InitShaderManager(shaderSource, sourceFile string) *ShaderManager[int32]
- func InitShaderManagerFloat(shaderSource, sourceFile string) *ShaderManager[float64]
- func InitShaderManagerUint(shaderSource, sourceFile string) *ShaderManager[uint32]
- func InitShaderManagerVec3(shaderSource, sourceFile string) *ShaderManager[mgl32.Vec4]
Constants ¶
This section is empty.
Variables ¶
var Verbose bool = ghf.Verbose
Functions ¶
func BindBufferSubData ¶
Sends a generic slice to a uniform buffer (UBO) for use in a shader block.
func BufferData ¶
Create and initialize buffer via generic slice (only takes float32 for now)
func CheckShadersforChanges ¶
func CheckShadersforChanges()
Checks to see if any of the loaded shaders have been modified, and if so recreates the program for that shader.
func CreateComputeShader ¶
func CreateFragmentShader ¶
Create fragment shader from path to glsl fragment shader source
- Returns shader ID as a uint32 if no errors
- Returns error if shader creation fails
func CreateNewUniformBuffer ¶
Makes a new uniform buffer on binding (n) set to the type and size of the (data)
Returns the uint32 ID of the created buffer
func CreateProgram ¶
Create and bind shader program via a vertex and fragment glsl source file path in that order.
- Returns shader ID as a uint32 if no errors
- Returns error if shader creation fails
func CreateShader ¶
Create shader via shader source file and shader type.
- Returns shader ID as a uint32 if no errors
- Returns error if shader creation fails
func CreateVertexShader ¶
Create vertex shader from path to glsl vertex shader source
- Returns shader ID as a uint32 if no errors
- Returns error if shader creation fails
func GenBindBuffers ¶
Generate and bind buffers, and return the ID as a uint32
func GenBindVertexArrays ¶
func GenBindVertexArrays() uint32
Generate and bind vertex arrays, and returns the ID as a uint32.
func LoadTexture ¶
Load a RGBA texture file via path, and returns a uint32 as texture ID
Types ¶
type Camera ¶
type Camera struct { Position mgl64.Vec3 Front mgl64.Vec3 Up mgl64.Vec3 Right mgl64.Vec3 WorldUp mgl64.Vec3 Yaw float64 Pitch float64 MovementAccel float64 MouseSens float64 Zoom float64 }
func NewCamera ¶
func NewCamera(camPosition, worldUp mgl64.Vec3, camYaw, camPitch, camAccel, mouseSens float64) *Camera
Setup camera
Inputs are as follows in order:
- Camera position as a Vec3
- World up direction as a Vec3
- Camera yaw as a float64 in degrees
- Camera pitch as a float64 in degrees
- Camera acceleration as a float64 as a multiplier
- Camera mouse sensitivity as a float64 as a multiplier
Returns a pointer to the camera struct
func (*Camera) GetViewMatrix ¶
Get the matrix of the object your looking at, and return it as a Mat4
func (*Camera) UpdateCamera ¶
Update the rotation and position of the camera
Inputs are as follows in order:
- Direction in which the camera should be going (Forward, Backward, Left, Right)
- The delta of the time or in other words the time of the frame as a float64
- The X offset in degrees as a float64
- The Y offset in degrees as a float64
type ShaderInfo ¶
type ShaderInfo struct {
// contains filtered or unexported fields
}
func NewShaderProgram ¶
func NewShaderProgram(vertexPath, fragmentPath string) (*ShaderInfo, error)
Creates a new shader program with a path to a glsl vertex shader, and fragment shader source, in that order
This is only meant to be used at start up
- Returns a pointer to the ShaderInfo struct or nil if error
- Returns a error or nil if none
type ShaderManager ¶
type ShaderManager[T int32 | float64 | uint32 | mgl32.Vec4] struct { Window *sdl.Window GLContext sdl.GLContext ShaderProgram uint32 }
ShaderManager holds reusable resources for compute shader execution
func InitShaderManager ¶
func InitShaderManager(shaderSource, sourceFile string) *ShaderManager[int32]
InitShaderManager initializes SDL, OpenGL, and compiles the shader
func InitShaderManagerFloat ¶
func InitShaderManagerFloat(shaderSource, sourceFile string) *ShaderManager[float64]
InitShaderManager initializes SDL, OpenGL, and compiles the shader
func InitShaderManagerUint ¶
func InitShaderManagerUint(shaderSource, sourceFile string) *ShaderManager[uint32]
InitShaderManager initializes SDL, OpenGL, and compiles the shader
func InitShaderManagerVec3 ¶
func InitShaderManagerVec3(shaderSource, sourceFile string) *ShaderManager[mgl32.Vec4]
InitShaderManager initializes SDL, OpenGL, and compiles the shader
func (*ShaderManager[T]) Cleanup ¶
func (sm *ShaderManager[T]) Cleanup()
Cleanup releases all resources used by the ShaderManager
func (*ShaderManager[T]) Execute ¶
func (sm *ShaderManager[T]) Execute(data []T, sizeWorkGP ...int) []T
Execute runs the compute shader with the provided data