rasterizer_canvas_base_gles3.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**************************************************************************/
  2. /* rasterizer_canvas_base_gles3.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 RASTERIZER_CANVAS_BASE_GLES3_H
  31. #define RASTERIZER_CANVAS_BASE_GLES3_H
  32. #include "rasterizer_storage_gles3.h"
  33. #include "servers/visual/rasterizer.h"
  34. #include "shaders/canvas_shadow.glsl.gen.h"
  35. #include "shaders/lens_distorted.glsl.gen.h"
  36. class RasterizerSceneGLES3;
  37. class RasterizerCanvasBaseGLES3 : public RasterizerCanvas {
  38. public:
  39. struct CanvasItemUBO {
  40. float projection_matrix[16];
  41. float time;
  42. uint8_t padding[12];
  43. };
  44. RasterizerSceneGLES3 *scene_render;
  45. struct Data {
  46. enum { NUM_QUAD_ARRAY_VARIATIONS = 8 };
  47. GLuint canvas_quad_vertices;
  48. GLuint canvas_quad_array;
  49. GLuint polygon_buffer;
  50. GLuint polygon_buffer_quad_arrays[NUM_QUAD_ARRAY_VARIATIONS];
  51. GLuint polygon_buffer_pointer_array;
  52. GLuint polygon_index_buffer;
  53. GLuint particle_quad_vertices;
  54. GLuint particle_quad_array;
  55. uint32_t polygon_buffer_size;
  56. uint32_t polygon_index_buffer_size;
  57. } data;
  58. struct State {
  59. CanvasItemUBO canvas_item_ubo_data;
  60. GLuint canvas_item_ubo;
  61. bool canvas_texscreen_used;
  62. CanvasShaderGLES3 canvas_shader;
  63. CanvasShadowShaderGLES3 canvas_shadow_shader;
  64. LensDistortedShaderGLES3 lens_shader;
  65. bool using_texture_rect;
  66. bool using_ninepatch;
  67. bool using_light_angle;
  68. bool using_modulate;
  69. bool using_large_vertex;
  70. RID current_tex;
  71. RID current_normal;
  72. RasterizerStorageGLES3::Texture *current_tex_ptr;
  73. Transform vp;
  74. Color canvas_item_modulate;
  75. Transform2D extra_matrix;
  76. Transform2D final_transform;
  77. bool using_skeleton;
  78. Transform2D skeleton_transform;
  79. Transform2D skeleton_transform_inverse;
  80. } state;
  81. RasterizerStorageGLES3 *storage;
  82. // allow user to choose api usage
  83. GLenum _buffer_upload_usage_flag;
  84. struct LightInternal : public RID_Data {
  85. struct UBOData {
  86. float light_matrix[16];
  87. float local_matrix[16];
  88. float shadow_matrix[16];
  89. float color[4];
  90. float shadow_color[4];
  91. float light_pos[2];
  92. float shadowpixel_size;
  93. float shadow_gradient;
  94. float light_height;
  95. float light_outside_alpha;
  96. float shadow_distance_mult;
  97. uint8_t padding[4];
  98. } ubo_data;
  99. GLuint ubo;
  100. };
  101. RID_Owner<LightInternal> light_internal_owner;
  102. virtual RID light_internal_create();
  103. virtual void light_internal_update(RID p_rid, Light *p_light);
  104. virtual void light_internal_free(RID p_rid);
  105. virtual void canvas_begin();
  106. virtual void canvas_end();
  107. void _set_texture_rect_mode(bool p_enable, bool p_ninepatch = false, bool p_light_angle = false, bool p_modulate = false, bool p_large_vertex = false);
  108. RasterizerStorageGLES3::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map, bool p_force = false);
  109. void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs, const float *p_light_angles = nullptr);
  110. void _draw_polygon(const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor, const int *p_bones, const float *p_weights);
  111. void _draw_generic(GLuint p_primitive, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor);
  112. void _draw_generic_indices(GLuint p_primitive, const int *p_indices, int p_index_count, int p_vertex_count, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, bool p_singlecolor);
  113. void _copy_texscreen(const Rect2 &p_rect);
  114. virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
  115. virtual void canvas_light_shadow_buffer_update(RID p_buffer, const Transform2D &p_light_xform, int p_light_mask, float p_near, float p_far, LightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache);
  116. virtual void reset_canvas();
  117. void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src);
  118. void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
  119. void render_rect_nvidia_workaround(const Item::CommandRect *p_rect, const RasterizerStorageGLES3::Texture *p_texture);
  120. void initialize();
  121. void finalize();
  122. virtual void draw_window_margins(int *black_margin, RID *black_image);
  123. RasterizerCanvasBaseGLES3();
  124. };
  125. #endif // RASTERIZER_CANVAS_BASE_GLES3_H