2. The maximum value of the function $f(x)=2 \sin ^{2} x-\tan ^{2} x$ is $\qquad$
$$
\begin{array}{l}
f(x)=2 \sin ^{2} x-\frac{\sin ^{2} x}{\cos ^{2} x}=\frac{\sin ^{2} x\left(2 \cos ^{2} x-1\right)}{\cos ^{2} x}=-\frac{\left(\cos ^{2} x-1\right)\left(2 \cos ^{2} x-1\right)}{\cos ^{2} x} \\
=-\frac{2 \cos ^{4} x-3 \cos ^{2} x+1}{\cos ^{2} x}=3-\left(2 \cos ^{2} x+\frac{1}{\cos ^{2} x}\right) \leqslant 3-2 \sqrt{2},
\end{array}
$$

The equality holds when $\cos ^{2} x=\frac{\sqrt{2}}{2}$. Therefore, the maximum value of $f(x)=2 \sin ^{2} x-\tan ^{2} x$ is $3-2 \sqrt{2}$.