| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662 |
- //
- // Copyright (c) 2008-2022 the Urho3D project.
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to deal
- // in the Software without restriction, including without limitation the rights
- // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- // copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- // THE SOFTWARE.
- //
- #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/GraphicsImpl.h"
- #include "../Graphics/Material.h"
- #include "../Graphics/Octree.h"
- #include "../Graphics/ParticleEffect.h"
- #include "../Graphics/ParticleEmitter.h"
- #include "../Graphics/RibbonTrail.h"
- #include "../Graphics/Shader.h"
- #include "../Graphics/ShaderPrecache.h"
- #include "../Graphics/Skybox.h"
- #include "../Graphics/StaticModelGroup.h"
- #include "../Graphics/Technique.h"
- #include "../Graphics/Terrain.h"
- #include "../Graphics/TerrainPatch.h"
- #ifdef _WIN32
- #include "../Graphics/Texture2D.h"
- #endif
- #include "../Graphics/Texture2DArray.h"
- #include "../Graphics/Texture3D.h"
- #include "../Graphics/TextureCube.h"
- #include "../Graphics/Zone.h"
- #include "../IO/FileSystem.h"
- #include "../IO/Log.h"
- #include <SDL/SDL.h>
- #include "../DebugNew.h"
- #ifdef _WIN32
- // Prefer the high-performance GPU on switchable GPU systems
- #include <windows.h>
- extern "C"
- {
- __declspec(dllexport) DWORD NvOptimusEnablement = 1;
- __declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
- }
- #endif
- 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 PODVector<unsigned char>& 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_;
- }
- PODVector<IntVector3> Graphics::GetResolutions(int monitor) const
- {
- PODVector<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;
- }
- unsigned Graphics::FindBestResolutionIndex(int monitor, int width, int height, int refreshRate) const
- {
- const PODVector<IntVector3> resolutions = GetResolutions(monitor);
- if (resolutions.Empty())
- return M_MAX_UNSIGNED;
- unsigned best = 0;
- unsigned bestError = M_MAX_UNSIGNED;
- for (unsigned i = 0; i < resolutions.Size(); ++i)
- {
- auto error = static_cast<unsigned>(Abs(resolutions[i].x_ - width) + Abs(resolutions[i].y_ - height));
- if (refreshRate != 0)
- error += static_cast<unsigned>(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(unsigned size)
- {
- if (!size)
- return nullptr;
- if (size > maxScratchBufferRequest_)
- maxScratchBufferRequest_ = size;
- // First check for a free buffer that is large enough
- for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
- {
- if (!i->reserved_ && i->size_ >= size)
- {
- i->reserved_ = true;
- return i->data_.Get();
- }
- }
- // Then check if a free buffer can be resized
- for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
- {
- if (!i->reserved_)
- {
- i->data_ = new unsigned char[size];
- i->size_ = size;
- i->reserved_ = true;
- URHO3D_LOGDEBUG("Resized scratch buffer to size " + String(size));
- return i->data_.Get();
- }
- }
- // Finally allocate a new buffer
- ScratchBuffer newBuffer;
- newBuffer.data_ = new unsigned char[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 (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
- {
- if (i->reserved_ && i->data_.Get() == buffer)
- {
- i->reserved_ = false;
- return;
- }
- }
- URHO3D_LOGWARNING("Reserved scratch buffer " + ToStringHex((unsigned)(size_t)buffer) + " not found");
- }
- void Graphics::CleanupScratchBuffers()
- {
- for (Vector<ScratchBuffer>::Iterator i = scratchBuffers_.Begin(); i != scratchBuffers_.End(); ++i)
- {
- if (!i->reserved_ && i->size_ > maxScratchBufferRequest_ * 2 && i->size_ >= 1024 * 1024)
- {
- i->data_ = maxScratchBufferRequest_ > 0 ? (new unsigned char[maxScratchBufferRequest_]) : nullptr;
- i->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 PODVector<IntVector3> resolutions = GetResolutions(params.monitor_);
- if (!resolutions.Empty())
- {
- const unsigned 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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 PODVector<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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- PODVector<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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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
- }
- 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);
- }
- }
|