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.

143 lines
3.7 KiB

  1. /*
  2. * This program source code file is part of KICAD, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2016 Kicad Developers, see change_log.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 2
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef OPENGL_ANTIALIASING_H__
  24. #define OPENGL_ANTIALIASING_H__
  25. #include <memory>
  26. #include <gal/opengl/shader.h>
  27. #include <math/vector2d.h>
  28. namespace KIGFX {
  29. class OPENGL_COMPOSITOR;
  30. class OPENGL_PRESENTOR
  31. {
  32. public:
  33. virtual ~OPENGL_PRESENTOR()
  34. {
  35. }
  36. virtual bool Init() = 0;
  37. virtual unsigned int CreateBuffer() = 0;
  38. virtual VECTOR2U GetInternalBufferSize() = 0;
  39. virtual void OnLostBuffers() = 0;
  40. virtual void Begin() = 0;
  41. virtual void DrawBuffer( GLuint aBuffer ) = 0;
  42. virtual void Present() = 0;
  43. };
  44. class ANTIALIASING_NONE : public OPENGL_PRESENTOR
  45. {
  46. public:
  47. ANTIALIASING_NONE( OPENGL_COMPOSITOR* aCompositor );
  48. bool Init() override;
  49. unsigned int CreateBuffer() override;
  50. VECTOR2U GetInternalBufferSize() override;
  51. void OnLostBuffers() override;
  52. void Begin() override;
  53. void DrawBuffer( GLuint aBuffer ) override;
  54. void Present() override;
  55. private:
  56. OPENGL_COMPOSITOR* compositor;
  57. };
  58. class ANTIALIASING_SUPERSAMPLING : public OPENGL_PRESENTOR
  59. {
  60. public:
  61. ANTIALIASING_SUPERSAMPLING( OPENGL_COMPOSITOR* aCompositor );
  62. bool Init() override;
  63. unsigned int CreateBuffer() override;
  64. VECTOR2U GetInternalBufferSize() override;
  65. void OnLostBuffers() override;
  66. void Begin() override;
  67. void DrawBuffer( GLuint ) override;
  68. void Present() override;
  69. private:
  70. OPENGL_COMPOSITOR* compositor;
  71. unsigned int ssaaMainBuffer;
  72. bool areBuffersCreated;
  73. bool areShadersCreated;
  74. };
  75. class ANTIALIASING_SMAA : public OPENGL_PRESENTOR
  76. {
  77. public:
  78. ANTIALIASING_SMAA( OPENGL_COMPOSITOR* aCompositor );
  79. bool Init() override;
  80. unsigned int CreateBuffer () override;
  81. VECTOR2U GetInternalBufferSize() override;
  82. void OnLostBuffers() override;
  83. void Begin() override;
  84. void DrawBuffer( GLuint buffer ) override;
  85. void Present() override;
  86. private:
  87. void loadShaders();
  88. void updateUniforms();
  89. bool areBuffersInitialized;
  90. unsigned int smaaBaseBuffer; // base + overlay temporary
  91. unsigned int smaaEdgesBuffer;
  92. unsigned int smaaBlendBuffer;
  93. // smaa shader lookup textures
  94. unsigned int smaaAreaTex;
  95. unsigned int smaaSearchTex;
  96. bool shadersLoaded;
  97. std::unique_ptr<SHADER> pass_1_shader;
  98. GLint pass_1_metrics;
  99. std::unique_ptr<SHADER> pass_2_shader;
  100. GLint pass_2_metrics;
  101. std::unique_ptr<SHADER> pass_3_shader;
  102. GLint pass_3_metrics;
  103. OPENGL_COMPOSITOR* compositor;
  104. };
  105. }
  106. #endif