Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
2.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "mathlib/mathlib.h"
  7. #include "convar.h" // ConVar define
  8. #include "view.h"
  9. #include "gl_cvars.h" // mat_overbright
  10. #include "cmd.h" // Cmd_*
  11. #include "console.h" // ConMsg
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. static bool s_bAllow3DNow = true;
  15. static bool s_bAllowSSE2 = true;
  16. static void OnEnableFastMathChanged( IConVar *var = NULL, const char *pOldValue = NULL, float flOldValue = 0.0f);
  17. ConVar enable_fast_math( "enable_fast_math", "1" , FCVAR_RELEASE, "Turns Denormals-Are-Zeroes and Flush-to-Zero on or off", OnEnableFastMathChanged );
  18. // <sergiy> We should use consistent SSE flags on Linux and Windows to avoid different math/physics/casting results.
  19. // Also, we should try to use FZ/DAZ when we can because without it,
  20. // It would be preferable to use the verbose macros to set/reset FZ and DAZ modes on SSE, but
  21. // in Linux, we are using an outdated version of GCC that doesn't have those defined in standard headers.
  22. // So I'll just throw literals here until such time as we rev the version of GCC.
  23. static void OnEnableFastMathChanged( IConVar *var, const char *pOldValue, float flOldValue )
  24. {
  25. if ( enable_fast_math.GetBool() )
  26. {
  27. _mm_setcsr( _mm_getcsr() | 0x8040 );
  28. //_MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_ON );
  29. //_MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_ON );
  30. }
  31. else
  32. {
  33. _mm_setcsr( _mm_getcsr() & ~0x8040 );
  34. //_MM_SET_FLUSH_ZERO_MODE( _MM_FLUSH_ZERO_OFF );
  35. //_MM_SET_DENORMALS_ZERO_MODE( _MM_DENORMALS_ZERO_OFF );
  36. }
  37. }
  38. void InitMathlib( void )
  39. {
  40. MathLib_Init( 2.2f, // v_gamma.GetFloat()
  41. 2.2f, // v_texgamma.GetFloat()
  42. 0.0f /*v_brightness.GetFloat() */,
  43. 2.0f /*mat_overbright.GetInt() */, s_bAllow3DNow, true, s_bAllowSSE2, true );
  44. OnEnableFastMathChanged();
  45. }