public Video(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync) : base(parent) { try { this.application = application; FileTag = "D3D9_"; currentVertexTextures = new Texture2D[4]; currentPixelTextures = new Texture2D[8]; currentRenderTargets = new RenderTarget[4]; int depthBit = 16, stencilBit = 0; switch (depthStencilFormats) { case DepthStencilFormats.None: depthBit = 0; stencilBit = 0; break; case DepthStencilFormats.Defualt: depthBit = 24; stencilBit = 0; break; case DepthStencilFormats.Depth24Stencil8: depthBit = 24; stencilBit = 8; break; case DepthStencilFormats.Depth16: depthBit = 16; stencilBit = 0; break; case DepthStencilFormats.Depth24: depthBit = 24; stencilBit = 0; break; case DepthStencilFormats.Depth32: depthBit = 32; stencilBit = 0; break; default: Debug.ThrowError("Video", "Unsuported DepthStencilFormat type"); break; } com = new VideoCom(); var frame = application.FrameSize; BackBufferSize = frame; ComponentCaps componentCaps; var error = com.Init(application.Handle, vSync, frame.Width, frame.Height, depthBit, stencilBit, false, false, out componentCaps); switch (error) { case VideoError.Direct3DInterfaceFailed: Debug.ThrowError("Video", "Failed to create Direct3D9 interface.\nDo you have up to date graphics drivers?"); break; case VideoError.GetCapsFailed: Debug.ThrowError("Video", "Failed to get caps"); break; case VideoError.AdapterDisplayModeFailed: Debug.ThrowError("Video", "Failed to get adapter display mode"); break; case VideoError.VideoHardwareNotSupported: Debug.ThrowError("Video", "Your video hardware is not supported"); break; case VideoError.DeviceAndSwapChainFailed: Debug.ThrowError("Video", "Failed to create Device and SwapChain"); break; } Caps = new Caps() { ExDevice = componentCaps.ExDevice, HardwareInstancing = componentCaps.HardwareInstancing, MaxTextureCount = componentCaps.MaxTextureCount, MaxVertexShaderVersion = getMaxShaderVersion(componentCaps.MaxVertexShaderVersion), MaxPixelShaderVersion = getMaxShaderVersion(componentCaps.MaxPixelShaderVersion), MaxShaderVersion = getMaxShaderVersion(componentCaps.MaxShaderVersion) }; com.DeviceLost = deviceLost; com.DeviceReset = deviceReset; } catch (Exception e) { Dispose(); throw e; } }
internal void disableActiveTexture(Texture2D texture) { var textures = currentVertexTextures; for (int i = 0; i != textures.Length; ++i) { if (textures[i] == texture) { com.DisableVertexTexture(i); textures[i] = null; } } textures = currentPixelTextures; for (int i = 0; i != textures.Length; ++i) { if (textures[i] == texture) { com.DisableTexture(i); textures[i] = null; } } }