rasterizer_dummy.cpp 45 KB

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