rasterizer_canvas_base_gles2.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**************************************************************************/
  2. /* rasterizer_canvas_base_gles2.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_GLES2_H
  31. #define RASTERIZER_CANVAS_BASE_GLES2_H
  32. #include "drivers/gles_common/rasterizer_array.h"
  33. #include "rasterizer_storage_gles2.h"
  34. #include "servers/visual/rasterizer.h"
  35. #include "shaders/canvas.glsl.gen.h"
  36. #include "shaders/lens_distorted.glsl.gen.h"
  37. #include "drivers/gles_common/rasterizer_storage_common.h"
  38. #include "shaders/canvas_shadow.glsl.gen.h"
  39. class RasterizerCanvasBaseGLES2 : public RasterizerCanvas {
  40. public:
  41. enum {
  42. INSTANCE_ATTRIB_BASE = 8,
  43. };
  44. struct Uniforms {
  45. Transform projection_matrix;
  46. Transform2D modelview_matrix;
  47. Transform2D extra_matrix;
  48. Color final_modulate;
  49. float time;
  50. };
  51. struct Data {
  52. GLuint canvas_quad_vertices;
  53. GLuint polygon_buffer;
  54. GLuint polygon_index_buffer;
  55. uint32_t polygon_buffer_size;
  56. uint32_t polygon_index_buffer_size;
  57. GLuint ninepatch_vertices;
  58. GLuint ninepatch_elements;
  59. } data;
  60. struct State {
  61. Uniforms uniforms;
  62. bool canvas_texscreen_used;
  63. CanvasShaderGLES2 canvas_shader;
  64. CanvasShadowShaderGLES2 canvas_shadow_shader;
  65. LensDistortedShaderGLES2 lens_shader;
  66. bool using_texture_rect;
  67. bool using_light_angle;
  68. bool using_modulate;
  69. bool using_large_vertex;
  70. bool using_ninepatch;
  71. bool using_skeleton;
  72. Transform2D skeleton_transform;
  73. Transform2D skeleton_transform_inverse;
  74. Size2i skeleton_texture_size;
  75. RID current_tex;
  76. RID current_normal;
  77. RasterizerStorageGLES2::Texture *current_tex_ptr;
  78. Transform vp;
  79. Light *using_light;
  80. bool using_shadow;
  81. bool using_transparent_rt;
  82. } state;
  83. typedef void Texture;
  84. RasterizerSceneGLES2 *scene_render;
  85. RasterizerStorageGLES2 *storage;
  86. // allow user to choose api usage
  87. GLenum _buffer_upload_usage_flag;
  88. void _set_uniforms();
  89. virtual RID light_internal_create();
  90. virtual void light_internal_update(RID p_rid, Light *p_light);
  91. virtual void light_internal_free(RID p_rid);
  92. virtual void canvas_begin();
  93. virtual void canvas_end();
  94. 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);
  95. 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 = nullptr, const int *p_bones = nullptr);
  96. 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);
  97. 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);
  98. void _bind_quad_buffer();
  99. void _copy_texscreen(const Rect2 &p_rect);
  100. void _copy_screen(const Rect2 &p_rect);
  101. virtual void draw_window_margins(int *black_margin, RID *black_image);
  102. void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src);
  103. void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample);
  104. virtual void reset_canvas();
  105. 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);
  106. virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow);
  107. RasterizerStorageGLES2::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map);
  108. void _set_texture_rect_mode(bool p_texture_rect, bool p_light_angle = false, bool p_modulate = false, bool p_large_vertex = false);
  109. void initialize();
  110. void finalize();
  111. RasterizerCanvasBaseGLES2();
  112. };
  113. #endif // RASTERIZER_CANVAS_BASE_GLES2_H