本文整理汇总了C#中Microsoft.Xna.Framework.Graphics.GraphicsDevice类的典型用法代码示例。如果您正苦于以下问题:C# GraphicsDevice类的具体用法?C# GraphicsDevice怎么用?C# GraphicsDevice使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GraphicsDevice类属于Microsoft.Xna.Framework.Graphics命名空间,在下文中一共展示了GraphicsDevice类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateDevice
private void CreateDevice(IntPtr windowHandle, int width, int height)
{
try
{
parameters = new PresentationParameters();
parameters.BackBufferWidth = Math.Max(width, 1);
parameters.BackBufferHeight = Math.Max(height, 1);
parameters.BackBufferFormat = SurfaceFormat.Color;
parameters.DepthStencilFormat = DepthFormat.Depth24;
parameters.DeviceWindowHandle = windowHandle;
parameters.PresentationInterval = PresentInterval.Immediate;
parameters.IsFullScreen = false;
graphicsDevice = new GraphicsDevice(
GraphicsAdapter.DefaultAdapter,
GraphicsProfile.Reach,
parameters);
if (DeviceCreated != null)
DeviceCreated(this, EventArgs.Empty);
}
catch (Exception ex)
{
throw new ApplicationException("Failed to initialize GraphicsDeviceService. See inner exception for details.", ex);
}
}
示例2: TextureContext
public TextureContext(GraphicsDevice graphicsDevice, Stream stream, bool premultiplyAlpha)
{
_texture = Texture2D.FromStream(graphicsDevice, stream);
if (premultiplyAlpha)
PremultiplyTexture(_texture);
}
示例3: Draw
public override void Draw(GraphicsDevice device)
{
for (int i = 0; i < m_Elements.Count; i++)
{
m_Elements[i].Draw(device);
}
}
示例4: Reset
public static unsafe void Reset(GraphicsDevice graphicsDevice, PresentationParameters parameters)
{
var fi = typeof(GraphicsDevice).GetField("pComPtr", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var ptr = fi.GetValue(graphicsDevice);
var pComPtr = new IntPtr(System.Reflection.Pointer.Unbox(ptr));
if (g_mdxAssembly == null) throw new ApplicationException("GraphicsDevice.Reset failed. Please install Managed DirectX from the Assault Wing web site.");
var mdxDeviceType = g_mdxAssembly.GetType("Microsoft.DirectX.Direct3D.Device");
var mdxPresentParametersType = g_mdxAssembly.GetType("Microsoft.DirectX.Direct3D.PresentParameters");
var dev = Activator.CreateInstance(mdxDeviceType, pComPtr);
dynamic dxParameters = new MDXPresentParameters(Activator.CreateInstance(mdxPresentParametersType));
dxParameters.AutoDepthStencilFormat = parameters.DepthStencilFormat.ToD3D();
dxParameters.BackBufferCount = 1;
dxParameters.BackBufferFormat = parameters.BackBufferFormat.ToD3D();
dxParameters.BackBufferHeight = parameters.BackBufferHeight;
dxParameters.BackBufferWidth = parameters.BackBufferWidth;
dxParameters.DeviceWindow = null;
dxParameters.DeviceWindowHandle = parameters.DeviceWindowHandle;
dxParameters.EnableAutoDepthStencil = false; // ???
dxParameters.ForceNoMultiThreadedFlag = false; // ???
dxParameters.FullScreenRefreshRateInHz = 0; // ??? should be 0 for windowed mode; in fullscreen mode take value from DisplayModeCollection
dxParameters.MultiSample = GetMDXEnumValue("MultiSampleType", "None");
dxParameters.MultiSampleQuality = 0;
dxParameters.PresentationInterval = parameters.PresentationInterval.ToD3D();
dxParameters.PresentFlag = GetMDXEnumValue("PresentFlag", "None"); // ???
dxParameters.SwapEffect = GetMDXEnumValue("SwapEffect", "Flip"); // ??? see _parameters.RenderTargetUsage
dxParameters.Windowed = !parameters.IsFullScreen;
var resetMethod = mdxDeviceType.GetMethod("Reset");
var mdxPresentParametersArray = Array.CreateInstance(mdxPresentParametersType, 1);
mdxPresentParametersArray.SetValue(((MDXPresentParameters)dxParameters).WrappedValue, 0);
resetMethod.Invoke(dev, new[] { mdxPresentParametersArray });
}
示例5: TextTest
public TextTest(IKernel kernel, GraphicsDevice device, ContentManager content)
: base("Text Test", kernel)
{
_kernel = kernel;
_device = device;
_content = content;
}
示例6: SetConstantBuffers
internal void SetConstantBuffers(GraphicsDevice device, int shaderProgram)
#endif
{
// If there are no constant buffers then skip it.
if (_valid == 0)
return;
var valid = _valid;
for (var i = 0; i < _buffers.Length; i++)
{
var buffer = _buffers[i];
if (buffer != null)
{
#if DIRECTX
buffer.Apply(device, _stage, i);
#elif OPENGL || PSM
buffer.Apply(device, shaderProgram);
#endif
}
// Early out if this is the last one.
valid &= ~(1 << i);
if (valid == 0)
return;
}
}
示例7: Content
/// <summary>
/// Creates a new instance of Content.
/// </summary>
/// <param name="basePath">Path to client directory.</param>
/// <param name="device">A GraphicsDevice instance.</param>
private Content(string basePath, GraphicsDevice device)
{
this.BasePath = basePath;
this.Device = device;
Changes = new ChangeManager();
UIGraphics = new UIGraphicsProvider(this);
AvatarMeshes = new AvatarMeshProvider(this, Device);
AvatarBindings = new AvatarBindingProvider(this);
AvatarTextures = new AvatarTextureProvider(this, Device);
AvatarSkeletons = new AvatarSkeletonProvider(this);
AvatarAppearances = new AvatarAppearanceProvider(this);
AvatarOutfits = new AvatarOutfitProvider(this);
AvatarAnimations = new AvatarAnimationProvider(this);
AvatarPurchasables = new AvatarPurchasables(this);
AvatarHandgroups = new HandgroupProvider(this, Device);
AvatarCollections = new AvatarCollectionsProvider(this);
AvatarThumbnails = new AvatarThumbnailProvider(this, Device);
WorldObjects = new WorldObjectProvider(this);
WorldFloors = new WorldFloorProvider(this);
WorldWalls = new WorldWallProvider(this);
WorldObjectGlobals = new WorldGlobalProvider(this);
WorldCatalog = new WorldObjectCatalog();
Audio = new Audio(this);
GlobalTuning = new Tuning(Path.Combine(basePath, "tuning.dat"));
Init();
}
示例8: ApplyState
internal void ApplyState(GraphicsDevice device)
{
bool flag = device.GetRenderTargets().Length > 0;
if (this.CullMode == CullMode.None)
{
GL.Disable(EnableCap.CullFace);
}
else
{
GL.Enable(EnableCap.CullFace);
GL.CullFace(CullFaceMode.Back);
if (this.CullMode == CullMode.CullClockwiseFace)
{
if (flag)
GL.FrontFace(FrontFaceDirection.Cw);
else
GL.FrontFace(FrontFaceDirection.Ccw);
}
else if (flag)
GL.FrontFace(FrontFaceDirection.Ccw);
else
GL.FrontFace(FrontFaceDirection.Cw);
}
if (this.FillMode == FillMode.Solid)
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
else
GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
if (this.ScissorTestEnable)
GL.Enable(EnableCap.ScissorTest);
else
GL.Disable(EnableCap.ScissorTest);
GL.Enable(EnableCap.PolygonOffsetFill);
GL.PolygonOffset(this.SlopeScaleDepthBias, this.DepthBias * 1E+07f);
}
示例9: Renderer
public Renderer(GraphicsDevice device, RenderState renderState)
{
RenderState = renderState;
Device = device;
_effect = new BasicEffect(Device);
_bufferedInstructions = new List<IEnumerable<RenderInstruction>>();
}
示例10: DrawAfter2D
public void DrawAfter2D(GraphicsDevice gd, WorldState state)
{
gd.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
foreach (var avatar in Blueprint.Avatars){
avatar.Draw(gd, state);
}
}
示例11: GraphicsManger
public GraphicsManger(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, ContentManager content)
{
Console.WriteLine("graphics manager initialized");
GraphicsDevice = graphicsDevice;
SpriteBatch = spriteBatch;
Content = content;
}
示例12: DrawBefore2D
public void DrawBefore2D(GraphicsDevice gd, WorldState state)
{
foreach (var avatar in Blueprint.Avatars)
{
avatar.Draw(gd, state);
}
}
示例13: ResourceToTexture2D
public static Texture2D ResourceToTexture2D(string resource, GraphicsDevice gd)
{
using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream(resource))
{
return Texture2D.FromStream(gd, stream);
}
}
示例14: Snowplow
public Snowplow(GraphicsDevice device, Model model, VFXEffect effect)
: base(device,model,effect)
{
_isDoubleSided["Circle"] = true;
_isDoubleSided["Circle.004"] = true;
_isDoubleSided["Circle.003"] = true;
}
示例15: Initialize
public override void Initialize()
{
base.Initialize();
graphics = Game1.Instance.Graphics.GraphicsDevice;
spriteBatch = new SpriteBatch(graphics);
}