forked from joejulian/gio
gpu/backend: remove clear color and depth state
Specifying the clear color and depth at the time of clearing is less error prone and a better for modern GPU APIs. As a bonus, we can get rid of the BufferAttachment type. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -110,12 +110,10 @@ func TestFramebuffers(t *testing.T) {
|
||||
col2 = color.RGBA{R: 0xfe, G: 0xba, B: 0xbe, A: 0xca}
|
||||
)
|
||||
fcol1, fcol2 := f32color.RGBAFromSRGB(col1), f32color.RGBAFromSRGB(col2)
|
||||
b.ClearColor(fcol1.Float32())
|
||||
b.BindFramebuffer(fbo1)
|
||||
b.Clear(backend.BufferAttachmentColor)
|
||||
b.ClearColor(fcol2.Float32())
|
||||
b.Clear(fcol1.Float32())
|
||||
b.BindFramebuffer(fbo2)
|
||||
b.Clear(backend.BufferAttachmentColor)
|
||||
b.Clear(fcol2.Float32())
|
||||
img := screenshot(t, fbo1, sz)
|
||||
if got := img.RGBAAt(0, 0); got != col1 {
|
||||
t.Errorf("got color %v, expected %v", got, col1)
|
||||
@@ -129,7 +127,11 @@ func TestFramebuffers(t *testing.T) {
|
||||
func setupFBO(t *testing.T, b backend.Device, size image.Point) backend.Framebuffer {
|
||||
fbo := newFBO(t, b, size)
|
||||
b.BindFramebuffer(fbo)
|
||||
b.Clear(backend.BufferAttachmentColor | backend.BufferAttachmentDepth)
|
||||
// ClearColor accepts linear RGBA colors, while 8-bit colors
|
||||
// are in the sRGB color space.
|
||||
col := f32color.RGBAFromSRGB(clearCol)
|
||||
b.Clear(col.Float32())
|
||||
b.ClearDepth(0.0)
|
||||
b.Viewport(0, 0, size.X, size.Y)
|
||||
return fbo
|
||||
}
|
||||
@@ -172,10 +174,6 @@ func newBackend(t *testing.T) backend.Device {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.BeginFrame()
|
||||
// ClearColor accepts linear RGBA colors, while 8-bit colors
|
||||
// are in the sRGB color space.
|
||||
col := f32color.RGBAFromSRGB(clearCol)
|
||||
b.ClearColor(col.Float32())
|
||||
t.Cleanup(func() {
|
||||
b.EndFrame()
|
||||
ctx.ReleaseCurrent()
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"unsafe"
|
||||
|
||||
"gioui.org/gpu/backend"
|
||||
"gioui.org/internal/f32color"
|
||||
gunsafe "gioui.org/internal/unsafe"
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
@@ -27,8 +26,8 @@ type Device struct {
|
||||
}
|
||||
|
||||
type Backend struct {
|
||||
clearColor f32color.RGBA
|
||||
clearDepth float32
|
||||
// Temporary storage to avoid garbage.
|
||||
clearColor [4]float32
|
||||
viewport _D3D11_VIEWPORT
|
||||
depthState depthState
|
||||
blendState blendState
|
||||
@@ -539,16 +538,14 @@ func (b *Backend) NewProgram(vertexShader, fragmentShader backend.ShaderSources)
|
||||
return p, nil
|
||||
}
|
||||
|
||||
func (b *Backend) ClearColor(colr, colg, colb, cola float32) {
|
||||
b.clearColor = f32color.RGBA{R: colr, G: colg, B: colb, A: cola}
|
||||
func (b *Backend) Clear(colr, colg, colb, cola float32) {
|
||||
b.clearColor = [4]float32{colr, colg, colb, cola}
|
||||
b.dev.ctx.ClearRenderTargetView(b.fbo.renderTarget, &b.clearColor)
|
||||
}
|
||||
|
||||
func (b *Backend) Clear(buffers backend.BufferAttachments) {
|
||||
if buffers&backend.BufferAttachmentColor != 0 {
|
||||
b.dev.ctx.ClearRenderTargetView(b.fbo.renderTarget, &b.clearColor)
|
||||
}
|
||||
if buffers&backend.BufferAttachmentDepth != 0 && b.fbo.depthView != nil {
|
||||
b.dev.ctx.ClearDepthStencilView(b.fbo.depthView, _D3D11_CLEAR_DEPTH|_D3D11_CLEAR_STENCIL, b.clearDepth, 0)
|
||||
func (b *Backend) ClearDepth(depth float32) {
|
||||
if b.fbo.depthView != nil {
|
||||
b.dev.ctx.ClearDepthStencilView(b.fbo.depthView, _D3D11_CLEAR_DEPTH|_D3D11_CLEAR_STENCIL, depth, 0)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -650,10 +647,6 @@ func (b *Backend) DepthFunc(f backend.DepthFunc) {
|
||||
b.depthState.fn = f
|
||||
}
|
||||
|
||||
func (b *Backend) ClearDepth(d float32) {
|
||||
b.clearDepth = d
|
||||
}
|
||||
|
||||
func (b *Backend) SetBlend(enable bool) {
|
||||
b.blendState.enable = enable
|
||||
}
|
||||
|
||||
@@ -1034,7 +1034,7 @@ func (c *_ID3D11DeviceContext) ClearDepthStencilView(target *_ID3D11DepthStencil
|
||||
)
|
||||
}
|
||||
|
||||
func (c *_ID3D11DeviceContext) ClearRenderTargetView(target *_ID3D11RenderTargetView, color *f32color.RGBA) {
|
||||
func (c *_ID3D11DeviceContext) ClearRenderTargetView(target *_ID3D11RenderTargetView, color *[4]float32) {
|
||||
syscall.Syscall(
|
||||
c.vtbl.ClearRenderTargetView,
|
||||
3,
|
||||
|
||||
Reference in New Issue
Block a user