public override void Dispose() { if (d3dBuffer != null) { d3dBuffer.Dispose(); d3dBuffer = null; } }
public bool ReleaseIfDefaultPool() { if (d3dPool == Pool.Default) { if (d3dBuffer != null) { d3dBuffer.Dispose(); d3dBuffer = null; } return(true); } return(false); }
public void Indexes() { indexes = new int[9000]; LowestPartIndexes(0); //Highest index index is now 144 HiltIndexes(144); //Highest index is now 480 BladeIndexes(480, 104); //Highest index is now 2400 ib = new Direct3D.IndexBuffer(typeof(int), indexes.Length, DXDevice, Direct3D.Usage.WriteOnly, Direct3D.Pool.Default); ib.SetData(indexes, 0, Direct3D.LockFlags.None); }
//--------------------------------------------------------------------- public bool RecreateIfDefaultPool(D3D.Device device) { if (d3dPool == Pool.Default) { Type bufferType = (type == IndexType.Size16) ? typeof(short) : typeof(int); // Create the Index buffer d3dBuffer = new IndexBuffer( bufferType, //sizeInBytes, // sizeInBytes is wrong, because the D3D API is expecting the number of indices numIndices, device, D3DHelper.ConvertEnum(usage), d3dPool); return(true); } return(false); }
/// <summary> /// Reloads the IndexBuffer for the vertices of the TerrainPage. /// </summary> public void RefreshIndexBuffer_Vertices() { if (_page != null) { GraphicsStream stream; short[] indices = new short[_page.TerrainPatch.NumVertices * 6]; short vertCount = 0; for (int i = 0; i < indices.Length; i += 6, vertCount += 4) { indices[i] = vertCount; indices[i + 1] = (short)(vertCount + 1); indices[i + 2] = (short)(vertCount + 2); indices[i + 3] = (short)(vertCount + 2); indices[i + 4] = (short)(vertCount + 3); indices[i + 5] = vertCount; } if (_ibVerts != null) { _ibVerts.Dispose(); _ibVerts = null; } _ibVerts = new D3D.IndexBuffer(typeof(short), indices.Length, _viewport.Device, D3D.Usage.WriteOnly, D3D.Pool.Managed); stream = _ibVerts.Lock(0, 0, D3D.LockFlags.None); stream.Write(indices); _ibVerts.Unlock(); _ibVertSize = indices.Length; } else if (_ibVerts != null) { if (!_ibVerts.Disposed) { _ibVerts.Dispose(); } _ibVerts = null; _ibVertSize = 0; } }
/// <summary> /// Reloads the IndexBuffer for the TerrainPage. /// </summary> public void RefreshIndexBuffer_Page() { if (_page != null) { GraphicsStream stream; short[] indices = new short[_page.TerrainPatch.Indices.Length]; for (int i = 0; i < indices.Length; i++) { indices[i] = _page.TerrainPatch.Indices[i]; } if (_ib != null) { _ib.Dispose(); _ib = null; } _ib = new D3D.IndexBuffer(typeof(short), indices.Length, _viewport.Device, D3D.Usage.WriteOnly, D3D.Pool.Managed); stream = _ib.Lock(0, 0, D3D.LockFlags.None); stream.Write(indices); _ib.Unlock(); _ibSize = indices.Length; } else if (_ib != null) { if (!_ib.Disposed) { _ib.Dispose(); } _ib = null; _ibSize = 0; } }
/// <summary> /// Clears the buffers used. /// </summary> public void ClearBuffers() { if (_vb != null && !_vb.Disposed) { _vb.Dispose(); _vb = null; _vbSize = 0; } if (_vbVerts != null && !_vbVerts.Disposed) { _vbVerts.Dispose(); _vbVerts = null; _vbVertSize = 0; } if (_vbByHeight != null && !_vbByHeight.Disposed) { _vbByHeight.Dispose(); _vbByHeight = null; _vbSize = 0; } if (_ib != null && !_ib.Disposed) { _ib.Dispose(); _ib = null; _ibSize = 0; } if (_ibVerts != null && !_ibVerts.Disposed) { _ibVerts.Dispose(); _ibVerts = null; _ibVertSize = 0; } }
public D3DHardwareIndexBuffer(IndexType type, int numIndices, BufferUsage usage, D3D.Device device, bool useSystemMemory, bool useShadowBuffer) : base(type, numIndices, usage, useSystemMemory, useShadowBuffer) { #if !NO_OGRE_D3D_MANAGE_BUFFERS d3dPool = useSystemMemory? Pool.SystemMemory : // If not system mem, use managed pool UNLESS buffer is discardable // if discardable, keeping the software backing is expensive ((usage & BufferUsage.Discardable) != 0) ? Pool.Default : Pool.Managed; #else d3dPool = useSystemMemory ? Pool.SystemMemory : Pool.Default; #endif Type bufferType = (type == IndexType.Size16) ? typeof(short) : typeof(int); // create the buffer d3dBuffer = new IndexBuffer( bufferType, //sizeInBytes, // sizeInBytes is wrong, because the D3D API is expecting the number of indices numIndices, device, D3DHelper.ConvertEnum(usage), d3dPool); }
private bool Initialize(GeometryManager manager, int size, bool isLarge, bool dynamic) { try { D3d.Pool d3dPool = D3d.Pool.Managed; D3d.Usage d3dUsage = D3d.Usage.WriteOnly; if (dynamic) { d3dUsage |= D3d.Usage.Dynamic; } d3dManager = manager; d3dIndexSize = size; d3dIsLarge = isLarge; d3dIndexBuffer = new D3d.IndexBuffer(this.Type, d3dIndexSize, manager.Device.D3dDevice, d3dUsage, d3dPool); return(true); } catch (D3d.InvalidCallException e) { log.Warning("Unable to create index stream: {0}", e.Message); } catch (D3d.OutOfVideoMemoryException e) { log.Warning("Unable to create index stream: {0}", e.Message); } catch (OutOfMemoryException e) { log.Warning("Unable to create index stream: {0}", e.Message); } return(false); }
public bool ReleaseIfDefaultPool() { if (d3dPool == Pool.Default) { if (d3dBuffer != null) { d3dBuffer.Dispose(); d3dBuffer = null; } return true; } return false; }
//--------------------------------------------------------------------- public bool RecreateIfDefaultPool(D3D.Device device) { if (d3dPool == Pool.Default) { Type bufferType = (type == IndexType.Size16) ? typeof(short) : typeof(int); // Create the Index buffer d3dBuffer = new IndexBuffer( bufferType, //sizeInBytes, // sizeInBytes is wrong, because the D3D API is expecting the number of indices numIndices, device, D3DHelper.ConvertEnum(usage), d3dPool); return true; } return false; }
/// <summary> /// Reloads the IndexBuffer for the TerrainPage. /// </summary> public void RefreshIndexBuffer_Page() { if ( _page != null ) { GraphicsStream stream; short[] indices = new short[_page.TerrainPatch.Indices.Length]; for ( int i = 0; i < indices.Length; i++ ) indices[i] = _page.TerrainPatch.Indices[i]; if ( _ib != null ) { _ib.Dispose(); _ib = null; } _ib = new D3D.IndexBuffer( typeof( short ), indices.Length, _viewport.Device, D3D.Usage.WriteOnly, D3D.Pool.Managed ); stream = _ib.Lock( 0, 0, D3D.LockFlags.None ); stream.Write( indices ); _ib.Unlock(); _ibSize = indices.Length; } else if ( _ib != null ) { if ( !_ib.Disposed ) _ib.Dispose(); _ib = null; _ibSize = 0; } }
/// <summary> /// Reloads the IndexBuffer for the vertices of the TerrainPage. /// </summary> public void RefreshIndexBuffer_Vertices() { if ( _page != null ) { GraphicsStream stream; short[] indices = new short[_page.TerrainPatch.NumVertices * 6]; short vertCount = 0; for ( int i = 0; i < indices.Length; i += 6, vertCount += 4 ) { indices[i] = vertCount; indices[i + 1] = (short) ( vertCount + 1 ); indices[i + 2] = (short) ( vertCount + 2 ); indices[i + 3] = (short) ( vertCount + 2 ); indices[i + 4] = (short) ( vertCount + 3 ); indices[i + 5] = vertCount; } if ( _ibVerts != null ) { _ibVerts.Dispose(); _ibVerts = null; } _ibVerts = new D3D.IndexBuffer( typeof( short ), indices.Length, _viewport.Device, D3D.Usage.WriteOnly, D3D.Pool.Managed ); stream = _ibVerts.Lock( 0, 0, D3D.LockFlags.None ); stream.Write( indices ); _ibVerts.Unlock(); _ibVertSize = indices.Length; } else if ( _ibVerts != null ) { if ( !_ibVerts.Disposed ) _ibVerts.Dispose(); _ibVerts = null; _ibVertSize = 0; } }
/// <summary> /// Clears the buffers used. /// </summary> public void ClearBuffers() { if ( _vb != null && !_vb.Disposed ) { _vb.Dispose(); _vb = null; _vbSize = 0; } if ( _vbVerts != null && !_vbVerts.Disposed ) { _vbVerts.Dispose(); _vbVerts = null; _vbVertSize = 0; } if ( _vbByHeight != null && !_vbByHeight.Disposed ) { _vbByHeight.Dispose(); _vbByHeight = null; _vbSize = 0; } if ( _ib != null && !_ib.Disposed ) { _ib.Dispose(); _ib = null; _ibSize = 0; } if ( _ibVerts != null && !_ibVerts.Disposed ) { _ibVerts.Dispose(); _ibVerts = null; _ibVertSize = 0; } }
public void OnDeviceReset(object sender, System.EventArgs e) { Direct3D.Device dev = (Direct3D.Device)sender; dev.RenderState.Lighting = false; // ZBufferring is on by default //dev.RenderState.ZBufferEnable = true; if(null != vertexBuffer) { vertexBuffer.Dispose(); } vertexBuffer = new Direct3D.VertexBuffer(m_aVertices[0].GetType(), m_aVertices.Length, dev, Direct3D.Usage.WriteOnly, Direct3D.CustomVertex.PositionColoredTextured.Format, Direct3D.Pool.Default); vertexBuffer.SetData(m_aVertices, 0, Direct3D.LockFlags.None); // In DirectX 9, Vertex and Pixel Shaders do not need to be recreated on a device reset dev.VertexShader = vertexShader; dev.PixelShader = pixelShader; dev.VertexFormat = Direct3D.CustomVertex.PositionColoredTextured.Format; dev.SetStreamSource(0, vertexBuffer, 0); if(null != indexBuffer) { indexBuffer.Dispose(); } indexBuffer = new Direct3D.IndexBuffer(m_aIndices[0].GetType(), m_aIndices.Length, dev, Direct3D.Usage.WriteOnly, Direct3D.Pool.Default); indexBuffer.SetData(m_aIndices, 0, Direct3D.LockFlags.None); dev.Indices = indexBuffer; System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream stream = assembly.GetManifestResourceStream("_6_ShaderAsm.photo.png"); // If you want to know the names of all of the embedded resources, // you can get an array of strings with the names. // string[] resourceNames = assembly.GetManifestResourceNames(); // If you want to load the texture from a file instead of an embedded resource, you can do this: // texture = Direct3D.TextureLoader.FromFile(dev, "photo.png"); if(null != texture) { texture.Dispose(); } texture = Direct3D.TextureLoader.FromStream(dev, stream); stream.Close(); dev.SetTexture(0, texture); }
private bool Initialize(GeometryManager manager,int size, bool isLarge, bool dynamic) { try { D3d.Pool d3dPool = D3d.Pool.Managed; D3d.Usage d3dUsage = D3d.Usage.WriteOnly; if( dynamic ) { d3dUsage |= D3d.Usage.Dynamic; } d3dManager = manager; d3dIndexSize = size; d3dIsLarge = isLarge; d3dIndexBuffer = new D3d.IndexBuffer( this.Type,d3dIndexSize,manager.Device.D3dDevice, d3dUsage,d3dPool ); return true; } catch (D3d.InvalidCallException e) { log.Warning("Unable to create index stream: {0}", e.Message); } catch (D3d.OutOfVideoMemoryException e) { log.Warning("Unable to create index stream: {0}", e.Message); } catch (OutOfMemoryException e) { log.Warning("Unable to create index stream: {0}", e.Message); } return false; }
public void OnDeviceReset(object sender, System.EventArgs e) { Direct3D.Device dev = (Direct3D.Device)sender; dev.RenderState.Lighting = false; if(null != vertexBuffer) { vertexBuffer.Dispose(); } vertexBuffer = new Direct3D.VertexBuffer(m_aVertices[0].GetType(), m_aVertices.Length, dev, Direct3D.Usage.WriteOnly, Direct3D.CustomVertex.TransformedColored.Format, Direct3D.Pool.Default); vertexBuffer.SetData(m_aVertices, 0, Direct3D.LockFlags.None); dev.VertexShader = null; dev.VertexFormat = Direct3D.CustomVertex.TransformedColored.Format; dev.SetStreamSource(0, vertexBuffer, 0); if(null != indexBuffer) { indexBuffer.Dispose(); } indexBuffer = new Direct3D.IndexBuffer(m_aIndices[0].GetType(), m_aIndices.Length, dev, Direct3D.Usage.WriteOnly, Direct3D.Pool.Default); indexBuffer.SetData(m_aIndices, 0, Direct3D.LockFlags.None); dev.Indices = indexBuffer; }