renderMapTiles gl uProjM uViewM RenderMTilesProgram {..}
  = do
    useProgram gl . programId $ shader rmtRenderProg
    enableCoordsBuf gl
    enableTexCoordsBuf gl
    activeTexture gl gl_TEXTURE0

    -- supply shader with uniforms
    uniformMatrix4fv gl (uProjLoc rmtRenderProg) False (getProjM uProjM)
    uniformMatrix4fv gl (uViewLoc rmtRenderProg) False (getViewM uViewM)
    uniform1fv gl (uClippingDistLoc rmtRenderProg) (projMToClippingDist uProjM)
    uniform1i  gl (uSamplerLoc      rmtRenderProg) 0
    uniform1fv gl (uTexOpacityLoc   rmtRenderProg) rmtTexOpacity

    depthMask gl False
    bindBuffer gl gl_ARRAY_BUFFER (Just rmtTexCoordsBuffer) >> setTexCoordsBuf gl
    forM_ rmtTiles $ \MapTile{..} -> do
      bindTexture gl gl_TEXTURE_2D $ Just mtTexture
      bindBuffer gl gl_ARRAY_BUFFER (Just mtVertexBuffer) >> setCoordsBuf gl
      drawArrays gl gl_TRIANGLE_STRIP 0 4
    bindTexture gl gl_TEXTURE_2D Nothing
    depthMask gl True
    disableCoordsBuf gl
    disableTexCoordsBuf gl
renderMapTiles gl uProjM uViewM RenderMTilesProgram {..}
  = do
    useProgram gl . programId $ shader rmtRenderProg
    enableCoordsBuf gl
    enableTexCoordsBuf gl
    activeTexture gl gl_TEXTURE0

    -- supply shader with uniforms
    uniformMatrix4fv gl (uProjLoc rmtRenderProg) False (getProjM uProjM)
    uniformMatrix4fv gl (uViewLoc rmtRenderProg) False (getViewM uViewM)
    uniform1fv gl (uClippingDistLoc rmtRenderProg) (projMToClippingDist uProjM)
    uniform1i  gl (uSamplerLoc      rmtRenderProg) 0
    uniform1fv gl (uTexOpacityLoc   rmtRenderProg) rmtTexOpacity

    depthMask gl False
    bindBuffer gl gl_ARRAY_BUFFER (Just rmtTexCoordsBuffer) >> setTexCoordsBuf gl
    forM_ rmtTiles $ \MapTile{..} -> do
      bindTexture gl gl_TEXTURE_2D $ Just mtTexture
      bindBuffer gl gl_ARRAY_BUFFER (Just mtVertexBuffer) >> setCoordsBuf gl
      drawArrays gl gl_TRIANGLE_STRIP 0 4
    bindTexture gl gl_TEXTURE_2D Nothing
    depthMask gl True
    disableCoordsBuf gl
    disableTexCoordsBuf gl
renderMapTiles gl uProjM uViewM RenderMTilesProgram {..}
  = do
    useProgram gl . programId $ shader rmtRenderProg
    enableCoordsBuf gl
    enableTexCoordsBuf gl
    activeTexture gl gl_TEXTURE0

    -- supply shader with uniforms
    uniformMatrix4fv gl (uProjLoc rmtRenderProg) False (getProjM uProjM)
    uniformMatrix4fv gl (uViewLoc rmtRenderProg) False (getViewM uViewM)
    uniform1fv gl (uClippingDistLoc rmtRenderProg) (projMToClippingDist uProjM)
    uniform1i  gl (uSamplerLoc      rmtRenderProg) 0
    uniform1fv gl (uTexOpacityLoc   rmtRenderProg) rmtTexOpacity

    depthMask gl False
    bindBuffer gl gl_ARRAY_BUFFER (Just rmtTexCoordsBuffer) >> setTexCoordsBuf gl
    forM_ rmtTiles $ \MapTile{..} -> do
      bindTexture gl gl_TEXTURE_2D $ Just mtTexture
      bindBuffer gl gl_ARRAY_BUFFER (Just mtVertexBuffer) >> setCoordsBuf gl
      drawArrays gl gl_TRIANGLE_STRIP 0 4
    bindTexture gl gl_TEXTURE_2D Nothing
    depthMask gl True
    disableCoordsBuf gl
    disableTexCoordsBuf gl