| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216 |
- // Copyright (c) 2008-2023 the Urho3D project
- // License: MIT
- #include "../Precompiled.h"
- #include "../Core/Profiler.h"
- #include "../Graphics/AnimatedModel.h"
- #include "../Graphics/Animation.h"
- #include "../Graphics/AnimationController.h"
- #include "../Graphics/Camera.h"
- #include "../Graphics/CustomGeometry.h"
- #include "../Graphics/DebugRenderer.h"
- #include "../Graphics/DecalSet.h"
- #include "../Graphics/Graphics.h"
- #include "../Graphics/GraphicsEvents.h"
- #include "../Graphics/Material.h"
- #include "../Graphics/Octree.h"
- #include "../Graphics/ParticleEffect.h"
- #include "../Graphics/ParticleEmitter.h"
- #include "../Graphics/RibbonTrail.h"
- #include "../Graphics/Skybox.h"
- #include "../Graphics/StaticModelGroup.h"
- #include "../Graphics/Technique.h"
- #include "../Graphics/Terrain.h"
- #include "../Graphics/TerrainPatch.h"
- #include "../Graphics/Zone.h"
- #include "../GraphicsAPI/GraphicsImpl.h"
- #include "../GraphicsAPI/Shader.h"
- #include "../GraphicsAPI/ShaderPrecache.h"
- #include "../GraphicsAPI/Texture2D.h"
- #include "../GraphicsAPI/Texture2DArray.h"
- #include "../GraphicsAPI/Texture3D.h"
- #include "../GraphicsAPI/TextureCube.h"
- #include "../IO/FileSystem.h"
- #include "../IO/Log.h"
- #include <SDL/SDL.h>
- #include "../DebugNew.h"
- namespace Urho3D
- {
- void Graphics::SetExternalWindow(void* window)
- {
- if (!window_)
- externalWindow_ = window;
- else
- URHO3D_LOGERROR("Window already opened, can not set external window");
- }
- void Graphics::SetWindowTitle(const String& windowTitle)
- {
- windowTitle_ = windowTitle;
- if (window_)
- SDL_SetWindowTitle(window_, windowTitle_.CString());
- }
- void Graphics::SetWindowIcon(Image* windowIcon)
- {
- windowIcon_ = windowIcon;
- if (window_)
- CreateWindowIcon();
- }
- void Graphics::SetWindowPosition(const IntVector2& position)
- {
- if (window_)
- SDL_SetWindowPosition(window_, position.x_, position.y_);
- else
- position_ = position; // Sets as initial position for SDL_CreateWindow()
- }
- void Graphics::SetWindowPosition(int x, int y)
- {
- SetWindowPosition(IntVector2(x, y));
- }
- void Graphics::SetOrientations(const String& orientations)
- {
- orientations_ = orientations.Trimmed();
- SDL_SetHint(SDL_HINT_ORIENTATIONS, orientations_.CString());
- }
- bool Graphics::SetScreenMode(int width, int height)
- {
- return SetScreenMode(width, height, screenParams_);
- }
- bool Graphics::SetWindowModes(const WindowModeParams& windowMode, const WindowModeParams& secondaryWindowMode, bool maximize)
- {
- primaryWindowMode_ = windowMode;
- secondaryWindowMode_ = secondaryWindowMode;
- return SetScreenMode(primaryWindowMode_.width_, primaryWindowMode_.height_, primaryWindowMode_.screenParams_, maximize);
- }
- bool Graphics::SetDefaultWindowModes(int width, int height, const ScreenModeParams& params)
- {
- // Fill window mode to be applied now
- WindowModeParams primaryWindowMode;
- primaryWindowMode.width_ = width;
- primaryWindowMode.height_ = height;
- primaryWindowMode.screenParams_ = params;
- // Fill window mode to be applied on Graphics::ToggleFullscreen
- WindowModeParams secondaryWindowMode = primaryWindowMode;
- // Pick resolution automatically
- secondaryWindowMode.width_ = 0;
- secondaryWindowMode.height_ = 0;
- if (params.fullscreen_ || params.borderless_)
- {
- secondaryWindowMode.screenParams_.fullscreen_ = false;
- secondaryWindowMode.screenParams_.borderless_ = false;
- }
- else
- {
- secondaryWindowMode.screenParams_.borderless_ = true;
- }
- const bool maximize = (!width || !height) && !params.fullscreen_ && !params.borderless_ && params.resizable_;
- return SetWindowModes(primaryWindowMode, secondaryWindowMode, maximize);
- }
- bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable,
- bool highDPI, bool vsync, bool tripleBuffer, int multiSample, int monitor, int refreshRate)
- {
- ScreenModeParams params;
- params.fullscreen_ = fullscreen;
- params.borderless_ = borderless;
- params.resizable_ = resizable;
- params.highDPI_ = highDPI;
- params.vsync_ = vsync;
- params.tripleBuffer_ = tripleBuffer;
- params.multiSample_ = multiSample;
- params.monitor_ = monitor;
- params.refreshRate_ = refreshRate;
- return SetDefaultWindowModes(width, height, params);
- }
- bool Graphics::SetMode(int width, int height)
- {
- return SetDefaultWindowModes(width, height, screenParams_);
- }
- bool Graphics::ToggleFullscreen()
- {
- Swap(primaryWindowMode_, secondaryWindowMode_);
- return SetScreenMode(primaryWindowMode_.width_, primaryWindowMode_.height_, primaryWindowMode_.screenParams_);
- }
- void Graphics::SetShaderParameter(StringHash param, const Variant& value)
- {
- switch (value.GetType())
- {
- case VAR_BOOL:
- SetShaderParameter(param, value.GetBool());
- break;
- case VAR_INT:
- SetShaderParameter(param, value.GetI32());
- break;
- case VAR_FLOAT:
- case VAR_DOUBLE:
- SetShaderParameter(param, value.GetFloat());
- break;
- case VAR_VECTOR2:
- SetShaderParameter(param, value.GetVector2());
- break;
- case VAR_VECTOR3:
- SetShaderParameter(param, value.GetVector3());
- break;
- case VAR_VECTOR4:
- SetShaderParameter(param, value.GetVector4());
- break;
- case VAR_COLOR:
- SetShaderParameter(param, value.GetColor());
- break;
- case VAR_MATRIX3:
- SetShaderParameter(param, value.GetMatrix3());
- break;
- case VAR_MATRIX3X4:
- SetShaderParameter(param, value.GetMatrix3x4());
- break;
- case VAR_MATRIX4:
- SetShaderParameter(param, value.GetMatrix4());
- break;
- case VAR_BUFFER:
- {
- const Vector<byte>& buffer = value.GetBuffer();
- if (buffer.Size() >= sizeof(float))
- SetShaderParameter(param, reinterpret_cast<const float*>(&buffer[0]), buffer.Size() / sizeof(float));
- }
- break;
- default:
- // Unsupported parameter type, do nothing
- break;
- }
- }
- IntVector2 Graphics::GetWindowPosition() const
- {
- if (window_)
- {
- IntVector2 position;
- SDL_GetWindowPosition(window_, &position.x_, &position.y_);
- return position;
- }
- return position_;
- }
- Vector<IntVector3> Graphics::GetResolutions(int monitor) const
- {
- Vector<IntVector3> ret;
- // Emscripten is not able to return a valid list
- #ifndef __EMSCRIPTEN__
- i32 numModes = SDL_GetNumDisplayModes(monitor);
- for (i32 i = 0; i < numModes; ++i)
- {
- SDL_DisplayMode mode;
- SDL_GetDisplayMode(monitor, i, &mode);
- int width = mode.w;
- int height = mode.h;
- int rate = mode.refresh_rate;
- // Store mode if unique
- bool unique = true;
- for (const IntVector3& resolution : ret)
- {
- if (resolution.x_ == width && resolution.y_ == height && resolution.z_ == rate)
- {
- unique = false;
- break;
- }
- }
- if (unique)
- ret.Push(IntVector3(width, height, rate));
- }
- #endif
- return ret;
- }
- i32 Graphics::FindBestResolutionIndex(int monitor, int width, int height, int refreshRate) const
- {
- const Vector<IntVector3> resolutions = GetResolutions(monitor);
- if (resolutions.Empty())
- return NINDEX;
- i32 best = 0;
- i32 bestError = M_MAX_INT;
- for (i32 i = 0; i < resolutions.Size(); ++i)
- {
- i32 error = Abs(resolutions[i].x_ - width) + Abs(resolutions[i].y_ - height);
- if (refreshRate != 0)
- error += Abs(resolutions[i].z_ - refreshRate);
- if (error < bestError)
- {
- best = i;
- bestError = error;
- }
- }
- return best;
- }
- IntVector2 Graphics::GetDesktopResolution(int monitor) const
- {
- #if !defined(__ANDROID__) && !defined(IOS) && !defined(TVOS)
- SDL_DisplayMode mode;
- SDL_GetDesktopDisplayMode(monitor, &mode);
- return IntVector2(mode.w, mode.h);
- #else
- // SDL_GetDesktopDisplayMode() may not work correctly on mobile platforms. Rather return the window size
- return IntVector2(width_, height_);
- #endif
- }
- int Graphics::GetMonitorCount() const
- {
- return SDL_GetNumVideoDisplays();
- }
- int Graphics::GetCurrentMonitor() const
- {
- return window_ ? SDL_GetWindowDisplayIndex(window_) : 0;
- }
- bool Graphics::GetMaximized() const
- {
- return window_? static_cast<bool>(SDL_GetWindowFlags(window_) & SDL_WINDOW_MAXIMIZED) : false;
- }
- Vector3 Graphics::GetDisplayDPI(int monitor) const
- {
- Vector3 result;
- SDL_GetDisplayDPI(monitor, &result.z_, &result.x_, &result.y_);
- return result;
- }
- void Graphics::Maximize()
- {
- if (!window_)
- return;
- SDL_MaximizeWindow(window_);
- }
- void Graphics::Minimize()
- {
- if (!window_)
- return;
- SDL_MinimizeWindow(window_);
- }
- void Graphics::Raise() const
- {
- if (!window_)
- return;
- SDL_RaiseWindow(window_);
- }
- void Graphics::BeginDumpShaders(const String& fileName)
- {
- shaderPrecache_ = new ShaderPrecache(context_, fileName);
- }
- void Graphics::EndDumpShaders()
- {
- shaderPrecache_.Reset();
- }
- void Graphics::PrecacheShaders(Deserializer& source)
- {
- URHO3D_PROFILE(PrecacheShaders);
- ShaderPrecache::LoadShaders(this, source);
- }
- void Graphics::SetShaderCacheDir(const String& path)
- {
- String trimmedPath = path.Trimmed();
- if (trimmedPath.Length())
- shaderCacheDir_ = AddTrailingSlash(trimmedPath);
- }
- void Graphics::AddGPUObject(GPUObject* object)
- {
- MutexLock lock(gpuObjectMutex_);
- gpuObjects_.Push(object);
- }
- void Graphics::RemoveGPUObject(GPUObject* object)
- {
- MutexLock lock(gpuObjectMutex_);
- gpuObjects_.Remove(object);
- }
- void* Graphics::ReserveScratchBuffer(i32 size)
- {
- assert(size >= 0);
- if (!size)
- return nullptr;
- if (size > maxScratchBufferRequest_)
- maxScratchBufferRequest_ = size;
- // First check for a free buffer that is large enough
- for (ScratchBuffer& scratchBuffer : scratchBuffers_)
- {
- if (!scratchBuffer.reserved_ && scratchBuffer.size_ >= size)
- {
- scratchBuffer.reserved_ = true;
- return scratchBuffer.data_.Get();
- }
- }
- // Then check if a free buffer can be resized
- for (ScratchBuffer& scratchBuffer : scratchBuffers_)
- {
- if (!scratchBuffer.reserved_)
- {
- scratchBuffer.data_ = new u8[size];
- scratchBuffer.size_ = size;
- scratchBuffer.reserved_ = true;
- URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(size));
- return scratchBuffer.data_.Get();
- }
- }
- // Finally allocate a new buffer
- ScratchBuffer newBuffer;
- newBuffer.data_ = new u8[size];
- newBuffer.size_ = size;
- newBuffer.reserved_ = true;
- scratchBuffers_.Push(newBuffer);
- URHO3D_LOGDEBUG("Allocated scratch buffer with size " + String(size));
- return newBuffer.data_.Get();
- }
- void Graphics::FreeScratchBuffer(void* buffer)
- {
- if (!buffer)
- return;
- for (ScratchBuffer& scratchBuffer : scratchBuffers_)
- {
- if (scratchBuffer.reserved_ && scratchBuffer.data_.Get() == buffer)
- {
- scratchBuffer.reserved_ = false;
- return;
- }
- }
- URHO3D_LOGWARNING("Reserved scratch buffer " + ToStringHex((unsigned)(size_t)buffer) + " not found");
- }
- void Graphics::CleanupScratchBuffers()
- {
- for (ScratchBuffer& scratchBuffer : scratchBuffers_)
- {
- if (!scratchBuffer.reserved_ && scratchBuffer.size_ > maxScratchBufferRequest_ * 2 && scratchBuffer.size_ >= 1024 * 1024)
- {
- scratchBuffer.data_ = maxScratchBufferRequest_ > 0 ? (new u8[maxScratchBufferRequest_]) : nullptr;
- scratchBuffer.size_ = maxScratchBufferRequest_;
- URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(maxScratchBufferRequest_));
- }
- }
- maxScratchBufferRequest_ = 0;
- }
- void Graphics::CreateWindowIcon()
- {
- if (windowIcon_)
- {
- SDL_Surface* surface = windowIcon_->GetSDLSurface();
- if (surface)
- {
- SDL_SetWindowIcon(window_, surface);
- SDL_FreeSurface(surface);
- }
- }
- }
- void Graphics::AdjustScreenMode(int& newWidth, int& newHeight, ScreenModeParams& params, bool& maximize) const
- {
- // High DPI is supported only for OpenGL backend
- if (Graphics::GetGAPI() != GAPI_OPENGL)
- params.highDPI_ = false;
- #if defined(IOS) || defined(TVOS)
- // iOS and tvOS app always take the fullscreen (and with status bar hidden)
- params.fullscreen_ = true;
- #endif
- // Make sure monitor index is not bigger than the currently detected monitors
- const int numMonitors = SDL_GetNumVideoDisplays();
- if (params.monitor_ >= numMonitors || params.monitor_ < 0)
- params.monitor_ = 0; // this monitor is not present, use first monitor
- // Fullscreen or Borderless can not be resizable and cannot be maximized
- if (params.fullscreen_ || params.borderless_)
- {
- params.resizable_ = false;
- maximize = false;
- }
- // Borderless cannot be fullscreen, they are mutually exclusive
- if (params.borderless_)
- params.fullscreen_ = false;
- // On iOS window needs to be resizable to handle orientation changes properly
- #ifdef IOS
- if (!externalWindow_)
- params.resizable_ = true;
- #endif
- // Ensure that multisample factor is in valid range
- params.multiSample_ = NextPowerOfTwo(Clamp(params.multiSample_, 1, 16));
- // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size.
- // If zero in fullscreen, use desktop mode
- if (!newWidth || !newHeight)
- {
- if (params.fullscreen_ || params.borderless_)
- {
- SDL_DisplayMode mode;
- SDL_GetDesktopDisplayMode(params.monitor_, &mode);
- newWidth = mode.w;
- newHeight = mode.h;
- }
- else
- {
- newWidth = 1024;
- newHeight = 768;
- }
- }
- // Check fullscreen mode validity (desktop only). Use a closest match if not found
- #ifdef DESKTOP_GRAPHICS
- if (params.fullscreen_)
- {
- const Vector<IntVector3> resolutions = GetResolutions(params.monitor_);
- if (!resolutions.Empty())
- {
- const i32 bestResolution = FindBestResolutionIndex(params.monitor_,
- newWidth, newHeight, params.refreshRate_);
- newWidth = resolutions[bestResolution].x_;
- newHeight = resolutions[bestResolution].y_;
- params.refreshRate_ = resolutions[bestResolution].z_;
- }
- }
- else
- {
- // If windowed, use the same refresh rate as desktop
- SDL_DisplayMode mode;
- SDL_GetDesktopDisplayMode(params.monitor_, &mode);
- params.refreshRate_ = mode.refresh_rate;
- }
- #endif
- }
- void Graphics::OnScreenModeChanged()
- {
- #ifdef URHO3D_LOGGING
- String msg;
- msg.AppendWithFormat("Set screen mode %dx%d rate %d Hz %s monitor %d", width_, height_, screenParams_.refreshRate_,
- (screenParams_.fullscreen_ ? "fullscreen" : "windowed"), screenParams_.monitor_);
- if (screenParams_.borderless_)
- msg.Append(" borderless");
- if (screenParams_.resizable_)
- msg.Append(" resizable");
- if (screenParams_.highDPI_)
- msg.Append(" highDPI");
- if (screenParams_.multiSample_ > 1)
- msg.AppendWithFormat(" multisample %d", screenParams_.multiSample_);
- URHO3D_LOGINFO(msg);
- #endif
- using namespace ScreenMode;
- VariantMap& eventData = GetEventDataMap();
- eventData[P_WIDTH] = width_;
- eventData[P_HEIGHT] = height_;
- eventData[P_FULLSCREEN] = screenParams_.fullscreen_;
- eventData[P_BORDERLESS] = screenParams_.borderless_;
- eventData[P_RESIZABLE] = screenParams_.resizable_;
- eventData[P_HIGHDPI] = screenParams_.highDPI_;
- eventData[P_MONITOR] = screenParams_.monitor_;
- eventData[P_REFRESHRATE] = screenParams_.refreshRate_;
- SendEvent(E_SCREENMODE, eventData);
- }
- Graphics::Graphics(Context* context, GAPI gapi)
- : Object(context)
- {
- Graphics::gapi = gapi;
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- {
- Constructor_OGL();
- return;
- }
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- {
- Constructor_D3D11();
- return;
- }
- #endif
- }
- Graphics::~Graphics()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- {
- Destructor_OGL();
- return;
- }
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- {
- Destructor_D3D11();
- return;
- }
- #endif
- }
- bool Graphics::SetScreenMode(int width, int height, const ScreenModeParams& params, bool maximize)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetScreenMode_OGL(width, height, params, maximize);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetScreenMode_D3D11(width, height, params, maximize);;
- #endif
- return {}; // Prevent warning
- }
- void Graphics::SetSRGB(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetSRGB_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetSRGB_D3D11(enable);
- #endif
- }
- void Graphics::SetDither(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDither_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDither_D3D11(enable);
- #endif
- }
- void Graphics::SetFlushGPU(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetFlushGPU_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetFlushGPU_D3D11(enable);;
- #endif
- }
- void Graphics::SetForceGL2(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetForceGL2_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetForceGL2_D3D11(enable);
- #endif
- }
- void Graphics::Close()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return Close_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return Close_D3D11();
- #endif
- }
- bool Graphics::TakeScreenShot(Image& destImage)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return TakeScreenShot_OGL(destImage);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return TakeScreenShot_D3D11(destImage);
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::BeginFrame()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return BeginFrame_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return BeginFrame_D3D11();
- #endif
- return {}; // Prevent warning
- }
- void Graphics::EndFrame()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return EndFrame_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return EndFrame_D3D11();
- #endif
- }
- void Graphics::Clear(ClearTargetFlags flags, const Color& color, float depth, unsigned stencil)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return Clear_OGL(flags, color, depth, stencil);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return Clear_D3D11(flags, color, depth, stencil);
- #endif
- }
- bool Graphics::ResolveToTexture(Texture2D* destination, const IntRect& viewport)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ResolveToTexture_OGL(destination, viewport);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ResolveToTexture_D3D11(destination, viewport);
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::ResolveToTexture(Texture2D* texture)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ResolveToTexture_OGL(texture);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ResolveToTexture_D3D11(texture);
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::ResolveToTexture(TextureCube* texture)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ResolveToTexture_OGL(texture);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ResolveToTexture_D3D11(texture);
- #endif
- return {}; // Prevent warning
- }
- void Graphics::Draw(PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return Draw_OGL(type, vertexStart, vertexCount);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return Draw_D3D11(type, vertexStart, vertexCount);;
- #endif
- }
- void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return Draw_OGL(type, indexStart, indexCount, minVertex, vertexCount);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return Draw_D3D11(type, indexStart, indexCount, minVertex, vertexCount);
- #endif
- }
- void Graphics::Draw(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex, unsigned vertexCount)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return Draw_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return Draw_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount);
- #endif
- }
- void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return DrawInstanced_OGL(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return DrawInstanced_D3D11(type, indexStart, indexCount, minVertex, vertexCount, instanceCount);
- #endif
- }
- void Graphics::DrawInstanced(PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned baseVertexIndex, unsigned minVertex,
- unsigned vertexCount, unsigned instanceCount)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return DrawInstanced_OGL(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return DrawInstanced_D3D11(type, indexStart, indexCount, baseVertexIndex, minVertex, vertexCount, instanceCount);
- #endif
- }
- void Graphics::SetVertexBuffer(VertexBuffer* buffer)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetVertexBuffer_OGL(buffer);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetVertexBuffer_D3D11(buffer);
- #endif
- }
- bool Graphics::SetVertexBuffers(const Vector<VertexBuffer*>& buffers, unsigned instanceOffset)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetVertexBuffers_OGL(buffers, instanceOffset);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetVertexBuffers_D3D11(buffers, instanceOffset);
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::SetVertexBuffers(const Vector<SharedPtr<VertexBuffer>>& buffers, unsigned instanceOffset)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetVertexBuffers_OGL(buffers, instanceOffset);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetVertexBuffers_D3D11(buffers, instanceOffset);
- #endif
- return {}; // Prevent warning
- }
- void Graphics::SetIndexBuffer(IndexBuffer* buffer)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetIndexBuffer_OGL(buffer);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetIndexBuffer_D3D11(buffer);
- #endif
- }
- void Graphics::SetShaders(ShaderVariation* vs, ShaderVariation* ps)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaders_OGL(vs, ps);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaders_D3D11(vs, ps);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const float* data, unsigned count)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, data, count);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, data, count);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, float value)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, value);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, value);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, int value)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, value);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, value);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, bool value)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, value);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, value);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Color& color)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, color);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, color);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Vector2& vector)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, vector);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, vector);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Matrix3& matrix)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, matrix);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, matrix);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Vector3& vector)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, vector);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, vector);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Matrix4& matrix)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, matrix);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, matrix);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Vector4& vector)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, vector);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, vector);
- #endif
- }
- void Graphics::SetShaderParameter(StringHash param, const Matrix3x4& matrix)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetShaderParameter_OGL(param, matrix);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetShaderParameter_D3D11(param, matrix);
- #endif
- }
- bool Graphics::NeedParameterUpdate(ShaderParameterGroup group, const void* source)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return NeedParameterUpdate_OGL(group, source);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return NeedParameterUpdate_D3D11(group, source);
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::HasShaderParameter(StringHash param)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return HasShaderParameter_OGL(param);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return HasShaderParameter_D3D11(param);
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::HasTextureUnit(TextureUnit unit)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return HasTextureUnit_OGL(unit);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return HasTextureUnit_D3D11(unit);
- #endif
- return {}; // Prevent warning
- }
- void Graphics::ClearParameterSource(ShaderParameterGroup group)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ClearParameterSource_OGL(group);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ClearParameterSource_D3D11(group);
- #endif
- }
- void Graphics::ClearParameterSources()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ClearParameterSources_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ClearParameterSources_D3D11();
- #endif
- }
- void Graphics::ClearTransformSources()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ClearTransformSources_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ClearTransformSources_D3D11();
- #endif
- }
- void Graphics::SetTexture(unsigned index, Texture* texture)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetTexture_OGL(index, texture);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetTexture_D3D11(index, texture);
- #endif
- }
- void Graphics::SetDefaultTextureFilterMode(TextureFilterMode mode)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDefaultTextureFilterMode_OGL(mode);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDefaultTextureFilterMode_D3D11(mode);
- #endif
- }
- void Graphics::SetDefaultTextureAnisotropy(unsigned level)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDefaultTextureAnisotropy_OGL(level);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDefaultTextureAnisotropy_D3D11(level);
- #endif
- }
- void Graphics::ResetRenderTargets()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ResetRenderTargets_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ResetRenderTargets_D3D11();
- #endif
- }
- void Graphics::ResetRenderTarget(unsigned index)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ResetRenderTarget_OGL(index);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ResetRenderTarget_D3D11(index);
- #endif
- }
- void Graphics::ResetDepthStencil()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return ResetDepthStencil_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return ResetDepthStencil_D3D11();
- #endif
- }
- void Graphics::SetRenderTarget(unsigned index, RenderSurface* renderTarget)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetRenderTarget_OGL(index, renderTarget);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetRenderTarget_D3D11(index, renderTarget);
- #endif
- }
- void Graphics::SetRenderTarget(unsigned index, Texture2D* texture)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetRenderTarget_OGL(index, texture);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetRenderTarget_D3D11(index, texture);
- #endif
- }
- void Graphics::SetDepthStencil(RenderSurface* depthStencil)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDepthStencil_OGL(depthStencil);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDepthStencil_D3D11(depthStencil);
- #endif
- }
- void Graphics::SetDepthStencil(Texture2D* texture)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDepthStencil_OGL(texture);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDepthStencil_D3D11(texture);
- #endif
- }
- void Graphics::SetViewport(const IntRect& rect)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetViewport_OGL(rect);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetViewport_D3D11(rect);
- #endif
- }
- void Graphics::SetBlendMode(BlendMode mode, bool alphaToCoverage)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetBlendMode_OGL(mode, alphaToCoverage);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetBlendMode_D3D11(mode, alphaToCoverage);
- #endif
- }
- void Graphics::SetColorWrite(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetColorWrite_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetColorWrite_D3D11(enable);
- #endif
- }
- void Graphics::SetCullMode(CullMode mode)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetCullMode_OGL(mode);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetCullMode_D3D11(mode);
- #endif
- }
- void Graphics::SetDepthBias(float constantBias, float slopeScaledBias)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDepthBias_OGL(constantBias, slopeScaledBias);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDepthBias_D3D11(constantBias, slopeScaledBias);
- #endif
- }
- void Graphics::SetDepthTest(CompareMode mode)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDepthTest_OGL(mode);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDepthTest_D3D11(mode);
- #endif
- }
- void Graphics::SetDepthWrite(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetDepthWrite_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetDepthWrite_D3D11(enable);
- #endif
- }
- void Graphics::SetFillMode(FillMode mode)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetFillMode_OGL(mode);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetFillMode_D3D11(mode);
- #endif
- }
- void Graphics::SetLineAntiAlias(bool enable)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetLineAntiAlias_OGL(enable);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetLineAntiAlias_D3D11(enable);
- #endif
- }
- void Graphics::SetScissorTest(bool enable, const Rect& rect, bool borderInclusive)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetScissorTest_OGL(enable, rect, borderInclusive);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetScissorTest_D3D11(enable, rect, borderInclusive);
- #endif
- }
- void Graphics::SetScissorTest(bool enable, const IntRect& rect)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetScissorTest_OGL(enable, rect);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetScissorTest_D3D11(enable, rect);
- #endif
- }
- void Graphics::SetClipPlane(bool enable, const Plane& clipPlane, const Matrix3x4& view, const Matrix4& projection)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetClipPlane_OGL(enable, clipPlane, view, projection);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetClipPlane_D3D11(enable, clipPlane, view, projection);
- #endif
- }
- void Graphics::SetStencilTest(bool enable, CompareMode mode, StencilOp pass, StencilOp fail, StencilOp zFail, u32 stencilRef,
- u32 compareMask, u32 writeMask)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return SetStencilTest_OGL(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return SetStencilTest_D3D11(enable, mode, pass, fail, zFail, stencilRef, compareMask, writeMask);
- #endif
- }
- bool Graphics::IsInitialized() const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return IsInitialized_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return IsInitialized_D3D11();
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::GetDither() const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetDither_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetDither_D3D11();
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::IsDeviceLost() const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return IsDeviceLost_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return IsDeviceLost_D3D11();
- #endif
- return {}; // Prevent warning
- }
- Vector<int> Graphics::GetMultiSampleLevels() const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetMultiSampleLevels_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetMultiSampleLevels_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetFormat(CompressedFormat format) const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetFormat_OGL(format);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetFormat_D3D11(format);
- #endif
- return {}; // Prevent warning
- }
- ShaderVariation* Graphics::GetShader(ShaderType type, const String& name, const String& defines) const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetShader_OGL(type, name, defines);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetShader_D3D11(type, name, defines);
- #endif
- return {}; // Prevent warning
- }
- ShaderVariation* Graphics::GetShader(ShaderType type, const char* name, const char* defines) const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetShader_OGL(type, name, defines);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetShader_D3D11(type, name, defines);
- #endif
- return {}; // Prevent warning
- }
- VertexBuffer* Graphics::GetVertexBuffer(unsigned index) const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetVertexBuffer_OGL(index);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetVertexBuffer_D3D11(index);
- #endif
- return {}; // Prevent warning
- }
- TextureUnit Graphics::GetTextureUnit(const String& name)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetTextureUnit_OGL(name);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetTextureUnit_D3D11(name);
- #endif
- return {}; // Prevent warning
- }
- const String& Graphics::GetTextureUnitName(TextureUnit unit)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetTextureUnitName_OGL(unit);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetTextureUnitName_D3D11(unit);
- #endif
- return String::EMPTY; // Prevent warning
- }
- Texture* Graphics::GetTexture(unsigned index) const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetTexture_OGL(index);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetTexture_D3D11(index);
- #endif
- return {}; // Prevent warning
- }
- RenderSurface* Graphics::GetRenderTarget(unsigned index) const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRenderTarget_OGL(index);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRenderTarget_D3D11(index);
- #endif
- return {}; // Prevent warning
- }
- IntVector2 Graphics::GetRenderTargetDimensions() const
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRenderTargetDimensions_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRenderTargetDimensions_D3D11();
- #endif
- return {}; // Prevent warning
- }
- void Graphics::OnWindowResized()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return OnWindowResized_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return OnWindowResized_D3D11();
- #endif
- }
- void Graphics::OnWindowMoved()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return OnWindowMoved_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return OnWindowMoved_D3D11();
- #endif
- }
- ConstantBuffer* Graphics::GetOrCreateConstantBuffer(ShaderType type, unsigned index, unsigned size)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetOrCreateConstantBuffer_OGL(type, index, size);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetOrCreateConstantBuffer_D3D11(type, index, size);
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetMaxBones()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetMaxBones_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetMaxBones_D3D11();
- #endif
- return {}; // Prevent warning
- }
- bool Graphics::GetGL3Support()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetGL3Support_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetGL3Support_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetAlphaFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetAlphaFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetAlphaFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetLuminanceFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetLuminanceFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetLuminanceFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetLuminanceAlphaFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetLuminanceAlphaFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetLuminanceAlphaFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGBFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGBFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGBFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGBAFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGBAFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGBAFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGBA16Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGBA16Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGBA16Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGBAFloat16Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGBAFloat16Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGBAFloat16Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGBAFloat32Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGBAFloat32Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGBAFloat32Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRG16Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRG16Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRG16Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGFloat16Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGFloat16Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGFloat16Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetRGFloat32Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetRGFloat32Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetRGFloat32Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetFloat16Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetFloat16Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetFloat16Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetFloat32Format()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetFloat32Format_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetFloat32Format_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetLinearDepthFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetLinearDepthFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetLinearDepthFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetDepthStencilFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetDepthStencilFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetDepthStencilFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetReadableDepthFormat()
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetReadableDepthFormat_OGL();
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetReadableDepthFormat_D3D11();
- #endif
- return {}; // Prevent warning
- }
- unsigned Graphics::GetFormat(const String& formatName)
- {
- GAPI gapi = Graphics::GetGAPI();
- #ifdef URHO3D_OPENGL
- if (gapi == GAPI_OPENGL)
- return GetFormat_OGL(formatName);
- #endif
- #ifdef URHO3D_D3D11
- if (gapi == GAPI_D3D11)
- return GetFormat_D3D11(formatName);
- #endif
- return {}; // Prevent warning
- }
- void RegisterGraphicsLibrary(Context* context)
- {
- Animation::RegisterObject(context);
- Material::RegisterObject(context);
- Model::RegisterObject(context);
- Shader::RegisterObject(context);
- Technique::RegisterObject(context);
- Texture2D::RegisterObject(context);
- Texture2DArray::RegisterObject(context);
- Texture3D::RegisterObject(context);
- TextureCube::RegisterObject(context);
- Camera::RegisterObject(context);
- Drawable::RegisterObject(context);
- Light::RegisterObject(context);
- StaticModel::RegisterObject(context);
- StaticModelGroup::RegisterObject(context);
- Skybox::RegisterObject(context);
- AnimatedModel::RegisterObject(context);
- AnimationController::RegisterObject(context);
- BillboardSet::RegisterObject(context);
- ParticleEffect::RegisterObject(context);
- ParticleEmitter::RegisterObject(context);
- RibbonTrail::RegisterObject(context);
- CustomGeometry::RegisterObject(context);
- DecalSet::RegisterObject(context);
- Terrain::RegisterObject(context);
- TerrainPatch::RegisterObject(context);
- DebugRenderer::RegisterObject(context);
- Octree::RegisterObject(context);
- Zone::RegisterObject(context);
- }
- }
|