diff --git a/internal/graphicsdriver/directx/graphics11_windows.go b/internal/graphicsdriver/directx/graphics11_windows.go index 262de28e4..2a9344010 100644 --- a/internal/graphicsdriver/directx/graphics11_windows.go +++ b/internal/graphicsdriver/directx/graphics11_windows.go @@ -539,13 +539,6 @@ func (g *graphics11) setAsRenderTargets(dsts []*image11, useStencil bool) error if i.screen { return fmt.Errorf("directx: a stencil buffer is not available for a screen image") } - if i.stencilView == nil { - sv, err := g.device.CreateDepthStencilView(unsafe.Pointer(i.stencil), nil) - if err != nil { - return err - } - i.stencilView = sv - } if i.stencil == nil { w, h := i.internalSize() s, err := g.device.CreateTexture2D(&_D3D11_TEXTURE2D_DESC{ @@ -568,6 +561,13 @@ func (g *graphics11) setAsRenderTargets(dsts []*image11, useStencil bool) error } i.stencil = s } + if i.stencilView == nil { + sv, err := g.device.CreateDepthStencilView(unsafe.Pointer(i.stencil), nil) + if err != nil { + return err + } + i.stencilView = sv + } } g.deviceContext.OMSetRenderTargets(rtvs, dsts[0].stencilView) @@ -584,25 +584,25 @@ func (g *graphics11) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics srvs := [graphics.ShaderSrcImageCount]*_ID3D11ShaderResourceView{} g.deviceContext.PSSetShaderResources(0, srvs[:]) - var dsts []*image11 - var viewports []_D3D11_VIEWPORT - for _, id := range dstIDs { + var dsts [graphics.ShaderDstImageCount]*image11 + var viewports [graphics.ShaderDstImageCount]_D3D11_VIEWPORT + var targetCount int + for i, id := range dstIDs { img := g.images[id] if img == nil { - dsts = append(dsts, nil) - viewports = append(viewports, _D3D11_VIEWPORT{}) continue } - dsts = append(dsts, img) + dsts[i] = img w, h := img.internalSize() - viewports = append(viewports, _D3D11_VIEWPORT{ + viewports[i] = _D3D11_VIEWPORT{ TopLeftX: 0, TopLeftY: 0, Width: float32(w), Height: float32(h), MinDepth: 0, MaxDepth: 1, - }) + } + targetCount++ } var srcs [graphics.ShaderSrcImageCount]*image11 @@ -614,9 +614,13 @@ func (g *graphics11) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics srcs[i] = img } - g.deviceContext.RSSetViewports(viewports) + // TODO: this is not correct, we can't assume that a single image means no MRT! + if targetCount > 1 { + targetCount = graphics.ShaderDstImageCount + } + g.deviceContext.RSSetViewports(viewports[:targetCount]) - if err := g.setAsRenderTargets(dsts, fillRule != graphicsdriver.FillAll); err != nil { + if err := g.setAsRenderTargets(dsts[:targetCount], fillRule != graphicsdriver.FillAll); err != nil { return err } diff --git a/internal/shaderir/glsl/glsl.go b/internal/shaderir/glsl/glsl.go index 7cb61841c..830b9f982 100644 --- a/internal/shaderir/glsl/glsl.go +++ b/internal/shaderir/glsl/glsl.go @@ -296,8 +296,6 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh vs = strings.TrimSpace(vs) + "\n" fs = strings.TrimSpace(fs) + "\n" - fmt.Println("FS:", fs) - return vs, fs } diff --git a/internal/shaderir/hlsl/hlsl.go b/internal/shaderir/hlsl/hlsl.go index 85b820d26..9454024d5 100644 --- a/internal/shaderir/hlsl/hlsl.go +++ b/internal/shaderir/hlsl/hlsl.go @@ -236,8 +236,6 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string, offsets []i vertexShader = shaders[0] pixelShader = shaders[1] - fmt.Println("PS:", pixelShader) - return }