Example #1
0
func (r *EffectsRenderer) initFramebuffer(w, h int) (fb uint32, tex uint32, err error) {
	gl.GenFramebuffers(1, &fb)
	gl.BindFramebuffer(gl.FRAMEBUFFER, fb)

	gl.GenTextures(1, &tex)
	gl.BindTexture(gl.TEXTURE_2D, tex)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(w), int32(h), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)

	gl.FramebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0)
	if err = r.GetError(); err != nil {
		return
	}
	buffers := []uint32{gl.COLOR_ATTACHMENT0}
	gl.DrawBuffers(1, &buffers[0])

	var rb uint32
	gl.GenRenderbuffers(1, &rb)
	gl.BindRenderbuffer(gl.RENDERBUFFER, rb)
	gl.RenderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, int32(w), int32(h))
	gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.STENCIL_ATTACHMENT, gl.RENDERBUFFER, rb)

	gl.BindTexture(gl.TEXTURE_2D, 0)
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.BindRenderbuffer(gl.RENDERBUFFER, 0)
	return
}
Example #2
0
func (r *GlowRenderer) Draw() (err error) {
	gl.UseProgram(r.shader)
	gl.Uniform1i(r.textureUnitLoc, 0)
	gl.BindBuffer(gl.ARRAY_BUFFER, r.coords)
	gl.EnableVertexAttribArray(r.positionLoc)
	gl.VertexAttribPointer(r.positionLoc, 3, gl.FLOAT, false, 5*4, gl.PtrOffset(0))
	gl.EnableVertexAttribArray(r.textureLoc)
	gl.VertexAttribPointer(r.textureLoc, 2, gl.FLOAT, false, 5*4, gl.PtrOffset(3*4))
	gl.Uniform1i(r.blurAmountLoc, int32(r.blur))
	gl.Uniform1f(r.blurScaleLoc, r.scale)
	gl.Uniform1f(r.blurStrengthLoc, r.strength)
	gl.Uniform2f(r.bufferDimensionsLoc, float32(r.width), float32(r.height))

	gl.BindFramebuffer(gl.FRAMEBUFFER, r.BlurFb)
	gl.Viewport(0, 0, int32(r.width), int32(r.height))
	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, r.GlowTex)
	gl.Uniform1i(r.orientationLoc, 0)
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)

	gl.Viewport(0, 0, int32(r.oldwidth), int32(r.oldheight))
	gl.BlendFunc(gl.ONE, gl.ONE)
	gl.BindTexture(gl.TEXTURE_2D, r.BlurTex)
	gl.Uniform1i(r.orientationLoc, 1)
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)

	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	return nil
}
Example #3
0
//PreRender binds either the next post process fbo if there is one or unbinds any fbo to render to screen. Also disable depth test.
func (ppfb *PostProcessFramebuffer) PreRender() {
	if ppfb.next != nil {
		ppfb.Fb.Bind(gl2.FRAMEBUFFER)
	} else {
		gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	}
	gl.Disable(gl.DEPTH_TEST)
}
Example #4
0
func (r *EffectsRenderer) Delete() error {
	gl.BindTexture(gl.TEXTURE_2D, 0)
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.BindRenderbuffer(gl.RENDERBUFFER, 0)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	gl.DeleteFramebuffers(1, &r.framebuffer)
	gl.DeleteTextures(1, &r.texture)
	gl.DeleteBuffers(1, &r.coords)
	return r.GetError()
}
Example #5
0
func (r *EffectsRenderer) Bind() error {
	gl.BindFramebuffer(gl.FRAMEBUFFER, r.framebuffer)
	gl.Enable(gl.STENCIL_TEST)
	gl.Viewport(0, 0, int32(r.width), int32(r.height))
	gl.ClearStencil(0)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.StencilMask(0xFF) // Write to buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)
	gl.StencilMask(0x00) // Don't write to buffer
	return nil
}
Example #6
0
func (r *GlowRenderer) Delete() error {
	gl.BindTexture(gl.TEXTURE_2D, 0)
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.BindRenderbuffer(gl.RENDERBUFFER, 0)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	gl.DeleteFramebuffers(1, &r.GlowFb)
	gl.DeleteTextures(1, &r.GlowTex)
	gl.DeleteFramebuffers(1, &r.BlurFb)
	gl.DeleteTextures(1, &r.BlurTex)
	gl.DeleteBuffers(1, &r.coords)
	return r.GetError()
}
Example #7
0
func (r *EffectsRenderer) Draw() (err error) {
	gl.UseProgram(r.shader)
	gl.Uniform1i(r.textureUnitLoc, 0)
	gl.Uniform3f(r.colorLoc, r.Color[0], r.Color[1], r.Color[2])
	gl.BindBuffer(gl.ARRAY_BUFFER, r.coords)
	gl.EnableVertexAttribArray(r.positionLoc)
	gl.VertexAttribPointer(r.positionLoc, 3, gl.FLOAT, false, 5*4, gl.PtrOffset(0))
	gl.EnableVertexAttribArray(r.textureLoc)
	gl.VertexAttribPointer(r.textureLoc, 2, gl.FLOAT, false, 5*4, gl.PtrOffset(3*4))

	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.Viewport(0, 0, int32(r.oldwidth), int32(r.oldheight))
	gl.BlendFunc(gl.ONE, gl.ONE)
	gl.BindTexture(gl.TEXTURE_2D, r.texture)
	gl.DrawArrays(gl.TRIANGLE_STRIP, 0, 4)

	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	return nil
}
Example #8
0
func (r *EffectsRenderer) Unbind() error {
	gl.Viewport(0, 0, int32(r.oldwidth), int32(r.oldheight))
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.Disable(gl.STENCIL_TEST)
	return nil
}