utilities.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /**************************************************************************/
  2. /* utilities.h */
  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. #ifndef UTILITIES_GLES3_H
  31. #define UTILITIES_GLES3_H
  32. #ifdef GLES3_ENABLED
  33. #include "servers/rendering/storage/utilities.h"
  34. #include "platform_config.h"
  35. #ifndef OPENGL_INCLUDE_H
  36. #include <GLES3/gl3.h>
  37. #else
  38. #include OPENGL_INCLUDE_H
  39. #endif
  40. namespace GLES3 {
  41. class Utilities : public RendererUtilities {
  42. private:
  43. static Utilities *singleton;
  44. public:
  45. static Utilities *get_singleton() { return singleton; }
  46. Utilities();
  47. ~Utilities();
  48. // Buffer size is specified in bytes
  49. static Vector<uint8_t> buffer_get_data(GLenum p_target, GLuint p_buffer, uint32_t p_buffer_size);
  50. /* INSTANCES */
  51. virtual RS::InstanceType get_base_type(RID p_rid) const override;
  52. virtual bool free(RID p_rid) override;
  53. /* DEPENDENCIES */
  54. virtual void base_update_dependency(RID p_base, DependencyTracker *p_instance) override;
  55. /* VISIBILITY NOTIFIER */
  56. virtual RID visibility_notifier_allocate() override;
  57. virtual void visibility_notifier_initialize(RID p_notifier) override;
  58. virtual void visibility_notifier_free(RID p_notifier) override;
  59. virtual void visibility_notifier_set_aabb(RID p_notifier, const AABB &p_aabb) override;
  60. virtual void visibility_notifier_set_callbacks(RID p_notifier, const Callable &p_enter_callbable, const Callable &p_exit_callable) override;
  61. virtual AABB visibility_notifier_get_aabb(RID p_notifier) const override;
  62. virtual void visibility_notifier_call(RID p_notifier, bool p_enter, bool p_deferred) override;
  63. /* TIMING */
  64. #define MAX_QUERIES 256
  65. #define FRAME_COUNT 3
  66. struct Frame {
  67. GLuint queries[MAX_QUERIES];
  68. TightLocalVector<String> timestamp_names;
  69. TightLocalVector<uint64_t> timestamp_cpu_values;
  70. uint32_t timestamp_count = 0;
  71. TightLocalVector<String> timestamp_result_names;
  72. TightLocalVector<uint64_t> timestamp_cpu_result_values;
  73. TightLocalVector<uint64_t> timestamp_result_values;
  74. uint32_t timestamp_result_count = 0;
  75. uint64_t index = 0;
  76. };
  77. const uint32_t max_timestamp_query_elements = MAX_QUERIES;
  78. Frame frames[FRAME_COUNT]; // Frames for capturing timestamps. We use 3 so we don't need to wait for commands to complete
  79. uint32_t frame = 0;
  80. virtual void capture_timestamps_begin() override;
  81. virtual void capture_timestamp(const String &p_name) override;
  82. virtual uint32_t get_captured_timestamps_count() const override;
  83. virtual uint64_t get_captured_timestamps_frame() const override;
  84. virtual uint64_t get_captured_timestamp_gpu_time(uint32_t p_index) const override;
  85. virtual uint64_t get_captured_timestamp_cpu_time(uint32_t p_index) const override;
  86. virtual String get_captured_timestamp_name(uint32_t p_index) const override;
  87. void _capture_timestamps_begin();
  88. void capture_timestamps_end();
  89. /* MISC */
  90. virtual void update_dirty_resources() override;
  91. virtual void set_debug_generate_wireframes(bool p_generate) override;
  92. virtual bool has_os_feature(const String &p_feature) const override;
  93. virtual void update_memory_info() override;
  94. virtual uint64_t get_rendering_info(RS::RenderingInfo p_info) override;
  95. virtual String get_video_adapter_name() const override;
  96. virtual String get_video_adapter_vendor() const override;
  97. virtual RenderingDevice::DeviceType get_video_adapter_type() const override;
  98. virtual String get_video_adapter_api_version() const override;
  99. virtual Size2i get_maximum_viewport_size() const override;
  100. };
  101. } // namespace GLES3
  102. #endif // GLES3_ENABLED
  103. #endif // UTILITIES_GLES3_H