本文整理汇总了C#中Viewport类的典型用法代码示例。如果您正苦于以下问题:C# Viewport类的具体用法?C# Viewport怎么用?C# Viewport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Viewport类属于命名空间,在下文中一共展示了Viewport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitalizeGraphics
private void InitalizeGraphics()
{
if (Window.RenderCanvasHandle == IntPtr.Zero)
throw new InvalidOperationException("Window handle cannot be zero");
SwapChainDescription swapChainDesc = new SwapChainDescription()
{
BufferCount = 1,
Flags = SwapChainFlags.None,
IsWindowed = true,
OutputHandle = Window.RenderCanvasHandle,
SwapEffect = SwapEffect.Discard,
Usage = Usage.RenderTargetOutput,
ModeDescription = new ModeDescription()
{
Format = SlimDX.DXGI.Format.R8G8B8A8_UNorm,
//Format = SlimDX.DXGI.Format.B8G8R8A8_UNorm,
Width = Window.ClientSize.Width,
Height = Window.ClientSize.Height,
RefreshRate = new Rational(60, 1),
Scaling = DisplayModeScaling.Unspecified,
ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified
},
SampleDescription = new SampleDescription(1, 0)
};
var giFactory = new SlimDX.DXGI.Factory();
var adapter = giFactory.GetAdapter(0);
Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(adapter, DriverType.Hardware, DeviceCreationFlags.None, swapChainDesc, out device, out swapChain);
_swapChain = swapChain;
GraphicsDevice = device;
// create a view of our render target, which is the backbuffer of the swap chain we just created
using (var resource = SlimDX.Direct3D10.Resource.FromSwapChain<Texture2D>(swapChain, 0))
{
_backBuffer = new RenderTargetView(device, resource);
}
// setting a viewport is required if you want to actually see anything
var viewport = new Viewport(0, 0, Window.ClientSize.Width, Window.ClientSize.Height);
device.OutputMerger.SetTargets(_backBuffer);
device.Rasterizer.SetViewports(viewport);
CreateDepthStencil();
LoadVisualizationEffect();
// Allocate a large buffer to write the PhysX visualization vertices into
// There's more optimized ways of doing this, but for this sample a large buffer will do
_userPrimitivesBuffer = new SlimDX.Direct3D10.Buffer(GraphicsDevice, VertexPositionColor.SizeInBytes * 50000, ResourceUsage.Dynamic, BindFlags.VertexBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None);
var elements = new[]
{
new InputElement("Position", 0, Format.R32G32B32A32_Float, 0, 0),
new InputElement("Color", 0, Format.R32G32B32A32_Float, 16, 0)
};
_inputLayout = new InputLayout(GraphicsDevice, _visualizationEffect.RenderScenePass0.Description.Signature, elements);
}
示例2: GenerateBits
// Pack input data to ulong
public static ulong GenerateBits(FSLayer layer, Viewport vp, VPLayer vpLayer, Translucency trans, ushort Material, ushort depth, ushort ibID, ushort vbID)
{
ulong result = (ulong)layer << 62;
result += (ulong)vp << 59;
result += (ulong)vpLayer << 56;
result += (ulong)trans << 54;
int maxvb = 1 << 10;
if (vbID > maxvb || ibID > maxvb)
{
// Overflow
Common.Instance.WriteLine("VB/IB OVERFLOW!!!");
}
result += (ulong)vbID << 43;
result += (ulong)ibID << 32;
if (trans == Translucency.OPAQUE)
{
// Material first
result += (ulong)Material << 16;
result += (ulong)depth;
}
else
{
// Depth first
result += (ulong)depth << 16;
result += (ulong)Material;
}
if (vpLayer != GetVPLayer(result))
{
int test = 2;
}
return result;
}
示例3: InitDevice
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
public void InitDevice()
{
device = D3DDevice.CreateDeviceAndSwapChain(host.Handle, out swapChain);
// Create a render target view
using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
{
renderTargetView = device.CreateRenderTargetView(pBuffer);
}
device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView }, null);
// Setup the viewport
Viewport vp = new Viewport()
{
Width = (uint)host.ActualWidth,
Height = (uint)host.ActualHeight,
MinDepth = 0.0f,
MaxDepth = 1.0f,
TopLeftX = 0,
TopLeftY = 0
};
device.RS.SetViewports(new Viewport[] { vp });
}
示例4: ViewportAdapter
/// <summary>
/// Constructor that takes an attribute list.
/// </summary>
/// <param name="attrList"> A <see cref="System.Int32"/>. </param>
public ViewportAdapter(System.Int32[] attrList) : base(attrList)
{
Viewport = new Viewport(this);
// make sure the viewport catches all events
AddEvents((int)Gdk.EventMask.AllEventsMask);
// mouse interaction signals
ButtonPressEvent += OnButtonPress;
ButtonReleaseEvent += OnButtonRelease;
MotionNotifyEvent += OnMotionNotify;
ScrollEvent += OnScroll;
KeyPressEvent += OnKeyPress;
KeyReleaseEvent += OnKeyRelease;
// Connect some other signals
DeleteEvent += OnWindowDeleteEvent;
ExposeEvent += OnExposed;
Realized += OnRealized;
SizeAllocated += OnSizeAllocated;
ConfigureEvent += OnConfigure;
CanFocus = true;
GrabFocus();
}
示例5: initialize
public Sprite initialize(Viewport v)
{
created_at = DateTime.Now;
viewport = v;
viewport.sprites.Add(this);
return this;
}
示例6: CheckHit
public override HitResult CheckHit(SETItem item, Vector3 Near, Vector3 Far, Viewport Viewport, Matrix Projection, Matrix View, MatrixStack transform)
{
HitResult result = HitResult.NoHit;
transform.Push();
transform.NJTranslate(item.Position.ToVector3());
transform.NJRotateY(item.Rotation.Y);
transform.Push();
transform.NJTranslate(0, 0, 10);
transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 2);
result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
transform.Pop();
transform.Push();
transform.NJTranslate(0, 0, 20);
transform.NJRotateX(0x2000);
transform.NJTranslate(0, 0, -3);
transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
transform.Pop();
transform.Push();
transform.NJTranslate(0, 0, 20);
transform.NJRotateX(0xE000);
transform.NJTranslate(0, 0, -3);
transform.NJScale(0.1000000014901161f, 0.1000000014901161f, 0.699999988079071f);
result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
transform.Pop();
transform.NJScale((item.Scale.X + 10) / 5f, (item.Scale.Y + 10) / 5f, 0.1000000014901161f);
result = HitResult.Min(result, model.CheckHit(Near, Far, Viewport, Projection, View, transform, meshes));
transform.Pop();
return result;
}
示例7: InitDevice
/// <summary>
/// Create Direct3D device and swap chain
/// </summary>
protected void InitDevice()
{
device = D3DDevice.CreateDeviceAndSwapChain(directControl.Handle, out swapChain);
// Create a render target view
using (Texture2D pBuffer = swapChain.GetBuffer<Texture2D>(0))
{
renderTargetView = device.CreateRenderTargetView(pBuffer);
}
device.OM.SetRenderTargets(new RenderTargetView[] { renderTargetView });
// Setup the viewport
Viewport vp = new Viewport()
{
Width = (uint)directControl.ClientSize.Width,
Height = (uint)directControl.ClientSize.Height,
MinDepth = 0.0f,
MaxDepth = 1.0f,
TopLeftX = 0,
TopLeftY = 0
};
device.RS.SetViewports(new Viewport[] { vp });
}
示例8: SetupViewport
void SetupViewport()
{
var renderer = Renderer;
var graphics = Graphics;
renderer.NumViewports = 2;
// Set up the front camera viewport
Viewport viewport = new Viewport(Context, scene, CameraNode.GetComponent<Camera>(), null);
renderer.SetViewport(0, viewport);
// Clone the default render path so that we do not interfere with the other viewport, then add
// bloom and FXAA post process effects to the front viewport. Render path commands can be tagged
// for example with the effect name to allow easy toggling on and off. We start with the effects
// disabled.
var cache = ResourceCache;
RenderPath effectRenderPath = viewport.RenderPath.Clone();
effectRenderPath.Append(cache.GetXmlFile("PostProcess/Bloom.xml"));
effectRenderPath.Append(cache.GetXmlFile("PostProcess/FXAA2.xml"));
// Make the bloom mixing parameter more pronounced
effectRenderPath.SetShaderParameter("BloomMix", new Vector2(0.9f, 0.6f));
effectRenderPath.SetEnabled("Bloom", false);
effectRenderPath.SetEnabled("FXAA2", false);
viewport.RenderPath = effectRenderPath;
// Set up the rear camera viewport on top of the front view ("rear view mirror")
// The viewport index must be greater in that case, otherwise the view would be left behind
IntRect rect = new IntRect(graphics.Width*2/3, 32, graphics.Width - 32, graphics.Height/3);
Viewport rearViewport = new Viewport(Context, scene, rearCameraNode.GetComponent<Camera>(), rect, null);
renderer.SetViewport(1, rearViewport);
}
示例9: LoadResources
public void LoadResources()
{
if (m_Disposed == true)
{
Buffer = new Texture2D(GameEnvironment.Device, new Texture2DDescription()
{
Format = m_Format,
Width = m_Width,
Height = m_Height,
OptionFlags = ResourceOptionFlags.None,
MipLevels = 1,
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default
});
View = new RenderTargetView(GameEnvironment.Device, Buffer);
ResourceView = new ShaderResourceView(GameEnvironment.Device, Buffer);
Viewport = new Viewport(0, 0, Buffer.Description.Width, Buffer.Description.Height);
m_Disposed = false;
}
}
示例10: Minimap
public Minimap(Device device, DeviceContext dc, int minimapWidth, int minimapHeight, Terrain terrain, CameraBase viewCam)
{
_dc = dc;
_minimapViewport = new Viewport(0, 0, minimapWidth, minimapHeight);
CreateMinimapTextureViews(device, minimapWidth, minimapHeight);
_terrain = terrain;
SetupOrthoCamera();
_viewCam = viewCam;
// frustum vb will contain four corners of view frustum, with first vertex repeated as the last
var vbd = new BufferDescription(
VertexPC.Stride * 5,
ResourceUsage.Dynamic,
BindFlags.VertexBuffer,
CpuAccessFlags.Write,
ResourceOptionFlags.None,
0
);
_frustumVB = new Buffer(device, vbd);
_edgePlanes = new[] {
new Plane(1, 0, 0, -_terrain.Width / 2),
new Plane(-1, 0, 0, _terrain.Width / 2),
new Plane(0, 1, 0, -_terrain.Depth / 2),
new Plane(0, -1, 0, _terrain.Depth / 2)
};
ScreenPosition = new Vector2(0.25f, 0.75f);
Size = new Vector2(0.25f, 0.25f);
}
示例11: CreateDeviceSwapChainAndRenderTarget
public static void CreateDeviceSwapChainAndRenderTarget(Form form,
out Device device, out SwapChain swapChain, out RenderTargetView renderTarget)
{
try
{
// the debug mode requires the sdk to be installed otherwise an exception is thrown
device = new Device(DeviceCreationFlags.Debug);
}
catch (Direct3D10Exception)
{
device = new Device(DeviceCreationFlags.None);
}
var swapChainDescription = new SwapChainDescription();
var modeDescription = new ModeDescription();
var sampleDescription = new SampleDescription();
modeDescription.Format = Format.R8G8B8A8_UNorm;
modeDescription.RefreshRate = new Rational(60, 1);
modeDescription.Scaling = DisplayModeScaling.Unspecified;
modeDescription.ScanlineOrdering = DisplayModeScanlineOrdering.Unspecified;
modeDescription.Width = WIDTH;
modeDescription.Height = HEIGHT;
sampleDescription.Count = 1;
sampleDescription.Quality = 0;
swapChainDescription.ModeDescription = modeDescription;
swapChainDescription.SampleDescription = sampleDescription;
swapChainDescription.BufferCount = 1;
swapChainDescription.Flags = SwapChainFlags.None;
swapChainDescription.IsWindowed = true;
swapChainDescription.OutputHandle = form.Handle;
swapChainDescription.SwapEffect = SwapEffect.Discard;
swapChainDescription.Usage = Usage.RenderTargetOutput;
using (var factory = new Factory())
{
swapChain = new SwapChain(factory, device, swapChainDescription);
}
using (var resource = swapChain.GetBuffer<Texture2D>(0))
{
renderTarget = new RenderTargetView(device, resource);
}
var viewport = new Viewport
{
X = 0,
Y = 0,
Width = WIDTH,
Height = HEIGHT,
MinZ = 0.0f,
MaxZ = 1.0f
};
device.Rasterizer.SetViewports(viewport);
device.OutputMerger.SetTargets(renderTarget);
}
示例12: CreateRasterizer
public static PrimitiveRasterizer CreateRasterizer(
PrimitiveTopology primitiveTopology,
RasterizerStateDescription rasterizerState,
int multiSampleCount,
ShaderOutputInputBindings outputInputBindings,
ref Viewport viewport,
Func<int, int, bool> fragmentQuadFilter)
{
switch (primitiveTopology)
{
case PrimitiveTopology.PointList:
throw new NotImplementedException();
case PrimitiveTopology.LineList:
case PrimitiveTopology.LineStrip:
throw new NotImplementedException();
case PrimitiveTopology.TriangleList:
case PrimitiveTopology.TriangleStrip:
return new TriangleRasterizer(
rasterizerState, multiSampleCount,
outputInputBindings, ref viewport,
fragmentQuadFilter);
default:
throw new ArgumentOutOfRangeException("primitiveTopology");
}
}
示例13: Offset
public static ScreenOffset Offset(Vector3 point, Rectangle bounds, Viewport viewport, Matrix projection,
Matrix view, Matrix currentAttitude)
{
// Create a World matrix for the point.
var world = Matrix.CreateWorld(point, new Vector3(0, 0, -1), new Vector3(0, 1, 0));
// Use Viewport.Project to project the point from 3D space into screen coordinates.
var projected = viewport.Project(Vector3.Zero, projection, view, world*currentAttitude);
if (projected.Z > 1 || projected.Z < 0)
{
// If the point is outside of this range, it is behind the camera.
// So hide the TextBlock for this point.
return default(ScreenOffset);
}
// Create a TranslateTransform to position the TextBlock.
// Offset by half of the TextBlock's RenderSize to center it on the point.
var tt = new ScreenOffset
{
TranslateX = projected.X - (bounds.Width/2),
TranslateY = projected.Y - (bounds.Height/2),
Scale = 1/projected.Z
};
return tt;
}
示例14: RenderTarget
public RenderTarget(Device device, int width, int height, int sampleCount, int sampleQuality, Format format)
: this()
{
Texture = _disposer.Add(new Texture2D(device, new Texture2DDescription
{
Format = format,
Width = width,
Height = height,
ArraySize = 1,
MipLevels = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
SampleDescription = new SampleDescription(sampleCount, sampleQuality),
}));
RenderTargetView = _disposer.Add(new RenderTargetView(device, Texture, new RenderTargetViewDescription
{
Format = format,
Dimension = RenderTargetViewDimension.Texture2DMultisampled,
//MipSlice = 0,
}));
ShaderResourceView = _disposer.Add(new ShaderResourceView(device, Texture));
Viewport = new Viewport(0, 0, width, height, 0.0f, 1.0f);
}
示例15: FilterPixelShader
public FilterPixelShader(Device device, int imageWidth, int imageHeight, int constantBufferSize, string pixelShaderBytecodeFilename)
{
vertexShader = new VertexShader(device, new ShaderBytecode(File.ReadAllBytes("Content/FullScreenQuadVS.cso")));
pixelShader = new PixelShader(device, new ShaderBytecode(File.ReadAllBytes(pixelShaderBytecodeFilename)));
var rasterizerStateDesc = new RasterizerStateDescription()
{
CullMode = CullMode.None,
FillMode = FillMode.Solid,
IsDepthClipEnabled = false,
IsFrontCounterClockwise = true,
IsMultisampleEnabled = false,
};
rasterizerState = new RasterizerState(device, rasterizerStateDesc);
if (constantBufferSize > 0)
{
var constantBufferDesc = new BufferDescription()
{
Usage = ResourceUsage.Dynamic,
BindFlags = BindFlags.ConstantBuffer,
SizeInBytes = constantBufferSize,
CpuAccessFlags = CpuAccessFlags.Write,
StructureByteStride = 0,
OptionFlags = 0,
};
constantBuffer = new Buffer(device, constantBufferDesc);
}
viewport = new Viewport(0, 0, imageWidth, imageHeight); // TODO: get these dimensions
vertexBufferBinding = new VertexBufferBinding(null, 0, 0);
}