rasterizer_dummy.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715
  1. /*************************************************************************/
  2. /* rasterizer_dummy.cpp */
  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. #include "rasterizer_dummy.h"
  31. /* TEXTURE API */
  32. RID RasterizerDummy::texture_create() {
  33. Texture *texture = memnew(Texture);
  34. ERR_FAIL_COND_V(!texture, RID());
  35. return texture_owner.make_rid(texture);
  36. }
  37. void RasterizerDummy::texture_allocate(RID p_texture, int p_width, int p_height, Image::Format p_format, uint32_t p_flags) {
  38. Texture *texture = texture_owner.get(p_texture);
  39. ERR_FAIL_COND(!texture);
  40. texture->width = p_width;
  41. texture->height = p_height;
  42. texture->format = p_format;
  43. texture->flags = p_flags;
  44. }
  45. void RasterizerDummy::texture_set_data(RID p_texture, const Image &p_image, VS::CubeMapSide p_cube_side) {
  46. Texture *texture = texture_owner.get(p_texture);
  47. ERR_FAIL_COND(!texture);
  48. ERR_FAIL_COND(texture->format != p_image.get_format());
  49. texture->image[p_cube_side] = p_image;
  50. }
  51. Image RasterizerDummy::texture_get_data(RID p_texture, VS::CubeMapSide p_cube_side) const {
  52. Texture *texture = texture_owner.get(p_texture);
  53. ERR_FAIL_COND_V(!texture, Image());
  54. return texture->image[p_cube_side];
  55. }
  56. void RasterizerDummy::texture_set_flags(RID p_texture, uint32_t p_flags) {
  57. Texture *texture = texture_owner.get(p_texture);
  58. ERR_FAIL_COND(!texture);
  59. uint32_t cube = texture->flags & VS::TEXTURE_FLAG_CUBEMAP;
  60. texture->flags = p_flags | cube; // can't remove a cube from being a cube
  61. }
  62. uint32_t RasterizerDummy::texture_get_flags(RID p_texture) const {
  63. Texture *texture = texture_owner.get(p_texture);
  64. ERR_FAIL_COND_V(!texture, 0);
  65. return texture->flags;
  66. }
  67. Image::Format RasterizerDummy::texture_get_format(RID p_texture) const {
  68. Texture *texture = texture_owner.get(p_texture);
  69. ERR_FAIL_COND_V(!texture, Image::FORMAT_GRAYSCALE);
  70. return texture->format;
  71. }
  72. uint32_t RasterizerDummy::texture_get_width(RID p_texture) const {
  73. Texture *texture = texture_owner.get(p_texture);
  74. ERR_FAIL_COND_V(!texture, 0);
  75. return texture->width;
  76. }
  77. uint32_t RasterizerDummy::texture_get_height(RID p_texture) const {
  78. Texture *texture = texture_owner.get(p_texture);
  79. ERR_FAIL_COND_V(!texture, 0);
  80. return texture->height;
  81. }
  82. bool RasterizerDummy::texture_has_alpha(RID p_texture) const {
  83. Texture *texture = texture_owner.get(p_texture);
  84. ERR_FAIL_COND_V(!texture, 0);
  85. return false;
  86. }
  87. void RasterizerDummy::texture_set_size_override(RID p_texture, int p_width, int p_height) {
  88. Texture *texture = texture_owner.get(p_texture);
  89. ERR_FAIL_COND(!texture);
  90. ERR_FAIL_COND(p_width <= 0 || p_width > 4096);
  91. ERR_FAIL_COND(p_height <= 0 || p_height > 4096);
  92. //real texture size is in alloc width and height
  93. // texture->width=p_width;
  94. // texture->height=p_height;
  95. }
  96. void RasterizerDummy::texture_set_reload_hook(RID p_texture, ObjectID p_owner, const StringName &p_function) const {
  97. }
  98. /* SHADER API */
  99. /* SHADER API */
  100. RID RasterizerDummy::shader_create(VS::ShaderMode p_mode) {
  101. Shader *shader = memnew(Shader);
  102. shader->mode = p_mode;
  103. shader->fragment_line = 0;
  104. shader->vertex_line = 0;
  105. shader->light_line = 0;
  106. RID rid = shader_owner.make_rid(shader);
  107. return rid;
  108. }
  109. void RasterizerDummy::shader_set_mode(RID p_shader, VS::ShaderMode p_mode) {
  110. ERR_FAIL_INDEX(p_mode, 3);
  111. Shader *shader = shader_owner.get(p_shader);
  112. ERR_FAIL_COND(!shader);
  113. shader->mode = p_mode;
  114. }
  115. VS::ShaderMode RasterizerDummy::shader_get_mode(RID p_shader) const {
  116. Shader *shader = shader_owner.get(p_shader);
  117. ERR_FAIL_COND_V(!shader, VS::SHADER_MATERIAL);
  118. return shader->mode;
  119. }
  120. void RasterizerDummy::shader_set_code(RID p_shader, const String &p_vertex, const String &p_fragment, const String &p_light, int p_vertex_ofs, int p_fragment_ofs, int p_light_ofs) {
  121. Shader *shader = shader_owner.get(p_shader);
  122. ERR_FAIL_COND(!shader);
  123. shader->fragment_code = p_fragment;
  124. shader->vertex_code = p_vertex;
  125. shader->light_code = p_light;
  126. shader->fragment_line = p_fragment_ofs;
  127. shader->vertex_line = p_vertex_ofs;
  128. shader->light_line = p_vertex_ofs;
  129. }
  130. String RasterizerDummy::shader_get_vertex_code(RID p_shader) const {
  131. Shader *shader = shader_owner.get(p_shader);
  132. ERR_FAIL_COND_V(!shader, String());
  133. return shader->vertex_code;
  134. }
  135. String RasterizerDummy::shader_get_fragment_code(RID p_shader) const {
  136. Shader *shader = shader_owner.get(p_shader);
  137. ERR_FAIL_COND_V(!shader, String());
  138. return shader->fragment_code;
  139. }
  140. String RasterizerDummy::shader_get_light_code(RID p_shader) const {
  141. Shader *shader = shader_owner.get(p_shader);
  142. ERR_FAIL_COND_V(!shader, String());
  143. return shader->light_code;
  144. }
  145. void RasterizerDummy::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
  146. Shader *shader = shader_owner.get(p_shader);
  147. ERR_FAIL_COND(!shader);
  148. }
  149. void RasterizerDummy::shader_set_default_texture_param(RID p_shader, const StringName &p_name, RID p_texture) {
  150. }
  151. RID RasterizerDummy::shader_get_default_texture_param(RID p_shader, const StringName &p_name) const {
  152. return RID();
  153. }
  154. Variant RasterizerDummy::shader_get_default_param(RID p_shader, const StringName &p_name) {
  155. return Variant();
  156. }
  157. /* COMMON MATERIAL API */
  158. RID RasterizerDummy::material_create() {
  159. return material_owner.make_rid(memnew(Material));
  160. }
  161. void RasterizerDummy::material_set_shader(RID p_material, RID p_shader) {
  162. Material *material = material_owner.get(p_material);
  163. ERR_FAIL_COND(!material);
  164. material->shader = p_shader;
  165. }
  166. RID RasterizerDummy::material_get_shader(RID p_material) const {
  167. Material *material = material_owner.get(p_material);
  168. ERR_FAIL_COND_V(!material, RID());
  169. return material->shader;
  170. }
  171. void RasterizerDummy::material_set_param(RID p_material, const StringName &p_param, const Variant &p_value) {
  172. Material *material = material_owner.get(p_material);
  173. ERR_FAIL_COND(!material);
  174. if (p_value.get_type() == Variant::NIL)
  175. material->shader_params.erase(p_param);
  176. else
  177. material->shader_params[p_param] = p_value;
  178. }
  179. Variant RasterizerDummy::material_get_param(RID p_material, const StringName &p_param) const {
  180. Material *material = material_owner.get(p_material);
  181. ERR_FAIL_COND_V(!material, Variant());
  182. if (material->shader_params.has(p_param))
  183. return material->shader_params[p_param];
  184. else
  185. return Variant();
  186. }
  187. void RasterizerDummy::material_set_flag(RID p_material, VS::MaterialFlag p_flag, bool p_enabled) {
  188. Material *material = material_owner.get(p_material);
  189. ERR_FAIL_COND(!material);
  190. ERR_FAIL_INDEX(p_flag, VS::MATERIAL_FLAG_MAX);
  191. material->flags[p_flag] = p_enabled;
  192. }
  193. bool RasterizerDummy::material_get_flag(RID p_material, VS::MaterialFlag p_flag) const {
  194. Material *material = material_owner.get(p_material);
  195. ERR_FAIL_COND_V(!material, false);
  196. ERR_FAIL_INDEX_V(p_flag, VS::MATERIAL_FLAG_MAX, false);
  197. return material->flags[p_flag];
  198. }
  199. void RasterizerDummy::material_set_depth_draw_mode(RID p_material, VS::MaterialDepthDrawMode p_mode) {
  200. Material *material = material_owner.get(p_material);
  201. ERR_FAIL_COND(!material);
  202. material->depth_draw_mode = p_mode;
  203. }
  204. VS::MaterialDepthDrawMode RasterizerDummy::material_get_depth_draw_mode(RID p_material) const {
  205. Material *material = material_owner.get(p_material);
  206. ERR_FAIL_COND_V(!material, VS::MATERIAL_DEPTH_DRAW_ALWAYS);
  207. return material->depth_draw_mode;
  208. }
  209. void RasterizerDummy::material_set_blend_mode(RID p_material, VS::MaterialBlendMode p_mode) {
  210. Material *material = material_owner.get(p_material);
  211. ERR_FAIL_COND(!material);
  212. material->blend_mode = p_mode;
  213. }
  214. VS::MaterialBlendMode RasterizerDummy::material_get_blend_mode(RID p_material) const {
  215. Material *material = material_owner.get(p_material);
  216. ERR_FAIL_COND_V(!material, VS::MATERIAL_BLEND_MODE_ADD);
  217. return material->blend_mode;
  218. }
  219. void RasterizerDummy::material_set_line_width(RID p_material, float p_line_width) {
  220. Material *material = material_owner.get(p_material);
  221. ERR_FAIL_COND(!material);
  222. material->line_width = p_line_width;
  223. }
  224. float RasterizerDummy::material_get_line_width(RID p_material) const {
  225. Material *material = material_owner.get(p_material);
  226. ERR_FAIL_COND_V(!material, 0);
  227. return material->line_width;
  228. }
  229. /* MESH API */
  230. RID RasterizerDummy::mesh_create() {
  231. return mesh_owner.make_rid(memnew(Mesh));
  232. }
  233. void RasterizerDummy::mesh_add_surface(RID p_mesh, VS::PrimitiveType p_primitive, const Array &p_arrays, const Array &p_blend_shapes, bool p_alpha_sort) {
  234. Mesh *mesh = mesh_owner.get(p_mesh);
  235. ERR_FAIL_COND(!mesh);
  236. ERR_FAIL_INDEX(p_primitive, VS::PRIMITIVE_MAX);
  237. ERR_FAIL_COND(p_arrays.size() != VS::ARRAY_MAX);
  238. Surface s;
  239. s.format = 0;
  240. for (int i = 0; i < p_arrays.size(); i++) {
  241. if (p_arrays[i].get_type() == Variant::NIL)
  242. continue;
  243. s.format |= (1 << i);
  244. if (i == VS::ARRAY_VERTEX) {
  245. Vector3Array v = p_arrays[i];
  246. int len = v.size();
  247. ERR_FAIL_COND(len == 0);
  248. Vector3Array::Read r = v.read();
  249. for (int i = 0; i < len; i++) {
  250. if (i == 0)
  251. s.aabb.pos = r[0];
  252. else
  253. s.aabb.expand_to(r[i]);
  254. }
  255. }
  256. }
  257. ERR_FAIL_COND((s.format & VS::ARRAY_FORMAT_VERTEX) == 0); // mandatory
  258. s.data = p_arrays;
  259. s.morph_data = p_blend_shapes;
  260. s.primitive = p_primitive;
  261. s.alpha_sort = p_alpha_sort;
  262. s.morph_target_count = mesh->morph_target_count;
  263. s.morph_format = s.format;
  264. Surface *surface = memnew(Surface);
  265. *surface = s;
  266. mesh->surfaces.push_back(surface);
  267. }
  268. void RasterizerDummy::mesh_add_custom_surface(RID p_mesh, const Variant &p_dat) {
  269. ERR_EXPLAIN("Dummy Rasterizer does not support custom surfaces. Running on wrong platform?");
  270. ERR_FAIL_V();
  271. }
  272. Array RasterizerDummy::mesh_get_surface_arrays(RID p_mesh, int p_surface) const {
  273. Mesh *mesh = mesh_owner.get(p_mesh);
  274. ERR_FAIL_COND_V(!mesh, Array());
  275. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array());
  276. Surface *surface = mesh->surfaces[p_surface];
  277. ERR_FAIL_COND_V(!surface, Array());
  278. return surface->data;
  279. }
  280. Array RasterizerDummy::mesh_get_surface_morph_arrays(RID p_mesh, int p_surface) const {
  281. Mesh *mesh = mesh_owner.get(p_mesh);
  282. ERR_FAIL_COND_V(!mesh, Array());
  283. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array());
  284. Surface *surface = mesh->surfaces[p_surface];
  285. ERR_FAIL_COND_V(!surface, Array());
  286. return surface->morph_data;
  287. }
  288. void RasterizerDummy::mesh_set_morph_target_count(RID p_mesh, int p_amount) {
  289. Mesh *mesh = mesh_owner.get(p_mesh);
  290. ERR_FAIL_COND(!mesh);
  291. ERR_FAIL_COND(mesh->surfaces.size() != 0);
  292. mesh->morph_target_count = p_amount;
  293. }
  294. int RasterizerDummy::mesh_get_morph_target_count(RID p_mesh) const {
  295. Mesh *mesh = mesh_owner.get(p_mesh);
  296. ERR_FAIL_COND_V(!mesh, -1);
  297. return mesh->morph_target_count;
  298. }
  299. void RasterizerDummy::mesh_set_morph_target_mode(RID p_mesh, VS::MorphTargetMode p_mode) {
  300. ERR_FAIL_INDEX(p_mode, 2);
  301. Mesh *mesh = mesh_owner.get(p_mesh);
  302. ERR_FAIL_COND(!mesh);
  303. mesh->morph_target_mode = p_mode;
  304. }
  305. VS::MorphTargetMode RasterizerDummy::mesh_get_morph_target_mode(RID p_mesh) const {
  306. Mesh *mesh = mesh_owner.get(p_mesh);
  307. ERR_FAIL_COND_V(!mesh, VS::MORPH_MODE_NORMALIZED);
  308. return mesh->morph_target_mode;
  309. }
  310. void RasterizerDummy::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material, bool p_owned) {
  311. Mesh *mesh = mesh_owner.get(p_mesh);
  312. ERR_FAIL_COND(!mesh);
  313. ERR_FAIL_INDEX(p_surface, mesh->surfaces.size());
  314. Surface *surface = mesh->surfaces[p_surface];
  315. ERR_FAIL_COND(!surface);
  316. if (surface->material_owned && surface->material.is_valid())
  317. free(surface->material);
  318. surface->material_owned = p_owned;
  319. surface->material = p_material;
  320. }
  321. RID RasterizerDummy::mesh_surface_get_material(RID p_mesh, int p_surface) const {
  322. Mesh *mesh = mesh_owner.get(p_mesh);
  323. ERR_FAIL_COND_V(!mesh, RID());
  324. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID());
  325. Surface *surface = mesh->surfaces[p_surface];
  326. ERR_FAIL_COND_V(!surface, RID());
  327. return surface->material;
  328. }
  329. int RasterizerDummy::mesh_surface_get_array_len(RID p_mesh, int p_surface) const {
  330. Mesh *mesh = mesh_owner.get(p_mesh);
  331. ERR_FAIL_COND_V(!mesh, -1);
  332. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1);
  333. Surface *surface = mesh->surfaces[p_surface];
  334. ERR_FAIL_COND_V(!surface, -1);
  335. Vector3Array arr = surface->data[VS::ARRAY_VERTEX];
  336. return arr.size();
  337. }
  338. int RasterizerDummy::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const {
  339. Mesh *mesh = mesh_owner.get(p_mesh);
  340. ERR_FAIL_COND_V(!mesh, -1);
  341. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1);
  342. Surface *surface = mesh->surfaces[p_surface];
  343. ERR_FAIL_COND_V(!surface, -1);
  344. IntArray arr = surface->data[VS::ARRAY_INDEX];
  345. return arr.size();
  346. }
  347. uint32_t RasterizerDummy::mesh_surface_get_format(RID p_mesh, int p_surface) const {
  348. Mesh *mesh = mesh_owner.get(p_mesh);
  349. ERR_FAIL_COND_V(!mesh, 0);
  350. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0);
  351. Surface *surface = mesh->surfaces[p_surface];
  352. ERR_FAIL_COND_V(!surface, 0);
  353. return surface->format;
  354. }
  355. VS::PrimitiveType RasterizerDummy::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const {
  356. Mesh *mesh = mesh_owner.get(p_mesh);
  357. ERR_FAIL_COND_V(!mesh, VS::PRIMITIVE_POINTS);
  358. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS);
  359. Surface *surface = mesh->surfaces[p_surface];
  360. ERR_FAIL_COND_V(!surface, VS::PRIMITIVE_POINTS);
  361. return surface->primitive;
  362. }
  363. void RasterizerDummy::mesh_remove_surface(RID p_mesh, int p_index) {
  364. Mesh *mesh = mesh_owner.get(p_mesh);
  365. ERR_FAIL_COND(!mesh);
  366. ERR_FAIL_INDEX(p_index, mesh->surfaces.size());
  367. Surface *surface = mesh->surfaces[p_index];
  368. ERR_FAIL_COND(!surface);
  369. memdelete(mesh->surfaces[p_index]);
  370. mesh->surfaces.remove(p_index);
  371. }
  372. int RasterizerDummy::mesh_get_surface_count(RID p_mesh) const {
  373. Mesh *mesh = mesh_owner.get(p_mesh);
  374. ERR_FAIL_COND_V(!mesh, -1);
  375. return mesh->surfaces.size();
  376. }
  377. AABB RasterizerDummy::mesh_get_aabb(RID p_mesh, RID p_skeleton) const {
  378. Mesh *mesh = mesh_owner.get(p_mesh);
  379. ERR_FAIL_COND_V(!mesh, AABB());
  380. AABB aabb;
  381. for (int i = 0; i < mesh->surfaces.size(); i++) {
  382. if (i == 0)
  383. aabb = mesh->surfaces[i]->aabb;
  384. else
  385. aabb.merge_with(mesh->surfaces[i]->aabb);
  386. }
  387. return aabb;
  388. }
  389. void RasterizerDummy::mesh_set_custom_aabb(RID p_mesh, const AABB &p_aabb) {
  390. Mesh *mesh = mesh_owner.get(p_mesh);
  391. ERR_FAIL_COND(!mesh);
  392. mesh->custom_aabb = p_aabb;
  393. }
  394. AABB RasterizerDummy::mesh_get_custom_aabb(RID p_mesh) const {
  395. const Mesh *mesh = mesh_owner.get(p_mesh);
  396. ERR_FAIL_COND_V(!mesh, AABB());
  397. return mesh->custom_aabb;
  398. }
  399. /* MULTIMESH API */
  400. RID RasterizerDummy::multimesh_create() {
  401. return multimesh_owner.make_rid(memnew(MultiMesh));
  402. }
  403. void RasterizerDummy::multimesh_set_instance_count(RID p_multimesh, int p_count) {
  404. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  405. ERR_FAIL_COND(!multimesh);
  406. multimesh->elements.clear(); // make sure to delete everything, so it "fails" in all implementations
  407. multimesh->elements.resize(p_count);
  408. }
  409. int RasterizerDummy::multimesh_get_instance_count(RID p_multimesh) const {
  410. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  411. ERR_FAIL_COND_V(!multimesh, -1);
  412. return multimesh->elements.size();
  413. }
  414. void RasterizerDummy::multimesh_set_mesh(RID p_multimesh, RID p_mesh) {
  415. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  416. ERR_FAIL_COND(!multimesh);
  417. multimesh->mesh = p_mesh;
  418. }
  419. void RasterizerDummy::multimesh_set_aabb(RID p_multimesh, const AABB &p_aabb) {
  420. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  421. ERR_FAIL_COND(!multimesh);
  422. multimesh->aabb = p_aabb;
  423. }
  424. void RasterizerDummy::multimesh_instance_set_transform(RID p_multimesh, int p_index, const Transform &p_transform) {
  425. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  426. ERR_FAIL_COND(!multimesh);
  427. ERR_FAIL_INDEX(p_index, multimesh->elements.size());
  428. multimesh->elements[p_index].xform = p_transform;
  429. }
  430. void RasterizerDummy::multimesh_instance_set_color(RID p_multimesh, int p_index, const Color &p_color) {
  431. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  432. ERR_FAIL_COND(!multimesh)
  433. ERR_FAIL_INDEX(p_index, multimesh->elements.size());
  434. multimesh->elements[p_index].color = p_color;
  435. }
  436. RID RasterizerDummy::multimesh_get_mesh(RID p_multimesh) const {
  437. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  438. ERR_FAIL_COND_V(!multimesh, RID());
  439. return multimesh->mesh;
  440. }
  441. AABB RasterizerDummy::multimesh_get_aabb(RID p_multimesh) const {
  442. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  443. ERR_FAIL_COND_V(!multimesh, AABB());
  444. return multimesh->aabb;
  445. }
  446. Transform RasterizerDummy::multimesh_instance_get_transform(RID p_multimesh, int p_index) const {
  447. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  448. ERR_FAIL_COND_V(!multimesh, Transform());
  449. ERR_FAIL_INDEX_V(p_index, multimesh->elements.size(), Transform());
  450. return multimesh->elements[p_index].xform;
  451. }
  452. Color RasterizerDummy::multimesh_instance_get_color(RID p_multimesh, int p_index) const {
  453. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  454. ERR_FAIL_COND_V(!multimesh, Color());
  455. ERR_FAIL_INDEX_V(p_index, multimesh->elements.size(), Color());
  456. return multimesh->elements[p_index].color;
  457. }
  458. void RasterizerDummy::multimesh_set_visible_instances(RID p_multimesh, int p_visible) {
  459. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  460. ERR_FAIL_COND(!multimesh);
  461. multimesh->visible = p_visible;
  462. }
  463. int RasterizerDummy::multimesh_get_visible_instances(RID p_multimesh) const {
  464. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  465. ERR_FAIL_COND_V(!multimesh, -1);
  466. return multimesh->visible;
  467. }
  468. /* IMMEDIATE API */
  469. RID RasterizerDummy::immediate_create() {
  470. Immediate *im = memnew(Immediate);
  471. return immediate_owner.make_rid(im);
  472. }
  473. void RasterizerDummy::immediate_begin(RID p_immediate, VS::PrimitiveType p_rimitive, RID p_texture) {
  474. }
  475. void RasterizerDummy::immediate_vertex(RID p_immediate, const Vector3 &p_vertex) {
  476. }
  477. void RasterizerDummy::immediate_normal(RID p_immediate, const Vector3 &p_normal) {
  478. }
  479. void RasterizerDummy::immediate_tangent(RID p_immediate, const Plane &p_tangent) {
  480. }
  481. void RasterizerDummy::immediate_color(RID p_immediate, const Color &p_color) {
  482. }
  483. void RasterizerDummy::immediate_uv(RID p_immediate, const Vector2 &tex_uv) {
  484. }
  485. void RasterizerDummy::immediate_uv2(RID p_immediate, const Vector2 &tex_uv) {
  486. }
  487. void RasterizerDummy::immediate_end(RID p_immediate) {
  488. }
  489. void RasterizerDummy::immediate_clear(RID p_immediate) {
  490. }
  491. AABB RasterizerDummy::immediate_get_aabb(RID p_immediate) const {
  492. return AABB(Vector3(-1, -1, -1), Vector3(2, 2, 2));
  493. }
  494. void RasterizerDummy::immediate_set_material(RID p_immediate, RID p_material) {
  495. Immediate *im = immediate_owner.get(p_immediate);
  496. ERR_FAIL_COND(!im);
  497. im->material = p_material;
  498. }
  499. RID RasterizerDummy::immediate_get_material(RID p_immediate) const {
  500. const Immediate *im = immediate_owner.get(p_immediate);
  501. ERR_FAIL_COND_V(!im, RID());
  502. return im->material;
  503. }
  504. /* PARTICLES API */
  505. RID RasterizerDummy::particles_create() {
  506. Particles *particles = memnew(Particles);
  507. ERR_FAIL_COND_V(!particles, RID());
  508. return particles_owner.make_rid(particles);
  509. }
  510. void RasterizerDummy::particles_set_amount(RID p_particles, int p_amount) {
  511. ERR_FAIL_COND(p_amount < 1);
  512. Particles *particles = particles_owner.get(p_particles);
  513. ERR_FAIL_COND(!particles);
  514. particles->data.amount = p_amount;
  515. }
  516. int RasterizerDummy::particles_get_amount(RID p_particles) const {
  517. Particles *particles = particles_owner.get(p_particles);
  518. ERR_FAIL_COND_V(!particles, -1);
  519. return particles->data.amount;
  520. }
  521. void RasterizerDummy::particles_set_emitting(RID p_particles, bool p_emitting) {
  522. Particles *particles = particles_owner.get(p_particles);
  523. ERR_FAIL_COND(!particles);
  524. particles->data.emitting = p_emitting;
  525. ;
  526. }
  527. bool RasterizerDummy::particles_is_emitting(RID p_particles) const {
  528. const Particles *particles = particles_owner.get(p_particles);
  529. ERR_FAIL_COND_V(!particles, false);
  530. return particles->data.emitting;
  531. }
  532. void RasterizerDummy::particles_set_visibility_aabb(RID p_particles, const AABB &p_visibility) {
  533. Particles *particles = particles_owner.get(p_particles);
  534. ERR_FAIL_COND(!particles);
  535. particles->data.visibility_aabb = p_visibility;
  536. }
  537. void RasterizerDummy::particles_set_emission_half_extents(RID p_particles, const Vector3 &p_half_extents) {
  538. Particles *particles = particles_owner.get(p_particles);
  539. ERR_FAIL_COND(!particles);
  540. particles->data.emission_half_extents = p_half_extents;
  541. }
  542. Vector3 RasterizerDummy::particles_get_emission_half_extents(RID p_particles) const {
  543. Particles *particles = particles_owner.get(p_particles);
  544. ERR_FAIL_COND_V(!particles, Vector3());
  545. return particles->data.emission_half_extents;
  546. }
  547. void RasterizerDummy::particles_set_emission_base_velocity(RID p_particles, const Vector3 &p_base_velocity) {
  548. Particles *particles = particles_owner.get(p_particles);
  549. ERR_FAIL_COND(!particles);
  550. particles->data.emission_base_velocity = p_base_velocity;
  551. }
  552. Vector3 RasterizerDummy::particles_get_emission_base_velocity(RID p_particles) const {
  553. Particles *particles = particles_owner.get(p_particles);
  554. ERR_FAIL_COND_V(!particles, Vector3());
  555. return particles->data.emission_base_velocity;
  556. }
  557. void RasterizerDummy::particles_set_emission_points(RID p_particles, const DVector<Vector3> &p_points) {
  558. Particles *particles = particles_owner.get(p_particles);
  559. ERR_FAIL_COND(!particles);
  560. particles->data.emission_points = p_points;
  561. }
  562. DVector<Vector3> RasterizerDummy::particles_get_emission_points(RID p_particles) const {
  563. Particles *particles = particles_owner.get(p_particles);
  564. ERR_FAIL_COND_V(!particles, DVector<Vector3>());
  565. return particles->data.emission_points;
  566. }
  567. void RasterizerDummy::particles_set_gravity_normal(RID p_particles, const Vector3 &p_normal) {
  568. Particles *particles = particles_owner.get(p_particles);
  569. ERR_FAIL_COND(!particles);
  570. particles->data.gravity_normal = p_normal;
  571. }
  572. Vector3 RasterizerDummy::particles_get_gravity_normal(RID p_particles) const {
  573. Particles *particles = particles_owner.get(p_particles);
  574. ERR_FAIL_COND_V(!particles, Vector3());
  575. return particles->data.gravity_normal;
  576. }
  577. AABB RasterizerDummy::particles_get_visibility_aabb(RID p_particles) const {
  578. const Particles *particles = particles_owner.get(p_particles);
  579. ERR_FAIL_COND_V(!particles, AABB());
  580. return particles->data.visibility_aabb;
  581. }
  582. void RasterizerDummy::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable, float p_value) {
  583. ERR_FAIL_INDEX(p_variable, VS::PARTICLE_VAR_MAX);
  584. Particles *particles = particles_owner.get(p_particles);
  585. ERR_FAIL_COND(!particles);
  586. particles->data.particle_vars[p_variable] = p_value;
  587. }
  588. float RasterizerDummy::particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const {
  589. const Particles *particles = particles_owner.get(p_particles);
  590. ERR_FAIL_COND_V(!particles, -1);
  591. return particles->data.particle_vars[p_variable];
  592. }
  593. void RasterizerDummy::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable, float p_randomness) {
  594. Particles *particles = particles_owner.get(p_particles);
  595. ERR_FAIL_COND(!particles);
  596. particles->data.particle_randomness[p_variable] = p_randomness;
  597. }
  598. float RasterizerDummy::particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const {
  599. const Particles *particles = particles_owner.get(p_particles);
  600. ERR_FAIL_COND_V(!particles, -1);
  601. return particles->data.particle_randomness[p_variable];
  602. }
  603. void RasterizerDummy::particles_set_color_phases(RID p_particles, int p_phases) {
  604. Particles *particles = particles_owner.get(p_particles);
  605. ERR_FAIL_COND(!particles);
  606. ERR_FAIL_COND(p_phases < 0 || p_phases > VS::MAX_PARTICLE_COLOR_PHASES);
  607. particles->data.color_phase_count = p_phases;
  608. }
  609. int RasterizerDummy::particles_get_color_phases(RID p_particles) const {
  610. Particles *particles = particles_owner.get(p_particles);
  611. ERR_FAIL_COND_V(!particles, -1);
  612. return particles->data.color_phase_count;
  613. }
  614. void RasterizerDummy::particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos) {
  615. ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
  616. if (p_pos < 0.0)
  617. p_pos = 0.0;
  618. if (p_pos > 1.0)
  619. p_pos = 1.0;
  620. Particles *particles = particles_owner.get(p_particles);
  621. ERR_FAIL_COND(!particles);
  622. particles->data.color_phases[p_phase].pos = p_pos;
  623. }
  624. float RasterizerDummy::particles_get_color_phase_pos(RID p_particles, int p_phase) const {
  625. ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, -1.0);
  626. const Particles *particles = particles_owner.get(p_particles);
  627. ERR_FAIL_COND_V(!particles, -1);
  628. return particles->data.color_phases[p_phase].pos;
  629. }
  630. void RasterizerDummy::particles_set_color_phase_color(RID p_particles, int p_phase, const Color &p_color) {
  631. ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
  632. Particles *particles = particles_owner.get(p_particles);
  633. ERR_FAIL_COND(!particles);
  634. particles->data.color_phases[p_phase].color = p_color;
  635. //update alpha
  636. particles->has_alpha = false;
  637. for (int i = 0; i < VS::MAX_PARTICLE_COLOR_PHASES; i++) {
  638. if (particles->data.color_phases[i].color.a < 0.99)
  639. particles->has_alpha = true;
  640. }
  641. }
  642. Color RasterizerDummy::particles_get_color_phase_color(RID p_particles, int p_phase) const {
  643. ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, Color());
  644. const Particles *particles = particles_owner.get(p_particles);
  645. ERR_FAIL_COND_V(!particles, Color());
  646. return particles->data.color_phases[p_phase].color;
  647. }
  648. void RasterizerDummy::particles_set_attractors(RID p_particles, int p_attractors) {
  649. Particles *particles = particles_owner.get(p_particles);
  650. ERR_FAIL_COND(!particles);
  651. ERR_FAIL_COND(p_attractors < 0 || p_attractors > VisualServer::MAX_PARTICLE_ATTRACTORS);
  652. particles->data.attractor_count = p_attractors;
  653. }
  654. int RasterizerDummy::particles_get_attractors(RID p_particles) const {
  655. Particles *particles = particles_owner.get(p_particles);
  656. ERR_FAIL_COND_V(!particles, -1);
  657. return particles->data.attractor_count;
  658. }
  659. void RasterizerDummy::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3 &p_pos) {
  660. Particles *particles = particles_owner.get(p_particles);
  661. ERR_FAIL_COND(!particles);
  662. ERR_FAIL_INDEX(p_attractor, particles->data.attractor_count);
  663. particles->data.attractors[p_attractor].pos = p_pos;
  664. ;
  665. }
  666. Vector3 RasterizerDummy::particles_get_attractor_pos(RID p_particles, int p_attractor) const {
  667. Particles *particles = particles_owner.get(p_particles);
  668. ERR_FAIL_COND_V(!particles, Vector3());
  669. ERR_FAIL_INDEX_V(p_attractor, particles->data.attractor_count, Vector3());
  670. return particles->data.attractors[p_attractor].pos;
  671. }
  672. void RasterizerDummy::particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force) {
  673. Particles *particles = particles_owner.get(p_particles);
  674. ERR_FAIL_COND(!particles);
  675. ERR_FAIL_INDEX(p_attractor, particles->data.attractor_count);
  676. particles->data.attractors[p_attractor].force = p_force;
  677. }
  678. float RasterizerDummy::particles_get_attractor_strength(RID p_particles, int p_attractor) const {
  679. Particles *particles = particles_owner.get(p_particles);
  680. ERR_FAIL_COND_V(!particles, 0);
  681. ERR_FAIL_INDEX_V(p_attractor, particles->data.attractor_count, 0);
  682. return particles->data.attractors[p_attractor].force;
  683. }
  684. void RasterizerDummy::particles_set_material(RID p_particles, RID p_material, bool p_owned) {
  685. Particles *particles = particles_owner.get(p_particles);
  686. ERR_FAIL_COND(!particles);
  687. if (particles->material_owned && particles->material.is_valid())
  688. free(particles->material);
  689. particles->material_owned = p_owned;
  690. particles->material = p_material;
  691. }
  692. RID RasterizerDummy::particles_get_material(RID p_particles) const {
  693. const Particles *particles = particles_owner.get(p_particles);
  694. ERR_FAIL_COND_V(!particles, RID());
  695. return particles->material;
  696. }
  697. void RasterizerDummy::particles_set_use_local_coordinates(RID p_particles, bool p_enable) {
  698. Particles *particles = particles_owner.get(p_particles);
  699. ERR_FAIL_COND(!particles);
  700. particles->data.local_coordinates = p_enable;
  701. }
  702. bool RasterizerDummy::particles_is_using_local_coordinates(RID p_particles) const {
  703. const Particles *particles = particles_owner.get(p_particles);
  704. ERR_FAIL_COND_V(!particles, false);
  705. return particles->data.local_coordinates;
  706. }
  707. bool RasterizerDummy::particles_has_height_from_velocity(RID p_particles) const {
  708. const Particles *particles = particles_owner.get(p_particles);
  709. ERR_FAIL_COND_V(!particles, false);
  710. return particles->data.height_from_velocity;
  711. }
  712. void RasterizerDummy::particles_set_height_from_velocity(RID p_particles, bool p_enable) {
  713. Particles *particles = particles_owner.get(p_particles);
  714. ERR_FAIL_COND(!particles);
  715. particles->data.height_from_velocity = p_enable;
  716. }
  717. AABB RasterizerDummy::particles_get_aabb(RID p_particles) const {
  718. const Particles *particles = particles_owner.get(p_particles);
  719. ERR_FAIL_COND_V(!particles, AABB());
  720. return particles->data.visibility_aabb;
  721. }
  722. /* SKELETON API */
  723. RID RasterizerDummy::skeleton_create() {
  724. Skeleton *skeleton = memnew(Skeleton);
  725. ERR_FAIL_COND_V(!skeleton, RID());
  726. return skeleton_owner.make_rid(skeleton);
  727. }
  728. void RasterizerDummy::skeleton_resize(RID p_skeleton, int p_bones) {
  729. Skeleton *skeleton = skeleton_owner.get(p_skeleton);
  730. ERR_FAIL_COND(!skeleton);
  731. if (p_bones == skeleton->bones.size()) {
  732. return;
  733. };
  734. skeleton->bones.resize(p_bones);
  735. }
  736. int RasterizerDummy::skeleton_get_bone_count(RID p_skeleton) const {
  737. Skeleton *skeleton = skeleton_owner.get(p_skeleton);
  738. ERR_FAIL_COND_V(!skeleton, -1);
  739. return skeleton->bones.size();
  740. }
  741. void RasterizerDummy::skeleton_bone_set_transform(RID p_skeleton, int p_bone, const Transform &p_transform) {
  742. Skeleton *skeleton = skeleton_owner.get(p_skeleton);
  743. ERR_FAIL_COND(!skeleton);
  744. ERR_FAIL_INDEX(p_bone, skeleton->bones.size());
  745. skeleton->bones[p_bone] = p_transform;
  746. }
  747. Transform RasterizerDummy::skeleton_bone_get_transform(RID p_skeleton, int p_bone) {
  748. Skeleton *skeleton = skeleton_owner.get(p_skeleton);
  749. ERR_FAIL_COND_V(!skeleton, Transform());
  750. ERR_FAIL_INDEX_V(p_bone, skeleton->bones.size(), Transform());
  751. // something
  752. return skeleton->bones[p_bone];
  753. }
  754. /* LIGHT API */
  755. RID RasterizerDummy::light_create(VS::LightType p_type) {
  756. Light *light = memnew(Light);
  757. light->type = p_type;
  758. return light_owner.make_rid(light);
  759. }
  760. VS::LightType RasterizerDummy::light_get_type(RID p_light) const {
  761. Light *light = light_owner.get(p_light);
  762. ERR_FAIL_COND_V(!light, VS::LIGHT_OMNI);
  763. return light->type;
  764. }
  765. void RasterizerDummy::light_set_color(RID p_light, VS::LightColor p_type, const Color &p_color) {
  766. Light *light = light_owner.get(p_light);
  767. ERR_FAIL_COND(!light);
  768. ERR_FAIL_INDEX(p_type, 3);
  769. light->colors[p_type] = p_color;
  770. }
  771. Color RasterizerDummy::light_get_color(RID p_light, VS::LightColor p_type) const {
  772. Light *light = light_owner.get(p_light);
  773. ERR_FAIL_COND_V(!light, Color());
  774. ERR_FAIL_INDEX_V(p_type, 3, Color());
  775. return light->colors[p_type];
  776. }
  777. void RasterizerDummy::light_set_shadow(RID p_light, bool p_enabled) {
  778. Light *light = light_owner.get(p_light);
  779. ERR_FAIL_COND(!light);
  780. light->shadow_enabled = p_enabled;
  781. }
  782. bool RasterizerDummy::light_has_shadow(RID p_light) const {
  783. Light *light = light_owner.get(p_light);
  784. ERR_FAIL_COND_V(!light, false);
  785. return light->shadow_enabled;
  786. }
  787. void RasterizerDummy::light_set_volumetric(RID p_light, bool p_enabled) {
  788. Light *light = light_owner.get(p_light);
  789. ERR_FAIL_COND(!light);
  790. light->volumetric_enabled = p_enabled;
  791. }
  792. bool RasterizerDummy::light_is_volumetric(RID p_light) const {
  793. Light *light = light_owner.get(p_light);
  794. ERR_FAIL_COND_V(!light, false);
  795. return light->volumetric_enabled;
  796. }
  797. void RasterizerDummy::light_set_projector(RID p_light, RID p_texture) {
  798. Light *light = light_owner.get(p_light);
  799. ERR_FAIL_COND(!light);
  800. light->projector = p_texture;
  801. }
  802. RID RasterizerDummy::light_get_projector(RID p_light) const {
  803. Light *light = light_owner.get(p_light);
  804. ERR_FAIL_COND_V(!light, RID());
  805. return light->projector;
  806. }
  807. void RasterizerDummy::light_set_var(RID p_light, VS::LightParam p_var, float p_value) {
  808. Light *light = light_owner.get(p_light);
  809. ERR_FAIL_COND(!light);
  810. ERR_FAIL_INDEX(p_var, VS::LIGHT_PARAM_MAX);
  811. light->vars[p_var] = p_value;
  812. }
  813. float RasterizerDummy::light_get_var(RID p_light, VS::LightParam p_var) const {
  814. Light *light = light_owner.get(p_light);
  815. ERR_FAIL_COND_V(!light, 0);
  816. ERR_FAIL_INDEX_V(p_var, VS::LIGHT_PARAM_MAX, 0);
  817. return light->vars[p_var];
  818. }
  819. void RasterizerDummy::light_set_operator(RID p_light, VS::LightOp p_op) {
  820. Light *light = light_owner.get(p_light);
  821. ERR_FAIL_COND(!light);
  822. };
  823. VS::LightOp RasterizerDummy::light_get_operator(RID p_light) const {
  824. return VS::LightOp(0);
  825. };
  826. void RasterizerDummy::light_omni_set_shadow_mode(RID p_light, VS::LightOmniShadowMode p_mode) {
  827. }
  828. VS::LightOmniShadowMode RasterizerDummy::light_omni_get_shadow_mode(RID p_light) const {
  829. return VS::LightOmniShadowMode(0);
  830. }
  831. void RasterizerDummy::light_directional_set_shadow_mode(RID p_light, VS::LightDirectionalShadowMode p_mode) {
  832. }
  833. VS::LightDirectionalShadowMode RasterizerDummy::light_directional_get_shadow_mode(RID p_light) const {
  834. return VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
  835. }
  836. void RasterizerDummy::light_directional_set_shadow_param(RID p_light, VS::LightDirectionalShadowParam p_param, float p_value) {
  837. }
  838. float RasterizerDummy::light_directional_get_shadow_param(RID p_light, VS::LightDirectionalShadowParam p_param) const {
  839. return 0;
  840. }
  841. AABB RasterizerDummy::light_get_aabb(RID p_light) const {
  842. Light *light = light_owner.get(p_light);
  843. ERR_FAIL_COND_V(!light, AABB());
  844. switch (light->type) {
  845. case VS::LIGHT_SPOT: {
  846. float len = light->vars[VS::LIGHT_PARAM_RADIUS];
  847. float size = Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE])) * len;
  848. return AABB(Vector3(-size, -size, -len), Vector3(size * 2, size * 2, len));
  849. } break;
  850. case VS::LIGHT_OMNI: {
  851. float r = light->vars[VS::LIGHT_PARAM_RADIUS];
  852. return AABB(-Vector3(r, r, r), Vector3(r, r, r) * 2);
  853. } break;
  854. case VS::LIGHT_DIRECTIONAL: {
  855. return AABB();
  856. } break;
  857. default: {}
  858. }
  859. ERR_FAIL_V(AABB());
  860. }
  861. RID RasterizerDummy::light_instance_create(RID p_light) {
  862. Light *light = light_owner.get(p_light);
  863. ERR_FAIL_COND_V(!light, RID());
  864. LightInstance *light_instance = memnew(LightInstance);
  865. light_instance->light = p_light;
  866. light_instance->base = light;
  867. return light_instance_owner.make_rid(light_instance);
  868. }
  869. void RasterizerDummy::light_instance_set_transform(RID p_light_instance, const Transform &p_transform) {
  870. LightInstance *lighti = light_instance_owner.get(p_light_instance);
  871. ERR_FAIL_COND(!lighti);
  872. lighti->transform = p_transform;
  873. }
  874. bool RasterizerDummy::light_instance_has_shadow(RID p_light_instance) const {
  875. return false;
  876. }
  877. bool RasterizerDummy::light_instance_assign_shadow(RID p_light_instance) {
  878. return false;
  879. }
  880. Rasterizer::ShadowType RasterizerDummy::light_instance_get_shadow_type(RID p_light_instance) const {
  881. LightInstance *lighti = light_instance_owner.get(p_light_instance);
  882. ERR_FAIL_COND_V(!lighti, Rasterizer::SHADOW_NONE);
  883. switch (lighti->base->type) {
  884. case VS::LIGHT_DIRECTIONAL: return SHADOW_PSM; break;
  885. case VS::LIGHT_OMNI: return SHADOW_DUAL_PARABOLOID; break;
  886. case VS::LIGHT_SPOT: return SHADOW_SIMPLE; break;
  887. }
  888. return Rasterizer::SHADOW_NONE;
  889. }
  890. Rasterizer::ShadowType RasterizerDummy::light_instance_get_shadow_type(RID p_light_instance, bool p_far) const {
  891. return SHADOW_NONE;
  892. }
  893. void RasterizerDummy::light_instance_set_shadow_transform(RID p_light_instance, int p_index, const CameraMatrix &p_camera, const Transform &p_transform, float p_split_near, float p_split_far) {
  894. }
  895. int RasterizerDummy::light_instance_get_shadow_passes(RID p_light_instance) const {
  896. return 0;
  897. }
  898. bool RasterizerDummy::light_instance_get_pssm_shadow_overlap(RID p_light_instance) const {
  899. return false;
  900. }
  901. void RasterizerDummy::light_instance_set_custom_transform(RID p_light_instance, int p_index, const CameraMatrix &p_camera, const Transform &p_transform, float p_split_near, float p_split_far) {
  902. LightInstance *lighti = light_instance_owner.get(p_light_instance);
  903. ERR_FAIL_COND(!lighti);
  904. ERR_FAIL_COND(lighti->base->type != VS::LIGHT_DIRECTIONAL);
  905. ERR_FAIL_INDEX(p_index, 1);
  906. lighti->custom_projection = p_camera;
  907. lighti->custom_transform = p_transform;
  908. }
  909. void RasterizerDummy::shadow_clear_near() {
  910. }
  911. bool RasterizerDummy::shadow_allocate_near(RID p_light) {
  912. return false;
  913. }
  914. bool RasterizerDummy::shadow_allocate_far(RID p_light) {
  915. return false;
  916. }
  917. /* PARTICLES INSTANCE */
  918. RID RasterizerDummy::particles_instance_create(RID p_particles) {
  919. ERR_FAIL_COND_V(!particles_owner.owns(p_particles), RID());
  920. ParticlesInstance *particles_instance = memnew(ParticlesInstance);
  921. ERR_FAIL_COND_V(!particles_instance, RID());
  922. particles_instance->particles = p_particles;
  923. return particles_instance_owner.make_rid(particles_instance);
  924. }
  925. void RasterizerDummy::particles_instance_set_transform(RID p_particles_instance, const Transform &p_transform) {
  926. ParticlesInstance *particles_instance = particles_instance_owner.get(p_particles_instance);
  927. ERR_FAIL_COND(!particles_instance);
  928. particles_instance->transform = p_transform;
  929. }
  930. /* RENDER API */
  931. /* all calls (inside begin/end shadow) are always warranted to be in the following order: */
  932. RID RasterizerDummy::viewport_data_create() {
  933. return RID();
  934. }
  935. RID RasterizerDummy::render_target_create() {
  936. return RID();
  937. }
  938. void RasterizerDummy::render_target_set_size(RID p_render_target, int p_width, int p_height) {
  939. }
  940. RID RasterizerDummy::render_target_get_texture(RID p_render_target) const {
  941. return RID();
  942. }
  943. bool RasterizerDummy::render_target_renedered_in_frame(RID p_render_target) {
  944. return false;
  945. }
  946. void RasterizerDummy::begin_frame() {
  947. }
  948. void RasterizerDummy::capture_viewport(Image *r_capture) {
  949. }
  950. void RasterizerDummy::clear_viewport(const Color &p_color){
  951. };
  952. void RasterizerDummy::set_viewport(const VS::ViewportRect &p_viewport) {
  953. }
  954. void RasterizerDummy::set_render_target(RID p_render_target, bool p_transparent_bg, bool p_vflip) {
  955. }
  956. void RasterizerDummy::begin_scene(RID p_viewport_data, RID p_env, VS::ScenarioDebugMode p_debug){
  957. };
  958. void RasterizerDummy::begin_shadow_map(RID p_light_instance, int p_shadow_pass) {
  959. }
  960. void RasterizerDummy::set_camera(const Transform &p_world, const CameraMatrix &p_projection, bool p_ortho_hint) {
  961. }
  962. void RasterizerDummy::add_light(RID p_light_instance) {
  963. }
  964. void RasterizerDummy::add_mesh(const RID &p_mesh, const InstanceData *p_data) {
  965. }
  966. void RasterizerDummy::add_multimesh(const RID &p_multimesh, const InstanceData *p_data) {
  967. }
  968. void RasterizerDummy::add_particles(const RID &p_particle_instance, const InstanceData *p_data) {
  969. }
  970. void RasterizerDummy::end_scene() {
  971. }
  972. void RasterizerDummy::end_shadow_map() {
  973. }
  974. void RasterizerDummy::end_frame() {
  975. }
  976. RID RasterizerDummy::canvas_light_occluder_create() {
  977. return RID();
  978. }
  979. void RasterizerDummy::canvas_light_occluder_set_polylines(RID p_occluder, const DVector<Vector2> &p_lines) {
  980. }
  981. RID RasterizerDummy::canvas_light_shadow_buffer_create(int p_width) {
  982. return RID();
  983. }
  984. void RasterizerDummy::canvas_light_shadow_buffer_update(RID p_buffer, const Matrix32 &p_light_xform, int p_light_mask, float p_near, float p_far, CanvasLightOccluderInstance *p_occluders, CameraMatrix *p_xform_cache) {
  985. }
  986. void RasterizerDummy::canvas_debug_viewport_shadows(CanvasLight *p_lights_with_shadow) {
  987. }
  988. /* CANVAS API */
  989. void RasterizerDummy::begin_canvas_bg() {
  990. }
  991. void RasterizerDummy::canvas_begin() {
  992. }
  993. void RasterizerDummy::canvas_disable_blending() {
  994. }
  995. void RasterizerDummy::canvas_set_opacity(float p_opacity) {
  996. }
  997. void RasterizerDummy::canvas_set_blend_mode(VS::MaterialBlendMode p_mode) {
  998. }
  999. void RasterizerDummy::canvas_begin_rect(const Matrix32 &p_transform) {
  1000. }
  1001. void RasterizerDummy::canvas_set_clip(bool p_clip, const Rect2 &p_rect) {
  1002. }
  1003. void RasterizerDummy::canvas_end_rect() {
  1004. }
  1005. void RasterizerDummy::canvas_draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width) {
  1006. }
  1007. void RasterizerDummy::canvas_draw_rect(const Rect2 &p_rect, int p_flags, const Rect2 &p_source, RID p_texture, const Color &p_modulate) {
  1008. }
  1009. void RasterizerDummy::canvas_draw_style_box(const Rect2 &p_rect, const Rect2 &p_src_region, RID p_texture, const float *p_margin, bool p_draw_center, const Color &p_modulate) {
  1010. }
  1011. void RasterizerDummy::canvas_draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, RID p_texture, float p_width) {
  1012. }
  1013. void RasterizerDummy::canvas_draw_polygon(int p_vertex_count, const int *p_indices, const Vector2 *p_vertices, const Vector2 *p_uvs, const Color *p_colors, const RID &p_texture, bool p_singlecolor) {
  1014. }
  1015. void RasterizerDummy::canvas_set_transform(const Matrix32 &p_transform) {
  1016. }
  1017. void RasterizerDummy::canvas_render_items(CanvasItem *p_item_list, int p_z, const Color &p_modulate, CanvasLight *p_light) {
  1018. }
  1019. /* ENVIRONMENT */
  1020. RID RasterizerDummy::environment_create() {
  1021. Environment *env = memnew(Environment);
  1022. return environment_owner.make_rid(env);
  1023. }
  1024. void RasterizerDummy::environment_set_background(RID p_env, VS::EnvironmentBG p_bg) {
  1025. ERR_FAIL_INDEX(p_bg, VS::ENV_BG_MAX);
  1026. Environment *env = environment_owner.get(p_env);
  1027. ERR_FAIL_COND(!env);
  1028. env->bg_mode = p_bg;
  1029. }
  1030. VS::EnvironmentBG RasterizerDummy::environment_get_background(RID p_env) const {
  1031. const Environment *env = environment_owner.get(p_env);
  1032. ERR_FAIL_COND_V(!env, VS::ENV_BG_MAX);
  1033. return env->bg_mode;
  1034. }
  1035. void RasterizerDummy::environment_set_background_param(RID p_env, VS::EnvironmentBGParam p_param, const Variant &p_value) {
  1036. ERR_FAIL_INDEX(p_param, VS::ENV_BG_PARAM_MAX);
  1037. Environment *env = environment_owner.get(p_env);
  1038. ERR_FAIL_COND(!env);
  1039. env->bg_param[p_param] = p_value;
  1040. }
  1041. Variant RasterizerDummy::environment_get_background_param(RID p_env, VS::EnvironmentBGParam p_param) const {
  1042. ERR_FAIL_INDEX_V(p_param, VS::ENV_BG_PARAM_MAX, Variant());
  1043. const Environment *env = environment_owner.get(p_env);
  1044. ERR_FAIL_COND_V(!env, Variant());
  1045. return env->bg_param[p_param];
  1046. }
  1047. void RasterizerDummy::environment_set_enable_fx(RID p_env, VS::EnvironmentFx p_effect, bool p_enabled) {
  1048. ERR_FAIL_INDEX(p_effect, VS::ENV_FX_MAX);
  1049. Environment *env = environment_owner.get(p_env);
  1050. ERR_FAIL_COND(!env);
  1051. env->fx_enabled[p_effect] = p_enabled;
  1052. }
  1053. bool RasterizerDummy::environment_is_fx_enabled(RID p_env, VS::EnvironmentFx p_effect) const {
  1054. ERR_FAIL_INDEX_V(p_effect, VS::ENV_FX_MAX, false);
  1055. const Environment *env = environment_owner.get(p_env);
  1056. ERR_FAIL_COND_V(!env, false);
  1057. return env->fx_enabled[p_effect];
  1058. }
  1059. void RasterizerDummy::environment_fx_set_param(RID p_env, VS::EnvironmentFxParam p_param, const Variant &p_value) {
  1060. ERR_FAIL_INDEX(p_param, VS::ENV_FX_PARAM_MAX);
  1061. Environment *env = environment_owner.get(p_env);
  1062. ERR_FAIL_COND(!env);
  1063. env->fx_param[p_param] = p_value;
  1064. }
  1065. Variant RasterizerDummy::environment_fx_get_param(RID p_env, VS::EnvironmentFxParam p_param) const {
  1066. ERR_FAIL_INDEX_V(p_param, VS::ENV_FX_PARAM_MAX, Variant());
  1067. const Environment *env = environment_owner.get(p_env);
  1068. ERR_FAIL_COND_V(!env, Variant());
  1069. return env->fx_param[p_param];
  1070. }
  1071. RID RasterizerDummy::sampled_light_dp_create(int p_width, int p_height) {
  1072. return sampled_light_owner.make_rid(memnew(SampledLight));
  1073. }
  1074. void RasterizerDummy::sampled_light_dp_update(RID p_sampled_light, const Color *p_data, float p_multiplier) {
  1075. }
  1076. /*MISC*/
  1077. bool RasterizerDummy::is_texture(const RID &p_rid) const {
  1078. return texture_owner.owns(p_rid);
  1079. }
  1080. bool RasterizerDummy::is_material(const RID &p_rid) const {
  1081. return material_owner.owns(p_rid);
  1082. }
  1083. bool RasterizerDummy::is_mesh(const RID &p_rid) const {
  1084. return mesh_owner.owns(p_rid);
  1085. }
  1086. bool RasterizerDummy::is_immediate(const RID &p_rid) const {
  1087. return immediate_owner.owns(p_rid);
  1088. }
  1089. bool RasterizerDummy::is_multimesh(const RID &p_rid) const {
  1090. return multimesh_owner.owns(p_rid);
  1091. }
  1092. bool RasterizerDummy::is_particles(const RID &p_beam) const {
  1093. return particles_owner.owns(p_beam);
  1094. }
  1095. bool RasterizerDummy::is_light(const RID &p_rid) const {
  1096. return light_owner.owns(p_rid);
  1097. }
  1098. bool RasterizerDummy::is_light_instance(const RID &p_rid) const {
  1099. return light_instance_owner.owns(p_rid);
  1100. }
  1101. bool RasterizerDummy::is_particles_instance(const RID &p_rid) const {
  1102. return particles_instance_owner.owns(p_rid);
  1103. }
  1104. bool RasterizerDummy::is_skeleton(const RID &p_rid) const {
  1105. return skeleton_owner.owns(p_rid);
  1106. }
  1107. bool RasterizerDummy::is_environment(const RID &p_rid) const {
  1108. return environment_owner.owns(p_rid);
  1109. }
  1110. bool RasterizerDummy::is_canvas_light_occluder(const RID &p_rid) const {
  1111. return false;
  1112. }
  1113. bool RasterizerDummy::is_shader(const RID &p_rid) const {
  1114. return false;
  1115. }
  1116. void RasterizerDummy::free(const RID &p_rid) {
  1117. if (texture_owner.owns(p_rid)) {
  1118. // delete the texture
  1119. Texture *texture = texture_owner.get(p_rid);
  1120. texture_owner.free(p_rid);
  1121. memdelete(texture);
  1122. } else if (shader_owner.owns(p_rid)) {
  1123. // delete the texture
  1124. Shader *shader = shader_owner.get(p_rid);
  1125. shader_owner.free(p_rid);
  1126. memdelete(shader);
  1127. } else if (material_owner.owns(p_rid)) {
  1128. Material *material = material_owner.get(p_rid);
  1129. material_owner.free(p_rid);
  1130. memdelete(material);
  1131. } else if (mesh_owner.owns(p_rid)) {
  1132. Mesh *mesh = mesh_owner.get(p_rid);
  1133. for (int i = 0; i < mesh->surfaces.size(); i++) {
  1134. memdelete(mesh->surfaces[i]);
  1135. };
  1136. mesh->surfaces.clear();
  1137. mesh_owner.free(p_rid);
  1138. memdelete(mesh);
  1139. } else if (multimesh_owner.owns(p_rid)) {
  1140. MultiMesh *multimesh = multimesh_owner.get(p_rid);
  1141. multimesh_owner.free(p_rid);
  1142. memdelete(multimesh);
  1143. } else if (immediate_owner.owns(p_rid)) {
  1144. Immediate *immediate = immediate_owner.get(p_rid);
  1145. immediate_owner.free(p_rid);
  1146. memdelete(immediate);
  1147. } else if (particles_owner.owns(p_rid)) {
  1148. Particles *particles = particles_owner.get(p_rid);
  1149. particles_owner.free(p_rid);
  1150. memdelete(particles);
  1151. } else if (particles_instance_owner.owns(p_rid)) {
  1152. ParticlesInstance *particles_isntance = particles_instance_owner.get(p_rid);
  1153. particles_instance_owner.free(p_rid);
  1154. memdelete(particles_isntance);
  1155. } else if (skeleton_owner.owns(p_rid)) {
  1156. Skeleton *skeleton = skeleton_owner.get(p_rid);
  1157. skeleton_owner.free(p_rid);
  1158. memdelete(skeleton);
  1159. } else if (light_owner.owns(p_rid)) {
  1160. Light *light = light_owner.get(p_rid);
  1161. light_owner.free(p_rid);
  1162. memdelete(light);
  1163. } else if (light_instance_owner.owns(p_rid)) {
  1164. LightInstance *light_instance = light_instance_owner.get(p_rid);
  1165. light_instance_owner.free(p_rid);
  1166. memdelete(light_instance);
  1167. } else if (environment_owner.owns(p_rid)) {
  1168. Environment *env = environment_owner.get(p_rid);
  1169. environment_owner.free(p_rid);
  1170. memdelete(env);
  1171. } else if (sampled_light_owner.owns(p_rid)) {
  1172. SampledLight *sampled_light = sampled_light_owner.get(p_rid);
  1173. ERR_FAIL_COND(!sampled_light);
  1174. sampled_light_owner.free(p_rid);
  1175. memdelete(sampled_light);
  1176. };
  1177. }
  1178. void RasterizerDummy::custom_shade_model_set_shader(int p_model, RID p_shader){
  1179. };
  1180. RID RasterizerDummy::custom_shade_model_get_shader(int p_model) const {
  1181. return RID();
  1182. };
  1183. void RasterizerDummy::custom_shade_model_set_name(int p_model, const String &p_name){
  1184. };
  1185. String RasterizerDummy::custom_shade_model_get_name(int p_model) const {
  1186. return String();
  1187. };
  1188. void RasterizerDummy::custom_shade_model_set_param_info(int p_model, const List<PropertyInfo> &p_info){
  1189. };
  1190. void RasterizerDummy::custom_shade_model_get_param_info(int p_model, List<PropertyInfo> *p_info) const {
  1191. };
  1192. void RasterizerDummy::set_time_scale(float p_scale) {
  1193. }
  1194. void RasterizerDummy::init() {
  1195. }
  1196. void RasterizerDummy::finish() {
  1197. }
  1198. int RasterizerDummy::get_render_info(VS::RenderInfo p_info) {
  1199. return 0;
  1200. }
  1201. bool RasterizerDummy::needs_to_draw_next_frame() const {
  1202. return false;
  1203. }
  1204. bool RasterizerDummy::has_feature(VS::Features p_feature) const {
  1205. return false;
  1206. }
  1207. void RasterizerDummy::restore_framebuffer() {
  1208. }
  1209. RasterizerDummy::RasterizerDummy(){
  1210. };
  1211. RasterizerDummy::~RasterizerDummy(){
  1212. };