Dx9 off screen buffers not doing depth tests under MSAA?

It seems that when MSAA is enabled for Dx9, any new offscreen buffer that is created does not perform a depth test (or depth write?) The main buffer is fine.

I’ve enclosed a small sample to illustrate the problem. Pressing 1 will toggle between rendering the panda actor into the main buffer and into an offscreen buffer. When the MSAA is enabled, rendering into the offscreen buffer gives rendering error symptons exactly the same as if depthtest was disabled (press 2).

Has anybody else ran into this problem before?

from pandac.PandaModules import *
loadPrcFileData('', 'load-display pandadx9' )
#loadPrcFileData('', 'load-display pandagl' )
loadPrcFileData('', 'framebuffer-multisample 1')
loadPrcFileData('', 'multisamples 4')
import direct.directbase.DirectStart
from direct.gui.DirectGui import OnscreenText

def CreateColorFBOAndTex( strName = 'Buffer', iSort = -10, iSizeX = None, iSizeY = None, booDepth = True ):
	winprops = WindowProperties()
	iSizeX = GetScreenResX() if iSizeX == None else iSizeX
	iSizeY = GetScreenResY() if iSizeY == None else iSizeY
	winprops.setSize( iSizeX , iSizeY )
	fbprops = FrameBufferProperties()
	fbprops.setColorBits(1)
	fbprops.setAlphaBits(1)
	fbprops.setDepthBits( 1 )
	fbprops.setStencilBits( 1 )
	objBuffer = base.graphicsEngine.makeOutput(base.pipe, strName, iSort, fbprops, winprops, GraphicsPipe.BFRefuseWindow, base.win.getGsg(), base.win)
	objColorMap = Texture()
	objBuffer.addRenderTexture(objColorMap, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor)
	return objBuffer, objColorMap
	

pos = Point3( 0.18462, 0.894416, 0.550514)
pos = Point3( 31.8462, 39.4416, 35.50514)
base.cam.setPos( pos )
base.cam.lookAt( 0, 0, 0 )
base.cam.node().getLens().setNear( 0.1 )
base.cam.node().setActive(0)
	
objBuffer, objColorMap = CreateColorFBOAndTex( iSizeX = 1024, iSizeY = 768 )
npCam = base.makeCamera( objBuffer, sort = -10)
npCam.node().setLens( base.cam.node().getLens().makeCopy() )
npCam.node().setScene( render )
npCam.setPos( pos )
npCam.lookAt( 0, 0, 0 )

npModel = loader.loadModel('panda')
global booDepth
booDepth = True
npModel.setDepthTest( True )
npModel.setDepthWrite( True )

npModel.reparentTo( render )
render.setAntialias(AntialiasAttrib.MMultisample)

global npCard
card_maker = CardMaker('')
card_maker.setFrame( -1.0, 1.0, -1.0, 1.0)
npCard = NodePath(card_maker.generate())
npCard.setTexture( objColorMap, 1 )
npCard.reparentTo( render2d )

text0 = OnscreenText(text = 'Rendering in to offscreen buffer', fg=(1,0,0,1),scale=.05)
text1 = OnscreenText(text = 'Depth test on', fg=(1,0,0,1),scale=.05, pos = (0, -0.1) )
text2 = OnscreenText(text = 'Push keys 1, 2 to change above', fg=(1,0,0,1),scale=.05, pos = (0, -0.2) )

def foo():
	global npCard
	global text0
	if npCard.isStashed():
		npCard.unstash()
		base.cam.node().setActive(0)
		text0.setText( 'Rendering into offscreen buffer' )
	else:
		npCard.stash()
		base.cam.node().setActive(1)
		text0.setText( 'Rendering into main framebuffer' )

def foo2():
	global booDepth
	global npCard
	global text1
	booDepth = not booDepth
	if booDepth:
		npModel.setDepthTest( True )
		text1.setText( 'Depth test on' )
	else:
		npModel.setDepthTest( False )
		text1.setText( 'Depth test off' )

	
base.accept('1', foo)
base.accept('2', foo2)

def ttask(task):
	npCam.setMat( base.cam.getMat() )
	return task.cont

taskMgr.add( ttask, 'ttask' )

run()

I haven’t heard of that problem specifically, but it does seem awfully similar to this report. But in that case, it’s not related to DX9.

Maybe there’s some more general problem with offscreen buffers and the depth map.

David