I'm currently working on a renderer for Tiled's .tmx maps. Among one of the features there is that layers and tilesets are independent, so that a layer can use any tile set on any tile. It's not so much of a problem, though, as my Image
type is basically:
data Image = Image { imageTexture :: TextureObject
, imageMinTex2 :: TexCoord2
, imageMaxTex2 :: TexCoord2
} deriving (Show, Eq)
Drawing an image is therefore
- Bind texture
- Render Quad using min/max texture coords
A quite simple implementation. However, if every Tile
is an Image
, in my implementation, then this would mean that on every tile, a texture is bound. Often times it will be the same, and quite often just a few tiles have entirely different texture.
So how expensive is a texture binding in OpenGL? Do I have to sort the Tiles by texture or will the OpenGL drivers do that for me?