rasterizer.h 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. /*************************************************************************/
  2. /* rasterizer.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 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 RASTERIZER_H
  31. #define RASTERIZER_H
  32. #include "camera_matrix.h"
  33. #include "servers/visual_server.h"
  34. #include "self_list.h"
  35. class RasterizerScene {
  36. public:
  37. /* SHADOW ATLAS API */
  38. virtual RID shadow_atlas_create() = 0;
  39. virtual void shadow_atlas_set_size(RID p_atlas, int p_size) = 0;
  40. virtual void shadow_atlas_set_quadrant_subdivision(RID p_atlas, int p_quadrant, int p_subdivision) = 0;
  41. virtual bool shadow_atlas_update_light(RID p_atlas, RID p_light_intance, float p_coverage, uint64_t p_light_version) = 0;
  42. virtual int get_directional_light_shadow_size(RID p_light_intance) = 0;
  43. virtual void set_directional_shadow_count(int p_count) = 0;
  44. /* ENVIRONMENT API */
  45. virtual RID environment_create() = 0;
  46. virtual void environment_set_background(RID p_env, VS::EnvironmentBG p_bg) = 0;
  47. virtual void environment_set_sky(RID p_env, RID p_sky) = 0;
  48. virtual void environment_set_sky_custom_fov(RID p_env, float p_scale) = 0;
  49. virtual void environment_set_bg_color(RID p_env, const Color &p_color) = 0;
  50. virtual void environment_set_bg_energy(RID p_env, float p_energy) = 0;
  51. virtual void environment_set_canvas_max_layer(RID p_env, int p_max_layer) = 0;
  52. virtual void environment_set_ambient_light(RID p_env, const Color &p_color, float p_energy = 1.0, float p_sky_contribution = 0.0) = 0;
  53. virtual void environment_set_dof_blur_near(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) = 0;
  54. virtual void environment_set_dof_blur_far(RID p_env, bool p_enable, float p_distance, float p_transition, float p_far_amount, VS::EnvironmentDOFBlurQuality p_quality) = 0;
  55. virtual void environment_set_glow(RID p_env, bool p_enable, int p_level_flags, float p_intensity, float p_strength, float p_bloom_threshold, VS::EnvironmentGlowBlendMode p_blend_mode, float p_hdr_bleed_threshold, float p_hdr_bleed_scale, bool p_bicubic_upscale) = 0;
  56. virtual void environment_set_fog(RID p_env, bool p_enable, float p_begin, float p_end, RID p_gradient_texture) = 0;
  57. virtual void environment_set_ssr(RID p_env, bool p_enable, int p_max_steps, float p_fade_int, float p_fade_out, float p_depth_tolerance, bool p_roughness) = 0;
  58. virtual void environment_set_ssao(RID p_env, bool p_enable, float p_radius, float p_intensity, float p_radius2, float p_intensity2, float p_bias, float p_light_affect, float p_ao_channel_affect, const Color &p_color, VS::EnvironmentSSAOQuality p_quality, VS::EnvironmentSSAOBlur p_blur, float p_bilateral_sharpness) = 0;
  59. virtual void environment_set_tonemap(RID p_env, VS::EnvironmentToneMapper p_tone_mapper, float p_exposure, float p_white, bool p_auto_exposure, float p_min_luminance, float p_max_luminance, float p_auto_exp_speed, float p_auto_exp_scale) = 0;
  60. virtual void environment_set_adjustment(RID p_env, bool p_enable, float p_brightness, float p_contrast, float p_saturation, RID p_ramp) = 0;
  61. virtual void environment_set_fog(RID p_env, bool p_enable, const Color &p_color, const Color &p_sun_color, float p_sun_amount) = 0;
  62. virtual void environment_set_fog_depth(RID p_env, bool p_enable, float p_depth_begin, float p_depth_curve, bool p_transmit, float p_transmit_curve) = 0;
  63. virtual void environment_set_fog_height(RID p_env, bool p_enable, float p_min_height, float p_max_height, float p_height_curve) = 0;
  64. virtual bool is_environment(RID p_env) = 0;
  65. virtual VS::EnvironmentBG environment_get_background(RID p_env) = 0;
  66. virtual int environment_get_canvas_max_layer(RID p_env) = 0;
  67. struct InstanceBase : RID_Data {
  68. VS::InstanceType base_type;
  69. RID base;
  70. RID skeleton;
  71. RID material_override;
  72. Transform transform;
  73. int depth_layer;
  74. uint32_t layer_mask;
  75. //RID sampled_light;
  76. Vector<RID> materials;
  77. Vector<RID> light_instances;
  78. Vector<RID> reflection_probe_instances;
  79. Vector<RID> gi_probe_instances;
  80. Vector<float> blend_values;
  81. VS::ShadowCastingSetting cast_shadows;
  82. //fit in 32 bits
  83. bool mirror : 8;
  84. bool receive_shadows : 8;
  85. bool visible : 8;
  86. bool baked_light : 4; //this flag is only to know if it actually did use baked light
  87. bool redraw_if_visible : 4;
  88. float depth; //used for sorting
  89. SelfList<InstanceBase> dependency_item;
  90. InstanceBase *lightmap_capture;
  91. RID lightmap;
  92. Vector<Color> lightmap_capture_data; //in a array (12 values) to avoid wasting space if unused. Alpha is unused, but needed to send to shader
  93. virtual void base_removed() = 0;
  94. virtual void base_changed() = 0;
  95. virtual void base_material_changed() = 0;
  96. InstanceBase() :
  97. dependency_item(this) {
  98. base_type = VS::INSTANCE_NONE;
  99. cast_shadows = VS::SHADOW_CASTING_SETTING_ON;
  100. receive_shadows = true;
  101. visible = true;
  102. depth_layer = 0;
  103. layer_mask = 1;
  104. baked_light = false;
  105. redraw_if_visible = false;
  106. lightmap_capture = NULL;
  107. }
  108. };
  109. virtual RID light_instance_create(RID p_light) = 0;
  110. virtual void light_instance_set_transform(RID p_light_instance, const Transform &p_transform) = 0;
  111. virtual void light_instance_set_shadow_transform(RID p_light_instance, const CameraMatrix &p_projection, const Transform &p_transform, float p_far, float p_split, int p_pass, float p_bias_scale = 1.0) = 0;
  112. virtual void light_instance_mark_visible(RID p_light_instance) = 0;
  113. virtual RID reflection_atlas_create() = 0;
  114. virtual void reflection_atlas_set_size(RID p_ref_atlas, int p_size) = 0;
  115. virtual void reflection_atlas_set_subdivision(RID p_ref_atlas, int p_subdiv) = 0;
  116. virtual RID reflection_probe_instance_create(RID p_probe) = 0;
  117. virtual void reflection_probe_instance_set_transform(RID p_instance, const Transform &p_transform) = 0;
  118. virtual void reflection_probe_release_atlas_index(RID p_instance) = 0;
  119. virtual bool reflection_probe_instance_needs_redraw(RID p_instance) = 0;
  120. virtual bool reflection_probe_instance_has_reflection(RID p_instance) = 0;
  121. virtual bool reflection_probe_instance_begin_render(RID p_instance, RID p_reflection_atlas) = 0;
  122. virtual bool reflection_probe_instance_postprocess_step(RID p_instance) = 0;
  123. virtual RID gi_probe_instance_create() = 0;
  124. virtual void gi_probe_instance_set_light_data(RID p_probe, RID p_base, RID p_data) = 0;
  125. virtual void gi_probe_instance_set_transform_to_data(RID p_probe, const Transform &p_xform) = 0;
  126. virtual void gi_probe_instance_set_bounds(RID p_probe, const Vector3 &p_bounds) = 0;
  127. virtual void render_scene(const Transform &p_cam_transform, const CameraMatrix &p_cam_projection, bool p_cam_ortogonal, InstanceBase **p_cull_result, int p_cull_count, RID *p_light_cull_result, int p_light_cull_count, RID *p_reflection_probe_cull_result, int p_reflection_probe_cull_count, RID p_environment, RID p_shadow_atlas, RID p_reflection_atlas, RID p_reflection_probe, int p_reflection_probe_pass) = 0;
  128. virtual void render_shadow(RID p_light, RID p_shadow_atlas, int p_pass, InstanceBase **p_cull_result, int p_cull_count) = 0;
  129. virtual void set_scene_pass(uint64_t p_pass) = 0;
  130. virtual void set_debug_draw_mode(VS::ViewportDebugDraw p_debug_draw) = 0;
  131. virtual bool free(RID p_rid) = 0;
  132. virtual ~RasterizerScene() {}
  133. };
  134. class RasterizerStorage {
  135. public:
  136. /* TEXTURE API */
  137. virtual RID texture_create() = 0;
  138. virtual void texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags = VS::TEXTURE_FLAGS_DEFAULT) = 0;
  139. virtual void texture_set_data(RID p_texture, const Ref<Image> &p_image, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) = 0;
  140. virtual void texture_set_data_partial(RID p_texture, const Ref<Image> &p_image, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int p_dst_mip, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) = 0;
  141. virtual Ref<Image> texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side = VS::CUBEMAP_LEFT) const = 0;
  142. virtual void texture_set_flags(RID p_texture, uint32_t p_flags) = 0;
  143. virtual uint32_t texture_get_flags(RID p_texture) const = 0;
  144. virtual Image::Format texture_get_format(RID p_texture) const = 0;
  145. virtual uint32_t texture_get_texid(RID p_texture) const = 0;
  146. virtual uint32_t texture_get_width(RID p_texture) const = 0;
  147. virtual uint32_t texture_get_height(RID p_texture) const = 0;
  148. virtual void texture_set_size_override(RID p_texture, int p_width, int p_height) = 0;
  149. virtual void texture_set_path(RID p_texture, const String &p_path) = 0;
  150. virtual String texture_get_path(RID p_texture) const = 0;
  151. virtual void texture_set_shrink_all_x2_on_set_data(bool p_enable) = 0;
  152. virtual void texture_debug_usage(List<VS::TextureInfo> *r_info) = 0;
  153. virtual RID texture_create_radiance_cubemap(RID p_source, int p_resolution = -1) const = 0;
  154. virtual void texture_set_detect_3d_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) = 0;
  155. virtual void texture_set_detect_srgb_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) = 0;
  156. virtual void texture_set_detect_normal_callback(RID p_texture, VisualServer::TextureDetectCallback p_callback, void *p_userdata) = 0;
  157. virtual void textures_keep_original(bool p_enable) = 0;
  158. virtual void texture_set_proxy(RID p_proxy, RID p_base) = 0;
  159. virtual void texture_set_force_redraw_if_visible(RID p_texture, bool p_enable) = 0;
  160. /* SKY API */
  161. virtual RID sky_create() = 0;
  162. virtual void sky_set_texture(RID p_sky, RID p_cube_map, int p_radiance_size) = 0;
  163. /* SHADER API */
  164. virtual RID shader_create() = 0;
  165. virtual void shader_set_code(RID p_shader, const String &p_code) = 0;
  166. virtual String shader_get_code(RID p_shader) const = 0;
  167. virtual void shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const = 0;
  168. virtual void shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) = 0;
  169. virtual RID shader_get_default_texture_param(RID p_shader, const StringName &p_name) const = 0;
  170. /* COMMON MATERIAL API */
  171. virtual RID material_create() = 0;
  172. virtual void material_set_render_priority(RID p_material, int priority) = 0;
  173. virtual void material_set_shader(RID p_shader_material, RID p_shader) = 0;
  174. virtual RID material_get_shader(RID p_shader_material) const = 0;
  175. virtual void material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) = 0;
  176. virtual Variant material_get_param(RID p_material, const StringName &p_param) const = 0;
  177. virtual void material_set_line_width(RID p_material, float p_width) = 0;
  178. virtual void material_set_next_pass(RID p_material, RID p_next_material) = 0;
  179. virtual bool material_is_animated(RID p_material) = 0;
  180. virtual bool material_casts_shadows(RID p_material) = 0;
  181. virtual void material_add_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) = 0;
  182. virtual void material_remove_instance_owner(RID p_material, RasterizerScene::InstanceBase *p_instance) = 0;
  183. /* MESH API */
  184. virtual RID mesh_create() = 0;
  185. virtual void mesh_add_surface(RID p_mesh, uint32_t p_format, VS::PrimitiveType p_primitive, const PoolVector<uint8_t> &p_array, int p_vertex_count, const PoolVector<uint8_t> &p_index_array, int p_index_count, const AABB &p_aabb, const Vector<PoolVector<uint8_t> > &p_blend_shapes = Vector<PoolVector<uint8_t> >(), const Vector<AABB> &p_bone_aabbs = Vector<AABB>()) = 0;
  186. virtual void mesh_set_blend_shape_count(RID p_mesh, int p_amount) = 0;
  187. virtual int mesh_get_blend_shape_count(RID p_mesh) const = 0;
  188. virtual void mesh_set_blend_shape_mode(RID p_mesh, VS::BlendShapeMode p_mode) = 0;
  189. virtual VS::BlendShapeMode mesh_get_blend_shape_mode(RID p_mesh) const = 0;
  190. virtual void mesh_surface_update_region(RID p_mesh, int p_surface, int p_offset, const PoolVector<uint8_t> &p_data) = 0;
  191. virtual void mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material) = 0;
  192. virtual RID mesh_surface_get_material(RID p_mesh, int p_surface) const = 0;
  193. virtual int mesh_surface_get_array_len(RID p_mesh, int p_surface) const = 0;
  194. virtual int mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const = 0;
  195. virtual PoolVector<uint8_t> mesh_surface_get_array(RID p_mesh, int p_surface) const = 0;
  196. virtual PoolVector<uint8_t> mesh_surface_get_index_array(RID p_mesh, int p_surface) const = 0;
  197. virtual uint32_t mesh_surface_get_format(RID p_mesh, int p_surface) const = 0;
  198. virtual VS::PrimitiveType mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const = 0;
  199. virtual AABB mesh_surface_get_aabb(RID p_mesh, int p_surface) const = 0;
  200. virtual Vector<PoolVector<uint8_t> > mesh_surface_get_blend_shapes(RID p_mesh, int p_surface) const = 0;
  201. virtual Vector<AABB> mesh_surface_get_skeleton_aabb(RID p_mesh, int p_surface) const = 0;
  202. virtual void mesh_remove_surface(RID p_mesh, int p_index) = 0;
  203. virtual int mesh_get_surface_count(RID p_mesh) const = 0;
  204. virtual void mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) = 0;
  205. virtual AABB mesh_get_custom_aabb(RID p_mesh) const = 0;
  206. virtual AABB mesh_get_aabb(RID p_mesh, RID p_skeleton) const = 0;
  207. virtual void mesh_clear(RID p_mesh) = 0;
  208. /* MULTIMESH API */
  209. virtual RID multimesh_create() = 0;
  210. virtual void multimesh_allocate(RID p_multimesh, int p_instances, VS::MultimeshTransformFormat p_transform_format, VS::MultimeshColorFormat p_color_format, VS::MultimeshCustomDataFormat p_data = VS::MULTIMESH_CUSTOM_DATA_NONE) = 0;
  211. virtual int multimesh_get_instance_count(RID p_multimesh) const = 0;
  212. virtual void multimesh_set_mesh(RID p_multimesh, RID p_mesh) = 0;
  213. virtual void multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) = 0;
  214. virtual void multimesh_instance_set_transform_2d(RID p_multimesh, int p_index, const Transform2D &p_transform) = 0;
  215. virtual void multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) = 0;
  216. virtual void multimesh_instance_set_custom_data(RID p_multimesh, int p_index, const Color &p_color) = 0;
  217. virtual RID multimesh_get_mesh(RID p_multimesh) const = 0;
  218. virtual Transform multimesh_instance_get_transform(RID p_multimesh, int p_index) const = 0;
  219. virtual Transform2D multimesh_instance_get_transform_2d(RID p_multimesh, int p_index) const = 0;
  220. virtual Color multimesh_instance_get_color(RID p_multimesh, int p_index) const = 0;
  221. virtual Color multimesh_instance_get_custom_data(RID p_multimesh, int p_index) const = 0;
  222. virtual void multimesh_set_as_bulk_array(RID p_multimesh, const PoolVector<float> &p_array) = 0;
  223. virtual void multimesh_set_visible_instances(RID p_multimesh, int p_visible) = 0;
  224. virtual int multimesh_get_visible_instances(RID p_multimesh) const = 0;
  225. virtual AABB multimesh_get_aabb(RID p_multimesh) const = 0;
  226. /* IMMEDIATE API */
  227. virtual RID immediate_create() = 0;
  228. virtual void immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture = RID()) = 0;
  229. virtual void immediate_vertex(RID p_immediate, const Vector3 &p_vertex) = 0;
  230. virtual void immediate_normal(RID p_immediate, const Vector3 &p_normal) = 0;
  231. virtual void immediate_tangent(RID p_immediate, const Plane &p_tangent) = 0;
  232. virtual void immediate_color(RID p_immediate, const Color &p_color) = 0;
  233. virtual void immediate_uv(RID p_immediate, const Vector2 &tex_uv) = 0;
  234. virtual void immediate_uv2(RID p_immediate, const Vector2 &tex_uv) = 0;
  235. virtual void immediate_end(RID p_immediate) = 0;
  236. virtual void immediate_clear(RID p_immediate) = 0;
  237. virtual void immediate_set_material(RID p_immediate, RID p_material) = 0;
  238. virtual RID immediate_get_material(RID p_immediate) const = 0;
  239. virtual AABB immediate_get_aabb(RID p_immediate) const = 0;
  240. /* SKELETON API */
  241. virtual RID skeleton_create() = 0;
  242. virtual void skeleton_allocate(RID p_skeleton, int p_bones, bool p_2d_skeleton = false) = 0;
  243. virtual int skeleton_get_bone_count(RID p_skeleton) const = 0;
  244. virtual void skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) = 0;
  245. virtual Transform skeleton_bone_get_transform(RID p_skeleton, int p_bone) const = 0;
  246. virtual void skeleton_bone_set_transform_2d(RID p_skeleton, int p_bone, const Transform2D &p_transform) = 0;
  247. virtual Transform2D skeleton_bone_get_transform_2d(RID p_skeleton, int p_bone) const = 0;
  248. virtual void skeleton_set_base_transform_2d(RID p_skeleton, const Transform2D &p_base_transform) = 0;
  249. /* Light API */
  250. virtual RID light_create(VS::LightType p_type) = 0;
  251. RID directional_light_create() { return light_create(VS::LIGHT_DIRECTIONAL); }
  252. RID omni_light_create() { return light_create(VS::LIGHT_OMNI); }
  253. RID spot_light_create() { return light_create(VS::LIGHT_SPOT); }
  254. virtual void light_set_color(RID p_light, const Color &p_color) = 0;
  255. virtual void light_set_param(RID p_light, VS::LightParam p_param, float p_value) = 0;
  256. virtual void light_set_shadow(RID p_light, bool p_enabled) = 0;
  257. virtual void light_set_shadow_color(RID p_light, const Color &p_color) = 0;
  258. virtual void light_set_projector(RID p_light, RID p_texture) = 0;
  259. virtual void light_set_negative(RID p_light, bool p_enable) = 0;
  260. virtual void light_set_cull_mask(RID p_light, uint32_t p_mask) = 0;
  261. virtual void light_set_reverse_cull_face_mode(RID p_light, bool p_enabled) = 0;
  262. virtual void light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) = 0;
  263. virtual void light_omni_set_shadow_detail(RID p_light, VS::LightOmniShadowDetail p_detail) = 0;
  264. virtual void light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) = 0;
  265. virtual void light_directional_set_blend_splits(RID p_light, bool p_enable) = 0;
  266. virtual bool light_directional_get_blend_splits(RID p_light) const = 0;
  267. virtual void light_directional_set_shadow_depth_range_mode(RID p_light, VS::LightDirectionalShadowDepthRangeMode p_range_mode) = 0;
  268. virtual VS::LightDirectionalShadowDepthRangeMode light_directional_get_shadow_depth_range_mode(RID p_light) const = 0;
  269. virtual VS::LightDirectionalShadowMode light_directional_get_shadow_mode(RID p_light) = 0;
  270. virtual VS::LightOmniShadowMode light_omni_get_shadow_mode(RID p_light) = 0;
  271. virtual bool light_has_shadow(RID p_light) const = 0;
  272. virtual VS::LightType light_get_type(RID p_light) const = 0;
  273. virtual AABB light_get_aabb(RID p_light) const = 0;
  274. virtual float light_get_param(RID p_light, VS::LightParam p_param) = 0;
  275. virtual Color light_get_color(RID p_light) = 0;
  276. virtual uint64_t light_get_version(RID p_light) const = 0;
  277. /* PROBE API */
  278. virtual RID reflection_probe_create() = 0;
  279. virtual void reflection_probe_set_update_mode(RID p_probe, VS::ReflectionProbeUpdateMode p_mode) = 0;
  280. virtual void reflection_probe_set_intensity(RID p_probe, float p_intensity) = 0;
  281. virtual void reflection_probe_set_interior_ambient(RID p_probe, const Color &p_ambient) = 0;
  282. virtual void reflection_probe_set_interior_ambient_energy(RID p_probe, float p_energy) = 0;
  283. virtual void reflection_probe_set_interior_ambient_probe_contribution(RID p_probe, float p_contrib) = 0;
  284. virtual void reflection_probe_set_max_distance(RID p_probe, float p_distance) = 0;
  285. virtual void reflection_probe_set_extents(RID p_probe, const Vector3 &p_extents) = 0;
  286. virtual void reflection_probe_set_origin_offset(RID p_probe, const Vector3 &p_offset) = 0;
  287. virtual void reflection_probe_set_as_interior(RID p_probe, bool p_enable) = 0;
  288. virtual void reflection_probe_set_enable_box_projection(RID p_probe, bool p_enable) = 0;
  289. virtual void reflection_probe_set_enable_shadows(RID p_probe, bool p_enable) = 0;
  290. virtual void reflection_probe_set_cull_mask(RID p_probe, uint32_t p_layers) = 0;
  291. virtual AABB reflection_probe_get_aabb(RID p_probe) const = 0;
  292. virtual VS::ReflectionProbeUpdateMode reflection_probe_get_update_mode(RID p_probe) const = 0;
  293. virtual uint32_t reflection_probe_get_cull_mask(RID p_probe) const = 0;
  294. virtual Vector3 reflection_probe_get_extents(RID p_probe) const = 0;
  295. virtual Vector3 reflection_probe_get_origin_offset(RID p_probe) const = 0;
  296. virtual float reflection_probe_get_origin_max_distance(RID p_probe) const = 0;
  297. virtual bool reflection_probe_renders_shadows(RID p_probe) const = 0;
  298. virtual void instance_add_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) = 0;
  299. virtual void instance_remove_skeleton(RID p_skeleton, RasterizerScene::InstanceBase *p_instance) = 0;
  300. virtual void instance_add_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) = 0;
  301. virtual void instance_remove_dependency(RID p_base, RasterizerScene::InstanceBase *p_instance) = 0;
  302. /* GI PROBE API */
  303. virtual RID gi_probe_create() = 0;
  304. virtual void gi_probe_set_bounds(RID p_probe, const AABB &p_bounds) = 0;
  305. virtual AABB gi_probe_get_bounds(RID p_probe) const = 0;
  306. virtual void gi_probe_set_cell_size(RID p_probe, float p_range) = 0;
  307. virtual float gi_probe_get_cell_size(RID p_probe) const = 0;
  308. virtual void gi_probe_set_to_cell_xform(RID p_probe, const Transform &p_xform) = 0;
  309. virtual Transform gi_probe_get_to_cell_xform(RID p_probe) const = 0;
  310. virtual void gi_probe_set_dynamic_data(RID p_probe, const PoolVector<int> &p_data) = 0;
  311. virtual PoolVector<int> gi_probe_get_dynamic_data(RID p_probe) const = 0;
  312. virtual void gi_probe_set_dynamic_range(RID p_probe, int p_range) = 0;
  313. virtual int gi_probe_get_dynamic_range(RID p_probe) const = 0;
  314. virtual void gi_probe_set_energy(RID p_probe, float p_range) = 0;
  315. virtual float gi_probe_get_energy(RID p_probe) const = 0;
  316. virtual void gi_probe_set_bias(RID p_probe, float p_range) = 0;
  317. virtual float gi_probe_get_bias(RID p_probe) const = 0;
  318. virtual void gi_probe_set_normal_bias(RID p_probe, float p_range) = 0;
  319. virtual float gi_probe_get_normal_bias(RID p_probe) const = 0;
  320. virtual void gi_probe_set_propagation(RID p_probe, float p_range) = 0;
  321. virtual float gi_probe_get_propagation(RID p_probe) const = 0;
  322. virtual void gi_probe_set_interior(RID p_probe, bool p_enable) = 0;
  323. virtual bool gi_probe_is_interior(RID p_probe) const = 0;
  324. virtual void gi_probe_set_compress(RID p_probe, bool p_enable) = 0;
  325. virtual bool gi_probe_is_compressed(RID p_probe) const = 0;
  326. virtual uint32_t gi_probe_get_version(RID p_probe) = 0;
  327. enum GIProbeCompression {
  328. GI_PROBE_UNCOMPRESSED,
  329. GI_PROBE_S3TC,
  330. GI_PROBE_ETC2
  331. };
  332. virtual GIProbeCompression gi_probe_get_dynamic_data_get_preferred_compression() const = 0;
  333. virtual RID gi_probe_dynamic_data_create(int p_width, int p_height, int p_depth, GIProbeCompression p_compression) = 0;
  334. virtual void gi_probe_dynamic_data_update(RID p_gi_probe_data, int p_depth_slice, int p_slice_count, int p_mipmap, const void *p_data) = 0;
  335. /* LIGHTMAP CAPTURE */
  336. struct LightmapCaptureOctree {
  337. enum {
  338. CHILD_EMPTY = 0xFFFFFFFF
  339. };
  340. uint16_t light[6][3]; //anisotropic light
  341. float alpha;
  342. uint32_t children[8];
  343. };
  344. virtual RID lightmap_capture_create() = 0;
  345. virtual void lightmap_capture_set_bounds(RID p_capture, const AABB &p_bounds) = 0;
  346. virtual AABB lightmap_capture_get_bounds(RID p_capture) const = 0;
  347. virtual void lightmap_capture_set_octree(RID p_capture, const PoolVector<uint8_t> &p_octree) = 0;
  348. virtual PoolVector<uint8_t> lightmap_capture_get_octree(RID p_capture) const = 0;
  349. virtual void lightmap_capture_set_octree_cell_transform(RID p_capture, const Transform &p_xform) = 0;
  350. virtual Transform lightmap_capture_get_octree_cell_transform(RID p_capture) const = 0;
  351. virtual void lightmap_capture_set_octree_cell_subdiv(RID p_capture, int p_subdiv) = 0;
  352. virtual int lightmap_capture_get_octree_cell_subdiv(RID p_capture) const = 0;
  353. virtual void lightmap_capture_set_energy(RID p_capture, float p_energy) = 0;
  354. virtual float lightmap_capture_get_energy(RID p_capture) const = 0;
  355. virtual const PoolVector<LightmapCaptureOctree> *lightmap_capture_get_octree_ptr(RID p_capture) const = 0;
  356. /* PARTICLES */
  357. virtual RID particles_create() = 0;
  358. virtual void particles_set_emitting(RID p_particles, bool p_emitting) = 0;
  359. virtual bool particles_get_emitting(RID p_particles) = 0;
  360. virtual void particles_set_amount(RID p_particles, int p_amount) = 0;
  361. virtual void particles_set_lifetime(RID p_particles, float p_lifetime) = 0;
  362. virtual void particles_set_one_shot(RID p_particles, bool p_one_shot) = 0;
  363. virtual void particles_set_pre_process_time(RID p_particles, float p_time) = 0;
  364. virtual void particles_set_explosiveness_ratio(RID p_particles, float p_ratio) = 0;
  365. virtual void particles_set_randomness_ratio(RID p_particles, float p_ratio) = 0;
  366. virtual void particles_set_custom_aabb(RID p_particles, const AABB &p_aabb) = 0;
  367. virtual void particles_set_speed_scale(RID p_particles, float p_scale) = 0;
  368. virtual void particles_set_use_local_coordinates(RID p_particles, bool p_enable) = 0;
  369. virtual void particles_set_process_material(RID p_particles, RID p_material) = 0;
  370. virtual void particles_set_fixed_fps(RID p_particles, int p_fps) = 0;
  371. virtual void particles_set_fractional_delta(RID p_particles, bool p_enable) = 0;
  372. virtual void particles_restart(RID p_particles) = 0;
  373. virtual void particles_set_draw_order(RID p_particles, VS::ParticlesDrawOrder p_order) = 0;
  374. virtual void particles_set_draw_passes(RID p_particles, int p_count) = 0;
  375. virtual void particles_set_draw_pass_mesh(RID p_particles, int p_pass, RID p_mesh) = 0;
  376. virtual void particles_request_process(RID p_particles) = 0;
  377. virtual AABB particles_get_current_aabb(RID p_particles) = 0;
  378. virtual AABB particles_get_aabb(RID p_particles) const = 0;
  379. virtual void particles_set_emission_transform(RID p_particles, const Transform &p_transform) = 0;
  380. virtual int particles_get_draw_passes(RID p_particles) const = 0;
  381. virtual RID particles_get_draw_pass_mesh(RID p_particles, int p_pass) const = 0;
  382. /* RENDER TARGET */
  383. enum RenderTargetFlags {
  384. RENDER_TARGET_VFLIP,
  385. RENDER_TARGET_TRANSPARENT,
  386. RENDER_TARGET_NO_3D_EFFECTS,
  387. RENDER_TARGET_NO_3D,
  388. RENDER_TARGET_NO_SAMPLING,
  389. RENDER_TARGET_HDR,
  390. RENDER_TARGET_KEEP_3D_LINEAR,
  391. RENDER_TARGET_FLAG_MAX
  392. };
  393. virtual RID render_target_create() = 0;
  394. virtual void render_target_set_size(RID p_render_target, int p_width, int p_height) = 0;
  395. virtual RID render_target_get_texture(RID p_render_target) const = 0;
  396. virtual void render_target_set_flag(RID p_render_target, RenderTargetFlags p_flag, bool p_value) = 0;
  397. virtual bool render_target_was_used(RID p_render_target) = 0;
  398. virtual void render_target_clear_used(RID p_render_target) = 0;
  399. virtual void render_target_set_msaa(RID p_render_target, VS::ViewportMSAA p_msaa) = 0;
  400. /* CANVAS SHADOW */
  401. virtual RID canvas_light_shadow_buffer_create(int p_width) = 0;
  402. /* LIGHT SHADOW MAPPING */
  403. virtual RID canvas_light_occluder_create() = 0;
  404. virtual void canvas_light_occluder_set_polylines(RID p_occluder, const PoolVector<Vector2> &p_lines) = 0;
  405. virtual VS::InstanceType get_base_type(RID p_rid) const = 0;
  406. virtual bool free(RID p_rid) = 0;
  407. virtual bool has_os_feature(const String &p_feature) const = 0;
  408. virtual void update_dirty_resources() = 0;
  409. virtual void set_debug_generate_wireframes(bool p_generate) = 0;
  410. virtual void render_info_begin_capture() = 0;
  411. virtual void render_info_end_capture() = 0;
  412. virtual int get_captured_render_info(VS::RenderInfo p_info) = 0;
  413. virtual int get_render_info(VS::RenderInfo p_info) = 0;
  414. static RasterizerStorage *base_singleton;
  415. RasterizerStorage();
  416. virtual ~RasterizerStorage() {}
  417. };
  418. class RasterizerCanvas {
  419. public:
  420. enum CanvasRectFlags {
  421. CANVAS_RECT_REGION = 1,
  422. CANVAS_RECT_TILE = 2,
  423. CANVAS_RECT_FLIP_H = 4,
  424. CANVAS_RECT_FLIP_V = 8,
  425. CANVAS_RECT_TRANSPOSE = 16,
  426. CANVAS_RECT_CLIP_UV = 32
  427. };
  428. struct Light : public RID_Data {
  429. bool enabled;
  430. Color color;
  431. Transform2D xform;
  432. float height;
  433. float energy;
  434. float scale;
  435. int z_min;
  436. int z_max;
  437. int layer_min;
  438. int layer_max;
  439. int item_mask;
  440. int item_shadow_mask;
  441. VS::CanvasLightMode mode;
  442. RID texture;
  443. Vector2 texture_offset;
  444. RID canvas;
  445. RID shadow_buffer;
  446. int shadow_buffer_size;
  447. float shadow_gradient_length;
  448. VS::CanvasLightShadowFilter shadow_filter;
  449. Color shadow_color;
  450. float shadow_smooth;
  451. void *texture_cache; // implementation dependent
  452. Rect2 rect_cache;
  453. Transform2D xform_cache;
  454. float radius_cache; //used for shadow far plane
  455. CameraMatrix shadow_matrix_cache;
  456. Transform2D light_shader_xform;
  457. Vector2 light_shader_pos;
  458. Light *shadows_next_ptr;
  459. Light *filter_next_ptr;
  460. Light *next_ptr;
  461. Light *mask_next_ptr;
  462. RID light_internal;
  463. Light() {
  464. enabled = true;
  465. color = Color(1, 1, 1);
  466. shadow_color = Color(0, 0, 0, 0);
  467. height = 0;
  468. z_min = -1024;
  469. z_max = 1024;
  470. layer_min = 0;
  471. layer_max = 0;
  472. item_mask = 1;
  473. scale = 1.0;
  474. energy = 1.0;
  475. item_shadow_mask = -1;
  476. mode = VS::CANVAS_LIGHT_MODE_ADD;
  477. texture_cache = NULL;
  478. next_ptr = NULL;
  479. mask_next_ptr = NULL;
  480. filter_next_ptr = NULL;
  481. shadow_buffer_size = 256;
  482. shadow_gradient_length = 0;
  483. shadow_filter = VS::CANVAS_LIGHT_FILTER_NONE;
  484. shadow_smooth = 0.0;
  485. }
  486. };
  487. virtual RID light_internal_create() = 0;
  488. virtual void light_internal_update(RID p_rid, Light *p_light) = 0;
  489. virtual void light_internal_free(RID p_rid) = 0;
  490. struct Item : public RID_Data {
  491. struct Command {
  492. enum Type {
  493. TYPE_LINE,
  494. TYPE_POLYLINE,
  495. TYPE_RECT,
  496. TYPE_NINEPATCH,
  497. TYPE_PRIMITIVE,
  498. TYPE_POLYGON,
  499. TYPE_MESH,
  500. TYPE_MULTIMESH,
  501. TYPE_PARTICLES,
  502. TYPE_CIRCLE,
  503. TYPE_TRANSFORM,
  504. TYPE_CLIP_IGNORE,
  505. };
  506. Type type;
  507. virtual ~Command() {}
  508. };
  509. struct CommandLine : public Command {
  510. Point2 from, to;
  511. Color color;
  512. float width;
  513. bool antialiased;
  514. CommandLine() { type = TYPE_LINE; }
  515. };
  516. struct CommandPolyLine : public Command {
  517. bool antialiased;
  518. bool multiline;
  519. Vector<Point2> triangles;
  520. Vector<Color> triangle_colors;
  521. Vector<Point2> lines;
  522. Vector<Color> line_colors;
  523. CommandPolyLine() {
  524. type = TYPE_POLYLINE;
  525. antialiased = false;
  526. multiline = false;
  527. }
  528. };
  529. struct CommandRect : public Command {
  530. Rect2 rect;
  531. RID texture;
  532. RID normal_map;
  533. Color modulate;
  534. Rect2 source;
  535. uint8_t flags;
  536. CommandRect() {
  537. flags = 0;
  538. type = TYPE_RECT;
  539. }
  540. };
  541. struct CommandNinePatch : public Command {
  542. Rect2 rect;
  543. Rect2 source;
  544. RID texture;
  545. RID normal_map;
  546. float margin[4];
  547. bool draw_center;
  548. Color color;
  549. VS::NinePatchAxisMode axis_x;
  550. VS::NinePatchAxisMode axis_y;
  551. CommandNinePatch() {
  552. draw_center = true;
  553. type = TYPE_NINEPATCH;
  554. }
  555. };
  556. struct CommandPrimitive : public Command {
  557. Vector<Point2> points;
  558. Vector<Point2> uvs;
  559. Vector<Color> colors;
  560. RID texture;
  561. RID normal_map;
  562. float width;
  563. CommandPrimitive() {
  564. type = TYPE_PRIMITIVE;
  565. width = 1;
  566. }
  567. };
  568. struct CommandPolygon : public Command {
  569. Vector<int> indices;
  570. Vector<Point2> points;
  571. Vector<Point2> uvs;
  572. Vector<Color> colors;
  573. Vector<int> bones;
  574. Vector<float> weights;
  575. RID texture;
  576. RID normal_map;
  577. int count;
  578. bool antialiased;
  579. CommandPolygon() {
  580. type = TYPE_POLYGON;
  581. count = 0;
  582. }
  583. };
  584. struct CommandMesh : public Command {
  585. RID mesh;
  586. RID texture;
  587. RID normal_map;
  588. CommandMesh() { type = TYPE_MESH; }
  589. };
  590. struct CommandMultiMesh : public Command {
  591. RID multimesh;
  592. RID texture;
  593. RID normal_map;
  594. CommandMultiMesh() { type = TYPE_MULTIMESH; }
  595. };
  596. struct CommandParticles : public Command {
  597. RID particles;
  598. RID texture;
  599. RID normal_map;
  600. int h_frames;
  601. int v_frames;
  602. CommandParticles() { type = TYPE_PARTICLES; }
  603. };
  604. struct CommandCircle : public Command {
  605. Point2 pos;
  606. float radius;
  607. Color color;
  608. CommandCircle() { type = TYPE_CIRCLE; }
  609. };
  610. struct CommandTransform : public Command {
  611. Transform2D xform;
  612. CommandTransform() { type = TYPE_TRANSFORM; }
  613. };
  614. struct CommandClipIgnore : public Command {
  615. bool ignore;
  616. CommandClipIgnore() {
  617. type = TYPE_CLIP_IGNORE;
  618. ignore = false;
  619. }
  620. };
  621. struct ViewportRender {
  622. VisualServer *owner;
  623. void *udata;
  624. Rect2 rect;
  625. };
  626. Transform2D xform;
  627. bool clip;
  628. bool visible;
  629. bool behind;
  630. //VS::MaterialBlendMode blend_mode;
  631. int light_mask;
  632. Vector<Command *> commands;
  633. mutable bool custom_rect;
  634. mutable bool rect_dirty;
  635. mutable Rect2 rect;
  636. RID material;
  637. RID skeleton;
  638. Item *next;
  639. struct CopyBackBuffer {
  640. Rect2 rect;
  641. Rect2 screen_rect;
  642. bool full;
  643. };
  644. CopyBackBuffer *copy_back_buffer;
  645. Color final_modulate;
  646. Transform2D final_transform;
  647. Rect2 final_clip_rect;
  648. Item *final_clip_owner;
  649. Item *material_owner;
  650. ViewportRender *vp_render;
  651. bool distance_field;
  652. bool light_masked;
  653. Rect2 global_rect_cache;
  654. const Rect2 &get_rect() const {
  655. if (custom_rect || !rect_dirty)
  656. return rect;
  657. //must update rect
  658. int s = commands.size();
  659. if (s == 0) {
  660. rect = Rect2();
  661. rect_dirty = false;
  662. return rect;
  663. }
  664. Transform2D xf;
  665. bool found_xform = false;
  666. bool first = true;
  667. const Item::Command *const *cmd = &commands[0];
  668. for (int i = 0; i < s; i++) {
  669. const Item::Command *c = cmd[i];
  670. Rect2 r;
  671. switch (c->type) {
  672. case Item::Command::TYPE_LINE: {
  673. const Item::CommandLine *line = static_cast<const Item::CommandLine *>(c);
  674. r.position = line->from;
  675. r.expand_to(line->to);
  676. } break;
  677. case Item::Command::TYPE_POLYLINE: {
  678. const Item::CommandPolyLine *pline = static_cast<const Item::CommandPolyLine *>(c);
  679. if (pline->triangles.size()) {
  680. for (int j = 0; j < pline->triangles.size(); j++) {
  681. if (j == 0) {
  682. r.position = pline->triangles[j];
  683. } else {
  684. r.expand_to(pline->triangles[j]);
  685. }
  686. }
  687. } else {
  688. for (int j = 0; j < pline->lines.size(); j++) {
  689. if (j == 0) {
  690. r.position = pline->lines[j];
  691. } else {
  692. r.expand_to(pline->lines[j]);
  693. }
  694. }
  695. }
  696. } break;
  697. case Item::Command::TYPE_RECT: {
  698. const Item::CommandRect *crect = static_cast<const Item::CommandRect *>(c);
  699. r = crect->rect;
  700. } break;
  701. case Item::Command::TYPE_NINEPATCH: {
  702. const Item::CommandNinePatch *style = static_cast<const Item::CommandNinePatch *>(c);
  703. r = style->rect;
  704. } break;
  705. case Item::Command::TYPE_PRIMITIVE: {
  706. const Item::CommandPrimitive *primitive = static_cast<const Item::CommandPrimitive *>(c);
  707. r.position = primitive->points[0];
  708. for (int i = 1; i < primitive->points.size(); i++) {
  709. r.expand_to(primitive->points[i]);
  710. }
  711. } break;
  712. case Item::Command::TYPE_POLYGON: {
  713. const Item::CommandPolygon *polygon = static_cast<const Item::CommandPolygon *>(c);
  714. int l = polygon->points.size();
  715. const Point2 *pp = &polygon->points[0];
  716. r.position = pp[0];
  717. for (int i = 1; i < l; i++) {
  718. r.expand_to(pp[i]);
  719. }
  720. } break;
  721. case Item::Command::TYPE_MESH: {
  722. const Item::CommandMesh *mesh = static_cast<const Item::CommandMesh *>(c);
  723. AABB aabb = RasterizerStorage::base_singleton->mesh_get_aabb(mesh->mesh, RID());
  724. r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y);
  725. } break;
  726. case Item::Command::TYPE_MULTIMESH: {
  727. const Item::CommandMultiMesh *multimesh = static_cast<const Item::CommandMultiMesh *>(c);
  728. AABB aabb = RasterizerStorage::base_singleton->multimesh_get_aabb(multimesh->multimesh);
  729. r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y);
  730. } break;
  731. case Item::Command::TYPE_PARTICLES: {
  732. const Item::CommandParticles *particles_cmd = static_cast<const Item::CommandParticles *>(c);
  733. if (particles_cmd->particles.is_valid()) {
  734. AABB aabb = RasterizerStorage::base_singleton->particles_get_aabb(particles_cmd->particles);
  735. r = Rect2(aabb.position.x, aabb.position.y, aabb.size.x, aabb.size.y);
  736. }
  737. } break;
  738. case Item::Command::TYPE_CIRCLE: {
  739. const Item::CommandCircle *circle = static_cast<const Item::CommandCircle *>(c);
  740. r.position = Point2(-circle->radius, -circle->radius) + circle->pos;
  741. r.size = Point2(circle->radius * 2.0, circle->radius * 2.0);
  742. } break;
  743. case Item::Command::TYPE_TRANSFORM: {
  744. const Item::CommandTransform *transform = static_cast<const Item::CommandTransform *>(c);
  745. xf = transform->xform;
  746. found_xform = true;
  747. continue;
  748. } break;
  749. case Item::Command::TYPE_CLIP_IGNORE: {
  750. } break;
  751. }
  752. if (found_xform) {
  753. r = xf.xform(r);
  754. found_xform = false;
  755. }
  756. if (first) {
  757. rect = r;
  758. first = false;
  759. } else
  760. rect = rect.merge(r);
  761. }
  762. rect_dirty = false;
  763. return rect;
  764. }
  765. void clear() {
  766. for (int i = 0; i < commands.size(); i++)
  767. memdelete(commands[i]);
  768. commands.clear();
  769. clip = false;
  770. rect_dirty = true;
  771. final_clip_owner = NULL;
  772. material_owner = NULL;
  773. light_masked = false;
  774. }
  775. Item() {
  776. light_mask = 1;
  777. vp_render = NULL;
  778. next = NULL;
  779. final_clip_owner = NULL;
  780. clip = false;
  781. final_modulate = Color(1, 1, 1, 1);
  782. visible = true;
  783. rect_dirty = true;
  784. custom_rect = false;
  785. behind = false;
  786. material_owner = NULL;
  787. copy_back_buffer = NULL;
  788. distance_field = false;
  789. light_masked = false;
  790. }
  791. virtual ~Item() {
  792. clear();
  793. if (copy_back_buffer) memdelete(copy_back_buffer);
  794. }
  795. };
  796. virtual void canvas_begin() = 0;
  797. virtual void canvas_end() = 0;
  798. virtual void canvas_render_items(Item *p_item_list, int p_z, const Color &p_modulate, Light *p_light, const Transform2D &p_base_transform) = 0;
  799. virtual void canvas_debug_viewport_shadows(Light *p_lights_with_shadow) = 0;
  800. struct LightOccluderInstance : public RID_Data {
  801. bool enabled;
  802. RID canvas;
  803. RID polygon;
  804. RID polygon_buffer;
  805. Rect2 aabb_cache;
  806. Transform2D xform;
  807. Transform2D xform_cache;
  808. int light_mask;
  809. VS::CanvasOccluderPolygonCullMode cull_cache;
  810. LightOccluderInstance *next;
  811. LightOccluderInstance() {
  812. enabled = true;
  813. next = NULL;
  814. light_mask = 1;
  815. cull_cache = VS::CANVAS_OCCLUDER_POLYGON_CULL_DISABLED;
  816. }
  817. };
  818. 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) = 0;
  819. virtual void reset_canvas() = 0;
  820. virtual void draw_window_margins(int *p_margins, RID *p_margin_textures) = 0;
  821. virtual ~RasterizerCanvas() {}
  822. };
  823. class Rasterizer {
  824. protected:
  825. static Rasterizer *(*_create_func)();
  826. public:
  827. static Rasterizer *create();
  828. virtual RasterizerStorage *get_storage() = 0;
  829. virtual RasterizerCanvas *get_canvas() = 0;
  830. virtual RasterizerScene *get_scene() = 0;
  831. virtual void set_boot_image(const Ref<Image> &p_image, const Color &p_color, bool p_scale) = 0;
  832. virtual void initialize() = 0;
  833. virtual void begin_frame() = 0;
  834. virtual void set_current_render_target(RID p_render_target) = 0;
  835. virtual void restore_render_target() = 0;
  836. virtual void clear_render_target(const Color &p_color) = 0;
  837. virtual void blit_render_target_to_screen(RID p_render_target, const Rect2 &p_screen_rect, int p_screen = 0) = 0;
  838. virtual void end_frame(bool p_swap_buffers) = 0;
  839. virtual void finalize() = 0;
  840. virtual ~Rasterizer() {}
  841. };
  842. #endif // RASTERIZER_H