Strange Bug with OGl and Pixmaps

BlitzMax Forums/BlitzMax Bug Reports/Strange Bug with OGl and Pixmaps

Hi there, found some strange behaviour with OpenGL and Pixmaps.
SuperStrict
Type TMemory Abstract
	Global _g_list:TList = New TList

	Function PEEK:Byte(offset:Short)
	Local ram:Byte
	For Local mem:Tram = EachIn _g_list
	Next
	Return ram		
	End Function
End Type

Type TRAM Extends TMemory
	Field _ram:Byte[]	
	Function create:TRAM(size:Int = 65536)
		Local ram:TRAM = New TRAM
		ram._ram = ram._ram[..size]
		_g_list.addlast(ram)
		Return ram
	End Function
End Type

Type TCPU
	Field _cycles:Int	

	Method update() 
		_cycles:+ 2
	End Method
End Type


Type TVIC

	Field _rasterzeile:Int
	Field _rasterspalte:Int

	Field VICMAP:TImage
	Field V_MAP:TPixmap
	
	Method init()
		VICMAP = CreateImage(168+(24*2) , 96+(21*2) )
		_rasterzeile = - 21
		_rasterspalte =-24
	End Method
	Method update()
		tram.peek($d000 )

		Global count:Int
		Global _msec:Int
		Global delayed:Int = 0
		Global alt_cycles:Int
		Local cycles:Int

		Global x:Byte , y:Byte				
		cycles = CPU._cycles

		Global cyc_diff:Int
		cyc_diff = cycles - alt_cycles
		ms = MilliSecs()
		If _msec + 1000 <= ms
			_msec = ms
			
			Print count + "(FPS)"
			count = 0
		EndIf
		While cyc_diff >= 4
			alt_cycles :+ 4
			cyc_diff = cycles - alt_cycles
			If (_rasterzeile = -21) And (_rasterspalte = -24) Then
				count:+1
				SetScale 2,2
				UnlockImage(VICMAP)

				DrawImage (VICMAP , 0 , 0)
				
				V_MAP  =LockImage(VICMAP)
				' BUG BUG BUG BUG BUG
				'DrawText " ",0,0 'ohne diesen "text" funktioniert ogl nicht BUG: unREM drawtext and it works. 
				' BUG BUG BUG BUG BUG
				Flip 0
				Cls
			EndIf

			If (_rasterzeile >= 0) And (_rasterzeile <96) And (_rasterspalte >=0) And (_rasterspalte <=167) Then 
				y = _rasterzeile / 8
				x = _rasterspalte / 8
				For Local i:Int = 0 To 7
					WritePixel V_MAP,_rasterspalte+i+24,21+_rasterzeile,Rand($ff123456)
				Next
			Else
				For Local i:Int = 0 To 7
					WritePixel V_MAP , _rasterspalte + 24 + i , _rasterzeile + 21 ,$ff443344
				Next
			EndIf
			_rasterspalte:+ 8
			If _rasterspalte > 191 Then
				_rasterspalte = -24
				_rasterzeile:+ 1
			EndIf
			If _rasterzeile > 116 Then _rasterzeile = -21
		Wend
	End Method
End Type

SetGraphicsDriver GLMax2DDriver()
Graphics (168+48)*2 , (96+42)*2


'So, her mit dem Prozessor:
Global CPU:TCPU = New TCPU
' RAM muss sein:
Local ram:TRAM = TRAM.create()
'Ein Grafikchip ist nett:
Local VIC:TVIC = New TVIC
VIC.init()
Global ms:Int = MilliSecs()

'Mainloop
Repeat

	CPU._cycles:+2
	VIC.update()
	
Until KeyHit(key_escape) Or (AppTerminate() = True)
End


This code is an heavily shortened piece from an 8-bit-cpu-emulator.
With DX, it draws fine. Under OGl, I get only a blank white screen as long as the drawtext command is REM'd out. Enabling Drawtext, the code works.

The code will also work when I remove the function Call "TRam.peek($d000)" from my code, which is NOT an option.

Furthermore, the (unshortened) Code runs quite well under Windwos DX and OGL (about 40 FPS with heavy Pixmapuse), but under Ubuntu and on MAC with comparable CPU and GPU ists much slower (10FPS on Linux, same Computer as Windwos; Mac: 1-2 FPS on a Macbook Pro).
The Code was tested by various users and the results are always the same: Win fast, Linux slow, Mac dead.
As i liked to run this Emulator on all Plattforms and as I MUST perform lots of pixel-operations for the VIC, question would be for me if its related to the bug or is OGl much slower on other systems generally ?

Did some testing, commenting out the For-EachIn-Loop in TMemory makes it work again.
Commenting it out and adding a line like "Local testlist:TList = new TList" breaks it.

This is indeed very strange behaviour.

Tested this on a PPC Mac, performs very poor (1-2 FPS).

hamZta

Stranger yet! Must be something in the OpenGL driver, when I try running it without the DrawText call and using the DirectX driver it works fine.

Me thinks there is a gl state not being set/unset..

EDIT: DOH! You cannot render a locked image.. try this:
				V_MAP  =LockImage(VICMAP)
				
				DrawImage (VICMAP , 0 , 0)
				
				
				UnlockImage(VICMAP)


Now it's kind of scary that using DirectX makes the original work!

Hi,

This appears to be related to some nasty 'under-the-hood' jiggery pokery to do with 'shared opengl contexts'.

Not 100% sure what's happening, but know of at least one way to fix it!

Will look into this further...