Where are vertex's stored?

BlitzMax Forums/BlitzMax Programming/Where are vertex's stored?

If I wanted to move around and display a large number of individual pixels (ie vertexes in OpenGL), would it be best to have them in a display list, and if so is that display list stored in main memory or videoram? What the best/fastest way to plot a lot of colored pixels as in a particle system?

Probably vertex arrays. Vertex arrays store all the data in one big block of system memory, then send it all across to the card in one go. (There's also Vertex Buffers, which stores the data in video RAM, but they're only faster if the data doesn't change at all, like static 3D meshes.)

The head demo in the samples folder uses vertex arrays, IIRC.

I did a test with sprites a few days ago to see if it was faster drawing lots of them using VAs or just using DrawImage. VAs were faster, but only by a small amount on my system (1% or so). YMMV.

Display lists are stored in internal, video card friendly formats, and they may indeed be cached in video ram. Vertex array have neither of these properties.

For the highest performance, display lists are the way to go. For smallish models, you might not notice a huge difference, however.

always thought that VBO are the far best performance wise ...

And if you need to animate each of the vertexes individually?

vertices.

look up a book called something like "computer graphics, a top-down approach using opengl"....i remember using this in school and doing a sierpinski gasket exercise, one in 2D and one in 3D......can't remember exactly the method used, but it was just pushing a ton of pixels on screen, and the 3D version also rotated/translated those pixels.

also a cool way of learning recursion, for those who don't know about it....

And if you need to animate each of the vertexes individually?

Vertex Arrays or individual vertices. VBs and display lists are only an advantage for static vertex lists that you don't change.

I have seen mention of display lists but nothing about vertex arrays. are they supported in blitzmaX? how?

glhead.bmx uses them.

Also,
Rem
	Teamonkey's simple vertex array demo
End Rem

Strict

Const ARRAY_SIZE = 1000	' 1000 sprites
Const SCREEN_W = 800
Const SCREEN_H = 600

Type TImageArray
	Field image:Int
	Field img_width:Int, img_height:Int, tex_width:Int, tex_height:Int
	Field frame:Int = 0
	Field size:Int

	Field ver:Float[]		' Vertex array
	Field tex:Float[]		' Texture co-ordinates array
	
	Function Create:TImageArray(pixmap_in:TPixmap, size_in:Int)
		Assert(size_in > 0)

		Local timg:TImageArray = New TImageArray
		
		timg.image = bglTexFromPixmap(pixmap_in)
		timg.img_width  = pixmap_in.width
		timg.img_height = pixmap_in.height
		timg.tex_width  = timg.img_width
		timg.tex_height = timg.img_height
		
		bglAdjustTexSize timg.tex_width,timg.tex_height

		timg.ver = New Float[size_in*8]	' 2*4 vertices per index
		timg.tex = New Float[size_in*8]
		timg.size = size_in
		
		Assert(timg.ver.length=size_in*8 And timg.tex.length=size_in*8)
		
		Return timg		
	End Function

	Method DrawAll()
		glEnable GL_TEXTURE_2D
		glBindTexture GL_TEXTURE_2D,image
		glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR
		glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR

		glEnableClientState(GL_VERTEX_ARRAY)
		glEnableClientState(GL_TEXTURE_COORD_ARRAY)
		
		glVertexPointer(2,GL_FLOAT,0,ver)
		glTexCoordPointer(2,GL_FLOAT,0,tex)

		glDrawArrays(GL_QUADS, 0, size*4)
	End Method
	
	
	Method SetPos(index:Int, x#, y#)
		Assert(index>=0 And index<size)
	
		Local origin_x#, origin_y#
		GetOrigin(origin_x, origin_y)

		Local x0# = 0.0
		Local x1# = tex_width
		Local y0# = 0.0
		Local y1# = tex_height
		Local tx# = x + origin_x
		Local ty# = y + origin_y

		' These are transform parameters.
		Const ix# = 1.0
		Const iy# = 0.0
		Const jx# = 0.0
		Const jy# = 1.0

		' Texture co-ordinates.
		Local u0# = 0.0
		Local u1# = Float(tex_width)/Float(img_width)
		Local v0# = 0.0
		Local v1# = Float(tex_height)/Float(img_height)

		' Calculate vertex positions
		ver[index*8 + 0] = x0*ix + y0*iy + tx		' x first
		ver[index*8 + 2] = x1*ix + y0*iy + tx
		ver[index*8 + 4] = x1*ix + y1*iy + tx
		ver[index*8 + 6] = x0*ix + y1*iy + tx

		ver[index*8 + 1] = x0*jx + y0*jy + ty		' now the y's
		ver[index*8 + 3] = x1*jx + y0*jy + ty
		ver[index*8 + 5] = x1*jx + y1*jy + ty
		ver[index*8 + 7] = x0*jx + y1*jy + ty
		
		' Extract texture co-ordinates
		tex[index*8 + 0] = u0
		tex[index*8 + 2] = u1
		tex[index*8 + 4] = u1
		tex[index*8 + 6] = u0

		tex[index*8 + 1] = v0
		tex[index*8 + 3] = v0
		tex[index*8 + 5] = v1
		tex[index*8 + 7] = v1
	End Method
End Type



' *****
' START
' *****

Graphics SCREEN_W, SCREEN_H, 0

Cls

Local img:TPixmap = LoadPixmap("ball.png")
Local imgArr:TImageArray = TImageArray.Create(img, ARRAY_SIZE)

SetBlend ALPHABLEND

For Local i=0 To (ARRAY_SIZE)-1
	Local x# = RndFloat()*SCREEN_W
	Local y# = RndFloat()*SCREEN_H

	imgArr.SetPos(i,x,y)
Next

imgArr.DrawAll()

Flip
WaitKey

Sorry about the length of that - what's the name of the tag that puts it in a scrollable box?

EDIT: Thanks, mephtis.

BTW, don't worry about the maths in the SetPos method. I just copied and pasted it (on the whole) from DrawImage. It basically sets four vertex co-ordinates per sprite (top-left, top-right, bottom-right, bottom-left in turn) with texture co-ordinates to match. It's more complex than it could be, because I've left in the transform bits that could potentially let you rotate the sprites.

codebox

To run the code, you must have ball.png from the samples in the same directory.