本文整理汇总了C#中Texture2DDescription类的典型用法代码示例。如果您正苦于以下问题:C# Texture2DDescription类的具体用法?C# Texture2DDescription怎么用?C# Texture2DDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Texture2DDescription类属于命名空间,在下文中一共展示了Texture2DDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TextureCubeArray
/// <summary>
///
/// </summary>
/// <param name="device"></param>
/// <param name="size"></param>
/// <param name="count"></param>
/// <param name="format"></param>
/// <param name="mips"></param>
public TextureCubeArray ( GraphicsDevice device, int size, int count, ColorFormat format, bool mips ) : base(device)
{
if (count>2048/6) {
throw new GraphicsException("Too much elements in texture array");
}
this.Width = size;
this.Depth = 1;
this.Height = size;
this.MipCount = mips ? ShaderResource.CalculateMipLevels(Width,Height) : 1;
var texDesc = new Texture2DDescription();
texDesc.ArraySize = 6 * count;
texDesc.BindFlags = BindFlags.ShaderResource;
texDesc.CpuAccessFlags = CpuAccessFlags.None;
texDesc.Format = MakeTypeless( Converter.Convert( format ) );
texDesc.Height = Height;
texDesc.MipLevels = 0;
texDesc.OptionFlags = ResourceOptionFlags.TextureCube;
texDesc.SampleDescription.Count = 1;
texDesc.SampleDescription.Quality = 0;
texDesc.Usage = ResourceUsage.Default;
texDesc.Width = Width;
texCubeArray = new D3D.Texture2D( device.Device, texDesc );
SRV = new ShaderResourceView( device.Device, texCubeArray );
}
示例2: Init
internal void Init(string name, Texture2DDescription desc, Vector2I size, int bytes)
{
m_name = name;
m_size = size;
m_desc = desc;
m_bytes = bytes;
}
示例3: MyTextureArray
internal MyTextureArray(TexId[] mergeList)
{
var srcDesc = MyTextures.GetView(mergeList[0]).Description;
Size = MyTextures.GetSize(mergeList[0]);
ArrayLen = mergeList.Length;
Texture2DDescription desc = new Texture2DDescription();
desc.ArraySize = ArrayLen;
desc.BindFlags = BindFlags.ShaderResource;
desc.CpuAccessFlags = CpuAccessFlags.None;
desc.Format = srcDesc.Format;
desc.Height = (int)Size.Y;
desc.Width = (int)Size.X;
desc.MipLevels = 0;
desc.SampleDescription.Count = 1;
desc.SampleDescription.Quality = 0;
desc.Usage = ResourceUsage.Default;
m_resource = new Texture2D(MyRender11.Device, desc);
// foreach mip
var mipmaps = (int)Math.Log(Size.X, 2) + 1;
for (int a = 0; a < ArrayLen; a++)
{
for (int m = 0; m < mipmaps; m++)
{
MyRender11.Context.CopySubresourceRegion(MyTextures.Textures.Data[mergeList[a].Index].Resource, Resource.CalculateSubResourceIndex(m, 0, mipmaps), null, Resource,
Resource.CalculateSubResourceIndex(m, a, mipmaps));
}
}
ShaderView = new ShaderResourceView(MyRender11.Device, Resource);
}
示例4: DX11RenderMip2D
public DX11RenderMip2D(DX11RenderContext context, int w, int h, Format format)
{
this.context = context;
int levels = this.CountMipLevels(w,h);
var texBufferDesc = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = format,
Height = h,
Width = w,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
MipLevels = levels,
};
this.Resource = new Texture2D(context.Device, texBufferDesc);
this.desc = this.Resource.Description;
this.SRV = new ShaderResourceView(context.Device, this.Resource);
this.Slices = new DX11MipSliceRenderTarget[levels];
int sw = w;
int sh = h;
for (int i = 0; i < levels; i++)
{
this.Slices[i] = new DX11MipSliceRenderTarget(this.context, this, i, w, h);
w /= 2; h /= 2;
}
}
示例5: Texture2D
public void Texture2D()
{
BlittableRGBA[] pixels = new BlittableRGBA[]
{
new BlittableRGBA(Color.Red),
new BlittableRGBA(Color.Green)
};
int sizeInBytes = ArraySizeInBytes.Size(pixels);
Texture2DDescription description = new Texture2DDescription(2, 1, TextureFormat.RedGreenBlueAlpha8, false);
using (GraphicsWindow window = Device.CreateWindow(1, 1))
using (WritePixelBuffer writePixelBuffer = Device.CreateWritePixelBuffer(PixelBufferHint.Stream, sizeInBytes))
using (Texture2D texture = Device.CreateTexture2D(description))
{
writePixelBuffer.CopyFromSystemMemory(pixels);
//
// Create texture with pixel buffer
//
texture.CopyFromBuffer(writePixelBuffer, BlittableRGBA.Format, BlittableRGBA.Datatype);
//
// Read back pixels
//
using (ReadPixelBuffer readPixelBuffer = texture.CopyToBuffer(BlittableRGBA.Format, BlittableRGBA.Datatype))
{
BlittableRGBA[] readPixels = readPixelBuffer.CopyToSystemMemory<BlittableRGBA>();
Assert.AreEqual(sizeInBytes, readPixelBuffer.SizeInBytes);
Assert.AreEqual(pixels[0], readPixels[0]);
Assert.AreEqual(pixels[1], readPixels[1]);
Assert.AreEqual(description, texture.Description);
}
}
}
示例6: OnDeviceInitInternal
public void OnDeviceInitInternal()
{
{
Texture2DDescription desc = new Texture2DDescription();
desc.Width = Size.X;
desc.Height = Size.Y;
desc.Format = m_resourceFormat;
desc.ArraySize = 1;
desc.MipLevels = m_mipmapLevels;
desc.BindFlags = m_bindFlags;
desc.Usage = m_resourceUsage;
desc.CpuAccessFlags = m_cpuAccessFlags;
desc.SampleDescription.Count = m_samplesCount;
desc.SampleDescription.Quality = m_samplesQuality;
desc.OptionFlags = m_roFlags;
m_resource = new Texture2D(MyRender11.Device, desc);
}
{
ShaderResourceViewDescription desc = new ShaderResourceViewDescription();
desc.Format = m_srvFormat;
desc.Dimension = ShaderResourceViewDimension.Texture2D;
desc.Texture2D.MipLevels = m_mipmapLevels;
desc.Texture2D.MostDetailedMip = 0;
m_srv = new ShaderResourceView(MyRender11.Device, m_resource, desc);
}
m_resource.DebugName = m_name;
m_srv.DebugName = m_name;
}
示例7: SharedTexture
/// <summary>
/// Creates a default D3D11 Texture with forced Shared-Flag
/// </summary>
/// <param name="device"></param>
/// <param name="description"></param>
/// <param name="D3D10Dev"> </param>
/// <param name="D2DFactory"> </param>
public SharedTexture(D2DInteropHandler handler, Texture2DDescription description)
{
As11Tex = new Texture2D(handler.D3DDevice11, new Texture2DDescription()
{
ArraySize = description.ArraySize,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = description.CpuAccessFlags,
Format = description.Format,
Height = description.Height,
MipLevels = description.MipLevels,
OptionFlags = ResourceOptionFlags.KeyedMutex,
SampleDescription = description.SampleDescription,
Usage = description.Usage,
Width = description.Width
});
Mutex11 = new KeyedMutex(As11Tex);
AsResource = new SlimDX.DXGI.Resource(As11Tex);
As10Tex = handler.D3DDevice10.OpenSharedResource<SlimDX.Direct3D10.Texture2D>(AsResource.SharedHandle);
Mutex10 = new KeyedMutex(As10Tex);
AsSurface = As10Tex.AsSurface();
As2DTarget = SlimDX.Direct2D.RenderTarget.FromDXGI(handler.D2DFactory, AsSurface, new RenderTargetProperties()
{
MinimumFeatureLevel = FeatureLevel.Direct3D10,
Usage = RenderTargetUsage.None,
Type = RenderTargetType.Hardware,
PixelFormat = new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)
});
}
示例8: RenderTexture
public RenderTexture(Device device, Vector2I screenSize)
{
var textureDesc = new Texture2DDescription()
{
Width = screenSize.X,
Height = screenSize.Y,
MipLevels = 1,
ArraySize = 1,
Format = Format.R32G32B32A32_Float,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None
};
_renderTargetTexture = new Texture2D(device, textureDesc);
_renderTargetView = new RenderTargetView(device, _renderTargetTexture,
new RenderTargetViewDescription
{
Format = textureDesc.Format,
Dimension = RenderTargetViewDimension.Texture2D,
Texture2D = {MipSlice = 0},
});
// Create the render target view.
ShaderResourceView = new ShaderResourceView(device, _renderTargetTexture,
new ShaderResourceViewDescription
{
Format = textureDesc.Format,
Dimension = ShaderResourceViewDimension.Texture2D,
Texture2D = { MipLevels = 1, MostDetailedMip = 0 },
});
}
示例9: RenderStereoTextureCommand
public RenderStereoTextureCommand(int width, int height, StereoRenderer stereoRenderer)
: base(width, height, stereoRenderer.Scene)
{
this.CommandAttributes |= CommandAttributes.StereoRendering;
this.sceneManager = stereoRenderer.Scene;
this.stereoRenderer = stereoRenderer;
this.stereoCamera = (StereoCamera)stereoRenderer.Camera;
this.stereoCamera.StereoParametersChanged += RequestUpdate;
Texture2DDescription StereoTextureDesc = new Texture2DDescription
{
ArraySize = 1,
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
Format = Format.R8G8B8A8_UNorm,
Width = 2 * width,
Height = height,
MipLevels = 1,
OptionFlags = ResourceOptionFlags.None,
SampleDescription = new SampleDescription(1, 0),
Usage = ResourceUsage.Default
};
Texture = new Texture2D(Game.Context.Device, StereoTextureDesc);
}
示例10: BuildVertexBuffer
void BuildVertexBuffer(Texture2DDescription textureDesc)
{
var game = Game.Instance;
var clientSize = game.RenderViewSize;
var texWidth = textureDesc.Width;
var texHeight = textureDesc.Height;
var clientRatio = clientSize.Width / (float)clientSize.Height;
var textureRatio = texWidth / (float)texHeight;
float w = 1f;
float h = 1f;
if (clientRatio > textureRatio)
{
if (texHeight > clientSize.Height)
{
w = h * textureRatio / clientRatio;
}
else
{
h = texHeight / (float)clientSize.Height;
w = texWidth / (float)clientSize.Width;
}
}
else
{
if (texWidth > clientSize.Width)
{
h = w * clientRatio / textureRatio;
}
else
{
h = texHeight / (float)clientSize.Height;
w = texWidth / (float)clientSize.Width;
}
}
int start = 0;
DefineVertex(ref start, w, -h, 1, 1);
DefineVertex(ref start, -w, -h, 0, 1);
DefineVertex(ref start, w, h, 1, 0);
DefineVertex(ref start, w, h, 1, 0);
DefineVertex(ref start, -w, -h, 0, 1);
DefineVertex(ref start, -w, h, 0, 0);
var desc = new BufferDescription();
desc.BindFlags = BindFlags.VertexBuffer;
desc.Usage = ResourceUsage.Default;
desc.CpuAccessFlags = CpuAccessFlags.None;
desc.SizeInBytes = Utilities.SizeOf<float>() * vertices.Length;
desc.StructureByteStride = 0;
desc.OptionFlags = ResourceOptionFlags.None;
vertexBuffer = Buffer.Create(game.Device, vertices, desc);
vertexBuffer.DebugName = "Preview(Texture2D)";
vertexBufferBinding = new VertexBufferBinding(vertexBuffer, Utilities.SizeOf<float>() * VERTEX_FLOAT_COUNT, 0);
}
示例11: CheckTexturesConsistency
public static bool CheckTexturesConsistency(Texture2DDescription desc1, Texture2DDescription desc2)
{
return desc1.Format == desc2.Format
&& desc1.MipLevels == desc2.MipLevels
&& desc1.Width == desc2.Width
&& desc1.Height == desc2.Height;
}
示例12: RenderTexture
/// <summary>
/// Constructor
/// Creates the texture we will render to based on the supplied width and height
/// </summary>
/// <param name="device">The device we will create the texture with</param>
/// <param name="texWidth"></param>
/// <param name="texHeight"></param>
public RenderTexture(Device device, int texWidth, int texHeight)
{
Texture2DDescription textureDescription = new Texture2DDescription()
{
Width = texWidth,
Height = texHeight,
MipLevels = 1,
ArraySize = 1,
Format = SlimDX.DXGI.Format.R32G32B32A32_Float,
SampleDescription = new SlimDX.DXGI.SampleDescription(1, 0),
BindFlags = BindFlags.RenderTarget | BindFlags.ShaderResource,
CpuAccessFlags = CpuAccessFlags.None,
OptionFlags = ResourceOptionFlags.None,
Usage = ResourceUsage.Default,
};
Texture = new Texture2D(device, textureDescription);
RenderTargetViewDescription renderTargetViewDescription = new RenderTargetViewDescription()
{
Format = textureDescription.Format,
Dimension = RenderTargetViewDimension.Texture2D,
MipSlice = 0,
};
renderTargetView = new RenderTargetView(device, Texture, renderTargetViewDescription);
ShaderResourceViewDescription shaderResourceViewDescription = new ShaderResourceViewDescription()
{
Format = textureDescription.Format,
Dimension = ShaderResourceViewDimension.Texture2D,
MostDetailedMip = 0,
MipLevels = 1
};
shaderResourceView = new ShaderResourceView(device, Texture, shaderResourceViewDescription);
}
示例13: EnumerateColorAttachments
public void EnumerateColorAttachments()
{
Texture2DDescription description = new Texture2DDescription(1, 1, TextureFormat.RedGreenBlue8, false);
using (GraphicsWindow window = Device.CreateWindow(1, 1))
using (Framebuffer framebuffer = window.Context.CreateFramebuffer())
using (Texture2D color0 = Device.CreateTexture2D(description))
using (Texture2D color1 = Device.CreateTexture2D(description))
using (Texture2D color2 = Device.CreateTexture2D(description))
{
framebuffer.ColorAttachments[0] = color0;
framebuffer.ColorAttachments[1] = color1;
framebuffer.ColorAttachments[2] = color2;
Assert.AreEqual(3, framebuffer.ColorAttachments.Count);
framebuffer.ColorAttachments[1] = null;
Assert.AreEqual(2, framebuffer.ColorAttachments.Count);
framebuffer.ColorAttachments[1] = color1;
Assert.AreEqual(3, framebuffer.ColorAttachments.Count);
int count = 0;
foreach (Texture2D texture in framebuffer.ColorAttachments)
{
Assert.AreEqual(description, texture.Description);
++count;
}
Assert.AreEqual(framebuffer.ColorAttachments.Count, count);
}
}
示例14: TextureFromBitmap
public static Texture2D TextureFromBitmap(Bitmap image)
{
BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
ImageLockMode.ReadWrite, image.PixelFormat);
int bytes = data.Stride*image.Height;
DataStream stream = new DataStream(bytes, true, true);
stream.WriteRange(data.Scan0, bytes);
stream.Position = 0;
DataRectangle dRect = new DataRectangle(data.Stride, stream);
Texture2DDescription texDesc = new Texture2DDescription
{
ArraySize = 1,
MipLevels = 1,
SampleDescription = new SampleDescription(1, 0),
Format = Format.B8G8R8A8_UNorm,
CpuAccessFlags = CpuAccessFlags.None,
BindFlags = BindFlags.ShaderResource,
Usage = ResourceUsage.Immutable,
Height = image.Height,
Width = image.Width
};
image.UnlockBits(data);
image.Dispose();
Texture2D texture = new Texture2D(Game.Context.Device, texDesc, dRect);
stream.Dispose();
return texture;
}
示例15: OnResize
void OnResize(object sender, EventArgs args)
{
var texDesc = new Texture2DDescription
{
ArraySize = 1, BindFlags = BindFlags.None,
CpuAccessFlags = CpuAccessFlags.None,
Format = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
Height = ClientSize.Height,
Width = ClientSize.Width,
Usage = ResourceUsage.Default,
SampleDescription = new SharpDX.DXGI.SampleDescription(1, 0),
OptionFlags = ResourceOptionFlags.None,
MipLevels = 1
};
if (mResolveTexture != null)
mResolveTexture.Dispose();
mResolveTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);
if (mMapTexture != null) mMapTexture.Dispose();
texDesc.CpuAccessFlags = CpuAccessFlags.Read;
texDesc.Usage = ResourceUsage.Staging;
mMapTexture = new Texture2D(WorldFrame.Instance.GraphicsContext.Device, texDesc);
mTarget.Resize(ClientSize.Width, ClientSize.Height, true);
mCamera.SetAspect((float) ClientSize.Width / ClientSize.Height);
}