Temporary fix for directx11

This commit is contained in:
Zyko 2024-04-10 20:12:10 +02:00
parent c73221ac16
commit 65646df8ed
3 changed files with 21 additions and 21 deletions

View File

@ -539,13 +539,6 @@ func (g *graphics11) setAsRenderTargets(dsts []*image11, useStencil bool) error
if i.screen { if i.screen {
return fmt.Errorf("directx: a stencil buffer is not available for a screen image") 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 { if i.stencil == nil {
w, h := i.internalSize() w, h := i.internalSize()
s, err := g.device.CreateTexture2D(&_D3D11_TEXTURE2D_DESC{ s, err := g.device.CreateTexture2D(&_D3D11_TEXTURE2D_DESC{
@ -568,6 +561,13 @@ func (g *graphics11) setAsRenderTargets(dsts []*image11, useStencil bool) error
} }
i.stencil = s 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) g.deviceContext.OMSetRenderTargets(rtvs, dsts[0].stencilView)
@ -584,25 +584,25 @@ func (g *graphics11) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics
srvs := [graphics.ShaderSrcImageCount]*_ID3D11ShaderResourceView{} srvs := [graphics.ShaderSrcImageCount]*_ID3D11ShaderResourceView{}
g.deviceContext.PSSetShaderResources(0, srvs[:]) g.deviceContext.PSSetShaderResources(0, srvs[:])
var dsts []*image11 var dsts [graphics.ShaderDstImageCount]*image11
var viewports []_D3D11_VIEWPORT var viewports [graphics.ShaderDstImageCount]_D3D11_VIEWPORT
for _, id := range dstIDs { var targetCount int
for i, id := range dstIDs {
img := g.images[id] img := g.images[id]
if img == nil { if img == nil {
dsts = append(dsts, nil)
viewports = append(viewports, _D3D11_VIEWPORT{})
continue continue
} }
dsts = append(dsts, img) dsts[i] = img
w, h := img.internalSize() w, h := img.internalSize()
viewports = append(viewports, _D3D11_VIEWPORT{ viewports[i] = _D3D11_VIEWPORT{
TopLeftX: 0, TopLeftX: 0,
TopLeftY: 0, TopLeftY: 0,
Width: float32(w), Width: float32(w),
Height: float32(h), Height: float32(h),
MinDepth: 0, MinDepth: 0,
MaxDepth: 1, MaxDepth: 1,
}) }
targetCount++
} }
var srcs [graphics.ShaderSrcImageCount]*image11 var srcs [graphics.ShaderSrcImageCount]*image11
@ -614,9 +614,13 @@ func (g *graphics11) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics
srcs[i] = img 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 return err
} }

View File

@ -296,8 +296,6 @@ func Compile(p *shaderir.Program, version GLSLVersion) (vertexShader, fragmentSh
vs = strings.TrimSpace(vs) + "\n" vs = strings.TrimSpace(vs) + "\n"
fs = strings.TrimSpace(fs) + "\n" fs = strings.TrimSpace(fs) + "\n"
fmt.Println("FS:", fs)
return vs, fs return vs, fs
} }

View File

@ -236,8 +236,6 @@ func Compile(p *shaderir.Program) (vertexShader, pixelShader string, offsets []i
vertexShader = shaders[0] vertexShader = shaders[0]
pixelShader = shaders[1] pixelShader = shaders[1]
fmt.Println("PS:", pixelShader)
return return
} }