mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
Fixed opengl tests
This commit is contained in:
parent
92a257a557
commit
6a8c00e0aa
@ -127,7 +127,7 @@ func main() {
|
|||||||
ebiten.SetVsyncEnabled(false)
|
ebiten.SetVsyncEnabled(false)
|
||||||
ebiten.SetWindowTitle("MRT (Ebitengine Demo)")
|
ebiten.SetWindowTitle("MRT (Ebitengine Demo)")
|
||||||
if err := ebiten.RunGameWithOptions(&Game{}, &ebiten.RunGameOptions{
|
if err := ebiten.RunGameWithOptions(&Game{}, &ebiten.RunGameOptions{
|
||||||
GraphicsLibrary: ebiten.GraphicsLibraryDirectX,
|
GraphicsLibrary: ebiten.GraphicsLibraryOpenGL,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -622,8 +622,7 @@ func (g *graphics11) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphics
|
|||||||
// it is safe to assume that MRT is used.
|
// it is safe to assume that MRT is used.
|
||||||
// Also, it only matters in order to specify empty targets/viewports when not all slots are
|
// Also, it only matters in order to specify empty targets/viewports when not all slots are
|
||||||
// being filled.
|
// being filled.
|
||||||
usesMRT := targetCount > 1 || firstTarget > 0
|
if targetCount > 1 || firstTarget > 0 {
|
||||||
if usesMRT {
|
|
||||||
targetCount = graphics.ShaderDstImageCount
|
targetCount = graphics.ShaderDstImageCount
|
||||||
}
|
}
|
||||||
g.deviceContext.RSSetViewports(viewports[:targetCount])
|
g.deviceContext.RSSetViewports(viewports[:targetCount])
|
||||||
|
@ -204,8 +204,8 @@ func (g *Graphics) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphicsdr
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.drawCalled = true
|
g.drawCalled = true
|
||||||
g.context.ctx.BindTexture(gl.TEXTURE_2D, 0)
|
targetCount := 0
|
||||||
dstCount := 0
|
firstTarget := -1
|
||||||
var dsts [graphics.ShaderDstImageCount]*Image
|
var dsts [graphics.ShaderDstImageCount]*Image
|
||||||
for i, dstID := range dstIDs {
|
for i, dstID := range dstIDs {
|
||||||
if dstID == graphicsdriver.InvalidImageID {
|
if dstID == graphicsdriver.InvalidImageID {
|
||||||
@ -215,30 +215,32 @@ func (g *Graphics) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphicsdr
|
|||||||
if dst == nil {
|
if dst == nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if firstTarget == -1 {
|
||||||
|
firstTarget = i
|
||||||
|
}
|
||||||
dst.ensureFramebuffer()
|
dst.ensureFramebuffer()
|
||||||
dsts[i] = dst
|
dsts[i] = dst
|
||||||
dstCount++
|
targetCount++
|
||||||
}
|
}
|
||||||
if dstCount == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
g.context.bindFramebuffer(0)
|
|
||||||
|
|
||||||
// Only necessary for the same shared framebuffer
|
f := uint32(dsts[firstTarget].framebuffer.native)
|
||||||
f := uint32(dsts[0].framebuffer.native)
|
// If the number of targets is more than one, or if the only target is the first one, then
|
||||||
if dstCount > 1 {
|
// it is safe to assume that MRT is used.
|
||||||
if g.context.mrtFramebuffer == 0 {
|
// Also, it only matters in order to specify empty targets/viewports when not all slots are
|
||||||
|
// being filled.
|
||||||
|
usesMRT := firstTarget > 0 || targetCount > 1
|
||||||
|
if usesMRT {
|
||||||
|
f = uint32(g.context.mrtFramebuffer)
|
||||||
|
// Create the initial MRT framebuffer
|
||||||
|
if f == 0 {
|
||||||
f = g.context.ctx.CreateFramebuffer()
|
f = g.context.ctx.CreateFramebuffer()
|
||||||
if f <= 0 {
|
if f <= 0 {
|
||||||
return fmt.Errorf("opengl: creating framebuffer failed: the returned value is not positive but %d", f)
|
return fmt.Errorf("opengl: creating framebuffer failed: the returned value is not positive but %d", f)
|
||||||
}
|
}
|
||||||
g.context.mrtFramebuffer = framebufferNative(f)
|
g.context.mrtFramebuffer = framebufferNative(f)
|
||||||
} else {
|
|
||||||
f = uint32(g.context.mrtFramebuffer)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
g.context.bindFramebuffer(framebufferNative(f))
|
g.context.bindFramebuffer(framebufferNative(f))
|
||||||
//g.context.ctx.BindFramebuffer(gl.FRAMEBUFFER, f)
|
|
||||||
|
|
||||||
// Reset color attachments
|
// Reset color attachments
|
||||||
if s := g.context.ctx.CheckFramebufferStatus(gl.FRAMEBUFFER); s == gl.FRAMEBUFFER_COMPLETE {
|
if s := g.context.ctx.CheckFramebufferStatus(gl.FRAMEBUFFER); s == gl.FRAMEBUFFER_COMPLETE {
|
||||||
@ -273,8 +275,8 @@ func (g *Graphics) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphicsdr
|
|||||||
g.context.bindFramebuffer(framebufferNative(f))
|
g.context.bindFramebuffer(framebufferNative(f))
|
||||||
}
|
}
|
||||||
|
|
||||||
w, h := dsts[0].framebuffer.viewportWidth, dsts[0].framebuffer.viewportHeight
|
w, h := dsts[firstTarget].viewportSize() //.framebuffer.viewportWidth, dsts[firstTarget].framebuffer.viewportHeight
|
||||||
g.context.setViewport(w, h, dsts[0].screen)
|
g.context.setViewport(w, h, dsts[firstTarget].screen)
|
||||||
|
|
||||||
g.context.blend(blend)
|
g.context.blend(blend)
|
||||||
|
|
||||||
@ -298,7 +300,7 @@ func (g *Graphics) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphicsdr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In OpenGL, the NDC's Y direction is upward, so flip the Y direction for the final framebuffer.
|
// In OpenGL, the NDC's Y direction is upward, so flip the Y direction for the final framebuffer.
|
||||||
if dstCount == 1 && dsts[0] != nil && dsts[0].screen {
|
if !usesMRT && dsts[firstTarget].screen {
|
||||||
const idx = graphics.ProjectionMatrixUniformVariableIndex
|
const idx = graphics.ProjectionMatrixUniformVariableIndex
|
||||||
// Invert the sign bits as float32 values.
|
// Invert the sign bits as float32 values.
|
||||||
g.uniformVars[idx].value[1] ^= 1 << 31
|
g.uniformVars[idx].value[1] ^= 1 << 31
|
||||||
@ -326,13 +328,8 @@ func (g *Graphics) DrawTriangles(dstIDs [graphics.ShaderDstImageCount]graphicsdr
|
|||||||
g.uniformVars = g.uniformVars[:0]
|
g.uniformVars = g.uniformVars[:0]
|
||||||
|
|
||||||
if fillRule != graphicsdriver.FillAll {
|
if fillRule != graphicsdriver.FillAll {
|
||||||
for _, dst := range dsts {
|
if err := dsts[firstTarget].ensureStencilBuffer(framebufferNative(f)); err != nil {
|
||||||
if dst == nil {
|
return err
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := dst.ensureStencilBuffer(framebufferNative(f)); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
g.context.ctx.Enable(gl.STENCIL_TEST)
|
g.context.ctx.Enable(gl.STENCIL_TEST)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user