An idea for saving VRAM with textures

Miscellaneous Forums/General Discussion/An idea for saving VRAM with textures

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Here is some code to demonstrate this. It could be further inproved by writting every other frame. But the way i see it, the quickier it's over with, the better :o) You can change the texture size plus the number of texels writte to the texture per frame:

Graphics3D 800,600
SetBuffer BackBuffer()

Global camera = CreateCamera()

Global tex_width = 512
Global tex_height = 512

Global texels_per_frame = 10000


Dim texture_array(tex_width-1,tex_height-1)

Global texture = CreateTexture(tex_width,tex_height,256)
SetBuffer TextureBuffer(texture)
	Color 255,0,0
	Rect 0,0,tex_width,tex_height

;copy this to the array
LockBuffer TextureBuffer(texture)
For x = 0 To tex_width-1
	For y = 0 To tex_height-1
		temp = ReadPixelFast(x,y,TextureBuffer(texture) )
		texture_array(x,y) = temp
	Next
Next

UnlockBuffer TextureBuffer(texture)

SetBuffer TextureBuffer(texture)
	Color 0,255,0
	Rect 0,0,tex_width,tex_height

SetBuffer BackBuffer()


Global x_pos = 0
Global y_pos = 0

Global frame
Global fps
Global timer
Global change = 0

Global sprite = CreateSprite()
EntityTexture sprite,texture
PositionEntity sprite,0,0,10

Global cube = CreateCube()
PositionEntity cube,2,0,10

While Not KeyHit(1)

	TurnEntity cube,1,1,1
	
	If KeyHit(200) Then
		change = 1
	End If


	If MilliSecs()<timer+1000 Then
								frame=frame+1
	Else
								fps=frame
								frame=0
								timer=MilliSecs()
	End If
	If change = 1 Then
		update_texture()
	End If
	UpdateWorld
	RenderWorld
	Text 10,10,"fps="+fps
	If change = 1 Then
		Text 10,30,"changing..."
		Text 10,40," x_pos = "+x_pos
	End If
	Flip 0
Wend
End


Function update_texture()

	temp = 0
	;SetBuffer TextureBuffer(texture)
	LockBuffer TextureBuffer(texture)
	Repeat
		WritePixelFast(x_pos,y_pos,texture_array(x_pos,y_pos),TextureBuffer(texture))
		x_pos = x_pos + 1
		If x_pos > (tex_width-1) Then
			x_pos = 0
			y_pos = y_pos + 1
			If y_pos > (tex_height-1) Then
				y_pos = 0
				change = 0
			End If
		End If
		temp = temp + 1
	Until temp > texels_per_frame
	
	UnlockBuffer TextureBuffer(texture)
	;SetBuffer BackBuffer()
	
End Function