drawing the same image 1000's of times

BlitzMax Forums/BlitzMax Programming/drawing the same image 1000's of times

Nate the Great(Posted 2010) [#1]
well im just wonering how I can optimize this. I read somewhere blitz max 'switches states' or something along those lines even if you are drawing the same image over again which makes it unnecesarry to switch, I would like it if these images could also vary in color without slowdown but I dont know if that is possible.

does anyone know how I would go about programming something like this, I cant find anything like that in the code archives.


ImaginaryHuman(Posted 2010) [#2]
When you do SetColor, the texture/image is not swapped at all, so you could do as many SetColor calls as you like, wherever you like, to `tint` the image that's drawn. Note that every image you draw actually has its color values multiplied by the tint color, even if the tint is just white. So when you do SetColor $FF,$0,$0 it'll only allow your image's red values to be output, for example. If this will suffice for changing colors, you could have a grayscale image and then tint it on the fly. But if you want more advanced color changes you'll have to get a bit more clever.

As far as texture swaps go, from looking at the GL code a while ago I seem to recall seeing that it would check to see if the texture being switched to was the same as the texture currently in use, and if so it would not attempt to do a texture swap. So as long as you draw from only one image it should be fast. I think.

If you need more images, either put them all on one image and draw rectangles from it, or rethink things.


Nate the Great(Posted 2010) [#3]
Thanks, its just one image and thats why I knew it could be optimized if it was switching texture buffers pointlessly between image draws. I didnt know bmax did that internally.


beanage(Posted 2010) [#4]
If you want to put some more effort in it, you should use an OpenGL vertex array, a Vertex Buffer, or a Displaylist (While using a displaylist is propably going to be the most easy one), to saving the cpu cycles on calling drawing comands for 1K+ Quads. In a hurry atm, but I will help you there if you want.

Just interested, is this about improving your SPH sim rendering speed? In that case, use a vertex array/buffer, and instead of updating the coordinates of particle objects, update the coords inside the opengl buffer. *excited giggling* :)