feed_effects.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**************************************************************************/
  2. /* feed_effects.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifdef GLES3_ENABLED
  31. #include "feed_effects.h"
  32. #ifdef ANDROID_ENABLED
  33. #include <GLES3/gl3ext.h>
  34. #endif
  35. #define GL_PROGRAM_POINT_SIZE 0x8642
  36. using namespace GLES3;
  37. FeedEffects *FeedEffects::singleton = nullptr;
  38. FeedEffects *FeedEffects::get_singleton() {
  39. return singleton;
  40. }
  41. FeedEffects::FeedEffects() {
  42. singleton = this;
  43. feed.shader.initialize();
  44. feed.shader_version = feed.shader.version_create();
  45. feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT);
  46. { // Screen Triangle.
  47. glGenBuffers(1, &screen_triangle);
  48. glBindBuffer(GL_ARRAY_BUFFER, screen_triangle);
  49. const float qv[6] = {
  50. -1.0f,
  51. -1.0f,
  52. 3.0f,
  53. -1.0f,
  54. -1.0f,
  55. 3.0f,
  56. };
  57. glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 6, qv, GL_STATIC_DRAW);
  58. glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
  59. glGenVertexArrays(1, &screen_triangle_array);
  60. glBindVertexArray(screen_triangle_array);
  61. glBindBuffer(GL_ARRAY_BUFFER, screen_triangle);
  62. glVertexAttribPointer(RS::ARRAY_VERTEX, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 2, nullptr);
  63. glEnableVertexAttribArray(RS::ARRAY_VERTEX);
  64. glBindVertexArray(0);
  65. glBindBuffer(GL_ARRAY_BUFFER, 0); //unbind
  66. }
  67. }
  68. FeedEffects::~FeedEffects() {
  69. singleton = nullptr;
  70. glDeleteBuffers(1, &screen_triangle);
  71. glDeleteVertexArrays(1, &screen_triangle_array);
  72. feed.shader.version_free(feed.shader_version);
  73. }
  74. Transform3D transform3D_from_mat4(const float *p_mat4) {
  75. Transform3D res;
  76. res.basis.rows[0][0] = p_mat4[0];
  77. res.basis.rows[1][0] = p_mat4[1];
  78. res.basis.rows[2][0] = p_mat4[2];
  79. // p_mat4[3] = 0;
  80. res.basis.rows[0][1] = p_mat4[4];
  81. res.basis.rows[1][1] = p_mat4[5];
  82. res.basis.rows[2][1] = p_mat4[6];
  83. // p_mat4[7] = 0;
  84. res.basis.rows[0][2] = p_mat4[8];
  85. res.basis.rows[1][2] = p_mat4[9];
  86. res.basis.rows[2][2] = p_mat4[10];
  87. // p_mat4[11] = 0;
  88. res.origin.x = p_mat4[12];
  89. res.origin.y = p_mat4[13];
  90. res.origin.z = p_mat4[14];
  91. // p_mat4[15] = 1;
  92. return res;
  93. }
  94. void FeedEffects::draw() {
  95. bool success = feed.shader.version_bind_shader(feed.shader_version, FeedShaderGLES3::MODE_DEFAULT, FeedShaderGLES3::USE_EXTERNAL_SAMPLER);
  96. if (!success) {
  97. OS::get_singleton()->print("Godot : FeedShaderGLES3 Could not bind version_bind_shader USE_EXTERNAL_SAMPLER");
  98. return;
  99. }
  100. draw_screen_triangle();
  101. }
  102. void FeedEffects::draw_screen_triangle() {
  103. glBindVertexArray(screen_triangle_array);
  104. glDrawArrays(GL_TRIANGLES, 0, 3);
  105. glBindVertexArray(0);
  106. }
  107. #endif // GLES3_ENABLED