本文整理汇总了C#中Texture.GetLevelDescription方法的典型用法代码示例。如果您正苦于以下问题:C# Texture.GetLevelDescription方法的具体用法?C# Texture.GetLevelDescription怎么用?C# Texture.GetLevelDescription使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Texture
的用法示例。
在下文中一共展示了Texture.GetLevelDescription方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HagsTexture
public HagsTexture(string filename)
{
_texture = TextureManager.Instance.LoadTexture(filename);
if (_texture != null)
Size = new Size(_texture.GetLevelDescription(0).Width, _texture.GetLevelDescription(0).Height);
this.filename = filename;
TextureManager.Instance.hagsTextures.Add(this);
}
示例2: TextureViewer_Load
void TextureViewer_Load(object sender, EventArgs e)
{
this.Show();
Application.DoEvents();
pp = new PresentParameters();
pp.BackBufferCount = 2;
pp.SwapEffect = SwapEffect.Discard;
pp.Windowed = true;
Direct3D d3d = new Direct3D();
d3d_device = new Device(d3d, 0, DeviceType.Hardware, d3dPanel.Handle, CreateFlags.HardwareVertexProcessing, pp);
texture = Texture.FromFile(d3d_device, texturePath);
int texWidth = texture.GetLevelDescription(0).Width;
int texHeight = texture.GetLevelDescription(0).Height;
d3dPanel.Top = menuStrip1.Height;
d3dPanel.Left = 0;
d3dPanel.ClientSize = new Size(texWidth, texHeight);
this.ClientSize = new System.Drawing.Size(
d3dPanel.Width,
d3dPanel.Height + menuStrip1.Height
);
pp.BackBufferWidth = texWidth;
pp.BackBufferHeight = texHeight;
d3d_device.Reset(pp);
sprite = new Sprite(d3d_device);
while (this.Visible)
{
d3d_device.Clear(ClearFlags.ZBuffer | ClearFlags.Target, new Color4(Color.Black), 1.0f, 0);
d3d_device.BeginScene();
sprite.Begin(SpriteFlags.AlphaBlend);
Rectangle rect = new Rectangle()
{
X = 0,
Y = 0,
Width = texture.GetLevelDescription(0).Width,
Height = texture.GetLevelDescription(0).Height
};
sprite.Draw(texture, rect, new Color4(Color.White));
sprite.End();
d3d_device.EndScene();
d3d_device.Present();
Application.DoEvents();
}
}
示例3: DrawCentered
public static void DrawCentered(this Sprite sprite,
Texture texture,
Vector2 position,
Rectangle? rectangle = null)
{
var desc = texture.GetLevelDescription(0);
sprite.Draw(
texture, new ColorBGRA(255, 255, 255, 255), rectangle,
new Vector3(-(position.X - desc.Width / 2f), -(position.Y - desc.Height / 2f), 0));
}
示例4: AnalogCamera
public AnalogCamera(DsDevice device, Device d3dDevice)
{
this.d3dDevice = d3dDevice;
texture = new Texture(d3dDevice, 720, 576, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
var desc = texture.GetLevelDescription(0);
DataRectangle dr = texture.LockRectangle(0, LockFlags.Discard);
int rowPitch = dr.Pitch;
texture.UnlockRectangle(0);
try
{
BuildGraph(device);
}
catch
{
Dispose();
throw;
}
}
示例5: WebCamera
public WebCamera(DsDevice device, Device d3dDevice)
{
//bitmapWindow = new Test();
//bitmapWindow.Show();
this.d3dDevice = d3dDevice;
texture = new Texture(d3dDevice, 1280, 720, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default);
//texture = Texture.FromFile(d3dDevice, ".\\Images\\checkerboard.jpg", D3DX.DefaultNonPowerOf2, D3DX.DefaultNonPowerOf2, 1, Usage.Dynamic, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0);
var desc = texture.GetLevelDescription(0);
DataRectangle dr = texture.LockRectangle(0, LockFlags.Discard);
int rowPitch = dr.Pitch;
texture.UnlockRectangle(0);
try
{
BuildGraph(device);
}
catch
{
Dispose();
throw;
}
}
示例6: SetManagedDevice
private void SetManagedDevice(IntPtr unmanagedDevice)
{
// Start by freeing everything
FreeResources();
// Create a managed Device from the unmanaged pointer
// The constructor don't call IUnknown.AddRef but the "destructor" seem to call IUnknown.Release
// Direct3D seem to be happier with that according to the DirectX log
Marshal.AddRef(unmanagedDevice);
this.unmanagedDevice = unmanagedDevice;
device = new Device(unmanagedDevice);
// Create helper objects to draw over the video
sprite = new Sprite(device);
gdiFont = new System.Drawing.Font("Tahoma", 15);
d3dFont = new Direct3D.Font(device, gdiFont);
// Load a bitmap (the spider) from embedded resources. This is a png file with alpha transparency
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("DirectShowLib.Sample.redspider.png"))
{
spiderTex = TextureLoader.FromStream(device, stream, D3DX.Default, D3DX.Default, D3DX.Default, D3DX.Default, Usage.None, Format.A8R8G8B8, Pool.Default, Filter.None, Filter.None, 0);
SurfaceDescription spiderDesc = spiderTex.GetLevelDescription(0);
spiderSize = new Size(spiderDesc.Width, spiderDesc.Height);
}
}
示例7: MakeTextures
/// <summary>
/// The make textures.
/// </summary>
/// <param name="device">The device.</param>
/// <remarks></remarks>
public void MakeTextures(ref Device device)
{
/*
BitmapTextures = new Texture[Bitmaps.Count];
for (int x = 0; x < Bitmaps.Count; x++) BitmapTextures[x] = CreateTexture(ref device, Bitmaps[x]);
*/
if (BumpMapBitmap != null)
{
BumpMapTexture = CreateTexture(ref device, BumpMapBitmap);
SurfaceDescription desc = BumpMapTexture.GetLevelDescription(0);
NormalMap = new Texture(
device, desc.Width, desc.Height, BumpMapTexture.LevelCount, 0, Format.A8R8G8B8, Pool.Managed);
TextureLoader.ComputeNormalMap(NormalMap, BumpMapTexture, 0, Channel.Alpha, 1.0f);
}
if (primarydetailBitmap != null)
{
primarydetailTexture = CreateTexture(ref device, primarydetailBitmap);
}
if (secondarydetailBitmap != null)
{
secondarydetailTexture = CreateTexture(ref device, secondarydetailBitmap);
}
if (microdetailBitmap != null)
{
microdetailTexture = CreateTexture(ref device, microdetailBitmap);
}
if (CubeMapBitmap != null)
{
// CubeMapTexture = Texture.FromBitmap(device, CubeMapBitmap, Usage.AutoGenerateMipMap, Pool.Managed);
}
if (MainBitmap != null)
{
MainTexture = CreateTexture(ref device, MainBitmap);
// try
// {
// }
// catch
// {
// MainTexture = Texture.FromBitmap(device, MainBitmap, Usage.AutoGenerateMipMap, Pool.Managed);
// }
}
}
示例8: m_RefreshTimer_Elapsed
private void m_RefreshTimer_Elapsed(object sender, ElapsedEventArgs e)
{
if (isUpdating) {
return;
}
isUpdating = true;
if (m_ImageUri == null) {
return;
}
if (m_ImageUri.ToLower().StartsWith("http://")) {
if (m_SaveFilePath == null) {
return;
}
//download it
try {
WebDownload webDownload = new WebDownload(m_ImageUri);
webDownload.DownloadType = DownloadType.Unspecified;
FileInfo saveFile = new FileInfo(m_SaveFilePath);
if (!saveFile.Directory.Exists) {
saveFile.Directory.Create();
}
webDownload.DownloadFile(m_SaveFilePath);
}
catch {}
}
else {
m_SaveFilePath = m_ImageUri;
}
if (m_ImageTexture != null
&& !m_ImageTexture.Disposed) {
m_ImageTexture.Dispose();
m_ImageTexture = null;
}
if (!File.Exists(m_SaveFilePath)) {
displayText = "Image Not Found";
return;
}
m_ImageTexture = ImageHelper.LoadTexture(m_SaveFilePath);
m_surfaceDescription = m_ImageTexture.GetLevelDescription(0);
int width = ClientSize.Width;
int height = ClientSize.Height;
if (ClientSize.Width == 0) {
width = m_surfaceDescription.Width;
}
if (ClientSize.Height == 0) {
height = m_surfaceDescription.Height;
}
if (ParentWidget is Form) {
Form parentForm = (Form) ParentWidget;
parentForm.ClientSize = new Size(width, height + parentForm.HeaderHeight);
}
else {
ParentWidget.ClientSize = new Size(width, height);
}
ClientSize = new Size(width, height);
IsLoaded = true;
isUpdating = false;
displayText = null;
if (m_RefreshTime == 0) {
m_RefreshTimer.Stop();
}
}
示例9: CreateTextureCopy
protected static Texture CreateTextureCopy(Texture sourceTexture, out SizeF textureSize)
{
if (sourceTexture == null)
{
textureSize = Size.Empty;
return null;
}
SurfaceDescription desc = sourceTexture.GetLevelDescription(0);
textureSize = new SizeF(desc.Width, desc.Height);
DeviceEx device = SkinContext.Device;
Texture result = new Texture(device, desc.Width, desc.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Default);
using (Surface target = result.GetSurfaceLevel(0))
using (Surface source = sourceTexture.GetSurfaceLevel(0))
device.StretchRectangle(source, target, TextureFilter.None);
return result;
}
示例10: RenderImage
/// <summary>
/// render the image contained in texture onscreen
/// </summary>
/// <param name="texture">Directx texture containing the image</param>
/// <param name="x">x (left) coordinate</param>
/// <param name="y">y (top) coordinate</param>
/// <param name="nw">width </param>
/// <param name="nh">height</param>
/// <param name="iTextureWidth">width in texture</param>
/// <param name="iTextureHeight">height in texture</param>
/// <param name="iTextureLeft">x (left) offset in texture</param>
/// <param name="iTextureTop">y (top) offset in texture</param>
/// <param name="lColorDiffuse">diffuse color</param>
//public static void RenderImage(ref Texture texture, float x, float y, float nw, float nh, float iTextureWidth, float iTextureHeight, float iTextureLeft, float iTextureTop, long lColorDiffuse)
public static void RenderImage(Texture texture, float x, float y, float nw, float nh, float iTextureWidth,
float iTextureHeight, float iTextureLeft, float iTextureTop, long lColorDiffuse)
{
if (texture == null)
return;
if (texture.Disposed)
return;
if (GUIGraphicsContext.DX9Device == null)
return;
if (GUIGraphicsContext.DX9Device.Disposed)
return;
if (x < 0 || y < 0)
return;
if (nw < 0 || nh < 0)
return;
if (iTextureWidth < 0 || iTextureHeight < 0)
return;
if (iTextureLeft < 0 || iTextureTop < 0)
return;
VertexBuffer m_vbBuffer = null;
try
{
m_vbBuffer = new VertexBuffer(typeof (CustomVertex.TransformedColoredTextured),
4, GUIGraphicsContext.DX9Device,
0, CustomVertex.TransformedColoredTextured.Format,
GUIGraphicsContext.GetTexturePoolType());
Direct3D.SurfaceDescription desc;
desc = texture.GetLevelDescription(0);
float uoffs = ((float)iTextureLeft) / ((float)desc.Width);
float voffs = ((float)iTextureTop) / ((float)desc.Height);
float umax = ((float)iTextureWidth) / ((float)desc.Width);
float vmax = ((float)iTextureHeight) / ((float)desc.Height);
if (uoffs < 0 || uoffs > 1)
return;
if (voffs < 0 || voffs > 1)
return;
if (umax < 0 || umax > 1)
return;
if (vmax < 0 || vmax > 1)
return;
if (umax + uoffs < 0 || umax + uoffs > 1)
return;
if (vmax + voffs < 0 || vmax + voffs > 1)
return;
if (x < 0)
x = 0;
if (x > GUIGraphicsContext.Width)
x = GUIGraphicsContext.Width;
if (y < 0)
y = 0;
if (y > GUIGraphicsContext.Height)
y = GUIGraphicsContext.Height;
if (nw < 0)
nw = 0;
if (nh < 0)
nh = 0;
if (x + nw > GUIGraphicsContext.Width)
{
nw = GUIGraphicsContext.Width - x;
}
if (y + nh > GUIGraphicsContext.Height)
{
nh = GUIGraphicsContext.Height - y;
}
CustomVertex.TransformedColoredTextured[] verts =
(CustomVertex.TransformedColoredTextured[])m_vbBuffer.Lock(0, 0);
// Lock the buffer (which will return our structs)
verts[0].X = x - 0.5f;
verts[0].Y = y + nh - 0.5f;
verts[0].Z = 0.0f;
verts[0].Rhw = 1.0f;
verts[0].Color = (int)lColorDiffuse;
verts[0].Tu = uoffs;
verts[0].Tv = voffs + vmax;
verts[1].X = x - 0.5f;
verts[1].Y = y - 0.5f;
verts[1].Z = 0.0f;
verts[1].Rhw = 1.0f;
verts[1].Color = (int)lColorDiffuse;
//.........这里部分代码省略.........
示例11: BeginRenderOpacityBrushOverride
protected override bool BeginRenderOpacityBrushOverride(Texture tex, RenderContext renderContext)
{
if (_gradientBrushTexture == null || _refresh)
{
_gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops);
if (_gradientBrushTexture == null)
return false;
}
Matrix finalTransform = renderContext.Transform.Clone();
if (_refresh)
{
_refresh = false;
_effect = ContentManager.Instance.GetEffect(EFFECT_LINEAROPACITYGRADIENT);
g_startpoint = new float[] {StartPoint.X, StartPoint.Y};
g_endpoint = new float[] {EndPoint.X, EndPoint.Y};
if (MappingMode == BrushMappingMode.Absolute)
{
g_startpoint[0] /= _vertsBounds.Width;
g_startpoint[1] /= _vertsBounds.Height;
g_endpoint[0] /= _vertsBounds.Width;
g_endpoint[1] /= _vertsBounds.Height;
}
g_framesize = new float[] {_vertsBounds.Width, _vertsBounds.Height};
if (RelativeTransform != null)
{
Matrix m = RelativeTransform.GetTransform();
m.Transform(ref g_startpoint[0], ref g_startpoint[1]);
m.Transform(ref g_endpoint[0], ref g_endpoint[1]);
}
}
SurfaceDescription desc = tex.GetLevelDescription(0);
float[] g_LowerVertsBounds = new float[] {_vertsBounds.Left / desc.Width, _vertsBounds.Top / desc.Height};
float[] g_UpperVertsBounds = new float[] {_vertsBounds.Right / desc.Width, _vertsBounds.Bottom / desc.Height};
_effect.Parameters[PARAM_TRANSFORM] = GetCachedFinalBrushTransform();
_effect.Parameters[PARAM_OPACITY] = (float) (Opacity * renderContext.Opacity);
_effect.Parameters[PARAM_STARTPOINT] = g_startpoint;
_effect.Parameters[PARAM_ENDPOINT] = g_endpoint;
_effect.Parameters[PARAM_FRAMESIZE] = g_framesize;
_effect.Parameters[PARAM_ALPHATEX] = _gradientBrushTexture.Texture;
_effect.Parameters[PARAM_UPPERVERTSBOUNDS] = g_UpperVertsBounds;
_effect.Parameters[PARAM_LOWERVERTSBOUNDS] = g_LowerVertsBounds;
GraphicsDevice.Device.SetSamplerState(0, SamplerState.AddressU, SpreadAddressMode);
_effect.StartRender(tex, finalTransform);
return true;
}
示例12: CloneTexture
public static Texture CloneTexture( Texture oldTexture, Usage usage, Pool pool)
{
SurfaceDescription sd = oldTexture.GetLevelDescription(0);
return CloneTexture(oldTexture, sd.Width, sd.Height, oldTexture.LevelCount, sd.Format, usage, Filter.None, pool);
}
示例13: AutoTexture
/// <summary>
/// Create an AutoTexture
/// </summary>
public AutoTexture(Direct3d d3d, Texture texture)
{
mTexture = texture;
mD3d = d3d;
mSurfDesc = mTexture.GetLevelDescription(0);
d3d.DxLost += new Direct3d.DxDirect3dDelegate(d3d_DxLost);
d3d.DxRestore += new Direct3d.DxDirect3dDelegate(d3d_DxRestore);
}
示例14: m_RefreshTimer_Elapsed
private void m_RefreshTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
try
{
if (isUpdating)
return;
isUpdating = true;
if (m_ImageUri == null)
return;
if (m_ImageUri.ToLower().StartsWith("http://"))
{
bool forceDownload = false;
if (m_SaveFilePath == null)
{
// TODO: hack, need to get the correct cache directory
m_SaveFilePath = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath) + "\\Cache\\PictureBoxImages\\temp";
forceDownload = true;
}
System.IO.FileInfo saveFile = new System.IO.FileInfo(m_SaveFilePath);
if (saveFile.Exists)
{
try
{
Texture texture = ImageHelper.LoadTexture(m_SaveFilePath);
texture.Dispose();
}
catch
{
saveFile.Delete();
saveFile.Refresh();
}
}
if (forceDownload || !saveFile.Exists || (m_RefreshTime > 0 && saveFile.LastWriteTime.Subtract(System.DateTime.Now) > TimeSpan.FromSeconds(m_RefreshTime)))
{
//download it
try
{
WorldWind.Net.WebDownload webDownload = new WorldWind.Net.WebDownload(m_ImageUri);
webDownload.DownloadType = WorldWind.Net.DownloadType.Unspecified;
if (!saveFile.Directory.Exists)
saveFile.Directory.Create();
webDownload.DownloadFile(m_SaveFilePath);
}
catch { }
}
}
else
{
m_SaveFilePath = m_ImageUri;
}
if (m_ImageTexture != null && !m_ImageTexture.Disposed)
{
m_ImageTexture.Dispose();
m_ImageTexture = null;
}
if (!System.IO.File.Exists(m_SaveFilePath))
{
displayText = "Image Not Found";
return;
}
m_ImageTexture = ImageHelper.LoadTexture(m_SaveFilePath);
m_surfaceDescription = m_ImageTexture.GetLevelDescription(0);
int width = ClientSize.Width;
int height = ClientSize.Height;
if (ClientSize.Width == 0)
{
width = m_surfaceDescription.Width;
}
if (ClientSize.Height == 0)
{
height = m_surfaceDescription.Height;
}
if (ParentWidget is Widgets.Form && SizeParentToImage)
{
Widgets.Form parentForm = (Widgets.Form)ParentWidget;
parentForm.ClientSize = new System.Drawing.Size(width, height + parentForm.HeaderHeight);
}
else if(SizeParentToImage)
{
ParentWidget.ClientSize = new System.Drawing.Size(width, height);
}
ClientSize = new System.Drawing.Size(width, height);
m_currentImageUri = m_ImageUri;
IsLoaded = true;
//.........这里部分代码省略.........
示例15: BeginRenderOpacityBrushOverride
protected override bool BeginRenderOpacityBrushOverride(Texture tex, RenderContext renderContext)
{
if (_gradientBrushTexture == null || _refresh)
{
_gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops);
if (_gradientBrushTexture == null)
return false;
}
Matrix finalTransform = renderContext.Transform.Clone();
if (_refresh)
{
_refresh = false;
_gradientBrushTexture = BrushCache.Instance.GetGradientBrush(GradientStops);
_effect = ContentManager.Instance.GetEffect(EFFECT_RADIALOPACITYGRADIENT);
g_focus = new float[] { GradientOrigin.X, GradientOrigin.Y };
g_center = new float[] { Center.X, Center.Y };
g_radius = new float[] { (float) RadiusX, (float) RadiusY };
if (MappingMode == BrushMappingMode.Absolute)
{
g_focus[0] /= _vertsBounds.Width;
g_focus[1] /= _vertsBounds.Height;
g_center[0] /= _vertsBounds.Width;
g_center[1] /= _vertsBounds.Height;
g_radius[0] /= _vertsBounds.Width;
g_radius[1] /= _vertsBounds.Height;
}
g_relativetransform = RelativeTransform == null ? Matrix.Identity : Matrix.Invert(RelativeTransform.GetTransform());
}
SurfaceDescription desc = tex.GetLevelDescription(0);
float[] g_LowerVertsBounds = new float[] { _vertsBounds.Left / desc.Width, _vertsBounds.Top / desc.Height };
float[] g_UpperVertsBounds = new float[] { _vertsBounds.Right / desc.Width, _vertsBounds.Bottom / desc.Height };
_effect.Parameters[PARAM_RELATIVE_TRANSFORM] = g_relativetransform;
_effect.Parameters[PARAM_TRANSFORM] = GetCachedFinalBrushTransform();
_effect.Parameters[PARAM_FOCUS] = g_focus;
_effect.Parameters[PARAM_CENTER] = g_center;
_effect.Parameters[PARAM_RADIUS] = g_radius;
_effect.Parameters[PARAM_OPACITY] = (float) (Opacity * renderContext.Opacity);
_effect.Parameters[PARAM_ALPHATEX] = _gradientBrushTexture.Texture;
_effect.Parameters[PARAM_UPPERVERTSBOUNDS] = g_UpperVertsBounds;
_effect.Parameters[PARAM_LOWERVERTSBOUNDS] = g_LowerVertsBounds;
GraphicsDevice.Device.SetSamplerState(0, SamplerState.AddressU, SpreadAddressMode);
_effect.StartRender(tex, finalTransform);
return true;
}