Graphics.cpp 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216
  1. // Copyright (c) 2008-2023 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.GetI32());
  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 Vector<byte>& 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. Vector<IntVector3> Graphics::GetResolutions(int monitor) const
  189. {
  190. Vector<IntVector3> ret;
  191. // Emscripten is not able to return a valid list
  192. #ifndef __EMSCRIPTEN__
  193. i32 numModes = SDL_GetNumDisplayModes(monitor);
  194. for (i32 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 (const IntVector3& resolution : ret)
  204. {
  205. if (resolution.x_ == width && resolution.y_ == height && resolution.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. i32 Graphics::FindBestResolutionIndex(int monitor, int width, int height, int refreshRate) const
  218. {
  219. const Vector<IntVector3> resolutions = GetResolutions(monitor);
  220. if (resolutions.Empty())
  221. return NINDEX;
  222. i32 best = 0;
  223. i32 bestError = M_MAX_INT;
  224. for (i32 i = 0; i < resolutions.Size(); ++i)
  225. {
  226. i32 error = Abs(resolutions[i].x_ - width) + Abs(resolutions[i].y_ - height);
  227. if (refreshRate != 0)
  228. error += 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(i32 size)
  314. {
  315. assert(size >= 0);
  316. if (!size)
  317. return nullptr;
  318. if (size > maxScratchBufferRequest_)
  319. maxScratchBufferRequest_ = size;
  320. // First check for a free buffer that is large enough
  321. for (ScratchBuffer& scratchBuffer : scratchBuffers_)
  322. {
  323. if (!scratchBuffer.reserved_ && scratchBuffer.size_ >= size)
  324. {
  325. scratchBuffer.reserved_ = true;
  326. return scratchBuffer.data_.Get();
  327. }
  328. }
  329. // Then check if a free buffer can be resized
  330. for (ScratchBuffer& scratchBuffer : scratchBuffers_)
  331. {
  332. if (!scratchBuffer.reserved_)
  333. {
  334. scratchBuffer.data_ = new u8[size];
  335. scratchBuffer.size_ = size;
  336. scratchBuffer.reserved_ = true;
  337. URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(size));
  338. return scratchBuffer.data_.Get();
  339. }
  340. }
  341. // Finally allocate a new buffer
  342. ScratchBuffer newBuffer;
  343. newBuffer.data_ = new u8[size];
  344. newBuffer.size_ = size;
  345. newBuffer.reserved_ = true;
  346. scratchBuffers_.Push(newBuffer);
  347. URHO3D_LOGDEBUG("Allocated scratch buffer with size " + String(size));
  348. return newBuffer.data_.Get();
  349. }
  350. void Graphics::FreeScratchBuffer(void* buffer)
  351. {
  352. if (!buffer)
  353. return;
  354. for (ScratchBuffer& scratchBuffer : scratchBuffers_)
  355. {
  356. if (scratchBuffer.reserved_ && scratchBuffer.data_.Get() == buffer)
  357. {
  358. scratchBuffer.reserved_ = false;
  359. return;
  360. }
  361. }
  362. URHO3D_LOGWARNING("Reserved scratch buffer " + ToStringHex((unsigned)(size_t)buffer) + " not found");
  363. }
  364. void Graphics::CleanupScratchBuffers()
  365. {
  366. for (ScratchBuffer& scratchBuffer : scratchBuffers_)
  367. {
  368. if (!scratchBuffer.reserved_ && scratchBuffer.size_ > maxScratchBufferRequest_ * 2 && scratchBuffer.size_ >= 1024 * 1024)
  369. {
  370. scratchBuffer.data_ = maxScratchBufferRequest_ > 0 ? (new u8[maxScratchBufferRequest_]) : nullptr;
  371. scratchBuffer.size_ = maxScratchBufferRequest_;
  372. URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(maxScratchBufferRequest_));
  373. }
  374. }
  375. maxScratchBufferRequest_ = 0;
  376. }
  377. void Graphics::CreateWindowIcon()
  378. {
  379. if (windowIcon_)
  380. {
  381. SDL_Surface* surface = windowIcon_->GetSDLSurface();
  382. if (surface)
  383. {
  384. SDL_SetWindowIcon(window_, surface);
  385. SDL_FreeSurface(surface);
  386. }
  387. }
  388. }
  389. void Graphics::AdjustScreenMode(int& newWidth, int& newHeight, ScreenModeParams& params, bool& maximize) const
  390. {
  391. // High DPI is supported only for OpenGL backend
  392. if (Graphics::GetGAPI() != GAPI_OPENGL)
  393. params.highDPI_ = false;
  394. #if defined(IOS) || defined(TVOS)
  395. // iOS and tvOS app always take the fullscreen (and with status bar hidden)
  396. params.fullscreen_ = true;
  397. #endif
  398. // Make sure monitor index is not bigger than the currently detected monitors
  399. const int numMonitors = SDL_GetNumVideoDisplays();
  400. if (params.monitor_ >= numMonitors || params.monitor_ < 0)
  401. params.monitor_ = 0; // this monitor is not present, use first monitor
  402. // Fullscreen or Borderless can not be resizable and cannot be maximized
  403. if (params.fullscreen_ || params.borderless_)
  404. {
  405. params.resizable_ = false;
  406. maximize = false;
  407. }
  408. // Borderless cannot be fullscreen, they are mutually exclusive
  409. if (params.borderless_)
  410. params.fullscreen_ = false;
  411. // On iOS window needs to be resizable to handle orientation changes properly
  412. #ifdef IOS
  413. if (!externalWindow_)
  414. params.resizable_ = true;
  415. #endif
  416. // Ensure that multisample factor is in valid range
  417. params.multiSample_ = NextPowerOfTwo(Clamp(params.multiSample_, 1, 16));
  418. // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size.
  419. // If zero in fullscreen, use desktop mode
  420. if (!newWidth || !newHeight)
  421. {
  422. if (params.fullscreen_ || params.borderless_)
  423. {
  424. SDL_DisplayMode mode;
  425. SDL_GetDesktopDisplayMode(params.monitor_, &mode);
  426. newWidth = mode.w;
  427. newHeight = mode.h;
  428. }
  429. else
  430. {
  431. newWidth = 1024;
  432. newHeight = 768;
  433. }
  434. }
  435. // Check fullscreen mode validity (desktop only). Use a closest match if not found
  436. #ifdef DESKTOP_GRAPHICS
  437. if (params.fullscreen_)
  438. {
  439. const Vector<IntVector3> resolutions = GetResolutions(params.monitor_);
  440. if (!resolutions.Empty())
  441. {
  442. const i32 bestResolution = FindBestResolutionIndex(params.monitor_,
  443. newWidth, newHeight, params.refreshRate_);
  444. newWidth = resolutions[bestResolution].x_;
  445. newHeight = resolutions[bestResolution].y_;
  446. params.refreshRate_ = resolutions[bestResolution].z_;
  447. }
  448. }
  449. else
  450. {
  451. // If windowed, use the same refresh rate as desktop
  452. SDL_DisplayMode mode;
  453. SDL_GetDesktopDisplayMode(params.monitor_, &mode);
  454. params.refreshRate_ = mode.refresh_rate;
  455. }
  456. #endif
  457. }
  458. void Graphics::OnScreenModeChanged()
  459. {
  460. #ifdef URHO3D_LOGGING
  461. String msg;
  462. msg.AppendWithFormat("Set screen mode %dx%d rate %d Hz %s monitor %d", width_, height_, screenParams_.refreshRate_,
  463. (screenParams_.fullscreen_ ? "fullscreen" : "windowed"), screenParams_.monitor_);
  464. if (screenParams_.borderless_)
  465. msg.Append(" borderless");
  466. if (screenParams_.resizable_)
  467. msg.Append(" resizable");
  468. if (screenParams_.highDPI_)
  469. msg.Append(" highDPI");
  470. if (screenParams_.multiSample_ > 1)
  471. msg.AppendWithFormat(" multisample %d", screenParams_.multiSample_);
  472. URHO3D_LOGINFO(msg);
  473. #endif
  474. using namespace ScreenMode;
  475. VariantMap& eventData = GetEventDataMap();
  476. eventData[P_WIDTH] = width_;
  477. eventData[P_HEIGHT] = height_;
  478. eventData[P_FULLSCREEN] = screenParams_.fullscreen_;
  479. eventData[P_BORDERLESS] = screenParams_.borderless_;
  480. eventData[P_RESIZABLE] = screenParams_.resizable_;
  481. eventData[P_HIGHDPI] = screenParams_.highDPI_;
  482. eventData[P_MONITOR] = screenParams_.monitor_;
  483. eventData[P_REFRESHRATE] = screenParams_.refreshRate_;
  484. SendEvent(E_SCREENMODE, eventData);
  485. }
  486. Graphics::Graphics(Context* context, GAPI gapi)
  487. : Object(context)
  488. {
  489. Graphics::gapi = gapi;
  490. #ifdef URHO3D_OPENGL
  491. if (gapi == GAPI_OPENGL)
  492. {
  493. Constructor_OGL();
  494. return;
  495. }
  496. #endif
  497. #ifdef URHO3D_D3D11
  498. if (gapi == GAPI_D3D11)
  499. {
  500. Constructor_D3D11();
  501. return;
  502. }
  503. #endif
  504. }
  505. Graphics::~Graphics()
  506. {
  507. GAPI gapi = Graphics::GetGAPI();
  508. #ifdef URHO3D_OPENGL
  509. if (gapi == GAPI_OPENGL)
  510. {
  511. Destructor_OGL();
  512. return;
  513. }
  514. #endif
  515. #ifdef URHO3D_D3D11
  516. if (gapi == GAPI_D3D11)
  517. {
  518. Destructor_D3D11();
  519. return;
  520. }
  521. #endif
  522. }
  523. bool Graphics::SetScreenMode(int width, int height, const ScreenModeParams& params, bool maximize)
  524. {
  525. GAPI gapi = Graphics::GetGAPI();
  526. #ifdef URHO3D_OPENGL
  527. if (gapi == GAPI_OPENGL)
  528. return SetScreenMode_OGL(width, height, params, maximize);
  529. #endif
  530. #ifdef URHO3D_D3D11
  531. if (gapi == GAPI_D3D11)
  532. return SetScreenMode_D3D11(width, height, params, maximize);;
  533. #endif
  534. return {}; // Prevent warning
  535. }
  536. void Graphics::SetSRGB(bool enable)
  537. {
  538. GAPI gapi = Graphics::GetGAPI();
  539. #ifdef URHO3D_OPENGL
  540. if (gapi == GAPI_OPENGL)
  541. return SetSRGB_OGL(enable);
  542. #endif
  543. #ifdef URHO3D_D3D11
  544. if (gapi == GAPI_D3D11)
  545. return SetSRGB_D3D11(enable);
  546. #endif
  547. }
  548. void Graphics::SetDither(bool enable)
  549. {
  550. GAPI gapi = Graphics::GetGAPI();
  551. #ifdef URHO3D_OPENGL
  552. if (gapi == GAPI_OPENGL)
  553. return SetDither_OGL(enable);
  554. #endif
  555. #ifdef URHO3D_D3D11
  556. if (gapi == GAPI_D3D11)
  557. return SetDither_D3D11(enable);
  558. #endif
  559. }
  560. void Graphics::SetFlushGPU(bool enable)
  561. {
  562. GAPI gapi = Graphics::GetGAPI();
  563. #ifdef URHO3D_OPENGL
  564. if (gapi == GAPI_OPENGL)
  565. return SetFlushGPU_OGL(enable);
  566. #endif
  567. #ifdef URHO3D_D3D11
  568. if (gapi == GAPI_D3D11)
  569. return SetFlushGPU_D3D11(enable);;
  570. #endif
  571. }
  572. void Graphics::SetForceGL2(bool enable)
  573. {
  574. GAPI gapi = Graphics::GetGAPI();
  575. #ifdef URHO3D_OPENGL
  576. if (gapi == GAPI_OPENGL)
  577. return SetForceGL2_OGL(enable);
  578. #endif
  579. #ifdef URHO3D_D3D11
  580. if (gapi == GAPI_D3D11)
  581. return SetForceGL2_D3D11(enable);
  582. #endif
  583. }
  584. void Graphics::Close()
  585. {
  586. GAPI gapi = Graphics::GetGAPI();
  587. #ifdef URHO3D_OPENGL
  588. if (gapi == GAPI_OPENGL)
  589. return Close_OGL();
  590. #endif
  591. #ifdef URHO3D_D3D11
  592. if (gapi == GAPI_D3D11)
  593. return Close_D3D11();
  594. #endif
  595. }
  596. bool Graphics::TakeScreenShot(Image& destImage)
  597. {
  598. GAPI gapi = Graphics::GetGAPI();
  599. #ifdef URHO3D_OPENGL
  600. if (gapi == GAPI_OPENGL)
  601. return TakeScreenShot_OGL(destImage);
  602. #endif
  603. #ifdef URHO3D_D3D11
  604. if (gapi == GAPI_D3D11)
  605. return TakeScreenShot_D3D11(destImage);
  606. #endif
  607. return {}; // Prevent warning
  608. }
  609. bool Graphics::BeginFrame()
  610. {
  611. GAPI gapi = Graphics::GetGAPI();
  612. #ifdef URHO3D_OPENGL
  613. if (gapi == GAPI_OPENGL)
  614. return BeginFrame_OGL();
  615. #endif
  616. #ifdef URHO3D_D3D11
  617. if (gapi == GAPI_D3D11)
  618. return BeginFrame_D3D11();
  619. #endif
  620. return {}; // Prevent warning
  621. }
  622. void Graphics::EndFrame()
  623. {
  624. GAPI gapi = Graphics::GetGAPI();
  625. #ifdef URHO3D_OPENGL
  626. if (gapi == GAPI_OPENGL)
  627. return EndFrame_OGL();
  628. #endif
  629. #ifdef URHO3D_D3D11
  630. if (gapi == GAPI_D3D11)
  631. return EndFrame_D3D11();
  632. #endif
  633. }
  634. void Graphics::Clear(ClearTargetFlags flags, const Color& color, float depth, unsigned stencil)
  635. {
  636. GAPI gapi = Graphics::GetGAPI();
  637. #ifdef URHO3D_OPENGL
  638. if (gapi == GAPI_OPENGL)
  639. return Clear_OGL(flags, color, depth, stencil);
  640. #endif
  641. #ifdef URHO3D_D3D11
  642. if (gapi == GAPI_D3D11)
  643. return Clear_D3D11(flags, color, depth, stencil);
  644. #endif
  645. }
  646. bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
  647. {
  648. GAPI gapi = Graphics::GetGAPI();
  649. #ifdef URHO3D_OPENGL
  650. if (gapi == GAPI_OPENGL)
  651. return ResolveToTexture_OGL(destination, viewport);
  652. #endif
  653. #ifdef URHO3D_D3D11
  654. if (gapi == GAPI_D3D11)
  655. return ResolveToTexture_D3D11(destination, viewport);
  656. #endif
  657. return {}; // Prevent warning
  658. }
  659. bool Graphics::ResolveToTexture(Texture2D* texture)
  660. {
  661. GAPI gapi = Graphics::GetGAPI();
  662. #ifdef URHO3D_OPENGL
  663. if (gapi == GAPI_OPENGL)
  664. return ResolveToTexture_OGL(texture);
  665. #endif
  666. #ifdef URHO3D_D3D11
  667. if (gapi == GAPI_D3D11)
  668. return ResolveToTexture_D3D11(texture);
  669. #endif
  670. return {}; // Prevent warning
  671. }
  672. bool Graphics::ResolveToTexture(TextureCube* texture)
  673. {
  674. GAPI gapi = Graphics::GetGAPI();
  675. #ifdef URHO3D_OPENGL
  676. if (gapi == GAPI_OPENGL)
  677. return ResolveToTexture_OGL(texture);
  678. #endif
  679. #ifdef URHO3D_D3D11
  680. if (gapi == GAPI_D3D11)
  681. return ResolveToTexture_D3D11(texture);
  682. #endif
  683. return {}; // Prevent warning
  684. }
  685. void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
  686. {
  687. GAPI gapi = Graphics::GetGAPI();
  688. #ifdef URHO3D_OPENGL
  689. if (gapi == GAPI_OPENGL)
  690. return Draw_OGL(type, vertexStart, vertexCount);
  691. #endif
  692. #ifdef URHO3D_D3D11
  693. if (gapi == GAPI_D3D11)
  694. return Draw_D3D11(type, vertexStart, vertexCount);;
  695. #endif
  696. }
  697. void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount)
  698. {
  699. GAPI gapi = Graphics::GetGAPI();
  700. #ifdef URHO3D_OPENGL
  701. if (gapi == GAPI_OPENGL)
  702. return Draw_OGL(type, indexStart, indexCount, minVertex, vertexCount);
  703. #endif
  704. #ifdef URHO3D_D3D11
  705. if (gapi == GAPI_D3D11)
  706. return Draw_D3D11(type, indexStart, indexCount, minVertex, vertexCount);
  707. #endif
  708. }
  709. void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount)
  710. {
  711. GAPI gapi = Graphics::GetGAPI();
  712. #ifdef URHO3D_OPENGL
  713. if (gapi == GAPI_OPENGL)
  714. return Draw_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
  715. #endif
  716. #ifdef URHO3D_D3D11
  717. if (gapi == GAPI_D3D11)
  718. return Draw_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
  719. #endif
  720. }
  721. void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount)
  722. {
  723. GAPI gapi = Graphics::GetGAPI();
  724. #ifdef URHO3D_OPENGL
  725. if (gapi == GAPI_OPENGL)
  726. return DrawInstanced_OGL(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
  727. #endif
  728. #ifdef URHO3D_D3D11
  729. if (gapi == GAPI_D3D11)
  730. return DrawInstanced_D3D11(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
  731. #endif
  732. }
  733. void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex,
  734. unsigned vertexCount, unsigned instanceCount)
  735. {
  736. GAPI gapi = Graphics::GetGAPI();
  737. #ifdef URHO3D_OPENGL
  738. if (gapi == GAPI_OPENGL)
  739. return DrawInstanced_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
  740. #endif
  741. #ifdef URHO3D_D3D11
  742. if (gapi == GAPI_D3D11)
  743. return DrawInstanced_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
  744. #endif
  745. }
  746. void Graphics::SetVertexBuffer(VertexBuffer* buffer)
  747. {
  748. GAPI gapi = Graphics::GetGAPI();
  749. #ifdef URHO3D_OPENGL
  750. if (gapi == GAPI_OPENGL)
  751. return SetVertexBuffer_OGL(buffer);
  752. #endif
  753. #ifdef URHO3D_D3D11
  754. if (gapi == GAPI_D3D11)
  755. return SetVertexBuffer_D3D11(buffer);
  756. #endif
  757. }
  758. bool Graphics::SetVertexBuffers(const Vector<VertexBuffer*>& buffers, unsigned instanceOffset)
  759. {
  760. GAPI gapi = Graphics::GetGAPI();
  761. #ifdef URHO3D_OPENGL
  762. if (gapi == GAPI_OPENGL)
  763. return SetVertexBuffers_OGL(buffers, instanceOffset);
  764. #endif
  765. #ifdef URHO3D_D3D11
  766. if (gapi == GAPI_D3D11)
  767. return SetVertexBuffers_D3D11(buffers, instanceOffset);
  768. #endif
  769. return {}; // Prevent warning
  770. }
  771. bool Graphics::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer>>& buffers, unsigned instanceOffset)
  772. {
  773. GAPI gapi = Graphics::GetGAPI();
  774. #ifdef URHO3D_OPENGL
  775. if (gapi == GAPI_OPENGL)
  776. return SetVertexBuffers_OGL(buffers, instanceOffset);
  777. #endif
  778. #ifdef URHO3D_D3D11
  779. if (gapi == GAPI_D3D11)
  780. return SetVertexBuffers_D3D11(buffers, instanceOffset);
  781. #endif
  782. return {}; // Prevent warning
  783. }
  784. void Graphics::SetIndexBuffer(IndexBuffer* buffer)
  785. {
  786. GAPI gapi = Graphics::GetGAPI();
  787. #ifdef URHO3D_OPENGL
  788. if (gapi == GAPI_OPENGL)
  789. return SetIndexBuffer_OGL(buffer);
  790. #endif
  791. #ifdef URHO3D_D3D11
  792. if (gapi == GAPI_D3D11)
  793. return SetIndexBuffer_D3D11(buffer);
  794. #endif
  795. }
  796. void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
  797. {
  798. GAPI gapi = Graphics::GetGAPI();
  799. #ifdef URHO3D_OPENGL
  800. if (gapi == GAPI_OPENGL)
  801. return SetShaders_OGL(vs, ps);
  802. #endif
  803. #ifdef URHO3D_D3D11
  804. if (gapi == GAPI_D3D11)
  805. return SetShaders_D3D11(vs, ps);
  806. #endif
  807. }
  808. void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
  809. {
  810. GAPI gapi = Graphics::GetGAPI();
  811. #ifdef URHO3D_OPENGL
  812. if (gapi == GAPI_OPENGL)
  813. return SetShaderParameter_OGL(param, data, count);
  814. #endif
  815. #ifdef URHO3D_D3D11
  816. if (gapi == GAPI_D3D11)
  817. return SetShaderParameter_D3D11(param, data, count);
  818. #endif
  819. }
  820. void Graphics::SetShaderParameter(StringHash param, float value)
  821. {
  822. GAPI gapi = Graphics::GetGAPI();
  823. #ifdef URHO3D_OPENGL
  824. if (gapi == GAPI_OPENGL)
  825. return SetShaderParameter_OGL(param, value);
  826. #endif
  827. #ifdef URHO3D_D3D11
  828. if (gapi == GAPI_D3D11)
  829. return SetShaderParameter_D3D11(param, value);
  830. #endif
  831. }
  832. void Graphics::SetShaderParameter(StringHash param, int value)
  833. {
  834. GAPI gapi = Graphics::GetGAPI();
  835. #ifdef URHO3D_OPENGL
  836. if (gapi == GAPI_OPENGL)
  837. return SetShaderParameter_OGL(param, value);
  838. #endif
  839. #ifdef URHO3D_D3D11
  840. if (gapi == GAPI_D3D11)
  841. return SetShaderParameter_D3D11(param, value);
  842. #endif
  843. }
  844. void Graphics::SetShaderParameter(StringHash param, bool value)
  845. {
  846. GAPI gapi = Graphics::GetGAPI();
  847. #ifdef URHO3D_OPENGL
  848. if (gapi == GAPI_OPENGL)
  849. return SetShaderParameter_OGL(param, value);
  850. #endif
  851. #ifdef URHO3D_D3D11
  852. if (gapi == GAPI_D3D11)
  853. return SetShaderParameter_D3D11(param, value);
  854. #endif
  855. }
  856. void Graphics::SetShaderParameter(StringHash param, const Color& color)
  857. {
  858. GAPI gapi = Graphics::GetGAPI();
  859. #ifdef URHO3D_OPENGL
  860. if (gapi == GAPI_OPENGL)
  861. return SetShaderParameter_OGL(param, color);
  862. #endif
  863. #ifdef URHO3D_D3D11
  864. if (gapi == GAPI_D3D11)
  865. return SetShaderParameter_D3D11(param, color);
  866. #endif
  867. }
  868. void Graphics::SetShaderParameter(StringHash param, const Vector2& vector)
  869. {
  870. GAPI gapi = Graphics::GetGAPI();
  871. #ifdef URHO3D_OPENGL
  872. if (gapi == GAPI_OPENGL)
  873. return SetShaderParameter_OGL(param, vector);
  874. #endif
  875. #ifdef URHO3D_D3D11
  876. if (gapi == GAPI_D3D11)
  877. return SetShaderParameter_D3D11(param, vector);
  878. #endif
  879. }
  880. void Graphics::SetShaderParameter(StringHash param, const Matrix3& matrix)
  881. {
  882. GAPI gapi = Graphics::GetGAPI();
  883. #ifdef URHO3D_OPENGL
  884. if (gapi == GAPI_OPENGL)
  885. return SetShaderParameter_OGL(param, matrix);
  886. #endif
  887. #ifdef URHO3D_D3D11
  888. if (gapi == GAPI_D3D11)
  889. return SetShaderParameter_D3D11(param, matrix);
  890. #endif
  891. }
  892. void Graphics::SetShaderParameter(StringHash param, const Vector3& vector)
  893. {
  894. GAPI gapi = Graphics::GetGAPI();
  895. #ifdef URHO3D_OPENGL
  896. if (gapi == GAPI_OPENGL)
  897. return SetShaderParameter_OGL(param, vector);
  898. #endif
  899. #ifdef URHO3D_D3D11
  900. if (gapi == GAPI_D3D11)
  901. return SetShaderParameter_D3D11(param, vector);
  902. #endif
  903. }
  904. void Graphics::SetShaderParameter(StringHash param, const Matrix4& matrix)
  905. {
  906. GAPI gapi = Graphics::GetGAPI();
  907. #ifdef URHO3D_OPENGL
  908. if (gapi == GAPI_OPENGL)
  909. return SetShaderParameter_OGL(param, matrix);
  910. #endif
  911. #ifdef URHO3D_D3D11
  912. if (gapi == GAPI_D3D11)
  913. return SetShaderParameter_D3D11(param, matrix);
  914. #endif
  915. }
  916. void Graphics::SetShaderParameter(StringHash param, const Vector4& vector)
  917. {
  918. GAPI gapi = Graphics::GetGAPI();
  919. #ifdef URHO3D_OPENGL
  920. if (gapi == GAPI_OPENGL)
  921. return SetShaderParameter_OGL(param, vector);
  922. #endif
  923. #ifdef URHO3D_D3D11
  924. if (gapi == GAPI_D3D11)
  925. return SetShaderParameter_D3D11(param, vector);
  926. #endif
  927. }
  928. void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
  929. {
  930. GAPI gapi = Graphics::GetGAPI();
  931. #ifdef URHO3D_OPENGL
  932. if (gapi == GAPI_OPENGL)
  933. return SetShaderParameter_OGL(param, matrix);
  934. #endif
  935. #ifdef URHO3D_D3D11
  936. if (gapi == GAPI_D3D11)
  937. return SetShaderParameter_D3D11(param, matrix);
  938. #endif
  939. }
  940. bool Graphics::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
  941. {
  942. GAPI gapi = Graphics::GetGAPI();
  943. #ifdef URHO3D_OPENGL
  944. if (gapi == GAPI_OPENGL)
  945. return NeedParameterUpdate_OGL(group, source);
  946. #endif
  947. #ifdef URHO3D_D3D11
  948. if (gapi == GAPI_D3D11)
  949. return NeedParameterUpdate_D3D11(group, source);
  950. #endif
  951. return {}; // Prevent warning
  952. }
  953. bool Graphics::HasShaderParameter(StringHash param)
  954. {
  955. GAPI gapi = Graphics::GetGAPI();
  956. #ifdef URHO3D_OPENGL
  957. if (gapi == GAPI_OPENGL)
  958. return HasShaderParameter_OGL(param);
  959. #endif
  960. #ifdef URHO3D_D3D11
  961. if (gapi == GAPI_D3D11)
  962. return HasShaderParameter_D3D11(param);
  963. #endif
  964. return {}; // Prevent warning
  965. }
  966. bool Graphics::HasTextureUnit(TextureUnit unit)
  967. {
  968. GAPI gapi = Graphics::GetGAPI();
  969. #ifdef URHO3D_OPENGL
  970. if (gapi == GAPI_OPENGL)
  971. return HasTextureUnit_OGL(unit);
  972. #endif
  973. #ifdef URHO3D_D3D11
  974. if (gapi == GAPI_D3D11)
  975. return HasTextureUnit_D3D11(unit);
  976. #endif
  977. return {}; // Prevent warning
  978. }
  979. void Graphics::ClearParameterSource(ShaderParameterGroup group)
  980. {
  981. GAPI gapi = Graphics::GetGAPI();
  982. #ifdef URHO3D_OPENGL
  983. if (gapi == GAPI_OPENGL)
  984. return ClearParameterSource_OGL(group);
  985. #endif
  986. #ifdef URHO3D_D3D11
  987. if (gapi == GAPI_D3D11)
  988. return ClearParameterSource_D3D11(group);
  989. #endif
  990. }
  991. void Graphics::ClearParameterSources()
  992. {
  993. GAPI gapi = Graphics::GetGAPI();
  994. #ifdef URHO3D_OPENGL
  995. if (gapi == GAPI_OPENGL)
  996. return ClearParameterSources_OGL();
  997. #endif
  998. #ifdef URHO3D_D3D11
  999. if (gapi == GAPI_D3D11)
  1000. return ClearParameterSources_D3D11();
  1001. #endif
  1002. }
  1003. void Graphics::ClearTransformSources()
  1004. {
  1005. GAPI gapi = Graphics::GetGAPI();
  1006. #ifdef URHO3D_OPENGL
  1007. if (gapi == GAPI_OPENGL)
  1008. return ClearTransformSources_OGL();
  1009. #endif
  1010. #ifdef URHO3D_D3D11
  1011. if (gapi == GAPI_D3D11)
  1012. return ClearTransformSources_D3D11();
  1013. #endif
  1014. }
  1015. void Graphics::SetTexture(unsigned index, Texture* texture)
  1016. {
  1017. GAPI gapi = Graphics::GetGAPI();
  1018. #ifdef URHO3D_OPENGL
  1019. if (gapi == GAPI_OPENGL)
  1020. return SetTexture_OGL(index, texture);
  1021. #endif
  1022. #ifdef URHO3D_D3D11
  1023. if (gapi == GAPI_D3D11)
  1024. return SetTexture_D3D11(index, texture);
  1025. #endif
  1026. }
  1027. void Graphics::SetDefaultTextureFilterMode(TextureFilterMode mode)
  1028. {
  1029. GAPI gapi = Graphics::GetGAPI();
  1030. #ifdef URHO3D_OPENGL
  1031. if (gapi == GAPI_OPENGL)
  1032. return SetDefaultTextureFilterMode_OGL(mode);
  1033. #endif
  1034. #ifdef URHO3D_D3D11
  1035. if (gapi == GAPI_D3D11)
  1036. return SetDefaultTextureFilterMode_D3D11(mode);
  1037. #endif
  1038. }
  1039. void Graphics::SetDefaultTextureAnisotropy(unsigned level)
  1040. {
  1041. GAPI gapi = Graphics::GetGAPI();
  1042. #ifdef URHO3D_OPENGL
  1043. if (gapi == GAPI_OPENGL)
  1044. return SetDefaultTextureAnisotropy_OGL(level);
  1045. #endif
  1046. #ifdef URHO3D_D3D11
  1047. if (gapi == GAPI_D3D11)
  1048. return SetDefaultTextureAnisotropy_D3D11(level);
  1049. #endif
  1050. }
  1051. void Graphics::ResetRenderTargets()
  1052. {
  1053. GAPI gapi = Graphics::GetGAPI();
  1054. #ifdef URHO3D_OPENGL
  1055. if (gapi == GAPI_OPENGL)
  1056. return ResetRenderTargets_OGL();
  1057. #endif
  1058. #ifdef URHO3D_D3D11
  1059. if (gapi == GAPI_D3D11)
  1060. return ResetRenderTargets_D3D11();
  1061. #endif
  1062. }
  1063. void Graphics::ResetRenderTarget(unsigned index)
  1064. {
  1065. GAPI gapi = Graphics::GetGAPI();
  1066. #ifdef URHO3D_OPENGL
  1067. if (gapi == GAPI_OPENGL)
  1068. return ResetRenderTarget_OGL(index);
  1069. #endif
  1070. #ifdef URHO3D_D3D11
  1071. if (gapi == GAPI_D3D11)
  1072. return ResetRenderTarget_D3D11(index);
  1073. #endif
  1074. }
  1075. void Graphics::ResetDepthStencil()
  1076. {
  1077. GAPI gapi = Graphics::GetGAPI();
  1078. #ifdef URHO3D_OPENGL
  1079. if (gapi == GAPI_OPENGL)
  1080. return ResetDepthStencil_OGL();
  1081. #endif
  1082. #ifdef URHO3D_D3D11
  1083. if (gapi == GAPI_D3D11)
  1084. return ResetDepthStencil_D3D11();
  1085. #endif
  1086. }
  1087. void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
  1088. {
  1089. GAPI gapi = Graphics::GetGAPI();
  1090. #ifdef URHO3D_OPENGL
  1091. if (gapi == GAPI_OPENGL)
  1092. return SetRenderTarget_OGL(index, renderTarget);
  1093. #endif
  1094. #ifdef URHO3D_D3D11
  1095. if (gapi == GAPI_D3D11)
  1096. return SetRenderTarget_D3D11(index, renderTarget);
  1097. #endif
  1098. }
  1099. void Graphics::SetRenderTarget(unsigned index, Texture2D* texture)
  1100. {
  1101. GAPI gapi = Graphics::GetGAPI();
  1102. #ifdef URHO3D_OPENGL
  1103. if (gapi == GAPI_OPENGL)
  1104. return SetRenderTarget_OGL(index, texture);
  1105. #endif
  1106. #ifdef URHO3D_D3D11
  1107. if (gapi == GAPI_D3D11)
  1108. return SetRenderTarget_D3D11(index, texture);
  1109. #endif
  1110. }
  1111. void Graphics::SetDepthStencil(RenderSurface* depthStencil)
  1112. {
  1113. GAPI gapi = Graphics::GetGAPI();
  1114. #ifdef URHO3D_OPENGL
  1115. if (gapi == GAPI_OPENGL)
  1116. return SetDepthStencil_OGL(depthStencil);
  1117. #endif
  1118. #ifdef URHO3D_D3D11
  1119. if (gapi == GAPI_D3D11)
  1120. return SetDepthStencil_D3D11(depthStencil);
  1121. #endif
  1122. }
  1123. void Graphics::SetDepthStencil(Texture2D* texture)
  1124. {
  1125. GAPI gapi = Graphics::GetGAPI();
  1126. #ifdef URHO3D_OPENGL
  1127. if (gapi == GAPI_OPENGL)
  1128. return SetDepthStencil_OGL(texture);
  1129. #endif
  1130. #ifdef URHO3D_D3D11
  1131. if (gapi == GAPI_D3D11)
  1132. return SetDepthStencil_D3D11(texture);
  1133. #endif
  1134. }
  1135. void Graphics::SetViewport(const IntRect& rect)
  1136. {
  1137. GAPI gapi = Graphics::GetGAPI();
  1138. #ifdef URHO3D_OPENGL
  1139. if (gapi == GAPI_OPENGL)
  1140. return SetViewport_OGL(rect);
  1141. #endif
  1142. #ifdef URHO3D_D3D11
  1143. if (gapi == GAPI_D3D11)
  1144. return SetViewport_D3D11(rect);
  1145. #endif
  1146. }
  1147. void Graphics::SetBlendMode(BlendMode mode, bool alphaToCoverage)
  1148. {
  1149. GAPI gapi = Graphics::GetGAPI();
  1150. #ifdef URHO3D_OPENGL
  1151. if (gapi == GAPI_OPENGL)
  1152. return SetBlendMode_OGL(mode, alphaToCoverage);
  1153. #endif
  1154. #ifdef URHO3D_D3D11
  1155. if (gapi == GAPI_D3D11)
  1156. return SetBlendMode_D3D11(mode, alphaToCoverage);
  1157. #endif
  1158. }
  1159. void Graphics::SetColorWrite(bool enable)
  1160. {
  1161. GAPI gapi = Graphics::GetGAPI();
  1162. #ifdef URHO3D_OPENGL
  1163. if (gapi == GAPI_OPENGL)
  1164. return SetColorWrite_OGL(enable);
  1165. #endif
  1166. #ifdef URHO3D_D3D11
  1167. if (gapi == GAPI_D3D11)
  1168. return SetColorWrite_D3D11(enable);
  1169. #endif
  1170. }
  1171. void Graphics::SetCullMode(CullMode mode)
  1172. {
  1173. GAPI gapi = Graphics::GetGAPI();
  1174. #ifdef URHO3D_OPENGL
  1175. if (gapi == GAPI_OPENGL)
  1176. return SetCullMode_OGL(mode);
  1177. #endif
  1178. #ifdef URHO3D_D3D11
  1179. if (gapi == GAPI_D3D11)
  1180. return SetCullMode_D3D11(mode);
  1181. #endif
  1182. }
  1183. void Graphics::SetDepthBias(float constantBias, float slopeScaledBias)
  1184. {
  1185. GAPI gapi = Graphics::GetGAPI();
  1186. #ifdef URHO3D_OPENGL
  1187. if (gapi == GAPI_OPENGL)
  1188. return SetDepthBias_OGL(constantBias, slopeScaledBias);
  1189. #endif
  1190. #ifdef URHO3D_D3D11
  1191. if (gapi == GAPI_D3D11)
  1192. return SetDepthBias_D3D11(constantBias, slopeScaledBias);
  1193. #endif
  1194. }
  1195. void Graphics::SetDepthTest(CompareMode mode)
  1196. {
  1197. GAPI gapi = Graphics::GetGAPI();
  1198. #ifdef URHO3D_OPENGL
  1199. if (gapi == GAPI_OPENGL)
  1200. return SetDepthTest_OGL(mode);
  1201. #endif
  1202. #ifdef URHO3D_D3D11
  1203. if (gapi == GAPI_D3D11)
  1204. return SetDepthTest_D3D11(mode);
  1205. #endif
  1206. }
  1207. void Graphics::SetDepthWrite(bool enable)
  1208. {
  1209. GAPI gapi = Graphics::GetGAPI();
  1210. #ifdef URHO3D_OPENGL
  1211. if (gapi == GAPI_OPENGL)
  1212. return SetDepthWrite_OGL(enable);
  1213. #endif
  1214. #ifdef URHO3D_D3D11
  1215. if (gapi == GAPI_D3D11)
  1216. return SetDepthWrite_D3D11(enable);
  1217. #endif
  1218. }
  1219. void Graphics::SetFillMode(FillMode mode)
  1220. {
  1221. GAPI gapi = Graphics::GetGAPI();
  1222. #ifdef URHO3D_OPENGL
  1223. if (gapi == GAPI_OPENGL)
  1224. return SetFillMode_OGL(mode);
  1225. #endif
  1226. #ifdef URHO3D_D3D11
  1227. if (gapi == GAPI_D3D11)
  1228. return SetFillMode_D3D11(mode);
  1229. #endif
  1230. }
  1231. void Graphics::SetLineAntiAlias(bool enable)
  1232. {
  1233. GAPI gapi = Graphics::GetGAPI();
  1234. #ifdef URHO3D_OPENGL
  1235. if (gapi == GAPI_OPENGL)
  1236. return SetLineAntiAlias_OGL(enable);
  1237. #endif
  1238. #ifdef URHO3D_D3D11
  1239. if (gapi == GAPI_D3D11)
  1240. return SetLineAntiAlias_D3D11(enable);
  1241. #endif
  1242. }
  1243. void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusive)
  1244. {
  1245. GAPI gapi = Graphics::GetGAPI();
  1246. #ifdef URHO3D_OPENGL
  1247. if (gapi == GAPI_OPENGL)
  1248. return SetScissorTest_OGL(enable, rect, borderInclusive);
  1249. #endif
  1250. #ifdef URHO3D_D3D11
  1251. if (gapi == GAPI_D3D11)
  1252. return SetScissorTest_D3D11(enable, rect, borderInclusive);
  1253. #endif
  1254. }
  1255. void Graphics::SetScissorTest(bool enable, const IntRect& rect)
  1256. {
  1257. GAPI gapi = Graphics::GetGAPI();
  1258. #ifdef URHO3D_OPENGL
  1259. if (gapi == GAPI_OPENGL)
  1260. return SetScissorTest_OGL(enable, rect);
  1261. #endif
  1262. #ifdef URHO3D_D3D11
  1263. if (gapi == GAPI_D3D11)
  1264. return SetScissorTest_D3D11(enable, rect);
  1265. #endif
  1266. }
  1267. void Graphics::SetClipPlane(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection)
  1268. {
  1269. GAPI gapi = Graphics::GetGAPI();
  1270. #ifdef URHO3D_OPENGL
  1271. if (gapi == GAPI_OPENGL)
  1272. return SetClipPlane_OGL(enable, clipPlane, view, projection);
  1273. #endif
  1274. #ifdef URHO3D_D3D11
  1275. if (gapi == GAPI_D3D11)
  1276. return SetClipPlane_D3D11(enable, clipPlane, view, projection);
  1277. #endif
  1278. }
  1279. void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, StencilOp fail, StencilOp zFail, u32 stencilRef,
  1280. u32 compareMask, u32 writeMask)
  1281. {
  1282. GAPI gapi = Graphics::GetGAPI();
  1283. #ifdef URHO3D_OPENGL
  1284. if (gapi == GAPI_OPENGL)
  1285. return SetStencilTest_OGL(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
  1286. #endif
  1287. #ifdef URHO3D_D3D11
  1288. if (gapi == GAPI_D3D11)
  1289. return SetStencilTest_D3D11(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
  1290. #endif
  1291. }
  1292. bool Graphics::IsInitialized() const
  1293. {
  1294. GAPI gapi = Graphics::GetGAPI();
  1295. #ifdef URHO3D_OPENGL
  1296. if (gapi == GAPI_OPENGL)
  1297. return IsInitialized_OGL();
  1298. #endif
  1299. #ifdef URHO3D_D3D11
  1300. if (gapi == GAPI_D3D11)
  1301. return IsInitialized_D3D11();
  1302. #endif
  1303. return {}; // Prevent warning
  1304. }
  1305. bool Graphics::GetDither() const
  1306. {
  1307. GAPI gapi = Graphics::GetGAPI();
  1308. #ifdef URHO3D_OPENGL
  1309. if (gapi == GAPI_OPENGL)
  1310. return GetDither_OGL();
  1311. #endif
  1312. #ifdef URHO3D_D3D11
  1313. if (gapi == GAPI_D3D11)
  1314. return GetDither_D3D11();
  1315. #endif
  1316. return {}; // Prevent warning
  1317. }
  1318. bool Graphics::IsDeviceLost() const
  1319. {
  1320. GAPI gapi = Graphics::GetGAPI();
  1321. #ifdef URHO3D_OPENGL
  1322. if (gapi == GAPI_OPENGL)
  1323. return IsDeviceLost_OGL();
  1324. #endif
  1325. #ifdef URHO3D_D3D11
  1326. if (gapi == GAPI_D3D11)
  1327. return IsDeviceLost_D3D11();
  1328. #endif
  1329. return {}; // Prevent warning
  1330. }
  1331. Vector<int> Graphics::GetMultiSampleLevels() const
  1332. {
  1333. GAPI gapi = Graphics::GetGAPI();
  1334. #ifdef URHO3D_OPENGL
  1335. if (gapi == GAPI_OPENGL)
  1336. return GetMultiSampleLevels_OGL();
  1337. #endif
  1338. #ifdef URHO3D_D3D11
  1339. if (gapi == GAPI_D3D11)
  1340. return GetMultiSampleLevels_D3D11();
  1341. #endif
  1342. return {}; // Prevent warning
  1343. }
  1344. unsigned Graphics::GetFormat(CompressedFormat format) const
  1345. {
  1346. GAPI gapi = Graphics::GetGAPI();
  1347. #ifdef URHO3D_OPENGL
  1348. if (gapi == GAPI_OPENGL)
  1349. return GetFormat_OGL(format);
  1350. #endif
  1351. #ifdef URHO3D_D3D11
  1352. if (gapi == GAPI_D3D11)
  1353. return GetFormat_D3D11(format);
  1354. #endif
  1355. return {}; // Prevent warning
  1356. }
  1357. ShaderVariation* Graphics::GetShader(ShaderType type, const String& name, const String& defines) const
  1358. {
  1359. GAPI gapi = Graphics::GetGAPI();
  1360. #ifdef URHO3D_OPENGL
  1361. if (gapi == GAPI_OPENGL)
  1362. return GetShader_OGL(type, name, defines);
  1363. #endif
  1364. #ifdef URHO3D_D3D11
  1365. if (gapi == GAPI_D3D11)
  1366. return GetShader_D3D11(type, name, defines);
  1367. #endif
  1368. return {}; // Prevent warning
  1369. }
  1370. ShaderVariation* Graphics::GetShader(ShaderType type, const char* name, const char* defines) const
  1371. {
  1372. GAPI gapi = Graphics::GetGAPI();
  1373. #ifdef URHO3D_OPENGL
  1374. if (gapi == GAPI_OPENGL)
  1375. return GetShader_OGL(type, name, defines);
  1376. #endif
  1377. #ifdef URHO3D_D3D11
  1378. if (gapi == GAPI_D3D11)
  1379. return GetShader_D3D11(type, name, defines);
  1380. #endif
  1381. return {}; // Prevent warning
  1382. }
  1383. VertexBuffer* Graphics::GetVertexBuffer(unsigned index) const
  1384. {
  1385. GAPI gapi = Graphics::GetGAPI();
  1386. #ifdef URHO3D_OPENGL
  1387. if (gapi == GAPI_OPENGL)
  1388. return GetVertexBuffer_OGL(index);
  1389. #endif
  1390. #ifdef URHO3D_D3D11
  1391. if (gapi == GAPI_D3D11)
  1392. return GetVertexBuffer_D3D11(index);
  1393. #endif
  1394. return {}; // Prevent warning
  1395. }
  1396. TextureUnit Graphics::GetTextureUnit(const String& name)
  1397. {
  1398. GAPI gapi = Graphics::GetGAPI();
  1399. #ifdef URHO3D_OPENGL
  1400. if (gapi == GAPI_OPENGL)
  1401. return GetTextureUnit_OGL(name);
  1402. #endif
  1403. #ifdef URHO3D_D3D11
  1404. if (gapi == GAPI_D3D11)
  1405. return GetTextureUnit_D3D11(name);
  1406. #endif
  1407. return {}; // Prevent warning
  1408. }
  1409. const String& Graphics::GetTextureUnitName(TextureUnit unit)
  1410. {
  1411. GAPI gapi = Graphics::GetGAPI();
  1412. #ifdef URHO3D_OPENGL
  1413. if (gapi == GAPI_OPENGL)
  1414. return GetTextureUnitName_OGL(unit);
  1415. #endif
  1416. #ifdef URHO3D_D3D11
  1417. if (gapi == GAPI_D3D11)
  1418. return GetTextureUnitName_D3D11(unit);
  1419. #endif
  1420. return String::EMPTY; // Prevent warning
  1421. }
  1422. Texture* Graphics::GetTexture(unsigned index) const
  1423. {
  1424. GAPI gapi = Graphics::GetGAPI();
  1425. #ifdef URHO3D_OPENGL
  1426. if (gapi == GAPI_OPENGL)
  1427. return GetTexture_OGL(index);
  1428. #endif
  1429. #ifdef URHO3D_D3D11
  1430. if (gapi == GAPI_D3D11)
  1431. return GetTexture_D3D11(index);
  1432. #endif
  1433. return {}; // Prevent warning
  1434. }
  1435. RenderSurface* Graphics::GetRenderTarget(unsigned index) const
  1436. {
  1437. GAPI gapi = Graphics::GetGAPI();
  1438. #ifdef URHO3D_OPENGL
  1439. if (gapi == GAPI_OPENGL)
  1440. return GetRenderTarget_OGL(index);
  1441. #endif
  1442. #ifdef URHO3D_D3D11
  1443. if (gapi == GAPI_D3D11)
  1444. return GetRenderTarget_D3D11(index);
  1445. #endif
  1446. return {}; // Prevent warning
  1447. }
  1448. IntVector2 Graphics::GetRenderTargetDimensions() const
  1449. {
  1450. GAPI gapi = Graphics::GetGAPI();
  1451. #ifdef URHO3D_OPENGL
  1452. if (gapi == GAPI_OPENGL)
  1453. return GetRenderTargetDimensions_OGL();
  1454. #endif
  1455. #ifdef URHO3D_D3D11
  1456. if (gapi == GAPI_D3D11)
  1457. return GetRenderTargetDimensions_D3D11();
  1458. #endif
  1459. return {}; // Prevent warning
  1460. }
  1461. void Graphics::OnWindowResized()
  1462. {
  1463. GAPI gapi = Graphics::GetGAPI();
  1464. #ifdef URHO3D_OPENGL
  1465. if (gapi == GAPI_OPENGL)
  1466. return OnWindowResized_OGL();
  1467. #endif
  1468. #ifdef URHO3D_D3D11
  1469. if (gapi == GAPI_D3D11)
  1470. return OnWindowResized_D3D11();
  1471. #endif
  1472. }
  1473. void Graphics::OnWindowMoved()
  1474. {
  1475. GAPI gapi = Graphics::GetGAPI();
  1476. #ifdef URHO3D_OPENGL
  1477. if (gapi == GAPI_OPENGL)
  1478. return OnWindowMoved_OGL();
  1479. #endif
  1480. #ifdef URHO3D_D3D11
  1481. if (gapi == GAPI_D3D11)
  1482. return OnWindowMoved_D3D11();
  1483. #endif
  1484. }
  1485. ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size)
  1486. {
  1487. GAPI gapi = Graphics::GetGAPI();
  1488. #ifdef URHO3D_OPENGL
  1489. if (gapi == GAPI_OPENGL)
  1490. return GetOrCreateConstantBuffer_OGL(type, index, size);
  1491. #endif
  1492. #ifdef URHO3D_D3D11
  1493. if (gapi == GAPI_D3D11)
  1494. return GetOrCreateConstantBuffer_D3D11(type, index, size);
  1495. #endif
  1496. return {}; // Prevent warning
  1497. }
  1498. unsigned Graphics::GetMaxBones()
  1499. {
  1500. GAPI gapi = Graphics::GetGAPI();
  1501. #ifdef URHO3D_OPENGL
  1502. if (gapi == GAPI_OPENGL)
  1503. return GetMaxBones_OGL();
  1504. #endif
  1505. #ifdef URHO3D_D3D11
  1506. if (gapi == GAPI_D3D11)
  1507. return GetMaxBones_D3D11();
  1508. #endif
  1509. return {}; // Prevent warning
  1510. }
  1511. bool Graphics::GetGL3Support()
  1512. {
  1513. GAPI gapi = Graphics::GetGAPI();
  1514. #ifdef URHO3D_OPENGL
  1515. if (gapi == GAPI_OPENGL)
  1516. return GetGL3Support_OGL();
  1517. #endif
  1518. #ifdef URHO3D_D3D11
  1519. if (gapi == GAPI_D3D11)
  1520. return GetGL3Support_D3D11();
  1521. #endif
  1522. return {}; // Prevent warning
  1523. }
  1524. unsigned Graphics::GetAlphaFormat()
  1525. {
  1526. GAPI gapi = Graphics::GetGAPI();
  1527. #ifdef URHO3D_OPENGL
  1528. if (gapi == GAPI_OPENGL)
  1529. return GetAlphaFormat_OGL();
  1530. #endif
  1531. #ifdef URHO3D_D3D11
  1532. if (gapi == GAPI_D3D11)
  1533. return GetAlphaFormat_D3D11();
  1534. #endif
  1535. return {}; // Prevent warning
  1536. }
  1537. unsigned Graphics::GetLuminanceFormat()
  1538. {
  1539. GAPI gapi = Graphics::GetGAPI();
  1540. #ifdef URHO3D_OPENGL
  1541. if (gapi == GAPI_OPENGL)
  1542. return GetLuminanceFormat_OGL();
  1543. #endif
  1544. #ifdef URHO3D_D3D11
  1545. if (gapi == GAPI_D3D11)
  1546. return GetLuminanceFormat_D3D11();
  1547. #endif
  1548. return {}; // Prevent warning
  1549. }
  1550. unsigned Graphics::GetLuminanceAlphaFormat()
  1551. {
  1552. GAPI gapi = Graphics::GetGAPI();
  1553. #ifdef URHO3D_OPENGL
  1554. if (gapi == GAPI_OPENGL)
  1555. return GetLuminanceAlphaFormat_OGL();
  1556. #endif
  1557. #ifdef URHO3D_D3D11
  1558. if (gapi == GAPI_D3D11)
  1559. return GetLuminanceAlphaFormat_D3D11();
  1560. #endif
  1561. return {}; // Prevent warning
  1562. }
  1563. unsigned Graphics::GetRGBFormat()
  1564. {
  1565. GAPI gapi = Graphics::GetGAPI();
  1566. #ifdef URHO3D_OPENGL
  1567. if (gapi == GAPI_OPENGL)
  1568. return GetRGBFormat_OGL();
  1569. #endif
  1570. #ifdef URHO3D_D3D11
  1571. if (gapi == GAPI_D3D11)
  1572. return GetRGBFormat_D3D11();
  1573. #endif
  1574. return {}; // Prevent warning
  1575. }
  1576. unsigned Graphics::GetRGBAFormat()
  1577. {
  1578. GAPI gapi = Graphics::GetGAPI();
  1579. #ifdef URHO3D_OPENGL
  1580. if (gapi == GAPI_OPENGL)
  1581. return GetRGBAFormat_OGL();
  1582. #endif
  1583. #ifdef URHO3D_D3D11
  1584. if (gapi == GAPI_D3D11)
  1585. return GetRGBAFormat_D3D11();
  1586. #endif
  1587. return {}; // Prevent warning
  1588. }
  1589. unsigned Graphics::GetRGBA16Format()
  1590. {
  1591. GAPI gapi = Graphics::GetGAPI();
  1592. #ifdef URHO3D_OPENGL
  1593. if (gapi == GAPI_OPENGL)
  1594. return GetRGBA16Format_OGL();
  1595. #endif
  1596. #ifdef URHO3D_D3D11
  1597. if (gapi == GAPI_D3D11)
  1598. return GetRGBA16Format_D3D11();
  1599. #endif
  1600. return {}; // Prevent warning
  1601. }
  1602. unsigned Graphics::GetRGBAFloat16Format()
  1603. {
  1604. GAPI gapi = Graphics::GetGAPI();
  1605. #ifdef URHO3D_OPENGL
  1606. if (gapi == GAPI_OPENGL)
  1607. return GetRGBAFloat16Format_OGL();
  1608. #endif
  1609. #ifdef URHO3D_D3D11
  1610. if (gapi == GAPI_D3D11)
  1611. return GetRGBAFloat16Format_D3D11();
  1612. #endif
  1613. return {}; // Prevent warning
  1614. }
  1615. unsigned Graphics::GetRGBAFloat32Format()
  1616. {
  1617. GAPI gapi = Graphics::GetGAPI();
  1618. #ifdef URHO3D_OPENGL
  1619. if (gapi == GAPI_OPENGL)
  1620. return GetRGBAFloat32Format_OGL();
  1621. #endif
  1622. #ifdef URHO3D_D3D11
  1623. if (gapi == GAPI_D3D11)
  1624. return GetRGBAFloat32Format_D3D11();
  1625. #endif
  1626. return {}; // Prevent warning
  1627. }
  1628. unsigned Graphics::GetRG16Format()
  1629. {
  1630. GAPI gapi = Graphics::GetGAPI();
  1631. #ifdef URHO3D_OPENGL
  1632. if (gapi == GAPI_OPENGL)
  1633. return GetRG16Format_OGL();
  1634. #endif
  1635. #ifdef URHO3D_D3D11
  1636. if (gapi == GAPI_D3D11)
  1637. return GetRG16Format_D3D11();
  1638. #endif
  1639. return {}; // Prevent warning
  1640. }
  1641. unsigned Graphics::GetRGFloat16Format()
  1642. {
  1643. GAPI gapi = Graphics::GetGAPI();
  1644. #ifdef URHO3D_OPENGL
  1645. if (gapi == GAPI_OPENGL)
  1646. return GetRGFloat16Format_OGL();
  1647. #endif
  1648. #ifdef URHO3D_D3D11
  1649. if (gapi == GAPI_D3D11)
  1650. return GetRGFloat16Format_D3D11();
  1651. #endif
  1652. return {}; // Prevent warning
  1653. }
  1654. unsigned Graphics::GetRGFloat32Format()
  1655. {
  1656. GAPI gapi = Graphics::GetGAPI();
  1657. #ifdef URHO3D_OPENGL
  1658. if (gapi == GAPI_OPENGL)
  1659. return GetRGFloat32Format_OGL();
  1660. #endif
  1661. #ifdef URHO3D_D3D11
  1662. if (gapi == GAPI_D3D11)
  1663. return GetRGFloat32Format_D3D11();
  1664. #endif
  1665. return {}; // Prevent warning
  1666. }
  1667. unsigned Graphics::GetFloat16Format()
  1668. {
  1669. GAPI gapi = Graphics::GetGAPI();
  1670. #ifdef URHO3D_OPENGL
  1671. if (gapi == GAPI_OPENGL)
  1672. return GetFloat16Format_OGL();
  1673. #endif
  1674. #ifdef URHO3D_D3D11
  1675. if (gapi == GAPI_D3D11)
  1676. return GetFloat16Format_D3D11();
  1677. #endif
  1678. return {}; // Prevent warning
  1679. }
  1680. unsigned Graphics::GetFloat32Format()
  1681. {
  1682. GAPI gapi = Graphics::GetGAPI();
  1683. #ifdef URHO3D_OPENGL
  1684. if (gapi == GAPI_OPENGL)
  1685. return GetFloat32Format_OGL();
  1686. #endif
  1687. #ifdef URHO3D_D3D11
  1688. if (gapi == GAPI_D3D11)
  1689. return GetFloat32Format_D3D11();
  1690. #endif
  1691. return {}; // Prevent warning
  1692. }
  1693. unsigned Graphics::GetLinearDepthFormat()
  1694. {
  1695. GAPI gapi = Graphics::GetGAPI();
  1696. #ifdef URHO3D_OPENGL
  1697. if (gapi == GAPI_OPENGL)
  1698. return GetLinearDepthFormat_OGL();
  1699. #endif
  1700. #ifdef URHO3D_D3D11
  1701. if (gapi == GAPI_D3D11)
  1702. return GetLinearDepthFormat_D3D11();
  1703. #endif
  1704. return {}; // Prevent warning
  1705. }
  1706. unsigned Graphics::GetDepthStencilFormat()
  1707. {
  1708. GAPI gapi = Graphics::GetGAPI();
  1709. #ifdef URHO3D_OPENGL
  1710. if (gapi == GAPI_OPENGL)
  1711. return GetDepthStencilFormat_OGL();
  1712. #endif
  1713. #ifdef URHO3D_D3D11
  1714. if (gapi == GAPI_D3D11)
  1715. return GetDepthStencilFormat_D3D11();
  1716. #endif
  1717. return {}; // Prevent warning
  1718. }
  1719. unsigned Graphics::GetReadableDepthFormat()
  1720. {
  1721. GAPI gapi = Graphics::GetGAPI();
  1722. #ifdef URHO3D_OPENGL
  1723. if (gapi == GAPI_OPENGL)
  1724. return GetReadableDepthFormat_OGL();
  1725. #endif
  1726. #ifdef URHO3D_D3D11
  1727. if (gapi == GAPI_D3D11)
  1728. return GetReadableDepthFormat_D3D11();
  1729. #endif
  1730. return {}; // Prevent warning
  1731. }
  1732. unsigned Graphics::GetFormat(const String& formatName)
  1733. {
  1734. GAPI gapi = Graphics::GetGAPI();
  1735. #ifdef URHO3D_OPENGL
  1736. if (gapi == GAPI_OPENGL)
  1737. return GetFormat_OGL(formatName);
  1738. #endif
  1739. #ifdef URHO3D_D3D11
  1740. if (gapi == GAPI_D3D11)
  1741. return GetFormat_D3D11(formatName);
  1742. #endif
  1743. return {}; // Prevent warning
  1744. }
  1745. void RegisterGraphicsLibrary(Context* context)
  1746. {
  1747. Animation::RegisterObject(context);
  1748. Material::RegisterObject(context);
  1749. Model::RegisterObject(context);
  1750. Shader::RegisterObject(context);
  1751. Technique::RegisterObject(context);
  1752. Texture2D::RegisterObject(context);
  1753. Texture2DArray::RegisterObject(context);
  1754. Texture3D::RegisterObject(context);
  1755. TextureCube::RegisterObject(context);
  1756. Camera::RegisterObject(context);
  1757. Drawable::RegisterObject(context);
  1758. Light::RegisterObject(context);
  1759. StaticModel::RegisterObject(context);
  1760. StaticModelGroup::RegisterObject(context);
  1761. Skybox::RegisterObject(context);
  1762. AnimatedModel::RegisterObject(context);
  1763. AnimationController::RegisterObject(context);
  1764. BillboardSet::RegisterObject(context);
  1765. ParticleEffect::RegisterObject(context);
  1766. ParticleEmitter::RegisterObject(context);
  1767. RibbonTrail::RegisterObject(context);
  1768. CustomGeometry::RegisterObject(context);
  1769. DecalSet::RegisterObject(context);
  1770. Terrain::RegisterObject(context);
  1771. TerrainPatch::RegisterObject(context);
  1772. DebugRenderer::RegisterObject(context);
  1773. Octree::RegisterObject(context);
  1774. Zone::RegisterObject(context);
  1775. }
  1776. }