| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721 |
- // Copyright (c) 2008-2022 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.GetInt());
- 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<u8>& 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__
- auto numModes = (unsigned)SDL_GetNumDisplayModes(monitor);
- for (unsigned 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 (unsigned j = 0; j < ret.Size(); ++j)
- {
- if (ret[j].x_ == width && ret[j].y_ == height && ret[j].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_D3D9
- if (gapi == GAPI_D3D9)
- {
- Constructor_D3D9();
- 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_D3D9
- if (gapi == GAPI_D3D9)
- {
- Destructor_D3D9();
- 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_D3D9
- if (gapi == GAPI_D3D9)
- return SetScreenMode_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetSRGB_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDither_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetFlushGPU_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetForceGL2_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return Close_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return TakeScreenShot_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return BeginFrame_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return EndFrame_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return Clear_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ResolveToTexture_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ResolveToTexture_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ResolveToTexture_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return Draw_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return Draw_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return Draw_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return DrawInstanced_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return DrawInstanced_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetVertexBuffer_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetVertexBuffers_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetVertexBuffers_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetIndexBuffer_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaders_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return NeedParameterUpdate_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return HasShaderParameter_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return HasTextureUnit_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ClearParameterSource_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ClearParameterSources_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return ClearTransformSources_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return SetTexture_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDefaultTextureFilterMode_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDefaultTextureAnisotropy_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ResetRenderTargets_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return ResetRenderTarget_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return ResetDepthStencil_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return SetRenderTarget_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetRenderTarget_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDepthStencil_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDepthStencil_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetViewport_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetBlendMode_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetColorWrite_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetCullMode_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDepthBias_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDepthTest_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetDepthWrite_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetFillMode_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetLineAntiAlias_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetScissorTest_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetScissorTest_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return SetClipPlane_D3D9(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, unsigned stencilRef,
- unsigned compareMask, unsigned 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_D3D9
- if (gapi == GAPI_D3D9)
- return SetStencilTest_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return IsInitialized_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetDither_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return IsDeviceLost_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetMultiSampleLevels_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetFormat_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetShader_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetShader_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetVertexBuffer_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetTextureUnit_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetTextureUnitName_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetTexture_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRenderTarget_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRenderTargetDimensions_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return OnWindowResized_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return OnWindowMoved_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetOrCreateConstantBuffer_D3D9(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_D3D9
- if (gapi == GAPI_D3D9)
- return GetMaxBones_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetGL3Support_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetAlphaFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetLuminanceFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetLuminanceAlphaFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGBFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGBAFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGBA16Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGBAFloat16Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGBAFloat32Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRG16Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGFloat16Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetRGFloat32Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetFloat16Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetFloat32Format_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetLinearDepthFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetDepthStencilFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetReadableDepthFormat_D3D9();
- #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_D3D9
- if (gapi == GAPI_D3D9)
- return GetFormat_D3D9(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);
- }
- }
|