BRL.DXGraphics: Added support for Stencil Buffer

BlitzMax Forums/BlitzMax Programming/BRL.DXGraphics: Added support for Stencil Buffer

BORNtobeNAMELESS(Posted 2010) [#1]
This change was neccessary to make using the Stencil-Buffer in a D3D9 context possible.

In file d3d9graphics.bmx, in line 53, right after the "Local pp..."-Line, add the following:
	If flags & GRAPHICS_STENCILBUFFER Then
		pp.EnableAutoDepthStencil = True
		pp.AutoDepthStencilFormat = D3DFMT_D24S8
	EndIf
Maybe someone else finds this usefull, too. Should be added to official Module i think, as the GRAPHICS-Flag was totaly ignored before, and it looks like the other flags are ignored, too.


SebHoll(Posted 2010) [#2]
Bumpety, bump, bump. :-)


marksibly(Posted 2010) [#3]
Hi,

The reason I didn't add them is because I can't feasibly test them right now - ie:
I don't want to just add them and 'hope' they magically work.

If the community can come up with a reliable implementation for *all* the flags, then I'd think about adding them - but not in a 'one at a time, maybe, maybe not' manner.


GW(Posted 2010) [#4]
What use is a stencil buffer for 2d graphics?


ImaginaryHuman(Posted 2010) [#5]
Tonnes of uses for the stencil buffer in 2d. Split screens, masked areas, collision detection, even filled vector graphics.


Tachyon(Posted 2010) [#6]
Yeah but....DX9 only? Bleh.


ImaginaryHuman(Posted 2010) [#7]
You can ask for a stencil buffer in opengl by saying |STENCIL_BUFFER in the graphics flags.


theHand(Posted 2010) [#8]
....Then let's leave it up to Mr. Sibly.


BORNtobeNAMELESS(Posted 2010) [#9]
I created a module to take full use of the StencilBuffer in Max2D. It's able to do the stencil stuff for OpenGL and D3D9. In all my tests it works like a charm.

You can find it and a test in my git:
http://git.btbn.de/btbn.mod.git/tree/HEAD:/stencil.mod

You need to change two BRL-Modules in order to make it work and compile. First is the one provided in my first post in this thread, and the second one is:

In BRL.D3D9Max2D:
Add the following method to TD3D9Max2DDriver:

	Method GetD3DDevice:IDirect3DDevice9()
		Return _d3dDev
	EndMethod


Or does somebody know how to get this device without a change, as it's private?


kfprimm(Posted 2010) [#10]
There is no way to change the device after it's created.

Here's my tweak,


As with the code above, add it after the presentation parameters.

This will check for compatibility with every defined format (excluding lockable formats), giving the highest precision priority.

I've tested it on a GeForce GTX 260 system and on a laptop with an embedded ATI Radeon Xpress chipset. It seems to work just fine.