Is there a simple way to test a DX9 driver in BMax

BlitzMax Forums/BlitzMax Programming/Is there a simple way to test a DX9 driver in BMax

Grey Alien(Posted 2008) [#1]
? I gather there is no office DX9 support in BMax, but I found a driver by DStastny but the link is broken: http://www.blitzbasic.com/Community/posts.php?topic=67633

Does anyone know anything else about this? Thx.


markcw(Posted 2008) [#2]
Found it on internet archive.

If it's okay with Doug I have mirrored his Dx9 Max2d driver v 0.2 and 0.5 zips here:
http://www.blitzmax.com/logs/userlog.php?user=8652&log=1737


markcw(Posted 2008) [#3]
Found it on internet archive.

If it's okay with Doug I have mirrored his Dx9 Max2d driver v 0.2 and 0.5 zips here:
http://www.blitzmax.com/logs/userlog.php?user=8652&log=1737


Grey Alien(Posted 2008) [#4]
Great thanks, downloading now. Hope I can get it to work OK. Anyone used it before?


Grey Alien(Posted 2008) [#5]
OK the examples won't compile in BMax 1.30. They fail on this line

wc.hInstance=GetModuleHandleA(0)


in the Create() function in DX9Graphics.bmx:

	Function Create:TD3D9Graphics( width:Int,height:Int,depth:Int,hertz:Int,flags:Int )
		Global _reg : Int
		If Not _reg : Int
			Local wc:WNDCLASS=New WNDCLASS
			wc.hInstance=GetModuleHandleA(0)
			wc.lpfnWndProc=WndProc
			wc.hCursor=LoadCursorA( Null,Byte Ptr IDC_ARROW )
			wc.lpszClassName=_DX9GRAPHICSEXWINDOWCLASS
			RegisterClassA( wc )
			_reg=True
		EndIf

		Local hinst:Int=GetModuleHandleA(0)
		Local title:Byte Ptr=AppTitle.ToCString()
	
		Local hwnd:Int
		If depth
			hwnd=CreateWindowExA( 0,_DX9GRAPHICSEXWINDOWCLASS,title,WS_VISIBLE|WS_POPUP,0,0,width,height,0,0,hinst,Null )
		Else
			Local style:Int=WS_VISIBLE|WS_CAPTION|WS_SYSMENU |WS_SIZEBOX 
			Local rect :TRect = TRect.Create(32,32,width+32,height+32)
			AdjustWindowRect Int Ptr Byte Ptr rect,style,0
			width=rect.Width()
			height=rect.Height()
			hwnd=CreateWindowExA( 0,_DX9GRAPHICSEXWINDOWCLASS,title,style,rect._Left,rect._Top,width,height,0,0,hinst,Null )
		EndIf

		MemFree title

		If Not hwnd Return Null

		Return New TD3D9Graphics._Create(hwnd ,width,height,depth,hertz,flags)
	End Function


with this error:

Compile Error: Unable to convert from 'Int' to 'Byte Ptr'

Does anyone know how to resolve this please? thanks.


DStastny(Posted 2008) [#6]
Well I wrote it :) but have looked at BMAX 1.30 try changing the

Local hinst:Int=GetModuleHandleA(0)
to hinst:BYTE PTR

I will have to update my MAX something must have changed with the declaration of GetModuleHandle???


markcw(Posted 2008) [#7]
That's a funny looking line, what does it mean?
AdjustWindowRect Int Ptr Byte Ptr rect,style,0



MGE(Posted 2008) [#8]
DStastny - Have you considered adding support for the "DX9 Sprite Object"? We could all just adapt our own routines based around that object. It has parameters for texture, scaling, alpha, RGB modulation, etc.


Grey Alien(Posted 2008) [#9]
Hi Doug, that line's not the problem (although if the other line worked it probably would be.) The problem is this line:

wc.hInstance=GetModuleHandleA(0)


and wc is declared on the line above. It's a WNDCLASS type which is not in your bmx file so I can't change the field type. Perhaps there's a way to convert a Byte Ptr to an Int safely?


DStastny(Posted 2008) [#10]
Dont know what happened I typed in a post and it just disappeared :(

wc.hInstance=GetModuleHandleA(0)


wc.hInstance=GetModuleHandleA(NULL)


Seems they changed GetModuleHandleA.

Let me know how it works out with your Framework or and if you have any other issues I might be able to help you wiht.

Doug


MGE(Posted 2008) [#11]
GA, are you at a point where you need faster rendering for your games?


Grey Alien(Posted 2008) [#12]
DStastny: Great that works thx!

MGE: I just want to test DX9 with my new video card which is extremely bad at DX7 but which is great at GL to see if it's bad at ALL DX or just DX 7...


jsp(Posted 2008) [#13]
Does it just work or do you see also measurable improvements?


Grey Alien(Posted 2008) [#14]
Just tested and there's a huge improvement in speed. My new graphics card is very poor at DX7 it seems and fine at GL and DX9. My old card ran DX7 very fast.


GW(Posted 2008) [#15]
Thanks for linking the download.


GfK(Posted 2008) [#16]
Tested this briefly last night on an Intel GMA965 X3100.

Works fine, apart from nothing appears when I use DrawLine, and DrawRect sometimes only renders the lower-right tri of the quad (I'm using DrawRect to add borders for widescreen, so this is quite serious).


MGE(Posted 2008) [#17]
I tested a DX9 driver a while back and I think one of the problems was the drawrect stuff. I can't recall if it was the same driver though.


DStastny(Posted 2008) [#18]
@GFK do you have a simple sample that demonstrates the problem?

Thanks
Doug


GfK(Posted 2008) [#19]
Not on that PC right now - will sort something out by tonight.


GfK(Posted 2008) [#20]
Quick example but it demonstrates the problem perfectly.

With DX7 I get a rotating line at the centre of the screen, and a white square floating across the top.

With DX9 the line isn't drawn, and I only see the lower right tri that makes up half of the rect.

If I uncomment 'SetLineWidth 20', I can see the rotating 'line' again but its a triangle with one point extending from the centre.

Strict

Import "Dx9Max2dDriver\Dx9Max2dGraphicsDriver.bmx"
SetGraphicsDriver D3D9Max2DDriver()

Local lineAngle:Float
Local rect:Int

Graphics 800,600

'SetLineWidth 20

While Not KeyDown(key_escape)
	Cls
		SetColor 255,255,255
		lineAngle:+1
		DrawLine 400,300,Cos(lineAngle) * 100 + 400, Sin(lineAngle) * 100 + 300
		
		rect:+1
		DrawRect rect,0,100,100
	Flip
Wend



Grey Alien(Posted 2008) [#21]
Just to confirm, this works perfectly on my crap Radeon 2600XT :-)

Anyway, based on your test results, I'm in no hurry to use this DX9 driver. Would love an "official" one. Please add your weight to my request thread:

http://www.blitzbasic.com/Community/posts.php?topic=80499


DStastny(Posted 2008) [#22]
Hmmm, thanks I will figure that out something simple I suspect.

People just have to point out rendering glitches and I will fix them

DStastny


MGE(Posted 2008) [#23]
DStastny - Just to clarify, are you saying you're willing to "see it through" and get everything working based on bug reports, glitches, etc, etc? Because if that's true, then we need to create a new thread just for you and your driver and start doing massive compatibility testing with various gpu's, code examples, etc, etc.

If so...that would be so awesome. :)

Do you have a stable place to host the downloads? If not I can help in that matter.


DStastny(Posted 2008) [#24]
I have always been willing to do it. Very few people where willing to help find compatibility issues or didnt care because its not Open GL. For my personal usage patterns its fine, but even I know there are nuiances to the patterns and how people use Max2d. Cant fix whats not reported and if the people dont reply to me I cant make changes to help.

BTW, I duped the problem, very strange its dropping the first non textured tri. Just need to figure out whats what.

DStastny


GfK(Posted 2008) [#25]
Well, you should keep doing it.

Ignore people who are hellbent on using OpenGL - in my experience it might be faster but has way more problems than DX ever did. I'd rather stick with DX for Windows, simply due to stability.

Obviously I'd like DX9 to be faster, too. But that's probably out of your hands. :)


MGE(Posted 2008) [#26]
Hi DStastny! Excellent. I personally only use DX for Windows, so this is great that you would like to support this project. :)

Can you create a new thread "DX9 Driver" (or whatever) and with the initial post, provide a link to the download and instructions how to actually use it (in detail) so everyone can properly test it?

Also, it would be great to provide instructions on how to change drivers in realtime if that's possible?

Thanks again, I look forward to testing this driver and also trying to work with you to add support for the DX9 Sprite Object. ;) :) :)


Grey Alien(Posted 2008) [#27]
Yeah it would be great to have this support, you've done a great job so far.


DStastny(Posted 2008) [#28]
Ok I found the stupid stupid problem. Sorry about this.

I made a real junior programming mistake. To allocate vertex buffers I use.

  _PrimativeSolidBuffer= MemAlloc(SOLIDVBBUFFERSIZE)
  _PrimativeTextureBuffer= MemAlloc(TEXTVBBUFFERSIZE)		


To allocate temporary buffer for the vertex data while I buffer drawing commands.

I never set the z component of the vertex data for Solid Vertexs since well it was zero. Only if you init to zero. DOOH!

Until I can make arrangments for new place to upload updated driver if someone could change

Dx9Max2dGraphicsDriver and find above lines change to
  _PrimativeSolidBuffer= MemAlloc(SOLIDVBBUFFERSIZE)
  _PrimativeTextureBuffer= MemAlloc(TEXTVBBUFFERSIZE)	
  ' Init buffers		
  MemClear(_PrimativeSolidBuffer,SOLIDVBBUFFERSIZE)
  MemClear(_PrimativeTextureBuffer,TEXTVBBUFFERSIZE)


And confirm if it fixes the bizzare random glitches it would be appreciated. I guess I got burned with most of my testing with textured quads not enough with untextured.

Man that was stupid.

Let me know.

DStastny


Grey Alien(Posted 2008) [#29]
Don't worry about it! :-) It's cool you found a possible fix. We need GfK to test on his PC again.


GfK(Posted 2008) [#30]
Gimme ten mins...


GfK(Posted 2008) [#31]
Works perfectly now.

Don't forget (if you haven't done it already), the version from MarkCW's post contains two other errors that Grey Alien mentioned (two 0's that should be Null).


DStastny(Posted 2008) [#32]
Thanks