rasterizer_canvas_gles2.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*************************************************************************/
  2. /* rasterizer_canvas_gles2.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 RASTERIZERCANVASGLES2_H
  31. #define RASTERIZERCANVASGLES2_H
  32. #include "rasterizer_storage_gles2.h"
  33. #include "servers/visual/rasterizer.h"
  34. #include "shaders/canvas.glsl.gen.h"
  35. #include "shaders/lens_distorted.glsl.gen.h"
  36. #include "shaders/canvas_shadow.glsl.gen.h"
  37. class RasterizerSceneGLES2;
  38. class RasterizerCanvasGLES2 : public RasterizerCanvas {
  39. public:
  40. enum {
  41. INSTANCE_ATTRIB_BASE = 8,
  42. };
  43. struct Uniforms {
  44. Transform projection_matrix;
  45. Transform2D modelview_matrix;
  46. Transform2D extra_matrix;
  47. Color final_modulate;
  48. float time;
  49. };
  50. struct Data {
  51. GLuint canvas_quad_vertices;
  52. GLuint polygon_buffer;
  53. GLuint polygon_index_buffer;
  54. uint32_t polygon_buffer_size;
  55. GLuint ninepatch_vertices;
  56. GLuint ninepatch_elements;
  57. } data;
  58. struct State {
  59. Uniforms uniforms;
  60. bool canvas_texscreen_used;
  61. CanvasShaderGLES2 canvas_shader;
  62. CanvasShadowShaderGLES2 canvas_shadow_shader;
  63. LensDistortedShaderGLES2 lens_shader;
  64. bool using_texture_rect;
  65. bool using_ninepatch;
  66. bool using_skeleton;
  67. Transform2D skeleton_transform;
  68. Transform2D skeleton_transform_inverse;
  69. Vector2i skeleton_texture_size;
  70. RID current_tex;
  71. RID current_normal;
  72. RasterizerStorageGLES2::Texture *current_tex_ptr;
  73. Transform vp;
  74. } state;
  75. typedef void Texture;
  76. RasterizerSceneGLES2 *scene_render;
  77. RasterizerStorageGLES2 *storage;
  78. virtual RID light_internal_create();
  79. virtual void light_internal_update(RID p_rid, Light *p_light);
  80. virtual void light_internal_free(RID p_rid);
  81. void _set_uniforms();
  82. virtual void canvas_begin();
  83. virtual void canvas_end();
  84. _FORCE_INLINE_ void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs);
  85. _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 float *p_weights = NULL, const int *p_bones = NULL);
  86. _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);
  87. _FORCE_INLINE_ void _canvas_item_render_commands(Item *p_item, Item *current_clip, bool &reclip, RasterizerStorageGLES2::Material *p_material);
  88. _FORCE_INLINE_ void _copy_texscreen(const Rect2 &p_rect);
  89. virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform);
  90. virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
  91. 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);
  92. virtual void reset_canvas();
  93. RasterizerStorageGLES2::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map);
  94. void _bind_quad_buffer();
  95. void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src);
  96. void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
  97. void initialize();
  98. void finalize();
  99. virtual void draw_window_margins(int *black_margin, RID *black_image);
  100. RasterizerCanvasGLES2();
  101. };
  102. #endif // RASTERIZERCANVASGLES2_H