Team Fortress 2 Source Code as on 22/4/2020
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.

60 lines
2.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. // TOGL CODE LICENSE
  3. //
  4. // Copyright 2011-2014 Valve Corporation
  5. // All Rights Reserved.
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. //
  25. // intelglmallocworkaround.h
  26. // class responsible for setting up a malloc override that zeroes allocated
  27. // memory of less than 96 bytes. this is to work around a bug
  28. // in the Intel GLSL compiler on Mac OS X 10.8 due to uninitialized memory.
  29. //
  30. // 96 was chosen due to this quote from Apple:
  31. // "I verified that the size of the structure is exactly 64 bytes on 10.8.3, 10.8.4 and will be on 10.8.5."
  32. //
  33. // certain GLSL shaders would (intermittently) cause a crash the first time they
  34. // were drawn, and the bug has supposedly been fixed in 10.9, but is unlikely to
  35. // ever make it to 10.8.
  36. //
  37. //===============================================================================
  38. #ifndef INTELGLMALLOCWORKAROUND_H
  39. #define INTELGLMALLOCWORKAROUND_H
  40. #include <stdlib.h>
  41. class IntelGLMallocWorkaround
  42. {
  43. public:
  44. static IntelGLMallocWorkaround *Get();
  45. bool Enable();
  46. protected:
  47. IntelGLMallocWorkaround() :m_pfnMallocReentry(NULL) {}
  48. ~IntelGLMallocWorkaround() {}
  49. static IntelGLMallocWorkaround *s_pWorkaround;
  50. static void* ZeroingAlloc(size_t);
  51. typedef void* (*pfnMalloc_t)(size_t);
  52. pfnMalloc_t m_pfnMallocReentry;
  53. };
  54. #endif // INTELGLMALLOCWORKAROUND_H