func NewFloor(shader loader.Shader, reflected ...Drawable) Drawable { glctx := shader.Context() floor := NewStaticShape(glctx) floor.vertices = floorVertices floor.normals = floorNormals floor.Buffer() flipped := mgl.Scale3D(1, -1, 1) return &Floor{ Node: Node{ Shape: floor, transform: &flipped, shader: shader, }, reflected: reflected, } }
func NewSkybox(shader loader.Shader, texture gl.Texture) Drawable { glctx := shader.Context() skyboxShape := NewStaticShape(glctx) skyboxShape.vertices = skyboxVertices skyboxShape.indices = skyboxIndices skyboxShape.Buffer() skyboxShape.Texture = texture skybox := &Skybox{ Node: Node{ Shape: skyboxShape, shader: shader, }, } return skybox }
func (ctx *FrameContext) DrawContext(shader loader.Shader) DrawContext { r := DrawContext{ GL: ctx.GL, Camera: ctx.Camera, Shader: shader, } if ctx.activeShader != shader { shader.Use() ctx.activeShader = shader } if ctx.shaderCache == nil { ctx.shaderCache = map[loader.Shader]struct{}{shader: struct{}{}} ctx.bindShader(shader) } else if _, ok := ctx.shaderCache[shader]; !ok { ctx.bindShader(shader) } return r }
func (ctx *FrameContext) bindShader(shader loader.Shader) { cam, glctx := ctx.Camera, ctx.GL projection, view, position := cam.Projection(), cam.View(), cam.Position() glctx.UniformMatrix4fv(shader.Uniform("cameraPos"), position[:]) glctx.UniformMatrix4fv(shader.Uniform("view"), view[:]) glctx.UniformMatrix4fv(shader.Uniform("projection"), projection[:]) }