Urho3D
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
Urho3D::Graphics Class Reference

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

#include <D3D9Graphics.h>

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

List of all members.

Public Member Functions

 Graphics (Context *context)
 Construct.
virtual ~Graphics ()
 Destruct. Close the window and release the Direct3D9 device.
void SetExternalWindow (void *window)
 Set external window handle. Only effective before setting the initial screen mode.
void SetWindowTitle (const String &windowTitle)
 Set window title.
bool SetMode (int width, int height, bool fullscreen, bool vsync, bool tripleBuffer, int multiSample)
 Set screen mode. Return true if successful.
bool SetMode (int width, int height)
 Set screen resolution only. Return true if successful.
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 (unsigned flags, const Color &color=Color(0.0f, 0.0f, 0.0f, 0.0f), float depth=1.0f, unsigned stencil=0)
 Clear any or all of rendertarget, depth buffer and stencil buffer.
bool ResolveToTexture (Texture2D *destination, const IntRect &viewport)
 Resolve multisampled backbuffer to a texture rendertarget.
void Draw (PrimitiveType type, unsigned vertexStart, unsigned vertexCount)
 Draw non-indexed geometry.
void Draw (PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount)
 Draw indexed geometry.
void DrawInstanced (PrimitiveType type, unsigned indexStart, unsigned indexCount, unsigned minVertex, unsigned vertexCount, unsigned instanceCount)
 Draw indexed, instanced geometry. An instancing vertex buffer must be set.
void SetVertexBuffer (VertexBuffer *buffer)
 Set vertex buffer.
bool SetVertexBuffers (const Vector< VertexBuffer * > &buffers, const PODVector< unsigned > &elementMasks, unsigned instanceOffset=0)
 Set multiple vertex buffers.
bool SetVertexBuffers (const Vector< SharedPtr< VertexBuffer > > &buffers, const PODVector< unsigned > &elementMasks, unsigned instanceOffset=0)
 Set multiple vertex buffers.
void SetIndexBuffer (IndexBuffer *buffer)
 Set index buffer.
void SetShaders (ShaderVariation *vs, ShaderVariation *ps)
 Set shaders.
void SetShaderParameter (StringHash param, const float *data, unsigned count)
 Set shader float constants.
void SetShaderParameter (StringHash param, float value)
 Set shader float constant.
void SetShaderParameter (StringHash param, const Color &color)
 Set shader color constant.
void SetShaderParameter (StringHash param, const Matrix3 &matrix)
 Set shader 3x3 matrix constant.
void SetShaderParameter (StringHash param, const Vector3 &vector)
 Set shader 3D vector constant.
void SetShaderParameter (StringHash param, const Matrix4 &matrix)
 Set shader 4x4 matrix constant.
void SetShaderParameter (StringHash param, const Vector4 &vector)
 Set shader 4D vector constant.
void SetShaderParameter (StringHash param, const Matrix3x4 &matrix)
 Set shader 3x4 matrix constant.
void RegisterShaderParameter (StringHash param, const ShaderParameter &definition)
 Register a shader parameter globally. Called by Shader.
bool NeedParameterUpdate (ShaderParameterGroup group, const void *source)
 Check whether a shader parameter group needs update. Does not actually check whether parameters exist in the shaders.
bool HasShaderParameter (ShaderType type, StringHash param)
 Check whether a shader parameter exists on the currently set shaders.
bool HasTextureUnit (TextureUnit unit)
 Check whether the current pixel shader uses a texture unit.
void ClearParameterSource (ShaderParameterGroup group)
 Clear remembered shader parameter source group.
void ClearParameterSources ()
 Clear remembered shader parameter sources.
void ClearTransformSources ()
 Clear remembered transform shader parameter sources.
void SetTexture (unsigned index, Texture *texture)
 Set texture.
void SetDefaultTextureFilterMode (TextureFilterMode mode)
 Set default texture filtering mode.
void SetTextureAnisotropy (unsigned level)
 Set texture anisotropy.
void ResetRenderTargets ()
 Reset all rendertargets, depth-stencil surface and viewport.
void ResetRenderTarget (unsigned index)
 Reset specific rendertarget.
void ResetDepthStencil ()
 Reset depth-stencil surface.
void SetRenderTarget (unsigned index, RenderSurface *renderTarget)
 Set rendertarget.
void SetRenderTarget (unsigned index, Texture2D *texture)
 Set rendertarget.
void SetDepthStencil (RenderSurface *depthStencil)
 Set depth-stencil surface.
void SetDepthStencil (Texture2D *texture)
 Set depth-stencil surface.
void SetViewTexture (Texture *texture)
 Set view texture (deferred rendering final output rendertarget) to prevent it from being sampled.
void SetViewport (const IntRect &rect)
 Set viewport.
void SetBlendMode (BlendMode mode)
 Set blending mode.
void SetColorWrite (bool enable)
 Set color write on/off.
void SetCullMode (CullMode mode)
 Set hardware culling mode.
void SetDepthBias (float constantBias, float slopeScaledBias)
 Set depth bias.
void SetDepthTest (CompareMode mode)
 Set depth compare.
void SetDepthWrite (bool enable)
 Set depth write on/off.
void SetFillMode (FillMode mode)
 Set polygon fill mode.
void SetScissorTest (bool enable, const Rect &rect=Rect::FULL, bool borderInclusive=true)
 Set scissor test.
void SetScissorTest (bool enable, const IntRect &rect)
 Set scissor test.
void SetStencilTest (bool enable, CompareMode mode=CMP_ALWAYS, StencilOp pass=OP_KEEP, StencilOp fail=OP_KEEP, StencilOp zFail=OP_KEEP, unsigned stencilRef=0, unsigned compareMask=M_MAX_UNSIGNED, unsigned writeMask=M_MAX_UNSIGNED)
 Set stencil test.
void SetStreamFrequency (unsigned index, unsigned frequency)
 Set vertex buffer stream frequency.
void ResetStreamFrequencies ()
 Reset stream frequencies.
void SetForceSM2 (bool enable)
 Set force Shader Model 2 flag. Only effective before setting the initial screen mode.
bool IsInitialized () const
 Return whether rendering initialized.
GraphicsImplGetImpl () const
 Return graphics implementation, which holds the actual API-specific resources.
void * GetExternalWindow () const
 Return OS-specific external window handle. Null if not in use.
const StringGetWindowTitle () const
 Return window title.
int GetWidth () const
 Return window width.
int GetHeight () const
 Return window height.
int GetMultiSample () const
 Return multisample mode (1 = no multisampling.)
bool GetFullscreen () const
 Return whether window is fullscreen.
bool GetVSync () const
 Return whether vertical sync is on.
bool GetTripleBuffer () const
 Return whether triple buffering is enabled.
bool IsDeviceLost () const
 Return whether Direct3D device is lost, and can not yet render. This happens during fullscreen resolution switching.
unsigned GetNumPrimitives () const
 Return number of primitives drawn this frame.
unsigned GetNumBatches () const
 Return number of batches drawn this frame.
unsigned GetDummyColorFormat () const
 Return dummy color texture format for shadow maps. Is "NULL" (consume no video memory) if supported.
unsigned GetShadowMapFormat () const
 Return shadow map depth texture format, or 0 if not supported.
unsigned GetHiresShadowMapFormat () const
 Return 24-bit shadow map depth texture format, or 0 if not supported.
bool GetSM3Support () const
 Return whether Shader Model 3 is supported.
bool GetLightPrepassSupport () const
 Return whether light pre-pass rendering is supported.
bool GetDeferredSupport () const
 Return whether deferred rendering is supported.
bool GetHardwareShadowSupport () const
 Return whether shadow map depth compare is done in hardware.
bool GetStreamOffsetSupport () const
 Return whether stream offset is supported.
PODVector< IntVector2GetResolutions () const
 Return supported fullscreen resolutions.
PODVector< int > GetMultiSampleLevels () const
 Return supported multisampling levels.
unsigned GetFormat (CompressedFormat format) const
 Return hardware format for a compressed image format, or 0 if unsupported.
VertexBufferGetVertexBuffer (unsigned index) const
 Return vertex buffer by index.
IndexBufferGetIndexBuffer () const
 Return current index buffer.
VertexDeclarationGetVertexDeclaration () const
 Return current vertex declaration.
ShaderVariationGetVertexShader () const
 Return current vertex shader.
ShaderVariationGetPixelShader () const
 Return current pixel shader.
TextureUnit GetTextureUnit (const String &name)
 Return texture unit index by name.
TextureGetTexture (unsigned index) const
 Return current texture by texture unit index.
TextureFilterMode GetDefaultTextureFilterMode () const
 Return default texture filtering mode.
RenderSurfaceGetRenderTarget (unsigned index) const
 Return current rendertarget by index.
RenderSurfaceGetDepthStencil () const
 Return current depth-stencil surface.
IntRect GetViewport () const
 Return the viewport coordinates.
unsigned GetTextureAnisotropy () const
 Return texture anisotropy.
BlendMode GetBlendMode () const
 Return blending mode.
bool GetColorWrite () const
 Return whether color write is enabled.
CullMode GetCullMode () const
 Return hardware culling mode.
float GetDepthConstantBias () const
 Return depth constant bias.
float GetDepthSlopeScaledBias () const
 Return depth slope scaled bias.
CompareMode GetDepthTest () const
 Return depth compare mode.
bool GetDepthWrite () const
 Return whether depth write is enabled.
FillMode GetFillMode () const
 Return polygon fill mode.
bool GetStencilTest () const
 Return whether stencil test is enabled.
bool GetScissorTest () const
 Return whether scissor test is enabled.
const IntRectGetScissorRect () const
 Return scissor rectangle coordinates.
CompareMode GetStencilTestMode () const
 Return stencil compare mode.
StencilOp GetStencilPass () const
 Return stencil operation to do if stencil test passes.
StencilOp GetStencilFail () const
 Return stencil operation to do if stencil test fails.
StencilOp GetStencilZFail () const
 Return stencil operation to do if depth compare fails.
unsigned GetStencilRef () const
 Return stencil reference value.
unsigned GetStencilCompareMask () const
 Return stencil compare bitmask.
unsigned GetStencilWriteMask () const
 Return stencil write bitmask.
unsigned GetStreamFrequency (unsigned index) const
 Return stream frequency by vertex buffer index.
IntVector2 GetRenderTargetDimensions () const
 Return rendertarget width and height.
bool GetForceSM2 () const
 Return force Shader Model 2 flag.
void AddGPUObject (GPUObject *object)
 Add a GPU object to keep track of. Called by GPUObject.
void RemoveGPUObject (GPUObject *object)
 Remove a GPU object. Called by GPUObject.
void * ReserveScratchBuffer (unsigned size)
 Reserve a CPU-side scratch buffer.
void FreeScratchBuffer (void *buffer)
 Free a CPU-side scratch buffer.
void CleanupScratchBuffers ()
 Clean up too large scratch buffers.
- Public Member Functions inherited from Urho3D::Object
 Object (Context *context)
 Construct.
virtual ~Object ()
 Destruct. Clean up self from event sender & receiver structures.
virtual ShortStringHash GetType () const =0
 Return type hash.
virtual const StringGetTypeName () const =0
 Return type name.
virtual void OnEvent (Object *sender, StringHash eventType, VariantMap &eventData)
 Handle event.
void SubscribeToEvent (StringHash eventType, EventHandler *handler)
 Subscribe to an event that can be sent by any sender.
void SubscribeToEvent (Object *sender, StringHash eventType, EventHandler *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 PODVector< StringHash > &exceptions, bool onlyUserData)
 Unsubscribe from all events except those listed, and optionally only those with userdata (script registered events.)
void SendEvent (StringHash eventType)
 Send event to all subscribers.
void SendEvent (StringHash eventType, VariantMap &eventData)
 Send event with parameters to all subscribers.
ContextGetContext () const
 Return execution context.
ObjectGetSubsystem (ShortStringHash 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.
template<class T >
T * GetSubsystem () const
 Template version of returning a subsystem.
- 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.
void AddRef ()
 Increment reference count. Can also be called outside of a SharedPtr for traditional reference counting.
void ReleaseRef ()
 Decrement reference count and delete self if no more references. Can also be called outside of a SharedPtr for traditional reference counting.
int Refs () const
 Return reference count.
int WeakRefs () const
 Return weak reference count.
RefCountRefCountPtr ()
 Return pointer to the reference count structure.

Static Public Member Functions

static unsigned GetAlphaFormat ()
 Return the API-specific alpha texture format.
static unsigned GetLuminanceFormat ()
 Return the API-specific luminance texture format.
static unsigned GetLuminanceAlphaFormat ()
 Return the API-specific luminance alpha texture format.
static unsigned GetRGBFormat ()
 Return the API-specific RGB texture format.
static unsigned GetRGBAFormat ()
 Return the API-specific RGBA texture format.
static unsigned GetRGBA16Format ()
 Return the API-specific RGBA 16-bit texture format.
static unsigned GetRGBAFloat16Format ()
 Return the API-specific RGBA 16-bit float texture format.
static unsigned GetRGBAFloat32Format ()
 Return the API-specific RGBA 32-bit float texture format.
static unsigned GetRG16Format ()
 Return the API-specific RG 16-bit texture format.
static unsigned GetRGFloat16Format ()
 Return the API-specific RG 16-bit float texture format.
static unsigned GetRGFloat32Format ()
 Return the API-specific RG 32-bit float texture format.
static unsigned GetFloat16Format ()
 Return the API-specific single channel 16-bit float texture format.
static unsigned GetFloat32Format ()
 Return the API-specific single channel 32-bit float texture format.
static unsigned GetLinearDepthFormat ()
 Return the API-specific linear depth texture format.
static unsigned GetDepthStencilFormat ()
 Return the API-specific hardware depth-stencil texture format.
static unsigned GetFormat (const String &formatName)
 Return the API-specific texture format from a textual description, for example "rgb".

Private Member Functions

 OBJECT (Graphics)
bool OpenWindow (int width, int height)
 Create the application window.
void AdjustWindow (int &newWidth, int &newHeight, bool &newFullscreen)
 Adjust the window for new resolution and fullscreen mode.
bool CreateInterface ()
 Create the Direct3D interface.
bool CreateDevice (unsigned adapter, unsigned deviceType)
 Create the Direct3D device.
void CheckFeatureSupport ()
 Check supported rendering features.
void ResetDevice ()
 Reset the Direct3D device.
void OnDeviceLost ()
 Notify all GPU resources so they can release themselves as needed.
void OnDeviceReset ()
 Notify all GPU resources so they can recreate themselves as needed.
void ResetCachedState ()
 Reset cached rendering state.
void SetTextureUnitMappings ()
 Initialize texture unit mappings.

Private Attributes

GraphicsImplimpl_
 Implementation.
String windowTitle_
 Window title.
void * externalWindow_
 External window, null if not in use (default.)
int width_
 Window width.
int height_
 Window height.
int multiSample_
 Multisampling mode.
int windowPosX_
 Stored window X-position.
int windowPosY_
 Stored window Y-position.
bool fullscreen_
 Fullscreen flag.
bool vsync_
 Vertical sync flag.
bool tripleBuffer_
 Triple buffering flag.
bool deviceLost_
 Direct3D device lost flag.
bool lightPrepassSupport_
 Light pre-pass rendering support flag.
bool deferredSupport_
 Deferred rendering support flag.
bool hardwareShadowSupport_
 Hardware shadow map depth compare support flag.
bool streamOffsetSupport_
 Stream offset support flag.
bool hasSM3_
 Shader Model 3 flag.
bool forceSM2_
 Force Shader Model 2 flag.
unsigned numPrimitives_
 Number of primitives this frame.
unsigned numBatches_
 Number of batches this frame.
unsigned maxScratchBufferRequest_
 Largest scratch buffer request this frame.
Vector< GPUObject * > gpuObjects_
 GPU objects.
Vector< ScratchBufferscratchBuffers_
 Scratch buffers.
HashMap< unsigned long long,
SharedPtr< VertexDeclaration > > 
vertexDeclarations_
 Vertex declarations.
unsigned dummyColorFormat_
 Shadow map dummy color texture format.
unsigned shadowMapFormat_
 Shadow map depth texture format.
unsigned hiresShadowMapFormat_
 Shadow map 24-bit depth texture format.
VertexBuffervertexBuffers_ [MAX_VERTEX_STREAMS]
 Vertex buffers in use.
unsigned streamFrequencies_ [MAX_VERTEX_STREAMS]
 Stream frequencies by vertex buffer.
unsigned streamOffsets_ [MAX_VERTEX_STREAMS]
 Stream offsets by vertex buffer.
IndexBufferindexBuffer_
 Index buffer in use.
VertexDeclarationvertexDeclaration_
 Vertex declaration in use.
ShaderVariationvertexShader_
 Vertex shader in use.
ShaderVariationpixelShader_
 Pixel shader in use.
HashMap< StringHash,
ShaderParameter
shaderParameters_
 All known shader parameters.
Texturetextures_ [MAX_TEXTURE_UNITS]
 Textures in use.
HashMap< String, TextureUnit > textureUnits_
 Texture unit mappings.
RenderSurfacerenderTargets_ [MAX_RENDERTARGETS]
 Rendertargets in use.
RenderSurfacedepthStencil_
 Depth-stencil surface in use.
TextureviewTexture_
 View texture.
IntRect viewport_
 Viewport coordinates.
unsigned textureAnisotropy_
 Texture anisotropy level.
BlendMode blendMode_
 Blending mode.
bool colorWrite_
 Color write enable.
CullMode cullMode_
 Hardware culling mode.
float constantDepthBias_
 Depth constant bias.
float slopeScaledDepthBias_
 Depth slope scaled bias.
CompareMode depthTestMode_
 Depth compare mode.
bool depthWrite_
 Depth write enable flag.
FillMode fillMode_
 Polygon fill mode.
IntRect scissorRect_
 Scissor test rectangle.
bool scissorTest_
 Scissor test enable flag.
CompareMode stencilTestMode_
 Stencil test compare mode.
StencilOp stencilPass_
 Stencil operation on pass.
StencilOp stencilFail_
 Stencil operation on fail.
StencilOp stencilZFail_
 Stencil operation on depth fail.
bool stencilTest_
 Stencil test enable flag.
unsigned stencilRef_
 Stencil test reference value.
unsigned stencilCompareMask_
 Stencil compare bitmask.
unsigned stencilWriteMask_
 Stencil write bitmask.
TextureFilterMode defaultTextureFilterMode_
 Default texture filtering mode.
const void * shaderParameterSources_ [MAX_SHADER_PARAMETER_GROUPS]
 Remembered shader parameter sources.

Additional Inherited Members

- Protected Attributes inherited from Urho3D::Object
Contextcontext_
 Execution context.

Detailed Description

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


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