rasterizer_flash.cpp 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601
  1. /*************************************************/
  2. /* rasterizer_gles2.cpp */
  3. /*************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /*************************************************/
  7. /* Source code within this file is: */
  8. /* (c) 2007-2010 Juan Linietsky, Ariel Manzur */
  9. /* All Rights Reserved. */
  10. /*************************************************/
  11. #include "rasterizer_flash.h"
  12. #include "os/os.h"
  13. #include "globals.h"
  14. #include <stdio.h>
  15. #include "servers/visual/particle_system_sw.h"
  16. #include <string.h>
  17. _FORCE_INLINE_ static void _set_color_attrib(const Color& p_color) {
  18. }
  19. RasterizerFlash::FX::FX() {
  20. bgcolor_active=false;
  21. bgcolor=Color(0,1,0,1);
  22. skybox_active=false;
  23. glow_active=false;
  24. glow_passes=4;
  25. glow_attenuation=0.7;
  26. glow_bloom=0.0;
  27. antialias_active=true;
  28. antialias_tolerance=15;
  29. ssao_active=true;
  30. ssao_attenuation=0.7;
  31. ssao_radius=0.18;
  32. ssao_max_distance=1.0;
  33. ssao_range_min=0.25;
  34. ssao_range_max=0.48;
  35. ssao_only=false;
  36. fog_active=false;
  37. fog_near=5;
  38. fog_far=100;
  39. fog_attenuation=1.0;
  40. fog_color_near=Color(1,1,1,1);
  41. fog_color_far=Color(1,1,1,1);
  42. fog_bg=false;
  43. toon_active=false;
  44. toon_treshold=0.4;
  45. toon_soft=0.001;
  46. edge_active=false;
  47. edge_color=Color(0,0,0,1);
  48. edge_size=1.0;
  49. }
  50. void RasterizerFlash::_draw_primitive(int p_points, const Vector3 *p_vertices, const Vector3 *p_normals, const Color* p_colors, const Vector3 *p_uvs,const Plane *p_tangents,int p_instanced) {
  51. };
  52. RID RasterizerFlash::texture_create() {
  53. Texture *texture = memnew(Texture);
  54. return texture_owner.make_rid( texture );
  55. }
  56. void RasterizerFlash::texture_allocate(RID p_texture,int p_width, int p_height,Image::Format p_format,uint32_t p_flags,int p_mipmap_count) {
  57. }
  58. void RasterizerFlash::texture_set_data(RID p_texture,const Image& p_image,VS::CubeMapSide p_cube_side) {
  59. }
  60. Image RasterizerFlash::texture_get_data(RID p_texture,VS::CubeMapSide p_cube_side) const {
  61. return Image();
  62. }
  63. void RasterizerFlash::texture_set_flags(RID p_texture,uint32_t p_flags) {
  64. }
  65. uint32_t RasterizerFlash::texture_get_flags(RID p_texture) const {
  66. Texture * texture = texture_owner.get(p_texture);
  67. ERR_FAIL_COND_V(!texture,0);
  68. return texture->flags;
  69. }
  70. Image::Format RasterizerFlash::texture_get_format(RID p_texture) const {
  71. Texture * texture = texture_owner.get(p_texture);
  72. ERR_FAIL_COND_V(!texture,Image::FORMAT_GRAYSCALE);
  73. return texture->format;
  74. }
  75. uint32_t RasterizerFlash::texture_get_width(RID p_texture) const {
  76. Texture * texture = texture_owner.get(p_texture);
  77. ERR_FAIL_COND_V(!texture,0);
  78. return texture->width;
  79. }
  80. uint32_t RasterizerFlash::texture_get_height(RID p_texture) const {
  81. Texture * texture = texture_owner.get(p_texture);
  82. ERR_FAIL_COND_V(!texture,0);
  83. return texture->height;
  84. }
  85. bool RasterizerFlash::texture_has_alpha(RID p_texture) const {
  86. Texture * texture = texture_owner.get(p_texture);
  87. ERR_FAIL_COND_V(!texture,0);
  88. return texture->has_alpha;
  89. }
  90. void RasterizerFlash::texture_set_size_override(RID p_texture,int p_width, int p_height) {
  91. Texture * texture = texture_owner.get(p_texture);
  92. ERR_FAIL_COND(!texture);
  93. ERR_FAIL_COND(p_width<=0 || p_width>4096);
  94. ERR_FAIL_COND(p_height<=0 || p_height>4096);
  95. //real texture size is in alloc width and height
  96. texture->width=p_width;
  97. texture->height=p_height;
  98. }
  99. /* SHADER API */
  100. RID RasterizerFlash::shader_create(VS::ShaderMode p_mode) {
  101. Shader *shader = memnew( Shader );
  102. shader->mode=p_mode;
  103. RID rid = shader_owner.make_rid(shader);
  104. shader_set_mode(rid,p_mode);
  105. _shader_make_dirty(shader);
  106. return rid;
  107. }
  108. void RasterizerFlash::shader_set_mode(RID p_shader,VS::ShaderMode p_mode) {
  109. }
  110. VS::ShaderMode RasterizerFlash::shader_get_mode(RID p_shader) const {
  111. Shader *shader=shader_owner.get(p_shader);
  112. ERR_FAIL_COND_V(!shader,VS::SHADER_MATERIAL);
  113. return shader->mode;
  114. }
  115. void RasterizerFlash::shader_set_code(RID p_shader, const String& p_vertex, const String& p_fragment,int p_vertex_ofs,int p_fragment_ofs) {
  116. Shader *shader=shader_owner.get(p_shader);
  117. ERR_FAIL_COND(!shader);
  118. #ifdef DEBUG_ENABLED
  119. if (shader->vertex_code==p_vertex && shader->fragment_code==p_fragment)
  120. return;
  121. #endif
  122. shader->fragment_code=p_fragment;
  123. shader->vertex_code=p_vertex;
  124. shader->fragment_line=p_fragment_ofs;
  125. shader->vertex_line=p_vertex_ofs;
  126. _shader_make_dirty(shader);
  127. }
  128. String RasterizerFlash::shader_get_vertex_code(RID p_shader) const {
  129. Shader *shader=shader_owner.get(p_shader);
  130. ERR_FAIL_COND_V(!shader,String());
  131. return shader->vertex_code;
  132. }
  133. String RasterizerFlash::shader_get_fragment_code(RID p_shader) const {
  134. Shader *shader=shader_owner.get(p_shader);
  135. ERR_FAIL_COND_V(!shader,String());
  136. return shader->fragment_code;
  137. }
  138. void RasterizerFlash::_shader_make_dirty(Shader* p_shader) {
  139. if (p_shader->dirty_list.in_list())
  140. return;
  141. _shader_dirty_list.add(&p_shader->dirty_list);
  142. }
  143. void RasterizerFlash::shader_get_param_list(RID p_shader, List<PropertyInfo> *p_param_list) const {
  144. Shader *shader=shader_owner.get(p_shader);
  145. ERR_FAIL_COND(!shader);
  146. if (shader->dirty_list.in_list())
  147. _update_shader(shader); // ok should be not anymore dirty
  148. Map<int,StringName> order;
  149. for(Map<StringName,ShaderLanguage::Uniform>::Element *E=shader->uniforms.front();E;E=E->next()) {
  150. order[E->get().order]=E->key();
  151. }
  152. for(Map<int,StringName>::Element *E=order.front();E;E=E->next()) {
  153. PropertyInfo pi;
  154. ShaderLanguage::Uniform &u=shader->uniforms[E->get()];
  155. pi.name=E->get();
  156. switch(u.type) {
  157. case ShaderLanguage::TYPE_VOID:
  158. case ShaderLanguage::TYPE_BOOL:
  159. case ShaderLanguage::TYPE_FLOAT:
  160. case ShaderLanguage::TYPE_VEC2:
  161. case ShaderLanguage::TYPE_VEC3:
  162. case ShaderLanguage::TYPE_MAT3:
  163. case ShaderLanguage::TYPE_MAT4:
  164. case ShaderLanguage::TYPE_VEC4:
  165. pi.type=u.default_value.get_type();
  166. break;
  167. case ShaderLanguage::TYPE_TEXTURE:
  168. pi.type=Variant::_RID;
  169. pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
  170. pi.hint_string="Texture";
  171. break;
  172. case ShaderLanguage::TYPE_CUBEMAP:
  173. pi.type=Variant::_RID;
  174. pi.hint=PROPERTY_HINT_RESOURCE_TYPE;
  175. pi.hint_string="Texture";
  176. break;
  177. };
  178. p_param_list->push_back(pi);
  179. }
  180. }
  181. /* COMMON MATERIAL API */
  182. RID RasterizerFlash::material_create() {
  183. return material_owner.make_rid( memnew( Material ) );
  184. }
  185. void RasterizerFlash::material_set_shader(RID p_material, RID p_shader) {
  186. Material *material = material_owner.get(p_material);
  187. ERR_FAIL_COND(!material);
  188. if (material->shader==p_shader)
  189. return;
  190. material->shader=p_shader;
  191. material->shader_version=0;
  192. }
  193. RID RasterizerFlash::material_get_shader(RID p_material) const {
  194. Material *material = material_owner.get(p_material);
  195. ERR_FAIL_COND_V(!material,RID());
  196. return material->shader;
  197. }
  198. void RasterizerFlash::material_set_param(RID p_material, const StringName& p_param, const Variant& p_value) {
  199. Material *material = material_owner.get(p_material);
  200. ERR_FAIL_COND(!material);
  201. Map<StringName,Material::UniformData>::Element *E=material->shader_params.find(p_param);
  202. if (E) {
  203. if (p_value.get_type()==Variant::NIL) {
  204. material->shader_params.erase(E);
  205. material->shader_version=0; //get default!
  206. } else {
  207. E->get().value=p_value;
  208. }
  209. } else {
  210. Material::UniformData ud;
  211. ud.index=-1;
  212. ud.value=p_value;
  213. ud.istexture=p_value.get_type()==Variant::_RID; /// cache it being texture
  214. material->shader_params[p_param]=ud; //may be got at some point, or erased
  215. }
  216. }
  217. Variant RasterizerFlash::material_get_param(RID p_material, const StringName& p_param) const {
  218. Material *material = material_owner.get(p_material);
  219. ERR_FAIL_COND_V(!material,Variant());
  220. if (material->shader.is_valid()) {
  221. //update shader params if necesary
  222. //make sure the shader is compiled and everything
  223. //so the actual parameters can be properly retrieved!
  224. material->shader_cache=shader_owner.get( material->shader );
  225. if (!material->shader_cache) {
  226. //invalidate
  227. material->shader=RID();
  228. material->shader_cache=NULL;
  229. } else {
  230. if (material->shader_cache->dirty_list.in_list())
  231. _update_shader(material->shader_cache);
  232. if (material->shader_cache->valid && material->shader_cache->version!=material->shader_version) {
  233. //validate
  234. _update_material_shader_params(material);
  235. }
  236. }
  237. }
  238. if (material->shader_params.has(p_param))
  239. return material->shader_params[p_param].value;
  240. else
  241. return Variant();
  242. }
  243. void RasterizerFlash::material_set_flag(RID p_material, VS::MaterialFlag p_flag,bool p_enabled) {
  244. Material *material = material_owner.get(p_material);
  245. ERR_FAIL_COND(!material);
  246. ERR_FAIL_INDEX(p_flag,VS::MATERIAL_FLAG_MAX);
  247. material->flags[p_flag]=p_enabled;
  248. }
  249. bool RasterizerFlash::material_get_flag(RID p_material,VS::MaterialFlag p_flag) const {
  250. Material *material = material_owner.get(p_material);
  251. ERR_FAIL_COND_V(!material,false);
  252. ERR_FAIL_INDEX_V(p_flag,VS::MATERIAL_FLAG_MAX,false);
  253. return material->flags[p_flag];
  254. }
  255. void RasterizerFlash::material_set_hint(RID p_material, VS::MaterialHint p_hint,bool p_enabled) {
  256. Material *material = material_owner.get(p_material);
  257. ERR_FAIL_COND(!material);
  258. ERR_FAIL_INDEX(p_hint,VS::MATERIAL_HINT_MAX);
  259. material->hints[p_hint]=p_enabled;
  260. }
  261. bool RasterizerFlash::material_get_hint(RID p_material,VS::MaterialHint p_hint) const {
  262. Material *material = material_owner.get(p_material);
  263. ERR_FAIL_COND_V(!material,false);
  264. ERR_FAIL_INDEX_V(p_hint,VS::MATERIAL_HINT_MAX,false);
  265. return material->hints[p_hint];
  266. }
  267. void RasterizerFlash::material_set_shade_model(RID p_material, VS::MaterialShadeModel p_model) {
  268. Material *material = material_owner.get(p_material);
  269. ERR_FAIL_COND(!material);
  270. material->shade_model=p_model;
  271. };
  272. VS::MaterialShadeModel RasterizerFlash::material_get_shade_model(RID p_material) const {
  273. Material *material = material_owner.get(p_material);
  274. ERR_FAIL_COND_V(!material,VS::MATERIAL_SHADE_MODEL_LAMBERT);
  275. return material->shade_model;
  276. };
  277. void RasterizerFlash::material_set_blend_mode(RID p_material,VS::MaterialBlendMode p_mode) {
  278. Material *material = material_owner.get(p_material);
  279. ERR_FAIL_COND(!material);
  280. material->blend_mode=p_mode;
  281. }
  282. VS::MaterialBlendMode RasterizerFlash::material_get_blend_mode(RID p_material) const {
  283. Material *material = material_owner.get(p_material);
  284. ERR_FAIL_COND_V(!material,VS::MATERIAL_BLEND_MODE_ADD);
  285. return material->blend_mode;
  286. }
  287. void RasterizerFlash::material_set_line_width(RID p_material,float p_line_width) {
  288. Material *material = material_owner.get(p_material);
  289. ERR_FAIL_COND(!material);
  290. material->line_width=p_line_width;
  291. }
  292. float RasterizerFlash::material_get_line_width(RID p_material) const {
  293. Material *material = material_owner.get(p_material);
  294. ERR_FAIL_COND_V(!material,0);
  295. return material->line_width;
  296. }
  297. /* MESH API */
  298. RID RasterizerFlash::mesh_create() {
  299. return mesh_owner.make_rid( memnew( Mesh ) );
  300. }
  301. void RasterizerFlash::mesh_add_surface(RID p_mesh,VS::PrimitiveType p_primitive,const Array& p_arrays,const Array& p_blend_shapes) {
  302. }
  303. Error RasterizerFlash::_surface_set_arrays(Surface *p_surface, uint8_t *p_mem,uint8_t *p_index_mem,const Array& p_arrays,bool p_main) {
  304. return FAILED;
  305. }
  306. void RasterizerFlash::mesh_add_custom_surface(RID p_mesh,const Variant& p_dat) {
  307. ERR_EXPLAIN("OpenGL Rasterizer does not support custom surfaces. Running on wrong platform?");
  308. ERR_FAIL_V();
  309. }
  310. Array RasterizerFlash::mesh_get_surface_arrays(RID p_mesh,int p_surface) const {
  311. Mesh *mesh = mesh_owner.get( p_mesh );
  312. ERR_FAIL_COND_V(!mesh,Array());
  313. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array() );
  314. Surface *surface = mesh->surfaces[p_surface];
  315. ERR_FAIL_COND_V( !surface, Array() );
  316. return surface->data;
  317. }
  318. Array RasterizerFlash::mesh_get_surface_morph_arrays(RID p_mesh,int p_surface) const{
  319. Mesh *mesh = mesh_owner.get( p_mesh );
  320. ERR_FAIL_COND_V(!mesh,Array());
  321. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), Array() );
  322. Surface *surface = mesh->surfaces[p_surface];
  323. ERR_FAIL_COND_V( !surface, Array() );
  324. return surface->morph_data;
  325. }
  326. void RasterizerFlash::mesh_set_morph_target_count(RID p_mesh,int p_amount) {
  327. Mesh *mesh = mesh_owner.get( p_mesh );
  328. ERR_FAIL_COND(!mesh);
  329. ERR_FAIL_COND( mesh->surfaces.size()!=0 );
  330. mesh->morph_target_count=p_amount;
  331. }
  332. int RasterizerFlash::mesh_get_morph_target_count(RID p_mesh) const{
  333. Mesh *mesh = mesh_owner.get( p_mesh );
  334. ERR_FAIL_COND_V(!mesh,-1);
  335. return mesh->morph_target_count;
  336. }
  337. void RasterizerFlash::mesh_set_morph_target_mode(RID p_mesh,VS::MorphTargetMode p_mode) {
  338. ERR_FAIL_INDEX(p_mode,2);
  339. Mesh *mesh = mesh_owner.get( p_mesh );
  340. ERR_FAIL_COND(!mesh);
  341. mesh->morph_target_mode=p_mode;
  342. }
  343. VS::MorphTargetMode RasterizerFlash::mesh_get_morph_target_mode(RID p_mesh) const {
  344. Mesh *mesh = mesh_owner.get( p_mesh );
  345. ERR_FAIL_COND_V(!mesh,VS::MORPH_MODE_NORMALIZED);
  346. return mesh->morph_target_mode;
  347. }
  348. void RasterizerFlash::mesh_surface_set_material(RID p_mesh, int p_surface, RID p_material,bool p_owned) {
  349. Mesh *mesh = mesh_owner.get( p_mesh );
  350. ERR_FAIL_COND(!mesh);
  351. ERR_FAIL_INDEX(p_surface, mesh->surfaces.size() );
  352. Surface *surface = mesh->surfaces[p_surface];
  353. ERR_FAIL_COND( !surface);
  354. if (surface->material_owned && surface->material.is_valid())
  355. free(surface->material);
  356. surface->material_owned=p_owned;
  357. surface->material=p_material;
  358. }
  359. RID RasterizerFlash::mesh_surface_get_material(RID p_mesh, int p_surface) const {
  360. Mesh *mesh = mesh_owner.get( p_mesh );
  361. ERR_FAIL_COND_V(!mesh,RID());
  362. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), RID() );
  363. Surface *surface = mesh->surfaces[p_surface];
  364. ERR_FAIL_COND_V( !surface, RID() );
  365. return surface->material;
  366. }
  367. int RasterizerFlash::mesh_surface_get_array_len(RID p_mesh, int p_surface) const {
  368. Mesh *mesh = mesh_owner.get( p_mesh );
  369. ERR_FAIL_COND_V(!mesh,-1);
  370. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 );
  371. Surface *surface = mesh->surfaces[p_surface];
  372. ERR_FAIL_COND_V( !surface, -1 );
  373. return surface->array_len;
  374. }
  375. int RasterizerFlash::mesh_surface_get_array_index_len(RID p_mesh, int p_surface) const {
  376. Mesh *mesh = mesh_owner.get( p_mesh );
  377. ERR_FAIL_COND_V(!mesh,-1);
  378. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), -1 );
  379. Surface *surface = mesh->surfaces[p_surface];
  380. ERR_FAIL_COND_V( !surface, -1 );
  381. return surface->index_array_len;
  382. }
  383. uint32_t RasterizerFlash::mesh_surface_get_format(RID p_mesh, int p_surface) const {
  384. Mesh *mesh = mesh_owner.get( p_mesh );
  385. ERR_FAIL_COND_V(!mesh,0);
  386. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), 0 );
  387. Surface *surface = mesh->surfaces[p_surface];
  388. ERR_FAIL_COND_V( !surface, 0 );
  389. return surface->format;
  390. }
  391. VS::PrimitiveType RasterizerFlash::mesh_surface_get_primitive_type(RID p_mesh, int p_surface) const {
  392. Mesh *mesh = mesh_owner.get( p_mesh );
  393. ERR_FAIL_COND_V(!mesh,VS::PRIMITIVE_POINTS);
  394. ERR_FAIL_INDEX_V(p_surface, mesh->surfaces.size(), VS::PRIMITIVE_POINTS );
  395. Surface *surface = mesh->surfaces[p_surface];
  396. ERR_FAIL_COND_V( !surface, VS::PRIMITIVE_POINTS );
  397. return surface->primitive;
  398. }
  399. void RasterizerFlash::mesh_remove_surface(RID p_mesh,int p_index) {
  400. Mesh *mesh = mesh_owner.get( p_mesh );
  401. ERR_FAIL_COND(!mesh);
  402. ERR_FAIL_INDEX(p_index, mesh->surfaces.size() );
  403. Surface *surface = mesh->surfaces[p_index];
  404. ERR_FAIL_COND( !surface);
  405. if (mesh->morph_target_count) {
  406. for(int i=0;i<mesh->morph_target_count;i++)
  407. memfree(surface->morph_targets_local[i].array);
  408. memfree( surface->morph_targets_local );
  409. }
  410. memdelete( mesh->surfaces[p_index] );
  411. mesh->surfaces.remove(p_index);
  412. }
  413. int RasterizerFlash::mesh_get_surface_count(RID p_mesh) const {
  414. Mesh *mesh = mesh_owner.get( p_mesh );
  415. ERR_FAIL_COND_V(!mesh,-1);
  416. return mesh->surfaces.size();
  417. }
  418. AABB RasterizerFlash::mesh_get_aabb(RID p_mesh) const {
  419. Mesh *mesh = mesh_owner.get( p_mesh );
  420. ERR_FAIL_COND_V(!mesh,AABB());
  421. AABB aabb;
  422. for (int i=0;i<mesh->surfaces.size();i++) {
  423. if (i==0)
  424. aabb=mesh->surfaces[i]->aabb;
  425. else
  426. aabb.merge_with(mesh->surfaces[i]->aabb);
  427. }
  428. return aabb;
  429. }
  430. /* MULTIMESH API */
  431. RID RasterizerFlash::multimesh_create() {
  432. return multimesh_owner.make_rid( memnew( MultiMesh ));
  433. }
  434. void RasterizerFlash::multimesh_set_instance_count(RID p_multimesh,int p_count) {
  435. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  436. ERR_FAIL_COND(!multimesh);
  437. multimesh->elements.clear(); // make sure to delete everything, so it "fails" in all implementations
  438. multimesh->elements.resize(p_count);
  439. }
  440. int RasterizerFlash::multimesh_get_instance_count(RID p_multimesh) const {
  441. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  442. ERR_FAIL_COND_V(!multimesh,-1);
  443. return multimesh->elements.size();
  444. }
  445. void RasterizerFlash::multimesh_set_mesh(RID p_multimesh,RID p_mesh) {
  446. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  447. ERR_FAIL_COND(!multimesh);
  448. multimesh->mesh=p_mesh;
  449. }
  450. void RasterizerFlash::multimesh_set_aabb(RID p_multimesh,const AABB& p_aabb) {
  451. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  452. ERR_FAIL_COND(!multimesh);
  453. multimesh->aabb=p_aabb;
  454. }
  455. void RasterizerFlash::multimesh_instance_set_transform(RID p_multimesh,int p_index,const Transform& p_transform) {
  456. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  457. ERR_FAIL_COND(!multimesh);
  458. ERR_FAIL_INDEX(p_index,multimesh->elements.size());
  459. MultiMesh::Element &e=multimesh->elements[p_index];
  460. e.matrix[0]=p_transform.basis.elements[0][0];
  461. e.matrix[1]=p_transform.basis.elements[1][0];
  462. e.matrix[2]=p_transform.basis.elements[2][0];
  463. e.matrix[3]=0;
  464. e.matrix[4]=p_transform.basis.elements[0][1];
  465. e.matrix[5]=p_transform.basis.elements[1][1];
  466. e.matrix[6]=p_transform.basis.elements[2][1];
  467. e.matrix[7]=0;
  468. e.matrix[8]=p_transform.basis.elements[0][2];
  469. e.matrix[9]=p_transform.basis.elements[1][2];
  470. e.matrix[10]=p_transform.basis.elements[2][2];
  471. e.matrix[11]=0;
  472. e.matrix[12]=p_transform.origin.x;
  473. e.matrix[13]=p_transform.origin.y;
  474. e.matrix[14]=p_transform.origin.z;
  475. e.matrix[15]=1;
  476. }
  477. void RasterizerFlash::multimesh_instance_set_color(RID p_multimesh,int p_index,const Color& p_color) {
  478. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  479. ERR_FAIL_COND(!multimesh)
  480. ERR_FAIL_INDEX(p_index,multimesh->elements.size());
  481. MultiMesh::Element &e=multimesh->elements[p_index];
  482. e.color[0]=CLAMP(p_color.r*255,0,255);
  483. e.color[1]=CLAMP(p_color.g*255,0,255);
  484. e.color[2]=CLAMP(p_color.b*255,0,255);
  485. e.color[3]=CLAMP(p_color.a*255,0,255);
  486. }
  487. RID RasterizerFlash::multimesh_get_mesh(RID p_multimesh) const {
  488. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  489. ERR_FAIL_COND_V(!multimesh,RID());
  490. return multimesh->mesh;
  491. }
  492. AABB RasterizerFlash::multimesh_get_aabb(RID p_multimesh) const {
  493. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  494. ERR_FAIL_COND_V(!multimesh,AABB());
  495. return multimesh->aabb;
  496. }
  497. Transform RasterizerFlash::multimesh_instance_get_transform(RID p_multimesh,int p_index) const {
  498. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  499. ERR_FAIL_COND_V(!multimesh,Transform());
  500. ERR_FAIL_INDEX_V(p_index,multimesh->elements.size(),Transform());
  501. MultiMesh::Element &e=multimesh->elements[p_index];
  502. Transform tr;
  503. tr.basis.elements[0][0]=e.matrix[0];
  504. tr.basis.elements[1][0]=e.matrix[1];
  505. tr.basis.elements[2][0]=e.matrix[2];
  506. tr.basis.elements[0][1]=e.matrix[4];
  507. tr.basis.elements[1][1]=e.matrix[5];
  508. tr.basis.elements[2][1]=e.matrix[6];
  509. tr.basis.elements[0][2]=e.matrix[8];
  510. tr.basis.elements[1][2]=e.matrix[9];
  511. tr.basis.elements[2][2]=e.matrix[10];
  512. tr.origin.x=e.matrix[12];
  513. tr.origin.y=e.matrix[13];
  514. tr.origin.z=e.matrix[14];
  515. return tr;
  516. }
  517. Color RasterizerFlash::multimesh_instance_get_color(RID p_multimesh,int p_index) const {
  518. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  519. ERR_FAIL_COND_V(!multimesh,Color());
  520. ERR_FAIL_INDEX_V(p_index,multimesh->elements.size(),Color());
  521. MultiMesh::Element &e=multimesh->elements[p_index];
  522. Color c;
  523. c.r=e.color[0]/255.0;
  524. c.g=e.color[1]/255.0;
  525. c.b=e.color[2]/255.0;
  526. c.a=e.color[3]/255.0;
  527. return c;
  528. }
  529. void RasterizerFlash::multimesh_set_visible_instances(RID p_multimesh,int p_visible) {
  530. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  531. ERR_FAIL_COND(!multimesh);
  532. multimesh->visible=p_visible;
  533. }
  534. int RasterizerFlash::multimesh_get_visible_instances(RID p_multimesh) const {
  535. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  536. ERR_FAIL_COND_V(!multimesh,-1);
  537. return multimesh->visible;
  538. }
  539. /* PARTICLES API */
  540. RID RasterizerFlash::particles_create() {
  541. Particles *particles = memnew( Particles );
  542. ERR_FAIL_COND_V(!particles,RID());
  543. return particles_owner.make_rid(particles);
  544. }
  545. void RasterizerFlash::particles_set_amount(RID p_particles, int p_amount) {
  546. ERR_FAIL_COND(p_amount<1);
  547. Particles* particles = particles_owner.get( p_particles );
  548. ERR_FAIL_COND(!particles);
  549. particles->data.amount=p_amount;
  550. }
  551. int RasterizerFlash::particles_get_amount(RID p_particles) const {
  552. Particles* particles = particles_owner.get( p_particles );
  553. ERR_FAIL_COND_V(!particles,-1);
  554. return particles->data.amount;
  555. }
  556. void RasterizerFlash::particles_set_emitting(RID p_particles, bool p_emitting) {
  557. Particles* particles = particles_owner.get( p_particles );
  558. ERR_FAIL_COND(!particles);
  559. particles->data.emitting=p_emitting;;
  560. }
  561. bool RasterizerFlash::particles_is_emitting(RID p_particles) const {
  562. const Particles* particles = particles_owner.get( p_particles );
  563. ERR_FAIL_COND_V(!particles,false);
  564. return particles->data.emitting;
  565. }
  566. void RasterizerFlash::particles_set_visibility_aabb(RID p_particles, const AABB& p_visibility) {
  567. Particles* particles = particles_owner.get( p_particles );
  568. ERR_FAIL_COND(!particles);
  569. particles->data.visibility_aabb=p_visibility;
  570. }
  571. void RasterizerFlash::particles_set_emission_half_extents(RID p_particles, const Vector3& p_half_extents) {
  572. Particles* particles = particles_owner.get( p_particles );
  573. ERR_FAIL_COND(!particles);
  574. particles->data.emission_half_extents=p_half_extents;
  575. }
  576. Vector3 RasterizerFlash::particles_get_emission_half_extents(RID p_particles) const {
  577. Particles* particles = particles_owner.get( p_particles );
  578. ERR_FAIL_COND_V(!particles,Vector3());
  579. return particles->data.emission_half_extents;
  580. }
  581. void RasterizerFlash::particles_set_emission_base_velocity(RID p_particles, const Vector3& p_base_velocity) {
  582. Particles* particles = particles_owner.get( p_particles );
  583. ERR_FAIL_COND(!particles);
  584. particles->data.emission_base_velocity=p_base_velocity;
  585. }
  586. Vector3 RasterizerFlash::particles_get_emission_base_velocity(RID p_particles) const {
  587. Particles* particles = particles_owner.get( p_particles );
  588. ERR_FAIL_COND_V(!particles,Vector3());
  589. return particles->data.emission_base_velocity;
  590. }
  591. void RasterizerFlash::particles_set_emission_points(RID p_particles, const DVector<Vector3>& p_points) {
  592. Particles* particles = particles_owner.get( p_particles );
  593. ERR_FAIL_COND(!particles);
  594. particles->data.emission_points=p_points;
  595. }
  596. DVector<Vector3> RasterizerFlash::particles_get_emission_points(RID p_particles) const {
  597. Particles* particles = particles_owner.get( p_particles );
  598. ERR_FAIL_COND_V(!particles,DVector<Vector3>());
  599. return particles->data.emission_points;
  600. }
  601. void RasterizerFlash::particles_set_gravity_normal(RID p_particles, const Vector3& p_normal) {
  602. Particles* particles = particles_owner.get( p_particles );
  603. ERR_FAIL_COND(!particles);
  604. particles->data.gravity_normal=p_normal;
  605. }
  606. Vector3 RasterizerFlash::particles_get_gravity_normal(RID p_particles) const {
  607. Particles* particles = particles_owner.get( p_particles );
  608. ERR_FAIL_COND_V(!particles,Vector3());
  609. return particles->data.gravity_normal;
  610. }
  611. AABB RasterizerFlash::particles_get_visibility_aabb(RID p_particles) const {
  612. const Particles* particles = particles_owner.get( p_particles );
  613. ERR_FAIL_COND_V(!particles,AABB());
  614. return particles->data.visibility_aabb;
  615. }
  616. void RasterizerFlash::particles_set_variable(RID p_particles, VS::ParticleVariable p_variable,float p_value) {
  617. ERR_FAIL_INDEX(p_variable,VS::PARTICLE_VAR_MAX);
  618. Particles* particles = particles_owner.get( p_particles );
  619. ERR_FAIL_COND(!particles);
  620. particles->data.particle_vars[p_variable]=p_value;
  621. }
  622. float RasterizerFlash::particles_get_variable(RID p_particles, VS::ParticleVariable p_variable) const {
  623. const Particles* particles = particles_owner.get( p_particles );
  624. ERR_FAIL_COND_V(!particles,-1);
  625. return particles->data.particle_vars[p_variable];
  626. }
  627. void RasterizerFlash::particles_set_randomness(RID p_particles, VS::ParticleVariable p_variable,float p_randomness) {
  628. Particles* particles = particles_owner.get( p_particles );
  629. ERR_FAIL_COND(!particles);
  630. particles->data.particle_randomness[p_variable]=p_randomness;
  631. }
  632. float RasterizerFlash::particles_get_randomness(RID p_particles, VS::ParticleVariable p_variable) const {
  633. const Particles* particles = particles_owner.get( p_particles );
  634. ERR_FAIL_COND_V(!particles,-1);
  635. return particles->data.particle_randomness[p_variable];
  636. }
  637. void RasterizerFlash::particles_set_color_phases(RID p_particles, int p_phases) {
  638. Particles* particles = particles_owner.get( p_particles );
  639. ERR_FAIL_COND(!particles);
  640. ERR_FAIL_COND( p_phases<0 || p_phases>VS::MAX_PARTICLE_COLOR_PHASES );
  641. particles->data.color_phase_count=p_phases;
  642. }
  643. int RasterizerFlash::particles_get_color_phases(RID p_particles) const {
  644. Particles* particles = particles_owner.get( p_particles );
  645. ERR_FAIL_COND_V(!particles,-1);
  646. return particles->data.color_phase_count;
  647. }
  648. void RasterizerFlash::particles_set_color_phase_pos(RID p_particles, int p_phase, float p_pos) {
  649. ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
  650. if (p_pos<0.0)
  651. p_pos=0.0;
  652. if (p_pos>1.0)
  653. p_pos=1.0;
  654. Particles* particles = particles_owner.get( p_particles );
  655. ERR_FAIL_COND(!particles);
  656. particles->data.color_phases[p_phase].pos=p_pos;
  657. }
  658. float RasterizerFlash::particles_get_color_phase_pos(RID p_particles, int p_phase) const {
  659. ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, -1.0);
  660. const Particles* particles = particles_owner.get( p_particles );
  661. ERR_FAIL_COND_V(!particles,-1);
  662. return particles->data.color_phases[p_phase].pos;
  663. }
  664. void RasterizerFlash::particles_set_color_phase_color(RID p_particles, int p_phase, const Color& p_color) {
  665. ERR_FAIL_INDEX(p_phase, VS::MAX_PARTICLE_COLOR_PHASES);
  666. Particles* particles = particles_owner.get( p_particles );
  667. ERR_FAIL_COND(!particles);
  668. particles->data.color_phases[p_phase].color=p_color;
  669. //update alpha
  670. particles->has_alpha=false;
  671. for(int i=0;i<VS::MAX_PARTICLE_COLOR_PHASES;i++) {
  672. if (particles->data.color_phases[i].color.a<0.99)
  673. particles->has_alpha=true;
  674. }
  675. }
  676. Color RasterizerFlash::particles_get_color_phase_color(RID p_particles, int p_phase) const {
  677. ERR_FAIL_INDEX_V(p_phase, VS::MAX_PARTICLE_COLOR_PHASES, Color());
  678. const Particles* particles = particles_owner.get( p_particles );
  679. ERR_FAIL_COND_V(!particles,Color());
  680. return particles->data.color_phases[p_phase].color;
  681. }
  682. void RasterizerFlash::particles_set_attractors(RID p_particles, int p_attractors) {
  683. Particles* particles = particles_owner.get( p_particles );
  684. ERR_FAIL_COND(!particles);
  685. ERR_FAIL_COND( p_attractors<0 || p_attractors>VisualServer::MAX_PARTICLE_ATTRACTORS );
  686. particles->data.attractor_count=p_attractors;
  687. }
  688. int RasterizerFlash::particles_get_attractors(RID p_particles) const {
  689. Particles* particles = particles_owner.get( p_particles );
  690. ERR_FAIL_COND_V(!particles,-1);
  691. return particles->data.attractor_count;
  692. }
  693. void RasterizerFlash::particles_set_attractor_pos(RID p_particles, int p_attractor, const Vector3& p_pos) {
  694. Particles* particles = particles_owner.get( p_particles );
  695. ERR_FAIL_COND(!particles);
  696. ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count);
  697. particles->data.attractors[p_attractor].pos=p_pos;;
  698. }
  699. Vector3 RasterizerFlash::particles_get_attractor_pos(RID p_particles,int p_attractor) const {
  700. Particles* particles = particles_owner.get( p_particles );
  701. ERR_FAIL_COND_V(!particles,Vector3());
  702. ERR_FAIL_INDEX_V(p_attractor,particles->data.attractor_count,Vector3());
  703. return particles->data.attractors[p_attractor].pos;
  704. }
  705. void RasterizerFlash::particles_set_attractor_strength(RID p_particles, int p_attractor, float p_force) {
  706. Particles* particles = particles_owner.get( p_particles );
  707. ERR_FAIL_COND(!particles);
  708. ERR_FAIL_INDEX(p_attractor,particles->data.attractor_count);
  709. particles->data.attractors[p_attractor].force=p_force;
  710. }
  711. float RasterizerFlash::particles_get_attractor_strength(RID p_particles,int p_attractor) const {
  712. Particles* particles = particles_owner.get( p_particles );
  713. ERR_FAIL_COND_V(!particles,0);
  714. ERR_FAIL_INDEX_V(p_attractor,particles->data.attractor_count,0);
  715. return particles->data.attractors[p_attractor].force;
  716. }
  717. void RasterizerFlash::particles_set_material(RID p_particles, RID p_material,bool p_owned) {
  718. Particles* particles = particles_owner.get( p_particles );
  719. ERR_FAIL_COND(!particles);
  720. if (particles->material_owned && particles->material.is_valid())
  721. free(particles->material);
  722. particles->material_owned=p_owned;
  723. particles->material=p_material;
  724. }
  725. RID RasterizerFlash::particles_get_material(RID p_particles) const {
  726. const Particles* particles = particles_owner.get( p_particles );
  727. ERR_FAIL_COND_V(!particles,RID());
  728. return particles->material;
  729. }
  730. void RasterizerFlash::particles_set_use_local_coordinates(RID p_particles, bool p_enable) {
  731. Particles* particles = particles_owner.get( p_particles );
  732. ERR_FAIL_COND(!particles);
  733. particles->data.local_coordinates=p_enable;
  734. }
  735. bool RasterizerFlash::particles_is_using_local_coordinates(RID p_particles) const {
  736. const Particles* particles = particles_owner.get( p_particles );
  737. ERR_FAIL_COND_V(!particles,false);
  738. return particles->data.local_coordinates;
  739. }
  740. bool RasterizerFlash::particles_has_height_from_velocity(RID p_particles) const {
  741. const Particles* particles = particles_owner.get( p_particles );
  742. ERR_FAIL_COND_V(!particles,false);
  743. return particles->data.height_from_velocity;
  744. }
  745. void RasterizerFlash::particles_set_height_from_velocity(RID p_particles, bool p_enable) {
  746. Particles* particles = particles_owner.get( p_particles );
  747. ERR_FAIL_COND(!particles);
  748. particles->data.height_from_velocity=p_enable;
  749. }
  750. AABB RasterizerFlash::particles_get_aabb(RID p_particles) const {
  751. const Particles* particles = particles_owner.get( p_particles );
  752. ERR_FAIL_COND_V(!particles,AABB());
  753. return particles->data.visibility_aabb;
  754. }
  755. /* SKELETON API */
  756. RID RasterizerFlash::skeleton_create() {
  757. Skeleton *skeleton = memnew( Skeleton );
  758. ERR_FAIL_COND_V(!skeleton,RID());
  759. return skeleton_owner.make_rid( skeleton );
  760. }
  761. void RasterizerFlash::skeleton_resize(RID p_skeleton,int p_bones) {
  762. Skeleton *skeleton = skeleton_owner.get( p_skeleton );
  763. ERR_FAIL_COND(!skeleton);
  764. if (p_bones == skeleton->bones.size()) {
  765. return;
  766. };
  767. skeleton->bones.resize(p_bones);
  768. }
  769. int RasterizerFlash::skeleton_get_bone_count(RID p_skeleton) const {
  770. Skeleton *skeleton = skeleton_owner.get( p_skeleton );
  771. ERR_FAIL_COND_V(!skeleton, -1);
  772. return skeleton->bones.size();
  773. }
  774. void RasterizerFlash::skeleton_bone_set_transform(RID p_skeleton,int p_bone, const Transform& p_transform) {
  775. Skeleton *skeleton = skeleton_owner.get( p_skeleton );
  776. ERR_FAIL_COND(!skeleton);
  777. ERR_FAIL_INDEX( p_bone, skeleton->bones.size() );
  778. skeleton->bones[p_bone] = p_transform;
  779. }
  780. Transform RasterizerFlash::skeleton_bone_get_transform(RID p_skeleton,int p_bone) {
  781. Skeleton *skeleton = skeleton_owner.get( p_skeleton );
  782. ERR_FAIL_COND_V(!skeleton, Transform());
  783. ERR_FAIL_INDEX_V( p_bone, skeleton->bones.size(), Transform() );
  784. // something
  785. return skeleton->bones[p_bone];
  786. }
  787. /* LIGHT API */
  788. RID RasterizerFlash::light_create(VS::LightType p_type) {
  789. Light *light = memnew( Light );
  790. light->type=p_type;
  791. return light_owner.make_rid(light);
  792. }
  793. VS::LightType RasterizerFlash::light_get_type(RID p_light) const {
  794. Light *light = light_owner.get(p_light);
  795. ERR_FAIL_COND_V(!light,VS::LIGHT_OMNI);
  796. return light->type;
  797. }
  798. void RasterizerFlash::light_set_color(RID p_light,VS::LightColor p_type, const Color& p_color) {
  799. Light *light = light_owner.get(p_light);
  800. ERR_FAIL_COND(!light);
  801. ERR_FAIL_INDEX( p_type, 3 );
  802. light->colors[p_type]=p_color;
  803. }
  804. Color RasterizerFlash::light_get_color(RID p_light,VS::LightColor p_type) const {
  805. Light *light = light_owner.get(p_light);
  806. ERR_FAIL_COND_V(!light, Color());
  807. ERR_FAIL_INDEX_V( p_type, 3, Color() );
  808. return light->colors[p_type];
  809. }
  810. void RasterizerFlash::light_set_shadow(RID p_light,bool p_enabled) {
  811. Light *light = light_owner.get(p_light);
  812. ERR_FAIL_COND(!light);
  813. light->shadow_enabled=p_enabled;
  814. }
  815. bool RasterizerFlash::light_has_shadow(RID p_light) const {
  816. Light *light = light_owner.get(p_light);
  817. ERR_FAIL_COND_V(!light,false);
  818. return light->shadow_enabled;
  819. }
  820. void RasterizerFlash::light_set_volumetric(RID p_light,bool p_enabled) {
  821. Light *light = light_owner.get(p_light);
  822. ERR_FAIL_COND(!light);
  823. light->volumetric_enabled=p_enabled;
  824. }
  825. bool RasterizerFlash::light_is_volumetric(RID p_light) const {
  826. Light *light = light_owner.get(p_light);
  827. ERR_FAIL_COND_V(!light,false);
  828. return light->volumetric_enabled;
  829. }
  830. void RasterizerFlash::light_set_projector(RID p_light,RID p_texture) {
  831. Light *light = light_owner.get(p_light);
  832. ERR_FAIL_COND(!light);
  833. light->projector=p_texture;
  834. }
  835. RID RasterizerFlash::light_get_projector(RID p_light) const {
  836. Light *light = light_owner.get(p_light);
  837. ERR_FAIL_COND_V(!light,RID());
  838. return light->projector;
  839. }
  840. void RasterizerFlash::light_set_var(RID p_light, VS::LightParam p_var, float p_value) {
  841. Light * light = light_owner.get( p_light );
  842. ERR_FAIL_COND(!light);
  843. ERR_FAIL_INDEX( p_var, VS::LIGHT_PARAM_MAX );
  844. light->vars[p_var]=p_value;
  845. }
  846. float RasterizerFlash::light_get_var(RID p_light, VS::LightParam p_var) const {
  847. Light * light = light_owner.get( p_light );
  848. ERR_FAIL_COND_V(!light,0);
  849. ERR_FAIL_INDEX_V( p_var, VS::LIGHT_PARAM_MAX,0 );
  850. return light->vars[p_var];
  851. }
  852. void RasterizerFlash::light_set_operator(RID p_light,VS::LightOp p_op) {
  853. };
  854. VS::LightOp RasterizerFlash::light_get_operator(RID p_light) const {
  855. return VS::LightOp();
  856. };
  857. void RasterizerFlash::light_omni_set_shadow_mode(RID p_light,VS::LightOmniShadowMode p_mode) {
  858. };
  859. VS::LightOmniShadowMode RasterizerFlash::light_omni_get_shadow_mode(RID p_light) const {
  860. return VS::LIGHT_OMNI_SHADOW_DEFAULT;
  861. };
  862. void RasterizerFlash::light_directional_set_shadow_mode(RID p_light,VS::LightDirectionalShadowMode p_mode) {
  863. };
  864. VS::LightDirectionalShadowMode RasterizerFlash::light_directional_get_shadow_mode(RID p_light) const {
  865. return VS::LIGHT_DIRECTIONAL_SHADOW_ORTHOGONAL;
  866. };
  867. void RasterizerFlash::light_directional_set_shadow_max_distance(RID p_light,float p_distance) {
  868. };
  869. float RasterizerFlash::light_directional_get_shadow_max_distance(RID p_light) const {
  870. return 0;
  871. };
  872. void RasterizerFlash::light_directional_set_pssm_split_weight(RID p_light,float p_weight) {
  873. };
  874. float RasterizerFlash::light_directional_get_pssm_split_weight(RID p_light) const {
  875. return 0;
  876. };
  877. void RasterizerFlash::light_directional_set_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param, float p_value) {
  878. };
  879. float RasterizerFlash::light_directional_get_shadow_param(RID p_light,VS::LightDirectionalShadowParam p_param) const {
  880. return 0;
  881. };
  882. AABB RasterizerFlash::light_get_aabb(RID p_light) const {
  883. Light *light = light_owner.get( p_light );
  884. ERR_FAIL_COND_V(!light,AABB());
  885. switch( light->type ) {
  886. case VS::LIGHT_SPOT: {
  887. float len=light->vars[VS::LIGHT_PARAM_RADIUS];
  888. float size=Math::tan(Math::deg2rad(light->vars[VS::LIGHT_PARAM_SPOT_ANGLE]))*len;
  889. return AABB( Vector3( -size,-size,-len ), Vector3( size*2, size*2, len ) );
  890. } break;
  891. case VS::LIGHT_OMNI: {
  892. float r = light->vars[VS::LIGHT_PARAM_RADIUS];
  893. return AABB( -Vector3(r,r,r), Vector3(r,r,r)*2 );
  894. } break;
  895. case VS::LIGHT_DIRECTIONAL: {
  896. return AABB();
  897. } break;
  898. default: {}
  899. }
  900. ERR_FAIL_V( AABB() );
  901. }
  902. RID RasterizerFlash::light_instance_create(RID p_light) {
  903. Light *light = light_owner.get( p_light );
  904. ERR_FAIL_COND_V(!light, RID());
  905. LightInstance *light_instance = memnew( LightInstance );
  906. light_instance->light=p_light;
  907. light_instance->base=light;
  908. light_instance->last_pass=0;
  909. return light_instance_owner.make_rid( light_instance );
  910. }
  911. void RasterizerFlash::light_instance_set_transform(RID p_light_instance,const Transform& p_transform) {
  912. LightInstance *lighti = light_instance_owner.get( p_light_instance );
  913. ERR_FAIL_COND(!lighti);
  914. lighti->transform=p_transform;
  915. }
  916. void RasterizerFlash::light_instance_set_active_hint(RID p_light_instance) {
  917. LightInstance *lighti = light_instance_owner.get( p_light_instance );
  918. ERR_FAIL_COND(!lighti);
  919. if (lighti->base->type==VS::LIGHT_DIRECTIONAL)
  920. lighti->shadow_pass=scene_pass;
  921. else
  922. lighti->shadow_pass=frame;
  923. }
  924. bool RasterizerFlash::light_instance_has_shadow(RID p_light_instance) const {
  925. LightInstance *lighti = light_instance_owner.get( p_light_instance );
  926. ERR_FAIL_COND_V(!lighti, false);
  927. if (!lighti->base->shadow_enabled)
  928. return false;
  929. if (lighti->base->type==VS::LIGHT_DIRECTIONAL) {
  930. if (lighti->shadow_pass!=scene_pass)
  931. return false;
  932. } else {
  933. if (lighti->shadow_pass!=frame)
  934. return false;
  935. }
  936. return !lighti->shadow_buffers.empty();
  937. }
  938. bool RasterizerFlash::light_instance_assign_shadow(RID p_light_instance) {
  939. return false;
  940. }
  941. Rasterizer::ShadowType RasterizerFlash::light_instance_get_shadow_type(RID p_light_instance) const {
  942. LightInstance *lighti = light_instance_owner.get( p_light_instance );
  943. ERR_FAIL_COND_V(!lighti,Rasterizer::SHADOW_NONE);
  944. switch(lighti->base->type) {
  945. case VS::LIGHT_DIRECTIONAL: return SHADOW_PSM; break;
  946. case VS::LIGHT_OMNI: return SHADOW_DUAL_PARABOLOID; break;
  947. case VS::LIGHT_SPOT: return SHADOW_SIMPLE; break;
  948. }
  949. return Rasterizer::SHADOW_NONE;
  950. }
  951. int RasterizerFlash::light_instance_get_shadow_passes(RID p_light_instance) const {
  952. LightInstance *lighti = light_instance_owner.get( p_light_instance );
  953. ERR_FAIL_COND_V(!lighti,0);
  954. if (lighti->base->type==VS::LIGHT_OMNI)
  955. return 2; // dp
  956. else
  957. return 1;
  958. }
  959. void RasterizerFlash::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) {
  960. LightInstance *lighti = light_instance_owner.get( p_light_instance );
  961. ERR_FAIL_COND(!lighti);
  962. ERR_FAIL_COND(lighti->base->type!=VS::LIGHT_DIRECTIONAL);
  963. ERR_FAIL_INDEX(p_index,1);
  964. lighti->custom_projection=p_camera;
  965. lighti->custom_transform=p_transform;
  966. }
  967. /* PARTICLES INSTANCE */
  968. RID RasterizerFlash::particles_instance_create(RID p_particles) {
  969. ERR_FAIL_COND_V(!particles_owner.owns(p_particles),RID());
  970. ParticlesInstance *particles_instance = memnew( ParticlesInstance );
  971. ERR_FAIL_COND_V(!particles_instance, RID() );
  972. particles_instance->particles=p_particles;
  973. return particles_instance_owner.make_rid(particles_instance);
  974. }
  975. void RasterizerFlash::particles_instance_set_transform(RID p_particles_instance,const Transform& p_transform) {
  976. ParticlesInstance *particles_instance=particles_instance_owner.get(p_particles_instance);
  977. ERR_FAIL_COND(!particles_instance);
  978. particles_instance->transform=p_transform;
  979. }
  980. /* RENDER API */
  981. /* all calls (inside begin/end shadow) are always warranted to be in the following order: */
  982. void RasterizerFlash::begin_frame() {
  983. }
  984. void RasterizerFlash::clear_viewport(const Color& p_color) {
  985. };
  986. void RasterizerFlash::set_viewport(const VS::ViewportRect& p_viewport) {
  987. viewport=p_viewport;
  988. }
  989. void RasterizerFlash::begin_scene(bool p_copy_bg, RID p_fx,VS::ScenarioDebugMode p_debug) {
  990. };
  991. void RasterizerFlash::begin_shadow_map( RID p_light_instance, int p_shadow_pass ) {
  992. }
  993. void RasterizerFlash::set_camera(const Transform& p_world,const CameraMatrix& p_projection) {
  994. camera_transform=p_world;
  995. camera_transform_inverse=camera_transform.inverse();
  996. camera_projection=p_projection;
  997. camera_plane = Plane( camera_transform.origin, camera_transform.basis.get_axis(2) );
  998. camera_z_near=camera_projection.get_z_near();
  999. camera_z_far=camera_projection.get_z_far();
  1000. camera_projection.get_viewport_size(camera_vp_size.x,camera_vp_size.y);
  1001. }
  1002. void RasterizerFlash::add_light( RID p_light_instance ) {
  1003. #define LIGHT_FADE_TRESHOLD 0.05
  1004. ERR_FAIL_COND( light_instance_count >= MAX_SCENE_LIGHTS );
  1005. LightInstance *li = light_instance_owner.get(p_light_instance);
  1006. ERR_FAIL_COND(!li);
  1007. if (li->base->type==VS::LIGHT_DIRECTIONAL) {
  1008. ERR_FAIL_COND( directional_light_count >= RenderList::MAX_LIGHTS);
  1009. directional_lights[directional_light_count++]=li;
  1010. }
  1011. /* make light hash */
  1012. // actually, not really a hash, but helps to sort the lights
  1013. // and avoid recompiling redudant shader versions
  1014. li->last_pass=scene_pass;
  1015. li->sort_key=light_instance_count;
  1016. light_instances[light_instance_count++]=li;
  1017. }
  1018. void RasterizerFlash::_update_shader( Shader* p_shader) const {
  1019. }
  1020. void RasterizerFlash::_add_geometry( const Geometry* p_geometry, const InstanceData *p_instance, const Geometry *p_geometry_cmp, const GeometryOwner *p_owner) {
  1021. Material *m=NULL;
  1022. RID m_src=p_instance->material_override.is_valid() ? p_instance->material_override : p_geometry->material;
  1023. if (m_src)
  1024. m=material_owner.get( m_src );
  1025. if (!m) {
  1026. m=material_owner.get( default_material );
  1027. }
  1028. ERR_FAIL_COND(!m);
  1029. if (m->last_pass!=frame) {
  1030. if (m->shader.is_valid()) {
  1031. m->shader_cache=shader_owner.get(m->shader);
  1032. if (m->shader_cache) {
  1033. if (!m->shader_cache->valid)
  1034. m->shader_cache=NULL;
  1035. } else {
  1036. m->shader=RID();
  1037. }
  1038. } else {
  1039. m->shader_cache=NULL;
  1040. }
  1041. m->last_pass=frame;
  1042. }
  1043. LightInstance *lights[RenderList::MAX_LIGHTS];
  1044. RenderList *render_list=NULL;
  1045. bool has_alpha = m->blend_mode!=VS::MATERIAL_BLEND_MODE_MIX || (m->shader_cache && m->shader_cache->has_alpha) || m->flags[VS::MATERIAL_FLAG_ONTOP];
  1046. if (has_alpha) {
  1047. render_list = &alpha_render_list;
  1048. } else {
  1049. render_list = &opaque_render_list;
  1050. }
  1051. if (false && !has_alpha) {
  1052. //hacemos aca el per picsel liting viejis
  1053. }
  1054. RenderList::Element *e = render_list->add_element();
  1055. e->geometry=p_geometry;
  1056. e->geometry_cmp=p_geometry_cmp;
  1057. e->material=m;
  1058. e->instance=p_instance;
  1059. //e->depth=camera_plane.distance_to(p_world->origin);
  1060. e->depth=camera_transform.origin.distance_to(p_instance->transform.origin);
  1061. e->owner=p_owner;
  1062. e->light_type=0;
  1063. e->additive=false;
  1064. e->additive_ptr=&e->additive;
  1065. if (p_instance->skeleton.is_valid()) {
  1066. e->skeleton=skeleton_owner.get(p_instance->skeleton);
  1067. if (!e->skeleton)
  1068. const_cast<InstanceData*>(p_instance)->skeleton=RID();
  1069. } else {
  1070. e->skeleton=NULL;
  1071. }
  1072. e->mirror=p_instance->mirror;
  1073. if (m->flags[VS::MATERIAL_FLAG_INVERT_FACES])
  1074. e->mirror=!e->mirror;
  1075. e->light_key=0;
  1076. e->light_type=0xFF; // no lights!
  1077. e->light_count=0;
  1078. if (m->flags[VS::MATERIAL_FLAG_UNSHADED]) {
  1079. e->light_key-=1;
  1080. } else {
  1081. //setup lights
  1082. uint16_t light_count=0;
  1083. uint16_t sort_key[4];
  1084. uint8_t light_types[4];
  1085. int dlc = MIN(directional_light_count,RenderList::MAX_LIGHTS);;
  1086. light_count=dlc;
  1087. for(int i=0;i<dlc;i++) {
  1088. sort_key[i]=directional_lights[i]->sort_key;
  1089. light_types[i]=VS::LIGHT_DIRECTIONAL;
  1090. }
  1091. const RID *liptr = p_instance->light_instances.ptr();
  1092. int ilc=p_instance->light_instances.size();
  1093. for(int i=0;i<ilc;i++) {
  1094. if (light_count>=RenderList::MAX_LIGHTS)
  1095. break;
  1096. LightInstance *li=light_instance_owner.get( liptr[i] );
  1097. if (!li || li->last_pass!=scene_pass) //lit by light not in visible scene
  1098. continue;
  1099. light_types[light_count]=li->base->type;
  1100. sort_key[light_count++]=li->sort_key;
  1101. }
  1102. if (light_count>dlc) {
  1103. SortArray<uint16_t> light_sort;
  1104. light_sort.sort(&sort_key[dlc],(light_count-dlc)); //generate an equal sort key
  1105. }
  1106. if (fragment_lighting && !has_alpha) {
  1107. //per vertex lighting, all lights at the same time
  1108. for(int i=0;i<light_count;i++) {
  1109. RenderList::Element *ec;
  1110. if (i>0) {
  1111. ec = render_list->add_element();
  1112. memcpy(ec,e,sizeof(RenderList::Element));
  1113. } else {
  1114. ec=e;
  1115. }
  1116. ec->light_type=light_types[i];
  1117. ec->light_count=1;
  1118. ec->lights[0]=sort_key[i];
  1119. ec->additive_ptr=&e->additive;
  1120. }
  1121. /*for(int i=0;i<light_count;i++)
  1122. e->lights[i]=sort_key[i];*/
  1123. } else {
  1124. //per vertex lighting, all lights at the same time
  1125. e->light_count=light_count;
  1126. for(int i=0;i<light_count;i++)
  1127. e->lights[i]=sort_key[i];
  1128. }
  1129. }
  1130. }
  1131. void RasterizerFlash::add_mesh( const RID& p_mesh, const InstanceData *p_data) {
  1132. Mesh *mesh = mesh_owner.get(p_mesh);
  1133. ERR_FAIL_COND(!mesh);
  1134. int ssize = mesh->surfaces.size();
  1135. for (int i=0;i<ssize;i++) {
  1136. Surface *s = mesh->surfaces[i];
  1137. _add_geometry(s,p_data,s,NULL);
  1138. }
  1139. mesh->last_pass=frame;
  1140. }
  1141. void RasterizerFlash::add_multimesh( const RID& p_multimesh, const InstanceData *p_data){
  1142. MultiMesh *multimesh = multimesh_owner.get(p_multimesh);
  1143. ERR_FAIL_COND(!multimesh);
  1144. if (!multimesh->mesh.is_valid())
  1145. return;
  1146. if (multimesh->elements.empty())
  1147. return;
  1148. Mesh *mesh = mesh_owner.get(multimesh->mesh);
  1149. ERR_FAIL_COND(!mesh);
  1150. int surf_count = mesh->surfaces.size();
  1151. if (multimesh->last_pass!=scene_pass) {
  1152. multimesh->cache_surfaces.resize(surf_count);
  1153. for(int i=0;i<surf_count;i++) {
  1154. multimesh->cache_surfaces[i].material=mesh->surfaces[i]->material;
  1155. multimesh->cache_surfaces[i].has_alpha=mesh->surfaces[i]->has_alpha;
  1156. multimesh->cache_surfaces[i].surface=mesh->surfaces[i];
  1157. }
  1158. multimesh->last_pass=scene_pass;
  1159. }
  1160. for(int i=0;i<surf_count;i++) {
  1161. _add_geometry(&multimesh->cache_surfaces[i],p_data,multimesh->cache_surfaces[i].surface,multimesh);
  1162. }
  1163. }
  1164. void RasterizerFlash::add_particles( const RID& p_particle_instance, const InstanceData *p_data){
  1165. //print_line("adding particles");
  1166. ParticlesInstance *particles_instance = particles_instance_owner.get(p_particle_instance);
  1167. ERR_FAIL_COND(!particles_instance);
  1168. Particles *p=particles_owner.get( particles_instance->particles );
  1169. ERR_FAIL_COND(!p);
  1170. _add_geometry(p,p_data,p,particles_instance);
  1171. }
  1172. void RasterizerFlash::_set_cull(bool p_front,bool p_reverse_cull) {
  1173. }
  1174. _FORCE_INLINE_ void RasterizerFlash::_update_material_shader_params(Material *p_material) const {
  1175. Map<StringName,Material::UniformData> old_mparams=p_material->shader_params;
  1176. Map<StringName,Material::UniformData> &mparams=p_material->shader_params;
  1177. mparams.clear();
  1178. int idx=0;
  1179. for(Map<StringName,ShaderLanguage::Uniform>::Element *E=p_material->shader_cache->uniforms.front();E;E=E->next()) {
  1180. Material::UniformData ud;
  1181. bool keep=true;
  1182. if (!old_mparams.has(E->key()))
  1183. keep=false;
  1184. else if (old_mparams[E->key()].value.get_type()!=E->value().default_value.get_type()) {
  1185. if (old_mparams[E->key()].value.get_type()==Variant::OBJECT) {
  1186. if (E->value().default_value.get_type()!=Variant::_RID) //hackfor textures
  1187. keep=false;
  1188. } else if (!old_mparams[E->key()].value.is_num() || !E->value().default_value.get_type())
  1189. keep=false;
  1190. }
  1191. if (keep) {
  1192. ud.value=old_mparams[E->key()].value;
  1193. print_line("KEEP: "+String(E->key()));
  1194. } else {
  1195. ud.value=E->value().default_value;
  1196. print_line("NEW: "+String(E->key())+" because: hasold-"+itos(old_mparams.has(E->key())));
  1197. if (old_mparams.has(E->key()))
  1198. print_line(" told "+Variant::get_type_name(old_mparams[E->key()].value.get_type())+" tnew "+Variant::get_type_name(E->value().default_value.get_type()));
  1199. }
  1200. ud.istexture=(E->get().type==ShaderLanguage::TYPE_TEXTURE || E->get().type==ShaderLanguage::TYPE_CUBEMAP);
  1201. ud.index=idx++;
  1202. mparams[E->key()]=ud;
  1203. }
  1204. p_material->shader_version=p_material->shader_cache->version;
  1205. }
  1206. bool RasterizerFlash::_setup_material(const Geometry *p_geometry,const Material *p_material,bool p_vertexlit,bool p_no_const_light) {
  1207. return false;
  1208. }
  1209. void RasterizerFlash::_setup_lights(const uint16_t * p_lights,int p_light_count) {
  1210. }
  1211. Error RasterizerFlash::_setup_geometry(const Geometry *p_geometry, const Material* p_material, const Skeleton *p_skeleton,const float *p_morphs) {
  1212. return OK;
  1213. };
  1214. void RasterizerFlash::_render(const Geometry *p_geometry,const Material *p_material, const Skeleton* p_skeleton, const GeometryOwner *p_owner) {
  1215. };
  1216. void RasterizerFlash::_render_list_forward(RenderList *p_render_list,bool p_reverse_cull,bool p_fragment_light) {
  1217. };
  1218. void RasterizerFlash::end_scene() {
  1219. }
  1220. void RasterizerFlash::end_shadow_map() {
  1221. }
  1222. void RasterizerFlash::end_frame() {
  1223. }
  1224. void RasterizerFlash::flush_frame() {
  1225. }
  1226. /* CANVAS API */
  1227. void RasterizerFlash::canvas_begin() {
  1228. }
  1229. void RasterizerFlash::canvas_set_opacity(float p_opacity) {
  1230. canvas_opacity = p_opacity;
  1231. }
  1232. void RasterizerFlash::canvas_set_blend_mode(VS::MaterialBlendMode p_mode) {
  1233. }
  1234. void RasterizerFlash::canvas_begin_rect(const Matrix32& p_transform) {
  1235. }
  1236. void RasterizerFlash::canvas_set_clip(bool p_clip, const Rect2& p_rect) {
  1237. }
  1238. void RasterizerFlash::canvas_end_rect() {
  1239. //glPopMatrix();
  1240. }
  1241. RasterizerFlash::Texture* RasterizerFlash::_bind_canvas_texture(const RID& p_texture) {
  1242. return NULL;
  1243. }
  1244. void RasterizerFlash::canvas_draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width) {
  1245. }
  1246. void RasterizerFlash::_draw_gui_primitive(int p_points, const Vector2 *p_vertices, const Color* p_colors, const Vector2 *p_uvs) {
  1247. }
  1248. void RasterizerFlash::_draw_textured_quad(const Rect2& p_rect, const Rect2& p_src_region, const Size2& p_tex_size,bool p_h_flip, bool p_v_flip ) {
  1249. }
  1250. void RasterizerFlash::_draw_quad(const Rect2& p_rect) {
  1251. Vector2 coords[4]= {
  1252. Vector2( p_rect.pos.x,p_rect.pos.y ),
  1253. Vector2( p_rect.pos.x+p_rect.size.width,p_rect.pos.y ),
  1254. Vector2( p_rect.pos.x+p_rect.size.width,p_rect.pos.y+p_rect.size.height ),
  1255. Vector2( p_rect.pos.x,p_rect.pos.y+p_rect.size.height )
  1256. };
  1257. _draw_gui_primitive(4,coords,0,0);
  1258. }
  1259. void RasterizerFlash::canvas_draw_rect(const Rect2& p_rect, int p_flags, const Rect2& p_source,RID p_texture,const Color& p_modulate) {
  1260. Color m = p_modulate;
  1261. m.a*=canvas_opacity;
  1262. _set_color_attrib(m);
  1263. Texture *texture = _bind_canvas_texture(p_texture);
  1264. if ( texture ) {
  1265. if (!(p_flags&CANVAS_RECT_REGION)) {
  1266. Rect2 region = Rect2(0,0,texture->width,texture->height);
  1267. _draw_textured_quad(p_rect,region,region.size,p_flags&CANVAS_RECT_FLIP_H,p_flags&CANVAS_RECT_FLIP_V);
  1268. } else {
  1269. _draw_textured_quad(p_rect, p_source, Size2(texture->width,texture->height),p_flags&CANVAS_RECT_FLIP_H,p_flags&CANVAS_RECT_FLIP_V );
  1270. }
  1271. } else {
  1272. //glDisable(GL_TEXTURE_2D);
  1273. _draw_quad( p_rect );
  1274. //print_line("rect: "+p_rect);
  1275. }
  1276. }
  1277. void RasterizerFlash::canvas_draw_style_box(const Rect2& p_rect, RID p_texture,const float *p_margin, bool p_draw_center,const Color& p_modulate) {
  1278. Color m = p_modulate;
  1279. m.a*=canvas_opacity;
  1280. _set_color_attrib(m);
  1281. Texture* texture=_bind_canvas_texture(p_texture);
  1282. ERR_FAIL_COND(!texture);
  1283. /* CORNERS */
  1284. _draw_textured_quad( // top left
  1285. Rect2( p_rect.pos, Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])),
  1286. Rect2( Point2(), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_TOP])),
  1287. Size2( texture->width, texture->height ) );
  1288. _draw_textured_quad( // top right
  1289. Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])),
  1290. Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],0), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_TOP])),
  1291. Size2( texture->width, texture->height ) );
  1292. _draw_textured_quad( // bottom left
  1293. Rect2( Point2(p_rect.pos.x,p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])),
  1294. Rect2( Point2(0,texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_LEFT],p_margin[MARGIN_BOTTOM])),
  1295. Size2( texture->width, texture->height ) );
  1296. _draw_textured_quad( // bottom right
  1297. Rect2( Point2( p_rect.pos.x + p_rect.size.width - p_margin[MARGIN_RIGHT], p_rect.pos.y + p_rect.size.height - p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])),
  1298. Rect2( Point2(texture->width-p_margin[MARGIN_RIGHT],texture->height-p_margin[MARGIN_BOTTOM]), Size2(p_margin[MARGIN_RIGHT],p_margin[MARGIN_BOTTOM])),
  1299. Size2( texture->width, texture->height ) );
  1300. Rect2 rect_center( p_rect.pos+Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( p_rect.size.width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], p_rect.size.height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] ));
  1301. Rect2 src_center( Point2( p_margin[MARGIN_LEFT], p_margin[MARGIN_TOP]), Size2( texture->width - p_margin[MARGIN_LEFT] - p_margin[MARGIN_RIGHT], texture->height - p_margin[MARGIN_TOP] - p_margin[MARGIN_BOTTOM] ));
  1302. _draw_textured_quad( // top
  1303. Rect2( Point2(rect_center.pos.x,p_rect.pos.y),Size2(rect_center.size.width,p_margin[MARGIN_TOP])),
  1304. Rect2( Point2(p_margin[MARGIN_LEFT],0), Size2(src_center.size.width,p_margin[MARGIN_TOP])),
  1305. Size2( texture->width, texture->height ) );
  1306. _draw_textured_quad( // bottom
  1307. Rect2( Point2(rect_center.pos.x,rect_center.pos.y+rect_center.size.height),Size2(rect_center.size.width,p_margin[MARGIN_BOTTOM])),
  1308. Rect2( Point2(p_margin[MARGIN_LEFT],src_center.pos.y+src_center.size.height), Size2(src_center.size.width,p_margin[MARGIN_BOTTOM])),
  1309. Size2( texture->width, texture->height ) );
  1310. _draw_textured_quad( // left
  1311. Rect2( Point2(p_rect.pos.x,rect_center.pos.y),Size2(p_margin[MARGIN_LEFT],rect_center.size.height)),
  1312. Rect2( Point2(0,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_LEFT],src_center.size.height)),
  1313. Size2( texture->width, texture->height ) );
  1314. _draw_textured_quad( // right
  1315. Rect2( Point2(rect_center.pos.x+rect_center.size.width,rect_center.pos.y),Size2(p_margin[MARGIN_RIGHT],rect_center.size.height)),
  1316. Rect2( Point2(src_center.pos.x+src_center.size.width,p_margin[MARGIN_TOP]), Size2(p_margin[MARGIN_RIGHT],src_center.size.height)),
  1317. Size2( texture->width, texture->height ) );
  1318. if (p_draw_center) {
  1319. _draw_textured_quad(
  1320. rect_center,
  1321. src_center,
  1322. Size2( texture->width, texture->height ));
  1323. }
  1324. }
  1325. void RasterizerFlash::canvas_draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, RID p_texture,float p_width) {
  1326. ERR_FAIL_COND(p_points.size()<1);
  1327. _set_color_attrib(Color(1,1,1,canvas_opacity));
  1328. _bind_canvas_texture(p_texture);
  1329. _draw_gui_primitive(p_points.size(),p_points.ptr(),p_colors.ptr(),p_uvs.ptr());
  1330. }
  1331. void RasterizerFlash::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) {
  1332. };
  1333. void RasterizerFlash::canvas_set_transform(const Matrix32& p_transform) {
  1334. }
  1335. /* ENVIRONMENT */
  1336. RID RasterizerFlash::environment_create() {
  1337. Environment * env = memnew( Environment );
  1338. return environment_owner.make_rid(env);
  1339. }
  1340. void RasterizerFlash::environment_set_background(RID p_env,VS::EnvironmentBG p_bg) {
  1341. ERR_FAIL_INDEX(p_bg,VS::ENV_BG_MAX);
  1342. Environment * env = environment_owner.get(p_env);
  1343. ERR_FAIL_COND(!env);
  1344. env->bg_mode=p_bg;
  1345. }
  1346. VS::EnvironmentBG RasterizerFlash::environment_get_background(RID p_env) const{
  1347. const Environment * env = environment_owner.get(p_env);
  1348. ERR_FAIL_COND_V(!env,VS::ENV_BG_MAX);
  1349. return env->bg_mode;
  1350. }
  1351. void RasterizerFlash::environment_set_background_param(RID p_env,VS::EnvironmentBGParam p_param, const Variant& p_value){
  1352. ERR_FAIL_INDEX(p_param,VS::ENV_BG_PARAM_MAX);
  1353. Environment * env = environment_owner.get(p_env);
  1354. ERR_FAIL_COND(!env);
  1355. env->bg_param[p_param]=p_value;
  1356. }
  1357. Variant RasterizerFlash::environment_get_background_param(RID p_env,VS::EnvironmentBGParam p_param) const{
  1358. ERR_FAIL_INDEX_V(p_param,VS::ENV_BG_PARAM_MAX,Variant());
  1359. const Environment * env = environment_owner.get(p_env);
  1360. ERR_FAIL_COND_V(!env,Variant());
  1361. return env->bg_param[p_param];
  1362. }
  1363. void RasterizerFlash::environment_set_enable_fx(RID p_env,VS::EnvironmentFx p_effect,bool p_enabled){
  1364. ERR_FAIL_INDEX(p_effect,VS::ENV_FX_MAX);
  1365. Environment * env = environment_owner.get(p_env);
  1366. ERR_FAIL_COND(!env);
  1367. env->fx_enabled[p_effect]=p_enabled;
  1368. }
  1369. bool RasterizerFlash::environment_is_fx_enabled(RID p_env,VS::EnvironmentFx p_effect) const{
  1370. ERR_FAIL_INDEX_V(p_effect,VS::ENV_FX_MAX,false);
  1371. const Environment * env = environment_owner.get(p_env);
  1372. ERR_FAIL_COND_V(!env,false);
  1373. return env->fx_enabled[p_effect];
  1374. }
  1375. void RasterizerFlash::environment_fx_set_param(RID p_env,VS::EnvironmentFxParam p_param,const Variant& p_value){
  1376. ERR_FAIL_INDEX(p_param,VS::ENV_FX_PARAM_MAX);
  1377. Environment * env = environment_owner.get(p_env);
  1378. ERR_FAIL_COND(!env);
  1379. env->fx_param[p_param]=p_value;
  1380. }
  1381. Variant RasterizerFlash::environment_fx_get_param(RID p_env,VS::EnvironmentFxParam p_param) const{
  1382. ERR_FAIL_INDEX_V(p_param,VS::ENV_FX_PARAM_MAX,Variant());
  1383. const Environment * env = environment_owner.get(p_env);
  1384. ERR_FAIL_COND_V(!env,Variant());
  1385. return env->fx_param[p_param];
  1386. }
  1387. /* FX */
  1388. RID RasterizerFlash::fx_create() {
  1389. FX *fx = memnew( FX );
  1390. ERR_FAIL_COND_V(!fx,RID());
  1391. return fx_owner.make_rid(fx);
  1392. }
  1393. void RasterizerFlash::fx_get_effects(RID p_fx,List<String> *p_effects) const {
  1394. FX *fx = fx_owner.get(p_fx);
  1395. ERR_FAIL_COND(!fx);
  1396. p_effects->clear();
  1397. p_effects->push_back("bgcolor");
  1398. p_effects->push_back("skybox");
  1399. p_effects->push_back("antialias");
  1400. //p_effects->push_back("hdr");
  1401. p_effects->push_back("glow"); // glow has a bloom parameter, too
  1402. p_effects->push_back("ssao");
  1403. p_effects->push_back("fog");
  1404. p_effects->push_back("dof_blur");
  1405. p_effects->push_back("toon");
  1406. p_effects->push_back("edge");
  1407. }
  1408. void RasterizerFlash::fx_set_active(RID p_fx,const String& p_effect, bool p_active) {
  1409. FX *fx = fx_owner.get(p_fx);
  1410. ERR_FAIL_COND(!fx);
  1411. if (p_effect=="bgcolor")
  1412. fx->bgcolor_active=p_active;
  1413. else if (p_effect=="skybox")
  1414. fx->skybox_active=p_active;
  1415. else if (p_effect=="antialias")
  1416. fx->antialias_active=p_active;
  1417. else if (p_effect=="glow")
  1418. fx->glow_active=p_active;
  1419. else if (p_effect=="ssao")
  1420. fx->ssao_active=p_active;
  1421. else if (p_effect=="fog")
  1422. fx->fog_active=p_active;
  1423. // else if (p_effect=="dof_blur")
  1424. // fx->dof_blur_active=p_active;
  1425. else if (p_effect=="toon")
  1426. fx->toon_active=p_active;
  1427. else if (p_effect=="edge")
  1428. fx->edge_active=p_active;
  1429. }
  1430. bool RasterizerFlash::fx_is_active(RID p_fx,const String& p_effect) const {
  1431. FX *fx = fx_owner.get(p_fx);
  1432. ERR_FAIL_COND_V(!fx,false);
  1433. if (p_effect=="bgcolor")
  1434. return fx->bgcolor_active;
  1435. else if (p_effect=="skybox")
  1436. return fx->skybox_active;
  1437. else if (p_effect=="antialias")
  1438. return fx->antialias_active;
  1439. else if (p_effect=="glow")
  1440. return fx->glow_active;
  1441. else if (p_effect=="ssao")
  1442. return fx->ssao_active;
  1443. else if (p_effect=="fog")
  1444. return fx->fog_active;
  1445. //else if (p_effect=="dof_blur")
  1446. // return fx->dof_blur_active;
  1447. else if (p_effect=="toon")
  1448. return fx->toon_active;
  1449. else if (p_effect=="edge")
  1450. return fx->edge_active;
  1451. return false;
  1452. }
  1453. void RasterizerFlash::fx_get_effect_params(RID p_fx,const String& p_effect,List<PropertyInfo> *p_params) const {
  1454. FX *fx = fx_owner.get(p_fx);
  1455. ERR_FAIL_COND(!fx);
  1456. if (p_effect=="bgcolor") {
  1457. p_params->push_back( PropertyInfo( Variant::COLOR, "color" ) );
  1458. } else if (p_effect=="skybox") {
  1459. p_params->push_back( PropertyInfo( Variant::_RID, "cubemap" ) );
  1460. } else if (p_effect=="antialias") {
  1461. p_params->push_back( PropertyInfo( Variant::REAL, "tolerance", PROPERTY_HINT_RANGE,"1,128,1" ) );
  1462. } else if (p_effect=="glow") {
  1463. p_params->push_back( PropertyInfo( Variant::INT, "passes", PROPERTY_HINT_RANGE,"1,4,1" ) );
  1464. p_params->push_back( PropertyInfo( Variant::REAL, "attenuation", PROPERTY_HINT_RANGE,"0.01,8.0,0.01" ) );
  1465. p_params->push_back( PropertyInfo( Variant::REAL, "bloom", PROPERTY_HINT_RANGE,"-1.0,1.0,0.01" ) );
  1466. } else if (p_effect=="ssao") {
  1467. p_params->push_back( PropertyInfo( Variant::REAL, "radius", PROPERTY_HINT_RANGE,"0.0,16.0,0.01" ) );
  1468. p_params->push_back( PropertyInfo( Variant::REAL, "max_distance", PROPERTY_HINT_RANGE,"0.0,256.0,0.01" ) );
  1469. p_params->push_back( PropertyInfo( Variant::REAL, "range_max", PROPERTY_HINT_RANGE,"0.0,1.0,0.01" ) );
  1470. p_params->push_back( PropertyInfo( Variant::REAL, "range_min", PROPERTY_HINT_RANGE,"0.0,1.0,0.01" ) );
  1471. p_params->push_back( PropertyInfo( Variant::REAL, "attenuation", PROPERTY_HINT_RANGE,"0.0,8.0,0.01" ) );
  1472. } else if (p_effect=="fog") {
  1473. p_params->push_back( PropertyInfo( Variant::REAL, "begin", PROPERTY_HINT_RANGE,"0.0,8192,0.01" ) );
  1474. p_params->push_back( PropertyInfo( Variant::REAL, "end", PROPERTY_HINT_RANGE,"0.0,8192,0.01" ) );
  1475. p_params->push_back( PropertyInfo( Variant::REAL, "attenuation", PROPERTY_HINT_RANGE,"0.0,8.0,0.01" ) );
  1476. p_params->push_back( PropertyInfo( Variant::COLOR, "color_begin" ) );
  1477. p_params->push_back( PropertyInfo( Variant::COLOR, "color_end" ) );
  1478. p_params->push_back( PropertyInfo( Variant::BOOL, "fog_bg" ) );
  1479. // } else if (p_effect=="dof_blur") {
  1480. // return fx->dof_blur_active;
  1481. } else if (p_effect=="toon") {
  1482. p_params->push_back( PropertyInfo( Variant::REAL, "treshold", PROPERTY_HINT_RANGE,"0.0,1.0,0.01" ) );
  1483. p_params->push_back( PropertyInfo( Variant::REAL, "soft", PROPERTY_HINT_RANGE,"0.001,1.0,0.001" ) );
  1484. } else if (p_effect=="edge") {
  1485. }
  1486. }
  1487. Variant RasterizerFlash::fx_get_effect_param(RID p_fx,const String& p_effect,const String& p_param) const {
  1488. FX *fx = fx_owner.get(p_fx);
  1489. ERR_FAIL_COND_V(!fx,Variant());
  1490. if (p_effect=="bgcolor") {
  1491. if (p_param=="color")
  1492. return fx->bgcolor;
  1493. } else if (p_effect=="skybox") {
  1494. if (p_param=="cubemap")
  1495. return fx->skybox_cubemap;
  1496. } else if (p_effect=="antialias") {
  1497. if (p_param=="tolerance")
  1498. return fx->antialias_tolerance;
  1499. } else if (p_effect=="glow") {
  1500. if (p_param=="passes")
  1501. return fx->glow_passes;
  1502. if (p_param=="attenuation")
  1503. return fx->glow_attenuation;
  1504. if (p_param=="bloom")
  1505. return fx->glow_bloom;
  1506. } else if (p_effect=="ssao") {
  1507. if (p_param=="attenuation")
  1508. return fx->ssao_attenuation;
  1509. if (p_param=="max_distance")
  1510. return fx->ssao_max_distance;
  1511. if (p_param=="range_max")
  1512. return fx->ssao_range_max;
  1513. if (p_param=="range_min")
  1514. return fx->ssao_range_min;
  1515. if (p_param=="radius")
  1516. return fx->ssao_radius;
  1517. } else if (p_effect=="fog") {
  1518. if (p_param=="begin")
  1519. return fx->fog_near;
  1520. if (p_param=="end")
  1521. return fx->fog_far;
  1522. if (p_param=="attenuation")
  1523. return fx->fog_attenuation;
  1524. if (p_param=="color_begin")
  1525. return fx->fog_color_near;
  1526. if (p_param=="color_end")
  1527. return fx->fog_color_far;
  1528. if (p_param=="fog_bg")
  1529. return fx->fog_bg;
  1530. // } else if (p_effect=="dof_blur") {
  1531. // return fx->dof_blur_active;
  1532. } else if (p_effect=="toon") {
  1533. if (p_param=="treshold")
  1534. return fx->toon_treshold;
  1535. if (p_param=="soft")
  1536. return fx->toon_soft;
  1537. } else if (p_effect=="edge") {
  1538. }
  1539. return Variant();
  1540. }
  1541. void RasterizerFlash::fx_set_effect_param(RID p_fx,const String& p_effect, const String& p_param, const Variant& p_value) {
  1542. FX *fx = fx_owner.get(p_fx);
  1543. ERR_FAIL_COND(!fx);
  1544. if (p_effect=="bgcolor") {
  1545. if (p_param=="color")
  1546. fx->bgcolor=p_value;
  1547. } else if (p_effect=="skybox") {
  1548. if (p_param=="cubemap")
  1549. fx->skybox_cubemap=p_value;
  1550. } else if (p_effect=="antialias") {
  1551. if (p_param=="tolerance")
  1552. fx->antialias_tolerance=p_value;
  1553. } else if (p_effect=="glow") {
  1554. if (p_param=="passes")
  1555. fx->glow_passes=p_value;
  1556. if (p_param=="attenuation")
  1557. fx->glow_attenuation=p_value;
  1558. if (p_param=="bloom")
  1559. fx->glow_bloom=p_value;
  1560. } else if (p_effect=="ssao") {
  1561. if (p_param=="attenuation")
  1562. fx->ssao_attenuation=p_value;
  1563. if (p_param=="radius")
  1564. fx->ssao_radius=p_value;
  1565. if (p_param=="max_distance")
  1566. fx->ssao_max_distance=p_value;
  1567. if (p_param=="range_max")
  1568. fx->ssao_range_max=p_value;
  1569. if (p_param=="range_min")
  1570. fx->ssao_range_min=p_value;
  1571. } else if (p_effect=="fog") {
  1572. if (p_param=="begin")
  1573. fx->fog_near=p_value;
  1574. if (p_param=="end")
  1575. fx->fog_far=p_value;
  1576. if (p_param=="attenuation")
  1577. fx->fog_attenuation=p_value;
  1578. if (p_param=="color_begin")
  1579. fx->fog_color_near=p_value;
  1580. if (p_param=="color_end")
  1581. fx->fog_color_far=p_value;
  1582. if (p_param=="fog_bg")
  1583. fx->fog_bg=p_value;
  1584. // } else if (p_effect=="dof_blur") {
  1585. // fx->dof_blur_active=p_value;
  1586. } else if (p_effect=="toon") {
  1587. if (p_param=="treshold")
  1588. fx->toon_treshold=p_value;
  1589. if (p_param=="soft")
  1590. fx->toon_soft=p_value;
  1591. } else if (p_effect=="edge") {
  1592. }
  1593. }
  1594. /*MISC*/
  1595. bool RasterizerFlash::is_texture(const RID& p_rid) const {
  1596. return texture_owner.owns(p_rid);
  1597. }
  1598. bool RasterizerFlash::is_material(const RID& p_rid) const {
  1599. return material_owner.owns(p_rid);
  1600. }
  1601. bool RasterizerFlash::is_mesh(const RID& p_rid) const {
  1602. return mesh_owner.owns(p_rid);
  1603. }
  1604. bool RasterizerFlash::is_multimesh(const RID& p_rid) const {
  1605. return multimesh_owner.owns(p_rid);
  1606. }
  1607. bool RasterizerFlash::is_particles(const RID &p_beam) const {
  1608. return particles_owner.owns(p_beam);
  1609. }
  1610. bool RasterizerFlash::is_light(const RID& p_rid) const {
  1611. return light_owner.owns(p_rid);
  1612. }
  1613. bool RasterizerFlash::is_light_instance(const RID& p_rid) const {
  1614. return light_instance_owner.owns(p_rid);
  1615. }
  1616. bool RasterizerFlash::is_particles_instance(const RID& p_rid) const {
  1617. return particles_instance_owner.owns(p_rid);
  1618. }
  1619. bool RasterizerFlash::is_skeleton(const RID& p_rid) const {
  1620. return skeleton_owner.owns(p_rid);
  1621. }
  1622. bool RasterizerFlash::is_environment(const RID& p_rid) const {
  1623. return environment_owner.owns(p_rid);
  1624. }
  1625. bool RasterizerFlash::is_fx(const RID& p_rid) const {
  1626. return fx_owner.owns(p_rid);
  1627. }
  1628. bool RasterizerFlash::is_shader(const RID& p_rid) const {
  1629. return false;
  1630. }
  1631. void RasterizerFlash::free(const RID& p_rid) {
  1632. if (texture_owner.owns(p_rid)) {
  1633. // delete the texture
  1634. Texture *texture = texture_owner.get(p_rid);
  1635. _rinfo.texture_mem-=texture->total_data_size;
  1636. texture_owner.free(p_rid);
  1637. memdelete(texture);
  1638. } else if (shader_owner.owns(p_rid)) {
  1639. } else if (material_owner.owns(p_rid)) {
  1640. Material *material = material_owner.get( p_rid );
  1641. ERR_FAIL_COND(!material);
  1642. _free_fixed_material(p_rid); //just in case
  1643. material_owner.free(p_rid);
  1644. memdelete(material);
  1645. } else if (mesh_owner.owns(p_rid)) {
  1646. } else if (multimesh_owner.owns(p_rid)) {
  1647. MultiMesh *multimesh = multimesh_owner.get(p_rid);
  1648. ERR_FAIL_COND(!multimesh);
  1649. multimesh_owner.free(p_rid);
  1650. memdelete(multimesh);
  1651. } else if (particles_owner.owns(p_rid)) {
  1652. Particles *particles = particles_owner.get(p_rid);
  1653. ERR_FAIL_COND(!particles);
  1654. particles_owner.free(p_rid);
  1655. memdelete(particles);
  1656. } else if (particles_instance_owner.owns(p_rid)) {
  1657. ParticlesInstance *particles_isntance = particles_instance_owner.get(p_rid);
  1658. ERR_FAIL_COND(!particles_isntance);
  1659. particles_instance_owner.free(p_rid);
  1660. memdelete(particles_isntance);
  1661. } else if (skeleton_owner.owns(p_rid)) {
  1662. Skeleton *skeleton = skeleton_owner.get( p_rid );
  1663. ERR_FAIL_COND(!skeleton)
  1664. skeleton_owner.free(p_rid);
  1665. memdelete(skeleton);
  1666. } else if (light_owner.owns(p_rid)) {
  1667. Light *light = light_owner.get( p_rid );
  1668. ERR_FAIL_COND(!light)
  1669. light_owner.free(p_rid);
  1670. memdelete(light);
  1671. } else if (light_instance_owner.owns(p_rid)) {
  1672. LightInstance *light_instance = light_instance_owner.get( p_rid );
  1673. ERR_FAIL_COND(!light_instance);
  1674. light_instance->clear_shadow_buffers();
  1675. light_instance_owner.free(p_rid);
  1676. memdelete( light_instance );
  1677. } else if (fx_owner.owns(p_rid)) {
  1678. FX *fx = fx_owner.get( p_rid );
  1679. ERR_FAIL_COND(!fx);
  1680. fx_owner.free(p_rid);
  1681. memdelete( fx );
  1682. } else if (environment_owner.owns(p_rid)) {
  1683. Environment *env = environment_owner.get( p_rid );
  1684. ERR_FAIL_COND(!env);
  1685. environment_owner.free(p_rid);
  1686. memdelete( env );
  1687. };
  1688. }
  1689. void RasterizerFlash::ShadowBuffer::init(int p_size) {
  1690. }
  1691. void RasterizerFlash::_init_shadow_buffers() {
  1692. int near_shadow_size=GLOBAL_DEF("rasterizer/near_shadow_size",512);
  1693. int far_shadow_size=GLOBAL_DEF("rasterizer/far_shadow_size",64);
  1694. near_shadow_buffers.resize( GLOBAL_DEF("rasterizer/near_shadow_count",4) );
  1695. far_shadow_buffers.resize( GLOBAL_DEF("rasterizer/far_shadow_count",16) );
  1696. shadow_near_far_split_size_ratio = GLOBAL_DEF("rasterizer/shadow_near_far_split_size_ratio",0.3);
  1697. for (int i=0;i<near_shadow_buffers.size();i++) {
  1698. near_shadow_buffers[i].init(near_shadow_size );
  1699. }
  1700. for (int i=0;i<far_shadow_buffers.size();i++) {
  1701. far_shadow_buffers[i].init(far_shadow_size);
  1702. }
  1703. }
  1704. void RasterizerFlash::_update_framebuffer() {
  1705. return;
  1706. }
  1707. void RasterizerFlash::init() {
  1708. }
  1709. void RasterizerFlash::finish() {
  1710. memdelete_arr(skinned_buffer);
  1711. }
  1712. int RasterizerFlash::get_render_info(VS::RenderInfo p_info) {
  1713. switch(p_info) {
  1714. case VS::INFO_OBJECTS_IN_FRAME: {
  1715. return _rinfo.object_count;
  1716. } break;
  1717. case VS::INFO_VERTICES_IN_FRAME: {
  1718. return _rinfo.vertex_count;
  1719. } break;
  1720. case VS::INFO_MATERIAL_CHANGES_IN_FRAME: {
  1721. return _rinfo.mat_change_count;
  1722. } break;
  1723. case VS::INFO_SHADER_CHANGES_IN_FRAME: {
  1724. return _rinfo.shader_change_count;
  1725. } break;
  1726. case VS::INFO_USAGE_VIDEO_MEM_TOTAL: {
  1727. return 0;
  1728. } break;
  1729. case VS::INFO_VIDEO_MEM_USED: {
  1730. return get_render_info(VS::INFO_TEXTURE_MEM_USED)+get_render_info(VS::INFO_VERTEX_MEM_USED);
  1731. } break;
  1732. case VS::INFO_TEXTURE_MEM_USED: {
  1733. _rinfo.texture_mem;
  1734. } break;
  1735. case VS::INFO_VERTEX_MEM_USED: {
  1736. return 0;
  1737. } break;
  1738. }
  1739. return false;
  1740. }
  1741. RasterizerFlash::RasterizerFlash(bool p_compress_arrays,bool p_keep_ram_copy,bool p_default_fragment_lighting) {
  1742. keep_copies=p_keep_ram_copy;
  1743. pack_arrays=p_compress_arrays;
  1744. fragment_lighting=GLOBAL_DEF("rasterizer/use_fragment_lighting",p_default_fragment_lighting);
  1745. frame = 0;
  1746. };
  1747. RasterizerFlash::~RasterizerFlash() {
  1748. };