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; } }
private void init(IDisposableResource parent, IApplication application, DepthStencilFormats depthStencilFormats, bool vSync) #endif { this.application = application; try { FileTag = "D3D11_"; Cap = new Caps(); 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 featureLevel = REIGN_D3D_FEATURE_LEVEL.LEVEL_9_1; var frame = application.FrameSize; #if WIN32 var error = com.Init(application.Handle, vSync, frame.Width, frame.Height, depthBit, stencilBit, false, out featureLevel); #elif WINRT var error = com.Init(application.CoreWindow, vSync, frame.Width, frame.Height, depthBit, stencilBit, out featureLevel, swapChainBackgroundPanel); #else var error = com.Init(vSync, frame.Width, frame.Height, depthBit, stencilBit, out featureLevel, OS.UpdateAndRender); #endif BackBufferSize = frame; switch (error) { case VideoError.DepthStencilTextureFailed: Debug.ThrowError("Video", "Failed to create DepthStencilTexture"); break; case VideoError.DepthStencilViewFailed: Debug.ThrowError("Video", "Failed to create DepthStencilView"); break; case VideoError.RenderTargetViewFailed: Debug.ThrowError("Video", "Failed to create RenderTargetView"); break; #if !WP8 case VideoError.GetSwapChainFailed: Debug.ThrowError("Video", "Failed to get SwapChain"); break; #endif #if WIN32 case VideoError.DeviceAndSwapChainFailed: Debug.ThrowError("Video", "Failed to create Device and SwapChain"); break; #else case VideoError.DeviceFailed: Debug.ThrowError("Video", "Failed to create Device"); break; #if !WP8 case VideoError.SwapChainFailed: Debug.ThrowError("Video", "Failed to create SwapChain"); break; case VideoError.D2DFactoryFailed: Debug.ThrowError("Video", "Failed to create D2D Factory"); break; case VideoError.D2DDeviceFailed: Debug.ThrowError("Video", "Failed to create D2D Device"); break; case VideoError.D2DDeviceContextFailed: Debug.ThrowError("Video", "Failed to D2D DeviceContext"); break; case VideoError.NativeSwapChainPanelFailed: Debug.ThrowError("Video", "Failed to get native SwapChainPanel"); break; case VideoError.GetDXGIBackBufferFailed: Debug.ThrowError("Video", "Failed to create DXGI BackBuffer"); break; case VideoError.DXGISurfaceFailed: Debug.ThrowError("Video", "Failed to create DXGI Surface"); break; case VideoError.D2DBitmapFailed: Debug.ThrowError("Video", "Failed to create D2D Bitmap"); break; #else case VideoError.RenderTextureFailed: Debug.ThrowError("Video", "Failed to create RenderTexture"); break; #endif #endif } #if WP8 ((XAMLApplication)application).MainPage.Surface.SetContentProvider(com.GetProvider()); #endif switch (featureLevel) { #if WINRT || WP8 case REIGN_D3D_FEATURE_LEVEL.LEVEL_11_1: Cap.MaxShaderVersion = ShaderVersions.HLSL_5_0; Cap.FeatureLevel = FeatureLevels.D3D11_1; break; #endif case REIGN_D3D_FEATURE_LEVEL.LEVEL_11_0: Cap.MaxShaderVersion = ShaderVersions.HLSL_5_0; Cap.FeatureLevel = FeatureLevels.D3D11; break; case REIGN_D3D_FEATURE_LEVEL.LEVEL_10_1: Cap.MaxShaderVersion = ShaderVersions.HLSL_4_1; Cap.FeatureLevel = FeatureLevels.D3D10_1; break; case REIGN_D3D_FEATURE_LEVEL.LEVEL_10_0: Cap.MaxShaderVersion = ShaderVersions.HLSL_4_0; Cap.FeatureLevel = FeatureLevels.D3D10; break; case REIGN_D3D_FEATURE_LEVEL.LEVEL_9_3: Cap.MaxShaderVersion = ShaderVersions.HLSL_3_0; Cap.FeatureLevel = FeatureLevels.D3D9_3; break; case REIGN_D3D_FEATURE_LEVEL.LEVEL_9_2: Cap.MaxShaderVersion = ShaderVersions.HLSL_2_a; Cap.FeatureLevel = FeatureLevels.D3D9_2; break; case REIGN_D3D_FEATURE_LEVEL.LEVEL_9_1: Cap.MaxShaderVersion = ShaderVersions.HLSL_2_0; Cap.FeatureLevel = FeatureLevels.D3D9_1; break; } } catch (Exception e) { Dispose(); throw e; } }