Rebel Fork Framework
Urho3D::Graphics Class Reference

Graphics subsystem. Manages the application window, rendering state and GPU resources. More...

#include <Urho3D/Graphics/Graphics.h>

Inheritance diagram for Urho3D::Graphics:
Urho3D::Object Urho3D::RefCounted

Public Member Functions

 Graphics (Context *context)
 ~Graphics () override
 Destruct. Release the Direct3D11 device and close the window.
void Configure (const GraphicsSettings &settings)
 Configure before initial setup.
void SetWindowTitle (const ea::string &windowTitle)
void SetWindowIcon (Image *windowIcon)
void SetWindowPosition (const IntVector2 &position)
void SetWindowPosition (int x, int y)
 Set window position. Sets initial position if window is not created yet.
bool SetScreenMode (const WindowSettings &windowSettings)
bool SetWindowModes (const WindowSettings &primarySettings, const WindowSettings &secondarySettings)
bool SetDefaultWindowModes (const WindowSettings &commonSettings)
 Set default window modes. Return true if successful.
bool SetMode (int width, int height, bool fullscreen, bool borderless, bool resizable, bool highDPI, bool vsync, bool tripleBuffer, int multiSample, int monitor, int refreshRate)
 Set default window modes. Deprecated. Return true if successful.
bool SetMode (int width, int height)
 Set screen resolution only. Deprecated. Return true if successful.
void InitializePipelineStateCache (const FileIdentifier &fileName)
void SavePipelineStateCache (const FileIdentifier &fileName)
 Save pipeline state cache.
bool ToggleFullscreen ()
 Toggle between full screen and windowed mode. Return true if successful.
void Close ()
 Close the window.
bool TakeScreenShot (Image &destImage)
 Take a screenshot. Return true if successful.
bool BeginFrame ()
 Begin frame rendering. Return true if device available and can render.
void EndFrame ()
 End frame rendering and swap buffers.
void Clear (ClearTargetFlags flags, const Color &color=Color::TRANSPARENT_BLACK, float depth=1.0f, unsigned stencil=0)
 Clear any or all of rendertarget, depth buffer and stencil buffer.
void ResetRenderTargets ()
 Reset all rendertargets, depth-stencil surface and viewport.
bool IsInitialized () const
void * GetExternalWindow () const
 Return OS-specific external window handle. Null if not in use.
SDL_Window * GetWindow () const
 Return SDL window.
const ea::string & GetWindowTitle () const
const ea::string & GetApiName () const
IntVector2 GetWindowPosition () const
const WindowSettings & GetWindowSettings () const
 Return screen mode parameters.
const IntVector2 GetSwapChainSize () const
 Return swap chain size.
int GetWidth () const
int GetHeight () const
int GetMultiSample () const
IntVector2 GetSize () const
bool GetFullscreen () const
bool GetBorderless () const
bool GetResizable () const
bool GetVSync () const
int GetRefreshRate () const
 Return refresh rate when using vsync in fullscreen.
int GetMonitor () const
 Return the current monitor index. Effective on in fullscreen.
bool GetSRGB () const
TextureFormat GetDummyColorFormat () const
 Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported.
TextureFormat GetShadowMapFormat () const
 Return shadow map depth texture format, or 0 if not supported.
TextureFormat GetHiresShadowMapFormat () const
 Return 24-bit shadow map depth texture format, or 0 if not supported.
bool GetInstancingSupport () const
bool GetHardwareShadowSupport () const
ea::vector< IntVector3GetResolutions (int monitor) const
unsigned FindBestResolutionIndex (int monitor, int width, int height, int refreshRate) const
 Return index of the best resolution for requested width, height and refresh rate.
IntVector2 GetDesktopResolution (int monitor) const
int GetMonitorCount () const
int GetCurrentMonitor () const
bool GetMaximized () const
Vector3 GetDisplayDPI (int monitor=0) const
TextureFormat GetFormat (CompressedFormat format) const
 Return hardware format for a compressed image format, or 0 if unsupported.
ShaderVariationGetShader (ShaderType type, const ea::string &name, const ea::string &defines=EMPTY_STRING) const
 Return a shader variation by name and defines.
ShaderVariationGetShader (ShaderType type, const char *name, const char *defines) const
 Return a shader variation by name and defines.
IntVector2 GetRenderTargetDimensions () const
 Return current rendertarget width and height.
void OnWindowResized ()
 Window was resized through user interaction. Called by Input subsystem.
void OnWindowMoved ()
 Window was moved through user interaction. Called by Input subsystem.
void Restore ()
void Maximize ()
 Maximize the window.
void Minimize ()
 Minimize the window.
void Raise () const
 Raises window if it was minimized.
void * GetSDLWindow ()
 Get the SDL_Window as a void* to avoid having to include the graphics implementation.
RenderBackend GetRenderBackend () const
const GraphicsSettingsGetSettings () const
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 ~Object () override
 Destruct. Clean up self from event sender & receiver structures.
virtual StringHash GetType () const =0
virtual const ea::string & GetTypeName () const =0
virtual const TypeInfoGetTypeInfo () const =0
 Return type info.
virtual bool IsInstanceOf (StringHash type) const =0
 Check whether current instance implements specified type.
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
virtual void SerializeInBlock (Archive &archive)
 Serialize content from/to archive. May throw ArchiveException.
template<typename T >
bool IsInstanceOf () const
 Check current instance is type of specified class.
template<typename T >
T * Cast ()
 Cast the object to specified most derived class.
template<typename T >
const T * Cast () const
 Cast the object to specified most derived class.
void SubscribeToEventManual (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
void SubscribeToEventManual (Object *sender, StringHash eventType, EventHandler *handler)
 Subscribe to a specific sender's event.
template<class T >
void SubscribeToEvent (StringHash eventType, T handler)
 Subscribe to an event that can be sent by any sender.
template<class T >
void SubscribeToEvent (Object *sender, StringHash eventType, T handler)
 Subscribe to a specific sender's event.
void UnsubscribeFromEvent (StringHash eventType)
 Unsubscribe from an event.
void UnsubscribeFromEvent (Object *sender, StringHash eventType)
 Unsubscribe from a specific sender's event.
void UnsubscribeFromEvents (Object *sender)
 Unsubscribe from a specific sender's events.
void UnsubscribeFromAllEvents ()
 Unsubscribe from all events.
void UnsubscribeFromAllEventsExcept (const ea::vector< StringHash > &exceptions)
 Unsubscribe from all events except those listed.
void UnsubscribeFromAllEventsExcept (const ea::vector< Object * > &exceptions)
 Unsubscribe from all events except those with listed senders.
void SendEvent (StringHash eventType)
 Send event to all subscribers.
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
VariantMapGetEventDataMap () const
 Return a preallocated map for event data. Used for optimization to avoid constant re-allocation of event data maps.
template<typename... Args>
void SendEvent (StringHash eventType, const Args &... args)
 Send event with variadic parameter pairs to all subscribers. The parameters are (paramID, paramValue) pairs.
ContextGetContext () const
 Return execution context.
const VariantGetGlobalVar (StringHash key) const
const VariantMapGetGlobalVars () const
void SetGlobalVar (StringHash key, const Variant &value)
ObjectGetSubsystem (StringHash type) const
 Return subsystem by type.
ObjectGetEventSender () const
 Return active event sender. Null outside event handling.
EventHandlerGetEventHandler () const
 Return active event handler. Null outside event handling.
bool HasSubscribedToEvent (StringHash eventType) const
 Return whether has subscribed to an event without specific sender.
bool HasSubscribedToEvent (Object *sender, StringHash eventType) const
 Return whether has subscribed to a specific sender's event.
bool HasEventHandlers () const
 Return whether has subscribed to any event.
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
const ea::string & GetCategory () const
void SendEvent (StringHash eventType, const VariantMap &eventData)
 Send event with parameters to all subscribers.
void SetBlockEvents (bool block)
 Block object from sending and receiving events.
bool GetBlockEvents () const
 Return sending and receiving events blocking status.
- Public Member Functions inherited from Urho3D::RefCounted
 RefCounted ()
 Construct. Allocate the reference count structure and set an initial self weak reference.
virtual ~RefCounted ()
 Destruct. Mark as expired and also delete the reference count structure if no outside weak references exist.
 RefCounted (const RefCounted &rhs)=delete
 Prevent copy construction.
RefCountedoperator= (const RefCounted &rhs)=delete
 Prevent assignment.
int AddRef ()
int ReleaseRef ()
int Refs () const
int WeakRefs () const
RefCountRefCountPtr () const
 Return pointer to the reference count structure.
bool HasScriptObject () const
 Return true if script runtime object wrapping this native object exists.
bool IsScriptStrongRef () const
 Return true if script reference is strong.

Static Public Member Functions

static void SetMaxBones (unsigned maxBones)
 Sets the maximum number of supported bones for hardware skinning. Check GPU capabilities before setting.
static unsigned GetMaxBones ()
 Return maximum number of supported bones for skinning. More...
static bool GetGL3Support ()
 Return whether is using an OpenGL 3 context. Return always false on DirectX 11.
- Static Public Member Functions inherited from Urho3D::Object
static const TypeInfoGetTypeInfoStatic ()
 Return type info static.

Private Member Functions

 URHO3D_OBJECT (Graphics, Object)
void CreateWindowIcon ()
 Create the application window icon.
void OnScreenModeChanged ()
 Called when screen mode is successfully changed by the backend.

Private Attributes

SDL_Window * window_ {}
 SDL window.
ea::string windowTitle_
 Window title.
WeakPtr< ImagewindowIcon_
 Window icon image.
WindowSettings primaryWindowSettings_
WindowSettings secondaryWindowSettings_
 Secondary window mode to be applied on Graphics::ToggleFullscreen.
IntVector2 position_
 Window position.
bool etcTextureSupport_ {}
 ETC1 format support flag.
bool etc2TextureSupport_ {}
 ETC2 format support flag.
bool pvrtcTextureSupport_ {}
 PVRTC formats support flag.
ea::string shaderPath_
 Base directory for shaders.
ea::string universalShaderNamePrefix_ { "v2/" }
 Shader name prefix for universal shaders.
ea::string universalShaderPath_ { "Shaders/GLSL/{}.glsl" }
 Format string for universal shaders.
ea::string shaderExtension_
 File extension for shaders.
WeakPtr< ShaderlastShader_
 Last used shader in shader variation query.
ea::string lastShaderName_
 Last used shader name in shader variation query.
ea::string apiName_
 Graphics API name.
GraphicsSettings settings_
SharedPtr< RenderDevice > renderDevice_

Static Private Attributes

static unsigned maxBonesHWSkinned = 0
 Max number of bones which can be skinned on GPU. Zero means default value.

Additional Inherited Members

- Static Public Attributes inherited from Urho3D::Object
static constexpr ea::array< StringHash, 0 > TypeHierarchy {}
- Protected Attributes inherited from Urho3D::Object
WeakPtr< Contextcontext_
 Execution context.

Detailed Description

Graphics subsystem. Manages the application window, rendering state and GPU resources.

Member Function Documentation

◆ GetApiName()

const ea::string& Urho3D::Graphics::GetApiName ( ) const

Return graphics API name.

◆ GetBorderless()

bool Urho3D::Graphics::GetBorderless ( ) const

Return whether window is borderless.

◆ GetCurrentMonitor()

int Urho3D::Graphics::GetCurrentMonitor ( ) const

Returns the index of the display containing the center of the window on success or a negative error code on failure.

◆ GetDesktopResolution()

IntVector2 Urho3D::Graphics::GetDesktopResolution ( int  monitor) const

Return the desktop resolution.

◆ GetDisplayDPI()

Vector3 Urho3D::Graphics::GetDisplayDPI ( int  monitor = 0) const

Return display dpi information: (hdpi, vdpi, ddpi). On failure returns zero vector.

◆ GetFullscreen()

bool Urho3D::Graphics::GetFullscreen ( ) const

Return whether window is fullscreen.

◆ GetHardwareShadowSupport()

bool Urho3D::Graphics::GetHardwareShadowSupport ( ) const

Return whether shadow map depth compare is done in hardware.

◆ GetHeight()

int Urho3D::Graphics::GetHeight ( ) const

Return window height in pixels.

◆ GetInstancingSupport()

bool Urho3D::Graphics::GetInstancingSupport ( ) const

Return whether hardware instancing is supported.

◆ GetMaxBones()

unsigned Urho3D::Graphics::GetMaxBones ( )

Return maximum number of supported bones for skinning.

User-specified number of bones

◆ GetMaximized()

bool Urho3D::Graphics::GetMaximized ( ) const

Returns true if window is maximized or runs in full screen mode.

◆ GetMonitorCount()

int Urho3D::Graphics::GetMonitorCount ( ) const

Return the number of currently connected monitors.

◆ GetMultiSample()

int Urho3D::Graphics::GetMultiSample ( ) const

Return multisample mode (1 = no multisampling).

◆ GetRenderBackend()

RenderBackend Urho3D::Graphics::GetRenderBackend ( ) const


◆ GetResizable()

bool Urho3D::Graphics::GetResizable ( ) const

Return whether window is resizable.

◆ GetResolutions()

ea::vector< IntVector3 > Urho3D::Graphics::GetResolutions ( int  monitor) const

Return supported fullscreen resolutions (third component is refreshRate). Will be empty if listing the resolutions is not supported on the platform (e.g. Web).

◆ GetSize()

IntVector2 Urho3D::Graphics::GetSize ( ) const

Return window size in pixels.

◆ GetSRGB()

bool Urho3D::Graphics::GetSRGB ( ) const

Return whether the main window is using sRGB conversion on write.

◆ GetVSync()

bool Urho3D::Graphics::GetVSync ( ) const

Return whether vertical sync is on.

◆ GetWidth()

int Urho3D::Graphics::GetWidth ( ) const

Return window width in pixels.

◆ GetWindowPosition()

IntVector2 Urho3D::Graphics::GetWindowPosition ( ) const

Return window position.

◆ GetWindowTitle()

const ea::string& Urho3D::Graphics::GetWindowTitle ( ) const

Return window title.

◆ InitializePipelineStateCache()

void Urho3D::Graphics::InitializePipelineStateCache ( const FileIdentifier fileName)

Initialize pipeline state cache. Should be called after GPU is initialized and before pipeline states are created.

◆ IsInitialized()

bool Urho3D::Graphics::IsInitialized ( ) const

Return whether rendering initialized.

◆ Restore()

void Urho3D::Graphics::Restore ( )

Restore GPU objects and reinitialize state. Requires an open window. Used only on OpenGL.

◆ SetScreenMode()

bool Urho3D::Graphics::SetScreenMode ( const WindowSettings &  windowSettings)

Set screen mode. Return true if successful. Don't use SetScreenMode if ToggleFullscreen is used directly or indirectly.

◆ SetWindowIcon()

void Urho3D::Graphics::SetWindowIcon ( Image windowIcon)

Set window icon.

◆ SetWindowModes()

bool Urho3D::Graphics::SetWindowModes ( const WindowSettings &  primarySettings,
const WindowSettings &  secondarySettings 

Set window modes to be rotated by ToggleFullscreen. Apply primary window settings immediately. Return true if successful.

◆ SetWindowPosition()

void Urho3D::Graphics::SetWindowPosition ( const IntVector2 position)

Set window position. Sets initial position if window is not created yet.

◆ SetWindowTitle()

void Urho3D::Graphics::SetWindowTitle ( const ea::string &  windowTitle)

Set window title.

Member Data Documentation

◆ primaryWindowSettings_

WindowSettings Urho3D::Graphics::primaryWindowSettings_

Most recently applied window settings. It may not represent actual window state if window was resized by user or Graphics::SetScreenMode was explicitly called.

The documentation for this class was generated from the following files: