public static Vertices <TVertexType> CreateSingleElementVertices(DeviceContext context, TVertexType[] data, DeclarationUsage elementUsage, int index) { if (typeof(float) != typeof(TVertexType) && typeof(Vector2) != typeof(TVertexType) && typeof(Vector3) != typeof(TVertexType) && typeof(Vector4) != typeof(TVertexType) && typeof(Half2) != typeof(TVertexType) && typeof(Half4) != typeof(TVertexType)) { throw new ArgumentException("Only float and vector types are supported for single element vertex buffers"); } if (data == null) { throw new ArgumentNullException(); } if (index >= 16 || index < 0) { throw new ArgumentException("index"); } DeclarationType format = VertexDeclarationBuilder.DetermineFormat(typeof(TVertexType)); VertexElement[] elements = new VertexElement[] { new VertexElement(0, 0, format, DeclarationMethod.Default, elementUsage, (byte)index) }; int stride = VertexElementAttribute.CalculateVertexStride(elements); return(new Vertices <TVertexType>(context, data, elements, stride)); }
public VertexDeclarationBuilder(DeviceContext context) { _context = context; _declarationMapping = new Dictionary <Type, VertexElement[]>(); _typeHash = new Dictionary <Type, short>(); _hashingDecl = new DeclarationHash(typeof(Vector3), _typeHash, ref _typeIndex); //static to keep from GC messing Instance = this; BuildFormatList(); }
public DeviceContext(IntPtr handle, int backBufferWidth, int backBufferHeight, bool fullScreen, bool verticalSync) { PerformanceMonitor = new PerformanceMonitor(); _formHandle = handle; PresentationParameters = new PresentParameters() { BackBufferFormat = Format.X8R8G8B8, BackBufferCount = 1, BackBufferWidth = backBufferWidth, BackBufferHeight = backBufferHeight, MultiSampleType = MultisampleType.None, SwapEffect = SwapEffect.Discard, EnableAutoDepthStencil = true, AutoDepthStencilFormat = Format.D24S8, PresentFlags = PresentFlags.DiscardDepthStencil, PresentationInterval = PresentInterval.Immediate, Windowed = !fullScreen, DeviceWindowHandle = _formHandle }; try { Direct3D library = new Direct3D(); if (library.AdapterCount == 0) { throw new Exception("Unable to find an appropriate Direct3D adapter."); } AdapterDetails adapterDetails = library.GetAdapterIdentifier(0); AdapterInformation adapterInformation = library.Adapters[0]; _device = new Device(library, 0, DeviceType.Hardware, _formHandle, CreateFlags.HardwareVertexProcessing, PresentationParameters); _viewport = _device.Viewport; _capabilities = _device.Capabilities; Tracer.Info("Adapter: {0}", adapterDetails.DeviceName); Tracer.Info("Driver: {0}, v{1}", adapterDetails.Driver, adapterDetails.DriverVersion); Tracer.Info("Max Texture Size: {0}x{1}", _capabilities.MaxTextureWidth, _capabilities.MaxTextureHeight); Tracer.Info("Max Texture Repeat: {0}", _capabilities.MaxTextureRepeat); Tracer.Info("Max Texture Aspect Ratio: {0}", _capabilities.MaxTextureAspectRatio); Tracer.Info("Texture Size Options: {0}", _capabilities.TextureCaps); } catch (Exception e) { Tracer.Error(e); return; } _vertexDeclarationBuilder = new VertexDeclarationBuilder(this); }
public static int SizeOfFormatType(DeclarationType type) { return(VertexDeclarationBuilder.SizeOfFormatType(type)); }