Graphics.cpp 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #include "../Precompiled.h"
  4. #include "../Core/Profiler.h"
  5. #include "../Graphics/AnimatedModel.h"
  6. #include "../Graphics/Animation.h"
  7. #include "../Graphics/AnimationController.h"
  8. #include "../Graphics/Camera.h"
  9. #include "../Graphics/CustomGeometry.h"
  10. #include "../Graphics/DebugRenderer.h"
  11. #include "../Graphics/DecalSet.h"
  12. #include "../Graphics/Graphics.h"
  13. #include "../Graphics/GraphicsEvents.h"
  14. #include "../Graphics/Material.h"
  15. #include "../Graphics/Octree.h"
  16. #include "../Graphics/ParticleEffect.h"
  17. #include "../Graphics/ParticleEmitter.h"
  18. #include "../Graphics/RibbonTrail.h"
  19. #include "../Graphics/Skybox.h"
  20. #include "../Graphics/StaticModelGroup.h"
  21. #include "../Graphics/Technique.h"
  22. #include "../Graphics/Terrain.h"
  23. #include "../Graphics/TerrainPatch.h"
  24. #include "../Graphics/Zone.h"
  25. #include "../GraphicsAPI/GraphicsImpl.h"
  26. #include "../GraphicsAPI/Shader.h"
  27. #include "../GraphicsAPI/ShaderPrecache.h"
  28. #include "../GraphicsAPI/Texture2D.h"
  29. #include "../GraphicsAPI/Texture2DArray.h"
  30. #include "../GraphicsAPI/Texture3D.h"
  31. #include "../GraphicsAPI/TextureCube.h"
  32. #include "../IO/FileSystem.h"
  33. #include "../IO/Log.h"
  34. #include <SDL/SDL.h>
  35. #include "../DebugNew.h"
  36. namespace Urho3D
  37. {
  38. void Graphics::SetExternalWindow(void* window)
  39. {
  40. if (!window_)
  41. externalWindow_ = window;
  42. else
  43. URHO3D_LOGERROR("Window already opened, can not set external window");
  44. }
  45. void Graphics::SetWindowTitle(const String& windowTitle)
  46. {
  47. windowTitle_ = windowTitle;
  48. if (window_)
  49. SDL_SetWindowTitle(window_, windowTitle_.CString());
  50. }
  51. void Graphics::SetWindowIcon(Image* windowIcon)
  52. {
  53. windowIcon_ = windowIcon;
  54. if (window_)
  55. CreateWindowIcon();
  56. }
  57. void Graphics::SetWindowPosition(const IntVector2& position)
  58. {
  59. if (window_)
  60. SDL_SetWindowPosition(window_, position.x_, position.y_);
  61. else
  62. position_ = position; // Sets as initial position for SDL_CreateWindow()
  63. }
  64. void Graphics::SetWindowPosition(int x, int y)
  65. {
  66. SetWindowPosition(IntVector2(x, y));
  67. }
  68. void Graphics::SetOrientations(const String& orientations)
  69. {
  70. orientations_ = orientations.Trimmed();
  71. SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
  72. }
  73. bool Graphics::SetScreenMode(int width, int height)
  74. {
  75. return SetScreenMode(width, height, screenParams_);
  76. }
  77. bool Graphics::SetWindowModes(const WindowModeParams& windowMode, const WindowModeParams& secondaryWindowMode, bool maximize)
  78. {
  79. primaryWindowMode_ = windowMode;
  80. secondaryWindowMode_ = secondaryWindowMode;
  81. return SetScreenMode(primaryWindowMode_.width_, primaryWindowMode_.height_, primaryWindowMode_.screenParams_, maximize);
  82. }
  83. bool Graphics::SetDefaultWindowModes(int width, int height, const ScreenModeParams& params)
  84. {
  85. // Fill window mode to be applied now
  86. WindowModeParams primaryWindowMode;
  87. primaryWindowMode.width_ = width;
  88. primaryWindowMode.height_ = height;
  89. primaryWindowMode.screenParams_ = params;
  90. // Fill window mode to be applied on Graphics::ToggleFullscreen
  91. WindowModeParams secondaryWindowMode = primaryWindowMode;
  92. // Pick resolution automatically
  93. secondaryWindowMode.width_ = 0;
  94. secondaryWindowMode.height_ = 0;
  95. if (params.fullscreen_ || params.borderless_)
  96. {
  97. secondaryWindowMode.screenParams_.fullscreen_ = false;
  98. secondaryWindowMode.screenParams_.borderless_ = false;
  99. }
  100. else
  101. {
  102. secondaryWindowMode.screenParams_.borderless_ = true;
  103. }
  104. const bool maximize = (!width || !height) && !params.fullscreen_ && !params.borderless_ && params.resizable_;
  105. return SetWindowModes(primaryWindowMode, secondaryWindowMode, maximize);
  106. }
  107. bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable,
  108. bool highDPI, bool vsync, bool tripleBuffer, int multiSample, int monitor, int refreshRate)
  109. {
  110. ScreenModeParams params;
  111. params.fullscreen_ = fullscreen;
  112. params.borderless_ = borderless;
  113. params.resizable_ = resizable;
  114. params.highDPI_ = highDPI;
  115. params.vsync_ = vsync;
  116. params.tripleBuffer_ = tripleBuffer;
  117. params.multiSample_ = multiSample;
  118. params.monitor_ = monitor;
  119. params.refreshRate_ = refreshRate;
  120. return SetDefaultWindowModes(width, height, params);
  121. }
  122. bool Graphics::SetMode(int width, int height)
  123. {
  124. return SetDefaultWindowModes(width, height, screenParams_);
  125. }
  126. bool Graphics::ToggleFullscreen()
  127. {
  128. Swap(primaryWindowMode_, secondaryWindowMode_);
  129. return SetScreenMode(primaryWindowMode_.width_, primaryWindowMode_.height_, primaryWindowMode_.screenParams_);
  130. }
  131. void Graphics::SetShaderParameter(StringHash param, const Variant& value)
  132. {
  133. switch (value.GetType())
  134. {
  135. case VAR_BOOL:
  136. SetShaderParameter(param, value.GetBool());
  137. break;
  138. case VAR_INT:
  139. SetShaderParameter(param, value.GetInt());
  140. break;
  141. case VAR_FLOAT:
  142. case VAR_DOUBLE:
  143. SetShaderParameter(param, value.GetFloat());
  144. break;
  145. case VAR_VECTOR2:
  146. SetShaderParameter(param, value.GetVector2());
  147. break;
  148. case VAR_VECTOR3:
  149. SetShaderParameter(param, value.GetVector3());
  150. break;
  151. case VAR_VECTOR4:
  152. SetShaderParameter(param, value.GetVector4());
  153. break;
  154. case VAR_COLOR:
  155. SetShaderParameter(param, value.GetColor());
  156. break;
  157. case VAR_MATRIX3:
  158. SetShaderParameter(param, value.GetMatrix3());
  159. break;
  160. case VAR_MATRIX3X4:
  161. SetShaderParameter(param, value.GetMatrix3x4());
  162. break;
  163. case VAR_MATRIX4:
  164. SetShaderParameter(param, value.GetMatrix4());
  165. break;
  166. case VAR_BUFFER:
  167. {
  168. const PODVector<unsigned char>& buffer = value.GetBuffer();
  169. if (buffer.Size() >= sizeof(float))
  170. SetShaderParameter(param, reinterpret_cast<const float*>(&buffer[0]), buffer.Size() / sizeof(float));
  171. }
  172. break;
  173. default:
  174. // Unsupported parameter type, do nothing
  175. break;
  176. }
  177. }
  178. IntVector2 Graphics::GetWindowPosition() const
  179. {
  180. if (window_)
  181. {
  182. IntVector2 position;
  183. SDL_GetWindowPosition(window_, &position.x_, &position.y_);
  184. return position;
  185. }
  186. return position_;
  187. }
  188. PODVector<IntVector3> Graphics::GetResolutions(int monitor) const
  189. {
  190. PODVector<IntVector3> ret;
  191. // Emscripten is not able to return a valid list
  192. #ifndef __EMSCRIPTEN__
  193. auto numModes = (unsigned)SDL_GetNumDisplayModes(monitor);
  194. for (unsigned i = 0; i < numModes; ++i)
  195. {
  196. SDL_DisplayMode mode;
  197. SDL_GetDisplayMode(monitor, i, &mode);
  198. int width = mode.w;
  199. int height = mode.h;
  200. int rate = mode.refresh_rate;
  201. // Store mode if unique
  202. bool unique = true;
  203. for (unsigned j = 0; j < ret.Size(); ++j)
  204. {
  205. if (ret[j].x_ == width && ret[j].y_ == height && ret[j].z_ == rate)
  206. {
  207. unique = false;
  208. break;
  209. }
  210. }
  211. if (unique)
  212. ret.Push(IntVector3(width, height, rate));
  213. }
  214. #endif
  215. return ret;
  216. }
  217. unsigned Graphics::FindBestResolutionIndex(int monitor, int width, int height, int refreshRate) const
  218. {
  219. const PODVector<IntVector3> resolutions = GetResolutions(monitor);
  220. if (resolutions.Empty())
  221. return M_MAX_UNSIGNED;
  222. unsigned best = 0;
  223. unsigned bestError = M_MAX_UNSIGNED;
  224. for (unsigned i = 0; i < resolutions.Size(); ++i)
  225. {
  226. auto error = static_cast<unsigned>(Abs(resolutions[i].x_ - width) + Abs(resolutions[i].y_ - height));
  227. if (refreshRate != 0)
  228. error += static_cast<unsigned>(Abs(resolutions[i].z_ - refreshRate));
  229. if (error < bestError)
  230. {
  231. best = i;
  232. bestError = error;
  233. }
  234. }
  235. return best;
  236. }
  237. IntVector2 Graphics::GetDesktopResolution(int monitor) const
  238. {
  239. #if !defined(__ANDROID__) && !defined(IOS) && !defined(TVOS)
  240. SDL_DisplayMode mode;
  241. SDL_GetDesktopDisplayMode(monitor, &mode);
  242. return IntVector2(mode.w, mode.h);
  243. #else
  244. // SDL_GetDesktopDisplayMode() may not work correctly on mobile platforms. Rather return the window size
  245. return IntVector2(width_, height_);
  246. #endif
  247. }
  248. int Graphics::GetMonitorCount() const
  249. {
  250. return SDL_GetNumVideoDisplays();
  251. }
  252. int Graphics::GetCurrentMonitor() const
  253. {
  254. return window_ ? SDL_GetWindowDisplayIndex(window_) : 0;
  255. }
  256. bool Graphics::GetMaximized() const
  257. {
  258. return window_? static_cast<bool>(SDL_GetWindowFlags(window_) & SDL_WINDOW_MAXIMIZED) : false;
  259. }
  260. Vector3 Graphics::GetDisplayDPI(int monitor) const
  261. {
  262. Vector3 result;
  263. SDL_GetDisplayDPI(monitor, &result.z_, &result.x_, &result.y_);
  264. return result;
  265. }
  266. void Graphics::Maximize()
  267. {
  268. if (!window_)
  269. return;
  270. SDL_MaximizeWindow(window_);
  271. }
  272. void Graphics::Minimize()
  273. {
  274. if (!window_)
  275. return;
  276. SDL_MinimizeWindow(window_);
  277. }
  278. void Graphics::Raise() const
  279. {
  280. if (!window_)
  281. return;
  282. SDL_RaiseWindow(window_);
  283. }
  284. void Graphics::BeginDumpShaders(const String& fileName)
  285. {
  286. shaderPrecache_ = new ShaderPrecache(context_, fileName);
  287. }
  288. void Graphics::EndDumpShaders()
  289. {
  290. shaderPrecache_.Reset();
  291. }
  292. void Graphics::PrecacheShaders(Deserializer& source)
  293. {
  294. URHO3D_PROFILE(PrecacheShaders);
  295. ShaderPrecache::LoadShaders(this, source);
  296. }
  297. void Graphics::SetShaderCacheDir(const String& path)
  298. {
  299. String trimmedPath = path.Trimmed();
  300. if (trimmedPath.Length())
  301. shaderCacheDir_ = AddTrailingSlash(trimmedPath);
  302. }
  303. void Graphics::AddGPUObject(GPUObject* object)
  304. {
  305. MutexLock lock(gpuObjectMutex_);
  306. gpuObjects_.Push(object);
  307. }
  308. void Graphics::RemoveGPUObject(GPUObject* object)
  309. {
  310. MutexLock lock(gpuObjectMutex_);
  311. gpuObjects_.Remove(object);
  312. }
  313. void* Graphics::ReserveScratchBuffer(unsigned size)
  314. {
  315. if (!size)
  316. return nullptr;
  317. if (size > maxScratchBufferRequest_)
  318. maxScratchBufferRequest_ = size;
  319. // First check for a free buffer that is large enough
  320. for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
  321. {
  322. if (!i->reserved_ && i->size_ >= size)
  323. {
  324. i->reserved_ = true;
  325. return i->data_.Get();
  326. }
  327. }
  328. // Then check if a free buffer can be resized
  329. for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
  330. {
  331. if (!i->reserved_)
  332. {
  333. i->data_ = new unsigned char[size];
  334. i->size_ = size;
  335. i->reserved_ = true;
  336. URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(size));
  337. return i->data_.Get();
  338. }
  339. }
  340. // Finally allocate a new buffer
  341. ScratchBuffer newBuffer;
  342. newBuffer.data_ = new unsigned char[size];
  343. newBuffer.size_ = size;
  344. newBuffer.reserved_ = true;
  345. scratchBuffers_.Push(newBuffer);
  346. URHO3D_LOGDEBUG("Allocated scratch buffer with size " + String(size));
  347. return newBuffer.data_.Get();
  348. }
  349. void Graphics::FreeScratchBuffer(void* buffer)
  350. {
  351. if (!buffer)
  352. return;
  353. for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
  354. {
  355. if (i->reserved_ && i->data_.Get() == buffer)
  356. {
  357. i->reserved_ = false;
  358. return;
  359. }
  360. }
  361. URHO3D_LOGWARNING("Reserved scratch buffer " + ToStringHex((unsigned)(size_t)buffer) + " not found");
  362. }
  363. void Graphics::CleanupScratchBuffers()
  364. {
  365. for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
  366. {
  367. if (!i->reserved_ && i->size_ > maxScratchBufferRequest_ * 2 && i->size_ >= 1024 * 1024)
  368. {
  369. i->data_ = maxScratchBufferRequest_ > 0 ? (new unsigned char[maxScratchBufferRequest_]) : nullptr;
  370. i->size_ = maxScratchBufferRequest_;
  371. URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(maxScratchBufferRequest_));
  372. }
  373. }
  374. maxScratchBufferRequest_ = 0;
  375. }
  376. void Graphics::CreateWindowIcon()
  377. {
  378. if (windowIcon_)
  379. {
  380. SDL_Surface* surface = windowIcon_->GetSDLSurface();
  381. if (surface)
  382. {
  383. SDL_SetWindowIcon(window_, surface);
  384. SDL_FreeSurface(surface);
  385. }
  386. }
  387. }
  388. void Graphics::AdjustScreenMode(int& newWidth, int& newHeight, ScreenModeParams& params, bool& maximize) const
  389. {
  390. // High DPI is supported only for OpenGL backend
  391. if (Graphics::GetGAPI() != GAPI_OPENGL)
  392. params.highDPI_ = false;
  393. #if defined(IOS) || defined(TVOS)
  394. // iOS and tvOS app always take the fullscreen (and with status bar hidden)
  395. params.fullscreen_ = true;
  396. #endif
  397. // Make sure monitor index is not bigger than the currently detected monitors
  398. const int numMonitors = SDL_GetNumVideoDisplays();
  399. if (params.monitor_ >= numMonitors || params.monitor_ < 0)
  400. params.monitor_ = 0; // this monitor is not present, use first monitor
  401. // Fullscreen or Borderless can not be resizable and cannot be maximized
  402. if (params.fullscreen_ || params.borderless_)
  403. {
  404. params.resizable_ = false;
  405. maximize = false;
  406. }
  407. // Borderless cannot be fullscreen, they are mutually exclusive
  408. if (params.borderless_)
  409. params.fullscreen_ = false;
  410. // On iOS window needs to be resizable to handle orientation changes properly
  411. #ifdef IOS
  412. if (!externalWindow_)
  413. params.resizable_ = true;
  414. #endif
  415. // Ensure that multisample factor is in valid range
  416. params.multiSample_ = NextPowerOfTwo(Clamp(params.multiSample_, 1, 16));
  417. // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size.
  418. // If zero in fullscreen, use desktop mode
  419. if (!newWidth || !newHeight)
  420. {
  421. if (params.fullscreen_ || params.borderless_)
  422. {
  423. SDL_DisplayMode mode;
  424. SDL_GetDesktopDisplayMode(params.monitor_, &mode);
  425. newWidth = mode.w;
  426. newHeight = mode.h;
  427. }
  428. else
  429. {
  430. newWidth = 1024;
  431. newHeight = 768;
  432. }
  433. }
  434. // Check fullscreen mode validity (desktop only). Use a closest match if not found
  435. #ifdef DESKTOP_GRAPHICS
  436. if (params.fullscreen_)
  437. {
  438. const PODVector<IntVector3> resolutions = GetResolutions(params.monitor_);
  439. if (!resolutions.Empty())
  440. {
  441. const unsigned bestResolution = FindBestResolutionIndex(params.monitor_,
  442. newWidth, newHeight, params.refreshRate_);
  443. newWidth = resolutions[bestResolution].x_;
  444. newHeight = resolutions[bestResolution].y_;
  445. params.refreshRate_ = resolutions[bestResolution].z_;
  446. }
  447. }
  448. else
  449. {
  450. // If windowed, use the same refresh rate as desktop
  451. SDL_DisplayMode mode;
  452. SDL_GetDesktopDisplayMode(params.monitor_, &mode);
  453. params.refreshRate_ = mode.refresh_rate;
  454. }
  455. #endif
  456. }
  457. void Graphics::OnScreenModeChanged()
  458. {
  459. #ifdef URHO3D_LOGGING
  460. String msg;
  461. msg.AppendWithFormat("Set screen mode %dx%d rate %d Hz %s monitor %d", width_, height_, screenParams_.refreshRate_,
  462. (screenParams_.fullscreen_ ? "fullscreen" : "windowed"), screenParams_.monitor_);
  463. if (screenParams_.borderless_)
  464. msg.Append(" borderless");
  465. if (screenParams_.resizable_)
  466. msg.Append(" resizable");
  467. if (screenParams_.highDPI_)
  468. msg.Append(" highDPI");
  469. if (screenParams_.multiSample_ > 1)
  470. msg.AppendWithFormat(" multisample %d", screenParams_.multiSample_);
  471. URHO3D_LOGINFO(msg);
  472. #endif
  473. using namespace ScreenMode;
  474. VariantMap& eventData = GetEventDataMap();
  475. eventData[P_WIDTH] = width_;
  476. eventData[P_HEIGHT] = height_;
  477. eventData[P_FULLSCREEN] = screenParams_.fullscreen_;
  478. eventData[P_BORDERLESS] = screenParams_.borderless_;
  479. eventData[P_RESIZABLE] = screenParams_.resizable_;
  480. eventData[P_HIGHDPI] = screenParams_.highDPI_;
  481. eventData[P_MONITOR] = screenParams_.monitor_;
  482. eventData[P_REFRESHRATE] = screenParams_.refreshRate_;
  483. SendEvent(E_SCREENMODE, eventData);
  484. }
  485. Graphics::Graphics(Context* context, GAPI gapi)
  486. : Object(context)
  487. {
  488. Graphics::gapi = gapi;
  489. #ifdef URHO3D_OPENGL
  490. if (gapi == GAPI_OPENGL)
  491. {
  492. Constructor_OGL();
  493. return;
  494. }
  495. #endif
  496. #ifdef URHO3D_D3D9
  497. if (gapi == GAPI_D3D9)
  498. {
  499. Constructor_D3D9();
  500. return;
  501. }
  502. #endif
  503. #ifdef URHO3D_D3D11
  504. if (gapi == GAPI_D3D11)
  505. {
  506. Constructor_D3D11();
  507. return;
  508. }
  509. #endif
  510. }
  511. Graphics::~Graphics()
  512. {
  513. GAPI gapi = Graphics::GetGAPI();
  514. #ifdef URHO3D_OPENGL
  515. if (gapi == GAPI_OPENGL)
  516. {
  517. Destructor_OGL();
  518. return;
  519. }
  520. #endif
  521. #ifdef URHO3D_D3D9
  522. if (gapi == GAPI_D3D9)
  523. {
  524. Destructor_D3D9();
  525. return;
  526. }
  527. #endif
  528. #ifdef URHO3D_D3D11
  529. if (gapi == GAPI_D3D11)
  530. {
  531. Destructor_D3D11();
  532. return;
  533. }
  534. #endif
  535. }
  536. bool Graphics::SetScreenMode(int width, int height, const ScreenModeParams& params, bool maximize)
  537. {
  538. GAPI gapi = Graphics::GetGAPI();
  539. #ifdef URHO3D_OPENGL
  540. if (gapi == GAPI_OPENGL)
  541. return SetScreenMode_OGL(width, height, params, maximize);
  542. #endif
  543. #ifdef URHO3D_D3D9
  544. if (gapi == GAPI_D3D9)
  545. return SetScreenMode_D3D9(width, height, params, maximize);;
  546. #endif
  547. #ifdef URHO3D_D3D11
  548. if (gapi == GAPI_D3D11)
  549. return SetScreenMode_D3D11(width, height, params, maximize);;
  550. #endif
  551. return {}; // Prevent warning
  552. }
  553. void Graphics::SetSRGB(bool enable)
  554. {
  555. GAPI gapi = Graphics::GetGAPI();
  556. #ifdef URHO3D_OPENGL
  557. if (gapi == GAPI_OPENGL)
  558. return SetSRGB_OGL(enable);
  559. #endif
  560. #ifdef URHO3D_D3D9
  561. if (gapi == GAPI_D3D9)
  562. return SetSRGB_D3D9(enable);
  563. #endif
  564. #ifdef URHO3D_D3D11
  565. if (gapi == GAPI_D3D11)
  566. return SetSRGB_D3D11(enable);
  567. #endif
  568. }
  569. void Graphics::SetDither(bool enable)
  570. {
  571. GAPI gapi = Graphics::GetGAPI();
  572. #ifdef URHO3D_OPENGL
  573. if (gapi == GAPI_OPENGL)
  574. return SetDither_OGL(enable);
  575. #endif
  576. #ifdef URHO3D_D3D9
  577. if (gapi == GAPI_D3D9)
  578. return SetDither_D3D9(enable);
  579. #endif
  580. #ifdef URHO3D_D3D11
  581. if (gapi == GAPI_D3D11)
  582. return SetDither_D3D11(enable);
  583. #endif
  584. }
  585. void Graphics::SetFlushGPU(bool enable)
  586. {
  587. GAPI gapi = Graphics::GetGAPI();
  588. #ifdef URHO3D_OPENGL
  589. if (gapi == GAPI_OPENGL)
  590. return SetFlushGPU_OGL(enable);
  591. #endif
  592. #ifdef URHO3D_D3D9
  593. if (gapi == GAPI_D3D9)
  594. return SetFlushGPU_D3D9(enable);;
  595. #endif
  596. #ifdef URHO3D_D3D11
  597. if (gapi == GAPI_D3D11)
  598. return SetFlushGPU_D3D11(enable);;
  599. #endif
  600. }
  601. void Graphics::SetForceGL2(bool enable)
  602. {
  603. GAPI gapi = Graphics::GetGAPI();
  604. #ifdef URHO3D_OPENGL
  605. if (gapi == GAPI_OPENGL)
  606. return SetForceGL2_OGL(enable);
  607. #endif
  608. #ifdef URHO3D_D3D9
  609. if (gapi == GAPI_D3D9)
  610. return SetForceGL2_D3D9(enable);
  611. #endif
  612. #ifdef URHO3D_D3D11
  613. if (gapi == GAPI_D3D11)
  614. return SetForceGL2_D3D11(enable);
  615. #endif
  616. }
  617. void Graphics::Close()
  618. {
  619. GAPI gapi = Graphics::GetGAPI();
  620. #ifdef URHO3D_OPENGL
  621. if (gapi == GAPI_OPENGL)
  622. return Close_OGL();
  623. #endif
  624. #ifdef URHO3D_D3D9
  625. if (gapi == GAPI_D3D9)
  626. return Close_D3D9();
  627. #endif
  628. #ifdef URHO3D_D3D11
  629. if (gapi == GAPI_D3D11)
  630. return Close_D3D11();
  631. #endif
  632. }
  633. bool Graphics::TakeScreenShot(Image& destImage)
  634. {
  635. GAPI gapi = Graphics::GetGAPI();
  636. #ifdef URHO3D_OPENGL
  637. if (gapi == GAPI_OPENGL)
  638. return TakeScreenShot_OGL(destImage);
  639. #endif
  640. #ifdef URHO3D_D3D9
  641. if (gapi == GAPI_D3D9)
  642. return TakeScreenShot_D3D9(destImage);
  643. #endif
  644. #ifdef URHO3D_D3D11
  645. if (gapi == GAPI_D3D11)
  646. return TakeScreenShot_D3D11(destImage);
  647. #endif
  648. return {}; // Prevent warning
  649. }
  650. bool Graphics::BeginFrame()
  651. {
  652. GAPI gapi = Graphics::GetGAPI();
  653. #ifdef URHO3D_OPENGL
  654. if (gapi == GAPI_OPENGL)
  655. return BeginFrame_OGL();
  656. #endif
  657. #ifdef URHO3D_D3D9
  658. if (gapi == GAPI_D3D9)
  659. return BeginFrame_D3D9();
  660. #endif
  661. #ifdef URHO3D_D3D11
  662. if (gapi == GAPI_D3D11)
  663. return BeginFrame_D3D11();
  664. #endif
  665. return {}; // Prevent warning
  666. }
  667. void Graphics::EndFrame()
  668. {
  669. GAPI gapi = Graphics::GetGAPI();
  670. #ifdef URHO3D_OPENGL
  671. if (gapi == GAPI_OPENGL)
  672. return EndFrame_OGL();
  673. #endif
  674. #ifdef URHO3D_D3D9
  675. if (gapi == GAPI_D3D9)
  676. return EndFrame_D3D9();
  677. #endif
  678. #ifdef URHO3D_D3D11
  679. if (gapi == GAPI_D3D11)
  680. return EndFrame_D3D11();
  681. #endif
  682. }
  683. void Graphics::Clear(ClearTargetFlags flags, const Color& color, float depth, unsigned stencil)
  684. {
  685. GAPI gapi = Graphics::GetGAPI();
  686. #ifdef URHO3D_OPENGL
  687. if (gapi == GAPI_OPENGL)
  688. return Clear_OGL(flags, color, depth, stencil);
  689. #endif
  690. #ifdef URHO3D_D3D9
  691. if (gapi == GAPI_D3D9)
  692. return Clear_D3D9(flags, color, depth, stencil);
  693. #endif
  694. #ifdef URHO3D_D3D11
  695. if (gapi == GAPI_D3D11)
  696. return Clear_D3D11(flags, color, depth, stencil);
  697. #endif
  698. }
  699. bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
  700. {
  701. GAPI gapi = Graphics::GetGAPI();
  702. #ifdef URHO3D_OPENGL
  703. if (gapi == GAPI_OPENGL)
  704. return ResolveToTexture_OGL(destination, viewport);
  705. #endif
  706. #ifdef URHO3D_D3D9
  707. if (gapi == GAPI_D3D9)
  708. return ResolveToTexture_D3D9(destination, viewport);
  709. #endif
  710. #ifdef URHO3D_D3D11
  711. if (gapi == GAPI_D3D11)
  712. return ResolveToTexture_D3D11(destination, viewport);
  713. #endif
  714. return {}; // Prevent warning
  715. }
  716. bool Graphics::ResolveToTexture(Texture2D* texture)
  717. {
  718. GAPI gapi = Graphics::GetGAPI();
  719. #ifdef URHO3D_OPENGL
  720. if (gapi == GAPI_OPENGL)
  721. return ResolveToTexture_OGL(texture);
  722. #endif
  723. #ifdef URHO3D_D3D9
  724. if (gapi == GAPI_D3D9)
  725. return ResolveToTexture_D3D9(texture);
  726. #endif
  727. #ifdef URHO3D_D3D11
  728. if (gapi == GAPI_D3D11)
  729. return ResolveToTexture_D3D11(texture);
  730. #endif
  731. return {}; // Prevent warning
  732. }
  733. bool Graphics::ResolveToTexture(TextureCube* texture)
  734. {
  735. GAPI gapi = Graphics::GetGAPI();
  736. #ifdef URHO3D_OPENGL
  737. if (gapi == GAPI_OPENGL)
  738. return ResolveToTexture_OGL(texture);
  739. #endif
  740. #ifdef URHO3D_D3D9
  741. if (gapi == GAPI_D3D9)
  742. return ResolveToTexture_D3D9(texture);
  743. #endif
  744. #ifdef URHO3D_D3D11
  745. if (gapi == GAPI_D3D11)
  746. return ResolveToTexture_D3D11(texture);
  747. #endif
  748. return {}; // Prevent warning
  749. }
  750. void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
  751. {
  752. GAPI gapi = Graphics::GetGAPI();
  753. #ifdef URHO3D_OPENGL
  754. if (gapi == GAPI_OPENGL)
  755. return Draw_OGL(type, vertexStart, vertexCount);
  756. #endif
  757. #ifdef URHO3D_D3D9
  758. if (gapi == GAPI_D3D9)
  759. return Draw_D3D9(type, vertexStart, vertexCount);;
  760. #endif
  761. #ifdef URHO3D_D3D11
  762. if (gapi == GAPI_D3D11)
  763. return Draw_D3D11(type, vertexStart, vertexCount);;
  764. #endif
  765. }
  766. void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount)
  767. {
  768. GAPI gapi = Graphics::GetGAPI();
  769. #ifdef URHO3D_OPENGL
  770. if (gapi == GAPI_OPENGL)
  771. return Draw_OGL(type, indexStart, indexCount, minVertex, vertexCount);
  772. #endif
  773. #ifdef URHO3D_D3D9
  774. if (gapi == GAPI_D3D9)
  775. return Draw_D3D9(type, indexStart, indexCount, minVertex, vertexCount);
  776. #endif
  777. #ifdef URHO3D_D3D11
  778. if (gapi == GAPI_D3D11)
  779. return Draw_D3D11(type, indexStart, indexCount, minVertex, vertexCount);
  780. #endif
  781. }
  782. void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount)
  783. {
  784. GAPI gapi = Graphics::GetGAPI();
  785. #ifdef URHO3D_OPENGL
  786. if (gapi == GAPI_OPENGL)
  787. return Draw_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
  788. #endif
  789. #ifdef URHO3D_D3D9
  790. if (gapi == GAPI_D3D9)
  791. return Draw_D3D9(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
  792. #endif
  793. #ifdef URHO3D_D3D11
  794. if (gapi == GAPI_D3D11)
  795. return Draw_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
  796. #endif
  797. }
  798. void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount)
  799. {
  800. GAPI gapi = Graphics::GetGAPI();
  801. #ifdef URHO3D_OPENGL
  802. if (gapi == GAPI_OPENGL)
  803. return DrawInstanced_OGL(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
  804. #endif
  805. #ifdef URHO3D_D3D9
  806. if (gapi == GAPI_D3D9)
  807. return DrawInstanced_D3D9(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
  808. #endif
  809. #ifdef URHO3D_D3D11
  810. if (gapi == GAPI_D3D11)
  811. return DrawInstanced_D3D11(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
  812. #endif
  813. }
  814. void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex,
  815. unsigned vertexCount, unsigned instanceCount)
  816. {
  817. GAPI gapi = Graphics::GetGAPI();
  818. #ifdef URHO3D_OPENGL
  819. if (gapi == GAPI_OPENGL)
  820. return DrawInstanced_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
  821. #endif
  822. #ifdef URHO3D_D3D9
  823. if (gapi == GAPI_D3D9)
  824. return DrawInstanced_D3D9(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
  825. #endif
  826. #ifdef URHO3D_D3D11
  827. if (gapi == GAPI_D3D11)
  828. return DrawInstanced_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
  829. #endif
  830. }
  831. void Graphics::SetVertexBuffer(VertexBuffer* buffer)
  832. {
  833. GAPI gapi = Graphics::GetGAPI();
  834. #ifdef URHO3D_OPENGL
  835. if (gapi == GAPI_OPENGL)
  836. return SetVertexBuffer_OGL(buffer);
  837. #endif
  838. #ifdef URHO3D_D3D9
  839. if (gapi == GAPI_D3D9)
  840. return SetVertexBuffer_D3D9(buffer);
  841. #endif
  842. #ifdef URHO3D_D3D11
  843. if (gapi == GAPI_D3D11)
  844. return SetVertexBuffer_D3D11(buffer);
  845. #endif
  846. }
  847. bool Graphics::SetVertexBuffers(const PODVector<VertexBuffer*>& buffers, unsigned instanceOffset)
  848. {
  849. GAPI gapi = Graphics::GetGAPI();
  850. #ifdef URHO3D_OPENGL
  851. if (gapi == GAPI_OPENGL)
  852. return SetVertexBuffers_OGL(buffers, instanceOffset);
  853. #endif
  854. #ifdef URHO3D_D3D9
  855. if (gapi == GAPI_D3D9)
  856. return SetVertexBuffers_D3D9(buffers, instanceOffset);
  857. #endif
  858. #ifdef URHO3D_D3D11
  859. if (gapi == GAPI_D3D11)
  860. return SetVertexBuffers_D3D11(buffers, instanceOffset);
  861. #endif
  862. return {}; // Prevent warning
  863. }
  864. bool Graphics::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer>>& buffers, unsigned instanceOffset)
  865. {
  866. GAPI gapi = Graphics::GetGAPI();
  867. #ifdef URHO3D_OPENGL
  868. if (gapi == GAPI_OPENGL)
  869. return SetVertexBuffers_OGL(buffers, instanceOffset);
  870. #endif
  871. #ifdef URHO3D_D3D9
  872. if (gapi == GAPI_D3D9)
  873. return SetVertexBuffers_D3D9(buffers, instanceOffset);
  874. #endif
  875. #ifdef URHO3D_D3D11
  876. if (gapi == GAPI_D3D11)
  877. return SetVertexBuffers_D3D11(buffers, instanceOffset);
  878. #endif
  879. return {}; // Prevent warning
  880. }
  881. void Graphics::SetIndexBuffer(IndexBuffer* buffer)
  882. {
  883. GAPI gapi = Graphics::GetGAPI();
  884. #ifdef URHO3D_OPENGL
  885. if (gapi == GAPI_OPENGL)
  886. return SetIndexBuffer_OGL(buffer);
  887. #endif
  888. #ifdef URHO3D_D3D9
  889. if (gapi == GAPI_D3D9)
  890. return SetIndexBuffer_D3D9(buffer);
  891. #endif
  892. #ifdef URHO3D_D3D11
  893. if (gapi == GAPI_D3D11)
  894. return SetIndexBuffer_D3D11(buffer);
  895. #endif
  896. }
  897. void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
  898. {
  899. GAPI gapi = Graphics::GetGAPI();
  900. #ifdef URHO3D_OPENGL
  901. if (gapi == GAPI_OPENGL)
  902. return SetShaders_OGL(vs, ps);
  903. #endif
  904. #ifdef URHO3D_D3D9
  905. if (gapi == GAPI_D3D9)
  906. return SetShaders_D3D9(vs, ps);
  907. #endif
  908. #ifdef URHO3D_D3D11
  909. if (gapi == GAPI_D3D11)
  910. return SetShaders_D3D11(vs, ps);
  911. #endif
  912. }
  913. void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
  914. {
  915. GAPI gapi = Graphics::GetGAPI();
  916. #ifdef URHO3D_OPENGL
  917. if (gapi == GAPI_OPENGL)
  918. return SetShaderParameter_OGL(param, data, count);
  919. #endif
  920. #ifdef URHO3D_D3D9
  921. if (gapi == GAPI_D3D9)
  922. return SetShaderParameter_D3D9(param, data, count);
  923. #endif
  924. #ifdef URHO3D_D3D11
  925. if (gapi == GAPI_D3D11)
  926. return SetShaderParameter_D3D11(param, data, count);
  927. #endif
  928. }
  929. void Graphics::SetShaderParameter(StringHash param, float value)
  930. {
  931. GAPI gapi = Graphics::GetGAPI();
  932. #ifdef URHO3D_OPENGL
  933. if (gapi == GAPI_OPENGL)
  934. return SetShaderParameter_OGL(param, value);
  935. #endif
  936. #ifdef URHO3D_D3D9
  937. if (gapi == GAPI_D3D9)
  938. return SetShaderParameter_D3D9(param, value);
  939. #endif
  940. #ifdef URHO3D_D3D11
  941. if (gapi == GAPI_D3D11)
  942. return SetShaderParameter_D3D11(param, value);
  943. #endif
  944. }
  945. void Graphics::SetShaderParameter(StringHash param, int value)
  946. {
  947. GAPI gapi = Graphics::GetGAPI();
  948. #ifdef URHO3D_OPENGL
  949. if (gapi == GAPI_OPENGL)
  950. return SetShaderParameter_OGL(param, value);
  951. #endif
  952. #ifdef URHO3D_D3D9
  953. if (gapi == GAPI_D3D9)
  954. return SetShaderParameter_D3D9(param, value);
  955. #endif
  956. #ifdef URHO3D_D3D11
  957. if (gapi == GAPI_D3D11)
  958. return SetShaderParameter_D3D11(param, value);
  959. #endif
  960. }
  961. void Graphics::SetShaderParameter(StringHash param, bool value)
  962. {
  963. GAPI gapi = Graphics::GetGAPI();
  964. #ifdef URHO3D_OPENGL
  965. if (gapi == GAPI_OPENGL)
  966. return SetShaderParameter_OGL(param, value);
  967. #endif
  968. #ifdef URHO3D_D3D9
  969. if (gapi == GAPI_D3D9)
  970. return SetShaderParameter_D3D9(param, value);
  971. #endif
  972. #ifdef URHO3D_D3D11
  973. if (gapi == GAPI_D3D11)
  974. return SetShaderParameter_D3D11(param, value);
  975. #endif
  976. }
  977. void Graphics::SetShaderParameter(StringHash param, const Color& color)
  978. {
  979. GAPI gapi = Graphics::GetGAPI();
  980. #ifdef URHO3D_OPENGL
  981. if (gapi == GAPI_OPENGL)
  982. return SetShaderParameter_OGL(param, color);
  983. #endif
  984. #ifdef URHO3D_D3D9
  985. if (gapi == GAPI_D3D9)
  986. return SetShaderParameter_D3D9(param, color);
  987. #endif
  988. #ifdef URHO3D_D3D11
  989. if (gapi == GAPI_D3D11)
  990. return SetShaderParameter_D3D11(param, color);
  991. #endif
  992. }
  993. void Graphics::SetShaderParameter(StringHash param, const Vector2& vector)
  994. {
  995. GAPI gapi = Graphics::GetGAPI();
  996. #ifdef URHO3D_OPENGL
  997. if (gapi == GAPI_OPENGL)
  998. return SetShaderParameter_OGL(param, vector);
  999. #endif
  1000. #ifdef URHO3D_D3D9
  1001. if (gapi == GAPI_D3D9)
  1002. return SetShaderParameter_D3D9(param, vector);
  1003. #endif
  1004. #ifdef URHO3D_D3D11
  1005. if (gapi == GAPI_D3D11)
  1006. return SetShaderParameter_D3D11(param, vector);
  1007. #endif
  1008. }
  1009. void Graphics::SetShaderParameter(StringHash param, const Matrix3& matrix)
  1010. {
  1011. GAPI gapi = Graphics::GetGAPI();
  1012. #ifdef URHO3D_OPENGL
  1013. if (gapi == GAPI_OPENGL)
  1014. return SetShaderParameter_OGL(param, matrix);
  1015. #endif
  1016. #ifdef URHO3D_D3D9
  1017. if (gapi == GAPI_D3D9)
  1018. return SetShaderParameter_D3D9(param, matrix);
  1019. #endif
  1020. #ifdef URHO3D_D3D11
  1021. if (gapi == GAPI_D3D11)
  1022. return SetShaderParameter_D3D11(param, matrix);
  1023. #endif
  1024. }
  1025. void Graphics::SetShaderParameter(StringHash param, const Vector3& vector)
  1026. {
  1027. GAPI gapi = Graphics::GetGAPI();
  1028. #ifdef URHO3D_OPENGL
  1029. if (gapi == GAPI_OPENGL)
  1030. return SetShaderParameter_OGL(param, vector);
  1031. #endif
  1032. #ifdef URHO3D_D3D9
  1033. if (gapi == GAPI_D3D9)
  1034. return SetShaderParameter_D3D9(param, vector);
  1035. #endif
  1036. #ifdef URHO3D_D3D11
  1037. if (gapi == GAPI_D3D11)
  1038. return SetShaderParameter_D3D11(param, vector);
  1039. #endif
  1040. }
  1041. void Graphics::SetShaderParameter(StringHash param, const Matrix4& matrix)
  1042. {
  1043. GAPI gapi = Graphics::GetGAPI();
  1044. #ifdef URHO3D_OPENGL
  1045. if (gapi == GAPI_OPENGL)
  1046. return SetShaderParameter_OGL(param, matrix);
  1047. #endif
  1048. #ifdef URHO3D_D3D9
  1049. if (gapi == GAPI_D3D9)
  1050. return SetShaderParameter_D3D9(param, matrix);
  1051. #endif
  1052. #ifdef URHO3D_D3D11
  1053. if (gapi == GAPI_D3D11)
  1054. return SetShaderParameter_D3D11(param, matrix);
  1055. #endif
  1056. }
  1057. void Graphics::SetShaderParameter(StringHash param, const Vector4& vector)
  1058. {
  1059. GAPI gapi = Graphics::GetGAPI();
  1060. #ifdef URHO3D_OPENGL
  1061. if (gapi == GAPI_OPENGL)
  1062. return SetShaderParameter_OGL(param, vector);
  1063. #endif
  1064. #ifdef URHO3D_D3D9
  1065. if (gapi == GAPI_D3D9)
  1066. return SetShaderParameter_D3D9(param, vector);
  1067. #endif
  1068. #ifdef URHO3D_D3D11
  1069. if (gapi == GAPI_D3D11)
  1070. return SetShaderParameter_D3D11(param, vector);
  1071. #endif
  1072. }
  1073. void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
  1074. {
  1075. GAPI gapi = Graphics::GetGAPI();
  1076. #ifdef URHO3D_OPENGL
  1077. if (gapi == GAPI_OPENGL)
  1078. return SetShaderParameter_OGL(param, matrix);
  1079. #endif
  1080. #ifdef URHO3D_D3D9
  1081. if (gapi == GAPI_D3D9)
  1082. return SetShaderParameter_D3D9(param, matrix);
  1083. #endif
  1084. #ifdef URHO3D_D3D11
  1085. if (gapi == GAPI_D3D11)
  1086. return SetShaderParameter_D3D11(param, matrix);
  1087. #endif
  1088. }
  1089. bool Graphics::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
  1090. {
  1091. GAPI gapi = Graphics::GetGAPI();
  1092. #ifdef URHO3D_OPENGL
  1093. if (gapi == GAPI_OPENGL)
  1094. return NeedParameterUpdate_OGL(group, source);
  1095. #endif
  1096. #ifdef URHO3D_D3D9
  1097. if (gapi == GAPI_D3D9)
  1098. return NeedParameterUpdate_D3D9(group, source);
  1099. #endif
  1100. #ifdef URHO3D_D3D11
  1101. if (gapi == GAPI_D3D11)
  1102. return NeedParameterUpdate_D3D11(group, source);
  1103. #endif
  1104. return {}; // Prevent warning
  1105. }
  1106. bool Graphics::HasShaderParameter(StringHash param)
  1107. {
  1108. GAPI gapi = Graphics::GetGAPI();
  1109. #ifdef URHO3D_OPENGL
  1110. if (gapi == GAPI_OPENGL)
  1111. return HasShaderParameter_OGL(param);
  1112. #endif
  1113. #ifdef URHO3D_D3D9
  1114. if (gapi == GAPI_D3D9)
  1115. return HasShaderParameter_D3D9(param);
  1116. #endif
  1117. #ifdef URHO3D_D3D11
  1118. if (gapi == GAPI_D3D11)
  1119. return HasShaderParameter_D3D11(param);
  1120. #endif
  1121. return {}; // Prevent warning
  1122. }
  1123. bool Graphics::HasTextureUnit(TextureUnit unit)
  1124. {
  1125. GAPI gapi = Graphics::GetGAPI();
  1126. #ifdef URHO3D_OPENGL
  1127. if (gapi == GAPI_OPENGL)
  1128. return HasTextureUnit_OGL(unit);
  1129. #endif
  1130. #ifdef URHO3D_D3D9
  1131. if (gapi == GAPI_D3D9)
  1132. return HasTextureUnit_D3D9(unit);
  1133. #endif
  1134. #ifdef URHO3D_D3D11
  1135. if (gapi == GAPI_D3D11)
  1136. return HasTextureUnit_D3D11(unit);
  1137. #endif
  1138. return {}; // Prevent warning
  1139. }
  1140. void Graphics::ClearParameterSource(ShaderParameterGroup group)
  1141. {
  1142. GAPI gapi = Graphics::GetGAPI();
  1143. #ifdef URHO3D_OPENGL
  1144. if (gapi == GAPI_OPENGL)
  1145. return ClearParameterSource_OGL(group);
  1146. #endif
  1147. #ifdef URHO3D_D3D9
  1148. if (gapi == GAPI_D3D9)
  1149. return ClearParameterSource_D3D9(group);
  1150. #endif
  1151. #ifdef URHO3D_D3D11
  1152. if (gapi == GAPI_D3D11)
  1153. return ClearParameterSource_D3D11(group);
  1154. #endif
  1155. }
  1156. void Graphics::ClearParameterSources()
  1157. {
  1158. GAPI gapi = Graphics::GetGAPI();
  1159. #ifdef URHO3D_OPENGL
  1160. if (gapi == GAPI_OPENGL)
  1161. return ClearParameterSources_OGL();
  1162. #endif
  1163. #ifdef URHO3D_D3D9
  1164. if (gapi == GAPI_D3D9)
  1165. return ClearParameterSources_D3D9();
  1166. #endif
  1167. #ifdef URHO3D_D3D11
  1168. if (gapi == GAPI_D3D11)
  1169. return ClearParameterSources_D3D11();
  1170. #endif
  1171. }
  1172. void Graphics::ClearTransformSources()
  1173. {
  1174. GAPI gapi = Graphics::GetGAPI();
  1175. #ifdef URHO3D_OPENGL
  1176. if (gapi == GAPI_OPENGL)
  1177. return ClearTransformSources_OGL();
  1178. #endif
  1179. #ifdef URHO3D_D3D9
  1180. if (gapi == GAPI_D3D9)
  1181. return ClearTransformSources_D3D9();
  1182. #endif
  1183. #ifdef URHO3D_D3D11
  1184. if (gapi == GAPI_D3D11)
  1185. return ClearTransformSources_D3D11();
  1186. #endif
  1187. }
  1188. void Graphics::SetTexture(unsigned index, Texture* texture)
  1189. {
  1190. GAPI gapi = Graphics::GetGAPI();
  1191. #ifdef URHO3D_OPENGL
  1192. if (gapi == GAPI_OPENGL)
  1193. return SetTexture_OGL(index, texture);
  1194. #endif
  1195. #ifdef URHO3D_D3D9
  1196. if (gapi == GAPI_D3D9)
  1197. return SetTexture_D3D9(index, texture);
  1198. #endif
  1199. #ifdef URHO3D_D3D11
  1200. if (gapi == GAPI_D3D11)
  1201. return SetTexture_D3D11(index, texture);
  1202. #endif
  1203. }
  1204. void Graphics::SetDefaultTextureFilterMode(TextureFilterMode mode)
  1205. {
  1206. GAPI gapi = Graphics::GetGAPI();
  1207. #ifdef URHO3D_OPENGL
  1208. if (gapi == GAPI_OPENGL)
  1209. return SetDefaultTextureFilterMode_OGL(mode);
  1210. #endif
  1211. #ifdef URHO3D_D3D9
  1212. if (gapi == GAPI_D3D9)
  1213. return SetDefaultTextureFilterMode_D3D9(mode);
  1214. #endif
  1215. #ifdef URHO3D_D3D11
  1216. if (gapi == GAPI_D3D11)
  1217. return SetDefaultTextureFilterMode_D3D11(mode);
  1218. #endif
  1219. }
  1220. void Graphics::SetDefaultTextureAnisotropy(unsigned level)
  1221. {
  1222. GAPI gapi = Graphics::GetGAPI();
  1223. #ifdef URHO3D_OPENGL
  1224. if (gapi == GAPI_OPENGL)
  1225. return SetDefaultTextureAnisotropy_OGL(level);
  1226. #endif
  1227. #ifdef URHO3D_D3D9
  1228. if (gapi == GAPI_D3D9)
  1229. return SetDefaultTextureAnisotropy_D3D9(level);
  1230. #endif
  1231. #ifdef URHO3D_D3D11
  1232. if (gapi == GAPI_D3D11)
  1233. return SetDefaultTextureAnisotropy_D3D11(level);
  1234. #endif
  1235. }
  1236. void Graphics::ResetRenderTargets()
  1237. {
  1238. GAPI gapi = Graphics::GetGAPI();
  1239. #ifdef URHO3D_OPENGL
  1240. if (gapi == GAPI_OPENGL)
  1241. return ResetRenderTargets_OGL();
  1242. #endif
  1243. #ifdef URHO3D_D3D9
  1244. if (gapi == GAPI_D3D9)
  1245. return ResetRenderTargets_D3D9();
  1246. #endif
  1247. #ifdef URHO3D_D3D11
  1248. if (gapi == GAPI_D3D11)
  1249. return ResetRenderTargets_D3D11();
  1250. #endif
  1251. }
  1252. void Graphics::ResetRenderTarget(unsigned index)
  1253. {
  1254. GAPI gapi = Graphics::GetGAPI();
  1255. #ifdef URHO3D_OPENGL
  1256. if (gapi == GAPI_OPENGL)
  1257. return ResetRenderTarget_OGL(index);
  1258. #endif
  1259. #ifdef URHO3D_D3D9
  1260. if (gapi == GAPI_D3D9)
  1261. return ResetRenderTarget_D3D9(index);
  1262. #endif
  1263. #ifdef URHO3D_D3D11
  1264. if (gapi == GAPI_D3D11)
  1265. return ResetRenderTarget_D3D11(index);
  1266. #endif
  1267. }
  1268. void Graphics::ResetDepthStencil()
  1269. {
  1270. GAPI gapi = Graphics::GetGAPI();
  1271. #ifdef URHO3D_OPENGL
  1272. if (gapi == GAPI_OPENGL)
  1273. return ResetDepthStencil_OGL();
  1274. #endif
  1275. #ifdef URHO3D_D3D9
  1276. if (gapi == GAPI_D3D9)
  1277. return ResetDepthStencil_D3D9();
  1278. #endif
  1279. #ifdef URHO3D_D3D11
  1280. if (gapi == GAPI_D3D11)
  1281. return ResetDepthStencil_D3D11();
  1282. #endif
  1283. }
  1284. void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
  1285. {
  1286. GAPI gapi = Graphics::GetGAPI();
  1287. #ifdef URHO3D_OPENGL
  1288. if (gapi == GAPI_OPENGL)
  1289. return SetRenderTarget_OGL(index, renderTarget);
  1290. #endif
  1291. #ifdef URHO3D_D3D9
  1292. if (gapi == GAPI_D3D9)
  1293. return SetRenderTarget_D3D9(index, renderTarget);
  1294. #endif
  1295. #ifdef URHO3D_D3D11
  1296. if (gapi == GAPI_D3D11)
  1297. return SetRenderTarget_D3D11(index, renderTarget);
  1298. #endif
  1299. }
  1300. void Graphics::SetRenderTarget(unsigned index, Texture2D* texture)
  1301. {
  1302. GAPI gapi = Graphics::GetGAPI();
  1303. #ifdef URHO3D_OPENGL
  1304. if (gapi == GAPI_OPENGL)
  1305. return SetRenderTarget_OGL(index, texture);
  1306. #endif
  1307. #ifdef URHO3D_D3D9
  1308. if (gapi == GAPI_D3D9)
  1309. return SetRenderTarget_D3D9(index, texture);
  1310. #endif
  1311. #ifdef URHO3D_D3D11
  1312. if (gapi == GAPI_D3D11)
  1313. return SetRenderTarget_D3D11(index, texture);
  1314. #endif
  1315. }
  1316. void Graphics::SetDepthStencil(RenderSurface* depthStencil)
  1317. {
  1318. GAPI gapi = Graphics::GetGAPI();
  1319. #ifdef URHO3D_OPENGL
  1320. if (gapi == GAPI_OPENGL)
  1321. return SetDepthStencil_OGL(depthStencil);
  1322. #endif
  1323. #ifdef URHO3D_D3D9
  1324. if (gapi == GAPI_D3D9)
  1325. return SetDepthStencil_D3D9(depthStencil);
  1326. #endif
  1327. #ifdef URHO3D_D3D11
  1328. if (gapi == GAPI_D3D11)
  1329. return SetDepthStencil_D3D11(depthStencil);
  1330. #endif
  1331. }
  1332. void Graphics::SetDepthStencil(Texture2D* texture)
  1333. {
  1334. GAPI gapi = Graphics::GetGAPI();
  1335. #ifdef URHO3D_OPENGL
  1336. if (gapi == GAPI_OPENGL)
  1337. return SetDepthStencil_OGL(texture);
  1338. #endif
  1339. #ifdef URHO3D_D3D9
  1340. if (gapi == GAPI_D3D9)
  1341. return SetDepthStencil_D3D9(texture);
  1342. #endif
  1343. #ifdef URHO3D_D3D11
  1344. if (gapi == GAPI_D3D11)
  1345. return SetDepthStencil_D3D11(texture);
  1346. #endif
  1347. }
  1348. void Graphics::SetViewport(const IntRect& rect)
  1349. {
  1350. GAPI gapi = Graphics::GetGAPI();
  1351. #ifdef URHO3D_OPENGL
  1352. if (gapi == GAPI_OPENGL)
  1353. return SetViewport_OGL(rect);
  1354. #endif
  1355. #ifdef URHO3D_D3D9
  1356. if (gapi == GAPI_D3D9)
  1357. return SetViewport_D3D9(rect);
  1358. #endif
  1359. #ifdef URHO3D_D3D11
  1360. if (gapi == GAPI_D3D11)
  1361. return SetViewport_D3D11(rect);
  1362. #endif
  1363. }
  1364. void Graphics::SetBlendMode(BlendMode mode, bool alphaToCoverage)
  1365. {
  1366. GAPI gapi = Graphics::GetGAPI();
  1367. #ifdef URHO3D_OPENGL
  1368. if (gapi == GAPI_OPENGL)
  1369. return SetBlendMode_OGL(mode, alphaToCoverage);
  1370. #endif
  1371. #ifdef URHO3D_D3D9
  1372. if (gapi == GAPI_D3D9)
  1373. return SetBlendMode_D3D9(mode, alphaToCoverage);
  1374. #endif
  1375. #ifdef URHO3D_D3D11
  1376. if (gapi == GAPI_D3D11)
  1377. return SetBlendMode_D3D11(mode, alphaToCoverage);
  1378. #endif
  1379. }
  1380. void Graphics::SetColorWrite(bool enable)
  1381. {
  1382. GAPI gapi = Graphics::GetGAPI();
  1383. #ifdef URHO3D_OPENGL
  1384. if (gapi == GAPI_OPENGL)
  1385. return SetColorWrite_OGL(enable);
  1386. #endif
  1387. #ifdef URHO3D_D3D9
  1388. if (gapi == GAPI_D3D9)
  1389. return SetColorWrite_D3D9(enable);
  1390. #endif
  1391. #ifdef URHO3D_D3D11
  1392. if (gapi == GAPI_D3D11)
  1393. return SetColorWrite_D3D11(enable);
  1394. #endif
  1395. }
  1396. void Graphics::SetCullMode(CullMode mode)
  1397. {
  1398. GAPI gapi = Graphics::GetGAPI();
  1399. #ifdef URHO3D_OPENGL
  1400. if (gapi == GAPI_OPENGL)
  1401. return SetCullMode_OGL(mode);
  1402. #endif
  1403. #ifdef URHO3D_D3D9
  1404. if (gapi == GAPI_D3D9)
  1405. return SetCullMode_D3D9(mode);
  1406. #endif
  1407. #ifdef URHO3D_D3D11
  1408. if (gapi == GAPI_D3D11)
  1409. return SetCullMode_D3D11(mode);
  1410. #endif
  1411. }
  1412. void Graphics::SetDepthBias(float constantBias, float slopeScaledBias)
  1413. {
  1414. GAPI gapi = Graphics::GetGAPI();
  1415. #ifdef URHO3D_OPENGL
  1416. if (gapi == GAPI_OPENGL)
  1417. return SetDepthBias_OGL(constantBias, slopeScaledBias);
  1418. #endif
  1419. #ifdef URHO3D_D3D9
  1420. if (gapi == GAPI_D3D9)
  1421. return SetDepthBias_D3D9(constantBias, slopeScaledBias);
  1422. #endif
  1423. #ifdef URHO3D_D3D11
  1424. if (gapi == GAPI_D3D11)
  1425. return SetDepthBias_D3D11(constantBias, slopeScaledBias);
  1426. #endif
  1427. }
  1428. void Graphics::SetDepthTest(CompareMode mode)
  1429. {
  1430. GAPI gapi = Graphics::GetGAPI();
  1431. #ifdef URHO3D_OPENGL
  1432. if (gapi == GAPI_OPENGL)
  1433. return SetDepthTest_OGL(mode);
  1434. #endif
  1435. #ifdef URHO3D_D3D9
  1436. if (gapi == GAPI_D3D9)
  1437. return SetDepthTest_D3D9(mode);
  1438. #endif
  1439. #ifdef URHO3D_D3D11
  1440. if (gapi == GAPI_D3D11)
  1441. return SetDepthTest_D3D11(mode);
  1442. #endif
  1443. }
  1444. void Graphics::SetDepthWrite(bool enable)
  1445. {
  1446. GAPI gapi = Graphics::GetGAPI();
  1447. #ifdef URHO3D_OPENGL
  1448. if (gapi == GAPI_OPENGL)
  1449. return SetDepthWrite_OGL(enable);
  1450. #endif
  1451. #ifdef URHO3D_D3D9
  1452. if (gapi == GAPI_D3D9)
  1453. return SetDepthWrite_D3D9(enable);
  1454. #endif
  1455. #ifdef URHO3D_D3D11
  1456. if (gapi == GAPI_D3D11)
  1457. return SetDepthWrite_D3D11(enable);
  1458. #endif
  1459. }
  1460. void Graphics::SetFillMode(FillMode mode)
  1461. {
  1462. GAPI gapi = Graphics::GetGAPI();
  1463. #ifdef URHO3D_OPENGL
  1464. if (gapi == GAPI_OPENGL)
  1465. return SetFillMode_OGL(mode);
  1466. #endif
  1467. #ifdef URHO3D_D3D9
  1468. if (gapi == GAPI_D3D9)
  1469. return SetFillMode_D3D9(mode);
  1470. #endif
  1471. #ifdef URHO3D_D3D11
  1472. if (gapi == GAPI_D3D11)
  1473. return SetFillMode_D3D11(mode);
  1474. #endif
  1475. }
  1476. void Graphics::SetLineAntiAlias(bool enable)
  1477. {
  1478. GAPI gapi = Graphics::GetGAPI();
  1479. #ifdef URHO3D_OPENGL
  1480. if (gapi == GAPI_OPENGL)
  1481. return SetLineAntiAlias_OGL(enable);
  1482. #endif
  1483. #ifdef URHO3D_D3D9
  1484. if (gapi == GAPI_D3D9)
  1485. return SetLineAntiAlias_D3D9(enable);
  1486. #endif
  1487. #ifdef URHO3D_D3D11
  1488. if (gapi == GAPI_D3D11)
  1489. return SetLineAntiAlias_D3D11(enable);
  1490. #endif
  1491. }
  1492. void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusive)
  1493. {
  1494. GAPI gapi = Graphics::GetGAPI();
  1495. #ifdef URHO3D_OPENGL
  1496. if (gapi == GAPI_OPENGL)
  1497. return SetScissorTest_OGL(enable, rect, borderInclusive);
  1498. #endif
  1499. #ifdef URHO3D_D3D9
  1500. if (gapi == GAPI_D3D9)
  1501. return SetScissorTest_D3D9(enable, rect, borderInclusive);
  1502. #endif
  1503. #ifdef URHO3D_D3D11
  1504. if (gapi == GAPI_D3D11)
  1505. return SetScissorTest_D3D11(enable, rect, borderInclusive);
  1506. #endif
  1507. }
  1508. void Graphics::SetScissorTest(bool enable, const IntRect& rect)
  1509. {
  1510. GAPI gapi = Graphics::GetGAPI();
  1511. #ifdef URHO3D_OPENGL
  1512. if (gapi == GAPI_OPENGL)
  1513. return SetScissorTest_OGL(enable, rect);
  1514. #endif
  1515. #ifdef URHO3D_D3D9
  1516. if (gapi == GAPI_D3D9)
  1517. return SetScissorTest_D3D9(enable, rect);
  1518. #endif
  1519. #ifdef URHO3D_D3D11
  1520. if (gapi == GAPI_D3D11)
  1521. return SetScissorTest_D3D11(enable, rect);
  1522. #endif
  1523. }
  1524. void Graphics::SetClipPlane(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection)
  1525. {
  1526. GAPI gapi = Graphics::GetGAPI();
  1527. #ifdef URHO3D_OPENGL
  1528. if (gapi == GAPI_OPENGL)
  1529. return SetClipPlane_OGL(enable, clipPlane, view, projection);
  1530. #endif
  1531. #ifdef URHO3D_D3D9
  1532. if (gapi == GAPI_D3D9)
  1533. return SetClipPlane_D3D9(enable, clipPlane, view, projection);
  1534. #endif
  1535. #ifdef URHO3D_D3D11
  1536. if (gapi == GAPI_D3D11)
  1537. return SetClipPlane_D3D11(enable, clipPlane, view, projection);
  1538. #endif
  1539. }
  1540. void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, StencilOp fail, StencilOp zFail, unsigned stencilRef,
  1541. unsigned compareMask, unsigned writeMask)
  1542. {
  1543. GAPI gapi = Graphics::GetGAPI();
  1544. #ifdef URHO3D_OPENGL
  1545. if (gapi == GAPI_OPENGL)
  1546. return SetStencilTest_OGL(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
  1547. #endif
  1548. #ifdef URHO3D_D3D9
  1549. if (gapi == GAPI_D3D9)
  1550. return SetStencilTest_D3D9(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
  1551. #endif
  1552. #ifdef URHO3D_D3D11
  1553. if (gapi == GAPI_D3D11)
  1554. return SetStencilTest_D3D11(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
  1555. #endif
  1556. }
  1557. bool Graphics::IsInitialized() const
  1558. {
  1559. GAPI gapi = Graphics::GetGAPI();
  1560. #ifdef URHO3D_OPENGL
  1561. if (gapi == GAPI_OPENGL)
  1562. return IsInitialized_OGL();
  1563. #endif
  1564. #ifdef URHO3D_D3D9
  1565. if (gapi == GAPI_D3D9)
  1566. return IsInitialized_D3D9();
  1567. #endif
  1568. #ifdef URHO3D_D3D11
  1569. if (gapi == GAPI_D3D11)
  1570. return IsInitialized_D3D11();
  1571. #endif
  1572. return {}; // Prevent warning
  1573. }
  1574. bool Graphics::GetDither() const
  1575. {
  1576. GAPI gapi = Graphics::GetGAPI();
  1577. #ifdef URHO3D_OPENGL
  1578. if (gapi == GAPI_OPENGL)
  1579. return GetDither_OGL();
  1580. #endif
  1581. #ifdef URHO3D_D3D9
  1582. if (gapi == GAPI_D3D9)
  1583. return GetDither_D3D9();
  1584. #endif
  1585. #ifdef URHO3D_D3D11
  1586. if (gapi == GAPI_D3D11)
  1587. return GetDither_D3D11();
  1588. #endif
  1589. return {}; // Prevent warning
  1590. }
  1591. bool Graphics::IsDeviceLost() const
  1592. {
  1593. GAPI gapi = Graphics::GetGAPI();
  1594. #ifdef URHO3D_OPENGL
  1595. if (gapi == GAPI_OPENGL)
  1596. return IsDeviceLost_OGL();
  1597. #endif
  1598. #ifdef URHO3D_D3D9
  1599. if (gapi == GAPI_D3D9)
  1600. return IsDeviceLost_D3D9();
  1601. #endif
  1602. #ifdef URHO3D_D3D11
  1603. if (gapi == GAPI_D3D11)
  1604. return IsDeviceLost_D3D11();
  1605. #endif
  1606. return {}; // Prevent warning
  1607. }
  1608. PODVector<int> Graphics::GetMultiSampleLevels() const
  1609. {
  1610. GAPI gapi = Graphics::GetGAPI();
  1611. #ifdef URHO3D_OPENGL
  1612. if (gapi == GAPI_OPENGL)
  1613. return GetMultiSampleLevels_OGL();
  1614. #endif
  1615. #ifdef URHO3D_D3D9
  1616. if (gapi == GAPI_D3D9)
  1617. return GetMultiSampleLevels_D3D9();
  1618. #endif
  1619. #ifdef URHO3D_D3D11
  1620. if (gapi == GAPI_D3D11)
  1621. return GetMultiSampleLevels_D3D11();
  1622. #endif
  1623. return {}; // Prevent warning
  1624. }
  1625. unsigned Graphics::GetFormat(CompressedFormat format) const
  1626. {
  1627. GAPI gapi = Graphics::GetGAPI();
  1628. #ifdef URHO3D_OPENGL
  1629. if (gapi == GAPI_OPENGL)
  1630. return GetFormat_OGL(format);
  1631. #endif
  1632. #ifdef URHO3D_D3D9
  1633. if (gapi == GAPI_D3D9)
  1634. return GetFormat_D3D9(format);
  1635. #endif
  1636. #ifdef URHO3D_D3D11
  1637. if (gapi == GAPI_D3D11)
  1638. return GetFormat_D3D11(format);
  1639. #endif
  1640. return {}; // Prevent warning
  1641. }
  1642. ShaderVariation* Graphics::GetShader(ShaderType type, const String& name, const String& defines) const
  1643. {
  1644. GAPI gapi = Graphics::GetGAPI();
  1645. #ifdef URHO3D_OPENGL
  1646. if (gapi == GAPI_OPENGL)
  1647. return GetShader_OGL(type, name, defines);
  1648. #endif
  1649. #ifdef URHO3D_D3D9
  1650. if (gapi == GAPI_D3D9)
  1651. return GetShader_D3D9(type, name, defines);
  1652. #endif
  1653. #ifdef URHO3D_D3D11
  1654. if (gapi == GAPI_D3D11)
  1655. return GetShader_D3D11(type, name, defines);
  1656. #endif
  1657. return {}; // Prevent warning
  1658. }
  1659. ShaderVariation* Graphics::GetShader(ShaderType type, const char* name, const char* defines) const
  1660. {
  1661. GAPI gapi = Graphics::GetGAPI();
  1662. #ifdef URHO3D_OPENGL
  1663. if (gapi == GAPI_OPENGL)
  1664. return GetShader_OGL(type, name, defines);
  1665. #endif
  1666. #ifdef URHO3D_D3D9
  1667. if (gapi == GAPI_D3D9)
  1668. return GetShader_D3D9(type, name, defines);
  1669. #endif
  1670. #ifdef URHO3D_D3D11
  1671. if (gapi == GAPI_D3D11)
  1672. return GetShader_D3D11(type, name, defines);
  1673. #endif
  1674. return {}; // Prevent warning
  1675. }
  1676. VertexBuffer* Graphics::GetVertexBuffer(unsigned index) const
  1677. {
  1678. GAPI gapi = Graphics::GetGAPI();
  1679. #ifdef URHO3D_OPENGL
  1680. if (gapi == GAPI_OPENGL)
  1681. return GetVertexBuffer_OGL(index);
  1682. #endif
  1683. #ifdef URHO3D_D3D9
  1684. if (gapi == GAPI_D3D9)
  1685. return GetVertexBuffer_D3D9(index);
  1686. #endif
  1687. #ifdef URHO3D_D3D11
  1688. if (gapi == GAPI_D3D11)
  1689. return GetVertexBuffer_D3D11(index);
  1690. #endif
  1691. return {}; // Prevent warning
  1692. }
  1693. TextureUnit Graphics::GetTextureUnit(const String& name)
  1694. {
  1695. GAPI gapi = Graphics::GetGAPI();
  1696. #ifdef URHO3D_OPENGL
  1697. if (gapi == GAPI_OPENGL)
  1698. return GetTextureUnit_OGL(name);
  1699. #endif
  1700. #ifdef URHO3D_D3D9
  1701. if (gapi == GAPI_D3D9)
  1702. return GetTextureUnit_D3D9(name);
  1703. #endif
  1704. #ifdef URHO3D_D3D11
  1705. if (gapi == GAPI_D3D11)
  1706. return GetTextureUnit_D3D11(name);
  1707. #endif
  1708. return {}; // Prevent warning
  1709. }
  1710. const String& Graphics::GetTextureUnitName(TextureUnit unit)
  1711. {
  1712. GAPI gapi = Graphics::GetGAPI();
  1713. #ifdef URHO3D_OPENGL
  1714. if (gapi == GAPI_OPENGL)
  1715. return GetTextureUnitName_OGL(unit);
  1716. #endif
  1717. #ifdef URHO3D_D3D9
  1718. if (gapi == GAPI_D3D9)
  1719. return GetTextureUnitName_D3D9(unit);
  1720. #endif
  1721. #ifdef URHO3D_D3D11
  1722. if (gapi == GAPI_D3D11)
  1723. return GetTextureUnitName_D3D11(unit);
  1724. #endif
  1725. return String::EMPTY; // Prevent warning
  1726. }
  1727. Texture* Graphics::GetTexture(unsigned index) const
  1728. {
  1729. GAPI gapi = Graphics::GetGAPI();
  1730. #ifdef URHO3D_OPENGL
  1731. if (gapi == GAPI_OPENGL)
  1732. return GetTexture_OGL(index);
  1733. #endif
  1734. #ifdef URHO3D_D3D9
  1735. if (gapi == GAPI_D3D9)
  1736. return GetTexture_D3D9(index);
  1737. #endif
  1738. #ifdef URHO3D_D3D11
  1739. if (gapi == GAPI_D3D11)
  1740. return GetTexture_D3D11(index);
  1741. #endif
  1742. return {}; // Prevent warning
  1743. }
  1744. RenderSurface* Graphics::GetRenderTarget(unsigned index) const
  1745. {
  1746. GAPI gapi = Graphics::GetGAPI();
  1747. #ifdef URHO3D_OPENGL
  1748. if (gapi == GAPI_OPENGL)
  1749. return GetRenderTarget_OGL(index);
  1750. #endif
  1751. #ifdef URHO3D_D3D9
  1752. if (gapi == GAPI_D3D9)
  1753. return GetRenderTarget_D3D9(index);
  1754. #endif
  1755. #ifdef URHO3D_D3D11
  1756. if (gapi == GAPI_D3D11)
  1757. return GetRenderTarget_D3D11(index);
  1758. #endif
  1759. return {}; // Prevent warning
  1760. }
  1761. IntVector2 Graphics::GetRenderTargetDimensions() const
  1762. {
  1763. GAPI gapi = Graphics::GetGAPI();
  1764. #ifdef URHO3D_OPENGL
  1765. if (gapi == GAPI_OPENGL)
  1766. return GetRenderTargetDimensions_OGL();
  1767. #endif
  1768. #ifdef URHO3D_D3D9
  1769. if (gapi == GAPI_D3D9)
  1770. return GetRenderTargetDimensions_D3D9();
  1771. #endif
  1772. #ifdef URHO3D_D3D11
  1773. if (gapi == GAPI_D3D11)
  1774. return GetRenderTargetDimensions_D3D11();
  1775. #endif
  1776. return {}; // Prevent warning
  1777. }
  1778. void Graphics::OnWindowResized()
  1779. {
  1780. GAPI gapi = Graphics::GetGAPI();
  1781. #ifdef URHO3D_OPENGL
  1782. if (gapi == GAPI_OPENGL)
  1783. return OnWindowResized_OGL();
  1784. #endif
  1785. #ifdef URHO3D_D3D9
  1786. if (gapi == GAPI_D3D9)
  1787. return OnWindowResized_D3D9();
  1788. #endif
  1789. #ifdef URHO3D_D3D11
  1790. if (gapi == GAPI_D3D11)
  1791. return OnWindowResized_D3D11();
  1792. #endif
  1793. }
  1794. void Graphics::OnWindowMoved()
  1795. {
  1796. GAPI gapi = Graphics::GetGAPI();
  1797. #ifdef URHO3D_OPENGL
  1798. if (gapi == GAPI_OPENGL)
  1799. return OnWindowMoved_OGL();
  1800. #endif
  1801. #ifdef URHO3D_D3D9
  1802. if (gapi == GAPI_D3D9)
  1803. return OnWindowMoved_D3D9();
  1804. #endif
  1805. #ifdef URHO3D_D3D11
  1806. if (gapi == GAPI_D3D11)
  1807. return OnWindowMoved_D3D11();
  1808. #endif
  1809. }
  1810. ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size)
  1811. {
  1812. GAPI gapi = Graphics::GetGAPI();
  1813. #ifdef URHO3D_OPENGL
  1814. if (gapi == GAPI_OPENGL)
  1815. return GetOrCreateConstantBuffer_OGL(type, index, size);
  1816. #endif
  1817. #ifdef URHO3D_D3D9
  1818. if (gapi == GAPI_D3D9)
  1819. return GetOrCreateConstantBuffer_D3D9(type, index, size);
  1820. #endif
  1821. #ifdef URHO3D_D3D11
  1822. if (gapi == GAPI_D3D11)
  1823. return GetOrCreateConstantBuffer_D3D11(type, index, size);
  1824. #endif
  1825. return {}; // Prevent warning
  1826. }
  1827. unsigned Graphics::GetMaxBones()
  1828. {
  1829. GAPI gapi = Graphics::GetGAPI();
  1830. #ifdef URHO3D_OPENGL
  1831. if (gapi == GAPI_OPENGL)
  1832. return GetMaxBones_OGL();
  1833. #endif
  1834. #ifdef URHO3D_D3D9
  1835. if (gapi == GAPI_D3D9)
  1836. return GetMaxBones_D3D9();
  1837. #endif
  1838. #ifdef URHO3D_D3D11
  1839. if (gapi == GAPI_D3D11)
  1840. return GetMaxBones_D3D11();
  1841. #endif
  1842. return {}; // Prevent warning
  1843. }
  1844. bool Graphics::GetGL3Support()
  1845. {
  1846. GAPI gapi = Graphics::GetGAPI();
  1847. #ifdef URHO3D_OPENGL
  1848. if (gapi == GAPI_OPENGL)
  1849. return GetGL3Support_OGL();
  1850. #endif
  1851. #ifdef URHO3D_D3D9
  1852. if (gapi == GAPI_D3D9)
  1853. return GetGL3Support_D3D9();
  1854. #endif
  1855. #ifdef URHO3D_D3D11
  1856. if (gapi == GAPI_D3D11)
  1857. return GetGL3Support_D3D11();
  1858. #endif
  1859. return {}; // Prevent warning
  1860. }
  1861. unsigned Graphics::GetAlphaFormat()
  1862. {
  1863. GAPI gapi = Graphics::GetGAPI();
  1864. #ifdef URHO3D_OPENGL
  1865. if (gapi == GAPI_OPENGL)
  1866. return GetAlphaFormat_OGL();
  1867. #endif
  1868. #ifdef URHO3D_D3D9
  1869. if (gapi == GAPI_D3D9)
  1870. return GetAlphaFormat_D3D9();
  1871. #endif
  1872. #ifdef URHO3D_D3D11
  1873. if (gapi == GAPI_D3D11)
  1874. return GetAlphaFormat_D3D11();
  1875. #endif
  1876. return {}; // Prevent warning
  1877. }
  1878. unsigned Graphics::GetLuminanceFormat()
  1879. {
  1880. GAPI gapi = Graphics::GetGAPI();
  1881. #ifdef URHO3D_OPENGL
  1882. if (gapi == GAPI_OPENGL)
  1883. return GetLuminanceFormat_OGL();
  1884. #endif
  1885. #ifdef URHO3D_D3D9
  1886. if (gapi == GAPI_D3D9)
  1887. return GetLuminanceFormat_D3D9();
  1888. #endif
  1889. #ifdef URHO3D_D3D11
  1890. if (gapi == GAPI_D3D11)
  1891. return GetLuminanceFormat_D3D11();
  1892. #endif
  1893. return {}; // Prevent warning
  1894. }
  1895. unsigned Graphics::GetLuminanceAlphaFormat()
  1896. {
  1897. GAPI gapi = Graphics::GetGAPI();
  1898. #ifdef URHO3D_OPENGL
  1899. if (gapi == GAPI_OPENGL)
  1900. return GetLuminanceAlphaFormat_OGL();
  1901. #endif
  1902. #ifdef URHO3D_D3D9
  1903. if (gapi == GAPI_D3D9)
  1904. return GetLuminanceAlphaFormat_D3D9();
  1905. #endif
  1906. #ifdef URHO3D_D3D11
  1907. if (gapi == GAPI_D3D11)
  1908. return GetLuminanceAlphaFormat_D3D11();
  1909. #endif
  1910. return {}; // Prevent warning
  1911. }
  1912. unsigned Graphics::GetRGBFormat()
  1913. {
  1914. GAPI gapi = Graphics::GetGAPI();
  1915. #ifdef URHO3D_OPENGL
  1916. if (gapi == GAPI_OPENGL)
  1917. return GetRGBFormat_OGL();
  1918. #endif
  1919. #ifdef URHO3D_D3D9
  1920. if (gapi == GAPI_D3D9)
  1921. return GetRGBFormat_D3D9();
  1922. #endif
  1923. #ifdef URHO3D_D3D11
  1924. if (gapi == GAPI_D3D11)
  1925. return GetRGBFormat_D3D11();
  1926. #endif
  1927. return {}; // Prevent warning
  1928. }
  1929. unsigned Graphics::GetRGBAFormat()
  1930. {
  1931. GAPI gapi = Graphics::GetGAPI();
  1932. #ifdef URHO3D_OPENGL
  1933. if (gapi == GAPI_OPENGL)
  1934. return GetRGBAFormat_OGL();
  1935. #endif
  1936. #ifdef URHO3D_D3D9
  1937. if (gapi == GAPI_D3D9)
  1938. return GetRGBAFormat_D3D9();
  1939. #endif
  1940. #ifdef URHO3D_D3D11
  1941. if (gapi == GAPI_D3D11)
  1942. return GetRGBAFormat_D3D11();
  1943. #endif
  1944. return {}; // Prevent warning
  1945. }
  1946. unsigned Graphics::GetRGBA16Format()
  1947. {
  1948. GAPI gapi = Graphics::GetGAPI();
  1949. #ifdef URHO3D_OPENGL
  1950. if (gapi == GAPI_OPENGL)
  1951. return GetRGBA16Format_OGL();
  1952. #endif
  1953. #ifdef URHO3D_D3D9
  1954. if (gapi == GAPI_D3D9)
  1955. return GetRGBA16Format_D3D9();
  1956. #endif
  1957. #ifdef URHO3D_D3D11
  1958. if (gapi == GAPI_D3D11)
  1959. return GetRGBA16Format_D3D11();
  1960. #endif
  1961. return {}; // Prevent warning
  1962. }
  1963. unsigned Graphics::GetRGBAFloat16Format()
  1964. {
  1965. GAPI gapi = Graphics::GetGAPI();
  1966. #ifdef URHO3D_OPENGL
  1967. if (gapi == GAPI_OPENGL)
  1968. return GetRGBAFloat16Format_OGL();
  1969. #endif
  1970. #ifdef URHO3D_D3D9
  1971. if (gapi == GAPI_D3D9)
  1972. return GetRGBAFloat16Format_D3D9();
  1973. #endif
  1974. #ifdef URHO3D_D3D11
  1975. if (gapi == GAPI_D3D11)
  1976. return GetRGBAFloat16Format_D3D11();
  1977. #endif
  1978. return {}; // Prevent warning
  1979. }
  1980. unsigned Graphics::GetRGBAFloat32Format()
  1981. {
  1982. GAPI gapi = Graphics::GetGAPI();
  1983. #ifdef URHO3D_OPENGL
  1984. if (gapi == GAPI_OPENGL)
  1985. return GetRGBAFloat32Format_OGL();
  1986. #endif
  1987. #ifdef URHO3D_D3D9
  1988. if (gapi == GAPI_D3D9)
  1989. return GetRGBAFloat32Format_D3D9();
  1990. #endif
  1991. #ifdef URHO3D_D3D11
  1992. if (gapi == GAPI_D3D11)
  1993. return GetRGBAFloat32Format_D3D11();
  1994. #endif
  1995. return {}; // Prevent warning
  1996. }
  1997. unsigned Graphics::GetRG16Format()
  1998. {
  1999. GAPI gapi = Graphics::GetGAPI();
  2000. #ifdef URHO3D_OPENGL
  2001. if (gapi == GAPI_OPENGL)
  2002. return GetRG16Format_OGL();
  2003. #endif
  2004. #ifdef URHO3D_D3D9
  2005. if (gapi == GAPI_D3D9)
  2006. return GetRG16Format_D3D9();
  2007. #endif
  2008. #ifdef URHO3D_D3D11
  2009. if (gapi == GAPI_D3D11)
  2010. return GetRG16Format_D3D11();
  2011. #endif
  2012. return {}; // Prevent warning
  2013. }
  2014. unsigned Graphics::GetRGFloat16Format()
  2015. {
  2016. GAPI gapi = Graphics::GetGAPI();
  2017. #ifdef URHO3D_OPENGL
  2018. if (gapi == GAPI_OPENGL)
  2019. return GetRGFloat16Format_OGL();
  2020. #endif
  2021. #ifdef URHO3D_D3D9
  2022. if (gapi == GAPI_D3D9)
  2023. return GetRGFloat16Format_D3D9();
  2024. #endif
  2025. #ifdef URHO3D_D3D11
  2026. if (gapi == GAPI_D3D11)
  2027. return GetRGFloat16Format_D3D11();
  2028. #endif
  2029. return {}; // Prevent warning
  2030. }
  2031. unsigned Graphics::GetRGFloat32Format()
  2032. {
  2033. GAPI gapi = Graphics::GetGAPI();
  2034. #ifdef URHO3D_OPENGL
  2035. if (gapi == GAPI_OPENGL)
  2036. return GetRGFloat32Format_OGL();
  2037. #endif
  2038. #ifdef URHO3D_D3D9
  2039. if (gapi == GAPI_D3D9)
  2040. return GetRGFloat32Format_D3D9();
  2041. #endif
  2042. #ifdef URHO3D_D3D11
  2043. if (gapi == GAPI_D3D11)
  2044. return GetRGFloat32Format_D3D11();
  2045. #endif
  2046. return {}; // Prevent warning
  2047. }
  2048. unsigned Graphics::GetFloat16Format()
  2049. {
  2050. GAPI gapi = Graphics::GetGAPI();
  2051. #ifdef URHO3D_OPENGL
  2052. if (gapi == GAPI_OPENGL)
  2053. return GetFloat16Format_OGL();
  2054. #endif
  2055. #ifdef URHO3D_D3D9
  2056. if (gapi == GAPI_D3D9)
  2057. return GetFloat16Format_D3D9();
  2058. #endif
  2059. #ifdef URHO3D_D3D11
  2060. if (gapi == GAPI_D3D11)
  2061. return GetFloat16Format_D3D11();
  2062. #endif
  2063. return {}; // Prevent warning
  2064. }
  2065. unsigned Graphics::GetFloat32Format()
  2066. {
  2067. GAPI gapi = Graphics::GetGAPI();
  2068. #ifdef URHO3D_OPENGL
  2069. if (gapi == GAPI_OPENGL)
  2070. return GetFloat32Format_OGL();
  2071. #endif
  2072. #ifdef URHO3D_D3D9
  2073. if (gapi == GAPI_D3D9)
  2074. return GetFloat32Format_D3D9();
  2075. #endif
  2076. #ifdef URHO3D_D3D11
  2077. if (gapi == GAPI_D3D11)
  2078. return GetFloat32Format_D3D11();
  2079. #endif
  2080. return {}; // Prevent warning
  2081. }
  2082. unsigned Graphics::GetLinearDepthFormat()
  2083. {
  2084. GAPI gapi = Graphics::GetGAPI();
  2085. #ifdef URHO3D_OPENGL
  2086. if (gapi == GAPI_OPENGL)
  2087. return GetLinearDepthFormat_OGL();
  2088. #endif
  2089. #ifdef URHO3D_D3D9
  2090. if (gapi == GAPI_D3D9)
  2091. return GetLinearDepthFormat_D3D9();
  2092. #endif
  2093. #ifdef URHO3D_D3D11
  2094. if (gapi == GAPI_D3D11)
  2095. return GetLinearDepthFormat_D3D11();
  2096. #endif
  2097. return {}; // Prevent warning
  2098. }
  2099. unsigned Graphics::GetDepthStencilFormat()
  2100. {
  2101. GAPI gapi = Graphics::GetGAPI();
  2102. #ifdef URHO3D_OPENGL
  2103. if (gapi == GAPI_OPENGL)
  2104. return GetDepthStencilFormat_OGL();
  2105. #endif
  2106. #ifdef URHO3D_D3D9
  2107. if (gapi == GAPI_D3D9)
  2108. return GetDepthStencilFormat_D3D9();
  2109. #endif
  2110. #ifdef URHO3D_D3D11
  2111. if (gapi == GAPI_D3D11)
  2112. return GetDepthStencilFormat_D3D11();
  2113. #endif
  2114. return {}; // Prevent warning
  2115. }
  2116. unsigned Graphics::GetReadableDepthFormat()
  2117. {
  2118. GAPI gapi = Graphics::GetGAPI();
  2119. #ifdef URHO3D_OPENGL
  2120. if (gapi == GAPI_OPENGL)
  2121. return GetReadableDepthFormat_OGL();
  2122. #endif
  2123. #ifdef URHO3D_D3D9
  2124. if (gapi == GAPI_D3D9)
  2125. return GetReadableDepthFormat_D3D9();
  2126. #endif
  2127. #ifdef URHO3D_D3D11
  2128. if (gapi == GAPI_D3D11)
  2129. return GetReadableDepthFormat_D3D11();
  2130. #endif
  2131. return {}; // Prevent warning
  2132. }
  2133. unsigned Graphics::GetFormat(const String& formatName)
  2134. {
  2135. GAPI gapi = Graphics::GetGAPI();
  2136. #ifdef URHO3D_OPENGL
  2137. if (gapi == GAPI_OPENGL)
  2138. return GetFormat_OGL(formatName);
  2139. #endif
  2140. #ifdef URHO3D_D3D9
  2141. if (gapi == GAPI_D3D9)
  2142. return GetFormat_D3D9(formatName);
  2143. #endif
  2144. #ifdef URHO3D_D3D11
  2145. if (gapi == GAPI_D3D11)
  2146. return GetFormat_D3D11(formatName);
  2147. #endif
  2148. return {}; // Prevent warning
  2149. }
  2150. void RegisterGraphicsLibrary(Context* context)
  2151. {
  2152. Animation::RegisterObject(context);
  2153. Material::RegisterObject(context);
  2154. Model::RegisterObject(context);
  2155. Shader::RegisterObject(context);
  2156. Technique::RegisterObject(context);
  2157. Texture2D::RegisterObject(context);
  2158. Texture2DArray::RegisterObject(context);
  2159. Texture3D::RegisterObject(context);
  2160. TextureCube::RegisterObject(context);
  2161. Camera::RegisterObject(context);
  2162. Drawable::RegisterObject(context);
  2163. Light::RegisterObject(context);
  2164. StaticModel::RegisterObject(context);
  2165. StaticModelGroup::RegisterObject(context);
  2166. Skybox::RegisterObject(context);
  2167. AnimatedModel::RegisterObject(context);
  2168. AnimationController::RegisterObject(context);
  2169. BillboardSet::RegisterObject(context);
  2170. ParticleEffect::RegisterObject(context);
  2171. ParticleEmitter::RegisterObject(context);
  2172. RibbonTrail::RegisterObject(context);
  2173. CustomGeometry::RegisterObject(context);
  2174. DecalSet::RegisterObject(context);
  2175. Terrain::RegisterObject(context);
  2176. TerrainPatch::RegisterObject(context);
  2177. DebugRenderer::RegisterObject(context);
  2178. Octree::RegisterObject(context);
  2179. Zone::RegisterObject(context);
  2180. }
  2181. }