2
0

rasterizer_canvas_gles3.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*************************************************************************/
  2. /* rasterizer_canvas_gles3.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
  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 RASTERIZERCANVASGLES3_H
  31. #define RASTERIZERCANVASGLES3_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 RasterizerCanvasGLES3 : 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. GLuint canvas_quad_vertices;
  47. GLuint canvas_quad_array;
  48. GLuint polygon_buffer;
  49. GLuint polygon_buffer_quad_arrays[4];
  50. GLuint polygon_buffer_pointer_array;
  51. GLuint polygon_index_buffer;
  52. GLuint particle_quad_vertices;
  53. GLuint particle_quad_array;
  54. uint32_t polygon_buffer_size;
  55. } data;
  56. struct State {
  57. CanvasItemUBO canvas_item_ubo_data;
  58. GLuint canvas_item_ubo;
  59. bool canvas_texscreen_used;
  60. CanvasShaderGLES3 canvas_shader;
  61. CanvasShadowShaderGLES3 canvas_shadow_shader;
  62. LensDistortedShaderGLES3 lens_shader;
  63. bool using_texture_rect;
  64. bool using_ninepatch;
  65. RID current_tex;
  66. RID current_normal;
  67. RasterizerStorageGLES3::Texture *current_tex_ptr;
  68. Transform vp;
  69. Color canvas_item_modulate;
  70. Transform2D extra_matrix;
  71. Transform2D final_transform;
  72. bool using_skeleton;
  73. Transform2D skeleton_transform;
  74. Transform2D skeleton_transform_inverse;
  75. } state;
  76. RasterizerStorageGLES3 *storage;
  77. struct LightInternal : public RID_Data {
  78. struct UBOData {
  79. float light_matrix[16];
  80. float local_matrix[16];
  81. float shadow_matrix[16];
  82. float color[4];
  83. float shadow_color[4];
  84. float light_pos[2];
  85. float shadowpixel_size;
  86. float shadow_gradient;
  87. float light_height;
  88. float light_outside_alpha;
  89. float shadow_distance_mult;
  90. uint8_t padding[4];
  91. } ubo_data;
  92. GLuint ubo;
  93. };
  94. RID_Owner<LightInternal> light_internal_owner;
  95. virtual RID light_internal_create();
  96. virtual void light_internal_update(RID p_rid, Light *p_light);
  97. virtual void light_internal_free(RID p_rid);
  98. virtual void canvas_begin();
  99. virtual void canvas_end();
  100. _FORCE_INLINE_ void _set_texture_rect_mode(bool p_enable, bool p_ninepatch = false);
  101. _FORCE_INLINE_ RasterizerStorageGLES3::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map, bool p_force = false);
  102. _FORCE_INLINE_ void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs);
  103. _FORCE_INLINE_ 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);
  104. _FORCE_INLINE_ 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);
  105. _FORCE_INLINE_ void _canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip);
  106. _FORCE_INLINE_ void _copy_texscreen(const Rect2 &p_rect);
  107. virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_transform);
  108. virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
  109. 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);
  110. virtual void reset_canvas();
  111. void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src);
  112. void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
  113. void initialize();
  114. void finalize();
  115. virtual void draw_window_margins(int *black_margin, RID *black_image);
  116. RasterizerCanvasGLES3();
  117. };
  118. #endif // RASTERIZERCANVASGLES3_H