4 using System.Collections.Generic;
5 using SiliconStudio.Core;
6 using SiliconStudio.Core.Mathematics;
7 using SiliconStudio.Paradox.Effects;
8 using SiliconStudio.Paradox.Graphics.Internals;
10 namespace SiliconStudio.
Paradox.Graphics
17 public static readonly
int ThreadCount = 1;
19 internal readonly Dictionary<SamplerStateDescription, SamplerState> CachedSamplerStates =
new Dictionary<SamplerStateDescription, SamplerState>();
20 internal readonly Dictionary<BlendStateDescription, BlendState> CachedBlendStates =
new Dictionary<BlendStateDescription, BlendState>();
21 internal readonly Dictionary<RasterizerStateDescription, RasterizerState> CachedRasterizerStates =
new Dictionary<RasterizerStateDescription, RasterizerState>();
22 internal readonly Dictionary<VertexArrayObject.Description,
VertexArrayObject> CachedVertexArrayObjects =
new Dictionary<VertexArrayObject.Description,
VertexArrayObject>();
29 internal HashSet<GraphicsResourceBase> Resources =
new HashSet<GraphicsResourceBase>();
31 internal readonly
bool NeedWorkAroundForUpdateSubResource;
32 internal readonly ShaderStageSetup StageStatus =
new ShaderStageSetup();
33 internal Effect CurrentEffect;
34 private readonly
bool isDeferred;
37 private readonly Dictionary<object, IDisposable> sharedDataPerDevice;
38 private readonly Dictionary<object, IDisposable> sharedDataPerDeviceContext =
new Dictionary<object, IDisposable>();
59 sharedDataPerDevice =
new Dictionary<object, IDisposable>();
61 Recreate(adapter, profile, deviceCreationFlags, windowHandle);
69 if (adapter == null)
throw new ArgumentNullException(
"adapter");
70 if (profile == null)
throw new ArgumentNullException(
"profile");
73 IsDebugMode = (deviceCreationFlags & DeviceCreationFlags.Debug) != 0;
76 InitializePlatformDevice(profile, deviceCreationFlags, windowHandle);
81 InitializeFactories();
83 if (SamplerStates == null)
96 DestroyPlatformDevice();
99 if (Disposing != null)
102 SamplerStates.Dispose();
103 BlendStates.Dispose();
104 RasterizerStates.Dispose();
106 DepthStencilBuffer.Dispose();
107 primitiveQuad.Dispose();
125 internal delegate T CreateSharedData<out T>() where T :
class, IDisposable;
142 return Presenter != null ? Presenter.BackBuffer : null;
164 return Presenter != null ? Presenter.DepthStencilBuffer : null;
182 public bool IsDebugMode {
get;
private set; }
190 public bool IsDeferred
201 public bool IsProfilingSupported {
get;
private set; }
228 if (presenter != null)
231 SetRenderTargets(presenter.DepthStencilBuffer, presenter.BackBuffer);
232 SetViewport(presenter.DefaultViewport);
264 public int ThreadIndex {
get;
internal set; }
315 primitiveQuad.Draw();
345 DrawTexture(texture, null, color);
357 primitiveQuad.Draw(texture, sampler, color);
365 if (Presenter != null)
377 SetRenderTarget(depthStencilBuffer, null);
386 SetRenderTarget(null, renderTargetView);
395 SetRenderTargets(null, renderTargetViews);
408 internal T GetOrCreateSharedData<T>(GraphicsDeviceSharedDataType type,
object key, CreateSharedData<T> sharedDataCreator) where T :
class, IDisposable
410 Dictionary<object, IDisposable> dictionary = (type == GraphicsDeviceSharedDataType.PerDevice) ? sharedDataPerDevice : sharedDataPerDeviceContext;
414 IDisposable localValue;
415 if (!dictionary.TryGetValue(key, out localValue))
417 localValue = sharedDataCreator();
418 if (localValue == null)
423 localValue = localValue.DisposeBy(
this);
424 dictionary.Add(key, localValue);
426 return (T)localValue;
EventHandler< EventArgs > Disposing
Occurs while this component is disposing and before it is disposed.
static GraphicsAdapter Default
Gets the default adapter. This property can be null.
Primitive quad use to draw an effect on a quad (fullscreen by default). This is directly accessible f...
A renderable texture view.
void Present()
Presents the current Presenter.
void SetRenderTarget(DepthStencilBuffer depthStencilBuffer)
Sets a new depthStencilBuffer to this GraphicsDevice. If there is any RenderTarget already bound...
void Recreate(GraphicsAdapter adapter, GraphicsProfile[] profile, DeviceCreationFlags deviceCreationFlags, WindowHandle windowHandle)
void DrawTexture(Texture texture, SamplerState sampler, Color4 color)
Draws a fullscreen texture using the specified sampler and the texture color multiplied by a custom c...
Base factory for BlendState.
A platform specific window handle.
Factory for GraphicsAdapter.
Base factory for IDepthStencilState.
void DrawQuad()
Draws a full screen quad. An Effect must be applied before calling this method.
static readonly Color4 White
The White color (1, 1, 1, 1).
Base class for a framework component.
static GraphicsDevice New(GraphicsAdapter adapter, DeviceCreationFlags creationFlags=DeviceCreationFlags.None, params GraphicsProfile[] graphicsProfiles)
Initializes a new instance of the GraphicsDevice class.
Represents a color in the form of rgba.
Performs primitive-based rendering, creates resources, handles system-level variables, adjusts gamma ramp levels, and creates shaders. See The+GraphicsDevice+class to learn more about the class.
This class is a frontend to SwapChain and SwapChain1.
void DrawTexture(Texture texture, Color4 color)
Draws a fullscreen texture using a SamplerStateFactory.LinearClamp sampler and the texture color mult...
void SetRenderTarget(RenderTarget renderTargetView)
Binds a single render target to the output-merger stage. See Textures+and+render+targets to learn how...
GraphicsDevice(GraphicsAdapter adapter, GraphicsProfile[] profile, DeviceCreationFlags deviceCreationFlags, WindowHandle windowHandle)
Initializes a new instance of the GraphicsDevice class.
static GraphicsDevice New(GraphicsAdapter adapter, DeviceCreationFlags creationFlags=DeviceCreationFlags.None, WindowHandle windowHandle=null, params GraphicsProfile[] graphicsProfiles)
Initializes a new instance of the GraphicsDevice class.
This class represents a graphics adapter.
static GraphicsDevice New(DeviceCreationFlags creationFlags=DeviceCreationFlags.None, params GraphicsProfile[] graphicsProfiles)
Initializes a new instance of the GraphicsDevice class.
GraphicsDeviceFeatures Features
Gets the features supported by this graphics device.
Features supported by a GraphicsDevice.
Base factory for SamplerState.
void DrawTexture(Texture texture)
Draws a fullscreen texture using a SamplerStateFactory.LinearClamp sampler. See Draw+a+texture to lea...
void DrawTexture(Texture texture, SamplerState sampler)
Draws a fullscreen texture using the specified sampler. See Draw+a+texture to learn how to use it...
void SetRenderTargets(params RenderTarget[] renderTargetViews)
GraphicsProfile
Identifies the set of supported devices for the demo based on device capabilities.
override void Destroy()
Disposes of object resources.
A container to handle a hierarchical collection of effect variables.
Base factory for RasterizerState.
Base class for texture resources.