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) 2007-2020 Juan Linietsky, Ariel Manzur. */ 9 /* Copyright (c) 2014-2020 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 31 #ifndef RASTERIZERCANVASBASEGLES2_H 32 #define RASTERIZERCANVASBASEGLES2_H 33 34 #include "rasterizer_array_gles2.h" 35 #include "rasterizer_storage_gles2.h" 36 #include "servers/visual/rasterizer.h" 37 38 #include "shaders/canvas.glsl.gen.h" 39 #include "shaders/lens_distorted.glsl.gen.h" 40 41 #include "shaders/canvas_shadow.glsl.gen.h" 42 43 class RasterizerCanvasBaseGLES2 : public RasterizerCanvas { 44 public: 45 enum { 46 INSTANCE_ATTRIB_BASE = 8, 47 }; 48 49 struct Uniforms { 50 Transform projection_matrix; 51 52 Transform2D modelview_matrix; 53 Transform2D extra_matrix; 54 55 Color final_modulate; 56 57 float time; 58 }; 59 60 struct Data { 61 GLuint canvas_quad_vertices; 62 GLuint polygon_buffer; 63 GLuint polygon_index_buffer; 64 65 uint32_t polygon_buffer_size; 66 uint32_t polygon_index_buffer_size; 67 68 GLuint ninepatch_vertices; 69 GLuint ninepatch_elements; 70 } data; 71 72 struct State { 73 Uniforms uniforms; 74 bool canvas_texscreen_used; 75 CanvasShaderGLES2 canvas_shader; 76 CanvasShadowShaderGLES2 canvas_shadow_shader; 77 LensDistortedShaderGLES2 lens_shader; 78 79 bool using_texture_rect; 80 bool using_ninepatch; 81 bool using_skeleton; 82 83 Transform2D skeleton_transform; 84 Transform2D skeleton_transform_inverse; 85 Size2i skeleton_texture_size; 86 87 RID current_tex; 88 RID current_normal; 89 RasterizerStorageGLES2::Texture *current_tex_ptr; 90 91 Transform vp; 92 Light *using_light; 93 bool using_shadow; 94 bool using_transparent_rt; 95 96 } state; 97 98 typedef void Texture; 99 100 RasterizerSceneGLES2 *scene_render; 101 102 RasterizerStorageGLES2 *storage; 103 104 bool use_nvidia_rect_workaround; 105 106 void _set_uniforms(); 107 108 virtual RID light_internal_create(); 109 virtual void light_internal_update(RID p_rid, Light *p_light); 110 virtual void light_internal_free(RID p_rid); 111 112 virtual void canvas_begin(); 113 virtual void canvas_end(); 114 115 void _draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color *p_colors, const Vector2 *p_uvs); 116 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); 117 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); 118 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); 119 120 void _bind_quad_buffer(); 121 void _copy_texscreen(const Rect2 &p_rect); 122 void _copy_screen(const Rect2 &p_rect); 123 124 virtual void draw_window_margins(int *black_margin, RID *black_image); 125 void draw_generic_textured_rect(const Rect2 &p_rect, const Rect2 &p_src); 126 void draw_lens_distortion_rect(const Rect2 &p_rect, float p_k1, float p_k2, const Vector2 &p_eye_center, float p_oversample); 127 128 virtual void reset_canvas(); 129 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); 130 virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow); 131 132 RasterizerStorageGLES2::Texture *_bind_canvas_texture(const RID &p_texture, const RID &p_normal_map); 133 134 void initialize(); 135 void finalize(); 136 137 RasterizerCanvasBaseGLES2(); 138 }; 139 140 #endif // RASTERIZERCANVASBASEGLES2_H 141